2020-11-18 17:17:56 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @copyright 2020 Podlibre
|
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Controllers\Admin;
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
use CodeIgniter\HTTP\RedirectResponse;
|
2021-05-06 14:00:48 +00:00
|
|
|
use App\Entities\Podcast;
|
|
|
|
use CodeIgniter\Exceptions\PageNotFoundException;
|
|
|
|
use ErrorException;
|
|
|
|
use Config\Database;
|
|
|
|
use Podlibre\PodcastNamespace\ReversedTaxonomy;
|
|
|
|
use App\Entities\Episode;
|
2021-05-12 14:00:25 +00:00
|
|
|
use App\Entities\Image;
|
2021-05-17 17:11:23 +00:00
|
|
|
use App\Entities\Location;
|
2021-05-14 17:59:35 +00:00
|
|
|
use App\Entities\Person;
|
2020-11-18 17:17:56 +00:00
|
|
|
use App\Models\CategoryModel;
|
|
|
|
use App\Models\LanguageModel;
|
|
|
|
use App\Models\PodcastModel;
|
|
|
|
use App\Models\EpisodeModel;
|
|
|
|
use App\Models\PlatformModel;
|
2021-02-10 16:20:01 +00:00
|
|
|
use App\Models\PersonModel;
|
2020-11-18 17:17:56 +00:00
|
|
|
use Config\Services;
|
|
|
|
use League\HTMLToMarkdown\HtmlConverter;
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
class PodcastImportController extends BaseController
|
2020-11-18 17:17:56 +00:00
|
|
|
{
|
|
|
|
/**
|
2021-05-06 14:00:48 +00:00
|
|
|
* @var Podcast|null
|
2020-11-18 17:17:56 +00:00
|
|
|
*/
|
|
|
|
protected $podcast;
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function _remap(string $method, string ...$params): mixed
|
2020-11-18 17:17:56 +00:00
|
|
|
{
|
2021-05-06 14:00:48 +00:00
|
|
|
if (count($params) === 0) {
|
|
|
|
return $this->$method();
|
|
|
|
}
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
if (($this->podcast = (new PodcastModel())->getPodcastById((int) $params[0])) !== null) {
|
2021-05-06 14:00:48 +00:00
|
|
|
return $this->$method();
|
2020-11-18 17:17:56 +00:00
|
|
|
}
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
throw PageNotFoundException::forPageNotFound();
|
2020-11-18 17:17:56 +00:00
|
|
|
}
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function index(): string
|
2020-11-18 17:17:56 +00:00
|
|
|
{
|
|
|
|
helper(['form', 'misc']);
|
|
|
|
|
|
|
|
$languageOptions = (new LanguageModel())->getLanguageOptions();
|
|
|
|
$categoryOptions = (new CategoryModel())->getCategoryOptions();
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'languageOptions' => $languageOptions,
|
|
|
|
'categoryOptions' => $categoryOptions,
|
|
|
|
'browserLang' => get_browser_language(
|
2021-04-02 17:20:02 +00:00
|
|
|
$this->request->getServer('HTTP_ACCEPT_LANGUAGE'),
|
2020-11-18 17:17:56 +00:00
|
|
|
),
|
|
|
|
];
|
|
|
|
|
|
|
|
return view('admin/podcast/import', $data);
|
|
|
|
}
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function attemptImport(): RedirectResponse
|
2020-11-18 17:17:56 +00:00
|
|
|
{
|
|
|
|
helper(['media', 'misc']);
|
|
|
|
|
|
|
|
$rules = [
|
|
|
|
'imported_feed_url' => 'required|validate_url',
|
|
|
|
'season_number' => 'is_natural_no_zero|permit_empty',
|
|
|
|
'max_episodes' => 'is_natural_no_zero|permit_empty',
|
|
|
|
];
|
|
|
|
|
|
|
|
if (!$this->validate($rules)) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
|
|
|
try {
|
2021-02-11 17:41:20 +00:00
|
|
|
ini_set('user_agent', 'Castopod/' . CP_VERSION);
|
2020-11-18 17:17:56 +00:00
|
|
|
$feed = simplexml_load_file(
|
2021-04-02 17:20:02 +00:00
|
|
|
$this->request->getPost('imported_feed_url'),
|
2020-11-18 17:17:56 +00:00
|
|
|
);
|
2021-05-06 14:00:48 +00:00
|
|
|
} catch (ErrorException $errorException) {
|
2020-11-18 17:17:56 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', [
|
2021-05-06 14:00:48 +00:00
|
|
|
$errorException->getMessage() .
|
2021-05-14 17:59:35 +00:00
|
|
|
': <a href="' .
|
|
|
|
$this->request->getPost('imported_feed_url') .
|
|
|
|
'" rel="noreferrer noopener" target="_blank">' .
|
|
|
|
$this->request->getPost('imported_feed_url') .
|
|
|
|
' ⎋</a>',
|
2020-11-18 17:17:56 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
$nsItunes = $feed->channel[0]->children(
|
2021-04-02 17:20:02 +00:00
|
|
|
'http://www.itunes.com/dtds/podcast-1.0.dtd',
|
2020-11-18 17:17:56 +00:00
|
|
|
);
|
|
|
|
$nsPodcast = $feed->channel[0]->children(
|
2021-04-02 17:20:02 +00:00
|
|
|
'https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md',
|
2020-11-18 17:17:56 +00:00
|
|
|
);
|
2021-02-11 17:41:20 +00:00
|
|
|
$nsContent = $feed->channel[0]->children(
|
2021-04-02 17:20:02 +00:00
|
|
|
'http://purl.org/rss/1.0/modules/content/',
|
2021-02-11 17:41:20 +00:00
|
|
|
);
|
2020-11-18 17:17:56 +00:00
|
|
|
|
|
|
|
if ((string) $nsPodcast->locked === 'yes') {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', [lang('PodcastImport.lock_import')]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$converter = new HtmlConverter();
|
|
|
|
|
2021-04-02 17:20:02 +00:00
|
|
|
$channelDescriptionHtml = (string) $feed->channel[0]->description;
|
2020-11-18 17:17:56 +00:00
|
|
|
|
2020-11-23 20:55:50 +01:00
|
|
|
try {
|
2021-05-12 14:00:25 +00:00
|
|
|
if (
|
2021-05-17 17:11:23 +00:00
|
|
|
isset($nsItunes->image) &&
|
2021-05-12 14:00:25 +00:00
|
|
|
$nsItunes->image->attributes()['href'] !== null
|
|
|
|
) {
|
|
|
|
$imageFile = download_file(
|
|
|
|
(string) $nsItunes->image->attributes()['href'],
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$imageFile = download_file(
|
|
|
|
(string) $feed->channel[0]->image->url,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-17 17:11:23 +00:00
|
|
|
$location = null;
|
|
|
|
if (isset($nsPodcast->location)) {
|
|
|
|
$location = new Location(
|
|
|
|
(string) $nsPodcast->location,
|
|
|
|
(string) $nsPodcast->location->attributes()['geo'],
|
|
|
|
(string) $nsPodcast->location->attributes()['osm'],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
$podcast = new Podcast([
|
2020-11-23 20:55:50 +01:00
|
|
|
'name' => $this->request->getPost('name'),
|
|
|
|
'imported_feed_url' => $this->request->getPost(
|
2021-04-02 17:20:02 +00:00
|
|
|
'imported_feed_url',
|
2020-11-23 20:55:50 +01:00
|
|
|
),
|
|
|
|
'new_feed_url' => base_url(
|
2021-04-02 17:20:02 +00:00
|
|
|
route_to('podcast_feed', $this->request->getPost('name')),
|
2020-11-23 20:55:50 +01:00
|
|
|
),
|
2021-04-02 17:20:02 +00:00
|
|
|
'title' => (string) $feed->channel[0]->title,
|
2020-11-23 20:55:50 +01:00
|
|
|
'description_markdown' => $converter->convert(
|
2021-04-02 17:20:02 +00:00
|
|
|
$channelDescriptionHtml,
|
2020-11-23 20:55:50 +01:00
|
|
|
),
|
|
|
|
'description_html' => $channelDescriptionHtml,
|
2021-05-12 14:00:25 +00:00
|
|
|
'image' => new Image($imageFile),
|
2020-11-23 20:55:50 +01:00
|
|
|
'language_code' => $this->request->getPost('language'),
|
|
|
|
'category_id' => $this->request->getPost('category'),
|
2021-05-12 14:00:25 +00:00
|
|
|
'parental_advisory' =>
|
2021-05-17 17:11:23 +00:00
|
|
|
isset($nsItunes->explicit)
|
|
|
|
? (in_array((string) $nsItunes->explicit, ['yes', 'true'])
|
2021-05-14 17:59:35 +00:00
|
|
|
? 'explicit'
|
2021-05-17 17:11:23 +00:00
|
|
|
: (in_array((string) $nsItunes->explicit, ['no', 'false'])
|
2021-05-14 17:59:35 +00:00
|
|
|
? 'clean'
|
2021-05-17 17:11:23 +00:00
|
|
|
: null))
|
|
|
|
: null,
|
2021-04-02 17:20:02 +00:00
|
|
|
'owner_name' => (string) $nsItunes->owner->name,
|
|
|
|
'owner_email' => (string) $nsItunes->owner->email,
|
|
|
|
'publisher' => (string) $nsItunes->author,
|
2021-05-17 17:11:23 +00:00
|
|
|
'type' => isset($nsItunes->type) ? (string) $nsItunes->type : 'episodic',
|
2021-04-02 17:20:02 +00:00
|
|
|
'copyright' => (string) $feed->channel[0]->copyright,
|
2021-05-12 14:00:25 +00:00
|
|
|
'is_blocked' =>
|
2021-05-17 17:11:23 +00:00
|
|
|
isset($nsItunes->block)
|
|
|
|
? (string) $nsItunes->block === 'yes'
|
|
|
|
: false,
|
2021-05-12 14:00:25 +00:00
|
|
|
'is_completed' =>
|
2021-05-17 17:11:23 +00:00
|
|
|
isset($nsItunes->complete)
|
|
|
|
? (string) $nsItunes->complete === 'yes'
|
|
|
|
: false,
|
|
|
|
'location' => $location,
|
2021-05-12 14:00:25 +00:00
|
|
|
'created_by' => user_id(),
|
|
|
|
'updated_by' => user_id(),
|
2020-11-23 20:55:50 +01:00
|
|
|
]);
|
2021-05-06 14:00:48 +00:00
|
|
|
} catch (ErrorException $ex) {
|
2020-11-23 20:55:50 +01:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', [
|
|
|
|
$ex->getMessage() .
|
2021-05-14 17:59:35 +00:00
|
|
|
': <a href="' .
|
|
|
|
$this->request->getPost('imported_feed_url') .
|
|
|
|
'" rel="noreferrer noopener" target="_blank">' .
|
|
|
|
$this->request->getPost('imported_feed_url') .
|
|
|
|
' ⎋</a>',
|
2020-11-23 20:55:50 +01:00
|
|
|
]);
|
|
|
|
}
|
2020-11-18 17:17:56 +00:00
|
|
|
|
|
|
|
$podcastModel = new PodcastModel();
|
2021-05-06 14:00:48 +00:00
|
|
|
$db = Database::connect();
|
2020-11-18 17:17:56 +00:00
|
|
|
|
|
|
|
$db->transStart();
|
|
|
|
|
|
|
|
if (!($newPodcastId = $podcastModel->insert($podcast, true))) {
|
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $podcastModel->errors());
|
|
|
|
}
|
|
|
|
|
|
|
|
$authorize = Services::authorization();
|
|
|
|
$podcastAdminGroup = $authorize->group('podcast_admin');
|
|
|
|
|
|
|
|
$podcastModel->addPodcastContributor(
|
2021-05-12 14:00:25 +00:00
|
|
|
user_id(),
|
2020-11-18 17:17:56 +00:00
|
|
|
$newPodcastId,
|
2021-04-02 17:20:02 +00:00
|
|
|
$podcastAdminGroup->id,
|
2020-11-18 17:17:56 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$podcastsPlatformsData = [];
|
2021-02-10 16:20:01 +00:00
|
|
|
$platformTypes = [
|
|
|
|
['name' => 'podcasting', 'elements' => $nsPodcast->id],
|
|
|
|
['name' => 'social', 'elements' => $nsPodcast->social],
|
|
|
|
['name' => 'funding', 'elements' => $nsPodcast->funding],
|
|
|
|
];
|
|
|
|
$platformModel = new PlatformModel();
|
|
|
|
foreach ($platformTypes as $platformType) {
|
|
|
|
foreach ($platformType['elements'] as $platform) {
|
|
|
|
$platformLabel = $platform->attributes()['platform'];
|
|
|
|
$platformSlug = slugify($platformLabel);
|
2021-05-14 17:59:35 +00:00
|
|
|
if ($platformModel->getPlatform($platformSlug) !== null) {
|
2021-05-06 14:00:48 +00:00
|
|
|
$podcastsPlatformsData[] = [
|
2021-04-02 17:20:02 +00:00
|
|
|
'platform_slug' => $platformSlug,
|
|
|
|
'podcast_id' => $newPodcastId,
|
|
|
|
'link_url' => $platform->attributes()['url'],
|
|
|
|
'link_content' => $platform->attributes()['id'],
|
|
|
|
'is_visible' => false,
|
2021-05-06 14:00:48 +00:00
|
|
|
];
|
2021-02-10 16:20:01 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-18 17:17:56 +00:00
|
|
|
}
|
2021-05-12 14:00:25 +00:00
|
|
|
|
2020-11-23 20:55:50 +01:00
|
|
|
if (count($podcastsPlatformsData) > 1) {
|
|
|
|
$platformModel->createPodcastPlatforms(
|
|
|
|
$newPodcastId,
|
2021-04-02 17:20:02 +00:00
|
|
|
$podcastsPlatformsData,
|
2020-11-23 20:55:50 +01:00
|
|
|
);
|
|
|
|
}
|
2020-11-18 17:17:56 +00:00
|
|
|
|
2021-02-10 16:20:01 +00:00
|
|
|
foreach ($nsPodcast->person as $podcastPerson) {
|
2021-05-14 17:59:35 +00:00
|
|
|
$fullName = (string) $podcastPerson;
|
2021-02-10 16:20:01 +00:00
|
|
|
$personModel = new PersonModel();
|
|
|
|
$newPersonId = null;
|
2021-05-14 17:59:35 +00:00
|
|
|
if (($newPerson = $personModel->getPerson($fullName)) !== null) {
|
2021-02-10 16:20:01 +00:00
|
|
|
$newPersonId = $newPerson->id;
|
2021-05-14 17:59:35 +00:00
|
|
|
} else {
|
|
|
|
$newPodcastPerson = new Person([
|
|
|
|
'full_name' => $fullName,
|
|
|
|
'unique_name' => slugify($fullName),
|
|
|
|
'information_url' => $podcastPerson->attributes()['href'],
|
|
|
|
'image' => new Image(download_file($podcastPerson->attributes()['img'])),
|
|
|
|
'created_by' => user_id(),
|
|
|
|
'updated_by' => user_id(),
|
|
|
|
]);
|
|
|
|
|
|
|
|
if (!$newPersonId = $personModel->insert($newPodcastPerson)) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $personModel->errors());
|
|
|
|
}
|
2021-02-10 16:20:01 +00:00
|
|
|
}
|
|
|
|
|
2021-05-17 17:11:23 +00:00
|
|
|
// TODO: these checks should be in the taxonomy as default values
|
|
|
|
$podcastPersonGroup = $podcastPerson->attributes()['group'] ?? "Cast";
|
|
|
|
$podcastPersonRole = $podcastPerson->attributes()['role'] ?? "Host";
|
|
|
|
|
|
|
|
$personGroup = ReversedTaxonomy::$taxonomy[(string) $podcastPersonGroup];
|
|
|
|
|
|
|
|
$personGroupSlug = $personGroup['slug'];
|
|
|
|
$personRoleSlug = $personGroup['roles'][(string) $podcastPersonRole]['slug'];
|
2021-02-10 16:20:01 +00:00
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
$podcastPersonModel = new PersonModel();
|
2021-05-17 17:11:23 +00:00
|
|
|
if (!$podcastPersonModel->addPodcastPerson($newPodcastId, $newPersonId, $personGroupSlug, $personRoleSlug)) {
|
2021-02-10 16:20:01 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $podcastPersonModel->errors());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-18 17:17:56 +00:00
|
|
|
$numberItems = $feed->channel[0]->item->count();
|
|
|
|
$lastItem =
|
2021-05-12 14:00:25 +00:00
|
|
|
$this->request->getPost('max_episodes') !== null &&
|
2020-11-18 17:17:56 +00:00
|
|
|
$this->request->getPost('max_episodes') < $numberItems
|
2021-05-14 17:59:35 +00:00
|
|
|
? $this->request->getPost('max_episodes')
|
|
|
|
: $numberItems;
|
2020-11-18 17:17:56 +00:00
|
|
|
|
|
|
|
$slugs = [];
|
|
|
|
|
2021-02-10 16:20:01 +00:00
|
|
|
//////////////////////////////////////////////////////////////////
|
2020-11-18 17:17:56 +00:00
|
|
|
// For each Episode:
|
2021-05-06 14:00:48 +00:00
|
|
|
for ($itemNumber = 1; $itemNumber <= $lastItem; ++$itemNumber) {
|
2020-11-18 17:17:56 +00:00
|
|
|
$item = $feed->channel[0]->item[$numberItems - $itemNumber];
|
|
|
|
|
|
|
|
$nsItunes = $item->children(
|
2021-04-02 17:20:02 +00:00
|
|
|
'http://www.itunes.com/dtds/podcast-1.0.dtd',
|
2020-11-18 17:17:56 +00:00
|
|
|
);
|
2020-12-23 14:11:38 +00:00
|
|
|
$nsPodcast = $item->children(
|
2021-04-02 17:20:02 +00:00
|
|
|
'https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md',
|
2020-12-23 14:11:38 +00:00
|
|
|
);
|
2021-02-11 17:41:20 +00:00
|
|
|
$nsContent = $item->children(
|
2021-04-02 17:20:02 +00:00
|
|
|
'http://purl.org/rss/1.0/modules/content/',
|
2021-02-11 17:41:20 +00:00
|
|
|
);
|
2020-11-18 17:17:56 +00:00
|
|
|
|
|
|
|
$slug = slugify(
|
|
|
|
$this->request->getPost('slug_field') === 'title'
|
|
|
|
? $item->title
|
2021-04-02 17:20:02 +00:00
|
|
|
: basename($item->link),
|
2020-11-18 17:17:56 +00:00
|
|
|
);
|
|
|
|
if (in_array($slug, $slugs)) {
|
|
|
|
$slugNumber = 2;
|
|
|
|
while (in_array($slug . '-' . $slugNumber, $slugs)) {
|
2021-05-06 14:00:48 +00:00
|
|
|
++$slugNumber;
|
2020-11-18 17:17:56 +00:00
|
|
|
}
|
|
|
|
$slug = $slug . '-' . $slugNumber;
|
|
|
|
}
|
|
|
|
$slugs[] = $slug;
|
2021-05-14 17:59:35 +00:00
|
|
|
$itemDescriptionHtml = match ($this->request->getPost('description_field')) {
|
|
|
|
'content' => $nsContent->encoded,
|
|
|
|
'summary' => $nsItunes->summary,
|
|
|
|
'subtitle_summary' => $nsItunes->subtitle . '<br/>' . $nsItunes->summary,
|
|
|
|
default => $item->description,
|
|
|
|
};
|
2020-11-18 17:17:56 +00:00
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
if (
|
2021-05-17 17:11:23 +00:00
|
|
|
isset($nsItunes->image) &&
|
2021-05-12 14:00:25 +00:00
|
|
|
$nsItunes->image->attributes()['href'] !== null
|
|
|
|
) {
|
|
|
|
$episodeImage = new Image(
|
|
|
|
download_file(
|
|
|
|
(string) $nsItunes->image->attributes()['href'],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$episodeImage = null;
|
|
|
|
}
|
|
|
|
|
2021-05-17 17:11:23 +00:00
|
|
|
$location = null;
|
|
|
|
if (isset($nsPodcast->location)) {
|
|
|
|
$location = new Location(
|
|
|
|
(string) $nsPodcast->location,
|
|
|
|
(string) $nsPodcast->location->attributes()['geo'],
|
|
|
|
(string) $nsPodcast->location->attributes()['osm'],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
$newEpisode = new Episode([
|
2020-11-18 17:17:56 +00:00
|
|
|
'podcast_id' => $newPodcastId,
|
2021-05-12 14:00:25 +00:00
|
|
|
'guid' => $item->guid ?? null,
|
2020-11-18 17:17:56 +00:00
|
|
|
'title' => $item->title,
|
|
|
|
'slug' => $slug,
|
2021-05-12 14:00:25 +00:00
|
|
|
'audio_file' => download_file(
|
|
|
|
$item->enclosure->attributes()['url'],
|
|
|
|
),
|
2020-11-18 17:17:56 +00:00
|
|
|
'description_markdown' => $converter->convert(
|
2021-04-02 17:20:02 +00:00
|
|
|
$itemDescriptionHtml,
|
2020-11-18 17:17:56 +00:00
|
|
|
),
|
|
|
|
'description_html' => $itemDescriptionHtml,
|
2021-05-12 14:00:25 +00:00
|
|
|
'image' => $episodeImage,
|
|
|
|
'parental_advisory' =>
|
2021-05-17 17:11:23 +00:00
|
|
|
isset($nsItunes->explicit)
|
|
|
|
? (in_array((string) $nsItunes->explicit, ['yes', 'true'])
|
2021-05-14 17:59:35 +00:00
|
|
|
? 'explicit'
|
2021-05-17 17:11:23 +00:00
|
|
|
: (in_array((string) $nsItunes->explicit, ['no', 'false'])
|
2021-05-14 17:59:35 +00:00
|
|
|
? 'clean'
|
2021-05-17 17:11:23 +00:00
|
|
|
: null))
|
|
|
|
: null,
|
2020-11-18 17:17:56 +00:00
|
|
|
'number' =>
|
2021-05-14 17:59:35 +00:00
|
|
|
$this->request->getPost('force_renumber') === 'yes'
|
|
|
|
? $itemNumber
|
|
|
|
: $nsItunes->episode,
|
2021-05-12 14:00:25 +00:00
|
|
|
'season_number' =>
|
2021-05-14 17:59:35 +00:00
|
|
|
$this->request->getPost('season_number') === null
|
|
|
|
? $nsItunes->season
|
|
|
|
: $this->request->getPost('season_number'),
|
2021-05-17 17:11:23 +00:00
|
|
|
'type' => isset($nsItunes->episodeType)
|
|
|
|
? (string) $nsItunes->episodeType
|
|
|
|
: 'full',
|
|
|
|
'is_blocked' => isset($nsItunes->block)
|
|
|
|
? (string) $nsItunes->block === 'yes'
|
|
|
|
: false,
|
|
|
|
'location' => $location,
|
2021-05-12 14:00:25 +00:00
|
|
|
'created_by' => user_id(),
|
|
|
|
'updated_by' => user_id(),
|
2020-11-18 17:17:56 +00:00
|
|
|
'published_at' => strtotime($item->pubDate),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$episodeModel = new EpisodeModel();
|
|
|
|
|
2021-02-10 16:20:01 +00:00
|
|
|
if (!($newEpisodeId = $episodeModel->insert($newEpisode, true))) {
|
2020-11-18 17:17:56 +00:00
|
|
|
// FIXME: What shall we do?
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $episodeModel->errors());
|
|
|
|
}
|
2021-02-10 16:20:01 +00:00
|
|
|
|
|
|
|
foreach ($nsPodcast->person as $episodePerson) {
|
2021-05-14 17:59:35 +00:00
|
|
|
$fullName = (string) $episodePerson;
|
2021-02-10 16:20:01 +00:00
|
|
|
$personModel = new PersonModel();
|
|
|
|
$newPersonId = null;
|
2021-05-14 17:59:35 +00:00
|
|
|
if (($newPerson = $personModel->getPerson($fullName)) !== null) {
|
2021-02-10 16:20:01 +00:00
|
|
|
$newPersonId = $newPerson->id;
|
2021-05-14 17:59:35 +00:00
|
|
|
} else {
|
2021-05-17 17:11:23 +00:00
|
|
|
$newPerson = new Person([
|
2021-05-14 17:59:35 +00:00
|
|
|
'full_name' => $fullName,
|
2021-05-17 17:11:23 +00:00
|
|
|
'unique_name' => slugify($fullName),
|
2021-05-14 17:59:35 +00:00
|
|
|
'information_url' => $episodePerson->attributes()['href'],
|
2021-05-17 17:11:23 +00:00
|
|
|
'image' => new Image(download_file($episodePerson->attributes()['img'])),
|
|
|
|
'created_by' => user_id(),
|
|
|
|
'updated_by' => user_id(),
|
2021-05-14 17:59:35 +00:00
|
|
|
]);
|
|
|
|
|
2021-05-17 17:11:23 +00:00
|
|
|
if (!($newPersonId = $personModel->insert($newPerson))) {
|
2021-05-14 17:59:35 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $personModel->errors());
|
|
|
|
}
|
2021-02-10 16:20:01 +00:00
|
|
|
}
|
|
|
|
|
2021-05-17 17:11:23 +00:00
|
|
|
// TODO: these checks should be in the taxonomy as default values
|
|
|
|
$episodePersonGroup = $episodePerson->attributes()['group'] ?? "Cast";
|
|
|
|
$episodePersonRole = $episodePerson->attributes()['role'] ?? "Host";
|
|
|
|
|
|
|
|
$personGroup = ReversedTaxonomy::$taxonomy[(string) $episodePersonGroup];
|
2021-05-14 17:59:35 +00:00
|
|
|
|
2021-05-17 17:11:23 +00:00
|
|
|
$personGroupSlug = $personGroup['slug'];
|
|
|
|
$personRoleSlug = $personGroup['roles'][(string) $episodePersonRole]['slug'];
|
2021-02-10 16:20:01 +00:00
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
$episodePersonModel = new PersonModel();
|
2021-05-17 17:11:23 +00:00
|
|
|
if (!$episodePersonModel->addEpisodePerson($newPodcastId, $newEpisodeId, $newPersonId, $personGroupSlug, $personRoleSlug)) {
|
2021-02-10 16:20:01 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $episodePersonModel->errors());
|
|
|
|
}
|
|
|
|
}
|
2020-11-18 17:17:56 +00:00
|
|
|
}
|
|
|
|
|
2021-04-02 17:20:02 +00:00
|
|
|
// set interact as the newly imported podcast actor
|
|
|
|
$importedPodcast = (new PodcastModel())->getPodcastById($newPodcastId);
|
|
|
|
set_interact_as_actor($importedPodcast->actor_id);
|
|
|
|
|
2020-11-18 17:17:56 +00:00
|
|
|
$db->transComplete();
|
|
|
|
|
|
|
|
return redirect()->route('podcast-view', [$newPodcastId]);
|
|
|
|
}
|
|
|
|
}
|