. * */ namespace Vvveb\Component; use function Vvveb\getUrl; use Vvveb\System\Cache; use Vvveb\System\Component\ComponentBase; use Vvveb\System\Event; use Vvveb\System\Import\Rss; class News extends ComponentBase { protected $domain = 'https://blog.vvveb.com'; protected $url = '/feed/news'; public static $defaultOptions = [ 'page' => 0, 'limit' => 10, ]; public $options = []; function getNews() { $feed = getUrl($this->domain . $this->url, true, 604800, 3, false); if ($feed) { $rss = new Rss($feed); $result = $rss->get($this->options['page'], $this->options['limit']); return $result; } return []; } function results() { list($this->domain, $this->url) = Event::trigger(__CLASS__, 'url', $this->domain, $this->url); $cache = Cache::getInstance(); // check for news ~twice a week $news = $cache->cache('vvveb', 'news', function () { return $this->getNews(); }, 259200); $results = [ 'domain' => $this->domain, 'url' => $this->url, 'news' => $news, 'count' => count($news), ]; list($results) = Event::trigger(__CLASS__, __FUNCTION__, $results); return $results; } }