BellaBook3.3 RSS 2.0 Feed

23 comments

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.

Jem Turner jem@jemjabella.co.uk +44(0)7521056376

23 comments so far

  1. Amelie said:
    On January 9, 2007 at 9:42 pm

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

  2. Amelie said:
    On January 9, 2007 at 9:43 pm

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

  3. Jem said:
    On January 9, 2007 at 9:47 pm

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

  4. Amelie said:
    On January 9, 2007 at 10:15 pm

    Waaaah :(

  5. Grant Mc said:
    On January 9, 2007 at 10:54 pm

    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.

  6. Sam said:
    On January 9, 2007 at 11:21 pm

    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”

  7. Adam said:
    On January 10, 2007 at 12:14 am

    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.

  8. Hillarie said:
    On January 10, 2007 at 12:16 am

    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).

  9. Jem said:
    On January 10, 2007 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

  10. Jem said:
    On January 10, 2007 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.

  11. Dave said:
    On January 10, 2007 at 9:32 am

    “$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).

  12. Dave said:
    On January 10, 2007 at 9:34 am

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

  13. Jem said:
    On January 10, 2007 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! ;)

  14. Dave said:
    On January 10, 2007 at 10:05 am

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

  15. Jem said:
    On January 10, 2007 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

  16. Dave said:
    On January 10, 2007 at 11:03 am

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

  17. Stephanie said:
    On January 10, 2007 at 7:56 pm

    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!

  18. Sam said:
    On January 10, 2007 at 9:32 pm

    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. ;)

  19. Jem said:
    On January 10, 2007 at 9:33 pm

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

  20. Stephen said:
    On January 10, 2007 at 10:12 pm

    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?

  21. Jem said:
    On January 10, 2007 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

  22. Katie said:
    On January 11, 2007 at 5:14 am

    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.

  23. Six said:
    On January 12, 2007 at 6:50 pm

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