spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / scripts / sidebar To page 1To page 2To page 3current pageTo page 5To page 6
[previous] [next]

The Multi-Feed RSS Sidebar Tab

Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

The Perl

Our Perl code is just short of 350 lines long and has a bunch of comments, so we won't display the whole listing here (feel free to download the zipped package and have a look for yourself, though). We will however touch on some key points and discuss a few code snippets. The basic task of the Perl code is as follows:

Several global variables are defined near the top of the feedtab script:

Retrieving your feed listing is the purpose of the &getFeeds function; it is discussed next.

sub getFeeds {
#
# Example initial feed array. Modify/expand this; or 
# retrieve the structure via your own mechanism (DB, external 
# configuration file, etc.)
#
   my @NEWSFEEDS = (
      {
         location   => 'webreference.rdf',
         title      => 'WebReference.com',
         shortTitle => 'WebReference Features',
         dark       => '#fc0',
         light      => '#ffed9a',
         bg         => '#fff',
         hbg        => '#fd3',
      },
      {
         location   => 'js/tips/channels/last1512.rdf',
         title      => 'JavaScript Tip of the Day',
         dark       => '#fc6',
         light      => '#ffd',
         bg         => '#fff',
         hbg        => '#fd3',
      },
   );
  
   my %retHash=();

   foreach my $feed (@NEWSFEEDS) {
      my %feedHash=();

      # assign all properties from provided feeds
      foreach my $key (keys %$feed) {
         $feedHash{$key} =$feed->{$key};
      }

      # check for/assign default 
      # info if not initially present
      foreach my $key (keys %defHash) {
         $feedHash{$key} = $defHash{$key} unless (defined($feedHash{$key}));
      }
      $retHash{$feed->{'location'}}=\%feedHash;
   }
   return %retHash;
}

#
# end sub getFeeds
###############################################

We left &getFeeds purposely fairly bare, since how you retrieve your feeds for listing will depend entirely on what structure you have them in already. In the worse case, you can simply modify and extend the hashes in the @NEWSFEEDS array to accommodate all of your RSS feed listings. The location and title fields are the only required fields; all others will serve as overrides for the defaults for this particular feed (any of the defaults discussed in the earlier %defHash discussion can be used). The shortTitle field, in particular, can be used as a specifically formatted feed title in the event that you don't like the title included within the selected RSS file (which will otherwise be used as the default).

Two other main routines are used in the Perl code; depending on whether the user has chosen to view a specific feed or to view the feed listing for further selection. Since both routines are very similar, we'll focus on a few details of the specific feed display and leave the &showAll routine for your own examination. As a security precaution, feedtab.cgi checks to see that any feed requested by the user matches a feed as listed in the &getFeeds() hash. This prevents a malicous end user from crafting a feedtab request that will attempt to read other files on our system; i.e., only those feeds that we explicitly allow may be read using feedtab. All other requests are shuttled off to the main feed display, &showAll.


home / scripts / sidebar To page 1To page 2To page 3current pageTo page 5To page 6
[previous] [next]

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Working with the DOM Stylesheets Collection · Administering RBAC in PHP 5 CMS Framework · xref: Automatic Cross Referencing Script
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Combine BottomCount() with Other MDX Functions to Add Sophistication · Creating a Daemon with Python · The Coming Voice-over-WiMAX Revolution

Created: May 17, 2002
Revised: May 17, 2002

URL: http://webreference.com/scripts/sidebar/4.html