* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
- function rss_add_http_header($context, $modname, $modinstance, $title) {
+ function rss_add_http_header($context, $componentname, $componentinstance, $title) {
global $PAGE, $USER;
- $rsspath = rss_get_url($context->id, $USER->id, $modname, $modinstance->id);
+ $rsspath = rss_get_url($context->id, $USER->id, $componentname, $componentinstance->id);
$PAGE->add_alternate_version($title, $rsspath, 'application/rss+xml');
}
* @global object
* @global object
*/
-function rss_get_link($contextid, $userid, $modulename, $id, $tooltiptext='') {
+function rss_get_link($contextid, $userid, $componentname, $id, $tooltiptext='') {
global $OUTPUT;
static $rsspath = '';
- $rsspath = rss_get_url($contextid, $userid, $modulename, $id);
+ $rsspath = rss_get_url($contextid, $userid, $componentname, $id);
$rsspix = $OUTPUT->pix_url('i/rss');
return '<a href="'. $rsspath .'"><img src="'. $rsspix .'" title="'. strip_tags($tooltiptext) .'" alt="'.get_string('rss').'" /></a>';
* @param string modulename the name of the current module. For example "forum"
* @param int id For modules, module instance id
*/
-function rss_get_url($contextid, $userid, $modulename, $id) {
+function rss_get_url($contextid, $userid, $componentname, $id) {
global $CFG;
require_once($CFG->libdir.'/filelib.php');
$usertoken = rss_get_token($userid);
- return get_file_url($contextid.'/'.$usertoken.'/'.$modulename.'/'.$id.'/rss.xml', null, 'rssfile');
+ return get_file_url($contextid.'/'.$usertoken.'/'.$componentname.'/'.$id.'/rss.xml', null, 'rssfile');
}
/**
* This function prints the icon (from theme) with the link to rss/file.php
*/
-function rss_print_link($contextid, $userid, $modulename, $id, $tooltiptext='') {
- print rss_get_link($contextid, $userid, $modulename, $id, $tooltiptext);
+function rss_print_link($contextid, $userid, $componentname, $id, $tooltiptext='') {
+ print rss_get_link($contextid, $userid, $componentname, $id, $tooltiptext);
}
* Given an object, deletes all RSS files associated with it.
* Relies on a naming convention. See rss_get_filename()
*
- * @param string $modname the name of the module ie 'forum'. Used to construct the cache path.
+ * @param string $componentname the name of the module ie 'forum'. Used to construct the cache path.
* @param object $instance An object with an id member variable ie $forum, $glossary.
* @return void
*/
-function rss_delete_file($modname, $instance) {
+function rss_delete_file($componentname, $instance) {
global $CFG;
- $dirpath = "$CFG->dataroot/cache/rss/$modname";
+ $dirpath = "$CFG->dataroot/cache/rss/$componentname";
if (is_dir($dirpath)) {
$dh = opendir($dirpath);
while (false !== ($filename = readdir($dh))) {
if ($filename!='.' && $filename!='..') {
if (preg_match("/{$instance->id}_/", $filename)) {
- unlink("$CFG->dataroot/cache/rss/$modname/$filename");
+ unlink("$dirpath/$filename");
}
}
}
* @param boolean $hasrsstype Should there be a rsstype member variable?
* @param boolean $hasrssarticles Should there be a rssarticles member variable?
*/
-function rss_enabled($modname, $instance, $hasrsstype=true, $hasrssarticles=true) {
+function rss_enabled_for_mod($modname, $instance=null, $hasrsstype=true, $hasrssarticles=true) {
if ($hasrsstype) {
if (empty($instance->rsstype) || $instance->rsstype==0) {
return false;
}
}
- if (!instance_is_visible($modname,$instance)) {
+ if (!empty($instance) && !instance_is_visible($modname,$instance)) {
return false;
}
* This function saves to file the rss feed specified in the parameters
*
* @global object
- * @param string $modname the module name ie forum. Used to create a cache directory.
+ * @param string $componentname the module name ie forum. Used to create a cache directory.
* @param string $filename the name of the file to be created ie "1234"
* @param string $result the data to be written to the file
*/
-function rss_save_file($modname, $filename, $result) {
+function rss_save_file($componentname, $filename, $result) {
global $CFG;
$status = true;
- if (! $basedir = make_upload_directory ('cache/rss/'. $modname)) {
+ if (! $basedir = make_upload_directory ('cache/rss/'. $componentname)) {
//Cannot be created, so error
$status = false;
}
if ($status) {
- $fullfilename = rss_get_file_full_name($modname, $filename);
+ $fullfilename = rss_get_file_full_name($componentname, $filename);
$rss_file = fopen($fullfilename, "w");
if ($rss_file) {
$status = fwrite ($rss_file, $result);
}
-function rss_get_file_full_name($modname, $filename) {
+function rss_get_file_full_name($componentname, $filename) {
global $CFG;
- return "$CFG->dataroot/cache/rss/$modname/$filename.xml";
+ return "$CFG->dataroot/cache/rss/$componentname/$filename.xml";
}
function rss_get_file_name($instance, $sql) {
$forum = $DB->get_record('forum', array('id' => $forumid), '*', MUST_EXIST);
- if (!rss_enabled('forum', $forum)) {
+ if (!rss_enabled_for_mod('forum', $forum)) {
return null;
}
//hash the sql to get the cache file name
$filename = rss_get_file_name($forum, $sql);
- $cachedfilepath = rss_get_file_full_name('forum', $filename);
+ $cachedfilepath = rss_get_file_full_name('mod_forum', $filename);
//Is the cache out of date?
$cachedfilelastmodified = 0;
//need to regenerate the cached version
$result = forum_rss_feed_contents($forum, $sql);
if (!empty($result)) {
- $status = rss_save_file('forum',$filename,$result);
+ $status = rss_save_file('mod_forum',$filename,$result);
}
}
* @return void
*/
function forum_rss_delete_file($forum) {
- rss_delete_file('forum', $forum);
+ rss_delete_file('mod_forum', $forum);
}
///////////////////////////////////////////////////////