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
HOWTO: create a new opcode without writing any code New Code
By K5_eries , Section Code []
Posted on Sat Dec 30, 2000 at 12:00:00 PM PST
The title doesn't sound too exciting, but I think this is a pretty useful technique. I am writing this little tutorial in the hopes that it will encourage more people who dont' necessarily have that much coding experience to hack Scoop. Thanks to a combination of new features, especially boxes and templates, it is really easy to add all kinds of new functionality to Scoop from within the web-admin interface. I'm going to walk through the steps requried to add an online help system, which is something I've wanted to do for a while, anyway.

Goal
Our goal in this tutorial is to add the following feature to Scoop. You can type, anwhere and on any page, something like this into your Scoop blocks:

|BOX,help_link_box,foobar,About Foobar|
(although later we'll discuss how to make |HELP,x,y| an alias for this)

This will create a link that, when clicked, creates a new popup window with help about the topic 'foobar' - the content of which is stored in a block called 'help-foobar'. Although I'm not going to get into the details here, this can be made real pretty with all kinds of fancy Javascript tricks too. I'm going to keep the code in this tutorial Javascript-free, so as not to complicate the issue.

This is going to require a few changes to the Scoop code. Hopefully, you've got the latest version from CVS, although this should all work on any 0.6-based release or prerelease. Also, I'm hoping that the two places that do require changes to the code will eventually be changed so that the changes can be accomplished from the Vars menu instead. I'll have to talk to Rusty about that.

Creating the link
Anyway, back on topic. The first thing we need to do is create a Box that will print out the link when called. This box will not have any HTML associated with it, so we need to create an HTML box template called "raw_box" - which looks like this one line:


|CONTENT|


The code for the box, with boxid help_link_box, looks like this:

#First, get the two arguments, x and y. In our example, $target == "foobar" and 
# $label == "What's Foobar?"
my $target = shift @ARGS;
my $label = shift @ARGS;

#This should eventually become a block, but for now just print it out raw
my $content = qq{ <a href="|rootdir|/?op=help;helpid=$target" target=_help>$label</a> };

return { content => $content };

Be sure to associate this box with the raw_box template from the Templates SELECT box in the Boxes control panel.

Creating the "help" opcode
This is one of two places where you'll need to edit the scoop codebase, although like I said I hope that one day we'll get this controlled through a var. The file lib/Scoop/OpTemplates.pm controls which opcodes are shown in the "Templates" control panel (under Admin Tools). Just add "help" to the list of values. Restart Apache, and we're good to go.

Everything else from this point on does not require any changes to the scoop codebase, and can be done through the web interface. We need to create a template for the help display page. Again, this will be another one-line block, call it help_template:


|BOX,help_display_box|


In the Templates control panel, associate the "help" opcode with the "help_template" template.

The help_display_box will be required to provide all of the HTML necessary to make the page look good, so let's give it a nice block to do this in. Call it, for simplicity, help_display_box, and have it look something like this:


<HTML>
<HEAD>
<TITLE>|TITLE|</TITLE>
</HEAD>
<BODY>
<h1>|TITLE|</h1>
<p>
|CONTENT|
</BODY>
</HTML>

Now, it's time to create the help_display_box box. Be sure to associate it with the box template of the same name (it should show up in the "templates" SELECT box in the Boxes control panel). Here's the code for the help_display_box. It could use some additional error checking, etc. but let's keep it short for now:


#get the CGI paramters generated by help_link_box
my $target = $S->{CGI}->param( 'helpid' );

my $title = "Help about $target";
#get the content from the appropriately-named block
my $content = $S->{UI}->{BLOCKS}->{$target} || "Error: no content found for $target";

return { title => $title, content => $content };

Creating the help
That's it for the help system. All that remains is to actually create some help. This is accomplished using the Blocks system. For help about topic foobar, just create a block called "help-foobar" and put whatever HTML-formatted help in it that you would like. This block will automatically get loaded at the right time by the system we just created.

Advanced Topics
There's one more thing that would be nice, and that is to allow using the syntax |HELP,foobar,About Foobar| instead of the clunky |BOX,help_link_box,foobar,About Foobar|. Turns out, this is not so difficult. It requires two changes to the Scoop code, and here they are.

First, in lib/Scoop.pm look for a block like the following (it's line 425 for me):


      my $special_keys = {
          "BOX" => 'Scoop::box_magic',
          "URL" => 'Scoop::make_url',
          "A"   => 'Scoop::make_anchor'
      };

Add another mapping to this list: "HELP" => 'Scoop::make_help'.

Next, open up lib/Scoop/Utility.pm and add a function called make_help. It should look like this:


sub make_help 
{
    my $S = shift;
    my @ARGS = @_;
    
    return $S->box_magic( @ARGS );
}

Restart Apache, and you're done.

Well, folks, that's it for now. Sorry if any parts of this are confusing. This is a first draft, and since I am not near my Scoop install, the code is untested. I'll hopefully get some patches for the current CVS code that are a bit more elaborate than what's described here soon, if there is interest. So let me know if this is something you might find useful.

As always, feedback/questions/criticisms are more than welcome.

< Permanent Discussion Boards | Author deletion of stories >

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

Login
Make a new account
Username:
Password:

Related Links
· Scoop
· More on New Code
· Also by K5_eries

Story Views
  141 Scoop users have viewed this story.

Display: Sort:
HOWTO: create a new opcode without writing any code | 3 comments (2 topical, 0 hidden)
first corrections (4.00 / 2) (#2)
by K5_eries on Sat Dec 30, 2000 at 10:03:20 PM PST

Well, I'm near my Scoop install now, and I'm already finding bugs with the code outlined above. Here are my first set of corrections:
  • In several places, I erroneously used ALL-CAPS block names, like |CONTENT| and |TITLE| - these should be replaced with all-lower-case versions, like |content| and |title|.
  • The key line in the help_display_box box should read:
    my $content = $S->{UI}->{BLOCKS}->{"help-".$target} \|\| "Error: no content found for $target";
  • make_help (in Utility.pm) should actually read like this:
    
    sub make_help 
       {
           my $S = shift;
           my @ARGS = @_;
           
           return $S->box_magic( 'help_link_box', @ARGS );
       }
    
    
That should just about do it. Enjoy.



Can you tell how to do (none / 0) (#3)
by haylaz on Sat Apr 26, 2008 at 08:28:39 AM PST

WebcamSex WebcamSex WebcamSex WebcamSex WebcamSex



HOWTO: create a new opcode without writing any code | 3 comments (2 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