2 //This file returns the required rss feeds
3 //The URL format MUST include:
4 // course: the course 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 $nomoodlecookie = true; // Because it interferes with caching
18 require_once('../config.php');
19 require_once($CFG->libdir.'/filelib.php');
20 require_once($CFG->libdir.'/rsslib.php');
22 $lifetime = 3600; // Seconds for files to remain in caches - 1 hour
24 $relativepath = get_file_argument('file.php');
31 // extract relative path components
32 $args = explode('/', trim($relativepath, '/'));
34 if (count($args) < 5) {
38 $courseid = (int)$args[0];
39 $userid = (int)$args[1];
40 $modulename = clean_param($args[2], PARAM_FILE);
42 $filename = 'rss.xml';
44 if ($isblog = $modulename == 'blog') {
45 $blogid = (int)$args[4]; // could be groupid / courseid / userid depending on $instance
46 if ($args[5] != 'rss.xml') {
47 $tagid = (int)$args[5];
52 $instance = (int)$instance; // we know it's an id number
56 if (!$course = get_record('course', 'id', $courseid)) {
60 //Check name of module
62 $mods = get_list_of_plugins("mod");
63 if (!in_array(strtolower($modulename), $mods)) {
68 //Get course_module to check it's visible
69 if (!$isblog && (!$cm = get_coursemodule_from_instance($modulename,$instance,$courseid)) ) {
73 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
74 $isuser = has_capability('moodle/course:view', $context, $userid);
76 //Check for "security" if !course->guest or course->password
77 if ($course->id != SITEID) {
78 if ((!$course->guest || $course->password) && (!$isuser)) {
83 //Check for "security" if the course is hidden or the activity is hidden
84 if (!$isblog and (!$course->visible || !$cm->visible) && (!has_capability('moodle/course:viewhiddenactivities', $context))) {
88 //Work out the filename of the RSS file
90 require_once($CFG->dirroot.'/blog/rsslib.php');
91 $pathname = blog_generate_rss_feed($instance, $blogid, $tagid);
93 $pathname = $CFG->dataroot.'/rss/'.$modulename.'/'.$instance.'.xml';
96 //Check that file exists
97 if (!file_exists($pathname)) {
102 send_file($pathname, $filename, $lifetime);
104 function rss_not_found() {
105 /// error, send some XML with error message
106 global $lifetime, $filename;
107 send_file(rss_geterrorxmlfile(), $filename, $lifetime, false, true);