Gena01
|
|
« on: February 24, 2008, 09:14:30 pm » |
|
I have updated and fixed up the RSS feeds for my website. There's actually two feeds: blog and news. Blog feed is built on the core SMF functionality. Recently while testing some things I noticed that my blog feed was showing last number of posts and not the threads that were posted on the blog board. It seems that SMF has quite a few options for generating XML feeds.
You can see the options documented here: http://www.simplemachines.org/community/index.php?topic=25009.0
The only thing missing (so far) is a way to generate an RSS feed based on the tags, but I already got an idea of how to put it together.
The news feed was something that I coded by hand and is based on the scripts that i've used and rewritten a number of times for my website. The back-end is stored in an XML file and over the years i've used different tricks to parse the news items. One of my last experiments was using XSL files to do the transformation. One problem I ran into was the fact that my news feed was missing date/time information when the articles were posted. Apparently I was using a different date format than the one that RSS uses. After a few minutes of considering my options I rewrote the whole thing in PHP using 5.x XML functionality.
The script in PHP was amazing and quite simple. I parse the file using SimpleXML and then convert the date using PHPs date function. The date conversion was probably the simplest of them all: date(DATE_RSS, strtotime($date));
So kudos to PHP core developers for creating a nice and simple way of generating RSS feeds in a couple of lines of PHP code.
P.S. One small gotcha with generating XML feeds and having short tags enabled is a way to get this to play nice with the PHP parser. One trick I pulled out of PHP documentation/manual is to print "<?xml".. inside PHP.
Gena01
|