2020-07-10 12:20:25 +00:00
|
|
|
<?php
|
2020-08-04 11:25:22 +00:00
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-07-10 12:20:25 +00:00
|
|
|
/**
|
2022-02-19 16:06:11 +00:00
|
|
|
* @copyright 2020 Ad Aures
|
2020-07-10 12:20:25 +00:00
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
2020-08-04 11:25:22 +00:00
|
|
|
|
2021-08-23 11:05:16 +00:00
|
|
|
namespace Modules\Admin\Controllers;
|
2020-07-10 12:20:25 +00:00
|
|
|
|
2023-04-14 11:11:53 +00:00
|
|
|
use App\Entities\Actor;
|
2021-05-17 17:11:23 +00:00
|
|
|
use App\Entities\Location;
|
2021-05-12 14:00:25 +00:00
|
|
|
use App\Entities\Podcast;
|
2022-07-05 16:39:20 +00:00
|
|
|
use App\Entities\Post;
|
2022-01-20 14:51:31 +00:00
|
|
|
use App\Models\ActorModel;
|
2020-07-10 12:20:25 +00:00
|
|
|
use App\Models\CategoryModel;
|
2021-05-19 16:35:13 +00:00
|
|
|
use App\Models\EpisodeModel;
|
2020-07-10 12:20:25 +00:00
|
|
|
use App\Models\LanguageModel;
|
|
|
|
use App\Models\PodcastModel;
|
2022-07-05 16:39:20 +00:00
|
|
|
use App\Models\PostModel;
|
2021-05-19 16:35:13 +00:00
|
|
|
use CodeIgniter\Exceptions\PageNotFoundException;
|
2021-05-12 14:00:25 +00:00
|
|
|
use CodeIgniter\HTTP\RedirectResponse;
|
2022-07-05 16:39:20 +00:00
|
|
|
use CodeIgniter\I18n\Time;
|
2022-06-07 11:13:06 +00:00
|
|
|
use Modules\Analytics\Models\AnalyticsPodcastByCountryModel;
|
|
|
|
use Modules\Analytics\Models\AnalyticsPodcastByEpisodeModel;
|
|
|
|
use Modules\Analytics\Models\AnalyticsPodcastByHourModel;
|
|
|
|
use Modules\Analytics\Models\AnalyticsPodcastByPlayerModel;
|
|
|
|
use Modules\Analytics\Models\AnalyticsPodcastByRegionModel;
|
|
|
|
use Modules\Analytics\Models\AnalyticsPodcastModel;
|
|
|
|
use Modules\Analytics\Models\AnalyticsWebsiteByBrowserModel;
|
|
|
|
use Modules\Analytics\Models\AnalyticsWebsiteByEntryPageModel;
|
|
|
|
use Modules\Analytics\Models\AnalyticsWebsiteByRefererModel;
|
2023-05-09 07:47:54 +00:00
|
|
|
use Modules\Media\Entities\Image;
|
2023-03-30 13:23:10 +00:00
|
|
|
use Modules\Media\FileManagers\FileManagerInterface;
|
2023-03-16 13:00:05 +00:00
|
|
|
use Modules\Media\Models\MediaModel;
|
2020-07-10 12:20:25 +00:00
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
class PodcastController extends BaseController
|
2020-07-10 12:20:25 +00:00
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
protected Podcast $podcast;
|
2020-07-10 12:20:25 +00:00
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function _remap(string $method, string ...$params): mixed
|
2020-07-10 12:20:25 +00:00
|
|
|
{
|
2021-08-11 15:47:23 +00:00
|
|
|
if ($params === []) {
|
2021-05-19 16:35:13 +00:00
|
|
|
return $this->{$method}();
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
if (
|
2023-04-14 11:11:53 +00:00
|
|
|
($podcast = (new PodcastModel())->getPodcastById((int) $params[0])) instanceof Podcast
|
2021-05-14 17:59:35 +00:00
|
|
|
) {
|
2021-06-10 08:14:06 +00:00
|
|
|
$this->podcast = $podcast;
|
2021-05-19 16:35:13 +00:00
|
|
|
return $this->{$method}();
|
2021-05-06 14:00:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
throw PageNotFoundException::forPageNotFound();
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
public function list(): string
|
2020-07-31 16:05:10 +00:00
|
|
|
{
|
2022-10-15 11:22:08 +00:00
|
|
|
if (auth()->user()->can('podcasts.view')) {
|
2020-08-18 16:31:28 +00:00
|
|
|
$data = [
|
2022-10-15 11:22:08 +00:00
|
|
|
'podcasts' => (new PodcastModel())->findAll(),
|
2020-08-18 16:31:28 +00:00
|
|
|
];
|
|
|
|
} else {
|
2021-05-19 16:35:13 +00:00
|
|
|
$data = [
|
2022-10-15 11:22:08 +00:00
|
|
|
'podcasts' => get_user_podcasts(auth()->user()),
|
2021-05-19 16:35:13 +00:00
|
|
|
];
|
2020-07-27 09:35:34 +00:00
|
|
|
}
|
|
|
|
|
2021-09-02 16:34:25 +00:00
|
|
|
return view('podcast/list', $data);
|
2020-07-16 10:08:23 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
public function view(): string
|
2020-07-10 12:20:25 +00:00
|
|
|
{
|
2021-05-19 16:35:13 +00:00
|
|
|
$data = [
|
|
|
|
'podcast' => $this->podcast,
|
|
|
|
];
|
2020-07-10 12:20:25 +00:00
|
|
|
|
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/view', $data);
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
public function viewAnalytics(): string
|
2020-10-06 15:39:27 +00:00
|
|
|
{
|
2021-05-19 16:35:13 +00:00
|
|
|
$data = [
|
|
|
|
'podcast' => $this->podcast,
|
|
|
|
];
|
2020-10-06 15:39:27 +00:00
|
|
|
|
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/analytics/index', $data);
|
2020-10-14 10:38:48 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
public function viewAnalyticsWebpages(): string
|
2020-10-14 10:38:48 +00:00
|
|
|
{
|
2021-05-19 16:35:13 +00:00
|
|
|
$data = [
|
|
|
|
'podcast' => $this->podcast,
|
|
|
|
];
|
2020-10-14 10:38:48 +00:00
|
|
|
|
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/analytics/webpages', $data);
|
2020-10-14 10:38:48 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
public function viewAnalyticsLocations(): string
|
2020-10-14 10:38:48 +00:00
|
|
|
{
|
2021-05-19 16:35:13 +00:00
|
|
|
$data = [
|
|
|
|
'podcast' => $this->podcast,
|
|
|
|
];
|
2020-10-14 10:38:48 +00:00
|
|
|
|
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/analytics/locations', $data);
|
2020-10-14 10:38:48 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
public function viewAnalyticsUniqueListeners(): string
|
2020-10-14 10:38:48 +00:00
|
|
|
{
|
2021-05-19 16:35:13 +00:00
|
|
|
$data = [
|
|
|
|
'podcast' => $this->podcast,
|
|
|
|
];
|
2020-10-14 10:38:48 +00:00
|
|
|
|
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/analytics/unique_listeners', $data);
|
2020-10-14 10:38:48 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
public function viewAnalyticsListeningTime(): string
|
2020-10-19 10:33:23 +00:00
|
|
|
{
|
2021-05-19 16:35:13 +00:00
|
|
|
$data = [
|
|
|
|
'podcast' => $this->podcast,
|
|
|
|
];
|
2020-10-19 10:33:23 +00:00
|
|
|
|
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/analytics/listening_time', $data);
|
2020-10-19 10:33:23 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
public function viewAnalyticsTimePeriods(): string
|
2020-11-02 18:15:19 +00:00
|
|
|
{
|
2021-05-19 16:35:13 +00:00
|
|
|
$data = [
|
|
|
|
'podcast' => $this->podcast,
|
|
|
|
];
|
2020-11-02 18:15:19 +00:00
|
|
|
|
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/analytics/time_periods', $data);
|
2020-11-02 18:15:19 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
public function viewAnalyticsPlayers(): string
|
2020-10-14 10:38:48 +00:00
|
|
|
{
|
2021-05-19 16:35:13 +00:00
|
|
|
$data = [
|
|
|
|
'podcast' => $this->podcast,
|
|
|
|
];
|
2020-10-14 10:38:48 +00:00
|
|
|
|
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/analytics/players', $data);
|
2020-10-06 15:39:27 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
public function create(): string
|
2020-07-10 12:20:25 +00:00
|
|
|
{
|
|
|
|
helper(['form', 'misc']);
|
2020-07-16 10:08:23 +00:00
|
|
|
|
2020-09-04 09:09:26 +00:00
|
|
|
$languageOptions = (new LanguageModel())->getLanguageOptions();
|
|
|
|
$categoryOptions = (new CategoryModel())->getCategoryOptions();
|
2020-08-14 18:27:57 +00:00
|
|
|
|
2020-07-16 10:08:23 +00:00
|
|
|
$data = [
|
2020-08-14 18:27:57 +00:00
|
|
|
'languageOptions' => $languageOptions,
|
|
|
|
'categoryOptions' => $categoryOptions,
|
2023-06-12 14:47:38 +00:00
|
|
|
'browserLang' => get_browser_language($this->request->getServer('HTTP_ACCEPT_LANGUAGE')),
|
2020-07-16 10:08:23 +00:00
|
|
|
];
|
|
|
|
|
2021-09-02 16:34:25 +00:00
|
|
|
return view('podcast/create', $data);
|
2020-07-16 10:08:23 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
public function attemptCreate(): RedirectResponse
|
2020-07-16 10:08:23 +00:00
|
|
|
{
|
|
|
|
$rules = [
|
2023-06-12 14:47:38 +00:00
|
|
|
'cover' => 'uploaded[cover]|is_image[cover]|ext_in[cover,jpg,jpeg,png]|min_dims[cover,1400,1400]|is_image_ratio[cover,1,1]',
|
2023-03-21 18:06:54 +00:00
|
|
|
'banner' => 'is_image[banner]|ext_in[banner,jpg,jpeg,png]|min_dims[banner,1500,500]|is_image_ratio[banner,3,1]',
|
2020-07-16 10:08:23 +00:00
|
|
|
];
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! $this->validate($rules)) {
|
2020-07-16 10:08:23 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
|
|
|
|
2021-12-20 17:12:12 +00:00
|
|
|
$db = db_connect();
|
|
|
|
$db->transStart();
|
|
|
|
|
2021-12-14 16:41:10 +00:00
|
|
|
$newPodcast = new Podcast([
|
2023-06-21 16:17:11 +00:00
|
|
|
'created_by' => user_id(),
|
|
|
|
'updated_by' => user_id(),
|
2023-06-12 14:47:38 +00:00
|
|
|
'title' => $this->request->getPost('title'),
|
|
|
|
'handle' => $this->request->getPost('handle'),
|
|
|
|
'cover' => $this->request->getFile('cover'),
|
|
|
|
'banner' => $this->request->getFile('banner'),
|
2020-10-29 15:45:19 +00:00
|
|
|
'description_markdown' => $this->request->getPost('description'),
|
2023-06-12 14:47:38 +00:00
|
|
|
'language_code' => $this->request->getPost('language'),
|
|
|
|
'category_id' => $this->request->getPost('category'),
|
|
|
|
'parental_advisory' => $this->request->getPost('parental_advisory') !== 'undefined'
|
2020-10-02 15:38:16 +00:00
|
|
|
? $this->request->getPost('parental_advisory')
|
|
|
|
: null,
|
2024-01-01 10:11:29 +00:00
|
|
|
'owner_name' => $this->request->getPost('owner_name'),
|
|
|
|
'owner_email' => $this->request->getPost('owner_email'),
|
|
|
|
'is_owner_email_removed_from_feed' => $this->request->getPost('is_owner_email_removed_from_feed') === 'yes',
|
|
|
|
'publisher' => $this->request->getPost('publisher'),
|
|
|
|
'type' => $this->request->getPost('type'),
|
2024-02-05 16:51:04 +00:00
|
|
|
'medium' => $this->request->getPost('medium'),
|
2024-01-01 10:11:29 +00:00
|
|
|
'copyright' => $this->request->getPost('copyright'),
|
|
|
|
'location' => $this->request->getPost('location_name') === '' ? null : new Location(
|
2023-06-12 14:47:38 +00:00
|
|
|
$this->request->getPost('location_name')
|
|
|
|
),
|
2024-04-24 10:03:20 +00:00
|
|
|
'verify_txt' => $this->request->getPost('verify_txt'),
|
2023-06-12 14:47:38 +00:00
|
|
|
'custom_rss_string' => $this->request->getPost('custom_rss'),
|
|
|
|
'is_blocked' => $this->request->getPost('block') === 'yes',
|
|
|
|
'is_completed' => $this->request->getPost('complete') === 'yes',
|
|
|
|
'is_locked' => $this->request->getPost('lock') === 'yes',
|
2022-09-28 15:02:09 +00:00
|
|
|
'is_premium_by_default' => $this->request->getPost('premium_by_default') === 'yes',
|
2023-06-12 14:47:38 +00:00
|
|
|
'published_at' => null,
|
2020-07-16 10:08:23 +00:00
|
|
|
]);
|
|
|
|
|
2020-08-04 11:25:22 +00:00
|
|
|
$podcastModel = new PodcastModel();
|
2021-12-14 16:41:10 +00:00
|
|
|
if (! ($newPodcastId = $podcastModel->insert($newPodcast, true))) {
|
2020-10-02 15:38:16 +00:00
|
|
|
$db->transRollback();
|
2020-07-16 10:08:23 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
2020-08-04 11:25:22 +00:00
|
|
|
->with('errors', $podcastModel->errors());
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|
2020-07-16 10:08:23 +00:00
|
|
|
|
2022-10-15 11:22:08 +00:00
|
|
|
// generate podcast roles and permissions
|
|
|
|
// before setting current user as podcast admin
|
2024-04-28 16:39:01 +00:00
|
|
|
config('AuthGroups')
|
2022-10-15 11:22:08 +00:00
|
|
|
->generatePodcastAuthorizations($newPodcastId);
|
|
|
|
add_podcast_group(auth()->user(), (int) $newPodcastId, setting('AuthGroups.mostPowerfulPodcastGroup'));
|
2020-07-16 10:08:23 +00:00
|
|
|
|
2020-10-02 15:38:16 +00:00
|
|
|
// set Podcast categories
|
|
|
|
(new CategoryModel())->setPodcastCategories(
|
2021-05-12 14:00:25 +00:00
|
|
|
(int) $newPodcastId,
|
2021-05-25 18:00:09 +00:00
|
|
|
$this->request->getPost('other_categories') ?? [],
|
2020-10-02 15:38:16 +00:00
|
|
|
);
|
|
|
|
|
2022-12-09 15:04:42 +00:00
|
|
|
// OP3
|
|
|
|
service('settings')
|
|
|
|
->set('Analytics.enableOP3', $this->request->getPost('enable_op3') === 'yes', 'podcast:' . $newPodcastId);
|
|
|
|
|
2020-07-16 10:08:23 +00:00
|
|
|
$db->transComplete();
|
|
|
|
|
2022-01-05 14:58:53 +00:00
|
|
|
return redirect()->route('podcast-view', [$newPodcastId])->with(
|
|
|
|
'message',
|
|
|
|
lang('Podcast.messages.createSuccess')
|
|
|
|
);
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
public function edit(): string
|
2020-07-10 12:20:25 +00:00
|
|
|
{
|
2020-07-16 10:08:23 +00:00
|
|
|
helper('form');
|
2020-07-10 12:20:25 +00:00
|
|
|
|
2020-09-04 09:09:26 +00:00
|
|
|
$languageOptions = (new LanguageModel())->getLanguageOptions();
|
|
|
|
$categoryOptions = (new CategoryModel())->getCategoryOptions();
|
2020-08-14 18:27:57 +00:00
|
|
|
|
2020-07-16 10:08:23 +00:00
|
|
|
$data = [
|
2023-06-12 14:47:38 +00:00
|
|
|
'podcast' => $this->podcast,
|
2020-08-14 18:27:57 +00:00
|
|
|
'languageOptions' => $languageOptions,
|
|
|
|
'categoryOptions' => $categoryOptions,
|
2020-07-16 10:08:23 +00:00
|
|
|
];
|
2020-07-10 12:20:25 +00:00
|
|
|
|
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/edit', $data);
|
2020-07-16 10:08:23 +00:00
|
|
|
}
|
2020-07-10 12:20:25 +00:00
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
public function attemptEdit(): RedirectResponse
|
2020-07-16 10:08:23 +00:00
|
|
|
{
|
|
|
|
$rules = [
|
2023-06-12 14:47:38 +00:00
|
|
|
'cover' => 'is_image[cover]|ext_in[cover,jpg,jpeg,png]|min_dims[cover,1400,1400]|is_image_ratio[cover,1,1]',
|
2023-03-21 18:06:54 +00:00
|
|
|
'banner' => 'is_image[banner]|ext_in[banner,jpg,jpeg,png]|min_dims[banner,1500,500]|is_image_ratio[banner,3,1]',
|
2020-07-16 10:08:23 +00:00
|
|
|
];
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! $this->validate($rules)) {
|
2020-07-16 10:08:23 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
|
|
|
|
2023-06-21 16:17:11 +00:00
|
|
|
$this->podcast->updated_by = (int) user_id();
|
|
|
|
|
2020-07-16 10:08:23 +00:00
|
|
|
$this->podcast->title = $this->request->getPost('title');
|
2021-06-08 09:52:11 +00:00
|
|
|
$this->podcast->description_markdown = $this->request->getPost('description');
|
2021-12-17 17:14:37 +00:00
|
|
|
$this->podcast->setCover($this->request->getFile('cover'));
|
|
|
|
$this->podcast->setBanner($this->request->getFile('banner'));
|
2020-07-16 10:08:23 +00:00
|
|
|
|
2020-10-29 15:45:19 +00:00
|
|
|
$this->podcast->language_code = $this->request->getPost('language');
|
2020-08-21 08:41:09 +00:00
|
|
|
$this->podcast->category_id = $this->request->getPost('category');
|
2020-10-02 15:38:16 +00:00
|
|
|
$this->podcast->parental_advisory =
|
|
|
|
$this->request->getPost('parental_advisory') !== 'undefined'
|
|
|
|
? $this->request->getPost('parental_advisory')
|
|
|
|
: null;
|
|
|
|
$this->podcast->publisher = $this->request->getPost('publisher');
|
2020-07-16 10:08:23 +00:00
|
|
|
$this->podcast->owner_name = $this->request->getPost('owner_name');
|
|
|
|
$this->podcast->owner_email = $this->request->getPost('owner_email');
|
2024-04-28 10:16:23 +00:00
|
|
|
$this->podcast->is_owner_email_removed_from_feed = $this->request->getPost(
|
|
|
|
'is_owner_email_removed_from_feed'
|
|
|
|
) === 'yes';
|
2020-07-16 10:08:23 +00:00
|
|
|
$this->podcast->type = $this->request->getPost('type');
|
2024-02-05 16:51:04 +00:00
|
|
|
$this->podcast->medium = $this->request->getPost('medium');
|
2020-07-16 10:08:23 +00:00
|
|
|
$this->podcast->copyright = $this->request->getPost('copyright');
|
2021-06-09 17:00:18 +00:00
|
|
|
$this->podcast->location = $this->request->getPost('location_name') === '' ? null : new Location(
|
|
|
|
$this->request->getPost('location_name')
|
|
|
|
);
|
2024-04-24 10:03:20 +00:00
|
|
|
$this->podcast->verify_txt = $this->request->getPost('verify_txt') === '' ? null : $this->request->getPost(
|
|
|
|
'verify_txt'
|
|
|
|
);
|
2021-06-08 09:52:11 +00:00
|
|
|
$this->podcast->custom_rss_string = $this->request->getPost('custom_rss');
|
2022-02-09 17:44:24 +00:00
|
|
|
$this->podcast->new_feed_url = $this->request->getPost('new_feed_url') === '' ? null : $this->request->getPost(
|
|
|
|
'new_feed_url'
|
|
|
|
);
|
2023-11-16 16:24:29 +00:00
|
|
|
|
2021-02-11 19:07:30 +01:00
|
|
|
$this->podcast->is_blocked = $this->request->getPost('block') === 'yes';
|
2020-10-29 15:45:19 +00:00
|
|
|
$this->podcast->is_completed =
|
2020-10-02 15:38:16 +00:00
|
|
|
$this->request->getPost('complete') === 'yes';
|
2021-02-11 19:07:30 +01:00
|
|
|
$this->podcast->is_locked = $this->request->getPost('lock') === 'yes';
|
2022-09-28 15:02:09 +00:00
|
|
|
$this->podcast->is_premium_by_default = $this->request->getPost('premium_by_default') === 'yes';
|
2020-07-10 12:20:25 +00:00
|
|
|
|
2022-03-15 16:47:35 +00:00
|
|
|
// republish on websub hubs upon edit
|
|
|
|
$this->podcast->is_published_on_hubs = false;
|
|
|
|
|
2021-06-11 08:03:54 +00:00
|
|
|
$db = db_connect();
|
2021-12-17 17:14:37 +00:00
|
|
|
|
2020-10-02 15:38:16 +00:00
|
|
|
$db->transStart();
|
2020-07-16 10:08:23 +00:00
|
|
|
|
2020-10-02 15:38:16 +00:00
|
|
|
$podcastModel = new PodcastModel();
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! $podcastModel->update($this->podcast->id, $this->podcast)) {
|
2020-10-02 15:38:16 +00:00
|
|
|
$db->transRollback();
|
2020-07-16 10:08:23 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
2020-08-04 11:25:22 +00:00
|
|
|
->with('errors', $podcastModel->errors());
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|
2020-07-16 10:08:23 +00:00
|
|
|
|
2020-10-02 15:38:16 +00:00
|
|
|
// set Podcast categories
|
|
|
|
(new CategoryModel())->setPodcastCategories(
|
|
|
|
$this->podcast->id,
|
2021-05-25 18:00:09 +00:00
|
|
|
$this->request->getPost('other_categories') ?? [],
|
2020-10-02 15:38:16 +00:00
|
|
|
);
|
|
|
|
|
2022-12-09 15:04:42 +00:00
|
|
|
// enable/disable OP3?
|
|
|
|
service('settings')
|
|
|
|
->set(
|
|
|
|
'Analytics.enableOP3',
|
|
|
|
$this->request->getPost('enable_op3') === 'yes',
|
|
|
|
'podcast:' . $this->podcast->id
|
|
|
|
);
|
|
|
|
|
2020-10-02 15:38:16 +00:00
|
|
|
$db->transComplete();
|
|
|
|
|
2022-01-05 14:58:53 +00:00
|
|
|
return redirect()->route('podcast-edit', [$this->podcast->id])->with(
|
|
|
|
'message',
|
|
|
|
lang('Podcast.messages.editSuccess')
|
|
|
|
);
|
2020-10-02 15:38:16 +00:00
|
|
|
}
|
|
|
|
|
2023-11-16 16:24:29 +00:00
|
|
|
public function monetizationOther(): string
|
|
|
|
{
|
|
|
|
helper('form');
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'podcast' => $this->podcast,
|
|
|
|
];
|
|
|
|
|
|
|
|
replace_breadcrumb_params([
|
|
|
|
0 => $this->podcast->at_handle,
|
|
|
|
]);
|
|
|
|
return view('podcast/monetization_other', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function monetizationOtherAction(): RedirectResponse
|
|
|
|
{
|
|
|
|
if (
|
|
|
|
($partnerId = $this->request->getPost('partner_id')) === '' ||
|
|
|
|
($partnerLinkUrl = $this->request->getPost('partner_link_url')) === '' ||
|
|
|
|
($partnerImageUrl = $this->request->getPost('partner_image_url')) === '') {
|
|
|
|
$partnerId = null;
|
|
|
|
$partnerLinkUrl = null;
|
|
|
|
$partnerImageUrl = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->podcast->payment_pointer = $this->request->getPost(
|
|
|
|
'payment_pointer'
|
|
|
|
) === '' ? null : $this->request->getPost('payment_pointer');
|
|
|
|
|
|
|
|
$this->podcast->partner_id = $partnerId;
|
|
|
|
$this->podcast->partner_link_url = $partnerLinkUrl;
|
|
|
|
$this->podcast->partner_image_url = $partnerImageUrl;
|
|
|
|
|
|
|
|
$podcastModel = new PodcastModel();
|
|
|
|
if (! $podcastModel->update($this->podcast->id, $this->podcast)) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $podcastModel->errors());
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect()->route('podcast-monetization-other', [$this->podcast->id])->with(
|
|
|
|
'message',
|
|
|
|
lang('Podcast.messages.editSuccess')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-11-01 17:12:03 +00:00
|
|
|
public function deleteBanner(): RedirectResponse
|
|
|
|
{
|
2023-05-09 07:47:54 +00:00
|
|
|
if (! $this->podcast->banner instanceof Image) {
|
2021-11-01 17:12:03 +00:00
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
|
2022-01-20 14:51:31 +00:00
|
|
|
$db = db_connect();
|
|
|
|
|
|
|
|
$db->transStart();
|
|
|
|
|
2021-12-17 17:14:37 +00:00
|
|
|
$mediaModel = new MediaModel();
|
2021-12-20 17:12:12 +00:00
|
|
|
if (! $mediaModel->deleteMedia($this->podcast->banner)) {
|
2021-11-01 17:12:03 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
2021-12-17 17:14:37 +00:00
|
|
|
->with('errors', $mediaModel->errors());
|
2021-11-01 17:12:03 +00:00
|
|
|
}
|
2022-03-04 14:33:48 +00:00
|
|
|
|
2022-01-23 16:02:24 +00:00
|
|
|
(new PodcastModel())->clearCache([
|
|
|
|
'id' => $this->podcast->id,
|
|
|
|
]);
|
2021-11-01 17:12:03 +00:00
|
|
|
|
2022-01-20 14:51:31 +00:00
|
|
|
// remove banner url from actor
|
|
|
|
$actor = (new ActorModel())->getActorById($this->podcast->actor_id);
|
|
|
|
|
2023-04-14 11:11:53 +00:00
|
|
|
if ($actor instanceof Actor) {
|
2022-01-20 14:51:31 +00:00
|
|
|
$actor->cover_image_url = null;
|
|
|
|
$actor->cover_image_mimetype = null;
|
|
|
|
|
|
|
|
(new ActorModel())->update($actor->id, $actor);
|
|
|
|
}
|
|
|
|
|
|
|
|
$db->transComplete();
|
|
|
|
|
2021-11-01 17:12:03 +00:00
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
|
2021-09-02 16:34:25 +00:00
|
|
|
public function latestEpisodes(int $limit, int $podcastId): string
|
2020-10-02 15:38:16 +00:00
|
|
|
{
|
|
|
|
$episodes = (new EpisodeModel())
|
2021-09-02 16:34:25 +00:00
|
|
|
->where('podcast_id', $podcastId)
|
2022-10-18 17:25:49 +00:00
|
|
|
->orderBy('-`published_at`', '', false)
|
2020-10-02 15:38:16 +00:00
|
|
|
->orderBy('created_at', 'desc')
|
|
|
|
->findAll($limit);
|
|
|
|
|
2021-09-02 16:34:25 +00:00
|
|
|
return view('podcast/latest_episodes', [
|
2021-05-19 16:35:13 +00:00
|
|
|
'episodes' => $episodes,
|
2023-06-12 14:47:38 +00:00
|
|
|
'podcast' => (new PodcastModel())->getPodcastById($podcastId),
|
2021-05-19 16:35:13 +00:00
|
|
|
]);
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|
|
|
|
|
2022-06-07 11:13:06 +00:00
|
|
|
public function delete(): string
|
2020-07-10 12:20:25 +00:00
|
|
|
{
|
2022-06-07 11:13:06 +00:00
|
|
|
helper(['form']);
|
2020-07-10 12:20:25 +00:00
|
|
|
|
2022-06-07 11:13:06 +00:00
|
|
|
$data = [
|
|
|
|
'podcast' => $this->podcast,
|
|
|
|
];
|
|
|
|
|
|
|
|
replace_breadcrumb_params([
|
2022-10-15 11:22:08 +00:00
|
|
|
0 => $this->podcast->at_handle,
|
2022-06-07 11:13:06 +00:00
|
|
|
]);
|
|
|
|
return view('podcast/delete', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function attemptDelete(): RedirectResponse
|
|
|
|
{
|
|
|
|
$rules = [
|
|
|
|
'understand' => 'required',
|
|
|
|
];
|
|
|
|
|
|
|
|
if (! $this->validate($rules)) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
|
|
|
|
|
|
|
$db = db_connect();
|
|
|
|
|
|
|
|
$db->transStart();
|
|
|
|
|
|
|
|
//delete podcast episodes
|
|
|
|
$podcastEpisodes = (new EpisodeModel())->where('podcast_id', $this->podcast->id)
|
|
|
|
->findAll();
|
|
|
|
|
|
|
|
foreach ($podcastEpisodes as $podcastEpisode) {
|
|
|
|
$episodeModel = new EpisodeModel();
|
|
|
|
|
|
|
|
if (! $episodeModel->delete($podcastEpisode->id)) {
|
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $episodeModel->errors());
|
|
|
|
}
|
|
|
|
|
|
|
|
$episodeMediaList = [$podcastEpisode->transcript, $podcastEpisode->chapters, $podcastEpisode->audio];
|
|
|
|
|
|
|
|
//only delete episode cover if different from podcast's
|
|
|
|
if ($podcastEpisode->cover_id !== null) {
|
|
|
|
$episodeMediaList[] = $podcastEpisode->cover;
|
|
|
|
}
|
|
|
|
|
2023-03-30 13:23:10 +00:00
|
|
|
$mediaModel = new MediaModel();
|
|
|
|
|
2022-06-07 11:13:06 +00:00
|
|
|
foreach ($episodeMediaList as $episodeMedia) {
|
2023-03-30 13:23:10 +00:00
|
|
|
if ($episodeMedia !== null && ! $mediaModel->delete($episodeMedia->id)) {
|
2022-06-07 11:13:06 +00:00
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('error', lang('Podcast.messages.deleteEpisodeMediaError', [
|
|
|
|
'episode_slug' => $podcastEpisode->slug,
|
2023-06-12 14:47:38 +00:00
|
|
|
'type' => $episodeMedia->type,
|
2022-06-07 11:13:06 +00:00
|
|
|
]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//delete podcast
|
|
|
|
$podcastModel = new PodcastModel();
|
|
|
|
|
|
|
|
if (! $podcastModel->delete($this->podcast->id)) {
|
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $podcastModel->errors());
|
|
|
|
}
|
|
|
|
|
|
|
|
//delete podcast media
|
|
|
|
$podcastMediaList = [
|
|
|
|
[
|
|
|
|
'type' => 'cover',
|
|
|
|
'file' => $this->podcast->cover,
|
|
|
|
],
|
2022-06-13 16:30:34 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
if ($this->podcast->banner_id !== null) {
|
|
|
|
$podcastMediaList[] =
|
2022-06-07 11:13:06 +00:00
|
|
|
[
|
|
|
|
'type' => 'banner',
|
|
|
|
'file' => $this->podcast->banner,
|
2022-06-13 16:30:34 +00:00
|
|
|
];
|
|
|
|
}
|
2022-06-07 11:13:06 +00:00
|
|
|
|
2023-03-30 13:23:10 +00:00
|
|
|
$mediaModel = new MediaModel();
|
|
|
|
|
2022-06-07 11:13:06 +00:00
|
|
|
foreach ($podcastMediaList as $podcastMedia) {
|
2023-05-09 07:47:54 +00:00
|
|
|
if ($podcastMedia['file'] instanceof Image && ! $mediaModel->delete($podcastMedia['file']->id)) {
|
2022-06-07 11:13:06 +00:00
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('error', lang('Podcast.messages.deletePodcastMediaError', [
|
|
|
|
'type' => $podcastMedia['type'],
|
|
|
|
]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//delete podcast actor
|
|
|
|
$actorModel = new ActorModel();
|
|
|
|
|
|
|
|
if (! $actorModel->delete($this->podcast->actor_id)) {
|
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $actorModel->errors());
|
|
|
|
}
|
|
|
|
|
|
|
|
//delete podcast analytics
|
|
|
|
$analyticsModels = [
|
|
|
|
new AnalyticsPodcastModel(),
|
|
|
|
new AnalyticsPodcastByCountryModel(),
|
|
|
|
new AnalyticsPodcastByEpisodeModel(),
|
|
|
|
new AnalyticsPodcastByHourModel(),
|
|
|
|
new AnalyticsPodcastByPlayerModel(),
|
|
|
|
new AnalyticsPodcastByRegionModel(),
|
|
|
|
new AnalyticsWebsiteByBrowserModel(),
|
|
|
|
new AnalyticsWebsiteByEntryPageModel(),
|
|
|
|
new AnalyticsWebsiteByRefererModel(),
|
|
|
|
];
|
|
|
|
foreach ($analyticsModels as $analyticsModel) {
|
|
|
|
if (! $analyticsModel->where([
|
|
|
|
'podcast_id' => $this->podcast->id,
|
|
|
|
])->delete()) {
|
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $analyticsModel->errors());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$db->transComplete();
|
|
|
|
|
2023-03-30 13:23:10 +00:00
|
|
|
/** @var FileManagerInterface $fileManager */
|
|
|
|
$fileManager = service('file_manager');
|
|
|
|
|
2022-06-07 11:13:06 +00:00
|
|
|
//delete podcast media files and folder
|
|
|
|
$folder = 'podcasts/' . $this->podcast->handle;
|
2023-03-30 13:23:10 +00:00
|
|
|
if (! $fileManager->deleteAll($folder)) {
|
2022-06-07 11:13:06 +00:00
|
|
|
return redirect()->route('podcast-list')
|
|
|
|
->with('message', lang('Podcast.messages.deleteSuccess', [
|
|
|
|
'podcast_handle' => $this->podcast->handle,
|
|
|
|
]))
|
|
|
|
->with('warning', lang('Podcast.messages.deletePodcastMediaFolderError', [
|
|
|
|
'folder_path' => $folder,
|
|
|
|
]));
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect()->route('podcast-list')
|
|
|
|
->with('message', lang('Podcast.messages.deleteSuccess', [
|
|
|
|
'podcast_handle' => $this->podcast->handle,
|
|
|
|
]));
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|
2022-07-05 16:39:20 +00:00
|
|
|
|
|
|
|
public function publish(): string | RedirectResponse
|
|
|
|
{
|
|
|
|
helper(['form']);
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'podcast' => $this->podcast,
|
|
|
|
];
|
|
|
|
|
|
|
|
replace_breadcrumb_params([
|
2022-10-15 11:22:08 +00:00
|
|
|
0 => $this->podcast->at_handle,
|
2022-07-05 16:39:20 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
return view('podcast/publish', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function attemptPublish(): RedirectResponse
|
|
|
|
{
|
|
|
|
if ($this->podcast->publication_status !== 'not_published') {
|
|
|
|
return redirect()->route('podcast-view', [$this->podcast->id])->with(
|
|
|
|
'error',
|
|
|
|
lang('Podcast.messages.publishError')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$rules = [
|
2023-06-12 14:47:38 +00:00
|
|
|
'publication_method' => 'required',
|
|
|
|
'scheduled_publication_date' => 'valid_date[Y-m-d H:i]|permit_empty',
|
2022-07-05 16:39:20 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
if (! $this->validate($rules)) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
|
|
|
|
2023-08-29 15:42:52 +00:00
|
|
|
$validData = $this->validator->getValidated();
|
|
|
|
|
2022-07-05 16:39:20 +00:00
|
|
|
$db = db_connect();
|
|
|
|
$db->transStart();
|
|
|
|
|
2023-08-29 15:42:52 +00:00
|
|
|
$publishMethod = $validData['publication_method'];
|
2022-07-05 16:39:20 +00:00
|
|
|
if ($publishMethod === 'schedule') {
|
2023-08-29 15:42:52 +00:00
|
|
|
$scheduledPublicationDate = $validData['scheduled_publication_date'];
|
2022-07-05 16:39:20 +00:00
|
|
|
if ($scheduledPublicationDate) {
|
|
|
|
$this->podcast->published_at = Time::createFromFormat(
|
|
|
|
'Y-m-d H:i',
|
|
|
|
$scheduledPublicationDate,
|
|
|
|
$this->request->getPost('client_timezone'),
|
|
|
|
)->setTimezone(app_timezone());
|
|
|
|
} else {
|
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('error', lang('Podcast.messages.scheduleDateError'));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$this->podcast->published_at = Time::now();
|
|
|
|
}
|
|
|
|
|
|
|
|
$message = $this->request->getPost('message');
|
|
|
|
// only create post if message is not empty
|
|
|
|
if ($message !== '') {
|
|
|
|
$newPost = new Post([
|
2023-06-12 14:47:38 +00:00
|
|
|
'actor_id' => $this->podcast->actor_id,
|
|
|
|
'message' => $message,
|
2022-07-05 16:39:20 +00:00
|
|
|
'created_by' => user_id(),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$newPost->published_at = $this->podcast->published_at;
|
|
|
|
|
|
|
|
$postModel = new PostModel();
|
|
|
|
if (! $postModel->addPost($newPost)) {
|
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $postModel->errors());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$episodes = (new EpisodeModel())
|
|
|
|
->where('podcast_id', $this->podcast->id)
|
|
|
|
->where('published_at !=', null)
|
|
|
|
->findAll();
|
|
|
|
|
|
|
|
foreach ($episodes as $episode) {
|
|
|
|
$episode->published_at = $this->podcast->published_at->addSeconds(1);
|
|
|
|
|
|
|
|
$episodeModel = new EpisodeModel();
|
|
|
|
if (! $episodeModel->update($episode->id, $episode)) {
|
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $episodeModel->errors());
|
|
|
|
}
|
|
|
|
|
|
|
|
$post = (new PostModel())->where('episode_id', $episode->id)
|
|
|
|
->first();
|
|
|
|
|
2023-09-23 14:27:40 +00:00
|
|
|
if ($post instanceof Post) {
|
2022-07-05 16:39:20 +00:00
|
|
|
$post->published_at = $episode->published_at;
|
|
|
|
$postModel = new PostModel();
|
|
|
|
if (! $postModel->update($post->id, $post)) {
|
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $postModel->errors());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$podcastModel = new PodcastModel();
|
|
|
|
if (! $podcastModel->update($this->podcast->id, $this->podcast)) {
|
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $podcastModel->errors());
|
|
|
|
}
|
|
|
|
|
|
|
|
$db->transComplete();
|
|
|
|
|
|
|
|
return redirect()->route('podcast-view', [$this->podcast->id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function publishEdit(): string | RedirectResponse
|
|
|
|
{
|
|
|
|
helper(['form']);
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'podcast' => $this->podcast,
|
2023-06-12 14:47:38 +00:00
|
|
|
'post' => (new PostModel())
|
2022-07-05 16:39:20 +00:00
|
|
|
->where([
|
2023-06-12 14:47:38 +00:00
|
|
|
'actor_id' => $this->podcast->actor_id,
|
2022-07-05 16:39:20 +00:00
|
|
|
'episode_id' => null,
|
|
|
|
])
|
|
|
|
->first(),
|
|
|
|
];
|
|
|
|
|
|
|
|
replace_breadcrumb_params([
|
2022-10-15 11:22:08 +00:00
|
|
|
0 => $this->podcast->at_handle,
|
2022-07-05 16:39:20 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
return view('podcast/publish_edit', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function attemptPublishEdit(): RedirectResponse
|
|
|
|
{
|
|
|
|
if ($this->podcast->publication_status !== 'scheduled') {
|
|
|
|
return redirect()->route('podcast-view', [$this->podcast->id])->with(
|
|
|
|
'error',
|
|
|
|
lang('Podcast.messages.publishEditError')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$rules = [
|
2023-06-12 14:47:38 +00:00
|
|
|
'publication_method' => 'required',
|
|
|
|
'scheduled_publication_date' => 'valid_date[Y-m-d H:i]|permit_empty',
|
2022-07-05 16:39:20 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
if (! $this->validate($rules)) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
|
|
|
|
2023-08-29 15:42:52 +00:00
|
|
|
$validData = $this->validator->getValidated();
|
|
|
|
|
2022-07-05 16:39:20 +00:00
|
|
|
$db = db_connect();
|
|
|
|
$db->transStart();
|
|
|
|
|
2023-08-29 15:42:52 +00:00
|
|
|
$publishMethod = $validData['publication_method'];
|
2022-07-05 16:39:20 +00:00
|
|
|
if ($publishMethod === 'schedule') {
|
2023-08-29 15:42:52 +00:00
|
|
|
$scheduledPublicationDate = $validData['scheduled_publication_date'];
|
2022-07-05 16:39:20 +00:00
|
|
|
if ($scheduledPublicationDate) {
|
|
|
|
$this->podcast->published_at = Time::createFromFormat(
|
|
|
|
'Y-m-d H:i',
|
|
|
|
$scheduledPublicationDate,
|
|
|
|
$this->request->getPost('client_timezone'),
|
|
|
|
)->setTimezone(app_timezone());
|
|
|
|
} else {
|
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('error', lang('Podcast.messages.scheduleDateError'));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$this->podcast->published_at = Time::now();
|
|
|
|
}
|
|
|
|
|
|
|
|
$post = (new PostModel())
|
|
|
|
->where([
|
2023-06-12 14:47:38 +00:00
|
|
|
'actor_id' => $this->podcast->actor_id,
|
2022-07-05 16:39:20 +00:00
|
|
|
'episode_id' => null,
|
|
|
|
])
|
|
|
|
->first();
|
|
|
|
|
|
|
|
$newPostMessage = $this->request->getPost('message');
|
|
|
|
|
2023-09-23 14:27:40 +00:00
|
|
|
if ($post instanceof Post) {
|
2022-07-05 16:39:20 +00:00
|
|
|
if ($newPostMessage !== '') {
|
|
|
|
// edit post if post exists and message is not empty
|
|
|
|
$post->message = $newPostMessage;
|
|
|
|
$post->published_at = $this->podcast->published_at;
|
|
|
|
|
|
|
|
$postModel = new PostModel();
|
|
|
|
if (! $postModel->editPost($post)) {
|
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $postModel->errors());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// remove post if post exists and message is empty
|
|
|
|
$postModel = new PostModel();
|
|
|
|
$post = $postModel
|
|
|
|
->where([
|
2023-06-12 14:47:38 +00:00
|
|
|
'actor_id' => $this->podcast->actor_id,
|
2022-07-05 16:39:20 +00:00
|
|
|
'episode_id' => null,
|
|
|
|
])
|
|
|
|
->first();
|
|
|
|
$postModel->removePost($post);
|
|
|
|
}
|
|
|
|
} elseif ($newPostMessage !== '') {
|
|
|
|
// create post if there is no post and message is not empty
|
|
|
|
$newPost = new Post([
|
2023-06-12 14:47:38 +00:00
|
|
|
'actor_id' => $this->podcast->actor_id,
|
|
|
|
'message' => $newPostMessage,
|
2022-07-05 16:39:20 +00:00
|
|
|
'created_by' => user_id(),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$newPost->published_at = $this->podcast->published_at;
|
|
|
|
|
|
|
|
$postModel = new PostModel();
|
|
|
|
if (! $postModel->addPost($newPost)) {
|
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $postModel->errors());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$episodes = (new EpisodeModel())
|
|
|
|
->where('podcast_id', $this->podcast->id)
|
|
|
|
->where('published_at !=', null)
|
|
|
|
->findAll();
|
|
|
|
|
|
|
|
foreach ($episodes as $episode) {
|
|
|
|
$episode->published_at = $this->podcast->published_at->addSeconds(1);
|
|
|
|
|
|
|
|
$episodeModel = new EpisodeModel();
|
|
|
|
if (! $episodeModel->update($episode->id, $episode)) {
|
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $episodeModel->errors());
|
|
|
|
}
|
|
|
|
|
|
|
|
$post = (new PostModel())->where('episode_id', $episode->id)
|
|
|
|
->first();
|
|
|
|
|
2023-09-23 14:27:40 +00:00
|
|
|
if ($post instanceof Post) {
|
2022-07-05 16:39:20 +00:00
|
|
|
$post->published_at = $episode->published_at;
|
|
|
|
$postModel = new PostModel();
|
|
|
|
if (! $postModel->update($post->id, $post)) {
|
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $postModel->errors());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$podcastModel = new PodcastModel();
|
|
|
|
if (! $podcastModel->update($this->podcast->id, $this->podcast)) {
|
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $podcastModel->errors());
|
|
|
|
}
|
|
|
|
|
|
|
|
$db->transComplete();
|
|
|
|
|
|
|
|
return redirect()->route('podcast-view', [$this->podcast->id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function publishCancel(): RedirectResponse
|
|
|
|
{
|
|
|
|
if ($this->podcast->publication_status !== 'scheduled') {
|
|
|
|
return redirect()->route('podcast-view', [$this->podcast->id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$db = db_connect();
|
|
|
|
$db->transStart();
|
|
|
|
|
|
|
|
$postModel = new PostModel();
|
|
|
|
$post = $postModel
|
|
|
|
->where([
|
2023-06-12 14:47:38 +00:00
|
|
|
'actor_id' => $this->podcast->actor_id,
|
2022-07-05 16:39:20 +00:00
|
|
|
'episode_id' => null,
|
|
|
|
])
|
|
|
|
->first();
|
2023-09-23 14:27:40 +00:00
|
|
|
if ($post instanceof Post) {
|
2022-07-05 16:39:20 +00:00
|
|
|
$postModel->removePost($post);
|
|
|
|
}
|
|
|
|
|
|
|
|
$episodes = (new EpisodeModel())
|
|
|
|
->where('podcast_id', $this->podcast->id)
|
|
|
|
->where('published_at !=', null)
|
|
|
|
->findAll();
|
|
|
|
|
|
|
|
foreach ($episodes as $episode) {
|
|
|
|
$episode->published_at = null;
|
|
|
|
|
|
|
|
$episodeModel = new EpisodeModel();
|
|
|
|
if (! $episodeModel->update($episode->id, $episode)) {
|
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $episodeModel->errors());
|
|
|
|
}
|
|
|
|
|
|
|
|
$postModel = new PostModel();
|
|
|
|
$post = $postModel->where('episode_id', $episode->id)
|
|
|
|
->first();
|
|
|
|
$postModel->removePost($post);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->podcast->published_at = null;
|
|
|
|
|
|
|
|
$podcastModel = new PodcastModel();
|
|
|
|
if (! $podcastModel->update($this->podcast->id, $this->podcast)) {
|
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $podcastModel->errors());
|
|
|
|
}
|
|
|
|
|
|
|
|
$db->transComplete();
|
|
|
|
|
|
|
|
return redirect()->route('podcast-view', [$this->podcast->id])->with(
|
|
|
|
'message',
|
|
|
|
lang('Podcast.messages.publishCancelSuccess')
|
|
|
|
);
|
|
|
|
}
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|