Please Donate: The Leukemia & Lymphoma Society - Scenic Shore 150 Bike Tour [Donate Here]

PHPNuke Feeds for RSS 2.0 and Atom 0.3

September 27th, 2004

RSS for PHPNuke
Last week as I found that Firefox supported RSS feeds as Live Bookmarks. I watch over the a website which uses PHPNuke. I found that the only feed it provided was an older version of the RSS format which Firefox did not support. Granted PHPNuke was a much older version so I upgraded it hoping there would be a better feed, but I found nothing. I then looked for a module which provided new feed formats, but found none, so I had to make my own...

I took the RSS 0.91 version provided in backend.php and created an RSS 2.0 and Atom 0.3 feed. It was easy enough to create my own database query to get the additional information for these more data heavy feeds so it was an easy task.

To verify I had the feed properly formatted in the end I used the Feed Validator website. After I had the initial structure looking correct the validator pointed out a couple of problems. First I needed to correct the date format. And second, there were characters in the custom feed which were not in the ASCII character set.

The date format was easy enough to fix, but in PHP4 I had to do a bit of work. The explanation of the problem shows the dates must use the W3C date format, also known as the ISO 8601 date format. The hard part was getting the timezone right. It appears that in PHP5 the format character 'c' will provide the ISO 8601 according to the documentation. A few lines of code is all that is needed to make this date format.

Next I had the illegal characters in the content of the site news. The actual character encoding specified in the feed is iso-8859-1. Just like is done in backend.php I use the htmlspecialchars function to clean up the string for use in the feed, but it did not clean up these special characters. My short term fix was to simply edit the news stories with the invalid characters and make the feed validator happy. Now it works, but a longer term solution should catch those invalid characters. I do not normally write code with PHP, so there could a useful function to fix the character encoding that I do not know about. I am open to suggestions.

Now that I have the code working I made the content available on the PHPNuke site, but when I reload the main screen in Firefox it does not provide the icon in the lower right to let me create a live bookmark of the feeds. As I expected, I needed to add some meta data to the meta.php document. On line 34 of that document I added the following lines:

echo "<link rel=\"alternate\" type=\"application/rss+xml\"
  title=\"RSS\" href=\"$nukeurl/rss2.php\" />\n";
echo "<link rel=\"alternate\" type=\"application/atom+xml\"
  title=\"Atom\" href=\"$nukeurl/atom.php\" />\n";

And here are the new php documents for the feeds. I would like to get feedback on any improvements. And if you have a PHPNuke website you think I would like, please send me a link. I would like to get your feeds into my live bookmark list.

16 Responses to “PHPNuke Feeds for RSS 2.0 and Atom 0.3”

  1. Roberto Says:

    RSS 2.0 works correctly, good job!

  2. Eexlebots Says:

    Dude you are awesome. Must now update site...

  3. cpteos Says:

    Thanks for this solution. You're awesome.

    I found it by Search_Engine. Have you announced it on phpnuke.org also?

    EO

  4. cpteos Says:

    ooh, E-Mailadresses are posted searchable for spambots.

    Please delete my E-mailadress in the comment before this.

    cpteos

  5. ttrentham Says:

    Cool. This is one of those enhancements along with Trackback that I've been wanting to see in PHPNuke, but haven't had the time to do it myself. I'm using it now as well and will let you know if I run into anything. Thanks!

  6. Rodney Hampton Says:

    I am still using php nuke version 5.0 (I've done some of my own patching to make it more secure). Anyway, all I had to do was change two lines that handled the sql to get both of your scripts to work:

    $result = mysql_query("SELECT s.sid,t.topicname,s.informant,s.title,s.time,s.hometext FROM ".$prefix."_stories s, ".$prefix."_topics t where s.topic = t.topicid ORDER BY sid DESC LIMIT 10");

    while ($row = mysql_fetch_assoc($result)) {

  7. Pepito Grillo Says:

    Thanks very much for sharing this...

  8. bruno Says:

    Merci ...
    pour votre travail
    mon site phpnuke
    fonctionne parfaitement avec le Rss de Safari sous Tiger !!!

  9. John Says:

    Hi , I'm new to working with rss and maybe you can help me. I made this file http://www.libertyunites.us/backendtributes.php that works ok but I can not get the images to show up, I tweeked a mod to offer Prayers for the victims of terror and this war. I wanted people to be able to pull the persons picture from my server as well as a link to read/post a prayer/tribute. If you have any ideas please let me know. Stop on over to LU and take a look. I hope you can help.

    Blessings
    John

    http://www.libertyunites.us

  10. Petasques Says:

    Thanks for the script. To fix the character encoding that you do not know about:

    http://hulan.cz/blog/item/php-script-to-convert-x-html-entities-to-decimal-unicode-representation/category/apache-php

    you'll find the function entity_to_decimal_value($string) that converts the entity to its unicode decimal value

  11. Mehmet Says:

    Excellent. It was a missing point for phpnuke.

    Thank you

  12. JAugusto Says:

    Thanks Brennan. Worked beautifully. I had to change some code because my site is based on Nuke but a lot has been changed, but it worked just fine.

    I also had a big problem getting a sucessfull validation from feedvalidator.org due to 2 blank lines on the top.

    After 1 hour(!) I found it was 2 spaces after the ?> on the language.php file! uff

  13. peter Says:

    You are the man! I had been wanting to update my rss feeds for a while but could never find the time. You've saved me a good deal of effort.

    musicNerve.com

  14. Hans van Eijsden Says:

    Thank you SO much! It fixed my PHPnuke 7.1 and finally, it also works with Google Toolbar. Thanx again dude! :)

  15. Thomas Says:

    Thanks. I'm trying to build PHPNuke support into my Feed Button Maker. :) If you wanna help test, email me.

  16. goggel Says:

    Is there a way of add the whole article into the feed, and hopefully the author and the comments also?. I wan't to use Wordpress for my site instead and at the moment I think RSS is the best way to import it. So far your script works perfect, I'm only missing the main part of the article, author and all the comments