Пример #1
0
 /**
  * Returns a list of all components installed on the server
  *
  * @return array (string)legacyname => (string)frankenstylename
  */
 public static function list_components()
 {
     $list['moodle'] = 'core';
     $coresubsystems = get_core_subsystems();
     ksort($coresubsystems);
     // should be but just in case
     foreach ($coresubsystems as $name => $location) {
         if ($name != 'moodle.org') {
             $list[$name] = 'core_' . $name;
         }
     }
     $plugintypes = get_plugin_types();
     foreach ($plugintypes as $type => $location) {
         $pluginlist = get_plugin_list($type);
         foreach ($pluginlist as $name => $ununsed) {
             if ($type == 'mod') {
                 if (array_key_exists($name, $list)) {
                     throw new Exception('Activity module and core subsystem name collision');
                 }
                 $list[$name] = $type . '_' . $name;
             } else {
                 $list[$type . '_' . $name] = $type . '_' . $name;
             }
         }
     }
     return $list;
 }
Пример #2
0
 public function test_deprecated_get_core_subsystems()
 {
     global $CFG;
     $subsystems = core_component::get_core_subsystems();
     $this->assertSame($subsystems, get_core_subsystems(true));
     $realsubsystems = get_core_subsystems();
     $this->assertDebuggingCalled();
     $this->assertSame($realsubsystems, get_core_subsystems(false));
     $this->assertDebuggingCalled();
     $this->assertEquals(count($subsystems), count($realsubsystems));
     foreach ($subsystems as $subsystem => $fulldir) {
         $this->assertArrayHasKey($subsystem, $realsubsystems);
         if ($fulldir === null) {
             $this->assertNull($realsubsystems[$subsystem]);
             continue;
         }
         $this->assertSame($fulldir, $CFG->dirroot . '/' . $realsubsystems[$subsystem]);
     }
 }
 /**
  * Determine the module metadata for all moodle YUI modules.
  *
  * This works through all modules capable of serving YUI modules, and attempts to get
  * metadata for each of those modules.
  *
  * @return Array of module metadata
  */
 private function get_moodle_metadata()
 {
     $moodlemodules = array();
     // Core isn't a plugin type or subsystem - handle it seperately.
     if ($module = $this->get_moodle_path_metadata(get_component_directory('core'))) {
         $moodlemodules = array_merge($moodlemodules, $module);
     }
     // Handle other core subsystems.
     $subsystems = get_core_subsystems();
     foreach ($subsystems as $subsystem => $path) {
         if (is_null($path)) {
             continue;
         }
         $path = get_component_directory($subsystem);
         if ($module = $this->get_moodle_path_metadata($path)) {
             $moodlemodules = array_merge($moodlemodules, $module);
         }
     }
     // And finally the plugins.
     $plugintypes = get_plugin_types();
     foreach ($plugintypes as $plugintype => $pathroot) {
         $pluginlist = get_plugin_list($plugintype);
         foreach ($pluginlist as $plugin => $path) {
             if ($module = $this->get_moodle_path_metadata($path)) {
                 $moodlemodules = array_merge($moodlemodules, $module);
             }
         }
     }
     return $moodlemodules;
 }
Пример #4
0
/**
 * Given a specific page type, parent context and currect context, return all the page type patterns
 * that might be used by this block.
 *
 * @param string $pagetype for example 'course-view-weeks' or 'mod-quiz-view'.
 * @param stdClass $parentcontext Block's parent context
 * @param stdClass $currentcontext Current context of block
 * @return array an array of all the page type patterns that might match this page type.
 */
function generate_page_type_patterns($pagetype, $parentcontext = null, $currentcontext = null)
{
    global $CFG;
    $bits = explode('-', $pagetype);
    $core = get_core_subsystems();
    $plugins = get_plugin_types();
    //progressively strip pieces off the page type looking for a match
    $componentarray = null;
    for ($i = count($bits); $i > 0; $i--) {
        $possiblecomponentarray = array_slice($bits, 0, $i);
        $possiblecomponent = implode('', $possiblecomponentarray);
        // Check to see if the component is a core component
        if (array_key_exists($possiblecomponent, $core) && !empty($core[$possiblecomponent])) {
            $libfile = $CFG->dirroot . '/' . $core[$possiblecomponent] . '/lib.php';
            if (file_exists($libfile)) {
                require_once $libfile;
                $function = $possiblecomponent . '_page_type_list';
                if (function_exists($function)) {
                    if ($patterns = $function($pagetype, $parentcontext, $currentcontext)) {
                        break;
                    }
                }
            }
        }
        //check the plugin directory and look for a callback
        if (array_key_exists($possiblecomponent, $plugins) && !empty($plugins[$possiblecomponent])) {
            //We've found a plugin type. Look for a plugin name by getting the next section of page type
            if (count($bits) > $i) {
                $pluginname = $bits[$i];
                $directory = get_plugin_directory($possiblecomponent, $pluginname);
                if (!empty($directory)) {
                    $libfile = $directory . '/lib.php';
                    if (file_exists($libfile)) {
                        require_once $libfile;
                        $function = $possiblecomponent . '_' . $pluginname . '_page_type_list';
                        if (!function_exists($function)) {
                            $function = $pluginname . '_page_type_list';
                        }
                        if (function_exists($function)) {
                            if ($patterns = $function($pagetype, $parentcontext, $currentcontext)) {
                                break;
                            }
                        }
                    }
                }
            }
            //we'll only get to here if we still don't have any patterns
            //the plugin type may have a callback
            $directory = get_plugin_directory($possiblecomponent, null);
            if (!empty($directory)) {
                $libfile = $directory . '/lib.php';
                if (file_exists($libfile)) {
                    require_once $libfile;
                    $function = $possiblecomponent . '_page_type_list';
                    if (function_exists($function)) {
                        if ($patterns = $function($pagetype, $parentcontext, $currentcontext)) {
                            break;
                        }
                    }
                }
            }
        }
    }
    if (empty($patterns)) {
        $patterns = default_page_type_list($pagetype, $parentcontext, $currentcontext);
    }
    // Ensure that the * pattern is always available if editing block 'at distance', so
    // we always can 'bring back' it to the original context. MDL-30340
    if ((!isset($currentcontext) or !isset($parentcontext) or $currentcontext->id != $parentcontext->id) && !isset($patterns['*'])) {
        // TODO: We could change the string here, showing its 'bring back' meaning
        $patterns['*'] = get_string('page-x', 'pagetype');
    }
    return $patterns;
}
Пример #5
0
/**
 * Normalize the component name using the "frankenstyle" names.
 * @param string $component
 * @return array $type+$plugin elements
 */
function normalize_component($component)
{
    if ($component === 'moodle' or $component === 'core') {
        $type = 'core';
        $plugin = NULL;
    } else {
        if (strpos($component, '_') === false) {
            $subsystems = get_core_subsystems();
            if (array_key_exists($component, $subsystems)) {
                $type = 'core';
                $plugin = $component;
            } else {
                // everything else is a module
                $type = 'mod';
                $plugin = $component;
            }
        } else {
            list($type, $plugin) = explode('_', $component, 2);
            $plugintypes = get_plugin_types(false);
            if ($type !== 'core' and !array_key_exists($type, $plugintypes)) {
                $type = 'mod';
                $plugin = $component;
            }
        }
    }
    return array($type, $plugin);
}
/**
 * Given a specific page type, parent context and currect context, return all the page type patterns
 * that might be used by this block.
 *
 * @param string $pagetype for example 'course-view-weeks' or 'mod-quiz-view'.
 * @param stdClass $parentcontext Block's parent context
 * @param stdClass $currentcontext Current context of block
 * @return array an array of all the page type patterns that might match this page type.
 */
function generate_page_type_patterns($pagetype, $parentcontext = null, $currentcontext = null)
{
    global $CFG;
    $bits = explode('-', $pagetype);
    $core = get_core_subsystems();
    $plugins = get_plugin_types();
    //progressively strip pieces off the page type looking for a match
    $componentarray = null;
    for ($i = count($bits); $i > 0; $i--) {
        $possiblecomponentarray = array_slice($bits, 0, $i);
        $possiblecomponent = implode('', $possiblecomponentarray);
        // Check to see if the component is a core component
        if (array_key_exists($possiblecomponent, $core) && !empty($core[$possiblecomponent])) {
            $libfile = $CFG->dirroot . '/' . $core[$possiblecomponent] . '/lib.php';
            if (file_exists($libfile)) {
                require_once $libfile;
                $function = $possiblecomponent . '_page_type_list';
                if (function_exists($function)) {
                    if ($patterns = $function($pagetype, $parentcontext, $currentcontext)) {
                        break;
                    }
                }
            }
        }
        //check the plugin directory and look for a callback
        if (array_key_exists($possiblecomponent, $plugins) && !empty($plugins[$possiblecomponent])) {
            //We've found a plugin type. Look for a plugin name by getting the next section of page type
            if (count($bits) > $i) {
                $pluginname = $bits[$i];
                $directory = get_plugin_directory($possiblecomponent, $pluginname);
                if (!empty($directory)) {
                    $libfile = $directory . '/lib.php';
                    if (file_exists($libfile)) {
                        require_once $libfile;
                        $function = $pluginname . '_page_type_list';
                        if (function_exists($function)) {
                            if ($patterns = $function($pagetype, $parentcontext, $currentcontext)) {
                                break;
                            }
                        }
                    }
                }
            }
            //we'll only get to here if we still don't have any patterns
            //the plugin type may have a callback
            $directory = get_plugin_directory($possiblecomponent, null);
            if (!empty($directory)) {
                $libfile = $directory . '/lib.php';
                if (file_exists($libfile)) {
                    require_once $libfile;
                    $function = $possiblecomponent . '_page_type_list';
                    if (function_exists($function)) {
                        if ($patterns = $function($pagetype, $parentcontext, $currentcontext)) {
                            break;
                        }
                    }
                }
            }
        }
    }
    if (empty($patterns)) {
        $patterns = default_page_type_list($pagetype, $parentcontext, $currentcontext);
    }
    return $patterns;
}
Пример #7
0
 /**
  * Returns all the subsystems having PHPUnit tests
  *
  * Note we are hacking here the list of subsystems
  * to cover some well-known subsystems that are not properly
  * returned by the {@link get_core_subsystems()} function.
  *
  * @return array all the subsystems having PHPUnit tests
  */
 private static function get_all_subsystems_with_tests()
 {
     global $CFG;
     $subsystemswithtests = array();
     $subsystems = get_core_subsystems();
     // Hack the list a bit to cover some well-known ones
     $subsystems['backup'] = 'backup';
     $subsystems['db-dml'] = 'lib/dml';
     $subsystems['db-ddl'] = 'lib/ddl';
     ksort($subsystems);
     foreach ($subsystems as $subsys => $relsubsys) {
         if ($relsubsys === null) {
             continue;
         }
         $fullsubsys = $CFG->dirroot . '/' . $relsubsys;
         if (!is_dir($fullsubsys)) {
             continue;
         }
         // Look for tests recursively
         if (self::directory_has_tests($fullsubsys)) {
             $subsystemswithtests['core_' . $subsys] = $fullsubsys;
         }
     }
     return $subsystemswithtests;
 }
    // the corresponding build.xml file
    foreach ($plugins as $plugin => $pluginpath) {
        $component = $type . '_' . $plugin;
        if (!$options['absolute']) {
            // Want relatives, clean dirroot.
            $pluginpath = str_replace($CFG->dirroot . '/', '', $pluginpath);
        } else {
            // Want absolutes, replace dirroot by basedir.
            $pluginpath = str_replace($CFG->dirroot, $options['basedir'], $pluginpath);
        }
        echo 'plugin,' . $component . ',' . $pluginpath . PHP_EOL;
    }
}
// Get all the subsystems and
// generate the corresponding build.xml file
$subsystems = get_core_subsystems(true);
$subsystems['core'] = $options['basedir'];
// To get the main one too
foreach ($subsystems as $subsystem => $subsystempath) {
    if ($subsystem == 'backup') {
        // Because I want, yes :-P
        $subsystempath = $options['basedir'] . '/backup';
    }
    // All subsystems are core_ prefixed.
    $component = 'core_' . $subsystem;
    if ($subsystem === 'core') {
        // But core.
        $component = 'core';
    }
    // If it's a subsystem with path.
    if (!empty($subsystempath)) {
/**
 * Returns package names available for the file location
 * 
 * If the file is inside plugin directory only frankenstyle name for this plugin is returned
 * Otherwise returns list of available core packages
 *
 * @param local_moodlecheck_file $file
 * @return array
 */
function local_moodlecheck_package_names(local_moodlecheck_file $file)
{
    // Check if $file is inside any plugin directory
    foreach (local_moodlecheck_get_plugins() as $pluginfullname => $dir) {
        if ($file->is_in_dir($dir)) {
            return array($pluginfullname);
        }
    }
    // If not return list of core packages
    static $corepackages = array();
    if (empty($corepackages)) {
        $coresubsystems = get_core_subsystems();
        foreach ($coresubsystems as $key => $val) {
            $corepackages[] = 'core_' . $key;
        }
    }
    return $corepackages;
}
Пример #10
0
/**
 * Given a specific page type, parent context and currect context, return all the page type patterns
 * that might be used by this block.
 *
 * @param string $pagetype for example 'course-view-weeks' or 'mod-quiz-view'.
 * @param stdClass $parentcontext Block's parent context
 * @param stdClass $currentcontext Current context of block
 * @return array an array of all the page type patterns that might match this page type.
 */
function generate_page_type_patterns($pagetype, $parentcontext = null, $currentcontext = null) {
    global $CFG;

    $bits = explode('-', $pagetype);

    $component = clean_param(reset($bits), PARAM_ALPHANUMEXT);
    $function = 'default_pagetypelist';

    $core = get_core_subsystems();
    $plugins = get_plugin_types();

    // First check to see if the initial component is a core component
    // if its not check to see if it is a plugin component.
    if (array_key_exists($component, $core) && !empty($core[$component])) {
        $libfile = $CFG->dirroot.'/'.$core[$component].'/lib.php';
        if (file_exists($libfile)) {
            require_once($libfile);
            if (function_exists($component.'_pagetypelist')) {
                $function = $component.'_pagetypelist';
            }
        }
    } else if (array_key_exists($component, $plugins) && !empty($plugins[$component])) {
        $function = 'plugin_pagetypelist';
        if (function_exists($component.'_pagetypelist')) {
            $function = $component.'_pagetypelist';
        }
    }
    // Call the most appropriate function we could determine
    $patterns = $function($pagetype, $parentcontext, $currentcontext);
    if (empty($patterns)) {
        // If there are no patterns default to just the current pattern.
        $patterns = array($pagetype => $pagetype);
    }
    return $patterns;
}
$types = get_plugin_types(false);
// For each type, get their available implementations
foreach ($types as $type => $typerelpath) {
    $plugins = get_plugin_list($type);
    // For each plugin, let's calculate the proper component name and generate
    // the corresponding build.xml file
    foreach ($plugins as $plugin => $pluginabspath) {
        $component = $type . '_' . $plugin;
        $directory = $options['basedir'] . '/' . $typerelpath . '/' . $plugin;
        echo "Creating {$directory}/build.xml for {$component}" . PHP_EOL;
        create_ant_build_xml_file($component, $directory);
    }
}
// Get all the subsystems and
// generate the corresponding build.xml file
$subsystems = get_core_subsystems();
$subsystems['core'] = '.';
// To get the main one too
foreach ($subsystems as $subsystem => $subsystemrelpath) {
    if (empty($subsystemrelpath)) {
        continue;
    }
    if ($subsystem == 'backup') {
        // Because I want, yes :-P
        $subsystemrelpath = 'backup';
    }
    $component = $subsystem;
    $directory = $options['basedir'] . '/' . $subsystemrelpath;
    echo "Creating {$directory}/build.xml for {$component}" . PHP_EOL;
    create_ant_build_xml_file($component, $directory);
}
Пример #12
0
 /**
  * For a given module name, return the name of the standard renderer class
  * that defines the renderer interface for that module.
  *
  * Also, if it exists, include the renderer.php file for that module, so
  * the class definition of the default renderer has been loaded.
  *
  * @param string $component name such as 'core', 'mod_forum' or 'qtype_multichoice'.
  * @param string $subtype optional subtype such as 'news' resulting to 'mod_forum_news'
  * @return string the name of the standard renderer class for that module.
  */
 protected function standard_renderer_classname($component, $subtype = null)
 {
     global $CFG;
     // needed in included files
     // standardize component name ala frankenstyle
     list($plugin, $type) = normalize_component($component);
     if ($type === null) {
         $component = $plugin;
     } else {
         $component = $plugin . '_' . $type;
     }
     if ($component !== 'core') {
         // renderers are stored in renderer.php files
         if (!($compdirectory = get_component_directory($component))) {
             throw new coding_exception('Invalid component specified in renderer request');
         }
         $rendererfile = $compdirectory . '/renderer.php';
         if (file_exists($rendererfile)) {
             include_once $rendererfile;
         }
     } else {
         if (!empty($subtype)) {
             $coresubsystems = get_core_subsystems();
             if (!isset($coresubsystems[$subtype])) {
                 throw new coding_exception('Invalid core subtype "' . $subtype . '" in renderer request');
             }
             $rendererfile = $CFG->dirroot . '/' . $coresubsystems[$subtype] . '/renderer.php';
             if (file_exists($rendererfile)) {
                 include_once $rendererfile;
             }
         }
     }
     if (empty($subtype)) {
         $class = $component . '_renderer';
     } else {
         $class = $component . '_' . $subtype . '_renderer';
     }
     return $class;
 }