From 700435010a411c673d5bef45696d5ff201b75f14 Mon Sep 17 00:00:00 2001 From: Visman Date: Thu, 2 Jul 2020 21:07:17 +0700 Subject: [PATCH] Coding style --- app/Controllers/Install.php | 7 +- app/Controllers/Routing.php | 552 ++++++++++++++++++++---- app/Core/DB/mysql.php | 40 +- app/Core/File.php | 5 +- app/Core/Func.php | 36 +- app/Core/Mail.php | 6 +- app/Core/Router.php | 10 +- app/Models/BanList/Delete.php | 8 +- app/Models/BanList/Filter.php | 16 +- app/Models/BanList/GetList.php | 13 +- app/Models/BanList/Insert.php | 7 +- app/Models/BanList/Update.php | 9 +- app/Models/Categories/Manager.php | 41 +- app/Models/Censorship/Load.php | 9 +- app/Models/Censorship/Refresh.php | 4 +- app/Models/Censorship/Save.php | 29 +- app/Models/Config/Save.php | 18 +- app/Models/Cookie/Model.php | 10 +- app/Models/Forum/CalcStat.php | 30 +- app/Models/Forum/Delete.php | 28 +- app/Models/Forum/LoadTree.php | 55 +-- app/Models/Forum/Markread.php | 47 +- app/Models/Forum/Model.php | 71 ++- app/Models/Forum/Refresh.php | 20 +- app/Models/Forum/Save.php | 18 +- app/Models/Group/Delete.php | 10 +- app/Models/Group/Model.php | 16 +- app/Models/Group/Perm.php | 63 +-- app/Models/Online/Info.php | 11 +- app/Models/Online/Model.php | 79 +++- app/Models/Page.php | 31 +- app/Models/Pages/Admin/Bans.php | 57 ++- app/Models/Pages/Admin/Categories.php | 27 +- app/Models/Pages/Admin/Forums.php | 56 ++- app/Models/Pages/Admin/Groups.php | 36 +- app/Models/Pages/Admin/Host.php | 7 +- app/Models/Pages/Admin/Options.php | 4 +- app/Models/Pages/Admin/Users/Action.php | 43 +- app/Models/Pages/Admin/Users/Result.php | 35 +- app/Models/Pages/Admin/Users/Stat.php | 28 +- app/Models/Pages/Auth.php | 19 +- app/Models/Pages/Delete.php | 19 +- app/Models/Pages/Forum.php | 9 +- app/Models/Pages/Index.php | 25 +- app/Models/Pages/Moderate.php | 26 +- app/Models/Pages/Post.php | 14 +- app/Models/Pages/PostFormTrait.php | 10 +- app/Models/Pages/Profile.php | 73 +++- app/Models/Pages/Profile/Config.php | 26 +- app/Models/Pages/Profile/Edit.php | 47 +- app/Models/Pages/Profile/Email.php | 44 +- app/Models/Pages/Profile/Mod.php | 34 +- app/Models/Pages/Profile/Pass.php | 34 +- app/Models/Pages/Profile/View.php | 30 +- app/Models/Pages/Redirect.php | 5 +- app/Models/Pages/Register.php | 17 +- app/Models/Pages/Report.php | 17 +- app/Models/Pages/Topic.php | 9 +- app/Models/Pages/Userlist.php | 10 +- app/Models/Post/Delete.php | 104 +++-- app/Models/Post/Load.php | 23 +- app/Models/Post/Model.php | 36 +- app/Models/Post/PreviousPost.php | 15 +- app/Models/Post/RebuildIndex.php | 17 +- app/Models/Post/UserInfoFromIP.php | 14 +- app/Models/Post/UserStat.php | 14 +- app/Models/Post/View.php | 11 +- app/Models/Report/Load.php | 29 +- app/Models/Report/Manager.php | 30 +- app/Models/Report/Model.php | 16 +- app/Models/Search/ActionP.php | 30 +- app/Models/Search/ActionT.php | 65 +-- app/Models/Search/Delete.php | 60 +-- app/Models/Search/Execute.php | 28 +- app/Models/Search/Index.php | 51 ++- app/Models/Search/Model.php | 5 +- app/Models/Topic/Access.php | 9 +- app/Models/Topic/CalcStat.php | 34 +- app/Models/Topic/Delete.php | 117 ++--- app/Models/Topic/Load.php | 43 +- app/Models/Topic/Merge.php | 33 +- app/Models/Topic/Model.php | 131 ++++-- app/Models/Topic/View.php | 13 +- app/Models/User/AdminsIds.php | 8 +- app/Models/User/ChangeGroup.php | 9 +- app/Models/User/Delete.php | 10 +- app/Models/User/Filter.php | 11 +- app/Models/User/Load.php | 39 +- app/Models/User/Model.php | 26 +- app/Models/User/Promote.php | 22 +- app/Models/User/UpdateCountPosts.php | 22 +- app/Models/User/UpdateCountTopics.php | 20 +- app/Models/User/UsersNumber.php | 8 +- app/bootstrap.php | 20 +- 94 files changed, 2250 insertions(+), 933 deletions(-) diff --git a/app/Controllers/Install.php b/app/Controllers/Install.php index e4a1481a..f2e08bfe 100644 --- a/app/Controllers/Install.php +++ b/app/Controllers/Install.php @@ -40,7 +40,12 @@ class Install $this->c->user = $this->c->users->create(['id' => 2, 'group_id' => $this->c->GROUP_ADMIN]); $r = $this->c->Router; - $r->add($r::DUO, '/install', 'Install:install', 'Install'); + $r->add( + $r::DUO, + '/install', + 'Install:install', + 'Install' + ); $method = $_SERVER['REQUEST_METHOD']; diff --git a/app/Controllers/Routing.php b/app/Controllers/Routing.php index bb7a3660..f43f3cbc 100644 --- a/app/Controllers/Routing.php +++ b/app/Controllers/Routing.php @@ -37,32 +37,88 @@ class Routing // регистрация/вход/выход if ($user->isGuest) { // вход - $r->add($r::DUO, '/login', 'Auth:login', 'Login'); + $r->add( + $r::DUO, + '/login', + 'Auth:login', + 'Login' + ); // забыли кодовую фразу - $r->add($r::DUO, '/login/forget', 'Auth:forget', 'Forget'); + $r->add( + $r::DUO, + '/login/forget', + 'Auth:forget', + 'Forget' + ); // смена кодовой фразы - $r->add($r::DUO, '/login/{id:\d+}/{key}/{hash}', 'Auth:changePass', 'ChangePassword'); + $r->add( + $r::DUO, + '/login/{id:\d+}/{key}/{hash}', + 'Auth:changePass', + 'ChangePassword' + ); // регистрация if ('1' == $config->o_regs_allow) { - $r->add($r::GET, '/registration', 'Rules:confirmation', 'Register'); - $r->add($r::PST, '/registration/agree', 'Register:reg', 'RegisterForm'); - $r->add($r::GET, '/registration/activate/{id:\d+}/{key}/{hash}', 'Register:activate', 'RegActivate'); + $r->add( + $r::GET, + '/registration', + 'Rules:confirmation', + 'Register' + ); + $r->add( + $r::PST, + '/registration/agree', + 'Register:reg', + 'RegisterForm' + ); + $r->add( + $r::GET, + '/registration/activate/{id:\d+}/{key}/{hash}', + 'Register:activate', + 'RegActivate' + ); } } else { // выход - $r->add($r::GET, '/logout/{token}', 'Auth:logout', 'Logout'); + $r->add( + $r::GET, + '/logout/{token}', + 'Auth:logout', + 'Logout' + ); // обработка "кривых" перенаправлений с логина и регистрации - $r->add($r::GET, '/login[/{tail:.*}]', 'Redirect:toIndex'); - $r->add($r::GET, '/registration[/{tail:.*}]', 'Redirect:toIndex'); + $r->add( + $r::GET, + '/login[/{tail:.*}]', + 'Redirect:toIndex' + ); + $r->add( + $r::GET, + '/registration[/{tail:.*}]', + 'Redirect:toIndex' + ); } // просмотр разрешен if ('1' == $user->g_read_board) { // главная - $r->add($r::GET, '/', 'Index:view', 'Index'); - $r->add($r::GET, '/index.php', 'Redirect:toIndex'); - $r->add($r::GET, '/index.html', 'Redirect:toIndex'); + $r->add( + $r::GET, + '/', + 'Index:view', + 'Index' + ); + $r->add( + $r::GET, + '/index.php', + 'Redirect:toIndex' + ); + $r->add( + $r::GET, + '/index.html', + 'Redirect:toIndex' + ); // правила if ( '1' == $config->o_rules @@ -71,96 +127,327 @@ class Routing || '1' == $config->o_regs_allow ) ) { - $r->add($r::GET, '/rules', 'Rules:view', 'Rules'); + $r->add( + $r::GET, + '/rules', + 'Rules:view', + 'Rules' + ); } // поиск if ('1' == $user->g_search) { - $r->add($r::GET, '/search[/simple/{keywords}[/{page:[1-9]\d*}]]', 'Search:view', 'Search'); - $r->add($r::PST, '/search', 'Search:view'); + $r->add( + $r::GET, + '/search[/simple/{keywords}[/{page:[1-9]\d*}]]', + 'Search:view', + 'Search' + ); + $r->add( + $r::PST, + '/search', + 'Search:view' + ); - $r->add($r::GET, '/search/advanced[/{keywords}/{author}/{forums}/{serch_in:\d}/{sort_by:\d}/{sort_dir:\d}/{show_as:\d}[/{page:[1-9]\d*}]]', 'Search:viewAdvanced', 'SearchAdvanced'); - $r->add($r::PST, '/search/advanced', 'Search:viewAdvanced'); + $r->add( + $r::GET, + '/search/advanced[/{keywords}/{author}/{forums}/{serch_in:\d}/{sort_by:\d}/{sort_dir:\d}/{show_as:\d}[/{page:[1-9]\d*}]]', + 'Search:viewAdvanced', + 'SearchAdvanced' + ); + $r->add( + $r::PST, + '/search/advanced', + 'Search:viewAdvanced' + ); - $r->add($r::GET, '/search[/user/{uid:[2-9]|[1-9]\d+}]/{action:(?!search)[a-z_]+}[/in_forum/{forum:[1-9]\d*}][/{page:[1-9]\d*}]', 'Search:action', 'SearchAction'); + $r->add( + $r::GET, + '/search[/user/{uid:[2-9]|[1-9]\d+}]/{action:(?!search)[a-z_]+}[/in_forum/{forum:[1-9]\d*}][/{page:[1-9]\d*}]', + 'Search:action', + 'SearchAction' + ); } // юзеры if ($user->viewUsers) { // список пользователей - $r->add($r::GET, '/userlist[/{group:all|[1-9]\d*}/{sort:username|registered|num_posts}/{dir:ASC|DESC}/{name}][/{page:[1-9]\d*}]', 'Userlist:view', 'Userlist'); - $r->add($r::PST, '/userlist', 'Userlist:view'); + $r->add( + $r::GET, + '/userlist[/{group:all|[1-9]\d*}/{sort:username|registered|num_posts}/{dir:ASC|DESC}/{name}][/{page:[1-9]\d*}]', + 'Userlist:view', + 'Userlist' + ); + $r->add( + $r::PST, + '/userlist', + 'Userlist:view' + ); // юзеры - $r->add($r::GET, '/user/{id:[2-9]|[1-9]\d+}/{name}', 'ProfileView:view', 'User'); - $r->add($r::DUO, '/user/{id:[2-9]|[1-9]\d+}/edit/profile', 'ProfileEdit:edit', 'EditUserProfile'); - $r->add($r::DUO, '/user/{id:[2-9]|[1-9]\d+}/edit/config', 'ProfileConfig:config', 'EditUserBoardConfig'); - $r->add($r::DUO, '/user/{id:[2-9]|[1-9]\d+}/edit/email', 'ProfileEmail:email', 'EditUserEmail'); - $r->add($r::DUO, '/user/{id:[2-9]|[1-9]\d+}/edit/passphrase', 'ProfilePass:pass', 'EditUserPass'); - $r->add($r::DUO, '/user/{id:[2-9]|[1-9]\d+}/edit/moderation', 'ProfileMod:moderation', 'EditUserModeration'); + $r->add( + $r::GET, + '/user/{id:[2-9]|[1-9]\d+}/{name}', + 'ProfileView:view', + 'User' + ); + $r->add( + $r::DUO, + '/user/{id:[2-9]|[1-9]\d+}/edit/profile', + 'ProfileEdit:edit', + 'EditUserProfile' + ); + $r->add( + $r::DUO, + '/user/{id:[2-9]|[1-9]\d+}/edit/config', + 'ProfileConfig:config', + 'EditUserBoardConfig' + ); + $r->add( + $r::DUO, + '/user/{id:[2-9]|[1-9]\d+}/edit/email', + 'ProfileEmail:email', + 'EditUserEmail' + ); + $r->add( + $r::DUO, + '/user/{id:[2-9]|[1-9]\d+}/edit/passphrase', + 'ProfilePass:pass', + 'EditUserPass' + ); + $r->add( + $r::DUO, + '/user/{id:[2-9]|[1-9]\d+}/edit/moderation', + 'ProfileMod:moderation', + 'EditUserModeration' + ); } elseif (! $user->isGuest) { // только свой профиль - $r->add($r::GET, '/user/{id:' . $user->id . '}/{name}', 'ProfileView:view', 'User'); - $r->add($r::DUO, '/user/{id:' . $user->id . '}/edit/profile', 'ProfileEdit:edit', 'EditUserProfile'); - $r->add($r::DUO, '/user/{id:' . $user->id . '}/edit/config', 'ProfileConfig:config', 'EditUserBoardConfig'); - $r->add($r::DUO, '/user/{id:' . $user->id . '}/edit/email', 'ProfileEmail:email', 'EditUserEmail'); - $r->add($r::DUO, '/user/{id:' . $user->id . '}/edit/passphrase', 'ProfilePass:pass', 'EditUserPass'); + $r->add( + $r::GET, + '/user/{id:' . $user->id . '}/{name}', + 'ProfileView:view', + 'User' + ); + $r->add( + $r::DUO, + '/user/{id:' . $user->id . '}/edit/profile', + 'ProfileEdit:edit', + 'EditUserProfile' + ); + $r->add( + $r::DUO, + '/user/{id:' . $user->id . '}/edit/config', + 'ProfileConfig:config', + 'EditUserBoardConfig' + ); + $r->add( + $r::DUO, + '/user/{id:' . $user->id . '}/edit/email', + 'ProfileEmail:email', + 'EditUserEmail' + ); + $r->add( + $r::DUO, + '/user/{id:' . $user->id . '}/edit/passphrase', + 'ProfilePass:pass', + 'EditUserPass' + ); } // смена своего email if (! $user->isGuest) { - $r->add($r::GET, '/user/{id:' . $user->id . '}/{email}/{key}/{hash}', 'ProfileEmail:setEmail', 'SetNewEmail'); + $r->add( + $r::GET, + '/user/{id:' . $user->id . '}/{email}/{key}/{hash}', + 'ProfileEmail:setEmail', + 'SetNewEmail' + ); } // пометка разделов прочитанными if (! $user->isGuest) { - $r->add($r::GET, '/forum/{id:\d+}/markread/{token}', 'Misc:markread', 'MarkRead'); + $r->add( + $r::GET, + '/forum/{id:\d+}/markread/{token}', + 'Misc:markread', + 'MarkRead' + ); } // разделы - $r->add($r::GET, '/forum/{id:[1-9]\d*}/{name}[/{page:[1-9]\d*}]', 'Forum:view', 'Forum' ); - $r->add($r::DUO, '/forum/{id:[1-9]\d*}/new/topic', 'Post:newTopic', 'NewTopic'); + $r->add( + $r::GET, + '/forum/{id:[1-9]\d*}/{name}[/{page:[1-9]\d*}]', + 'Forum:view', + 'Forum' + ); + $r->add( + $r::DUO, + '/forum/{id:[1-9]\d*}/new/topic', + 'Post:newTopic', + 'NewTopic' + ); // темы - $r->add($r::GET, '/topic/{id:[1-9]\d*}/{name}[/{page:[1-9]\d*}]', 'Topic:viewTopic', 'Topic' ); - $r->add($r::GET, '/topic/{id:[1-9]\d*}/view/new', 'Topic:viewNew', 'TopicViewNew' ); - $r->add($r::GET, '/topic/{id:[1-9]\d*}/view/unread', 'Topic:viewUnread', 'TopicViewUnread'); - $r->add($r::GET, '/topic/{id:[1-9]\d*}/view/last', 'Topic:viewLast', 'TopicViewLast' ); - $r->add($r::GET, '/topic/{id:[1-9]\d*}/new/reply[/{quote:[1-9]\d*}]', 'Post:newReply', 'NewReply' ); - $r->add($r::PST, '/topic/{id:[1-9]\d*}/new/reply', 'Post:newReply' ); + $r->add( + $r::GET, + '/topic/{id:[1-9]\d*}/{name}[/{page:[1-9]\d*}]', + 'Topic:viewTopic', + 'Topic' + ); + $r->add( + $r::GET, + '/topic/{id:[1-9]\d*}/view/new', + 'Topic:viewNew', + 'TopicViewNew' + ); + $r->add( + $r::GET, + '/topic/{id:[1-9]\d*}/view/unread', + 'Topic:viewUnread', + 'TopicViewUnread' + ); + $r->add( + $r::GET, + '/topic/{id:[1-9]\d*}/view/last', + 'Topic:viewLast', + 'TopicViewLast' + ); + $r->add( + $r::GET, + '/topic/{id:[1-9]\d*}/new/reply[/{quote:[1-9]\d*}]', + 'Post:newReply', + 'NewReply' + ); + $r->add( + $r::PST, + '/topic/{id:[1-9]\d*}/new/reply', + 'Post:newReply' + ); // сообщения - $r->add($r::GET, '/post/{id:[1-9]\d*}#p{id}', 'Topic:viewPost', 'ViewPost' ); - $r->add($r::DUO, '/post/{id:[1-9]\d*}/edit', 'Edit:edit', 'EditPost' ); - $r->add($r::DUO, '/post/{id:[1-9]\d*}/delete', 'Delete:delete', 'DeletePost'); + $r->add( + $r::GET, + '/post/{id:[1-9]\d*}#p{id}', + 'Topic:viewPost', + 'ViewPost' + ); + $r->add( + $r::DUO, + '/post/{id:[1-9]\d*}/edit', + 'Edit:edit', + 'EditPost' + ); + $r->add( + $r::DUO, + '/post/{id:[1-9]\d*}/delete', + 'Delete:delete', + 'DeletePost' + ); // сигналы (репорты) if ( ! $user->isAdmin && ! $user->isGuest ) { // ???? - $r->add($r::DUO, '/post/{id:[1-9]\d*}/report', 'Report:report', 'ReportPost'); + $r->add( + $r::DUO, + '/post/{id:[1-9]\d*}/report', + 'Report:report', + 'ReportPost' + ); } } // админ и модератор if ($user->isAdmMod) { - $r->add($r::GET, '/admin/', 'AdminIndex:index', 'Admin'); - $r->add($r::GET, '/admin/statistics', 'AdminStatistics:statistics', 'AdminStatistics'); + $r->add( + $r::GET, + '/admin/', + 'AdminIndex:index', + 'Admin' + ); + $r->add( + $r::GET, + '/admin/statistics', + 'AdminStatistics:statistics', + 'AdminStatistics' + ); if ($this->c->userRules->viewIP) { - $r->add($r::GET, '/admin/get/host/{ip:[0-9a-fA-F:.]+}', 'AdminHost:view', 'AdminHost'); - $r->add($r::GET, '/admin/users/user/{id:[2-9]|[1-9]\d+}[/{page:[1-9]\d*}]', 'AdminUsersStat:view', 'AdminUserStat'); + $r->add( + $r::GET, + '/admin/get/host/{ip:[0-9a-fA-F:.]+}', + 'AdminHost:view', + 'AdminHost' + ); + $r->add( + $r::GET, + '/admin/users/user/{id:[2-9]|[1-9]\d+}[/{page:[1-9]\d*}]', + 'AdminUsersStat:view', + 'AdminUserStat' + ); } - $r->add($r::DUO, '/admin/users', 'AdminUsers:view', 'AdminUsers'); - $r->add($r::DUO, '/admin/users/result/{data}[/{page:[1-9]\d*}]', 'AdminUsersResult:view', 'AdminUsersResult'); - $r->add($r::DUO, '/admin/users/{action:\w+}/{ids:\d+(?:-\d+)*}[/{token}]', 'AdminUsersAction:view', 'AdminUsersAction'); + $r->add( + $r::DUO, + '/admin/users', + 'AdminUsers:view', + 'AdminUsers' + ); + $r->add( + $r::DUO, + '/admin/users/result/{data}[/{page:[1-9]\d*}]', + 'AdminUsersResult:view', + 'AdminUsersResult' + ); + $r->add( + $r::DUO, + '/admin/users/{action:\w+}/{ids:\d+(?:-\d+)*}[/{token}]', + 'AdminUsersAction:view', + 'AdminUsersAction' + ); - $r->add($r::GET, '/admin/users/promote/{uid:[2-9]|[1-9]\d+}/{pid:[1-9]\d*}/{token}', 'AdminUsersPromote:promote', 'AdminUserPromote'); + $r->add( + $r::GET, + '/admin/users/promote/{uid:[2-9]|[1-9]\d+}/{pid:[1-9]\d*}/{token}', + 'AdminUsersPromote:promote', + 'AdminUserPromote' + ); if ($user->isAdmin) { - $r->add($r::DUO, '/admin/users/new', 'AdminUsersNew:view', 'AdminUsersNew'); + $r->add( + $r::DUO, + '/admin/users/new', + 'AdminUsersNew:view', + 'AdminUsersNew' + ); } if ($this->c->userRules->banUsers) { - $r->add($r::DUO, '/admin/bans', 'AdminBans:view', 'AdminBans'); - $r->add($r::DUO, '/admin/bans/new[/{ids:\d+(?:-\d+)*}[/{uid:[2-9]|[1-9]\d+}]]', 'AdminBans:add', 'AdminBansNew'); - $r->add($r::DUO, '/admin/bans/edit/{id:[1-9]\d*}', 'AdminBans:edit', 'AdminBansEdit'); - $r->add($r::GET, '/admin/bans/result/{data}[/{page:[1-9]\d*}]', 'AdminBans:result', 'AdminBansResult'); - $r->add($r::GET, '/admin/bans/delete/{id:[1-9]\d*}/{token}[/{uid:[2-9]|[1-9]\d+}]', 'AdminBans:delete', 'AdminBansDelete'); + $r->add( + $r::DUO, + '/admin/bans', + 'AdminBans:view', + 'AdminBans' + ); + $r->add( + $r::DUO, + '/admin/bans/new[/{ids:\d+(?:-\d+)*}[/{uid:[2-9]|[1-9]\d+}]]', + 'AdminBans:add', + 'AdminBansNew' + ); + $r->add( + $r::DUO, + '/admin/bans/edit/{id:[1-9]\d*}', + 'AdminBans:edit', + 'AdminBansEdit' + ); + $r->add( + $r::GET, + '/admin/bans/result/{data}[/{page:[1-9]\d*}]', + 'AdminBans:result', + 'AdminBansResult' + ); + $r->add( + $r::GET, + '/admin/bans/delete/{id:[1-9]\d*}/{token}[/{uid:[2-9]|[1-9]\d+}]', + 'AdminBans:delete', + 'AdminBansDelete' + ); } if ( @@ -168,33 +455,138 @@ class Routing || '0' == $config->o_report_method || '2' == $config->o_report_method ) { - $r->add($r::GET, '/admin/reports', 'AdminReports:view', 'AdminReports'); - $r->add($r::GET, '/admin/reports/zap/{id:[1-9]\d*}/{token}', 'AdminReports:zap', 'AdminReportsZap'); + $r->add( + $r::GET, + '/admin/reports', + 'AdminReports:view', + 'AdminReports' + ); + $r->add( + $r::GET, + '/admin/reports/zap/{id:[1-9]\d*}/{token}', + 'AdminReports:zap', + 'AdminReportsZap' + ); } - $r->add($r::PST, '/moderate', 'Moderate:action', 'Moderate'); + $r->add( + $r::PST, + '/moderate', + 'Moderate:action', + 'Moderate' + ); } // только админ if ($user->isAdmin) { - $r->add($r::GET, '/admin/statistics/info', 'AdminStatistics:info', 'AdminInfo' ); - $r->add($r::DUO, '/admin/options', 'AdminOptions:edit', 'AdminOptions' ); - $r->add($r::DUO, '/admin/permissions', 'AdminPermissions:edit', 'AdminPermissions' ); - $r->add($r::DUO, '/admin/categories', 'AdminCategories:view', 'AdminCategories' ); - $r->add($r::DUO, '/admin/categories/{id:[1-9]\d*}/delete', 'AdminCategories:delete', 'AdminCategoriesDelete'); - $r->add($r::DUO, '/admin/forums', 'AdminForums:view', 'AdminForums' ); - $r->add($r::DUO, '/admin/forums/new', 'AdminForums:edit', 'AdminForumsNew' ); - $r->add($r::DUO, '/admin/forums/{id:[1-9]\d*}/edit', 'AdminForums:edit', 'AdminForumsEdit' ); - $r->add($r::DUO, '/admin/forums/{id:[1-9]\d*}/delete', 'AdminForums:delete', 'AdminForumsDelete' ); - $r->add($r::GET, '/admin/groups', 'AdminGroups:view', 'AdminGroups' ); - $r->add($r::PST, '/admin/groups/default', 'AdminGroups:defaultSet', 'AdminGroupsDefault'); - $r->add($r::PST, '/admin/groups/new[/{base:[1-9]\d*}]', 'AdminGroups:edit', 'AdminGroupsNew' ); - $r->add($r::DUO, '/admin/groups/{id:[1-9]\d*}/edit', 'AdminGroups:edit', 'AdminGroupsEdit' ); - $r->add($r::DUO, '/admin/groups/{id:[1-9]\d*}/delete', 'AdminGroups:delete', 'AdminGroupsDelete' ); - $r->add($r::DUO, '/admin/censoring', 'AdminCensoring:edit', 'AdminCensoring' ); - $r->add($r::DUO, '/admin/maintenance', 'AdminMaintenance:view', 'AdminMaintenance' ); - $r->add($r::PST, '/admin/maintenance/rebuild', 'AdminMaintenance:rebuild', 'AdminMaintenanceRebuild'); - $r->add($r::GET, '/admin/maintenance/rebuild/{token}/{clear:[01]}/{limit:[1-9]\d*}/{start:[1-9]\d*}', 'AdminMaintenance:rebuild', 'AdminRebuildIndex' ); + $r->add( + $r::GET, + '/admin/statistics/info', + 'AdminStatistics:info', + 'AdminInfo' + ); + $r->add( + $r::DUO, + '/admin/options', + 'AdminOptions:edit', + 'AdminOptions' + ); + $r->add( + $r::DUO, + '/admin/permissions', + 'AdminPermissions:edit', + 'AdminPermissions' + ); + $r->add( + $r::DUO, + '/admin/categories', + 'AdminCategories:view', + 'AdminCategories' + ); + $r->add( + $r::DUO, + '/admin/categories/{id:[1-9]\d*}/delete', + 'AdminCategories:delete', + 'AdminCategoriesDelete' + ); + $r->add( + $r::DUO, + '/admin/forums', + 'AdminForums:view', + 'AdminForums' + ); + $r->add( + $r::DUO, + '/admin/forums/new', + 'AdminForums:edit', + 'AdminForumsNew' + ); + $r->add( + $r::DUO, + '/admin/forums/{id:[1-9]\d*}/edit', + 'AdminForums:edit', + 'AdminForumsEdit' + ); + $r->add( + $r::DUO, + '/admin/forums/{id:[1-9]\d*}/delete', + 'AdminForums:delete', + 'AdminForumsDelete' + ); + $r->add( + $r::GET, + '/admin/groups', + 'AdminGroups:view', + 'AdminGroups' + ); + $r->add( + $r::PST, + '/admin/groups/default', + 'AdminGroups:defaultSet', + 'AdminGroupsDefault' + ); + $r->add( + $r::PST, + '/admin/groups/new[/{base:[1-9]\d*}]', + 'AdminGroups:edit', + 'AdminGroupsNew' + ); + $r->add( + $r::DUO, + '/admin/groups/{id:[1-9]\d*}/edit', + 'AdminGroups:edit', + 'AdminGroupsEdit' + ); + $r->add( + $r::DUO, + '/admin/groups/{id:[1-9]\d*}/delete', + 'AdminGroups:delete', + 'AdminGroupsDelete' + ); + $r->add( + $r::DUO, + '/admin/censoring', + 'AdminCensoring:edit', + 'AdminCensoring' + ); + $r->add( + $r::DUO, + '/admin/maintenance', + 'AdminMaintenance:view', + 'AdminMaintenance' + ); + $r->add( + $r::PST, + '/admin/maintenance/rebuild', + 'AdminMaintenance:rebuild', + 'AdminMaintenanceRebuild' + ); + $r->add( + $r::GET, + '/admin/maintenance/rebuild/{token}/{clear:[01]}/{limit:[1-9]\d*}/{start:[1-9]\d*}', + 'AdminMaintenance:rebuild', + 'AdminRebuildIndex' + ); } diff --git a/app/Core/DB/mysql.php b/app/Core/DB/mysql.php index 7866ed17..794a18c6 100644 --- a/app/Core/DB/mysql.php +++ b/app/Core/DB/mysql.php @@ -157,7 +157,14 @@ class Mysql { $table = ($noPrefix ? '' : $this->dbPrefix) . $table; try { - $stmt = $this->db->query('SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ?s:table', [':table' => $table]); + $vars = [ + ':table' => $table, + ]; + $query = 'SELECT 1 + FROM INFORMATION_SCHEMA.TABLES + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ?s:table'; + + $stmt = $this->db->query($query, $vars); $result = $stmt->fetch(); $stmt->closeCursor(); } catch (PDOException $e) { @@ -179,7 +186,15 @@ class Mysql { $table = ($noPrefix ? '' : $this->dbPrefix) . $table; try { - $stmt = $this->db->query('SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ?s:table AND COLUMN_NAME = ?s:field', [':table' => $table, ':field' => $field]); + $vars = [ + ':table' => $table, + ':field' => $field, + ]; + $query = 'SELECT 1 + FROM INFORMATION_SCHEMA.COLUMNS + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ?s:table AND COLUMN_NAME = ?s:field'; + + $stmt = $this->db->query($query, $vars); $result = $stmt->fetch(); $stmt->closeCursor(); } catch (PDOException $e) { @@ -202,7 +217,15 @@ class Mysql $table = ($noPrefix ? '' : $this->dbPrefix) . $table; $index = 'PRIMARY' == $index ? $index : $table . '_' . $index; try { - $stmt = $this->db->query('SELECT 1 FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ?s:table AND INDEX_NAME = ?s:index', [':table' => $table, ':index' => $index]); + $vars = [ + ':table' => $table, + ':index' => $index, + ]; + $query = 'SELECT 1 + FROM INFORMATION_SCHEMA.STATISTICS + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ?s:table AND INDEX_NAME = ?s:index'; + + $stmt = $this->db->query($query, $vars); $result = $stmt->fetch(); $stmt->closeCursor(); } catch (PDOException $e) { @@ -546,9 +569,16 @@ class Mysql */ public function getMap(): array { - $stmt = $this->db->query('SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME LIKE ?s', ["{$this->dbPrefix}%"]); + $vars = [ + "{$this->dbPrefix}%", + ]; + $query = 'SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE + FROM INFORMATION_SCHEMA.COLUMNS + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME LIKE ?s'; + + $stmt = $this->db->query($query, $vars); $result = []; - $table = null; + $table = null; while ($row = $stmt->fetch()) { if ($table !== $row['TABLE_NAME']) { $table = $row['TABLE_NAME']; diff --git a/app/Core/File.php b/app/Core/File.php index 6fd7b713..16d67df7 100644 --- a/app/Core/File.php +++ b/app/Core/File.php @@ -120,7 +120,10 @@ class File protected function filterName(string $name): string { if (\function_exists('\\transliterator_transliterate')) { - $name = \transliterator_transliterate("Any-Latin; NFD; [:Nonspacing Mark:] Remove; NFC; [:Punctuation:] Remove; Lower();", $name); + $name = \transliterator_transliterate( + "Any-Latin; NFD; [:Nonspacing Mark:] Remove; NFC; [:Punctuation:] Remove; Lower();", + $name + ); } $name = \trim(\preg_replace('%[^\w.-]+%', '-', $name), '-'); diff --git a/app/Core/Func.php b/app/Core/Func.php index abcc710d..61cf8b0b 100644 --- a/app/Core/Func.php +++ b/app/Core/Func.php @@ -138,7 +138,17 @@ class Func $pages[] = [__($info, $cur, $all), 'info', null]; $cur = \min(\max(1, $cur), $all); if ($cur > 1) { - $pages[] = [$this->c->Router->link($marker, ['page' => $cur - 1] + $args), 'prev', null]; + $pages[] = [ + $this->c->Router->link( + $marker, + [ + 'page' => $cur - 1, + ] + + $args + ), + 'prev', + null, + ]; } $tpl = [1 => 1]; $start = $cur < 6 ? 2 : $cur - 2; @@ -160,7 +170,17 @@ class Func if ($i === $cur) { $pages[] = [null, $i, true]; } else { - $pages[] = [$this->c->Router->link($marker, ['page' => $i] + $args), $i, null]; + $pages[] = [ + $this->c->Router->link( + $marker, + [ + 'page' => $i, + ] + + $args + ), + $i, + null, + ]; } $k = $i; } @@ -168,7 +188,17 @@ class Func $cur > 0 && $cur < $all ) { - $pages[] = [$this->c->Router->link($marker, ['page' => $cur + 1] + $args), 'next', null]; + $pages[] = [ + $this->c->Router->link( + $marker, + [ + 'page' => $cur + 1, + ] + + $args + ), + 'next', + null, + ]; } } return $pages; diff --git a/app/Core/Mail.php b/app/Core/Mail.php index 64847e5e..dc50c020 100644 --- a/app/Core/Mail.php +++ b/app/Core/Mail.php @@ -101,7 +101,11 @@ class Mail if ( ! \is_string($email) || \mb_strlen($email, 'UTF-8') > 80 //???? for DB - || ! \preg_match('%^(?!\.)((?:(?:^|\.)(?>"(?!\s)(?:\x5C[^\x00-\x1F]|[^\x00-\x1F\x5C"])++(?"(?!\s)(?:\x5C[^\x00-\x1F]|[^\x00-\x1F\x5C"])++(? 64 ) { return false; diff --git a/app/Core/Router.php b/app/Core/Router.php index 7ea74e3d..d95144d6 100644 --- a/app/Core/Router.php +++ b/app/Core/Router.php @@ -159,7 +159,11 @@ class Router // значение не обязательно } else { // $link = preg_replace('%\[[^\[\]{}]*{' . preg_quote($name, '%') . '}[^\[\]{}]*\]%', '', $link); - $link = \preg_replace('%\[[^\[\]]*?{' . \preg_quote($name, '%') . '}[^\[\]]*+(\[((?>[^\[\]]*+)|(?1))+\])*?\]%', '', $link); + $link = \preg_replace( + '%\[[^\[\]]*?{' . \preg_quote($name, '%') . '}[^\[\]]*+(\[((?>[^\[\]]*+)|(?1))+\])*?\]%', + '', + $link + ); } } $link = \str_replace(['[', ']'], '', $link); @@ -238,7 +242,9 @@ class Router $args = []; foreach ($keys as $key) { if (isset($matches[$key])) { // ???? может isset($matches[$key][0]) тут поставить? - $args[$key] = isset($matches[$key][0]) ? \str_replace($this->subRepl, $this->subSearch, $matches[$key]) : null; + $args[$key] = isset($matches[$key][0]) + ? \str_replace($this->subRepl, $this->subSearch, $matches[$key]) + : null; } } return [self::OK, $handler, $args, $marker]; diff --git a/app/Models/BanList/Delete.php b/app/Models/BanList/Delete.php index 8ff130ea..ff7aa434 100644 --- a/app/Models/BanList/Delete.php +++ b/app/Models/BanList/Delete.php @@ -18,12 +18,14 @@ class Delete extends Method public function delete(int ...$ids): BanList { if (! empty($ids)) { - $vars = [ + $vars = [ ':ids' => $ids, ]; - $sql = 'DELETE FROM ::bans WHERE id IN (?ai:ids)'; + $query = 'DELETE + FROM ::bans + WHERE id IN (?ai:ids)'; - $this->c->DB->exec($sql, $vars); + $this->c->DB->exec($query, $vars); $this->model->load(); } diff --git a/app/Models/BanList/Filter.php b/app/Models/BanList/Filter.php index 0d658f2c..523ea1df 100644 --- a/app/Models/BanList/Filter.php +++ b/app/Models/BanList/Filter.php @@ -98,18 +98,18 @@ class Filter extends Method } if (empty($where)) { - $sql = "SELECT b.id - FROM ::bans AS b - ORDER BY {$orderBy}"; + $query = "SELECT b.id + FROM ::bans AS b + ORDER BY {$orderBy}"; } else { $where = \implode(' AND ', $where); - $sql = "SELECT b.id - FROM ::bans AS b - WHERE {$where} - ORDER BY {$orderBy}"; + $query = "SELECT b.id + FROM ::bans AS b + WHERE {$where} + ORDER BY {$orderBy}"; } - $ids = $this->c->DB->query($sql, $vars)->fetchAll(PDO::FETCH_COLUMN); + $ids = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN); return $ids; } diff --git a/app/Models/BanList/GetList.php b/app/Models/BanList/GetList.php index ebaa5cfa..00556864 100644 --- a/app/Models/BanList/GetList.php +++ b/app/Models/BanList/GetList.php @@ -15,16 +15,15 @@ class GetList extends Method */ public function getList(array $ids): array { - $vars = [ + $vars = [ ':ids' => $ids, ]; - $sql = 'SELECT b.id, b.username, b.ip, b.email, b.message, b.expire, u.id AS id_creator, u.username AS name_creator - FROM ::bans AS b - LEFT JOIN ::users AS u ON u.id=b.ban_creator - WHERE b.id IN (?ai:ids)'; - - $stmt = $this->c->DB->query($sql, $vars); + $query = 'SELECT b.id, b.username, b.ip, b.email, b.message, b.expire, u.id AS id_creator, u.username AS name_creator + FROM ::bans AS b + LEFT JOIN ::users AS u ON u.id=b.ban_creator + WHERE b.id IN (?ai:ids)'; + $stmt = $this->c->DB->query($query, $vars); $list = \array_fill_keys($ids, false); while ($row = $stmt->fetch()) { diff --git a/app/Models/BanList/Insert.php b/app/Models/BanList/Insert.php index 163b0b2e..35b6091e 100644 --- a/app/Models/BanList/Insert.php +++ b/app/Models/BanList/Insert.php @@ -34,9 +34,10 @@ class Insert extends Method $ban['creator'] = $this->c->user->id; - $sql = 'INSERT INTO ::bans (username, ip, email, message, expire, ban_creator) - VALUES (?s:username, ?s:ip, ?s:email, ?s:message, ?i:expire, ?i:creator)'; - $this->c->DB->exec($sql, $ban); + $query = 'INSERT INTO ::bans (username, ip, email, message, expire, ban_creator) + VALUES (?s:username, ?s:ip, ?s:email, ?s:message, ?i:expire, ?i:creator)'; + + $this->c->DB->exec($query, $ban); return $this->model; } diff --git a/app/Models/BanList/Update.php b/app/Models/BanList/Update.php index bcff32d7..a94801bb 100644 --- a/app/Models/BanList/Update.php +++ b/app/Models/BanList/Update.php @@ -33,10 +33,11 @@ class Update extends Method throw new InvalidArgumentException('Empty ban'); } - $sql = 'UPDATE ::bans - SET username=?s:username, ip=?s:ip, email=?s:email, message=?s:message, expire=?i:expire - WHERE id=?i:id'; - $this->c->DB->exec($sql, $ban); + $query = 'UPDATE ::bans + SET username=?s:username, ip=?s:ip, email=?s:email, message=?s:message, expire=?i:expire + WHERE id=?i:id'; + + $this->c->DB->exec($query, $ban); return $this->model; } diff --git a/app/Models/Categories/Manager.php b/app/Models/Categories/Manager.php index 22660b9e..1ad26f88 100644 --- a/app/Models/Categories/Manager.php +++ b/app/Models/Categories/Manager.php @@ -22,10 +22,12 @@ class Manager extends ManagerModel */ public function init(): self { - $sql = 'SELECT c.id, c.cat_name, c.disp_position - FROM ::categories AS c - ORDER BY c.disp_position'; - $this->repository = $this->c->DB->query($sql)->fetchAll(PDO::FETCH_UNIQUE); + $query = 'SELECT c.id, c.cat_name, c.disp_position + FROM ::categories AS c + ORDER BY c.disp_position'; + + $this->repository = $this->c->DB->query($query)->fetchAll(PDO::FETCH_UNIQUE); + return $this; } @@ -58,16 +60,17 @@ class Manager extends ManagerModel public function update(): self { foreach ($this->modified as $key => $value) { - $cat = $this->get($key); - $vars = [ + $cat = $this->get($key); + $vars = [ ':name' => $cat['cat_name'], ':position' => $cat['disp_position'], ':cid' => $key, ]; - $sql = 'UPDATE ::categories - SET cat_name=?s:name, disp_position=?i:position - WHERE id=?i:cid'; - $this->c->DB->query($sql, $vars); //???? + $query = 'UPDATE ::categories + SET cat_name=?s:name, disp_position=?i:position + WHERE id=?i:cid'; + + $this->c->DB->query($query, $vars); //???? } $this->modified = []; @@ -84,13 +87,13 @@ class Manager extends ManagerModel } ++$pos; - $vars = [ + $vars = [ ':name' => $name, ':position' => $pos, ]; - $sql = 'INSERT INTO ::categories (cat_name, disp_position) - VALUES (?s:name, ?i:position)'; - $this->c->DB->query($sql, $vars); + $query = 'INSERT INTO ::categories (cat_name, disp_position) + VALUES (?s:name, ?i:position)'; + $this->c->DB->query($query, $vars); $cid = $this->c->DB->lastInsertId(); @@ -114,12 +117,14 @@ class Manager extends ManagerModel $this->c->forums->delete(...$del); } - $vars = [ + $vars = [ ':cid' => $cid, ]; - $sql = 'DELETE FROM ::categories - WHERE id=?i:cid'; - $this->c->DB->exec($sql, $vars); + $query = 'DELETE + FROM ::categories + WHERE id=?i:cid'; + + $this->c->DB->exec($query, $vars); return $this; } diff --git a/app/Models/Censorship/Load.php b/app/Models/Censorship/Load.php index a3af54e0..5175ca3e 100644 --- a/app/Models/Censorship/Load.php +++ b/app/Models/Censorship/Load.php @@ -14,9 +14,10 @@ class Load extends Method */ public function load(): array { - $sql = 'SELECT ce.id, ce.search_for, ce.replace_with - FROM ::censoring AS ce - ORDER BY REPLACE(ce.search_for, \'*\', \'\')'; - return $this->c->DB->query($sql)->fetchAll(PDO::FETCH_UNIQUE); + $query = 'SELECT ce.id, ce.search_for, ce.replace_with + FROM ::censoring AS ce + ORDER BY REPLACE(ce.search_for, \'*\', \'\')'; + + return $this->c->DB->query($query)->fetchAll(PDO::FETCH_UNIQUE); } } diff --git a/app/Models/Censorship/Refresh.php b/app/Models/Censorship/Refresh.php index d825d8f9..6795170b 100644 --- a/app/Models/Censorship/Refresh.php +++ b/app/Models/Censorship/Refresh.php @@ -19,7 +19,9 @@ class Refresh extends Method $search = []; $replace = []; while ($row = $stmt->fetch()) { - $search[$row['id']] = '%(?model->searchList = $search; diff --git a/app/Models/Censorship/Save.php b/app/Models/Censorship/Save.php index ebc7c403..82393ed7 100644 --- a/app/Models/Censorship/Save.php +++ b/app/Models/Censorship/Save.php @@ -32,32 +32,37 @@ class Save extends Method $list[$id]['search_for'] !== $words[$id]['search_for'] || $list[$id]['replace_with'] !== $words[$id]['replace_with'] ) { - $vars = [ + $vars = [ ':id' => $id, ':search' => $list[$id]['search_for'], ':replace' => $list[$id]['replace_with'], ]; - $sql = 'UPDATE ::censoring - SET search_for=?s:search, replace_with=?s:replace - WHERE id=?i:id'; - $this->c->DB->exec($sql, $vars); + $query = 'UPDATE ::censoring + SET search_for=?s:search, replace_with=?s:replace + WHERE id=?i:id'; + + $this->c->DB->exec($query, $vars); } } elseif (0 === $id) { - $vars = [ + $vars = [ ':search' => $list[$id]['search_for'], ':replace' => $list[$id]['replace_with'], ]; - $sql = 'INSERT INTO ::censoring (search_for, replace_with) - VALUES (?s:search, ?s:replace)'; - $this->c->DB->exec($sql, $vars); + $query = 'INSERT INTO ::censoring (search_for, replace_with) + VALUES (?s:search, ?s:replace)'; + + $this->c->DB->exec($query, $vars); } } if ($forDel) { - $vars = [ + $vars = [ ':del' => $forDel ]; - $sql = 'DELETE FROM ::censoring WHERE id IN (?ai:del)'; - $this->c->DB->exec($sql, $vars); + $query = 'DELETE + FROM ::censoring + WHERE id IN (?ai:del)'; + + $this->c->DB->exec($query, $vars); } $this->c->Cache->delete('censorship'); diff --git a/app/Models/Config/Save.php b/app/Models/Config/Save.php index bd7532a6..9ef4f973 100644 --- a/app/Models/Config/Save.php +++ b/app/Models/Config/Save.php @@ -28,13 +28,27 @@ class Save extends Method ]; //???? //???? - $count = $this->c->DB->exec('UPDATE ::config SET conf_value=?s:value WHERE conf_name=?s:name', $vars); + $query = 'UPDATE ::config + SET conf_value=?s:value + WHERE conf_name=?s:name'; + + $count = $this->c->DB->exec($query, $vars); //???? //???? if (0 === $count) { //???? //???? - $this->c->DB->exec('INSERT INTO ::config (conf_name, conf_value) SELECT ?s:name, ?s:value FROM ::groups WHERE NOT EXISTS (SELECT 1 FROM ::config WHERE conf_name=?s:name) LIMIT 1', $vars); + $query = 'INSERT INTO ::config (conf_name, conf_value) + SELECT ?s:name, ?s:value + FROM ::groups + WHERE NOT EXISTS ( + SELECT 1 + FROM ::config + WHERE conf_name=?s:name + ) + LIMIT 1'; + + $this->c->DB->exec($query, $vars); } } $this->c->Cache->delete('config'); diff --git a/app/Models/Cookie/Model.php b/app/Models/Cookie/Model.php index 95c23cd4..f17fcbea 100644 --- a/app/Models/Cookie/Model.php +++ b/app/Models/Cookie/Model.php @@ -81,7 +81,9 @@ class Model extends ParentModel public function get(string $name, $default = null) { $name = $this->prefix . $name; - return isset($_COOKIE[$name]) ? $this->c->Secury->replInvalidChars($_COOKIE[$name]) : $default; + return isset($_COOKIE[$name]) + ? $this->c->Secury->replInvalidChars($_COOKIE[$name]) + : $default; } /** @@ -182,7 +184,11 @@ class Model extends ParentModel $passHash = $this->c->Secury->hmac($user->password . $expTime, $this->key2); $ckHash = $this->c->Secury->hmac($pfx . $user->id . $expTime . $passHash, $this->key1); - return $this->set(self::NAME, $pfx . $user->id . '_' . $expTime . '_' . $passHash . '_' . $ckHash, $expire); + return $this->set( + self::NAME, + $pfx . $user->id . '_' . $expTime . '_' . $passHash . '_' . $ckHash, + $expire + ); } /** diff --git a/app/Models/Forum/CalcStat.php b/app/Models/Forum/CalcStat.php index 72920c9d..4a3894f7 100644 --- a/app/Models/Forum/CalcStat.php +++ b/app/Models/Forum/CalcStat.php @@ -21,29 +21,29 @@ class CalcStat extends Method throw new RuntimeException('The model does not have ID'); } - $vars = [':fid' => $this->model->id]; - $sql = 'SELECT COUNT(t.id) - FROM ::topics AS t - WHERE t.forum_id=?i:fid AND t.moved_to!=0'; + $vars = [':fid' => $this->model->id]; + $query = 'SELECT COUNT(t.id) + FROM ::topics AS t + WHERE t.forum_id=?i:fid AND t.moved_to!=0'; - $moved = $this->c->DB->query($sql, $vars)->fetchColumn(); + $moved = $this->c->DB->query($query, $vars)->fetchColumn(); - $sql = 'SELECT COUNT(t.id) as num_topics, SUM(t.num_replies) as num_replies - FROM ::topics AS t - WHERE t.forum_id=?i:fid AND t.moved_to=0'; + $query = 'SELECT COUNT(t.id) as num_topics, SUM(t.num_replies) as num_replies + FROM ::topics AS t + WHERE t.forum_id=?i:fid AND t.moved_to=0'; - $result = $this->c->DB->query($sql, $vars)->fetch(); + $result = $this->c->DB->query($query, $vars)->fetch(); $this->model->num_topics = $result['num_topics'] + $moved; $this->model->num_posts = $result['num_topics'] + $result['num_replies']; - $sql = 'SELECT t.last_post, t.last_post_id, t.last_poster, t.subject as last_topic - FROM ::topics AS t - WHERE t.forum_id=?i:fid AND t.moved_to=0 - ORDER BY t.last_post DESC - LIMIT 1'; + $query = 'SELECT t.last_post, t.last_post_id, t.last_poster, t.subject as last_topic + FROM ::topics AS t + WHERE t.forum_id=?i:fid AND t.moved_to=0 + ORDER BY t.last_post DESC + LIMIT 1'; - $result = $this->c->DB->query($sql, $vars)->fetch(); + $result = $this->c->DB->query($query, $vars)->fetch(); if (empty($result)) { $this->model->last_post = 0; diff --git a/app/Models/Forum/Delete.php b/app/Models/Forum/Delete.php index 865f4b49..eabae90c 100644 --- a/app/Models/Forum/Delete.php +++ b/app/Models/Forum/Delete.php @@ -66,12 +66,14 @@ class Delete extends Action //???? подписки, опросы, предупреждения if ($users) { - $vars = [ + $vars = [ ':users' => $users, ]; - $sql = 'DELETE FROM ::mark_of_forum - WHERE uid IN (?ai:users)'; - $this->c->DB->exec($sql, $vars); + $query = 'DELETE + FROM ::mark_of_forum + WHERE uid IN (?ai:users)'; + + $this->c->DB->exec($query, $vars); //???? удаление модераторов из разделов } @@ -80,16 +82,20 @@ class Delete extends Action $this->c->groups->Perm->reset($forum); } - $vars = [ + $vars = [ ':forums' => \array_keys($forums), ]; - $sql = 'DELETE FROM ::mark_of_forum - WHERE fid IN (?ai:forums)'; - $this->c->DB->exec($sql, $vars); + $query = 'DELETE + FROM ::mark_of_forum + WHERE fid IN (?ai:forums)'; - $sql = 'DELETE FROM ::forums - WHERE id IN (?ai:forums)'; - $this->c->DB->exec($sql, $vars); + $this->c->DB->exec($query, $vars); + + $query = 'DELETE + FROM ::forums + WHERE id IN (?ai:forums)'; + + $this->c->DB->exec($query, $vars); } } } diff --git a/app/Models/Forum/LoadTree.php b/app/Models/Forum/LoadTree.php index d6b1cc7c..f07b9b72 100644 --- a/app/Models/Forum/LoadTree.php +++ b/app/Models/Forum/LoadTree.php @@ -57,28 +57,28 @@ class LoadTree extends Action ]; if ($this->c->user->isGuest) { - $sql = 'SELECT f.id, f.forum_desc, f.num_topics, f.sort_by, f.num_posts, - f.last_post, f.last_post_id, f.last_poster, f.last_topic - FROM ::forums AS f - WHERE id IN (?ai:forums)'; + $query = 'SELECT f.id, f.forum_desc, f.num_topics, f.sort_by, f.num_posts, + f.last_post, f.last_post_id, f.last_poster, f.last_topic + FROM ::forums AS f + WHERE id IN (?ai:forums)'; } elseif ('1' == $this->c->config->o_forum_subscriptions) { - $sql = 'SELECT f.id, f.forum_desc, f.num_topics, f.sort_by, f.num_posts, - f.last_post, f.last_post_id, f.last_poster, f.last_topic, - mof.mf_mark_all_read, s.user_id AS is_subscribed - FROM ::forums AS f - LEFT JOIN ::forum_subscriptions AS s ON (s.user_id=?i:uid AND s.forum_id=f.id) - LEFT JOIN ::mark_of_forum AS mof ON (mof.uid=?i:uid AND mof.fid=f.id) - WHERE f.id IN (?ai:forums)'; + $query = 'SELECT f.id, f.forum_desc, f.num_topics, f.sort_by, f.num_posts, + f.last_post, f.last_post_id, f.last_poster, f.last_topic, + mof.mf_mark_all_read, s.user_id AS is_subscribed + FROM ::forums AS f + LEFT JOIN ::forum_subscriptions AS s ON (s.user_id=?i:uid AND s.forum_id=f.id) + LEFT JOIN ::mark_of_forum AS mof ON (mof.uid=?i:uid AND mof.fid=f.id) + WHERE f.id IN (?ai:forums)'; } else { - $sql = 'SELECT f.id, f.forum_desc, f.num_topics, f.sort_by, f.num_posts, - f.last_post, f.last_post_id, f.last_poster, f.last_topic, - mof.mf_mark_all_read - FROM ::forums AS f - LEFT JOIN ::mark_of_forum AS mof ON (mof.uid=?i:id AND mof.fid=f.id) - WHERE f.id IN (?ai:forums)'; + $query = 'SELECT f.id, f.forum_desc, f.num_topics, f.sort_by, f.num_posts, + f.last_post, f.last_post_id, f.last_poster, f.last_topic, + mof.mf_mark_all_read + FROM ::forums AS f + LEFT JOIN ::mark_of_forum AS mof ON (mof.uid=?i:id AND mof.fid=f.id) + WHERE f.id IN (?ai:forums)'; } - $stmt = $this->c->DB->query($sql, $vars); + $stmt = $this->c->DB->query($query, $vars); while ($cur = $stmt->fetch()) { $list[$cur['id']]->replAttrs($cur)->__ready = true; } @@ -113,19 +113,20 @@ class LoadTree extends Action } // проверка по темам - $vars = [ + $vars = [ ':uid' => $this->c->user->id, ':forums' => \array_keys($time), ':max' => $max, ]; - $sql = 'SELECT t.forum_id, t.last_post - FROM ::topics AS t - LEFT JOIN ::mark_of_topic AS mot ON (mot.uid=?i:uid AND mot.tid=t.id) - WHERE t.forum_id IN(?ai:forums) - AND t.last_post>?i:max - AND t.moved_to=0 - AND (mot.mt_last_visit IS NULL OR t.last_post>mot.mt_last_visit)'; - $stmt = $this->c->DB->query($sql, $vars); + $query = 'SELECT t.forum_id, t.last_post + FROM ::topics AS t + LEFT JOIN ::mark_of_topic AS mot ON (mot.uid=?i:uid AND mot.tid=t.id) + WHERE t.forum_id IN(?ai:forums) + AND t.last_post>?i:max + AND t.moved_to=0 + AND (mot.mt_last_visit IS NULL OR t.last_post>mot.mt_last_visit)'; + + $stmt = $this->c->DB->query($query, $vars); while ($cur = $stmt->fetch()) { if ($cur['last_post'] > $time[$cur['forum_id']]) { $list[$cur['forum_id']]->__newMessages = true; //???? diff --git a/app/Models/Forum/Markread.php b/app/Models/Forum/Markread.php index 66ddf666..9ce7378e 100644 --- a/app/Models/Forum/Markread.php +++ b/app/Models/Forum/Markread.php @@ -29,37 +29,46 @@ class Markread extends Action $this->c->users->update($user); - $vars = [ + $vars = [ ':uid' => $user->id, ]; - $sql = 'DELETE FROM ::mark_of_topic WHERE uid=?i:uid'; - $this->c->DB->exec($sql, $vars); + $query = 'DELETE + FROM ::mark_of_topic + WHERE uid=?i:uid'; - $sql = 'DELETE FROM ::mark_of_forum WHERE uid=?i:uid'; - $this->c->DB->exec($sql, $vars); + $this->c->DB->exec($query, $vars); + + $query = 'DELETE + FROM ::mark_of_forum + WHERE uid=?i:uid'; + + $this->c->DB->exec($query, $vars); } elseif ($forum->id > 0) { - $vars = [ + $vars = [ ':uid' => $user->id, ':fid' => $forum->id, ':mark' => \time(), ]; - $sql = 'DELETE FROM ::mark_of_topic - WHERE uid=?i:uid AND tid IN ( - SELECT id - FROM ::topics - WHERE forum_id=?i:fid - )'; - $this->c->DB->exec($sql, $vars); + $query = 'DELETE + FROM ::mark_of_topic + WHERE uid=?i:uid AND tid IN ( + SELECT id + FROM ::topics + WHERE forum_id=?i:fid + )'; + + $this->c->DB->exec($query, $vars); if ($user->mf_mark_all_read) { // ???? - $sql = 'UPDATE ::mark_of_forum - SET mf_mark_all_read=?i:mark - WHERE uid=?i:uid AND fid=?i:fid'; + $query = 'UPDATE ::mark_of_forum + SET mf_mark_all_read=?i:mark + WHERE uid=?i:uid AND fid=?i:fid'; } else { // ???? - $sql = 'INSERT INTO ::mark_of_forum (uid, fid, mf_mark_all_read) - VALUES (?i:uid, ?i:fid, ?i:mark)'; + $query = 'INSERT INTO ::mark_of_forum (uid, fid, mf_mark_all_read) + VALUES (?i:uid, ?i:fid, ?i:mark)'; } - $this->c->DB->exec($sql, $vars); + + $this->c->DB->exec($query, $vars); } else { throw new RuntimeException('The model does not have ID'); } diff --git a/app/Models/Forum/Model.php b/app/Models/Forum/Model.php index 8a68fcfb..14cebcdc 100644 --- a/app/Models/Forum/Model.php +++ b/app/Models/Forum/Model.php @@ -105,7 +105,13 @@ class Model extends DataModel if (0 === $this->id) { return $this->c->Router->link('Index'); } else { - return $this->c->Router->link('Forum', ['id' => $this->id, 'name' => $this->forum_name]); + return $this->c->Router->link( + 'Forum', + [ + 'id' => $this->id, + 'name' => $this->forum_name, + ] + ); } } @@ -117,9 +123,20 @@ class Model extends DataModel protected function getlinkNew(): string { if (0 === $this->id) { - return $this->c->Router->link('SearchAction', ['action' => 'new']); + return $this->c->Router->link( + 'SearchAction', + [ + 'action' => 'new', + ] + ); } else { - return $this->c->Router->link('SearchAction', ['action' => 'new', 'forum' => $this->id]); + return $this->c->Router->link( + 'SearchAction', + [ + 'action' => 'new', + 'forum' => $this->id, + ] + ); } } @@ -133,7 +150,12 @@ class Model extends DataModel if ($this->last_post_id < 1) { return null; } else { - return $this->c->Router->link('ViewPost', ['id' => $this->last_post_id]); + return $this->c->Router->link( + 'ViewPost', + [ + 'id' => $this->last_post_id, + ] + ); } } @@ -144,7 +166,12 @@ class Model extends DataModel */ protected function getlinkCreateTopic(): string { - return $this->c->Router->link('NewTopic', ['id' => $this->id]); + return $this->c->Router->link( + 'NewTopic', + [ + 'id' => $this->id, + ] + ); } /** @@ -154,10 +181,17 @@ class Model extends DataModel */ protected function getlinkMarkRead(): string { - return $this->c->Router->link('MarkRead', [ + return $this->c->Router->link( + 'MarkRead', [ 'id' => $this->id, - 'token' => $this->c->Csrf->create('MarkRead', ['id' => $this->id]), - ]); + 'token' => $this->c->Csrf->create( + 'MarkRead', + [ + 'id' => $this->id, + ] + ), + ] + ); } /** @@ -311,7 +345,12 @@ class Model extends DataModel */ protected function getpagination(): array { - return $this->c->Func->paginate($this->numPages, $this->page, 'Forum', ['id' => $this->id, 'name' => $this->forum_name]); + return $this->c->Func->paginate( + $this->numPages, + $this->page, + 'Forum', + ['id' => $this->id, 'name' => $this->forum_name] + ); } /** @@ -353,18 +392,18 @@ class Model extends DataModel break; } - $vars = [ + $vars = [ ':fid' => $this->id, ':offset' => ($this->page - 1) * $this->c->user->disp_topics, ':rows' => $this->c->user->disp_topics, ]; - $sql = "SELECT t.id - FROM ::topics AS t - WHERE t.forum_id=?i:fid - ORDER BY t.sticky DESC, {$sortBy}, t.id DESC - LIMIT ?i:offset, ?i:rows"; + $query = "SELECT t.id + FROM ::topics AS t + WHERE t.forum_id=?i:fid + ORDER BY t.sticky DESC, {$sortBy}, t.id DESC + LIMIT ?i:offset, ?i:rows"; - $this->idsList = $this->c->DB->query($sql, $vars)->fetchAll(PDO::FETCH_COLUMN); + $this->idsList = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN); return empty($this->idsList) ? [] : $this->c->topics->view($this); } diff --git a/app/Models/Forum/Refresh.php b/app/Models/Forum/Refresh.php index dd8e1716..c45f20f6 100644 --- a/app/Models/Forum/Refresh.php +++ b/app/Models/Forum/Refresh.php @@ -31,19 +31,19 @@ class Refresh extends Action } if ('1' == $read) { - $list = []; - $vars = [ + $list = []; + $vars = [ ':gid' => $gid, ]; - $sql = 'SELECT f.cat_id, c.cat_name, f.id, f.forum_name, f.redirect_url, f.parent_forum_id, - f.moderators, f.no_sum_mess, f.disp_position, fp.post_topics, fp.post_replies - FROM ::categories AS c - INNER JOIN ::forums AS f ON c.id=f.cat_id - LEFT JOIN ::forum_perms AS fp ON (fp.group_id=?i:gid AND fp.forum_id=f.id) - WHERE fp.read_forum IS NULL OR fp.read_forum=1 - ORDER BY c.disp_position, c.id, f.disp_position'; + $query = 'SELECT f.cat_id, c.cat_name, f.id, f.forum_name, f.redirect_url, f.parent_forum_id, + f.moderators, f.no_sum_mess, f.disp_position, fp.post_topics, fp.post_replies + FROM ::categories AS c + INNER JOIN ::forums AS f ON c.id=f.cat_id + LEFT JOIN ::forum_perms AS fp ON (fp.group_id=?i:gid AND fp.forum_id=f.id) + WHERE fp.read_forum IS NULL OR fp.read_forum=1 + ORDER BY c.disp_position, c.id, f.disp_position'; - $stmt = $this->c->DB->query($sql, $vars); + $stmt = $this->c->DB->query($query, $vars); while ($row = $stmt->fetch()) { $row['moderators'] = $this->formatModers($row['moderators']); $list[$row['id']] = $row; diff --git a/app/Models/Forum/Save.php b/app/Models/Forum/Save.php index 5b771307..4b8bc39c 100644 --- a/app/Models/Forum/Save.php +++ b/app/Models/Forum/Save.php @@ -40,8 +40,10 @@ class Save extends Action return $forum; } $vars[] = $forum->id; + $query = 'UPDATE ::forums + SET ' . \implode(', ', $set) . ' WHERE id=?i'; - $this->c->DB->exec('UPDATE ::forums SET ' . \implode(', ', $set) . ' WHERE id=?i', $vars); + $this->c->DB->exec($query, $vars); // модификация категории у потомков при ее изменении if ( @@ -51,13 +53,15 @@ class Save extends Action foreach ($forum->descendants as $f) { $f->__cat_id = $values['cat_id']; } - $vars = [ + $vars = [ ':ids' => \array_keys($forum->descendants), ':category' => $values['cat_id'], ]; - $sql = 'UPDATE ::forums SET cat_id=?i:category WHERE id IN (?ai:ids)'; + $query = 'UPDATE ::forums + SET cat_id=?i:category + WHERE id IN (?ai:ids)'; - $this->c->DB->exec($sql, $vars); + $this->c->DB->exec($query, $vars); } $forum->resModified(); @@ -93,7 +97,11 @@ class Save extends Action if (empty($set)) { throw new RuntimeException('The model is empty'); } - $this->c->DB->query('INSERT INTO ::forums (' . \implode(', ', $set) . ') VALUES (' . \implode(', ', $set2) . ')', $vars); + + $query = 'INSERT INTO ::forums (' . \implode(', ', $set) . ') + VALUES (' . \implode(', ', $set2) . ')'; + + $this->c->DB->query($query, $vars); $forum->id = $this->c->DB->lastInsertId(); $forum->resModified(); diff --git a/app/Models/Group/Delete.php b/app/Models/Group/Delete.php index 2e161479..dfbc6c74 100644 --- a/app/Models/Group/Delete.php +++ b/app/Models/Group/Delete.php @@ -21,11 +21,13 @@ class Delete extends Action $this->manager->Perm->delete($group); - $vars = [ + $vars = [ ':gid' => $group->g_id, ]; - $sql = 'DELETE FROM ::groups - WHERE g_id=?i:gid'; - $this->c->DB->exec($sql, $vars); + $query = 'DELETE + FROM ::groups + WHERE g_id=?i:gid'; + + $this->c->DB->exec($query, $vars); } } diff --git a/app/Models/Group/Model.php b/app/Models/Group/Model.php index e40afa41..4a468b83 100644 --- a/app/Models/Group/Model.php +++ b/app/Models/Group/Model.php @@ -8,7 +8,12 @@ class Model extends DataModel { protected function getlinkEdit(): string { - return $this->c->Router->link('AdminGroupsEdit', ['id' => $this->g_id]); + return $this->c->Router->link( + 'AdminGroupsEdit', + [ + 'id' => $this->g_id, + ] + ); } protected function getcanDelete(): bool @@ -24,7 +29,14 @@ class Model extends DataModel protected function getlinkDelete(): ?string { - return $this->canDelete ? $this->c->Router->link('AdminGroupsDelete', ['id' => $this->g_id]) : null; + return $this->canDelete + ? $this->c->Router->link( + 'AdminGroupsDelete', + [ + 'id' => $this->g_id, + ] + ) + : null; } protected function getgroupGuest(): bool diff --git a/app/Models/Group/Perm.php b/app/Models/Group/Perm.php index d66d6116..872c4cc2 100644 --- a/app/Models/Group/Perm.php +++ b/app/Models/Group/Perm.php @@ -26,16 +26,17 @@ class Perm extends Action */ public function get(Forum $forum): array { - $vars = [ + $vars = [ ':fid' => $forum->id > 0 ? $forum->id : 0, ':adm' => $this->c->GROUP_ADMIN, ]; - $sql = 'SELECT g.g_id, fp.read_forum, fp.post_replies, fp.post_topics - FROM ::groups AS g - LEFT JOIN ::forum_perms AS fp ON (g.g_id=fp.group_id AND fp.forum_id=?i:fid) - WHERE g.g_id!=?i:adm - ORDER BY g.g_id'; - $perms = $this->c->DB->query($sql, $vars)->fetchAll(PDO::FETCH_UNIQUE); + $query = 'SELECT g.g_id, fp.read_forum, fp.post_replies, fp.post_topics + FROM ::groups AS g + LEFT JOIN ::forum_perms AS fp ON (g.g_id=fp.group_id AND fp.forum_id=?i:fid) + WHERE g.g_id!=?i:adm + ORDER BY g.g_id'; + + $perms = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_UNIQUE); $result = []; foreach ($perms as $gid => $perm) { @@ -95,13 +96,15 @@ class Perm extends Action $modDef || $modPerm ) { - $vars = [ + $vars = [ ':gid' => $id, ':fid' => $forum->id, ]; - $sql = 'DELETE FROM ::forum_perms - WHERE group_id=?i:gid AND forum_id=?i:fid'; - $this->c->DB->exec($sql, $vars); + $query = 'DELETE + FROM ::forum_perms + WHERE group_id=?i:gid AND forum_id=?i:fid'; + + $this->c->DB->exec($query, $vars); } if ($modDef) { @@ -112,8 +115,10 @@ class Perm extends Action $list[] = 'group_id'; $list[] = 'forum_id'; $list2 = \array_fill(0, \count($list), '?i'); - $sql = 'INSERT INTO ::forum_perms (' . \implode(', ', $list) . ') VALUES (' . \implode(', ', $list2) . ')'; - $this->c->DB->exec($sql, $vars); + $query = 'INSERT INTO ::forum_perms (' . \implode(', ', $list) . ') + VALUES (' . \implode(', ', $list2) . ')'; + + $this->c->DB->exec($query, $vars); } } } @@ -131,12 +136,14 @@ class Perm extends Action throw new RuntimeException('The forum does not have ID'); } - $vars = [ + $vars = [ ':fid' => $forum->id, ]; - $sql = 'DELETE FROM ::forum_perms - WHERE forum_id=?i:fid'; - $this->c->DB->exec($sql, $vars); + $query = 'DELETE + FROM ::forum_perms + WHERE forum_id=?i:fid'; + + $this->c->DB->exec($query, $vars); } /** @@ -152,12 +159,14 @@ class Perm extends Action throw new RuntimeException('The group does not have ID'); } - $vars = [ + $vars = [ ':gid' => $group->g_id, ]; - $sql = 'DELETE FROM ::forum_perms - WHERE group_id=?i:gid'; - $this->c->DB->exec($sql, $vars); + $query = 'DELETE + FROM ::forum_perms + WHERE group_id=?i:gid'; + + $this->c->DB->exec($query, $vars); } /** @@ -179,15 +188,15 @@ class Perm extends Action $this->delete($to); - $vars = [ + $vars = [ ':old' => $from->g_id, ':new' => $to->g_id, ]; - $sql = 'INSERT INTO ::forum_perms (group_id, forum_id, read_forum, post_replies, post_topics) - SELECT ?i:new, forum_id, read_forum, post_replies, post_topics - FROM ::forum_perms - WHERE group_id=?i:old'; + $query = 'INSERT INTO ::forum_perms (group_id, forum_id, read_forum, post_replies, post_topics) + SELECT ?i:new, forum_id, read_forum, post_replies, post_topics + FROM ::forum_perms + WHERE group_id=?i:old'; - $this->c->DB->exec($sql, $vars); + $this->c->DB->exec($query, $vars); } } diff --git a/app/Models/Online/Info.php b/app/Models/Online/Info.php index d6cb95df..98ab16fa 100644 --- a/app/Models/Online/Info.php +++ b/app/Models/Online/Info.php @@ -25,10 +25,13 @@ class Info extends Method if ('1' == $this->c->user->g_view_users) { foreach ($this->model->users as $id => $name) { $info[] = [ - $this->c->Router->link('User', [ - 'id' => $id, - 'name' => $name, - ]), + $this->c->Router->link( + 'User', + [ + 'id' => $id, + 'name' => $name, + ] + ), $name, ]; } diff --git a/app/Models/Online/Model.php b/app/Models/Online/Model.php index 21e923a2..d3db8faa 100644 --- a/app/Models/Online/Model.php +++ b/app/Models/Online/Model.php @@ -56,11 +56,19 @@ class Model extends ParentModel $needClean = false; if ($detail) { - $sql = 'SELECT o.user_id, o.ident, o.logged, o.o_position, o.o_name FROM ::online AS o ORDER BY o.logged'; + $query = 'SELECT o.user_id, o.ident, o.logged, o.o_position, o.o_name + FROM ::online AS o + ORDER BY o.logged'; } else { - $sql = 'SELECT o.user_id, o.ident, o.logged FROM ::online AS o ORDER BY o.logged'; + $query = 'SELECT o.user_id, o.ident, o.logged + FROM ::online AS o + ORDER BY o.logged'; } - $stmt = $this->c->DB->query($sql); + $stmt = $this->c->DB->query($query); + + $query = 'UPDATE ::users + SET last_visit=?i:last + WHERE id=?i:id'; while ($cur = $stmt->fetch()) { $this->visits[$cur['user_id']] = $cur['logged']; @@ -71,7 +79,12 @@ class Model extends ParentModel $needClean = true; if ($cur['user_id'] > 1) { - $this->c->DB->exec('UPDATE ::users SET last_visit=?i:last WHERE id=?i:id', [':last' => $cur['logged'], ':id' => $cur['user_id']]); //???? + $vars = [ + ':last' => $cur['logged'], + ':id' => $cur['user_id'], + ]; + + $this->c->DB->exec($query, $vars); //???? } } continue; @@ -107,7 +120,13 @@ class Model extends ParentModel // удаление просроченных посетителей if ($needClean) { - $this->c->DB->exec('DELETE FROM ::online WHERE logged $tVisit]); + $vars = [ + ':visit' => $tVisit, + ]; + $query = 'DELETE FROM ::online + WHERE loggedc->DB->exec($query, $vars); } // обновление максимального значение посетителей онлайн @@ -146,11 +165,24 @@ class Model extends ParentModel ':name' => (string) $this->c->user->isBot, ':ip' => $this->c->user->ip ]; + if ($this->c->user->logged > 0) { - $this->c->DB->exec('UPDATE ::online SET logged=?i:logged, o_position=?s:pos, o_name=?s:name WHERE user_id=1 AND ident=?s:ip', $vars); + $query = 'UPDATE ::online + SET logged=?i:logged, o_position=?s:pos, o_name=?s:name + WHERE user_id=1 AND ident=?s:ip'; } else { - $this->c->DB->exec('INSERT INTO ::online (user_id, ident, logged, o_position, o_name) SELECT 1, ?s:ip, ?i:logged, ?s:pos, ?s:name FROM ::groups WHERE NOT EXISTS (SELECT 1 FROM ::online WHERE user_id=1 AND ident=?s:ip) LIMIT 1', $vars); + $query = 'INSERT INTO ::online (user_id, ident, logged, o_position, o_name) + SELECT 1, ?s:ip, ?i:logged, ?s:pos, ?s:name + FROM ::groups + WHERE NOT EXISTS ( + SELECT 1 + FROM ::online + WHERE user_id=1 AND ident=?s:ip + ) + LIMIT 1'; } + + $this->c->DB->exec($query, $vars); } else { // пользователь $vars = [ @@ -159,11 +191,24 @@ class Model extends ParentModel ':id' => $this->c->user->id, ':name' => $this->c->user->username, ]; + if ($this->c->user->logged > 0) { - $this->c->DB->exec('UPDATE ::online SET logged=?i:logged, o_position=?s:pos WHERE user_id=?i:id', $vars); + $query = 'UPDATE ::online + SET logged=?i:logged, o_position=?s:pos + WHERE user_id=?i:id'; } else { - $this->c->DB->exec('INSERT INTO ::online (user_id, ident, logged, o_position) SELECT ?i:id, ?s:name, ?i:logged, ?s:pos FROM ::groups WHERE NOT EXISTS (SELECT 1 FROM ::online WHERE user_id=?i:id) LIMIT 1', $vars); + $query = 'INSERT INTO ::online (user_id, ident, logged, o_position) + SELECT ?i:id, ?s:name, ?i:logged, ?s:pos + FROM ::groups + WHERE NOT EXISTS ( + SELECT 1 + FROM ::online + WHERE user_id=?i:id + ) + LIMIT 1'; } + + $this->c->DB->exec($query, $vars); } } @@ -175,9 +220,21 @@ class Model extends ParentModel public function delete(User $user): void { if ($user->isGuest) { - $this->c->DB->exec('DELETE FROM ::online WHERE user_id=1 AND ident=?s:ip', [':ip' => $user->ip]); + $vars = [ + ':ip' => $user->ip, + ]; + $query = 'DELETE + FROM ::online + WHERE user_id=1 AND ident=?s:ip'; } else { - $this->c->DB->exec('DELETE FROM ::online WHERE user_id=?i:id', [':id' => $user->id]); + $vars = [ + ':id' => $user->id, + ]; + $query = 'DELETE + FROM ::online + WHERE user_id=?i:id'; } + + $this->c->DB->exec($query, $vars); } } diff --git a/app/Models/Page.php b/app/Models/Page.php index e933e7d7..d688a970 100644 --- a/app/Models/Page.php +++ b/app/Models/Page.php @@ -87,19 +87,34 @@ abstract class Page extends Model ) { $sub = []; $sub['latest'] = [ - $r->link('SearchAction', ['action' => 'latest_active_topics']), + $r->link( + 'SearchAction', + [ + 'action' => 'latest_active_topics', + ] + ), 'Latest active topics', 'Find latest active topics', ]; if (! $this->user->isGuest) { $sub['with-your-posts'] = [ - $r->link('SearchAction', ['action' => 'topics_with_your_posts']), + $r->link( + 'SearchAction', + [ + 'action' => 'topics_with_your_posts', + ] + ), 'Topics with your posts', 'Find topics with your posts', ]; } $sub['unanswered'] = [ - $r->link('SearchAction', ['action' => 'unanswered_topics']), + $r->link( + 'SearchAction', + [ + 'action' => 'unanswered_topics', + ] + ), 'Unanswered topics', 'Find unanswered topics', ]; @@ -128,7 +143,15 @@ abstract class Page extends Model $nav['admin'] = [$r->link('Admin'), 'Admin']; } - $nav['logout'] = [$r->link('Logout', ['token' => $this->c->Csrf->create('Logout')]), 'Logout']; + $nav['logout'] = [ + $r->link( + 'Logout', + [ + 'token' => $this->c->Csrf->create('Logout'), + ] + ), + 'Logout', + ]; } if ( diff --git a/app/Models/Pages/Admin/Bans.php b/app/Models/Pages/Admin/Bans.php index a56af235..90c88161 100644 --- a/app/Models/Pages/Admin/Bans.php +++ b/app/Models/Pages/Admin/Bans.php @@ -254,9 +254,15 @@ class Bans extends Admin protected function formBan(array $data = [], array $args = []): array { $form = [ - 'action' => $this->c->Router->link($this->formBanPage, $args), + 'action' => $this->c->Router->link( + $this->formBanPage, + $args + ), 'hidden' => [ - 'token' => $this->c->Csrf->create($this->formBanPage, $args), + 'token' => $this->c->Csrf->create( + $this->formBanPage, + $args + ), ], 'sets' => [], 'btns' => [ @@ -411,7 +417,15 @@ class Bans extends Admin $this->nameTpl = 'admin/bans_result'; $this->mainSuffix = '-one-column'; - $this->aCrumbs[] = [$this->c->Router->link('AdminBansResult', ['data' => $args['data']]), __('Results head')]; + $this->aCrumbs[] = [ + $this->c->Router->link( + 'AdminBansResult', + [ + 'data' => $args['data'], + ] + ), + __('Results head'), + ]; $this->formResult = $this->form($banList, $startNum, $args); $this->pagination = $this->c->Func->paginate($pages, $page, 'AdminBansResult', ['data' => $args['data']]); @@ -496,7 +510,13 @@ class Bans extends Admin 'type' => '1' == $this->c->user->g_view_users && $ban['id_creator'] > 1 ? 'link' : 'str', 'caption' => __('Results banned by head'), 'value' => $ban['name_creator'], - 'href' => $this->c->Router->link('User', ['id' => $ban['id_creator'], 'name' => $ban['name_creator'],]), // ???? + 'href' => $this->c->Router->link( + 'User', + [ + 'id' => $ban['id_creator'], + 'name' => $ban['name_creator'], + ] + ), // ???? ]; $fields[] = [ 'type' => 'endwrap', @@ -515,7 +535,10 @@ class Bans extends Admin 'value' => '✎', 'caption' => __('Results actions head'), 'title' => __('Edit'), - 'link' => $this->c->Router->link('AdminBansEdit', $arr), + 'link' => $this->c->Router->link( + 'AdminBansEdit', + $arr + ), ]; $fields["delete-btn{$number}"] = [ 'class' => ['result', 'btn-delete'], @@ -523,10 +546,16 @@ class Bans extends Admin 'value' => '❌', 'caption' => __('Results actions head'), 'title' => __('Delete'), - 'link' => $this->c->Router->link('AdminBansDelete', [ - 'id' => $ban['id'], - 'token' => $this->c->Csrf->create('AdminBansDelete', $arr), - ]), + 'link' => $this->c->Router->link( + 'AdminBansDelete', + [ + 'id' => $ban['id'], + 'token' => $this->c->Csrf->create( + 'AdminBansDelete', + $arr + ), + ] + ), ]; $fields[] = [ 'type' => 'endwrap', @@ -746,8 +775,14 @@ class Bans extends Admin } } - $this->aCrumbs[] = [$this->c->Router->link($this->formBanPage, $args), $this->formBanSubHead]; - $this->formBan = $this->formBan($data, $args); + $this->aCrumbs[] = [ + $this->c->Router->link( + $this->formBanPage, + $args + ), + $this->formBanSubHead, + ]; + $this->formBan = $this->formBan($data, $args); return $this; } diff --git a/app/Models/Pages/Admin/Categories.php b/app/Models/Pages/Admin/Categories.php index 5db133dc..6d2b012f 100644 --- a/app/Models/Pages/Admin/Categories.php +++ b/app/Models/Pages/Admin/Categories.php @@ -106,7 +106,12 @@ class Categories extends Admin 'type' => 'btn', 'value' => '❌', 'caption' => __('Delete'), - 'link' => $this->c->Router->link('AdminCategoriesDelete', ['id' => $key]), + 'link' => $this->c->Router->link( + 'AdminCategoriesDelete', + [ + 'id' => $key, + ] + ), ]; $form['sets']["category{$key}"] = [ 'class' => 'category', @@ -175,7 +180,15 @@ class Categories extends Admin $this->nameTpl = 'admin/form'; $this->aIndex = 'categories'; - $this->aCrumbs[] = [$this->c->Router->link('AdminCategoriesDelete', ['id' => $args['id']]), __('Delete category head')]; + $this->aCrumbs[] = [ + $this->c->Router->link( + 'AdminCategoriesDelete', + [ + 'id' => $args['id'], + ] + ), + __('Delete category head'), + ]; $this->aCrumbs[] = __('"%s"', $category['cat_name']); $this->form = $this->formDelete($args, $category); $this->classForm = 'deletecategory'; @@ -195,9 +208,15 @@ class Categories extends Admin protected function formDelete(array $args, array $category): array { return [ - 'action' => $this->c->Router->link('AdminCategoriesDelete', $args), + 'action' => $this->c->Router->link( + 'AdminCategoriesDelete', + $args + ), 'hidden' => [ - 'token' => $this->c->Csrf->create('AdminCategoriesDelete', $args), + 'token' => $this->c->Csrf->create( + 'AdminCategoriesDelete', + $args + ), ], 'sets' => [ 'del' => [ diff --git a/app/Models/Pages/Admin/Forums.php b/app/Models/Pages/Admin/Forums.php index ea3ea3f8..d8354337 100644 --- a/app/Models/Pages/Admin/Forums.php +++ b/app/Models/Pages/Admin/Forums.php @@ -182,7 +182,12 @@ class Forums extends Admin 'type' => 'btn', 'value' => $forum->forum_name, 'caption' => __('Forum label'), - 'link' => $this->c->Router->link('AdminForumsEdit', ['id' => $forum->id]), + 'link' => $this->c->Router->link( + 'AdminForumsEdit', + [ + 'id' => $forum->id, + ] + ), ]; $fields["form[{$forum->id}][disp_position]"] = [ 'class' => ['position', 'forum'], @@ -198,7 +203,14 @@ class Forums extends Admin 'type' => 'btn', 'value' => '❌', 'caption' => __('Delete'), - 'link' => $disabled ? '#' : $this->c->Router->link('AdminForumsDelete', ['id' => $forum->id]), + 'link' => $disabled + ? '#' + : $this->c->Router->link( + 'AdminForumsDelete', + [ + 'id' => $forum->id, + ] + ), 'disabled' => $disabled, ]; $form['sets']["forum{$forum->id}"] = [ @@ -259,7 +271,15 @@ class Forums extends Admin $this->nameTpl = 'admin/form'; $this->aIndex = 'forums'; - $this->aCrumbs[] = [$this->c->Router->link('AdminForumsDelete', ['id' => $forum->id]), __('Delete forum head')]; + $this->aCrumbs[] = [ + $this->c->Router->link( + 'AdminForumsDelete', + [ + 'id' => $forum->id, + ] + ), + __('Delete forum head'), + ]; $this->aCrumbs[] = __('"%s"', $forum->forum_name); $this->form = $this->formDelete($args, $forum); $this->classForm = 'deleteforum'; @@ -279,9 +299,15 @@ class Forums extends Admin protected function formDelete(array $args, Forum $forum): array { return [ - 'action' => $this->c->Router->link('AdminForumsDelete', $args), + 'action' => $this->c->Router->link( + 'AdminForumsDelete', + $args + ), 'hidden' => [ - 'token' => $this->c->Csrf->create('AdminForumsDelete', $args), + 'token' => $this->c->Csrf->create( + 'AdminForumsDelete', + $args + ), ], 'sets' => [ 'confirm' => [ @@ -337,13 +363,19 @@ class Forums extends Admin if (empty($args['id'])) { $forum = $this->c->forums->create(); $marker = 'AdminForumsNew'; - $this->aCrumbs[] = [$this->c->Router->link($marker), __('Add forum head')]; + $this->aCrumbs[] = [ + $this->c->Router->link($marker), + __('Add forum head'), + ]; $this->titleForm = __('Add forum head'); $this->classForm = 'createforum'; } else { $forum = $this->c->forums->loadTree((int) $args['id']); //????? $marker = 'AdminForumsEdit'; - $this->aCrumbs[] = [$this->c->Router->link($marker, $args), __('Edit forum head')]; + $this->aCrumbs[] = [ + $this->c->Router->link($marker, $args), + __('Edit forum head'), + ]; $this->aCrumbs[] = __('"%s"', $forum->forum_name); $this->titleForm = __('Edit forum head'); $this->classForm = 'editforum'; @@ -433,9 +465,15 @@ class Forums extends Admin protected function formEdit(array $args, Forum $forum, string $marker): array { $form = [ - 'action' => $this->c->Router->link($marker, $args), + 'action' => $this->c->Router->link( + $marker, + $args + ), 'hidden' => [ - 'token' => $this->c->Csrf->create($marker, $args), + 'token' => $this->c->Csrf->create( + $marker, + $args + ), ], 'sets' => [], 'btns' => [], diff --git a/app/Models/Pages/Admin/Groups.php b/app/Models/Pages/Admin/Groups.php index e814233a..7279b94f 100644 --- a/app/Models/Pages/Admin/Groups.php +++ b/app/Models/Pages/Admin/Groups.php @@ -210,7 +210,13 @@ class Groups extends Admin $marker = 'AdminGroupsEdit'; $vars = ['id' => $group->g_id]; $notNext .= ',' . $group->g_id; - $this->aCrumbs[] = [$this->c->Router->link($marker, $vars), __('Edit group')]; + $this->aCrumbs[] = [ + $this->c->Router->link( + $marker, + $vars + ), + __('Edit group'), + ]; $this->aCrumbs[] = __('"%s"', $group->g_title); $this->titleForm = __('Edit group'); $this->classForm = 'editgroup'; @@ -366,9 +372,15 @@ class Groups extends Admin protected function formEdit(array $args, Group $group, string $marker): array { $form = [ - 'action' => $this->c->Router->link($marker, $args), + 'action' => $this->c->Router->link( + $marker, + $args + ), 'hidden' => [ - 'token' => $this->c->Csrf->create($marker, $args), + 'token' => $this->c->Csrf->create( + $marker, + $args + ), ], 'sets' => [], 'btns' => [ @@ -717,7 +729,13 @@ class Groups extends Admin $this->nameTpl = 'admin/form'; - $this->aCrumbs[] = [$this->c->Router->link('AdminGroupsDelete', $args), __('Group delete')]; + $this->aCrumbs[] = [ + $this->c->Router->link( + 'AdminGroupsDelete', + $args + ), + __('Group delete'), + ]; $this->aCrumbs[] = __('"%s"', $group->g_title); $this->form = $this->formDelete($args, $group, $count, $groups); $this->titleForm = __('Group delete'); @@ -739,9 +757,15 @@ class Groups extends Admin protected function formDelete(array $args, Group $group, int $count, array $groups): array { $form = [ - 'action' => $this->c->Router->link('AdminGroupsDelete', $args), + 'action' => $this->c->Router->link( + 'AdminGroupsDelete', + $args + ), 'hidden' => [ - 'token' => $this->c->Csrf->create('AdminGroupsDelete', $args), + 'token' => $this->c->Csrf->create( + 'AdminGroupsDelete', + $args + ), ], 'sets' => [], 'btns' => [ diff --git a/app/Models/Pages/Admin/Host.php b/app/Models/Pages/Admin/Host.php index 3f46ae8e..a09db36a 100644 --- a/app/Models/Pages/Admin/Host.php +++ b/app/Models/Pages/Admin/Host.php @@ -33,7 +33,12 @@ class Host extends Admin $this->back = true; $this->fIswev = [ 'i', - __('Host info', $ip, $host, $this->c->Router->link('AdminUsersResult', ['data' => "ip:{$ip}"])), + __('Host info', $ip, $host, $this->c->Router->link( + 'AdminUsersResult', + [ + 'data' => "ip:{$ip}", + ] + )), ]; return $this; diff --git a/app/Models/Pages/Admin/Options.php b/app/Models/Pages/Admin/Options.php index 74d921cf..d720f4b8 100644 --- a/app/Models/Pages/Admin/Options.php +++ b/app/Models/Pages/Admin/Options.php @@ -296,8 +296,8 @@ class Options extends Admin ]; $timestamp = \time() + ($this->user->timezone + $this->user->dst) * 3600; - $time = \ForkBB\dt($timestamp, false, $config->o_date_format, $config->o_time_format, true, true); - $date = \ForkBB\dt($timestamp, true, $config->o_date_format, $config->o_time_format, false, true); + $time = \ForkBB\dt($timestamp, false, $config->o_date_format, $config->o_time_format, true, true); + $date = \ForkBB\dt($timestamp, true, $config->o_date_format, $config->o_time_format, false, true); $form['sets']['timeouts'] = [ 'legend' => __('Timeouts subhead'), diff --git a/app/Models/Pages/Admin/Users/Action.php b/app/Models/Pages/Admin/Users/Action.php index 110e18b1..1f59c880 100644 --- a/app/Models/Pages/Admin/Users/Action.php +++ b/app/Models/Pages/Admin/Users/Action.php @@ -150,7 +150,13 @@ class Action extends Users $this->nameTpl = 'admin/form'; $this->classForm = 'delete-users'; $this->titleForm = __('Deleting users'); - $this->aCrumbs[] = [$this->c->Router->link('AdminUsersAction', $args), __('Deleting users')]; + $this->aCrumbs[] = [ + $this->c->Router->link( + 'AdminUsersAction', + $args + ), + __('Deleting users'), + ]; $this->form = $this->formDelete($args); return $this; @@ -168,9 +174,15 @@ class Action extends Users $yn = [1 => __('Yes'), 0 => __('No')]; $names = \implode(', ', $this->nameList($this->userList)); $form = [ - 'action' => $this->c->Router->link('AdminUsersAction', $args), + 'action' => $this->c->Router->link( + 'AdminUsersAction', + $args + ), 'hidden' => [ - 'token' => $this->c->Csrf->create('AdminUsersAction', $args), + 'token' => $this->c->Csrf->create( + 'AdminUsersAction', + $args + ), ], 'sets' => [ 'options' => [ @@ -254,7 +266,12 @@ class Action extends Users if ($profile) { $user = $this->c->users->load((int) $args['ids']); - $link = $this->c->Router->link('EditUserProfile', ['id' => $user->id]); + $link = $this->c->Router->link( + 'EditUserProfile', + [ + 'id' => $user->id, + ] + ); if ( $user->isAdmin @@ -311,7 +328,13 @@ class Action extends Users $this->nameTpl = 'admin/form'; $this->classForm = 'change-group'; $this->titleForm = __('Change user group'); - $this->aCrumbs[] = [$this->c->Router->link('AdminUsersAction', $args), __('Change user group')]; + $this->aCrumbs[] = [ + $this->c->Router->link( + 'AdminUsersAction', + $args + ), + __('Change user group'), + ]; $this->form = $this->formChange($args, $profile, $link, 'absent' !== $rulePass); return $this; @@ -349,9 +372,15 @@ class Action extends Users $yn = [1 => __('Yes'), 0 => __('No')]; $names = \implode(', ', $this->nameList($this->userList)); $form = [ - 'action' => $this->c->Router->link('AdminUsersAction', $args), + 'action' => $this->c->Router->link( + 'AdminUsersAction', + $args + ), 'hidden' => [ - 'token' => $this->c->Csrf->create('AdminUsersAction', $args), + 'token' => $this->c->Csrf->create( + 'AdminUsersAction', + $args + ), ], 'sets' => [ 'options' => [ diff --git a/app/Models/Pages/Admin/Users/Result.php b/app/Models/Pages/Admin/Users/Result.php index d506270a..b236eb98 100644 --- a/app/Models/Pages/Admin/Users/Result.php +++ b/app/Models/Pages/Admin/Users/Result.php @@ -133,7 +133,15 @@ class Result extends Users $this->nameTpl = 'admin/users_result'; $this->mainSuffix = '-one-column'; - $this->aCrumbs[] = [$this->c->Router->link('AdminUsersResult', ['data' => $args['data']]), $crName]; + $this->aCrumbs[] = [ + $this->c->Router->link( + 'AdminUsersResult', + [ + 'data' => $args['data'], + ] + ), + $crName, + ]; $this->formResult = $this->form($userList, $startNum, $args); $this->pagination = $this->c->Func->paginate($pages, $page, 'AdminUsersResult', ['data' => $args['data']]); @@ -226,9 +234,15 @@ class Result extends Users protected function form(array $users, int $number, array $args): array { $form = [ - 'action' => $this->c->Router->link('AdminUsersResult', $args), + 'action' => $this->c->Router->link( + 'AdminUsersResult', + $args + ), 'hidden' => [ - 'token' => $this->c->Csrf->create('AdminUsersResult', $args), + 'token' => $this->c->Csrf->create( + 'AdminUsersResult', + $args + ), ], 'sets' => [], 'btns' => [], @@ -300,7 +314,13 @@ class Result extends Users 'type' => $user->num_posts ? 'link' : 'str', 'caption' => __('Results posts head'), 'value' => $user->num_posts ? \ForkBB\num($user->num_posts) : null, - 'href' => $this->c->Router->link('SearchAction', ['action' => 'posts', 'uid' => $user->id]), + 'href' => $this->c->Router->link( + 'SearchAction', + [ + 'action' => 'posts', + 'uid' => $user->id, + ] + ), 'title' => __('Results show posts link'), ]; $fields["l{$number}-note"] = [ @@ -316,7 +336,12 @@ class Result extends Users 'type' => $user->isGuest || ! $user->num_posts ? 'str' : 'link', 'caption' => __('Results action head'), 'value' => $user->isGuest ? null : __('Results view IP link'), - 'href' => $this->c->Router->link('AdminUserStat', ['id' => $user->id]), + 'href' => $this->c->Router->link( + 'AdminUserStat', + [ + 'id' => $user->id, + ] + ), ]; } diff --git a/app/Models/Pages/Admin/Users/Stat.php b/app/Models/Pages/Admin/Users/Stat.php index 2ae75040..31150288 100644 --- a/app/Models/Pages/Admin/Users/Stat.php +++ b/app/Models/Pages/Admin/Users/Stat.php @@ -40,7 +40,15 @@ class Stat extends Users $this->nameTpl = 'admin/users_result'; $this->mainSuffix = '-one-column'; - $this->aCrumbs[] = [$this->c->Router->link('AdminUserStat', ['id' => $args['id']]), $user->username]; + $this->aCrumbs[] = [ + $this->c->Router->link( + 'AdminUserStat', + [ + 'id' => $args['id'], + ] + ), + $user->username, + ]; $this->formResult = $this->form($stat, $startNum); $this->pagination = $this->c->Func->paginate($pages, $page, 'AdminUserStat', ['id' => $args['id']]); @@ -75,7 +83,14 @@ class Stat extends Users 'type' => $flag ? 'link' : 'str', 'caption' => __('Results IP address head'), 'value' => $flag ? $ip : null, - 'href' => $flag ? $this->c->Router->link('AdminHost', ['ip' => $ip]) : null, + 'href' => $flag + ? $this->c->Router->link( + 'AdminHost', + [ + 'ip' => $ip, + ] + ) + : null, ]; $fields["l{$number}-last-used"] = [ 'class' => ['result', 'last-used'], @@ -94,7 +109,14 @@ class Stat extends Users 'type' => $flag ? 'link' : 'str', 'caption' => __('Results action head'), 'value' => $flag ? __('Results find more link') : null, - 'href' => $flag ? $this->c->Router->link('AdminUsersResult', ['data' => $this->encodeData($ip)]) : null, + 'href' => $flag + ? $this->c->Router->link( + 'AdminUsersResult', + [ + 'data' => $this->encodeData($ip), + ] + ) + : null, ]; $form['sets']["l{$number}"] = [ diff --git a/app/Models/Pages/Auth.php b/app/Models/Pages/Auth.php index 07bb8676..65692aef 100644 --- a/app/Models/Pages/Auth.php +++ b/app/Models/Pages/Auth.php @@ -215,7 +215,14 @@ class Auth extends Page if ($v->validation($_POST)) { $key = $this->c->Secury->randomPass(32); $hash = $this->c->Secury->hash($tmpUser->id . $key); - $link = $this->c->Router->link('ChangePassword', ['id' => $tmpUser->id, 'key' => $key, 'hash' => $hash]); + $link = $this->c->Router->link( + 'ChangePassword', + [ + 'id' => $tmpUser->id, + 'key' => $key, + 'hash' => $hash, + ] + ); $tplData = [ 'fRootLink' => $this->c->Router->link('Index'), 'fMailer' => __('Mailer', $this->c->config->o_board_title), @@ -385,9 +392,15 @@ class Auth extends Page protected function formChange(array $args): array { return [ - 'action' => $this->c->Router->link('ChangePassword', $args), + 'action' => $this->c->Router->link( + 'ChangePassword', + $args + ), 'hidden' => [ - 'token' => $this->c->Csrf->create('ChangePassword', $args), + 'token' => $this->c->Csrf->create( + 'ChangePassword', + $args + ), ], 'sets' => [ 'forget' => [ diff --git a/app/Models/Pages/Delete.php b/app/Models/Pages/Delete.php index da875104..65d0be3b 100644 --- a/app/Models/Pages/Delete.php +++ b/app/Models/Pages/Delete.php @@ -86,9 +86,19 @@ class Delete extends Page protected function formDelete(array $args, Post $post, bool $deleteTopic): array { return [ - 'action' => $this->c->Router->link('DeletePost', ['id' => $post->id]), + 'action' => $this->c->Router->link( + 'DeletePost', + [ + 'id' => $post->id, + ] + ), 'hidden' => [ - 'token' => $this->c->Csrf->create('DeletePost', ['id' => $post->id]), + 'token' => $this->c->Csrf->create( + 'DeletePost', + [ + 'id' => $post->id, + ] + ), ], 'sets' => [ 'info' => [ @@ -124,7 +134,10 @@ class Delete extends Page 'cancel' => [ 'type' => 'btn', 'value' => __('Cancel'), - 'link' => $this->c->Router->link('ViewPost', $args), + 'link' => $this->c->Router->link( + 'ViewPost', + $args + ), ], ], ]; diff --git a/app/Models/Pages/Forum.php b/app/Models/Pages/Forum.php index ca6a75de..d2dd64fe 100644 --- a/app/Models/Pages/Forum.php +++ b/app/Models/Pages/Forum.php @@ -38,7 +38,14 @@ class Forum extends Page $this->fIndex = 'index'; $this->nameTpl = 'forum'; $this->onlinePos = 'forum-' . $args['id']; - $this->canonical = $this->c->Router->link('Forum', ['id' => $args['id'], 'name' => $forum->forum_name, 'page' => $forum->page]); + $this->canonical = $this->c->Router->link( + 'Forum', + [ + 'id' => $args['id'], + 'name' => $forum->forum_name, + 'page' => $forum->page, + ] + ); $this->model = $forum; $this->topics = $forum->pageData(); $this->crumbs = $this->crumbs($forum); diff --git a/app/Models/Pages/Index.php b/app/Models/Pages/Index.php index 3e8cbab3..f1054f20 100644 --- a/app/Models/Pages/Index.php +++ b/app/Models/Pages/Index.php @@ -19,10 +19,13 @@ class Index extends Page // крайний пользователь // ???? может в stats переместить? $this->c->stats->userLast = $this->user->viewUsers - ? [ $this->c->Router->link('User', [ - 'id' => $this->c->stats->userLast['id'], - 'name' => $this->c->stats->userLast['username'], - ]), + ? [ + $this->c->Router->link( + 'User', [ + 'id' => $this->c->stats->userLast['id'], + 'name' => $this->c->stats->userLast['username'], + ] + ), $this->c->stats->userLast['username'], ] : $this->c->stats->userLast['username']; @@ -49,10 +52,18 @@ class Index extends Page $this->categoryes = $ctgs; if (! $this->user->isGuest) { - $this->linkMarkRead = $this->c->Router->link('MarkRead', [ + $this->linkMarkRead = $this->c->Router->link( + 'MarkRead', + [ 'id' => 0, - 'token' => $this->c->Csrf->create('MarkRead', ['id' => 0]), - ]); + 'token' => $this->c->Csrf->create( + 'MarkRead', + [ + 'id' => 0, + ] + ), + ] + ); } return $this; diff --git a/app/Models/Pages/Moderate.php b/app/Models/Pages/Moderate.php index 6e636426..334f1c53 100644 --- a/app/Models/Pages/Moderate.php +++ b/app/Models/Pages/Moderate.php @@ -247,11 +247,14 @@ class Moderate extends Page $this->processAsPosts = true; } - $this->backLink = $this->c->Router->link('Topic', [ - 'id' => $this->curTopic->id, - 'name' => $this->curTopic->subject, - 'page' => $page - ]); + $this->backLink = $this->c->Router->link( + 'Topic', + [ + 'id' => $this->curTopic->id, + 'name' => $this->curTopic->subject, + 'page' => $page, + ] + ); } else { $objects = $this->c->topics->loadByIds($v->ids, false); foreach ($objects as $topic) { @@ -263,11 +266,14 @@ class Moderate extends Page } } - $this->backLink = $this->c->Router->link('Forum', [ - 'id' => $this->curForum->id, - 'name' => $this->curForum->forum_name, - 'page' => $page - ]); + $this->backLink = $this->c->Router->link( + 'Forum', + [ + 'id' => $this->curForum->id, + 'name' => $this->curForum->forum_name, + 'page' => $page, + ] + ); } return $this->{'action' . \ucfirst($v->action)}($objects, $v); diff --git a/app/Models/Pages/Post.php b/app/Models/Pages/Post.php index 051cb464..76bbf35e 100644 --- a/app/Models/Pages/Post.php +++ b/app/Models/Pages/Post.php @@ -58,7 +58,12 @@ class Post extends Page $this->nameTpl = 'post'; $this->onlinePos = 'forum-' . $forum->id; - $this->canonical = $this->c->Router->link('NewTopic', ['id' => $forum->id]); + $this->canonical = $this->c->Router->link( + 'NewTopic', + [ + 'id' => $forum->id, + ] + ); $this->robots = 'noindex'; $this->crumbs = $this->crumbs(__('Post new topic'), $forum); $this->formTitle = __('Post new topic'); @@ -123,7 +128,12 @@ class Post extends Page $this->nameTpl = 'post'; $this->onlinePos = 'topic-' . $topic->id; - $this->canonical = $this->c->Router->link('NewReply', ['id' => $topic->id]); + $this->canonical = $this->c->Router->link( + 'NewReply', + [ + 'id' => $topic->id, + ] + ); $this->robots = 'noindex'; $this->crumbs = $this->crumbs(__('Post a reply'), $topic); $this->formTitle = __('Post a reply'); diff --git a/app/Models/Pages/PostFormTrait.php b/app/Models/Pages/PostFormTrait.php index 41c5f8b8..464d6d6c 100644 --- a/app/Models/Pages/PostFormTrait.php +++ b/app/Models/Pages/PostFormTrait.php @@ -26,9 +26,15 @@ trait PostFormTrait $autofocus = $quickReply ? null : true; $form = [ - 'action' => $this->c->Router->link($marker, $args), + 'action' => $this->c->Router->link( + $marker, + $args + ), 'hidden' => [ - 'token' => $this->c->Csrf->create($marker, $args), + 'token' => $this->c->Csrf->create( + $marker, + $args + ), ], 'sets' => [], 'btns' => [ diff --git a/app/Models/Pages/Profile.php b/app/Models/Pages/Profile.php index 5838f33d..557e56f6 100644 --- a/app/Models/Pages/Profile.php +++ b/app/Models/Pages/Profile.php @@ -99,29 +99,44 @@ abstract class Profile extends Page if (isset($this->c->bans->userList[\mb_strtolower($this->curUser->username)])) { //???? $id = $this->c->bans->userList[\mb_strtolower($this->curUser->username)]; $btns['unban-user'] = [ - $this->c->Router->link('AdminBansDelete', [ - 'id' => $id, - 'uid' => $this->curUser->id, - 'token' => $this->c->Csrf->create('AdminBansDelete', [ - 'id' => $id, - 'uid' => $this->curUser->id, - ]), - ]), + $this->c->Router->link( + 'AdminBansDelete', + [ + 'id' => $id, + 'uid' => $this->curUser->id, + 'token' => $this->c->Csrf->create( + 'AdminBansDelete', + [ + 'id' => $id, + 'uid' => $this->curUser->id, + ] + ), + ] + ), __('Unban user'), ]; } else { $btns['ban-user'] = [ - $this->c->Router->link('AdminBansNew', [ - 'ids' => $this->curUser->id, - 'uid' => $this->curUser->id, - ]), + $this->c->Router->link( + 'AdminBansNew', + [ + 'ids' => $this->curUser->id, + 'uid' => $this->curUser->id, + ] + ), __('Ban user'), ]; } } if ($this->rules->deleteUser) { $btns['delete-user'] = [ - $this->c->Router->link('AdminUsersAction', ['action' => 'delete', 'ids' => $this->curUser->id]), // ???? + $this->c->Router->link( + 'AdminUsersAction', + [ + 'action' => 'delete', + 'ids' => $this->curUser->id, + ] + ), // ???? __('Delete user'), ]; } @@ -130,7 +145,12 @@ abstract class Profile extends Page && $this->rules->editProfile ) { $btns['edit-profile'] = [ - $this->c->Router->link('EditUserProfile', ['id' => $this->curUser->id]), + $this->c->Router->link( + 'EditUserProfile', + [ + 'id' => $this->curUser->id, + ] + ), __('Edit '), ]; } @@ -145,7 +165,12 @@ abstract class Profile extends Page && $this->rules->editConfig ) { $btns['edit-settings'] = [ - $this->c->Router->link('EditUserBoardConfig', ['id' => $this->curUser->id]), + $this->c->Router->link( + 'EditUserBoardConfig', + [ + 'id' => $this->curUser->id, + ] + ), __('Configure '), ]; } @@ -159,13 +184,19 @@ abstract class Profile extends Page */ protected function linkChangeGroup(): string { - return $this->c->Router->link('AdminUsersAction', [ - 'action' => 'change_group', - 'ids' => $this->curUser->id, - 'token' => $this->c->Csrf->create('AdminUsersAction', [ + return $this->c->Router->link( + 'AdminUsersAction', + [ 'action' => 'change_group', 'ids' => $this->curUser->id, - ]), - ]); + 'token' => $this->c->Csrf->create( + 'AdminUsersAction', + [ + 'action' => 'change_group', + 'ids' => $this->curUser->id, + ] + ), + ] + ); } } diff --git a/app/Models/Pages/Profile/Config.php b/app/Models/Pages/Profile/Config.php index fe9aef57..6ab44c89 100644 --- a/app/Models/Pages/Profile/Config.php +++ b/app/Models/Pages/Profile/Config.php @@ -80,7 +80,17 @@ class Config extends Profile $this->fIswev = $v->getErrors(); } - $this->crumbs = $this->crumbs([$this->c->Router->link('EditUserBoardConfig', ['id' => $this->curUser->id]), __('Board configuration')]); + $this->crumbs = $this->crumbs( + [ + $this->c->Router->link( + 'EditUserBoardConfig', + [ + 'id' => $this->curUser->id, + ] + ), + __('Board configuration'), + ] + ); $this->form = $this->form(); $this->actionBtns = $this->btns('config'); @@ -108,9 +118,19 @@ class Config extends Profile protected function form(): array { $form = [ - 'action' => $this->c->Router->link('EditUserBoardConfig', ['id' => $this->curUser->id]), + 'action' => $this->c->Router->link( + 'EditUserBoardConfig', + [ + 'id' => $this->curUser->id, + ] + ), 'hidden' => [ - 'token' => $this->c->Csrf->create('EditUserBoardConfig', ['id' => $this->curUser->id]), + 'token' => $this->c->Csrf->create( + 'EditUserBoardConfig', + [ + 'id' => $this->curUser->id + ] + ), ], 'sets' => [], 'btns' => [ diff --git a/app/Models/Pages/Profile/Edit.php b/app/Models/Pages/Profile/Edit.php index 21f828e7..e18e12aa 100644 --- a/app/Models/Pages/Profile/Edit.php +++ b/app/Models/Pages/Profile/Edit.php @@ -136,7 +136,17 @@ class Edit extends Profile } } - $this->crumbs = $this->crumbs([$this->c->Router->link('EditUserProfile', ['id' => $this->curUser->id]), __('Editing profile')]); + $this->crumbs = $this->crumbs( + [ + $this->c->Router->link( + 'EditUserProfile', + [ + 'id' => $this->curUser->id, + ] + ), + __('Editing profile'), + ] + ); $this->form = $this->form(); $this->actionBtns = $this->btns('edit'); @@ -189,9 +199,19 @@ class Edit extends Profile protected function form(): array { $form = [ - 'action' => $this->c->Router->link('EditUserProfile', ['id' => $this->curUser->id]), + 'action' => $this->c->Router->link( + 'EditUserProfile', + [ + 'id' => $this->curUser->id, + ] + ), 'hidden' => [ - 'token' => $this->c->Csrf->create('EditUserProfile', ['id' => $this->curUser->id]), + 'token' => $this->c->Csrf->create( + 'EditUserProfile', + [ + 'id' => $this->curUser->id, + ] + ), ], 'sets' => [], 'btns' => [ @@ -243,7 +263,12 @@ class Edit extends Profile 'type' => 'link', 'value' => __('Configure moderator rights'), 'title' => __('Configure moderator rights'), - 'href' => $this->c->Router->link('EditUserModeration', ['id' => $this->curUser->id]), + 'href' => $this->c->Router->link( + 'EditUserModeration', + [ + 'id' => $this->curUser->id, + ] + ), ]; } if ($this->rules->setTitle) { @@ -266,7 +291,12 @@ class Edit extends Profile $fields['change_pass'] = [ 'type' => 'link', 'value' => __('Change passphrase'), - 'href' => $this->c->Router->link('EditUserPass', ['id' => $this->curUser->id]), + 'href' => $this->c->Router->link( + 'EditUserPass', + [ + 'id' => $this->curUser->id, + ] + ), ]; } if ($this->rules->useAvatar) { @@ -376,7 +406,12 @@ class Edit extends Profile $fields['change_email'] = [ 'type' => 'link', 'value' => __('To change email'), - 'href' => $this->c->Router->link('EditUserEmail', ['id' => $this->curUser->id]), + 'href' => $this->c->Router->link( + 'EditUserEmail', + [ + 'id' => $this->curUser->id, + ] + ), ]; } $fields['email_setting'] = [ diff --git a/app/Models/Pages/Profile/Email.php b/app/Models/Pages/Profile/Email.php index 8915f79a..cfdd0bbf 100644 --- a/app/Models/Pages/Profile/Email.php +++ b/app/Models/Pages/Profile/Email.php @@ -93,7 +93,15 @@ class Email extends Profile } else { $key = $this->c->Secury->randomPass(33); $hash = $this->c->Secury->hash($this->curUser->id . $v->new_email . $key); - $link = $this->c->Router->link('SetNewEmail', ['id' => $this->curUser->id, 'email' => $v->new_email, 'key' => $key, 'hash' => $hash]); + $link = $this->c->Router->link( + 'SetNewEmail', + [ + 'id' => $this->curUser->id, + 'email' => $v->new_email, + 'key' => $key, + 'hash' => $hash, + ] + ); $tplData = [ 'fRootLink' => $this->c->Router->link('Index'), 'fMailer' => __('Mailer', $this->c->config->o_board_title), @@ -134,8 +142,24 @@ class Email extends Profile $this->crumbs = $this->crumbs( - [$this->c->Router->link('EditUserEmail', ['id' => $this->curUser->id]), __('Change email')], - [$this->c->Router->link('EditUserProfile', ['id' => $this->curUser->id]), __('Editing profile')] + [ + $this->c->Router->link( + 'EditUserEmail', + [ + 'id' => $this->curUser->id, + ] + ), + __('Change email'), + ], + [ + $this->c->Router->link( + 'EditUserProfile', + [ + 'id' => $this->curUser->id, + ] + ), + __('Editing profile'), + ] ); $this->form = $this->form(); $this->actionBtns = $this->btns('edit'); @@ -151,9 +175,19 @@ class Email extends Profile protected function form(): array { $form = [ - 'action' => $this->c->Router->link('EditUserEmail', ['id' => $this->curUser->id]), + 'action' => $this->c->Router->link( + 'EditUserEmail', + [ + 'id' => $this->curUser->id, + ] + ), 'hidden' => [ - 'token' => $this->c->Csrf->create('EditUserEmail', ['id' => $this->curUser->id]), + 'token' => $this->c->Csrf->create( + 'EditUserEmail', + [ + 'id' => $this->curUser->id, + ] + ), ], 'sets' => [ 'new-email' => [ diff --git a/app/Models/Pages/Profile/Mod.php b/app/Models/Pages/Profile/Mod.php index fb840658..b71c003d 100644 --- a/app/Models/Pages/Profile/Mod.php +++ b/app/Models/Pages/Profile/Mod.php @@ -64,8 +64,24 @@ class Mod extends Profile } $this->crumbs = $this->crumbs( - [$this->c->Router->link('EditUserModeration', ['id' => $this->curUser->id]), __('Moderator rights')], - [$this->c->Router->link('EditUserProfile', ['id' => $this->curUser->id]), __('Editing profile')] + [ + $this->c->Router->link( + 'EditUserModeration', + [ + 'id' => $this->curUser->id, + ] + ), + __('Moderator rights'), + ], + [ + $this->c->Router->link( + 'EditUserProfile', + [ + 'id' => $this->curUser->id, + ] + ), + __('Editing profile'), + ] ); $this->form = $this->form(); $this->actionBtns = $this->btns('edit'); @@ -95,9 +111,19 @@ class Mod extends Profile protected function form(): array { $form = [ - 'action' => $this->c->Router->link('EditUserModeration', ['id' => $this->curUser->id]), + 'action' => $this->c->Router->link( + 'EditUserModeration', + [ + 'id' => $this->curUser->id, + ] + ), 'hidden' => [ - 'token' => $this->c->Csrf->create('EditUserModeration', ['id' => $this->curUser->id]), + 'token' => $this->c->Csrf->create( + 'EditUserModeration', + [ + 'id' => $this->curUser->id, + ] + ), ], 'sets' => [], 'btns' => [ diff --git a/app/Models/Pages/Profile/Pass.php b/app/Models/Pages/Profile/Pass.php index 7d867f7d..e23ab76f 100644 --- a/app/Models/Pages/Profile/Pass.php +++ b/app/Models/Pages/Profile/Pass.php @@ -67,8 +67,24 @@ class Pass extends Profile } $this->crumbs = $this->crumbs( - [$this->c->Router->link('EditUserPass', ['id' => $this->curUser->id]), __('Change pass')], - [$this->c->Router->link('EditUserProfile', ['id' => $this->curUser->id]), __('Editing profile')] + [ + $this->c->Router->link( + 'EditUserPass', + [ + 'id' => $this->curUser->id, + ] + ), + __('Change pass'), + ], + [ + $this->c->Router->link( + 'EditUserProfile', + [ + 'id' => $this->curUser->id, + ] + ), + __('Editing profile'), + ] ); $this->form = $this->form(); $this->actionBtns = $this->btns('edit'); @@ -84,9 +100,19 @@ class Pass extends Profile protected function form(): array { $form = [ - 'action' => $this->c->Router->link('EditUserPass', ['id' => $this->curUser->id]), + 'action' => $this->c->Router->link( + 'EditUserPass', + [ + 'id' => $this->curUser->id, + ] + ), 'hidden' => [ - 'token' => $this->c->Csrf->create('EditUserPass', ['id' => $this->curUser->id]), + 'token' => $this->c->Csrf->create( + 'EditUserPass', + [ + 'id' => $this->curUser->id, + ] + ), ], 'sets' => [ 'new-pass' => [ diff --git a/app/Models/Pages/Profile/View.php b/app/Models/Pages/Profile/View.php index 39c5e1e1..ebf92e98 100644 --- a/app/Models/Pages/Profile/View.php +++ b/app/Models/Pages/Profile/View.php @@ -169,7 +169,12 @@ class View extends Profile 'type' => 'link', 'caption' => __('Email info'), 'value' => __('Send email'), - 'href' => $this->c->Router->link('', ['id' => $this->curUser->id]), // ???? + 'href' => $this->c->Router->link( + '', // ???? + [ + 'id' => $this->curUser->id, + ] + ), ]; } } @@ -245,7 +250,13 @@ class View extends Profile 'type' => 'link', 'caption' => __('Posts info'), 'value' => $this->user->showPostCount ? \ForkBB\num($this->curUser->num_posts) : __('Show posts'), - 'href' => $this->c->Router->link('SearchAction', ['action' => 'posts', 'uid' => $this->curUser->id]), + 'href' => $this->c->Router->link( + 'SearchAction', + [ + 'action' => 'posts', + 'uid' => $this->curUser->id, + ] + ), 'title' => __('Show posts'), ]; $fields['topics'] = [ @@ -253,7 +264,13 @@ class View extends Profile 'type' => 'link', 'caption' => __('Topics info'), 'value' => $this->user->showPostCount ? \ForkBB\num($this->curUser->num_topics) : __('Show topics'), - 'href' => $this->c->Router->link('SearchAction', ['action' => 'topics', 'uid' => $this->curUser->id]), + 'href' => $this->c->Router->link( + 'SearchAction', + [ + 'action' => 'topics', + 'uid' => $this->curUser->id, + ] + ), 'title' => __('Show topics'), ]; } elseif ($this->user->showPostCount) { @@ -280,7 +297,12 @@ class View extends Profile 'type' => 'link', 'caption' => __('IP'), 'value' => $this->curUser->registration_ip, - 'href' => $this->c->Router->link('AdminHost', ['ip' => $this->curUser->registration_ip]), + 'href' => $this->c->Router->link( + 'AdminHost', + [ + 'ip' => $this->curUser->registration_ip, + ] + ), 'title' => __('IP title'), ]; } diff --git a/app/Models/Pages/Redirect.php b/app/Models/Pages/Redirect.php index 70a8c4ac..0c61ac3b 100644 --- a/app/Models/Pages/Redirect.php +++ b/app/Models/Pages/Redirect.php @@ -27,7 +27,10 @@ class Redirect extends Page */ public function page(string $marker, array $args = []): Page { - $this->link = $this->c->Router->link($marker, $args); + $this->link = $this->c->Router->link( + $marker, + $args + ); return $this; } diff --git a/app/Models/Pages/Register.php b/app/Models/Pages/Register.php index 160d855e..2c527484 100644 --- a/app/Models/Pages/Register.php +++ b/app/Models/Pages/Register.php @@ -172,7 +172,13 @@ class Register extends Page 'fRootLink' => $this->c->Router->link('Index'), 'fMailer' => __('Mailer', $this->c->config->o_board_title), 'username' => $v->username, - 'userLink' => $this->c->Router->link('User', ['id' => $newUserId, 'name' => $v->username]), + 'userLink' => $this->c->Router->link( + 'User', + [ + 'id' => $newUserId, + 'name' => $v->username, + ] + ), ]; try { @@ -194,7 +200,14 @@ class Register extends Page // отправка письма активации аккаунта if ('1' == $this->c->config->o_regs_verify) { $hash = $this->c->Secury->hash($newUserId . $key); - $link = $this->c->Router->link('RegActivate', ['id' => $newUserId, 'key' => $key, 'hash' => $hash]); + $link = $this->c->Router->link( + 'RegActivate', + [ + 'id' => $newUserId, + 'key' => $key, + 'hash' => $hash, + ] + ); $tplData = [ 'fTitle' => $this->c->config->o_board_title, 'fRootLink' => $this->c->Router->link('Index'), diff --git a/app/Models/Pages/Report.php b/app/Models/Pages/Report.php index fd1941ed..467f552c 100644 --- a/app/Models/Pages/Report.php +++ b/app/Models/Pages/Report.php @@ -112,9 +112,15 @@ class Report extends Page protected function formReport(array $args, array $data): array { return [ - 'action' => $this->c->Router->link('ReportPost', $args), + 'action' => $this->c->Router->link( + 'ReportPost', + $args + ), 'hidden' => [ - 'token' => $this->c->Csrf->create('ReportPost', $args), + 'token' => $this->c->Csrf->create( + 'ReportPost', + $args + ), ], 'sets' => [ 'report' => [ @@ -158,7 +164,12 @@ class Report extends Page $tplData = [ 'fMailer' => __('Mailer', $this->c->config->o_board_title), 'username' => $report->author->username, - 'postLink' => $this->c->Router->link('ViewPost', ['id' => $report->post->id]), + 'postLink' => $this->c->Router->link( + 'ViewPost', + [ + 'id' => $report->post->id, + ] + ), 'reason' => $report->message, 'forumId' => $report->post->parent->parent->id, 'topicSubject' => $report->post->parent->subject, diff --git a/app/Models/Pages/Topic.php b/app/Models/Pages/Topic.php index ebd69fcc..e51c291c 100644 --- a/app/Models/Pages/Topic.php +++ b/app/Models/Pages/Topic.php @@ -148,7 +148,14 @@ class Topic extends Page $this->nameTpl = 'topic'; $this->onlinePos = 'topic-' . $topic->id; $this->onlineDetail = true; - $this->canonical = $this->c->Router->link('Topic', ['id' => $topic->id, 'name' => \ForkBB\cens($topic->subject), 'page' => $topic->page]); + $this->canonical = $this->c->Router->link( + 'Topic', + [ + 'id' => $topic->id, + 'name' => \ForkBB\cens($topic->subject), + 'page' => $topic->page + ] + ); $this->model = $topic; $this->posts = $posts; $this->crumbs = $this->crumbs($topic); diff --git a/app/Models/Pages/Userlist.php b/app/Models/Pages/Userlist.php index 1f4b00ae..5563c1aa 100644 --- a/app/Models/Pages/Userlist.php +++ b/app/Models/Pages/Userlist.php @@ -116,7 +116,10 @@ class Userlist extends Page foreach (['ASC', 'DESC'] as $j => $dir) { $vars['dir'] = $dir; - $links[$i * 2 + $j] = $this->c->Router->link('Userlist', $vars); + $links[$i * 2 + $j] = $this->c->Router->link( + 'Userlist', + $vars + ); if ( $v->sort === $sort @@ -138,7 +141,10 @@ class Userlist extends Page $this->fIndex = 'userlist'; $this->nameTpl = 'userlist'; $this->onlinePos = 'userlist'; - $this->canonical = $this->c->Router->link('Userlist', $args); + $this->canonical = $this->c->Router->link( + 'Userlist', + $args + ); $this->robots = 'noindex'; $this->crumbs = $this->crumbs([$this->c->Router->link('Userlist'), __('User list')]); $this->pagination = $this->c->Func->paginate($pages, $page, 'Userlist', $args); diff --git a/app/Models/Post/Delete.php b/app/Models/Post/Delete.php index fcd27297..22631737 100644 --- a/app/Models/Post/Delete.php +++ b/app/Models/Post/Delete.php @@ -88,35 +88,40 @@ class Delete extends Action //???? подписки, опросы, предупреждения if ($usersToGuest) { - $vars = [ + $vars = [ ':users' => $usersToGuest, ]; - $sql = 'UPDATE ::posts - SET poster_id=1 - WHERE poster_id IN (?ai:users)'; - $this->c->DB->exec($sql, $vars); + $query = 'UPDATE ::posts + SET poster_id=1 + WHERE poster_id IN (?ai:users)'; + + $this->c->DB->exec($query, $vars); } if ($usersDel) { - $vars = [ + $vars = [ ':users' => $usersDel, ]; - $sql = 'SELECT p.topic_id - FROM ::posts as p - WHERE p.poster_id IN (?ai:users) - GROUP BY p.topic_id'; - $parents = $this->c->DB->query($sql, $vars)->fetchAll(PDO::FETCH_COLUMN); + $query = 'SELECT p.topic_id + FROM ::posts as p + WHERE p.poster_id IN (?ai:users) + GROUP BY p.topic_id'; - $sql = 'SELECT t.id - FROM ::topics AS t - INNER JOIN ::posts AS p ON t.first_post_id=p.id - WHERE p.poster_id IN (?ai:users)'; - $notUse = $this->c->DB->query($sql, $vars)->fetchAll(PDO::FETCH_COLUMN); + $parents = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN); + + $query = 'SELECT t.id + FROM ::topics AS t + INNER JOIN ::posts AS p ON t.first_post_id=p.id + WHERE p.poster_id IN (?ai:users)'; + + $notUse = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN); $parents = \array_diff($parents, $notUse); //???? - $sql = 'DELETE FROM ::posts - WHERE poster_id IN (?ai:users)'; - $this->c->DB->exec($sql, $vars); + $query = 'DELETE + FROM ::posts + WHERE poster_id IN (?ai:users)'; + + $this->c->DB->exec($query, $vars); foreach ($parents as &$parent) { $parent = $this->c->topics->load($parent); //???? ааааАААААААААААААА О_о @@ -124,45 +129,52 @@ class Delete extends Action unset($parent); } if ($forums) { - $vars = [ + $vars = [ ':forums' => \array_keys($forums), ]; - $sql = 'SELECT p.poster_id - FROM ::posts AS p - INNER JOIN ::topics AS t ON t.id=p.topic_id - WHERE t.forum_id IN (?ai:forums) - GROUP BY p.poster_id'; - $users = $this->c->DB->query($sql, $vars)->fetchAll(PDO::FETCH_COLUMN); + $query = 'SELECT p.poster_id + FROM ::posts AS p + INNER JOIN ::topics AS t ON t.id=p.topic_id + WHERE t.forum_id IN (?ai:forums) + GROUP BY p.poster_id'; - $sql = 'DELETE FROM ::posts - WHERE topic_id IN ( - SELECT id - FROM ::topics - WHERE forum_id IN (?ai:forums) - )'; - $this->c->DB->exec($sql, $vars); + $users = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN); + + $query = 'DELETE + FROM ::posts + WHERE topic_id IN ( + SELECT id + FROM ::topics + WHERE forum_id IN (?ai:forums) + )'; + $this->c->DB->exec($query, $vars); } if ($topics) { - $vars = [ + $vars = [ ':topics' => \array_keys($topics), ]; - $sql = 'SELECT p.poster_id - FROM ::posts AS p - WHERE p.topic_id IN (?ai:topics) - GROUP BY p.poster_id'; - $users = $this->c->DB->query($sql, $vars)->fetchAll(PDO::FETCH_COLUMN); + $query = 'SELECT p.poster_id + FROM ::posts AS p + WHERE p.topic_id IN (?ai:topics) + GROUP BY p.poster_id'; - $sql = 'DELETE FROM ::posts - WHERE topic_id IN (?ai:topics)'; - $this->c->DB->exec($sql, $vars); + $users = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN); + + $query = 'DELETE + FROM ::posts + WHERE topic_id IN (?ai:topics)'; + + $this->c->DB->exec($query, $vars); } if ($posts) { - $vars = [ + $vars = [ ':posts' => $posts, ]; - $sql = 'DELETE FROM ::posts - WHERE id IN (?ai:posts)'; - $this->c->DB->exec($sql, $vars); + $query = 'DELETE + FROM ::posts + WHERE id IN (?ai:posts)'; + + $this->c->DB->exec($query, $vars); } if ($parents) { $topics = $parents; diff --git a/app/Models/Post/Load.php b/app/Models/Post/Load.php index fa4af1d6..fd22bce7 100644 --- a/app/Models/Post/Load.php +++ b/app/Models/Post/Load.php @@ -15,10 +15,11 @@ class Load extends Action */ protected function getSql(string $where): string { - $sql = 'SELECT p.* - FROM ::posts AS p - WHERE ' . $where; - return $sql; + $query = 'SELECT p.* + FROM ::posts AS p + WHERE ' . $where; + + return $query; } /** @@ -46,12 +47,13 @@ class Load extends Action throw new InvalidArgumentException('Expected a positive topic id'); } - $vars = [ + $vars = [ ':pid' => $id, ':tid' => $tid, ]; - $sql = $this->getSql(null !== $tid ? 'p.id=?i:pid AND p.topic_id=?i:tid' : 'p.id=?i:pid'); - $data = $this->c->DB->query($sql, $vars)->fetch(); + $query = $this->getSql(null !== $tid ? 'p.id=?i:pid AND p.topic_id=?i:tid' : 'p.id=?i:pid'); + + $data = $this->c->DB->query($query, $vars)->fetch(); if (empty($data)) { return null; @@ -90,11 +92,12 @@ class Load extends Action } } - $vars = [ + $vars = [ ':ids' => $ids, ]; - $sql = $this->getSql('p.id IN (?ai:ids)'); - $stmt = $this->c->DB->query($sql, $vars); + $query = $this->getSql('p.id IN (?ai:ids)'); + + $stmt = $this->c->DB->query($query, $vars); $result = []; $topicIds = []; diff --git a/app/Models/Post/Model.php b/app/Models/Post/Model.php index fdf4b127..be305bfe 100644 --- a/app/Models/Post/Model.php +++ b/app/Models/Post/Model.php @@ -43,7 +43,12 @@ class Model extends DataModel */ protected function getlink(): string { - return $this->c->Router->link('ViewPost', ['id' => $this->id]); + return $this->c->Router->link( + 'ViewPost', + [ + 'id' => $this->id, + ] + ); } /** @@ -78,7 +83,12 @@ class Model extends DataModel protected function getlinkReport(): string { - return $this->c->Router->link('ReportPost', ['id' => $this->id]); + return $this->c->Router->link( + 'ReportPost', + [ + 'id' => $this->id, + ] + ); } protected function getcanDelete(): bool @@ -117,7 +127,12 @@ class Model extends DataModel protected function getlinkDelete(): string { - return $this->c->Router->link('DeletePost', ['id' => $this->id]); + return $this->c->Router->link( + 'DeletePost', + [ + 'id' => $this->id, + ] + ); } protected function getcanEdit(): bool @@ -147,7 +162,12 @@ class Model extends DataModel protected function getlinkEdit(): string { - return $this->c->Router->link('EditPost', ['id' => $this->id]); + return $this->c->Router->link( + 'EditPost', + [ + 'id' => $this->id, + ] + ); } protected function getcanQuote(): bool @@ -157,7 +177,13 @@ class Model extends DataModel protected function getlinkQuote(): string { - return $this->c->Router->link('NewReply', ['id' => $this->parent->id, 'quote' => $this->id]); + return $this->c->Router->link( + 'NewReply', + [ + 'id' => $this->parent->id, + 'quote' => $this->id, + ] + ); } /** diff --git a/app/Models/Post/PreviousPost.php b/app/Models/Post/PreviousPost.php index 96e1b4f9..72110544 100644 --- a/app/Models/Post/PreviousPost.php +++ b/app/Models/Post/PreviousPost.php @@ -16,16 +16,17 @@ class PreviousPost extends Action */ public function previousPost(Post $post): ?int { - $vars = [ + $vars = [ ':pid' => $post->id, ':tid' => $post->topic_id, ]; - $sql = 'SELECT p.id - FROM ::posts AS p - WHERE p.id < ?i:pid AND p.topic_id=?i:tid - ORDER BY p.id DESC - LIMIT 1'; - $id = $this->c->DB->query($sql, $vars)->fetchColumn(); + $query = 'SELECT p.id + FROM ::posts AS p + WHERE p.id < ?i:pid AND p.topic_id=?i:tid + ORDER BY p.id DESC + LIMIT 1'; + + $id = $this->c->DB->query($query, $vars)->fetchColumn(); return empty($id) ? null : $id; } diff --git a/app/Models/Post/RebuildIndex.php b/app/Models/Post/RebuildIndex.php index f3ae093f..1c954d8b 100644 --- a/app/Models/Post/RebuildIndex.php +++ b/app/Models/Post/RebuildIndex.php @@ -18,19 +18,18 @@ class RebuildIndex extends Action */ public function rebuildIndex(int $start, int $limit, string $mode): int { - $vars = [ + $vars = [ ':start' => $start, ':limit' => $limit, ]; + $query = 'SELECT p.id, p.message, t.id as topic_id, t.subject, t.first_post_id + FROM ::posts AS p + INNER JOIN ::topics AS t ON t.id=p.topic_id + WHERE p.id>=?i:start + ORDER BY p.id ASC + LIMIT ?i:limit'; - $sql = 'SELECT p.id, p.message, t.id as topic_id, t.subject, t.first_post_id - FROM ::posts AS p - INNER JOIN ::topics AS t ON t.id=p.topic_id - WHERE p.id>=?i:start - ORDER BY p.id ASC - LIMIT ?i:limit'; - - $stmt = $this->c->DB->query($sql, $vars); + $stmt = $this->c->DB->query($query, $vars); $number = 0; while ($row = $stmt->fetch()) { diff --git a/app/Models/Post/UserInfoFromIP.php b/app/Models/Post/UserInfoFromIP.php index dbce5a17..40d715ec 100644 --- a/app/Models/Post/UserInfoFromIP.php +++ b/app/Models/Post/UserInfoFromIP.php @@ -16,16 +16,16 @@ class UserInfoFromIP extends Action */ public function userInfoFromIP(string $ip): array { - $vars = [ + $vars = [ ':ip' => $ip, ]; - $sql = 'SELECT p.poster_id, p.poster - FROM ::posts AS p - WHERE p.poster_ip=?s:ip - GROUP BY p.poster_id, p.poster - ORDER BY p.poster'; + $query = 'SELECT p.poster_id, p.poster + FROM ::posts AS p + WHERE p.poster_ip=?s:ip + GROUP BY p.poster_id, p.poster + ORDER BY p.poster'; - $stmt = $this->c->DB->query($sql, $vars); + $stmt = $this->c->DB->query($query, $vars); $result = []; $ids = []; diff --git a/app/Models/Post/UserStat.php b/app/Models/Post/UserStat.php index 5d79baf6..1662b84d 100644 --- a/app/Models/Post/UserStat.php +++ b/app/Models/Post/UserStat.php @@ -17,15 +17,15 @@ class UserStat extends Action */ public function userStat(int $id): array { - $vars = [ + $vars = [ ':id' => $id, ]; - $sql = 'SELECT p.poster_ip, MAX(p.posted) AS last_used, COUNT(p.id) AS used_times - FROM ::posts AS p - WHERE p.poster_id=?i:id - GROUP BY p.poster_ip - ORDER BY last_used DESC'; + $query = 'SELECT p.poster_ip, MAX(p.posted) AS last_used, COUNT(p.id) AS used_times + FROM ::posts AS p + WHERE p.poster_id=?i:id + GROUP BY p.poster_ip + ORDER BY last_used DESC'; - return $this->c->DB->query($sql, $vars)->fetchAll(PDO::FETCH_UNIQUE); + return $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_UNIQUE); } } diff --git a/app/Models/Post/View.php b/app/Models/Post/View.php index 9f02c24e..02b1b4cc 100644 --- a/app/Models/Post/View.php +++ b/app/Models/Post/View.php @@ -40,13 +40,14 @@ class View extends Action } if (! $review) { - $vars = [ + $vars = [ ':ids' => $arg->idsList, ]; - $sql = 'SELECT w.id, w.message, w.poster, w.posted - FROM ::warnings AS w - WHERE w.id IN (?ai:ids)'; - $warnings = $this->c->DB->query($sql, $vars)->fetchAll(PDO::FETCH_GROUP); + $query = 'SELECT w.id, w.message, w.poster, w.posted + FROM ::warnings AS w + WHERE w.id IN (?ai:ids)'; + + $warnings = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_GROUP); } $userIds = []; diff --git a/app/Models/Report/Load.php b/app/Models/Report/Load.php index 15cc13af..46ee09d6 100644 --- a/app/Models/Report/Load.php +++ b/app/Models/Report/Load.php @@ -23,13 +23,14 @@ class Load extends Action throw new InvalidArgumentException('Expected a positive report id'); } - $vars = [ + $vars = [ ':id' => $id, ]; - $sql = 'SELECT r.* - FROM ::reports AS r - WHERE r.id=?i:id'; - $data = $this->c->DB->query($sql, $vars)->fetch(); + $query = 'SELECT r.* + FROM ::reports AS r + WHERE r.id=?i:id'; + + $data = $this->c->DB->query($query, $vars)->fetch(); if (empty($data)) { return null; @@ -53,18 +54,18 @@ class Load extends Action $vars = []; if ($noZapped) { - $sql = 'SELECT r.* - FROM ::reports AS r - WHERE r.zapped=0 - ORDER BY r.id DESC'; + $query = 'SELECT r.* + FROM ::reports AS r + WHERE r.zapped=0 + ORDER BY r.id DESC'; } else { - $sql = 'SELECT r.* - FROM ::reports AS r - WHERE r.zapped!=0 - ORDER BY r.zapped DESC'; // LIMIT 10 не нужен, если при обработке сигнала будут удалены старые + $query = 'SELECT r.* + FROM ::reports AS r + WHERE r.zapped!=0 + ORDER BY r.zapped DESC'; // LIMIT 10 не нужен, если при обработке сигнала будут удалены старые } - $data = $this->c->DB->query($sql, $vars)->fetchAll(); + $data = $this->c->DB->query($query, $vars)->fetchAll(); foreach ($data as $row) { $result[] = $this->manager->create($row); diff --git a/app/Models/Report/Manager.php b/app/Models/Report/Manager.php index 34fcf7de..f7fdb410 100644 --- a/app/Models/Report/Manager.php +++ b/app/Models/Report/Manager.php @@ -96,7 +96,12 @@ class Manager extends ManagerModel if ($this->c->Cache->has('report')) { $last = $this->list = $this->c->Cache->get('report'); } else { - $last = (int) $this->c->DB->query('SELECT r.id FROM ::reports AS r ORDER BY r.id DESC LIMIT 1')->fetchColumn(); + $query = 'SELECT r.id + FROM ::reports AS r + ORDER BY r.id DESC + LIMIT 1'; + + $last = (int) $this->c->DB->query($query)->fetchColumn(); $this->c->Cache->set('report', $last); } @@ -109,20 +114,23 @@ class Manager extends ManagerModel */ public function clear(): void { - $sql = 'SELECT r.zapped - FROM ::reports as r - WHERE r.zapped!=0 - ORDER BY r.zapped DESC - LIMIT 10,1'; - $time = (int) $this->c->DB->query($sql)->fetchColumn(); + $query = 'SELECT r.zapped + FROM ::reports as r + WHERE r.zapped!=0 + ORDER BY r.zapped DESC + LIMIT 10,1'; + + $time = (int) $this->c->DB->query($query)->fetchColumn(); if ($time > 0) { - $vars = [ + $vars = [ ':time' => $time, ]; - $sql = 'DELETE FROM ::reports - WHERE zapped<=?i:time'; - $this->c->DB->exec($sql, $vars); + $query = 'DELETE + FROM ::reports + WHERE zapped<=?i:time'; + + $this->c->DB->exec($query, $vars); } } } diff --git a/app/Models/Report/Model.php b/app/Models/Report/Model.php index 71b0d938..9775bb10 100644 --- a/app/Models/Report/Model.php +++ b/app/Models/Report/Model.php @@ -138,10 +138,18 @@ class Model extends DataModel public function getlinkZap(): string { if (empty($this->zapped)) { - return $this->c->Router->link('AdminReportsZap', [ - 'id' => $this->id, - 'token' => $this->c->Csrf->create('AdminReportsZap', ['id' => $this->id]), - ]); + return $this->c->Router->link( + 'AdminReportsZap', + [ + 'id' => $this->id, + 'token' => $this->c->Csrf->create( + 'AdminReportsZap', + [ + 'id' => $this->id, + ] + ), + ] + ); } else { return ''; } diff --git a/app/Models/Search/ActionP.php b/app/Models/Search/ActionP.php index 577205c6..160e2434 100644 --- a/app/Models/Search/ActionP.php +++ b/app/Models/Search/ActionP.php @@ -30,41 +30,29 @@ class ActionP extends Method return []; } - $sql = null; + $query = null; switch ($action) { case 'search': $list = $this->model->queryIds; break; case 'posts': - $sql = 'SELECT p.id - FROM ::posts AS p - INNER JOIN ::topics AS t ON t.id=p.topic_id - WHERE t.forum_id IN (?ai:forums) AND t.moved_to=0 AND p.poster_id=?i:uid - ORDER BY p.posted DESC'; + $query = 'SELECT p.id + FROM ::posts AS p + INNER JOIN ::topics AS t ON t.id=p.topic_id + WHERE t.forum_id IN (?ai:forums) AND t.moved_to=0 AND p.poster_id=?i:uid + ORDER BY p.posted DESC'; break; - -# case 'last': -# $sql = 'SELECT t.id -# FROM ::topics AS t -# WHERE t.forum_id IN (?ai:forums) AND t.moved_to=0 -# ORDER BY t.last_post DESC'; -# break; -# case 'unanswered': -# $sql = 'SELECT t.id -# FROM ::topics AS t -# WHERE t.forum_id IN (?ai:forums) AND t.moved_to=0 AND t.num_replies=0 -# ORDER BY t.last_post DESC'; -# break; default: throw new InvalidArgumentException('Unknown action: ' . $action); } - if (null !== $sql) { + if (null !== $query) { $vars = [ ':forums' => $forums, ':uid' => $uid, ]; - $list = $this->c->DB->query($sql, $vars)->fetchAll(PDO::FETCH_COLUMN); + + $list = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN); } $this->model->numPages = (int) \ceil((\count($list) ?: 1) / $this->c->user->disp_posts); diff --git a/app/Models/Search/ActionT.php b/app/Models/Search/ActionT.php index e15a3243..f7ec094d 100644 --- a/app/Models/Search/ActionT.php +++ b/app/Models/Search/ActionT.php @@ -30,61 +30,62 @@ class ActionT extends Method return []; } - $sql = null; + $query = null; switch ($action) { case 'search': $list = $this->model->queryIds; break; case 'latest_active_topics': - $sql = 'SELECT t.id - FROM ::topics AS t - WHERE t.forum_id IN (?ai:forums) AND t.moved_to=0 - ORDER BY t.last_post DESC'; + $query = 'SELECT t.id + FROM ::topics AS t + WHERE t.forum_id IN (?ai:forums) AND t.moved_to=0 + ORDER BY t.last_post DESC'; break; case 'unanswered_topics': - $sql = 'SELECT t.id - FROM ::topics AS t - WHERE t.forum_id IN (?ai:forums) AND t.moved_to=0 AND t.num_replies=0 - ORDER BY t.last_post DESC'; + $query = 'SELECT t.id + FROM ::topics AS t + WHERE t.forum_id IN (?ai:forums) AND t.moved_to=0 AND t.num_replies=0 + ORDER BY t.last_post DESC'; break; case 'topics_with_your_posts': - $sql = 'SELECT t.id - FROM ::topics AS t - INNER JOIN ::posts AS p ON t.id=p.topic_id - WHERE t.forum_id IN (?ai:forums) AND t.moved_to=0 AND p.poster_id=?i:uid - GROUP BY t.id - ORDER BY t.last_post DESC'; + $query = 'SELECT t.id + FROM ::topics AS t + INNER JOIN ::posts AS p ON t.id=p.topic_id + WHERE t.forum_id IN (?ai:forums) AND t.moved_to=0 AND p.poster_id=?i:uid + GROUP BY t.id + ORDER BY t.last_post DESC'; break; case 'topics': - $sql = 'SELECT t.id - FROM ::topics AS t - INNER JOIN ::posts AS p ON t.first_post_id=p.id - WHERE t.forum_id IN (?ai:forums) AND t.moved_to=0 AND p.poster_id=?i:uid - ORDER BY t.last_post DESC'; + $query = 'SELECT t.id + FROM ::topics AS t + INNER JOIN ::posts AS p ON t.first_post_id=p.id + WHERE t.forum_id IN (?ai:forums) AND t.moved_to=0 AND p.poster_id=?i:uid + ORDER BY t.last_post DESC'; break; case 'new': - $sql = 'SELECT t.id - FROM ::topics AS t - LEFT JOIN ::mark_of_topic AS mot ON (mot.uid=?i:uid AND mot.tid=t.id) - LEFT JOIN ::mark_of_forum AS mof ON (mof.uid=?i:uid AND mof.fid=t.forum_id) - WHERE t.forum_id IN (?ai:forums) - AND t.last_post>?i:max - AND t.moved_to=0 - AND (mot.mt_last_visit IS NULL OR t.last_post>mot.mt_last_visit) - AND (mof.mf_mark_all_read IS NULL OR t.last_post>mof.mf_mark_all_read) - ORDER BY t.last_post DESC'; + $query = 'SELECT t.id + FROM ::topics AS t + LEFT JOIN ::mark_of_topic AS mot ON (mot.uid=?i:uid AND mot.tid=t.id) + LEFT JOIN ::mark_of_forum AS mof ON (mof.uid=?i:uid AND mof.fid=t.forum_id) + WHERE t.forum_id IN (?ai:forums) + AND t.last_post>?i:max + AND t.moved_to=0 + AND (mot.mt_last_visit IS NULL OR t.last_post>mot.mt_last_visit) + AND (mof.mf_mark_all_read IS NULL OR t.last_post>mof.mf_mark_all_read) + ORDER BY t.last_post DESC'; break; default: throw new InvalidArgumentException('Unknown action: ' . $action); } - if (null !== $sql) { + if (null !== $query) { $vars = [ ':forums' => $forums, ':uid' => $uid, ':max' => \max((int) $this->c->user->last_visit, (int) $this->c->user->u_mark_all_read), ]; - $list = $this->c->DB->query($sql, $vars)->fetchAll(PDO::FETCH_COLUMN); + + $list = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN); } $this->model->numPages = (int) \ceil((\count($list) ?: 1) / $this->c->user->disp_topics); diff --git a/app/Models/Search/Delete.php b/app/Models/Search/Delete.php index 6732609e..95907d21 100644 --- a/app/Models/Search/Delete.php +++ b/app/Models/Search/Delete.php @@ -76,51 +76,55 @@ class Delete extends Method throw new InvalidArgumentException('Expected only User(s), Forum(s), Topic(s) or Post(s)'); } - $sql = null; + $query = null; if ($users) { - $vars = [ + $vars = [ ':users' => $users, ]; - $sql = 'DELETE FROM ::search_matches - WHERE post_id IN ( - SELECT p.id - FROM ::posts AS p - WHERE p.poster_id IN (?ai:users) - )'; + $query = 'DELETE + FROM ::search_matches + WHERE post_id IN ( + SELECT p.id + FROM ::posts AS p + WHERE p.poster_id IN (?ai:users) + )'; } if ($forums) { - $vars = [ + $vars = [ ':forums' => \array_keys($forums), ]; - $sql = 'DELETE FROM ::search_matches - WHERE post_id IN ( - SELECT p.id - FROM ::posts AS p - INNER JOIN ::topics AS t ON t.id=p.topic_id - WHERE t.forum_id IN (?ai:forums) - )'; + $query = 'DELETE + FROM ::search_matches + WHERE post_id IN ( + SELECT p.id + FROM ::posts AS p + INNER JOIN ::topics AS t ON t.id=p.topic_id + WHERE t.forum_id IN (?ai:forums) + )'; } if ($topics) { - $vars = [ + $vars = [ ':topics' => \array_keys($topics), ]; - $sql = 'DELETE FROM ::search_matches - WHERE post_id IN ( - SELECT p.id - FROM ::posts AS p - WHERE p.topic_id IN (?ai:topics) - )'; + $query = 'DELETE + FROM ::search_matches + WHERE post_id IN ( + SELECT p.id + FROM ::posts AS p + WHERE p.topic_id IN (?ai:topics) + )'; } if ($posts) { - $vars = [ + $vars = [ ':posts' => \array_keys($posts), ]; - $sql = 'DELETE FROM ::search_matches - WHERE post_id IN (?ai:posts)'; + $query = 'DELETE + FROM ::search_matches + WHERE post_id IN (?ai:posts)'; } - if ($sql) { - $this->c->DB->exec($sql, $vars); + if ($query) { + $this->c->DB->exec($query, $vars); } } } diff --git a/app/Models/Search/Execute.php b/app/Models/Search/Execute.php index 654385bc..3c2d9b54 100644 --- a/app/Models/Search/Execute.php +++ b/app/Models/Search/Execute.php @@ -54,15 +54,16 @@ class Execute extends Method $v->author . '-' . $v->forums; - $vars = [ + $vars = [ ':key' => $key, ]; - $sql = 'SELECT sc.search_time, sc.search_data - FROM ::search_cache AS sc - WHERE sc.search_key=?s:key - ORDER BY sc.search_time DESC - LIMIT 1'; - $row = $this->c->DB->query($sql, $vars)->fetch(); + $query = 'SELECT sc.search_time, sc.search_data + FROM ::search_cache AS sc + WHERE sc.search_key=?s:key + ORDER BY sc.search_time DESC + LIMIT 1'; + + $row = $this->c->DB->query($query, $vars)->fetch(); if ( ! empty($row['search_time']) @@ -77,26 +78,25 @@ class Execute extends Method } $ids = $this->exec($this->model->queryWords, $queryVars); - if (1 === $v->sort_dir) { \asort($ids, $this->sortType); } else { \arsort($ids, $this->sortType); } - $ids = \array_keys($ids); - $data = [ + $data = [ \implode(',', $ids), ]; - $vars = [ + $vars = [ ':data' => \implode("\n", $data), ':key' => $key, ':time' => \time(), ]; - $sql = 'INSERT INTO ::search_cache (search_key, search_time, search_data) - VALUES (?s:key, ?i:time, ?s:data)'; - $this->c->DB->exec($sql, $vars); + $query = 'INSERT INTO ::search_cache (search_key, search_time, search_data) + VALUES (?s:key, ?i:time, ?s:data)'; + + $this->c->DB->exec($query, $vars); $this->model->queryIds = $ids; $this->model->queryNoCache = true; diff --git a/app/Models/Search/Index.php b/app/Models/Search/Index.php index eb7752a9..9171c567 100644 --- a/app/Models/Search/Index.php +++ b/app/Models/Search/Index.php @@ -23,14 +23,15 @@ class Index extends Method : []; if ('add' !== $mode) { - $vars = [ + $vars = [ ':pid' => $post->id, ]; - $sql = 'SELECT sw.id, sw.word, sm.subject_match - FROM ::search_words AS sw - INNER JOIN ::search_matches AS sm ON sw.id=sm.word_id - WHERE sm.post_id=?i:pid'; - $stmt = $this->c->DB->query($sql, $vars); + $query = 'SELECT sw.id, sw.word, sm.subject_match + FROM ::search_words AS sw + INNER JOIN ::search_matches AS sm ON sw.id=sm.word_id + WHERE sm.post_id=?i:pid'; + + $stmt = $this->c->DB->query($query, $vars); $mesCurWords = []; $subCurWords = []; @@ -67,21 +68,22 @@ class Index extends Method $allWords = \array_unique(\array_merge($words['add']['p'], $words['add']['s'])); } if (! empty($allWords)) { - $vars = [ + $vars = [ ':words' => $allWords, ]; - $sql = 'SELECT sw.word - FROM ::search_words AS sw - WHERE sw.word IN(?as:words)'; - $oldWords = $this->c->DB->query($sql, $vars)->fetchAll(PDO::FETCH_COLUMN); + $query = 'SELECT sw.word + FROM ::search_words AS sw + WHERE sw.word IN(?as:words)'; + + $oldWords = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN); $newWords = \array_diff($allWords, $oldWords); if (! empty($newWords)) { - $sql = 'INSERT INTO ::search_words (word) VALUES(?s:word)'; + $query = 'INSERT INTO ::search_words (word) VALUES(?s:word)'; $stmt = null; foreach ($newWords as $word) { if (null === $stmt) { - $stmt = $this->c->DB->prepare($sql, [':word' => $word]); + $stmt = $this->c->DB->prepare($query, [':word' => $word]); $stmt->execute(); } else { $stmt->execute([':word' => $word]); @@ -95,14 +97,16 @@ class Index extends Method continue; } - $vars = [ + $vars = [ ':pid' => $post->id, ':subj' => 's' === $key ? 1 : 0, ':ids' => $list, ]; - $sql = 'DELETE FROM ::search_matches - WHERE word_id IN(?ai:ids) AND post_id=?i:pid AND subject_match=?i:subj'; - $this->c->DB->exec($sql, $vars); + $query = 'DELETE + FROM ::search_matches + WHERE word_id IN(?ai:ids) AND post_id=?i:pid AND subject_match=?i:subj'; + + $this->c->DB->exec($query, $vars); } foreach ($words['add'] as $key => $list) @@ -111,16 +115,17 @@ class Index extends Method continue; } - $vars = [ + $vars = [ ':pid' => $post->id, ':subj' => 's' === $key ? 1 : 0, ':words' => $list, ]; - $sql = 'INSERT INTO ::search_matches (post_id, word_id, subject_match) - SELECT ?i:pid, id, ?i:subj - FROM ::search_words - WHERE word IN(?as:words)'; - $this->c->DB->exec($sql, $vars); + $query = 'INSERT INTO ::search_matches (post_id, word_id, subject_match) + SELECT ?i:pid, id, ?i:subj + FROM ::search_words + WHERE word IN(?as:words)'; + + $this->c->DB->exec($query, $vars); } } diff --git a/app/Models/Search/Model.php b/app/Models/Search/Model.php index 943b3e27..f6450955 100644 --- a/app/Models/Search/Model.php +++ b/app/Models/Search/Model.php @@ -37,7 +37,10 @@ class Model extends ParentModel */ protected function getlink(): string { - return $this->c->Router->link($this->linkMarker, $this->linkArgs); + return $this->c->Router->link( + $this->linkMarker, + $this->linkArgs + ); } /** diff --git a/app/Models/Topic/Access.php b/app/Models/Topic/Access.php index 9f99ea90..0a506305 100644 --- a/app/Models/Topic/Access.php +++ b/app/Models/Topic/Access.php @@ -22,12 +22,15 @@ class Access extends Action } if (! empty($ids)) { - $vars = [ + $vars = [ ':ids' => $ids, ':closed' => $open ? 0 : 1, ]; - $sql = 'UPDATE ::topics SET closed=?i:closed WHERE id IN (?ai:ids)'; - $this->c->DB->exec($sql, $vars); + $query = 'UPDATE ::topics + SET closed=?i:closed + WHERE id IN (?ai:ids)'; + + $this->c->DB->exec($query, $vars); } } } diff --git a/app/Models/Topic/CalcStat.php b/app/Models/Topic/CalcStat.php index b05b3272..a328a7b5 100644 --- a/app/Models/Topic/CalcStat.php +++ b/app/Models/Topic/CalcStat.php @@ -24,35 +24,35 @@ class CalcStat extends Method if ($this->model->moved_to) { $numReplies = 0; } else { - $vars = [ + $vars = [ ':tid' => $this->model->id ]; - $sql = 'SELECT COUNT(p.id) - 1 - FROM ::posts AS p - WHERE p.topic_id=?i:tid'; + $query = 'SELECT COUNT(p.id) - 1 + FROM ::posts AS p + WHERE p.topic_id=?i:tid'; - $numReplies = $this->c->DB->query($sql, $vars)->fetchColumn(); + $numReplies = $this->c->DB->query($query, $vars)->fetchColumn(); - $sql = 'SELECT p.id, p.poster, p.poster_id, p.posted - FROM ::posts AS p - WHERE p.topic_id=?i:tid - ORDER BY p.id - LIMIT 1'; + $query = 'SELECT p.id, p.poster, p.poster_id, p.posted + FROM ::posts AS p + WHERE p.topic_id=?i:tid + ORDER BY p.id + LIMIT 1'; - $result = $this->c->DB->query($sql, $vars)->fetch(); + $result = $this->c->DB->query($query, $vars)->fetch(); $this->model->poster = $result['poster']; $this->model->poster_id = $result['poster_id']; $this->model->posted = $result['posted']; $this->model->first_post_id = $result['id']; - $sql = 'SELECT p.id, p.poster, p.poster_id, p.posted, p.edited - FROM ::posts AS p - WHERE p.topic_id=?i:tid - ORDER BY p.id DESC - LIMIT 1'; + $query = 'SELECT p.id, p.poster, p.poster_id, p.posted, p.edited + FROM ::posts AS p + WHERE p.topic_id=?i:tid + ORDER BY p.id DESC + LIMIT 1'; - $result = $this->c->DB->query($sql, $vars)->fetch(); + $result = $this->c->DB->query($query, $vars)->fetch(); $this->model->last_post_id = $result['id']; $this->model->last_poster = $result['poster']; diff --git a/app/Models/Topic/Delete.php b/app/Models/Topic/Delete.php index 91366403..96bd9221 100644 --- a/app/Models/Topic/Delete.php +++ b/app/Models/Topic/Delete.php @@ -73,36 +73,39 @@ class Delete extends Action } if ($forums) { - $vars = [ + $vars = [ ':forums' => \array_keys($forums), ]; - $sql = 'SELECT p.poster_id - FROM ::topics AS t - INNER JOIN ::posts AS p ON t.first_post_id=p.id - WHERE t.forum_id IN (?ai:forums) AND t.moved_to=0 - GROUP BY p.poster_id'; - $usersUpd = $this->c->DB->query($sql, $vars)->fetchAll(PDO::FETCH_COLUMN); + $query = 'SELECT p.poster_id + FROM ::topics AS t + INNER JOIN ::posts AS p ON t.first_post_id=p.id + WHERE t.forum_id IN (?ai:forums) AND t.moved_to=0 + GROUP BY p.poster_id'; + + $usersUpd = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN); } if ($topics) { - $vars = [ + $vars = [ ':topics' => \array_keys($topics), ]; - $sql = 'SELECT p.poster_id - FROM ::topics AS t - INNER JOIN ::posts AS p ON t.first_post_id=p.id - WHERE t.id IN (?ai:topics) AND t.moved_to=0 - GROUP BY p.poster_id'; - $usersUpd = $this->c->DB->query($sql, $vars)->fetchAll(PDO::FETCH_COLUMN); + $query = 'SELECT p.poster_id + FROM ::topics AS t + INNER JOIN ::posts AS p ON t.first_post_id=p.id + WHERE t.id IN (?ai:topics) AND t.moved_to=0 + GROUP BY p.poster_id'; + + $usersUpd = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN); } if ($usersDel) { - $vars = [ + $vars = [ ':users' => $usersDel, ]; - $sql = 'SELECT t.id, t.forum_id - FROM ::topics AS t - INNER JOIN ::posts AS p ON t.first_post_id=p.id - WHERE p.poster_id IN (?ai:users)'; - $topics = $this->c->DB->query($sql, $vars)->fetchAll(PDO::FETCH_KEY_PAIR); //???? + $query = 'SELECT t.id, t.forum_id + FROM ::topics AS t + INNER JOIN ::posts AS p ON t.first_post_id=p.id + WHERE p.poster_id IN (?ai:users)'; + + $topics = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_KEY_PAIR); //???? if ($topics) { foreach ($topics as $value) { // ???? @@ -121,54 +124,66 @@ class Delete extends Action // удаление тем-ссылок на удаляемые темы if ($users) { - $vars = [ + $vars = [ ':users' => $users, ]; - $sql = 'DELETE FROM ::mark_of_topic - WHERE uid IN (?ai:users)'; - $this->c->DB->exec($sql, $vars); + $query = 'DELETE + FROM ::mark_of_topic + WHERE uid IN (?ai:users)'; + + $this->c->DB->exec($query, $vars); } if ($usersToGuest) { - $vars = [ + $vars = [ ':users' => $usersToGuest, ]; - $sql = 'UPDATE ::topics - SET poster_id=1 - WHERE poster_id IN (?ai:users)'; - $this->c->DB->exec($sql, $vars); + $query = 'UPDATE ::topics + SET poster_id=1 + WHERE poster_id IN (?ai:users)'; - $sql = 'UPDATE ::topics - SET last_poster_id=1 - WHERE last_poster_id IN (?ai:users)'; - $this->c->DB->exec($sql, $vars); + $this->c->DB->exec($query, $vars); + + $query = 'UPDATE ::topics + SET last_poster_id=1 + WHERE last_poster_id IN (?ai:users)'; + + $this->c->DB->exec($query, $vars); } if ($forums) { - $vars = [ + $vars = [ ':forums' => \array_keys($forums), ]; - $sql = 'DELETE FROM ::mark_of_topic - WHERE tid IN ( - SELECT id - FROM ::topics - WHERE forum_id IN (?ai:forums) - )'; - $this->c->DB->exec($sql, $vars); + $query = 'DELETE + FROM ::mark_of_topic + WHERE tid IN ( + SELECT id + FROM ::topics + WHERE forum_id IN (?ai:forums) + )'; - $sql = 'DELETE FROM ::topics - WHERE forum_id IN (?ai:forums)'; - $this->c->DB->exec($sql, $vars); + $this->c->DB->exec($query, $vars); + + $query = 'DELETE + FROM ::topics + WHERE forum_id IN (?ai:forums)'; + + $this->c->DB->exec($query, $vars); } if ($topics) { - $vars = [ + $vars = [ ':topics' => \array_keys($topics), ]; - $sql = 'DELETE FROM ::mark_of_topic - WHERE tid IN (?ai:topics)'; - $this->c->DB->exec($sql, $vars); + $query = 'DELETE + FROM ::mark_of_topic + WHERE tid IN (?ai:topics)'; - $sql = 'DELETE FROM ::topics - WHERE id IN (?ai:topics)'; - $this->c->DB->exec($sql, $vars); + $this->c->DB->exec($query, $vars); + + $query = 'DELETE + FROM ::topics + WHERE id IN (?ai:topics)'; + + $this->c->DB->exec($query, $vars); foreach ($parents as $forum) { $this->c->forums->update($forum->calcStat()); diff --git a/app/Models/Topic/Load.php b/app/Models/Topic/Load.php index 7fc885b3..e4aea42b 100644 --- a/app/Models/Topic/Load.php +++ b/app/Models/Topic/Load.php @@ -15,23 +15,24 @@ class Load extends Action protected function getSql(string $where, bool $full): string { if ($this->c->user->isGuest) { - $sql = 'SELECT t.* - FROM ::topics AS t - WHERE ' . $where; + $query = 'SELECT t.* + FROM ::topics AS t + WHERE ' . $where; } elseif ($full) { - $sql = 'SELECT t.*, s.user_id AS is_subscribed, mof.mf_mark_all_read, mot.mt_last_visit, mot.mt_last_read - FROM ::topics AS t - LEFT JOIN ::topic_subscriptions AS s ON (t.id=s.topic_id AND s.user_id=?i:uid) - LEFT JOIN ::mark_of_forum AS mof ON (mof.uid=?i:uid AND t.forum_id=mof.fid) - LEFT JOIN ::mark_of_topic AS mot ON (mot.uid=?i:uid AND t.id=mot.tid) - WHERE ' . $where; + $query = 'SELECT t.*, s.user_id AS is_subscribed, mof.mf_mark_all_read, mot.mt_last_visit, mot.mt_last_read + FROM ::topics AS t + LEFT JOIN ::topic_subscriptions AS s ON (t.id=s.topic_id AND s.user_id=?i:uid) + LEFT JOIN ::mark_of_forum AS mof ON (mof.uid=?i:uid AND t.forum_id=mof.fid) + LEFT JOIN ::mark_of_topic AS mot ON (mot.uid=?i:uid AND t.id=mot.tid) + WHERE ' . $where; } else { - $sql = 'SELECT t.*, mot.mt_last_visit, mot.mt_last_read - FROM ::topics AS t - LEFT JOIN ::mark_of_topic AS mot ON (mot.uid=?i:uid AND t.id=mot.tid) - WHERE ' . $where; + $query = 'SELECT t.*, mot.mt_last_visit, mot.mt_last_read + FROM ::topics AS t + LEFT JOIN ::mark_of_topic AS mot ON (mot.uid=?i:uid AND t.id=mot.tid) + WHERE ' . $where; } - return $sql; + + return $query; } /** @@ -49,12 +50,13 @@ class Load extends Action throw new InvalidArgumentException('Expected a positive topic id'); } - $vars = [ + $vars = [ ':tid' => $id, ':uid' => $this->c->user->id, ]; - $sql = $this->getSql('t.id=?i:tid', true); - $data = $this->c->DB->query($sql, $vars)->fetch(); + $query = $this->getSql('t.id=?i:tid', true); + + $data = $this->c->DB->query($query, $vars)->fetch(); // тема отсутствует или недоступна if (empty($data)) { @@ -90,12 +92,13 @@ class Load extends Action } } - $vars = [ + $vars = [ ':ids' => $ids, ':uid' => $this->c->user->id, ]; - $sql = $this->getSql('t.id IN (?ai:ids)', $full); - $stmt = $this->c->DB->query($sql, $vars); + $query = $this->getSql('t.id IN (?ai:ids)', $full); + + $stmt = $this->c->DB->query($query, $vars); $result = []; while ($row = $stmt->fetch()) { diff --git a/app/Models/Topic/Merge.php b/app/Models/Topic/Merge.php index cc99cbe3..e8087f9a 100644 --- a/app/Models/Topic/Merge.php +++ b/app/Models/Topic/Merge.php @@ -52,24 +52,26 @@ class Merge extends Action } //???? перенести обработку в посты? - $vars = [ + $vars = [ 'start' => "[from]", 'end' => "[/from]\n", 'topics' => $ids, ]; - $sql = 'UPDATE ::posts AS p, ::topics as t - SET p.message=CONCAT(?s:start, t.subject, ?s:end, p.message) - WHERE p.topic_id IN (?ai:topics) AND t.id=p.topic_id'; - $this->c->DB->exec($sql, $vars); + $query = 'UPDATE ::posts AS p, ::topics as t + SET p.message=CONCAT(?s:start, t.subject, ?s:end, p.message) + WHERE p.topic_id IN (?ai:topics) AND t.id=p.topic_id'; - $vars = [ + $this->c->DB->exec($query, $vars); + + $vars = [ 'id' => $firstTopic->id, 'topics' => $ids, ]; - $sql = 'UPDATE ::posts AS p - SET p.topic_id=?i:id - WHERE p.topic_id IN (?ai:topics)'; - $this->c->DB->exec($sql, $vars); + $query = 'UPDATE ::posts AS p + SET p.topic_id=?i:id + WHERE p.topic_id IN (?ai:topics)'; + + $this->c->DB->exec($query, $vars); // добавить перенос подписок на первую тему? @@ -79,13 +81,14 @@ class Merge extends Action $this->c->topics->update($topic->calcStat()); } - $vars = [ + $vars = [ 'topics' => $ids, ]; - $sql = 'SELECT t.id - FROM ::topics AS t - WHERE t.moved_to IN (?ai:topics)'; - $linkTopics = $this->c->DB->query($sql, $vars)->fetchAll(PDO::FETCH_COLUMN); + $query = 'SELECT t.id + FROM ::topics AS t + WHERE t.moved_to IN (?ai:topics)'; + + $linkTopics = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN); foreach ($linkTopics as $topic) { $topic->moved_to = $firstTopic->id; diff --git a/app/Models/Topic/Model.php b/app/Models/Topic/Model.php index fe0b36d2..e292a622 100644 --- a/app/Models/Topic/Model.php +++ b/app/Models/Topic/Model.php @@ -69,7 +69,13 @@ class Model extends DataModel */ protected function getlink(): string { - return $this->c->Router->link('Topic', ['id' => $this->moved_to ?: $this->id, 'name' => \ForkBB\cens($this->subject)]); + return $this->c->Router->link( + 'Topic', + [ + 'id' => $this->moved_to ?: $this->id, + 'name' => \ForkBB\cens($this->subject), + ] + ); } /** @@ -79,7 +85,12 @@ class Model extends DataModel */ protected function getlinkReply(): string { - return $this->c->Router->link('NewReply', ['id' => $this->id]); + return $this->c->Router->link( + 'NewReply', + [ + 'id' => $this->id, + ] + ); } /** @@ -92,7 +103,12 @@ class Model extends DataModel if ($this->moved_to) { return null; } else { - return $this->c->Router->link('ViewPost', ['id' => $this->last_post_id]); + return $this->c->Router->link( + 'ViewPost', + [ + 'id' => $this->last_post_id, + ] + ); } } @@ -103,7 +119,12 @@ class Model extends DataModel */ protected function getlinkNew(): string { - return $this->c->Router->link('TopicViewNew', ['id' => $this->id]); + return $this->c->Router->link( + 'TopicViewNew', + [ + 'id' => $this->id, + ] + ); } /** @@ -111,7 +132,12 @@ class Model extends DataModel */ protected function getlinkUnread(): string { - return $this->c->Router->link('TopicViewUnread', ['id' => $this->id]); + return $this->c->Router->link( + 'TopicViewUnread', + [ + 'id' => $this->id, + ] + ); } /** @@ -172,13 +198,15 @@ class Model extends DataModel return 0; } - $vars = [ + $vars = [ ':tid' => $this->id, ':visit' => $this->hasNew, ]; - $sql = 'SELECT MIN(p.id) FROM ::posts AS p WHERE p.topic_id=?i:tid AND p.posted>?i:visit'; + $query = 'SELECT MIN(p.id) + FROM ::posts AS p + WHERE p.topic_id=?i:tid AND p.posted>?i:visit'; - $pid = $this->c->DB->query($sql, $vars)->fetchColumn(); + $pid = $this->c->DB->query($query, $vars)->fetchColumn(); return $pid ?: 0; } @@ -194,13 +222,15 @@ class Model extends DataModel return 0; } - $vars = [ + $vars = [ ':tid' => $this->id, ':visit' => $this->hasUnread, ]; - $sql = 'SELECT MIN(p.id) FROM ::posts AS p WHERE p.topic_id=?i:tid AND p.posted>?i:visit'; + $query = 'SELECT MIN(p.id) + FROM ::posts AS p + WHERE p.topic_id=?i:tid AND p.posted>?i:visit'; - $pid = $this->c->DB->query($sql, $vars)->fetchColumn(); + $pid = $this->c->DB->query($query, $vars)->fetchColumn(); return $pid ?: 0; } @@ -264,17 +294,18 @@ class Model extends DataModel throw new InvalidArgumentException('Bad number of displayed page'); } - $vars = [ + $vars = [ ':tid' => $this->id, ':offset' => ($this->page - 1) * $this->c->user->disp_posts, ':rows' => $this->c->user->disp_posts, ]; - $sql = 'SELECT p.id - FROM ::posts AS p - WHERE p.topic_id=?i:tid - ORDER BY p.id - LIMIT ?i:offset, ?i:rows'; - $list = $this->c->DB->query($sql, $vars)->fetchAll(PDO::FETCH_COLUMN); + $query = 'SELECT p.id + FROM ::posts AS p + WHERE p.topic_id=?i:tid + ORDER BY p.id + LIMIT ?i:offset, ?i:rows'; + + $list = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN); if ( ! empty($list) @@ -305,16 +336,17 @@ class Model extends DataModel $this->page = 1; - $vars = [ - ':tid' => $this->id, - ':rows' => $this->c->config->o_topic_review, + $vars = [ + ':tid' => $this->id, + ':rows' => $this->c->config->o_topic_review, ]; - $sql = 'SELECT p.id - FROM ::posts AS p - WHERE p.topic_id=?i:tid - ORDER BY p.id DESC - LIMIT 0, ?i:rows'; - $this->idsList = $this->c->DB->query($sql, $vars)->fetchAll(PDO::FETCH_COLUMN); + $query = 'SELECT p.id + FROM ::posts AS p + WHERE p.topic_id=?i:tid + ORDER BY p.id DESC + LIMIT 0, ?i:rows'; + + $this->idsList = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN); return empty($this->idsList) ? [] : $this->c->posts->view($this, true); } @@ -326,16 +358,16 @@ class Model extends DataModel */ public function calcPage(int $pid): void { - $vars = [ + $vars = [ ':tid' => $this->id, ':pid' => $pid, ]; - $sql = 'SELECT COUNT(p.id) AS num - FROM ::posts AS p - INNER JOIN ::posts AS j ON (j.topic_id=?i:tid AND j.id=?i:pid) - WHERE p.topic_id=?i:tid AND p.idc->DB->query($sql, $vars)->fetch(); + $result = $this->c->DB->query($query, $vars)->fetch(); $this->page = empty($result) ? null : (int) \ceil(($result['num'] + 1) / $this->c->user->disp_posts); } @@ -355,12 +387,14 @@ class Model extends DataModel */ public function incViews(): void { - $vars = [ + $vars = [ ':tid' => $this->id, ]; - $sql = 'UPDATE ::topics SET num_views=num_views+1 WHERE id=?i:tid'; + $query = 'UPDATE ::topics + SET num_views=num_views+1 + WHERE id=?i:tid'; - $this->c->DB->query($sql, $vars); + $this->c->DB->query($query, $vars); } /** @@ -398,19 +432,22 @@ class Model extends DataModel empty($this->mt_last_read) && empty($this->mt_last_visit) ) { - $sql = 'INSERT INTO ::mark_of_topic (uid, tid, mt_last_visit, mt_last_read) - SELECT ?i:uid, ?i:tid, ?i:visit, ?i:read - FROM ::groups - WHERE NOT EXISTS (SELECT 1 - FROM ::mark_of_topic - WHERE uid=?i:uid AND tid=?i:tid) - LIMIT 1'; + $query = 'INSERT INTO ::mark_of_topic (uid, tid, mt_last_visit, mt_last_read) + SELECT ?i:uid, ?i:tid, ?i:visit, ?i:read + FROM ::groups + WHERE NOT EXISTS ( + SELECT 1 + FROM ::mark_of_topic + WHERE uid=?i:uid AND tid=?i:tid + ) + LIMIT 1'; } else { - $sql = 'UPDATE ::mark_of_topic - SET mt_last_visit=?i:visit, mt_last_read=?i:read - WHERE uid=?i:uid AND tid=?i:tid'; + $query = 'UPDATE ::mark_of_topic + SET mt_last_visit=?i:visit, mt_last_read=?i:read + WHERE uid=?i:uid AND tid=?i:tid'; } - $this->c->DB->exec($sql, $vars); + + $this->c->DB->exec($query, $vars); } } } diff --git a/app/Models/Topic/View.php b/app/Models/Topic/View.php index 618c48c9..2e54fdee 100644 --- a/app/Models/Topic/View.php +++ b/app/Models/Topic/View.php @@ -45,15 +45,16 @@ class View extends Action ! $this->c->user->isGuest && '1' == $this->c->config->o_show_dot ) { - $vars = [ + $vars = [ ':uid' => $this->c->user->id, ':ids' => $arg->idsList, ]; - $sql = 'SELECT p.topic_id - FROM ::posts AS p - WHERE p.poster_id=?i:uid AND p.topic_id IN (?ai:ids) - GROUP BY p.topic_id'; - $dots = $this->c->DB->query($sql, $vars)->fetchAll(PDO::FETCH_COLUMN); + $query = 'SELECT p.topic_id + FROM ::posts AS p + WHERE p.poster_id=?i:uid AND p.topic_id IN (?ai:ids) + GROUP BY p.topic_id'; + + $dots = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN); foreach ($dots as $id) { if ( diff --git a/app/Models/User/AdminsIds.php b/app/Models/User/AdminsIds.php index 19646b06..a3882bd3 100644 --- a/app/Models/User/AdminsIds.php +++ b/app/Models/User/AdminsIds.php @@ -14,11 +14,13 @@ class AdminsIds extends Action */ public function adminsIds(): array { - $vars = [ + $vars = [ ':gid' => $this->c->GROUP_ADMIN, ]; - $sql = 'SELECT u.id FROM ::users AS u WHERE u.group_id=?i:gid'; + $query = 'SELECT u.id + FROM ::users AS u + WHERE u.group_id=?i:gid'; - return $this->c->DB->query($sql, $vars)->fetchAll(PDO::FETCH_COLUMN); + return $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN); } } diff --git a/app/Models/User/ChangeGroup.php b/app/Models/User/ChangeGroup.php index 6594b767..83912b24 100644 --- a/app/Models/User/ChangeGroup.php +++ b/app/Models/User/ChangeGroup.php @@ -69,10 +69,11 @@ class ChangeGroup extends Action ':new' => $newGroupId, ':ids' => $ids, ]; - $sql = 'UPDATE ::users AS u - SET u.group_id = ?i:new - WHERE u.id IN (?ai:ids)'; - $this->c->DB->exec($sql, $vars); + $query = 'UPDATE ::users AS u + SET u.group_id = ?i:new + WHERE u.id IN (?ai:ids)'; + + $this->c->DB->exec($query, $vars); if ($adminPresent) { $this->c->admins->reset(); diff --git a/app/Models/User/Delete.php b/app/Models/User/Delete.php index e4e08180..702f67e5 100644 --- a/app/Models/User/Delete.php +++ b/app/Models/User/Delete.php @@ -64,12 +64,14 @@ class Delete extends Action $this->c->Online->delete($user); } - $vars = [ + $vars = [ ':users' => $ids, ]; - $sql = 'DELETE FROM ::users - WHERE id IN (?ai:users)'; - $this->c->DB->exec($sql, $vars); + $query = 'DELETE + FROM ::users + WHERE id IN (?ai:users)'; + + $this->c->DB->exec($query, $vars); if ($adminPresent) { $this->c->admins->reset(); diff --git a/app/Models/User/Filter.php b/app/Models/User/Filter.php index 8c0471c0..d6a2147f 100644 --- a/app/Models/User/Filter.php +++ b/app/Models/User/Filter.php @@ -98,13 +98,12 @@ class Filter extends Action } $where = \implode(' AND ', $where); + $query = "SELECT u.id + FROM ::users AS u + WHERE {$where} + ORDER BY {$orderBy}"; - $sql = "SELECT u.id - FROM ::users AS u - WHERE {$where} - ORDER BY {$orderBy}"; - - $ids = $this->c->DB->query($sql, $vars)->fetchAll(PDO::FETCH_COLUMN); + $ids = $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN); return $ids; } diff --git a/app/Models/User/Load.php b/app/Models/User/Load.php index 14f35d07..5ff2b1ab 100644 --- a/app/Models/User/Load.php +++ b/app/Models/User/Load.php @@ -14,11 +14,12 @@ class Load extends Action */ protected function getSql(string $where): string { - $sql = 'SELECT u.*, g.* - FROM ::users AS u - LEFT JOIN ::groups AS g ON u.group_id=g.g_id - WHERE ' . $where; - return $sql; + $query = 'SELECT u.*, g.* + FROM ::users AS u + LEFT JOIN ::groups AS g ON u.group_id=g.g_id + WHERE ' . $where; + + return $query; } /** @@ -32,9 +33,10 @@ class Load extends Action throw new InvalidArgumentException('Expected a positive user id'); } - $vars = [':id' => $id]; - $sql = $this->getSql('u.id=?i:id'); - $data = $this->c->DB->query($sql, $vars)->fetch(); + $vars = [':id' => $id]; + $query = $this->getSql('u.id=?i:id'); + + $data = $this->c->DB->query($query, $vars)->fetch(); return empty($data['id']) ? null : $this->manager->create($data); } @@ -55,9 +57,10 @@ class Load extends Action } } - $vars = [':ids' => $ids]; - $sql = $this->getSql('u.id IN (?ai:ids)'); - $data = $this->c->DB->query($sql, $vars)->fetchAll(); + $vars = [':ids' => $ids]; + $query = $this->getSql('u.id IN (?ai:ids)'); + + $data = $this->c->DB->query($query, $vars)->fetchAll(); $result = []; foreach ($data as $row) { @@ -71,9 +74,9 @@ class Load extends Action * * @throws ForkException */ - protected function returnUser(string $sql, array $vars): ?User + protected function returnUser(string $query, array $vars): ?User { - $data = $this->c->DB->query($sql, $vars)->fetchAll(); + $data = $this->c->DB->query($query, $vars)->fetchAll(); if (empty($data)) { return null; @@ -91,9 +94,9 @@ class Load extends Action { $where = $caseInsencytive ? 'LOWER(u.username)=LOWER(?s:name)' : 'u.username=?s:name'; $vars = [':name' => $name]; - $sql = $this->getSql($where); + $query = $this->getSql($where); - return $this->returnUser($sql, $vars); + return $this->returnUser($query, $vars); } /** @@ -101,9 +104,9 @@ class Load extends Action */ public function loadByEmail(string $email): ?User { - $vars = [':email' => $this->c->NormEmail->normalize($email)]; - $sql = $this->getSql('u.email_normal=?s:email'); + $vars = [':email' => $this->c->NormEmail->normalize($email)]; + $query = $this->getSql('u.email_normal=?s:email'); - return $this->returnUser($sql, $vars); + return $this->returnUser($query, $vars); } } diff --git a/app/Models/User/Model.php b/app/Models/User/Model.php index c2c2fcfd..4ddcc4ce 100644 --- a/app/Models/User/Model.php +++ b/app/Models/User/Model.php @@ -172,7 +172,13 @@ class Model extends DataModel if ($this->isGuest) { return null; } else { - return $this->c->Router->link('User', ['id' => $this->id, 'name' => $this->username]); + return $this->c->Router->link( + 'User', + [ + 'id' => $this->id, + 'name' => $this->username, + ] + ); } } @@ -365,14 +371,20 @@ class Model extends DataModel && $this->id !== $post->user->id //???? && 0 < $post->user->g_promote_min_posts * $post->user->g_promote_next_group ) { - return $this->c->Router->link('AdminUserPromote', [ - 'uid' => $post->user->id, - 'pid' => $post->id, - 'token' => $this->c->Csrf->create('AdminUserPromote', [ + return $this->c->Router->link( + 'AdminUserPromote', + [ 'uid' => $post->user->id, 'pid' => $post->id, - ]), - ]); + 'token' => $this->c->Csrf->create( + 'AdminUserPromote', + [ + 'uid' => $post->user->id, + 'pid' => $post->id, + ] + ), + ] + ); } else { return null; } diff --git a/app/Models/User/Promote.php b/app/Models/User/Promote.php index 1bf3ead4..22cca7eb 100644 --- a/app/Models/User/Promote.php +++ b/app/Models/User/Promote.php @@ -23,25 +23,27 @@ class Promote extends Action // перемещение всех пользователей из группы 0 в группу 1 if (2 == $count) { - $vars = [ + $vars = [ ':old' => $args[0]->g_id, ':new' => $args[1]->g_id, ]; - $sql = 'UPDATE ::users - SET group_id=?i:new - WHERE group_id=?i:old'; - return $this->c->DB->exec($sql, $vars); + $query = 'UPDATE ::users + SET group_id=?i:new + WHERE group_id=?i:old'; + + return $this->c->DB->exec($query, $vars); // продвижение всех пользователей в группе 0 } elseif (1 == $count) { - $vars = [ + $vars = [ ':old' => $args[0]->g_id, ':new' => $args[0]->g_promote_next_group, ':count' => $args[0]->g_promote_min_posts, ]; - $sql = 'UPDATE ::users - SET group_id=?i:new - WHERE group_id=?i:old AND num_posts>=?i:count'; - return $this->c->DB->exec($sql, $vars); + $query = 'UPDATE ::users + SET group_id=?i:new + WHERE group_id=?i:old AND num_posts>=?i:count'; + + return $this->c->DB->exec($query, $vars); } else { throw new RuntimeException("Illegal number of parameters ({$count})"); } diff --git a/app/Models/User/UpdateCountPosts.php b/app/Models/User/UpdateCountPosts.php index 1b7ca1fc..c9ca77d4 100644 --- a/app/Models/User/UpdateCountPosts.php +++ b/app/Models/User/UpdateCountPosts.php @@ -43,17 +43,17 @@ class UpdateCountPosts extends Action ]; } - $sql = 'UPDATE ::users AS u - SET u.num_posts = ( - SELECT COUNT(p.id) - FROM ::posts AS p - INNER JOIN ::topics AS t ON t.id=p.topic_id - INNER JOIN ::forums AS f ON f.id=t.forum_id - WHERE p.poster_id=u.id AND f.no_sum_mess=0 - GROUP BY p.poster_id - ) - WHERE ' . $where; + $query = 'UPDATE ::users AS u + SET u.num_posts = ( + SELECT COUNT(p.id) + FROM ::posts AS p + INNER JOIN ::topics AS t ON t.id=p.topic_id + INNER JOIN ::forums AS f ON f.id=t.forum_id + WHERE p.poster_id=u.id AND f.no_sum_mess=0 + GROUP BY p.poster_id + ) + WHERE ' . $where; - $this->c->DB->exec($sql, $vars); + $this->c->DB->exec($query, $vars); } } diff --git a/app/Models/User/UpdateCountTopics.php b/app/Models/User/UpdateCountTopics.php index e764c4f3..f2ba56ee 100644 --- a/app/Models/User/UpdateCountTopics.php +++ b/app/Models/User/UpdateCountTopics.php @@ -43,16 +43,16 @@ class UpdateCountTopics extends Action ]; } - $sql = 'UPDATE ::users AS u - SET u.num_topics = ( - SELECT COUNT(t.id) - FROM ::topics AS t - INNER JOIN ::posts AS p ON t.first_post_id=p.id - WHERE p.poster_id=u.id AND t.moved_to=0 - GROUP BY p.poster_id - ) - WHERE ' . $where; + $query = 'UPDATE ::users AS u + SET u.num_topics = ( + SELECT COUNT(t.id) + FROM ::topics AS t + INNER JOIN ::posts AS p ON t.first_post_id=p.id + WHERE p.poster_id=u.id AND t.moved_to=0 + GROUP BY p.poster_id + ) + WHERE ' . $where; - $this->c->DB->exec($sql, $vars); + $this->c->DB->exec($query, $vars); } } diff --git a/app/Models/User/UsersNumber.php b/app/Models/User/UsersNumber.php index 2e91c653..183fefda 100644 --- a/app/Models/User/UsersNumber.php +++ b/app/Models/User/UsersNumber.php @@ -23,11 +23,13 @@ class UsersNumber extends Action return 0; } - $vars = [ + $vars = [ ':gid' => $group->g_id, ]; - $sql = 'SELECT COUNT(u.id) FROM ::users AS u WHERE u.group_id=?i:gid'; + $query = 'SELECT COUNT(u.id) + FROM ::users AS u + WHERE u.group_id=?i:gid'; - return $this->c->DB->query($sql, $vars)->fetchColumn(); + return $this->c->DB->query($query, $vars)->fetchColumn(); } } diff --git a/app/bootstrap.php b/app/bootstrap.php index 9642cf9c..40dd732d 100644 --- a/app/bootstrap.php +++ b/app/bootstrap.php @@ -42,15 +42,15 @@ if ( $c->PUBLIC_URL = $c->BASE_URL . $forkPublicPrefix; $c->FORK_REVISION = 1; -$c->START = $forkStart; -$c->DIR_APP = __DIR__; -$c->DIR_PUBLIC = $forkPublic; -$c->DIR_CONFIG = __DIR__ . '/config'; -$c->DIR_CACHE = __DIR__ . '/cache'; -$c->DIR_VIEWS = __DIR__ . '/templates'; -$c->DIR_LANG = __DIR__ . '/lang'; -$c->DATE_FORMATS = [$c->config->o_date_format, 'Y-m-d', 'Y-d-m', 'd-m-Y', 'm-d-Y', 'M j Y', 'jS M Y']; -$c->TIME_FORMATS = [$c->config->o_time_format, 'H:i:s', 'H:i', 'g:i:s a', 'g:i a']; +$c->START = $forkStart; +$c->DIR_APP = __DIR__; +$c->DIR_PUBLIC = $forkPublic; +$c->DIR_CONFIG = __DIR__ . '/config'; +$c->DIR_CACHE = __DIR__ . '/cache'; +$c->DIR_VIEWS = __DIR__ . '/templates'; +$c->DIR_LANG = __DIR__ . '/lang'; +$c->DATE_FORMATS = [$c->config->o_date_format, 'Y-m-d', 'Y-d-m', 'd-m-Y', 'm-d-Y', 'M j Y', 'jS M Y']; +$c->TIME_FORMATS = [$c->config->o_time_format, 'H:i:s', 'H:i', 'g:i:s a', 'g:i a']; $controllers = ['Primary', 'Routing']; foreach ($controllers as $controller) { @@ -76,7 +76,7 @@ if ( && $c->DEBUG > 0 ) { $debug = $c->View->rendering($c->Debug->debug()); - $tpl = \str_replace('', $debug, $tpl); + $tpl = \str_replace('', $debug, $tpl); } exit($tpl);