]> git.mxchange.org Git - friendica.git/commitdiff
Preparation for Unicode Emojis
authorMichael <heluecht@pirati.ca>
Sun, 20 Aug 2017 19:47:00 +0000 (19:47 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 20 Aug 2017 19:47:00 +0000 (19:47 +0000)
include/Smilies.php
include/bbcode.php

index f4de32f8f8db4f3609594461e4575bb091d9f98c..92b2063e47db905cfd4b7ef031156c7108eea53c 100644 (file)
@@ -13,6 +13,26 @@ use Friendica\App;
 
 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
         *
@@ -107,7 +127,6 @@ class Smilies {
                call_hooks('smilie', $params);
 
                return $params;
-
        }
 
        /**
@@ -121,12 +140,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;
@@ -135,6 +155,19 @@ class Smilies {
                $s = preg_replace_callback('/<code>(.*?)<\/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, '<img ')) {
+                                       $cleaned['texts'][] = $params['texts'][$key];
+                                       $cleaned['icons'][] = $params['icons'][$key];
+                               }
+                       }
+                       $params = $cleaned;
+               }
+
                $params['string'] = $s;
 
                if($sample) {
@@ -180,5 +213,4 @@ class Smilies {
                $r =  str_replace($x[0],$t,$x[0]);
                return $r;
        }
-
 }
index 99f997762ffeb1cb9bb661102607adedbda610e4..8e38d139e8ec43940810cecb633a9f00b9c3d567 100644 (file)
@@ -9,6 +9,7 @@ require_once 'include/map.php';
 require_once 'mod/proxy.php';
 require_once 'include/Contact.php';
 require_once 'include/plaintext.php';
+require_once 'include/Smilies.php';
 
 function bb_PictureCacheExt($matches) {
        if (strpos($matches[3], "data:image/") === 0) {
@@ -1276,6 +1277,10 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
                $Text = preg_replace("/\[event\-id\](.*?)\[\/event\-id\]/ism", '', $Text);
        }
 
+       // Replace non graphical smilies for external posts
+       if ($simplehtml) {
+               $Text = Smilies::replace($Text, false, true);
+       }
 
        // Replace inline code blocks
        $Text = preg_replace_callback("|(?!<br[^>]*>)<code>([^<]*)</code>(?!<br[^>]*>)|ism",