mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
RSS for forums now checks the new posts against the file modification date,
and doesn't regenerate the RSS file if it doesn't need to. Much faster now. :-)
This commit is contained in:
parent
b65a50e5a2
commit
6069e20688
@ -28,6 +28,28 @@
|
||||
if ($forums = get_records("forum")) {
|
||||
foreach ($forums as $forum) {
|
||||
if (!empty($forum->rsstype) && !empty($forum->rssarticles) && $status) {
|
||||
|
||||
$filename = rss_file_name('forum', $forum); // RSS file
|
||||
|
||||
//First let's make sure there is work to do by checking existing files
|
||||
if (file_exists($filename)) {
|
||||
if ($lastmodified = filemtime($filename)) {
|
||||
if (!forum_rss_newstuff($forum, $lastmodified)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Ignore hidden forums
|
||||
if (!instance_is_visible('forum',$forum)) {
|
||||
if (file_exists($filename)) {
|
||||
@unlink($filename);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
mtrace("Updating RSS feed for $forum->name, ID: $forum->id");
|
||||
|
||||
//Some debug...
|
||||
if ($CFG->debug > 7) {
|
||||
echo "ID: $forum->id->";
|
||||
@ -57,6 +79,17 @@
|
||||
return $status;
|
||||
}
|
||||
|
||||
function forum_rss_newstuff($forum, $time) {
|
||||
// If there is new stuff in the forum since $time then this returns
|
||||
// true. Otherwise it returns false.
|
||||
if ($forum->rsstype == 1) {
|
||||
$items = forum_rss_feed_discussions($forum, $time);
|
||||
} else {
|
||||
$items = forum_rss_feed_posts($forum, $time);
|
||||
}
|
||||
return (!empty($items));
|
||||
}
|
||||
|
||||
//This function return the XML rss contents about the forum record passed as parameter
|
||||
//It returns false if something is wrong
|
||||
function forum_rss_feed($forum) {
|
||||
@ -118,12 +151,18 @@
|
||||
|
||||
//This function returns "items" record array to be used to build the rss feed
|
||||
//for a Type=discussions forum
|
||||
function forum_rss_feed_discussions($forum) {
|
||||
function forum_rss_feed_discussions($forum, $newsince=0) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
$items = array();
|
||||
|
||||
if ($newsince) {
|
||||
$newsince = " AND p.created > '$newsince'";
|
||||
} else {
|
||||
$newsince = "";
|
||||
}
|
||||
|
||||
if ($recs = get_records_sql ("SELECT d.id discussionid,
|
||||
d.name discussionname,
|
||||
u.id userid,
|
||||
@ -138,8 +177,14 @@
|
||||
WHERE d.forum = '$forum->id' AND
|
||||
p.discussion = d.id AND
|
||||
p.parent = 0 AND
|
||||
u.id = p.userid
|
||||
u.id = p.userid $newsince
|
||||
ORDER BY p.created desc")) {
|
||||
|
||||
//Are we just looking for new ones? If so, then return now.
|
||||
if ($newsince) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//Iterate over each discussion to get forum->rssarticles records
|
||||
$articlesleft = $forum->rssarticles;
|
||||
$item = NULL;
|
||||
@ -166,12 +211,18 @@
|
||||
|
||||
//This function returns "items" record array to be used to build the rss feed
|
||||
//for a Type=posts forum
|
||||
function forum_rss_feed_posts($forum) {
|
||||
function forum_rss_feed_posts($forum, $newsince=0) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
$items = array();
|
||||
|
||||
if ($newsince) {
|
||||
$newsince = " AND p.created > '$newsince'";
|
||||
} else {
|
||||
$newsince = "";
|
||||
}
|
||||
|
||||
if ($recs = get_records_sql ("SELECT p.id postid,
|
||||
d.id discussionid,
|
||||
u.id userid,
|
||||
@ -186,8 +237,14 @@
|
||||
{$CFG->prefix}user u
|
||||
WHERE d.forum = '$forum->id' AND
|
||||
p.discussion = d.id AND
|
||||
u.id = p.userid
|
||||
u.id = p.userid $newsince
|
||||
ORDER BY p.created desc")) {
|
||||
|
||||
//Are we just looking for new ones? If so, then return now.
|
||||
if ($newsince) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//Iterate over each discussion to get forum->rssarticles records
|
||||
$articlesleft = $forum->rssarticles;
|
||||
$item = NULL;
|
||||
|
@ -98,7 +98,7 @@ function rss_save_file ($modname,$mod,$result) {
|
||||
}
|
||||
|
||||
if ($status) {
|
||||
$file = $basedir .= "/".$mod->id.".xml";
|
||||
$file = rss_file_name($modname, $mod);
|
||||
$rss_file = fopen($file,"w");
|
||||
if ($rss_file) {
|
||||
$status = fwrite ($rss_file,$result);
|
||||
@ -110,6 +110,13 @@ function rss_save_file ($modname,$mod,$result) {
|
||||
return $status;
|
||||
}
|
||||
|
||||
|
||||
function rss_file_name($modname, $mod) {
|
||||
global $CFG;
|
||||
|
||||
return "$CFG->dataroot/rss/$modname/$mod->id.xml";
|
||||
}
|
||||
|
||||
//This function return all the common headers for every rss feed in the site
|
||||
function rss_standard_header($title = NULL, $link = NULL, $description = NULL) {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user