2004-12-14 18:57:51 +00:00
|
|
|
<?PHP //$Id$
|
2004-05-02 23:08:19 +00:00
|
|
|
//This file returns the required rss feeds
|
|
|
|
//The URL format MUST include:
|
|
|
|
// course: the course id
|
2004-12-14 18:57:51 +00:00
|
|
|
// user: the user id
|
|
|
|
// name: the name of the module (forum...)
|
|
|
|
// id: the id (instance) of the module (forumid...)
|
2004-05-02 23:08:19 +00:00
|
|
|
//If the course has a password or it doesn't
|
2006-03-17 07:37:27 +00:00
|
|
|
//allow guest access then the user field is
|
2004-05-02 23:08:19 +00:00
|
|
|
//required to see that the user is enrolled
|
|
|
|
//in the course, else no check is performed.
|
|
|
|
//This allows to limit a bit the rss access
|
|
|
|
//to correct users. It isn't unbreakable,
|
|
|
|
//obviously, but its the best I've thought!!
|
|
|
|
|
2004-12-14 18:57:51 +00:00
|
|
|
$nomoodlecookie = true; // Because it interferes with caching
|
2006-03-17 07:37:27 +00:00
|
|
|
|
2004-12-14 18:57:51 +00:00
|
|
|
require_once('../config.php');
|
2005-03-07 12:10:22 +00:00
|
|
|
require_once($CFG->libdir.'/filelib.php');
|
2005-01-25 06:09:31 +00:00
|
|
|
require_once($CFG->libdir.'/rsslib.php');
|
2004-05-02 23:08:19 +00:00
|
|
|
|
2004-12-14 18:57:51 +00:00
|
|
|
$lifetime = 3600; // Seconds for files to remain in caches - 1 hour
|
2004-05-02 23:08:19 +00:00
|
|
|
|
2006-09-23 09:38:39 +00:00
|
|
|
// disable moodle specific debug messages
|
|
|
|
disable_debugging();
|
|
|
|
|
2004-12-14 18:57:51 +00:00
|
|
|
$relativepath = get_file_argument('file.php');
|
2004-05-02 23:08:19 +00:00
|
|
|
|
2006-03-17 07:37:27 +00:00
|
|
|
|
2004-12-14 18:57:51 +00:00
|
|
|
if (!$relativepath) {
|
2006-03-17 08:20:28 +00:00
|
|
|
rss_not_found();
|
2004-05-02 23:08:19 +00:00
|
|
|
}
|
|
|
|
|
2004-12-14 18:57:51 +00:00
|
|
|
// extract relative path components
|
|
|
|
$args = explode('/', trim($relativepath, '/'));
|
2006-03-17 07:37:27 +00:00
|
|
|
|
2006-03-17 09:11:06 +00:00
|
|
|
if (count($args) < 5) {
|
2006-03-17 08:20:28 +00:00
|
|
|
rss_not_found();
|
2004-05-02 23:08:19 +00:00
|
|
|
}
|
|
|
|
|
2004-12-14 18:57:51 +00:00
|
|
|
$courseid = (int)$args[0];
|
|
|
|
$userid = (int)$args[1];
|
|
|
|
$modulename = clean_param($args[2], PARAM_FILE);
|
2006-03-17 09:11:06 +00:00
|
|
|
$instance = $args[3];
|
2004-12-15 23:21:25 +00:00
|
|
|
$filename = 'rss.xml';
|
2006-03-17 07:37:27 +00:00
|
|
|
|
2006-03-17 09:11:06 +00:00
|
|
|
if ($isblog = $modulename == 'blog') {
|
|
|
|
$blogid = (int)$args[4]; // could be groupid / courseid / userid depending on $instance
|
|
|
|
if ($args[5] != 'rss.xml') {
|
2006-03-17 09:48:24 +00:00
|
|
|
$tagid = (int)$args[5];
|
|
|
|
} else {
|
|
|
|
$tagid = 0;
|
2006-03-17 09:11:06 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$instance = (int)$instance; // we know it's an id number
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!$course = get_record('course', 'id', $courseid)) {
|
2006-03-17 08:20:28 +00:00
|
|
|
rss_not_found();
|
2004-05-02 23:08:19 +00:00
|
|
|
}
|
2006-03-17 07:37:27 +00:00
|
|
|
|
2004-12-12 12:54:32 +00:00
|
|
|
//Check name of module
|
2006-03-17 09:11:06 +00:00
|
|
|
if (!$isblog) {
|
|
|
|
$mods = get_list_of_plugins("mod");
|
|
|
|
if (!in_array(strtolower($modulename), $mods)) {
|
|
|
|
rss_not_found();
|
|
|
|
}
|
2004-05-02 23:08:19 +00:00
|
|
|
}
|
|
|
|
|
2004-05-09 18:59:36 +00:00
|
|
|
//Get course_module to check it's visible
|
2006-03-17 09:11:06 +00:00
|
|
|
if (!$isblog && (!$cm = get_coursemodule_from_instance($modulename,$instance,$courseid)) ) {
|
2006-03-17 08:20:28 +00:00
|
|
|
rss_not_found();
|
2004-05-09 18:59:36 +00:00
|
|
|
}
|
|
|
|
|
2006-09-06 08:55:23 +00:00
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
|
|
|
$isuser = has_capability('moodle/course:view', $context, $userid);
|
|
|
|
|
2004-05-02 23:08:19 +00:00
|
|
|
//Check for "security" if !course->guest or course->password
|
2005-07-25 09:05:12 +00:00
|
|
|
if ($course->id != SITEID) {
|
2006-09-06 08:55:23 +00:00
|
|
|
if ((!$course->guest || $course->password) && (!$isuser)) {
|
2006-03-17 08:20:28 +00:00
|
|
|
rss_not_found();
|
2005-07-25 09:05:12 +00:00
|
|
|
}
|
2004-05-09 18:59:36 +00:00
|
|
|
}
|
|
|
|
|
2006-03-17 07:37:27 +00:00
|
|
|
//Check for "security" if the course is hidden or the activity is hidden
|
2006-09-06 08:55:23 +00:00
|
|
|
if (!$isblog and (!$course->visible || !$cm->visible) && (!has_capability('moodle/course:viewhiddenactivities', $context))) {
|
2006-03-17 08:20:28 +00:00
|
|
|
rss_not_found();
|
2004-05-02 23:08:19 +00:00
|
|
|
}
|
|
|
|
|
2006-03-17 09:48:24 +00:00
|
|
|
//Work out the filename of the RSS file
|
2006-03-17 07:37:27 +00:00
|
|
|
if ($isblog) {
|
2006-03-17 09:48:24 +00:00
|
|
|
require_once($CFG->dirroot.'/blog/rsslib.php');
|
|
|
|
$pathname = blog_generate_rss_feed($instance, $blogid, $tagid);
|
2006-03-17 07:37:27 +00:00
|
|
|
} else {
|
|
|
|
$pathname = $CFG->dataroot.'/rss/'.$modulename.'/'.$instance.'.xml';
|
|
|
|
}
|
2006-03-17 09:48:24 +00:00
|
|
|
|
2004-12-14 18:57:51 +00:00
|
|
|
//Check that file exists
|
|
|
|
if (!file_exists($pathname)) {
|
2006-03-17 09:48:24 +00:00
|
|
|
rss_not_found();
|
2004-05-02 23:08:19 +00:00
|
|
|
}
|
|
|
|
|
2004-12-14 18:57:51 +00:00
|
|
|
//Send it to user!
|
|
|
|
send_file($pathname, $filename, $lifetime);
|
|
|
|
|
2006-03-17 08:20:28 +00:00
|
|
|
function rss_not_found() {
|
2004-12-14 18:57:51 +00:00
|
|
|
/// error, send some XML with error message
|
2004-12-14 20:28:23 +00:00
|
|
|
global $lifetime, $filename;
|
|
|
|
send_file(rss_geterrorxmlfile(), $filename, $lifetime, false, true);
|
2004-12-14 18:57:51 +00:00
|
|
|
}
|
2004-05-02 23:08:19 +00:00
|
|
|
?>
|