if (!($guestid = $DB->get_field('user', 'id', array('username' => 'guest', 'mnethostid' => $CFG->mnet_localhost_id)))) { // guest does not exist yet, weird rss_error('rsserror'); } set_config('siteguest', $guestid); } $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'); } } // Check the context actually exists list($context, $course, $cm) = get_context_info_array($contextid); $PAGE->set_context($context); $user = get_complete_user_data('id', $userid); // let enrol plugins deal with new enrolments if necessary enrol_check_plugins($user); \core\session\manager::set_user($user); //for login and capability checks try { $autologinguest = true; $setwantsurltome = true;
/** * This function is the main entry point to pcast * rss feeds generation. * * @global object $CFG * @global object $DB * @param string? $context * @param array $args * @return string (path) */ function pcast_rss_get_feed($context, $args) { global $CFG, $DB; if (empty($CFG->pcast_enablerssfeeds)) { debugging("DISABLED (module configuration)"); return null; } $status = true; $token = clean_param($args[1], PARAM_ALPHANUM); $pcastid = clean_param($args[3], PARAM_INT); $groupid = clean_param($args[4], PARAM_INT); $uservalidated = false; //check capabilities $cm = get_coursemodule_from_instance('pcast', $pcastid, 0, false, MUST_EXIST); if ($cm) { $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/pcast:view', $modcontext)) { $uservalidated = true; } } //get userid from Token $userid = rss_get_userid_from_token($token); //Check group mode 0/1/2 (All participants) $groupmode = groups_get_activity_groupmode($cm); //Using Groups, check to see if user should see all participants if ($groupmode == SEPARATEGROUPS) { //User must have the capability to see all groups or be a member of that group $members = get_enrolled_users($context, 'mod/pcast:write', $groupid, 'u.id', 'u.id ASC'); // Is a member of the current group if (!isset($members[$userid]->id) or $members[$userid]->id != $userid) { // Not a member of the group, can you see all groups (from CAPS) if (!has_capability('moodle/site:accessallgroups', $context, $userid)) { $uservalidated = false; } } else { // Are a member of the current group // Is the group #0 (Group 0 is all users) if ($groupid == 0 and !has_capability('moodle/site:accessallgroups', $context, $userid)) { $uservalidated = false; } } } if (!$uservalidated) { return null; } // OK the user can view the RSS feed $pcast = $DB->get_record('pcast', array('id' => $pcastid), '*', MUST_EXIST); // Check to se if RSS is enabled // NOTE: cannot use the rss_enabled_for_mod() function due to the functions internals and naming conflicts if ($pcast->rssepisodes == 0 || empty($pcast->rssepisodes)) { return null; } $sql = pcast_rss_get_sql($pcast); //get the cache file info $filename = rss_get_file_name($pcast, $sql); //Append the GroupID to the end of the filename $filename .= '_' . $groupid; $cachedfilepath = rss_get_file_full_name('mod_pcast', $filename); //Is the cache out of date? $cachedfilelastmodified = 0; if (file_exists($cachedfilepath)) { $cachedfilelastmodified = filemtime($cachedfilepath); } //if the cache is more than 60 seconds old and there's new stuff $dontrecheckcutoff = time() - 60; if ($dontrecheckcutoff > $cachedfilelastmodified && pcast_rss_newstuff($pcast, $cachedfilelastmodified)) { if (!($recs = $DB->get_records_sql($sql, array(), 0, $pcast->rssepisodes))) { return null; } $items = array(); $formatoptions = new stdClass(); $formatoptions->trusttext = true; foreach ($recs as $rec) { $item = new stdClass(); $user = new stdClass(); $item->title = $rec->episodename; $item->pcastid = $rec->pcastid; $item->id = $rec->episodeid; $item->userid = $rec->userid; $item->course = $rec->course; if ($pcast->displayauthor == 1) { //With author $user->firstname = $rec->userfirstname; $user->lastname = $rec->userlastname; $item->author = fullname($user); } $item->keywords = $rec->keywords; $item->subtitle = $rec->subtitle; $item->duration = $rec->duration; $item->pubdate = $rec->episodetimecreated; $item->link = new moodle_url('/mod/pcast/showepisode.php', array('eid' => $rec->episodeid)); $item->description = format_text($rec->episodesummary, 'HTML', NULL, $pcast->course); // $item->description = strip_tags($rec->episodesummary); if ($pcast->userscancategorize) { //TODO: This is very inefficient (this generates 2 DB queries per entry) $category = pcast_rss_category_lookup($rec); $item->topcategory = $category->top->name; $item->nestedcategory = $category->nested->name; } $items[] = $item; } //First all rss feeds common headers $url = new moodle_url('/mod/pcast/view.php', array('id' => $pcast->id)); $header = pcast_rss_header(format_string($pcast->name, true), $url, format_string($pcast->intro, true), $pcast); // Do we need iTunes tags? if (isset($pcast->enablerssitunes) && $pcast->enablerssitunes == 1) { $itunes = true; } else { $itunes = false; } //Now all the rss items if (!empty($header)) { $episodes = pcast_rss_add_items($context, $items, $itunes, $groupid); } //Now all rss feeds common footers if (!empty($header) && !empty($episodes)) { $footer = pcast_rss_footer(); } //Now, if everything is ok, concatenate it if (!empty($header) && !empty($episodes) && !empty($footer)) { $rss = $header . $episodes . $footer; //Save the XML contents to file. $status = rss_save_file('mod_pcast', $filename, $rss); } } if (!$status) { $cachedfilepath = null; } return $cachedfilepath; }