Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Work-around for bug in SourceForge blog RSS feeds. This code reads the SF feed, transforms it to fix the bug and emits the revised code as a fresh XML document. Fully described at http://delphidabbler.blogspot.co.uk/2014/02/ive-just-been-setting-up-new-blog-for.html
<?php
/*
Fix for SF RSS feed bug: https://sourceforge.net/p/allura/tickets/6687/
Reads RSS source code from SourceForge and re-renders it, adding an
isPermaLink=false attribute to every <guid> tag.
*/
mb_internal_encoding('UTF-8');
mb_http_output('UTF-8');
mb_language('uni');
mb_regex_encoding('UTF-8');
ob_start('mb_output_handler');
class SFBlogFeedConverter {
private $feedURL; // URL of SourceForge RSS feed
private $rssDOM; // RSS DOM
public function __construct($feedURL) {
$this->rssDOM = new DOMDocument();
$this->feedURL = $feedURL;
}
public function RenderRSS() {
if ( !@$this->rssDOM->Load($this->feedURL)) {
$code = 500;
$desc = 'Internal Server Error';
header("HTTP/1.0 $code $desc");
header("Status: $code $desc");
header('Content-Type: text/html; charset=utf-8');
echo "<!DOCTYPE html>\n"
. "<html>\n"
. "<head>\n"
. "<meta charset=\"utf-8\">\n"
. "<title>$code $desc</title>\n"
. "</head>\n"
. "<body>\n"
. "<h1>$code $desc</h1>\n"
// Replace [PROJECT] below with the required project name
. "<p>Can''t open [PROJECT] blog feed on SourceForge</p>\n"
. "</body>\n"
. "</html>\n";
return;
}
$guidNodes = $this->rssDOM->getElementsByTagName('guid');
foreach ($guidNodes as $guidNode) {
$guidNode->setAttribute('isPermaLink', 'false');
}
header('Content-Type: application/xml; charset=utf-8');
$xml = $this->rssDOM->saveXML();
header('Content-Length: ' . strlen($xml));
echo $xml;
}
}
$blogXML = new SFBlogFeedConverter(
// Replace [PROJECT] below with the required project name
'http://sourceforge.net/p/[PROJECT]/blog/feed'
);
$blogXML->RenderRSS();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment