mirror of
https://github.com/ad-aures/castopod.git
synced 2026-04-11 02:36:42 +02:00
refactor: add phpstan and update code to adhere to level 5
- move and refactor Image.php from Libraries to Entities folder - update some database field names / types - update composer packages
This commit is contained in:
parent
b691b927fe
commit
231d578d64
148 changed files with 11189 additions and 11421 deletions
65
app/Controllers/FeedController.php
Normal file
65
app/Controllers/FeedController.php
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @copyright 2020 Podlibre
|
||||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
||||
* @link https://castopod.org/
|
||||
*/
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use CodeIgniter\Exceptions\PageNotFoundException;
|
||||
use Opawg\UserAgentsPhp\UserAgentsRSS;
|
||||
use Exception;
|
||||
use App\Models\EpisodeModel;
|
||||
use App\Models\PodcastModel;
|
||||
use CodeIgniter\Controller;
|
||||
|
||||
class FeedController extends Controller
|
||||
{
|
||||
public function index(string $podcastName): ResponseInterface
|
||||
{
|
||||
helper('rss');
|
||||
|
||||
$podcast = (new PodcastModel())->where('name', $podcastName)->first();
|
||||
if (!$podcast) {
|
||||
throw PageNotFoundException::forPageNotFound();
|
||||
}
|
||||
|
||||
$service = null;
|
||||
try {
|
||||
$service = UserAgentsRSS::find($_SERVER['HTTP_USER_AGENT']);
|
||||
} catch (Exception $exception) {
|
||||
// If things go wrong the show must go on and the user must be able to download the file
|
||||
log_message('critical', $exception);
|
||||
}
|
||||
|
||||
$serviceSlug = null;
|
||||
if ($service) {
|
||||
$serviceSlug = $service['slug'];
|
||||
}
|
||||
|
||||
$cacheName =
|
||||
"podcast#{$podcast->id}_feed" . ($service ? "_{$serviceSlug}" : '');
|
||||
|
||||
if (!($found = cache($cacheName))) {
|
||||
$found = get_rss_feed($podcast, $serviceSlug);
|
||||
|
||||
// The page cache is set to expire after next episode publication or a decade by default so it is deleted manually upon podcast update
|
||||
$secondsToNextUnpublishedEpisode = (new EpisodeModel())->getSecondsToNextUnpublishedEpisode(
|
||||
$podcast->id,
|
||||
);
|
||||
|
||||
cache()->save(
|
||||
$cacheName,
|
||||
$found,
|
||||
$secondsToNextUnpublishedEpisode
|
||||
? $secondsToNextUnpublishedEpisode
|
||||
: DECADE,
|
||||
);
|
||||
}
|
||||
|
||||
return $this->response->setXML($found);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue