From d342c7637030bc7ba723293c487a63f56f3295bf Mon Sep 17 00:00:00 2001 From: moodler Date: Sun, 4 May 2003 04:07:36 +0000 Subject: [PATCH] Added Wiki format as a system-wide format (forums, journals, etc) Also, added better formatting to plain-text emails via a new function in weblib.php - format_text_email --- lang/en/help/textformat.html | 13 ++++++++++ lang/en/moodle.php | 1 + lib/weblib.php | 48 ++++++++++++++++++++++++++++-------- mod/forum/lib.php | 2 +- 4 files changed, 53 insertions(+), 11 deletions(-) diff --git a/lang/en/help/textformat.html b/lang/en/help/textformat.html index 8ef87f74242..147132aba18 100644 --- a/lang/en/help/textformat.html +++ b/lang/en/help/textformat.html @@ -50,4 +50,17 @@

It still translates smilies and new lines, but otherwise your text isn't touched. + + + +

4. Wiki text format

+ diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 75018cf0bb0..81ab3e611c0 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -224,6 +224,7 @@ $string['formattext'] = "Moodle auto-format"; $string['formattexttype'] = "Formatting"; $string['formattopics'] = "Topics format"; $string['formatweeks'] = "Weekly format"; +$string['formatwiki'] = "Wiki format"; $string['frontpagedescription'] = "Front page description"; $string['frontpageformat'] = "Front page format"; $string['fulllistofcourses'] = "All courses"; diff --git a/lib/weblib.php b/lib/weblib.php index 5fe0f6f61a5..3bbe13a629f 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -33,8 +33,9 @@ /// Define text formatting types ... eventually we can add Wiki, BBcode etc 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) +define("FORMAT_HTML", "1"); // Plain HTML (with some tags stripped) +define("FORMAT_PLAIN", "2"); // Plain text (even tags are printed in full) +define("FORMAT_WIKI", "3"); // Wiki-formatted text $JAVASCRIPT_TAGS = array("javascript:", "onclick=", "ondblclick=", "onkeydown=", "onkeypress=", "onkeyup=", "onmouseover=", "onmouseout=", "onmousedown=", "onmouseup=", @@ -421,7 +422,8 @@ 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_PLAIN => get_string("formatplain")); + FORMAT_PLAIN => get_string("formatplain"), + FORMAT_WIKI => get_string("formatwiki")); } function format_text($text, $format=FORMAT_MOODLE, $options=NULL) { @@ -444,6 +446,13 @@ function format_text($text, $format=FORMAT_MOODLE, $options=NULL) { return $text; break; + case FORMAT_WIKI: + $text = wiki_to_html($text); + $text = replace_smilies($text); + return $text; + break; + + default: // FORMAT_MOODLE or anything else if (!isset($options->smiley)) { $options->smiley=true; @@ -456,6 +465,30 @@ function format_text($text, $format=FORMAT_MOODLE, $options=NULL) { } } +function format_text_email($text, $format) { +/// Given text in a variety of format codings, this function returns +/// the text as plain text suitable for plain email. +/// +/// $text is raw text (originally from a user) +/// $format is one of the format constants, defined above + + switch ($format) { + + case FORMAT_PLAIN: + return $text; + break; + + case FORMAT_WIKI: + $text = wiki_to_html($text); + return strip_tags($text); + break; + + default: // FORMAT_MOODLE or anything else + // Need to add something in here to create a text-friendly way of presenting URLs + return strip_tags($text); + break; + } +} function clean_text($text, $format) { /// Given raw text (eg typed in by a user), this function cleans it up @@ -463,15 +496,10 @@ function clean_text($text, $format) { global $JAVASCRIPT_TAGS, $ALLOWED_TAGS; - switch ($format) { // Does the same thing, currently, but it's nice to have the option + switch ($format) { case FORMAT_MOODLE: - $text = strip_tags($text, $ALLOWED_TAGS); - foreach ($JAVASCRIPT_TAGS as $tag) { - $text = stri_replace($tag, "", $text); - } - return $text; - case FORMAT_HTML: + case FORMAT_WIKI: $text = strip_tags($text, $ALLOWED_TAGS); foreach ($JAVASCRIPT_TAGS as $tag) { $text = stri_replace($tag, "", $text); diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 2d949cef6c4..247dfefd6a9 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -220,7 +220,7 @@ function forum_cron () { $posttext .= "$post->subject\n"; $posttext .= $strbynameondate."\n"; $posttext .= "---------------------------------------------------------------------\n"; - $posttext .= strip_tags($post->message); + $posttext .= format_text_email($post->message, $post->format); $posttext .= "\n\n"; if ($post->attachment) { $post->course = $course->id;