aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2014-02-02 11:49:52 -0800
committerfriendica <info@friendica.com>2014-02-02 11:49:52 -0800
commitb7c4f033b503564096c236dd0ecb18ecff2822cb (patch)
tree217066fac1f7f8a4d8c606c18c919d22e5bd35ca
parent96e423dcfcb126241fb2787a816c687ce070cade (diff)
parentba6178bef316f706874c03e5b66343d461f87d4a (diff)
downloadvolse-hubzilla-b7c4f033b503564096c236dd0ecb18ecff2822cb.tar.gz
volse-hubzilla-b7c4f033b503564096c236dd0ecb18ecff2822cb.tar.bz2
volse-hubzilla-b7c4f033b503564096c236dd0ecb18ecff2822cb.zip
Merge pull request #299 from toclimb/smilies-fix
More efficient smilie replacing (see pull request #291)
-rwxr-xr-xinclude/text.php18
1 files changed, 8 insertions, 10 deletions
diff --git a/include/text.php b/include/text.php
index cf68ee121..1eef4e37a 100755
--- a/include/text.php
+++ b/include/text.php
@@ -889,8 +889,8 @@ function smilies($s, $sample = false) {
|| (local_user() && intval(get_pconfig(local_user(),'system','no_smilies'))))
return $s;
- $s = preg_replace_callback('{<(pre|code)>(?<target>.*?)</\1>}ism','smile_encode',$s);
- $s = preg_replace_callback('/<[a-z]+ (?<target>.*?)>/ism','smile_encode',$s);
+ $s = preg_replace_callback('{<(pre|code)>.*?</\1>}ism','smile_shield',$s);
+ $s = preg_replace_callback('/<[a-z]+ .*?>/ism','smile_shield',$s);
$texts = array(
'&lt;3',
@@ -981,20 +981,18 @@ function smilies($s, $sample = false) {
$s = str_replace($params['texts'],$params['icons'],$params['string']);
}
- $s = preg_replace_callback(
- '/<!--base64:(.*?)-->/ism',
- function ($m) { return base64url_decode($m[1]); },
- $s
- );
+ $s = preg_replace_callback('/<!--base64:(.*?)-->/ism', 'smile_unshield', $s);
return $s;
}
+function smile_shield($m) {
+ return '<!--base64:' . base64url_encode($m[0]) . '-->';
+}
-function smile_encode($m) {
- $cleartext = $m['target'];
- return str_replace($cleartext,'<!--base64:' . base64url_encode($cleartext) . '-->',$m[0]);
+function smile_unshield($m) {
+ return base64url_decode($m[1]);
}
// expand <3333 to the correct number of hearts