UsingRSSFeed

Note: The recipes here are for PmWiki versions 0.6 and 1.0 only. For PmWiki 2.0 recipes, see Cookbook.


To create a new cookbook entry, fill in or remove the sections below.

Goal

Adding a RSS feed to your page.
Use the rss feed from another site, or your own, to be displayed on your wiki. For example to include the most recent changes. (That could also be done with a (:include Main/RecentChanges:) [1], but when using a parser you can easily change the look, or display only the top 10 changes.)

Solution

An RSS parser like Magpie will do all the work for you, only thing left is to display it nicely.

Your host must allow outgoing http requests.

Installation:

  • Download the latest magpieRSS version from the Magpie site. You need the following files installed:
    • YOURWIKIHOME/local/magpie/rss_cache.inc
    • YOURWIKIHOME/local/magpie/rss_fetch.inc
    • YOURWIKIHOME/local/magpie/rss_parse.inc
    • YOURWIKIHOME/local/magpie/rss_utils.inc
    • YOURWIKIHOME/local/magpie/extlib/Snoopy.class.inc
  • Create a cache to avoid having the rss feed fetched a zillion times a day. You can configure the expire time.
    • YOURWIKIHOME/cache
  • Ensure the cache is writable to the web-server
  • You can change the locations to whatever you like, the script assumes the ones above
  • Download the script in a file rssdisplay.php, or whatever you like.
  • add that file (include_once('local/rssdisplay.php')) to your local.php
  • Attach:rssdisplay_1.14.php (magpie 0.61)
  • Attach:rssdisplay_1.4.php (for Pmwiki 0.5.27)
  • Attach:rssdisplay_1.2.php (for older versions)

Usage

  • [[$RSS http://rss.link<,how><,number_of_items>]]

Possible how options:

  • short
  • long

Defaults

  • how: short
  • number_of_items: 10

To display the items in a simple list with a max of ten items:

  • [[$RSS http://rss.link]]

To display a long format and a max of 5 items use:

  • [[$RSS http://rss.link,long,5]]

IMPORTANT

Please be aware that the rss parser of pmwiki processes DoubleBrackets directives. This might result in an endless recursion. (Well endless until the server and probably you as well get killed). The script takes care of this, just in case you develop your own.

Example

History

2004-01-101.0Initial version.
2004-01-121.2Added more ways to display the feed.
2004-01-121.4Using new Keep function
Added <ul> to meet xhtml validation
2004-05-161.14Magpie 0.61 basic atom support

Comments & Bugs

-NilsKnappmeier-

It didn't work nicely for me for the following reasons:

  1. My host only runs PHP 4.1.x, but magpie needs the function array_change_key_case which is only in PHP 4.2.x and above. Solution: Include Attach:change_key_case.php.txt into your config.php before you include rssdisplay.php
  2. For some reason, magpie hangs during the fetching operation. The patch I made is so small, that I will just put it here:

magpierss-0.61/extlib/Snoopy.class.inc
536,537c536
< while ( !feof($fp)) {
< $data = fread($fp, $this->maxlength);
---
> while ( $data = fread($fp, $this->maxlength) ) {

Now, everthing works for me (except that there seems to be a newline missing at the end of each line in short mode.

-carlo-

Thanks for the rssdisplay.php script, it works nicely! In my setup I changed the original script slightly, to show also the <description> RSS element if available, and to open news links in a new window. You may want to do the same in your script, as I think they are both sensible behaviours. Just my 2 cent.

-R.Joe-

Carlo - can you add an example of how you changed the code? Thanks! The script works very for me.

-bram-

I changed the script and the syntax a bit to allow several display methods

-Gregory-
Bug: Some links can't be used to include an RSS feed, for example:

http://www.wired.com/news/feeds/rss2/0,2610,,00.xml
The comas are not accepted.

-Ari-

Thank you for this, it works great! Two things I changed though - when printing out headlines with <h3></h3>, the <br> at the end is extraneous and just ends up putting an extra line, so I got rid of it. Also, the output gets screwed up when some of the items have a description, but not all. To fix it, I added $description=""; before line 120.

I was not able to get this to work. I downloaded everything as said. It's trying to turn my rss link into a new wiki page. it has the ? after part of the link. Is there some formatting that the .php script is supposed to correct?

Contributors

pmwiki-2.3.32 -- Last modified by {{Nature}}?

from IP: 68.231.69.235 ip should be disabled by default for security reasons