Ejemplo n.º 1
0
 /**
  * Parse all callbacks and builds the tree.
  *
  * @param integer   $user ID of the user for which the profile is displayed.
  * @param bool      $iscurrentuser true if the profile being viewed is of current user, else false.
  * @param \stdClass $course Course object
  *
  * @return tree Fully build tree to be rendered on my profile page.
  */
 public static function build_tree($user, $iscurrentuser, $course = null)
 {
     global $CFG;
     $tree = new tree();
     //print_r($user);
     // Add core nodes.
     require_once $CFG->libdir . "/myprofilelib.php";
     core_myprofile_navigation($tree, $user, $iscurrentuser, $course);
     // Core components.
     $components = \core_component::get_core_subsystems();
     foreach ($components as $component => $directory) {
         if (empty($directory)) {
             continue;
         }
         $file = $directory . "/lib.php";
         if (is_readable($file)) {
             require_once $file;
             $function = "core_" . $component . "_myprofile_navigation";
             //print_r($function);
             if (function_exists($function)) {
                 //echo "Current function: ".$function."<br>";
                 $function($tree, $user, $iscurrentuser, $course);
             }
         }
     }
     // Plugins.
     $pluginswithfunction = get_plugins_with_function('myprofile_navigation', 'lib.php');
     foreach ($pluginswithfunction as $plugins) {
         foreach ($plugins as $function) {
             $function($tree, $user, $iscurrentuser, $course);
         }
     }
     $tree->sort_categories();
     return $tree;
 }
Ejemplo n.º 2
0
 /**
  * Parse all callbacks and builds the tree.
  *
  * @param integer   $user ID of the user for which the profile is displayed.
  * @param bool      $iscurrentuser true if the profile being viewed is of current user, else false.
  * @param \stdClass $course Course object
  *
  * @return tree Fully build tree to be rendered on my profile page.
  */
 public static function build_tree($user, $iscurrentuser, $course = null)
 {
     global $CFG;
     $tree = new tree();
     // Add core nodes.
     require_once $CFG->libdir . "/myprofilelib.php";
     core_myprofile_navigation($tree, $user, $iscurrentuser, $course);
     // Core components.
     $components = \core_component::get_core_subsystems();
     foreach ($components as $component => $directory) {
         if (empty($directory)) {
             continue;
         }
         $file = $directory . "/lib.php";
         if (is_readable($file)) {
             require_once $file;
             $function = "core_" . $component . "_myprofile_navigation";
             if (function_exists($function)) {
                 $function($tree, $user, $iscurrentuser, $course);
             }
         }
     }
     // Plugins.
     $types = \core_component::get_plugin_types();
     foreach ($types as $type => $dir) {
         $pluginlist = get_plugin_list_with_function($type, "myprofile_navigation", "lib.php");
         foreach ($pluginlist as $function) {
             $function($tree, $user, $iscurrentuser, $course);
         }
     }
     $tree->sort_categories();
     return $tree;
 }
Ejemplo n.º 3
0
 /**
  * Scan the source for AMD modules and return them all.
  *
  * The expected location for amd modules is:
  *  <componentdir>/amd/src/modulename.js
  *
  * @param boolean $debug If true, returns the paths to the original (unminified) source files.
  * @return array $files An array of mappings from module names to file paths.
  */
 public static function find_all_amd_modules($debug = false)
 {
     global $CFG;
     $jsdirs = array();
     $jsfiles = array();
     $dir = $CFG->libdir . '/amd';
     if (!empty($dir) && is_dir($dir)) {
         $jsdirs['core'] = $dir;
     }
     $subsystems = core_component::get_core_subsystems();
     foreach ($subsystems as $subsystem => $dir) {
         if (!empty($dir) && is_dir($dir . '/amd')) {
             $jsdirs['core_' . $subsystem] = $dir . '/amd';
         }
     }
     $plugintypes = core_component::get_plugin_types();
     foreach ($plugintypes as $type => $dir) {
         $plugins = core_component::get_plugin_list_with_file($type, 'amd', false);
         foreach ($plugins as $plugin => $dir) {
             if (!empty($dir) && is_dir($dir)) {
                 $jsdirs[$type . '_' . $plugin] = $dir;
             }
         }
     }
     foreach ($jsdirs as $component => $dir) {
         $srcdir = $dir . '/build';
         if ($debug) {
             $srcdir = $dir . '/src';
         }
         if (!is_dir($srcdir) || !is_readable($srcdir)) {
             // This is probably an empty amd directory without src or build.
             // Skip it - RecursiveDirectoryIterator fatals if the directory is not readable as an iterator.
             continue;
         }
         $items = new RecursiveDirectoryIterator($srcdir);
         foreach ($items as $item) {
             $extension = $item->getExtension();
             if ($extension === 'js') {
                 $filename = str_replace('.min', '', $item->getBaseName('.js'));
                 // We skip lazy loaded modules.
                 if (strpos($filename, '-lazy') === false) {
                     $modulename = $component . '/' . $filename;
                     $jsfiles[$modulename] = $item->getRealPath();
                 }
             }
             unset($item);
         }
         unset($items);
     }
     return $jsfiles;
 }
Ejemplo n.º 4
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 = core_component::get_core_subsystems();
     ksort($coresubsystems);
     // should be but just in case
     foreach ($coresubsystems as $name => $location) {
         $list[$name] = 'core_' . $name;
     }
     $plugintypes = core_component::get_plugin_types();
     foreach ($plugintypes as $type => $location) {
         $pluginlist = core_component::get_plugin_list($type);
         foreach ($pluginlist as $name => $ununsed) {
             if ($type == 'mod') {
                 // Plugin names are now automatically validated.
                 $list[$name] = $type . '_' . $name;
             } else {
                 $list[$type . '_' . $name] = $type . '_' . $name;
             }
         }
     }
     return $list;
 }
Ejemplo n.º 5
0
/**
 * List all core subsystems and their location
 *
 * This is a whitelist of components that are part of the core and their
 * language strings are defined in /lang/en/<<subsystem>>.php. If a given
 * plugin is not listed here and it does not have proper plugintype prefix,
 * then it is considered as course activity module.
 *
 * The location is optionally dirroot relative path. NULL means there is no special
 * directory for this subsystem. If the location is set, the subsystem's
 * renderer.php is expected to be there.
 *
 * @deprecated since 2.6, use core_component::get_core_subsystems()
 *
 * @param bool $fullpaths false means relative paths from dirroot, use true for performance reasons
 * @return array of (string)name => (string|null)location
 */
function get_core_subsystems($fullpaths = false)
{
    global $CFG;
    // NOTE: do not add any other debugging here, keep forever.
    $subsystems = core_component::get_core_subsystems();
    if ($fullpaths) {
        return $subsystems;
    }
    debugging('Short paths are deprecated when using get_core_subsystems(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER);
    $dlength = strlen($CFG->dirroot);
    foreach ($subsystems as $k => $v) {
        if ($v === null) {
            continue;
        }
        $subsystems[$k] = substr($v, $dlength + 1);
    }
    return $subsystems;
}
Ejemplo n.º 6
0
 /**
  * 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(core_component::get_component_directory('core'))) {
         $moodlemodules = array_merge($moodlemodules, $module);
     }
     // Handle other core subsystems.
     $subsystems = core_component::get_core_subsystems();
     foreach ($subsystems as $subsystem => $path) {
         if (is_null($path)) {
             continue;
         }
         if ($module = $this->get_moodle_path_metadata($path)) {
             $moodlemodules = array_merge($moodlemodules, $module);
         }
     }
     // And finally the plugins.
     $plugintypes = core_component::get_plugin_types();
     foreach ($plugintypes as $plugintype => $pathroot) {
         $pluginlist = core_component::get_plugin_list($plugintype);
         foreach ($pluginlist as $plugin => $path) {
             if ($module = $this->get_moodle_path_metadata($path)) {
                 $moodlemodules = array_merge($moodlemodules, $module);
             }
         }
     }
     return $moodlemodules;
 }
Ejemplo n.º 7
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;
    // Required for includes bellow.
    $bits = explode('-', $pagetype);
    $core = core_component::get_core_subsystems();
    $plugins = core_component::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 = $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 = core_component::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 = $plugins[$possiblecomponent];
            $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;
}
Ejemplo n.º 8
0
 /**
  * For a given module name, return the possible class names
  * that defines the renderer interface for that module.
  *
  * Newer auto-loaded class names are returned as well as the old style _renderable classnames.
  *
  * 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\output\news_renderer'
  *              or '\mod_forum\output\news\renderer'
  *              or non-autoloaded 'mod_forum_news'
  * @return array[] Each element of the array is an array with keys:
  *                 classname - The class name to search
  *                 autoloaded - Does this classname assume autoloading?
  *                 validwithprefix - Is this class name valid when a prefix is added to it?
  *                 validwithoutprefix - Is this class name valid when no prefix is added to it?
  * @throws coding_exception
  */
 protected function standard_renderer_classnames($component, $subtype = null)
 {
     global $CFG;
     // Needed in included files.
     $classnames = array();
     // Standardize component name ala frankenstyle.
     list($plugin, $type) = core_component::normalize_component($component);
     if ($type === null) {
         $component = $plugin;
     } else {
         $component = $plugin . '_' . $type;
     }
     if ($component !== 'core') {
         // Renderers are stored in renderer.php files.
         if (!($compdirectory = core_component::get_component_directory($component))) {
             throw new coding_exception('Invalid component specified in renderer request', $component);
         }
         $rendererfile = $compdirectory . '/renderer.php';
         if (file_exists($rendererfile)) {
             include_once $rendererfile;
         }
     } else {
         if (!empty($subtype)) {
             $coresubsystems = core_component::get_core_subsystems();
             if (!array_key_exists($subtype, $coresubsystems)) {
                 // There may be nulls.
                 throw new coding_exception('Invalid core subtype "' . $subtype . '" in renderer request', $subtype);
             }
             if ($coresubsystems[$subtype]) {
                 $rendererfile = $coresubsystems[$subtype] . '/renderer.php';
                 if (file_exists($rendererfile)) {
                     include_once $rendererfile;
                 }
             }
         }
     }
     if (empty($subtype)) {
         // Theme specific auto-loaded name (only valid when prefixed with the theme name).
         $classnames[] = array('validwithprefix' => true, 'validwithoutprefix' => false, 'autoloaded' => true, 'classname' => '\\output\\' . $component . '_renderer');
         // Standard autoloaded plugin name (not valid with a prefix).
         $classnames[] = array('validwithprefix' => false, 'validwithoutprefix' => true, 'autoloaded' => true, 'classname' => '\\' . $component . '\\output\\renderer');
         // Legacy class name - (valid with or without a prefix).
         $classnames[] = array('validwithprefix' => true, 'validwithoutprefix' => true, 'autoloaded' => false, 'classname' => $component . '_renderer');
     } else {
         // Theme specific auto-loaded name (only valid when prefixed with the theme name).
         $classnames[] = array('validwithprefix' => true, 'validwithoutprefix' => false, 'autoloaded' => true, 'classname' => '\\output\\' . $component . '\\' . $subtype . '_renderer');
         // Version of the above with subtype being a namespace level on it's own.
         $classnames[] = array('validwithprefix' => true, 'validwithoutprefix' => false, 'autoloaded' => true, 'classname' => '\\output\\' . $component . '\\' . $subtype . '\\renderer');
         // Standard autoloaded plugin name (not valid with a prefix).
         $classnames[] = array('validwithprefix' => false, 'validwithoutprefix' => true, 'autoloaded' => true, 'classname' => '\\' . $component . '\\output\\' . $subtype . '_renderer');
         // Version of the above with subtype being a namespace level on it's own.
         $classnames[] = array('validwithprefix' => false, 'validwithoutprefix' => true, 'autoloaded' => true, 'classname' => '\\' . $component . '\\output\\' . $subtype . '\\renderer');
         // Legacy class name - (valid with or without a prefix).
         $classnames[] = array('validwithprefix' => true, 'validwithoutprefix' => true, 'autoloaded' => false, 'classname' => $component . '_' . $subtype . '_renderer');
     }
     return $classnames;
 }
Ejemplo n.º 9
0
 /**
  * Returns all the subsystems having 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.
  *
  * @param string $testtype The kind of test we are looking for
  * @return array all the subsystems having tests
  */
 private static function get_all_subsystems_with_tests($testtype)
 {
     global $CFG;
     $subsystemswithtests = array();
     $subsystems = core_component::get_core_subsystems();
     // Hack the list a bit to cover some well-known ones
     $subsystems['backup'] = $CFG->dirroot . '/backup';
     $subsystems['db-dml'] = $CFG->dirroot . '/lib/dml';
     $subsystems['db-ddl'] = $CFG->dirroot . '/lib/ddl';
     ksort($subsystems);
     foreach ($subsystems as $subsys => $fullsubsys) {
         if ($fullsubsys === null) {
             continue;
         }
         if (!is_dir($fullsubsys)) {
             continue;
         }
         // Look for tests recursively
         if (self::directory_has_tests($fullsubsys, $testtype)) {
             $subsystemswithtests['core_' . $subsys] = $fullsubsys;
         }
     }
     return $subsystemswithtests;
 }
Ejemplo n.º 10
0
 public function test_deprecated_get_component_directory()
 {
     $plugintypes = core_component::get_plugin_types();
     foreach ($plugintypes as $plugintype => $fulldir) {
         $plugins = core_component::get_plugin_list($plugintype);
         foreach ($plugins as $pluginname => $plugindir) {
             $this->assertSame($plugindir, get_component_directory($plugintype . '_' . $pluginname));
         }
     }
     $subsystems = core_component::get_core_subsystems();
     foreach ($subsystems as $subsystem => $fulldir) {
         $this->assertSame($fulldir, get_component_directory('core_' . $subsystem));
     }
 }
Ejemplo n.º 11
0
 /**
  * Return the list of available search areas.
  *
  * @param bool $enabled Return only the enabled ones.
  * @return \core_search\area\base[]
  */
 public static function get_search_areas_list($enabled = false)
 {
     // Two different arrays, we don't expect these arrays to be big.
     if (!$enabled && static::$allsearchareas !== null) {
         return static::$allsearchareas;
     } else {
         if ($enabled && static::$enabledsearchareas !== null) {
             return static::$enabledsearchareas;
         }
     }
     $searchareas = array();
     $plugintypes = \core_component::get_plugin_types();
     foreach ($plugintypes as $plugintype => $unused) {
         $plugins = \core_component::get_plugin_list($plugintype);
         foreach ($plugins as $pluginname => $pluginfullpath) {
             $componentname = $plugintype . '_' . $pluginname;
             $searchclasses = \core_component::get_component_classes_in_namespace($componentname, 'search');
             foreach ($searchclasses as $classname => $classpath) {
                 $areaname = substr(strrchr($classname, '\\'), 1);
                 $areaid = static::generate_areaid($componentname, $areaname);
                 $searchclass = new $classname();
                 if (!$enabled || $enabled && $searchclass->is_enabled()) {
                     $searchareas[$areaid] = $searchclass;
                 }
             }
         }
     }
     $subsystems = \core_component::get_core_subsystems();
     foreach ($subsystems as $subsystemname => $subsystempath) {
         $componentname = 'core_' . $subsystemname;
         $searchclasses = \core_component::get_component_classes_in_namespace($componentname, 'search');
         foreach ($searchclasses as $classname => $classpath) {
             $areaname = substr(strrchr($classname, '\\'), 1);
             $areaid = static::generate_areaid($componentname, $areaname);
             $searchclass = new $classname();
             if (!$enabled || $enabled && $searchclass->is_enabled()) {
                 $searchareas[$areaid] = $searchclass;
             }
         }
     }
     // Cache results.
     if ($enabled) {
         static::$enabledsearchareas = $searchareas;
     } else {
         static::$allsearchareas = $searchareas;
     }
     return $searchareas;
 }
Ejemplo n.º 12
0
    if (function_exists('opcache_reset')) {
        opcache_reset();
    }
    $cache = 0;
} else {
    $cache = 1;
}
require '../config.php';
// Invalidate the cache of version.php in any circumstances to help core_component
// detecting if the version has changed and component cache should be reset.
if (function_exists('opcache_invalidate')) {
    opcache_invalidate($CFG->dirroot . '/version.php', true);
}
// Make sure the component cache gets rebuilt if necessary, any method that
// indirectly calls the protected init() method is good here.
core_component::get_core_subsystems();
require_once $CFG->libdir . '/adminlib.php';
// various admin-only functions
require_once $CFG->libdir . '/upgradelib.php';
// general upgrade/install related functions
$confirmupgrade = optional_param('confirmupgrade', 0, PARAM_BOOL);
$confirmrelease = optional_param('confirmrelease', 0, PARAM_BOOL);
$confirmplugins = optional_param('confirmplugincheck', 0, PARAM_BOOL);
$showallplugins = optional_param('showallplugins', 0, PARAM_BOOL);
$agreelicense = optional_param('agreelicense', 0, PARAM_BOOL);
$fetchupdates = optional_param('fetchupdates', 0, PARAM_BOOL);
$newaddonreq = optional_param('installaddonrequest', null, PARAM_RAW);
// Set up PAGE.
$url = new moodle_url('/admin/index.php');
$url->param('cache', $cache);
$PAGE->set_url($url);
Ejemplo n.º 13
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.
  * @throws coding_exception
  */
 protected function standard_renderer_classname($component, $subtype = null)
 {
     global $CFG;
     // Needed in included files.
     // Standardize component name ala frankenstyle.
     list($plugin, $type) = core_component::normalize_component($component);
     if ($type === null) {
         $component = $plugin;
     } else {
         $component = $plugin . '_' . $type;
     }
     if ($component !== 'core') {
         // Renderers are stored in renderer.php files.
         if (!($compdirectory = core_component::get_component_directory($component))) {
             throw new coding_exception('Invalid component specified in renderer request', $component);
         }
         $rendererfile = $compdirectory . '/renderer.php';
         if (file_exists($rendererfile)) {
             include_once $rendererfile;
         }
     } else {
         if (!empty($subtype)) {
             $coresubsystems = core_component::get_core_subsystems();
             if (!array_key_exists($subtype, $coresubsystems)) {
                 // There may be nulls.
                 throw new coding_exception('Invalid core subtype "' . $subtype . '" in renderer request', $subtype);
             }
             if ($coresubsystems[$subtype]) {
                 $rendererfile = $coresubsystems[$subtype] . '/renderer.php';
                 if (file_exists($rendererfile)) {
                     include_once $rendererfile;
                 }
             }
         }
     }
     if (empty($subtype)) {
         $class = $component . '_renderer';
     } else {
         $class = $component . '_' . $subtype . '_renderer';
     }
     return $class;
 }