MDL-22053 removing relative paths from get_plugin|component_directory() because we...
authorPetr Skoda <skodak@moodle.org>
Sat, 10 Apr 2010 23:21:18 +0000 (23:21 +0000)
committerPetr Skoda <skodak@moodle.org>
Sat, 10 Apr 2010 23:21:18 +0000 (23:21 +0000)
lib/moodlelib.php
lib/outputrequirementslib.php
mnet/xmlrpc/serverlib.php

index 2e7c1d1..7d0eaf6 100644 (file)
@@ -6525,20 +6525,20 @@ function endecrypt ($pwd, $data, $case) {
 /// ENVIRONMENT CHECKING  ////////////////////////////////////////////////////////////
 
 /**
- * Return exact path to plugin directory
+ * Returns the exact absolute path to plugin directory.
+ *
  * @param string $plugintype type of plugin
  * @param string $name name of the plugin
- * @param bool $fullpaths false means relative paths from dirroot
- * @return directory path, full or relative to dirroot
+ * @return string full path to plugin directory; NULL if not found
  */
-function get_plugin_directory($plugintype, $name, $fullpaths=true) {
+function get_plugin_directory($plugintype, $name) {
     if ($plugintype === '') {
         $plugintype = 'mod';
     }
 
-    $types = get_plugin_types($fullpaths);
+    $types = get_plugin_types(true);
     if (!array_key_exists($plugintype, $types)) {
-        return null;
+        return NULL;
     }
     $name = clean_param($name, PARAM_SAFEDIR); // just in case ;-)
 
@@ -6546,37 +6546,38 @@ function get_plugin_directory($plugintype, $name, $fullpaths=true) {
 }
 
 /**
- * Return exact path to plugin directory,
+ * Return exact absolute path to a plugin directory,
  * this method support "simpletest_" prefix designed for unit testing.
+ *
  * @param string $component name such as 'moodle', 'mod_forum' or special simpletest value
- * @param bool $fullpaths false means relative paths from dirroot
- * @return directory path, full or relative to dirroot; NULL if not found
+ * @return string full path to component directory; NULL if not found
  */
-function get_component_directory($component, $fullpaths=true) {
+function get_component_directory($component) {
     global $CFG;
-
+/*
     $simpletest = false;
     if (strpos($component, 'simpletest_') === 0) {
         $subdir = substr($component, strlen('simpletest_'));
+        //TODO: this looks borked, where is it used actually?
         return $subdir;
     }
-
+*/
     list($type, $plugin) = normalize_component($component);
 
     if ($type === 'core') {
         if ($plugin === NULL ) {
-            $path = ($fullpaths ? $CFG->libdir : 'lib');
+            $path = $CFG->libdir;
         } else {
             $subsystems = get_core_subsystems();
             if (isset($subsystems[$plugin])) {
-                $path = ($fullpaths ? $CFG->dirroot.'/'.$subsystems[$plugin] : $subsystems[$plugin]);
+                $path = $CFG->dirroot.'/'.$subsystems[$plugin];
             } else {
                 $path = NULL;
             }
         }
 
     } else {
-        $path = get_plugin_directory($type, $plugin, $fullpaths);
+        $path = get_plugin_directory($type, $plugin);
     }
 
     return $path;
index a80df2a..f4e7c60 100644 (file)
@@ -408,9 +408,12 @@ class page_requirements_manager {
             }
 
         } else {
-            if ($dir = get_component_directory($component, false)) {
-                if (file_exists("$CFG->dirroot/$dir/module.js")) {
-                    $module = array('name'=>$component, 'fullpath'=>"/$dir/module.js", 'requires' => array());
+            if ($dir = get_component_directory($component)) {
+                if (file_exists("$dir/module.js")) {
+                    if (strpos($dir, $CFG->dirroot.'/') === 0) {
+                        $dir = substr($dir, strlen($CFG->dirroot));
+                        $module = array('name'=>$component, 'fullpath'=>"$dir/module.js", 'requires' => array());
+                    }
                 }
             }
         }
index de43045..d4e3f88 100644 (file)
@@ -597,7 +597,8 @@ function mnet_setup_dummy_method($method, $callstack, $rpcrecord) {
     $remoteclient = get_mnet_remote_client();
     // verify that the callpath in the stack matches our records
     // callstack will look like array('mod', 'forum', 'lib.php', 'forum_add_instance');
-    $path = get_plugin_directory($rpcrecord->plugintype, $rpcrecord->pluginname, false);
+    $path = get_plugin_directory($rpcrecord->plugintype, $rpcrecord->pluginname);
+    $path = substr($path, strlen($CFG->dirroot)+1); // this is a bit hacky and fragile, it is not guaranteed that plugins are in dirroot
     array_pop($callstack);
     $providedpath =  implode('/', $callstack);
     if ($providedpath != $path . '/' . $rpcrecord->filename) {