From: moodler Date: Mon, 5 May 2003 16:40:46 +0000 (+0000) Subject: Improvements for PLAIN FORMAT (links) plus some efficiency I think X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=5f350e8f6d6348391f8ffa2486912d1216a9334e;p=moodle.git Improvements for PLAIN FORMAT (links) plus some efficiency I think --- diff --git a/lib/weblib.php b/lib/weblib.php index 51944535f0..9fa7368c33 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -436,20 +436,21 @@ function format_text($text, $format=FORMAT_MOODLE, $options=NULL) { switch ($format) { case FORMAT_HTML: - $text = replace_smilies($text); + replace_smilies($text); return $text; break; case FORMAT_PLAIN: $text = htmlentities($text); - $text = replace_smilies($text); + replace_smilies($text); + convert_urls_into_links($text); $text = nl2br($text); return $text; break; case FORMAT_WIKI: $text = wiki_to_html($text); - $text = replace_smilies($text); + replace_smilies($text); return $text; break; @@ -512,7 +513,7 @@ function clean_text($text, $format) { } } -function replace_smilies($text) { +function replace_smilies(&$text) { /// Replaces all known smileys in the text with image equivalents global $CFG; @@ -552,7 +553,7 @@ function replace_smilies($text) { $runonce = true; } - return str_replace($e, $img, $text); + $text = str_replace($e, $img, $text); } function text_to_html($text, $smiley=true, $para=true) { @@ -566,20 +567,14 @@ function text_to_html($text, $smiley=true, $para=true) { $text = eregi_replace("([\n\r])<", " <", $text); $text = eregi_replace(">([\n\r])", "> ", $text); -/// Make lone URLs into links. eg http://moodle.com/ - $text = eregi_replace("([[:space:]]|^|\(|\[|\<)([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])", - "\\1\\2://\\3\\4", $text); - -/// eg www.moodle.com - $text = eregi_replace("([[:space:]]|^|\(|\[|\<)www\.([^[:space:]]*)([[:alnum:]#?/&=])", - "\\1www.\\2\\3", $text); + convert_urls_into_links($text); /// Make returns into HTML newlines. $text = nl2br($text); /// Turn smileys into images. if ($smiley) { - $text = replace_smilies($text); + replace_smilies($text); } /// Wrap the whole thing in a paragraph tag if required @@ -599,6 +594,18 @@ function wiki_to_html($text) { return $wiki->format($text); } +function convert_urls_into_links(&$text) { +/// Given some text, it converts any URLs it finds into HTML links. + +/// Make lone URLs into links. eg http://moodle.com/ + $text = eregi_replace("([[:space:]]|^|\(|\[|\<)([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])", + "\\1\\2://\\3\\4", $text); + +/// eg www.moodle.com + $text = eregi_replace("([[:space:]]|^|\(|\[|\<)www\.([^[:space:]]*)([[:alnum:]#?/&=])", + "\\1www.\\2\\3", $text); +} + function highlight($needle, $haystack) { /// This function will highlight instances of $needle in $haystack