Skip to content
Snippets Groups Projects
Commit c815ecd6 authored by Yassine Doghri's avatar Yassine Doghri
Browse files

feat(rss): generate rss feed from podcast entity

- refactor episode, podcast and category entities to add dynamic properties
- refactor Routes when adding feed route
- update migration files to better fit itunes' and rss' specs
- update podcast and episode forms
- add SimpleRSSElement class to Libraries
- add rss_helper
- update home controller to redirect if system has only one podcast
parent d3119173
No related branches found
No related tags found
No related merge requests found
Showing
with 394 additions and 132 deletions
......@@ -100,7 +100,7 @@ class App extends BaseConfig
| dates with the date helper, and can be retrieved through app_timezone()
|
*/
public $appTimezone = 'America/Chicago';
public $appTimezone = 'UTC';
/*
|--------------------------------------------------------------------------
......
......@@ -22,7 +22,7 @@ $routes->setDefaultMethod('index');
$routes->setTranslateURIDashes(false);
$routes->set404Override();
$routes->setAutoRoute(false);
$routes->addPlaceholder('podcastSlug', '@[a-z0-9\_]{1,191}');
$routes->addPlaceholder('podcastName', '[a-z0-9\_]{1,191}');
$routes->addPlaceholder('episodeSlug', '[a-z0-9\-]{1,191}');
/**
......@@ -34,24 +34,27 @@ $routes->addPlaceholder('episodeSlug', '[a-z0-9\-]{1,191}');
// We get a performance increase by specifying the default
// route since we don't have to scan directories.
$routes->get('/', 'Home::index', ['as' => 'home']);
$routes->add('new-podcast', 'Podcasts::create', ['as' => 'podcasts_create']);
$routes->add('new-podcast', 'Podcast::create', ['as' => 'podcast_create']);
$routes->group('(:podcastSlug)', function ($routes) {
$routes->add('/', 'Podcasts::view/$1', ['as' => 'podcasts_view']);
$routes->add('new-episode', 'Episodes::create/$1', [
'as' => 'episodes_create',
$routes->group('@(:podcastName)', function ($routes) {
$routes->add('/', 'Podcast::view/$1', ['as' => 'podcast_view']);
$routes->add('feed.xml', 'Feed/$1', ['as' => 'podcast_feed']);
$routes->add('new-episode', 'Episode::create/$1', [
'as' => 'episode_create',
]);
$routes->add('(:episodeSlug)', 'Episodes::view/$1/$2', [
'as' => 'episodes_view',
$routes->add('episodes/(:episodeSlug)', 'Episode::view/$1/$2', [
'as' => 'episode_view',
]);
});
// Route for podcast audio file analytics (/stats/podcast_id/episode_id/podcast_folder/filename.mp3)
$routes->add('/stats/(:num)/(:num)/(:any)', 'Analytics::hit/$1/$2/$3');
$routes->add('stats/(:num)/(:num)/(:any)', 'Analytics::hit/$1/$2/$3', [
'as' => 'analytics_hit',
]);
// Show the Unknown UserAgents
$routes->add('/.well-known/unknown-useragents', 'UnknownUserAgents');
$routes->add('/.well-known/unknown-useragents/(:num)', 'UnknownUserAgents/$1');
$routes->add('.well-known/unknown-useragents', 'UnknownUserAgents');
$routes->add('.well-known/unknown-useragents/(:num)', 'UnknownUserAgents/$1');
/**
* --------------------------------------------------------------------
......
......@@ -21,7 +21,7 @@ class Toolbar extends BaseConfig
\CodeIgniter\Debug\Toolbar\Collectors\Database::class,
\CodeIgniter\Debug\Toolbar\Collectors\Logs::class,
\CodeIgniter\Debug\Toolbar\Collectors\Views::class,
// \CodeIgniter\Debug\Toolbar\Collectors\Cache::class,
\CodeIgniter\Debug\Toolbar\Collectors\Cache::class,
\CodeIgniter\Debug\Toolbar\Collectors\Files::class,
\CodeIgniter\Debug\Toolbar\Collectors\Routes::class,
\CodeIgniter\Debug\Toolbar\Collectors\Events::class,
......
......@@ -50,7 +50,7 @@ class BaseController extends Controller
set_user_session_referer();
}
protected function stats($postcast_id)
protected static function triggerWebpageHit($postcast_id)
{
webpage_hit($postcast_id);
}
......
......@@ -10,15 +10,17 @@ namespace App\Controllers;
use App\Models\EpisodeModel;
use App\Models\PodcastModel;
class Episodes extends BaseController
helper('podcast');
class Episode extends BaseController
{
public function create($podcast_slug)
public function create($podcast_name)
{
helper(['form', 'database', 'media', 'id3']);
$episode_model = new EpisodeModel();
$podcast_model = new PodcastModel();
$podcast_name = substr($podcast_slug, 1);
$podcast = $podcast_model->where('name', $podcast_name)->first();
if (
......@@ -33,13 +35,9 @@ class Episodes extends BaseController
) {
$data = [
'podcast' => $podcast,
'episode_types' => field_enums(
$episode_model->prefixTable('episodes'),
'type'
),
];
echo view('episodes/create', $data);
echo view('episode/create', $data);
} else {
$episode_slug = $this->request->getVar('slug');
......@@ -49,7 +47,7 @@ class Episodes extends BaseController
$image = $this->request->getFile('image');
// By default, the episode's image path is set to the podcast's
$image_path = $podcast->image;
$image_path = $podcast->image_uri;
// check whether the user has inputted an image and store it
if ($image->isValid()) {
......@@ -81,20 +79,21 @@ class Episodes extends BaseController
'podcast_id' => $podcast->id,
'title' => $this->request->getVar('title'),
'slug' => $episode_slug,
'enclosure_url' => $episode_path,
'enclosure_uri' => $episode_path,
'enclosure_length' => $episode_file->getSize(),
'enclosure_type' => $episode_file_metadata['mime_type'],
'guid' => $podcast_slug . '/' . $episode_slug,
'pub_date' => $this->request->getVar('pub_date'),
'description' => $this->request->getVar('description'),
'duration' => $episode_file_metadata['playtime_seconds'],
'image' => $image_path,
'image_uri' => $image_path,
'explicit' => $this->request->getVar('explicit') or false,
'number' => $this->request->getVar('episode_number'),
'season_number' => $this->request->getVar('season_number')
? $this->request->getVar('season_number')
: null,
'type' => $this->request->getVar('type'),
'author_name' => $this->request->getVar('author_name'),
'author_email' => $this->request->getVar('author_email'),
'block' => $this->request->getVar('block') or false,
]);
......@@ -103,30 +102,25 @@ class Episodes extends BaseController
$episode_file = write_file_tags($podcast, $episode);
return redirect()->to(
base_url(
route_to(
'episodes_view',
'/@' . $podcast_name,
$episode_slug
)
)
base_url(route_to('episode_view', $podcast_name, $episode_slug))
);
}
}
public function view($podcast_slug, $episode_slug)
public function view($podcast_name, $episode_slug)
{
$podcast_model = new PodcastModel();
$episode_model = new EpisodeModel();
$podcast = $podcast_model->where('name', $podcast_name)->first();
$episode = $episode_model->where('slug', $episode_slug)->first();
$data = [
'podcast' => $podcast_model
->where('name', substr($podcast_slug, 1))
->first(),
'episode' => $episode_model->where('slug', $episode_slug)->first(),
'podcast' => $podcast,
'episode' => $episode,
];
self::stats($data['podcast']->id);
self::triggerWebpageHit($data['podcast']->id);
return view('episodes/view.php', $data);
return view('episode/view.php', $data);
}
}
<?php
namespace App\Controllers;
use App\Models\PodcastModel;
use CodeIgniter\Controller;
class Feed extends Controller
{
public function index($podcast_name)
{
helper('rss');
$podcast_model = new PodcastModel();
$podcast = $podcast_model->where('name', $podcast_name)->first();
// The page cache is set to a decade so it is deleted manually upon podcast update
$this->cachePage(DECADE);
return $this->response->setXML(get_rss_feed($podcast));
}
}
......@@ -14,8 +14,18 @@ class Home extends BaseController
public function index()
{
$model = new PodcastModel();
$data = ['podcasts' => $model->findAll()];
$all_podcasts = $model->findAll();
// check if there's only one podcast to redirect user to it
if (count($all_podcasts) == 1) {
return redirect()->to(
base_url(route_to('podcast_view', $all_podcasts[0]->name))
);
}
// default behavior: list all podcasts on home page
$data = ['podcasts' => $all_podcasts];
return view('home', $data);
}
}
......@@ -4,16 +4,14 @@
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
namespace App\Controllers;
use App\Entities\Podcast;
use App\Models\CategoryModel;
use App\Models\EpisodeModel;
use App\Models\LanguageModel;
use App\Models\PodcastModel;
class Podcasts extends BaseController
class Podcast extends BaseController
{
public function create()
{
......@@ -39,30 +37,27 @@ class Podcasts extends BaseController
'browser_lang' => get_browser_language(
$this->request->getServer('HTTP_ACCEPT_LANGUAGE')
),
'podcast_types' => field_enums(
$podcast_model->prefixTable('podcasts'),
'type'
),
];
echo view('podcasts/create', $data);
echo view('podcast/create', $data);
} else {
$image = $this->request->getFile('image');
$podcast_name = $this->request->getVar('name');
$image_path = save_podcast_media($image, $podcast_name, 'cover');
$podcast = new Podcast([
$podcast = new \App\Entities\Podcast([
'title' => $this->request->getVar('title'),
'name' => $podcast_name,
'description' => $this->request->getVar('description'),
'episode_description_footer' => $this->request->getVar(
'episode_description_footer'
),
'image' => $image_path,
'image_uri' => $image_path,
'language' => $this->request->getVar('language'),
'category' => $this->request->getVar('category'),
'explicit' => $this->request->getVar('explicit') or false,
'author' => $this->request->getVar('author'),
'author_name' => $this->request->getVar('author_name'),
'author_email' => $this->request->getVar('author_email'),
'owner_name' => $this->request->getVar('owner_name'),
'owner_email' => $this->request->getVar('owner_email'),
'type' => $this->request->getVar('type'),
......@@ -77,18 +72,16 @@ class Podcasts extends BaseController
$podcast_model->save($podcast);
return redirect()->to(
base_url(route_to('podcasts_view', '@' . $podcast_name))
base_url(route_to('podcast_view', $podcast->name))
);
}
}
public function view($slug)
public function view($podcast_name)
{
$podcast_model = new PodcastModel();
$episode_model = new EpisodeModel();
$podcast_name = substr($slug, 1);
$podcast = $podcast_model->where('name', $podcast_name)->first();
$data = [
'podcast' => $podcast,
......@@ -96,8 +89,8 @@ class Podcasts extends BaseController
->where('podcast_id', $podcast->id)
->findAll(),
];
self::stats($podcast->id);
self::triggerWebpageHit($podcast->id);
return view('podcasts/view', $data);
return view('podcast/view', $data);
}
}
......@@ -29,8 +29,7 @@ class AddCategories extends Migration
],
'code' => [
'type' => 'VARCHAR',
'constraint' => 1024,
'unique' => true,
'constraint' => 191,
],
'apple_category' => [
'type' => 'VARCHAR',
......@@ -42,6 +41,7 @@ class AddCategories extends Migration
],
]);
$this->forge->addKey('id', true);
$this->forge->addUniqueKey('code');
$this->forge->addForeignKey('parent_id', 'categories', 'id');
$this->forge->createTable('categories');
}
......
......@@ -41,7 +41,7 @@ class AddPodcasts extends Migration
'comment' =>
'The show description. Where description is text containing one or more sentences describing your podcast to potential listeners. The maximum amount of text allowed for this tag is 4000 characters. To include links in your description or rich HTML, adhere to the following technical guidelines: enclose all portions of your XML that contain embedded HTML in a CDATA section to prevent formatting issues, and to ensure proper link functionality.',
],
'image' => [
'image_uri' => [
'type' => 'VARCHAR',
'constraint' => 1024,
'comment' =>
......@@ -67,11 +67,18 @@ class AddPodcasts extends Migration
'comment' =>
'The podcast parental advisory information. The explicit value can be one of the following: True: If you specify true, indicating the presence of explicit content, Apple Podcasts displays an Explicit parental advisory graphic for your podcast. Podcasts containing explicit material aren’t available in some Apple Podcasts territories. False: If you specify false, indicating that your podcast doesn’t contain explicit language or adult content, Apple Podcasts displays a Clean parental advisory graphic for your podcast.',
],
'author' => [
'author_name' => [
'type' => 'VARCHAR',
'constraint' => 1024,
'comment' =>
'The group responsible for creating the show. Show author most often refers to the parent company or network of a podcast, but it can also be used to identify the host(s) if none exists. Author information is especially useful if a company or organization publishes multiple podcasts. Providing this information will allow listeners to see all shows created by the same entity.',
'Name of the group responsible for creating the show. Show author most often refers to the parent company or network of a podcast, but it can also be used to identify the host(s) if none exists. Author information is especially useful if a company or organization publishes multiple podcasts. Providing this information will allow listeners to see all shows created by the same entity.',
'null' => true,
],
'author_email' => [
'type' => 'VARCHAR',
'constraint' => 1024,
'owner_email' =>
'Email of the group responsible for creating the show. Show author most often refers to the parent company or network of a podcast, but it can also be used to identify the host(s) if none exists. Author information is especially useful if a company or organization publishes multiple podcasts. Providing this information will allow listeners to see all shows created by the same entity.',
'null' => true,
],
'owner_name' => [
......
......@@ -41,11 +41,11 @@ class AddEpisodes extends Migration
'constraint' => 191,
'comment' => 'Episode slug for URLs',
],
'enclosure_url' => [
'enclosure_uri' => [
'type' => 'VARCHAR',
'constraint' => 1024,
'comment' =>
'The URL attribute points to your podcast media file. The file extension specified within the URL attribute determines whether or not content appears in the podcast directory. Supported file formats include M4A, MP3, MOV, MP4, M4V, and PDF.',
'The URI attribute points to your podcast media file. The file extension specified within the URI attribute determines whether or not content appears in the podcast directory. Supported file formats include M4A, MP3, MOV, MP4, M4V, and PDF.',
],
'enclosure_length' => [
'type' => 'INT',
......@@ -69,7 +69,7 @@ class AddEpisodes extends Migration
'pub_date' => [
'type' => 'DATETIME',
'comment' =>
'The date and time when an episode was released. Format the date using the RFC 2822 specifications. For example: Wed, 15 Jun 2019 19:00:00 GMT.',
'The date and time when an episode was released. Format the date using the RFC 2822 specifications. For example: Wed, 15 Jun 2019 19:00:00 UTC.',
],
'description' => [
'type' => 'TEXT',
......@@ -84,7 +84,7 @@ class AddEpisodes extends Migration
'comment' =>
'The duration of an episode. Different duration formats are accepted however it is recommended to convert the length of the episode into seconds.',
],
'image' => [
'image_uri' => [
'type' => 'VARCHAR',
'constraint' => 1024,
'comment' =>
......@@ -112,6 +112,20 @@ class AddEpisodes extends Migration
'comment' =>
'The episode season number. If an episode is within a season use this tag. Where season is a non-zero integer (1, 2, 3, etc.) representing your season number. To allow the season feature for shows containing a single season, if only one season exists in the RSS feed, Apple Podcasts doesn’t display a season number. When you add a second season to the RSS feed, Apple Podcasts displays the season numbers.',
],
'author_name' => [
'type' => 'VARCHAR',
'constraint' => 1024,
'comment' =>
'Name of the group responsible for creating the episode. Episode author most often refers to the parent company or network of a podcast, but it can also be used to identify the host(s) if none exists. Author information is especially useful if a company or organization publishes multiple podcasts. Providing this information will allow listeners to see all episodes created by the same entity.',
'null' => true,
],
'author_email' => [
'type' => 'VARCHAR',
'constraint' => 1024,
'owner_email' =>
'Email of the group responsible for creating the episode. Episode author most often refers to the parent company or network of a podcast, but it can also be used to identify the host(s) if none exists. Author information is especially useful if a company or organization publishes multiple podcasts. Providing this information will allow listeners to see all episodes created by the same entity.',
'null' => true,
],
'type' => [
'type' => 'ENUM',
'constraint' => ['full', 'trailer', 'bonus'],
......
......@@ -7,13 +7,27 @@
namespace App\Entities;
use App\Models\CategoryModel;
use CodeIgniter\Entity;
class Category extends Entity
{
protected $parent;
protected $casts = [
'parent_id' => 'integer',
'code' => 'string',
'apple_category' => 'string',
'google_category' => 'string',
];
public function getParent()
{
$category_model = new CategoryModel();
$parent_id = $this->attributes['parent_id'];
return $parent_id != 0
? $category_model->find($this->attributes['parent_id'])
: null;
}
}
......@@ -7,25 +7,85 @@
namespace App\Entities;
use App\Models\PodcastModel;
use CodeIgniter\Entity;
class Episode extends Entity
{
protected $link;
protected $image_media_path;
protected $image_url;
protected $enclosure_media_path;
protected $enclosure_url;
protected $guid;
protected $podcast;
protected $casts = [
'slug' => 'string',
'title' => 'string',
'enclosure_url' => 'string',
'enclosure_uri' => 'string',
'enclosure_length' => 'integer',
'enclosure_type' => 'string',
'guid' => 'string',
'pub_date' => 'datetime',
'description' => 'string',
'duration' => 'integer',
'image' => 'string',
'image_uri' => 'string',
'author_name' => '?string',
'author_email' => '?string',
'explicit' => 'boolean',
'number' => 'integer',
'season_number' => '?integer',
'type' => 'string',
'block' => 'boolean',
];
public function getImageMediaPath()
{
return media_path($this->attributes['image_uri']);
}
public function getImageUrl()
{
return media_url($this->attributes['image_uri']);
}
public function getEnclosureMediaPath()
{
return media_path($this->attributes['enclosure_uri']);
}
public function getEnclosureUrl()
{
return base_url(
route_to(
'analytics_hit',
$this->attributes['podcast_id'],
$this->attributes['id'],
$this->attributes['enclosure_uri']
)
);
}
public function getLink()
{
return base_url(
route_to(
'episode_view',
$this->getPodcast()->name,
$this->attributes['slug']
)
);
}
public function getGuid()
{
return $this->getLink();
}
public function getPodcast()
{
$podcast_model = new PodcastModel();
return $podcast_model->find($this->attributes['podcast_id']);
}
}
......@@ -7,27 +7,57 @@
namespace App\Entities;
use App\Models\EpisodeModel;
use CodeIgniter\Entity;
class Podcast extends Entity
{
protected $link;
protected $image_url;
protected $episodes;
protected $casts = [
'id' => 'integer',
'title' => 'string',
'name' => 'string',
'description' => 'string',
'image' => 'string',
'image_uri' => 'string',
'language' => 'string',
'category' => 'string',
'explicit' => 'boolean',
'author' => '?string',
'author_name' => '?string',
'author_email' => '?string',
'owner_name' => '?string',
'owner_email' => '?string',
'type' => '?string',
'type' => 'string',
'copyright' => '?string',
'block' => 'boolean',
'complete' => 'boolean',
'episode_description_footer' => '?string',
'custom_html_head' => '?string',
];
public function getImageUrl()
{
return media_url($this->attributes['image_uri']);
}
public function getLink()
{
return base_url(route_to('podcast_view', $this->attributes['name']));
}
public function getFeedUrl()
{
return base_url(route_to('podcast_feed', $this->attributes['name']));
}
public function getEpisodes()
{
$episode_model = new EpisodeModel();
return $episode_model
->where('podcast_id', $this->attributes['id'])
->findAll();
}
}
<?php
/**
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
/**
* Get all possible enum values for a table field
*
* @param string $table
* @param string $field
*
* @return array $enums
*/
function field_enums($table = '', $field = '')
{
$enums = [];
if ($table == '' || $field == '') {
return $enums;
}
$db = \Config\Database::connect();
preg_match_all(
"/'(.*?)'/",
$db->query("SHOW COLUMNS FROM {$table} LIKE '{$field}'")->getRow()
->Type,
$matches
);
foreach ($matches[1] as $value) {
$enums[$value] = $value;
}
return $enums;
}
......@@ -44,20 +44,20 @@ function write_file_tags($podcast, $episode)
// Initialize getID3 tag-writing module
$tagwriter = new WriteTags();
$tagwriter->filename = media_path($episode->enclosure_url);
$tagwriter->filename = $episode->enclosure_media_path;
// set various options (optional)
$tagwriter->tagformats = ['id3v2.4'];
$tagwriter->tag_encoding = $TextEncoding;
$cover = new \CodeIgniter\Files\File(media_path($episode->image));
$cover = new \CodeIgniter\Files\File($episode->image_media_path);
$APICdata = file_get_contents($cover->getRealPath());
// TODO: variables used for podcast specific tags
// $podcast_url = base_url('@' . $podcast->name);
// $podcast_feed_url = base_url('@' . $podcast->name . '/feed.xml');
// $episode_media_url = media_url($podcast->name . '/' . $episode->slug);
// $podcast_url = $podcast->link;
// $podcast_feed_url = $podcast->feed_url;
// $episode_media_url = $episode->link;
// populate data array
$TagData = [
......
......@@ -12,7 +12,7 @@
* @param string $podcast_name
* @param string $file_name
*
* @return string The absolute path of the file in media root
* @return string The episode's file path in media root
*/
function save_podcast_media($file, $podcast_name, $media_name)
{
......
<?php
/**
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
use App\Models\CategoryModel;
use CodeIgniter\I18n\Time;
/**
* Generates the rss feed for a given podcast entity
*
* @param App\Entities\Podcast $podcast
* @return string rss feed as xml
*/
function get_rss_feed($podcast)
{
$category_model = new CategoryModel();
$episodes = $podcast->episodes;
$podcast_category = $category_model
->where('code', $podcast->category)
->first();
$itunes_namespace = 'http://www.itunes.com/dtds/podcast-1.0.dtd';
$rss = new SimpleRSSElement(
"<?xml version='1.0' encoding='utf-8'?><rss version='2.0' xmlns:itunes='$itunes_namespace' xmlns:content='http://purl.org/rss/1.0/modules/content/'></rss>"
);
$channel = $rss->addChild('channel');
$atom_link = $channel->addChild(
'atom:link',
null,
'http://www.w3.org/2005/Atom'
);
$atom_link->addAttribute('href', $podcast->feed_url);
$atom_link->addAttribute('rel', 'self');
$atom_link->addAttribute('type', 'application/rss+xml');
// the last build date corresponds to the creation of the feed.xml cache
$channel->addChild(
'lastBuildDate',
(new Time('now'))->format(DATE_RFC1123)
);
$channel->addChild(
'generator',
'Castopod 0.0.0-development - https://castopod.org'
);
$channel->addChild('docs', 'https://cyber.harvard.edu/rss/rss.html');
$channel->addChild('title', $podcast->title);
$channel->addChildWithCDATA('description', $podcast->description);
$itunes_image = $channel->addChild('image', null, $itunes_namespace);
$itunes_image->addAttribute('href', $podcast->image_url);
$channel->addChild('language', $podcast->language);
$itunes_category = $channel->addChild('category', null, $itunes_namespace);
$itunes_category->addAttribute(
'text',
$podcast_category->parent
? $podcast_category->parent->apple_category
: $podcast_category->apple_category
);
if ($podcast_category->parent) {
$itunes_category_child = $itunes_category->addChild(
'category',
null,
$itunes_namespace
);
$itunes_category_child->addAttribute(
'text',
$podcast_category->apple_category
);
$channel->addChild(
'category',
$podcast_category->parent->apple_category
);
}
$channel->addChild('category', $podcast_category->apple_category);
$channel->addChild(
'explicit',
$podcast->explicit ? 'true' : 'false',
$itunes_namespace
);
$podcast->author_name &&
$channel->addChild('author', $podcast->author_name, $itunes_namespace);
$channel->addChild('link', $podcast->link);
if ($podcast->owner_name || $podcast->owner_email) {
$owner = $channel->addChild('owner', null, $itunes_namespace);
$podcast->owner_name &&
$owner->addChild('name', $podcast->owner_name, $itunes_namespace);
$podcast->owner_email &&
$owner->addChild('email', $podcast->owner_email, $itunes_namespace);
}
$channel->addChild('type', $podcast->type, $itunes_namespace);
$podcast->copyright && $channel->addChild('copyright', $podcast->copyright);
$podcast->block && $channel->addChild('block', 'Yes', $itunes_namespace);
$podcast->complete &&
$channel->addChild('complete', 'Yes', $itunes_namespace);
$image = $channel->addChild('image');
$image->addChild('url', $podcast->image_url);
$image->addChild('title', $podcast->title);
$image->addChild('link', $podcast->link);
foreach ($episodes as $episode) {
$item = $channel->addChild('item');
$item->addChild('title', $episode->title);
$enclosure = $item->addChild('enclosure');
$enclosure->addAttribute('url', $episode->enclosure_url);
$enclosure->addAttribute('length', $episode->enclosure_length);
$enclosure->addAttribute('type', $episode->enclosure_type);
$item->addChild('guid', $episode->guid);
$item->addChild('pubDate', $episode->pub_date->format(DATE_RFC1123));
$item->addChildWithCDATA('description', $episode->description);
$item->addChild('duration', $episode->duration, $itunes_namespace);
$item->addChild('link', $episode->link);
$episode_itunes_image = $item->addChild(
'image',
null,
$itunes_namespace
);
$episode_itunes_image->addAttribute('href', $episode->image_url);
$item->addChild(
'explicit',
$episode->explicit ? 'true' : 'false',
$itunes_namespace
);
if ($episode->author_email || $episode->author_name) {
$item->addChild(
'author',
$episode->author_name
? $episode->author_email .
' (' .
$episode->author_name .
')'
: $episode->author_email
);
}
$item->addChild('episode', $episode->number, $itunes_namespace);
$episode->season_number &&
$item->addChild(
'season',
$episode->season_number,
$itunes_namespace
);
$item->addChild('episodeType', $episode->type, $itunes_namespace);
$episode->block && $item->addChild('block', 'Yes', $itunes_namespace);
}
return $rss->asXML();
}
......@@ -16,23 +16,3 @@ function media_url($uri = '', string $protocol = null): string
{
return base_url(config('App')->mediaRoot . '/' . $uri, $protocol);
}
/**
* Return the podcast URL to use in views
*
* @param mixed $uri URI string or array of URI segments
* @param string $protocol
* @return string
*/
function podcast_url(
$podcast_id = 1,
$episode_id = 1,
$podcast_name = '',
$uri = '',
string $protocol = null
): string {
return base_url(
"/stats/$podcast_id/$episode_id/$podcast_name/$uri",
$protocol
);
}
<?
return [
'back_to_podcast' => 'Go back to podcast',
'create' => 'Add an episode',
'form' => [
'file' => 'Audio file',
......@@ -10,6 +11,8 @@ return [
'pub_date' => 'Publication date',
'image' => 'Image',
'explicit' => 'Explicit',
'author_name' => 'Author name',
'author_email' => 'Author email',
'type' => [
'label' => 'Type',
'full' => 'Full',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment