From c9dda9905901044a74d9ca0a05470f5d193516ba Mon Sep 17 00:00:00 2001 From: moodler Date: Sat, 12 Oct 2002 03:53:40 +0000 Subject: [PATCH] Modified text_to_html to use the new smilies, which for efficiency are now defined in a global array, and use str_replace instead of ereg ... --- lib/weblib.php | 64 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 12 deletions(-) diff --git a/lib/weblib.php b/lib/weblib.php index 5cef384699..624520db59 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -12,6 +12,50 @@ define("FORMAT_MOODLE", "0"); define("FORMAT_HTML", "1"); +$SMILEY_TEXT[] = ":-)"; +$SMILEY_IMAGE[] = "\":-)\"wwwroot/pix/s/smiley.gif\">"; +$SMILEY_TEXT[] = ":)"; +$SMILEY_IMAGE[] = "\":-)\"wwwroot/pix/s/smiley.gif\">"; +$SMILEY_TEXT[] = ":-D"; +$SMILEY_IMAGE[] = "\":-D\"wwwroot/pix/s/biggrin.gif\">"; +$SMILEY_TEXT[] = ";-)"; +$SMILEY_IMAGE[] = "\";-)\"wwwroot/pix/s/wink.gif\">"; +$SMILEY_TEXT[] = ":-/"; +$SMILEY_IMAGE[] = "\":-/\"wwwroot/pix/s/mixed.gif\">"; +$SMILEY_TEXT[] = "V-."; +$SMILEY_IMAGE[] = "\"V-.\"wwwroot/pix/s/thoughtful.gif\">"; +$SMILEY_TEXT[] = ":-P"; +$SMILEY_IMAGE[] = "\":-P\"wwwroot/pix/s/tongueout.gif\">"; +$SMILEY_TEXT[] = "B-)"; +$SMILEY_IMAGE[] = "\"B-)\"wwwroot/pix/s/cool.gif\">"; +$SMILEY_TEXT[] = "^-)"; +$SMILEY_IMAGE[] = "\"^-)\"wwwroot/pix/s/approve.gif\">"; +$SMILEY_TEXT[] = "8-)"; +$SMILEY_IMAGE[] = "\"8-)\"wwwroot/pix/s/wideeyes.gif\">"; +$SMILEY_TEXT[] = ":o)"; +$SMILEY_IMAGE[] = "\":o)\"wwwroot/pix/s/clown.gif\">"; +$SMILEY_TEXT[] = ":-("; +$SMILEY_IMAGE[] = "\":-(\"wwwroot/pix/s/sad.gif\">"; +$SMILEY_TEXT[] = ":("; +$SMILEY_IMAGE[] = "\":-(\"wwwroot/pix/s/sad.gif\">"; +$SMILEY_TEXT[] = "8-."; +$SMILEY_IMAGE[] = "\"8-.\"wwwroot/pix/s/shy.gif\">"; +$SMILEY_TEXT[] = ":-I"; +$SMILEY_IMAGE[] = "\":-I\"wwwroot/pix/s/blush.gif\">"; +$SMILEY_TEXT[] = ":-X"; +$SMILEY_IMAGE[] = "\":-X\"wwwroot/pix/s/kiss.gif\">"; +$SMILEY_TEXT[] = "8-o"; +$SMILEY_IMAGE[] = "\"8-o\"wwwroot/pix/s/surprise.gif\">"; +$SMILEY_TEXT[] = "P-|"; +$SMILEY_IMAGE[] = "\"P-|\"wwwroot/pix/s/blackeye.gif\">"; +$SMILEY_TEXT[] = "8-["; +$SMILEY_IMAGE[] = "\"8-[\"wwwroot/pix/s/angry.gif\">"; +$SMILEY_TEXT[] = "xx-P"; +$SMILEY_IMAGE[] = "\"xx-P\"wwwroot/pix/s/dead.gif\">"; +$SMILEY_TEXT[] = "|-."; +$SMILEY_IMAGE[] = "\"|-.\"wwwroot/pix/s/sleepy.gif\">"; +$SMILEY_TEXT[] = "}-]"; +$SMILEY_IMAGE[] = "\"}-]\"wwwroot/pix/s/evil.gif\">"; /// Functions @@ -282,6 +326,12 @@ function format_text($text, $format, $options=NULL) { switch ($format) { case FORMAT_MOODLE: + if (!isset($options->smiley)) { + $options->smiley=true; + } + if (!isset($options->para)) { + $options->smiley=true; + } return text_to_html($text, $options->smiley, $options->para); break; @@ -312,7 +362,7 @@ function clean_text($text, $format) { function text_to_html($text, $smiley=true, $para=true) { // Given plain text, makes it into HTML as nicely as possible. - global $CFG; + global $CFG, $SMILEY_TEXT, $SMILEY_IMAGE; // Remove any whitespace that may be between HTML tags $text = eregi_replace(">([[:space:]]+)<", "><", $text); @@ -333,18 +383,8 @@ function text_to_html($text, $smiley=true, $para=true) { $text = nl2br($text); // Turn smileys into images. - if ($smiley) { - $text = ereg_replace(":)", "\"{smile}\"wwwroot/pix/s/smiley.gif\">", $text); - $text = ereg_replace(":-)", "\"{smile}\"wwwroot/pix/s/smiley.gif\">", $text); - $text = ereg_replace(":-D", "\"{grin}\"wwwroot/pix/s/biggrin.gif\">", $text); - $text = ereg_replace(";-)", "\"{wink}\"wwwroot/pix/s/wink.gif\">", $text); - $text = ereg_replace("8-)", "\"{wide-eyed}\"wwwroot/pix/s/wideeyes.gif\">", $text); - $text = ereg_replace(":-\(","\"{sad}\"wwwroot/pix/s/sad.gif\">", $text); - $text = ereg_replace(":-P", "\"{tongue-out}\"wwwroot/pix/s/tongueout.gif\">", $text); - $text = ereg_replace(":-/", "\"{mixed}\"wwwroot/pix/s/mixed.gif\">", $text); - $text = ereg_replace(":-o", "\"{surprised}\"wwwroot/pix/s/surprise.gif\">", $text); - $text = ereg_replace("B-)", "\"{cool}\"wwwroot/pix/s/cool.gif\">", $text); + $text = str_replace($SMILEY_TEXT, $SMILEY_IMAGE, $text); } if ($para) { -- 2.39.5