diff --git a/bridges/FacebookBridge.php b/bridges/FacebookBridge.php index a3fd5846..351dc39c 100644 --- a/bridges/FacebookBridge.php +++ b/bridges/FacebookBridge.php @@ -3,7 +3,7 @@ * * @name Facebook * @homepage http://facebook.com/ -* @description Facebook bridge +* @description Input a page title or a profile log. For a profile log, please insert the parameter as follow : myExamplePage/132621766841117 * @update 03/08/2015 * @maintainer teromene * @use1(u="username") @@ -16,8 +16,13 @@ class FacebookBridge extends BridgeAbstract{ $html = ''; if(isset($param['u'])) { + if(!strpos($param['u'], "/")) { + $html = file_get_html('https://facebook.com/'.urlencode($param['u']).'?_fb_noscript=1') or $this->returnError('No results for this query.', 404); + } else { - $html = file_get_html('https://facebook.com/'.urlencode($param['u']).'?_fb_noscript=1') or $this->returnError('No results for this query.', 404); + $html = file_get_html('https://facebook.com/pages/'.$param['u'].'?_fb_noscript=1') or $this->returnError('No results for this query.', 404); + + } } else { $this->returnError('You must specify a Facebook username.', 400); @@ -28,39 +33,42 @@ class FacebookBridge extends BridgeAbstract{ $element = $html->find("[id^=PagePostsSectionPagelet-]")[0]->children(0)->children(0); - foreach($element->children() as $post) { + if(isset($element)) { + + foreach($element->children() as $post) { - $item = new \Item(); + $item = new \Item(); - if($post->hasAttribute("data-time")) { + if($post->hasAttribute("data-time")) { - //Clean the content of the page - $content = preg_replace('/(?i)><div class=\"clearfix([^>]+)>(.+?)div\ class=\"userContent\"/i', "", $post); - $content = preg_replace('/(?i)><div class=\"_59tj([^>]+)>(.+?)<\/div><\/div><a/i', "", $content); - $content = preg_replace('/(?i)><div class=\"_3dp([^>]+)>(.+?)div\ class=\"[^u]+userContent\"/i', "", $content); - $content = preg_replace('/(?i)><div class=\"_4l5([^>]+)>(.+?)<\/div>/i', "", $content); + //Clean the content of the page + $content = preg_replace('/(?i)><div class=\"clearfix([^>]+)>(.+?)div\ class=\"userContent\"/i', "", $post); + $content = preg_replace('/(?i)><div class=\"_59tj([^>]+)>(.+?)<\/div><\/div><a/i', "", $content); + $content = preg_replace('/(?i)><div class=\"_3dp([^>]+)>(.+?)div\ class=\"[^u]+userContent\"/i', "", $content); + $content = preg_replace('/(?i)><div class=\"_4l5([^>]+)>(.+?)<\/div>/i', "", $content); - $content = strip_tags($content,"<a><img>"); + $content = strip_tags($content,"<a><img>"); - $date = $post->find("abbr")[0]; - if(isset($date) && $date->hasAttribute("data-utime")) { - $date = $date->getAttribute("data-utime"); - } else { - $date = 0; - } + $date = $post->find("abbr")[0]; + if(isset($date) && $date->hasAttribute("data-utime")) { + $date = $date->getAttribute("data-utime"); + } else { + $date = 0; + } - $item->uri = 'https://facebook.com'.$post->find("abbr")[0]->parent()->getAttribute("href"); - $item->content = $content; - $item->title = $param['u']." | ".strip_tags($content); - $item->timestamp = $date; + $item->uri = 'https://facebook.com'.str_replace("&", "&", $post->find("abbr")[0]->parent()->getAttribute("href")); + + $item->content = $content; + $item->title = $param['u']." | ".strip_tags($content); + $item->timestamp = $date; - $this->items[] = $item; + $this->items[] = $item; + } } } - } public function getName(){