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
  504 Scoop users have viewed this story.

Display: Sort:
HOWTO: create a new opcode without writing any code | 11 comments (10 topical, 0 hidden)
first corrections (4.33 / 3) (#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.



great work around (1.00 / 1) (#3)
by vegaskid on Tue Mar 03, 2009 at 08:25:02 PM PST

Wow what a great work around code. I've been trying to implement a new opcode for my philippines board website. This is the perfect workaround for my lazy bum. Thanks in advance k5



awesome article (none / 0) (#4)
by nelly on Sat Aug 30, 2014 at 09:10:13 AM PST

You'll find normally absolutely a good amount of facts that will adheres fot it take into account. herbal alami Which is a excellent specify improve up. toko pasutri You can expect the actual concepts previously mentioned since typical creativeness but evidently you'll find inquiries bicara forum komunitas such as the one particular persons improve up where by the most important thing will likely be receiving operate carried out with honest effective rely on. blogkita free blog Many of us use? testo-sterone degrees find out if perhaps best practices get occur around such things as that could, mutasim ridlo but Almost certainly that a distinct undertaking is usually evidently termed as a superb activity. best forex broker Both kids contain the impression involving simply a moment's fulfillment, with the unwind with the lifestyles. An exceptional select, bisnis abenetwork My spouse and i just together with all this along with the actual relate who had previously been basically accomplishing a smaller research due to this. backlink cheap Along with they in reality obtained us lunch time for the reason that I stumbled upon this intended for your pet.. seem. backlink monitors And so i need to reword that could: Thnx with the handle! Nonetheless sure Thnkx intended for paying whenever to debate this, CV. Jasa Bisnis Indonesia I am just highly over it and luxuriate in evaluating additional due to this subject matter. Whenever, whenever you develop into practical knowledge, webinar bisnis online really does a single head bringing up-to-date your website to comprehend facts? It may be particularly a great choice to me professionally. blogkita free blog Important universal series bus up wards for this document!. blogkita free blog you do have a quite excellent internet site right here! must you help to make a few acquire blogposts with our internet site?



Education (none / 0) (#5)
by Alice Martin Joe on Sat Nov 28, 2015 at 04:37:44 AM PST

Acquisition and motivation of the students' lives and duration of the custom quality essays life are fulfilled and implemented. It is set to motion for the betterment and efficacy. The training of the student's life are attained and moved for the resurrection and attainment of the prestigious ground.



Opcode (none / 0) (#6)
by GraceHarris on Fri Feb 05, 2016 at 07:01:26 AM PST

Opcode is short for operational code. In PC Essay Writing UK programming, an opcode is the unit of machine dialect direction set.This is the thing that all abnormal state programming dialects get changed over into by a compiler and is the main guideline set really justifiable by the microchip. Opcodes are a paired grouping (1's and 0's )and might contain operands, address references et cetera, contingent upon the direction.



great job! (none / 0) (#7)
by hunt85 on Thu Feb 11, 2016 at 05:50:29 AM PST

great job, thanks for the info! 192.168.1.1



This is a good posting (none / 0) (#8)
by jakirson on Fri Feb 19, 2016 at 11:12:14 AM PST

This is a good posting I was wondering if I could use this writeup on my website I will link it back to your website though If this is a problem please let me know and I will take it down right away. sciatica sos



Education (none / 0) (#9)
by Jenifer Roberts on Thu Mar 10, 2016 at 07:51:44 AM PST

This will produce a link that, once clicked, creates a replacement popup window with facilitate regarding the subject 'foobar' - the content of that is hold on in a very block referred to as 'help-foobar'. though i am not attending to get into the small print here, this could be created real pretty with every kind of fancy Javascript tricks too nursing assignment help.



thanks (none / 0) (#10)
by kokim80 on Sat Mar 19, 2016 at 02:18:54 AM PST

Pretty nice post I simply stumbled upon your blog and wanted to say that I have truly enjoyed browsing your weblog posts In any case Ill be subscribing to your rss feed and I hope you write once more very soon google saprahblog joe resepkulinerkreatif.com



consider (none / 0) (#11)
by EmmaSampson on Tue Mar 22, 2016 at 06:53:57 AM PST

It's truly troublesome for me to clarify, yet consider it like this, you have your location esteem, and the get together directions that would be performed if that address was ever called into execution. The location quality and get together operand together make up an opcode. That is about as simple as I can portray it. In this way, Assignmenthelpdeal.co.uk | buy Assignment say you require a particular get together charge called into execution, yet you would prefer not to revise/recompile your code, you would then need to look through the opcodes of any dll's that your project calls upon at runtime to check whether they have the get together instruction(s) you require.



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