diff --git a/bridges/FacebookBridge.php b/bridges/FacebookBridge.php index efc93265..1c8132b4 100644 --- a/bridges/FacebookBridge.php +++ b/bridges/FacebookBridge.php @@ -168,89 +168,96 @@ EOD; $this->authorName = $author; - foreach($element->children() as $post){ - // Ignore summary posts - if(strpos($post->class, '_3xaf') !== false) continue; + foreach($element->children() as $cell){ + // Manage summary posts + if(strpos($cell->class, '_3xaf') !== false){ + $posts = $cell->children(); + } else { + $posts = array($cell); + } - $item = array(); + foreach($posts as $post){ - if(count($post->find('abbr')) > 0){ + $item = array(); - //Retrieve post contents - $content = preg_replace( - '/(?i)>
]+)>(.+?)div\ class=\"userContent\"/i', - '', - $post); + if(count($post->find('abbr')) > 0){ - $content = preg_replace( - '/(?i)>
]+)>(.+?)<\/div><\/div>
]+)>(.+?)div\ class=\"userContent\"/i', + '', + $post); - $content = preg_replace( - '/(?i)>
]+)>(.+?)div\ class=\"[^u]+userContent\"/i', - '', - $content); + $content = preg_replace( + '/(?i)>
]+)>(.+?)<\/div><\/div>
]+)>(.+?)<\/div>/i', - '', - $content); + $content = preg_replace( + '/(?i)>
]+)>(.+?)div\ class=\"[^u]+userContent\"/i', + '', + $content); - //Remove html nodes, keep only img, links, basic formatting - $content = strip_tags($content, '

'); + $content = preg_replace( + '/(?i)>

]+)>(.+?)<\/div>/i', + '', + $content); - //Adapt link hrefs: convert relative links into absolute links and bypass external link redirection - $content = preg_replace_callback('/ href=\"([^"]+)\"/i', $unescape_fb_link, $content); + //Remove html nodes, keep only img, links, basic formatting + $content = strip_tags($content, '

'); - //Clean useless html tag properties and fix link closing tags - foreach (array( - 'onmouseover', - 'onclick', - 'target', - 'ajaxify', - 'tabindex', - 'class', - 'style', - 'data-[^=]*', - 'aria-[^=]*', - 'role', - 'rel', - 'id') as $property_name) - $content = preg_replace('/ ' . $property_name . '=\"[^"]*\"/i', '', $content); - $content = preg_replace('/<\/a [^>]+>/i', '', $content); + //Adapt link hrefs: convert relative links into absolute links and bypass external link redirection + $content = preg_replace_callback('/ href=\"([^"]+)\"/i', $unescape_fb_link, $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 - ); + //Clean useless html tag properties and fix link closing tags + foreach (array( + 'onmouseover', + 'onclick', + 'target', + 'ajaxify', + 'tabindex', + 'class', + 'style', + 'data-[^=]*', + 'aria-[^=]*', + 'role', + 'rel', + 'id') as $property_name) + $content = preg_replace('/ ' . $property_name . '=\"[^"]*\"/i', '', $content); + $content = preg_replace('/<\/a [^>]+>/i', '', $content); - //Retrieve date of the post - $date = $post->find("abbr")[0]; - if(isset($date) && $date->hasAttribute('data-utime')){ - $date = $date->getAttribute('data-utime'); - } else { - $date = 0; + //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')){ + $date = $date->getAttribute('data-utime'); + } else { + $date = 0; + } + + //Build title from username and content + $title = $author; + if(strlen($title) > 24) + $title = substr($title, 0, strpos(wordwrap($title, 24), "\n")) . '...'; + $title = $title . ' | ' . strip_tags($content); + if(strlen($title) > 64) + $title = substr($title, 0, strpos(wordwrap($title, 64), "\n")) . '...'; + + //Build and add final item + $item['uri'] = self::URI . $post->find('abbr')[0]->parent()->getAttribute('href'); + $item['content'] = $content; + $item['title'] = $title; + $item['author'] = $author; + $item['timestamp'] = $date; + $this->items[] = $item; } - - //Build title from username and content - $title = $author; - if(strlen($title) > 24) - $title = substr($title, 0, strpos(wordwrap($title, 24), "\n")) . '...'; - $title = $title . ' | ' . strip_tags($content); - if(strlen($title) > 64) - $title = substr($title, 0, strpos(wordwrap($title, 64), "\n")) . '...'; - - //Build and add final item - $item['uri'] = self::URI . $post->find('abbr')[0]->parent()->getAttribute('href'); - $item['content'] = $content; - $item['title'] = $title; - $item['author'] = $author; - $item['timestamp'] = $date; - $this->items[] = $item; } } }