Revision [12431]

This is an old revision of RSSHandler made by DarTar on 2005-12-26 10:55:54.

 

A single class for RSS feed generation


Wikka still has a quite limited RSS support, both as output and input. Before thinking of possible SyndicatingWikka extensions, we need to implement in a more consistent way the available RSS-related services.

RSS as input


As for RSSInfo RSS embedding, which can be used to feed content to Wikka from external servers, we are switching to a new parser (like Magpie): Magpie is less buggy and way more flexible than the current one (Onyx).
NewRssAction more...

RSS as output


As for RSS generation, at the moment (1.1.6.1) Wikka has two separate handlers to generate feeds for page revisions and recently changed pages.

The problem
There are many issues with the current feed generation tools:
- feed generation is hardcoded in these handlers, so it cannot be easily modified or extended;
- these handlers produce feeds based on different standards: RSS 2.0 (page revisions) and RSS 0.92 (recently changed pages)
- only the recently changed pages has a dedicated stylesheet.

The solution
Instead of manually fixing the current handlers, why not create some general feed generation utility to be adapted to the specific kind of output to be produced? And instead of writing it ourselves and reinventing the wheel, why not simply write a wrapper around an existing feed generation class? There are many examples of light, flexible and GPL'ed PHP classes for feed generation that we could integrate with Wikka.

One that looks quite promising is: FeedCreator

Here's the features reported on its website:

FeedCreator.class.php provides an easy way to create RSS feeds from within PHP using ease to use classes.

Features:	 
- creates valid feeds according to RSS 0.91, 1.0 or 2.0 as well as PIE 0.1 (deprecated), OPML 1.0, Unix mbox, ATOM 0.3, or customizable HTML or Javascript format.
- configurable feed caching
- very well documented and easy to use
- Feed image
- includes almost all RSS 0.91 attributes
- decide which version to create during runtime
- easy to use and well documented class interface
- intelligently truncates strings when needed


Using the class is quite straightforward, here's an example from the website:

<?php  
include("feedcreator.class.php");

$rss = new UniversalFeedCreator();
$rss->useCached();
$rss->title = "PHP news";
$rss->description = "daily news from the PHP scripting world";
$rss->link = "http://www.dailyphp.net/news";
$rss->syndicationURL = "http://www.dailyphp.net/".$PHP_SELF;

$image = new FeedImage();
$image->title = "dailyphp.net logo";
$image->url = "http://www.dailyphp.net/images/logo.gif";
$image->link = "http://www.dailyphp.net";
$image->description = "Feed provided by dailyphp.net. Click to visit.";
$rss->image = $image;

// get your news items from somewhere, e.g. your database:
mysql_select_db($dbHost, $dbUser, $dbPass);
$res = mysql_query("SELECT * FROM news ORDER BY newsdate DESC");
while ($data = mysql_fetch_object($res)) {
    $item = new FeedItem();
    $item->title = $data->title;
    $item->link = $data->url;
    $item->description = $data->short;
    $item->date = $data->newsdate;
    $item->source = "http://www.dailyphp.net";
    $item->author = "John Doe";
     
    $rss->addItem($item);
}

$rss->saveFeed("RSS1.0", "news/feed.xml");
?>


Now, what we need to do is simply integrate such a class into Wikka and create a wrapper method to provide more flexibility and configurability. This will allow us to create on the fly new handlers for specific kind of output and in multiple formats.

How does this sound?



CategoryDevelopmentSyndication
There are 4 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki