From d2aa927a0aa0816639d8af1f0df004d370a2487a Mon Sep 17 00:00:00 2001 From: stronk7 Date: Wed, 11 Feb 2009 17:51:34 +0000 Subject: [PATCH] MDL-17074 - backport ability of admin settings to use the config_plugins table --- lang/en_utf8/error.php | 1 + lib/adminlib.php | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lang/en_utf8/error.php b/lang/en_utf8/error.php index e0588a874a0..b768d3b5454 100644 --- a/lang/en_utf8/error.php +++ b/lang/en_utf8/error.php @@ -51,6 +51,7 @@ $string['groupunknown'] = 'Group $a not associated to specified course'; $string['guestnoeditprofile'] = 'The guest user cannot edit their profile'; $string['guestnoeditprofileother'] = 'The guest user profile cannot be edited'; $string['guestsarenotallowed'] = 'The guest user is not allowed to do this'; +$string['invalidadminsettingname'] = 'Invalid admin setting ($a)'; $string['invalidcontext'] = 'Invalid context'; $string['invalidcourse'] = 'Invalid course'; $string['invalidcourseid'] = 'You are trying to use an invalid course ID ($a)'; diff --git a/lib/adminlib.php b/lib/adminlib.php index e59a7a29b06..6ff9837e06e 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -1616,12 +1616,39 @@ class admin_setting { * @param mixed $defaultsetting string or array depending on implementation */ function admin_setting($name, $visiblename, $description, $defaultsetting) { - $this->name = $name; + $this->parse_setting_name($name); $this->visiblename = $visiblename; $this->description = $description; $this->defaultsetting = $defaultsetting; } + /** + * Set up $this->name and possibly $this->plugin based on whether $name looks + * like 'settingname' or 'plugin/settingname'. Also, do some sanity checking + * on the names, that is, output a developer debug warning if the name + * contains anything other than [a-zA-Z0-9_]+. + * + * @param string $name the setting name passed in to the constructor. + */ + function parse_setting_name($name) { + $bits = explode('/', $name); + if (count($bits) > 2) { + print_error('invalidadminsettingname', '', '', $name); + } + $this->name = array_pop($bits); + if (!preg_match('/^[a-zA-Z0-9_]+$/', $this->name)) { + print_error('invalidadminsettingname', '', '', $name); + } + if (!empty($bits)) { + $this->plugin = array_pop($bits); + if ($this->plugin === 'moodle') { + $this->plugin = null; + } else if (!preg_match('/^[a-zA-Z0-9_]+$/', $this->plugin)) { + print_error('invalidadminsettingname', '', '', $name); + } + } + } + function get_full_name() { return 's_'.$this->plugin.'_'.$this->name; }