0byt3m1n1
Path:
/
home
/
mgatv524
/
neovia.mgaplay.com.br
/
lib
/
Widget
/
[
Home
]
File: IcsTrait.php
<?php /* * Copyright (c) 2022 Xibo Signage Ltd * * Xibo - Digital Signage - http://www.xibo.org.uk * * This file is part of Xibo. * * Xibo is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * any later version. * * Xibo is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with Xibo. If not, see <http://www.gnu.org/licenses/>. */ namespace Xibo\Widget; use GuzzleHttp\Client; use GuzzleHttp\Exception\RequestException; use Stash\Invalidation; use Xibo\Support\Exception\ConfigurationException; trait IcsTrait { /** * Get the feed from Cache or Source * @return bool|string * @throws ConfigurationException */ private function getFeed() { // Create a key to use as a caching key for this item. // the rendered feed will be cached, so it is important the key covers all options. $feedUrl = urldecode($this->getOption('uri')); if (empty($feedUrl)) { throw new ConfigurationException(__('Please provide a calendar feed URL')); } /** @var \Stash\Item $cache */ $cache = $this->getPool()->getItem($this->makeCacheKey(md5($feedUrl))); $cache->setInvalidationMethod(Invalidation::SLEEP, 5000, 15); $this->getLog()->debug('Calendar ' . $feedUrl . '. Cache key: ' . $cache->getKey()); // Get the document out of the cache $document = $cache->get(); // Check our cache to see if the key exists if ($cache->isMiss()) { // Invalid local cache $this->getLog()->debug('Cache Miss, getting ICS file'); // Lock this cache item (120 seconds) $cache->lock(120); try { // Create a Guzzle Client to get the Feed XML $client = new Client(); $response = $client->get($feedUrl, $this->getConfig()->getGuzzleProxy([ 'timeout' => 20 // wait no more than 20 seconds: https://github.com/xibosignage/xibo/issues/1401 ])); $document = $response->getBody()->getContents(); } catch (RequestException $requestException) { // Log and return empty? $this->getLog()->error('Unable to get feed: ' . $requestException->getMessage()); $this->getLog()->debug($requestException->getTraceAsString()); throw new ConfigurationException(__('Unable to download feed')); } // Add this to the cache. $cache->set($document); $cache->expiresAfter($this->getOption('updateInterval', 360) * 60); // Save $this->getPool()->saveDeferred($cache); } else { $this->getLog()->debug('Feed returned from Cache'); } return $document; } }