From af89cdd43bb734820020725e373a6e61477a2d46 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Fri, 30 Mar 2012 16:22:26 +0800 Subject: [PATCH 1/3] MDL-26500 mod/forum: Rewrite pluginfile urls in RSS --- mod/forum/rsslib.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/mod/forum/rsslib.php b/mod/forum/rsslib.php index e5b7809cbed..f1444afd957 100644 --- a/mod/forum/rsslib.php +++ b/mod/forum/rsslib.php @@ -43,13 +43,11 @@ function forum_rss_get_feed($context, $args) { $forumid = clean_param($args[3], PARAM_INT); $cm = get_coursemodule_from_instance('forum', $forumid, 0, false, MUST_EXIST); - if ($cm) { - $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); + $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); - //context id from db should match the submitted one - if ($context->id != $modcontext->id || !has_capability('mod/forum:viewdiscussion', $modcontext)) { - return null; - } + //context id from db should match the submitted one + if ($context->id != $modcontext->id || !has_capability('mod/forum:viewdiscussion', $modcontext)) { + return null; } $forum = $DB->get_record('forum', array('id' => $forumid), '*', MUST_EXIST); @@ -73,7 +71,7 @@ function forum_rss_get_feed($context, $args) { $dontrecheckcutoff = time()-60; if ( $dontrecheckcutoff > $cachedfilelastmodified && forum_rss_newstuff($forum, $cm, $cachedfilelastmodified)) { //need to regenerate the cached version - $result = forum_rss_feed_contents($forum, $sql); + $result = forum_rss_feed_contents($forum, $sql, $modcontext); if (!empty($result)) { $status = rss_save_file('mod_forum',$filename,$result); } @@ -185,7 +183,7 @@ function forum_rss_feed_discussions_sql($forum, $cm, $newsince=0) { } $forumsort = "d.timemodified DESC"; - $postdata = "p.id, p.subject, p.created as postcreated, p.modified, p.discussion, p.userid, p.message as postmessage, p.messageformat AS postformat, p.messagetrust AS posttrust"; + $postdata = "p.id AS postid, p.subject, p.created as postcreated, p.modified, p.discussion, p.userid, p.message as postmessage, p.messageformat AS postformat, p.messagetrust AS posttrust"; $sql = "SELECT $postdata, d.id as discussionid, d.name as discussionname, d.timemodified, d.usermodified, d.groupid, d.timestart, d.timeend, u.firstname as userfirstname, u.lastname as userlastname, u.email, u.picture, u.imagealt @@ -287,11 +285,12 @@ function forum_rss_get_group_sql($cm, $groupmode, $currentgroup, $modcontext=nul * * @param stdClass $forum the forum object * @param string $sql The SQL used to retrieve the contents from the database + * @param object $context the context this forum relates to * @return bool|string false if the contents is empty, otherwise the contents of the feed is returned * * @Todo MDL-31129 implement post attachment handling */ -function forum_rss_feed_contents($forum, $sql) { +function forum_rss_feed_contents($forum, $sql, $context) { global $CFG, $DB; $status = true; @@ -330,7 +329,9 @@ function forum_rss_feed_contents($forum, $sql) { } $formatoptions->trusted = $rec->posttrust; - $item->description = format_text($rec->postmessage,$rec->postformat,$formatoptions,$forum->course); + $message = file_rewrite_pluginfile_urls($rec->postmessage, 'pluginfile.php', $context->id, + 'mod_forum', 'post', $rec->postid); + $item->description = format_text($message, $rec->postformat, $formatoptions, $forum->course); //TODO: MDL-31129 implement post attachment handling /*if (!$isdiscussion) { From 20d1c739ddb144916d1d19ea62a23f89c8571ae5 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Fri, 30 Mar 2012 19:40:45 +0800 Subject: [PATCH 2/3] MDL-26500 mod/glossary: Rewrite pluginfile urls in RSS --- mod/glossary/rsslib.php | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/mod/glossary/rsslib.php b/mod/glossary/rsslib.php index ab5ffee48a8..3966b28eee5 100644 --- a/mod/glossary/rsslib.php +++ b/mod/glossary/rsslib.php @@ -44,17 +44,16 @@ $glossaryid = clean_param($args[3], PARAM_INT); $cm = get_coursemodule_from_instance('glossary', $glossaryid, 0, false, MUST_EXIST); - if ($cm) { - $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); - if ($COURSE->id == $cm->course) { - $course = $COURSE; - } else { - $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST); - } - //context id from db should match the submitted one - if ($context->id != $modcontext->id || !has_capability('mod/glossary:view', $modcontext)) { - return null; - } + $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); + + if ($COURSE->id == $cm->course) { + $course = $COURSE; + } else { + $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST); + } + //context id from db should match the submitted one + if ($context->id != $modcontext->id || !has_capability('mod/glossary:view', $modcontext)) { + return null; } $glossary = $DB->get_record('glossary', array('id' => $glossaryid), '*', MUST_EXIST); @@ -99,7 +98,10 @@ $item->pubdate = $rec->entrytimecreated; $item->link = $CFG->wwwroot."/mod/glossary/showentry.php?courseid=".$glossary->course."&eid=".$rec->entryid; - $item->description = format_text($rec->entrydefinition,$rec->entryformat,$formatoptions,$glossary->course); + + $definition = file_rewrite_pluginfile_urls($rec->entrydefinition, 'pluginfile.php', + $modcontext->id, 'mod_glossary', 'entry', $rec->entryid); + $item->description = format_text($definition, $rec->entryformat, $formatoptions, $glossary->course); $items[] = $item; } From 285665550d3f6b91dd8dfc83bcd770c540b181cb Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Fri, 30 Mar 2012 20:03:10 +0800 Subject: [PATCH 3/3] MDL-26500 blog: Rewrite pluginfile urls in RSS --- blog/rsslib.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/blog/rsslib.php b/blog/rsslib.php index a851cbe25fe..770fb0673dd 100644 --- a/blog/rsslib.php +++ b/blog/rsslib.php @@ -218,7 +218,9 @@ function blog_rss_get_feed($context, $args) { $item->title = $blog_entry->subject; $item->pubdate = $blog_entry->lastmodified; $item->link = $CFG->wwwroot.'/blog/index.php?entryid='.$blog_entry->id; - $item->description = format_text($blog_entry->summary, $blog_entry->format); + $summary = file_rewrite_pluginfile_urls($blog_entry->summary, 'pluginfile.php', + $sitecontext->id, 'blog', 'post', $blog_entry->id); + $item->description = format_text($summary, $blog_entry->format); if ( !empty($CFG->usetags) && ($blogtags = tag_get_tags_array('post', $blog_entry->id)) ) { if ($blogtags) { $item->tags = $blogtags;