_options['dump'])) { $this->_options['force'] = TRUE; } if (isset($this->_options['force'])) { $this->_cacheTimeout = '1 second'; } } protected function __getUserAgent() { return 'curl/7.72.0'; } protected function _getCachePath() { return '../cache/facebook.%s'; } protected function _getFeedUrl($feed) { return sprintf('https://m.facebook.com/%s/posts', $feed); } protected function _parseFeedContent($tree) { $items = []; if (isset($this->_options['dump'])) { print($tree->html()); } foreach ($tree->find('#timelineBody div[data-ft]') as $header) { $data = json_decode($header->attr()['data-ft'], TRUE); if (isset($data['page_insights'])) { $data = $data['page_insights']; $data = array_filter( $data, function($a) { return isset($a['post_context']); } ); $data = array_pop($data); $data = $data['post_context']; $key = ((array)($data['story_fbid']))[0]; $texts = []; foreach ($header->find('p, h3') as $paragraph) { $texts[] = $paragraph->text(); } if (isset($this->_options['dump'])) { print_r($data); print($key); print(PHP_EOL); print_r($texts); print(PHP_EOL); } if (count($texts)) { $items[$key] = [ 'id' => $key, 'time' => $data['publish_time'], 'content' => $header->html(), 'texts' => $texts ]; } } } if (isset($this->_options['dump'])) { die(); } return array_values($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 ); } public function title() { return sprintf("%s's Facebook page posts", $this->_feed); } } ?>