diff --git a/bridges/FacebookBridge.php b/bridges/FacebookBridge.php index 351dc39c..109be9bb 100644 --- a/bridges/FacebookBridge.php +++ b/bridges/FacebookBridge.php @@ -1,87 +1,99 @@ returnError('No results for this query.', 404); + private $name; + + public function collectData(array $param){ + + $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/pages/'.$param['u'].'?_fb_noscript=1') or $this->returnError('No results for this query.', 404); + } } else { - - $html = file_get_html('https://facebook.com/pages/'.$param['u'].'?_fb_noscript=1') or $this->returnError('No results for this query.', 404); - + $this->returnError('You must specify a Facebook username.', 400); } - } else { - $this->returnError('You must specify a Facebook username.', 400); + $element = $html->find('[id^=PagePostsSectionPagelet-]')[0]->children(0)->children(0); - } + if(isset($element)) { + $author = str_replace(' | Facebook', '', $html->find('title#pageTitle', 0)->innertext); + $profilePic = 'https://graph.facebook.com/'.$param['u'].'/picture?width=200&height=200'; + $this->name = $author; - - $element = $html->find("[id^=PagePostsSectionPagelet-]")[0]->children(0)->children(0); - - if(isset($element)) { - - foreach($element->children() as $post) { - - $item = new \Item(); - - if($post->hasAttribute("data-time")) { - - //Clean the content of the page - $content = preg_replace('/(?i)>