X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2FSmilies.php;h=a2d7637c793d779d9334cf3fe988290e27d77248;hb=e40c3a9d7c980c4287c273bc12d934ceb8b55fc0;hp=d67b92d8b00f60a4e38ab0664510adb794b336ae;hpb=7d531afd00de35ef55d0cc5caa63242765341dae;p=friendica.git diff --git a/include/Smilies.php b/include/Smilies.php index d67b92d8b0..a2d7637c79 100644 --- a/include/Smilies.php +++ b/include/Smilies.php @@ -3,23 +3,54 @@ /** * @file include/Smilies.php * @brief This file contains the Smilies class which contains functions to handle smiles + * + * @todo Use the shortcodes from here: + * https://github.com/iamcal/emoji-data/blob/master/emoji_pretty.json?raw=true + * https://raw.githubusercontent.com/emojione/emojione/master/extras/alpha-codes/eac.json?raw=true + * https://github.com/johannhof/emoji-helper/blob/master/data/emoji.json?raw=true + * + * Have also a look here: + * https://www.webpagefx.com/tools/emoji-cheat-sheet/ */ +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 +95,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,12 +149,13 @@ 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) { + 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,6 +164,19 @@ 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, '<3'; + $t .= '<3'; $r = str_replace($x[0],$t,$x[0]); return $r; } - }