]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14741 - Adding default configuration for tinymce
authorscyrma <scyrma>
Thu, 5 Jun 2008 09:09:24 +0000 (09:09 +0000)
committerscyrma <scyrma>
Thu, 5 Jun 2008 09:09:24 +0000 (09:09 +0000)
lib/editor/htmlEditor.class.php [new file with mode: 0644]
lib/editor/tinymce.js.php [new file with mode: 0644]

diff --git a/lib/editor/htmlEditor.class.php b/lib/editor/htmlEditor.class.php
new file mode 100644 (file)
index 0000000..588fa7d
--- /dev/null
@@ -0,0 +1,129 @@
+<?php\r
+\r
+/**\r
+ *\r
+ * @copyright &copy; 2006 The Open University\r
+ * @author d.t.le@open.ac.uk, a.j.forth@open.ac.uk\r
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License\r
+ * @package portfolio\r
+ */\r
+\r
+\r
+class htmlEditor {\r
+\r
+    public function __construct() {\r
+    }\r
+\r
+    public function configure($editor = NULL) {\r
+\r
+        global $CFG;\r
+\r
+        if ($editor == '') {\r
+            $editor = $CFG->defaulthtmleditor;\r
+        }\r
+\r
+/*\r
+        if ($editor == '') {\r
+            switch ($CFG->htmleditorselection) {\r
+                case '0':\r
+                    return '';\r
+                    break;\r
+\r
+                case '1':\r
+                    $editor = 'tinymce';\r
+                    break;\r
+\r
+                case '2':\r
+                    $editor = 'fckeditor';\r
+                    break;\r
+\r
+                case '3':\r
+                    $editor = 'xinha';\r
+                    break;\r
+\r
+                case '4':\r
+                    $editor = 'yuirte';\r
+                    break;\r
+\r
+                default:\r
+                    return '';\r
+                    break;\r
+            }\r
+        }\r
+*/\r
+        $configuration = '';\r
+\r
+        switch ($editor) {\r
+\r
+            case 'tinymce':\r
+                $configuration = <<<EOF\r
+<script type="text/javascript" src="{$CFG->wwwroot}/lib/editor/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>\r
+<script type="text/javascript" src="{$CFG->wwwroot}/lib/editor/tinymce.js.php"></script>\r
+EOF;\r
+                break;\r
+\r
+            case 'fckeditor':\r
+                $configuration = <<<EOF\r
+<script type="text/javascript" src="{$CFG->wwwroot}/lib/editor/fckeditor/fckeditor.js"></script>\r
+<script type="text/javascript" src="{$CFG->wwwroot}/lib/editor/fckeditor.js.php"></script>\r
+EOF;\r
+                break;\r
+\r
+\r
+            case 'xinha':\r
+                $configuration = <<<EOF\r
+<script type="text/javascript">\r
+    _editor_url  = "{$CFG->wwwroot}/lib/editor/xinha/"\r
+    _editor_lang = "en";\r
+    _editor_skin = "blue-look";\r
+</script>\r
+<script type="text/javascript" src="{$CFG->wwwroot}/lib/editor/xinha/XinhaCore.js"></script>\r
+<script type="text/javascript" src="{$CFG->wwwroot}/lib/editor/xinha.js.php"></script>\r
+EOF;\r
+                break;\r
+\r
+            case 'yuirte':\r
+                $configuration = <<<EOF\r
+<!-- Skin CSS file -->\r
+<link rel="stylesheet" type="text/css" href="{$CFG->wwwroot}/lib/editor/yui/build/assets/skins/sam/skin.css">\r
+\r
+<!-- Utility Dependencies -->\r
+<script type="text/javascript" src="{$CFG->wwwroot}/lib/editor/yui/build/yahoo-dom-event/yahoo-dom-event.js"></script>\r
+<script type="text/javascript" src="{$CFG->wwwroot}/lib/editor/yui/build/element/element-beta-min.js"></script>\r
+\r
+<!-- Needed for Menus, Buttons and Overlays used in the Toolbar -->\r
+<script src="{$CFG->wwwroot}/lib/editor/yui/build/container/container_core-min.js"></script>\r
+<script src="{$CFG->wwwroot}/lib/editor/yui/build/menu/menu-min.js"></script>\r
+<script src="{$CFG->wwwroot}/lib/editor/yui/build/button/button-min.js"></script>\r
+\r
+<!-- Source file for Rich Text Editor-->\r
+<script src="{$CFG->wwwroot}/lib/editor/yui/build/editor/editor-beta-min.js"></script>\r
+\r
+<script type="text/javascript" src="{$CFG->wwwroot}/lib/editor/yuirte.js.php"></script>\r
+EOF;\r
+                break;\r
+\r
+            default:\r
+                break;\r
+\r
+        }\r
+\r
+        return $configuration;\r
+\r
+    }\r
+\r
+    public function activateEditor($name='', $id='') {\r
+\r
+        $configuration = <<<EOF\r
+<script type="text/javascript">\r
+createHTMLArea('$id');\r
+</script>\r
+EOF;\r
+\r
+        return $configuration;\r
+\r
+    }\r
+\r
+}\r
+\r
+?>\r
diff --git a/lib/editor/tinymce.js.php b/lib/editor/tinymce.js.php
new file mode 100644 (file)
index 0000000..cdb4f4b
--- /dev/null
@@ -0,0 +1,146 @@
+<?php\r
+\r
+require_once('../../config.php');\r
+\r
+/*\r
+ *\r
+ * ********************************************************************************************************\r
+ *\r
+ * This section configures the TinyMCE toolbar buttons on and off\r
+ * depending on the Moodle settings\r
+ *\r
+ * The changes are applied on a global basis,\r
+ * ..... but there is scope here to modify and restrict the config\r
+ * on a role basis, course basis, user basis, etc. if so desired.\r
+ *\r
+ */\r
+$editorhidebuttons = str_replace(' ', ',', $CFG->editorhidebuttons);\r
+\r
+$editorhidebuttons1 = $editorhidebuttons . ',visualaid,styleselect';\r
+\r
+$editorhidebuttons = 'theme_advanced_disable : "'.$editorhidebuttons1.'",';\r
+\r
+$editorhidebuttons = str_replace('fontsize',             'fontsizeselect',       $editorhidebuttons);\r
+$editorhidebuttons = str_replace('subscript',            'sub',                  $editorhidebuttons);\r
+$editorhidebuttons = str_replace('superscript',          'sup',                  $editorhidebuttons);\r
+$editorhidebuttons = str_replace('insertorderedlist',    'numlist',              $editorhidebuttons);\r
+$editorhidebuttons = str_replace('insertunorderedlist',  'bullist',              $editorhidebuttons);\r
+$editorhidebuttons = str_replace('createanchor',         'anchor',               $editorhidebuttons);\r
+$editorhidebuttons = str_replace('createlink',           'link',                 $editorhidebuttons);\r
+$editorhidebuttons = str_replace('htmlmode',             'code',                 $editorhidebuttons);\r
+$editorhidebuttons = str_replace('insertchar',           'charmap',              $editorhidebuttons);\r
+$editorhidebuttons = str_replace('insertimage',          'image',                $editorhidebuttons);\r
+$editorhidebuttons = str_replace('inserthorizontalrule', 'hr',                   $editorhidebuttons);\r
+$editorhidebuttons = str_replace('formatblock',          'formatselect',         $editorhidebuttons);\r
+$editorhidebuttons = str_replace('clean',                'cleanup,removeformat', $editorhidebuttons);\r
+\r
+// insertsmile,\r
+\r
+$pieces = explode(",", $editorhidebuttons1);\r
+\r
+$spellcheck = '';\r
+if (! in_array("spellcheck", $pieces)) {\r
+    $spellcheck = 'spellchecker,';\r
+}\r
+$inserttable = '';\r
+if (! in_array("inserttable", $pieces)) {\r
+    $inserttable = 'tablecontrols,separator,';\r
+}\r
+$search_replace = '';\r
+if (! in_array("search_replace", $pieces)) {\r
+    $search_replace = 'search,replace,separator,';\r
+}\r
+$lefttoright = '';\r
+if (! in_array("lefttoright", $pieces)) {\r
+    $lefttoright = 'ltr,separator,';\r
+}\r
+$righttoleft = '';\r
+if (! in_array("righttoleft", $pieces)) {\r
+    $righttoleft = 'rtl,separator,';\r
+}\r
+$cleanup = '';\r
+if (! in_array("cleanup", $pieces)) {\r
+    $cleanup = 'cleanup,removeformat,separator,';\r
+}\r
+$fontselect = '';\r
+if (! in_array("fontname", $pieces)) {\r
+    $fontselect = 'fontselect,';\r
+}\r
+$fontsize = '';\r
+if (! in_array("fontsize", $pieces)) {\r
+    $fontsize = 'fontsizeselect,';\r
+}\r
+$forecolor = '';\r
+if (! in_array("forecolor", $pieces)) {\r
+    $forecolor = 'forecolor,';\r
+}\r
+$hilitecolor = '';\r
+if (! in_array("hilitecolor", $pieces)) {\r
+    $hilitecolor = 'backcolor,';\r
+}\r
+$popupeditor = '';\r
+if (! in_array("popupeditor", $pieces)) {\r
+    $popupeditor = 'fullscreen,';\r
+}\r
+\r
+$editoraddbuttons3 = 'theme_advanced_buttons3_add : "'.$fontselect.$fontsize.$forecolor.$hilitecolor.'",';\r
+$editoraddbuttons4 = 'theme_advanced_buttons4 : "'.$spellcheck.$search_replace.$inserttable.$lefttoright.$righttoleft.$popupeditor.$cleanup.'",';\r
+\r
+/*\r
+ *\r
+ * ********************************************************************************************************\r
+ *\r
+ */\r
+\r
+\r
+$temp = $_SERVER["REQUEST_URI"];\r
+$temp = explode('/', $temp);\r
+$root = $temp[1];\r
+\r
+$configuration = <<<EOF\r
+\r
+function createHTMLArea(id) {\r
+\r
+    random       = Math.ceil(1000*Math.random())\r
+    editor       = 'editor'+random;\r
+    editorsubmit = 'editorsubmit'+random;\r
+\r
+    tinyMCE.init({\r
+        mode     : "exact",\r
+        elements : id,\r
+        theme    : "advanced",\r
+\r
+        plugins : "safari,spellchecker,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,pagebreak,imagemanager,filemanager",\r
+\r
+        spellchecker_languages : "+English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,Portuguese=pt,Spanish=es,Swedish=sv",\r
+\r
+        plugin_insertdate_dateFormat : "%Y-%m-%d",\r
+        plugin_insertdate_timeFormat : "%H:%M:%S",\r
+\r
+        content_css : "/$root/lib/editor/tinymce/examples/css/content.css",\r
+\r
+        theme_advanced_toolbar_location : "top",\r
+        theme_advanced_toolbar_align : "left",\r
+        theme_advanced_statusbar_location : "bottom",\r
+\r
+        theme_advanced_resize_horizontal : true,\r
+        theme_advanced_resizing : true,\r
+        apply_source_formatting : true,\r
+\r
+        $editorhidebuttons\r
+        $editoraddbuttons3\r
+        $editoraddbuttons4\r
+\r
+    });\r
+\r
+    script = "document.getElementById(id).form."+editorsubmit+" = document.getElementById(id).form.onsubmit;";\r
+    script = script + "document.getElementById(id).form.onsubmit = function() { tinyMCE.triggerSave(); document.getElementById(id).form."+editorsubmit+"(); document.getElementById(id).form."+editorsubmit+" = null;}";\r
+    eval(script);\r
+\r
+}\r
+\r
+EOF;\r
+\r
+echo $configuration;\r
+\r
+?>\r