From b592f8ebbfeb1893825187538f594ff32b9c86a7 Mon Sep 17 00:00:00 2001 From: ORelio Date: Sat, 24 Oct 2015 20:11:21 +0200 Subject: [PATCH] [Facebook] Convert textual emoticons to ASCII MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently emoticons are retrived in textual form eg smile emoticon which is not really visual... so let's convert them back as ASCII emoticons eg ':)'. This works using a hardcoded table mapping emoticon names to their visual representation, and the regular expression match the two words because eg in french facebook will display émoticône smile so we need to test both. Unknown emoticon descriptions will be left as is. --- bridges/FacebookBridge.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/bridges/FacebookBridge.php b/bridges/FacebookBridge.php index 3df13c34..15f648ca 100644 --- a/bridges/FacebookBridge.php +++ b/bridges/FacebookBridge.php @@ -34,6 +34,39 @@ class FacebookBridge extends BridgeAbstract{ } }; + //Utility function for converting facebook emoticons + $unescape_fb_emote = function ($matches) { + static $facebook_emoticons = array( + 'smile' => ':)', + 'frown' => ':(', + 'tongue' => ':P', + 'grin' => ':D', + 'gasp' => ':O', + 'wink' => ';)', + 'pacman' => ':<', + 'grumpy' => '>_<', + 'unsure' => ':/', + 'cry' => ':\'(', + 'kiki' => '^_^', + 'glasses' => '8-)', + 'sunglasses' => 'B-)', + 'heart' => '<3', + 'devil' => ']:D', + 'angel' => '0:)', + 'squint' => '-_-', + 'confused' => 'o_O', + 'upset' => 'xD', + 'colonthree' => ':3', + 'like' => '👍'); + $len = count($matches); + if ($len > 1) + for ($i = 1; $i < $len; $i++) + foreach ($facebook_emoticons as $name => $emote) + if ($matches[$i] === $name) + return $emote; + return $matches[0]; + }; + $html = ''; if(isset($param['u'])) { @@ -78,6 +111,9 @@ class FacebookBridge extends BridgeAbstract{ $content = preg_replace('/ '.$property_name.'=\"[^"]*\"/i', '', $content); $content = preg_replace('/<\/a [^>]+>/i', '', $content); + //Convert textual representation of emoticons eg "smile emoticon" back to ASCII emoticons eg ":)" + $content = preg_replace_callback('/([^ <>]+) ([^<>]+)<\/u><\/i>/i', $unescape_fb_emote, $content); + //Retrieve date of the post $date = $post->find("abbr")[0]; if(isset($date) && $date->hasAttribute('data-utime')) {