Wikka : RSSHandler

HomePage :: Categories :: Index :: Changes :: Comments :: Documentation :: Blog :: Login/Register

A single class for RSS feed generation


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

RSS as input

See also:
As for 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).

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 that we can adapt 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: http://feedcreator.org/

Here's the feature list reported from its website:

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

Features:

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 kinds of output and in multiple formats. The number and choice of formats to be displayed might be determined by Wiki Admins in the system configuration.

Test implementation: a new feed.xml.php handler

This is a replacement for the current recentchanges feed.

Installation and setup
Download the FeedCreator class. Unzip the package and save the class in a comfortable location, e.g. 3rdparty/plugins/feedcreator/feedcreator.class.php.
Add the following line to wikka.config.php, immediately before the GeSHi related entries:
	"feedcreator_path" => "3rdparty/plugins/feedcreator",

Usage
Append /feed.xml or /feed.xml?f=FORMAT (/feed.xml&f=FORMAT if mod_rewrite is disabled) to a page URL, where FORMAT can be any of the following: RSS0.91, RSS1.0, RSS2.0, ATOM1.0. If no format or an unknown format is specified, then RSS2.0 is used.

Validation
Changelog
To do
The code
Save the following code as handlers/page/feed.xml.php

  1. <?php
  2. /**
  3. * Creates a feed with recently changed pages
  4. *
  5. * This handler generates a list of recently changed pages on the current server. The output
  6. * format can be specified in the URL.
  7. *
  8. * @package� � � � Handlers
  9. * @name� � � � recentchanges.xml
  10. *
  11. * @author� � � � {@link http://wikka.jsnx.com/DarTar Dario Taraborelli}
  12. * @version� � � � 0.3.1
  13. * @access� � public
  14. * @since� � wikka 1.1.X.X
  15. * @uses� � wakka::config
  16. * @uses� � FeedCreator (1.7.2-ppt)
  17. * @todo� � - move defaults to wiki configuration files
  18. *
  19. * @input� � string� � $f� � optional: output format, can be any of the following:
  20. * � � � � � � � � RSS0.91, RSS1.0, RSS2.0, ATOM1.0
  21. *� � � � � � � � default: RSS2.0
  22. *� � � � � � � � the default format can be overridden by providing a URL parameter 'f'.
  23. * @output� � feed for recently changed pages in the specified format.
  24. */
  25. //defaults
  26. define('VALID_FORMATS', "RSS0.91,RSS1.0,RSS2.0,ATOM1.0");
  27. define('DEFAULT_OUTPUT_FORMAT',"RSS2.0");
  28. define('DESCRIPTION_TRUNCATE_SIZE',"500"); #character limit to truncate description
  29. define('DESCRIPTION_HTML_SYNDICATE',"TRUE"); #Indicates whether the description field should be rendered in HTML
  30. //stylesheets & images
  31. define('FEED_CSS',"http://wikka.jsnx.com/css/xml.css");
  32. define('IMAGE_URL',"http://wikka.jsnx.com/images/wikka_logo.jpg");
  33. //i18n strings
  34. define('FEED_TITLE',"%s - recently changed pages");
  35. define('FEED_DESCRIPTION',"New and recently changed pages from %s");
  36. define('IMAGE_TITLE',"Wikka logo");
  37. define('IMAGE_DESCRIPTION',"Feed provided by Wikka");
  38. //initialize variables
  39. $f = '';
  40. //get URL parameters
  41. $formats = explode(",",VALID_FORMATS);
  42. $f = (in_array($_GET['f'], $formats))? $_GET['f'] : DEFAULT_OUTPUT_FORMAT;
  43. //create objects
  44. include_once($this->config['feedcreator_path'].'/feedcreator.class.php');
  45. $rss = new UniversalFeedCreator();
  46. $rss->useCached(); #make this configurable
  47. $rss->title = sprintf(FEED_TITLE, $this->GetConfigValue("wakka_name"));
  48. $rss->description = sprintf(FEED_DESCRIPTION, $this->GetConfigValue("wakka_name"));
  49. $rss->cssStyleSheet = FEED_CSS;
  50. $rss->descriptionTruncSize = DESCRIPTION_TRUNCATE_SIZE;
  51. $rss->descriptionHtmlSyndicated = DESCRIPTION_HTML_SYNDICATE;
  52. $rss->link = $this->GetConfigValue("base_url").$this->GetConfigValue("root_page");
  53. $rss->syndicationURL = $this->Href($this->method,'','f='.$f);
  54. //feed image
  55. $image = new FeedImage();
  56. $image->title = IMAGE_TITLE;
  57. $image->url = IMAGE_URL;
  58. $image->link = $this->GetConfigValue("base_url").$this->GetConfigValue("root_page");
  59. $image->description = IMAGE_DESCRIPTION;
  60. $image->descriptionTruncSize =� DESCRIPTION_TRUNCATE_SIZE;
  61. $image->descriptionHtmlSyndicated = DESCRIPTION_HTML_SYNDICATE;
  62. $rss->image = $image;
  63. //get feed items
  64. if ($pages = $this->LoadRecentlyChanged())
  65. {
  66. � � $max = $this->GetConfigValue("xml_recent_changes");
  67. � � $c = 0;
  68. � � foreach ($pages as $page)
  69. � � {
  70. � � � � $c++;
  71. � � � � if (($c <= $max) || !$max)
  72. � � � � {
  73. � � � � � � $item = new FeedItem();
  74. � � � � � � $item->title = $this->GetConfigValue("wakka_name").' - '.$page['tag'];
  75. � � � � � � $item->link = $this->Href("show", $page["tag"], "time=".urlencode($page["time"]));
  76. � � � � � � $item->description = ($page['note'] ? ' - '.$page['note'] : '');
  77. � � � � � � $item->date = date('r',strtotime($page['time']));
  78. � � � � � � $item->source = $this->GetConfigValue("base_url");
  79. � � � � � � if (($f == 'ATOM1.0' || $f == 'RSS1.0') && $this->LoadUser($page['user']))
  80. � � � � � � {
  81. � � � � � � � � $item->author = $page['user']; # RSS0.91 and RSS2.0 require authorEmail
  82. � � � � � � }
  83. � � � � � � $rss->addItem($item);
  84. � � � � }
  85. � � }
  86. }
  87. //print feed
  88. echo $rss->createFeed($f);
  89. ?>




Feedback welcome


CategoryDevelopmentSyndication
There are 4 comments on this page. [Display comments]
Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki
Page was generated in 0.2316 seconds