Permalink
Browse files

MDL-26500 mod/forum: Rewrite pluginfile urls in RSS

  • Loading branch information...
1 parent b1d3043 commit 69065330c4da6553107f6524f17713114c3e94c4 @danpoltawski danpoltawski committed Mar 30, 2012
Showing with 14 additions and 12 deletions.
  1. +14 −12 mod/forum/rsslib.php
View
26 mod/forum/rsslib.php
@@ -45,13 +45,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);
@@ -75,7 +73,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);
}
@@ -172,7 +170,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
@@ -258,10 +256,12 @@ function forum_rss_get_group_sql($cm, $groupmode, $currentgroup, $modcontext=nul
* This function return the XML rss contents about the forum
* It returns false if something is wrong
*
- * @param object $forum
- * @param bool
+ * @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
*/
-function forum_rss_feed_contents($forum, $sql) {
+function forum_rss_feed_contents($forum, $sql, $context) {
global $CFG, $DB;
$status = true;
@@ -300,7 +300,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: implement post attachment handling
/*if (!$isdiscussion) {

0 comments on commit 6906533

Please sign in to comment.