Merge branch 'w36_MDL-35172_m24_editortoolbar' of git://github.com/skodak/moodle

This commit is contained in:
Eloy Lafuente (stronk7)
2012-09-06 12:08:26 +02:00
7 changed files with 126 additions and 38 deletions
+51 -10
View File
@@ -152,7 +152,12 @@ abstract class editor_tinymce_plugin {
*/
protected function add_button_after(array &$params, $row, $button,
$after = '', $alwaysadd = true) {
$this->check_row($row);
if ($this->is_button_present($params, $button)) {
return true;
}
$row = $this->fix_row($params, $row);
$field = 'theme_advanced_buttons' . $row;
$old = $params[$field];
@@ -190,7 +195,7 @@ abstract class editor_tinymce_plugin {
* to see if it succeeded.
*
* @param array $params TinyMCE init parameters array
* @param int $row Row to add button to (1 to 3)
* @param int $row Row to add button to (1 to 10)
* @param string $button Identifier of button/plugin
* @param string $before Adds button directly before the named plugin
* @param bool $alwaysadd If specified $after string not found, add at start
@@ -198,7 +203,11 @@ abstract class editor_tinymce_plugin {
*/
protected function add_button_before(array &$params, $row, $button,
$before = '', $alwaysadd = true) {
$this->check_row($row);
if ($this->is_button_present($params, $button)) {
return true;
}
$row = $this->fix_row($params, $row);
$field = 'theme_advanced_buttons' . $row;
$old = $params[$field];
@@ -226,15 +235,47 @@ abstract class editor_tinymce_plugin {
}
/**
* Checks the row value is valid.
*
* @param int $row Row to add button to (1 to 3)
* @throws coding_exception If row value is outside the range 1-3
* Tests if button already present.
* @param array $params
* @param string $button
* @return bool
*/
private function check_row($row) {
if ($row < 1 || $row > 3) {
throw new coding_exception("Invalid row option: $row");
private function is_button_present(array $params, $button) {
for($i=1; $i<=10; $i++) {
$field = 'theme_advanced_buttons' . $i;
if (!isset($params[$field])) {
continue;
}
$buttons = explode(',', $params[$field]);
if (in_array($button, $buttons)) {
return true;
}
}
return false;
}
/**
* Checks the row value is valid, fix if necessary.
*
* @param array $params TinyMCE init parameters array
* @param int $row Row to add button if exists
* @return int requested row if exists, lower number if does not exist.
*/
private function fix_row(array &$params, $row) {
$row = ($row < 1) ? 1 : (int)$row;
$row = ($row > 10) ? 10 : $row;
$field = 'theme_advanced_buttons' . $row;
if (isset($params[$field])) {
return $row;
}
for($i=$row; $i>=1; $i--) {
if (isset($params[$field])) {
return $row;
}
}
// This should not happen.
return 1;
}
/**
+41
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/>.
/**
* TinyMCE editor integration upgrade.
*
* @package editor_tinymce
* @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_editor_tinymce_upgrade($oldversion) {
global $CFG, $DB;
$dbman = $DB->get_manager();
if ($oldversion < 2012083100) {
// Reset redesigned editor toolbar setting.
unset_config('customtoolbar', 'editor_tinymce');
upgrade_plugin_savepoint(true, 2012083100, 'editor', 'tinymce');
}
return true;
}
@@ -27,8 +27,8 @@
$string['availablebuttons'] = 'Available buttons';
$string['common:browseimage'] = 'Find or upload an image...';
$string['common:browsemedia'] = 'Find or upload a sound, video or applet...';
$string['customtoolbar'] = 'Custom editor toolbar';
$string['customtoolbar_desc'] = 'Each line contains a list of comma separated button names, use "|" as a group separator. Leave empty if you want standard toolbar. See <a href="{$a}" target="_blank">{$a}</a> for the list of default TinyMCE buttons.';
$string['customtoolbar'] = 'Editor toolbar';
$string['customtoolbar_desc'] = 'Each line contains a list of comma separated button names, use "|" as a group separator, empty lines are ignored. See <a href="{$a}" target="_blank">{$a}</a> for the list of default TinyMCE buttons.';
$string['fontselectlist'] = 'Available fonts list';
$string['media_dlg:filename'] = 'Filename';
$string['pluginname'] = 'TinyMCE HTML editor';
+21 -23
View File
@@ -127,7 +127,6 @@ class tinymce_texteditor extends texteditor {
}
$fontselectlist = empty($config->fontselectlist) ? '' : $config->fontselectlist;
$fontbutton = ($fontselectlist === '') ? '' : 'fontselect,';
$params = array(
'moodle_config' => $config,
@@ -154,13 +153,6 @@ class tinymce_texteditor extends texteditor {
'theme_advanced_font_sizes' => "1,2,3,4,5,6,7",
'theme_advanced_layout_manager' => "SimpleLayout",
'theme_advanced_toolbar_align' => "left",
'theme_advanced_buttons1' => $fontbutton . 'fontsizeselect,formatselect,|,' .
'undo,redo,|,search,replace,|,fullscreen',
'theme_advanced_buttons2' => 'bold,italic,underline,strikethrough,sub,sup,|,' .
'justifyleft,justifycenter,justifyright,|,' .
'cleanup,removeformat,pastetext,pasteword,|,forecolor,backcolor,|,ltr,rtl',
'theme_advanced_buttons3' => 'bullist,numlist,outdent,indent,|,' .
'link,unlink,|,image,nonbreaking,charmap,table,|,code',
'theme_advanced_fonts' => $fontselectlist,
'theme_advanced_resize_horizontal' => true,
'theme_advanced_resizing' => true,
@@ -170,6 +162,19 @@ class tinymce_texteditor extends texteditor {
'theme_advanced_statusbar_location' => "bottom",
);
// Should we override the default toolbar layout unconditionally?
$customtoolbar = self::parse_toolbar_setting($config->customtoolbar);
if ($customtoolbar) {
$i = 1;
foreach ($customtoolbar as $line) {
$params['theme_advanced_buttons'.$i] = $line;
$i++;
}
} else {
// At least one line is required.
$params['theme_advanced_buttons1'] = '';
}
if (!empty($options['legacy']) or !empty($options['noclean']) or !empty($options['trusted'])) {
// now deal somehow with non-standard tags, people scream when we do not make moodle code xtml strict,
// but they scream even more when we strip all tags that are not strict :-(
@@ -188,20 +193,6 @@ class tinymce_texteditor extends texteditor {
// Allow plugins to adjust parameters.
editor_tinymce_plugin::all_update_init_params($params, $context, $options);
// Should we override the default toolbar layout unconditionally?
$customtoolbar = self::parse_toolbar_setting($config->customtoolbar);
if ($customtoolbar) {
unset($params['theme_advanced_buttons1']);
unset($params['theme_advanced_buttons2']);
unset($params['theme_advanced_buttons3']);
unset($params['theme_advanced_buttons4']);
$i = 1;
foreach ($customtoolbar as $line) {
$params['theme_advanced_buttons'.$i] = $line;
$i++;
}
}
// Remove temporary parameters.
unset($params['moodle_config']);
@@ -221,6 +212,7 @@ class tinymce_texteditor extends texteditor {
}
$customtoolbar = str_replace("\r", "\n", $customtoolbar);
$customtoolbar = strtolower($customtoolbar);
$i = 0;
foreach (explode("\n", $customtoolbar) as $line) {
$line = preg_replace('/[^a-z0-9_,\|\-]/', ',', $line);
$line = str_replace('|', ',|,', $line);
@@ -229,7 +221,13 @@ class tinymce_texteditor extends texteditor {
if ($line === '') {
continue;
}
$result[] = $line;
if ($i == 10) {
// Maximum is ten lines, merge the rest to the last line.
$result[9] = $result[9].','.$line;
} else {
$result[] = $line;
$i++;
}
}
return $result;
}
+6 -1
View File
@@ -31,8 +31,13 @@ if ($ADMIN->fulltree) {
require_once(__DIR__.'/adminlib.php');
$settings->add(new tiynce_subplugins_settings());
$settings->add(new admin_setting_heading('tinymcegeneralheader', new lang_string('settings'), ''));
$default = "fontselect,fontsizeselect,formatselect,|,undo,redo,|,search,replace,|,fullscreen
bold,italic,underline,strikethrough,sub,sup,|,justifyleft,justifycenter,justifyright,|,cleanup,removeformat,pastetext,pasteword,|,forecolor,backcolor,|,ltr,rtl
bullist,numlist,outdent,indent,|,link,unlink,|,image,nonbreaking,charmap,table,|,code";
$settings->add(new admin_setting_configtextarea('editor_tinymce/customtoolbar',
get_string('customtoolbar', 'editor_tinymce'), get_string('customtoolbar_desc', 'editor_tinymce', 'http://www.tinymce.com/wiki.php/Buttons/controls'), '', PARAM_RAW, 100, 6));
get_string('customtoolbar', 'editor_tinymce'), get_string('customtoolbar_desc', 'editor_tinymce', 'http://www.tinymce.com/wiki.php/Buttons/controls'), $default, PARAM_RAW, 100, 8));
$settings->add(new admin_setting_configtextarea('editor_tinymce/fontselectlist',
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));
+3
View File
@@ -49,5 +49,8 @@ class editor_tinymce_testcase extends advanced_testcase {
$result = tinymce_texteditor::parse_toolbar_setting("| \n\n| \n \r");
$this->assertSame(array(), $result);
$result = tinymce_texteditor::parse_toolbar_setting("one\ntwo\n\nthree\nfour\nfive\nsix\nseven\neight\nnine\nten");
$this->assertSame(array('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'), $result);
}
}
+2 -2
View File
@@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2012081000; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2012061700; // Requires this Moodle version
$plugin->version = 2012083100; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2012083100; // Requires this Moodle version
$plugin->component = 'editor_tinymce'; // Full name of the plugin (used for diagnostics)
$plugin->release = '3.6.0'; // This is NOT a directory name, see lib.php if you need to know where is the editor code!