]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-19211 text editor plugins configuration
authorskodak <skodak>
Sun, 17 May 2009 21:10:06 +0000 (21:10 +0000)
committerskodak <skodak>
Sun, 17 May 2009 21:10:06 +0000 (21:10 +0000)
admin/editors.php [new file with mode: 0644]
admin/settings/plugins.php
admin/uploaduser_form.php
lang/en_utf8/editor.php
lang/en_utf8/editor_tinymce.php
lib/adminlib.php
lib/db/install.php
lib/db/upgrade.php
lib/editorlib.php
lib/javascript.php
version.php

diff --git a/admin/editors.php b/admin/editors.php
new file mode 100644 (file)
index 0000000..e63dc2e
--- /dev/null
@@ -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);
index b48e54aa033460cf4fe3eaec4569f654901945c5..bffb8b11a1073ea9202b6000e90e4aac480609c5 100644 (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());
index 3a2cb8402765b9a8d122f0884d981937a29269d9..370bb55db0204ac518167e7ff21e33867caee1c3 100644 (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'));
index a335fbbd158e1b1aa0a27e8dd120ad44db698149..ed86b4161bb544773f94de9c5611d9c1ff1d33e4 100644 (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';
index 96fe132e1316e571a83300e1a2b5ead1a90b3586..152b832c9a316bcf8e184a165b80252be7d2b546 100644 (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 ==
index 5687ab6d34a6e85f259417b2bc44c0a56b549a58..f0583dc6548003dc80305c43e5b77902954f3e97 100644 (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()));
index 691bf0f9a73fe11e61c9be0753c0d8f97c1bf48c..7c441bf0a2b0a11fcac00041774f67487228878d 100644 (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);
index 958dd0a22e3587e5d7fead96f23e0518c0134ce0..d8a70fbc0ee1da21f2260da78d7995a0aaadafcb 100644 (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;
 }
 
-
-?>
index f1ccd5c1a817b166e8b61368d3cf6d7cdc3cbe1b..c35bc55c25f6333df89b687e6b17da3ba407d6a6 100644 (file)
 //                                                                       //
 ///////////////////////////////////////////////////////////////////////////
 
-//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;
 }
index b7c5fbeaaf0742710bf1e286ae0544d3da5ab8c5..eaa53685ceab61f6617eb5bdd02e9efcf7f0e59e 100644 (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();
+        }
     }
 ?>
\ No newline at end of file
index b69f081620c035040b05491e23acab224c55842d..10fc3a2776fe0a68f17ab96bac238ca8e6764ee6 100644 (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