diff --git a/app/Controllers/Admin/ContributorController.php b/app/Controllers/Admin/ContributorController.php index d09ed1c4c509fa38b0d79efaeceaa2bc6bce9324..fb2acb95cb0a20275f1a15ed8b7da5808994a549 100644 --- a/app/Controllers/Admin/ContributorController.php +++ b/app/Controllers/Admin/ContributorController.php @@ -107,9 +107,9 @@ class ContributorController extends BaseController { try { (new PodcastModel())->addPodcastContributor( - $this->request->getPost('user'), + (int) $this->request->getPost('user'), $this->podcast->id, - $this->request->getPost('role'), + (int) $this->request->getPost('role'), ); } catch (Exception) { return redirect() @@ -157,7 +157,7 @@ class ContributorController extends BaseController (new PodcastModel())->updatePodcastContributor( $this->user->id, $this->podcast->id, - $this->request->getPost('role'), + (int) $this->request->getPost('role'), ); return redirect()->route('contributor-list', [$this->podcast->id]); diff --git a/app/Controllers/Admin/EpisodeController.php b/app/Controllers/Admin/EpisodeController.php index 2bef93fe999b1fa9bc32bacf70dd612bc93d793f..df6c21ee0b7a9ec1850fb2e009a8747fcc5f984f 100644 --- a/app/Controllers/Admin/EpisodeController.php +++ b/app/Controllers/Admin/EpisodeController.php @@ -661,8 +661,8 @@ class EpisodeController extends BaseController $data = [ 'podcast_id' => $this->podcast->id, 'episode_id' => $this->episode->id, - 'start_time' => (int) $soundbite['start_time'], - 'duration' => (int) $soundbite['duration'], + 'start_time' => (float) $soundbite['start_time'], + 'duration' => (float) $soundbite['duration'], 'label' => $soundbite['label'], 'updated_by' => user_id(), ]; @@ -688,9 +688,9 @@ class EpisodeController extends BaseController return redirect()->route('soundbites-edit', [$this->podcast->id, $this->episode->id]); } - public function soundbiteDelete(int $soundbiteId): RedirectResponse + public function soundbiteDelete(string $soundbiteId): RedirectResponse { - (new SoundbiteModel())->deleteSoundbite($this->podcast->id, $this->episode->id, $soundbiteId); + (new SoundbiteModel())->deleteSoundbite($this->podcast->id, $this->episode->id, (int) $soundbiteId); return redirect()->route('soundbites-edit', [$this->podcast->id, $this->episode->id]); } diff --git a/app/Controllers/Admin/EpisodePersonController.php b/app/Controllers/Admin/EpisodePersonController.php index 50289a7a2d90f7f2bf9cc674b9dba016d369fb23..fd54851bc3f577bef03cfae529162ca460d3dd69 100644 --- a/app/Controllers/Admin/EpisodePersonController.php +++ b/app/Controllers/Admin/EpisodePersonController.php @@ -88,9 +88,9 @@ class EpisodePersonController extends BaseController return redirect()->back(); } - public function remove(int $personId): RedirectResponse + public function remove(string $personId): RedirectResponse { - (new PersonModel())->removePersonFromEpisode($this->podcast->id, $this->episode->id, $personId); + (new PersonModel())->removePersonFromEpisode($this->podcast->id, $this->episode->id, (int) $personId); return redirect()->back(); } diff --git a/app/Controllers/Admin/PodcastController.php b/app/Controllers/Admin/PodcastController.php index f68ef5e3fe1983906491b2c12af59202aeca64d9..ac7464f0bab67d3ae1ad71012d08e920264a0ee1 100644 --- a/app/Controllers/Admin/PodcastController.php +++ b/app/Controllers/Admin/PodcastController.php @@ -182,6 +182,15 @@ class PodcastController extends BaseController ->with('errors', $this->validator->getErrors()); } + 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; + } + $podcast = new Podcast([ 'title' => $this->request->getPost('title'), 'name' => $this->request->getPost('name'), @@ -199,11 +208,13 @@ class PodcastController extends BaseController 'type' => $this->request->getPost('type'), 'copyright' => $this->request->getPost('copyright'), 'location' => new Location($this->request->getPost('location_name'),), - 'payment_pointer' => $this->request->getPost('payment_pointer'), + 'payment_pointer' => $this->request->getPost( + 'payment_pointer' + ) === '' ? null : $this->request->getPost('payment_pointer'), 'custom_rss_string' => $this->request->getPost('custom_rss'), - 'partner_id' => $this->request->getPost('partner_id'), - 'partner_link_url' => $this->request->getPost('partner_link_url'), - 'partner_image_url' => $this->request->getPost('partner_image_url'), + 'partner_id' => $partnerId, + 'partner_link_url' => $partnerLinkUrl, + 'partner_image_url' => $partnerImageUrl, 'is_blocked' => $this->request->getPost('block') === 'yes', 'is_completed' => $this->request->getPost('complete') === 'yes', 'is_locked' => $this->request->getPost('lock') === 'yes', @@ -227,7 +238,7 @@ class PodcastController extends BaseController $authorize = Services::authorization(); $podcastAdminGroup = $authorize->group('podcast_admin'); - $podcastModel->addPodcastContributor(user_id(), $newPodcastId, $podcastAdminGroup->id); + $podcastModel->addPodcastContributor(user_id(), $newPodcastId, (int) $podcastAdminGroup->id); // set Podcast categories (new CategoryModel())->setPodcastCategories( @@ -277,6 +288,15 @@ class PodcastController extends BaseController ->with('errors', $this->validator->getErrors()); } + 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->title = $this->request->getPost('title'); $this->podcast->description_markdown = $this->request->getPost('description'); @@ -296,11 +316,13 @@ class PodcastController extends BaseController $this->podcast->type = $this->request->getPost('type'); $this->podcast->copyright = $this->request->getPost('copyright'); $this->podcast->location = new Location($this->request->getPost('location_name')); - $this->podcast->payment_pointer = $this->request->getPost('payment_pointer'); + $this->podcast->payment_pointer = $this->request->getPost( + 'payment_pointer' + ) === '' ? null : $this->request->getPost('payment_pointer'); $this->podcast->custom_rss_string = $this->request->getPost('custom_rss'); - $this->podcast->partner_id = $this->request->getPost('partner_id'); - $this->podcast->partner_link_url = $this->request->getPost('partner_link_url'); - $this->podcast->partner_image_url = $this->request->getPost('partner_image_url'); + $this->podcast->partner_id = $partnerId; + $this->podcast->partner_link_url = $partnerLinkUrl; + $this->podcast->partner_image_url = $partnerImageUrl; $this->podcast->is_blocked = $this->request->getPost('block') === 'yes'; $this->podcast->is_completed = $this->request->getPost('complete') === 'yes'; diff --git a/app/Controllers/Admin/PodcastImportController.php b/app/Controllers/Admin/PodcastImportController.php index a7962f96bb3e6a82071a46831c55a279809e2989..1a393e0de76fe723655b41869de780bbe43962c9 100644 --- a/app/Controllers/Admin/PodcastImportController.php +++ b/app/Controllers/Admin/PodcastImportController.php @@ -197,7 +197,7 @@ class PodcastImportController extends BaseController $authorize = Services::authorization(); $podcastAdminGroup = $authorize->group('podcast_admin'); - $podcastModel->addPodcastContributor(user_id(), $newPodcastId, $podcastAdminGroup->id); + $podcastModel->addPodcastContributor(user_id(), $newPodcastId, (int) $podcastAdminGroup->id); $podcastsPlatformsData = []; $platformTypes = [ @@ -218,7 +218,7 @@ class PodcastImportController extends BaseController foreach ($platformTypes as $platformType) { foreach ($platformType['elements'] as $platform) { $platformLabel = $platform->attributes()['platform']; - $platformSlug = slugify($platformLabel); + $platformSlug = slugify((string) $platformLabel); if ($platformModel->getPlatform($platformSlug) !== null) { $podcastsPlatformsData[] = [ 'platform_slug' => $platformSlug, @@ -246,7 +246,7 @@ class PodcastImportController extends BaseController 'full_name' => $fullName, 'unique_name' => slugify($fullName), 'information_url' => $podcastPerson->attributes()['href'], - 'image' => new Image(download_file($podcastPerson->attributes()['img'])), + 'image' => new Image(download_file((string) $podcastPerson->attributes()['img'])), 'created_by' => user_id(), 'updated_by' => user_id(), ]); @@ -301,7 +301,7 @@ class PodcastImportController extends BaseController $slug = slugify( $this->request->getPost('slug_field') === 'title' - ? $item->title + ? (string) $item->title : basename($item->link), ); if (in_array($slug, $slugs, true)) { @@ -342,7 +342,7 @@ class PodcastImportController extends BaseController 'guid' => $item->guid ?? null, 'title' => $item->title, 'slug' => $slug, - 'audio_file' => download_file($item->enclosure->attributes()['url'],), + 'audio_file' => download_file((string) $item->enclosure->attributes()['url'],), 'description_markdown' => $converter->convert($itemDescriptionHtml,), 'description_html' => $itemDescriptionHtml, 'image' => $episodeImage, @@ -372,7 +372,7 @@ class PodcastImportController extends BaseController 'location' => $location, 'created_by' => user_id(), 'updated_by' => user_id(), - 'published_at' => strtotime($item->pubDate), + 'published_at' => strtotime((string) $item->pubDate), ]); $episodeModel = new EpisodeModel(); @@ -396,7 +396,7 @@ class PodcastImportController extends BaseController 'full_name' => $fullName, 'unique_name' => slugify($fullName), 'information_url' => $episodePerson->attributes()['href'], - 'image' => new Image(download_file($episodePerson->attributes()['img'])), + 'image' => new Image(download_file((string) $episodePerson->attributes()['img'])), 'created_by' => user_id(), 'updated_by' => user_id(), ]); diff --git a/app/Controllers/Admin/PodcastPersonController.php b/app/Controllers/Admin/PodcastPersonController.php index 8bab93babe451811c1fd2dda16ea64a15779de74..00811f1838fb37e808df73572804e0defbb32f8e 100644 --- a/app/Controllers/Admin/PodcastPersonController.php +++ b/app/Controllers/Admin/PodcastPersonController.php @@ -74,9 +74,9 @@ class PodcastPersonController extends BaseController return redirect()->back(); } - public function remove(int $personId): RedirectResponse + public function remove(string $personId): RedirectResponse { - (new PersonModel())->removePersonFromPodcast($this->podcast->id, $personId); + (new PersonModel())->removePersonFromPodcast($this->podcast->id, (int) $personId); return redirect()->back(); } diff --git a/app/Controllers/Admin/PodcastPlatformController.php b/app/Controllers/Admin/PodcastPlatformController.php index a8ed9dde0de7a8d04be340e617ce179824e168d3..0f8d6b0a599156313e3193eb1c9dd833eb930233 100644 --- a/app/Controllers/Admin/PodcastPlatformController.php +++ b/app/Controllers/Admin/PodcastPlatformController.php @@ -90,9 +90,6 @@ class PodcastPlatformController extends BaseController $podcastPlatform, ) && $podcastPlatform['on_embeddable_player'] === 'yes', ]; - return redirect() - ->back() - ->with('message', lang('Platforms.messages.updateSuccess')); } $platformModel->savePodcastPlatforms($this->podcast->id, $platformType, $podcastsPlatformsData); diff --git a/app/Controllers/Admin/UserController.php b/app/Controllers/Admin/UserController.php index f6b5096b1d2e180a28214531f578c8c0dff8e3fe..508778712abff5814225734698febd0ea24ff0c0 100644 --- a/app/Controllers/Admin/UserController.php +++ b/app/Controllers/Admin/UserController.php @@ -143,7 +143,7 @@ class UserController extends BaseController $authorize = Services::authorization(); $roles = $this->request->getPost('roles'); - $authorize->setUserGroups($this->user->id, $roles); + $authorize->setUserGroups($this->user->id, $roles ?? []); // Success! return redirect() diff --git a/app/Controllers/PageController.php b/app/Controllers/PageController.php index 499dabd0f6f75d642cabb0d2f7e19d05d2d531ef..0ad1553ae1015301f30dd6d076b6aeac78688aba 100644 --- a/app/Controllers/PageController.php +++ b/app/Controllers/PageController.php @@ -16,7 +16,7 @@ use CodeIgniter\Exceptions\PageNotFoundException; class PageController extends BaseController { - protected Page $page; + protected ?Page $page = null; public function _remap(string $method, string ...$params): mixed { diff --git a/app/Database/Seeds/FakePodcastsAnalyticsSeeder.php b/app/Database/Seeds/FakePodcastsAnalyticsSeeder.php index d5a63f42353a0ead45f5f8ca28bfa94d967f7a95..b6d2b345f758c1b8bdaa1762b2cb49962e39109a 100644 --- a/app/Database/Seeds/FakePodcastsAnalyticsSeeder.php +++ b/app/Database/Seeds/FakePodcastsAnalyticsSeeder.php @@ -23,8 +23,6 @@ class FakePodcastsAnalyticsSeeder extends Seeder { public function run(): void { - $podcast = (new PodcastModel())->first(); - $jsonUserAgents = json_decode( file_get_contents('https://raw.githubusercontent.com/opawg/user-agents/master/src/user-agents.json',), true, @@ -41,13 +39,15 @@ class FakePodcastsAnalyticsSeeder extends Seeder JSON_THROW_ON_ERROR, ); - if ($podcast) { + $podcast = (new PodcastModel())->first(); + + if ($podcast !== null) { $firstEpisode = (new EpisodeModel()) ->selectMin('published_at') ->first(); for ( - $date = strtotime($firstEpisode->published_at); + $date = strtotime((string) $firstEpisode->published_at); $date < strtotime('now'); $date = strtotime(date('Y-m-d', $date) . ' +1 day') ) { @@ -63,15 +63,15 @@ class FakePodcastsAnalyticsSeeder extends Seeder ->where('`published_at` <= NOW()', null, false) ->findAll(); foreach ($episodes as $episode) { - $age = floor(($date - strtotime($episode->published_at)) / 86400); - $probability1 = (int) floor(exp(3 - $age / 40)) + 1; + $age = floor(($date - strtotime((string) $episode->published_at)) / 86400,); + $probability1 = floor(exp(3 - $age / 40)) + 1; for ( $lineNumber = 0; - $lineNumber < rand(1, $probability1); + $lineNumber < rand(1, (int) $probability1); ++$lineNumber ) { - $probability2 = (int) floor(exp(6 - $age / 20)) + 10; + $probability2 = floor(exp(6 - $age / 20)) + 10; $player = $jsonUserAgents[ @@ -97,7 +97,7 @@ class FakePodcastsAnalyticsSeeder extends Seeder '.' . rand(0, 255); - $cityReader = new Reader(WRITEPATH . 'uploads/GeoLite2-City/GeoLite2-City.mmdb'); + $cityReader = new Reader(WRITEPATH . 'uploads/GeoLite2-City/GeoLite2-City.mmdb',); $countryCode = 'N/A'; $regionCode = 'N/A'; @@ -113,13 +113,13 @@ class FakePodcastsAnalyticsSeeder extends Seeder $regionCode = $city->subdivisions === [] ? 'N/A' : $city->subdivisions[0]->isoCode; - $latitude = round($city->location->latitude, 3); - $longitude = round($city->location->longitude, 3); + $latitude = round((float) $city->location->latitude, 3); + $longitude = round((float) $city->location->longitude, 3); } catch (AddressNotFoundException) { //Bad luck, bad IP, nothing to do. } - $hits = rand(0, $probability2); + $hits = rand(0, (int) $probability2); $analyticsPodcasts[] = [ 'podcast_id' => $podcast->id, diff --git a/app/Database/Seeds/FakeWebsiteAnalyticsSeeder.php b/app/Database/Seeds/FakeWebsiteAnalyticsSeeder.php index 6dc97eea527c7951ef93eea91d9a00e6e6bf2837..ce982432d5d3fc3bcd4fe94d6cbcee075b0aaef6 100644 --- a/app/Database/Seeds/FakeWebsiteAnalyticsSeeder.php +++ b/app/Database/Seeds/FakeWebsiteAnalyticsSeeder.php @@ -189,7 +189,7 @@ class FakeWebsiteAnalyticsSeeder extends Seeder ->first(); for ( - $date = strtotime($firstEpisode->published_at); + $date = strtotime((string) $firstEpisode->published_at); $date < strtotime('now'); $date = strtotime(date('Y-m-d', $date) . ' +1 day') ) { @@ -202,7 +202,7 @@ class FakeWebsiteAnalyticsSeeder extends Seeder ->where('`published_at` <= NOW()', null, false) ->findAll(); foreach ($episodes as $episode) { - $age = floor(($date - strtotime($episode->published_at)) / 86400); + $age = floor(($date - strtotime((string) $episode->published_at)) / 86400); $probability1 = (int) floor(exp(3 - $age / 40)) + 1; for ( diff --git a/app/Libraries/ActivityPub/Controllers/BlockController.php b/app/Libraries/ActivityPub/Controllers/BlockController.php index 9c0fcafda1ce7e05caea1fe5757e53757227f918..09882421b2bc68c9e53a7339d536665b7cee35af 100644 --- a/app/Libraries/ActivityPub/Controllers/BlockController.php +++ b/app/Libraries/ActivityPub/Controllers/BlockController.php @@ -52,10 +52,10 @@ class BlockController extends Controller return redirect()->back(); } - public function attemptBlockDomain(): RedirectResponse + public function attemptUnblockActor(): RedirectResponse { $rules = [ - 'domain' => 'required', + 'actor_id' => 'required', ]; if (! $this->validate($rules)) { @@ -65,16 +65,16 @@ class BlockController extends Controller ->with('errors', $this->validator->getErrors()); } - model('BlockedDomainModel') - ->blockDomain($this->request->getPost('domain')); + model('ActorModel') + ->unblockActor((int) $this->request->getPost('actor_id')); return redirect()->back(); } - public function attemptUnblockActor(): RedirectResponse + public function attemptBlockDomain(): RedirectResponse { $rules = [ - 'actor_id' => 'required', + 'domain' => 'required', ]; if (! $this->validate($rules)) { @@ -84,8 +84,8 @@ class BlockController extends Controller ->with('errors', $this->validator->getErrors()); } - model('ActorModel') - ->unblockActor($this->request->getPost('actor_id')); + model('BlockedDomainModel') + ->blockDomain($this->request->getPost('domain')); return redirect()->back(); } diff --git a/app/Libraries/ActivityPub/Models/BlockedDomainModel.php b/app/Libraries/ActivityPub/Models/BlockedDomainModel.php index ff9bee5e361d46ff9bc45a2c6102b484a9907fc3..d5a3cccc5f1914dd02decd7ffc9a55158ae8f761 100644 --- a/app/Libraries/ActivityPub/Models/BlockedDomainModel.php +++ b/app/Libraries/ActivityPub/Models/BlockedDomainModel.php @@ -102,7 +102,7 @@ class BlockedDomainModel extends Model // set all actors from the domain as blocked model('ActorModel') ->where('domain', $name) - ->set('is_blocked', 1) + ->set('is_blocked', '1') ->update(); $result = $this->insert([ @@ -133,7 +133,7 @@ class BlockedDomainModel extends Model // unblock all actors from the domain model('ActorModel') ->where('domain', $name) - ->set('is_blocked', 0) + ->set('is_blocked', '0') ->update(); $result = $this->delete($name); diff --git a/app/Models/PageModel.php b/app/Models/PageModel.php index cb32877bbe3e2be8563779b5513c00f154d7caff..1b3b6284ee5b3ee4b6e0502bbac470b97aae5c85 100644 --- a/app/Models/PageModel.php +++ b/app/Models/PageModel.php @@ -28,7 +28,7 @@ class PageModel extends Model /** * @var string[] */ - protected $allowedFields = ['id', 'title', 'slug', 'content']; + protected $allowedFields = ['id', 'title', 'slug', 'content_markdown', 'content_html']; /** * @var string @@ -52,7 +52,7 @@ class PageModel extends Model 'title' => 'required', 'slug' => 'required|regex_match[/^[a-zA-Z0-9\-]{1,191}$/]|is_unique[pages.slug,id,{id}]', - 'content' => 'required', + 'content_markdown' => 'required', ]; /** diff --git a/app/Views/admin/page/edit.php b/app/Views/admin/page/edit.php index e12bbaad0139f41b363dfaaad5a38b3efc62d0a2..3fee95adf94c2e50124ed542649d54fa62a78ca2 100644 --- a/app/Views/admin/page/edit.php +++ b/app/Views/admin/page/edit.php @@ -45,7 +45,7 @@ 'class' => 'form-textarea', 'required' => 'required', ], - old('content', $page->content, false), + old('content', $page->content_markdown, false), 'data-editor="markdown"', ) ?> </div>