From: danstowell Date: Fri, 17 Mar 2006 07:44:22 +0000 (+0000) Subject: Fixes to rsslib to ensure the output is valid RSS 2.0 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=95a86f752b283d67bffc1848ec6f2c5948642e20;p=moodle.git Fixes to rsslib to ensure the output is valid RSS 2.0 --- diff --git a/lib/rsslib.php b/lib/rsslib.php index 531203e2aa..8143aabd99 100644 --- a/lib/rsslib.php +++ b/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 .= '' . utf8_encode(htmlspecialchars($item->link)) . ''; + $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 .= " "; //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\n"; + } + } + if (!preg_match_all($medialinkpattern, $rss_text, $matches)){ return $returnstring; } diff --git a/mod/forum/rsslib.php b/mod/forum/rsslib.php index cc90b4e514..7d8de62cef 100644 --- a/mod/forum/rsslib.php +++ b/mod/forum/rsslib.php @@ -269,12 +269,14 @@ 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; } }