2020-05-31 19:15:52 +00:00
|
|
|
<?php
|
2020-08-04 11:25:22 +00:00
|
|
|
|
2020-06-10 15:00:12 +00:00
|
|
|
/**
|
|
|
|
* @copyright 2020 Podlibre
|
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
2020-05-31 19:15:52 +00:00
|
|
|
|
|
|
|
namespace App\Entities;
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
use App\Libraries\Image;
|
|
|
|
use App\Libraries\SimpleRSSElement;
|
2020-09-04 09:09:26 +00:00
|
|
|
use App\Models\CategoryModel;
|
2020-06-26 14:34:52 +00:00
|
|
|
use App\Models\EpisodeModel;
|
2020-09-04 09:09:26 +00:00
|
|
|
use App\Models\PlatformModel;
|
2021-02-10 16:20:01 +00:00
|
|
|
use App\Models\PodcastPersonModel;
|
2021-05-06 14:00:48 +00:00
|
|
|
use CodeIgniter\Entity\Entity;
|
2020-07-31 16:05:10 +00:00
|
|
|
use App\Models\UserModel;
|
2021-05-06 14:00:48 +00:00
|
|
|
use CodeIgniter\Files\File;
|
|
|
|
use CodeIgniter\HTTP\Files\UploadedFile;
|
2020-08-04 11:25:22 +00:00
|
|
|
use League\CommonMark\CommonMarkConverter;
|
2021-05-06 14:00:48 +00:00
|
|
|
use RuntimeException;
|
2020-05-31 19:15:52 +00:00
|
|
|
|
|
|
|
class Podcast extends Entity
|
|
|
|
{
|
2020-08-05 17:26:04 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $link;
|
|
|
|
|
|
|
|
/**
|
2021-05-06 14:00:48 +00:00
|
|
|
* @var Actor
|
2021-04-02 17:20:02 +00:00
|
|
|
*/
|
|
|
|
protected $actor;
|
|
|
|
|
|
|
|
/**
|
2021-05-06 14:00:48 +00:00
|
|
|
* @var Image
|
2020-08-05 17:26:04 +00:00
|
|
|
*/
|
|
|
|
protected $image;
|
|
|
|
|
|
|
|
/**
|
2021-05-06 14:00:48 +00:00
|
|
|
* @var Episode[]
|
2020-08-05 17:26:04 +00:00
|
|
|
*/
|
2020-06-26 14:34:52 +00:00
|
|
|
protected $episodes;
|
2020-08-05 17:26:04 +00:00
|
|
|
|
2021-02-10 16:20:01 +00:00
|
|
|
/**
|
2021-05-06 14:00:48 +00:00
|
|
|
* @var PodcastPerson[]
|
2021-02-10 16:20:01 +00:00
|
|
|
*/
|
2021-04-02 17:20:02 +00:00
|
|
|
protected $persons;
|
2021-02-10 16:20:01 +00:00
|
|
|
|
2020-09-04 09:09:26 +00:00
|
|
|
/**
|
2021-05-06 14:00:48 +00:00
|
|
|
* @var Category
|
2020-09-04 09:09:26 +00:00
|
|
|
*/
|
|
|
|
protected $category;
|
|
|
|
|
2020-10-02 15:38:16 +00:00
|
|
|
/**
|
2021-05-06 14:00:48 +00:00
|
|
|
* @var Category[]
|
2020-10-02 15:38:16 +00:00
|
|
|
*/
|
|
|
|
protected $other_categories;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var integer[]
|
|
|
|
*/
|
|
|
|
protected $other_categories_ids;
|
|
|
|
|
2020-08-05 17:26:04 +00:00
|
|
|
/**
|
2021-05-06 14:00:48 +00:00
|
|
|
* @var User[]
|
2020-08-05 17:26:04 +00:00
|
|
|
*/
|
2020-07-16 10:08:23 +00:00
|
|
|
protected $contributors;
|
2020-08-05 17:26:04 +00:00
|
|
|
|
|
|
|
/**
|
2021-05-06 14:00:48 +00:00
|
|
|
* @var Platform
|
2020-08-05 17:26:04 +00:00
|
|
|
*/
|
2020-11-18 17:17:56 +00:00
|
|
|
protected $podcastingPlatforms;
|
|
|
|
|
|
|
|
/**
|
2021-05-06 14:00:48 +00:00
|
|
|
* @var Platform
|
2020-11-18 17:17:56 +00:00
|
|
|
*/
|
|
|
|
protected $socialPlatforms;
|
|
|
|
|
|
|
|
/**
|
2021-05-06 14:00:48 +00:00
|
|
|
* @var Platform
|
2020-11-18 17:17:56 +00:00
|
|
|
*/
|
|
|
|
protected $fundingPlatforms;
|
2020-06-26 14:34:52 +00:00
|
|
|
|
2020-09-04 09:09:26 +00:00
|
|
|
/**
|
2020-10-29 15:45:19 +00:00
|
|
|
* Holds text only description, striped of any markdown or html special characters
|
|
|
|
*
|
|
|
|
* @var string
|
2020-09-04 09:09:26 +00:00
|
|
|
*/
|
2020-10-29 15:45:19 +00:00
|
|
|
protected $description;
|
2020-09-04 09:09:26 +00:00
|
|
|
|
2021-03-19 16:12:36 +00:00
|
|
|
/**
|
|
|
|
* Return custom rss as string
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $custom_rss_string;
|
|
|
|
|
2020-05-31 19:15:52 +00:00
|
|
|
protected $casts = [
|
2020-06-12 19:31:10 +00:00
|
|
|
'id' => 'integer',
|
2021-04-02 17:20:02 +00:00
|
|
|
'actor_id' => 'integer',
|
2020-05-31 19:15:52 +00:00
|
|
|
'name' => 'string',
|
2021-04-02 17:20:02 +00:00
|
|
|
'title' => 'string',
|
2020-10-29 15:45:19 +00:00
|
|
|
'description_markdown' => 'string',
|
|
|
|
'description_html' => 'string',
|
2021-05-03 17:39:58 +00:00
|
|
|
'image_path' => 'string',
|
2021-04-02 17:20:02 +00:00
|
|
|
'image_mimetype' => 'string',
|
2020-10-29 15:45:19 +00:00
|
|
|
'language_code' => 'string',
|
2020-08-21 08:41:09 +00:00
|
|
|
'category_id' => 'integer',
|
2020-10-02 15:38:16 +00:00
|
|
|
'parental_advisory' => '?string',
|
|
|
|
'publisher' => '?string',
|
2020-10-29 15:45:19 +00:00
|
|
|
'owner_name' => 'string',
|
|
|
|
'owner_email' => 'string',
|
2020-06-26 14:34:52 +00:00
|
|
|
'type' => 'string',
|
2020-05-31 19:15:52 +00:00
|
|
|
'copyright' => '?string',
|
2020-10-29 15:45:19 +00:00
|
|
|
'episode_description_footer_markdown' => '?string',
|
|
|
|
'episode_description_footer_html' => '?string',
|
|
|
|
'is_blocked' => 'boolean',
|
|
|
|
'is_completed' => 'boolean',
|
|
|
|
'is_locked' => 'boolean',
|
2020-08-21 08:41:09 +00:00
|
|
|
'imported_feed_url' => '?string',
|
2020-10-06 15:39:27 +00:00
|
|
|
'new_feed_url' => '?string',
|
2020-12-23 14:11:38 +00:00
|
|
|
'location_name' => '?string',
|
|
|
|
'location_geo' => '?string',
|
|
|
|
'location_osmid' => '?string',
|
2020-11-26 18:53:52 +00:00
|
|
|
'payment_pointer' => '?string',
|
2021-03-19 16:12:36 +00:00
|
|
|
'custom_rss' => '?json-array',
|
2021-03-30 16:21:00 +00:00
|
|
|
'partner_id' => '?string',
|
|
|
|
'partner_link_url' => '?string',
|
|
|
|
'partner_image_url' => '?string',
|
2020-10-20 13:46:00 +00:00
|
|
|
'created_by' => 'integer',
|
|
|
|
'updated_by' => 'integer',
|
2020-05-31 19:15:52 +00:00
|
|
|
];
|
2020-06-26 14:34:52 +00:00
|
|
|
|
2021-04-02 17:20:02 +00:00
|
|
|
/**
|
|
|
|
* Returns the podcast actor
|
|
|
|
*
|
2021-05-06 14:00:48 +00:00
|
|
|
* @return Actor
|
2021-04-02 17:20:02 +00:00
|
|
|
*/
|
2021-05-06 14:00:48 +00:00
|
|
|
public function getActor(): Actor
|
2021-04-02 17:20:02 +00:00
|
|
|
{
|
|
|
|
if (!$this->attributes['actor_id']) {
|
2021-05-06 14:00:48 +00:00
|
|
|
throw new RuntimeException(
|
2021-04-02 17:20:02 +00:00
|
|
|
'Podcast must have an actor_id before getting actor.',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($this->actor)) {
|
2021-04-22 17:20:28 +00:00
|
|
|
$this->actor = model('ActorModel')->getActorById($this->actor_id);
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->actor;
|
|
|
|
}
|
|
|
|
|
2020-08-21 08:41:09 +00:00
|
|
|
/**
|
|
|
|
* Saves a cover image to the corresponding podcast folder in `public/media/podcast_name/`
|
|
|
|
*
|
2021-05-06 14:00:48 +00:00
|
|
|
* @param UploadedFile|File $image
|
2020-08-21 08:41:09 +00:00
|
|
|
*/
|
2021-05-06 14:00:48 +00:00
|
|
|
public function setImage($image = null): self
|
2020-06-30 18:17:41 +02:00
|
|
|
{
|
|
|
|
if ($image) {
|
|
|
|
helper('media');
|
|
|
|
|
2021-04-02 17:20:02 +00:00
|
|
|
$this->attributes['image_mimetype'] = $image->getMimeType();
|
2021-05-03 17:39:58 +00:00
|
|
|
$this->attributes['image_path'] = save_media(
|
2020-06-30 18:17:41 +02:00
|
|
|
$image,
|
2021-04-02 17:20:02 +00:00
|
|
|
'podcasts/' . $this->attributes['name'],
|
|
|
|
'cover',
|
2020-06-30 18:17:41 +02:00
|
|
|
);
|
2021-04-02 17:20:02 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
$this->image = new Image(
|
2021-05-03 17:39:58 +00:00
|
|
|
$this->attributes['image_path'],
|
2021-04-02 17:20:02 +00:00
|
|
|
$this->attributes['image_mimetype'],
|
2020-09-08 11:45:17 +00:00
|
|
|
);
|
|
|
|
$this->image->saveSizes();
|
2020-06-30 18:17:41 +02:00
|
|
|
}
|
|
|
|
|
2020-09-08 11:45:17 +00:00
|
|
|
return $this;
|
2020-06-30 18:17:41 +02:00
|
|
|
}
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
public function getImage(): Image
|
2020-06-26 14:34:52 +00:00
|
|
|
{
|
2021-05-06 14:00:48 +00:00
|
|
|
return new Image(
|
2021-05-03 17:39:58 +00:00
|
|
|
$this->attributes['image_path'],
|
2021-04-02 17:20:02 +00:00
|
|
|
$this->attributes['image_mimetype'],
|
|
|
|
);
|
2020-06-26 14:34:52 +00:00
|
|
|
}
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
public function getLink(): string
|
2020-06-26 14:34:52 +00:00
|
|
|
{
|
2021-04-02 17:20:02 +00:00
|
|
|
return url_to('podcast-activity', $this->attributes['name']);
|
2020-06-26 14:34:52 +00:00
|
|
|
}
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
public function getFeedUrl(): string
|
2020-06-26 14:34:52 +00:00
|
|
|
{
|
2021-04-02 17:20:02 +00:00
|
|
|
return url_to('podcast_feed', $this->attributes['name']);
|
2020-06-26 14:34:52 +00:00
|
|
|
}
|
|
|
|
|
2020-07-10 12:20:25 +00:00
|
|
|
/**
|
|
|
|
* Returns the podcast's episodes
|
|
|
|
*
|
2021-05-06 14:00:48 +00:00
|
|
|
* @return Episode[]
|
2020-07-10 12:20:25 +00:00
|
|
|
*/
|
2021-05-06 14:00:48 +00:00
|
|
|
public function getEpisodes(): array
|
2020-06-26 14:34:52 +00:00
|
|
|
{
|
2020-07-10 12:20:25 +00:00
|
|
|
if (empty($this->id)) {
|
2021-05-06 14:00:48 +00:00
|
|
|
throw new RuntimeException(
|
2021-04-02 17:20:02 +00:00
|
|
|
'Podcast must be created before getting episodes.',
|
2020-07-10 12:20:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-07-16 10:08:23 +00:00
|
|
|
if (empty($this->episodes)) {
|
2020-07-10 12:20:25 +00:00
|
|
|
$this->episodes = (new EpisodeModel())->getPodcastEpisodes(
|
2020-09-04 09:09:26 +00:00
|
|
|
$this->id,
|
2021-04-02 17:20:02 +00:00
|
|
|
$this->type,
|
2020-07-10 12:20:25 +00:00
|
|
|
);
|
|
|
|
}
|
2020-06-26 14:34:52 +00:00
|
|
|
|
2020-07-10 12:20:25 +00:00
|
|
|
return $this->episodes;
|
2020-06-26 14:34:52 +00:00
|
|
|
}
|
2020-07-16 10:08:23 +00:00
|
|
|
|
2021-02-10 16:20:01 +00:00
|
|
|
/**
|
|
|
|
* Returns the podcast's persons
|
|
|
|
*
|
2021-05-06 14:00:48 +00:00
|
|
|
* @return PodcastPerson[]
|
2021-02-10 16:20:01 +00:00
|
|
|
*/
|
2021-05-06 14:00:48 +00:00
|
|
|
public function getPersons(): array
|
2021-02-10 16:20:01 +00:00
|
|
|
{
|
|
|
|
if (empty($this->id)) {
|
2021-05-06 14:00:48 +00:00
|
|
|
throw new RuntimeException(
|
2021-04-02 17:20:02 +00:00
|
|
|
'Podcast must be created before getting persons.',
|
2021-02-10 16:20:01 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-04-02 17:20:02 +00:00
|
|
|
if (empty($this->persons)) {
|
2021-04-20 13:43:38 +00:00
|
|
|
$this->persons = (new PodcastPersonModel())->getPodcastPersons(
|
2021-04-02 17:20:02 +00:00
|
|
|
$this->id,
|
2021-02-10 16:20:01 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-04-02 17:20:02 +00:00
|
|
|
return $this->persons;
|
2021-02-10 16:20:01 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 09:09:26 +00:00
|
|
|
/**
|
|
|
|
* Returns the podcast category entity
|
|
|
|
*
|
2021-05-06 14:00:48 +00:00
|
|
|
* @return Category
|
2020-09-04 09:09:26 +00:00
|
|
|
*/
|
2021-05-06 14:00:48 +00:00
|
|
|
public function getCategory(): Category
|
2020-09-04 09:09:26 +00:00
|
|
|
{
|
|
|
|
if (empty($this->id)) {
|
2021-05-06 14:00:48 +00:00
|
|
|
throw new RuntimeException(
|
2021-04-02 17:20:02 +00:00
|
|
|
'Podcast must be created before getting category.',
|
2020-09-04 09:09:26 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($this->category)) {
|
2021-04-22 17:20:28 +00:00
|
|
|
$this->category = (new CategoryModel())->getCategoryById(
|
|
|
|
$this->category_id,
|
|
|
|
);
|
2020-09-04 09:09:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->category;
|
|
|
|
}
|
|
|
|
|
2020-07-28 15:57:48 +00:00
|
|
|
/**
|
|
|
|
* Returns all podcast contributors
|
|
|
|
*
|
2021-05-06 14:00:48 +00:00
|
|
|
* @return User[]
|
2020-07-28 15:57:48 +00:00
|
|
|
*/
|
2021-05-06 14:00:48 +00:00
|
|
|
public function getContributors(): array
|
2020-07-16 10:08:23 +00:00
|
|
|
{
|
2020-07-31 16:05:10 +00:00
|
|
|
if (empty($this->id)) {
|
2021-05-06 14:00:48 +00:00
|
|
|
throw new RuntimeException(
|
2021-04-02 17:20:02 +00:00
|
|
|
'Podcasts must be created before getting contributors.',
|
2020-07-31 16:05:10 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($this->contributors)) {
|
|
|
|
$this->contributors = (new UserModel())->getPodcastContributors(
|
2021-04-02 17:20:02 +00:00
|
|
|
$this->id,
|
2020-07-31 16:05:10 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->contributors;
|
2020-07-16 10:08:23 +00:00
|
|
|
}
|
2020-07-28 15:57:48 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
public function setDescriptionMarkdown(string $descriptionMarkdown): self
|
2020-07-28 15:57:48 +00:00
|
|
|
{
|
2020-08-04 11:25:22 +00:00
|
|
|
$converter = new CommonMarkConverter([
|
|
|
|
'html_input' => 'strip',
|
|
|
|
'allow_unsafe_links' => false,
|
|
|
|
]);
|
2020-07-28 15:57:48 +00:00
|
|
|
|
2020-10-29 15:45:19 +00:00
|
|
|
$this->attributes['description_markdown'] = $descriptionMarkdown;
|
|
|
|
$this->attributes['description_html'] = $converter->convertToHtml(
|
2021-04-02 17:20:02 +00:00
|
|
|
$descriptionMarkdown,
|
2020-10-29 15:45:19 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setEpisodeDescriptionFooterMarkdown(
|
2021-05-06 14:00:48 +00:00
|
|
|
?string $episodeDescriptionFooterMarkdown = null
|
|
|
|
): self {
|
2020-10-29 15:45:19 +00:00
|
|
|
if ($episodeDescriptionFooterMarkdown) {
|
|
|
|
$converter = new CommonMarkConverter([
|
|
|
|
'html_input' => 'strip',
|
|
|
|
'allow_unsafe_links' => false,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->attributes[
|
|
|
|
'episode_description_footer_markdown'
|
|
|
|
] = $episodeDescriptionFooterMarkdown;
|
|
|
|
$this->attributes[
|
|
|
|
'episode_description_footer_html'
|
|
|
|
] = $converter->convertToHtml($episodeDescriptionFooterMarkdown);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
public function getDescription(): string
|
2020-10-29 15:45:19 +00:00
|
|
|
{
|
|
|
|
if ($this->description) {
|
|
|
|
return $this->description;
|
|
|
|
}
|
|
|
|
|
|
|
|
return trim(
|
|
|
|
preg_replace(
|
|
|
|
'/\s+/',
|
|
|
|
' ',
|
2021-04-02 17:20:02 +00:00
|
|
|
strip_tags($this->attributes['description_html']),
|
|
|
|
),
|
2020-10-29 15:45:19 +00:00
|
|
|
);
|
2020-07-28 15:57:48 +00:00
|
|
|
}
|
2020-08-14 18:27:57 +00:00
|
|
|
|
2020-09-04 09:09:26 +00:00
|
|
|
/**
|
2020-11-18 17:17:56 +00:00
|
|
|
* Returns the podcast's podcasting platform links
|
2020-09-04 09:09:26 +00:00
|
|
|
*
|
2021-05-06 14:00:48 +00:00
|
|
|
* @return Platform[]
|
2020-09-04 09:09:26 +00:00
|
|
|
*/
|
2021-05-06 14:00:48 +00:00
|
|
|
public function getPodcastingPlatforms(): array
|
2020-09-04 09:09:26 +00:00
|
|
|
{
|
|
|
|
if (empty($this->id)) {
|
2021-05-06 14:00:48 +00:00
|
|
|
throw new RuntimeException(
|
2021-04-02 17:20:02 +00:00
|
|
|
'Podcast must be created before getting podcasting platform links.',
|
2020-09-04 09:09:26 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-11-18 17:17:56 +00:00
|
|
|
if (empty($this->podcastingPlatforms)) {
|
|
|
|
$this->podcastingPlatforms = (new PlatformModel())->getPodcastPlatforms(
|
|
|
|
$this->id,
|
2021-04-02 17:20:02 +00:00
|
|
|
'podcasting',
|
2020-11-18 17:17:56 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->podcastingPlatforms;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the podcast's social platform links
|
|
|
|
*
|
2021-05-06 14:00:48 +00:00
|
|
|
* @return Platform[]
|
2020-11-18 17:17:56 +00:00
|
|
|
*/
|
2021-05-06 14:00:48 +00:00
|
|
|
public function getSocialPlatforms(): array
|
2020-11-18 17:17:56 +00:00
|
|
|
{
|
|
|
|
if (empty($this->id)) {
|
2021-05-06 14:00:48 +00:00
|
|
|
throw new RuntimeException(
|
2021-04-02 17:20:02 +00:00
|
|
|
'Podcast must be created before getting social platform links.',
|
2020-11-18 17:17:56 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($this->socialPlatforms)) {
|
|
|
|
$this->socialPlatforms = (new PlatformModel())->getPodcastPlatforms(
|
|
|
|
$this->id,
|
2021-04-02 17:20:02 +00:00
|
|
|
'social',
|
2020-11-18 17:17:56 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->socialPlatforms;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the podcast's funding platform links
|
|
|
|
*
|
2021-05-06 14:00:48 +00:00
|
|
|
* @return Platform[]
|
2020-11-18 17:17:56 +00:00
|
|
|
*/
|
2021-05-06 14:00:48 +00:00
|
|
|
public function getFundingPlatforms(): array
|
2020-11-18 17:17:56 +00:00
|
|
|
{
|
|
|
|
if (empty($this->id)) {
|
2021-05-06 14:00:48 +00:00
|
|
|
throw new RuntimeException(
|
2021-04-02 17:20:02 +00:00
|
|
|
'Podcast must be created before getting funding platform links.',
|
2020-11-18 17:17:56 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($this->fundingPlatforms)) {
|
|
|
|
$this->fundingPlatforms = (new PlatformModel())->getPodcastPlatforms(
|
|
|
|
$this->id,
|
2021-04-02 17:20:02 +00:00
|
|
|
'funding',
|
2020-09-04 09:09:26 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-11-18 17:17:56 +00:00
|
|
|
return $this->fundingPlatforms;
|
2020-09-04 09:09:26 +00:00
|
|
|
}
|
2020-10-02 15:38:16 +00:00
|
|
|
|
2021-02-27 21:21:26 +00:00
|
|
|
/**
|
2021-05-06 14:00:48 +00:00
|
|
|
* @return Category[]
|
2021-02-27 21:21:26 +00:00
|
|
|
*/
|
2021-05-06 14:00:48 +00:00
|
|
|
public function getOtherCategories(): array
|
2020-10-02 15:38:16 +00:00
|
|
|
{
|
|
|
|
if (empty($this->id)) {
|
2021-05-06 14:00:48 +00:00
|
|
|
throw new RuntimeException(
|
2021-04-02 17:20:02 +00:00
|
|
|
'Podcast must be created before getting other categories.',
|
2020-10-02 15:38:16 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($this->other_categories)) {
|
|
|
|
$this->other_categories = (new CategoryModel())->getPodcastCategories(
|
2021-04-02 17:20:02 +00:00
|
|
|
$this->id,
|
2020-10-02 15:38:16 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->other_categories;
|
|
|
|
}
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
/**
|
|
|
|
* @return array<int>
|
|
|
|
*/
|
|
|
|
public function getOtherCategoriesIds(): array
|
2020-10-02 15:38:16 +00:00
|
|
|
{
|
|
|
|
if (empty($this->other_categories_ids)) {
|
|
|
|
$this->other_categories_ids = array_column(
|
|
|
|
$this->getOtherCategories(),
|
2021-04-02 17:20:02 +00:00
|
|
|
'id',
|
2020-10-02 15:38:16 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->other_categories_ids;
|
|
|
|
}
|
2020-12-23 14:11:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves the location name and fetches OpenStreetMap info
|
|
|
|
*/
|
2021-05-06 14:00:48 +00:00
|
|
|
public function setLocation(?string $locationName = null): self
|
2020-12-23 14:11:38 +00:00
|
|
|
{
|
|
|
|
helper('location');
|
|
|
|
|
|
|
|
if (
|
|
|
|
$locationName &&
|
|
|
|
(empty($this->attributes['location_name']) ||
|
|
|
|
$this->attributes['location_name'] != $locationName)
|
|
|
|
) {
|
|
|
|
$this->attributes['location_name'] = $locationName;
|
|
|
|
if ($location = fetch_osm_location($locationName)) {
|
|
|
|
$this->attributes['location_geo'] = $location['geo'];
|
|
|
|
$this->attributes['location_osmid'] = $location['osmid'];
|
|
|
|
}
|
|
|
|
} elseif (empty($locationName)) {
|
|
|
|
$this->attributes['location_name'] = null;
|
|
|
|
$this->attributes['location_geo'] = null;
|
|
|
|
$this->attributes['location_osmid'] = null;
|
|
|
|
}
|
2021-05-06 14:00:48 +00:00
|
|
|
|
2020-12-23 14:11:38 +00:00
|
|
|
return $this;
|
|
|
|
}
|
2021-03-19 16:12:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get custom rss tag as XML String
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2021-05-06 14:00:48 +00:00
|
|
|
function getCustomRssString(): string
|
2021-03-19 16:12:36 +00:00
|
|
|
{
|
|
|
|
if (empty($this->attributes['custom_rss'])) {
|
|
|
|
return '';
|
|
|
|
}
|
2021-05-06 14:00:48 +00:00
|
|
|
|
|
|
|
helper('rss');
|
|
|
|
|
|
|
|
$xmlNode = (new SimpleRSSElement(
|
|
|
|
'<?xml version="1.0" encoding="utf-8"?><rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:podcast="https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0"/>',
|
|
|
|
))->addChild('channel');
|
|
|
|
array_to_rss(
|
|
|
|
[
|
|
|
|
'elements' => $this->custom_rss,
|
|
|
|
],
|
|
|
|
$xmlNode,
|
|
|
|
);
|
|
|
|
|
|
|
|
return str_replace(['<channel>', '</channel>'], '', $xmlNode->asXML());
|
2021-03-19 16:12:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves custom rss tag into json
|
|
|
|
*
|
|
|
|
* @param string $customRssString
|
|
|
|
*/
|
2021-05-06 14:00:48 +00:00
|
|
|
function setCustomRssString($customRssString): self
|
2021-03-19 16:12:36 +00:00
|
|
|
{
|
2021-05-06 14:00:48 +00:00
|
|
|
if (empty($customRssString)) {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2021-03-19 16:12:36 +00:00
|
|
|
helper('rss');
|
|
|
|
$customRssArray = rss_to_array(
|
|
|
|
simplexml_load_string(
|
|
|
|
'<?xml version="1.0" encoding="utf-8"?><rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:podcast="https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0"><channel>' .
|
|
|
|
$customRssString .
|
2021-04-02 17:20:02 +00:00
|
|
|
'</channel></rss>',
|
|
|
|
),
|
2021-03-19 16:12:36 +00:00
|
|
|
)['elements'][0];
|
2021-05-06 14:00:48 +00:00
|
|
|
|
2021-03-19 16:12:36 +00:00
|
|
|
if (array_key_exists('elements', $customRssArray)) {
|
|
|
|
$this->attributes['custom_rss'] = json_encode(
|
2021-04-02 17:20:02 +00:00
|
|
|
$customRssArray['elements'],
|
2021-03-19 16:12:36 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$this->attributes['custom_rss'] = null;
|
|
|
|
}
|
2021-05-06 14:00:48 +00:00
|
|
|
|
|
|
|
return $this;
|
2021-03-19 16:12:36 +00:00
|
|
|
}
|
2020-05-31 19:15:52 +00:00
|
|
|
}
|