Scoop -- the swiss army chainsaw of content management
Front Page · Everything · News · Code · Help! · Wishlist · Project · Scoop Sites · Dev Notes · Latest CVS changes · Development Activities
Intro To Scoop Development Announcements
By hurstdog , Section Help! []
Posted on Wed Aug 22, 2001 at 12:00:00 PM PST

Every so often I get an email or talk to someone who says they want to help out with scoop but don't know where to start. Or that they know a little bit of perl, but not enough to help out with something like Scoop. This article aims to cover the basics necessary for you to know to help out with Scoop. It won't cover everything about Scoop, nor will it cover many details, but it will cover *just* enough to get you hacking.

This article assumes a working knowledge of perl, with a little familiarity with the Perl OO system. It also assumes a little knowledge of sql

First things first, where is everything!? Scoop is set up in a type of heirarchy, with everthing in the lib/ directory of your scoop distribution. You'll notice 2 directories there, Bundle, and Scoop. Don't worry about Bundle, unless you like futzing with CPAN. Scoop.pm has all the main initialization routines, which you shouldn't need to worry about for now. All of the different perl modules that make up scoop fall under the Scoop directory.

Within the Scoop directory its pretty easy to understand, Polls stuff is in Polls.pm and under the Polls/ dir, Comments in the Comments.pm and Comments/ dir, etc. If you're adding a new module, and it starts to get bigger than about 1000 lines, think hard about splitting it up like some of the other modules.

All of the modules have some degree of POD ( run 'perldoc perldoc' if you're not familiar with it), so a lot of information about how they work, and how to use them can be gleaned from typing 'perldoc Scoop.pm' or any other .pm file.

Now that you can poke around in the files a bit and see how things work, whats that $S think you see around everywhere? Well if you've done other OOPerl projects, you might have seen it as $self. Its the Scoop object, which is implicitly passed as the first parameter to any method call that it makes. Make sense? Here is an example.

$S->function('argument');

sub function {
        my $S = shift;    # gets the $S object
        my $arg = shift;  # gets 'argument'
}

So if you write any new functions, be sure to make the first parameter they take be $S (i.e. just put in that 'my $S = shift;' line) or you'll notice very strange errors... trust me on this :)

There is quite a bit more about the $S object than just being the first argument to a method call. Since it is a blessed hash ( run 'perldoc perltoot' for more info on perl OO ) you have access to all of its keys as well as all of its methods. For example, there are 2 ways to call the scoop CGI.pm methods:

# first way, cgi is set up as a method
$S->cgi->param();
# second way, cgi is a hashref to a method
$S->{CGI}->param();
What you use is up to you. Most of the time you will see the second notation in use in scoop though. For a list of most of the possible methods and keys in $S, check out the Scoop Administrators Guide section on $S.

Now what about getting access to all of the vars and blocks? Well, they're loaded at initialization, and reloaded on any change to them. What that means for the developers is that we don't have to go mucking around in any database calls just to get at a simple var or block. Its loaded up at initialization, and put in the $S->{UI} hashref. All of the vars are loaded and stored in $S->{UI}->{VARS} and all of the blocks are in $S->{UI}->{BLOCKS}. An example usage:

$S->{UI}->{BLOCKS}->{CONTENT} = $S->{UI}->{BLOCKS}->{story_summary};
if( $S->{UI}->{VARS}->{'show_time'} ) {
        my $time = localtime();
        $S->{UI}->{BLOCKS}->{CONTENT} =~ s/%%TIME%%/$time/g;
}

"But wait!" you say. "I see no 'CONTENT' block anywhere in my database! Am I missing something?" No. The CONTENT block comes from the template that is being used to display the page. Any |nameslikethis| in vertical bars in the template block get added to the BLOCKS hashref for you to fill while processing the request, UNLESS the name inside the vertical bars is an existing block, in which case that block gets substitued in for the |nameslikethis|. You might also notice in that example above that I don't do a substitution for |TIME|, I do it for %%TIME%%. Thats because the database stores those as %%nameslikethis%% as opposed to |nameslikethis|. This is to make sure that when scoop is displaying the block editor, it doesn't substitute out the |nameslikethis|, it gives you a chance to edit them.

So now you can call functions, and access blocks. But what about query strings in the url? How can you get to all those key/value pairs? With $S->{CGI}->param(). Used as $S->{CGI}->param('foo') it will return the value of foo from the url, unless foo had multiple values, in which it returns an arrayref of all the values (which is used only 1 place in Scoop, at the moment, so you'll probably not have to use it ). If you call param() with no parameters, it will return an array of all of the keys in the url.

# url is http://scoopsite.com/?op=foo;baz=bar;baz=blah;baz=arg
my @keys = $S->{CGI}->param();      # @keys = ('op', 'baz')
my $op   = $S->{CGI}->param('op');  # $op eq 'foo'
my @bazs = $S->{CGI}->param('baz'); # @bazs = ('bar', 'blah', 'arg')

One of the things you'll do most often in scoop is access the database. This is done via a few database wrapper utilities. Each takes an anonymous hash as its single argument, with a few predefined keys that help to build the query. Its best shown by example, so here is a few:

my $input = $S->{CGI}->param('input');
# ALWAYS quote user input, talked about more below
# in the database section
my $q_input = $S->{DBH}->quote($input);
my ($rv, $sth) = $S->db_select({
    DEBUG   => 1,
    WHAT    => 'uid',
    FROM    => 'users',
    WHERE   => qq| nickname = $q_input |,
   });

if( $rv ) {
    while( my $row = $sth->fetchrow_hashref ) {
        warn "nickname $input has uid $row->{uid}";
    }
}

For information on what functions $sth supports, read the pod for DBI, 'perldoc DBI'. The most used in scoop is fetchrow_hashref, since its the most readable. For the record, $rv is the return value from the query, it will be false if it failed, and true if it succeeded.

You might have noticed the warn() call above as well. If you've done cgi before you might recognize it. It logs a message to the error_log. Very handy for debugging.

Here is a short list of the keys that each db_* call supports, each is a mysql keyword, so dig in your sql manual for keys you don't understand

  • db_select - DISTINCT, WHERE, FROM, GROUP_BY, ORDER_BY, LIMIT, DEBUG
  • db_insert - INTO, COLS, VALUES, DEBUG
  • db_update - WHERE, LIMIT, DEBUG
  • db_delete - WHERE, LIMIT, DEBUG

Soon the database access functions will change a bit, to do quoting for you, but for now, you have to be sure to quote() ALL input from the users that is going into the database. In my example above you would have seen it used. You access the quote function through $S->{DBH}, which is a reference to the database handle

my $foo = $S->{CGI}->param('foo');
my $q_foo = $S->{DBH}->quote($foo);
# now $q_foo is safe to use in queries
Now why should you always quote your input you ask? Well, it keeps the code more secure. Say that I have a hidden form value like the following:
<input type="hidden" name="foo" value="bar">
When I get the value in scoop, I need to quote it. Even though its a hidden field! This is because someone might save that page, and modify the input value to be like the following
<input type="hidden" name="foo" value=" ';DELETE FROM USERS; ">
Now whats above won't work as-is, but with a little work, and playing around with the options (especially since everyone has access to the scoop source) people can see what will work to run arbitrary sql commands on your database. So you can see, that by not quoting input from the user, you're essentially giving anybody with enough time a myqsl prompt to your database.

Now you should know enough to create your own module. There are 3 main things you need to do to add a module into Scoop:

  1. Create the file in the Scoop/ directory. At the top of the file,( no need for the '#!/usr/bin/perl' line, since this is mod_perl), be sure to put in a 'package Scoop;' line. This will allow all of your function names to be accessed via the $S object. Be sure to use unique names, so it might be handy to prefix them with a meaningful string. Like rdf_add_channel() for RDF.pm methods.
  2. Make sure the file is associated with an op. Open up Scoop/ApacheHandler.pm in your favorite text editor (vim!!) and add a call to the method you made in your Scoop/MyModule.pm file to an appropriate place in the large if/else tree in _main_op_select()
  3. Make sure your module gets loaded on startup. Just add a line for it in startup.pl, which is in the etc/ directory of a default scoop tarball.
There are a few more small things, like setting which template to use with your op ( hint: check Scoop/Admin/OpTemplates.pm, add an op to the list, and set it in the Template Admin tool). Stopping and Starting apache after every change is another thing to remember to do.

So with that you should be able to hack on Scoop with relative ease. With a little bit of messing around with the current code you'll get the hang of it quickly, its not a very difficult system to learn. If you have any questions about a certain implementation, feel free to mail the scoop-dev list, you can join it on Sourceforge.net.

< Admin Logging | How do you get a provider that will deal with DOS attacks? >

Menu
· create account
· faq
· search
· report bugs
· Scoop Administrators Guide
· Scoop Box Exchange

Login
Make a new account
Username:
Password:

Related Links
· Scoop
· Scoop Administrators Guide
· Sourceforg e.net
· More on Announcements
· Also by hurstdog

Story Views
  378 Scoop users have viewed this story.

Display: Sort:
Intro To Scoop Development | 37 comments (37 topical, 0 hidden)
Plugging to Scoop from outside of Apache (none / 0) (#1)
by zby on Sun Nov 30, 2003 at 12:49:27 PM PST

I'd like to write a small addition to the scoop system. The problem is that it is meant to be run from command line - how can I build the main Scoop object (the $S variable) in such situation? Of course I can plug directly to the database, but I feel it would be a bit more safe if I used the Scoop subroutines for inserting data into the database.



i cann't understand (none / 0) (#7)
by funvideoblog on Tue May 02, 2006 at 08:02:15 PM PST

i cann't understand



Wil jij idool worden? (none / 0) (#8)
by Vincent on Tue Jan 06, 2009 at 12:14:57 AM PST

Wil jij idool worden? Dan krijg je vanaf begin volgend jaar weer de kans bij RTL 4. De zender komt terug met het format X Factor. Wendy van Dijk krijgt dit keer niet de exclusieve presentatie, dat mag ze samen gaan doen met Martijn Krabbé, zo meldt De Telegraaf. Marianne van Wijnkoop zit vrijwel zeker in de jury, de andere twee juryleden zijn nog onduidelijk. Henkjan Smits stapte zoals bekend over naar SBS 6 en Henk Temming in de jury was niet echt een succes. Opvallend is dat de talentenjacht dit keer niet in september begint, maar pas in het nieuwe jaar. Daardoor zal de talentenjacht dit keer tot aan het begin van de zomerperiode duren, een periode waarin de kijkcijfers doorgaans afvlakken. Dat terwijl X Factor al een matig kijkcijfersucces was in vergelijking tot Idols. Een andere opvallende wijziging: X Factor wordt niet langer uitgesmeerd over twee avonden, maar de live-show en uitslag zullen op één avond zijn te zien. Slimme zet, want de kijker heeft volgens mij ook wel door dat hij hiermee aan het lijntje wordt gehouden. In X Factor kunnen mensen van jong tot oud meedoen. In de liveshows strijden ze gecategoriseerd tegen elkaar: jong (tot 26), ouder (26+) en groepjes. De winnaar van X Factor I was Sharon Kips, die inmiddels een televisiecarrière bij de EO is begonnen.



Scoop (none / 0) (#9)
by mike22122 on Wed Feb 04, 2009 at 01:43:23 AM PST

Scoop cool. online tv - To get some TV resouces here: watch tv online and free online tv Thanks



Test not (none / 0) (#10)
by samscoopsasl on Tue Aug 30, 2011 at 05:18:59 PM PST

Test not at home this effective way with the intention of make a trouble-free swap telephone search with the aim of reverse phone uncover away on or after home who is losing with the purpose of telephone number. And you be able to as well squander this phone number lookup so whilst to complete a telephone search in relation to to facilitate liar. As well as yet with a overturn lookup be able to perform the swap cellular phone method the unsurpassed thing you be able to always make if you consider a propos it today.



datarecovery (none / 0) (#11)
by sachinruhela on Sat Oct 15, 2011 at 08:51:25 AM PST

data recovery software Your post is really good and informative.



Reply (none / 0) (#12)
by bynes69 on Mon Oct 24, 2011 at 05:42:10 AM PST

Thanks for the information. This is a wonderful post!! Research Paper Term Paper Essay



Reply (none / 0) (#13)
by bynes69 on Mon Oct 24, 2011 at 05:42:24 AM PST

Thanks for the information. This is a wonderful post!! Thesis Dissertation



hi (none / 0) (#14)
by mrmill on Thu Nov 03, 2011 at 04:48:09 AM PST

I sincerely got a kick from your article. I really do not truly have much to say in response, I only wanted to comment to reply great work. H-Beam Section Steel



aded (none / 0) (#15)
by roter on Sat Nov 12, 2011 at 01:27:32 AM PST

One of the things you'll Test inside do most often in scoop is access the database. This is done via a few database testinside dumps wrapper utilities. Each takes an anonymous hash as its single argument, with a 650-195 few predefined keys that help to build the query. Its best shown by example, so here is a few



Re: (none / 0) (#16)
by rrgan12 on Fri Nov 25, 2011 at 05:38:23 PM PST

Thanks for taking this opportunity to discuss this, I feel fervently about this and I like learning about this subject. If possible, as you gain information, please update this blog with more information. I have found it really useful.
-van insurance quote



Perl (none / 0) (#17)
by evasmith8812 on Tue Nov 29, 2011 at 05:00:06 PM PST

It looks like I need to brush up on my Perl a bit before I dive into this sort of thing. I've had some experience with Outlook Repair , but have not wait around with Perl too much. You guys know any good online tutorials that I can use?



superb (none / 0) (#18)
by darcyheckel on Thu Dec 08, 2011 at 11:44:01 AM PST

Or ce type de détails sont bien la peine d'essayer de trouver des informations fiables pour les visiteurs avec une valeur pour vous personnellement que va certainement montrer la norme de l'auteur. Mais seuls quelques-uns des points ont été effectivement traités réellement bon, je crois que creuser profond pour la question de construire plus informatif aidera réellement, sera l'avenir des billettes plus instructif que cela. best gifts for men 2011 christmas toys 2011



savom (none / 0) (#20)
by scooby3 on Sun Jan 01, 2012 at 04:55:02 PM PST

people should come here more often as well free dating sites i love talking like people seem to listen free dating sites for women and so on... goes the dynamite payday loans online



pridne (none / 0) (#21)
by bluejade on Wed Jan 04, 2012 at 10:21:25 PM PST

For those of you who are purchasing ebridalgowns,we realize that this is one of the most important purchasing decisions you will make.Faucets.Crystallized Ginger Granular



thi is (none / 0) (#22)
by reverse02 on Sun Jan 08, 2012 at 09:36:27 PM PST

This is something I can really use phone number lookup



codn (none / 0) (#23)
by bluejade on Tue Jan 10, 2012 at 07:54:47 PM PST

Journalism is very tough job as per my view so we should reward them time to time that more and more people come to becoming a good journalist.Pumpkin Seeds



very interesting (none / 0) (#24)
by superking on Tue Jan 17, 2012 at 05:55:10 AM PST

very interesting post.this is my first time visit here.i found so mmany interesting stuff in your blog especially its discussion..thanks for the post! payday UK



I recently (none / 0) (#25)
by superking on Wed Jan 18, 2012 at 02:17:18 AM PST

I recently found many useful information in your website especially this blog page. Among the lots of comments on your articles. Thanks for sharing. payday advance online



wloen (none / 0) (#27)
by bluejade on Sun Jan 29, 2012 at 08:08:59 PM PST

It's like you didn't read the article. The point was to illistrate when a 'Answer' is presented.Peanut Peeler



myCmnt (none / 0) (#30)
by rae denial on Wed Feb 08, 2012 at 04:11:21 AM PST

I am really happy that I stumbled across this in my search for something relating to this issue. For most people, feelings of anxiety, sadness, grief and anger are healthy and appropriate. But some people may have more profound and debilitating reactions to the war. skin tag remover



rent to own homes in Maryland (none / 0) (#31)
by jiku on Thu Feb 09, 2012 at 02:10:35 PM PST

I don't actually know what will be the exact solution of this kind of particulars. But you can try different ways to solve it as well. But you should choose more authentic solution if there is not damage your valuable PC.rent to own homes in Maryland



school grants for women (none / 0) (#32)
by schoolgrantsforwomen on Sat Feb 11, 2012 at 04:51:47 AM PST

I sincerely got a kick from your article. I really do not truly have much to say in response, I only wanted to comment to reply great work. school grants for women



Cool bro (none / 0) (#33)
by TheGateKeeper on Sat Feb 11, 2012 at 07:54:05 AM PST

Very nice blog bro, reminds me of Self Defense Laws, or possibly heavy bag workout.Greetings from stretches for hamstring. Do us a favor and keep posting and never take this website down. Before I forget, havbe a look at Muay Thai Camps in Thailand.



kidnet (none / 0) (#34)
by bluejade on Sun Feb 12, 2012 at 10:57:36 PM PST

It was during that lull that the poor head of treasury for the prospect company tooted. mosquito nettings



Re: (none / 0) (#35)
by davesteve12 on Mon Feb 20, 2012 at 02:06:26 PM PST

Perhaps this is one of the most interesting blogs that I have ever seen. Interesting article, Funny comment.
-motor traders insurance



Great guy! (none / 0) (#36)
by nurry on Mon Feb 20, 2012 at 02:22:09 PM PST

This place along side instant payday loans is rockin!



hzier (none / 0) (#37)
by wuliao on Tue Feb 21, 2012 at 08:23:35 PM PST

Well i guess that is not going to be possible any longer. I really miss that format. Oil Refining Plant



Intro To Scoop Development | 37 comments (37 topical, 0 hidden)
Display: Sort:

Hosted by ScoopHost.com Powered by Scoop
All trademarks and copyrights on this page are owned by their respective companies. Comments are owned by the Poster. The Rest © 1999 The Management

create account | faq | search