Ejemplo n.º 1
0
 public function run($command)
 {
     global $CFG;
     $data = $CFG->dataroot . '/tool_composer';
     $composerfile = $data . '/composer.json';
     if (!is_writable($data)) {
         throw new \moodle_exception('notwritable');
     }
     if (!file_exists($data)) {
         mkdir($data, $CFG->directorypermissions, true);
     }
     $vendordir = $data . '/vendor';
     $autoloadphp = '$CFG->dataroot . \'tool_composer/vendor/autoload.php\'';
     if ($this->installincodebase) {
         $vendordir = $CFG->dirroot . '/lib/vendor';
         $autoloadphp = '$CFG->dirroot . \'/lib/vendor/autoload.php\'';
     }
     $composer = new \stdClass();
     $composer->require = ['wikimedia/composer-merge-plugin' => '^1.3'];
     $include = [];
     foreach (\core_component::get_plugin_types() as $type => $dir) {
         $plugins = \core_component::get_plugin_list_with_file($type, 'composer.json');
         foreach ($plugins as $pluginname => $filepath) {
             // Ignore this plugin
             if ($type == 'tool' && $pluginname == 'composer') {
                 continue;
             }
             $include[] = $filepath;
             // Overwrite the autoload files if necessary
             $autoload = dirname($filepath) . '/vendor/autoload.php';
             if (file_exists($autoload)) {
                 if (!is_writable($autoload)) {
                     throw new \moodle_exception('notwritable');
                 }
                 // Back up the file if we haven't done so already.
                 if (!file_exists($autoload . '.bak')) {
                     file_put_contents($autoload . '.bak', file_get_contents($autoload));
                 }
                 file_put_contents($autoload, '<?php require_once ' . $autoloadphp . ';');
             }
         }
     }
     $composer->extra = (object) ['merge-plugin' => (object) ['include' => $include]];
     file_put_contents($composerfile, json_encode($composer));
     putenv('COMPOSER=' . $composerfile);
     putenv('COMPOSER_VENDOR_DIR=' . $vendordir);
     if ($this->installincodebase) {
         // Allow us to install Moodle plugins into the codebase
         chdir($CFG->dirroot);
     }
     // TODO: We may want to force --no-dev here for install / update
     passthru('composer --no-interaction ' . $command);
 }
Ejemplo n.º 2
0
 public function load_choices()
 {
     if (is_array($this->choices)) {
         return true;
     }
     $this->choices = array('mathjax' => get_string('settingmathsdisplay_mathjax', 'qtype_stack'));
     // Remove this if statement once we no longer need to support Moodle 2.5.x.
     if (class_exists('core_component') && method_exists('core_component', 'get_plugin_list_with_file')) {
         $filters = core_component::get_plugin_list_with_file('filter', 'filter.php');
     } else {
         $filters = get_plugin_list_with_file('filter', 'filter.php');
     }
     if (array_key_exists('tex', $filters)) {
         $this->choices['tex'] = get_string('settingmathsdisplay_tex', 'qtype_stack');
     }
     if (array_key_exists('maths', $filters)) {
         $this->choices['maths'] = get_string('settingmathsdisplay_maths', 'qtype_stack');
     }
     return true;
 }
Ejemplo n.º 3
0
 /**
  * Returns the list of available grading evaluation methods
  *
  * @return array of (string)name => (string)localized title
  */
 public static function available_evaluators_list()
 {
     $evals = array();
     foreach (core_component::get_plugin_list_with_file('workshopeval', 'lib.php', false) as $eval => $evalpath) {
         $evals[$eval] = get_string('pluginname', 'workshopeval_' . $eval);
     }
     return $evals;
 }
Ejemplo n.º 4
0
/**
 * Get a list of all the plugins that define a certain API function in a certain file.
 *
 * @param string $function the part of the name of the function after the
 *      frankenstyle prefix. e.g 'hook' if you are looking for functions with
 *      names like report_courselist_hook.
 * @param string $file the name of file within the plugin that defines the
 *      function. Defaults to lib.php.
 * @param bool $include Whether to include the files that contain the functions or not.
 * @return array with [plugintype][plugin] = functionname
 */
function get_plugins_with_function($function, $file = 'lib.php', $include = true)
{
    global $CFG;
    $cache = \cache::make('core', 'plugin_functions');
    // Including both although I doubt that we will find two functions definitions with the same name.
    // Clearning the filename as cache_helper::hash_key only allows a-zA-Z0-9_.
    $key = $function . '_' . clean_param($file, PARAM_ALPHA);
    if ($pluginfunctions = $cache->get($key)) {
        // Checking that the files are still available.
        foreach ($pluginfunctions as $plugintype => $plugins) {
            $allplugins = \core_component::get_plugin_list($plugintype);
            foreach ($plugins as $plugin => $fullpath) {
                // Cache might be out of sync with the codebase, skip the plugin if it is not available.
                if (empty($allplugins[$plugin])) {
                    unset($pluginfunctions[$plugintype][$plugin]);
                    continue;
                }
                $fileexists = file_exists($allplugins[$plugin] . DIRECTORY_SEPARATOR . $file);
                if ($include && $fileexists) {
                    // Include the files if it was requested.
                    include_once $allplugins[$plugin] . DIRECTORY_SEPARATOR . $file;
                } else {
                    if (!$fileexists) {
                        // If the file is not available any more it should not be returned.
                        unset($pluginfunctions[$plugintype][$plugin]);
                    }
                }
            }
        }
        return $pluginfunctions;
    }
    $pluginfunctions = array();
    // To fill the cached. Also, everything should continue working with cache disabled.
    $plugintypes = \core_component::get_plugin_types();
    foreach ($plugintypes as $plugintype => $unused) {
        // We need to include files here.
        $pluginswithfile = \core_component::get_plugin_list_with_file($plugintype, $file, true);
        foreach ($pluginswithfile as $plugin => $notused) {
            $fullfunction = $plugintype . '_' . $plugin . '_' . $function;
            $pluginfunction = false;
            if (function_exists($fullfunction)) {
                // Function exists with standard name. Store, indexed by frankenstyle name of plugin.
                $pluginfunction = $fullfunction;
            } else {
                if ($plugintype === 'mod') {
                    // For modules, we also allow plugin without full frankenstyle but just starting with the module name.
                    $shortfunction = $plugin . '_' . $function;
                    if (function_exists($shortfunction)) {
                        $pluginfunction = $shortfunction;
                    }
                }
            }
            if ($pluginfunction) {
                if (empty($pluginfunctions[$plugintype])) {
                    $pluginfunctions[$plugintype] = array();
                }
                $pluginfunctions[$plugintype][$plugin] = $pluginfunction;
            }
        }
    }
    $cache->set($key, $pluginfunctions);
    return $pluginfunctions;
}
Ejemplo n.º 5
0
/**
 * Get a list of all the plugins of a given type that define a certain API function
 * in a certain file. The plugin component names and function names are returned.
 *
 * @param string $plugintype the type of plugin, e.g. 'mod' or 'report'.
 * @param string $function the part of the name of the function after the
 *      frankenstyle prefix. e.g 'hook' if you are looking for functions with
 *      names like report_courselist_hook.
 * @param string $file the name of file within the plugin that defines the
 *      function. Defaults to lib.php.
 * @return array with frankenstyle plugin names as keys (e.g. 'report_courselist', 'mod_forum')
 *      and the function names as values (e.g. 'report_courselist_hook', 'forum_hook').
 */
function get_plugin_list_with_function($plugintype, $function, $file = 'lib.php')
{
    $pluginfunctions = array();
    $pluginswithfile = core_component::get_plugin_list_with_file($plugintype, $file, true);
    foreach ($pluginswithfile as $plugin => $notused) {
        $fullfunction = $plugintype . '_' . $plugin . '_' . $function;
        if (function_exists($fullfunction)) {
            // Function exists with standard name. Store, indexed by frankenstyle name of plugin.
            $pluginfunctions[$plugintype . '_' . $plugin] = $fullfunction;
        } else {
            if ($plugintype === 'mod') {
                // For modules, we also allow plugin without full frankenstyle but just starting with the module name.
                $shortfunction = $plugin . '_' . $function;
                if (function_exists($shortfunction)) {
                    $pluginfunctions[$plugintype . '_' . $plugin] = $shortfunction;
                }
            }
        }
    }
    return $pluginfunctions;
}
 /**
  * Returns an array of information about plugins, everything a renderer needs.
  * @return array
  */
 public static function get_store_plugin_summaries()
 {
     $return = array();
     $plugins = core_component::get_plugin_list_with_file('cachestore', 'lib.php', true);
     foreach ($plugins as $plugin => $path) {
         $class = 'cachestore_' . $plugin;
         $return[$plugin] = array('name' => get_string('pluginname', 'cachestore_' . $plugin), 'requirementsmet' => $class::are_requirements_met(), 'instances' => 0, 'modes' => array(cache_store::MODE_APPLICATION => $class::get_supported_modes() & cache_store::MODE_APPLICATION, cache_store::MODE_SESSION => $class::get_supported_modes() & cache_store::MODE_SESSION, cache_store::MODE_REQUEST => $class::get_supported_modes() & cache_store::MODE_REQUEST), 'supports' => array('multipleidentifiers' => $class::get_supported_features() & cache_store::SUPPORTS_MULTIPLE_IDENTIFIERS, 'dataguarantee' => $class::get_supported_features() & cache_store::SUPPORTS_DATA_GUARANTEE, 'nativettl' => $class::get_supported_features() & cache_store::SUPPORTS_NATIVE_TTL, 'nativelocking' => in_array('cache_is_lockable', class_implements($class)), 'keyawareness' => array_key_exists('cache_is_key_aware', class_implements($class))), 'canaddinstance' => $class::can_add_instance() && $class::are_requirements_met());
     }
     $instance = cache_config::instance();
     $stores = $instance->get_all_stores();
     foreach ($stores as $store) {
         $plugin = $store['plugin'];
         if (array_key_exists($plugin, $return)) {
             $return[$plugin]['instances']++;
         }
     }
     return $return;
 }
Ejemplo n.º 7
0
/**
 * Get a list of all the plugins of a given type that contain a particular file.
 *
 * @param string $plugintype the type of plugin, e.g. 'mod' or 'report'.
 * @param string $file the name of file that must be present in the plugin.
 *      (e.g. 'view.php', 'db/install.xml').
 * @param bool $include if true (default false), the file will be include_once-ed if found.
 * @return array with plugin name as keys (e.g. 'forum', 'courselist') and the path
 *      to the file relative to dirroot as value (e.g. "$CFG->dirroot/mod/forum/view.php").
 * @deprecated since 2.6
 * @see core_component::get_plugin_list_with_file()
 */
function get_plugin_list_with_file($plugintype, $file, $include = false)
{
    debugging('get_plugin_list_with_file() is deprecated, please use core_component::get_plugin_list_with_file() instead.', DEBUG_DEVELOPER);
    return core_component::get_plugin_list_with_file($plugintype, $file, $include);
}
Ejemplo n.º 8
0
 /**
  * Initialises the navigation object.
  *
  * This causes the navigation object to look at the current state of the page
  * that it is associated with and then load the appropriate content.
  *
  * This should only occur the first time that the navigation structure is utilised
  * which will normally be either when the navbar is called to be displayed or
  * when a block makes use of it.
  *
  * @return bool
  */
 public function initialise()
 {
     global $CFG, $SITE, $USER;
     // Check if it has already been initialised
     if ($this->initialised || during_initial_install()) {
         return true;
     }
     $this->initialised = true;
     // Set up the five base root nodes. These are nodes where we will put our
     // content and are as follows:
     // site: Navigation for the front page.
     // myprofile: User profile information goes here.
     // currentcourse: The course being currently viewed.
     // mycourses: The users courses get added here.
     // courses: Additional courses are added here.
     // users: Other users information loaded here.
     $this->rootnodes = array();
     if (get_home_page() == HOMEPAGE_SITE) {
         // The home element should be my moodle because the root element is the site
         if (isloggedin() && !isguestuser()) {
             // Makes no sense if you aren't logged in
             $this->rootnodes['home'] = $this->add(get_string('myhome'), new moodle_url('/my/'), self::TYPE_SETTING, null, 'home');
         }
     } else {
         // The home element should be the site because the root node is my moodle
         $this->rootnodes['home'] = $this->add(get_string('sitehome'), new moodle_url('/'), self::TYPE_SETTING, null, 'home');
         if (!empty($CFG->defaulthomepage) && $CFG->defaulthomepage == HOMEPAGE_MY) {
             // We need to stop automatic redirection
             $this->rootnodes['home']->action->param('redirect', '0');
         }
     }
     $this->rootnodes['site'] = $this->add_course($SITE);
     $this->rootnodes['myprofile'] = $this->add(get_string('myprofile'), null, self::TYPE_USER, null, 'myprofile');
     $this->rootnodes['currentcourse'] = $this->add(get_string('currentcourse'), null, self::TYPE_ROOTNODE, null, 'currentcourse');
     $this->rootnodes['mycourses'] = $this->add(get_string('mycourses'), new moodle_url('/my/'), self::TYPE_ROOTNODE, null, 'mycourses');
     $this->rootnodes['courses'] = $this->add(get_string('courses'), new moodle_url('/course/index.php'), self::TYPE_ROOTNODE, null, 'courses');
     $this->rootnodes['users'] = $this->add(get_string('users'), null, self::TYPE_ROOTNODE, null, 'users');
     // We always load the frontpage course to ensure it is available without
     // JavaScript enabled.
     $this->add_front_page_course_essentials($this->rootnodes['site'], $SITE);
     $this->load_course_sections($SITE, $this->rootnodes['site']);
     $course = $this->page->course;
     // $issite gets set to true if the current pages course is the sites frontpage course
     $issite = $this->page->course->id == $SITE->id;
     // Determine if the user is enrolled in any course.
     $enrolledinanycourse = enrol_user_sees_own_courses();
     $this->rootnodes['currentcourse']->mainnavonly = true;
     if ($enrolledinanycourse) {
         $this->rootnodes['mycourses']->isexpandable = true;
         if ($CFG->navshowallcourses) {
             // When we show all courses we need to show both the my courses and the regular courses branch.
             $this->rootnodes['courses']->isexpandable = true;
         }
     } else {
         $this->rootnodes['courses']->isexpandable = true;
     }
     if ($this->rootnodes['mycourses']->isactive) {
         $this->load_courses_enrolled();
     }
     $canviewcourseprofile = true;
     // Next load context specific content into the navigation
     switch ($this->page->context->contextlevel) {
         case CONTEXT_SYSTEM:
             // Nothing left to do here I feel.
             break;
         case CONTEXT_COURSECAT:
             // This is essential, we must load categories.
             $this->load_all_categories($this->page->context->instanceid, true);
             break;
         case CONTEXT_BLOCK:
         case CONTEXT_COURSE:
             if ($issite) {
                 // Nothing left to do here.
                 break;
             }
             // Load the course associated with the current page into the navigation.
             $coursenode = $this->add_course($course, false, self::COURSE_CURRENT);
             // If the course wasn't added then don't try going any further.
             if (!$coursenode) {
                 $canviewcourseprofile = false;
                 break;
             }
             // If the user is not enrolled then we only want to show the
             // course node and not populate it.
             // Not enrolled, can't view, and hasn't switched roles
             if (!can_access_course($course)) {
                 // Very ugly hack - do not force "parents" to enrol into course their child is enrolled in,
                 // this hack has been propagated from user/view.php to display the navigation node. (MDL-25805)
                 if (!$this->current_user_is_parent_role()) {
                     $coursenode->make_active();
                     $canviewcourseprofile = false;
                     break;
                 }
             }
             // Add the essentials such as reports etc...
             $this->add_course_essentials($coursenode, $course);
             // Extend course navigation with it's sections/activities
             $this->load_course_sections($course, $coursenode);
             if (!$coursenode->contains_active_node() && !$coursenode->search_for_active_node()) {
                 $coursenode->make_active();
             }
             break;
         case CONTEXT_MODULE:
             if ($issite) {
                 // If this is the site course then most information will have
                 // already been loaded.
                 // However we need to check if there is more content that can
                 // yet be loaded for the specific module instance.
                 $activitynode = $this->rootnodes['site']->find($this->page->cm->id, navigation_node::TYPE_ACTIVITY);
                 if ($activitynode) {
                     $this->load_activity($this->page->cm, $this->page->course, $activitynode);
                 }
                 break;
             }
             $course = $this->page->course;
             $cm = $this->page->cm;
             // Load the course associated with the page into the navigation
             $coursenode = $this->add_course($course, false, self::COURSE_CURRENT);
             // If the course wasn't added then don't try going any further.
             if (!$coursenode) {
                 $canviewcourseprofile = false;
                 break;
             }
             // If the user is not enrolled then we only want to show the
             // course node and not populate it.
             if (!can_access_course($course)) {
                 $coursenode->make_active();
                 $canviewcourseprofile = false;
                 break;
             }
             $this->add_course_essentials($coursenode, $course);
             // Load the course sections into the page
             $this->load_course_sections($course, $coursenode, null, $cm);
             $activity = $coursenode->find($cm->id, navigation_node::TYPE_ACTIVITY);
             if (!empty($activity)) {
                 // Finally load the cm specific navigaton information
                 $this->load_activity($cm, $course, $activity);
                 // Check if we have an active ndoe
                 if (!$activity->contains_active_node() && !$activity->search_for_active_node()) {
                     // And make the activity node active.
                     $activity->make_active();
                 }
             }
             break;
         case CONTEXT_USER:
             if ($issite) {
                 // The users profile information etc is already loaded
                 // for the front page.
                 break;
             }
             $course = $this->page->course;
             // Load the course associated with the user into the navigation
             $coursenode = $this->add_course($course, false, self::COURSE_CURRENT);
             // If the course wasn't added then don't try going any further.
             if (!$coursenode) {
                 $canviewcourseprofile = false;
                 break;
             }
             // If the user is not enrolled then we only want to show the
             // course node and not populate it.
             if (!can_access_course($course)) {
                 $coursenode->make_active();
                 $canviewcourseprofile = false;
                 break;
             }
             $this->add_course_essentials($coursenode, $course);
             $this->load_course_sections($course, $coursenode);
             break;
     }
     // Load for the current user
     $this->load_for_user();
     if ($this->page->context->contextlevel >= CONTEXT_COURSE && $this->page->context->instanceid != $SITE->id && $canviewcourseprofile) {
         $this->load_for_user(null, true);
     }
     // Load each extending user into the navigation.
     foreach ($this->extendforuser as $user) {
         if ($user->id != $USER->id) {
             $this->load_for_user($user);
         }
     }
     // Give the local plugins a chance to include some navigation if they want.
     foreach (core_component::get_plugin_list_with_file('local', 'lib.php', true) as $plugin => $file) {
         $function = "local_{$plugin}_extends_navigation";
         $oldfunction = "{$plugin}_extends_navigation";
         if (function_exists($function)) {
             // This is the preferred function name as there is less chance of conflicts
             $function($this);
         } else {
             if (function_exists($oldfunction)) {
                 // We continue to support the old function name to ensure backwards compatibility
                 debugging("Deprecated local plugin navigation callback: Please rename '{$oldfunction}' to '{$function}'. Support for the old callback will be dropped after the release of 2.4", DEBUG_DEVELOPER);
                 $oldfunction($this);
             }
         }
     }
     // Remove any empty root nodes
     foreach ($this->rootnodes as $node) {
         // Dont remove the home node
         /** @var navigation_node $node */
         if ($node->key !== 'home' && !$node->has_children() && !$node->isactive) {
             $node->remove();
         }
     }
     if (!$this->contains_active_node()) {
         $this->search_for_active_node();
     }
     // If the user is not logged in modify the navigation structure as detailed
     // in {@link http://docs.moodle.org/dev/Navigation_2.0_structure}
     if (!isloggedin()) {
         $activities = clone $this->rootnodes['site']->children;
         $this->rootnodes['site']->remove();
         $children = clone $this->children;
         $this->children = new navigation_node_collection();
         foreach ($activities as $child) {
             $this->children->add($child);
         }
         foreach ($children as $child) {
             $this->children->add($child);
         }
     }
     return true;
 }
Ejemplo n.º 9
0
 public function test_get_plugin_list_with_file()
 {
     $this->resetAfterTest(true);
     // No extra reset here because core_component reset automatically.
     $expected = array();
     $reports = core_component::get_plugin_list('report');
     foreach ($reports as $name => $fulldir) {
         if (file_exists("{$fulldir}/lib.php")) {
             $expected[] = $name;
         }
     }
     // Test cold.
     $list = core_component::get_plugin_list_with_file('report', 'lib.php', false);
     $this->assertEquals($expected, array_keys($list));
     // Test hot.
     $list = core_component::get_plugin_list_with_file('report', 'lib.php', false);
     $this->assertEquals($expected, array_keys($list));
     // Test with include.
     $list = core_component::get_plugin_list_with_file('report', 'lib.php', true);
     $this->assertEquals($expected, array_keys($list));
     // Test missing.
     $list = core_component::get_plugin_list_with_file('report', 'idontexist.php', true);
     $this->assertEquals(array(), array_keys($list));
 }
/**
 * Get a list of folders to ignores.
 *
 * @param string $extraignorelist optional comma separated list of substring matching paths to ignore.
 * @return array of paths.
 */
function local_codesniffer_get_ignores($extraignorelist = '')
{
    global $CFG;
    $files = array();
    // XML files to be processed.
    $paths = array();
    // Absolute paths to be excluded.
    $files['core'] = $CFG->libdir . DIRECTORY_SEPARATOR . '/thirdpartylibs.xml';
    // This one always exists.
    // With MDL-42148, for 2.6 and upwards, the general 'thirdpartylibs.xml' file
    // has been split so any plugin with dependencies can have its own. In order to
    // keep master compatibility with older branches we are doing some
    // conditional coding here.
    if (file_exists($CFG->dirroot . '/' . $CFG->admin . '/' . 'thirdpartylibs.php')) {
        // New behavior, distributed XML files, let's look for them.
        $plugintypes = core_component::get_plugin_types();
        foreach ($plugintypes as $type => $ignored) {
            $plugins = core_component::get_plugin_list_with_file($type, 'thirdpartylibs.xml', false);
            foreach ($plugins as $plugin => $path) {
                $files[$type . '_' . $plugin] = $path;
            }
        }
    }
    // Let's extract all the paths from the XML files.
    foreach ($files as $file) {
        $base = realpath(dirname($file));
        $thirdparty = simplexml_load_file($file);
        foreach ($thirdparty->xpath('/libraries/library/location') as $location) {
            $location = substr($base, strlen($CFG->dirroot)) . '/' . $location;
            // This was happening since ages ago, leading to incorrect excluded
            // paths like: "/lib/theme/bootstrapbase/less/bootstrap", so we try
            // reducing it. Note this does not affect 2.6 and up, where all
            // locations are relative to their xml file so this problem cannot happen.
            if (!file_exists(dirname($CFG->dirroot . DIRECTORY_SEPARATOR . $location))) {
                // Only if it starts with '/lib'.
                if (strpos($location, DIRECTORY_SEPARATOR . 'lib') === 0) {
                    $candidate = substr($location, strlen(DIRECTORY_SEPARATOR . 'lib'));
                    // Only modify the original location if the candidate exists.
                    if (file_exists(dirname($CFG->dirroot . DIRECTORY_SEPARATOR . $candidate))) {
                        $location = $candidate;
                    }
                }
            }
            // Accept only correct paths from XML files.
            if (file_exists(dirname($CFG->dirroot . DIRECTORY_SEPARATOR . $location))) {
                $paths[] = preg_quote(local_codechecker_clean_path($location));
            } else {
                debugging("Processing {$file} for exclussions, incorrect {$location} path found. Please fix it");
            }
        }
    }
    // Manually add our own pear stuff to be excluded.
    $paths[] = preg_quote(local_codechecker_clean_path('/local/codechecker' . DIRECTORY_SEPARATOR . 'pear'));
    // Changed in PHP_CodeSniffer 1.4.4 and upwards, so we apply the
    // same here: Paths go to keys and mark all them as 'absolute'.
    $finalpaths = array();
    foreach ($paths as $pattern) {
        $finalpaths[$pattern] = 'absolute';
    }
    // Let's add any substring matching path passed in $extraignorelist.
    if ($extraignorelist) {
        $extraignorearr = explode(',', $extraignorelist);
        foreach ($extraignorearr as $extraignore) {
            $extrapath = trim($extraignore);
            $finalpaths[$extrapath] = 'absolute';
        }
    }
    return $finalpaths;
}
Ejemplo n.º 11
0
 /**
  * Get all modules that triggers a course_module_viewed event
  *
  * @return array of mod names
  */
 public static function get_mods_with_viewed_event()
 {
     global $DB;
     $mods = \core_component::get_plugin_list_with_file('mod', 'classes/event/course_module_viewed.php');
     return array_keys($mods);
 }
Ejemplo n.º 12
0
/**
 * This function will check for everything (DB, PHP and PHP extensions for now)
 * returning an array of environment_result objects.
 *
 * @global object
 * @param string $version xml version we are going to use to test this server
 * @param int $env_select one of ENV_SELECT_NEWER | ENV_SELECT_DATAROOT | ENV_SELECT_RELEASE decide xml to use.
 * @return environment_results[] array of results encapsulated in one environment_result object
 */
function environment_check($version, $env_select)
{
    global $CFG;
    if ($env_select != ENV_SELECT_NEWER and $env_select != ENV_SELECT_DATAROOT and $env_select != ENV_SELECT_RELEASE) {
        throw new coding_exception('Incorrect value of $env_select parameter');
    }
    /// Normalize the version requested
    $version = normalize_version($version);
    $results = array();
    //To store all the results
    /// Only run the moodle versions checker on upgrade, not on install
    if (!empty($CFG->version)) {
        $results[] = environment_check_moodle($version, $env_select);
    }
    $results[] = environment_check_unicode($version, $env_select);
    $results[] = environment_check_database($version, $env_select);
    $results[] = environment_check_php($version, $env_select);
    if ($result = environment_check_pcre_unicode($version, $env_select)) {
        $results[] = $result;
    }
    $phpext_results = environment_check_php_extensions($version, $env_select);
    $results = array_merge($results, $phpext_results);
    $phpsetting_results = environment_check_php_settings($version, $env_select);
    $results = array_merge($results, $phpsetting_results);
    $custom_results = environment_custom_checks($version, $env_select);
    $results = array_merge($results, $custom_results);
    // Always use the plugin directory version of environment.xml,
    // add-on developers need to keep those up-to-date with future info.
    foreach (core_component::get_plugin_types() as $plugintype => $unused) {
        foreach (core_component::get_plugin_list_with_file($plugintype, 'environment.xml') as $pluginname => $unused) {
            $plugin = $plugintype . '_' . $pluginname;
            $result = environment_check_database($version, $plugin);
            if ($result->error_code != NO_VERSION_DATA_FOUND and $result->error_code != NO_DATABASE_SECTION_FOUND and $result->error_code != NO_DATABASE_VENDORS_FOUND) {
                $result->plugin = $plugin;
                $results[] = $result;
            }
            $result = environment_check_php($version, $plugin);
            if ($result->error_code != NO_VERSION_DATA_FOUND and $result->error_code != NO_PHP_SECTION_FOUND and $result->error_code != NO_PHP_VERSION_FOUND) {
                $result->plugin = $plugin;
                $results[] = $result;
            }
            $pluginresults = environment_check_php_extensions($version, $plugin);
            foreach ($pluginresults as $result) {
                if ($result->error_code != NO_VERSION_DATA_FOUND and $result->error_code != NO_PHP_EXTENSIONS_SECTION_FOUND) {
                    $result->plugin = $plugin;
                    $results[] = $result;
                }
            }
            $pluginresults = environment_check_php_settings($version, $plugin);
            foreach ($pluginresults as $result) {
                if ($result->error_code != NO_VERSION_DATA_FOUND) {
                    $result->plugin = $plugin;
                    $results[] = $result;
                }
            }
            $pluginresults = environment_custom_checks($version, $plugin);
            foreach ($pluginresults as $result) {
                if ($result->error_code != NO_VERSION_DATA_FOUND) {
                    $result->plugin = $plugin;
                    $results[] = $result;
                }
            }
        }
    }
    return $results;
}
Ejemplo n.º 13
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.º 14
0
 * List of 3rd party libs used in moodle and all plugins.
 *
 * @package   admin
 * @copyright 2013 Petr Skoda {@link http://skodak.org}
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once '../config.php';
require_once $CFG->libdir . '/adminlib.php';
require_once $CFG->libdir . '/tablelib.php';
admin_externalpage_setup('thirdpartylibs');
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('thirdpartylibs', 'core_admin'));
$files = array('core' => "{$CFG->libdir}/thirdpartylibs.xml");
$plugintypes = core_component::get_plugin_types();
foreach ($plugintypes as $type => $ignored) {
    $plugins = core_component::get_plugin_list_with_file($type, 'thirdpartylibs.xml', false);
    foreach ($plugins as $plugin => $path) {
        $files[$type . '_' . $plugin] = $path;
    }
}
$table = new html_table();
$table->head = array(get_string('thirdpartylibrary', 'core_admin'), get_string('version'), get_string('thirdpartylibrarylocation', 'core_admin'), get_string('license'));
$table->align = array('left', 'left', 'left', 'left');
$table->id = 'thirdpartylibs';
$table->attributes['class'] = 'admintable generaltable';
$table->data = array();
foreach ($files as $component => $xmlpath) {
    $xml = simplexml_load_file($xmlpath);
    foreach ($xml as $lib) {
        $base = realpath(dirname($xmlpath));
        $location = substr($base, strlen($CFG->dirroot)) . '/' . $lib->location;
Ejemplo n.º 15
0
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
defined('MOODLE_INTERNAL') || die;
require_once $CFG->dirroot . '/mod/quiz/lib.php';
// First get a list of quiz reports with there own settings pages. If there none,
// we use a simpler overall menu structure.
$reports = core_component::get_plugin_list_with_file('quiz', 'settings.php', false);
$reportsbyname = array();
foreach ($reports as $report => $reportdir) {
    $strreportname = get_string($report . 'report', 'quiz_' . $report);
    $reportsbyname[$strreportname] = $report;
}
core_collator::ksort($reportsbyname);
// First get a list of quiz reports with there own settings pages. If there none,
// we use a simpler overall menu structure.
$rules = core_component::get_plugin_list_with_file('quizaccess', 'settings.php', false);
$rulesbyname = array();
foreach ($rules as $rule => $ruledir) {
    $strrulename = get_string('pluginname', 'quizaccess_' . $rule);
    $rulesbyname[$strrulename] = $rule;
}
core_collator::ksort($rulesbyname);
// Create the quiz settings page.
if (empty($reportsbyname) && empty($rulesbyname)) {
    $pagetitle = get_string('modulename', 'quiz');
} else {
    $pagetitle = get_string('generalsettings', 'admin');
}
$quizsettings = new admin_settingpage('modsettingquiz', $pagetitle, 'moodle/site:config');
if ($ADMIN->fulltree) {
    // Introductory explanation that all the settings are defaults for the add quiz form.
Ejemplo n.º 16
0
    $ADMIN->add('cache', new admin_externalpage('cacheconfig', new lang_string('cacheconfig', 'cache'), $CFG->wwwroot . '/cache/admin.php'));
    $ADMIN->add('cache', new admin_externalpage('cachetestperformance', new lang_string('testperformance', 'cache'), $CFG->wwwroot . '/cache/testperformance.php'));
    $ADMIN->add('cache', new admin_category('cachestores', new lang_string('cachestores', 'cache')));
    foreach (core_component::get_plugin_list('cachestore') as $plugin => $path) {
        $settingspath = $path . '/settings.php';
        if (file_exists($settingspath)) {
            $settings = new admin_settingpage('cachestore_' . $plugin . '_settings', new lang_string('pluginname', 'cachestore_' . $plugin), 'moodle/site:config');
            include $settingspath;
            $ADMIN->add('cachestores', $settings);
        }
    }
}
// Add Calendar type settings.
if ($hassiteconfig) {
    $ADMIN->add('modules', new admin_category('calendartype', new lang_string('calendartypes', 'calendar')));
    foreach (core_component::get_plugin_list_with_file('calendartype', 'settings.php') as $plugin => $settingspath) {
        $settings = new admin_settingpage('calendartype_' . $plugin . '_settings', new lang_string('pluginname', 'calendartype_' . $plugin), 'moodle/site:config');
        include $settingspath;
        $ADMIN->add('calendartype', $settings);
    }
}
/// Add all local plugins - must be always last!
if ($hassiteconfig) {
    $ADMIN->add('modules', new admin_category('localplugins', new lang_string('localplugins')));
    $ADMIN->add('localplugins', new admin_externalpage('managelocalplugins', new lang_string('localpluginsmanage'), $CFG->wwwroot . '/' . $CFG->admin . '/localplugins.php'));
}
// Extend settings for each local plugin. Note that their settings may be in any part of the
// settings tree and may be visible not only for administrators.
foreach (core_plugin_manager::instance()->get_plugins_of_type('local') as $plugin) {
    /** @var \core\plugininfo\local $plugin */
    $plugin->load_settings($ADMIN, null, $hassiteconfig);
Ejemplo n.º 17
0
 /**
  * This function gives local plugins an opportunity to modify the settings navigation.
  */
 protected function load_local_plugin_settings()
 {
     foreach (core_component::get_plugin_list_with_file('local', 'lib.php', true) as $plugin => $unused) {
         $function = "local_{$plugin}_extend_settings_navigation";
         $oldfunction = "local_{$plugin}_extends_settings_navigation";
         if (function_exists($function)) {
             $function($this, $this->context);
         } else {
             if (function_exists($oldfunction)) {
                 debugging("Deprecated local plugin navigation callback: Please rename '{$oldfunction}' to '{$function}'. " . "Support for the old callback will be dropped in Moodle 3.1", DEBUG_DEVELOPER);
                 $oldfunction($this, $this->context);
             }
         }
     }
 }
Ejemplo n.º 18
0
$count = max($count, 0);
admin_externalpage_setup('cachetestperformance');
$applicationtable = new html_table();
$applicationtable->head = array(get_string('plugin', 'cache'), get_string('result', 'cache'), get_string('set', 'cache'), get_string('gethit', 'cache'), get_string('getmiss', 'cache'), get_string('delete', 'cache'));
$applicationtable->data = array();
$sessiontable = clone $applicationtable;
$requesttable = clone $applicationtable;
$application = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cache', 'applicationtest');
$session = cache_definition::load_adhoc(cache_store::MODE_SESSION, 'cache', 'sessiontest');
$request = cache_definition::load_adhoc(cache_store::MODE_REQUEST, 'cache', 'requesttest');
$strinvalidplugin = new lang_string('invalidplugin', 'cache');
$strunsupportedmode = new lang_string('unsupportedmode', 'cache');
$struntestable = new lang_string('untestable', 'cache');
$strtested = new lang_string('tested', 'cache');
$strnotready = new lang_string('storenotready', 'cache');
foreach (core_component::get_plugin_list_with_file('cachestore', 'lib.php', true) as $plugin => $path) {
    $class = 'cachestore_' . $plugin;
    $plugin = get_string('pluginname', 'cachestore_' . $plugin);
    if (!class_exists($class) || !method_exists($class, 'initialise_test_instance') || !$class::are_requirements_met()) {
        $applicationtable->data[] = array($plugin, $strinvalidplugin, '-', '-', '-', '-');
        $sessiontable->data[] = array($plugin, $strinvalidplugin, '-', '-', '-', '-');
        $requesttable->data[] = array($plugin, $strinvalidplugin, '-', '-', '-', '-');
        continue;
    }
    if (!$class::is_supported_mode(cache_store::MODE_APPLICATION)) {
        $applicationtable->data[] = array($plugin, $strunsupportedmode, '-', '-', '-', '-');
    } else {
        $store = $class::initialise_test_instance($application);
        if ($store === false) {
            $applicationtable->data[] = array($plugin, $struntestable, '-', '-', '-', '-');
        } else {