MDL-19211 text editor plugins configuration

This commit is contained in:
skodak
2009-05-17 21:10:06 +00:00
parent 793253ae05
commit a5747cf828
11 changed files with 266 additions and 16 deletions
+91
View File
@@ -0,0 +1,91 @@
<?php
/**
* Allows admin to configure editors.
*/
require_once('../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/tablelib.php');
require_login();
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
$returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=manageeditors";
$action = optional_param('action', '', PARAM_ACTION);
$editor = optional_param('editor', '', PARAM_SAFEDIR);
// get currently installed and enabled auth plugins
$available_editors = get_available_editors();
if (!empty($editor) and empty($available_editors[$editor])) {
redirect ($returnurl);
}
$active_editors = explode(',', $CFG->texteditors);
foreach ($active_editors as $key=>$active) {
if (empty($available_editors[$active])) {
unset($active_editors[$key]);
}
}
////////////////////////////////////////////////////////////////////////////////
// process actions
if (!confirm_sesskey()) {
redirect($returnurl);
}
switch ($action) {
case 'disable':
// remove from enabled list
$key = array_search($editor, $active_editors);
unset($active_editors[$key]);
break;
case 'enable':
// add to enabled list
if (!in_array($editor, $active_editors)) {
$active_editors[] = $editor;
$active_editors = array_unique($active_editors);
}
break;
case 'down':
$key = array_search($editor, $active_editors);
// check auth plugin is valid
if ($key !== false) {
// move down the list
if ($key < (count($active_editors) - 1)) {
$fsave = $active_editors[$key];
$active_editors[$key] = $active_editors[$key + 1];
$active_editors[$key + 1] = $fsave;
}
}
break;
case 'up':
$key = array_search($editor, $active_editors);
// check auth is valid
if ($key !== false) {
// move up the list
if ($key >= 1) {
$fsave = $active_editors[$key];
$active_editors[$key] = $active_editors[$key - 1];
$active_editors[$key - 1] = $fsave;
}
}
break;
default:
break;
}
// at least one editor must be active
if (empty($active_editors)) {
$active_editors = array('textarea');
}
set_config('texteditors', implode(',', $active_editors));
redirect ($returnurl);
+8
View File
@@ -73,6 +73,14 @@ if ($hassiteconfig || has_capability('moodle/question:config', $systemcontext))
}
/// Editor plugins
$ADMIN->add('modules', new admin_category('editorsettings', get_string('editors', 'editor')));
$temp = new admin_settingpage('manageeditors', get_string('editorsettings', 'editor'));
$temp->add(new admin_setting_manageeditors());
$ADMIN->add('editorsettings', $temp);
/// Filter plugins
$ADMIN->add('modules', new admin_category('filtersettings', get_string('managefilters')));
$ADMIN->add('filtersettings', new admin_page_managefilters());
+2
View File
@@ -174,6 +174,7 @@ class admin_uploaduser_form2 extends moodleform {
$mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
$mform->setDefault('autosubscribe', 1);
/* TODO: reimplement editor preferences
if ($CFG->htmleditor) {
$choices = array(0 => get_string('texteditor'), 1 => get_string('htmleditor'));
$mform->addElement('select', 'htmleditor', get_string('textediting'), $choices);
@@ -182,6 +183,7 @@ class admin_uploaduser_form2 extends moodleform {
$mform->addElement('static', 'htmleditor', get_string('textediting'), get_string('texteditor'));
}
$mform->setAdvanced('htmleditor');
*/
if (empty($CFG->enableajax)) {
$mform->addElement('static', 'ajax', get_string('ajaxuse'), get_string('ajaxno'));
+6
View File
@@ -1,6 +1,12 @@
<?PHP // $Id$
// editor.php - created with Moodle 1.7 beta + (2006101003)
$string['editors'] = 'Text editors';
$string['editorsettings'] = 'Manage editors';
$string['acteditorshhdr'] = 'Active text editors';
$string['configeditorplugins'] = 'Please choose the editor plugins you wish to use and arrange them in recommended order.';
$string['about'] = 'About this editor';
$string['absbottom'] = 'Absbottom';
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
//== Custom Moodle strings that are not part of upstream TinyMCE ==
$string['modulename'] = 'TinyMCE editor';
$string['modulename'] = 'TinyMCE HTML editor';
// == TinyMCE upstream lang strings from all plugins ==
+133 -1
View File
@@ -3732,6 +3732,138 @@ class admin_setting_manageauths extends admin_setting {
return highlight($query, $return);
}
}
/**
* Special class for authentication administration.
*/
class admin_setting_manageeditors extends admin_setting {
public function __construct() {
parent::__construct('editorsui', get_string('editorsettings', 'editor'), '', '');
}
public function get_setting() {
return true;
}
public function get_defaultsetting() {
return true;
}
public function write_setting($data) {
// do not write any setting
return '';
}
public function is_related($query) {
if (parent::is_related($query)) {
return true;
}
$textlib = textlib_get_instance();
$editors_available = get_available_editors();
foreach ($editors_available as $editor=>$editorstr) {
if (strpos($editor, $query) !== false) {
return true;
}
if (strpos($textlib->strtolower($editorstr), $query) !== false) {
return true;
}
}
return false;
}
public function output_html($data, $query='') {
global $CFG;
// display strings
$txt = get_strings(array('administration', 'settings', 'edit', 'name', 'enable', 'disable',
'up', 'down', 'none'));
$txt->updown = "$txt->up/$txt->down";
$editors_available = get_available_editors();
$active_editors = explode(',', $CFG->texteditors);
$active_editors = array_reverse($active_editors);
foreach ($active_editors as $key=>$editor) {
if (empty($editors_available[$editor])) {
unset($active_editors[$key]);
} else {
$name = $editors_available[$editor];
unset($editors_available[$editor]);
$editors_available[$editor] = $name;
}
}
if (empty($active_editors)) {
//$active_editors = array('textarea');
}
$editors_available = array_reverse($editors_available, true);
$return = print_heading(get_string('acteditorshhdr', 'editor'), '', 3, 'main', true);
$return .= print_box_start('generalbox editorsui', '', true);
$table = new object();
$table->head = array($txt->name, $txt->enable, $txt->updown, $txt->settings);
$table->align = array('left', 'center', 'center', 'center');
$table->width = '90%';
$table->data = array();
// iterate through auth plugins and add to the display table
$updowncount = 1;
$editorcount = count($active_editors);
$url = "editors.php?sesskey=" . sesskey();
foreach ($editors_available as $editor => $name) {
// hide/show link
if (in_array($editor, $active_editors)) {
$hideshow = "<a href=\"$url&amp;action=disable&amp;editor=$editor\">";
$hideshow .= "<img src=\"{$CFG->pixpath}/i/hide.gif\" class=\"icon\" alt=\"disable\" /></a>";
// $hideshow = "<a href=\"$url&amp;action=disable&amp;editor=$editor\"><input type=\"checkbox\" checked /></a>";
$enabled = true;
$displayname = "<span>$name</span>";
}
else {
$hideshow = "<a href=\"$url&amp;action=enable&amp;editor=$editor\">";
$hideshow .= "<img src=\"{$CFG->pixpath}/i/show.gif\" class=\"icon\" alt=\"enable\" /></a>";
// $hideshow = "<a href=\"$url&amp;action=enable&amp;editor=$editor\"><input type=\"checkbox\" /></a>";
$enabled = false;
$displayname = "<span class=\"dimmed_text\">$name</span>";
}
// up/down link (only if auth is enabled)
$updown = '';
if ($enabled) {
if ($updowncount > 1) {
$updown .= "<a href=\"$url&amp;action=up&amp;editor=$editor\">";
$updown .= "<img src=\"{$CFG->pixpath}/t/up.gif\" alt=\"up\" /></a>&nbsp;";
}
else {
$updown .= "<img src=\"{$CFG->pixpath}/spacer.gif\" class=\"icon\" alt=\"\" />&nbsp;";
}
if ($updowncount < $editorcount) {
$updown .= "<a href=\"$url&amp;action=down&amp;editor=$editor\">";
$updown .= "<img src=\"{$CFG->pixpath}/t/down.gif\" alt=\"down\" /></a>";
}
else {
$updown .= "<img src=\"{$CFG->pixpath}/spacer.gif\" class=\"icon\" alt=\"\" />";
}
++ $updowncount;
}
// settings link
if (file_exists($CFG->dirroot.'/editor/'.$editor.'/settings.php')) {
$settings = "<a href=\"settings.php?section=editorsetting$editor\">{$txt->settings}</a>";
} else {
$settings = '';
}
// add a row to the table
$table->data[] =array($displayname, $hideshow, $updown, $settings);
}
$return .= print_table($table, true);
$return .= get_string('configeditorplugins', 'editor').'<br />'.get_string('tablenosave', 'filters');
$return .= print_box_end(true);
return highlight($query, $return);
}
}
/**
* Special class for filter administration.
*/
@@ -4724,7 +4856,7 @@ class admin_setting_managerepository extends admin_setting {
$instanceoptionnames = repository::static_function($i->get_typename(), 'get_instance_option_names');
if ( !empty($typeoptionnames) || !empty($instanceoptionnames)) {
//calculate number of instances in order to display them for the Moodle administrator
if (!empty($instanceoptionnames)) {
$admininstancenumber = count(repository::static_function($i->get_typename(), 'get_instances', array(get_context_instance(CONTEXT_SYSTEM)),null,false,$i->get_typename()));
+1
View File
@@ -59,6 +59,7 @@ function xmldb_main_install() {
'sessiontimeout' => 7200, // must be present during roles installation
'stringfilters' => '', // These two are managed in a strange way by the filters
'filterall' => 0, // setting page, so have to be initialised here.
'texteditors' => 'tinymce,textarea',
);
foreach($defaults as $key => $value) {
set_config($key, $value);
+16 -2
View File
@@ -2137,8 +2137,22 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
upgrade_main_savepoint($result, 2009051200);
}
if ($result && $oldversion < 2009051700) {
/// migrate editor settings
if (empty($CFG->htmleditor)) {
set_config('texteditors', 'textarea');
} else {
set_config('texteditors', 'tinymce,textarea');
}
unset_config('htmleditor');
unset_config('defaulthtmleditor');
/// Main savepoint reached
upgrade_main_savepoint($result, 2009051700);
}
return $result;
}
?>
+1 -6
View File
@@ -23,11 +23,6 @@
// //
///////////////////////////////////////////////////////////////////////////
//TODO:
// * remove $CFG->htmleditor and $CFG->defaulthtmleditor and $USER->htmleditor
// *
function get_preferred_texteditor($format=null) {
global $CFG, $USER;
@@ -91,7 +86,7 @@ function get_texteditor($editor) {
function get_available_editors() {
$editors = array();
foreach (get_list_of_plugins('lib/editor') as $editor) {
$editors['editor'] = get_string('modulename', 'editor_'.$editor);
$editors[$editor] = get_string('modulename', 'editor_'.$editor);
}
return $editors;
}
+6 -5
View File
@@ -14,7 +14,7 @@ if (!defined('MOODLE_INTERNAL')) {
<script type="text/javascript" src="<?php echo $CFG->httpswwwroot ?>/lib/overlib/overlib_cssstyle.js"></script>
<script type="text/javascript" src="<?php echo $CFG->httpswwwroot ?>/lib/cookies.js"></script>
<script type="text/javascript" src="<?php echo $CFG->httpswwwroot ?>/lib/ufo.js"></script>
<script type="text/javascript" src="<?php echo $CFG->httpswwwroot ?>/lib/dropdown.js"></script>
<script type="text/javascript" src="<?php echo $CFG->httpswwwroot ?>/lib/dropdown.js"></script>
<script type="text/javascript" defer="defer">
//<![CDATA[
@@ -40,15 +40,16 @@ if (!empty($focus)) {
?>
//]]>
</script>
<?php
<?php
// editors integrations
//TODO: optimise loading of editors
//TODO: optimize loading of editors
if (empty($CFG->texteditors)) {
$CFG->texteditors = 'tinymce,textarea';
}
$activeeditors = explode(',', $CFG->texteditors);
foreach ($activeeditors as $editor) {
$editor = get_texteditor($editor);
echo $editor->header_js();
if ($editor = get_texteditor($editor)) {
echo $editor->header_js();
}
}
?>
+1 -1
View File
@@ -6,7 +6,7 @@
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)
$version = 2009051200; // YYYYMMDD = date of the last version bump
$version = 2009051700; // YYYYMMDD = date of the last version bump
// XX = daily increments
$release = '2.0 dev (Build: 20090517)'; // Human-friendly version name