08/01/07

Permalink 11:21:55 pm, by robertc Email , 444 words, 4402 views   English (UK)
Categories: Web Develop, Server Side Web Development Share on reddit Share on digg Share on del.icio.us Share on ma.gnolia.com Share on StumbleUpon

Adding discoverable RSS feeds to phpBBPlus

Last week I added RSS feeds to a forum I help manage. It wasn't too difficult, or even that original, but I thought I'd document it here in case I have to do it again :)

First step is to get an RSS feed set up. I used the naklon.info mod - it's self contained but integrates well, enforcing HTTP authentication for accessing private forums. The key thing about this mod is it allows you to generate forum specific and topic specific feeds by adding the f=x and topic=x parameters to the URL.

OK, so to make your RSS feeds discoverable you need to add a link element in the <head> element of the page. Here's the one from this blog, which you can see by viewing the source code:

<link rel="alternate" type="text/xml" title="RSS 2.0" href="http://www.boogdesign.com/b2evo/index.php?tempskin=_rss2" />

PhpBBPlus already has a mechanism for adding link elements - it's to add buttons to the 'Mozilla navigation bar' - so I'm just going to subvert that mechanism. First up, the file which actually builds the links is includes/page_header.php - the standard link template doesn't include the type attribute we need. Rather than risking breaking the existing template, I just added a new one. After:

$nav_link_proto = '<link rel="%s" href="%s" title="%s" />' . "\n";

I added:

$rss_link_proto = '<link rel="%s" type="application/rss+xml" href="http://www.lanarchy.co.uk/%s" title="%s" />' . "\n";

Then further down I modified the code to check the link type:

if ($nav_item == 'alternate') {
$nav_links_html .= sprintf($rss_link_proto, $nav_item, append_sid($nav_array['url']), $nav_array['title']);
} else {
$nav_links_html .= sprintf($nav_link_proto, $nav_item, append_sid($nav_array['url']), $nav_array['title']);
}

Next I modified the viewforum.php and viewtopic.php files to add in the links. In viewforum.php, I found the 'Mozilla navigation bar' section and appended the following:

$view_forum_rss = append_sid("rss.$phpEx?" . POST_FORUM_URL . "=$forum_id");
$nav_links['alternate'] = array(
'url' => $view_forum_rss,
'title' => 'RSS 2.0'
);

Then in viewtopic.php, again in the 'Mozilla navigation bar' section (it's marked by a comment), I added the same bit of code. Note that this means both the forums and the topics will present a feed for the forum. I preferred it this way as some of the topics aren't going to have that many updates and I figured the forum feed would be more generally useful, but it would be semantically more correct to change the viewtopic.php URL to use the topic parameter.

Trackback address for this post:

http://www.boogdesign.com/b2evo/th1srv/trackback.php/159

Comments, Trackbacks, Pingbacks:

No Comments/Trackbacks/Pingbacks for this post yet...

Leave a comment:

Your email address will not be displayed on this site.
Your URL will be displayed.

Allowed XHTML tags: <p, ul, ol, li, dl, dt, dd, address, blockquote, ins, del, span, bdo, br, em, strong, dfn, code, samp, kdb, var, cite, abbr, acronym, q, sub, sup, tt, i, b, big, small>
(Line breaks become <br />)
(Set cookies for name, email and url)
(Allow users to contact you through a message form (your email will NOT be displayed.))

Hot Topics

Popular

boogdesign posts

Longer posts on standards based web design, portable web development and Linux, intermingled with some stuff on my other nerd interests.

Search

Syndicate this blog XML

  • RSS 0.92 Posts RSS 0.92 Comments
  • RSS 1.0 Posts RSS 1.0 Comments
  • RSS 2.0 Posts RSS 2.0 Comments
  • Atom Posts Atom Comments
What is RSS?

License info

Creative Commons License
This work is licensed under a Creative Commons Attribution-Share Alike 2.5 License.

powered by
b2evolution

get hCard