radical hacks Web Store: Random Images sent in this cool hack which allows you to add random images to Web Store.

Charles writes....

To implement an SSI random image insertion effect using the randompicker script available on the internet in webstore, we did this:

1. To the webstore setup file we added this line:

    # MODIFICATION TO WEBSTORE ADDED FOR
    # RANDOM IMAGE INSERTION FEATURE
$random_picker_file_path = "/randompicker/random.txt";

2. To the display_page subroutine we added a line to parse the HTML for the standard SSI format line:

if ($_ =~ /<!--#exec cgi=.*randompicker.*-->/i)
    # Detects standard SSI format line.

Then we also added a line to call a special randompicker subroutine added to Webstore:

($_) = &random_picker;

Hence the beginning of the modified display_page subroutine looks like this:

sub display_page
  {
  local ($page, $routine, $file, $line) = @_;
  local ($queries,$company);

  $company = $form_data{'company'};
  &get_queries ($company);

  $queries =~ s/cart_id=/cart_id=$cart_id/g;

  # the subroutine begins by opening the requested file for
  # reading, exiting with file_open_error if there is a
  # problem as usual.

  open (PAGE, "<$page") ||
        &file_open_error("$page", "$routine", $file, $line);
  # It then reads in the file one line at a time.  However,
  # on every line it looks for special tag sequences which
  # it knows it must modify in order to maintain the state
  # information necessary for the workings of this script.
  # Specifically, every form must include a page and a
  # cart_id value and every URL hyperlink must have a
  # cart_id value added to it.
  #
  # Raw administratively pre-designed HTML pages must
  # include the following tag lines if they are to filter
  # properly and pass along this necessary state information.
  #
  # All forms must include two hidden field lines with the
  # "tags" to be substituted for imbedded as follows:
  #
  # <INPUT TYPE = "hidden" NAME = "cart_id" VALUE = "%%cart_id%%">
  # <INPUT TYPE = "hidden" NAME = "page" VALUE = "%%page%%">
  #
  # When the script reads in these lines, it will see the
  # tags "%%cart_id%%" and"%%page%%" and substitute them for
  # the actual page and cart_id values which came in as form
  # data.
  #
  # Similarly it might see the following URL reference:
  #
  # <A HREF = "web_store.cgi?page=Letters.html&cart_id=">
  #
  # In this case, it will see the cartid= tag and
  # substitute in the correct and complete
  # "cartid=some_number".

  while (<PAGE>)
    {
    # MODIFICATION ADDED TO EFFECT THE RANDOM PICKER
    # INSERTION FEATURE !!!
    if ($_ =~ /<!--#exec cgi=.*randompicker.*-->/i)
            # Detects standard SSI format line.
    {
     ($_) = &random_picker;
    }

3. We added the following subroutine to Webstore:


# MODIFICATION ADDED FOR RANDOM IMAGE INSERTION FEATURE !!!
###################################
#                   Subroutine   random_picker    #
################################

sub random_picker
{

local (@lines,@printen);
local ($random);
# Open the file containing phrases and read it in.

my $text_num = "0";
my $image_num = "1";
my $link_num = "2";

open(VIRTUAL,"$random_picker_file_path") ||
&file_open_error($random_picker_file_path,
"Opening random picker file.",__VIRTUAL__,__LINE__);
@lines = <VIRTUAL>;
close(VIRTUAL);

# Invoke srand; with a seed of the time and pid.  If
# you are on a machine
# which doesn't put the pid into $$ (ie. Macintosh,
# Win NT, etc...),change
# this line to:  srand(time ^ 22/7);

srand(time() ^ $$);

my $num = rand(@lines);

@printen = split(/\|/,$lines[$num]);
chop $printen[$link_num];

$random = qq~<center><a href="$printen[$link_num]"><img
src="$printen[$image_num]"
border="0"></a><br><a
href="$printen[$link_num]">$printen[$text_num]</a></center>
~;

return ($random);
}

The subroutine was taken from the listing of random.pl

To use the random.pl utility with Webstore, it will be neccessary to follow the instructions in the random.pl script and setup the list of banners to be associated with the feature. Once that is done, adjust the path to the random_picker_text variable in the setup file and insert this line wherever you want to insert the random clickable image in your HTML pages:

<!--#exec cgi="/cgi-bin/your_path/randompicker/random.pl"-->

Important: Remember to place the line on its own line to preserve HTML formatting information that would otherwise be removed when the line is parsed!!! Simply layout your page inserting the SSI block and then edit the HTML in a text editor (to isolate the line) when finished.