mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 08:55:15 +02:00
rss MDL-23391 refactored rss feeds to make them standard across components
This commit is contained in:
parent
d333dc2003
commit
274f98409a
@ -45,11 +45,20 @@ function blog_rss_print_link($filtertype, $filterselect, $tagid=0, $tooltiptext=
|
||||
|
||||
|
||||
// Generate any blog RSS feed via one function (called by ../rss/file.php)
|
||||
function blog_rss_get_feed($context, $cm, $instance, $args) {
|
||||
function blog_rss_get_feed($context, $args) {
|
||||
global $CFG, $SITE, $DB;
|
||||
|
||||
$type = $instance;
|
||||
if (empty($CFG->enablerssfeeds)) {
|
||||
debugging('Sorry, RSS feeds are disabled on this site');
|
||||
return '';
|
||||
}
|
||||
|
||||
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
if (!has_capability('moodle/blog:view', $sitecontext)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$type = $args[3];
|
||||
$id = (int) $args[4]; // could be groupid / courseid / userid depending on $instance
|
||||
|
||||
$tagid=0;
|
||||
@ -59,11 +68,6 @@ function blog_rss_get_feed($context, $cm, $instance, $args) {
|
||||
$tagid = 0;
|
||||
}
|
||||
|
||||
if (empty($CFG->enablerssfeeds)) {
|
||||
debugging('Sorry, RSS feeds are disabled on this site');
|
||||
return '';
|
||||
}
|
||||
|
||||
$filename = blog_rss_file_name($type, $id, $tagid);
|
||||
|
||||
if (file_exists($filename)) {
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
// This function is the main entry point to database module
|
||||
// rss feeds generation.
|
||||
function data_rss_get_feed($context, $cm, $instance, $args) {
|
||||
function data_rss_get_feed($context, $args) {
|
||||
global $CFG, $DB;
|
||||
|
||||
// Check CFG->data_enablerssfeeds.
|
||||
@ -12,18 +12,18 @@
|
||||
return null;
|
||||
}
|
||||
|
||||
//check capabilities
|
||||
if (!has_capability('mod/data:managetemplates', $context)) {
|
||||
if (!is_enrolled($context, null, 'mod/data:managetemplates')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$data = $DB->get_record('data', array('id' => $instance), '*', MUST_EXIST);
|
||||
$dataid = $args[3];
|
||||
$data = $DB->get_record('data', array('id' => $dataid), '*', MUST_EXIST);
|
||||
|
||||
if (!rss_enabled('data', $data, false, true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$sql = data_rss_get_sql($data, $cm);
|
||||
$sql = data_rss_get_sql($data);
|
||||
|
||||
//get the cache file info
|
||||
$filename = rss_get_file_name($data, $sql);
|
||||
@ -35,7 +35,7 @@
|
||||
$cachedfilelastmodified = filemtime($cachedfilepath);
|
||||
}
|
||||
|
||||
if (data_rss_newstuff($data, $cm, $cachedfilelastmodified)) {
|
||||
if (data_rss_newstuff($data, $cachedfilelastmodified)) {
|
||||
require_once($CFG->dirroot . '/mod/data/lib.php');
|
||||
|
||||
// Get the first field in the list (a hack for now until we have a selector)
|
||||
@ -98,7 +98,7 @@
|
||||
return $cachedfilepath;
|
||||
}
|
||||
|
||||
function data_rss_get_sql($data, $cm, $time=0) {
|
||||
function data_rss_get_sql($data, $time=0) {
|
||||
//do we only want new posts?
|
||||
if ($time) {
|
||||
$time = " AND dr.timemodified > '$time'";
|
||||
@ -122,14 +122,13 @@
|
||||
* Otherwise it returns false.
|
||||
*
|
||||
* @param object $data the data activity object
|
||||
* @param object $cm
|
||||
* @param int $time timestamp
|
||||
* @return bool
|
||||
*/
|
||||
function data_rss_newstuff($data, $cm, $time) {
|
||||
function data_rss_newstuff($data, $time) {
|
||||
global $DB;
|
||||
|
||||
$sql = data_rss_get_sql($data, $cm, $time);
|
||||
$sql = data_rss_get_sql($data, $time);
|
||||
|
||||
$recs = $DB->get_records_sql($sql, null, 0, 1);//limit of 1. If we get even 1 back we have new stuff
|
||||
return ($recs && !empty($recs));
|
||||
|
@ -32,7 +32,7 @@
|
||||
* @param array $args the arguments received in the url
|
||||
* @return string the full path to the cached RSS feed directory. Null if there is a problem.
|
||||
*/
|
||||
function forum_rss_get_feed($context, $cm, $forumid, $args) {
|
||||
function forum_rss_get_feed($context, $args) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$status = true;
|
||||
@ -43,17 +43,19 @@ function forum_rss_get_feed($context, $cm, $forumid, $args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//check capabilities
|
||||
if (!has_capability('mod/forum:viewdiscussion', $context)) {
|
||||
if (!is_enrolled($context, null, 'mod/forum:viewdiscussion')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$forumid = $args[3];
|
||||
$forum = $DB->get_record('forum', array('id' => $forumid), '*', MUST_EXIST);
|
||||
|
||||
if (!rss_enabled('forum', $forum)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$cm = get_coursemodule_from_instance('forum', $forumid, 0, false, MUST_EXIST);
|
||||
|
||||
//the sql that will retreive the data for the feed and be hashed to get the cache filename
|
||||
$sql = forum_rss_get_sql($forum, $cm);
|
||||
|
||||
|
@ -2589,8 +2589,7 @@ function glossary_extend_settings_navigation(settings_navigation $settings, navi
|
||||
|
||||
$glossary = $DB->get_record('glossary', array("id" => $PAGE->cm->instance));
|
||||
|
||||
if (!empty($CFG->enablerssfeeds) && !empty($CFG->glossary_enablerssfeeds)
|
||||
&& $glossary->rsstype && $glossary->rssarticles) {
|
||||
if (!empty($CFG->enablerssfeeds) && !empty($CFG->glossary_enablerssfeeds) && $glossary->rsstype && $glossary->rssarticles) {
|
||||
require_once("$CFG->libdir/rsslib.php");
|
||||
|
||||
$string = get_string('rsstype','forum');
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
//This function is the main entry point to glossary
|
||||
//rss feeds generation.
|
||||
function glossary_rss_get_feed($context, $cm, $instance, $args) {
|
||||
function glossary_rss_get_feed($context, $args) {
|
||||
global $CFG, $DB;
|
||||
|
||||
if (empty($CFG->glossary_enablerssfeeds)) {
|
||||
@ -15,14 +15,18 @@
|
||||
|
||||
//check capabilities
|
||||
//glossary module doesn't require any capabilities to view glossary entries (aside from being logged in)
|
||||
if (!is_enrolled($context)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$glossary = $DB->get_record('glossary', array('id' => $instance), '*', MUST_EXIST);
|
||||
$glossaryid = $args[3];
|
||||
$glossary = $DB->get_record('glossary', array('id' => $glossaryid), '*', MUST_EXIST);
|
||||
|
||||
if (!rss_enabled('glossary', $glossary)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$sql = glossary_rss_get_sql($glossary, $cm);
|
||||
$sql = glossary_rss_get_sql($glossary);
|
||||
|
||||
//get the cache file info
|
||||
$filename = rss_get_file_name($glossary, $sql);
|
||||
@ -34,7 +38,7 @@
|
||||
$cachedfilelastmodified = filemtime($cachedfilepath);
|
||||
}
|
||||
|
||||
if (glossary_rss_newstuff($glossary, $cm, $cachedfilelastmodified)) {
|
||||
if (glossary_rss_newstuff($glossary, $cachedfilelastmodified)) {
|
||||
if (!$recs = $DB->get_records_sql($sql, array(), 0, $glossary->rssarticles)) {
|
||||
return null;
|
||||
}
|
||||
@ -90,7 +94,7 @@
|
||||
return $cachedfilepath;
|
||||
}
|
||||
|
||||
function glossary_rss_get_sql($glossary, $cm, $time=0) {
|
||||
function glossary_rss_get_sql($glossary, $time=0) {
|
||||
//do we only want new items?
|
||||
if ($time) {
|
||||
$time = "AND e.timecreated > $time";
|
||||
@ -138,14 +142,13 @@
|
||||
* Otherwise it returns false.
|
||||
*
|
||||
* @param object $glossary the glossary activity object
|
||||
* @param object $cm
|
||||
* @param int $time timestamp
|
||||
* @return bool
|
||||
*/
|
||||
function glossary_rss_newstuff($glossary, $cm, $time) {
|
||||
function glossary_rss_newstuff($glossary, $time) {
|
||||
global $DB;
|
||||
|
||||
$sql = glossary_rss_get_sql($glossary, $cm, $time);
|
||||
$sql = glossary_rss_get_sql($glossary, $time);
|
||||
|
||||
$recs = $DB->get_records_sql($sql, null, 0, 1);//limit of 1. If we get even 1 back we have new stuff
|
||||
return ($recs && !empty($recs));
|
||||
|
28
rss/file.php
28
rss/file.php
@ -49,7 +49,7 @@ if (count($args) < 5) {
|
||||
$contextid = (int)$args[0];
|
||||
$token = $args[1];
|
||||
$componentname = clean_param($args[2], PARAM_FILE);
|
||||
$instance = $args[3];
|
||||
//$instance = $args[3];
|
||||
|
||||
$userid = rss_get_userid_from_token($token);
|
||||
if (!$userid) {
|
||||
@ -70,36 +70,14 @@ list($type, $plugin) = normalize_component($componentname);
|
||||
//this will store the path to the cached rss feed contents
|
||||
$pathname = null;
|
||||
|
||||
//check user's psuedo login created by session_set_user()
|
||||
//NOTE the component providing the feed should do its own capability checks
|
||||
try {
|
||||
$cm = null;
|
||||
if (!empty($plugin) && !empty($instance)) {
|
||||
$cm = get_coursemodule_from_instance($plugin, $instance, 0, false, MUST_EXIST);
|
||||
}
|
||||
|
||||
//Get course from context
|
||||
//TODO: note that in the case of the hub rss feed, the feed is not related to a course context,
|
||||
//it is more a "site" context. The Hub RSS bypass the following line using context id = 2
|
||||
$coursecontext = get_course_context($context);
|
||||
|
||||
$course = null;
|
||||
if ($coursecontext) {
|
||||
$course = $DB->get_record('course', array('id' => $coursecontext->instanceid), '*', MUST_EXIST);
|
||||
}
|
||||
|
||||
require_login($course, false, $cm, false, true);
|
||||
} catch (Exception $e) {
|
||||
rss_not_found();
|
||||
}
|
||||
|
||||
if (file_exists($componentdir)) {
|
||||
require_once("$componentdir/rsslib.php");
|
||||
$functionname = $plugin.'_rss_get_feed';
|
||||
|
||||
if (function_exists($functionname)) {
|
||||
//$pathname will be null if there was a problem or the user doesn't have the necessary capabilities
|
||||
$pathname = $functionname($context, $cm, $instance, $args);
|
||||
//NOTE the component providing the feed should do its own capability checks
|
||||
$pathname = $functionname($context, $args);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user