[Facebook] Convert textual emoticons to ASCII
Currently emoticons are retrived in textual form eg <i><u>smile emoticon</u></i> 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 <i><u>émoticône smile</u></i> so we need to test both. Unknown emoticon descriptions will be left as is.
This commit is contained in:
parent
c8ef31bac6
commit
b592f8ebbf
1 changed files with 36 additions and 0 deletions
|
@ -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', '</a>', $content);
|
||||
|
||||
//Convert textual representation of emoticons eg "<i><u>smile emoticon</u></i>" back to ASCII emoticons eg ":)"
|
||||
$content = preg_replace_callback('/<i><u>([^ <>]+) ([^<>]+)<\/u><\/i>/i', $unescape_fb_emote, $content);
|
||||
|
||||
//Retrieve date of the post
|
||||
$date = $post->find("abbr")[0];
|
||||
if(isset($date) && $date->hasAttribute('data-utime')) {
|
||||
|
|
Loading…
Reference in a new issue