Merge branch 'MDL-44747-master' of git://github.com/FMCorz/moodle

This commit is contained in:
Marina Glancy
2014-04-01 14:26:08 +08:00
3 changed files with 80 additions and 6 deletions
+73 -1
View File
@@ -24,6 +24,78 @@
defined('MOODLE_INTERNAL') || die();
/**
* Admin setting for toolbar.
*
* @package editor_atto
* @copyright 2014 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class editor_atto_toolbar_setting extends admin_setting_configtextarea {
/**
* Validate data.
*
* This ensures that:
* - Plugins are only used once,
* - Group names are unique,
* - Lines match: group = plugin[, plugin[, plugin ...]],
* - There are some groups and plugins defined,
* - The plugins used are installed.
*
* @param string $data
* @return mixed True on success, else error message.
*/
public function validate($data) {
$result = parent::validate($data);
if ($result !== true) {
return $result;
}
$lines = explode("\n", $data);
$groups = array();
$plugins = array();
foreach ($lines as $line) {
if (empty(trim($line))) {
continue;
}
$matches = array();
if (!preg_match('/^\s*([a-z0-9]+)\s*=\s*([a-z0-9]+(\s*,\s*[a-z0-9]+)*)+\s*$/', $line, $matches)) {
$result = get_string('errorcannotparseline', 'editor_atto', $line);
break;
}
$group = $matches[1];
if (isset($groups[$group])) {
$result = get_string('errorgroupisusedtwice', 'editor_atto', $group);
break;
}
$groups[$group] = true;
$lineplugins = array_map('trim', explode(',', $matches[2]));
foreach ($lineplugins as $plugin) {
if (isset($plugins[$plugin])) {
$result = get_string('errorpluginisusedtwice', 'editor_atto', $plugin);
break 2;
} else if (!core_component::get_component_directory('atto_' . $plugin)) {
$result = get_string('errorpluginnotfound', 'editor_atto', $plugin);
break 2;
}
$plugins[$plugin] = true;
}
}
// We did not find any groups or plugins.
if (empty($groups) || empty($plugins)) {
$result = get_string('errornopluginsorgroupsfound', 'editor_atto');
}
return $result;
}
}
/**
* Special class for Atto plugins administration.
@@ -32,7 +104,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2014 Jerome Mouneyrac
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class atto_subplugins_settings extends admin_setting {
class editor_atto_subplugins_setting extends admin_setting {
/**
* Constructor.
+5
View File
@@ -22,6 +22,11 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['errorcannotparseline'] = 'The line \'{$a}\' could not be parsed.';
$string['errorgroupisusedtwice'] = 'The group \'{$a}\' is defined twice, group names must be unique.';
$string['errornopluginsorgroupsfound'] = 'No plugins or groups found, please add some groups and plugins.';
$string['errorpluginnotfound'] = 'The plugin \'{$a}\' cannot be used, it does not appear to be installed.';
$string['errorpluginisusedtwice'] = 'The plugin \'{$a}\' is used twice, plugins can only be defined once.';
$string['pluginname'] = 'Atto HTML editor';
$string['subplugintype_atto'] = 'Atto plugin';
$string['subplugintype_atto_plural'] = 'Atto plugins';
+2 -5
View File
@@ -29,7 +29,7 @@ $ADMIN->add('editorsettings', new admin_category('editoratto', $editor->displayn
$settings = new admin_settingpage('editorsettingsatto', new lang_string('settings', 'editor_atto'));
if ($ADMIN->fulltree) {
require_once(__DIR__ . '/adminlib.php');
$settings->add(new atto_subplugins_settings());
$settings->add(new editor_atto_subplugins_setting());
$name = new lang_string('toolbarconfig', 'editor_atto');
$desc = new lang_string('toolbarconfig_desc', 'editor_atto');
$default = 'collapse = collapse
@@ -44,10 +44,7 @@ insert = equation, charmap, table, clear
undo = undo
accessibility = accessibilitychecker, accessibilityhelper
other = html';
$setting = new admin_setting_configtextarea('editor_atto/toolbar',
$name,
$desc,
$default);
$setting = new editor_atto_toolbar_setting('editor_atto/toolbar', $name, $desc, $default);
$settings->add($setting);
}