From: moodler Date: Sun, 27 Apr 2003 10:46:16 +0000 (+0000) Subject: New plain text format. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=6901fa7955de6fa982e8b619758df9abec49d7d2;p=moodle.git New plain text format. Translates smileys and carriage returns, but prints all other tags and code as plain text --- diff --git a/lang/en/moodle.php b/lang/en/moodle.php index c2f33ca881..db5249e712 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -187,6 +187,7 @@ $string['followingrequired'] = "The following items are required"; $string['forgotten'] = "Forgotten your username or password?"; $string['format'] = "Format"; $string['formathtml'] = "HTML format"; +$string['formatplain'] = "Plain text format"; $string['formatsocial'] = "Social format"; $string['formattext'] = "Moodle auto-format"; $string['formattexttype'] = "Formatting"; diff --git a/lib/weblib.php b/lib/weblib.php index 8bb6c47a1a..73a44bf8c1 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -32,8 +32,9 @@ /// Constants /// Define text formatting types ... eventually we can add Wiki, BBcode etc -define("FORMAT_MOODLE", "0"); -define("FORMAT_HTML", "1"); +define("FORMAT_MOODLE", "0"); // Does all sorts of transformations and filtering +define("FORMAT_HTML", "1"); // Plain HTML (with some tags stripped) +define("FORMAT_PLAIN", "2"); // Plain text (even tags are printed in full) $JAVASCRIPT_TAGS = array("javascript:", "onclick=", "ondblclick=", "onkeydown=", "onkeypress=", "onkeyup=", "onmouseover=", "onmouseout=", "onmousedown=", "onmouseup=", @@ -419,7 +420,8 @@ function parse_slash_arguments($string, $i=0) { function format_text_menu() { /// Just returns an array of formats suitable for a popup menu return array (FORMAT_MOODLE => get_string("formattext"), - FORMAT_HTML => get_string("formathtml") ); + FORMAT_HTML => get_string("formathtml"), + FORMAT_PLAIN => get_string("formatplain")); } function format_text($text, $format=FORMAT_MOODLE, $options=NULL) { @@ -435,6 +437,13 @@ function format_text($text, $format=FORMAT_MOODLE, $options=NULL) { return $text; break; + case FORMAT_PLAIN: + $text = htmlentities($text); + $text = replace_smilies($text); + $text = nl2br($text); + return $text; + break; + default: // FORMAT_MOODLE or anything else if (!isset($options->smiley)) { $options->smiley=true; @@ -468,6 +477,9 @@ function clean_text($text, $format) { $text = stri_replace($tag, "", $text); } return $text; + + case FORMAT_PLAIN: + return $text; } }