Skip to content

Commit

Permalink
Merge branch 'wip-MDL-32199-MOODLE_22_STABLE' of git://github.com/abg…
Browse files Browse the repository at this point in the history
…reeve/moodle into MOODLE_22_STABLE
  • Loading branch information
danpoltawski committed May 28, 2012
2 parents c9ab847 + 35124c3 commit 0e55d4a
Showing 1 changed file with 46 additions and 15 deletions.
61 changes: 46 additions & 15 deletions mod/forum/rsslib.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* @return string the full path to the cached RSS feed directory. Null if there is a problem. * @return string the full path to the cached RSS feed directory. Null if there is a problem.
*/ */
function forum_rss_get_feed($context, $args) { function forum_rss_get_feed($context, $args) {
global $CFG, $DB; global $CFG, $DB, $USER;


$status = true; $status = true;


Expand All @@ -45,7 +45,7 @@ function forum_rss_get_feed($context, $args) {


$forumid = clean_param($args[3], PARAM_INT); $forumid = clean_param($args[3], PARAM_INT);
$cm = get_coursemodule_from_instance('forum', $forumid, 0, false, MUST_EXIST); $cm = get_coursemodule_from_instance('forum', $forumid, 0, false, MUST_EXIST);
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); $modcontext = context_module::instance($cm->id);


//context id from db should match the submitted one //context id from db should match the submitted one
if ($context->id != $modcontext->id || !has_capability('mod/forum:viewdiscussion', $modcontext)) { if ($context->id != $modcontext->id || !has_capability('mod/forum:viewdiscussion', $modcontext)) {
Expand All @@ -60,8 +60,15 @@ function forum_rss_get_feed($context, $args) {
//the sql that will retreive the data for the feed and be hashed to get the cache filename //the sql that will retreive the data for the feed and be hashed to get the cache filename
$sql = forum_rss_get_sql($forum, $cm); $sql = forum_rss_get_sql($forum, $cm);


//hash the sql to get the cache file name // Hash the sql to get the cache file name.
$filename = rss_get_file_name($forum, $sql); // If the forum is Q and A then we need to cache the files per user. This can
// have a large impact on performance, so we want to only do it on this type of forum.
if ($forum->type == 'qanda') {
$filename = rss_get_file_name($forum, $sql . $USER->id);
} else {
$filename = rss_get_file_name($forum, $sql);
}

$cachedfilepath = rss_get_file_full_name('mod_forum', $filename); $cachedfilepath = rss_get_file_full_name('mod_forum', $filename);


//Is the cache out of date? //Is the cache out of date?
Expand Down Expand Up @@ -138,7 +145,7 @@ function forum_rss_feed_discussions_sql($forum, $cm, $newsince=0) {
$now = round(time(), -2); $now = round(time(), -2);
$params = array($cm->instance); $params = array($cm->instance);


$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); $modcontext = context_module::instance($cm->id);


if (!empty($CFG->forum_enabletimedposts)) { /// Users must fulfill timed posts if (!empty($CFG->forum_enabletimedposts)) { /// Users must fulfill timed posts
if (!has_capability('mod/forum:viewhiddentimedposts', $modcontext)) { if (!has_capability('mod/forum:viewhiddentimedposts', $modcontext)) {
Expand Down Expand Up @@ -184,7 +191,7 @@ function forum_rss_feed_discussions_sql($forum, $cm, $newsince=0) {
} }


function forum_rss_feed_posts_sql($forum, $cm, $newsince=0) { function forum_rss_feed_posts_sql($forum, $cm, $newsince=0) {
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); $modcontext = context_module::instance($cm->id);


//get group enforcement SQL //get group enforcement SQL
$groupmode = groups_get_activity_groupmode($cm); $groupmode = groups_get_activity_groupmode($cm);
Expand Down Expand Up @@ -262,7 +269,7 @@ function forum_rss_get_group_sql($cm, $groupmode, $currentgroup, $modcontext=nul
* @return bool|string false if the contents is empty, otherwise the contents of the feed is returned * @return bool|string false if the contents is empty, otherwise the contents of the feed is returned
*/ */
function forum_rss_feed_contents($forum, $sql, $context) { function forum_rss_feed_contents($forum, $sql, $context) {
global $CFG, $DB; global $CFG, $DB, $USER;


$status = true; $status = true;


Expand All @@ -276,18 +283,43 @@ function forum_rss_feed_contents($forum, $sql, $context) {
$isdiscussion = false; $isdiscussion = false;
} }


if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $forum->course)) {
print_error('invalidcoursemodule');
}
$context = context_module::instance($cm->id);

$formatoptions = new stdClass(); $formatoptions = new stdClass();
$items = array(); $items = array();
foreach ($recs as $rec) { foreach ($recs as $rec) {
$item = new stdClass(); $item = new stdClass();
$user = new stdClass(); $user = new stdClass();
if ($isdiscussion && !empty($rec->discussionname)) {
$item->title = format_string($rec->discussionname); if ($isdiscussion && !forum_user_can_see_discussion($forum, $rec->discussionid, $context)) {
} else if (!empty($rec->postsubject)) { // This is a discussion which the user has no permission to view
$item->title = format_string($rec->postsubject); $item->title = get_string('forumsubjecthidden', 'forum');
$message = get_string('forumbodyhidden', 'forum');
$item->author = get_string('forumauthorhidden', 'forum');
} else if (!$isdiscussion && !forum_user_can_see_post($forum, $rec->discussionid, $rec->postid, $USER, $cm)) {
// This is a post which the user has no permission to view
$item->title = get_string('forumsubjecthidden', 'forum');
$message = get_string('forumbodyhidden', 'forum');
$item->author = get_string('forumauthorhidden', 'forum');
} else { } else {
//we should have an item title by now but if we dont somehow then substitute something somewhat meaningful // The user must have permission to view
$item->title = format_string($forum->name.' '.userdate($rec->postcreated,get_string('strftimedatetimeshort', 'langconfig'))); if ($isdiscussion && !empty($rec->discussionname)) {
$item->title = format_string($rec->discussionname);
} else if (!empty($rec->postsubject)) {
$item->title = format_string($rec->postsubject);
} else {
//we should have an item title by now but if we dont somehow then substitute something somewhat meaningful
$item->title = format_string($forum->name.' '.userdate($rec->postcreated,get_string('strftimedatetimeshort', 'langconfig')));
}
$user->firstname = $rec->userfirstname;
$user->lastname = $rec->userlastname;
$item->author = fullname($user);
$message = file_rewrite_pluginfile_urls($rec->postmessage, 'pluginfile.php', $context->id,
'mod_forum', 'post', $rec->postid);
$formatoptions->trusted = $rec->posttrust;
} }
$user->firstname = $rec->userfirstname; $user->firstname = $rec->userfirstname;
$user->lastname = $rec->userlastname; $user->lastname = $rec->userlastname;
Expand All @@ -300,8 +332,6 @@ function forum_rss_feed_contents($forum, $sql, $context) {
} }


$formatoptions->trusted = $rec->posttrust; $formatoptions->trusted = $rec->posttrust;
$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); $item->description = format_text($message, $rec->postformat, $formatoptions, $forum->course);


//TODO: implement post attachment handling //TODO: implement post attachment handling
Expand All @@ -313,6 +343,7 @@ function forum_rss_feed_contents($forum, $sql, $context) {
$item->attachments = array(); $item->attachments = array();
} }
}*/ }*/
$item->pubdate = $rec->postcreated;


$items[] = $item; $items[] = $item;
} }
Expand Down

0 comments on commit 0e55d4a

Please sign in to comment.