2020-05-31 19:15:52 +00:00
|
|
|
<?php
|
2020-08-04 11:25:22 +00:00
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-06-10 15:00:12 +00:00
|
|
|
/**
|
2022-02-19 16:06:11 +00:00
|
|
|
* @copyright 2020 Ad Aures
|
2020-06-10 15:00:12 +00:00
|
|
|
* @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\SimpleRSSElement;
|
2022-01-04 15:40:27 +00:00
|
|
|
use App\Models\ActorModel;
|
2020-09-04 09:09:26 +00:00
|
|
|
use App\Models\CategoryModel;
|
2020-06-26 14:34:52 +00:00
|
|
|
use App\Models\EpisodeModel;
|
2021-05-14 17:59:35 +00:00
|
|
|
use App\Models\PersonModel;
|
2021-05-19 16:35:13 +00:00
|
|
|
use CodeIgniter\Entity\Entity;
|
2021-12-20 17:12:12 +00:00
|
|
|
use CodeIgniter\Files\File;
|
2021-12-17 17:14:37 +00:00
|
|
|
use CodeIgniter\HTTP\Files\UploadedFile;
|
2021-05-12 14:00:25 +00:00
|
|
|
use CodeIgniter\I18n\Time;
|
2022-10-15 11:22:08 +00:00
|
|
|
use CodeIgniter\Shield\Entities\User;
|
2023-06-13 16:05:02 +00:00
|
|
|
use Exception;
|
2022-02-02 17:01:19 +00:00
|
|
|
use League\CommonMark\Environment\Environment;
|
|
|
|
use League\CommonMark\Extension\Autolink\AutolinkExtension;
|
|
|
|
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
|
|
|
|
use League\CommonMark\Extension\DisallowedRawHtml\DisallowedRawHtmlExtension;
|
|
|
|
use League\CommonMark\Extension\SmartPunct\SmartPunctExtension;
|
|
|
|
use League\CommonMark\MarkdownConverter;
|
2022-10-15 11:22:08 +00:00
|
|
|
use Modules\Auth\Models\UserModel;
|
2023-03-16 13:00:05 +00:00
|
|
|
use Modules\Media\Entities\Image;
|
|
|
|
use Modules\Media\Models\MediaModel;
|
2024-04-24 14:47:05 +00:00
|
|
|
use Modules\Platforms\Entities\Platform;
|
|
|
|
use Modules\Platforms\Models\PlatformModel;
|
2022-09-28 15:02:09 +00:00
|
|
|
use Modules\PremiumPodcasts\Entities\Subscription;
|
|
|
|
use Modules\PremiumPodcasts\Models\SubscriptionModel;
|
2021-05-06 14:00:48 +00:00
|
|
|
use RuntimeException;
|
2020-05-31 19:15:52 +00:00
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
/**
|
|
|
|
* @property int $id
|
2021-06-21 11:58:43 +00:00
|
|
|
* @property string $guid
|
2021-05-12 14:00:25 +00:00
|
|
|
* @property int $actor_id
|
2021-05-14 17:59:35 +00:00
|
|
|
* @property Actor|null $actor
|
2021-07-26 13:10:46 +00:00
|
|
|
* @property string $handle
|
2023-06-21 16:17:11 +00:00
|
|
|
* @property string $at_handle
|
2021-05-12 14:00:25 +00:00
|
|
|
* @property string $link
|
|
|
|
* @property string $feed_url
|
|
|
|
* @property string $title
|
2021-05-17 17:11:23 +00:00
|
|
|
* @property string|null $description Holds text only description, striped of any markdown or html special characters
|
2021-05-12 14:00:25 +00:00
|
|
|
* @property string $description_markdown
|
|
|
|
* @property string $description_html
|
2021-12-14 16:41:10 +00:00
|
|
|
* @property int $cover_id
|
2023-05-09 07:47:54 +00:00
|
|
|
* @property ?Image $cover
|
2021-12-14 16:41:10 +00:00
|
|
|
* @property int|null $banner_id
|
2023-05-09 07:47:54 +00:00
|
|
|
* @property ?Image $banner
|
2021-05-12 14:00:25 +00:00
|
|
|
* @property string $language_code
|
|
|
|
* @property int $category_id
|
2021-05-14 17:59:35 +00:00
|
|
|
* @property Category|null $category
|
2021-05-12 14:00:25 +00:00
|
|
|
* @property int[] $other_categories_ids
|
|
|
|
* @property Category[] $other_categories
|
|
|
|
* @property string|null $parental_advisory
|
|
|
|
* @property string|null $publisher
|
|
|
|
* @property string $owner_name
|
|
|
|
* @property string $owner_email
|
2024-01-01 10:11:29 +00:00
|
|
|
* @property bool $is_owner_email_removed_from_feed
|
2021-05-12 14:00:25 +00:00
|
|
|
* @property string $type
|
2024-02-05 16:51:04 +00:00
|
|
|
* @property string $medium
|
2021-05-12 14:00:25 +00:00
|
|
|
* @property string|null $copyright
|
|
|
|
* @property string|null $episode_description_footer_markdown
|
|
|
|
* @property string|null $episode_description_footer_html
|
|
|
|
* @property bool $is_blocked
|
|
|
|
* @property bool $is_completed
|
|
|
|
* @property bool $is_locked
|
|
|
|
* @property string|null $imported_feed_url
|
|
|
|
* @property string|null $new_feed_url
|
2021-05-17 17:11:23 +00:00
|
|
|
* @property Location|null $location
|
2021-05-12 14:00:25 +00:00
|
|
|
* @property string|null $location_name
|
|
|
|
* @property string|null $location_geo
|
2021-05-17 17:11:23 +00:00
|
|
|
* @property string|null $location_osm
|
2021-05-12 14:00:25 +00:00
|
|
|
* @property string|null $payment_pointer
|
2025-01-08 11:11:19 +00:00
|
|
|
* @property array<string|int,mixed>|null $custom_rss
|
2024-01-23 13:19:53 +00:00
|
|
|
* @property bool $is_op3_enabled
|
|
|
|
* @property string $op3_url
|
2021-05-12 14:00:25 +00:00
|
|
|
* @property string $custom_rss_string
|
2022-03-15 16:47:35 +00:00
|
|
|
* @property bool $is_published_on_hubs
|
2021-05-12 14:00:25 +00:00
|
|
|
* @property string|null $partner_id
|
|
|
|
* @property string|null $partner_link_url
|
|
|
|
* @property string|null $partner_image_url
|
|
|
|
* @property int $created_by
|
|
|
|
* @property int $updated_by
|
2022-09-28 15:02:09 +00:00
|
|
|
* @property string $publication_status
|
|
|
|
* @property bool $is_premium_by_default
|
|
|
|
* @property bool $is_premium
|
|
|
|
* @property Time|null $published_at
|
|
|
|
* @property Time $created_at
|
|
|
|
* @property Time $updated_at
|
2021-05-12 14:00:25 +00:00
|
|
|
*
|
|
|
|
* @property Episode[] $episodes
|
2021-05-14 17:59:35 +00:00
|
|
|
* @property Person[] $persons
|
2021-05-12 14:00:25 +00:00
|
|
|
* @property User[] $contributors
|
2022-09-28 15:02:09 +00:00
|
|
|
* @property Subscription[] $subscriptions
|
2021-05-12 14:00:25 +00:00
|
|
|
* @property Platform[] $podcasting_platforms
|
|
|
|
* @property Platform[] $social_platforms
|
|
|
|
* @property Platform[] $funding_platforms
|
|
|
|
*/
|
2020-05-31 19:15:52 +00:00
|
|
|
class Podcast extends Entity
|
|
|
|
{
|
2021-05-14 17:59:35 +00:00
|
|
|
protected string $link;
|
2021-05-19 16:35:13 +00:00
|
|
|
|
2022-10-15 11:22:08 +00:00
|
|
|
protected string $at_handle;
|
|
|
|
|
2021-05-17 17:11:23 +00:00
|
|
|
protected ?Actor $actor = null;
|
2021-05-19 16:35:13 +00:00
|
|
|
|
2021-12-14 16:41:10 +00:00
|
|
|
protected ?Image $cover = null;
|
2021-11-01 17:12:03 +00:00
|
|
|
|
2021-12-14 16:41:10 +00:00
|
|
|
protected ?Image $banner = null;
|
2021-05-19 16:35:13 +00:00
|
|
|
|
2021-05-17 17:11:23 +00:00
|
|
|
protected ?string $description = null;
|
2021-05-19 16:35:13 +00:00
|
|
|
|
2021-05-17 17:11:23 +00:00
|
|
|
protected ?Category $category = null;
|
2020-09-04 09:09:26 +00:00
|
|
|
|
2020-10-02 15:38:16 +00:00
|
|
|
/**
|
2021-05-18 17:16:36 +00:00
|
|
|
* @var Category[]|null
|
2020-10-02 15:38:16 +00:00
|
|
|
*/
|
2021-05-18 17:16:36 +00:00
|
|
|
protected ?array $other_categories = null;
|
2020-10-02 15:38:16 +00:00
|
|
|
|
|
|
|
/**
|
2021-05-18 17:16:36 +00:00
|
|
|
* @var string[]|null
|
2020-10-02 15:38:16 +00:00
|
|
|
*/
|
2021-05-18 17:16:36 +00:00
|
|
|
protected ?array $other_categories_ids = null;
|
2020-10-02 15:38:16 +00:00
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
/**
|
2021-05-18 17:16:36 +00:00
|
|
|
* @var Episode[]|null
|
2021-05-12 14:00:25 +00:00
|
|
|
*/
|
2021-05-18 17:16:36 +00:00
|
|
|
protected ?array $episodes = null;
|
2021-05-12 14:00:25 +00:00
|
|
|
|
|
|
|
/**
|
2021-05-18 17:16:36 +00:00
|
|
|
* @var Person[]|null
|
2021-05-12 14:00:25 +00:00
|
|
|
*/
|
2021-05-18 17:16:36 +00:00
|
|
|
protected ?array $persons = null;
|
2021-05-12 14:00:25 +00:00
|
|
|
|
2020-08-05 17:26:04 +00:00
|
|
|
/**
|
2021-05-18 17:16:36 +00:00
|
|
|
* @var User[]|null
|
2020-08-05 17:26:04 +00:00
|
|
|
*/
|
2021-05-18 17:16:36 +00:00
|
|
|
protected ?array $contributors = null;
|
2020-08-05 17:26:04 +00:00
|
|
|
|
2022-09-28 15:02:09 +00:00
|
|
|
/**
|
|
|
|
* @var Subscription[]|null
|
|
|
|
*/
|
|
|
|
protected ?array $subscriptions = null;
|
|
|
|
|
2020-08-05 17:26:04 +00:00
|
|
|
/**
|
2021-05-18 17:16:36 +00:00
|
|
|
* @var Platform[]|null
|
2020-08-05 17:26:04 +00:00
|
|
|
*/
|
2021-05-18 17:16:36 +00:00
|
|
|
protected ?array $podcasting_platforms = null;
|
2020-11-18 17:17:56 +00:00
|
|
|
|
|
|
|
/**
|
2021-05-18 17:16:36 +00:00
|
|
|
* @var Platform[]|null
|
2020-11-18 17:17:56 +00:00
|
|
|
*/
|
2021-05-18 17:16:36 +00:00
|
|
|
protected ?array $social_platforms = null;
|
2020-11-18 17:17:56 +00:00
|
|
|
|
|
|
|
/**
|
2021-05-18 17:16:36 +00:00
|
|
|
* @var Platform[]|null
|
2020-11-18 17:17:56 +00:00
|
|
|
*/
|
2021-05-18 17:16:36 +00:00
|
|
|
protected ?array $funding_platforms = null;
|
2020-06-26 14:34:52 +00:00
|
|
|
|
2021-05-17 17:11:23 +00:00
|
|
|
protected ?Location $location = null;
|
2021-05-19 16:35:13 +00:00
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
protected string $custom_rss_string;
|
2021-03-19 16:12:36 +00:00
|
|
|
|
2022-07-05 16:39:20 +00:00
|
|
|
protected ?string $publication_status = null;
|
|
|
|
|
|
|
|
/**
|
2023-08-26 13:03:01 +00:00
|
|
|
* @var array<int, string>
|
|
|
|
* @phpstan-var list<string>
|
2022-07-05 16:39:20 +00:00
|
|
|
*/
|
|
|
|
protected $dates = ['published_at', 'created_at', 'updated_at'];
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
/**
|
|
|
|
* @var array<string, string>
|
|
|
|
*/
|
2020-05-31 19:15:52 +00:00
|
|
|
protected $casts = [
|
2023-06-12 14:47:38 +00:00
|
|
|
'id' => 'integer',
|
|
|
|
'guid' => 'string',
|
|
|
|
'actor_id' => 'integer',
|
|
|
|
'handle' => 'string',
|
|
|
|
'title' => 'string',
|
|
|
|
'description_markdown' => 'string',
|
|
|
|
'description_html' => 'string',
|
|
|
|
'cover_id' => 'int',
|
|
|
|
'banner_id' => '?int',
|
|
|
|
'language_code' => 'string',
|
|
|
|
'category_id' => 'integer',
|
|
|
|
'parental_advisory' => '?string',
|
|
|
|
'publisher' => '?string',
|
|
|
|
'owner_name' => 'string',
|
|
|
|
'owner_email' => 'string',
|
2024-01-01 10:11:29 +00:00
|
|
|
'is_owner_email_removed_from_feed' => 'boolean',
|
2023-06-12 14:47:38 +00:00
|
|
|
'type' => 'string',
|
2024-02-05 16:51:04 +00:00
|
|
|
'medium' => 'string',
|
2023-06-12 14:47:38 +00:00
|
|
|
'copyright' => '?string',
|
2020-10-29 15:45:19 +00:00
|
|
|
'episode_description_footer_markdown' => '?string',
|
2023-06-12 14:47:38 +00:00
|
|
|
'episode_description_footer_html' => '?string',
|
|
|
|
'is_blocked' => 'boolean',
|
|
|
|
'is_completed' => 'boolean',
|
|
|
|
'is_locked' => 'boolean',
|
|
|
|
'is_premium_by_default' => 'boolean',
|
|
|
|
'imported_feed_url' => '?string',
|
|
|
|
'new_feed_url' => '?string',
|
|
|
|
'location_name' => '?string',
|
|
|
|
'location_geo' => '?string',
|
|
|
|
'location_osm' => '?string',
|
|
|
|
'payment_pointer' => '?string',
|
|
|
|
'custom_rss' => '?json-array',
|
|
|
|
'is_published_on_hubs' => 'boolean',
|
|
|
|
'partner_id' => '?string',
|
|
|
|
'partner_link_url' => '?string',
|
|
|
|
'partner_image_url' => '?string',
|
|
|
|
'created_by' => 'integer',
|
|
|
|
'updated_by' => 'integer',
|
2020-05-31 19:15:52 +00:00
|
|
|
];
|
2020-06-26 14:34:52 +00:00
|
|
|
|
2022-10-15 11:22:08 +00:00
|
|
|
public function getAtHandle(): string
|
|
|
|
{
|
|
|
|
return '@' . $this->handle;
|
|
|
|
}
|
|
|
|
|
2022-01-10 10:31:47 +00:00
|
|
|
public function getActor(): ?Actor
|
2021-04-02 17:20:02 +00:00
|
|
|
{
|
2021-05-14 17:59:35 +00:00
|
|
|
if ($this->actor_id === 0) {
|
2021-06-08 09:52:11 +00:00
|
|
|
throw new RuntimeException('Podcast must have an actor_id before getting actor.');
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
2022-06-13 16:30:34 +00:00
|
|
|
if (! $this->actor instanceof Actor) {
|
2022-02-05 11:40:30 +00:00
|
|
|
$this->actor = model(ActorModel::class, false)
|
2021-05-19 16:35:13 +00:00
|
|
|
->getActorById($this->actor_id);
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->actor;
|
|
|
|
}
|
|
|
|
|
2021-12-20 17:12:12 +00:00
|
|
|
public function setCover(UploadedFile | File $file = null): self
|
2021-12-17 17:14:37 +00:00
|
|
|
{
|
2023-04-14 11:11:53 +00:00
|
|
|
if (! $file instanceof File || ($file instanceof UploadedFile && ! $file->isValid())) {
|
2021-12-17 17:14:37 +00:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (array_key_exists('cover_id', $this->attributes) && $this->attributes['cover_id'] !== null) {
|
|
|
|
$this->getCover()
|
|
|
|
->setFile($file);
|
|
|
|
$this->getCover()
|
2023-06-21 16:17:11 +00:00
|
|
|
->updated_by = $this->attributes['updated_by'];
|
2021-12-17 17:14:37 +00:00
|
|
|
(new MediaModel('image'))->updateMedia($this->getCover());
|
|
|
|
} else {
|
|
|
|
$cover = new Image([
|
2023-03-16 13:00:05 +00:00
|
|
|
'file_key' => 'podcasts/' . $this->attributes['handle'] . '/cover.' . $file->getExtension(),
|
2024-04-28 16:39:01 +00:00
|
|
|
'sizes' => config('Images')
|
2025-01-08 11:11:19 +00:00
|
|
|
->podcastCoverSizes,
|
2023-06-21 16:17:11 +00:00
|
|
|
'uploaded_by' => $this->attributes['updated_by'],
|
|
|
|
'updated_by' => $this->attributes['updated_by'],
|
2021-12-17 17:14:37 +00:00
|
|
|
]);
|
|
|
|
$cover->setFile($file);
|
|
|
|
|
|
|
|
$this->attributes['cover_id'] = (new MediaModel('image'))->saveMedia($cover);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2021-11-01 17:12:03 +00:00
|
|
|
public function getCover(): Image
|
|
|
|
{
|
2021-12-14 16:41:10 +00:00
|
|
|
if (! $this->cover instanceof Image) {
|
2023-06-13 16:05:02 +00:00
|
|
|
$cover = (new MediaModel('image'))->getMediaById($this->cover_id);
|
|
|
|
|
|
|
|
if (! $cover instanceof Image) {
|
|
|
|
throw new Exception('Could not retrieve podcast cover.');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->cover = $cover;
|
2021-11-01 17:12:03 +00:00
|
|
|
}
|
|
|
|
|
2021-12-14 16:41:10 +00:00
|
|
|
return $this->cover;
|
2020-06-30 18:17:41 +02:00
|
|
|
}
|
|
|
|
|
2021-12-20 17:12:12 +00:00
|
|
|
public function setBanner(UploadedFile | File $file = null): self
|
2021-12-17 17:14:37 +00:00
|
|
|
{
|
2023-04-14 11:11:53 +00:00
|
|
|
if (! $file instanceof File || ($file instanceof UploadedFile && ! $file->isValid())) {
|
2021-12-17 17:14:37 +00:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (array_key_exists('banner_id', $this->attributes) && $this->attributes['banner_id'] !== null) {
|
|
|
|
$this->getBanner()
|
|
|
|
->setFile($file);
|
|
|
|
$this->getBanner()
|
2023-06-21 16:17:11 +00:00
|
|
|
->updated_by = $this->attributes['updated_by'];
|
2021-12-17 17:14:37 +00:00
|
|
|
(new MediaModel('image'))->updateMedia($this->getBanner());
|
|
|
|
} else {
|
|
|
|
$banner = new Image([
|
2023-03-16 13:00:05 +00:00
|
|
|
'file_key' => 'podcasts/' . $this->attributes['handle'] . '/banner.' . $file->getExtension(),
|
2024-04-28 16:39:01 +00:00
|
|
|
'sizes' => config('Images')
|
2025-01-08 11:11:19 +00:00
|
|
|
->podcastBannerSizes,
|
2023-06-21 16:17:11 +00:00
|
|
|
'uploaded_by' => $this->attributes['updated_by'],
|
|
|
|
'updated_by' => $this->attributes['updated_by'],
|
2021-12-17 17:14:37 +00:00
|
|
|
]);
|
|
|
|
$banner->setFile($file);
|
|
|
|
|
|
|
|
$this->attributes['banner_id'] = (new MediaModel('image'))->saveMedia($banner);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2023-04-13 11:45:03 +00:00
|
|
|
public function getBanner(): ?Image
|
2020-06-26 14:34:52 +00:00
|
|
|
{
|
2021-12-14 16:41:10 +00:00
|
|
|
if ($this->banner_id === null) {
|
2023-04-13 11:45:03 +00:00
|
|
|
return null;
|
2021-12-14 16:41:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (! $this->banner instanceof Image) {
|
|
|
|
$this->banner = (new MediaModel('image'))->getMediaById($this->banner_id);
|
2021-11-01 17:12:03 +00:00
|
|
|
}
|
|
|
|
|
2021-12-14 16:41:10 +00:00
|
|
|
return $this->banner;
|
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-07-26 13:10:46 +00:00
|
|
|
return url_to('podcast-activity', $this->attributes['handle']);
|
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
|
|
|
{
|
2022-10-14 12:50:25 +00:00
|
|
|
return url_to('podcast-rss-feed', $this->attributes['handle']);
|
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
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->id === null) {
|
2021-06-08 09:52:11 +00:00
|
|
|
throw new RuntimeException('Podcast must be created before getting episodes.');
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->episodes === null) {
|
2021-06-08 09:52:11 +00:00
|
|
|
$this->episodes = (new EpisodeModel())->getPodcastEpisodes($this->id, $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
|
|
|
|
2022-05-05 15:48:16 +00:00
|
|
|
/**
|
|
|
|
* Returns the podcast's episodes count
|
|
|
|
*/
|
|
|
|
public function getEpisodesCount(): int|string
|
|
|
|
{
|
|
|
|
if ($this->id === null) {
|
|
|
|
throw new RuntimeException('Podcast must be created before getting number of episodes.');
|
|
|
|
}
|
|
|
|
|
|
|
|
return (new EpisodeModel())->getPodcastEpisodesCount($this->id);
|
|
|
|
}
|
|
|
|
|
2021-02-10 16:20:01 +00:00
|
|
|
/**
|
|
|
|
* Returns the podcast's persons
|
|
|
|
*
|
2021-05-14 17:59:35 +00:00
|
|
|
* @return Person[]
|
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
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->id === null) {
|
2021-06-08 09:52:11 +00:00
|
|
|
throw new RuntimeException('Podcast must be created before getting persons.');
|
2021-02-10 16:20:01 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->persons === null) {
|
2021-05-14 17:59:35 +00:00
|
|
|
$this->persons = (new PersonModel())->getPodcastPersons($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-14 17:59:35 +00:00
|
|
|
public function getCategory(): ?Category
|
2020-09-04 09:09:26 +00:00
|
|
|
{
|
2021-05-14 17:59:35 +00:00
|
|
|
if ($this->id === null) {
|
2021-06-08 09:52:11 +00:00
|
|
|
throw new RuntimeException('Podcast must be created before getting category.');
|
2020-09-04 09:09:26 +00:00
|
|
|
}
|
|
|
|
|
2021-08-11 15:47:23 +00:00
|
|
|
if (! $this->category instanceof Category) {
|
2021-06-08 09:52:11 +00:00
|
|
|
$this->category = (new CategoryModel())->getCategoryById($this->category_id);
|
2020-09-04 09:09:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->category;
|
|
|
|
}
|
|
|
|
|
2022-09-28 15:02:09 +00:00
|
|
|
/**
|
|
|
|
* Returns all podcast subscriptions
|
|
|
|
*
|
|
|
|
* @return Subscription[]
|
|
|
|
*/
|
|
|
|
public function getSubscriptions(): array
|
|
|
|
{
|
|
|
|
if ($this->id === null) {
|
|
|
|
throw new RuntimeException('Podcasts must be created before getting subscriptions.');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->subscriptions === null) {
|
|
|
|
$this->subscriptions = (new SubscriptionModel())->getPodcastSubscriptions($this->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->subscriptions;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->id === null) {
|
2021-06-08 09:52:11 +00:00
|
|
|
throw new RuntimeException('Podcasts must be created before getting contributors.');
|
2020-07-31 16:05:10 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->contributors === null) {
|
2021-06-08 09:52:11 +00:00
|
|
|
$this->contributors = (new UserModel())->getPodcastContributors($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-14 17:59:35 +00:00
|
|
|
public function setDescriptionMarkdown(string $descriptionMarkdown): static
|
2020-07-28 15:57:48 +00:00
|
|
|
{
|
2022-02-02 17:01:19 +00:00
|
|
|
$config = [
|
2023-06-12 14:47:38 +00:00
|
|
|
'html_input' => 'escape',
|
2020-08-04 11:25:22 +00:00
|
|
|
'allow_unsafe_links' => false,
|
2022-02-02 17:01:19 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
$environment = new Environment($config);
|
|
|
|
$environment->addExtension(new CommonMarkCoreExtension());
|
|
|
|
$environment->addExtension(new AutolinkExtension());
|
|
|
|
$environment->addExtension(new SmartPunctExtension());
|
|
|
|
$environment->addExtension(new DisallowedRawHtmlExtension());
|
|
|
|
|
|
|
|
$converter = new MarkdownConverter($environment);
|
2020-07-28 15:57:48 +00:00
|
|
|
|
2020-10-29 15:45:19 +00:00
|
|
|
$this->attributes['description_markdown'] = $descriptionMarkdown;
|
2022-02-02 17:01:19 +00:00
|
|
|
$this->attributes['description_html'] = $converter->convert($descriptionMarkdown);
|
2020-10-29 15:45:19 +00:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
public function setEpisodeDescriptionFooterMarkdown(?string $episodeDescriptionFooterMarkdown = null): static
|
|
|
|
{
|
2021-06-11 08:03:54 +00:00
|
|
|
if ($episodeDescriptionFooterMarkdown === null || $episodeDescriptionFooterMarkdown === '') {
|
2020-10-29 15:45:19 +00:00
|
|
|
$this->attributes[
|
|
|
|
'episode_description_footer_markdown'
|
2021-06-11 08:03:54 +00:00
|
|
|
] = null;
|
2020-10-29 15:45:19 +00:00
|
|
|
$this->attributes[
|
|
|
|
'episode_description_footer_html'
|
2021-06-11 08:03:54 +00:00
|
|
|
] = null;
|
|
|
|
|
|
|
|
return $this;
|
2020-10-29 15:45:19 +00:00
|
|
|
}
|
|
|
|
|
2022-02-02 17:01:19 +00:00
|
|
|
$config = [
|
2023-06-12 14:47:38 +00:00
|
|
|
'html_input' => 'escape',
|
2021-06-11 08:03:54 +00:00
|
|
|
'allow_unsafe_links' => false,
|
2022-02-02 17:01:19 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
$environment = new Environment($config);
|
|
|
|
$environment->addExtension(new CommonMarkCoreExtension());
|
|
|
|
$environment->addExtension(new AutolinkExtension());
|
|
|
|
$environment->addExtension(new SmartPunctExtension());
|
|
|
|
$environment->addExtension(new DisallowedRawHtmlExtension());
|
|
|
|
|
|
|
|
$converter = new MarkdownConverter($environment);
|
2021-06-11 08:03:54 +00:00
|
|
|
|
|
|
|
$this->attributes[
|
|
|
|
'episode_description_footer_markdown'
|
|
|
|
] = $episodeDescriptionFooterMarkdown;
|
|
|
|
$this->attributes[
|
|
|
|
'episode_description_footer_html'
|
2022-02-02 17:01:19 +00:00
|
|
|
] = $converter->convert($episodeDescriptionFooterMarkdown);
|
2021-06-11 08:03:54 +00:00
|
|
|
|
2020-10-29 15:45:19 +00:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
public function getDescription(): string
|
2020-10-29 15:45:19 +00:00
|
|
|
{
|
2021-05-17 17:11:23 +00:00
|
|
|
if ($this->description === null) {
|
|
|
|
$this->description = trim(
|
2022-10-17 14:17:50 +00:00
|
|
|
(string) preg_replace('~\s+~', ' ', strip_tags((string) $this->attributes['description_html'])),
|
2021-05-17 17:11:23 +00:00
|
|
|
);
|
2020-10-29 15:45:19 +00:00
|
|
|
}
|
|
|
|
|
2021-05-17 17:11:23 +00:00
|
|
|
return $this->description;
|
2020-07-28 15:57:48 +00:00
|
|
|
}
|
2020-08-14 18:27:57 +00:00
|
|
|
|
2022-07-05 16:39:20 +00:00
|
|
|
public function getPublicationStatus(): string
|
|
|
|
{
|
|
|
|
if ($this->publication_status === null) {
|
2023-04-14 11:11:53 +00:00
|
|
|
if (! $this->published_at instanceof Time) {
|
2022-07-05 16:39:20 +00:00
|
|
|
$this->publication_status = 'not_published';
|
|
|
|
} elseif ($this->published_at->isBefore(Time::now())) {
|
|
|
|
$this->publication_status = 'published';
|
|
|
|
} else {
|
|
|
|
$this->publication_status = 'scheduled';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->publication_status;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->id === null) {
|
2021-06-08 09:52:11 +00:00
|
|
|
throw new RuntimeException('Podcast must be created before getting podcasting platform links.');
|
2020-09-04 09:09:26 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->podcasting_platforms === null) {
|
2024-04-24 14:47:05 +00:00
|
|
|
$this->podcasting_platforms = (new PlatformModel())->getPlatforms($this->id, 'podcasting');
|
2020-11-18 17:17:56 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
return $this->podcasting_platforms;
|
2020-11-18 17:17:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->id === null) {
|
2021-06-08 09:52:11 +00:00
|
|
|
throw new RuntimeException('Podcast must be created before getting social platform links.');
|
2020-11-18 17:17:56 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->social_platforms === null) {
|
2024-04-24 14:47:05 +00:00
|
|
|
$this->social_platforms = (new PlatformModel())->getPlatforms($this->id, 'social');
|
2020-11-18 17:17:56 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
return $this->social_platforms;
|
2020-11-18 17:17:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->id === null) {
|
2021-06-08 09:52:11 +00:00
|
|
|
throw new RuntimeException('Podcast must be created before getting funding platform links.');
|
2020-11-18 17:17:56 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->funding_platforms === null) {
|
2024-04-24 14:47:05 +00:00
|
|
|
$this->funding_platforms = (new PlatformModel())->getPlatforms($this->id, 'funding');
|
2020-09-04 09:09:26 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
return $this->funding_platforms;
|
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
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->id === null) {
|
2021-06-08 09:52:11 +00:00
|
|
|
throw new RuntimeException('Podcast must be created before getting other categories.');
|
2020-10-02 15:38:16 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->other_categories === null) {
|
2021-06-08 09:52:11 +00:00
|
|
|
$this->other_categories = (new CategoryModel())->getPodcastCategories($this->id);
|
2020-10-02 15:38:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->other_categories;
|
|
|
|
}
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
/**
|
2022-03-04 14:33:48 +00:00
|
|
|
* @return int[]|string[]
|
2021-05-06 14:00:48 +00:00
|
|
|
*/
|
|
|
|
public function getOtherCategoriesIds(): array
|
2020-10-02 15:38:16 +00:00
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->other_categories_ids === null) {
|
2021-06-08 09:52:11 +00:00
|
|
|
$this->other_categories_ids = array_column($this->getOtherCategories(), '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-17 17:11:23 +00:00
|
|
|
public function setLocation(?Location $location = null): static
|
2020-12-23 14:11:38 +00:00
|
|
|
{
|
2023-04-14 11:11:53 +00:00
|
|
|
if (! $location instanceof Location) {
|
2021-05-12 14:00:25 +00:00
|
|
|
$this->attributes['location_name'] = null;
|
|
|
|
$this->attributes['location_geo'] = null;
|
2021-05-17 17:11:23 +00:00
|
|
|
$this->attributes['location_osm'] = null;
|
2020-12-23 14:11:38 +00:00
|
|
|
|
2021-05-17 17:11:23 +00:00
|
|
|
return $this;
|
|
|
|
}
|
2021-05-12 14:00:25 +00:00
|
|
|
|
2020-12-23 14:11:38 +00:00
|
|
|
if (
|
2021-05-19 16:35:13 +00:00
|
|
|
! isset($this->attributes['location_name']) ||
|
2021-05-17 17:11:23 +00:00
|
|
|
$this->attributes['location_name'] !== $location->name
|
2020-12-23 14:11:38 +00:00
|
|
|
) {
|
2021-05-17 17:11:23 +00:00
|
|
|
$location->fetchOsmLocation();
|
2021-05-12 14:00:25 +00:00
|
|
|
|
2021-05-17 17:11:23 +00:00
|
|
|
$this->attributes['location_name'] = $location->name;
|
|
|
|
$this->attributes['location_geo'] = $location->geo;
|
|
|
|
$this->attributes['location_osm'] = $location->osm;
|
2020-12-23 14:11:38 +00:00
|
|
|
}
|
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
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
public function getLocation(): ?Location
|
|
|
|
{
|
|
|
|
if ($this->location_name === null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-04-14 11:11:53 +00:00
|
|
|
if (! $this->location instanceof Location) {
|
2021-06-08 09:52:11 +00:00
|
|
|
$this->location = new Location($this->location_name, $this->location_geo, $this->location_osm);
|
2021-05-12 14:00:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->location;
|
|
|
|
}
|
|
|
|
|
2021-03-19 16:12:36 +00:00
|
|
|
/**
|
|
|
|
* Get custom rss tag as XML String
|
|
|
|
*/
|
2021-05-19 16:35:13 +00:00
|
|
|
public function getCustomRssString(): string
|
2021-03-19 16:12:36 +00:00
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->attributes['custom_rss'] === null) {
|
2021-03-19 16:12:36 +00:00
|
|
|
return '';
|
|
|
|
}
|
2021-05-06 14:00:48 +00:00
|
|
|
|
|
|
|
helper('rss');
|
|
|
|
|
|
|
|
$xmlNode = (new SimpleRSSElement(
|
2023-07-29 08:04:19 +00:00
|
|
|
'<?xml version="1.0" encoding="utf-8"?><rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:podcast="https://podcastindex.org/namespace/1.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0"/>',
|
2021-05-06 14:00:48 +00:00
|
|
|
))->addChild('channel');
|
2021-05-19 16:35:13 +00:00
|
|
|
array_to_rss([
|
|
|
|
'elements' => $this->custom_rss,
|
2021-06-08 09:52:11 +00:00
|
|
|
], $xmlNode);
|
2021-05-06 14:00:48 +00:00
|
|
|
|
2022-10-17 14:17:50 +00:00
|
|
|
return str_replace(['<channel>', '</channel>'], '', (string) $xmlNode->asXML());
|
2021-03-19 16:12:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves custom rss tag into json
|
|
|
|
*/
|
2021-05-19 16:35:13 +00:00
|
|
|
public function setCustomRssString(string $customRssString): static
|
2021-03-19 16:12:36 +00:00
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($customRssString === '') {
|
2021-08-11 12:15:20 +00:00
|
|
|
$this->attributes['custom_rss'] = null;
|
2021-05-06 14:00:48 +00:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2021-03-19 16:12:36 +00:00
|
|
|
helper('rss');
|
|
|
|
$customRssArray = rss_to_array(
|
|
|
|
simplexml_load_string(
|
2023-07-29 08:04:19 +00:00
|
|
|
'<?xml version="1.0" encoding="utf-8"?><rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:podcast="https://podcastindex.org/namespace/1.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0"><channel>' .
|
2021-03-19 16:12:36 +00:00
|
|
|
$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)) {
|
2021-06-08 09:52:11 +00:00
|
|
|
$this->attributes['custom_rss'] = json_encode($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
|
|
|
}
|
2022-09-28 15:02:09 +00:00
|
|
|
|
|
|
|
public function getIsPremium(): bool
|
|
|
|
{
|
|
|
|
// podcast is premium if at least one of its episodes is set as premium
|
|
|
|
return (new EpisodeModel())->doesPodcastHavePremiumEpisodes($this->id);
|
|
|
|
}
|
2024-01-23 13:19:53 +00:00
|
|
|
|
|
|
|
public function getIsOp3Enabled(): bool
|
|
|
|
{
|
|
|
|
return service('settings')->get('Analytics.enableOP3', 'podcast:' . $this->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOp3Url(): string
|
|
|
|
{
|
|
|
|
return 'https://op3.dev/show/' . $this->guid;
|
|
|
|
}
|
2020-05-31 19:15:52 +00:00
|
|
|
}
|