mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
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:
parent
a800c94891
commit
4c46c425db
8 changed files with 299 additions and 73 deletions
|
@ -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"));?>"
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue