2020-08-27 10:05:44 +00:00
|
|
|
<?php
|
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-08-27 10:05:44 +00:00
|
|
|
/**
|
2022-02-19 16:06:11 +00:00
|
|
|
* @copyright 2020 Ad Aures
|
2020-08-27 10:05:44 +00:00
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
2024-04-24 14:47:05 +00:00
|
|
|
namespace Modules\Platforms\Controllers;
|
2020-08-27 10:05:44 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
use App\Entities\Podcast;
|
2020-08-27 10:05:44 +00:00
|
|
|
use App\Models\PodcastModel;
|
2021-05-19 16:35:13 +00:00
|
|
|
use CodeIgniter\Exceptions\PageNotFoundException;
|
|
|
|
use CodeIgniter\HTTP\RedirectResponse;
|
2024-04-24 14:47:05 +00:00
|
|
|
use Modules\Admin\Controllers\BaseController;
|
|
|
|
use Modules\Platforms\Models\PlatformModel;
|
2020-08-27 10:05:44 +00:00
|
|
|
|
2024-04-24 14:47:05 +00:00
|
|
|
class PlatformController extends BaseController
|
2020-08-27 10:05:44 +00:00
|
|
|
{
|
2024-04-24 14:47:05 +00:00
|
|
|
protected Podcast $podcast;
|
2020-08-27 10:05:44 +00:00
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function _remap(string $method, string ...$params): mixed
|
2020-08-27 10:05:44 +00:00
|
|
|
{
|
2021-08-11 15:47:23 +00:00
|
|
|
if ($params === []) {
|
2021-05-19 16:35:13 +00:00
|
|
|
return $this->{$method}();
|
2021-05-06 14:00:48 +00:00
|
|
|
}
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
if (
|
2024-04-24 14:47:05 +00:00
|
|
|
! ($podcast = (new PodcastModel())->getPodcastById((int) $params[0])) instanceof Podcast
|
2021-05-14 17:59:35 +00:00
|
|
|
) {
|
2024-04-24 14:47:05 +00:00
|
|
|
throw PageNotFoundException::forPageNotFound();
|
2020-08-27 10:05:44 +00:00
|
|
|
}
|
|
|
|
|
2024-04-24 14:47:05 +00:00
|
|
|
$this->podcast = $podcast;
|
|
|
|
|
|
|
|
unset($params[0]);
|
|
|
|
return $this->{$method}(...$params);
|
2020-08-27 10:05:44 +00:00
|
|
|
}
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function index(): string
|
2020-08-27 10:05:44 +00:00
|
|
|
{
|
2024-04-24 14:47:05 +00:00
|
|
|
return view('podcast/platforms/dashboard');
|
2020-08-27 10:05:44 +00:00
|
|
|
}
|
|
|
|
|
2024-12-18 16:05:25 +00:00
|
|
|
public function list(string $platformType): string
|
2020-08-27 10:05:44 +00:00
|
|
|
{
|
|
|
|
helper('form');
|
|
|
|
|
|
|
|
$data = [
|
2023-06-12 14:47:38 +00:00
|
|
|
'podcast' => $this->podcast,
|
2020-11-18 17:17:56 +00:00
|
|
|
'platformType' => $platformType,
|
2024-04-24 14:47:05 +00:00
|
|
|
'platforms' => (new PlatformModel())->getPlatformsWithData($this->podcast->id, $platformType),
|
2020-08-27 10:05:44 +00:00
|
|
|
];
|
|
|
|
|
2024-12-17 15:06:08 +00:00
|
|
|
$this->setHtmlHead(lang("Platforms.title.{$platformType}"));
|
2021-05-19 16:35:13 +00:00
|
|
|
replace_breadcrumb_params([
|
2022-10-15 11:22:08 +00:00
|
|
|
0 => $this->podcast->at_handle,
|
2021-05-19 16:35:13 +00:00
|
|
|
]);
|
2021-09-02 16:34:25 +00:00
|
|
|
return view('podcast/platforms', $data);
|
2020-08-27 10:05:44 +00:00
|
|
|
}
|
|
|
|
|
2024-12-18 16:05:25 +00:00
|
|
|
public function updateAction(string $platformType): RedirectResponse
|
2021-05-19 16:35:13 +00:00
|
|
|
{
|
2020-08-27 10:05:44 +00:00
|
|
|
$platformModel = new PlatformModel();
|
2024-12-29 16:02:08 +00:00
|
|
|
$validation = service('validation');
|
2020-08-27 10:05:44 +00:00
|
|
|
|
2024-04-24 14:47:05 +00:00
|
|
|
$platformsData = [];
|
2020-08-27 10:05:44 +00:00
|
|
|
foreach (
|
2024-07-01 16:14:12 +00:00
|
|
|
$this->request->getPost('platforms') as $platformSlug => $podcastPlatform
|
2020-08-27 10:05:44 +00:00
|
|
|
) {
|
2022-11-01 15:15:39 +00:00
|
|
|
$podcastPlatformUrl = trim((string) $podcastPlatform['url']);
|
2024-04-28 16:39:01 +00:00
|
|
|
if ($podcastPlatformUrl === '') {
|
2021-05-06 14:00:48 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-03-04 14:33:48 +00:00
|
|
|
|
2022-11-03 15:37:44 +00:00
|
|
|
if (! $validation->check(htmlentities($podcastPlatformUrl), 'valid_url_strict')) {
|
2021-05-06 14:00:48 +00:00
|
|
|
continue;
|
2020-08-27 10:05:44 +00:00
|
|
|
}
|
2022-03-04 14:33:48 +00:00
|
|
|
|
2022-11-01 15:15:39 +00:00
|
|
|
$podcastPlatformAccountId = trim((string) $podcastPlatform['account_id']);
|
2024-04-24 14:47:05 +00:00
|
|
|
$platformsData[] = [
|
|
|
|
'podcast_id' => $this->podcast->id,
|
|
|
|
'type' => $platformType,
|
|
|
|
'slug' => $platformSlug,
|
|
|
|
'link_url' => $podcastPlatformUrl,
|
|
|
|
'account_id' => $podcastPlatformAccountId === '' ? null : $podcastPlatformAccountId,
|
|
|
|
'is_visible' => array_key_exists('visible', $podcastPlatform) &&
|
2021-05-19 16:35:13 +00:00
|
|
|
$podcastPlatform['visible'] === 'yes',
|
2021-05-06 14:00:48 +00:00
|
|
|
];
|
2020-08-27 10:05:44 +00:00
|
|
|
}
|
|
|
|
|
2024-04-24 14:47:05 +00:00
|
|
|
$platformModel->savePlatforms($this->podcast->id, $platformType, $platformsData);
|
2020-08-27 10:05:44 +00:00
|
|
|
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->with('message', lang('Platforms.messages.updateSuccess'));
|
|
|
|
}
|
|
|
|
|
2024-12-18 16:05:25 +00:00
|
|
|
public function removeAction(string $platformType, string $platformSlug): RedirectResponse
|
2021-05-19 16:35:13 +00:00
|
|
|
{
|
2024-04-24 14:47:05 +00:00
|
|
|
(new PlatformModel())->removePlatform($this->podcast->id, $platformType, $platformSlug);
|
2020-08-27 10:05:44 +00:00
|
|
|
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->with('message', lang('Platforms.messages.removeLinkSuccess'));
|
|
|
|
}
|
|
|
|
}
|