BellaBook3.3 RSS 2.0 Feed

Six — via the fanlistings message board — was talking about her script wishlist for 2007 and mentioned a guestbook with RSS 2.0 capabilities. Not one to miss the opportunity to gain a potential user, I offered to knock something up for BellaBook.

The results, which work with version 3.3 are as follows (save it as feed.php in your guestbook directory):

<?php
require_once('config.php');
header('Content-type: text/xml');
echo '<?xml version="1.0" encoding="utf-8"?>'; ?>
	<rss version="2.0">
		<channel>
			<title><?php echo $title; ?></title>
			<link><?php echo $admin_url; ?></link>
			<description><?php echo $admin_sitename; ?>'s guestbook feed</description>
			<language>en-gb</language>
<?php
			$blah = file($entriesfile);
			$i = 0;
			$limit = (count($blah) > 10) ? 10 : count($blah);
			while ($i<$limit){
				list($name,$email,$url,$date,$ip,$message) = preg_split("/,(?! )/",$blah[$i]);

				$date = date("D, d M Y H:i:s T", strtotime($date));
				$message = stripslashes($message);
				$message = trim($message, ""x00..x1F");
		
				echo "<item>n";
					echo "<title>guestbook entry</title>\n";
					echo "<link>$admin_url</link>\n";
					echo "<pubDate>$date</pubDate>\n";
					echo "<description><![CDATA[$message]]></description>\n";
				echo "</item>\n";
				$i++;
			}
?>
		</channel>
	</rss>

I’m not entirely sure of its use, but who am I to question a request? Anyway, it is there and it works.

At the moment it is limited though; because there is current no individual entry ‘access’ there is no <guid>. Some feed readers don’t like this, and will re-display the entire feed each time it is updated. I will fix this with a new release of BBook, along with new spam-blocking measures some time this month.

23 Comments

  1. *Ahem* I wrote a feed for BB a long time ago. /gloat

  2. Oh, and mine does have a GUID! :P *Raspyrasp*

  3. Jem

    09 Jan at 9:47 pm

    Piss off Amelie :P Your BB is that modded it’s hardly even BB anymore!

  4. Thanks jem, i have finally decided on my new years resolution a bit late i know, and it is do develop a fully working script.

  5. ps. to someone who considers herself a grammar whore, it’s is a contraction for “it is” while its is possessive. “I’m not entirely sure of it’s use”

  6. That is actually a pretty useful feature to have for a webmaster who doesn’t want to check the guestbook manually for comments. Using a WordPress guestbook myself, I have the option of RSS or emailing of comments — I choose the emailing.

  7. I haven’t installed BellaBook on my site yet…DON’T HIT ME, DON’T HIT ME! I have BellaBuffs on one of my random sites, but no one ever goes there (even I don’t…it’s that painful to the eyes).

  8. Jem

    10 Jan at 9:03 am

    ps. to someone who considers herself a grammar whore, it’s is a contraction for “it is” while its is possessive. “I’m not entirely sure of it’s use” I do believe they’re called “typos” :P

  9. Jem

    10 Jan at 9:05 am

    That is actually a pretty useful feature to have for a webmaster who doesn’t want to check the guestbook manually for comments. This is why BellaBook has an ‘e-mail admin’ feature.

  10. “$blah”, “$blah”. Jeeze spot the shoddy programmer!!! ;) Maybe consider having “feed.xml” re-written to feed.php – people just recognise xml more with rss I think? There’s no reason why the GUID can’t be the post ID or the url (can you can then use isPermalink=”true” on the element if you do that? I haven’t been near RSS for a while).

  11. Sorry not the post ID the entry ID – assuming you have have guestbook.php#345454 or “whatever”…

  12. Jem

    10 Jan at 9:53 am

    assuming you have have guestbook.php#345454 or “whatever”… You know what they say about assumptions, dontcha? ;) This was what I was referring to when I said that entries don’t have individual ‘access’ – there is no guestbook.php#blabla (yet). When I do it, it’ll probably have to be guestbook.php#date-time anyway, as it’s flat file with no real primary key like a database would have. guestbook.php#123 would point to a new entry each time it is signed otherwise. Come on, this script was a year old on the 7th with no major coding updates inbetween, give me a break! ;)

  13. Okay, so how do you explain the dodgy variable names,huh? HUH?!

  14. Jem

    10 Jan at 10:09 am

    Sheer laziness. Is that a valid excuse? :P If you think that’s bad, you should see my private code. :X

  15. I just thought it was very unlike you that’s all. Everything’s usually named properly! Laziness is good though :)

  16. I just thought it was very unlike you that’s all. Everything’s usually named properly! Laziness is good though :) I actually think that it’s a lot like you… Sweet!

  17. ps. to someone who considers herself a grammar whore, it’s is a contraction for “it is” while its is possessive. “I’m not entirely sure of it’s use” I do believe they’re called “typos” :P i’m just teasing you.. i thought it was ironic. ;)

  18. Jem

    10 Jan at 9:33 pm

    Irony is wasted on me ;) much like humour in that respect, hehehe.

  19. As an unrelated aside, the fixed-width formatting of your code snippet disappears off the right hand side of my browser (normal text just auto-wraps to the column width), but for some reason I get no horizontal scrollbar. I have to maximise my browser to see all the code. Is this your doing or something twisted with my firefox?

  20. Jem

    10 Jan at 10:14 pm

    What’s your resolution Stephen? Is it possible that you need to F5? The code block isn’t fixed width, but the styling to make it scroll was only recently added so the stylesheet may be cached from a previous visit. Jem

  21. It does that for me as well, Stephen. Granted, I’m using IE *shames self*, but still. I’m using a 1024×768 resolution, and I’ve pressed F5 several times. Hmm.

  22. Jem, thanks so much for whipping this up for me/us! May I admire you? ;)