From a848c48cf3ec4f56768782373b35535afc1b5782 Mon Sep 17 00:00:00 2001 From: moodler Date: Fri, 17 Mar 2006 09:11:06 +0000 Subject: [PATCH] Just pushing the RSS a bit further, it's not tested properly yet --- blog/rsslib.php | 28 ++++++++++++++++++++++++---- rss/file.php | 49 ++++++++++++++++++++++++++++++++++++------------- 2 files changed, 60 insertions(+), 17 deletions(-) diff --git a/blog/rsslib.php b/blog/rsslib.php index bc43a1c858..5e6351180e 100755 --- a/blog/rsslib.php +++ b/blog/rsslib.php @@ -35,6 +35,26 @@ } + + function blog_generate_rss_feed($type, $id, $tag='') { + switch ($type) { + case 'site': + return blog_site_feeds($tag); + break; + case 'course': + return blog_course_feed($id,$tag); + break; + case 'group': + return blog_group_feed($id,$tag); + break; + case 'user': + return blog_user_feed($id,$tag); + break; + } + + return false; + } + /* Rss files for blogs * 4 different ways to store feeds. * site - $CFG->dataroot/rss/blogs/site/SITEID.xml @@ -74,7 +94,7 @@ // Only 1 view, site level feeds - function blog_site_feeds() { + function blog_site_feeds($tag='') { global $CFG; $status = true; @@ -159,7 +179,7 @@ } // takes in course object from db - function blog_course_feed($course) { + function blog_course_feed($course, $tag='') { global $CFG; $status = true; @@ -250,7 +270,7 @@ } // takes in course object from db - function blog_group_feed($group) { + function blog_group_feed($group, $tag='') { global $CFG; $status = true; @@ -334,7 +354,7 @@ } // takes in course object from db - function blog_user_feed($user) { + function blog_user_feed($user, $tag='') { global $CFG; $status = true; diff --git a/rss/file.php b/rss/file.php index 1d3d9cfa1e..19c2640daf 100644 --- a/rss/file.php +++ b/rss/file.php @@ -31,32 +31,42 @@ // extract relative path components $args = explode('/', trim($relativepath, '/')); - $isblog = ($args[0] == 'blog'); - $needcourse = !$isblog; - if (count($args) < 5 && !$isblog) { + if (count($args) < 5) { rss_not_found(); } $courseid = (int)$args[0]; $userid = (int)$args[1]; $modulename = clean_param($args[2], PARAM_FILE); - $instance = (int)$args[3]; + $instance = $args[3]; $filename = 'rss.xml'; - if ($needcourse and (!$course = get_record('course', 'id', $courseid))) { + if ($isblog = $modulename == 'blog') { + $blogid = (int)$args[4]; // could be groupid / courseid / userid depending on $instance + if ($args[5] != 'rss.xml') { + $tag = clean_param($args[5], PARAM_FILE); // could be groupid / courseid / userid depending on $instance + } + } else { + $instance = (int)$instance; // we know it's an id number + } + + + if (!$course = get_record('course', 'id', $courseid)) { rss_not_found(); } //Check name of module - $mods = get_list_of_plugins("mod"); - if ($needcourse and !in_array(strtolower($modulename), $mods)) { - rss_not_found(); + if (!$isblog) { + $mods = get_list_of_plugins("mod"); + if (!in_array(strtolower($modulename), $mods)) { + rss_not_found(); + } } //Get course_module to check it's visible - if ($needcourse && (!$cm = get_coursemodule_from_instance($modulename,$instance,$courseid)) ) { + if (!$isblog && (!$cm = get_coursemodule_from_instance($modulename,$instance,$courseid)) ) { rss_not_found(); } @@ -65,24 +75,37 @@ //Check for "security" if !course->guest or course->password if ($course->id != SITEID) { - if ($needcourse and ((!$course->guest || $course->password) && (!($isstudent || $isteacher)))) { + if ((!$course->guest || $course->password) && (!($isstudent || $isteacher))) { rss_not_found(); } } //Check for "security" if the course is hidden or the activity is hidden - if ($needcourse and ((!$course->visible || !$cm->visible) && (!$isteacher))) { + if ((!$course->visible || !$cm->visible) && (!$isteacher)) { rss_not_found(); } if ($isblog) { - $pathname = $CFG->dataroot.'/rss/'.$relativepath; + if (empty($tag)) { + $pathname = $CFG->dataroot.'/rss/blog/'.$instance.'/'.$blogid.'.xml'; + } else { + $pathname = $CFG->dataroot.'/rss/blog/'.$instance.'/'.$blogid.'/'.$tag.'.xml'; + } } else { $pathname = $CFG->dataroot.'/rss/'.$modulename.'/'.$instance.'.xml'; } //Check that file exists if (!file_exists($pathname)) { - rss_not_found(); + if ($isblog) { + if (filemtime($pathname) + 3600 < time()) { + require_once($CFG->dirroot.'/blog/rsslib.php'); + if (!blog_generate_rss_feed($instance, $blogid)) { + rss_not_found(); + } + } + } else { + rss_not_found(); + } } //Send it to user! -- 2.39.5