From 134fdda75f5630efd4053469d1a41940c28a1dff Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 14 Feb 2012 15:31:08 -0800 Subject: [PATCH] refactor smilie code to allow for extensions and generation of a table of the entire list --- include/text.php | 71 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 58 insertions(+), 13 deletions(-) diff --git a/include/text.php b/include/text.php index 3170280659..082d907ff6 100755 --- a/include/text.php +++ b/include/text.php @@ -678,21 +678,56 @@ function linkify($s) { */ if(! function_exists('smilies')) { -function smilies($s) { +function smilies($s, $sample = false) { $a = get_app(); - $s = str_replace( - array( '<3', '</3', '<\\3', ':-)', ':)', ';-)', ';)', ':-(', ':(', ':-P', ':P', ':-"', ':-"', ':-x', ':-X', ':-D', ':D', '8-|', '8-O', ':-O', '\\o/', 'o.O', 'O.o', '\\.../', '\\ooo/', ":'(", ":-!", ":-/", ":-[", "8-)", - ':beer', ':homebrew', ':coffee', - '~friendika', '~friendica', 'Diaspora*' ), - array( + $texts = array( + '<3', + '</3', + '<\\3', + ':-)', + ':)', + ';-)', + ';)', + ':-(', + ':(', + ':-P', + ':P', + ':-"', + ':-"', + ':-x', + ':-X', + ':-D', + ':D', + '8-|', + '8-O', + ':-O', + '\\o/', + 'o.O', + 'O.o', + '\\.../', + '\\ooo/', + ":'(", + ":-!", + ":-/", + ":-[", + "8-)", + ':beer', + ':homebrew', + ':coffee', + '~friendika', + '~friendica', + 'Diaspora*' + ); + + $icons = array( '<3', '</3', '<\\3', ':-)', ':)', ';-)', - ';)', + ';)', ':-(', ':(', ':-P', @@ -702,7 +737,7 @@ function smilies($s) { ':-x', ':-X', ':-D', - ':D', + ':D', '8-|', '8-O', ':-O', @@ -715,19 +750,29 @@ function smilies($s) { ':-!', ':-/', ':-[', - '8-)', - + '8-)', ':beer', ':homebrew', ':coffee', - '~friendika ~friendika', '~friendica ~friendica', 'DiasporaDiaspora*', - ), $s); + ); - call_hooks('smilie', $s); + $params = array('texts' => $texts, 'icons' => $icons, 'string' => $s); + call_hooks('smilie', $params); + + if($sample) { + $s = '
'; + for($x = 0; $x < count($params['texts']); $x ++) { + $s .= '
' . $params['texts'][$x] . '
' . $params['icons'][$x] . '
'; + } + } + else { + $s = str_replace($params['texts'],$params['icons'],$params['string']); + } + return $s; }}