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;
This commit is contained in:
moodler 2003-10-29 08:06:11 +00:00
parent a800c94891
commit 4c46c425db
8 changed files with 299 additions and 73 deletions

View File

@ -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

70
lang/en/editor.php Normal file
View File

@ -0,0 +1,70 @@
<?php // $Id$
// Strings for the HTML editor
$string['bold'] = "Bold";
$string['italic'] = "Italic";
$string['underline'] = "Underline";
$string['strikethrough'] = "Strikethrough";
$string['subscript'] = "Subscript";
$string['superscript'] = "Superscript";
$string['justifyleft'] = "Justify Left";
$string['justifycenter'] = "Justify Center";
$string['justifyright'] = "Justify Right";
$string['justifyfull'] = "Justify Full";
$string['orderedlist'] = "Ordered List";
$string['unorderedlist'] = "Bulleted List";
$string['outdent'] = "Decrease Indent";
$string['indent'] = "Increase Indent";
$string['forecolor'] = "Font Color";
$string['hilitecolor'] = "Background Color";
$string['horizontalrule'] = "Horizontal Rule";
$string['createlink'] = "Insert Web Link";
$string['insertimage'] = "Insert Image";
$string['inserttable'] = "Insert Table";
$string['htmlmode'] = "Toggle HTML Source";
$string['popupeditor'] = "Enlarge Editor";
$string['about'] = "About this editor";
$string['showhelp'] = "Help using editor";
$string['textindicator'] = "Current style";
$string['undo'] = "Undo your last action";
$string['redo'] = "Redo your last action";
$string['cut'] = "Cut selection";
$string['copy'] = "Copy selection";
$string['paste'] = "Paste from clipboard";
$string['ok'] = "OK";
$string['cancel'] = "Cancel";
$string['browse'] = "Browse";
$string['imageurl'] = "Image URL";
$string['preview'] = "Preview";
$string['alternatetext'] = "Alternate text";
$string['alignment'] = "Alignment";
$string['layout'] = "Layout";
$string['spacing'] = "Spacing";
$string['borderthickness'] = "Border thickness";
$string['horizontal'] = "Horizontal";
$string['vertical'] = "Vertical";
$string['notset'] = "Not Set";
$string['left'] = "Left";
$string['right'] = "Right";
$string['texttop'] = "Texttop";
$string['baseline'] = "Baseline";
$string['absbottom'] = "Absbottom";
$string['bottom'] = "Bottom";
$string['middle'] = "Middle";
$string['top'] = "Top";
$string['absmiddle'] = "Absmiddle";
$string['rows'] = "Rows";
$string['cols'] = "Cols";
$string['width'] = "Width";
$string['percent'] = "Percent";
$string['pixels'] = "Pixels";
$string['cellspacing'] = "Cellspacing";
$string['cellpadding'] = "Cellpadding";
$string['close'] = "Close";
$string['chooseicon'] = "Choose an icon to insert";
$string['choosechar'] = "Choose Character";
$string['insertsmile'] = "Insert smile";
$string['insertchar'] = "Insert Special Character";
$string['Path'] = "Path";
$string['TEXT_MODE'] = "You are in TEXT MODE. Use the [<>] button to switch back to WYSIWIG."
?>

View File

@ -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";

72
lang/fi/editor.php Normal file
View File

@ -0,0 +1,72 @@
<?PHP // $Id$
// htmlarea.php - created with Moodle 1.2 development (2003100900)
$string['Path'] = "Polku";
$string['TEXT_MODE'] = "Olet tekstitilassa. Käytä [<>] 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";
?>

View File

@ -22,48 +22,48 @@ HTMLArea.I18N = {
lang: "en",
tooltips: {
bold: "<?php print(get_string("bold","htmlarea"));?>",
italic: "<?php print(get_string("italic","htmlarea"));?>",
underline: "<?php print(get_string("underline","htmlarea"));?>",
strikethrough: "<?php print(get_string("strikethrough","htmlarea"));?>",
subscript: "<?php print(get_string("subscript","htmlarea"));?>",
superscript: "<?php print(get_string("superscript","htmlarea"));?>",
justifyleft: "<?php print(get_string("justifyleft","htmlarea"));?>",
justifycenter: "<?php print(get_string("justifycenter","htmlarea"));?>",
justifyright: "<?php print(get_string("justifyright","htmlarea"));?>",
justifyfull: "<?php print(get_string("justifyfull","htmlarea"));?>",
insertorderedlist: "<?php print(get_string("orderedlist","htmlarea"));?>",
insertunorderedlist: "<?php print(get_string("unorderedlist","htmlarea"));?>",
outdent: "<?php print(get_string("outdent","htmlarea"));?>",
indent: "<?php print(get_string("indent","htmlarea"));?>",
forecolor: "<?php print(get_string("forecolor","htmlarea"));?>",
hilitecolor: "<?php print(get_string("hilitecolor","htmlarea"));?>",
inserthorizontalrule: "<?php print(get_string("horizontalrule","htmlarea"));?>",
createlink: "<?php print(get_string("createlink","htmlarea"));?>",
insertimage: "<?php print(get_string("insertimage","htmlarea"));?>",
inserttable: "<?php print(get_string("inserttable","htmlarea"));?>",
htmlmode: "<?php print(get_string("htmlmode","htmlarea"));?>",
popupeditor: "<?php print(get_string("popupeditor","htmlarea"));?>",
about: "<?php print(get_string("about","htmlarea"));?>",
showhelp: "<?php print(get_string("showhelp","htmlarea"));?>",
textindicator: "<?php print(get_string("textindicator","htmlarea"));?>",
undo: "<?php print(get_string("undo","htmlarea"));?>",
redo: "<?php print(get_string("redo","htmlarea"));?>",
cut: "<?php print(get_string("cut","htmlarea"));?>",
copy: "<?php print(get_string("copy","htmlarea"));?>",
paste: "<?php print(get_string("paste","htmlarea"));?>",
insertsmile: "<?php print(get_string("insertsmile","htmlarea"));?>",
insertchar: "<?php print(get_string("insertchar","htmlarea"));?>"
bold: "<?php print(get_string("bold","editor"));?>",
italic: "<?php print(get_string("italic","editor"));?>",
underline: "<?php print(get_string("underline","editor"));?>",
strikethrough: "<?php print(get_string("strikethrough","editor"));?>",
subscript: "<?php print(get_string("subscript","editor"));?>",
superscript: "<?php print(get_string("superscript","editor"));?>",
justifyleft: "<?php print(get_string("justifyleft","editor"));?>",
justifycenter: "<?php print(get_string("justifycenter","editor"));?>",
justifyright: "<?php print(get_string("justifyright","editor"));?>",
justifyfull: "<?php print(get_string("justifyfull","editor"));?>",
insertorderedlist: "<?php print(get_string("orderedlist","editor"));?>",
insertunorderedlist: "<?php print(get_string("unorderedlist","editor"));?>",
outdent: "<?php print(get_string("outdent","editor"));?>",
indent: "<?php print(get_string("indent","editor"));?>",
forecolor: "<?php print(get_string("forecolor","editor"));?>",
hilitecolor: "<?php print(get_string("hilitecolor","editor"));?>",
inserthorizontalrule: "<?php print(get_string("horizontalrule","editor"));?>",
createlink: "<?php print(get_string("createlink","editor"));?>",
insertimage: "<?php print(get_string("insertimage","editor"));?>",
inserttable: "<?php print(get_string("inserttable","editor"));?>",
htmlmode: "<?php print(get_string("htmlmode","editor"));?>",
popupeditor: "<?php print(get_string("popupeditor","editor"));?>",
about: "<?php print(get_string("about","editor"));?>",
showhelp: "<?php print(get_string("showhelp","editor"));?>",
textindicator: "<?php print(get_string("textindicator","editor"));?>",
undo: "<?php print(get_string("undo","editor"));?>",
redo: "<?php print(get_string("redo","editor"));?>",
cut: "<?php print(get_string("cut","editor"));?>",
copy: "<?php print(get_string("copy","editor"));?>",
paste: "<?php print(get_string("paste","editor"));?>",
insertsmile: "<?php print(get_string("insertsmile","editor"));?>",
insertchar: "<?php print(get_string("insertchar","editor"));?>"
},
buttons: {
"ok": "<?php print(get_string("ok","htmlarea"));?>",
"cancel": "<?php print(get_string("cancel","htmlarea"));?>",
"browse": "<?php print(get_string("browse","htmlarea"));?>"
"ok": "<?php print(get_string("ok","editor"));?>",
"cancel": "<?php print(get_string("cancel","editor"));?>",
"browse": "<?php print(get_string("browse","editor"));?>"
},
msg: {
"Path": "<?php print(get_string("Path","htmlarea"));?>",
"TEXT_MODE": "<?php print(get_string("TEXT_MODE","htmlarea"));?>"
"Path": "<?php print(get_string("Path","editor"));?>",
"TEXT_MODE": "<?php print(get_string("TEXT_MODE","editor"));?>"
}
};

View File

@ -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"])) {
$agent = $_SERVER["HTTP_USER_AGENT"];
if (empty($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])) {
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;
}

View File

@ -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 "<object id=\"richedit\" style=\"background-color: buttonface\"";
echo " data=\"$richediturl\"";
echo " width=\"$width\" height=\"$height\" ";
echo " type=\"text/x-scriptlet\" VIEWASTEXT=\"true\"></object>\n";
echo "<textarea style=\"display:none\" name=\"$name\" rows=\"1\" cols=\"1\">";
p($value);
echo "</textarea>\n";
if (!empty($courseid) and isteacher($courseid)) {
echo "<script type=\"text/javascript\" src=\"$CFG->wwwroot/lib/editor/htmlarea.php?id=$courseid\"></script>\n";
} else {
echo "<script type=\"text/javascript\" src=\"$CFG->wwwroot/lib/editor/htmlarea.php\"></script>\n";
}
echo "<script type=\"text/javascript\" src=\"$CFG->wwwroot/lib/editor/dialog.js\"></script>\n";
echo "<script type=\"text/javascript\" src=\"$CFG->wwwroot/lib/editor/lang/en.php\"></script>\n";
echo "<script type=\"text/javascript\" src=\"$CFG->wwwroot/lib/editor/popupwin.js\"></script>\n";
echo "<style type=\"text/css\">@import url($CFG->wwwroot/lib/editor/htmlarea.css);</style>\n";
if ($rows < 20) {
$rows = 20; /// Minimum rows
}
if ($cols < 65) {
$cols = 65; /// Minimum columns
}
echo "<textarea id=\"TA\" name=\"$name\" rows=\"$rows\" cols=\"$cols\" wrap=\"virtual\">";
p($value);
echo "</textarea>\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 "<object id=\"richedit\" style=\"background-color: buttonface\"";
echo " data=\"$richediturl\"";
echo " width=\"$width\" height=\"$height\" ";
echo " type=\"text/x-scriptlet\" VIEWASTEXT=\"true\"></object>\n";
echo "<textarea style=\"display:none\" name=\"$name\" rows=\"1\" cols=\"1\">";
p($value);
echo "</textarea>\n";
}
} else {
echo "<textarea name=\"$name\" rows=\"$rows\" cols=\"$cols\" wrap=\"virtual\">";
p($value);
@ -1299,10 +1323,25 @@ function print_textarea($richedit, $rows, $cols, $width, $height, $name, $value=
}
function print_richedit_javascript($form, $name, $source="no") {
echo "<script language=\"javascript\" event=\"onload\" for=\"window\">\n";
echo " document.richedit.options = \"history=no;source=$source\";";
echo " document.richedit.docHtml = $form.$name.innerText;";
echo "</script>";
global $CFG;
if (!empty($CFG->useneweditor)) { /// Use the new HTMLarea editor
echo "<script language=\"javascript\" type=\"text/javascript\" defer=\"1\">\n";
echo "var editor = null;\n";
echo "function initEditor() {\n";
echo " editor = new HTMLArea(\"TA\");\n";
echo " editor.generate();\n";
echo " return false;\n";
echo "}\n";
echo "initEditor();\n";
echo "</script>\n";
} else { /// Use the old Richtext editor
echo "<script language=\"javascript\" event=\"onload\" for=\"window\">\n";
echo " document.richedit.options = \"history=no;source=$source\";";
echo " document.richedit.docHtml = $form.$name.innerText;";
echo "</script>";
}
}
@ -1629,7 +1668,7 @@ function redirect($url, $message="", $delay="0") {
// Uses META tags to redirect the user, after printing a notice
if (empty($message)) {
echo "<meta http-equiv=\"refresh\" content=\"$delay; url=$url\" />";
echo "<html><head><meta http-equiv=\"refresh\" content=\"$delay; url=$url\" /></head></html>";
} else {
if (empty($delay)) {
$delay = 3; // There's no point having a message with no delay

View File

@ -5,7 +5,7 @@
// database to determine whether upgrades should
// be performed (see lib/db/*.php)
$version = 2003102700; // The current version is a date (YYYYMMDDXX)
$version = 2003102900; // The current version is a date (YYYYMMDDXX)
$release = "1.2 development"; // User-friendly version number