From aa60291e12d2c76c8078483d03ff4ab63652f22e Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Mon, 19 Jul 2010 10:57:52 +0000 Subject: [PATCH] rss MDL-23391 alter the rss urls to be component names ie mod_forum instead of just module name ie forum --- blocks/news_items/block_news_items.php | 2 +- blog/rsslib.php | 2 +- mod/data/edit.php | 2 +- mod/data/index.php | 2 +- mod/data/lib.php | 2 +- mod/data/view.php | 2 +- mod/forum/index.php | 4 +- mod/forum/lib.php | 2 +- mod/glossary/index.php | 2 +- mod/glossary/lib.php | 2 +- rss/file.php | 88 +++++++++++--------------- 11 files changed, 48 insertions(+), 62 deletions(-) diff --git a/blocks/news_items/block_news_items.php b/blocks/news_items/block_news_items.php index d28f380a54d..d32781e8ddd 100644 --- a/blocks/news_items/block_news_items.php +++ b/blocks/news_items/block_news_items.php @@ -106,7 +106,7 @@ class block_news_items extends block_base { } else { $userid = $USER->id; } - $this->content->footer .= '
'.rss_get_link($this->page->context->id, $userid, 'forum', $forum->id, $tooltiptext); + $this->content->footer .= '
'.rss_get_link($this->page->context->id, $userid, 'mod_forum', $forum->id, $tooltiptext); } } diff --git a/blog/rsslib.php b/blog/rsslib.php index 6972c17a757..a4d2c47ff4c 100755 --- a/blog/rsslib.php +++ b/blog/rsslib.php @@ -45,7 +45,7 @@ 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_generate_rss_feed($type, $id, $tagid=0) { +function blog_rss_get_feed($type, $id, $tagid=0) { global $CFG, $SITE, $DB; if (empty($CFG->enablerssfeeds)) { diff --git a/mod/data/edit.php b/mod/data/edit.php index 906833d06d6..91d9ab63ada 100755 --- a/mod/data/edit.php +++ b/mod/data/edit.php @@ -106,7 +106,7 @@ if ($cancel) { /// RSS and CSS and JS meta if (!empty($CFG->enablerssfeeds) && !empty($CFG->data_enablerssfeeds) && $data->rssarticles > 0) { - $rsspath = rss_get_url($context->id, $USER->id, 'data', $data->id); + $rsspath = rss_get_url($context->id, $USER->id, 'mod_data', $data->id); $PAGE->add_alternate_version(format_string($course->shortname) . ': %fullname%', $rsspath, 'application/rss+xml'); } diff --git a/mod/data/index.php b/mod/data/index.php index a6914970bf3..a3d7c53cb15 100755 --- a/mod/data/index.php +++ b/mod/data/index.php @@ -114,7 +114,7 @@ foreach ($datas as $data) { $rsslink = ''; if ($rss && $data->rssarticles > 0) { - $rsslink = rss_get_link($context->id, $USER->id, 'data', $data->id, 'RSS'); + $rsslink = rss_get_link($context->id, $USER->id, 'mod_data', $data->id, 'RSS'); } if ($usesections) { diff --git a/mod/data/lib.php b/mod/data/lib.php index a1ba82cb4f3..4413d9ca8e7 100755 --- a/mod/data/lib.php +++ b/mod/data/lib.php @@ -2874,7 +2874,7 @@ function data_extend_settings_navigation(settings_navigation $settings, navigati $string = get_string('rsstype','forum'); - $url = new moodle_url(rss_get_url($PAGE->cm->context->id, $USER->id, 'data', $data->id)); + $url = new moodle_url(rss_get_url($PAGE->cm->context->id, $USER->id, 'mod_data', $data->id)); $datanode->add($string, $url, settings_navigation::TYPE_SETTING, null, null, new pix_icon('i/rss', '')); } } diff --git a/mod/data/view.php b/mod/data/view.php index 3579984f55e..d925b8152cd 100755 --- a/mod/data/view.php +++ b/mod/data/view.php @@ -317,7 +317,7 @@ //this links has been Settings (database activity administration) block /*if (!empty($CFG->enablerssfeeds) && !empty($CFG->data_enablerssfeeds) && $data->rssarticles > 0) { echo '
'; - rss_print_link($context->id, $USER->id, 'data', $data->id, get_string('rsstype')); + rss_print_link($context->id, $USER->id, 'mod_data', $data->id, get_string('rsstype')); echo '
'; echo '
'; }*/ diff --git a/mod/forum/index.php b/mod/forum/index.php index 07d442fb5ae..c36232fef9d 100644 --- a/mod/forum/index.php +++ b/mod/forum/index.php @@ -258,7 +258,7 @@ if ($generalforums) { $tooltiptext = get_string('rsssubscriberssposts', 'forum'); } //Get html code for RSS link - $row[] = rss_get_link($context->id, $USER->id, 'forum', $forum->id, $tooltiptext); + $row[] = rss_get_link($context->id, $USER->id, 'mod_forum', $forum->id, $tooltiptext); } else { $row[] = ' '; } @@ -388,7 +388,7 @@ if ($course->id != SITEID) { // Only real courses have learning forums $tooltiptext = get_string('rsssubscriberssposts', 'forum'); } //Get html code for RSS link - $row[] = rss_get_link($context->id, $USER->id, 'forum', $forum->id, $tooltiptext); + $row[] = rss_get_link($context->id, $USER->id, 'mod_forum', $forum->id, $tooltiptext); } else { $row[] = ' '; } diff --git a/mod/forum/lib.php b/mod/forum/lib.php index f72e03d7017..5d0dca09894 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -7520,7 +7520,7 @@ function forum_extend_settings_navigation(settings_navigation $settingsnav, navi } else { $userid = $USER->id; } - $url = new moodle_url(rss_get_url($PAGE->cm->context->id, $userid, "forum", $forumobject->id)); + $url = new moodle_url(rss_get_url($PAGE->cm->context->id, $userid, "mod_forum", $forumobject->id)); $forumnode->add($string, $url, settings_navigation::TYPE_SETTING, null, null, new pix_icon('i/rss', '')); } } diff --git a/mod/glossary/index.php b/mod/glossary/index.php index aa64bc50a16..4eef6dfaac6 100644 --- a/mod/glossary/index.php +++ b/mod/glossary/index.php @@ -113,7 +113,7 @@ foreach ($glossarys as $glossary) { $userid = $USER->id; } //Get html code for RSS link - $rsslink = rss_get_link($context->id, $userid, "glossary", $glossary->id, $tooltiptext); + $rsslink = rss_get_link($context->id, $userid, 'mod_glossary', $glossary->id, $tooltiptext); } } diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index 8e9e2b5b22b..5cba538c566 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -2603,7 +2603,7 @@ function glossary_extend_settings_navigation(settings_navigation $settings, navi $string = get_string('rsstype','forum'); - $url = new moodle_url(rss_get_url($PAGE->cm->context->id, $USER->id, 'glossary', $glossary->id)); + $url = new moodle_url(rss_get_url($PAGE->cm->context->id, $USER->id, 'mod_glossary', $glossary->id)); $glossarynode->add($string, $url, settings_navigation::TYPE_SETTING, null, null, new pix_icon('i/rss', '')); } } diff --git a/rss/file.php b/rss/file.php index 0072eb708aa..cf72290a053 100644 --- a/rss/file.php +++ b/rss/file.php @@ -48,7 +48,7 @@ if (count($args) < 5) { $contextid = (int)$args[0]; $token = $args[1]; -$modulename = clean_param($args[2], PARAM_FILE); +$componentname = clean_param($args[2], PARAM_FILE); $instance = $args[3]; $userid = rss_get_userid_from_token($token); @@ -71,64 +71,50 @@ $PAGE->set_context($context); $coursecontext = get_course_context($context); $course = $DB->get_record('course', array('id' => $coursecontext->instanceid), '*', MUST_EXIST); +//this will store the path to the cached rss feed contents $pathname = null; -switch ($modulename) { - case 'blog': - $blogid = (int) $args[4]; // could be groupid / courseid / userid depending on $instance - if ($args[5] != 'rss.xml') { - $tagid = (int) $args[5]; +$componentdir = get_component_directory($componentname); +list($type, $plugin) = normalize_component($componentname); + +if (file_exists($componentdir)) { + require_once("$componentdir/rsslib.php"); + $functionname = $plugin.'_rss_get_feed'; + + if (function_exists($functionname)) { + + if ($componentname=='blog') { + + $blogid = (int) $args[4]; // could be groupid / courseid / userid depending on $instance + if ($args[5] != 'rss.xml') { + $tagid = (int) $args[5]; + } else { + $tagid = 0; + } + + try { + require_login($course, false, NULL, false, true); + } catch (Exception $e) { + rss_not_found(); + } + $pathname = $functionname($instance, $blogid, $tagid); + } else if ($componentname=='local_hub') { + + $pathname = $functionname($args); } else { - $tagid = 0; - } - try { - require_login($course, false, NULL, false, true); - } catch (Exception $e) { - rss_not_found(); - } + $instance = (int)$instance; - //Work out the filename of the cached RSS file - require_once($CFG->dirroot . '/blog/rsslib.php'); - $pathname = blog_generate_rss_feed($instance, $blogid, $tagid); - break; + try { + $cm = get_coursemodule_from_instance($plugin, $instance, 0, false, MUST_EXIST); + require_login($course, false, $cm, false, true); + } catch (Exception $e) { + rss_not_found(); + } - case 'local_hub': //Note: I made this case generic for a probable futur refactor. - // rss/file.php should not handle individual cases. - //Here $modulename contain the folder path with '_' instead of '/' - - //Work out the filename of the cached RSS file - $functionname = $modulename . '_rss_get_feed'; - $modulepath = str_replace('_', '/', $modulename); - require_once($CFG->dirroot . '/' . $modulepath . '/rsslib.php'); - if (function_exists($functionname)) { - $pathname = $functionname($args); //All the xxx_rss_get_feed() could manage - // eveything with only $args parameter. - } - break; - - default: - $instance = (int) $instance; - - $mods = get_plugin_list('mod'); - $mods = array_keys($mods); - if (!in_array(strtolower($modulename), $mods)) { - rss_not_found(); - } - try { - $cm = get_coursemodule_from_instance($modulename, $instance, 0, false, MUST_EXIST); - require_login($course, false, $cm, false, true); - } catch (Exception $e) { - rss_not_found(); - } - - //Work out the filename of the cached RSS file - $functionname = $cm->modname . '_rss_get_feed'; - require_once($CFG->dirroot . "/mod/{$cm->modname}/rsslib.php"); - if (function_exists($functionname)) { $pathname = $functionname($context, $cm, $instance, $args); } - break; + } } //Check that file exists