_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/posts', $feed);
}
protected function _parseFeedContent($tree) {
$items = [];
if (isset($this->_options['dump'])) {
print($tree->html());
}
foreach ($tree->find('article') as $header) {
$data = json_decode($header->attr()['data-store'], TRUE)['linkdata'];
$data = array_filter(
json_decode(explode('page_insights.', $data)[1], TRUE),
function($a) { return isset($a['post_context']); }
)['post_context'];
$key = $data['story_fbid'];
$texts = [];
foreach ($header->find('p, h3') as $paragraph) {
$texts[] = utf8_decode($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);
}
}
?>