X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2FSmilies.php;h=d63511cd1d20af430b1c6ac0bcf3df09f0459cf1;hb=ef8ad9f1ede56c80ba0cc13298511d7943e04894;hp=74d87d1bd0e61c23bdcaf375bdc15f1f683899d0;hpb=951006dd10628151c8f108f82c3260f13846e557;p=friendica.git diff --git a/include/Smilies.php b/include/Smilies.php index 74d87d1bd0..d63511cd1d 100644 --- a/include/Smilies.php +++ b/include/Smilies.php @@ -5,21 +5,44 @@ * @brief This file contains the Smilies class which contains functions to handle smiles */ +use Friendica\App; +use Friendica\Core\System; + /** * This class contains functions to handle smiles */ class Smilies { + /** + * @brief Replaces/adds the emoticon list + * + * This function should be used whenever emoticons are added + * + * @param array $b Array of emoticons + * @param string $smiley The text smilie + * @param string $representation The replacement + */ + public static function add(&$b, $smiley, $representation) { + $found = array_search($smiley, $b['texts']); + + if (!is_int($found)) { + $b['texts'][] = $smiley; + $b['icons'][] = $representation; + } else { + $b['icons'][$found] = $representation; + } + } + /** * @brief Function to list all smilies - * + * * Get an array of all smilies, both internal and from addons. - * + * * @return array * 'texts' => smilie shortcut * 'icons' => icon in html - * + * * @hook smilie ('texts' => smilies texts array, 'icons' => smilies html array) */ public static function get_list() { @@ -64,48 +87,47 @@ class Smilies { ); $icons = array( - '<3', - '</3', - '<\\3', - ':-)', - ';-)', - ':-(', - ':-P', - ':-p', - ':-\', - ':-\', - ':-x', - ':-X', - ':-D', - '8-|', - '8-O', - ':-O', - '\\o/', - 'o.O', - 'O.o', - 'o_O', - 'O_o', - ':\'(', - ':-!', - ':-/', - ':-[', - '8-)', - ':beer', - ':homebrew', - ':coffee', - ':facepalm', - ':like', - ':dislike', - '~friendica ~friendica', - 'redred#matrix', - 'redred#matrixmatrix' + '<3', + '</3', + '<\\3', + ':-)', + ';-)', + ':-(', + ':-P', + ':-p', + ':-\', + ':-\', + ':-x', + ':-X', + ':-D', + '8-|', + '8-O', + ':-O', + '\\o/', + 'o.O', + 'O.o', + 'o_O', + 'O_o', + ':\'(', + ':-!', + ':-/', + ':-[', + '8-)', + ':beer', + ':homebrew', + ':coffee', + ':facepalm', + ':like', + ':dislike', + '~friendica ~friendica', + 'redred#matrix', + 'redred#matrixmatrix' ); $params = array('texts' => $texts, 'icons' => $icons); call_hooks('smilie', $params); return $params; - } /** @@ -119,13 +141,14 @@ class Smilies { * function from being executed by the prepare_text() routine when preparing * bbcode source for HTML display * - * @param string $s + * @param string $s Text that should be replaced * @param boolean $sample - * + * @param boolean $no_images Only replace emoticons without images + * * @return string HML Output of the Smilie */ - public static function replace($s, $sample = false) { - if (intval(get_config('system','no_smilies')) + public static function replace($s, $sample = false, $no_images = false) { + if(intval(get_config('system','no_smilies')) || (local_user() && intval(get_pconfig(local_user(),'system','no_smilies')))) return $s; @@ -133,11 +156,24 @@ class Smilies { $s = preg_replace_callback('/(.*?)<\/code>/ism','self::encode',$s); $params = self::get_list(); + + if ($no_images) { + $cleaned = array('texts' => array(), 'icons' => array()); + $icons = $params['icons']; + foreach ($icons AS $key => $icon) { + if (!strstr($icon, '
' . $params['icons'][$x] . '
'; } } @@ -152,11 +188,11 @@ class Smilies { return $s; } - private function encode($m) { + private static function encode($m) { return(str_replace($m[1],base64url_encode($m[1]),$m[0])); } - private function decode($m) { + private static function decode($m) { return(str_replace($m[1],base64url_decode($m[1]),$m[0])); } @@ -166,19 +202,16 @@ class Smilies { * * @param string $x * @return string HTML Output - * + * * @todo: Rework because it doesn't work correctly */ - private function preg_heart($x) { - if (strlen($x[1]) == 1) { + private static function preg_heart($x) { + if(strlen($x[1]) == 1) return $x[0]; - } $t = ''; - for ($cnt = 0; $cnt < strlen($x[1]); $cnt ++) { - $t .= '<3'; - } + for($cnt = 0; $cnt < strlen($x[1]); $cnt ++) + $t .= '<3'; $r = str_replace($x[0],$t,$x[0]); return $r; } - }