Skip to content

Commit

Permalink
Just pushing the RSS a bit further, it's not tested properly yet
Browse files Browse the repository at this point in the history
  • Loading branch information
moodler committed Mar 17, 2006
1 parent 66c52fd commit a848c48
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 17 deletions.
28 changes: 24 additions & 4 deletions blog/rsslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ function blog_rss_feeds() {

}


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
Expand Down Expand Up @@ -74,7 +94,7 @@ function blog_rss_save_file($type, $id, $result) {


// Only 1 view, site level feeds
function blog_site_feeds() {
function blog_site_feeds($tag='') {

global $CFG;
$status = true;
Expand Down Expand Up @@ -159,7 +179,7 @@ function blog_course_feeds() {
}

// takes in course object from db
function blog_course_feed($course) {
function blog_course_feed($course, $tag='') {

global $CFG;
$status = true;
Expand Down Expand Up @@ -250,7 +270,7 @@ function blog_group_feeds() {
}

// takes in course object from db
function blog_group_feed($group) {
function blog_group_feed($group, $tag='') {

global $CFG;
$status = true;
Expand Down Expand Up @@ -334,7 +354,7 @@ function blog_user_feeds() {
}

// takes in course object from db
function blog_user_feed($user) {
function blog_user_feed($user, $tag='') {

global $CFG;
$status = true;
Expand Down
49 changes: 36 additions & 13 deletions rss/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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!
Expand Down

0 comments on commit a848c48

Please sign in to comment.