2015-10-13 16:14:23 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class PodcastLimitReachedException extends Exception {}
|
|
|
|
|
|
|
|
class InvalidPodcastException extends Exception {}
|
|
|
|
|
|
|
|
class PodcastNotFoundException extends Exception {}
|
|
|
|
|
|
|
|
|
2015-10-14 16:58:13 +02:00
|
|
|
class Application_Service_PodcastService
|
2015-10-13 16:14:23 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
// These fields should never be modified with POST/PUT data
|
|
|
|
private static $privateFields = array(
|
|
|
|
"id",
|
|
|
|
"url",
|
|
|
|
"type",
|
|
|
|
"owner"
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* There is maximum of 50 podcasts allowed in the library - to limit
|
|
|
|
* resource consumption. This function returns true if the podcast
|
|
|
|
* limit has been reached.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2015-10-14 16:58:13 +02:00
|
|
|
public static function PodcastLimitReached()
|
2015-10-13 16:14:23 +02:00
|
|
|
{
|
2015-10-14 16:58:13 +02:00
|
|
|
if (PodcastQuery::create()->count() >= 50) {
|
2015-10-13 16:14:23 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns parsed rss feed, or false if the given URL cannot be downloaded
|
|
|
|
*
|
2015-10-15 20:44:17 +02:00
|
|
|
* @param string $feedUrl String containing the podcast feed URL
|
2015-10-13 16:14:23 +02:00
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public static function getPodcastFeed($feedUrl)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$feed = new SimplePie();
|
|
|
|
$feed->set_feed_url($feedUrl);
|
|
|
|
$feed->enable_cache(false);
|
|
|
|
$feed->init();
|
|
|
|
return $feed;
|
|
|
|
} catch (Exception $e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Creates a Podcast object from the given podcast URL.
|
|
|
|
* This is used by our Podcast REST API
|
|
|
|
*
|
2015-10-15 20:44:17 +02:00
|
|
|
* @param string $feedUrl Podcast RSS Feed Url
|
2015-10-13 16:14:23 +02:00
|
|
|
*
|
2015-10-15 20:44:17 +02:00
|
|
|
* @return array Podcast Array with a full list of episodes
|
2015-10-13 16:14:23 +02:00
|
|
|
* @throws Exception
|
|
|
|
* @throws InvalidPodcastException
|
|
|
|
* @throws PodcastLimitReachedException
|
|
|
|
*/
|
|
|
|
public static function createFromFeedUrl($feedUrl)
|
|
|
|
{
|
2015-10-14 16:58:13 +02:00
|
|
|
if (self::PodcastLimitReached()) {
|
2015-10-13 16:14:23 +02:00
|
|
|
throw new PodcastLimitReachedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO: why is this so slow?
|
|
|
|
$rss = self::getPodcastFeed($feedUrl);
|
2015-11-11 01:26:25 +01:00
|
|
|
if (!$rss || !empty($rss->error())) {
|
2015-10-13 16:14:23 +02:00
|
|
|
throw new InvalidPodcastException();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure we are only creating Podcast with the given URL, and excluding
|
|
|
|
// any extra data fields that may have been POSTED
|
|
|
|
$podcastArray = array();
|
|
|
|
$podcastArray["url"] = $feedUrl;
|
|
|
|
|
2015-10-19 17:54:53 +02:00
|
|
|
$podcastArray["title"] = htmlspecialchars($rss->get_title());
|
|
|
|
$podcastArray["description"] = htmlspecialchars($rss->get_description());
|
|
|
|
$podcastArray["link"] = htmlspecialchars($rss->get_link());
|
|
|
|
$podcastArray["language"] = htmlspecialchars($rss->get_language());
|
|
|
|
$podcastArray["copyright"] = htmlspecialchars($rss->get_copyright());
|
2015-11-10 00:17:49 +01:00
|
|
|
|
|
|
|
$name = empty($rss->get_author()) ? "" : $rss->get_author()->get_name();
|
|
|
|
$podcastArray["creator"] = htmlspecialchars($name);
|
|
|
|
|
|
|
|
$categories = array();
|
|
|
|
if (is_array($rss->get_categories())) {
|
|
|
|
foreach ($rss->get_categories() as $category) {
|
|
|
|
array_push($categories, $category->get_scheme() . ":" . $category->get_term());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$podcastArray["category"] = htmlspecialchars(implode($categories));
|
2015-10-13 16:14:23 +02:00
|
|
|
|
|
|
|
//TODO: put in constants
|
|
|
|
$itunesChannel = "http://www.itunes.com/dtds/podcast-1.0.dtd";
|
|
|
|
|
|
|
|
$itunesSubtitle = $rss->get_channel_tags($itunesChannel, 'subtitle');
|
|
|
|
$podcastArray["itunes_subtitle"] = isset($itunesSubtitle[0]["data"]) ? $itunesSubtitle[0]["data"] : "";
|
|
|
|
|
|
|
|
$itunesCategory = $rss->get_channel_tags($itunesChannel, 'category');
|
|
|
|
$categoryArray = array();
|
2015-11-10 00:17:49 +01:00
|
|
|
if (is_array($itunesCategory)) {
|
|
|
|
foreach ($itunesCategory as $c => $data) {
|
|
|
|
foreach ($data["attribs"] as $attrib) {
|
|
|
|
array_push($categoryArray, $attrib["text"]);
|
|
|
|
}
|
2015-10-13 16:14:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$podcastArray["itunes_category"] = implode(",", $categoryArray);
|
|
|
|
|
|
|
|
$itunesAuthor = $rss->get_channel_tags($itunesChannel, 'author');
|
|
|
|
$podcastArray["itunes_author"] = isset($itunesAuthor[0]["data"]) ? $itunesAuthor[0]["data"] : "";
|
|
|
|
|
|
|
|
$itunesSummary = $rss->get_channel_tags($itunesChannel, 'summary');
|
|
|
|
$podcastArray["itunes_summary"] = isset($itunesSummary[0]["data"]) ? $itunesSummary[0]["data"] : "";
|
|
|
|
|
|
|
|
$itunesKeywords = $rss->get_channel_tags($itunesChannel, 'keywords');
|
|
|
|
$podcastArray["itunes_keywords"] = isset($itunesKeywords[0]["data"]) ? $itunesKeywords[0]["data"] : "";
|
|
|
|
|
|
|
|
$itunesExplicit = $rss->get_channel_tags($itunesChannel, 'explicit');
|
|
|
|
$podcastArray["itunes_explicit"] = isset($itunesExplicit[0]["data"]) ? $itunesExplicit[0]["data"] : "";
|
|
|
|
|
|
|
|
self::validatePodcastMetadata($podcastArray);
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Base class
|
|
|
|
$podcast = new Podcast();
|
|
|
|
$podcast->fromArray($podcastArray, BasePeer::TYPE_FIELDNAME);
|
|
|
|
$podcast->setDbOwner(self::getOwnerId());
|
|
|
|
$podcast->save();
|
|
|
|
|
|
|
|
$importedPodcast = new ImportedPodcast();
|
|
|
|
$importedPodcast->fromArray($podcastArray, BasePeer::TYPE_FIELDNAME);
|
|
|
|
$importedPodcast->setPodcast($podcast);
|
2015-11-10 00:17:49 +01:00
|
|
|
$importedPodcast->setDbAutoIngest(true);
|
2015-10-13 16:14:23 +02:00
|
|
|
$importedPodcast->save();
|
|
|
|
|
2015-11-03 00:07:16 +01:00
|
|
|
return $podcast->toArray(BasePeer::TYPE_FIELDNAME);
|
2015-10-13 16:14:23 +02:00
|
|
|
} catch(Exception $e) {
|
|
|
|
$podcast->delete();
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-19 17:54:53 +02:00
|
|
|
public static function createStationPodcast()
|
|
|
|
{
|
|
|
|
$podcast = new Podcast();
|
2015-11-18 17:10:14 +01:00
|
|
|
$podcast->setDbUrl(Application_Common_HTTPHelper::getStationUrl() . "feeds/station-rss");
|
2015-10-19 17:54:53 +02:00
|
|
|
|
|
|
|
$title = Application_Model_Preference::GetStationName();
|
|
|
|
$title = empty($title) ? "My Station's Podcast" : $title;
|
|
|
|
$podcast->setDbTitle($title);
|
|
|
|
|
|
|
|
$podcast->setDbDescription(Application_Model_Preference::GetStationDescription());
|
2015-11-18 17:10:14 +01:00
|
|
|
$podcast->setDbLink(Application_Common_HTTPHelper::getStationUrl());
|
2015-11-17 18:26:21 +01:00
|
|
|
$podcast->setDbLanguage(explode('_', Application_Model_Preference::GetLocale())[0]);
|
2015-10-19 17:54:53 +02:00
|
|
|
$podcast->setDbCreator(Application_Model_Preference::GetStationName());
|
|
|
|
$podcast->setDbOwner(self::getOwnerId());
|
|
|
|
$podcast->save();
|
|
|
|
|
|
|
|
$stationPodcast = new StationPodcast();
|
|
|
|
$stationPodcast->setPodcast($podcast);
|
|
|
|
$stationPodcast->save();
|
|
|
|
|
|
|
|
Application_Model_Preference::setStationPodcastId($podcast->getDbId());
|
2015-10-21 01:03:34 +02:00
|
|
|
// Set the download key when we create the station podcast
|
|
|
|
// The value is randomly generated in the setter
|
|
|
|
Application_Model_Preference::setStationPodcastDownloadKey();
|
2015-11-03 22:23:17 +01:00
|
|
|
return $podcast->getDbId();
|
2015-10-19 17:54:53 +02:00
|
|
|
}
|
|
|
|
|
2015-10-13 16:14:23 +02:00
|
|
|
//TODO move this somewhere where it makes sense
|
|
|
|
private static function getOwnerId()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
if (Zend_Auth::getInstance()->hasIdentity()) {
|
|
|
|
$service_user = new Application_Service_UserService();
|
|
|
|
return $service_user->getCurrentUser()->getDbId();
|
|
|
|
} else {
|
|
|
|
$defaultOwner = CcSubjsQuery::create()
|
|
|
|
->filterByDbType('A')
|
|
|
|
->orderByDbId()
|
|
|
|
->findOne();
|
|
|
|
if (!$defaultOwner) {
|
|
|
|
// what to do if there is no admin user?
|
|
|
|
// should we handle this case?
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return $defaultOwner->getDbId();
|
|
|
|
}
|
|
|
|
} catch(Exception $e) {
|
|
|
|
Logging::info($e->getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Trims the podcast metadata to fit the table's column max size
|
|
|
|
*
|
|
|
|
* @param $podcastArray
|
|
|
|
*/
|
|
|
|
private static function validatePodcastMetadata(&$podcastArray)
|
|
|
|
{
|
|
|
|
$podcastTable = PodcastPeer::getTableMap();
|
|
|
|
|
|
|
|
foreach ($podcastArray as $key => &$value) {
|
|
|
|
try {
|
|
|
|
// Make sure column exists in table
|
|
|
|
$columnMaxSize = $podcastTable->getColumn($key)->getSize();
|
|
|
|
} catch (PropelException $e) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen($value) > $columnMaxSize) {
|
|
|
|
$value = substr($value, 0, $podcastTable->getColumn($key)->getSize());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-14 16:58:13 +02:00
|
|
|
/**
|
|
|
|
* Fetches a Podcast's rss feed and returns all its episodes with
|
|
|
|
* the Podcast object
|
|
|
|
*
|
|
|
|
* @param $podcastId
|
|
|
|
*
|
|
|
|
* @throws PodcastNotFoundException
|
|
|
|
* @throws InvalidPodcastException
|
|
|
|
* @return array - Podcast Array with a full list of episodes
|
|
|
|
*/
|
|
|
|
public static function getPodcastById($podcastId)
|
|
|
|
{
|
|
|
|
$podcast = PodcastQuery::create()->findPk($podcastId);
|
|
|
|
if (!$podcast) {
|
|
|
|
throw new PodcastNotFoundException();
|
|
|
|
}
|
|
|
|
|
2015-11-03 23:13:38 +01:00
|
|
|
$podcast = $podcast->toArray(BasePeer::TYPE_FIELDNAME);
|
|
|
|
$podcast["itunes_explicit"] = ($podcast["itunes_explicit"] == "yes") ? true : false;
|
|
|
|
return $podcast;
|
2015-10-14 16:58:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes a Podcast and its podcast episodes
|
|
|
|
*
|
|
|
|
* @param $podcastId
|
|
|
|
* @throws Exception
|
|
|
|
* @throws PodcastNotFoundException
|
|
|
|
*/
|
|
|
|
public static function deletePodcastById($podcastId)
|
|
|
|
{
|
|
|
|
$podcast = PodcastQuery::create()->findPk($podcastId);
|
|
|
|
if ($podcast) {
|
|
|
|
$podcast->delete();
|
2015-10-19 17:54:53 +02:00
|
|
|
|
2015-11-03 22:23:17 +01:00
|
|
|
// FIXME: I don't think we should be able to delete the station podcast...
|
2015-10-19 17:54:53 +02:00
|
|
|
if ($podcastId == Application_Model_Preference::getStationPodcastId()) {
|
|
|
|
Application_Model_Preference::setStationPodcastId(null);
|
|
|
|
}
|
2015-10-14 16:58:13 +02:00
|
|
|
} else {
|
|
|
|
throw new PodcastNotFoundException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-22 18:12:41 +02:00
|
|
|
/**
|
|
|
|
* Build a response with podcast data and embedded HTML to load on the frontend
|
|
|
|
*
|
|
|
|
* @param int $podcastId ID of the podcast to build a response for
|
|
|
|
* @param Zend_View_Interface $view Zend view object to render the response HTML
|
|
|
|
*
|
|
|
|
* @return array the response array containing the podcast data and editor HTML
|
|
|
|
*
|
|
|
|
* @throws PodcastNotFoundException
|
|
|
|
*/
|
|
|
|
public static function buildPodcastEditorResponse($podcastId, $view) {
|
|
|
|
// Check the StationPodcast table rather than checking
|
|
|
|
// the station podcast ID key in preferences for extensibility
|
|
|
|
$podcast = StationPodcastQuery::create()->findOneByDbPodcastId($podcastId);
|
2015-11-13 20:57:32 +01:00
|
|
|
$path = $podcast ? 'podcast/station.phtml' : 'podcast/podcast.phtml';
|
2015-10-22 18:12:41 +02:00
|
|
|
$podcast = Application_Service_PodcastService::getPodcastById($podcastId);
|
|
|
|
return array(
|
|
|
|
"podcast" => json_encode($podcast),
|
|
|
|
"html" => $view->render($path),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-10-14 16:58:13 +02:00
|
|
|
/**
|
|
|
|
* Updates a Podcast object with the given metadata
|
|
|
|
*
|
|
|
|
* @param $podcastId
|
|
|
|
* @param $data
|
|
|
|
* @return array
|
|
|
|
* @throws Exception
|
|
|
|
* @throws PodcastNotFoundException
|
|
|
|
*/
|
|
|
|
public static function updatePodcastFromArray($podcastId, $data)
|
|
|
|
{
|
|
|
|
$podcast = PodcastQuery::create()->findPk($podcastId);
|
|
|
|
if (!$podcast) {
|
|
|
|
throw new PodcastNotFoundException();
|
|
|
|
}
|
|
|
|
|
2015-10-15 14:06:01 +02:00
|
|
|
self::removePrivateFields($data["podcast"]);
|
|
|
|
self::validatePodcastMetadata($data["podcast"]);
|
2015-10-22 01:21:52 +02:00
|
|
|
if (array_key_exists("auto_ingest", $data["podcast"])) {
|
|
|
|
self::_updateAutoIngestTimestamp($podcast, $data);
|
|
|
|
}
|
2015-10-14 16:58:13 +02:00
|
|
|
|
2015-11-03 23:13:38 +01:00
|
|
|
$data["podcast"]["itunes_explicit"] = $data["podcast"]["itunes_explicit"] ? "yes" : "clean";
|
2015-10-15 14:06:01 +02:00
|
|
|
$podcast->fromArray($data["podcast"], BasePeer::TYPE_FIELDNAME);
|
|
|
|
$podcast->save();
|
2015-10-14 16:58:13 +02:00
|
|
|
|
|
|
|
return $podcast->toArray(BasePeer::TYPE_FIELDNAME);
|
|
|
|
}
|
|
|
|
|
2015-10-21 17:18:33 +02:00
|
|
|
/**
|
|
|
|
* Update the automatic ingestion timestamp for the given Podcast
|
|
|
|
*
|
|
|
|
* @param Podcast $podcast Podcast object to update
|
|
|
|
* @param array $data Podcast update data array
|
|
|
|
*/
|
|
|
|
private static function _updateAutoIngestTimestamp($podcast, $data) {
|
|
|
|
// Get podcast data with lazy loaded columns since we can't directly call getDbAutoIngest()
|
|
|
|
$currData = $podcast->toArray(BasePeer::TYPE_FIELDNAME, true);
|
|
|
|
// Add an auto-ingest timestamp when turning auto-ingest on
|
|
|
|
if ($data["podcast"]["auto_ingest"] == 1 && $currData["auto_ingest"] != 1) {
|
|
|
|
$data["podcast"]["auto_ingest_timestamp"] = gmdate('r');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-14 16:58:13 +02:00
|
|
|
private static function removePrivateFields(&$data)
|
|
|
|
{
|
|
|
|
foreach (self::$privateFields as $key) {
|
|
|
|
unset($data[$key]);
|
|
|
|
}
|
|
|
|
}
|
2015-10-19 17:54:53 +02:00
|
|
|
|
2015-11-04 23:08:25 +01:00
|
|
|
private static function addEscapedChild($node, $name, $value = null, $namespace = null) {
|
2015-11-11 22:47:07 +01:00
|
|
|
if (empty($value)) {
|
|
|
|
return null;
|
|
|
|
}
|
2015-11-04 23:08:25 +01:00
|
|
|
$child = $node->addChild($name, null, $namespace);
|
|
|
|
$child->{0} = $value;
|
|
|
|
return $child;
|
|
|
|
}
|
|
|
|
|
2015-10-19 17:54:53 +02:00
|
|
|
public static function createStationRssFeed()
|
|
|
|
{
|
|
|
|
$stationPodcastId = Application_Model_Preference::getStationPodcastId();
|
|
|
|
|
|
|
|
try {
|
|
|
|
$podcast = PodcastQuery::create()->findPk($stationPodcastId);
|
|
|
|
if (!$podcast) {
|
|
|
|
throw new PodcastNotFoundException();
|
|
|
|
}
|
|
|
|
|
|
|
|
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"/>');
|
|
|
|
|
|
|
|
$channel = $xml->addChild("channel");
|
2015-11-04 23:08:25 +01:00
|
|
|
self::addEscapedChild($channel, "title", $podcast->getDbTitle());
|
|
|
|
self::addEscapedChild($channel, "link", $podcast->getDbLink());
|
|
|
|
self::addEscapedChild($channel, "description", $podcast->getDbDescription());
|
|
|
|
self::addEscapedChild($channel, "language", $podcast->getDbLanguage());
|
|
|
|
self::addEscapedChild($channel, "copyright", $podcast->getDbCopyright());
|
2015-10-19 17:54:53 +02:00
|
|
|
|
2015-11-18 01:33:36 +01:00
|
|
|
$xml->addAttribute('xmlns:xmlns:atom', "http://www.w3.org/2005/Atom");
|
|
|
|
|
|
|
|
$atomLink = $channel->addChild("xmlns:atom:link");
|
2015-11-18 17:10:14 +01:00
|
|
|
$atomLink->addAttribute("href", Application_Common_HTTPHelper::getStationUrl() . "feeds/station-rss");
|
2015-11-18 01:33:36 +01:00
|
|
|
$atomLink->addAttribute("rel", "self");
|
|
|
|
$atomLink->addAttribute("type", "application/rss+xml");
|
|
|
|
|
2015-11-18 17:10:14 +01:00
|
|
|
$imageUrl = Application_Common_HTTPHelper::getStationUrl()."api/station-logo";
|
2015-10-19 17:54:53 +02:00
|
|
|
$image = $channel->addChild("image");
|
2015-11-18 01:28:52 +01:00
|
|
|
$image->addChild("title", $podcast->getDbTitle());
|
2015-11-04 23:08:25 +01:00
|
|
|
self::addEscapedChild($image, "url", $imageUrl);
|
2015-11-18 17:10:14 +01:00
|
|
|
self::addEscapedChild($image, "link", Application_Common_HTTPHelper::getStationUrl());
|
2015-10-19 17:54:53 +02:00
|
|
|
|
|
|
|
$xml->addAttribute('xmlns:xmlns:itunes', ITUNES_XML_NAMESPACE_URL);
|
2015-11-04 23:08:25 +01:00
|
|
|
self::addEscapedChild($channel, "xmlns:itunes:author", $podcast->getDbItunesAuthor());
|
|
|
|
self::addEscapedChild($channel, "xmlns:itunes:keywords", $podcast->getDbItunesKeywords());
|
|
|
|
self::addEscapedChild($channel, "xmlns:itunes:summary", $podcast->getDbItunesSummary());
|
|
|
|
self::addEscapedChild($channel, "xmlns:itunes:subtitle", $podcast->getDbItunesSubtitle());
|
|
|
|
self::addEscapedChild($channel, "xmlns:itunes:explicit", $podcast->getDbItunesExplicit());
|
2015-11-18 02:12:22 +01:00
|
|
|
$owner = $channel->addChild("xmlns:itunes:owner");
|
|
|
|
self::addEscapedChild($owner, "xmlns:itunes:name", Application_Model_Preference::GetStationName());
|
|
|
|
self::addEscapedChild($owner, "xmlns:itunes:email", Application_Model_Preference::GetEmail());
|
2015-10-19 17:54:53 +02:00
|
|
|
|
|
|
|
$itunesImage = $channel->addChild("xmlns:itunes:image");
|
|
|
|
$itunesImage->addAttribute("href", $imageUrl);
|
|
|
|
|
|
|
|
// Need to split categories into separate tags
|
|
|
|
$itunesCategories = explode(",", $podcast->getDbItunesCategory());
|
|
|
|
foreach ($itunesCategories as $c) {
|
2015-11-17 18:35:31 +01:00
|
|
|
if (!empty($c)) {
|
|
|
|
$category = $channel->addChild("xmlns:itunes:category");
|
|
|
|
$category->addAttribute("text", $c);
|
|
|
|
}
|
2015-10-19 17:54:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$episodes = PodcastEpisodesQuery::create()->filterByDbPodcastId($stationPodcastId)->find();
|
|
|
|
foreach ($episodes as $episode) {
|
|
|
|
$item = $channel->addChild("item");
|
|
|
|
$publishedFile = CcFilesQuery::create()->findPk($episode->getDbFileId());
|
|
|
|
|
|
|
|
//title
|
2015-11-04 23:08:25 +01:00
|
|
|
self::addEscapedChild($item, "title", $publishedFile->getDbTrackTitle());
|
2015-10-19 17:54:53 +02:00
|
|
|
|
|
|
|
//link - do we need this?
|
|
|
|
|
|
|
|
//pubDate
|
2015-11-11 22:47:07 +01:00
|
|
|
self::addEscapedChild($item, "pubDate", gmdate(DATE_RFC2822, strtotime($episode->getDbPublicationDate())));
|
2015-10-19 17:54:53 +02:00
|
|
|
|
|
|
|
//category
|
|
|
|
foreach($itunesCategories as $c) {
|
2015-11-17 18:26:21 +01:00
|
|
|
if (!empty($c)) {
|
|
|
|
self::addEscapedChild($item, "category", $c);
|
|
|
|
}
|
2015-10-19 17:54:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//guid
|
2015-11-04 23:08:25 +01:00
|
|
|
$guid = self::addEscapedChild($item, "guid", $episode->getDbEpisodeGuid());
|
2015-10-19 17:54:53 +02:00
|
|
|
$guid->addAttribute("isPermaLink", "false");
|
|
|
|
|
|
|
|
//description
|
2015-11-04 23:08:25 +01:00
|
|
|
self::addEscapedChild($item, "description", $publishedFile->getDbDescription());
|
2015-10-19 17:54:53 +02:00
|
|
|
|
|
|
|
//encolsure - url, length, type attribs
|
|
|
|
$enclosure = $item->addChild("enclosure");
|
|
|
|
$enclosure->addAttribute("url", $episode->getDbDownloadUrl());
|
2015-11-11 22:47:07 +01:00
|
|
|
$enclosure->addAttribute("length", $publishedFile->getDbFilesize());
|
2015-10-19 17:54:53 +02:00
|
|
|
$enclosure->addAttribute("type", $publishedFile->getDbMime());
|
|
|
|
|
|
|
|
//itunes:subtitle
|
2015-11-04 23:08:25 +01:00
|
|
|
// From http://www.apple.com/ca/itunes/podcasts/specs.html#subtitle :
|
|
|
|
// 'The contents of the <itunes:subtitle> tag are displayed in the Description column in iTunes.'
|
|
|
|
// self::addEscapedChild($item, "xmlns:itunes:subtitle", $publishedFile->getDbTrackTitle());
|
|
|
|
self::addEscapedChild($item, "xmlns:itunes:subtitle", $publishedFile->getDbDescription());
|
2015-10-19 17:54:53 +02:00
|
|
|
|
|
|
|
//itunes:summary
|
2015-11-04 23:08:25 +01:00
|
|
|
self::addEscapedChild($item, "xmlns:itunes:summary", $publishedFile->getDbDescription());
|
2015-10-19 17:54:53 +02:00
|
|
|
|
|
|
|
//itunes:author
|
2015-11-04 23:08:25 +01:00
|
|
|
self::addEscapedChild($item, "xmlns:itunes:author", $publishedFile->getDbArtistName());
|
2015-10-19 17:54:53 +02:00
|
|
|
|
|
|
|
//itunes:explicit - skip this?
|
|
|
|
|
|
|
|
//itunes:duration
|
2015-11-17 17:53:02 +01:00
|
|
|
self::addEscapedChild($item, "xmlns:itunes:duration", explode('.', $publishedFile->getDbLength())[0]);
|
2015-10-19 17:54:53 +02:00
|
|
|
}
|
|
|
|
|
2015-11-17 22:18:38 +01:00
|
|
|
//Format it nicely with newlines...
|
|
|
|
$dom = new DOMDocument();
|
|
|
|
$dom->loadXML($xml->asXML());
|
|
|
|
$dom->formatOutput = true;
|
|
|
|
$formattedXML = $dom->saveXML();
|
|
|
|
|
|
|
|
return $formattedXML;
|
2015-10-19 17:54:53 +02:00
|
|
|
|
|
|
|
} catch (FeedException $e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-10-13 16:14:23 +02:00
|
|
|
}
|