From 2ea9027bc4755b458649a572fcf74c03060a6e34 Mon Sep 17 00:00:00 2001 From: gregb_cc Date: Wed, 12 Mar 2003 03:42:44 +0000 Subject: [PATCH] Small cleanup of smilie replacement. This change removes the smilie variable assignment from the global namespace. This change retains the original user input as the alt text. The main reason for this change is to make it possible for me to use my make_class function on weblib.php (still need to do something about the defines though). --- lib/weblib.php | 79 ++++++++++++++++++++------------------------------ 1 file changed, 31 insertions(+), 48 deletions(-) diff --git a/lib/weblib.php b/lib/weblib.php index f6c0153a76..5362387a80 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -35,51 +35,6 @@ 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\">"; - $JAVASCRIPT_TAGS = array("javascript:", "onclick=", "ondblclick=", "onkeydown=", "onkeypress=", "onkeyup=", "onmouseover=", "onmouseout=", "onmousedown=", "onmouseup=", "onblur=", "onfocus=", "onload=", "onselect="); @@ -516,10 +471,38 @@ function clean_text($text, $format) { function replace_smilies($text) { /// Replaces all known smileys in the text with image equivalents + global $CFG; - global $CFG, $SMILEY_TEXT, $SMILEY_IMAGE; - - return str_replace($SMILEY_TEXT, $SMILEY_IMAGE, $text); + $emoticons = array( + ':-)' => 'smiley.gif', + ':)' => 'smiley.gif', + ':-D' => 'biggrin.gif', + ';-)' => 'wink.gif', + ':-/' => 'mixed.gif', + 'V-.' => 'thoughtful.gif', + ':-P' => 'tongueout.gif', + 'B-)' => 'cool.gif', + '^-)' => 'approve.gif', + '8-)' => 'wideeyes.gif', + ':o)' => 'clown.gif', + ':-(' => 'sad.gif', + ':(' => 'sad.gif', + '8-.' => 'shy.gif', + ':-I' => 'blush.gif', + ':-X' => 'kiss.gif', + '8-o' => 'surprise.gif', + 'P-|' => 'blackeye.gif', + '8-[' => 'angry.gif', + 'xx-P' => 'dead.gif', + '|-.' => 'sleepy.gif', + '}-]' => 'evil.gif', + ); + + foreach ($emoticons as $emoticon => $image){ + $smilies[$emoticon] = "\"$emoticon\"wwwroot}/pix/s/{$image}\">"; + } + + return strtr($text, $smilies); } function text_to_html($text, $smiley=true, $para=true) { -- 2.39.5