_options['force'])) { $this->_cacheTimeout = '1 second'; } } protected function _getCachePath() { return '../cache/facebook.%s'; } protected function _fetchItems() { $jsonContent = []; exec('direnv exec ' . implode(DIRECTORY_SEPARATOR, [dirname(__FILE__), '..', 'bin', 'fb-scrape']) . ' ' . 'python ' . implode(DIRECTORY_SEPARATOR, [dirname(__FILE__), '..', 'bin', 'fb-scrape', 'get-fb-content.py']) . ' ' . escapeshellarg($this->_feed), $jsonContent); $cacheFile = sprintf($this->_getCachePath(), $this->_feed); if (file_exists($cacheFile)) { $cache = unserialize($this->_getCache($cacheFile)); } else { $cache = []; } $fetched = json_decode(implode(PHP_EOL, $jsonContent), TRUE); $cacheIDs = array_map(function($obj) { return $obj['id']; }, $cache); foreach ($fetched as $fetchedItem) { if (!in_array($fetchedItem['id'], $cacheIDs)) { $cache[] = $fetchedItem; } } return $cache; } protected function _mapItems($content) { return array_map( function ($obj) { $texts = $obj['texts']; if (!count($texts)) { $texts[] = ''; } if ($obj['images']) { $texts = array_merge( $texts, array_map(function($i) { return sprintf('', $i); }, $obj['images']) ); } $item = new Item(); $item->ID = $obj['id']; $item->Link = sprintf( 'https://facebook.com/%s', $obj['id'] ); $item->Title = $texts[0]; $item->Text = implode('
', $texts); $item->Time = $obj['time']; return $item; }, $content ); } protected function _sortContent($content) { return $content; } protected function _spamFilter($items) { return $items; } public function title() { return sprintf("%s's Facebook page posts", $this->_feed); } } ?>