Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixes to rsslib to ensure the output is valid RSS 2.0

  • Loading branch information...
commit 95a86f752b283d67bffc1848ec6f2c5948642e20 1 parent 516194d
danstowell authored
Showing with 18 additions and 12 deletions.
  1. +13 −9 lib/rsslib.php
  2. +5 −3 mod/forum/rsslib.php
View
22 lib/rsslib.php
@@ -171,10 +171,12 @@ function rss_standard_header($title = NULL, $link = NULL, $description = NULL) {
}
$today = getdate();
$result .= rss_full_tag('copyright', 2, false, '© '. $today['year'] .' '. $site->fullname);
- if (!empty($USER->email)) {
+ /*
+ if (!empty($USER->email)) {
$result .= rss_full_tag('managingEditor', 2, false, fullname($USER));
$result .= rss_full_tag('webMaster', 2, false, fullname($USER));
}
+ */
//write image info
$rsspix = $CFG->pixpath."/i/rsssitelogo.gif";
@@ -217,7 +219,8 @@ function rss_add_items($items) {
}
$result .= rss_full_tag('title',3,false,$item->title);
$result .= rss_full_tag('link',3,false,$item->link);
- $result .= rss_full_tag('pubDate',3,false,date('r',$item->pubdate));
+ $result .= '<guid isPermaLink="true">' . utf8_encode(htmlspecialchars($item->link)) . '</guid>';
+ $result .= rss_full_tag('pubDate',3,false,date('D, d M Y H:i:s T',$item->pubdate));
//Include the author if exists
if (isset($item->author)) {
//$result .= rss_full_tag('author',3,false,$item->author);
@@ -515,13 +518,6 @@ function rss_add_enclosures($item){
$returnstring = '';
$rss_text = $item->description;
- // take into account attachments (e.g. from forum)
- if (isset($item->attachments) && is_array($item->attachments)) {
- foreach ($item->attachments as $attachment){
- $rss_text .= " <a href='$attachment'/>"; //just to make sure the regexp groks it
- }
- }
-
// list of media file extensions and their respective mime types
// could/should we put this to some more central place?
$mediafiletypes = array(
@@ -540,6 +536,14 @@ function rss_add_enclosures($item){
// regular expression (hopefully) matching all links to media files
$medialinkpattern = '@href\s*=\s*(\'|")(\S+(' . implode('|', array_keys($mediafiletypes)) . '))\1@Usie';
+ // take into account attachments (e.g. from forum) - with these, we are able to know the file size
+ if (isset($item->attachments) && is_array($item->attachments)) {
+ foreach ($item->attachments as $attachment){
+ $type = $mediafiletypes[substr($attachment->url, strrpos($attachment->url, '.')+1)];
+ $returnstring .= "\n<enclosure url='$attachment->url' type='$type' length='$attachment->length' />\n";
+ }
+ }
+
if (!preg_match_all($medialinkpattern, $rss_text, $matches)){
return $returnstring;
}
View
8 mod/forum/rsslib.php
@@ -269,12 +269,14 @@ function forum_rss_feed_posts($forum, $newsince=0) {
if (!empty($post_files)) {
$item->attachments = array();
foreach ($post_files as $file) {
+ $attachment = new stdClass;
if ($CFG->slasharguments) {
- $ffurl = "{$CFG->wwwroot}/file.php/$post_file_area_name/$file";
+ $attachment->url = "{$CFG->wwwroot}/file.php/$post_file_area_name/$file";
} else {
- $ffurl = "{$CFG->wwwroot}/file.php?file=/$post_file_area_name/$file";
+ $attachment->url = "{$CFG->wwwroot}/file.php?file=/$post_file_area_name/$file";
}
- $item->attachments[] = $ffurl;
+ $attachment->length = filesize("$CFG->dataroot/$post_file_area_name/$file");
+ $item->attachments[] = $attachment;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.