How To Create an RSSCollector Class

Bloo comes with a generalized RSSCollector class, which will gather RSS feeds from specified sources and store them in the your_prefix_rss_cache table.

Starting with version 1.25, developers can create SnapOns that contain classes descended from the generalized class and that can be used to collect specific RSS feeds through various means, such as those shown below:

1. With GET parameters:

http://myblog.com/?RSSCollect=1&RSSSet=[Name of RSS Set]
2. With a scheduled process on your webserver: See Setting up the RSS Collector

Below is an example of an RSSCollector descendent. This one is from the Bloo News extension:

class BlooNewsRSSCollector extends RSSCollector {
   var $name = "BlooNewsRSSCollector";
   var $rssSet = "BlooNews";
   var $floodProtectionSeconds = 14400; /* four hours is default */

   /* checks the feed to see if it was generated by a BlooNews RSS set */
   function feedValid( $rssFeedXML ) {
      $generator = $rssFeedXML->tagData[ "RSS" ][0][ "CHANNEL" ][0][ "GENERATOR" ];
      /* first 8 characters should be "BlooNews" */
      return ( substr( $generator, 0, 8 ) == "BlooNews" );
   }

   /* loads the list of bloo news sites to read */
   function loadFeedList( ) {
      /* read each rss feed from the bloogroll */
      $this->rssFeed = $this->getRowsFromQueryCommand( "=|BlooNews.feeds.get|=" );
   }
}

source: /extensions/bloo_news.classes.php
Some important things to note:
  • The name of the descendent class must be in the form of RSSSetNameRSSCollector. For instance, if the RSSSet is "BlooNews", the class must be called BlooNewsRSSCollector, as shown above
  • A member variable called $rssSet must be defined
  • An optional feedValid method can be defined, which returns true if the feed is valid for this RSSSet. In the example above, the feed is checked to make sure it's a true BlooNews feed.
  • A member variable called $floodProtectionSeconds can be defined. This will tell the RSSCollector how often to actually gather feeds in the RSSSet. This prevents flooding of requests, and should be set to something tolerable, as a value too large here will mean that updates of the RSS feeds in this set will be infrequent.
  • A method called loadFeedList is required. This method loads a member array called $rssFeed with the URLs of each feed in the set.