Loading app/Controllers/Feed.php +6 −4 Original line number Diff line number Diff line Loading @@ -23,22 +23,24 @@ class Feed extends Controller throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound(); } $service = null; $serviceSlug = ''; try { $service = \Opawg\UserAgentsPhp\UserAgentsRSS::find( $_SERVER['HTTP_USER_AGENT'] ); if ($service) { $serviceSlug = $service['slug']; } } 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']}" : ''); "podcast{$podcast->id}_feed" . ($service ? "_{$serviceSlug}" : ''); if (!($found = cache($cacheName))) { $found = get_rss_feed($podcast, $service ? $service['name'] : ''); $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( Loading app/Database/Seeds/FakePodcastsAnalyticsSeeder.php +1 −1 Original line number Diff line number Diff line Loading @@ -78,7 +78,7 @@ class FakePodcastsAnalyticsSeeder extends Seeder $service = $jsonRSSUserAgents[ rand(1, count($jsonRSSUserAgents) - 1) ]['name']; ]['slug']; $app = isset($player['app']) ? $player['app'] : ''; $device = isset($player['device']) ? $player['device'] Loading app/Entities/AnalyticsPodcastsByCountry.php +5 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,11 @@ use CodeIgniter\Entity; class AnalyticsPodcastsByCountry extends Entity { /** * @var string */ protected $labels; protected $casts = [ 'podcast_id' => 'integer', 'country_code' => 'string', Loading app/Entities/AnalyticsPodcastsByService.php 0 → 100644 +38 −0 Original line number Diff line number Diff line <?php /** * Class AnalyticsPodcastsByService * Entity for AnalyticsPodcastsByService * @copyright 2020 Podlibre * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @link https://castopod.org/ */ namespace App\Entities; use CodeIgniter\Entity; class AnalyticsPodcastsByService extends Entity { /** * @var string */ protected $labels; protected $casts = [ 'podcast_id' => 'integer', 'app' => '?string', 'device' => '?string', 'os' => '?string', 'is_bot' => 'boolean', 'date' => 'datetime', 'hits' => 'integer', ]; public function getLabels() { return \Opawg\UserAgentsPhp\UserAgentsRSS::getName( $this->attributes['labels'] ) ?? $this->attributes['labels']; } } app/Helpers/rss_helper.php +2 −2 Original line number Diff line number Diff line Loading @@ -17,7 +17,7 @@ use Config\Mimes; * @param string $service The name of the service that fetches the RSS feed for future reference when the audio file is eventually downloaded * @return string rss feed as xml */ function get_rss_feed($podcast, $serviceName = '') function get_rss_feed($podcast, $serviceSlug = '') { $episodes = $podcast->episodes; Loading Loading @@ -185,7 +185,7 @@ function get_rss_feed($podcast, $serviceName = '') $enclosure->addAttribute( 'url', $episode->enclosure_url . (empty($serviceName) ? '' : '?_from=' . urlencode($serviceName)) (empty($serviceSlug) ? '' : '?_from=' . urlencode($serviceSlug)) ); $enclosure->addAttribute('length', $episode->enclosure_filesize); $enclosure->addAttribute('type', $episode->enclosure_mimetype); Loading Loading
app/Controllers/Feed.php +6 −4 Original line number Diff line number Diff line Loading @@ -23,22 +23,24 @@ class Feed extends Controller throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound(); } $service = null; $serviceSlug = ''; try { $service = \Opawg\UserAgentsPhp\UserAgentsRSS::find( $_SERVER['HTTP_USER_AGENT'] ); if ($service) { $serviceSlug = $service['slug']; } } 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']}" : ''); "podcast{$podcast->id}_feed" . ($service ? "_{$serviceSlug}" : ''); if (!($found = cache($cacheName))) { $found = get_rss_feed($podcast, $service ? $service['name'] : ''); $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( Loading
app/Database/Seeds/FakePodcastsAnalyticsSeeder.php +1 −1 Original line number Diff line number Diff line Loading @@ -78,7 +78,7 @@ class FakePodcastsAnalyticsSeeder extends Seeder $service = $jsonRSSUserAgents[ rand(1, count($jsonRSSUserAgents) - 1) ]['name']; ]['slug']; $app = isset($player['app']) ? $player['app'] : ''; $device = isset($player['device']) ? $player['device'] Loading
app/Entities/AnalyticsPodcastsByCountry.php +5 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,11 @@ use CodeIgniter\Entity; class AnalyticsPodcastsByCountry extends Entity { /** * @var string */ protected $labels; protected $casts = [ 'podcast_id' => 'integer', 'country_code' => 'string', Loading
app/Entities/AnalyticsPodcastsByService.php 0 → 100644 +38 −0 Original line number Diff line number Diff line <?php /** * Class AnalyticsPodcastsByService * Entity for AnalyticsPodcastsByService * @copyright 2020 Podlibre * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @link https://castopod.org/ */ namespace App\Entities; use CodeIgniter\Entity; class AnalyticsPodcastsByService extends Entity { /** * @var string */ protected $labels; protected $casts = [ 'podcast_id' => 'integer', 'app' => '?string', 'device' => '?string', 'os' => '?string', 'is_bot' => 'boolean', 'date' => 'datetime', 'hits' => 'integer', ]; public function getLabels() { return \Opawg\UserAgentsPhp\UserAgentsRSS::getName( $this->attributes['labels'] ) ?? $this->attributes['labels']; } }
app/Helpers/rss_helper.php +2 −2 Original line number Diff line number Diff line Loading @@ -17,7 +17,7 @@ use Config\Mimes; * @param string $service The name of the service that fetches the RSS feed for future reference when the audio file is eventually downloaded * @return string rss feed as xml */ function get_rss_feed($podcast, $serviceName = '') function get_rss_feed($podcast, $serviceSlug = '') { $episodes = $podcast->episodes; Loading Loading @@ -185,7 +185,7 @@ function get_rss_feed($podcast, $serviceName = '') $enclosure->addAttribute( 'url', $episode->enclosure_url . (empty($serviceName) ? '' : '?_from=' . urlencode($serviceName)) (empty($serviceSlug) ? '' : '?_from=' . urlencode($serviceSlug)) ); $enclosure->addAttribute('length', $episode->enclosure_filesize); $enclosure->addAttribute('type', $episode->enclosure_mimetype); Loading