diff --git a/bridges/FacebookBridge.php b/bridges/FacebookBridge.php index 109be9bb..3df13c34 100644 --- a/bridges/FacebookBridge.php +++ b/bridges/FacebookBridge.php @@ -3,7 +3,7 @@ * @name Facebook * @homepage http://facebook.com/ * @description Input a page title or a profile log. For a profile log, please insert the parameter as follow : myExamplePage/132621766841117 -* @update 05/09/2015 +* @update 23/10/2015 * @maintainer teromene * @use1(u="username") */ @@ -13,6 +13,27 @@ class FacebookBridge extends BridgeAbstract{ public function collectData(array $param){ + //Extract a string using start and end delimiters + function ExtractFromDelimiters($string, $start, $end) { + if (strpos($string, $start) !== false) { + $section_retrieved = substr($string, strpos($string, $start) + strlen($start)); + $section_retrieved = substr($section_retrieved, 0, strpos($section_retrieved, $end)); + return $section_retrieved; + } return false; + } + + //Utility function for cleaning a Facebook link + $unescape_fb_link = function ($matches) { + if (is_array($matches) && count($matches) > 1) { + $link = $matches[1]; + if (strpos($link, '/') === 0) + $link = 'https://facebook.com'.$link.'"'; + if (strpos($link, 'facebook.com/l.php?u=') !== false) + $link = urldecode(ExtractFromDelimiters($link, 'facebook.com/l.php?u=', '&')); + return ' href="'.$link.'"'; + } + }; + $html = ''; if(isset($param['u'])) { @@ -39,16 +60,23 @@ class FacebookBridge extends BridgeAbstract{ if($post->hasAttribute("data-time")) { - //Clean the content of the page and convert relative links into absolute links + //Retrieve post contents $content = preg_replace('/(?i)>
]+)>(.+?)div\ class=\"userContent\"/i', '', $post); $content = preg_replace('/(?i)>
]+)>(.+?)<\/div><\/div>