From 071ec7fc3a9391d98a0fdfda741d5cf064f4ed48 Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 31 Jan 2019 16:26:45 +0100 Subject: Facebook providers based on the mobile site, fuck you --- providers/Facebook.php | 107 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 providers/Facebook.php (limited to 'providers') diff --git a/providers/Facebook.php b/providers/Facebook.php new file mode 100644 index 0000000..6514cfe --- /dev/null +++ b/providers/Facebook.php @@ -0,0 +1,107 @@ +_feed)); + curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)'); + curl_setopt($ch, CURLOPT_HTTPHEADER, $header); + curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); + curl_setopt($ch, CURLOPT_ENCODING, ''); + curl_setopt($ch, CURLOPT_TIMEOUT, 20); + $page = curl_exec($ch); + curl_close ($ch); + $this->_encoding = mb_detect_encoding($page); + return $page; + } + + protected function _fetchItems() { + $items = []; + $page = $this->__getWWWContent(); + $tree = htmlqp($page, NULL, ['convert_from_encoding' => $this->_encoding, 'convert_to_encoding' => $this->_encoding]); + $parents = []; + foreach ($tree->find('div[data-ft]') as $div) { + $data = json_decode($div->attr()['data-ft'], TRUE); + if (isset($data['mf_story_key'])) { + $pIns = $data['page_insights'][$data['page_id']]; + $key = $data['mf_story_key']; + $texts = []; + foreach ($div->find('h3') as $h3) { + if (!$h3->find(sprintf('a[href^="/%s/"]', $this->_feed))->count() || $h3->find('a')->count() > 1) { + $texts[] = trim($h3->text()); + } + } + foreach ($div->find('div>span p') as $p) { + $texts[] = trim(strip_tags($p->html())); + } + $items[$key] = [ + 'id' => $key, + 'content' => $div->html(), + 'texts' => $texts, + 'time' => $pIns['post_context']['publish_time'] + ]; + } + } + return array_values($items); + } + + protected function _spamFilter($items) { + return $items; + } + + protected function _mapItems($content) { + return array_map( + function ($obj) { + $item = new Item(); + $item->ID = $obj['id']; + $item->Link = sprintf( + 'https://facebook.com/%s', + $obj['id'] + ); + $item->Title = $obj['texts'][0]; + $item->Text = implode('
', $obj['texts']); + $item->Time = $obj['time']; + return $item; + }, + $content + ); + } + + protected function _sortContent($content) { + return $content; + } + + public function title() { + return sprintf("%s's Facebook page posts", $this->_feed); + } + +} + +?> -- cgit v1.2.3