New plain text format.

Translates smileys and carriage returns, but prints all other tags and code
as plain text
This commit is contained in:
moodler
2003-04-27 10:46:16 +00:00
parent e209e0b09e
commit 6901fa7955
2 changed files with 16 additions and 3 deletions
+1
View File
@@ -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";
+15 -3
View File
@@ -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;
}
}