naming consistency
[moodle.git] / rss / file.php
CommitLineData
e7f927a0 1<?PHP //$Id$
8adcb49f 2 //This file returns the required rss feeds
3 //The URL format MUST include:
4 // course: the course id
e7f927a0 5 // user: the user id
6 // name: the name of the module (forum...)
7 // id: the id (instance) of the module (forumid...)
8adcb49f 8 //If the course has a password or it doesn't
7fe0ce4e 9 //allow guest access then the user field is
8adcb49f 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!!
15
e7f927a0 16 $nomoodlecookie = true; // Because it interferes with caching
7fe0ce4e 17
e7f927a0 18 require_once('../config.php');
7ade05c5 19 require_once($CFG->libdir.'/filelib.php');
48b29ba4 20 require_once($CFG->libdir.'/rsslib.php');
8adcb49f 21
e7f927a0 22 $lifetime = 3600; // Seconds for files to remain in caches - 1 hour
8adcb49f 23
e7f927a0 24 $relativepath = get_file_argument('file.php');
8adcb49f 25
7fe0ce4e 26
e7f927a0 27 if (!$relativepath) {
28 not_found();
8adcb49f 29 }
30
e7f927a0 31 // extract relative path components
32 $args = explode('/', trim($relativepath, '/'));
7fe0ce4e 33
ab7d76bb 34 $isblog = ($args[0] == 'blog');
7fe0ce4e 35
36 if (count($args) < 5 && !$isblog) {
e7f927a0 37 not_found();
8adcb49f 38 }
39
e7f927a0 40 $courseid = (int)$args[0];
41 $userid = (int)$args[1];
42 $modulename = clean_param($args[2], PARAM_FILE);
43 $instance = (int)$args[3];
c5152930 44 $filename = 'rss.xml';
7fe0ce4e 45
46 if ((!$course = get_record("course", "id", $courseid)) && !$isblog) {
e7f927a0 47 not_found();
8adcb49f 48 }
7fe0ce4e 49
c062fee6 50 //Check name of module
51 $mods = get_list_of_plugins("mod");
7fe0ce4e 52 if (!in_array(strtolower($modulename), $mods) && !$isblog) {
e7f927a0 53 not_found();
8adcb49f 54 }
55
c0f778a2 56 //Get course_module to check it's visible
7fe0ce4e 57 if (!$isblog && (!$cm = get_coursemodule_from_instance($modulename,$instance,$courseid)) ) {
e7f927a0 58 not_found();
c0f778a2 59 }
c0f778a2 60
61 $isstudent = isstudent($courseid,$userid);
62 $isteacher = isteacher($courseid,$userid);
63
8adcb49f 64 //Check for "security" if !course->guest or course->password
56e8032e 65 if ($course->id != SITEID) {
7fe0ce4e 66 if (((!$course->guest || $course->password) && (!($isstudent || $isteacher))) && !$isblog) {
56e8032e 67 not_found();
68 }
c0f778a2 69 }
70
7fe0ce4e 71 //Check for "security" if the course is hidden or the activity is hidden
72 if (((!$course->visible || !$cm->visible) && (!$isteacher)) && !$isblog) {
e7f927a0 73 not_found();
8adcb49f 74 }
75
7fe0ce4e 76 if ($isblog) {
77 $pathname = $CFG->dataroot.'/rss/'.$relativepath;
78 } else {
79 $pathname = $CFG->dataroot.'/rss/'.$modulename.'/'.$instance.'.xml';
80 }
e7f927a0 81 //Check that file exists
82 if (!file_exists($pathname)) {
83 not_found();
8adcb49f 84 }
85
e7f927a0 86 //Send it to user!
87 send_file($pathname, $filename, $lifetime);
88
89 function not_found() {
90 /// error, send some XML with error message
be88433c 91 global $lifetime, $filename;
92 send_file(rss_geterrorxmlfile(), $filename, $lifetime, false, true);
e7f927a0 93 }
8adcb49f 94?>