diff --git a/admin/settings/plugins.php b/admin/settings/plugins.php index c2b2b2280b5..29d0665dd3f 100644 --- a/admin/settings/plugins.php +++ b/admin/settings/plugins.php @@ -5,66 +5,34 @@ */ if ($hassiteconfig) { + require_once("$CFG->libdir/pluginlib.php"); + $allplugins = plugin_manager::instance()->get_plugins(); + $ADMIN->add('modules', new admin_page_pluginsoverview()); + + // activity modules $ADMIN->add('modules', new admin_category('modsettings', new lang_string('activitymodules'))); $ADMIN->add('modsettings', new admin_page_managemods()); - $modules = $DB->get_records('modules', array(), "name ASC"); - foreach ($modules as $module) { - $modulename = $module->name; - if (!file_exists("$CFG->dirroot/mod/$modulename/lib.php")) { - continue; - } - $strmodulename = new lang_string('modulename', 'mod_'.$modulename); - if (file_exists($CFG->dirroot.'/mod/'.$modulename.'/settings.php')) { - // do not show disabled modules in tree, keep only settings link on manage page - $settings = new admin_settingpage('modsetting'.$modulename, $strmodulename, 'moodle/site:config', !$module->visible); - include($CFG->dirroot.'/mod/'.$modulename.'/settings.php'); - if ($settings) { - $ADMIN->add('modsettings', $settings); - } - } + foreach ($allplugins['mod'] as $module) { + $module->load_settings($ADMIN, 'modsettings', $hassiteconfig); } // hidden script for converting journals to online assignments (or something like that) linked from elsewhere $ADMIN->add('modsettings', new admin_externalpage('oacleanup', 'Online Assignment Cleanup', $CFG->wwwroot.'/'.$CFG->admin.'/oacleanup.php', 'moodle/site:config', true)); + // blocks $ADMIN->add('modules', new admin_category('blocksettings', new lang_string('blocks'))); $ADMIN->add('blocksettings', new admin_page_manageblocks()); - $blocks = $DB->get_records('block', array(), "name ASC"); - foreach ($blocks as $block) { - $blockname = $block->name; - if (!file_exists("$CFG->dirroot/blocks/$blockname/block_$blockname.php")) { - continue; - } - $strblockname = new lang_string('pluginname', 'block_'.$blockname); - if (file_exists($CFG->dirroot.'/blocks/'.$blockname.'/settings.php')) { - $settings = new admin_settingpage('blocksetting'.$blockname, $strblockname, 'moodle/site:config', !$block->visible); - include($CFG->dirroot.'/blocks/'.$blockname.'/settings.php'); - if ($settings) { - $ADMIN->add('blocksettings', $settings); - } - } + foreach ($allplugins['block'] as $block) { + $block->load_settings($ADMIN, 'blocksettings', $hassiteconfig); } // message outputs $ADMIN->add('modules', new admin_category('messageoutputs', new lang_string('messageoutputs', 'message'))); $ADMIN->add('messageoutputs', new admin_page_managemessageoutputs()); $ADMIN->add('messageoutputs', new admin_page_defaultmessageoutputs()); - require_once($CFG->dirroot.'/message/lib.php'); - $processors = get_message_processors(); - foreach ($processors as $processor) { - $processorname = $processor->name; - if (!$processor->available) { - continue; - } - if ($processor->hassettings) { - $strprocessorname = new lang_string('pluginname', 'message_'.$processorname); - $settings = new admin_settingpage('messagesetting'.$processorname, $strprocessorname, 'moodle/site:config', !$processor->enabled); - include($CFG->dirroot.'/message/output/'.$processor->name.'/settings.php'); - if ($settings) { - $ADMIN->add('messageoutputs', $settings); - } - } + foreach ($allplugins['message'] as $processor) { + $processor->load_settings($ADMIN, 'messageoutputs', $hassiteconfig); } // authentication plugins @@ -92,72 +60,27 @@ if ($hassiteconfig) { $temp->add(new admin_setting_configtext('recaptchaprivatekey', new lang_string('recaptchaprivatekey', 'admin'), new lang_string('configrecaptchaprivatekey', 'admin'), '', PARAM_NOTAGS)); $ADMIN->add('authsettings', $temp); - - $auths = get_plugin_list('auth'); - $authsenabled = get_enabled_auth_plugins(); - foreach ($auths as $authname => $authdir) { - $strauthname = new lang_string('pluginname', "auth_{$authname}"); - // do not show disabled auths in tree, keep only settings link on manage page - $enabled = in_array($authname, $authsenabled); - if (file_exists($authdir.'/settings.php')) { - // TODO: finish implementation of common settings - locking, etc. - $settings = new admin_settingpage('authsetting'.$authname, $strauthname, 'moodle/site:config', !$enabled); - include($authdir.'/settings.php'); - if ($settings) { - $ADMIN->add('authsettings', $settings); - } - - } else { - $ADMIN->add('authsettings', new admin_externalpage('authsetting'.$authname, $strauthname, "$CFG->wwwroot/$CFG->admin/auth_config.php?auth=$authname", 'moodle/site:config', !$enabled)); - } + foreach ($allplugins['auth'] as $auth) { + $auth->load_settings($ADMIN, 'authsettings', $hassiteconfig); } - // Enrolment plugins $ADMIN->add('modules', new admin_category('enrolments', new lang_string('enrolments', 'enrol'))); $temp = new admin_settingpage('manageenrols', new lang_string('manageenrols', 'enrol')); $temp->add(new admin_setting_manageenrols()); - if (empty($CFG->enrol_plugins_enabled)) { - $enabled = array(); - } else { - $enabled = explode(',', $CFG->enrol_plugins_enabled); - } - $enrols = get_plugin_list('enrol'); $ADMIN->add('enrolments', $temp); - foreach($enrols as $enrol=>$enrolpath) { - if (!file_exists("$enrolpath/settings.php")) { - continue; - } - - $settings = new admin_settingpage('enrolsettings'.$enrol, new lang_string('pluginname', 'enrol_'.$enrol), 'moodle/site:config', !in_array($enrol, $enabled)); - // settings.php may create a subcategory or unset the settings completely - include("$enrolpath/settings.php"); - if ($settings) { - $ADMIN->add('enrolments', $settings); - } - + foreach($allplugins['enrol'] as $enrol) { + $enrol->load_settings($ADMIN, 'enrolments', $hassiteconfig); } - unset($enabled); - unset($enrols); /// Editor plugins $ADMIN->add('modules', new admin_category('editorsettings', new lang_string('editors', 'editor'))); $temp = new admin_settingpage('manageeditors', new lang_string('editorsettings', 'editor')); $temp->add(new admin_setting_manageeditors()); - $htmleditors = editors_get_available(); $ADMIN->add('editorsettings', $temp); - - $editors_available = editors_get_available(); - foreach ($editors_available as $editor=>$editorstr) { - if (file_exists($CFG->dirroot . '/lib/editor/'.$editor.'/settings.php')) { - $settings = new admin_settingpage('editorsettings'.$editor, new lang_string('pluginname', 'editor_'.$editor), 'moodle/site:config'); - // settings.php may create a subcategory or unset the settings completely - include($CFG->dirroot . '/lib/editor/'.$editor.'/settings.php'); - if ($settings) { - $ADMIN->add('editorsettings', $settings); - } - } + foreach ($allplugins['editor'] as $editor) { + $editor->load_settings($ADMIN, 'editorsettings', $hassiteconfig); } /// License types @@ -218,17 +141,8 @@ if ($hassiteconfig) { } $ADMIN->add('filtersettings', $temp); - $activefilters = filter_get_globally_enabled(); - $filternames = filter_get_all_installed(); - foreach ($filternames as $filterpath => $strfiltername) { - if (file_exists("$CFG->dirroot/$filterpath/filtersettings.php")) { - $settings = new admin_settingpage('filtersetting'.str_replace('/', '', $filterpath), - $strfiltername, 'moodle/site:config', !isset($activefilters[$filterpath])); - include("$CFG->dirroot/$filterpath/filtersettings.php"); - if ($settings) { - $ADMIN->add('filtersettings', $settings); - } - } + foreach ($allplugins['filter'] as $filter) { + $filter->load_settings($ADMIN, 'filtersettings', $hassiteconfig); } @@ -325,19 +239,9 @@ if ($hassiteconfig) { $ADMIN->add('repositorysettings', new admin_externalpage('repositoryinstanceedit', new lang_string('editrepositoryinstance', 'repository'), $url, 'moodle/site:config', true), '', $url); - foreach (repository::get_types() as $repositorytype) { - //display setup page for plugins with: general options or multiple instances (e.g. has instance config) - $typeoptionnames = repository::static_function($repositorytype->get_typename(), 'get_type_option_names'); - $instanceoptionnames = repository::static_function($repositorytype->get_typename(), 'get_instance_option_names'); - if (!empty($typeoptionnames) || !empty($instanceoptionnames)) { - - $params = array('action'=>'edit', 'sesskey'=>sesskey(), 'repos'=>$repositorytype->get_typename()); - $settingsurl = new moodle_url("/$CFG->admin/repository.php", $params); - $repositoryexternalpage = new admin_externalpage('repositorysettings'.$repositorytype->get_typename(), $repositorytype->get_readablename(), $settingsurl); - $ADMIN->add('repositorysettings', $repositoryexternalpage); - } + foreach ($allplugins['repository'] as $repositorytype) { + $repositorytype->load_settings($ADMIN, 'repositorysettings', $hassiteconfig); } -} /// Web services $ADMIN->add('modules', new admin_category('webservicesettings', new lang_string('webservices', 'webservice'))); @@ -375,17 +279,8 @@ if ($hassiteconfig) { 'admin'), new lang_string('configenablewsdocumentation', 'admin', $wsdoclink), false)); $ADMIN->add('webservicesettings', $temp); /// links to protocol pages - $webservices_available = get_plugin_list('webservice'); - $active_webservices = empty($CFG->webserviceprotocols) ? array() : explode(',', $CFG->webserviceprotocols); - foreach ($webservices_available as $webservice => $location) { - if (file_exists("$location/settings.php")) { - $name = new lang_string('pluginname', 'webservice_'.$webservice); - $settings = new admin_settingpage('webservicesetting'.$webservice, $name, 'moodle/site:config', !in_array($webservice, $active_webservices) or empty($CFG->enablewebservices)); - include("$location/settings.php"); - if ($settings) { - $ADMIN->add('webservicesettings', $settings); - } - } + foreach ($allplugins['webservice'] as $webservice) { + $webservice->load_settings($ADMIN, 'webservicesettings', $hassiteconfig); } /// manage token page link $ADMIN->add('webservicesettings', new admin_externalpage('addwebservicetoken', new lang_string('managetokens', 'webservice'), "$CFG->wwwroot/$CFG->admin/webservice/tokens.php", 'moodle/site:config', true)); @@ -395,6 +290,7 @@ if ($hassiteconfig) { $temp->add(new admin_setting_heading('webservicesaredisabled', '', new lang_string('disabledwarning', 'webservice'))); } $ADMIN->add('webservicesettings', $temp); +} // Question type settings if ($hassiteconfig || has_capability('moodle/question:config', $systemcontext)) { @@ -405,17 +301,8 @@ if ($hassiteconfig || has_capability('moodle/question:config', $systemcontext)) // Question type settings. $ADMIN->add('modules', new admin_category('qtypesettings', new lang_string('questiontypes', 'admin'))); $ADMIN->add('qtypesettings', new admin_page_manageqtypes()); - $qtypes = get_plugin_list('qtype'); - foreach ($qtypes as $qtype => $path) { - $settingsfile = $path . '/settings.php'; - if (file_exists($settingsfile)) { - $settings = new admin_settingpage('qtypesetting' . $qtype, - new lang_string('pluginname', 'qtype_' . $qtype), 'moodle/question:config'); - include($settingsfile); - if ($settings) { - $ADMIN->add('qtypesettings', $settings); - } - } + foreach ($allplugins['qtype'] as $qtype) { + $qtype->load_settings($ADMIN, 'qtypesettings', $hassiteconfig); } } @@ -425,10 +312,8 @@ if ($hassiteconfig && !empty($CFG->enableplagiarism)) { $ADMIN->add('plagiarism', new admin_externalpage('manageplagiarismplugins', new lang_string('manageplagiarism', 'plagiarism'), $CFG->wwwroot . '/' . $CFG->admin . '/plagiarism.php')); - foreach (get_plugin_list('plagiarism') as $plugin => $plugindir) { - if (file_exists($plugindir.'/settings.php')) { - $ADMIN->add('plagiarism', new admin_externalpage('plagiarism'.$plugin, new lang_string($plugin, 'plagiarism_'.$plugin), "$CFG->wwwroot/plagiarism/$plugin/settings.php", 'moodle/site:config')); - } + foreach ($allplugins['plagiarism'] as $plugin) { + $plugin->load_settings($ADMIN, 'plagiarism', $hassiteconfig); } } $ADMIN->add('reports', new admin_externalpage('comments', new lang_string('comments'), $CFG->wwwroot.'/comment/', 'moodle/site:viewreports')); @@ -515,6 +400,8 @@ if ($hassiteconfig) { $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. We can not use $allplugins here foreach (get_plugin_list('local') as $plugin => $plugindir) { $settings_path = "$plugindir/settings.php"; if (file_exists($settings_path)) { diff --git a/enrol/imsenterprise/settings.php b/enrol/imsenterprise/settings.php index 9040b21dd67..1c7f205308e 100644 --- a/enrol/imsenterprise/settings.php +++ b/enrol/imsenterprise/settings.php @@ -27,7 +27,7 @@ defined('MOODLE_INTERNAL') || die(); if ($ADMIN->fulltree) { - require_once('locallib.php'); + require_once($CFG->dirroot.'/enrol/imsenterprise/locallib.php'); $settings->add(new admin_setting_heading('enrol_imsenterprise_settings', '', get_string('pluginname_desc', 'enrol_imsenterprise'))); diff --git a/lib/editor/tinymce/adminlib.php b/lib/editor/tinymce/adminlib.php index 5c15e1b0475..013319c7dad 100644 --- a/lib/editor/tinymce/adminlib.php +++ b/lib/editor/tinymce/adminlib.php @@ -39,12 +39,23 @@ class plugininfo_tinymce extends plugininfo_base { return new moodle_url('/lib/editor/tinymce/subplugins.php', array('delete' => $this->name, 'sesskey' => sesskey())); } - public function get_settings_url() { - global $CFG; - if (file_exists("$CFG->dirroot/lib/editor/tinymce/plugins/$this->name/settings.php")) { - return new moodle_url('/admin/settings.php', array('section'=>'tinymce'.$this->name.'settings')); - } else { - return null; + public function get_settings_section_name() { + return 'tinymce'.$this->name.'settings'; + } + + public function load_settings(part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) { + global $CFG, $USER, $DB, $OUTPUT, $PAGE; // in case settings.php wants to refer to them + $ADMIN = $adminroot; // may be used in settings.php + + $settings = null; + if ($hassiteconfig && file_exists($this->full_path('settings.php'))) { + $section = $this->get_settings_section_name(); + $settings = new admin_settingpage($section, $this->displayname, + 'moodle/site:config', $this->is_enabled() === false); + include($this->full_path('settings.php')); // this may also set $settings to null + } + if ($settings) { + $ADMIN->add($parentnodename, $settings); } } diff --git a/lib/editor/tinymce/settings.php b/lib/editor/tinymce/settings.php index 56ee3d03fab..5b16a610de8 100644 --- a/lib/editor/tinymce/settings.php +++ b/lib/editor/tinymce/settings.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die; -$ADMIN->add('editorsettings', new admin_category('editortinymce', new lang_string('pluginname', 'editor_tinymce'))); +$ADMIN->add('editorsettings', new admin_category('editortinymce', $editor->displayname, $editor->is_enabled() === false)); $settings = new admin_settingpage('editorsettingstinymce', new lang_string('settings', 'editor_tinymce')); if ($ADMIN->fulltree) { @@ -45,20 +45,11 @@ bullist,numlist,outdent,indent,|,link,unlink,|,image,nonbreaking,charmap,table,| $ADMIN->add('editortinymce', $settings); unset($settings); -$subplugins = get_plugin_list('tinymce'); -$disabled = array(); // Disabling of subplugins to be implemented later. -foreach ($subplugins as $name=>$dir) { - if (file_exists("$dir/settings.php")) { - $settings = new admin_settingpage('tinymce'.$name.'settings', new lang_string('pluginname', 'tinymce_'.$name), 'moodle/site:config', in_array($name, $disabled)); - // settings.php may create a subcategory or unset the settings completely. - include("$dir/settings.php"); - if ($settings) { - $ADMIN->add('editortinymce', $settings); - } - } +require_once("$CFG->libdir/pluginlib.php"); +$allplugins = plugin_manager::instance()->get_plugins(); +foreach ($allplugins['tinymce'] as $plugin) { + $plugin->load_settings($ADMIN, 'editortinymce', $hassiteconfig); } -unset($subplugins); -unset($disabled); // TinyMCE does not have standard settings page. $settings = null; diff --git a/lib/pluginlib.php b/lib/pluginlib.php index 6c8d1fc6e9f..5080c5bf934 100644 --- a/lib/pluginlib.php +++ b/lib/pluginlib.php @@ -1770,6 +1770,15 @@ abstract class plugininfo_base { return $updates; } + /** + * Returns the node name used in admin settings menu for this plugin settings (if applicable) + * + * @return null|string node name or null if plugin does not create settings node (default) + */ + public function get_settings_section_name() { + return null; + } + /** * Returns the URL of the plugin settings screen * @@ -1779,7 +1788,31 @@ abstract class plugininfo_base { * @return null|moodle_url */ public function get_settings_url() { - return null; + $section = $this->get_settings_section_name(); + if ($section === null) { + return null; + } + $settings = admin_get_root()->locate($section); + if ($settings && $settings instanceof admin_settingpage) { + return new moodle_url('/admin/settings.php', array('section' => $section)); + } else if ($settings && $settings instanceof admin_externalpage) { + return new moodle_url($settings->url); + } else { + return null; + } + } + + /** + * Loads plugin settings to the settings tree + * + * This function usually includes settings.php file in plugins folder. + * Alternatively it can create a link to some settings page (instance of admin_externalpage) + * + * @param part_of_admin_tree $adminroot + * @param string $parentnodename + * @param bool $hassiteconfig whether the current user has moodle/site:config capability + */ + public function load_settings(part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) { } /** @@ -1875,6 +1908,23 @@ class plugininfo_block extends plugininfo_base { return $blocks; } + /** + * Magic method getter, redirects to read only values. + * + * For block plugins pretends the object has 'visible' property for compatibility + * with plugins developed for Moodle version below 2.4 + * + * @param string $name + * @return mixed + */ + public function __get($name) { + if ($name === 'visible') { + debugging('This is now an instance of plugininfo_block, please use $block->is_enabled() instead of $block->visible', DEBUG_DEVELOPER); + return ($this->is_enabled() !== false); + } + return parent::__get($name); + } + public function init_display_name() { if (get_string_manager()->string_exists('pluginname', 'block_' . $this->name)) { @@ -1911,21 +1961,35 @@ class plugininfo_block extends plugininfo_base { } } - public function get_settings_url() { + public function get_settings_section_name() { + return 'blocksetting' . $this->name; + } - if (($block = block_instance($this->name)) === false) { - return parent::get_settings_url(); + public function load_settings(part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) { + global $CFG, $USER, $DB, $OUTPUT, $PAGE; // in case settings.php wants to refer to them + $ADMIN = $adminroot; // may be used in settings.php + $block = $this; // also can be used inside settings.php + $section = $this->get_settings_section_name(); - } else if ($block->has_config()) { + if (!$hassiteconfig || (($blockinstance = block_instance($this->name)) === false)) { + return; + } + + $settings = null; + if ($blockinstance->has_config()) { if (file_exists($this->full_path('settings.php'))) { - return new moodle_url('/admin/settings.php', array('section' => 'blocksetting' . $this->name)); + $settings = new admin_settingpage($section, $this->displayname, + 'moodle/site:config', $this->is_enabled() === false); + include($this->full_path('settings.php')); // this may also set $settings to null } else { $blocksinfo = self::get_blocks_info(); - return new moodle_url('/admin/block.php', array('block' => $blocksinfo[$this->name]->id)); + $settingsurl = new moodle_url('/admin/block.php', array('block' => $blocksinfo[$this->name]->id)); + $settings = new admin_externalpage($section, $this->displayname, + $settingsurl, 'moodle/site:config', $this->is_enabled() === false); } - - } else { - return parent::get_settings_url(); + } + if ($settings) { + $ADMIN->add($parentnodename, $settings); } } @@ -2066,14 +2130,26 @@ class plugininfo_filter extends plugininfo_base { return null; } - public function get_settings_url() { - + public function get_settings_section_name() { $globalstates = self::get_global_states(); $legacyname = $globalstates[$this->name]->legacyname; - if (filter_has_global_settings($legacyname)) { - return new moodle_url('/admin/settings.php', array('section' => 'filtersetting' . str_replace('/', '', $legacyname))); - } else { - return null; + return 'filtersetting' . str_replace('/', '', $legacyname); + } + + public function load_settings(part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) { + global $CFG, $USER, $DB, $OUTPUT, $PAGE; // in case settings.php wants to refer to them + $ADMIN = $adminroot; // may be used in settings.php + $filter = $this; // also can be used inside settings.php + + $settings = null; + if ($hassiteconfig && file_exists($this->full_path('filtersettings.php'))) { + $section = $this->get_settings_section_name(); + $settings = new admin_settingpage($section, $this->displayname, + 'moodle/site:config', $this->is_enabled() === false); + include($this->full_path('filtersettings.php')); // this may also set $settings to null + } + if ($settings) { + $ADMIN->add($parentnodename, $settings); } } @@ -2175,6 +2251,23 @@ class plugininfo_mod extends plugininfo_base { return $modules; } + /** + * Magic method getter, redirects to read only values. + * + * For module plugins we pretend the object has 'visible' property for compatibility + * with plugins developed for Moodle version below 2.4 + * + * @param string $name + * @return mixed + */ + public function __get($name) { + if ($name === 'visible') { + debugging('This is now an instance of plugininfo_mod, please use $module->is_enabled() instead of $module->visible', DEBUG_DEVELOPER); + return ($this->is_enabled() !== false); + } + return parent::__get($name); + } + public function init_display_name() { if (get_string_manager()->string_exists('pluginname', $this->component)) { $this->displayname = get_string('pluginname', $this->component); @@ -2220,12 +2313,24 @@ class plugininfo_mod extends plugininfo_base { } } - public function get_settings_url() { + public function get_settings_section_name() { + return 'modsetting' . $this->name; + } - if (file_exists($this->full_path('settings.php')) or file_exists($this->full_path('settingstree.php'))) { - return new moodle_url('/admin/settings.php', array('section' => 'modsetting' . $this->name)); - } else { - return parent::get_settings_url(); + public function load_settings(part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) { + global $CFG, $USER, $DB, $OUTPUT, $PAGE; // in case settings.php wants to refer to them + $ADMIN = $adminroot; // may be used in settings.php + $module = $this; // also can be used inside settings.php + $section = $this->get_settings_section_name(); + + $settings = null; + if ($hassiteconfig && file_exists($this->full_path('settings.php'))) { + $settings = new admin_settingpage($section, $this->displayname, + 'moodle/site:config', $this->is_enabled() === false); + include($this->full_path('settings.php')); // this may also set $settings to null + } + if ($settings) { + $ADMIN->add($parentnodename, $settings); } } @@ -2283,6 +2388,27 @@ class plugininfo_qtype extends plugininfo_base { return new moodle_url('/admin/qtypes.php', array('delete' => $this->name, 'sesskey' => sesskey())); } + + public function get_settings_section_name() { + return 'qtypesetting' . $this->name; + } + + public function load_settings(part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) { + global $CFG, $USER, $DB, $OUTPUT, $PAGE; // in case settings.php wants to refer to them + $ADMIN = $adminroot; // may be used in settings.php + $qtype = $this; // also can be used inside settings.php + $section = $this->get_settings_section_name(); + + $settings = null; + if ($hassiteconfig && file_exists($this->full_path('settings.php'))) { + $settings = new admin_settingpage($section, $this->displayname, + 'moodle/site:config', $this->is_enabled() === false); + include($this->full_path('settings.php')); // this may also set $settings to null + } + if ($settings) { + $ADMIN->add($parentnodename, $settings); + } + } } @@ -2308,11 +2434,31 @@ class plugininfo_auth extends plugininfo_base { return isset($enabled[$this->name]); } - public function get_settings_url() { - if (file_exists($this->full_path('settings.php'))) { - return new moodle_url('/admin/settings.php', array('section' => 'authsetting' . $this->name)); - } else { - return new moodle_url('/admin/auth_config.php', array('auth' => $this->name)); + public function get_settings_section_name() { + return 'authsetting' . $this->name; + } + + public function load_settings(part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) { + global $CFG, $USER, $DB, $OUTPUT, $PAGE; // in case settings.php wants to refer to them + $ADMIN = $adminroot; // may be used in settings.php + $auth = $this; // also to be used inside settings.php + $section = $this->get_settings_section_name(); + + $settings = null; + if ($hassiteconfig) { + if (file_exists($this->full_path('settings.php'))) { + // TODO: finish implementation of common settings - locking, etc. + $settings = new admin_settingpage($section, $this->displayname, + 'moodle/site:config', $this->is_enabled() === false); + include($this->full_path('settings.php')); // this may also set $settings to null + } else { + $settingsurl = new moodle_url('/admin/auth_config.php', array('auth' => $this->name)); + $settings = new admin_externalpage($section, $this->displayname, + $settingsurl, 'moodle/site:config', $this->is_enabled() === false); + } + } + if ($settings) { + $ADMIN->add($parentnodename, $settings); } } } @@ -2340,12 +2486,24 @@ class plugininfo_enrol extends plugininfo_base { return isset($enabled[$this->name]); } - public function get_settings_url() { + public function get_settings_section_name() { + return 'enrolsettings' . $this->name; + } - if ($this->is_enabled() or file_exists($this->full_path('settings.php'))) { - return new moodle_url('/admin/settings.php', array('section' => 'enrolsettings' . $this->name)); - } else { - return parent::get_settings_url(); + public function load_settings(part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) { + global $CFG, $USER, $DB, $OUTPUT, $PAGE; // in case settings.php wants to refer to them + $ADMIN = $adminroot; // may be used in settings.php + $enrol = $this; // also can be used inside settings.php + $section = $this->get_settings_section_name(); + + $settings = null; + if ($hassiteconfig && file_exists($this->full_path('settings.php'))) { + $settings = new admin_settingpage($section, $this->displayname, + 'moodle/site:config', $this->is_enabled() === false); + include($this->full_path('settings.php')); // this may also set $settings to null + } + if ($settings) { + $ADMIN->add($parentnodename, $settings); } } @@ -2360,15 +2518,31 @@ class plugininfo_enrol extends plugininfo_base { */ class plugininfo_message extends plugininfo_base { - public function get_settings_url() { + public function get_settings_section_name() { + return 'messagesetting' . $this->name; + } + + public function load_settings(part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) { + global $CFG, $USER, $DB, $OUTPUT, $PAGE; // in case settings.php wants to refer to them + $ADMIN = $adminroot; // may be used in settings.php + if (!$hassiteconfig) { + return; + } + $section = $this->get_settings_section_name(); + + $settings = null; $processors = get_message_processors(); if (isset($processors[$this->name])) { $processor = $processors[$this->name]; if ($processor->available && $processor->hassettings) { - return new moodle_url('settings.php', array('section' => 'messagesetting'.$processor->name)); + $settings = new admin_settingpage($section, $this->displayname, + 'moodle/site:config', $this->is_enabled() === false); + include($this->full_path('settings.php')); // this may also set $settings to null } } - return parent::get_settings_url(); + if ($settings) { + $ADMIN->add($parentnodename, $settings); + } } /** @@ -2389,7 +2563,7 @@ class plugininfo_message extends plugininfo_base { public function get_uninstall_url() { $processors = get_message_processors(); if (isset($processors[$this->name])) { - return new moodle_url('message.php', array('uninstall' => $processors[$this->name]->id, 'sesskey' => sesskey())); + return new moodle_url('/admin/message.php', array('uninstall' => $processors[$this->name]->id, 'sesskey' => sesskey())); } else { return parent::get_uninstall_url(); } @@ -2409,12 +2583,19 @@ class plugininfo_repository extends plugininfo_base { return isset($enabled[$this->name]); } - public function get_settings_url() { + public function get_settings_section_name() { + return 'repositorysettings'.$this->name; + } - if ($this->is_enabled()) { - return new moodle_url('/admin/repository.php', array('sesskey' => sesskey(), 'action' => 'edit', 'repos' => $this->name)); - } else { - return parent::get_settings_url(); + public function load_settings(part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) { + if ($hassiteconfig && $this->is_enabled()) { + // completely no access to repository setting when it is not enabled + $sectionname = $this->get_settings_section_name(); + $settingsurl = new moodle_url('/admin/repository.php', + array('sesskey' => sesskey(), 'action' => 'edit', 'repos' => $this->name)); + $settings = new admin_externalpage($sectionname, $this->displayname, + $settingsurl, 'moodle/site:config', false); + $adminroot->add($parentnodename, $settings); } } @@ -2543,12 +2724,117 @@ class plugininfo_local extends plugininfo_base { public function get_uninstall_url() { return new moodle_url('/admin/localplugins.php', array('delete' => $this->name, 'sesskey' => sesskey())); } +} - public function get_settings_url() { - if (file_exists($this->full_path('settings.php'))) { - return new moodle_url('/admin/settings.php', array('section' => 'local_' . $this->name)); - } else { - return parent::get_settings_url(); +/** + * Class for HTML editors + */ +class plugininfo_editor extends plugininfo_base { + + public function get_settings_section_name() { + return 'editorsettings' . $this->name; + } + + public function load_settings(part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) { + global $CFG, $USER, $DB, $OUTPUT, $PAGE; // in case settings.php wants to refer to them + $ADMIN = $adminroot; // may be used in settings.php + $editor = $this; // also can be used inside settings.php + $section = $this->get_settings_section_name(); + + $settings = null; + if ($hassiteconfig && file_exists($this->full_path('settings.php'))) { + $settings = new admin_settingpage($section, $this->displayname, + 'moodle/site:config', $this->is_enabled() === false); + include($this->full_path('settings.php')); // this may also set $settings to null + } + if ($settings) { + $ADMIN->add($parentnodename, $settings); + } + } + + /** + * Returns the information about plugin availability + * + * True means that the plugin is enabled. False means that the plugin is + * disabled. Null means that the information is not available, or the + * plugin does not support configurable availability or the availability + * can not be changed. + * + * @return null|bool + */ + public function is_enabled() { + global $CFG; + if (empty($CFG->texteditors)) { + $CFG->texteditors = 'tinymce,textarea'; + } + if (in_array($this->name, explode(',', $CFG->texteditors))) { + return true; + } + return false; + } +} + +/** + * Class for plagiarism plugins + */ +class plugininfo_plagiarism extends plugininfo_base { + + public function get_settings_section_name() { + return 'plagiarism'. $this->name; + } + + public function load_settings(part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) { + // plagiarism plugin just redirect to settings.php in the plugins directory + if ($hassiteconfig && file_exists($this->full_path('settings.php'))) { + $section = $this->get_settings_section_name(); + $settingsurl = new moodle_url($this->get_dir().'/settings.php'); + $settings = new admin_externalpage($section, $this->displayname, + $settingsurl, 'moodle/site:config', $this->is_enabled() === false); + $adminroot->add($parentnodename, $settings); } } } + +/** + * Class for webservice protocols + */ +class plugininfo_webservice extends plugininfo_base { + + public function get_settings_section_name() { + return 'webservicesetting' . $this->name; + } + + public function load_settings(part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) { + global $CFG, $USER, $DB, $OUTPUT, $PAGE; // in case settings.php wants to refer to them + $ADMIN = $adminroot; // may be used in settings.php + $webservice = $this; // also can be used inside settings.php + $section = $this->get_settings_section_name(); + + $settings = null; + if ($hassiteconfig && file_exists($this->full_path('settings.php'))) { + $settings = new admin_settingpage($section, $this->displayname, + 'moodle/site:config', $this->is_enabled() === false); + include($this->full_path('settings.php')); // this may also set $settings to null + } + if ($settings) { + $ADMIN->add($parentnodename, $settings); + } + } + + public function is_enabled() { + global $CFG; + if (empty($CFG->enablewebservices)) { + return false; + } + $active_webservices = empty($CFG->webserviceprotocols) ? array() : explode(',', $CFG->webserviceprotocols); + if (in_array($this->name, $active_webservices)) { + return true; + } + return false; + } + + public function get_uninstall_url() { + return new moodle_url('/admin/webservice/protocols.php', + array('sesskey' => sesskey(), 'action' => 'uninstall', 'webservice' => $this->name)); + } +} diff --git a/mod/assign/adminlib.php b/mod/assign/adminlib.php index 43c1e7d8e16..fcc5311b72e 100644 --- a/mod/assign/adminlib.php +++ b/mod/assign/adminlib.php @@ -447,10 +447,10 @@ class assign_plugin_manager { * @param string $subtype - The type of plugin (submission or feedback) * @param part_of_admin_tree $admin - The handle to the admin menu * @param admin_settingpage $settings - The handle to current node in the navigation tree - * @param stdClass $module - The handle to the current module + * @param stdClass|plugininfo_mod $module - The handle to the current module * @return None */ - static function add_admin_assign_plugin_settings($subtype, part_of_admin_tree $admin, admin_settingpage $settings, stdClass $module) { + static function add_admin_assign_plugin_settings($subtype, part_of_admin_tree $admin, admin_settingpage $settings, $module) { global $CFG; $plugins = get_plugin_list_with_file($subtype, 'settings.php', false); @@ -463,7 +463,7 @@ class assign_plugin_manager { foreach ($pluginsbyname as $pluginname => $plugin) { $settings = new admin_settingpage($subtype . '_'.$plugin, - $pluginname, 'moodle/site:config', !$module->visible); + $pluginname, 'moodle/site:config', $module->is_enabled() === false); if ($admin->fulltree) { $shortsubtype = substr($subtype, strlen('assign')); include($CFG->dirroot . "/mod/assign/$shortsubtype/$plugin/settings.php"); diff --git a/mod/assign/settings.php b/mod/assign/settings.php index ea7427fc552..fd29d76d784 100644 --- a/mod/assign/settings.php +++ b/mod/assign/settings.php @@ -27,12 +27,12 @@ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/mod/assign/adminlib.php'); $ADMIN->add('modules', new admin_category('assignmentplugins', - new lang_string('assignmentplugins', 'assign'), !$module->visible)); + new lang_string('assignmentplugins', 'assign'), $module->is_enabled() === false)); $ADMIN->add('assignmentplugins', new admin_category('assignsubmissionplugins', - new lang_string('submissionplugins', 'assign'), !$module->visible)); + new lang_string('submissionplugins', 'assign'), $module->is_enabled() === false)); $ADMIN->add('assignsubmissionplugins', new assign_admin_page_manage_assign_plugins('assignsubmission')); $ADMIN->add('assignmentplugins', new admin_category('assignfeedbackplugins', - new lang_string('feedbackplugins', 'assign'), !$module->visible)); + new lang_string('feedbackplugins', 'assign'), $module->is_enabled() === false)); $ADMIN->add('assignfeedbackplugins', new assign_admin_page_manage_assign_plugins('assignfeedback')); diff --git a/mod/quiz/settings.php b/mod/quiz/settings.php index 78efa460bcd..7efd52606f5 100644 --- a/mod/quiz/settings.php +++ b/mod/quiz/settings.php @@ -199,7 +199,7 @@ if (empty($reportsbyname)) { $ADMIN->add('modsettings', $quizsettings); } else { $ADMIN->add('modsettings', new admin_category('modsettingsquizcat', - get_string('modulename', 'quiz'), !$module->visible)); + get_string('modulename', 'quiz'), $module->is_enabled() === false)); $ADMIN->add('modsettingsquizcat', $quizsettings); // Add the report pages for the settings.php files in sub directories of mod/quiz/report. @@ -207,7 +207,7 @@ if (empty($reportsbyname)) { $reportname = $report; $settings = new admin_settingpage('modsettingsquizcat'.$reportname, - $strreportname, 'moodle/site:config', !$module->visible); + $strreportname, 'moodle/site:config', $module->is_enabled() === false); if ($ADMIN->fulltree) { include($CFG->dirroot . "/mod/quiz/report/$reportname/settings.php"); }