Skip to content

Commit

Permalink
MDL-22053 removing relative paths from get_plugin|component_directory…
Browse files Browse the repository at this point in the history
…() because we can be only sure that the absolute paths exists such as in case of $CFG->themedir outside of dirroot; commeting out some simpletes_ stuff which does not seem to be used any more
  • Loading branch information
skodak committed Apr 10, 2010
1 parent 0fddc03 commit ae58632
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
31 changes: 16 additions & 15 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -6525,58 +6525,59 @@ 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 ;-)

return $types[$plugintype].'/'.$name;
}

/**
* 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;
Expand Down
9 changes: 6 additions & 3 deletions lib/outputrequirementslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,12 @@ protected function find_module($component) {
}

} 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());
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion mnet/xmlrpc/serverlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ae58632

Please sign in to comment.