Merge branch 'w35_MDL-34877_m24_tinymcesettings' of git://github.com/skodak/moodle

This commit is contained in:
Aparup Banerjee 2012-08-28 13:56:15 +08:00
commit 0c4ee46d77
11 changed files with 243 additions and 15 deletions

View file

@ -34,4 +34,13 @@ class plugininfo_tinymce extends plugininfo_base {
public function get_uninstall_url() { public function get_uninstall_url() {
return new moodle_url('/lib/editor/tinymce/subplugins.php', array('delete' => $this->name, 'sesskey' => sesskey())); 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;
}
}
} }

View file

@ -37,6 +37,9 @@ abstract class editor_tinymce_plugin {
/** @var string Plugin folder */ /** @var string Plugin folder */
protected $plugin; protected $plugin;
/** @var array Plugin settings */
protected $config = null;
/** /**
* @param string $plugin Name of folder * @param string $plugin Name of folder
*/ */
@ -44,6 +47,55 @@ abstract class editor_tinymce_plugin {
$this->plugin = $plugin; $this->plugin = $plugin;
} }
/**
* Makes sure config is loaded and cached.
* @return void
*/
protected function load_config() {
if (!isset($this->config)) {
$name = $this->get_name();
$this->config = get_config("tinymce_$name");
}
}
/**
* Returns plugin config value.
* @param string $name
* @param string $default value if config does not exist yet
* @return string value or default
*/
public function get_config($name, $default = null) {
$this->load_config();
return isset($this->config->$name) ? $this->config->$name : $default;
}
/**
* Sets plugin config value.
* @param string $name name of config
* @param string $value string config value, null means delete
* @return string value
*/
public function set_config($name, $value) {
$pluginname = $this->get_name();
$this->load_config();
if ($value === null) {
unset($this->config->$name);
} else {
$this->config->$name = $value;
}
set_config($name, $value, "tinymce_$pluginname");
}
/**
* Returns name of this tinymce plugin.
* @return string
*/
public function get_name() {
// All class names start with "tinymce_".
$words = explode('_', get_class($this), 2);
return $words[1];
}
/** /**
* Adjusts TinyMCE init parameters for this plugin. * Adjusts TinyMCE init parameters for this plugin.
* *

View file

@ -29,6 +29,7 @@ $string['common:browsemedia'] = 'Find or upload a sound, video or applet...';
$string['fontselectlist'] = 'Available fonts list'; $string['fontselectlist'] = 'Available fonts list';
$string['media_dlg:filename'] = 'Filename'; $string['media_dlg:filename'] = 'Filename';
$string['pluginname'] = 'TinyMCE HTML editor'; $string['pluginname'] = 'TinyMCE HTML editor';
$string['settings'] = 'General settings';
$string['subplugindeleteconfirm'] = 'You are about to completely delete TinyMCE subplugin \'{$a}\'. This will completely delete everything in the database associated with this subplugin. Are you SURE you want to continue?'; $string['subplugindeleteconfirm'] = 'You are about to completely delete TinyMCE subplugin \'{$a}\'. This will completely delete everything in the database associated with this subplugin. Are you SURE you want to continue?';

View file

@ -27,8 +27,11 @@ require('../../../../../config.php');
@error_reporting(E_ALL ^ E_NOTICE); // Hide notices even if Moodle is configured to show them. @error_reporting(E_ALL ^ E_NOTICE); // Hide notices even if Moodle is configured to show them.
// General settings // General settings
$config['general.engine'] = get_config('editor_tinymce', 'spellengine') ? $engine = get_config('tinymce_spellchecker', 'spellengine');
get_config('editor_tinymce', 'spellengine') : 'GoogleSpell'; if (!$engine) {
$engine = 'GoogleSpell';
}
$config['general.engine'] = $engine;
// GoogleSpell settings // GoogleSpell settings
$config['GoogleSpell.proxyhost'] = isset($CFG->proxyhost) ? $CFG->proxyhost : ''; $config['GoogleSpell.proxyhost'] = isset($CFG->proxyhost) ? $CFG->proxyhost : '';

View file

@ -0,0 +1,32 @@
<?php
// 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 <http://www.gnu.org/licenses/>.
/**
* Spellchecker post install script.
*
* @package tinymce_spellchecker
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
function xmldb_tinymce_spellchecker_install() {
global $CFG, $DB;
require_once(__DIR__.'/upgradelib.php');
tinymce_spellchecker_migrate_settings();
}

View file

@ -0,0 +1,40 @@
<?php
// 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 <http://www.gnu.org/licenses/>.
/**
* Spellchecker upgrade script.
*
* @package tinymce_spellchecker
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
function xmldb_tinymce_spellchecker_upgrade($oldversion) {
global $CFG, $DB;
require_once(__DIR__.'/upgradelib.php');
$dbman = $DB->get_manager();
if ($oldversion < 2012051800) {
tinymce_spellchecker_migrate_settings();
upgrade_plugin_savepoint(true, 2012051800, 'tinymce', 'spellchecker');
}
return true;
}

View file

@ -0,0 +1,41 @@
<?php
// 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 <http://www.gnu.org/licenses/>.
/**
* Spellchecker upgrade script.
*
* @package tinymce_spellchecker
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Migrate spell related settings from tinymce.
*/
function tinymce_spellchecker_migrate_settings() {
$engine = get_config('editor_tinymce', 'spellengine');
if ($engine !== false) {
set_config('spellengine', $engine, 'tinymce_spellchecker');
unset_config('spellengine', 'editor_tinymce');
}
$list = get_config('editor_tinymce', 'spelllanguagelist');
if ($list !== false) {
set_config('spelllanguagelist', $list, 'tinymce_spellchecker');
unset_config('spelllanguagelist', 'editor_tinymce');
}
}

View file

@ -30,8 +30,7 @@ class tinymce_spellchecker extends editor_tinymce_plugin {
global $CFG; global $CFG;
// Check at least one language is supported. // Check at least one language is supported.
$config = $params['moodle_config']; $spelllanguagelist = $this->get_config('spelllanguagelist', '');
$spelllanguagelist = empty($config->spelllanguagelist) ? '' : $config->spelllanguagelist;
if ($spelllanguagelist !== '') { if ($spelllanguagelist !== '') {
// Add button after code button in advancedbuttons3. // Add button after code button in advancedbuttons3.
$added = $this->add_button_after($params, 3, 'spellchecker', 'code', false); $added = $this->add_button_after($params, 3, 'spellchecker', 'code', false);

View file

@ -0,0 +1,38 @@
<?php
// 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 <http://www.gnu.org/licenses/>.
/**
* Spellchecker settings.
*
* @package tinymce_spellchecker
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
if ($ADMIN->fulltree) {
$options = array(
'PSpell'=>'PSpell',
'GoogleSpell'=>'Google Spell',
'PSpellShell'=>'PSpellShell');
$settings->add(new admin_setting_configselect('tinymce_spellchecker/spellengine',
get_string('spellengine', 'admin'), '', 'GoogleSpell', $options));
$settings->add(new admin_setting_configtextarea('tinymce_spellchecker/spelllanguagelist',
get_string('spelllanguagelist', 'admin'), '',
'+English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,' .
'Portuguese=pt,Spanish=es,Swedish=sv', PARAM_RAW));
}

View file

@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
// The current plugin version (Date: YYYYMMDDXX). // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2012051701; $plugin->version = 2012051800;
// Required Moodle version. // Required Moodle version.
$plugin->requires = 2011112900; $plugin->requires = 2011112900;
// Full name of the plugin (used for diagnostics). // Full name of the plugin (used for diagnostics).

View file

@ -24,18 +24,31 @@
defined('MOODLE_INTERNAL') || die; defined('MOODLE_INTERNAL') || die;
$ADMIN->add('editorsettings', new admin_category('editortinymce', new lang_string('pluginname', 'editor_tinymce')));
$settings = new admin_settingpage('editorsettingstinymce', new lang_string('settings', 'editor_tinymce'));
if ($ADMIN->fulltree) { if ($ADMIN->fulltree) {
$options = array(
'PSpell'=>'PSpell',
'GoogleSpell'=>'Google Spell',
'PSpellShell'=>'PSpellShell');
$settings->add(new admin_setting_configselect('editor_tinymce/spellengine',
get_string('spellengine', 'admin'), '', 'GoogleSpell', $options));
$settings->add(new admin_setting_configtextarea('editor_tinymce/spelllanguagelist',
get_string('spelllanguagelist', 'admin'), '',
'+English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,' .
'Portuguese=pt,Spanish=es,Swedish=sv', PARAM_RAW));
$settings->add(new admin_setting_configtextarea('editor_tinymce/fontselectlist', $settings->add(new admin_setting_configtextarea('editor_tinymce/fontselectlist',
get_string('fontselectlist', 'editor_tinymce'), '', get_string('fontselectlist', 'editor_tinymce'), '',
'Trebuchet=Trebuchet MS,Verdana,Arial,Helvetica,sans-serif;Arial=arial,helvetica,sans-serif;Courier New=courier new,courier,monospace;Georgia=georgia,times new roman,times,serif;Tahoma=tahoma,arial,helvetica,sans-serif;Times New Roman=times new roman,times,serif;Verdana=verdana,arial,helvetica,sans-serif;Impact=impact;Wingdings=wingdings', PARAM_RAW)); 'Trebuchet=Trebuchet MS,Verdana,Arial,Helvetica,sans-serif;Arial=arial,helvetica,sans-serif;Courier New=courier new,courier,monospace;Georgia=georgia,times new roman,times,serif;Tahoma=tahoma,arial,helvetica,sans-serif;Times New Roman=times new roman,times,serif;Verdana=verdana,arial,helvetica,sans-serif;Impact=impact;Wingdings=wingdings', PARAM_RAW));
} }
$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);
}
}
}
unset($subplugins);
unset($disabled);
// TinyMCE does not have standard settings page.
$settings = null;