From 92536ddb3812214a9c5682b92e547e5c1998a5d7 Mon Sep 17 00:00:00 2001 From: Yassine Doghri Date: Wed, 9 Jun 2021 12:40:22 +0000 Subject: [PATCH] fix(activity-pub): get database records using new model instances update types and some remap logic --- app/Authorization/PermissionModel.php | 2 +- app/Config/Events.php | 12 +++--- .../Admin/ContributorController.php | 23 ++++++----- app/Controllers/Admin/EpisodeController.php | 10 +++-- .../Admin/EpisodePersonController.php | 2 +- app/Controllers/Admin/PersonController.php | 2 +- app/Controllers/Admin/PodcastController.php | 8 ++-- .../Admin/PodcastImportController.php | 14 +++---- .../Admin/PodcastPersonController.php | 4 +- .../Admin/PodcastPlatformController.php | 4 +- app/Controllers/EpisodeController.php | 17 ++++++--- app/Controllers/InstallController.php | 10 ++--- app/Controllers/NoteController.php | 16 +++++--- app/Controllers/PageController.php | 10 +++-- app/Controllers/PodcastController.php | 12 +++--- app/Database/Seeds/AuthSeeder.php | 2 +- .../Seeds/FakePodcastsAnalyticsSeeder.php | 6 +-- app/Entities/Episode.php | 6 +-- app/Entities/Note.php | 3 -- app/Entities/Podcast.php | 2 +- app/Helpers/components_helper.php | 2 +- app/Helpers/form_helper.php | 6 +-- app/Helpers/rss_helper.php | 12 +++--- .../Controllers/ActorController.php | 15 +++++--- .../Controllers/BlockController.php | 2 +- .../Controllers/NoteController.php | 13 +++++-- .../ActivityPub/Entities/Activity.php | 10 ++--- app/Libraries/ActivityPub/Entities/Actor.php | 2 +- app/Libraries/ActivityPub/Entities/Note.php | 32 ++++------------ .../Helpers/activitypub_helper.php | 12 +++--- app/Libraries/ActivityPub/HttpSignature.php | 2 +- .../ActivityPub/Models/ActorModel.php | 2 +- .../ActivityPub/Models/FavouriteModel.php | 6 +-- .../ActivityPub/Models/FollowModel.php | 2 +- .../ActivityPub/Models/NoteModel.php | 38 +++++++++---------- .../ActivityPub/Models/PreviewCardModel.php | 2 +- .../ActivityPub/Objects/NoteObject.php | 2 +- app/Libraries/ActivityPub/WebFinger.php | 2 +- .../Controllers/EpisodeController.php | 4 +- .../Analytics/Helpers/analytics_helper.php | 2 +- .../Models/AnalyticsPodcastByCountryModel.php | 4 +- .../Models/AnalyticsPodcastByEpisodeModel.php | 4 +- .../Models/AnalyticsPodcastByPlayerModel.php | 8 ++-- .../Models/AnalyticsPodcastByRegionModel.php | 2 +- .../Models/AnalyticsPodcastByServiceModel.php | 2 +- .../Models/AnalyticsPodcastModel.php | 12 +++--- .../AnalyticsWebsiteByEntryPageModel.php | 2 +- app/Libraries/Router.php | 6 +-- app/Models/CategoryModel.php | 2 +- app/Models/EpisodeModel.php | 2 +- app/Models/PersonModel.php | 2 +- app/Models/PlatformModel.php | 4 +- app/Models/PodcastModel.php | 4 +- app/Models/UserModel.php | 4 +- app/Views/podcast/activity.php | 2 +- app/Views/podcast/activity_authenticated.php | 2 +- 56 files changed, 204 insertions(+), 191 deletions(-) diff --git a/app/Authorization/PermissionModel.php b/app/Authorization/PermissionModel.php index 8809818d..72329220 100644 --- a/app/Authorization/PermissionModel.php +++ b/app/Authorization/PermissionModel.php @@ -34,7 +34,7 @@ class PermissionModel extends MythAuthPermissionModel $groupPermissions = $this->db ->table('auth_groups_permissions') ->select('id, auth_permissions.name') - ->join('auth_permissions', 'auth_permissions.id = permission_id', 'inner',) + ->join('auth_permissions', 'auth_permissions.id = permission_id', 'inner') ->where('group_id', $groupId) ->get() ->getResultObject(); diff --git a/app/Config/Events.php b/app/Config/Events.php index 4de3cedb..0ed8a413 100644 --- a/app/Config/Events.php +++ b/app/Config/Events.php @@ -123,7 +123,7 @@ Events::on('on_undo_follow', function ($actor, $targetActor): void { * @param Note $note */ Events::on('on_note_add', function ($note): void { - if ($note->is_reply) { + if ($note->in_reply_to_id !== null) { $note = $note->reply_to_note; } @@ -147,7 +147,7 @@ Events::on('on_note_add', function ($note): void { * @param Note $note */ Events::on('on_note_remove', function ($note): void { - if ($note->is_reply) { + if ($note->in_reply_to_id !== null) { Events::trigger('on_note_remove', $note->reply_to_note); } @@ -207,7 +207,7 @@ Events::on('on_note_reblog', function ($actor, $note): void { cache() ->deleteMatching("page_note#{$note->id}*"); - if ($note->is_reply) { + if ($note->in_reply_to_id !== null) { cache()->deleteMatching("page_note#{$note->in_reply_to_id}"); } }); @@ -239,7 +239,7 @@ Events::on('on_note_undo_reblog', function ($reblogNote): void { cache() ->deleteMatching("page_note#{$reblogNote->id}*"); - if ($note->is_reply) { + if ($note->in_reply_to_id !== null) { cache()->deleteMatching("page_note#{$note->in_reply_to_id}"); } @@ -308,7 +308,7 @@ Events::on('on_note_favourite', function ($actor, $note): void { cache() ->deleteMatching("page_note#{$note->id}*"); - if ($note->is_reply) { + if ($note->in_reply_to_id !== null) { cache()->deleteMatching("page_note#{$note->in_reply_to_id}*"); } @@ -340,7 +340,7 @@ Events::on('on_note_undo_favourite', function ($actor, $note): void { cache() ->deleteMatching("page_note#{$note->id}*"); - if ($note->is_reply) { + if ($note->in_reply_to_id !== null) { cache()->deleteMatching("page_note#{$note->in_reply_to_id}*"); } diff --git a/app/Controllers/Admin/ContributorController.php b/app/Controllers/Admin/ContributorController.php index fb2acb95..9df5bc9b 100644 --- a/app/Controllers/Admin/ContributorController.php +++ b/app/Controllers/Admin/ContributorController.php @@ -27,19 +27,24 @@ class ContributorController extends BaseController public function _remap(string $method, string ...$params): mixed { - $this->podcast = (new PodcastModel())->getPodcastById((int) $params[0]); - - if (count($params) <= 1) { - return $this->{$method}(); + if (count($params) === 0) { + throw PageNotFoundException::forPageNotFound(); } + if (($podcast = (new PodcastModel())->getPodcastById((int) $params[0])) === null) { + throw PageNotFoundException::forPageNotFound(); + } + + $this->podcast = $podcast; + if ( - ($this->user = (new UserModel())->getPodcastContributor((int) $params[1], (int) $params[0],)) !== null + count($params) > 1 && + ($this->user = (new UserModel())->getPodcastContributor((int) $params[1], (int) $params[0])) === null ) { - return $this->{$method}(); + throw PageNotFoundException::forPageNotFound(); } - throw PageNotFoundException::forPageNotFound(); + return $this->{$method}(); } public function list(): string @@ -57,7 +62,7 @@ class ContributorController extends BaseController public function view(): string { $data = [ - 'contributor' => (new UserModel())->getPodcastContributor($this->user->id, $this->podcast->id,), + 'contributor' => (new UserModel())->getPodcastContributor($this->user->id, $this->podcast->id), ]; replace_breadcrumb_params([ @@ -173,7 +178,7 @@ class ContributorController extends BaseController $podcastModel = new PodcastModel(); if ( - ! $podcastModel->removePodcastContributor($this->user->id, $this->podcast->id,) + ! $podcastModel->removePodcastContributor($this->user->id, $this->podcast->id) ) { return redirect() ->back() diff --git a/app/Controllers/Admin/EpisodeController.php b/app/Controllers/Admin/EpisodeController.php index df6c21ee..2a847444 100644 --- a/app/Controllers/Admin/EpisodeController.php +++ b/app/Controllers/Admin/EpisodeController.php @@ -33,11 +33,13 @@ class EpisodeController extends BaseController public function _remap(string $method, string ...$params): mixed { if ( - ($this->podcast = (new PodcastModel())->getPodcastById((int) $params[0],)) === null + ($podcast = (new PodcastModel())->getPodcastById((int) $params[0])) === null ) { throw PageNotFoundException::forPageNotFound(); } + $this->podcast = $podcast; + if (count($params) > 1) { if ( ! ($this->episode = (new EpisodeModel()) @@ -135,7 +137,7 @@ class EpisodeController extends BaseController 'audio_file' => $this->request->getFile('audio_file'), 'description_markdown' => $this->request->getPost('description'), 'image' => $image, - 'location' => new Location($this->request->getPost('location_name'),), + 'location' => new Location($this->request->getPost('location_name')), 'transcript' => $this->request->getFile('transcript'), 'chapters' => $this->request->getFile('chapters'), 'parental_advisory' => @@ -276,7 +278,7 @@ class EpisodeController extends BaseController } } elseif ($transcriptChoice === 'remote-url') { if ( - ($transcriptFileRemoteUrl = $this->request->getPost('transcript_file_remote_url',)) && + ($transcriptFileRemoteUrl = $this->request->getPost('transcript_file_remote_url')) && (($transcriptFile = $this->episode->transcript_file) && $transcriptFile !== null) ) { @@ -295,7 +297,7 @@ class EpisodeController extends BaseController } } elseif ($chaptersChoice === 'remote-url') { if ( - ($chaptersFileRemoteUrl = $this->request->getPost('chapters_file_remote_url',)) && + ($chaptersFileRemoteUrl = $this->request->getPost('chapters_file_remote_url')) && (($chaptersFile = $this->episode->chapters_file) && $chaptersFile !== null) ) { diff --git a/app/Controllers/Admin/EpisodePersonController.php b/app/Controllers/Admin/EpisodePersonController.php index fd54851b..771311fe 100644 --- a/app/Controllers/Admin/EpisodePersonController.php +++ b/app/Controllers/Admin/EpisodePersonController.php @@ -31,7 +31,7 @@ class EpisodePersonController extends BaseController } if ( - ($this->podcast = (new PodcastModel())->getPodcastById((int) $params[0],)) && + ($this->podcast = (new PodcastModel())->getPodcastById((int) $params[0])) && ($this->episode = (new EpisodeModel()) ->where([ 'id' => $params[1], diff --git a/app/Controllers/Admin/PersonController.php b/app/Controllers/Admin/PersonController.php index d8cb6bca..468f8363 100644 --- a/app/Controllers/Admin/PersonController.php +++ b/app/Controllers/Admin/PersonController.php @@ -27,7 +27,7 @@ class PersonController extends BaseController } if ( - ($this->person = (new PersonModel())->getPersonById((int) $params[0],)) !== null + ($this->person = (new PersonModel())->getPersonById((int) $params[0])) !== null ) { return $this->{$method}(); } diff --git a/app/Controllers/Admin/PodcastController.php b/app/Controllers/Admin/PodcastController.php index ac7464f0..d6b0e577 100644 --- a/app/Controllers/Admin/PodcastController.php +++ b/app/Controllers/Admin/PodcastController.php @@ -33,7 +33,7 @@ class PodcastController extends BaseController } if ( - ($this->podcast = (new PodcastModel())->getPodcastById((int) $params[0],)) !== null + ($this->podcast = (new PodcastModel())->getPodcastById((int) $params[0])) !== null ) { return $this->{$method}(); } @@ -45,7 +45,7 @@ class PodcastController extends BaseController { if (! has_permission('podcasts-list')) { $data = [ - 'podcasts' => (new PodcastModel())->getUserPodcasts((int) user_id(),), + 'podcasts' => (new PodcastModel())->getUserPodcasts((int) user_id()), ]; } else { $data = [ @@ -162,7 +162,7 @@ class PodcastController extends BaseController $data = [ 'languageOptions' => $languageOptions, 'categoryOptions' => $categoryOptions, - 'browserLang' => get_browser_language($this->request->getServer('HTTP_ACCEPT_LANGUAGE'),), + 'browserLang' => get_browser_language($this->request->getServer('HTTP_ACCEPT_LANGUAGE')), ]; return view('admin/podcast/create', $data); @@ -207,7 +207,7 @@ class PodcastController extends BaseController 'publisher' => $this->request->getPost('publisher'), 'type' => $this->request->getPost('type'), 'copyright' => $this->request->getPost('copyright'), - 'location' => new Location($this->request->getPost('location_name'),), + 'location' => new Location($this->request->getPost('location_name')), 'payment_pointer' => $this->request->getPost( 'payment_pointer' ) === '' ? null : $this->request->getPost('payment_pointer'), diff --git a/app/Controllers/Admin/PodcastImportController.php b/app/Controllers/Admin/PodcastImportController.php index 1a393e0d..908a1b4d 100644 --- a/app/Controllers/Admin/PodcastImportController.php +++ b/app/Controllers/Admin/PodcastImportController.php @@ -56,7 +56,7 @@ class PodcastImportController extends BaseController $data = [ 'languageOptions' => $languageOptions, 'categoryOptions' => $categoryOptions, - 'browserLang' => get_browser_language($this->request->getServer('HTTP_ACCEPT_LANGUAGE'),), + 'browserLang' => get_browser_language($this->request->getServer('HTTP_ACCEPT_LANGUAGE')), ]; return view('admin/podcast/import', $data); @@ -132,10 +132,10 @@ class PodcastImportController extends BaseController $podcast = new Podcast([ 'name' => $this->request->getPost('name'), - 'imported_feed_url' => $this->request->getPost('imported_feed_url',), - 'new_feed_url' => base_url(route_to('podcast_feed', $this->request->getPost('name')),), + 'imported_feed_url' => $this->request->getPost('imported_feed_url'), + 'new_feed_url' => base_url(route_to('podcast_feed', $this->request->getPost('name'))), 'title' => (string) $feed->channel[0]->title, - 'description_markdown' => $converter->convert($channelDescriptionHtml,), + 'description_markdown' => $converter->convert($channelDescriptionHtml), 'description_html' => $channelDescriptionHtml, 'image' => new Image($imageFile), 'language_code' => $this->request->getPost('language'), @@ -323,7 +323,7 @@ class PodcastImportController extends BaseController property_exists($nsItunes, 'image') && $nsItunes->image !== null && $nsItunes->image->attributes()['href'] !== null ) { - $episodeImage = new Image(download_file((string) $nsItunes->image->attributes()['href'],)); + $episodeImage = new Image(download_file((string) $nsItunes->image->attributes()['href'])); } else { $episodeImage = null; } @@ -342,8 +342,8 @@ class PodcastImportController extends BaseController 'guid' => $item->guid ?? null, 'title' => $item->title, 'slug' => $slug, - 'audio_file' => download_file((string) $item->enclosure->attributes()['url'],), - 'description_markdown' => $converter->convert($itemDescriptionHtml,), + 'audio_file' => download_file((string) $item->enclosure->attributes()['url']), + 'description_markdown' => $converter->convert($itemDescriptionHtml), 'description_html' => $itemDescriptionHtml, 'image' => $episodeImage, 'parental_advisory' => diff --git a/app/Controllers/Admin/PodcastPersonController.php b/app/Controllers/Admin/PodcastPersonController.php index 00811f18..db5e2df0 100644 --- a/app/Controllers/Admin/PodcastPersonController.php +++ b/app/Controllers/Admin/PodcastPersonController.php @@ -27,7 +27,7 @@ class PodcastPersonController extends BaseController } if ( - ($this->podcast = (new PodcastModel())->getPodcastById((int) $params[0],)) !== null + ($this->podcast = (new PodcastModel())->getPodcastById((int) $params[0])) !== null ) { unset($params[0]); return $this->{$method}(...$params); @@ -42,7 +42,7 @@ class PodcastPersonController extends BaseController $data = [ 'podcast' => $this->podcast, - 'podcastPersons' => (new PersonModel())->getPodcastPersons($this->podcast->id,), + 'podcastPersons' => (new PersonModel())->getPodcastPersons($this->podcast->id), 'personOptions' => (new PersonModel())->getPersonOptions(), 'taxonomyOptions' => (new PersonModel())->getTaxonomyOptions(), ]; diff --git a/app/Controllers/Admin/PodcastPlatformController.php b/app/Controllers/Admin/PodcastPlatformController.php index 0f8d6b0a..4b1cb539 100644 --- a/app/Controllers/Admin/PodcastPlatformController.php +++ b/app/Controllers/Admin/PodcastPlatformController.php @@ -28,7 +28,7 @@ class PodcastPlatformController extends BaseController } if ( - ($this->podcast = (new PodcastModel())->getPodcastById((int) $params[0],)) !== null + ($this->podcast = (new PodcastModel())->getPodcastById((int) $params[0])) !== null ) { unset($params[0]); return $this->{$method}(...$params); @@ -49,7 +49,7 @@ class PodcastPlatformController extends BaseController $data = [ 'podcast' => $this->podcast, 'platformType' => $platformType, - 'platforms' => (new PlatformModel())->getPlatformsWithLinks($this->podcast->id, $platformType,), + 'platforms' => (new PlatformModel())->getPlatformsWithLinks($this->podcast->id, $platformType), ]; replace_breadcrumb_params([ diff --git a/app/Controllers/EpisodeController.php b/app/Controllers/EpisodeController.php index f94fb386..89c6fac2 100644 --- a/app/Controllers/EpisodeController.php +++ b/app/Controllers/EpisodeController.php @@ -35,20 +35,25 @@ class EpisodeController extends BaseController } if ( - ($this->podcast = (new PodcastModel())->getPodcastByName($params[0],)) === null + ($podcast = (new PodcastModel())->getPodcastByName($params[0])) === null ) { throw PageNotFoundException::forPageNotFound(); } + $this->podcast = $podcast; + if ( - ($this->episode = (new EpisodeModel())->getEpisodeBySlug($params[0], $params[1],)) !== null + ($episode = (new EpisodeModel())->getEpisodeBySlug($params[0], $params[1])) === null ) { - unset($params[1]); - unset($params[0]); - return $this->{$method}(...$params); + throw PageNotFoundException::forPageNotFound(); } - throw PageNotFoundException::forPageNotFound(); + $this->episode = $episode; + + unset($params[1]); + unset($params[0]); + + return $this->{$method}(...$params); } public function index(): string diff --git a/app/Controllers/InstallController.php b/app/Controllers/InstallController.php index 9873ac50..828a6bbd 100644 --- a/app/Controllers/InstallController.php +++ b/app/Controllers/InstallController.php @@ -155,7 +155,7 @@ class InstallController extends Controller if (! $this->validate($rules)) { return redirect() - ->to((host_url() === null ? config('App') ->baseURL : host_url()) . config('App')->installGateway,) + ->to((host_url() === null ? config('App') ->baseURL : host_url()) . config('App')->installGateway) ->withInput() ->with('errors', $this->validator->getErrors()); } @@ -173,7 +173,7 @@ class InstallController extends Controller helper('text'); // redirect to full install url with new baseUrl input - return redirect()->to(reduce_double_slashes($baseUrl . '/' . config('App')->installGateway,)); + return redirect()->to(reduce_double_slashes($baseUrl . '/' . config('App')->installGateway)); } public function databaseConfig(): string @@ -198,10 +198,10 @@ class InstallController extends Controller } self::writeEnv([ - 'database.default.hostname' => $this->request->getPost('db_hostname',), + 'database.default.hostname' => $this->request->getPost('db_hostname'), 'database.default.database' => $this->request->getPost('db_name'), - 'database.default.username' => $this->request->getPost('db_username',), - 'database.default.password' => $this->request->getPost('db_password',), + 'database.default.username' => $this->request->getPost('db_username'), + 'database.default.password' => $this->request->getPost('db_password'), 'database.default.DBPrefix' => $this->request->getPost('db_prefix'), ]); diff --git a/app/Controllers/NoteController.php b/app/Controllers/NoteController.php index 90524b54..a5ddd3d8 100644 --- a/app/Controllers/NoteController.php +++ b/app/Controllers/NoteController.php @@ -39,8 +39,12 @@ class NoteController extends ActivityPubNoteController public function _remap(string $method, string ...$params): mixed { + if (count($params) < 2) { + throw PageNotFoundException::forPageNotFound(); + } + if ( - ($this->podcast = (new PodcastModel())->getPodcastByName($params[0],)) === null + ($this->podcast = (new PodcastModel())->getPodcastByName($params[0])) === null ) { throw PageNotFoundException::forPageNotFound(); } @@ -48,11 +52,13 @@ class NoteController extends ActivityPubNoteController $this->actor = $this->podcast->actor; if ( - count($params) > 1 && - ! ($this->note = (new NoteModel())->getNoteById($params[1])) + ($note = (new NoteModel())->getNoteById($params[1])) === null ) { throw PageNotFoundException::forPageNotFound(); } + + $this->note = $note; + unset($params[0]); unset($params[1]); @@ -125,7 +131,7 @@ class NoteController extends ActivityPubNoteController if ( $episodeUri && ($params = extract_params_from_episode_uri(new URI($episodeUri))) && - ($episode = (new EpisodeModel())->getEpisodeBySlug($params['podcastName'], $params['episodeSlug'],)) + ($episode = (new EpisodeModel())->getEpisodeBySlug($params['podcastName'], $params['episodeSlug'])) ) { $newNote->episode_id = $episode->id; } @@ -135,7 +141,7 @@ class NoteController extends ActivityPubNoteController $noteModel = new NoteModel(); if ( ! $noteModel - ->addNote($newNote, ! (bool) $newNote->episode_id, true,) + ->addNote($newNote, ! (bool) $newNote->episode_id, true) ) { return redirect() ->back() diff --git a/app/Controllers/PageController.php b/app/Controllers/PageController.php index 0ad1553a..7f330232 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 = null; + protected Page $page; public function _remap(string $method, string ...$params): mixed { @@ -25,12 +25,14 @@ class PageController extends BaseController } if ( - $this->page = (new PageModel())->where('slug', $params[0])->first() + ($page = (new PageModel())->where('slug', $params[0])->first()) === null ) { - return $this->{$method}(); + throw PageNotFoundException::forPageNotFound(); } - throw PageNotFoundException::forPageNotFound(); + $this->page = $page; + + return $this->{$method}(); } public function index(): string diff --git a/app/Controllers/PodcastController.php b/app/Controllers/PodcastController.php index 07fbc1b0..79335251 100644 --- a/app/Controllers/PodcastController.php +++ b/app/Controllers/PodcastController.php @@ -30,13 +30,15 @@ class PodcastController extends BaseController } if ( - ($this->podcast = (new PodcastModel())->getPodcastByName($params[0],)) !== null + ($podcast = (new PodcastModel())->getPodcastByName($params[0])) === null ) { - unset($params[0]); - return $this->{$method}(...$params); + throw PageNotFoundException::forPageNotFound(); } - throw PageNotFoundException::forPageNotFound(); + $this->podcast = $podcast; + + unset($params[0]); + return $this->{$method}(...$params); } public function activity(): string @@ -61,7 +63,7 @@ class PodcastController extends BaseController if (! ($cachedView = cache($cacheName))) { $data = [ 'podcast' => $this->podcast, - 'notes' => (new NoteModel())->getActorPublishedNotes($this->podcast->actor_id,), + 'notes' => (new NoteModel())->getActorPublishedNotes($this->podcast->actor_id), ]; // if user is logged in then send to the authenticated activity view diff --git a/app/Database/Seeds/AuthSeeder.php b/app/Database/Seeds/AuthSeeder.php index 3905e55d..88e4baa8 100644 --- a/app/Database/Seeds/AuthSeeder.php +++ b/app/Database/Seeds/AuthSeeder.php @@ -277,7 +277,7 @@ class AuthSeeder extends Seeder foreach ($action['has_permission'] as $role) { // link permission to specified groups $dataGroupsPermissions[] = [ - 'group_id' => $this->getGroupIdByName($role, $dataGroups,), + 'group_id' => $this->getGroupIdByName($role, $dataGroups), 'permission_id' => $permissionId, ]; } diff --git a/app/Database/Seeds/FakePodcastsAnalyticsSeeder.php b/app/Database/Seeds/FakePodcastsAnalyticsSeeder.php index b6d2b345..b97c1c9d 100644 --- a/app/Database/Seeds/FakePodcastsAnalyticsSeeder.php +++ b/app/Database/Seeds/FakePodcastsAnalyticsSeeder.php @@ -24,7 +24,7 @@ class FakePodcastsAnalyticsSeeder extends Seeder public function run(): void { $jsonUserAgents = json_decode( - file_get_contents('https://raw.githubusercontent.com/opawg/user-agents/master/src/user-agents.json',), + file_get_contents('https://raw.githubusercontent.com/opawg/user-agents/master/src/user-agents.json'), true, 512, JSON_THROW_ON_ERROR, @@ -63,7 +63,7 @@ class FakePodcastsAnalyticsSeeder extends Seeder ->where('`published_at` <= NOW()', null, false) ->findAll(); foreach ($episodes as $episode) { - $age = floor(($date - strtotime((string) $episode->published_at)) / 86400,); + $age = floor(($date - strtotime((string) $episode->published_at)) / 86400); $probability1 = floor(exp(3 - $age / 40)) + 1; for ( @@ -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'; diff --git a/app/Entities/Episode.php b/app/Entities/Episode.php index 4b4b63d3..243586e0 100644 --- a/app/Entities/Episode.php +++ b/app/Entities/Episode.php @@ -396,7 +396,7 @@ class Episode extends Entity public function getLink(): string { - return base_url(route_to('episode', $this->getPodcast() ->name, $this->attributes['slug'],)); + return base_url(route_to('episode', $this->getPodcast() ->name, $this->attributes['slug'])); } public function getEmbeddablePlayerUrl(string $theme = null): string @@ -410,7 +410,7 @@ class Episode extends Entity $this->attributes['slug'], $theme, ) - : route_to('embeddable-player', $this->getPodcast() ->name, $this->attributes['slug'],), + : route_to('embeddable-player', $this->getPodcast() ->name, $this->attributes['slug']), ); } @@ -471,7 +471,7 @@ class Episode extends Entity { if ($this->description === null) { $this->description = trim( - preg_replace('~\s+~', ' ', strip_tags($this->attributes['description_html']),), + preg_replace('~\s+~', ' ', strip_tags($this->attributes['description_html'])), ); } diff --git a/app/Entities/Note.php b/app/Entities/Note.php index 68d39c4f..5dc0c8bd 100644 --- a/app/Entities/Note.php +++ b/app/Entities/Note.php @@ -17,9 +17,6 @@ use RuntimeException; /** * @property int|null $episode_id * @property Episode|null $episode - * @property Actor $actor - * @property Note $reblog_of_note - * @property Note $reply_to_note */ class Note extends ActivityPubNote { diff --git a/app/Entities/Podcast.php b/app/Entities/Podcast.php index bf1b92b6..ddde24bf 100644 --- a/app/Entities/Podcast.php +++ b/app/Entities/Podcast.php @@ -320,7 +320,7 @@ class Podcast extends Entity { if ($this->description === null) { $this->description = trim( - (string) preg_replace('~\s+~', ' ', strip_tags($this->attributes['description_html']),), + (string) preg_replace('~\s+~', ' ', strip_tags($this->attributes['description_html'])), ); } diff --git a/app/Helpers/components_helper.php b/app/Helpers/components_helper.php index 5cb29ff2..53d1f524 100644 --- a/app/Helpers/components_helper.php +++ b/app/Helpers/components_helper.php @@ -96,7 +96,7 @@ if (! function_exists('button')) { if ($uri !== '') { return anchor($uri, $label, array_merge([ 'class' => $buttonClass, - ], $customAttributes,)); + ], $customAttributes)); } $defaultButtonAttributes = [ diff --git a/app/Helpers/form_helper.php b/app/Helpers/form_helper.php index 2111845a..69edf75e 100644 --- a/app/Helpers/form_helper.php +++ b/app/Helpers/form_helper.php @@ -159,9 +159,9 @@ if (! function_exists('form_multiselect')) { 'data-class' => $customExtra['class'], 'data-select-text' => lang('Common.forms.multiSelect.selectText'), 'data-loading-text' => lang('Common.forms.multiSelect.loadingText'), - 'data-no-results-text' => lang('Common.forms.multiSelect.noResultsText',), - 'data-no-choices-text' => lang('Common.forms.multiSelect.noChoicesText',), - 'data-max-item-text' => lang('Common.forms.multiSelect.maxItemText',), + 'data-no-results-text' => lang('Common.forms.multiSelect.noResultsText'), + 'data-no-choices-text' => lang('Common.forms.multiSelect.noChoicesText'), + 'data-max-item-text' => lang('Common.forms.multiSelect.maxItemText'), ]; $extra = stringify_attributes(array_merge($defaultExtra, $customExtra)); diff --git a/app/Helpers/rss_helper.php b/app/Helpers/rss_helper.php index 4b95ecf3..fd2af8d7 100644 --- a/app/Helpers/rss_helper.php +++ b/app/Helpers/rss_helper.php @@ -84,7 +84,7 @@ if (! function_exists('get_rss_feed')) { $recipientElement->addAttribute('split', '100'); } $channel - ->addChild('locked', $podcast->is_locked ? 'yes' : 'no', $podcastNamespace,) + ->addChild('locked', $podcast->is_locked ? 'yes' : 'no', $podcastNamespace) ->addAttribute('owner', $podcast->owner_email); if ($podcast->imported_feed_url !== null) { $channel->addChild('previousUrl', $podcast->imported_feed_url, $podcastNamespace); @@ -142,13 +142,13 @@ if (! function_exists('get_rss_feed')) { $personElement->addAttribute( 'role', htmlspecialchars( - lang("PersonsTaxonomy.persons.{$role->group}.roles.{$role->role}.label", [], 'en',), + lang("PersonsTaxonomy.persons.{$role->group}.roles.{$role->role}.label", [], 'en'), ), ); $personElement->addAttribute( 'group', - htmlspecialchars(lang("PersonsTaxonomy.persons.{$role->group}.label", [], 'en',),), + htmlspecialchars(lang("PersonsTaxonomy.persons.{$role->group}.label", [], 'en')), ); } } @@ -253,7 +253,7 @@ if (! function_exists('get_rss_feed')) { $transcriptElement->addAttribute('url', $episode->transcript_file_url); $transcriptElement->addAttribute( 'type', - Mimes::guessTypeFromExtension(pathinfo($episode->transcript_file_url, PATHINFO_EXTENSION,),), + Mimes::guessTypeFromExtension(pathinfo($episode->transcript_file_url, PATHINFO_EXTENSION)), ); $transcriptElement->addAttribute('language', $podcast->language_code); } @@ -281,13 +281,13 @@ if (! function_exists('get_rss_feed')) { $personElement->addAttribute( 'role', htmlspecialchars( - lang("PersonsTaxonomy.persons.{$role->group}.roles.{$role->role}.label", [], 'en',), + lang("PersonsTaxonomy.persons.{$role->group}.roles.{$role->role}.label", [], 'en'), ), ); $personElement->addAttribute( 'group', - htmlspecialchars(lang("PersonsTaxonomy.persons.{$role->group}.label", [], 'en',),), + htmlspecialchars(lang("PersonsTaxonomy.persons.{$role->group}.label", [], 'en')), ); $personElement->addAttribute('img', $person->image->large_url); diff --git a/app/Libraries/ActivityPub/Controllers/ActorController.php b/app/Libraries/ActivityPub/Controllers/ActorController.php index 7e68c635..8b8705b4 100644 --- a/app/Libraries/ActivityPub/Controllers/ActorController.php +++ b/app/Libraries/ActivityPub/Controllers/ActorController.php @@ -39,12 +39,17 @@ class ActorController extends Controller public function _remap(string $method, string ...$params): mixed { + if (count($params) < 1) { + throw PageNotFoundException::forPageNotFound(); + } + if ( - count($params) > 0 && - ! ($this->actor = model('ActorModel')->getActorByUsername($params[0],)) + ($actor = model('ActorModel')->getActorByUsername($params[0])) === null ) { throw PageNotFoundException::forPageNotFound(); } + + $this->actor = $actor; unset($params[0]); return $this->{$method}(...$params); @@ -109,7 +114,7 @@ class ActorController extends Controller 'actor_id' => $payloadActor->id, 'in_reply_to_id' => $replyToNote->id, 'message' => $payload->object->content, - 'published_at' => Time::parse($payload->object->published,), + 'published_at' => Time::parse($payload->object->published), ]); } @@ -295,7 +300,7 @@ class ActorController extends Controller { // get followers for a specific actor $followers = model('ActorModel') - ->join('activitypub_follows', 'activitypub_follows.actor_id = id', 'inner',) + ->join('activitypub_follows', 'activitypub_follows.actor_id = id', 'inner') ->where('activitypub_follows.target_actor_id', $this->actor->id) ->orderBy('activitypub_follows.created_at', 'DESC'); @@ -364,7 +369,7 @@ class ActorController extends Controller } return redirect()->to( - str_replace('{uri}', urlencode($this->actor->uri), $data->links[$ostatusKey]->template,), + str_replace('{uri}', urlencode($this->actor->uri), $data->links[$ostatusKey]->template), ); } diff --git a/app/Libraries/ActivityPub/Controllers/BlockController.php b/app/Libraries/ActivityPub/Controllers/BlockController.php index 09882421..4111e08f 100644 --- a/app/Libraries/ActivityPub/Controllers/BlockController.php +++ b/app/Libraries/ActivityPub/Controllers/BlockController.php @@ -37,7 +37,7 @@ class BlockController extends Controller if ($parts = split_handle($handle)) { if ( - ($actor = get_or_create_actor($parts['username'], $parts['domain'],)) === null + ($actor = get_or_create_actor($parts['username'], $parts['domain'])) === null ) { return redirect() ->back() diff --git a/app/Libraries/ActivityPub/Controllers/NoteController.php b/app/Libraries/ActivityPub/Controllers/NoteController.php index 017d709c..10cac4a5 100644 --- a/app/Libraries/ActivityPub/Controllers/NoteController.php +++ b/app/Libraries/ActivityPub/Controllers/NoteController.php @@ -39,9 +39,16 @@ class NoteController extends Controller public function _remap(string $method, string ...$params): mixed { - if (! ($this->note = model('NoteModel')->getNoteById($params[0]))) { + if (count($params) < 1) { throw PageNotFoundException::forPageNotFound(); } + + if (($note = model('NoteModel')->getNoteById($params[0])) === null) { + throw PageNotFoundException::forPageNotFound(); + } + + $this->note = $note; + unset($params[0]); return $this->{$method}(...$params); @@ -69,7 +76,7 @@ class NoteController extends Controller * get note replies */ $noteReplies = model('NoteModel') - ->where('in_reply_to_id', service('uuid') ->fromString($this->note->id) ->getBytes(),) + ->where('in_reply_to_id', service('uuid') ->fromString($this->note->id) ->getBytes()) ->where('`published_at` <= NOW()', null, false) ->orderBy('published_at', 'ASC'); @@ -252,7 +259,7 @@ class NoteController extends Controller } return redirect()->to( - str_replace('{uri}', urlencode($this->note->uri), $data->links[$ostatusKey]->template,), + str_replace('{uri}', urlencode($this->note->uri), $data->links[$ostatusKey]->template), ); } diff --git a/app/Libraries/ActivityPub/Entities/Activity.php b/app/Libraries/ActivityPub/Entities/Activity.php index 967e48a5..cd9996f5 100644 --- a/app/Libraries/ActivityPub/Entities/Activity.php +++ b/app/Libraries/ActivityPub/Entities/Activity.php @@ -18,9 +18,9 @@ use RuntimeException; * @property int $actor_id * @property Actor $actor * @property int|null $target_actor_id - * @property Actor|null $target_actor + * @property Actor $target_actor * @property string|null $note_id - * @property Note|null $note + * @property Note $note * @property string $type * @property object $payload * @property string|null $status @@ -65,7 +65,7 @@ class Activity extends UuidEntity } if ($this->actor === null) { - $this->actor = model('ActorModel') + $this->actor = model('ActorModel', false) ->getActorById($this->actor_id); } @@ -79,7 +79,7 @@ class Activity extends UuidEntity } if ($this->target_actor === null) { - $this->target_actor = model('ActorModel') + $this->target_actor = model('ActorModel', false) ->getActorById($this->target_actor_id); } @@ -93,7 +93,7 @@ class Activity extends UuidEntity } if ($this->note === null) { - $this->note = model('NoteModel') + $this->note = model('NoteModel', false) ->getNoteById($this->note_id); } diff --git a/app/Libraries/ActivityPub/Entities/Actor.php b/app/Libraries/ActivityPub/Entities/Actor.php index d55b2113..0e7746c7 100644 --- a/app/Libraries/ActivityPub/Entities/Actor.php +++ b/app/Libraries/ActivityPub/Entities/Actor.php @@ -101,7 +101,7 @@ class Actor extends Entity } if ($this->followers === null) { - $this->followers = (array) model('ActorModel') + $this->followers = (array) model('ActorModel', false) ->getFollowers($this->id); } diff --git a/app/Libraries/ActivityPub/Entities/Note.php b/app/Libraries/ActivityPub/Entities/Note.php index 2491c702..06199303 100644 --- a/app/Libraries/ActivityPub/Entities/Note.php +++ b/app/Libraries/ActivityPub/Entities/Note.php @@ -18,12 +18,10 @@ use RuntimeException; * @property string $id * @property string $uri * @property int $actor_id - * @property Actor|null $actor + * @property Actor $actor * @property string|null $in_reply_to_id - * @property bool $is_reply * @property Note|null $reply_to_note * @property string|null $reblog_of_id - * @property bool $is_reblog * @property Note|null $reblog_of_note * @property string $message * @property string $message_html @@ -44,12 +42,8 @@ class Note extends UuidEntity { protected ?Actor $actor = null; - protected bool $is_reply = false; - protected ?Note $reply_to_note = null; - protected bool $is_reblog = false; - protected ?Note $reblog_of_note = null; protected ?PreviewCard $preview_card = null; @@ -97,14 +91,14 @@ class Note extends UuidEntity /** * Returns the note's actor */ - public function getActor(): ?Actor + public function getActor(): Actor { if ($this->actor_id === null) { throw new RuntimeException('Note must have an actor_id before getting actor.'); } if ($this->actor === null) { - $this->actor = model('ActorModel') + $this->actor = model('ActorModel', false) ->getActorById($this->actor_id); } @@ -118,7 +112,7 @@ class Note extends UuidEntity } if ($this->preview_card === null) { - $this->preview_card = model('PreviewCardModel') + $this->preview_card = model('PreviewCardModel', false) ->getNotePreviewCard($this->id); } @@ -130,11 +124,6 @@ class Note extends UuidEntity return $this->getPreviewCard() !== null; } - public function getIsReply(): bool - { - return $this->in_reply_to_id && ($this->getReplyToNote() !== null); - } - /** * @return Note[] */ @@ -145,7 +134,7 @@ class Note extends UuidEntity } if ($this->replies === null) { - $this->replies = (array) model('NoteModel') + $this->replies = (array) model('NoteModel', false) ->getNoteReplies($this->id); } @@ -164,7 +153,7 @@ class Note extends UuidEntity } if ($this->reply_to_note === null) { - $this->reply_to_note = model('NoteModel') + $this->reply_to_note = model('NoteModel', false) ->getNoteById($this->in_reply_to_id); } @@ -181,18 +170,13 @@ class Note extends UuidEntity } if ($this->reblogs === null) { - $this->reblogs = (array) model('NoteModel') + $this->reblogs = (array) model('NoteModel', false) ->getNoteReblogs($this->id); } return $this->reblogs; } - public function getIsReblog(): bool - { - return $this->reblog_of_id !== null; - } - public function getReblogOfNote(): ?self { if ($this->reblog_of_id === null) { @@ -200,7 +184,7 @@ class Note extends UuidEntity } if ($this->reblog_of_note === null) { - $this->reblog_of_note = model('NoteModel') + $this->reblog_of_note = model('NoteModel', false) ->getNoteById($this->reblog_of_id); } diff --git a/app/Libraries/ActivityPub/Helpers/activitypub_helper.php b/app/Libraries/ActivityPub/Helpers/activitypub_helper.php index 8c3b214b..7902c556 100644 --- a/app/Libraries/ActivityPub/Helpers/activitypub_helper.php +++ b/app/Libraries/ActivityPub/Helpers/activitypub_helper.php @@ -45,7 +45,7 @@ if (! function_exists('split_handle')) { function split_handle(string $handle): array | false { if ( - ! preg_match('~^@?(?P[\w\.\-]+)@(?P[\w\.\-]+)(?P:[\d]+)?$~', $handle, $matches,) + ! preg_match('~^@?(?P[\w\.\-]+)@(?P[\w\.\-]+)(?P:[\d]+)?$~', $handle, $matches) ) { return false; } @@ -171,7 +171,7 @@ if (! function_exists('create_preview_card_from_url')) { ]); if ( - ! ($newPreviewCardId = model('PreviewCardModel')->insert($newPreviewCard, true,)) + ! ($newPreviewCardId = model('PreviewCardModel')->insert($newPreviewCard, true)) ) { return null; } @@ -194,7 +194,7 @@ if (! function_exists('get_or_create_preview_card_from_url')) { // check if preview card has already been generated if ( $previewCard = model('PreviewCardModel') - ->getPreviewCardFromUrl((string) $url,) + ->getPreviewCardFromUrl((string) $url) ) { return $previewCard; } @@ -361,7 +361,7 @@ if (! function_exists('linkify')) { if ( $actor = model( 'ActorModel', - )->getActorByUsername($match['username'], $match['domain'],) + )->getActorByUsername($match['username'], $match['domain']) ) { // TODO: check that host is local to remove target blank? return '<' . @@ -394,11 +394,11 @@ if (! function_exists('linkify')) { } } else { if ( - $actor = model('ActorModel',) + $actor = model('ActorModel') ->getActorByUsername($match['username']) ) { return '<' . - array_push($links, anchor($actor->uri, $match[0]),) . + array_push($links, anchor($actor->uri, $match[0])) . '>'; } diff --git a/app/Libraries/ActivityPub/HttpSignature.php b/app/Libraries/ActivityPub/HttpSignature.php index 046a1cf6..a630613c 100644 --- a/app/Libraries/ActivityPub/HttpSignature.php +++ b/app/Libraries/ActivityPub/HttpSignature.php @@ -35,7 +35,7 @@ class HttpSignature ([\w\-\.#\/@]+) )", algorithm="(?P[\w\-]+)", - (headers="\(request-target\) (?P[\w\\-\s]+)",)? + (headers="\(request-target\) (?P[\w\\-\s]+)")? signature="(?P[\w+\/]+={0,2})" /x'; diff --git a/app/Libraries/ActivityPub/Models/ActorModel.php b/app/Libraries/ActivityPub/Models/ActorModel.php index ff5b7e3a..aff67eb2 100644 --- a/app/Libraries/ActivityPub/Models/ActorModel.php +++ b/app/Libraries/ActivityPub/Models/ActorModel.php @@ -129,7 +129,7 @@ class ActorModel extends Model config('ActivityPub') ->cachePrefix . "actor#{$actorId}_followers"; if (! ($found = cache($cacheName))) { - $found = $this->join('activitypub_follows', 'activitypub_follows.actor_id = id', 'inner',) + $found = $this->join('activitypub_follows', 'activitypub_follows.actor_id = id', 'inner') ->where('activitypub_follows.target_actor_id', $actorId) ->findAll(); diff --git a/app/Libraries/ActivityPub/Models/FavouriteModel.php b/app/Libraries/ActivityPub/Models/FavouriteModel.php index 84d37571..57ac63ae 100644 --- a/app/Libraries/ActivityPub/Models/FavouriteModel.php +++ b/app/Libraries/ActivityPub/Models/FavouriteModel.php @@ -57,7 +57,7 @@ class FavouriteModel extends UuidModel ]); model('NoteModel') - ->where('id', service('uuid') ->fromString($note->id) ->getBytes(),) + ->where('id', service('uuid') ->fromString($note->id) ->getBytes()) ->increment('favourites_count'); if ($registerActivity) { @@ -97,7 +97,7 @@ class FavouriteModel extends UuidModel $this->db->transStart(); model('NoteModel') - ->where('id', service('uuid') ->fromString($note->id) ->getBytes(),) + ->where('id', service('uuid') ->fromString($note->id) ->getBytes()) ->decrement('favourites_count'); $this->db @@ -125,7 +125,7 @@ class FavouriteModel extends UuidModel $likeActivity = new LikeActivity(); $likeActivity - ->set('id', base_url(route_to('activity', $actor->username, $activity->id),),) + ->set('id', base_url(route_to('activity', $actor->username, $activity->id))) ->set('actor', $actor->uri) ->set('object', $note->uri); diff --git a/app/Libraries/ActivityPub/Models/FollowModel.php b/app/Libraries/ActivityPub/Models/FollowModel.php index b54069b5..62e2c654 100644 --- a/app/Libraries/ActivityPub/Models/FollowModel.php +++ b/app/Libraries/ActivityPub/Models/FollowModel.php @@ -83,7 +83,7 @@ class FollowModel extends Model 'queued', ); - $followActivity->set('id', base_url(route_to('activity', $actor->username, $activityId),)); + $followActivity->set('id', base_url(route_to('activity', $actor->username, $activityId))); model('ActivityModel') ->update($activityId, [ diff --git a/app/Libraries/ActivityPub/Models/NoteModel.php b/app/Libraries/ActivityPub/Models/NoteModel.php index 2da2fdc5..5662bec3 100644 --- a/app/Libraries/ActivityPub/Models/NoteModel.php +++ b/app/Libraries/ActivityPub/Models/NoteModel.php @@ -155,7 +155,7 @@ class NoteModel extends UuidModel */ public function getSecondsToNextUnpublishedNote(int $actorId): int | false { - $result = $this->select('TIMESTAMPDIFF(SECOND, NOW(), `published_at`) as timestamp_diff',) + $result = $this->select('TIMESTAMPDIFF(SECOND, NOW(), `published_at`) as timestamp_diff') ->where([ 'actor_id' => $actorId, ]) @@ -185,11 +185,11 @@ class NoteModel extends UuidModel if (! ($found = cache($cacheName))) { if (! $withBlocked) { $this->select('activitypub_notes.*') - ->join('activitypub_actors', 'activitypub_actors.id = activitypub_notes.actor_id', 'inner',) + ->join('activitypub_actors', 'activitypub_actors.id = activitypub_notes.actor_id', 'inner') ->where('activitypub_actors.is_blocked', 0); } - $this->where('in_reply_to_id', $this->uuid->fromString($noteId) ->getBytes(),) + $this->where('in_reply_to_id', $this->uuid->fromString($noteId) ->getBytes()) ->where('`published_at` <= NOW()', null, false) ->orderBy('published_at', 'ASC'); $found = $this->findAll(); @@ -213,7 +213,7 @@ class NoteModel extends UuidModel ->cachePrefix . "note#{$noteId}_reblogs"; if (! ($found = cache($cacheName))) { - $found = $this->where('reblog_of_id', $this->uuid->fromString($noteId) ->getBytes(),) + $found = $this->where('reblog_of_id', $this->uuid->fromString($noteId) ->getBytes()) ->where('`published_at` <= NOW()', null, false) ->orderBy('published_at', 'ASC') ->findAll(); @@ -262,7 +262,7 @@ class NoteModel extends UuidModel if ( $messageUrls !== [] && - ($previewCard = get_or_create_preview_card_from_url(new URI($messageUrls[0]),)) && + ($previewCard = get_or_create_preview_card_from_url(new URI($messageUrls[0]))) && ! $this->addPreviewCard($newNoteId, $previewCard->id) ) { $this->db->transRollback(); @@ -298,7 +298,7 @@ class NoteModel extends UuidModel 'queued', ); - $createActivity->set('id', base_url(route_to('activity', $note->actor->username, $activityId),)); + $createActivity->set('id', base_url(route_to('activity', $note->actor->username, $activityId))); model('ActivityModel') ->update($activityId, [ @@ -361,10 +361,10 @@ class NoteModel extends UuidModel ->where('id', $note->actor_id) ->decrement('notes_count'); - if ($note->is_reply) { + if ($note->in_reply_to_id !== null) { // Note to remove is a reply model('NoteModel') - ->where('id', $this->uuid->fromString($note->in_reply_to_id) ->getBytes(),) + ->where('id', $this->uuid->fromString($note->in_reply_to_id) ->getBytes()) ->decrement('replies_count'); Events::trigger('on_reply_remove', $note); @@ -372,6 +372,7 @@ class NoteModel extends UuidModel // remove all note reblogs foreach ($note->reblogs as $reblog) { + // FIXME: issue when actor is not local, can't get actor information $this->removeNote($reblog); } @@ -410,7 +411,7 @@ class NoteModel extends UuidModel 'queued', ); - $deleteActivity->set('id', base_url(route_to('activity', $note->actor->username, $activityId),)); + $deleteActivity->set('id', base_url(route_to('activity', $note->actor->username, $activityId))); model('ActivityModel') ->update($activityId, [ @@ -444,7 +445,7 @@ class NoteModel extends UuidModel $noteId = $this->addNote($reply, $createPreviewCard, $registerActivity); model('NoteModel') - ->where('id', $this->uuid->fromString($reply->in_reply_to_id) ->getBytes(),) + ->where('id', $this->uuid->fromString($reply->in_reply_to_id) ->getBytes()) ->increment('replies_count'); Events::trigger('on_note_reply', $reply); @@ -491,7 +492,7 @@ class NoteModel extends UuidModel 'queued', ); - $announceActivity->set('id', base_url(route_to('activity', $note->actor->username, $activityId),)); + $announceActivity->set('id', base_url(route_to('activity', $note->actor->username, $activityId))); model('ActivityModel') ->update($activityId, [ @@ -517,7 +518,7 @@ class NoteModel extends UuidModel ->decrement('notes_count'); model('NoteModel') - ->where('id', $this->uuid->fromString($reblogNote->reblog_of_id) ->getBytes(),) + ->where('id', $this->uuid->fromString($reblogNote->reblog_of_id) ->getBytes()) ->decrement('reblogs_count'); if ($registerActivity) { @@ -536,7 +537,7 @@ class NoteModel extends UuidModel $announceActivity = new AnnounceActivity($reblogNote); $announceActivity->set( 'id', - base_url(route_to('activity', $reblogNote->actor->username, $activity->id,),), + base_url(route_to('activity', $reblogNote->actor->username, $activity->id)), ); $undoActivity @@ -554,10 +555,7 @@ class NoteModel extends UuidModel 'queued', ); - $undoActivity->set( - 'id', - base_url(route_to('activity', $reblogNote->actor->username, $activityId,),), - ); + $undoActivity->set('id', base_url(route_to('activity', $reblogNote->actor->username, $activityId))); model('ActivityModel') ->update($activityId, [ @@ -607,11 +605,11 @@ class NoteModel extends UuidModel cache() ->deleteMatching($cachePrefix . "note-{$hashedNoteUri}*"); - if ($note->is_reply) { + if ($note->in_reply_to_id !== null) { $this->clearCache($note->reply_to_note); } - if ($note->is_reblog) { + if ($note->reblog_of_id !== null) { $this->clearCache($note->reblog_of_note); } } @@ -627,7 +625,7 @@ class NoteModel extends UuidModel if (! isset($data['data']['uri'])) { $actor = model('ActorModel') - ->getActorById($data['data']['actor_id']); + ->getActorById((int) $data['data']['actor_id']); $data['data']['uri'] = base_url(route_to('note', $actor->username, $uuid4->toString())); } diff --git a/app/Libraries/ActivityPub/Models/PreviewCardModel.php b/app/Libraries/ActivityPub/Models/PreviewCardModel.php index 90c404eb..340dbe05 100644 --- a/app/Libraries/ActivityPub/Models/PreviewCardModel.php +++ b/app/Libraries/ActivityPub/Models/PreviewCardModel.php @@ -81,7 +81,7 @@ class PreviewCardModel extends Model 'activitypub_notes_preview_cards.preview_card_id = id', 'inner', ) - ->where('note_id', service('uuid') ->fromString($noteId) ->getBytes(),) + ->where('note_id', service('uuid') ->fromString($noteId) ->getBytes()) ->first(); cache() diff --git a/app/Libraries/ActivityPub/Objects/NoteObject.php b/app/Libraries/ActivityPub/Objects/NoteObject.php index e3087062..31e1b67b 100644 --- a/app/Libraries/ActivityPub/Objects/NoteObject.php +++ b/app/Libraries/ActivityPub/Objects/NoteObject.php @@ -35,7 +35,7 @@ class NoteObject extends ObjectType $this->published = $note->published_at->format(DATE_W3C); $this->attributedTo = $note->actor->uri; - if ($note->is_reply) { + if ($note->in_reply_to_id !== null) { $this->inReplyTo = $note->reply_to_note->uri; } diff --git a/app/Libraries/ActivityPub/WebFinger.php b/app/Libraries/ActivityPub/WebFinger.php index f81779ad..e472ff24 100644 --- a/app/Libraries/ActivityPub/WebFinger.php +++ b/app/Libraries/ActivityPub/WebFinger.php @@ -62,7 +62,7 @@ class WebFinger } if ( - ! ($actor = model('ActorModel')->getActorByUsername($username, $domain,)) + ! ($actor = model('ActorModel')->getActorByUsername($username, $domain)) ) { throw new Exception('Could not find actor'); } diff --git a/app/Libraries/Analytics/Controllers/EpisodeController.php b/app/Libraries/Analytics/Controllers/EpisodeController.php index f94fb386..2fb5ede1 100644 --- a/app/Libraries/Analytics/Controllers/EpisodeController.php +++ b/app/Libraries/Analytics/Controllers/EpisodeController.php @@ -35,13 +35,13 @@ class EpisodeController extends BaseController } if ( - ($this->podcast = (new PodcastModel())->getPodcastByName($params[0],)) === null + ($this->podcast = (new PodcastModel())->getPodcastByName($params[0])) === null ) { throw PageNotFoundException::forPageNotFound(); } if ( - ($this->episode = (new EpisodeModel())->getEpisodeBySlug($params[0], $params[1],)) !== null + ($this->episode = (new EpisodeModel())->getEpisodeBySlug($params[0], $params[1])) !== null ) { unset($params[1]); unset($params[0]); diff --git a/app/Libraries/Analytics/Helpers/analytics_helper.php b/app/Libraries/Analytics/Helpers/analytics_helper.php index 838ad78e..726e4db7 100644 --- a/app/Libraries/Analytics/Helpers/analytics_helper.php +++ b/app/Libraries/Analytics/Helpers/analytics_helper.php @@ -64,7 +64,7 @@ if (! function_exists('generate_episode_analytics_url')) { $audioFileDuration <= 60 ? $audioFileSize : $audioFileHeaderSize + - floor((($audioFileSize - $audioFileHeaderSize) / $audioFileDuration) * 60,), + floor((($audioFileSize - $audioFileHeaderSize) / $audioFileDuration) * 60), $audioFileSize, $audioFileDuration, $publicationDate->getTimestamp(), diff --git a/app/Libraries/Analytics/Models/AnalyticsPodcastByCountryModel.php b/app/Libraries/Analytics/Models/AnalyticsPodcastByCountryModel.php index 0b65fffc..c15b671f 100644 --- a/app/Libraries/Analytics/Models/AnalyticsPodcastByCountryModel.php +++ b/app/Libraries/Analytics/Models/AnalyticsPodcastByCountryModel.php @@ -45,7 +45,7 @@ class AnalyticsPodcastByCountryModel extends Model public function getDataWeekly(int $podcastId): array { if ( - ! ($found = cache("{$podcastId}_analytics_podcast_by_country_weekly",)) + ! ($found = cache("{$podcastId}_analytics_podcast_by_country_weekly")) ) { $oneWeekAgo = date('Y-m-d', strtotime('-1 week')); $found = $this->select('country_code as labels') @@ -73,7 +73,7 @@ class AnalyticsPodcastByCountryModel extends Model public function getDataYearly(int $podcastId): array { if ( - ! ($found = cache("{$podcastId}_analytics_podcast_by_country_yearly",)) + ! ($found = cache("{$podcastId}_analytics_podcast_by_country_yearly")) ) { $oneYearAgo = date('Y-m-d', strtotime('-1 year')); $found = $this->select('country_code as labels') diff --git a/app/Libraries/Analytics/Models/AnalyticsPodcastByEpisodeModel.php b/app/Libraries/Analytics/Models/AnalyticsPodcastByEpisodeModel.php index a3fc88df..a1a63388 100644 --- a/app/Libraries/Analytics/Models/AnalyticsPodcastByEpisodeModel.php +++ b/app/Libraries/Analytics/Models/AnalyticsPodcastByEpisodeModel.php @@ -43,7 +43,7 @@ class AnalyticsPodcastByEpisodeModel extends Model public function getDataByDay(int $podcastId, int $episodeId): array { if ( - ! ($found = cache("{$podcastId}_{$episodeId}_analytics_podcast_by_episode_by_day",)) + ! ($found = cache("{$podcastId}_{$episodeId}_analytics_podcast_by_episode_by_day")) ) { $found = $this->select('date as labels') ->selectSum('hits', 'values') @@ -69,7 +69,7 @@ class AnalyticsPodcastByEpisodeModel extends Model public function getDataByMonth(int $podcastId, int $episodeId = null): array { if ( - ! ($found = cache("{$podcastId}_{$episodeId}_analytics_podcast_by_episode_by_month",)) + ! ($found = cache("{$podcastId}_{$episodeId}_analytics_podcast_by_episode_by_month")) ) { $found = $this->select('DATE_FORMAT(date,"%Y-%m-01") as labels') ->selectSum('hits', 'values') diff --git a/app/Libraries/Analytics/Models/AnalyticsPodcastByPlayerModel.php b/app/Libraries/Analytics/Models/AnalyticsPodcastByPlayerModel.php index b8b8f32a..76da85df 100644 --- a/app/Libraries/Analytics/Models/AnalyticsPodcastByPlayerModel.php +++ b/app/Libraries/Analytics/Models/AnalyticsPodcastByPlayerModel.php @@ -45,7 +45,7 @@ class AnalyticsPodcastByPlayerModel extends Model public function getDataByAppWeekly(int $podcastId): array { if ( - ! ($found = cache("{$podcastId}_analytics_podcasts_by_player_by_app_weekly",)) + ! ($found = cache("{$podcastId}_analytics_podcasts_by_player_by_app_weekly")) ) { $oneWeekAgo = date('Y-m-d', strtotime('-1 week')); $found = $this->select('app as labels') @@ -73,7 +73,7 @@ class AnalyticsPodcastByPlayerModel extends Model public function getDataByAppYearly(int $podcastId): array { if ( - ! ($found = cache("{$podcastId}_analytics_podcasts_by_player_by_app_yearly",)) + ! ($found = cache("{$podcastId}_analytics_podcasts_by_player_by_app_yearly")) ) { $oneYearAgo = date('Y-m-d', strtotime('-1 year')); $found = $this->select('app as labels') @@ -101,7 +101,7 @@ class AnalyticsPodcastByPlayerModel extends Model public function getDataByOsWeekly(int $podcastId): array { if ( - ! ($found = cache("{$podcastId}_analytics_podcasts_by_player_by_os_weekly",)) + ! ($found = cache("{$podcastId}_analytics_podcasts_by_player_by_os_weekly")) ) { $oneWeekAgo = date('Y-m-d', strtotime('-1 week')); $found = $this->select('os as labels') @@ -130,7 +130,7 @@ class AnalyticsPodcastByPlayerModel extends Model public function getDataByDeviceWeekly(int $podcastId): array { if ( - ! ($found = cache("{$podcastId}_analytics_podcasts_by_player_by_device_weekly",)) + ! ($found = cache("{$podcastId}_analytics_podcasts_by_player_by_device_weekly")) ) { $oneWeekAgo = date('Y-m-d', strtotime('-1 week')); $found = $this->select('device as labels') diff --git a/app/Libraries/Analytics/Models/AnalyticsPodcastByRegionModel.php b/app/Libraries/Analytics/Models/AnalyticsPodcastByRegionModel.php index be9b5af3..22d59d6f 100644 --- a/app/Libraries/Analytics/Models/AnalyticsPodcastByRegionModel.php +++ b/app/Libraries/Analytics/Models/AnalyticsPodcastByRegionModel.php @@ -47,7 +47,7 @@ class AnalyticsPodcastByRegionModel extends Model $locale = service('request') ->getLocale(); if ( - ! ($found = cache("{$podcastId}_analytics_podcast_by_region_{$locale}",)) + ! ($found = cache("{$podcastId}_analytics_podcast_by_region_{$locale}")) ) { $found = $this->select('country_code, region_code') ->selectSum('hits', 'value') diff --git a/app/Libraries/Analytics/Models/AnalyticsPodcastByServiceModel.php b/app/Libraries/Analytics/Models/AnalyticsPodcastByServiceModel.php index b0519119..160c8327 100644 --- a/app/Libraries/Analytics/Models/AnalyticsPodcastByServiceModel.php +++ b/app/Libraries/Analytics/Models/AnalyticsPodcastByServiceModel.php @@ -45,7 +45,7 @@ class AnalyticsPodcastByServiceModel extends Model public function getDataByServiceWeekly(int $podcastId): array { if ( - ! ($found = cache("{$podcastId}_analytics_podcasts_by_service_weekly",)) + ! ($found = cache("{$podcastId}_analytics_podcasts_by_service_weekly")) ) { $oneWeekAgo = date('Y-m-d', strtotime('-1 week')); $found = $this->select('service as labels') diff --git a/app/Libraries/Analytics/Models/AnalyticsPodcastModel.php b/app/Libraries/Analytics/Models/AnalyticsPodcastModel.php index 630c7c41..f2f2a702 100644 --- a/app/Libraries/Analytics/Models/AnalyticsPodcastModel.php +++ b/app/Libraries/Analytics/Models/AnalyticsPodcastModel.php @@ -67,7 +67,7 @@ class AnalyticsPodcastModel extends Model public function getDataByWeekday(int $podcastId): array { if (! ($found = cache("{$podcastId}_analytics_podcasts_by_weekday"))) { - $found = $this->select('LEFT(DAYNAME(date),3) as labels, WEEKDAY(date) as sort_labels',) + $found = $this->select('LEFT(DAYNAME(date),3) as labels, WEEKDAY(date) as sort_labels') ->selectSum('hits', 'values') ->where([ 'podcast_id' => $podcastId, @@ -91,7 +91,7 @@ class AnalyticsPodcastModel extends Model public function getDataBandwidthByDay(int $podcastId): array { if (! ($found = cache("{$podcastId}_analytics_podcast_by_bandwidth"))) { - $found = $this->select('date as labels, round(bandwidth / 1048576, 1) as `values`',) + $found = $this->select('date as labels, round(bandwidth / 1048576, 1) as `values`') ->where([ 'podcast_id' => $podcastId, 'date >' => date('Y-m-d', strtotime('-60 days')), @@ -136,7 +136,7 @@ class AnalyticsPodcastModel extends Model public function getDataUniqueListenersByDay(int $podcastId): array { if ( - ! ($found = cache("{$podcastId}_analytics_podcast_unique_listeners_by_day",)) + ! ($found = cache("{$podcastId}_analytics_podcast_unique_listeners_by_day")) ) { $found = $this->select('date as labels, unique_listeners as values') ->where([ @@ -160,7 +160,7 @@ class AnalyticsPodcastModel extends Model public function getDataUniqueListenersByMonth(int $podcastId): array { if ( - ! ($found = cache("{$podcastId}_analytics_podcast_unique_listeners_by_month",)) + ! ($found = cache("{$podcastId}_analytics_podcast_unique_listeners_by_month")) ) { $found = $this->select('DATE_FORMAT(date,"%Y-%m-01") as labels') ->selectSum('unique_listeners', 'values') @@ -185,7 +185,7 @@ class AnalyticsPodcastModel extends Model public function getDataTotalListeningTimeByDay(int $podcastId): array { if ( - ! ($found = cache("{$podcastId}_analytics_podcast_listening_time_by_day",)) + ! ($found = cache("{$podcastId}_analytics_podcast_listening_time_by_day")) ) { $found = $this->select('date as labels') ->selectSum('duration', 'values') @@ -211,7 +211,7 @@ class AnalyticsPodcastModel extends Model public function getDataTotalListeningTimeByMonth(int $podcastId): array { if ( - ! ($found = cache("{$podcastId}_analytics_podcast_listening_time_by_month",)) + ! ($found = cache("{$podcastId}_analytics_podcast_listening_time_by_month")) ) { $found = $this->select('DATE_FORMAT(date,"%Y-%m-01") as labels') ->selectSum('duration', 'values') diff --git a/app/Libraries/Analytics/Models/AnalyticsWebsiteByEntryPageModel.php b/app/Libraries/Analytics/Models/AnalyticsWebsiteByEntryPageModel.php index fa425e8d..b49bb1a6 100644 --- a/app/Libraries/Analytics/Models/AnalyticsWebsiteByEntryPageModel.php +++ b/app/Libraries/Analytics/Models/AnalyticsWebsiteByEntryPageModel.php @@ -46,7 +46,7 @@ class AnalyticsWebsiteByEntryPageModel extends Model { if (! ($found = cache("{$podcastId}_analytics_website_by_entry_page"))) { $oneWeekAgo = date('Y-m-d', strtotime('-1 week')); - $found = $this->select("IF(entry_page_url='/','/',SUBSTRING_INDEX(entry_page_url,'/',-1)) as labels",) + $found = $this->select("IF(entry_page_url='/','/',SUBSTRING_INDEX(entry_page_url,'/',-1)) as labels") ->selectSum('hits', 'values') ->where([ 'podcast_id' => $podcastId, diff --git a/app/Libraries/Router.php b/app/Libraries/Router.php index 368c64f5..3f59a70b 100644 --- a/app/Libraries/Router.php +++ b/app/Libraries/Router.php @@ -54,7 +54,7 @@ class Router extends CodeIgniterRouter if (str_contains($key, '{locale}')) { $localeSegment = array_search( '{locale}', - preg_split('~[\/]*((^[a-zA-Z0-9])|\(([^()]*)\))*[\/]+~m', $key,), + preg_split('~[\/]*((^[a-zA-Z0-9])|\(([^()]*)\))*[\/]+~m', $key), true, ); @@ -104,7 +104,7 @@ class Router extends CodeIgniterRouter // check if the alternate-content has been requested in the accept // header and overwrite the $val with the matching controller method if ( - array_key_exists('alternate-content', $this->matchedRouteOptions,) && + array_key_exists('alternate-content', $this->matchedRouteOptions) && is_array($this->matchedRouteOptions['alternate-content']) ) { $request = Services::request(); @@ -119,7 +119,7 @@ class Router extends CodeIgniterRouter $expectedContentType = $parsedHeader[0]; foreach ($supported as $available) { if ( - $negotiate->callMatch($expectedContentType, $available, true,) + $negotiate->callMatch($expectedContentType, $available, true) ) { if ( array_key_exists( diff --git a/app/Models/CategoryModel.php b/app/Models/CategoryModel.php index fe91ac4f..5bfc38aa 100644 --- a/app/Models/CategoryModel.php +++ b/app/Models/CategoryModel.php @@ -130,7 +130,7 @@ class CategoryModel extends Model $cacheName = "podcast#{$podcastId}_categories"; if (! ($categories = cache($cacheName))) { $categories = $this->select('categories.*') - ->join('podcasts_categories', 'podcasts_categories.category_id = categories.id',) + ->join('podcasts_categories', 'podcasts_categories.category_id = categories.id') ->where('podcasts_categories.podcast_id', $podcastId) ->findAll(); diff --git a/app/Models/EpisodeModel.php b/app/Models/EpisodeModel.php index b3bff127..275c753f 100644 --- a/app/Models/EpisodeModel.php +++ b/app/Models/EpisodeModel.php @@ -265,7 +265,7 @@ class EpisodeModel extends Model */ public function getSecondsToNextUnpublishedEpisode(int $podcastId): int | false { - $result = $this->select('TIMESTAMPDIFF(SECOND, NOW(), `published_at`) as timestamp_diff',) + $result = $this->select('TIMESTAMPDIFF(SECOND, NOW(), `published_at`) as timestamp_diff') ->where([ 'podcast_id' => $podcastId, ]) diff --git a/app/Models/PersonModel.php b/app/Models/PersonModel.php index 20eed991..7b9aca80 100644 --- a/app/Models/PersonModel.php +++ b/app/Models/PersonModel.php @@ -423,7 +423,7 @@ class PersonModel extends Model */ protected function clearCache(array $data): array { - $personId = is_array($data['id']) ? $data['id']['id'] : $data['id']; + $personId = is_array($data['id']) ? $data['id'][0] : $data['id']; cache() ->delete('person_options'); diff --git a/app/Models/PlatformModel.php b/app/Models/PlatformModel.php index ab7f1f5a..5eb57279 100644 --- a/app/Models/PlatformModel.php +++ b/app/Models/PlatformModel.php @@ -99,7 +99,7 @@ class PlatformModel extends Model public function getPlatformsWithLinks(int $podcastId, string $platformType): array { if ( - ! ($found = cache("podcast#{$podcastId}_platforms_{$platformType}_withLinks",)) + ! ($found = cache("podcast#{$podcastId}_platforms_{$platformType}_withLinks")) ) { $found = $this->select( 'platforms.*, podcasts_platforms.link_url, podcasts_platforms.link_content, podcasts_platforms.is_visible, podcasts_platforms.is_on_embeddable_player', @@ -129,7 +129,7 @@ class PlatformModel extends Model $found = $this->select( 'platforms.*, podcasts_platforms.link_url, podcasts_platforms.link_content, podcasts_platforms.is_visible, podcasts_platforms.is_on_embeddable_player', ) - ->join('podcasts_platforms', 'podcasts_platforms.platform_slug = platforms.slug',) + ->join('podcasts_platforms', 'podcasts_platforms.platform_slug = platforms.slug') ->where('podcasts_platforms.podcast_id', $podcastId) ->where('platforms.type', $platformType) ->findAll(); diff --git a/app/Models/PodcastModel.php b/app/Models/PodcastModel.php index 05e200bc..1b20c1fe 100644 --- a/app/Models/PodcastModel.php +++ b/app/Models/PodcastModel.php @@ -175,7 +175,7 @@ class PodcastModel extends Model $cacheName = "user{$userId}_podcasts"; if (! ($found = cache($cacheName))) { $found = $this->select('podcasts.*') - ->join('podcasts_users', 'podcasts_users.podcast_id = podcasts.id',) + ->join('podcasts_users', 'podcasts_users.podcast_id = podcasts.id') ->where('podcasts_users.user_id', $userId) ->findAll(); @@ -268,7 +268,7 @@ class PodcastModel extends Model if (! ($found = cache($cacheName))) { $episodeModel = new EpisodeModel(); $found = $episodeModel - ->select('YEAR(published_at) as year, count(*) as number_of_episodes',) + ->select('YEAR(published_at) as year, count(*) as number_of_episodes') ->where([ 'podcast_id' => $podcastId, 'season_number' => null, diff --git a/app/Models/UserModel.php b/app/Models/UserModel.php index e228622a..63e90f98 100644 --- a/app/Models/UserModel.php +++ b/app/Models/UserModel.php @@ -29,7 +29,7 @@ class UserModel extends MythAuthUserModel if (! ($found = cache($cacheName))) { $found = $this->select('users.*, auth_groups.name as podcast_role') ->join('podcasts_users', 'podcasts_users.user_id = users.id') - ->join('auth_groups', 'auth_groups.id = podcasts_users.group_id',) + ->join('auth_groups', 'auth_groups.id = podcasts_users.group_id') ->where('podcasts_users.podcast_id', $podcastId) ->findAll(); @@ -42,7 +42,7 @@ class UserModel extends MythAuthUserModel public function getPodcastContributor(int $userId, int $podcastId): ?User { - return $this->select('users.*, podcasts_users.podcast_id as podcast_id, auth_groups.name as podcast_role',) + return $this->select('users.*, podcasts_users.podcast_id as podcast_id, auth_groups.name as podcast_role') ->join('podcasts_users', 'podcasts_users.user_id = users.id') ->join('auth_groups', 'auth_groups.id = podcasts_users.group_id') ->where([ diff --git a/app/Views/podcast/activity.php b/app/Views/podcast/activity.php index 45832393..eb6dd5b7 100644 --- a/app/Views/podcast/activity.php +++ b/app/Views/podcast/activity.php @@ -40,7 +40,7 @@
- is_reblog): ?> + reblog_of_id !== null): ?> $note->reblog_of_note, ]) ?> diff --git a/app/Views/podcast/activity_authenticated.php b/app/Views/podcast/activity_authenticated.php index bffb4f4c..d74f16c6 100644 --- a/app/Views/podcast/activity_authenticated.php +++ b/app/Views/podcast/activity_authenticated.php @@ -85,7 +85,7 @@
- is_reblog): ?> + reblog_of_id !== null): ?> $note->reblog_of_note, ]) ?>