rss MDL-23391 alter the rss urls to be component names ie mod_forum instead of just...
authorAndrew Davis <andrew@affinitysoftware.net>
Mon, 19 Jul 2010 10:57:52 +0000 (10:57 +0000)
committerAndrew Davis <andrew@affinitysoftware.net>
Mon, 19 Jul 2010 10:57:52 +0000 (10:57 +0000)
blocks/news_items/block_news_items.php
blog/rsslib.php
mod/data/edit.php
mod/data/index.php
mod/data/lib.php
mod/data/view.php
mod/forum/index.php
mod/forum/lib.php
mod/glossary/index.php
mod/glossary/lib.php
rss/file.php

index d28f380..d32781e 100644 (file)
@@ -106,7 +106,7 @@ class block_news_items extends block_base {
                 } else {
                     $userid = $USER->id;
                 }
-                $this->content->footer .= '<br />'.rss_get_link($this->page->context->id, $userid, 'forum', $forum->id, $tooltiptext);
+                $this->content->footer .= '<br />'.rss_get_link($this->page->context->id, $userid, 'mod_forum', $forum->id, $tooltiptext);
             }
 
         }
index 6972c17..a4d2c47 100755 (executable)
@@ -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)) {
index 906833d..91d9ab6 100755 (executable)
@@ -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');
 }
index a691497..a3d7c53 100755 (executable)
@@ -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) {
index a1ba82c..4413d9c 100755 (executable)
@@ -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', ''));
     }
 }
index 3579984..d925b81 100755 (executable)
     //this links has been Settings (database activity administration) block
     /*if (!empty($CFG->enablerssfeeds) && !empty($CFG->data_enablerssfeeds) && $data->rssarticles > 0) {
         echo '<div style="float:right;">';
-        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 '</div>';
         echo '<div style="clear:both;"></div>';
     }*/
index 07d442f..c36232f 100644 (file)
@@ -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[] = '&nbsp;';
             }
@@ -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[] = '&nbsp;';
                 }
index f72e03d..5d0dca0 100644 (file)
@@ -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', ''));
     }
 }
index aa64bc5..4eef6df 100644 (file)
@@ -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);
         }
     }
 
index 8e9e2b5..5cba538 100644 (file)
@@ -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', ''));
     }
 }
index 0072eb7..cf72290 100644 (file)
@@ -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();
-        }
 
-        //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;
-
-    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;
+            $instance = (int)$instance;
 
-    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();
-        }
+            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();
+            }
 
-        //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