2020-06-26 14:34:52 +00:00
|
|
|
<?php
|
2020-08-04 11:25:22 +00:00
|
|
|
|
2020-07-10 12:20:25 +00:00
|
|
|
/**
|
|
|
|
* @copyright 2020 Podlibre
|
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
2020-06-26 14:34:52 +00:00
|
|
|
|
|
|
|
namespace App\Controllers;
|
|
|
|
|
|
|
|
use App\Models\PodcastModel;
|
|
|
|
use CodeIgniter\Controller;
|
|
|
|
|
|
|
|
class Feed extends Controller
|
|
|
|
{
|
2020-08-04 11:25:22 +00:00
|
|
|
public function index($podcastName)
|
2020-06-26 14:34:52 +00:00
|
|
|
{
|
2020-08-04 11:25:22 +00:00
|
|
|
helper('rss');
|
|
|
|
|
|
|
|
$podcast = (new PodcastModel())->where('name', $podcastName)->first();
|
2020-10-21 16:04:18 +00:00
|
|
|
if (!$podcast) {
|
|
|
|
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
|
|
|
|
}
|
2020-08-04 11:25:22 +00:00
|
|
|
|
2020-10-21 16:04:18 +00:00
|
|
|
$service = null;
|
|
|
|
try {
|
|
|
|
$service = \Opawg\UserAgentsPhp\UserAgentsRSS::find(
|
|
|
|
$_SERVER['HTTP_USER_AGENT']
|
|
|
|
);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
// If things go wrong the show must go on and the user must be able to download the file
|
|
|
|
log_message('critical', $e);
|
|
|
|
}
|
|
|
|
$cacheName =
|
|
|
|
"podcast{$podcast->id}_feed" .
|
|
|
|
($service ? "_{$service['slug']}" : '');
|
|
|
|
if (!($found = cache($cacheName))) {
|
|
|
|
$found = get_rss_feed(
|
|
|
|
$podcast,
|
|
|
|
$service ? '?s=' . urlencode($service['name']) : ''
|
|
|
|
);
|
|
|
|
cache()->save($cacheName, $found, DECADE);
|
|
|
|
}
|
|
|
|
return $this->response->setXML($found);
|
2020-06-26 14:34:52 +00:00
|
|
|
}
|
|
|
|
}
|