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.