_options['dump'])) {
$this->_options['force'] = TRUE;
}
if (isset($this->_options['force'])) {
$this->_cacheTimeout = '1 second';
}
}
protected function _getCachePath() {
return '../cache/facebook.%s';
}
protected function _getFeedUrl($feed) {
return sprintf('https://m.facebook.com/%s', $feed);
}
protected function __getUserAgent() {
return 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0.1';
}
protected function _parseFeedContent($tree) {
if (isset($this->_options['dump'])) {
print($tree->html());
die();
}
$items = [];
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 _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);
}
}
?>