From 4c46c425db2822009f61bac0aadb3328e6fcb0df Mon Sep 17 00:00:00 2001 From: moodler Date: Wed, 29 Oct 2003 08:06:11 +0000 Subject: [PATCH] Changes to integrate the new HTML editor into Moodle in an optional way until it's stable enough to replace Richtext To enable the new editor, add this line into config.php: $CFG->useneweditor = true; --- config-dist.php | 9 +++++ lang/en/editor.php | 70 +++++++++++++++++++++++++++++++++++++++ lang/en/moodle.php | 12 +++---- lang/fi/editor.php | 72 ++++++++++++++++++++++++++++++++++++++++ lib/editor/lang/en.php | 74 +++++++++++++++++++++--------------------- lib/moodlelib.php | 62 +++++++++++++++++++++++++++-------- lib/weblib.php | 71 +++++++++++++++++++++++++++++++--------- version.php | 2 +- 8 files changed, 299 insertions(+), 73 deletions(-) create mode 100644 lang/en/editor.php create mode 100644 lang/fi/editor.php diff --git a/config-dist.php b/config-dist.php index 71a3866760..afb2998293 100644 --- a/config-dist.php +++ b/config-dist.php @@ -135,6 +135,15 @@ $CFG->admin = 'admin'; // eg $CFG->textfilter1 = "mod/glossary/dynalink.php"; // $CFG->textfilter2 = "library/librarylib.php"; +//========================================================================= +// 8. HTML EDITOR (temporary setting in development version only) +//========================================================================= +// We are currently moving to a new HTML editor that works on +// Mozilla browsers as well as Internet Explorer. To enable this +// editor, uncomment the following line. +// +// $CFG->useneweditor = true; + //========================================================================= // ALL DONE! To continue installation, visit your main page with a browser diff --git a/lang/en/editor.php b/lang/en/editor.php new file mode 100644 index 0000000000..3cfb66a3f1 --- /dev/null +++ b/lang/en/editor.php @@ -0,0 +1,70 @@ +] button to switch back to WYSIWIG." +?> diff --git a/lang/en/moodle.php b/lang/en/moodle.php index f9ab072fcd..c4a80089a8 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -371,7 +371,7 @@ $string['helpindex'] = "Index of all help files"; $string['helppicture'] = "How to upload a picture"; $string['helpreading'] = "Read carefully"; $string['helptext'] = "How to write text"; -$string['helprichtext'] = "About Richtext editor"; +$string['helprichtext'] = "About the HTML editor"; $string['helpsummaries'] = "About these summaries"; $string['helpquestions'] = "Ask good questions"; $string['helpwiki'] = "How to write Wiki text"; @@ -384,11 +384,11 @@ $string['home'] = "Home"; $string['hour'] = "hour"; $string['hours'] = "hours"; $string['howtomakethemes'] = "How to make new themes"; -$string['htmleditor'] = "Use Richtext HTML editor (IE only, 5.5 or later)"; -$string['htmleditoravailable'] = "The Richtext editor is available"; -$string['htmleditordisabled'] = "You have disabled the Richtext editor in your user profile"; -$string['htmleditordisabledadmin'] = "The administrator has disabled the Richtext editor on this site"; -$string['htmleditordisabledbrowser'] = "The Richtext editor is unavailable because you are not using Internet Explorer 5.5 or better"; +$string['htmleditor'] = "Use HTML editor (some browsers only)"; +$string['htmleditoravailable'] = "The HTML editor is available"; +$string['htmleditordisabled'] = "You have disabled the HTML editor in your user profile"; +$string['htmleditordisabledadmin'] = "The administrator has disabled the HTML editor on this site"; +$string['htmleditordisabledbrowser'] = "The HTML editor is unavailable because your web browser is not compatible"; $string['htmlformat'] = "Pretty HTML format"; $string['icqnumber'] = "ICQ number"; $string['idnumber'] = "ID number"; diff --git a/lang/fi/editor.php b/lang/fi/editor.php new file mode 100644 index 0000000000..a9cc164070 --- /dev/null +++ b/lang/fi/editor.php @@ -0,0 +1,72 @@ +] painiketta palataksesi takaisin WYSIWIG -tilaan."; +$string['about'] = "Tietoja editorista"; +$string['absbottom'] = "Absbottom"; +$string['absmiddle'] = "Absmiddle"; +$string['alignment'] = "Tasaus"; +$string['alternatetext'] = "Oletusteksti"; +$string['baseline'] = "Baseline"; +$string['bold'] = "Lihavoitu"; +$string['borderthickness'] = "Reunan paksuus"; +$string['bottom'] = "Alas"; +$string['browse'] = "Selaa"; +$string['cancel'] = "Peruuta"; +$string['cellpadding'] = "Solun täyttö"; +$string['cellspacing'] = "Solujen väli"; +$string['choosechar'] = "Valitse merkki"; +$string['chooseicon'] = "Valitse liitettävä hymiö"; +$string['close'] = "Sulje"; +$string['cols'] = "Solut"; +$string['copy'] = "Kopioi"; +$string['createlink'] = "Lisää linkki"; +$string['cut'] = "Leikkaa"; +$string['forecolor'] = "Tekstin väri"; +$string['hilitecolor'] = "Taustan väri"; +$string['horizontal'] = "Vaaka"; +$string['horizontalrule'] = "Vaakaviiva"; +$string['htmlmode'] = "Näytä HTML koodi"; +$string['imageurl'] = "Kuvan URL"; +$string['indent'] = "Lisää sisennystä"; +$string['insertchar'] = "Lisää merkki"; +$string['insertimage'] = "Lisää kuva"; +$string['insertsmile'] = "Lisää hymiö"; +$string['inserttable'] = "Lisää taulukko"; +$string['italic'] = "Kursivoitu"; +$string['justifycenter'] = "Keskitä"; +$string['justifyfull'] = "Tasaa molemmat reunat"; +$string['justifyleft'] = "Tasaa vasemmat reunat"; +$string['justifyright'] = "Tasaa oikeat reunat"; +$string['layout'] = "Ulkoasu"; +$string['left'] = "Vasen"; +$string['middle'] = "Middle"; +$string['notset'] = "Not Set"; +$string['ok'] = "OK"; +$string['orderedlist'] = "Numerointi"; +$string['outdent'] = "Vähennä sisennystä"; +$string['paste'] = "Liitä"; +$string['percent'] = "Prosenttia"; +$string['pixels'] = "Pikseliä"; +$string['popupeditor'] = "Suurenna editori"; +$string['preview'] = "Esikatsele"; +$string['redo'] = "Palauta viimeinen toiminto"; +$string['right'] = "Oikea"; +$string['rows'] = "Rivit"; +$string['showhelp'] = "Ohje"; +$string['spacing'] = "Välys"; +$string['strikethrough'] = "Yliviivattu"; +$string['subscript'] = "Alaindeksi"; +$string['superscript'] = "Ylädeksi"; +$string['textindicator'] = "Nykyinen tyyli"; +$string['texttop'] = "Texttop"; +$string['top'] = "Ylös"; +$string['underline'] = "Alleviivattu"; +$string['undo'] = "Peruuta viimeinen toiminto"; +$string['unorderedlist'] = "Luettelomerkit"; +$string['vertical'] = "Pysty"; +$string['width'] = "Leveys"; + +?> diff --git a/lib/editor/lang/en.php b/lib/editor/lang/en.php index 787ab600a1..41f02aec29 100644 --- a/lib/editor/lang/en.php +++ b/lib/editor/lang/en.php @@ -22,48 +22,48 @@ HTMLArea.I18N = { lang: "en", tooltips: { - bold: "", - italic: "", - underline: "", - strikethrough: "", - subscript: "", - superscript: "", - justifyleft: "", - justifycenter: "", - justifyright: "", - justifyfull: "", - insertorderedlist: "", - insertunorderedlist: "", - outdent: "", - indent: "", - forecolor: "", - hilitecolor: "", - inserthorizontalrule: "", - createlink: "", - insertimage: "", - inserttable: "", - htmlmode: "", - popupeditor: "", - about: "", - showhelp: "", - textindicator: "", - undo: "", - redo: "", - cut: "", - copy: "", - paste: "", - insertsmile: "", - insertchar: "" + bold: "", + italic: "", + underline: "", + strikethrough: "", + subscript: "", + superscript: "", + justifyleft: "", + justifycenter: "", + justifyright: "", + justifyfull: "", + insertorderedlist: "", + insertunorderedlist: "", + outdent: "", + indent: "", + forecolor: "", + hilitecolor: "", + inserthorizontalrule: "", + createlink: "", + insertimage: "", + inserttable: "", + htmlmode: "", + popupeditor: "", + about: "", + showhelp: "", + textindicator: "", + undo: "", + redo: "", + cut: "", + copy: "", + paste: "", + insertsmile: "", + insertchar: "" }, buttons: { - "ok": "", - "cancel": "", - "browse": "" + "ok": "", + "cancel": "", + "browse": "" }, msg: { - "Path": "", - "TEXT_MODE": "" + "Path": "", + "TEXT_MODE": "" } }; diff --git a/lib/moodlelib.php b/lib/moodlelib.php index ad6abe38a4..089587afce 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -1512,23 +1512,52 @@ function check_browser_version($brand="MSIE", $version=5.5) { /// Checks to see if is a browser matches the specified /// brand and is equal or better version. - if (empty($_SERVER["HTTP_USER_AGENT"])) { - return false; - } - $string = explode(";", $_SERVER["HTTP_USER_AGENT"]); - if (!isset($string[1])) { - return false; - } - $string = explode(" ", trim($string[1])); - if (!isset($string[0]) and !isset($string[1])) { + $agent = $_SERVER["HTTP_USER_AGENT"]; + + if (empty($agent)) { return false; } - if ($string[0] == $brand and (float)$string[1] >= $version ) { - return true; + + switch ($brand) { + + case "Gecko": /// Gecko based browsers + + if (substr_count($agent, "Camino")) { // MacOS X Camino not supported. + return false; + } + + // the proper string - Gecko/CCYYMMDD Vendor/Version + if (ereg("^([a-zA-Z]+)/([0-9]+\.[0-9]+) \((.*)\) (.*)$", $agent, $match)) { + if (ereg("^([Gecko]+)/([0-9]+)",$match[4], $reldate)) { + if ($reldate[2] > $version) { + return true; + } + } + } + break; + + + case "MSIE": /// Internet Explorer + + $string = explode(";", $agent); + if (!isset($string[1])) { + return false; + } + $string = explode(" ", trim($string[1])); + if (!isset($string[0]) and !isset($string[1])) { + return false; + } + if ($string[0] == $brand and (float)$string[1] >= $version ) { + return true; + } + break; + } + return false; } + function ini_get_bool($ini_get_arg) { /// This function makes the return value of ini_get consistent if you are /// setting server directives through the .htaccess file in apache. @@ -1545,10 +1574,17 @@ function ini_get_bool($ini_get_arg) { } function can_use_richtext_editor() { -/// Is the richedit editor enabled? +/// Is the HTML editor enabled? This depends on site and user +/// settings, as well as the current browser being used. + global $USER, $CFG; + if (!empty($USER->htmleditor) and !empty($CFG->htmleditor)) { - return check_browser_version("MSIE", 5.5); + if (check_browser_version("MSIE", 5.5)) { + return true; + } else if (check_browser_version("Gecko", 20030516) and !empty($CFG->useneweditor) ) { + return true; + } } return false; } diff --git a/lib/weblib.php b/lib/weblib.php index bfefaae265..49df224468 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -1270,6 +1270,7 @@ function make_table($table) { function print_textarea($richedit, $rows, $cols, $width, $height, $name, $value="", $courseid=0) { /// Prints a richtext field or a normal textarea + global $CFG, $THEME, $course; if (empty($courseid)) { @@ -1279,18 +1280,41 @@ function print_textarea($richedit, $rows, $cols, $width, $height, $name, $value= } if ($richedit) { - $richediturl = "$CFG->wwwroot/lib/rte/richedit.html"; - if (!empty($courseid) and isteacher($courseid)) { - $richediturl = "$CFG->wwwroot/lib/rte/richedit.php?id=$courseid"; - } + if (!empty($CFG->useneweditor)) { /// Use the new HTMLarea editor - echo "\n"; - echo "\n"; + if (!empty($courseid) and isteacher($courseid)) { + echo "\n"; + } else { + echo "\n"; + } + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + if ($rows < 20) { + $rows = 20; /// Minimum rows + } + if ($cols < 65) { + $cols = 65; /// Minimum columns + } + echo "\n"; + + } else { /// Use the old Richtext editor + $richediturl = "$CFG->wwwroot/lib/rte/richedit.html"; + if (!empty($courseid) and isteacher($courseid)) { + $richediturl = "$CFG->wwwroot/lib/rte/richedit.php?id=$courseid"; + } + + echo "\n"; + echo "\n"; + } } else { echo "