2 //This file returns the required rss feeds
3 //The URL format MUST include:
4 // context: the context id
6 // name: the name of the module (forum...)
7 // id: the id (instance) of the module (forumid...)
8 //If the course has a password or it doesn't
9 //allow guest access then the user field is
10 //required to see that the user is enrolled
11 //in the course, else no check is performed.
12 //This allows to limit a bit the rss access
13 //to correct users. It isn't unbreakable,
14 //obviously, but its the best I've thought!!
16 // disable moodle specific debug messages and any errors in output
17 define('NO_DEBUG_DISPLAY', true);//comment this out to see any error messages during RSS generation
19 // session not used here
20 define('NO_MOODLE_COOKIES', true);
22 require_once('../config.php');
23 require_once($CFG->libdir.'/filelib.php');
24 require_once($CFG->libdir.'/rsslib.php');
26 //Check RSS feeds are enabled
27 if (empty($CFG->enablerssfeeds)) {
28 debugging('DISABLED (admin variables)');
32 $lifetime = 3600; // Seconds for files to remain in browser caches - 1 hour
33 $filename = 'rss.xml';
35 // this is a big one big hack - NO_MOODLE_COOKIES is not compatible with capabilities MDL-7243
36 // it should be replaced once we get to codes in urls
38 $relativepath = get_file_argument();
43 // extract relative path components
44 $args = explode('/', trim($relativepath, '/'));
45 if (count($args) < 5) {
49 $contextid = (int)$args[0];
51 $componentname = clean_param($args[2], PARAM_FILE);
52 //$instance = $args[3];
54 $userid = rss_get_userid_from_token($token);
56 rss_not_authenticated();
58 $user = get_complete_user_data('id', $userid);
59 session_set_user($user); //for login and capability checks
61 $context = get_context_instance_by_id($contextid);
65 $PAGE->set_context($context);
67 $componentdir = get_component_directory($componentname);
68 list($type, $plugin) = normalize_component($componentname);
70 //this will store the path to the cached rss feed contents
73 if (file_exists($componentdir)) {
74 require_once("$componentdir/rsslib.php");
75 $functionname = $plugin.'_rss_get_feed';
77 if (function_exists($functionname)) {
78 //$pathname will be null if there was a problem or the user doesn't have the necessary capabilities
79 //NOTE the component providing the feed should do its own capability checks
80 $pathname = $functionname($context, $args);
84 //Check that file exists
85 if (empty($pathname) || !file_exists($pathname)) {
90 send_file($pathname, $filename, $lifetime);
92 function rss_not_found() {
93 /// error, send some XML with error message
94 global $lifetime, $filename;
95 send_file(rss_geterrorxmlfile(), $filename, $lifetime, false, true);
99 function rss_not_authenticated() {
100 global $lifetime, $filename;
101 send_file(rss_geterrorxmlfile('rsserrorauth'), $filename, $lifetime, false, true);