Skip to content

Commit

Permalink
rss MDL-24509 added support for 1.9 rss feed requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Davis committed Oct 5, 2010
1 parent 8a73f57 commit c61daed
Showing 1 changed file with 56 additions and 5 deletions.
61 changes: 56 additions & 5 deletions rss/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,58 @@
$token = clean_param($args[1], PARAM_ALPHANUM);
$componentname = clean_param($args[2], PARAM_FILE);

//check if they have requested a 1.9 RSS feed
//if token is an int its a user id (1.9 request)
//if token contains any letters its a token (2.0 request)
$inttoken = intval($token);
if ($token==="$inttoken") {
//they've requested a feed using a 1.9 url. redirect them to the 2.0 url using the guest account

$instanceid = clean_param($args[3], PARAM_INT);

//1.9 URL puts course id where the context id is in 2.0 URLs
$courseid = $contextid;
unset($contextid);

//find the context id
if ($course = $DB->get_record('course', array('id' => $courseid))) {
$modinfo =& get_fast_modinfo($course);

if (!isset($modinfo->instances[$componentname])) {
$modinfo->instances[$componentname] = array();
}

foreach ($modinfo->instances[$componentname] as $modinstanceid=>$cm) {
if ($modinstanceid==$instanceid) {
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
break;
}
}
}

if (empty($context)) {
//this shouldnt happen. something bad is going on.
rss_error('rsserror');
}

//calling isguestuser() just to make sure that $CFG->siteguest is set
isguestuser($token);
$guesttoken = rss_get_token($CFG->siteguest);

// Authenticate the user from the token
$userid = rss_get_userid_from_token($token);
if (!$userid) {
rss_error('rsserrorauth');
//change forum to mod_forum (for example)
$componentname = 'mod_'.$componentname;

$url = $PAGE->url;
$url->set_slashargument("/{$context->id}/$guesttoken/$componentname/$instanceid/rss.xml");

//redirect to the 2.0 rss URL
redirect($url);
} else {
// Authenticate the user from the token
$userid = rss_get_userid_from_token($token);
if (!$userid) {
rss_error('rsserrorauth');
}
}

$user = get_complete_user_data('id', $userid);
Expand All @@ -85,7 +132,11 @@
$preventredirect = true;
require_login($course, $autologinguest, $cm, $setwantsurltome, $preventredirect);
} catch (Exception $e) {
rss_error('rsserrorauth');
if (isguestuser()) {
rss_error('rsserrorguest');
} else {
rss_error('rsserrorauth');
}
}

// Work out which component in Moodle we want (from the frankenstyle name)
Expand Down

0 comments on commit c61daed

Please sign in to comment.