diff --git a/admin/auth.php b/admin/auth.php
index 7115ff04cf3..fbd9a7cd46d 100644
--- a/admin/auth.php
+++ b/admin/auth.php
@@ -19,9 +19,6 @@ $returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=manageauths";
$action = optional_param('action', '', PARAM_ACTION);
$auth = optional_param('auth', '', PARAM_SAFEDIR);
-// get currently installed and enabled auth plugins
-$authsavailable = get_list_of_plugins('auth');
-
get_enabled_auth_plugins(true); // fix the list of enabled auths
if (empty($CFG->auth)) {
$authsenabled = array();
diff --git a/admin/cron.php b/admin/cron.php
index 2af42acc751..eee679d26f3 100644
--- a/admin/cron.php
+++ b/admin/cron.php
@@ -183,9 +183,9 @@
// report includes cron.php with function report_reportname_cron() if it wishes
// to be cronned. It is up to cron.php to handle e.g. if it only needs to
// actually do anything occasionally.
- $reports = get_list_of_plugins($CFG->admin.'/report');
- foreach($reports as $report) {
- $cronfile = $CFG->dirroot.'/'.$CFG->admin.'/report/'.$report.'/cron.php';
+ $reports = get_plugin_list('report');
+ foreach($reports as $report => $reportdir) {
+ $cronfile = $reportdir.'/cron.php';
if (file_exists($cronfile)) {
require_once($cronfile);
$cronfunction = 'report_'.$report.'_cron';
@@ -506,10 +506,10 @@
}
// run gradebook import/export/report cron
- if ($gradeimports = get_list_of_plugins('grade/import')) {
- foreach ($gradeimports as $gradeimport) {
- if (file_exists($CFG->dirroot.'/grade/import/'.$gradeimport.'/lib.php')) {
- require_once($CFG->dirroot.'/grade/import/'.$gradeimport.'/lib.php');
+ if ($gradeimports = get_plugin_list('gradeimport')) {
+ foreach ($gradeimports as $gradeimport => $plugindir) {
+ if (file_exists($plugindir.'/lib.php')) {
+ require_once($plugindir.'/lib.php');
$cron_function = 'grade_import_'.$gradeimport.'_cron';
if (function_exists($cron_function)) {
mtrace("Processing gradebook import function $cron_function ...", '');
@@ -519,10 +519,10 @@
}
}
- if ($gradeexports = get_list_of_plugins('grade/export')) {
- foreach ($gradeexports as $gradeexport) {
- if (file_exists($CFG->dirroot.'/grade/export/'.$gradeexport.'/lib.php')) {
- require_once($CFG->dirroot.'/grade/export/'.$gradeexport.'/lib.php');
+ if ($gradeexports = get_plugin_list('gradeexport')) {
+ foreach ($gradeexports as $gradeexport => $plugindir) {
+ if (file_exists($plugindir.'/lib.php')) {
+ require_once($plugindir.'/lib.php');
$cron_function = 'grade_export_'.$gradeexport.'_cron';
if (function_exists($cron_function)) {
mtrace("Processing gradebook export function $cron_function ...", '');
@@ -532,10 +532,10 @@
}
}
- if ($gradereports = get_list_of_plugins('grade/report')) {
- foreach ($gradereports as $gradereport) {
- if (file_exists($CFG->dirroot.'/grade/report/'.$gradereport.'/lib.php')) {
- require_once($CFG->dirroot.'/grade/report/'.$gradereport.'/lib.php');
+ if ($gradereports = get_plugin_list('gradereport')) {
+ foreach ($gradereports as $gradereport => $plugindir) {
+ if (file_exists($plugindir.'/lib.php')) {
+ require_once($plugindir.'/lib.php');
$cron_function = 'grade_report_'.$gradereport.'_cron';
if (function_exists($cron_function)) {
mtrace("Processing gradebook report function $cron_function ...", '');
@@ -550,10 +550,13 @@
$fs->cron();
// run any customized cronjobs, if any
- // looking for functions in lib/local/cron.php
- if (file_exists($CFG->dirroot.'/local/cron.php')) {
- mtrace('Processing customized cron script ...', '');
- include_once($CFG->dirroot.'/local/cron.php');
+ if ($locals = get_plugin_list('local')) {
+ mtrace('Processing customized cron scripts ...', '');
+ foreach ($locals as $local => $localdir) {
+ if (file_exists("$localdir/cron.php")) {
+ include("$localdir/cron.php");
+ }
+ }
mtrace('done.');
}
diff --git a/admin/enrol.php b/admin/enrol.php
index bed502be41a..5e68bd10566 100644
--- a/admin/enrol.php
+++ b/admin/enrol.php
@@ -51,9 +51,9 @@
admin_externalpage_print_header();
- $modules = get_list_of_plugins("enrol");
+ $modules = get_plugin_list('enrol');
$options = array();
- foreach ($modules as $module) {
+ foreach ($modules as $module => $moduledir) {
$options[$module] = get_string("enrolname", "enrol_$module");
}
asort($options);
@@ -71,12 +71,11 @@
$table->width = '700';
$table->data = array();
- $modules = get_list_of_plugins("enrol");
$enabledplugins = explode(',', $CFG->enrol_plugins_enabled);
- foreach ($modules as $module) {
+ foreach ($modules as $module => $moduledir) {
// skip if directory is empty
- if (!file_exists("$CFG->dirroot/enrol/$module/enrol.php")) {
+ if (!file_exists("$moduledir/enrol.php")) {
continue;
}
diff --git a/admin/enrol_config.php b/admin/enrol_config.php
index cb48a975b4c..95990d454f4 100644
--- a/admin/enrol_config.php
+++ b/admin/enrol_config.php
@@ -34,8 +34,8 @@
unset($options);
- $modules = get_list_of_plugins("enrol");
- foreach ($modules as $module) {
+ $modules = get_plugin_list('enrol');
+ foreach ($modules as $module => $enroldir) {
$options[$module] = get_string("enrolname", "enrol_$module");
}
asort($options);
diff --git a/admin/report/unittest/test_tables.php b/admin/report/unittest/test_tables.php
index 6cbaaaa8ea9..c0baa05a363 100644
--- a/admin/report/unittest/test_tables.php
+++ b/admin/report/unittest/test_tables.php
@@ -83,10 +83,9 @@ die;die;die;
/// upgrade all plugins types
- $upgradedplugins = false;
$plugintypes = get_plugin_types();
- foreach ($plugintypes as $type=>$location) {
- $upgradedplugins = upgrade_plugins($type, $location) || $upgradedplugins;
+ foreach ($plugintypes as $type => $location) {
+ upgrade_plugins($type);
}
/// Check for changes to RPC functions
@@ -95,11 +94,6 @@ die;die;die;
upgrade_RPC_functions($return_url); // Return here afterwards
}
-/// Check for local database customisations
-/// first old *.php update and then the new upgrade.php script
- require_once("$CFG->dirroot/lib/locallib.php");
- upgrade_local_db($return_url); // Return here afterwards
-
/// just make sure upgrade logging is properly terminated
upgrade_finished();
diff --git a/admin/settings/courses.php b/admin/settings/courses.php
index a131cf4621e..a6b9073fb56 100644
--- a/admin/settings/courses.php
+++ b/admin/settings/courses.php
@@ -17,9 +17,9 @@ if ($hassiteconfig
/// NOTE: these settings must be applied after all other settings because they depend on them
///main course settings
$temp = new admin_settingpage('coursesettings', get_string('coursesettings'));
- $courseformats = get_list_of_plugins('course/format');
+ $courseformats = get_plugin_list('format');
$formcourseformats = array();
- foreach ($courseformats as $courseformat) {
+ foreach ($courseformats as $courseformat => $courseformatdir) {
$formcourseformats["$courseformat"] = get_string("format$courseformat","format_$courseformat");
if ($formcourseformats["$courseformat"]=="[[format$courseformat]]") {
$formcourseformats["$courseformat"] = get_string("format$courseformat");
diff --git a/admin/settings/grades.php b/admin/settings/grades.php
index ac902c48d76..414b79549b2 100644
--- a/admin/settings/grades.php
+++ b/admin/settings/grades.php
@@ -173,12 +173,12 @@ if (has_capability('moodle/grade:manage', $systemcontext)
// Reports
$ADMIN->add('grades', new admin_category('gradereports', get_string('reportsettings', 'grades')));
- foreach (get_list_of_plugins('grade/report') as $plugin) {
+ foreach (get_plugin_list('gradereport') as $plugin => $plugindir) {
// Include all the settings commands for this plugin if there are any
- if (file_exists($CFG->dirroot.'/grade/report/'.$plugin.'/settings.php')) {
+ if (file_exists($plugindir.'/settings.php')) {
$settings = new admin_settingpage('gradereport'.$plugin, get_string('modulename', 'gradereport_'.$plugin), 'moodle/grade:manage');
if ($ADMIN->fulltree) {
- include($CFG->dirroot.'/grade/report/'.$plugin.'/settings.php');
+ include($plugindir.'/settings.php');
}
$ADMIN->add('gradereports', $settings);
}
@@ -186,13 +186,13 @@ if (has_capability('moodle/grade:manage', $systemcontext)
// Imports
$ADMIN->add('grades', new admin_category('gradeimports', get_string('importsettings', 'grades')));
- foreach (get_list_of_plugins('grade/import') as $plugin) {
+ foreach (get_plugin_list('gradeimport') as $plugin => $plugindir) {
// Include all the settings commands for this plugin if there are any
- if (file_exists($CFG->dirroot.'/grade/import/'.$plugin.'/settings.php')) {
+ if (file_exists($plugindir.'/settings.php')) {
$settings = new admin_settingpage('gradeimport'.$plugin, get_string('modulename', 'gradeimport_'.$plugin), 'moodle/grade:manage');
if ($ADMIN->fulltree) {
- include($CFG->dirroot.'/grade/import/'.$plugin.'/settings.php');
+ include($plugindir.'/settings.php');
}
$ADMIN->add('gradeimports', $settings);
}
@@ -201,12 +201,12 @@ if (has_capability('moodle/grade:manage', $systemcontext)
// Exports
$ADMIN->add('grades', new admin_category('gradeexports', get_string('exportsettings', 'grades')));
- foreach (get_list_of_plugins('grade/export') as $plugin) {
+ foreach (get_plugin_list('gradeexport') as $plugin => $plugindir) {
// Include all the settings commands for this plugin if there are any
- if (file_exists($CFG->dirroot.'/grade/export/'.$plugin.'/settings.php')) {
+ if (file_exists($plugindir.'/settings.php')) {
$settings = new admin_settingpage('gradeexport'.$plugin, get_string('modulename', 'gradeexport_'.$plugin), 'moodle/grade:manage');
if ($ADMIN->fulltree) {
- include($CFG->dirroot.'/grade/export/'.$plugin.'/settings.php');
+ include($plugindir.'/settings.php');
}
$ADMIN->add('gradeexports', $settings);
}
@@ -214,4 +214,3 @@ if (has_capability('moodle/grade:manage', $systemcontext)
} // end of speedup
-?>
diff --git a/admin/settings/plugins.php b/admin/settings/plugins.php
index bffb8b11a10..e5105cdc004 100644
--- a/admin/settings/plugins.php
+++ b/admin/settings/plugins.php
@@ -258,20 +258,30 @@ if ($hassiteconfig || has_capability('moodle/question:config', $systemcontext))
/// Now add reports
-foreach (get_list_of_plugins($CFG->admin.'/report') as $plugin) {
- $settings_path = "$CFG->dirroot/$CFG->admin/report/$plugin/settings.php";
+foreach (get_plugin_list('report') as $plugin => $plugindir) {
+ $settings_path = "$plugindir/settings.php";
if (file_exists($settings_path)) {
include($settings_path);
continue;
}
- $index_path = "$CFG->dirroot/$CFG->admin/report/$plugin/index.php";
+ $index_path = "$plugindir/index.php";
if (!file_exists($index_path)) {
continue;
}
// old style 3rd party plugin without settings.php
- $www_path = "$CFG->dirroot/$CFG->admin/report/$plugin/index.php";
+ $www_path = "$CFG->wwwroot/$CFG->admin/report/$plugin/index.php";
$reportname = get_string($plugin, 'report_' . $plugin);
$ADMIN->add('reports', new admin_externalpage('report'.$plugin, $reportname, $www_path, 'moodle/site:viewreports'));
}
+
+/// Add all local plugins - must be always last!
+
+foreach (get_plugin_list('local') as $plugin => $plugindir) {
+ $settings_path = "$plugindir/settings.php";
+ if (file_exists($settings_path)) {
+ include($settings_path);
+ continue;
+ }
+}
\ No newline at end of file
diff --git a/admin/settings/users.php b/admin/settings/users.php
index c725cf4e1c8..9d61028e830 100644
--- a/admin/settings/users.php
+++ b/admin/settings/users.php
@@ -36,22 +36,22 @@ if ($hassiteconfig
$ADMIN->add('authsettings', $temp);
- if ($auths = get_list_of_plugins('auth')) {
+ if ($auths = get_plugin_list('auth')) {
$authsenabled = get_enabled_auth_plugins();
$authbyname = array();
- foreach ($auths as $auth) {
+ foreach ($auths as $auth => $authdir) {
$strauthname = auth_get_plugin_title($auth);
$authbyname[$strauthname] = $auth;
}
ksort($authbyname);
foreach ($authbyname as $strauthname=>$authname) {
- if (file_exists($CFG->dirroot.'/auth/'.$authname.'/settings.php')) {
+ if (file_exists($authdir.'/settings.php')) {
// do not show disabled auths in tree, keep only settings link on manage page
$settings = new admin_settingpage('authsetting'.$authname, $strauthname, 'moodle/site:config', !in_array($authname, $authsenabled));
if ($ADMIN->fulltree) {
- include($CFG->dirroot.'/auth/'.$authname.'/settings.php');
+ include($authdir.'/settings.php');
}
// TODO: finish implementation of common settings - locking, etc.
$ADMIN->add('authsettings', $settings);
diff --git a/admin/uploaduser.php b/admin/uploaduser.php
index 9b55b3c484c..5d67b4f0089 100755
--- a/admin/uploaduser.php
+++ b/admin/uploaduser.php
@@ -159,7 +159,8 @@ if ($formdata = $mform->is_cancelled()) {
$allowedauths = uu_allowed_auths();
$allowedauths = array_keys($allowedauths);
- $availableauths = get_list_of_plugins('auth');
+ $availableauths = get_plugin_list('auth');
+ $availableauths = array_keys($availableauths);
$allowedroles = uu_allowed_roles(true);
foreach ($allowedroles as $rid=>$rname) {
diff --git a/admin/xmldb/actions/XMLDBAction.class.php b/admin/xmldb/actions/XMLDBAction.class.php
index 149858c08b4..c0cb9031b1d 100644
--- a/admin/xmldb/actions/XMLDBAction.class.php
+++ b/admin/xmldb/actions/XMLDBAction.class.php
@@ -201,23 +201,23 @@ class XMLDBAction {
* @param xmldb_structure structure object containing all the info
* @return string PHP code to be used to stabilish a savepoint
*/
- function upgrade_savepoint_php ($structure) {
+ function upgrade_savepoint_php($structure) {
$path = $structure->getPath();
/// Trim "db" from path
$path = dirname($path);
- /// Get all the available plugin types
- $plugintypes = get_plugin_types();
-
/// Get pluginname, plugindir and plugintype
$pluginname = basename($path);
if ($path == 'lib') { /// exception for lib (not proper plugin)
$plugindir = 'lib';
$plugintype = 'lib';
} else { /// rest of plugins
+ //TODO: this is not nice and may fail, plugintype should be passed around somehow instead
+ $plugintypes = get_plugin_types(false);
$plugindir = dirname($path);
+ $plugindir = str_replace('\\', '/', $plugindir);
$plugintype = array_search($plugindir, $plugintypes);
}
diff --git a/blocks/admin/block_admin.php b/blocks/admin/block_admin.php
index bb82b727137..5432733a989 100644
--- a/blocks/admin/block_admin.php
+++ b/blocks/admin/block_admin.php
@@ -62,9 +62,9 @@ class block_admin extends block_list {
if (has_capability('moodle/grade:viewall', $context)) {
$reportavailable = true;
} else if (!empty($course->showgrades)) {
- if ($reports = get_list_of_plugins('grade/report')) { // Get all installed reports
+ if ($reports = get_plugin_list('gradereport')) { // Get all installed reports
arsort($reports); // user is last, we want to test it first
- foreach ($reports as $plugin) {
+ foreach ($reports as $plugin => $plugindir) {
if (has_capability('gradereport/'.$plugin.':view', $context)) {
//stop when the first visible plugin is found
$reportavailable = true;
diff --git a/course/edit_form.php b/course/edit_form.php
index 1cb7a83bbb5..abcd88c6bb7 100644
--- a/course/edit_form.php
+++ b/course/edit_form.php
@@ -112,10 +112,10 @@ class course_edit_form extends moodleform {
$mform->setHelpButton('summary', array('text2', get_string('helptext')), true);
$mform->setType('summary', PARAM_RAW);
- $courseformats = get_list_of_plugins('course/format');
+ $courseformats = get_plugin_list('format');
$formcourseformats = array();
- foreach ($courseformats as $courseformat) {
- $formcourseformats["$courseformat"] = get_string("format$courseformat","format_$courseformat");
+ foreach ($courseformats as $courseformat => $formatdir) {
+ $formcourseformats["$courseformat"] = get_string("format$courseformat", "format_$courseformat");
if($formcourseformats["$courseformat"]=="[[format$courseformat]]") {
$formcourseformats["$courseformat"] = get_string("format$courseformat");
}
diff --git a/course/import.php b/course/import.php
index f33b64a9779..4853bb66402 100644
--- a/course/import.php
+++ b/course/import.php
@@ -37,11 +37,11 @@
print_header($course->fullname.': '.$strimport, $course->fullname.': '.$strimport, $navigation);
- $directories = get_list_of_plugins('course/import');
+ $imports = get_plugin_list('import');
- foreach ($directories as $directory) {
+ foreach ($imports as $import => $importdir) {
echo '
';
- include_once($CFG->dirroot.'/course/import/'.$directory.'/mod.php');
+ include($importdir.'/mod.php');
echo '
';
}
diff --git a/course/report.php b/course/report.php
index 593da6bc3b2..07b8218d755 100644
--- a/course/report.php
+++ b/course/report.php
@@ -21,10 +21,10 @@
$navigation = build_navigation($navlinks);
print_header($course->fullname.': '.$strreports, $course->fullname.': '.$strreports, $navigation);
- $directories = get_list_of_plugins('course/report');
+ $reports = get_plugin_list('report');
- foreach ($directories as $directory) {
- $pluginfile = $CFG->dirroot.'/course/report/'.$directory.'/mod.php';
+ foreach ($reports as $report => $reportdirectory) {
+ $pluginfile = $reportdirectory.'/mod.php';
if (file_exists($pluginfile)) {
ob_start();
include($pluginfile); // Fragment for listing
diff --git a/grade/edit/settings/form.php b/grade/edit/settings/form.php
index 9c7232e7905..acc35917a1d 100644
--- a/grade/edit/settings/form.php
+++ b/grade/edit/settings/form.php
@@ -100,10 +100,10 @@ class course_settings_form extends moodleform {
$types = array('report', 'export', 'import');
foreach($types as $type) {
- foreach (get_list_of_plugins('grade/'.$type) as $plugin) {
+ foreach (get_plugin_list('grade'.$type) as $plugin => $plugindir) {
// Include all the settings commands for this plugin if there are any
- if (file_exists($CFG->dirroot.'/grade/'.$type.'/'.$plugin.'/lib.php')) {
- require_once($CFG->dirroot.'/grade/'.$type.'/'.$plugin.'/lib.php');
+ if (file_exists($plugindir.'/lib.php')) {
+ require_once($plugindir.'/lib.php');
$functionname = 'grade_'.$type.'_'.$plugin.'_settings_definition';
if (function_exists($functionname)) {
$mform->addElement('header', 'grade_'.$type.$plugin, get_string('modulename', 'grade'.$type.'_'.$plugin, NULL));
diff --git a/grade/lib.php b/grade/lib.php
index 924da2240bd..81c63f6bbb6 100644
--- a/grade/lib.php
+++ b/grade/lib.php
@@ -494,10 +494,10 @@ function grade_get_plugin_info($courseid, $active_type, $active_plugin) {
// report plugins with its special structure
// Get all installed reports
- if ($reports = get_list_of_plugins('grade/report', 'CVS')) {
+ if ($reports = get_plugin_list('gradereport')) {
// Remove ones we can't see
- foreach ($reports as $key => $plugin) {
+ foreach ($reports as $plugin => $unused) {
if (!has_capability('gradereport/'.$plugin.':view', $context)) {
unset($reports[$key]);
}
@@ -507,7 +507,7 @@ function grade_get_plugin_info($courseid, $active_type, $active_plugin) {
$reportnames = array();
if (!empty($reports)) {
- foreach ($reports as $plugin) {
+ foreach ($reports as $plugin => $plugindir) {
$pluginstr = get_string('modulename', 'gradereport_'.$plugin);
$url = $url_prefix.'report/'.$plugin.'/index.php?id='.$courseid;
if ($active_type == 'report' and $active_plugin == $plugin ) {
@@ -516,7 +516,7 @@ function grade_get_plugin_info($courseid, $active_type, $active_plugin) {
$reportnames[$plugin] = new grade_plugin_info($plugin, $url, $pluginstr);
// Add link to preferences tab if such a page exists
- if (file_exists($CFG->dirroot . '/grade/report/'.$plugin.'/preferences.php')) {
+ if (file_exists($plugindir.'/preferences.php')) {
$pref_url = $url_prefix.'report/'.$plugin.'/preferences.php?id='.$courseid;
$plugin_info['preferences'][$plugin] = new grade_plugin_info($plugin, $pref_url, $pluginstr);
}
@@ -631,8 +631,8 @@ function grade_get_plugin_info($courseid, $active_type, $active_plugin) {
}
// standard import plugins
- if ($imports = get_list_of_plugins('grade/import', 'CVS')) { // Get all installed import plugins
- foreach ($imports as $key => $plugin) { // Remove ones we can't see
+ if ($imports = get_plugin_list('gradeimport')) { // Get all installed import plugins
+ foreach ($imports as $plugin => $plugindir) { // Remove ones we can't see
if (!has_capability('gradeimport/'.$plugin.':view', $context)) {
unset($imports[$key]);
}
@@ -656,7 +656,7 @@ function grade_get_plugin_info($courseid, $active_type, $active_plugin) {
}
// standard export plugins
- if ($exports = get_list_of_plugins('grade/export', 'CVS')) { // Get all installed export plugins
+ if ($exports = get_plugin_list('gradeexport')) { // Get all installed export plugins
foreach ($exports as $key => $plugin) { // Remove ones we can't see
if (!has_capability('gradeexport/'.$plugin.':view', $context)) {
unset($exports[$key]);
@@ -665,7 +665,7 @@ function grade_get_plugin_info($courseid, $active_type, $active_plugin) {
}
$exportnames = array();
if (!empty($exports)) {
- foreach ($exports as $plugin) {
+ foreach ($exports as $plugin => $plugindir) {
$pluginstr = get_string('modulename', 'gradeexport_'.$plugin);
$url = $url_prefix.'export/'.$plugin.'/index.php?id='.$courseid;
if ($active_type == 'export' and $active_plugin == $plugin ) {
diff --git a/grade/report/index.php b/grade/report/index.php
index 4092346aeae..e50c3c4b4a5 100644
--- a/grade/report/index.php
+++ b/grade/report/index.php
@@ -34,11 +34,12 @@ require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
/// find all accessible reports
-if ($reports = get_list_of_plugins('grade/report', 'CVS')) { // Get all installed reports
- foreach ($reports as $key => $plugin) { // Remove ones we can't see
- if (!has_capability('gradereport/'.$plugin.':view', $context)) {
- unset($reports[$key]);
- }
+$reports = get_plugin_list('gradereport'); // Get all installed reports
+$reports = array_keys($reports);
+
+foreach ($reports as $plugin => $plugindir) { // Remove ones we can't see
+ if (!has_capability('gradereport/'.$plugin.':view', $context)) {
+ unset($reports[$key]);
}
}
@@ -75,4 +76,3 @@ if (empty($last)) {
//redirect to last or guessed report
redirect($CFG->wwwroot.'/grade/report/'.$last.'/index.php?id='.$course->id);
-?>
diff --git a/lib/accesslib.php b/lib/accesslib.php
index bd303244fd8..b55a65cd1b7 100755
--- a/lib/accesslib.php
+++ b/lib/accesslib.php
@@ -3025,13 +3025,12 @@ function role_assign($roleid, $userid, $groupid, $contextid, $timestart=0, $time
}
/// Ask all the modules if anything needs to be done for this user
- if ($mods = get_list_of_plugins('mod')) {
- foreach ($mods as $mod) {
- include_once($CFG->dirroot.'/mod/'.$mod.'/lib.php');
- $functionname = $mod.'_role_assign';
- if (function_exists($functionname)) {
- $functionname($userid, $context, $roleid);
- }
+ $mods = get_plugin_list('mod');
+ foreach ($mods as $mod => $moddir) {
+ include_once($moddir.'/lib.php');
+ $functionname = $mod.'_role_assign';
+ if (function_exists($functionname)) {
+ $functionname($userid, $context, $roleid);
}
}
@@ -3087,7 +3086,7 @@ function role_unassign($roleid=0, $userid=0, $groupid=0, $contextid=0, $enrol=NU
if ($select) {
if ($ras = $DB->get_records_select('role_assignments', implode(' AND ', $select), $params)) {
- $mods = get_list_of_plugins('mod');
+ $mods = get_plugin_list('mod');
foreach($ras as $ra) {
$fireevent = false;
/// infinite loop protection when deleting recursively
@@ -3117,8 +3116,8 @@ function role_unassign($roleid=0, $userid=0, $groupid=0, $contextid=0, $enrol=NU
}
/// Ask all the modules if anything needs to be done for this user
- foreach ($mods as $mod) {
- include_once($CFG->dirroot.'/mod/'.$mod.'/lib.php');
+ foreach ($mods as $mod=>$moddir) {
+ include_once($moddir.'/lib.php');
$functionname = $mod.'_role_unassign';
if (function_exists($functionname)) {
$functionname($ra->userid, $context); // watch out, $context might be NULL if something goes wrong
@@ -3208,101 +3207,34 @@ function enrol_into_course($course, $user, $enrol) {
* capabilities are defined for the component, we simply return an empty array.
*
* @global object
- * @param string $component examples: 'moodle', 'mod/forum', 'block/quiz_results'
+ * @param string $component full plugin name, examples: 'moodle', 'mod_forum'
* @return array array of capabilities
*/
function load_capability_def($component) {
- global $CFG;
+ $defpath = get_component_directory($component).'/db/access.php';
- if ($component == 'moodle') {
- $defpath = $CFG->libdir.'/db/access.php';
- $varprefix = 'moodle';
- } else {
- $compparts = explode('/', $component);
-
- if ($compparts[0] == 'report') {
- $defpath = $CFG->dirroot.'/'.$CFG->admin.'/report/'.$compparts[1].'/db/access.php';
- $varprefix = $compparts[0].'_'.$compparts[1];
-
- } else if ($compparts[0] == 'block') {
- // Blocks are an exception. Blocks directory is 'blocks', and not
- // 'block'. So we need to jump through hoops.
- $defpath = $CFG->dirroot.'/'.$compparts[0].
- 's/'.$compparts[1].'/db/access.php';
- $varprefix = $compparts[0].'_'.$compparts[1];
-
- } else if ($compparts[0] == 'format') {
- // Similar to the above, course formats are 'format' while they
- // are stored in 'course/format'.
- $defpath = $CFG->dirroot.'/course/'.$component.'/db/access.php';
- $varprefix = $compparts[0].'_'.$compparts[1];
-
- } else if ($compparts[0] == 'editor') {
- $defpath = $CFG->dirroot.'/lib/editor/'.$compparts[1].'/db/access.php';
- $varprefix = $compparts[0].'_'.$compparts[1];
-
- } else if ($compparts[0] == 'gradeimport') {
- $defpath = $CFG->dirroot.'/grade/import/'.$compparts[1].'/db/access.php';
- $varprefix = $compparts[0].'_'.$compparts[1];
-
- } else if ($compparts[0] == 'gradeexport') {
- $defpath = $CFG->dirroot.'/grade/export/'.$compparts[1].'/db/access.php';
- $varprefix = $compparts[0].'_'.$compparts[1];
-
- } else if ($compparts[0] == 'gradereport') {
- $defpath = $CFG->dirroot.'/grade/report/'.$compparts[1].'/db/access.php';
- $varprefix = $compparts[0].'_'.$compparts[1];
-
- } else if ($compparts[0] == 'quizreport') {
- $defpath = $CFG->dirroot.'/mod/quiz/report/'.$compparts[1].'/db/access.php';
- $varprefix = $compparts[0].'_'.$compparts[1];
-
- } else if ($compparts[0] == 'coursereport') {
- $defpath = $CFG->dirroot.'/course/report/'.$compparts[1].'/db/access.php';
- $varprefix = $compparts[0].'_'.$compparts[1];
-
- } else {
- $defpath = $CFG->dirroot.'/'.$component.'/db/access.php';
- $varprefix = str_replace('/', '_', $component);
- }
- }
$capabilities = array();
-
if (file_exists($defpath)) {
require($defpath);
- $capabilities = ${$varprefix.'_capabilities'};
+ $capabilities = ${$component.'_capabilities'};
}
+
return $capabilities;
}
/**
* Gets the capabilities that have been cached in the database for this component.
- *
- * @global object
- * @param string $component - examples: 'moodle', 'mod/forum', 'block/quiz_results'
+ * @param string $component - examples: 'moodle', 'mod_forum'
* @return array array of capabilities
*/
function get_cached_capabilities($component='moodle') {
global $DB;
-
- if ($component == 'moodle') {
- $storedcaps = $DB->get_records_select('capabilities', "name LIKE ?", array('moodle/%:%'));
-
- } else if ($component == 'local') {
- $storedcaps = $DB->get_records_select('capabilities', "name LIKE ?", array('moodle/local:%'));
-
- } else {
- $storedcaps = $DB->get_records_select('capabilities', "name LIKE ?", array("$component:%"));
- }
-
- return $storedcaps;
+ return $DB->get_records('capabilities', array('component'=>$component));
}
/**
* Returns default capabilities for given legacy role type.
- *
- * @global object
* @param string $legacyrole legacy role name
* @return array
*/
@@ -3336,8 +3268,6 @@ function get_default_capabilities($legacyrole) {
* Reset role capabilitites to default according to selected legacy capability.
* If several legacy caps selected, use the first from get_default_capabilities.
* If no legacy selected, removes all capabilities.
- *
- * @global object
* @param int @roleid
*/
function reset_role_capabilities($roleid) {
diff --git a/lib/adminlib.php b/lib/adminlib.php
index ebec3dfeebd..75a74a2d993 100644
--- a/lib/adminlib.php
+++ b/lib/adminlib.php
@@ -198,38 +198,6 @@ function get_used_table_names() {
return $table_names;
}
-/**
- * Lists all plugin types
- *
- * @global object
- * @return array Array of strings - name=>location
- */
-function get_plugin_types() {
- global $CFG;
-
- return array('mod' => 'mod',
- 'qtype' => 'question/type',
- 'block' => 'blocks',
- 'auth' => 'auth',
- 'enrol' => 'enrol',
- 'format' => 'course/format',
- 'editor' => 'lib/editor',
- 'gradeexport' => 'grade/export',
- 'gradeimport' => 'grade/import',
- 'gradereport' => 'grade/report',
- 'message' => 'message/output',
- 'coursereport' => 'course/report',
- 'report' => $CFG->admin.'/report',
- 'portfolio' => 'portfolio/type',
- 'repository' => 'repository',
-
- // following types a very ugly hacks - we should not make exceptions like this - all plugins should be equal;
- // these plugins may cause problems such as when wanting to uninstall them
- 'quizreport' => 'mod/quiz/report',
- 'assignment_type' => 'mod/assignment/type',
- );
-}
-
/**
* Returns list of all directories where we expect install.xml files
*
@@ -245,21 +213,15 @@ function get_db_directories() {
$dbdirs[] = $CFG->libdir.'/db';
/// Then, all the ones defined by get_plugin_types()
- if ($plugintypes = get_plugin_types()) {
- foreach ($plugintypes as $plugintype => $pluginbasedir) {
- if ($plugins = get_list_of_plugins($pluginbasedir, 'db')) {
- foreach ($plugins as $plugin) {
- $dbdirs[] = $CFG->dirroot . '/' . $pluginbasedir . '/' . $plugin . '/db';
- }
+ $plugintypes = get_plugin_types();
+ foreach ($plugintypes as $plugintype => $pluginbasedir) {
+ if ($plugins = get_plugin_list($plugintype)) {
+ foreach ($plugins as $plugin => $plugindir) {
+ $dbdirs[] = $plugindir.'/db';
}
}
}
-/// Local database changes, if the local folder exists.
- if (file_exists($CFG->dirroot . '/local')) {
- $dbdirs[] = $CFG->dirroot.'/local/db';
- }
-
return $dbdirs;
}
@@ -4125,8 +4087,8 @@ class admin_setting_special_gradeexport extends admin_setting_configmulticheckbo
}
$this->choices = array();
- if ($plugins = get_list_of_plugins('grade/export')) {
- foreach($plugins as $plugin) {
+ if ($plugins = get_plugin_list('gradeexport')) {
+ foreach($plugins as $plugin => $unused) {
$this->choices[$plugin] = get_string('modulename', 'gradeexport_'.$plugin);
}
}
@@ -4301,9 +4263,9 @@ class admin_setting_grade_profilereport extends admin_setting_configselect {
global $CFG;
require_once($CFG->libdir.'/gradelib.php');
- foreach (get_list_of_plugins('grade/report') as $plugin) {
- if (file_exists($CFG->dirroot.'/grade/report/'.$plugin.'/lib.php')) {
- require_once($CFG->dirroot.'/grade/report/'.$plugin.'/lib.php');
+ foreach (get_plugin_list('gradereport') as $plugin => $plugindir) {
+ if (file_exists($plugindir.'/lib.php')) {
+ require_once($plugindir.'/lib.php');
$functionname = 'grade_report_'.$plugin.'_profilereport';
if (function_exists($functionname)) {
$this->choices[$plugin] = get_string('modulename', 'gradereport_'.$plugin);
@@ -4457,9 +4419,9 @@ class admin_enrolment_page extends admin_externalpage {
$found = false;
- if ($modules = get_list_of_plugins('enrol')) {
+ if ($modules = get_plugin_list('enrol')) {
$textlib = textlib_get_instance();
- foreach ($modules as $plugin) {
+ foreach ($modules as $plugin => $dir) {
if (strpos($plugin, $query) !== false) {
$found = true;
break;
@@ -4655,8 +4617,8 @@ class admin_setting_manageauths extends admin_setting {
}
$textlib = textlib_get_instance();
- $authsavailable = get_list_of_plugins('auth');
- foreach ($authsavailable as $auth) {
+ $authsavailable = get_plugin_list('auth');
+ foreach ($authsavailable as $auth => $dir) {
if (strpos($auth, $query) !== false) {
return true;
}
@@ -4687,7 +4649,7 @@ class admin_setting_manageauths extends admin_setting {
'up', 'down', 'none'));
$txt->updown = "$txt->up/$txt->down";
- $authsavailable = get_list_of_plugins('auth');
+ $authsavailable = get_plugin_list('auth');
get_enabled_auth_plugins(true); // fix the list of enabled auths
if (empty($CFG->auth)) {
$authsenabled = array();
@@ -4710,7 +4672,7 @@ class admin_setting_manageauths extends admin_setting {
}
}
- foreach ($authsavailable as $auth) {
+ foreach ($authsavailable as $auth => $dir) {
if (array_key_exists($auth, $displayauths)) {
continue; //already in the list
}
@@ -5081,8 +5043,8 @@ class admin_setting_manageportfolio extends admin_setting {
}
$textlib = textlib_get_instance();
- $portfolios= get_list_of_plugins('portfolio/type');
- foreach ($portfolios as $p) {
+ $portfolios = get_plugin_list('portfolio');
+ foreach ($portfolios as $p => $dir) {
if (strpos($p, $query) !== false) {
return true;
}
@@ -5112,7 +5074,8 @@ class admin_setting_manageportfolio extends admin_setting {
$namestr = get_string('name');
$pluginstr = get_string('plugin', 'portfolio');
- $plugins = get_list_of_plugins('portfolio/type');
+ $plugins = get_plugin_list('portfolio');
+ $plugins = array_keys($plugins);
$instances = portfolio_instances(false, false);
$alreadyplugins = array();
@@ -5418,10 +5381,6 @@ function admin_get_root($reload=false, $requirefulltree=true) {
}
require($CFG->dirroot.'/'.$CFG->admin.'/settings/plugins.php');
- if (file_exists($CFG->dirroot.'/local/settings.php')) {
- require($CFG->dirroot.'/local/settings.php');
- }
-
$ADMIN->loaded = true;
}
@@ -5882,9 +5841,9 @@ function print_plugin_tables() {
$plugins_installed['filter'] = array();
$plugins_ondisk = array();
- $plugins_ondisk['mod'] = get_list_of_plugins('mod', 'db');
- $plugins_ondisk['blocks'] = get_list_of_plugins('blocks', 'db');
- $plugins_ondisk['filter'] = get_list_of_plugins('filter', 'db');
+ $plugins_ondisk['mod'] = array_keys(get_plugin_list('mod'));
+ $plugins_ondisk['blocks'] = array_keys(get_plugin_list('block'));
+ $plugins_ondisk['filter'] = array_keys(get_plugin_list('filter'));
$strstandard = get_string('standard');
$strnonstandard = get_string('nonstandard');
@@ -6048,8 +6007,8 @@ class admin_setting_managerepository extends admin_setting {
}
$textlib = textlib_get_instance();
- $repositories= get_list_of_plugins('repository');
- foreach ($repositories as $p) {
+ $repositories= get_plugin_list('repository');
+ foreach ($repositories as $p => $dir) {
if (strpos($p, $query) !== false) {
return true;
}
@@ -6080,7 +6039,7 @@ class admin_setting_managerepository extends admin_setting {
$updownstr = get_string('updown', 'repository');
$hiddenstr = get_string('hiddenshow', 'repository');
$deletestr = get_string('delete');
- $plugins = get_list_of_plugins('repository');
+ $plugins = get_plugin_list('repository');
$instances = repository::get_types();
$instancesnumber = count($instances);
$alreadyplugins = array();
@@ -6161,7 +6120,7 @@ class admin_setting_managerepository extends admin_setting {
$instancehtml .= get_string('addplugin', 'repository');
$instancehtml .= '';
$addable = 0;
- foreach ($plugins as $p) {
+ foreach ($plugins as $p=>$dir) {
if (!in_array($p, $alreadyplugins)) {
$instancehtml .= '- '.get_string('add', 'repository')
diff --git a/lib/db/messages.php b/lib/db/messages.php
index dc827a79c07..44fd8f89a40 100644
--- a/lib/db/messages.php
+++ b/lib/db/messages.php
@@ -36,11 +36,9 @@ $messageproviders = array (
/// Important errors that an admin ought to know about
'errors' => array (
'capability' => 'moodle/site:config'
- )
+ ),
+ 'instantmessage' => array (
+ ),
+
);
-
-
-
-
-?>
diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php
index f2a1519d869..3e838c8ebd6 100644
--- a/lib/db/upgrade.php
+++ b/lib/db/upgrade.php
@@ -2191,6 +2191,66 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
upgrade_main_savepoint($result, 2009061600);
}
+ if ($result && $oldversion < 2009061702) {
+ // standardizing plugin names
+ if ($configs = $DB->get_records_select('config_plugins', "plugin LIKE 'quizreport_%'")) {
+ foreach ($configs as $config) {
+ $config->plugin = str_replace('quizreport_', 'quiz_', $config->plugin);
+ $DB->update_record('config_plugins', $config);
+ }
+ }
+ unset($configs);
+ upgrade_main_savepoint($result, 2009061702);
+ }
+
+ if ($result && $oldversion < 2009061703) {
+ // standardizing plugin names
+ if ($configs = $DB->get_records_select('config_plugins', "plugin LIKE 'assignment_type_%'")) {
+ foreach ($configs as $config) {
+ $config->plugin = str_replace('assignment_type_', 'assignment_', $config->plugin);
+ $DB->update_record('config_plugins', $config);
+ }
+ }
+ unset($configs);
+ upgrade_main_savepoint($result, 2009061703);
+ }
+
+ if ($result && $oldversion < 2009061704) {
+ // change component string in capability records to new "_" format
+ if ($caps = $DB->get_records('capabilities')) {
+ foreach ($caps as $cap) {
+ $cap->component = str_replace('/', '_', $cap->component);
+ $DB->update_record('capabilities', $cap);
+ }
+ }
+ unset($caps);
+ upgrade_main_savepoint($result, 2009061704);
+ }
+
+ if ($result && $oldversion < 2009061705) {
+ // change component string in events_handlers records to new "_" format
+ if ($handlers = $DB->get_records('events_handlers')) {
+ foreach ($handlers as $handler) {
+ $handler->handlermodule = str_replace('/', '_', $handler->handlermodule);
+ $DB->update_record('events_handlers', $handler);
+ }
+ }
+ unset($handlers);
+ upgrade_main_savepoint($result, 2009061705);
+ }
+
+ if ($result && $oldversion < 2009061706) {
+ // change component string in message_providers records to new "_" format
+ if ($mps = $DB->get_records('message_providers')) {
+ foreach ($mps as $mp) {
+ $mp->component = str_replace('/', '_', $mp->component);
+ $DB->update_record('message_providers', $cap);
+ }
+ }
+ unset($caps);
+ upgrade_main_savepoint($result, 2009061706);
+ }
+
return $result;
}
diff --git a/lib/ddl/database_manager.php b/lib/ddl/database_manager.php
index 965b453064c..0808d8ce8e4 100644
--- a/lib/ddl/database_manager.php
+++ b/lib/ddl/database_manager.php
@@ -1002,7 +1002,7 @@ class database_manager {
unset($dbtables[$tablename]);
}
- // look for unsupported tables - local custom tables should be in /local/db/install.xml ;-)
+ // look for unsupported tables - local custom tables should be in /local/xxxx/db/install.xml ;-)
// if there is no prefix, we can not say if tale is ours :-(
if ($this->generator->prefix !== '') {
foreach ($dbtables as $tablename=>$unused) {
diff --git a/lib/editorlib.php b/lib/editorlib.php
index f68292d7372..f42ed7eb5a2 100644
--- a/lib/editorlib.php
+++ b/lib/editorlib.php
@@ -105,7 +105,7 @@ function get_texteditor($editorname) {
*/
function get_available_editors() {
$editors = array();
- foreach (get_list_of_plugins('lib/editor') as $editorname) {
+ foreach (get_plugin_list('editor') as $editorname => $dir) {
$editors[$editorname] = get_string('modulename', 'editor_'.$editorname);
}
return $editors;
diff --git a/lib/eventslib.php b/lib/eventslib.php
index ef9cae6bb48..faba2a34c45 100755
--- a/lib/eventslib.php
+++ b/lib/eventslib.php
@@ -36,44 +36,7 @@
* @return array of capabilities or empty array if not exists
*/
function events_load_def($component) {
- global $CFG;
-
- if ($component == 'moodle') {
- $defpath = $CFG->libdir.'/db/events.php';
-
- } else if ($component == 'unittest') {
- $defpath = $CFG->libdir.'/simpletest/fixtures/events.php';
-
- } else {
- $compparts = explode('/', $component);
-
- if ($compparts[0] == 'block') {
- // Blocks are an exception. Blocks directory is 'blocks', and not
- // 'block'. So we need to jump through hoops.
- $defpath = $CFG->dirroot.'/blocks/'.$compparts[1].'/db/events.php';
-
- } else if ($compparts[0] == 'format') {
- // Similar to the above, course formats are 'format' while they
- // are stored in 'course/format'.
- $defpath = $CFG->dirroot.'/course/format/'.$compparts[1].'/db/events.php';
-
- } else if ($compparts[0] == 'editor') {
- $defpath = $CFG->dirroot.'/lib/editor/'.$compparts[1].'/db/events.php';
-
- } else if ($compparts[0] == 'gradeimport') {
- $defpath = $CFG->dirroot.'/grade/import/'.$compparts[1].'/db/events.php';
-
- } else if ($compparts[0] == 'gradeexport') {
- $defpath = $CFG->dirroot.'/grade/export/'.$compparts[1].'/db/events.php';
-
- } else if ($compparts[0] == 'gradereport') {
- $defpath = $CFG->dirroot.'/grade/report/'.$compparts[1].'/db/events.php';
- } else if ($compparts[0] == 'portfolio'){
- $defpath = $CFG->dirroot.'/portfolio/type/'.$compparts[1].'/db/events.php';
- } else {
- $defpath = $CFG->dirroot.'/'.$component.'/db/events.php';
- }
- }
+ $defpath = get_component_directory($component).'/db/events.php';
$handlers = array();
@@ -121,7 +84,7 @@ function events_get_cached($component) {
* the database.
*
* @global object
- * @param string $component examples: 'moodle', 'mod/forum', 'block/quiz_results'
+ * @param string $component examples: 'moodle', 'mod_forum', 'block_quiz_results'
* @return boolean
*/
function events_update_definition($component='moodle') {
diff --git a/lib/gradelib.php b/lib/gradelib.php
index 015b09015db..db3d001e803 100644
--- a/lib/gradelib.php
+++ b/lib/gradelib.php
@@ -1044,17 +1044,15 @@ function grade_grab_course_grades($courseid, $modname=null) {
return;
}
- if (!$mods = get_list_of_plugins('mod') ) {
+ if (!$mods = get_plugin_list('mod') ) {
print_error('nomodules', 'debug');
}
- foreach ($mods as $mod) {
+ foreach ($mods as $mod => $fullmod) {
if ($mod == 'NEWMODULE') { // Someone has unzipped the template, ignore it
continue;
}
- $fullmod = $CFG->dirroot.'/mod/'.$mod;
-
// include the module lib once
if (file_exists($fullmod.'/lib.php')) {
// get all instance of the activity
diff --git a/lib/javascript-mod.php b/lib/javascript-mod.php
index 4a6956193bd..a53179ffe63 100644
--- a/lib/javascript-mod.php
+++ b/lib/javascript-mod.php
@@ -24,40 +24,24 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-/** NO_MOODLE_COOKIES = true */
define('NO_MOODLE_COOKIES', true);
- /** NO_UPGRADE_CHECK = true */
define('NO_UPGRADE_CHECK', true);
include('../config.php');
$output = "// Javascript from Moodle modules\n";
- if ($mods = get_list_of_plugins('mod')) {
- foreach ($mods as $mod) {
- if (is_readable($CFG->dirroot.'/mod/'.$mod.'/javascript.php')) {
- $output .= file_get_contents($CFG->dirroot.'/mod/'.$mod.'/javascript.php');
+ $plugintypes = array('mod', 'filter', 'block');
+ foreach ($plugintypes as $plugintype) {
+ if ($mods = get_plugin_list($plugintype)) {
+ foreach ($mods as $mod => $moddir) {
+ if (is_readable($moddir.'/javascript.php')) {
+ $output .= file_get_contents($moddir.'/javascript.php');
+ }
}
}
}
- if ($filters = get_list_of_plugins('filter')) {
- foreach ($filters as $filter) {
- if (is_readable($CFG->dirroot.'/filter/'.$filter.'/javascript.php')) {
- $output .= file_get_contents($CFG->dirroot.'/filter/'.$filter.'/javascript.php');
- }
- }
- }
-
- if ($blocks = get_list_of_plugins('blocks')) {
- foreach ($blocks as $block) {
- if (is_readable($CFG->dirroot.'/blocks/'.$block.'/javascript.php')) {
- $output .= file_get_contents($CFG->dirroot.'/blocks/'.$block.'/javascript.php');
- }
- }
- }
-
-
$lifetime = '86400';
@header('Content-type: text/javascript');
@@ -68,5 +52,3 @@
@header('Pragma: ');
echo $output;
-
-?>
diff --git a/lib/locallib.php b/lib/locallib.php
deleted file mode 100644
index 4d29c5165ac..00000000000
--- a/lib/locallib.php
+++ /dev/null
@@ -1,175 +0,0 @@
-.
-
-/**
- * This file provides hooks from moodle core into custom code.
- *
- * Important note
- * --------------
- *
- * If at all possible, the facilities provided here should not be used.
- * Wherever possible, customisations should be written using one of the
- * standard plug-in points like modules, blocks, auth plugins, themes, ...
- *
- * However, sometimes that is just not possible, because of the nature
- * of the change you want to make. In which case the second best plan is
- * to implement your feature in a generally useful way, which can
- * be contributed back to the moodle project so that everyone benefits.
- *
- * But supposing you are forced to implement some nasty hack that only
- * you will ever want, then the local folder is for you. The idea is that
- * instead of scattering your changes throughout the code base, you
- * put them all in a folder called 'local'. Then you won't have to
- * deal with merging problems when you upgrade the rest of your moodle
- * installation.
- *
- *
- * Available hooks
- * ===============
- *
- * These are similar to the module interface, however, not all the the
- * facilities that are available to modules are available to local code (yet).
- * See also http://docs.moodle.org/en/Development:Local_customisation for more
- * information.
- *
- *
- * Local database customisations
- * -----------------------------
- *
- * If your local customisations require changes to the database, use the files:
- *
- * local/version.php
- * local/db/upgrade.php
- * local/db/install.php
- *
- * In the file version.php, set the variable $local_version to a versionstamp
- * value like 2006030300 (a concatenation of year, month, day, serial).
- *
- * In the file upgrade.php, implement the
- * function xmldb_local_upgrade($oldversion) to make the database changes.
- *
- * Note that you don't need to have an install.xml file. Instead,
- * when your moodle instance is first installed, xmldb_local_install() will be called.
- *
- * Please note that modifying of core tables is NOT supported at all!
- *
- * Local capabilities
- * ------------------
- *
- * If your local customisations require their own capabilities, use
- *
- * local/db/access.php
- *
- * You should create an array called $local_capabilities, which looks like:
- *
- * $local_capabilities = array(
- * 'moodle/local:capability' => array(
- * 'captype' => 'read',
- * 'contextlevel' => CONTEXT_SYSTEM,
- * ),
- * );
- *
- * Note that for all local capabilities you add, you'll need to add language strings.
- * Moodle will expect to find them in local/lang/en_utf8/local.php (eg for English)
- * with a key (following the above example) of local:capability
- * See the next section for local language support.
- *
- *
- * Local language support
- * ----------------------
- *
- * Moodle already supports local overriding of any language strings, or the
- * creation of new strings. Just create a folder lang/XX_utf8_local where XX is
- * a language code. Any language files you put in there will be used before
- * the standard files. So, for example, can can create a file
- * lang/en_utf8_local/moodle.php containing
- * $strings['login'] = 'Sign in';
- * and that will change the string 'Login' to 'Sign in'. (See also
- * http://docs.moodle.org/en/Language_editing for another way to achieve this.)
- *
- * This mechanism can also be used to create completely new language files. For
- * example, suppose you have created some code in local/myfeature.php that needs
- * some language strings. You can put those strings in the file
- * lang/en_utf8_local/local_myfeature.php, and then access then using
- * get_string('mystring', 'local_myfeature'). (Note that you do not have to call
- * the file local_myfeature.php, you can call it anything you like, however,
- * the convention of calling lang files for local/ code local_somthing is recommended.)
- *
- * In addition, there is one other mechanism that is available. Strings from the
- * 'local' langauge file (for example get_string('mystring', 'local') will be
- * found if the string is found in the file local/lang/en_utf8/local.php. Since
- * the lang file 'local' is used for a lot of things like capability names, you
- * can use this file for things like that.
- *
- *
- * Local admin menu items
- * ----------------------
- *
- * It is possible to add new items to the admin_tree block.
- * To do this, create a file, local/settings.php
- * which can access the $ADMIN variable directly and add things to it.
- * You might do something like:
- * $ADMIN->add('root', new admin_category($name, $title);
- * $ADMIN->add('foo', new admin_externalpage($name, $title, $url, $cap);
- *
- *
- * Course deletion
- * ---------------
- *
- * To have your local customisations notified when a course is deleted,
- * make a file called
- *
- * local/lib.php
- *
- * In there, implement the function local_delete_course($courseid). This
- * function will then be called whenever the functions remove_course_contents()
- * or delete_course() from moodlelib are called.
- *
- * @package moodlecore
- * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-/**
- * Notify local code that a course is being deleted.
- * Look for a function local_delete_course() in a file called
- * local/lib.php andn call it if it is there.
- *
- * @global object
- * @param int $courseid the course that is being deleted.
- * @param bool $showfeedback Whether to display notifications on success.
- * @return bool false if local_delete_course failed, or true if
- * there was noting to do or local_delete_course succeeded.
- */
-function notify_local_delete_course($courseid, $showfeedback) {
- global $CFG;
- $localfile = $CFG->dirroot .'/local/lib.php';
- if (file_exists($localfile)) {
- require_once($localfile);
- if (function_exists('local_delete_course')) {
- if (local_delete_course($courseid)) {
- if ($showfeedback) {
- notify(get_string('deleted') . ' local data');
- }
- } else {
- return false;
- }
- }
- }
- return true;
-}
-?>
diff --git a/lib/messagelib.php b/lib/messagelib.php
index 5a48b5ede5f..00838a4e5b5 100644
--- a/lib/messagelib.php
+++ b/lib/messagelib.php
@@ -118,7 +118,7 @@ function message_send_handler($eventdata){
/**
* This code updates the message_providers table with the current set of providers
- * @param $component - examples: 'moodle', 'mod/forum', 'block/quiz_results'
+ * @param $component - examples: 'moodle', 'mod_forum', 'block_quiz_results'
* @return boolean
*/
function message_update_providers($component='moodle') {
@@ -210,46 +210,13 @@ function message_get_providers_from_db($component) {
/**
* Loads the messages definitions for the component (from file). If no
* messages are defined for the component, we simply return an empty array.
- * @param $component - examples: 'moodle', 'mod/forum', 'block/quiz_results'
+ * @param $component - examples: 'moodle', 'mod_forum', 'block_quiz_results'
* @return array of message providerss or empty array if not exists
*
* INTERNAL - to be used from messagelib only
*/
function message_get_providers_from_file($component) {
- global $CFG;
-
- if ($component == 'moodle') {
- $defpath = $CFG->libdir.'/db/messages.php';
-
- } else if ($component == 'unittest') {
- $defpath = $CFG->libdir.'/simpletest/fixtures/messages.php';
-
- } else {
- $compparts = explode('/', $component);
-
- if ($compparts[0] == 'block') {
- // Blocks are an exception. Blocks directory is 'blocks', and not
- // 'block'. So we need to jump through hoops.
- $defpath = $CFG->dirroot.'/blocks/'.$compparts[1].'/db/messages.php';
-
- } else if ($compparts[0] == 'format') {
- // Similar to the above, course formats are 'format' while they
- // are stored in 'course/format'.
- $defpath = $CFG->dirroot.'/course/format/'.$compparts[1].'/db/messages.php';
-
- } else if ($compparts[0] == 'gradeimport') {
- $defpath = $CFG->dirroot.'/grade/import/'.$compparts[1].'/db/messages.php';
-
- } else if ($compparts[0] == 'gradeexport') {
- $defpath = $CFG->dirroot.'/grade/export/'.$compparts[1].'/db/messages.php';
-
- } else if ($compparts[0] == 'gradereport') {
- $defpath = $CFG->dirroot.'/grade/report/'.$compparts[1].'/db/messages.php';
-
- } else {
- $defpath = $CFG->dirroot.'/'.$component.'/db/messages.php';
- }
- }
+ $defpath = get_component_directory($component).'/db/messages.php';
$messageproviders = array();
diff --git a/lib/moodlelib.php b/lib/moodlelib.php
index 8708db492ac..9655b17ba82 100644
--- a/lib/moodlelib.php
+++ b/lib/moodlelib.php
@@ -314,6 +314,8 @@ define('FEATURE_GROUPMEMBERSONLY', 'groupmembersonly');
/** True if module supports intro editor */
define('FEATURE_MOD_INTRO', 'mod_intro');
+/** True if module supports subplugins */
+define('FEATURE_MOD_SUBPLUGINS', 'mod_subplugins');
/** True if module has default completion */
define('FEATURE_MODEDIT_DEFAULT_COMPLETION', 'modedit_default_completion');
@@ -3882,10 +3884,10 @@ function remove_course_contents($courseid, $showfeedback=true) {
$strdeleted = get_string('deleted');
/// Clean up course formats (iterate through all formats in the even the course format was ever changed)
- $formats = get_list_of_plugins('course/format');
- foreach ($formats as $format) {
+ $formats = get_plugin_list('format');
+ foreach ($formats as $format=>$formatdir) {
$formatdelete = $format.'_course_format_delete_course';
- $formatlib = "$CFG->dirroot/course/format/$format/lib.php";
+ $formatlib = "$formatdir/lib.php";
if (file_exists($formatlib)) {
include_once($formatlib);
if (function_exists($formatdelete)) {
@@ -3946,10 +3948,6 @@ function remove_course_contents($courseid, $showfeedback=true) {
print_error('nomodules', 'debug');
}
-/// Give local code a chance to delete its references to this course.
- require_once($CFG->libdir.'/locallib.php');
- notify_local_delete_course($courseid, $showfeedback);
-
/// Delete course blocks
blocks_delete_all_for_context($context->id);
@@ -5692,29 +5690,12 @@ class string_manager {
$dirroot . '/lang/' => '',
$dataroot . '/lang/' => '',
);
- $this->searchplacesbyplugintype = array(
- 'assignment_' => array('mod/assignment/type'),
- 'auth_' => array('auth'),
- 'block_' => array('blocks'),
- 'datafield_' => array('mod/data/field'),
- 'datapreset_' => array('mod/data/preset'),
- 'enrol_' => array('enrol'),
- 'filter_' => array('filter'),
- 'format_' => array('course/format'),
- 'editor_' => array('lib/editor'),
- 'quiz_' => array('mod/quiz/report'),
- 'qtype_' => array('question/type'),
- 'qformat_' => array('question/format'),
- 'report_' => array($admin.'/report', 'course/report'),
- 'repository_'=>array('repository'),
- 'resource_' => array('mod/resource/type'),
- 'gradereport_' => array('grade/report'),
- 'gradeimport_' => array('grade/import'),
- 'gradeexport_' => array('grade/export'),
- 'profilefield_' => array('user/profile/field'),
- 'portfolio_' => array('portfolio/type'),
- '' => array('mod')
- );
+ $this->searchplacesbyplugintype = array(''=>array('mod'));
+ $plugintypes = get_plugin_types(false);
+ foreach ($plugintypes as $plugintype => $dir) {
+ $this->searchplacesbyplugintype[$plugintype.'_'] = array($dir);
+ }
+ unset($this->searchplacesbyplugintype['mod_']);
$this->restore_extra_locations_from_session();
if ($runninginstaller) {
$stringnames = file($dirroot . '/install/stringnames.txt');
@@ -5822,14 +5803,10 @@ class string_manager {
foreach ($locations as $location => $ignored) {
$locations[$location] = $module . '/';
}
- if ($module == 'local') {
- $locations[$this->dirroot . '/local/lang/'] = 'local/';
- } else {
- list($type, $plugin) = $this->parse_module_name($module);
- if (isset($this->searchplacesbyplugintype[$type])) {
- foreach ($this->searchplacesbyplugintype[$type] as $location) {
- $locations[$this->dirroot . "/$location/$plugin/lang/"] = $plugin . '/';
- }
+ list($type, $plugin) = $this->parse_module_name($module);
+ if (isset($this->searchplacesbyplugintype[$type])) {
+ foreach ($this->searchplacesbyplugintype[$type] as $location) {
+ $locations[$this->dirroot . "/$location/$plugin/lang/"] = $plugin . '/';
}
}
}
@@ -6371,7 +6348,7 @@ function get_list_of_themes() {
if (!empty($CFG->themelist)) { // use admin's list of themes
$themelist = explode(',', $CFG->themelist);
} else {
- $themelist = get_list_of_plugins("theme");
+ $themelist = array_keys(get_plugin_list("theme"));
}
foreach ($themelist as $key => $theme) {
@@ -6759,33 +6736,196 @@ function show_event($event) {
/// ENVIRONMENT CHECKING ////////////////////////////////////////////////////////////
/**
- * Lists plugin directories within some directory
+ * Return exact 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
+ */
+function get_plugin_directory($plugintype, $name, $fullpaths=true) {
+ if ($plugintype === '') {
+ $plugintype = 'mod';
+ }
+
+ $types = get_plugin_types($fullpaths);
+ if (!array_key_exists($plugintype, $types)) {
+ return null;
+ }
+ $name = clean_param($name, PARAM_SAFEDIR); // just in case ;-)
+
+ return $types[$plugintype].'/'.$name;
+}
+
+/**
+ * Return exact path to 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
+ */
+function get_component_directory($component, $fullpaths=true) {
+ global $CFG;
+
+ $simpletest = false;
+ if (strpos($component, 'simpletest_') === 0) {
+ $subdir = substr($component, strlen('simpletest_'));
+ return $subdir;
+ }
+ if ($component == 'moodle') {
+ $path = ($fullpaths ? $CFG->libdir : 'lib');
+ } else {
+ list($type, $plugin) = explode('_', $component, 2);
+ $path = get_plugin_directory($type, $plugin, $fullpaths);
+ }
+
+ return $path;
+}
+
+/**
+ * Lists all plugin types
+ * @param bool $fullpaths false means relative paths from dirroot
+ * @return array Array of strings - name=>location
+ */
+function get_plugin_types($fullpaths=true) {
+ global $CFG;
+
+ static $info = null;
+ static $fullinfo = null;
+
+ if (!$info) {
+ $info = array('mod' => 'mod',
+ 'auth' => 'auth',
+ 'enrol' => 'enrol',
+ 'message' => 'message/output',
+ 'block' => 'blocks',
+ 'filter' => 'filter',
+ 'editor' => 'lib/editor',
+ 'format' => 'course/format',
+ 'import' => 'course/import',
+ 'profilefield' => 'user/profile/field',
+ 'report' => $CFG->admin.'/report',
+ 'coursereport' => 'course/report', // must be after system reports
+ 'gradeexport' => 'grade/export',
+ 'gradeimport' => 'grade/import',
+ 'gradereport' => 'grade/report',
+ 'repository' => 'repository',
+ 'portfolio' => 'portfolio/type',
+ 'qtype' => 'question/type',
+ 'qformat' => 'question/format');
+/*
+ $mods = get_plugin_list('mod');
+ foreach ($mods as $mod => $moddir) {
+ if (!$subplugins = plugin_supports('mod', $mod, FEATURE_MOD_SUBPLUGINS, false)) {
+ continue;
+ }
+ foreach ($subplugins as $subtype=>$dir) {
+ $info[$subtype] = $dir;
+ }
+ }
+*/
+ // do not include themes if in non-standard location
+ if ($CFG->themedir === $CFG->dirroot.'/theme') {
+ $info['theme'] = 'theme';
+ }
+
+ // local is always last
+ $info['local'] = 'local';
+
+ $fullinfo = array();
+ foreach ($info as $type => $dir) {
+ $fullinfo[$type] = $CFG->dirroot.'/'.$dir;
+ }
+ $fullinfo['theme'] = $CFG->themedir;
+ }
+
+ return ($fullpaths ? $fullinfo : $info);
+}
+
+/**
+ * Simplified version of get_list_of_plugins()
+ * @param string $plugintype type of plugin
+ * @param bool $fullpaths false means relative paths from dirroot
+ * @return array name=>fulllocation pairs of plugins of given type
+ */
+function get_plugin_list($plugintype, $fullpaths=true) {
+ global $CFG;
+
+ $ignored = array('CVS', '_vti_cnf', 'simpletest', 'db');
+
+ if ($plugintype === '') {
+ $plugintype = 'mod';
+ }
+
+ if ($plugintype === 'mod') {
+ // mod is eán exception because we have to call this function from get_plugin_types()
+ $fulldir = $CFG->dirroot.'/mod';
+ $dir = $fullpaths ? $fulldir : 'mod';
+
+ } else {
+ $fulltypes = get_plugin_types(true);
+ $types = get_plugin_types($fullpaths);
+ if (!array_key_exists($plugintype, $types)) {
+ return array();
+ }
+ $fulldir = $fulltypes[$plugintype];
+ $dir = $types[$plugintype];
+ if (!file_exists($fulldir)) {
+ return array();
+ }
+ }
+
+ $result = array();
+
+ $items = new DirectoryIterator($fulldir);
+ foreach ($items as $item) {
+ if ($item->isDot() or !$item->isDir()) {
+ continue;
+ }
+ $pluginname = $item->getFilename();
+ if (in_array($pluginname, $ignored)) {
+ continue;
+ }
+ if ($pluginname !== clean_param($pluginname, PARAM_SAFEDIR)) {
+ // better ignore plugins with problematic names here
+ continue;
+ }
+ $result[$pluginname] = $dir.'/'.$pluginname;
+ }
+
+ ksort($result);
+ return $result;
+}
+
+/**
+ * Lists plugin-like directories within specified directory
*
- * @global object
- * @param string $plugin dir under we'll look for plugins (defaults to 'mod')
+ * This function was originally used for standar Moodle plugins, please use
+ * new get_plugin_list() now.
+ *
+ * This function is used for general directory listing and backwards compability.
+ *
+ * @param string $directory relatice directory from root
* @param string $exclude dir name to exclude from the list (defaults to none)
* @param string $basedir full path to the base dir where $plugin resides (defaults to $CFG->dirroot)
- * @return array Array of plugins found under the requested parameters
+ * @return array Sorted array of directory names found under the requested parameters
*/
-function get_list_of_plugins($plugin='mod', $exclude='', $basedir='') {
+function get_list_of_plugins($directory='mod', $exclude='', $basedir='') {
global $CFG;
$plugins = array();
if (empty($basedir)) {
-
- # This switch allows us to use the appropiate theme directory - and potentialy alternatives for other plugins
- switch ($plugin) {
- case "theme":
- $basedir = $CFG->themedir;
- break;
-
- default:
- $basedir = $CFG->dirroot .'/'. $plugin;
+ // This switch allows us to use the appropiate theme directory - and potentialy alternatives for other plugins
+ switch ($directory) {
+ case "theme":
+ $basedir = $CFG->themedir;
+ break;
+ default:
+ $basedir = $CFG->dirroot .'/'. $directory;
}
} else {
- $basedir = $basedir .'/'. $plugin;
+ $basedir = $basedir .'/'. $directory;
}
if (file_exists($basedir) && filetype($basedir) == 'dir') {
@@ -7121,19 +7261,17 @@ function moodle_needs_upgrading() {
if ($version > $CFG->version) {
return true;
}
- if ($mods = get_list_of_plugins('mod')) {
- foreach ($mods as $mod) {
- $fullmod = $CFG->dirroot .'/mod/'. $mod;
- $module = new object();
- if (!is_readable($fullmod .'/version.php')) {
- notify('Module "'. $mod .'" is not readable - check permissions');
- continue;
- }
- include_once($fullmod .'/version.php'); # defines $module with version etc
- if ($currmodule = $DB->get_record('modules', array('name'=>$mod))) {
- if ($module->version > $currmodule->version) {
- return true;
- }
+ $mods = get_plugin_list('mod');
+ foreach ($mods as $mod => $fullmod) {
+ $module = new object();
+ if (!is_readable($fullmod .'/version.php')) {
+ notify('Module "'. $mod .'" is not readable - check permissions');
+ continue;
+ }
+ include_once($fullmod .'/version.php'); # defines $module with version etc
+ if ($currmodule = $DB->get_record('modules', array('name'=>$mod))) {
+ if ($module->version > $currmodule->version) {
+ return true;
}
}
}
diff --git a/lib/portfoliolib.php b/lib/portfoliolib.php
index c0a4041784d..4bd415dea48 100644
--- a/lib/portfoliolib.php
+++ b/lib/portfoliolib.php
@@ -669,11 +669,11 @@ function portfolio_plugin_sanity_check($plugins=null) {
if (is_string($plugins)) {
$plugins = array($plugins);
} else if (empty($plugins)) {
- $plugins = get_list_of_plugins('portfolio/type');
+ $plugins = get_plugin_list('portfolio');
}
$insane = array();
- foreach ($plugins as $plugin) {
+ foreach ($plugins as $plugin => $dir) {
if ($result = portfolio_static_function($plugin, 'plugin_sanity_check')) {
$insane[$plugin] = $result;
}
diff --git a/lib/questionlib.php b/lib/questionlib.php
index b4753ad5c65..0114058ad81 100644
--- a/lib/questionlib.php
+++ b/lib/questionlib.php
@@ -166,10 +166,10 @@ require_once("$CFG->dirroot/question/type/questiontype.php");
// Load the questiontype.php file for each question type
// These files in turn call question_register_questiontype()
// with a new instance of each qtype class.
-$qtypenames = get_list_of_plugins('question/type');
-foreach($qtypenames as $qtypename) {
+$qtypenames = get_plugin_list('qtype');
+foreach($qtypenames as $qtypename => $qdir) {
// Instanciates all plug-in question types
- $qtypefilepath= "$CFG->dirroot/question/type/$qtypename/questiontype.php";
+ $qtypefilepath= "$qdir/questiontype.php";
// echo "Loading $qtypename
"; // Uncomment for debugging
if (is_readable($qtypefilepath)) {
@@ -2590,14 +2590,14 @@ function question_categorylist($categoryid) {
function get_import_export_formats( $type ) {
global $CFG;
- $fileformats = get_list_of_plugins("question/format");
+ $fileformats = get_plugin_list("qformat");
$fileformatname=array();
require_once( "{$CFG->dirroot}/question/format.php" );
- foreach ($fileformats as $key => $fileformat) {
- $format_file = $CFG->dirroot . "/question/format/$fileformat/format.php";
- if (file_exists( $format_file ) ) {
- require_once( $format_file );
+ foreach ($fileformats as $fileformat=>$fdir) {
+ $format_file = "$fdir/format.php";
+ if (file_exists($format_file) ) {
+ require_once($format_file);
}
else {
continue;
diff --git a/lib/setup.php b/lib/setup.php
index c0c8b6f2851..633cfb0ce99 100644
--- a/lib/setup.php
+++ b/lib/setup.php
@@ -187,6 +187,11 @@ global $SCRIPT;
$CFG->libdir = $CFG->dirroot .'/lib';
+ if (!isset($CFG->themedir)) {
+ $CFG->themedir = $CFG->dirroot.'/theme';
+ $CFG->themewww = $CFG->wwwroot.'/theme';
+ }
+
require_once($CFG->libdir .'/setuplib.php'); // Functions that MUST be loaded first
/// Time to start counting
@@ -509,10 +514,6 @@ global $SCRIPT;
/// Load up theme variables (colours etc)
- if (!isset($CFG->themedir)) {
- $CFG->themedir = $CFG->dirroot.'/theme';
- $CFG->themewww = $CFG->wwwroot.'/theme';
- }
$CFG->httpsthemewww = $CFG->themewww;
if (isset($_GET['theme'])) {
diff --git a/lib/upgradelib.php b/lib/upgradelib.php
index edbaee21428..8317655a5c0 100644
--- a/lib/upgradelib.php
+++ b/lib/upgradelib.php
@@ -77,7 +77,7 @@ class upgrade_requires_exception extends moodle_exception {
$a->pluginname = $plugin;
$a->pluginversion = $pluginversion;
$a->currentmoodle = $currentmoodle;
- $a->requiremoodle = $currentmoodle;
+ $a->requiremoodle = $requiremoodle;
parent::__construct('pluginrequirementsnotmet', 'error', "$CFG->wwwroot/$CFG->admin/index.php", $a);
}
}
@@ -256,23 +256,19 @@ function upgrade_block_savepoint($result, $version, $blockname, $allowabort=true
* @param bool $allowabort allow user to abort script execution here
* @return void
*/
-function upgrade_plugin_savepoint($result, $version, $type, $dir, $allowabort=true) {
+function upgrade_plugin_savepoint($result, $version, $type, $plugin, $allowabort=true) {
+ $component = $type.'_'.$plugin;
+
if (!$result) {
- throw new upgrade_exception("$type/$dir", $version);
+ throw new upgrade_exception($component, $version);
}
- /// TODO: Check that $type is a correct type - based on get_plugin_types()
- /// TODO: Check that $dir (that perhaps should be named $name) is an existing plugin
-
- $fullname = $type.'_'.$dir;
- $component = $type.'/'.$dir;
-
- $installedversion = get_config($fullname, 'version');
+ $installedversion = get_config($component, 'version');
if ($installedversion >= $version) {
// Something really wrong is going on in the upgrade script
throw new downgrade_exception($component, $installedversion, $version);
}
- set_config('version', $version, $fullname);
+ set_config('version', $version, $component);
upgrade_log(UPGRADE_LOG_NORMAL, $component, 'Upgrade savepoint reached');
// Reset upgrade timeout to default
@@ -287,14 +283,10 @@ function upgrade_plugin_savepoint($result, $version, $type, $dir, $allowabort=tr
/**
* Upgrade plugins
- *
- * @global object
- * @global object
* @param string $type The type of plugins that should be updated (e.g. 'enrol', 'qtype')
- * @param string $dir The directory where the plugins are located (e.g. 'question/questiontypes')
- * @param string $return The url to prompt the user to continue to
+ * return void
*/
-function upgrade_plugins($type, $dir, $startcallback, $endcallback, $verbose) {
+function upgrade_plugins($type, $startcallback, $endcallback, $verbose) {
global $CFG, $DB;
/// special cases
@@ -304,12 +296,10 @@ function upgrade_plugins($type, $dir, $startcallback, $endcallback, $verbose) {
return upgrade_plugins_blocks($startcallback, $endcallback, $verbose);
}
- $plugs = get_list_of_plugins($dir);
+ $plugs = get_plugin_list($type);
- foreach ($plugs as $plug) {
-
- $fullplug = $CFG->dirroot.'/'.$dir.'/'.$plug;
- $component = $type.'/'.$plug; // standardised plugin name
+ foreach ($plugs as $plug=>$fullplug) {
+ $component = $type.'_'.$plug; // standardised plugin name
if (!is_readable($fullplug.'/version.php')) {
continue;
@@ -322,8 +312,8 @@ function upgrade_plugins($type, $dir, $startcallback, $endcallback, $verbose) {
throw new plugin_defective_exception($component, 'Missing version value in version.php');
}
- $plugin->name = $plug; // The name MUST match the directory
- $plugin->fullname = $type.'_'.$plug; // The name MUST match the directory
+ $plugin->name = $plug;
+ $plugin->fullname = $component;
if (!empty($plugin->requires)) {
@@ -399,16 +389,15 @@ function upgrade_plugins($type, $dir, $startcallback, $endcallback, $verbose) {
function upgrade_plugins_modules($startcallback, $endcallback, $verbose) {
global $CFG, $DB;
- $mods = get_list_of_plugins('mod');
+ $mods = get_plugin_list('mod');
- foreach ($mods as $mod) {
+ foreach ($mods as $mod=>$fullmod) {
if ($mod == 'NEWMODULE') { // Someone has unzipped the template, ignore it
continue;
}
- $fullmod = $CFG->dirroot.'/mod/'.$mod;
- $component = 'mod/'.$mod;
+ $component = 'mod_'.$mod;
if (!is_readable($fullmod.'/version.php')) {
throw new plugin_defective_exception($component, 'Missing version.php');
@@ -510,9 +499,9 @@ function upgrade_plugins_blocks($startcallback, $endcallback, $verbose) {
//Is this a first install
$first_install = null;
- $blocks = get_list_of_plugins('blocks');
+ $blocks = get_plugin_list('block');
- foreach ($blocks as $blockname) {
+ foreach ($blocks as $blockname=>$fullblock) {
if (is_null($first_install)) {
$first_install = ($DB->count_records('block') == 0);
@@ -522,8 +511,7 @@ function upgrade_plugins_blocks($startcallback, $endcallback, $verbose) {
continue;
}
- $fullblock = $CFG->dirroot.'/blocks/'.$blockname;
- $component = 'block/'.$blockname;
+ $component = 'block_'.$blockname;
if (!is_readable($fullblock.'/block_'.$blockname.'.php')) {
throw new plugin_defective_exception('block/'.$blockname, 'Missing main block class file.');
@@ -611,8 +599,8 @@ function upgrade_plugins_blocks($startcallback, $endcallback, $verbose) {
}
// Upgrade various componebts
- events_update_definition($component);
update_capabilities($component);
+ events_update_definition($component);
message_update_providers($component);
$endcallback($component, false, $verbose);
@@ -636,71 +624,9 @@ function upgrade_plugins_blocks($startcallback, $endcallback, $verbose) {
}
}
-/**
- * This function checks to see whether local database customisations are up-to-date
- * by comparing $CFG->local_version to the variable $local_version defined in
- * local/version.php. If not, it looks for a function called 'xmldb_local_upgrade'
- * in a file called 'local/db/upgrade.php', and if it's there calls it with the
- * appropiate $oldversion parameter. Then it updates $CFG->local_version.
- *
- * @global object
- * @global object
- */
-function upgrade_local_db($startcallback, $endcallback) {
- global $CFG, $DB;
-
- // if we don't have code version, just return false
- if (!file_exists($CFG->dirroot.'/local/version.php')) {
- return;
- }
-
- $local_version = null;
- require($CFG->dirroot.'/local/version.php'); // Get code versions
-
- if (empty($CFG->local_version)) { // install
- $startcallback('local', true);
-
- if (file_exists($CFG->dirroot.'/local/db/install.php')) {
- require_once($CFG->dirroot.'/local/db/install.php');
- xmldb_local_install();
- }
- set_config('local_version', $local_version);
-
- /// Install various components
- events_update_definition('local');
- update_capabilities('local');
- message_update_providers('local');
-
- $endcallback('local', true);
-
- } else if ($local_version > $CFG->local_version) { // upgrade!
- $startcallback('local', false);
-
- if (file_exists($CFG->dirroot.'/local/db/upgrade.php')) {
- require_once($CFG->dirroot.'/local/db/upgrade.php');
- xmldb_local_upgrade($CFG->local_version);
- }
- set_config('local_version', $local_version);
-
- /// Upgrade various components
- events_update_definition('local');
- update_capabilities('local');
- message_update_providers('local');
-
- $endcallback('local', false);
-
- } else if ($local_version < $CFG->local_version) {
- throw new downgrade_exception('local', $CFG->local_version, $local_version);
- }
-}
-
-
/**
* upgrade logging functions
- *
- * @global object
*/
-
function upgrade_handle_exception($ex, $plugin=null) {
global $CFG;
@@ -1040,7 +966,6 @@ function install_core($version, $verbose) {
// Continue with the instalation
events_update_definition('moodle');
message_update_providers('moodle');
- message_update_providers('message');
// Write default settings unconditionlly
admin_apply_default_settings(NULL, true);
@@ -1070,6 +995,17 @@ function upgrade_core($version, $verbose) {
print_upgrade_part_start('moodle', false, $verbose);
+ // one time special local migration pre 2.0 upgrade script
+ if ($version < 2007101600) {
+ $pre20upgradefile = "$CFG->dirrot/local/upgrade_pre20.php";
+ if (file_exists($pre20upgradefile)) {
+ set_time_limit(0);
+ require($pre20upgradefile);
+ // reset upgrade timeout to default
+ upgrade_set_timeout();
+ }
+ }
+
$result = xmldb_main_upgrade($CFG->version);
if ($version > $CFG->version) {
// store version if not already there
@@ -1080,7 +1016,6 @@ function upgrade_core($version, $verbose) {
update_capabilities('moodle');
events_update_definition('moodle');
message_update_providers('moodle');
- message_update_providers('message');
remove_dir($CFG->dataroot . '/cache', true); // flush cache
@@ -1102,7 +1037,7 @@ function upgrade_noncore($verbose) {
try {
$plugintypes = get_plugin_types();
foreach ($plugintypes as $type=>$location) {
- upgrade_plugins($type, $location, 'print_upgrade_part_start', 'print_upgrade_part_end', $verbose);
+ upgrade_plugins($type, 'print_upgrade_part_start', 'print_upgrade_part_end', $verbose);
}
} catch (Exception $ex) {
upgrade_handle_exception($ex);
@@ -1119,14 +1054,6 @@ function upgrade_noncore($verbose) {
upgrade_handle_exception($ex);
}
}
-
- // Check for local database customisations
- try {
- require_once("$CFG->dirroot/lib/locallib.php");
- upgrade_local_db('print_upgrade_part_start', 'print_upgrade_part_end', $verbose);
- } catch (Exception $ex) {
- upgrade_handle_exception($ex);
- }
}
/**
diff --git a/lib/weblib.php b/lib/weblib.php
index 71db25fdf12..424a0b5826e 100644
--- a/lib/weblib.php
+++ b/lib/weblib.php
@@ -3029,41 +3029,37 @@ function style_sheet_setup($lastmodified=0, $lifetime=300, $themename='', $force
if ($themename == 'standard') { // Add any standard styles included in any modules
if (!empty($THEME->modsheets)) { // Search for styles.php within activity modules
- if ($mods = get_list_of_plugins('mod')) {
- foreach ($mods as $mod) {
- if (file_exists($CFG->dirroot.'/mod/'.$mod.'/styles.php')) {
- $files[] = array($CFG->dirroot, '/mod/'.$mod.'/styles.php');
- }
+ $mods = get_plugin_list('mod');
+ foreach ($mods as $mod => $moddir) {
+ if (file_exists($moddir.'/styles.php')) {
+ $files[] = array($moddir.'/styles.php');
}
}
}
if (!empty($THEME->blocksheets)) { // Search for styles.php within block modules
- if ($mods = get_list_of_plugins('blocks')) {
- foreach ($mods as $mod) {
- if (file_exists($CFG->dirroot.'/blocks/'.$mod.'/styles.php')) {
- $files[] = array($CFG->dirroot, '/blocks/'.$mod.'/styles.php');
- }
+ $mods = get_plugin_list('blocks');
+ foreach ($mods as $mod => $moddir) {
+ if (file_exists($moddir.'/styles.php')) {
+ $files[] = array($moddir.'/styles.php');
}
}
}
if (!isset($THEME->courseformatsheets) || $THEME->courseformatsheets) { // Search for styles.php in course formats
- if ($mods = get_list_of_plugins('format','',$CFG->dirroot.'/course')) {
- foreach ($mods as $mod) {
- if (file_exists($CFG->dirroot.'/course/format/'.$mod.'/styles.php')) {
- $files[] = array($CFG->dirroot, '/course/format/'.$mod.'/styles.php');
- }
+ $mods = get_plugin_list('format');
+ foreach ($mods as $mod => $moddir) {
+ if (file_exists($moddir.'/styles.php')) {
+ $files[] = array($moddir.'/styles.php');
}
}
}
if (!isset($THEME->gradereportsheets) || $THEME->gradereportsheets) { // Search for styles.php in grade reports
- if ($reports = get_list_of_plugins('grade/report')) {
- foreach ($reports as $report) {
- if (file_exists($CFG->dirroot.'/grade/report/'.$report.'/styles.php')) {
- $files[] = array($CFG->dirroot, '/grade/report/'.$report.'/styles.php');
- }
+ $reports = get_plugin_list('gradereport');
+ foreach ($reports as $report => $reportdir) {
+ if (file_exists($reportdir.'/styles.php')) {
+ $files[] = array($reportdir.'/styles.php');
}
}
}
diff --git a/local/readme.txt b/local/readme.txt
new file mode 100644
index 00000000000..b4cb65185d9
--- /dev/null
+++ b/local/readme.txt
@@ -0,0 +1,174 @@
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see .
+
+/**
+ * Readme file for local customisations
+ *
+ * @package local
+ * @copyright 2009 Petr Skoda (http://skodak.org)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+Local customisations directory
+==============================
+This directory is the recommended place for local customisations.
+
+Wherever possible, customisations should be written using one of the
+standard plug-in points like modules, blocks, auth plugins, themes, etc.
+
+See also http://docs.moodle.org/en/Development:Local_customisation for more
+information.
+
+
+Directory structure
+-------------------
+This directory has standard plugin structure. All standard plugin features
+are supported. There may be some extra files with special meaning in /local/.
+
+Sample /local/ directory listing:
+/local/nicehack/ - first customisation plugin
+/local/otherhack/ - other customisation plugin
+/local/upgrade_pre20.php - one time upgrade and migration script which is
+ executed before main 2.0 upgrade
+/local/defaults.php - custom admin setting defaults
+
+
+Custom capabilities
+-------------------
+Each plugin may define own capabilities. It is not recommended to define
+capabilities belonging to other plugins here, but it should work too.
+
+/local/nicehack/access.php content
+ array(
+ 'captype' => 'read',
+ 'contextlevel' => CONTEXT_SYSTEM,
+ ),
+);
+?>
+
+
+Custom language strings
+-----------------------
+If customisation needs new strings it is recommended to use normal plugin
+strings.
+
+sample language file /local/nicehack/lang/en_utf8.php
+
+
+use of the new string in code
+echo get_string('hello', 'local_nicehack', 'petr');
+
+
+Custom admin menu items
+----------------------
+It is possible to add new items and categories to the admin_tree block.
+I you need to define new admin setting classes put them into separate
+file and require_once() from settings.php
+
+For example if you want to add new external page use following
+/local/nicehack/settings.php
+add('root', new admin_category('tweaks', 'Custom tweaks'));
+$ADMIN->add('tweaks', new admin_externalpage('nicehackery', 'Tweak something',
+ $CFG->wwwroot.'/local/nicehack/setuppage.php'));
+?>
+
+
+Custom event handlers
+---------------------
+Events intended primarily for communication "core --> plugins". (It should not
+be use in opposite direction!) In theory it could be also used for
+"plugin --> plugin" communication too. The list of core events is documented
+in lib/db/events.php
+
+sample files
+/local/nicehack/db/events.php
+$handlers = array (
+ 'user_deleted' => array (
+ 'handlerfile' => '/local/nicehack/lib.php',
+ 'handlerfunction' => 'nicehack_userdeleted_handler',
+ 'schedule' => 'instant'
+ ),
+);
+
+NOTE: events are not yet fulyl implemented in current Moodle 2.0dev.
+
+
+Custom db tables
+----------------
+XMLDB editors is the recommended tool. Please note that modification
+of core table structure is highly discouraged.
+
+If you really really really need to modify core tables you might want to do
+that in install.php and later upgrade.php
+
+List of upgrade related files:
+/local/nicehack/db/install.xml - contains XML definition of new tables
+/local/nicehack/db/install.php - executed after db creation, may be also used
+ for general install code
+/local/nicehack/db/upgrade.php - executed when version changes
+/local/nicehack/version.php - version specification file
+
+
+Customised site defaults
+------------------------
+Different default site settings can be stored in file /local/defaults.php.
+These new defaults are used during installation, upgrade and later are
+displayed as default values in admin settings.
+
+Sample /local/defaults.php file content:
+
+
+First bracket contains string from column plugin of config_plugins table.
+Second bracket is the name of setting. In the admin settings UI the plugin and
+name of setting is separated by "|".
+
+Please note that not all settings are converted to admin_tree yet.
+
+
+1.9.x upgrade notes
+-------------------
+1.9.x contains basic support for local hacks placed directly into
+/local/ directory. This old local API is not supported any more in 2.0.
+
+You an use /local/upgrade_pre20.php script for any code that needs to
+be executed before the main upgrade to 2.0.
+
+
+
+Other customisation information
+===============================
+
+Local language pack modifications
+---------------------------------
+Moodle supports other type of local customisation of standard language
+packs. If you want to create your own language pack based on another
+language create new dataroot directory with "_local" suffix, for example
+following file with content changes string "Login" to "Sign in":
+moodledata/lang/en_utf8_local
+
+
+See also http://docs.moodle.org/en/Language_editing
diff --git a/message/db/messages.php b/message/db/messages.php
deleted file mode 100644
index 78ebf7d1dae..00000000000
--- a/message/db/messages.php
+++ /dev/null
@@ -1,37 +0,0 @@
- array (
- )
-
-);
-
-
-?>
diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php
index 73bc7543c67..6ce51f22379 100644
--- a/mod/assignment/lib.php
+++ b/mod/assignment/lib.php
@@ -2156,9 +2156,9 @@ function assignment_cron () {
global $CFG, $USER, $DB;
/// first execute all crons in plugins
- if ($plugins = get_list_of_plugins('mod/assignment/type')) {
- foreach ($plugins as $plugin) {
- require_once("$CFG->dirroot/mod/assignment/type/$plugin/assignment.class.php");
+ if ($plugins = get_plugin_list('assignment')) {
+ foreach ($plugins as $plugin=>$dir) {
+ require_once("$dir/assignment.class.php");
$assignmentclass = "assignment_$plugin";
$ass = new $assignmentclass();
$ass->cron();
@@ -2966,8 +2966,8 @@ function assignment_get_coursemodule_info($coursemodule) {
*/
function assignment_types() {
$types = array();
- $names = get_list_of_plugins('mod/assignment/type');
- foreach ($names as $name) {
+ $names = get_plugin_list('assignment');
+ foreach ($names as $name=>$dir) {
$types[$name] = get_string('type'.$name, 'assignment');
}
asort($types);
@@ -3137,7 +3137,8 @@ function assignment_get_types() {
}
/// Drop-in extra assignment types
- $assignmenttypes = get_list_of_plugins('mod/assignment/type');
+ $assignmenttypes = get_plugin_list('assignment');
+ $assignmenttypes = array_keys($assignmenttypes);
foreach ($assignmenttypes as $assignmenttype) {
if (!empty($CFG->{'assignment_hide_'.$assignmenttype})) { // Not wanted
continue;
@@ -3197,8 +3198,8 @@ function assignment_reset_userdata($data) {
$status = array();
- foreach (get_list_of_plugins('mod/assignment/type') as $type) {
- require_once("$CFG->dirroot/mod/assignment/type/$type/assignment.class.php");
+ foreach (get_plugin_list('mod/assignment/type') as $type=>$dir) {
+ require_once("$dir/assignment.class.php");
$assignmentclass = "assignment_$type";
$ass = new $assignmentclass();
$status = array_merge($status, $ass->reset_userdata($data));
@@ -3342,6 +3343,7 @@ function assignment_supports($feature) {
case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
case FEATURE_GRADE_HAS_GRADE: return true;
case FEATURE_GRADE_OUTCOMES: return true;
+ case FEATURE_MOD_SUBPLUGINS: return array('assignment'=>'mod/assignment/type'); // to be hopefully removed in 2.0
default: return null;
}
diff --git a/mod/assignment/restorelib.php b/mod/assignment/restorelib.php
index 370d6ab95de..c33217458f9 100644
--- a/mod/assignment/restorelib.php
+++ b/mod/assignment/restorelib.php
@@ -81,7 +81,7 @@
// skip restore of plugins that are not installed
static $plugins;
if (!isset($plugins)) {
- $plugins = get_list_of_plugins('mod/assignment/type');
+ $plugins = array_keys(get_plugin_list('assignment'));
}
if (!in_array($assignment->assignmenttype, $plugins)) {
diff --git a/mod/chat/lib.php b/mod/chat/lib.php
index 530a92a059d..2c7e44e4c9c 100644
--- a/mod/chat/lib.php
+++ b/mod/chat/lib.php
@@ -30,9 +30,11 @@ $CFG->chat_ajax_debug = false;
$CFG->chat_use_cache = false;
// The HTML head for the message window to start with ( is used to get some browsers starting with output
+global $CHAT_HTMLHEAD;
$CHAT_HTMLHEAD = "\n\n\n".padding(200);
// The HTML head for the message window to start with (with js scrolling)
+global $CHAT_HTMLHEAD_JS;
$CHAT_HTMLHEAD_JS = <<