Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

speed improvement in smilie_replace. It is now almost as fast (within…

… 5-10%) of

the version that used global smilie definitions.
  • Loading branch information...
commit 690819315138830384b4eb45dd77e65a3866cb1a 1 parent 617778f
gregb_cc authored
Showing with 5 additions and 3 deletions.
  1. +5 −3 lib/weblib.php
8 lib/weblib.php
View
@@ -474,7 +474,8 @@ function replace_smilies($text) {
global $CFG;
static $runonce = false;
- static $smilies = false;
+ static $e = array();
+ static $img = array();
static $emoticons = array(
':-)' => 'smiley.gif',
':)' => 'smiley.gif',
@@ -502,12 +503,13 @@ function replace_smilies($text) {
if($runonce == false):
foreach ($emoticons as $emoticon => $image){
- $smilies[$emoticon] = "<IMG ALT=\"$emoticon\" WIDTH=15 HEIGHT=15 SRC=\"{$CFG->wwwroot}/pix/s/{$image}\">";
+ $e[] = $emoticon;
+ $img[] = "<IMG ALT=\"$emoticon\" WIDTH=15 HEIGHT=15 SRC=\"{$CFG->wwwroot}/pix/s/{$image}\">";
}
$runonce = true;
endif;
- return strtr($text, $smilies);
+ return str_replace($e, $img, $text);
}
function text_to_html($text, $smiley=true, $para=true) {
Please sign in to comment.
Something went wrong with that request. Please try again.