1
0
mirror of https://github.com/moodle/moodle.git synced 2025-04-17 22:45:54 +02:00

rss MDL-24509 added support for 1.9 rss feed requests

This commit is contained in:
Andrew Davis 2010-10-05 03:30:01 +00:00
parent 8a73f57081
commit c61daed045

@ -61,11 +61,58 @@ $contextid = (int)$args[0];
$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
// Authenticate the user from the token
$userid = rss_get_userid_from_token($token);
if (!$userid) {
rss_error('rsserrorauth');
$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);
//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);
@ -85,7 +132,11 @@ try {
$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)