From b44332a6114c2f22bbd5184453ab758833ccc72a Mon Sep 17 00:00:00 2001 From: Bugo Date: Mon, 20 Jan 2025 00:27:26 +0500 Subject: [PATCH 01/22] Fix the issue with unknown function on uninstalling --- src/Sources/LightPortal/Plugins/HelloPortal/HelloPortal.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Sources/LightPortal/Plugins/HelloPortal/HelloPortal.php b/src/Sources/LightPortal/Plugins/HelloPortal/HelloPortal.php index 551d208e3..55a61dffe 100644 --- a/src/Sources/LightPortal/Plugins/HelloPortal/HelloPortal.php +++ b/src/Sources/LightPortal/Plugins/HelloPortal/HelloPortal.php @@ -8,7 +8,7 @@ * @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later * * @category plugin - * @version 22.12.24 + * @version 19.01.25 */ namespace Bugo\LightPortal\Plugins\HelloPortal; @@ -22,6 +22,7 @@ use Bugo\LightPortal\Plugins\Plugin; use function array_combine; +use function function_exists; use function str_contains; if (! defined('LP_NAME')) @@ -135,6 +136,9 @@ private function getStepData(): string { $this->setTemplate('steps'); + if (! function_exists('getSteps')) + return ''; + $steps = getSteps($this->txt, Config::$modSettings); if ($this->isCurrentArea('lp_settings', 'basic')) From fe78370fbf20121fbf5bbdc37c3e19ed0aec0922 Mon Sep 17 00:00:00 2001 From: Bugo Date: Mon, 20 Jan 2025 10:41:09 +0500 Subject: [PATCH 02/22] Fix the issue with retrieving board moderators from cache --- src/Sources/LightPortal/Enums/Permission.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Sources/LightPortal/Enums/Permission.php b/src/Sources/LightPortal/Enums/Permission.php index eaef5ed12..649c06b8c 100644 --- a/src/Sources/LightPortal/Enums/Permission.php +++ b/src/Sources/LightPortal/Enums/Permission.php @@ -76,7 +76,9 @@ public static function isGroupMember(int $groupId): bool private static function getBoardModerators(): array { - if (($moderators = app(Cache::class)->get('board_moderators')) === null) { + $cache = new Cache(); + + if (($moderators = $cache->get('board_moderators')) === null) { $result = Db::$db->query('', /** @lang text */ ' SELECT id_member FROM {db_prefix}moderators', @@ -88,7 +90,7 @@ private static function getBoardModerators(): array $moderators = array_column($items, 'id_member'); - app(Cache::class)->put('board_moderators', $moderators); + $cache->put('board_moderators', $moderators); } return $moderators; From 08a8d9d96320a8cfd0633410c108b53c99609b64 Mon Sep 17 00:00:00 2001 From: Bugo Date: Tue, 21 Jan 2025 10:58:28 +0500 Subject: [PATCH 03/22] Fix the issue with incorrect description --- src/Sources/LightPortal/Areas/ConfigArea.php | 6 ------ src/Sources/LightPortal/Areas/Configs/BasicConfig.php | 5 +++++ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Sources/LightPortal/Areas/ConfigArea.php b/src/Sources/LightPortal/Areas/ConfigArea.php index 9cd562d40..0d9611b0f 100644 --- a/src/Sources/LightPortal/Areas/ConfigArea.php +++ b/src/Sources/LightPortal/Areas/ConfigArea.php @@ -12,7 +12,6 @@ namespace Bugo\LightPortal\Areas; -use Bugo\Compat\Config; use Bugo\Compat\Db; use Bugo\Compat\Lang; use Bugo\Compat\Theme; @@ -220,11 +219,6 @@ public function adminAreas(array &$areas): void public function helpadmin(): void { - Lang::$txt['lp_standalone_url_help'] = Lang::getTxt('lp_standalone_url_help', [ - Config::$boardurl . '/portal.php', - Config::$scripturl - ]); - Lang::$txt['lp_menu_separate_subsection_title_help'] = Lang::getTxt('lp_menu_separate_subsection_title_help', [ '{lp_pages}', '$txt[`lp_pages`]', diff --git a/src/Sources/LightPortal/Areas/Configs/BasicConfig.php b/src/Sources/LightPortal/Areas/Configs/BasicConfig.php index ea0e05453..537e46735 100644 --- a/src/Sources/LightPortal/Areas/Configs/BasicConfig.php +++ b/src/Sources/LightPortal/Areas/Configs/BasicConfig.php @@ -87,6 +87,11 @@ public function show(): void Utils::$context['session_id'], ); + Lang::$txt['lp_standalone_url_help'] = Lang::getTxt('lp_standalone_url_help', [ + Config::$boardurl . '/portal.php', + Config::$scripturl + ]); + $configVars = [ [ 'select', From 208a9dc7326505e8f11dfd4daf7ad4d7da9aeeea Mon Sep 17 00:00:00 2001 From: Bugo Date: Tue, 21 Jan 2025 11:02:33 +0500 Subject: [PATCH 04/22] Fix the issue with unlinking non-existent files --- src/Sources/LightPortal/Areas/PluginArea.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Sources/LightPortal/Areas/PluginArea.php b/src/Sources/LightPortal/Areas/PluginArea.php index 14d4e6af1..f9c1d4079 100644 --- a/src/Sources/LightPortal/Areas/PluginArea.php +++ b/src/Sources/LightPortal/Areas/PluginArea.php @@ -338,8 +338,8 @@ private function preparedData(): array private function removeAssets(): void { - unlink(Theme::$current->settings['default_theme_dir'] . '/css/light_portal/plugins.css'); - unlink(Theme::$current->settings['default_theme_dir'] . '/scripts/light_portal/plugins.js'); + @unlink(Theme::$current->settings['default_theme_dir'] . '/css/light_portal/plugins.css'); + @unlink(Theme::$current->settings['default_theme_dir'] . '/scripts/light_portal/plugins.js'); } private function extendPluginList(): void From b3487ae7760386e086cdcdb5fb49a21a58d0ca52 Mon Sep 17 00:00:00 2001 From: Bugo Date: Fri, 24 Jan 2025 10:40:35 +0500 Subject: [PATCH 05/22] Refactor code --- src/Sources/LightPortal/Areas/PluginArea.php | 2 + .../Areas/Validators/AbstractValidator.php | 22 ++++++++++ .../Areas/Validators/BaseValidateTrait.php | 16 ++------ .../Areas/Validators/BlockValidator.php | 26 ++++-------- .../Areas/Validators/PageValidator.php | 41 ++++++++----------- src/Sources/LightPortal/Hooks/Actions.php | 3 -- .../LightPortal/Hooks/DefaultAction.php | 12 ++++-- src/Sources/LightPortal/Models/BlockModel.php | 6 ++- src/Sources/LightPortal/Models/PageModel.php | 6 ++- .../DummyArticleCards/langs/english.php | 2 +- .../EhPortalMigration/EhPortalMigration.php | 4 +- .../EzPortalMigration/EzPortalMigration.php | 4 +- .../LightPortal/Plugins/HelloPortal/steps.php | 2 +- .../Plugins/HelloPortal/template.php | 2 +- .../Plugins/PluginMaker/Handler.php | 11 +++-- .../Plugins/PluginMaker/Validator.php | 21 ++++------ .../TinyPortalMigration.php | 8 ++-- src/Sources/LightPortal/PortalApp.php | 32 +++++++++++++++ src/Sources/LightPortal/ServiceProvider.php | 2 + src/Sources/LightPortal/Tasks/Maintainer.php | 1 - .../UI/Partials/EntryTypeSelect.php | 2 +- .../UI/Tables/PageTypeSelectRow.php | 3 +- src/Sources/LightPortal/Utils/Setting.php | 7 +++- src/Sources/LightPortal/app.php | 22 ++-------- src/Sources/LightPortal/composer.json | 4 +- 25 files changed, 143 insertions(+), 118 deletions(-) create mode 100644 src/Sources/LightPortal/PortalApp.php diff --git a/src/Sources/LightPortal/Areas/PluginArea.php b/src/Sources/LightPortal/Areas/PluginArea.php index f9c1d4079..18c5c9224 100644 --- a/src/Sources/LightPortal/Areas/PluginArea.php +++ b/src/Sources/LightPortal/Areas/PluginArea.php @@ -280,6 +280,8 @@ private function preparedData(): array $txtData = [ 'plugins' => Lang::$txt['lp_plugins'], 'apply_filter' => Lang::$txt['apply_filter'], + 'list_view' => Lang::$txt['lp_list_view'], + 'card_view' => Lang::$txt['lp_card_view'], 'all' => Lang::$txt['all'], 'lp_active_only' => Lang::$txt['lp_active_only'], 'lp_plugins_desc' => Lang::$txt['lp_plugins_desc'], diff --git a/src/Sources/LightPortal/Areas/Validators/AbstractValidator.php b/src/Sources/LightPortal/Areas/Validators/AbstractValidator.php index 7351fab9e..d8e5150ce 100644 --- a/src/Sources/LightPortal/Areas/Validators/AbstractValidator.php +++ b/src/Sources/LightPortal/Areas/Validators/AbstractValidator.php @@ -12,7 +12,29 @@ namespace Bugo\LightPortal\Areas\Validators; +use Bugo\Compat\Lang; +use Bugo\Compat\Utils; +use Bugo\LightPortal\Utils\RequestTrait; + abstract class AbstractValidator { + use RequestTrait; + + protected array $errors = []; + abstract public function validate(): array; + + protected function handleErrors(): void + { + if ($this->errors === []) + return; + + $this->request()->put('preview', true); + + Utils::$context['post_errors'] = []; + + foreach ($this->errors as $error) { + Utils::$context['post_errors'][] = Lang::$txt['lp_post_error_' . $error]; + } + } } diff --git a/src/Sources/LightPortal/Areas/Validators/BaseValidateTrait.php b/src/Sources/LightPortal/Areas/Validators/BaseValidateTrait.php index b44b2c883..25032db10 100644 --- a/src/Sources/LightPortal/Areas/Validators/BaseValidateTrait.php +++ b/src/Sources/LightPortal/Areas/Validators/BaseValidateTrait.php @@ -13,7 +13,6 @@ namespace Bugo\LightPortal\Areas\Validators; use Bugo\Compat\Config; -use Bugo\Compat\Lang; use Bugo\Compat\Utils; use Bugo\LightPortal\Utils\RequestTrait; @@ -40,24 +39,15 @@ public function validate(): array return $data; } - private function findErrors(array $data): void + protected function findErrors(array $data): void { - $errors = []; - if ( (Config::$modSettings['userLanguage'] && empty($data['title_' . Config::$language])) || empty($data['title_' . Utils::$context['user']['language']]) ) { - $errors[] = 'no_title'; + $this->errors[] = 'no_title'; } - if ($errors) { - $this->request()->put('preview', true); - Utils::$context['post_errors'] = []; - - foreach ($errors as $error) { - Utils::$context['post_errors'][] = Lang::$txt['lp_post_error_' . $error]; - } - } + $this->handleErrors(); } } diff --git a/src/Sources/LightPortal/Areas/Validators/BlockValidator.php b/src/Sources/LightPortal/Areas/Validators/BlockValidator.php index aadf38dfd..570283f36 100644 --- a/src/Sources/LightPortal/Areas/Validators/BlockValidator.php +++ b/src/Sources/LightPortal/Areas/Validators/BlockValidator.php @@ -12,7 +12,6 @@ namespace Bugo\LightPortal\Areas\Validators; -use Bugo\Compat\Lang; use Bugo\Compat\Utils; use Bugo\LightPortal\Args\ErrorsDataArgs; use Bugo\LightPortal\Args\ParamsArgs; @@ -20,7 +19,6 @@ use Bugo\LightPortal\Enums\VarType; use Bugo\LightPortal\EventManagerFactory; use Bugo\LightPortal\Plugins\Event; -use Bugo\LightPortal\Utils\RequestTrait; use function array_keys; use function array_merge; @@ -29,8 +27,6 @@ class BlockValidator extends AbstractValidator { - use RequestTrait; - protected array $args = [ 'block_id' => FILTER_VALIDATE_INT, 'icon' => FILTER_DEFAULT, @@ -77,12 +73,11 @@ public function validate(): array return [$data, $params]; } - private function findErrors(array $data): void + protected function findErrors(array $data): void { - $errors = []; - - if (empty($data['areas'])) - $errors[] = 'no_areas'; + if (empty($data['areas'])) { + $this->errors[] = 'no_areas'; + } if ( $data['areas'] @@ -90,21 +85,14 @@ private function findErrors(array $data): void 'options' => ['regexp' => '/' . LP_AREAS_PATTERN . '/'] ])) ) { - $errors[] = 'no_valid_areas'; + $this->errors[] = 'no_valid_areas'; } app(EventManagerFactory::class)()->dispatch( PortalHook::findBlockErrors, - new Event(new ErrorsDataArgs($errors, $data)) + new Event(new ErrorsDataArgs($this->errors, $data)) ); - if ($errors) { - $this->request()->put('preview', true); - Utils::$context['post_errors'] = []; - - foreach ($errors as $error) { - Utils::$context['post_errors'][] = Lang::$txt['lp_post_error_' . $error]; - } - } + $this->handleErrors(); } } diff --git a/src/Sources/LightPortal/Areas/Validators/PageValidator.php b/src/Sources/LightPortal/Areas/Validators/PageValidator.php index 2ed609a54..2d5b25176 100644 --- a/src/Sources/LightPortal/Areas/Validators/PageValidator.php +++ b/src/Sources/LightPortal/Areas/Validators/PageValidator.php @@ -14,7 +14,6 @@ use Bugo\Compat\Config; use Bugo\Compat\Db; -use Bugo\Compat\Lang; use Bugo\Compat\Utils; use Bugo\LightPortal\Args\ErrorsDataArgs; use Bugo\LightPortal\Args\ParamsArgs; @@ -22,7 +21,6 @@ use Bugo\LightPortal\Enums\VarType; use Bugo\LightPortal\EventManagerFactory; use Bugo\LightPortal\Plugins\Event; -use Bugo\LightPortal\Utils\RequestTrait; use function array_merge; use function explode; @@ -30,8 +28,6 @@ class PageValidator extends AbstractValidator { - use RequestTrait; - protected array $args = [ 'page_id' => FILTER_VALIDATE_INT, 'category_id' => FILTER_VALIDATE_INT, @@ -82,19 +78,18 @@ public function validate(): array return [$data, $params]; } - private function findErrors(array $data): void + protected function findErrors(array $data): void { - $errors = []; - if ( (Config::$modSettings['userLanguage'] && empty($data['title_' . Config::$language])) || empty($data['title_' . Utils::$context['user']['language']]) ) { - $errors[] = 'no_title'; + $this->errors[] = 'no_title'; } - if (empty($data['slug'])) - $errors[] = 'no_slug'; + if (empty($data['slug'])) { + $this->errors[] = 'no_slug'; + } if ( $data['slug'] @@ -102,25 +97,23 @@ private function findErrors(array $data): void 'options' => ['regexp' => '/' . LP_ALIAS_PATTERN . '/'] ])) ) { - $errors[] = 'no_valid_slug'; + $this->errors[] = 'no_valid_slug'; } - if ($data['slug'] && ! $this->isUnique($data)) - $errors[] = 'no_unique_slug'; - - if (empty($data['content'])) - $errors[] = 'no_content'; + if ($data['slug'] && ! $this->isUnique($data)) { + $this->errors[] = 'no_unique_slug'; + } - app(EventManagerFactory::class)()->dispatch(PortalHook::findPageErrors, new Event(new ErrorsDataArgs($errors, $data))); + if (empty($data['content'])) { + $this->errors[] = 'no_content'; + } - if ($errors) { - $this->request()->put('preview', true); - Utils::$context['post_errors'] = []; + app(EventManagerFactory::class)()->dispatch( + PortalHook::findPageErrors, + new Event(new ErrorsDataArgs($this->errors, $data)) + ); - foreach ($errors as $error) { - Utils::$context['post_errors'][] = Lang::$txt['lp_post_error_' . $error]; - } - } + $this->handleErrors(); } private function isUnique(array $data): bool diff --git a/src/Sources/LightPortal/Hooks/Actions.php b/src/Sources/LightPortal/Hooks/Actions.php index 819769304..ba209af56 100644 --- a/src/Sources/LightPortal/Hooks/Actions.php +++ b/src/Sources/LightPortal/Hooks/Actions.php @@ -13,7 +13,6 @@ namespace Bugo\LightPortal\Hooks; use Bugo\Compat\Config; -use Bugo\Compat\Theme; use Bugo\Compat\User; use Bugo\Compat\Utils; use Bugo\LightPortal\Actions\BoardIndex; @@ -45,8 +44,6 @@ public function __invoke(array &$actions): void $actions[Action::FORUM->value] = [false, [app(BoardIndex::class), 'show']]; - Theme::load(); - if ($this->request()->is(LP_ACTION) && Utils::$context['current_subaction'] === 'categories') { app(Category::class)->show(); } diff --git a/src/Sources/LightPortal/Hooks/DefaultAction.php b/src/Sources/LightPortal/Hooks/DefaultAction.php index aaa04384c..ede35a4b0 100644 --- a/src/Sources/LightPortal/Hooks/DefaultAction.php +++ b/src/Sources/LightPortal/Hooks/DefaultAction.php @@ -13,6 +13,7 @@ namespace Bugo\LightPortal\Hooks; use Bugo\Compat\Config; +use Bugo\LightPortal\Actions\ActionInterface; use Bugo\LightPortal\Actions\BoardIndex; use Bugo\LightPortal\Actions\FrontPage; use Bugo\LightPortal\Actions\Page; @@ -31,15 +32,20 @@ class DefaultAction use RequestTrait; public function __invoke(): mixed + { + return call_user_func([$this->determineAction(), 'show']); + } + + private function determineAction(): ActionInterface { if ($this->request()->isNotEmpty(LP_PAGE_PARAM)) { - return call_user_func([app(Page::class), 'show']); + return app(Page::class); } if (empty(Config::$modSettings['lp_frontpage_mode']) || Setting::isStandaloneMode()) { - return call_user_func([app(BoardIndex::class), 'show']); + return app(BoardIndex::class); } - return call_user_func([app(FrontPage::class), 'show']); + return app(FrontPage::class); } } diff --git a/src/Sources/LightPortal/Models/BlockModel.php b/src/Sources/LightPortal/Models/BlockModel.php index 684579174..46ad8c445 100644 --- a/src/Sources/LightPortal/Models/BlockModel.php +++ b/src/Sources/LightPortal/Models/BlockModel.php @@ -13,6 +13,8 @@ namespace Bugo\LightPortal\Models; use Bugo\Compat\Utils; +use Bugo\LightPortal\Enums\Permission; +use Bugo\LightPortal\Enums\Placement; use Bugo\LightPortal\Enums\Status; use Bugo\LightPortal\Utils\Setting; @@ -63,13 +65,13 @@ public function __construct(array $postData, array $currentBlock) $this->content = $postData['content'] ?? $currentBlock['content'] ?? ''; - $this->placement = $postData['placement'] ?? $currentBlock['placement'] ?? 'top'; + $this->placement = $postData['placement'] ?? $currentBlock['placement'] ?? Placement::TOP->name(); $this->priority = $postData['priority'] ?? $currentBlock['priority'] ?? 0; $this->permissions = $postData['permissions'] ?? $currentBlock['permissions'] - ?? Setting::get('lp_permissions_default', 'int', 2); + ?? Setting::get('lp_permissions_default', 'int', Permission::MEMBER->value); $this->status = $currentBlock['status'] ?? Status::ACTIVE->value; diff --git a/src/Sources/LightPortal/Models/PageModel.php b/src/Sources/LightPortal/Models/PageModel.php index 319c0c525..438ca0a7c 100644 --- a/src/Sources/LightPortal/Models/PageModel.php +++ b/src/Sources/LightPortal/Models/PageModel.php @@ -14,6 +14,8 @@ use Bugo\Compat\User; use Bugo\Compat\Utils; +use Bugo\LightPortal\Enums\EntryType; +use Bugo\LightPortal\Enums\Permission; use Bugo\LightPortal\Enums\Status; use Bugo\LightPortal\Utils\Setting; @@ -76,10 +78,10 @@ public function __construct(array $postData, array $currentPage) $this->type = $postData['type'] ?? $currentPage['type'] ?? 'bbc'; - $this->entryType = $postData['entry_type'] ?? $currentPage['entry_type'] ?? 'default'; + $this->entryType = $postData['entry_type'] ?? $currentPage['entry_type'] ?? EntryType::DEFAULT->name(); $this->permissions = $postData['permissions'] ?? $currentPage['permissions'] - ?? Setting::get('lp_permissions_default', 'int', 2); + ?? Setting::get('lp_permissions_default', 'int', Permission::MEMBER->value); $this->status = $postData['status'] ?? $currentPage['status'] ?? ( diff --git a/src/Sources/LightPortal/Plugins/DummyArticleCards/langs/english.php b/src/Sources/LightPortal/Plugins/DummyArticleCards/langs/english.php index 8f1d0a84e..e3082618e 100644 --- a/src/Sources/LightPortal/Plugins/DummyArticleCards/langs/english.php +++ b/src/Sources/LightPortal/Plugins/DummyArticleCards/langs/english.php @@ -3,5 +3,5 @@ return [ 'description' => 'The plugin generates fake cards on the frontpage, for testing templates.', 'use_lorem_ipsum' => 'Use Lorem Ipsum for cards', - 'keywords' => 'Image keywords (only for Lorem Ipsum)', + 'keywords' => 'Image keywords', ]; diff --git a/src/Sources/LightPortal/Plugins/EhPortalMigration/EhPortalMigration.php b/src/Sources/LightPortal/Plugins/EhPortalMigration/EhPortalMigration.php index 2dc54c5cc..3a3120e42 100644 --- a/src/Sources/LightPortal/Plugins/EhPortalMigration/EhPortalMigration.php +++ b/src/Sources/LightPortal/Plugins/EhPortalMigration/EhPortalMigration.php @@ -8,7 +8,7 @@ * @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later * * @category plugin - * @version 22.12.24 + * @version 23.01.25 */ namespace Bugo\LightPortal\Plugins\EhPortalMigration; @@ -50,7 +50,7 @@ public function updateAdminAreas(Event $e): void public function updateBlockAreas(Event $e): void { - $e->args->areas[self::AREA] = [new BlockImport, 'main']; + $e->args->areas[self::AREA] = [new BlockImport(), 'main']; } public function updatePageAreas(Event $e): void diff --git a/src/Sources/LightPortal/Plugins/EzPortalMigration/EzPortalMigration.php b/src/Sources/LightPortal/Plugins/EzPortalMigration/EzPortalMigration.php index 4de46596b..7ed9d823a 100644 --- a/src/Sources/LightPortal/Plugins/EzPortalMigration/EzPortalMigration.php +++ b/src/Sources/LightPortal/Plugins/EzPortalMigration/EzPortalMigration.php @@ -8,7 +8,7 @@ * @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later * * @category plugin - * @version 22.12.24 + * @version 23.01.25 */ namespace Bugo\LightPortal\Plugins\EzPortalMigration; @@ -46,7 +46,7 @@ public function updateAdminAreas(Event $e): void public function updateBlockAreas(Event $e): void { - $e->args->areas[self::AREA] = [new BlockImport, 'main']; + $e->args->areas[self::AREA] = [new BlockImport(), 'main']; } public function updatePageAreas(Event $e): void diff --git a/src/Sources/LightPortal/Plugins/HelloPortal/steps.php b/src/Sources/LightPortal/Plugins/HelloPortal/steps.php index fad00b904..82a6038b9 100644 --- a/src/Sources/LightPortal/Plugins/HelloPortal/steps.php +++ b/src/Sources/LightPortal/Plugins/HelloPortal/steps.php @@ -1,4 +1,4 @@ - $temp[Language::getFallbackValue()]]; - if ($baseLang !== 'english') + if ($baseLang !== 'english') { Utils::$context['lp_languages'][$baseLang] = $temp[Config::$language]; + } return; } @@ -141,8 +142,9 @@ private function validateData(): void 'options' => Utils::$context['lp_plugin']['options'] ?? [] ]; - if (Utils::$context['lp_plugin']['type'] !== 'block' || Utils::$context['lp_plugin']['icon'] === 'undefined') + if (Utils::$context['lp_plugin']['type'] !== 'block' || Utils::$context['lp_plugin']['icon'] === 'undefined') { Utils::$context['lp_plugin']['icon'] = ''; + } if (! empty($postData['option_name'])) { foreach ($postData['option_name'] as $id => $option) { @@ -169,8 +171,9 @@ private function validateData(): void if (! empty($postData['option_translations'][$lang])) { foreach ($postData['option_translations'][$lang] as $id => $translation) { - if (! empty($translation)) + if (! empty($translation)) { Utils::$context['lp_plugin']['options'][$id]['translations'][$lang] = $translation; + } } } } diff --git a/src/Sources/LightPortal/Plugins/PluginMaker/Validator.php b/src/Sources/LightPortal/Plugins/PluginMaker/Validator.php index 6930ede34..7205abae7 100644 --- a/src/Sources/LightPortal/Plugins/PluginMaker/Validator.php +++ b/src/Sources/LightPortal/Plugins/PluginMaker/Validator.php @@ -8,7 +8,7 @@ * @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later * * @category plugin - * @version 09.01.25 + * @version 24.01.25 */ namespace Bugo\LightPortal\Plugins\PluginMaker; @@ -18,15 +18,12 @@ use Bugo\LightPortal\Areas\Validators\AbstractValidator; use Bugo\LightPortal\Enums\VarType; use Bugo\LightPortal\Lists\PluginList; -use Bugo\LightPortal\Utils\RequestTrait; if (! defined('LP_NAME')) die('No direct access...'); class Validator extends AbstractValidator { - use RequestTrait; - protected array $args = [ 'name' => FILTER_SANITIZE_FULL_SPECIAL_CHARS, 'type' => FILTER_DEFAULT, @@ -83,12 +80,10 @@ public function validate(): array return $data; } - private function findErrors(array $data): void + protected function findErrors(array $data): void { - $errors = []; - if (empty($data['name'])) { - $errors[] = 'no_name'; + $this->errors[] = 'no_name'; } if ( @@ -97,21 +92,21 @@ private function findErrors(array $data): void 'options' => ['regexp' => '/' . LP_ADDON_PATTERN . '/'] ])) ) { - $errors[] = 'no_valid_name'; + $this->errors[] = 'no_valid_name'; } if (! empty($data['name']) && ! $this->isUnique($data['name'])) { - $errors[] = 'no_unique_name'; + $this->errors[] = 'no_unique_name'; } if (empty($data['description_english'])) { - $errors[] = 'no_description'; + $this->errors[] = 'no_description'; } - if (! empty($errors)) { + if (! empty($this->errors)) { Utils::$context['post_errors'] = []; - foreach ($errors as $error) { + foreach ($this->errors as $error) { Utils::$context['post_errors'][] = Lang::$txt['lp_post_error_' . $error] ?? Lang::$txt['lp_plugin_maker'][$error]; } diff --git a/src/Sources/LightPortal/Plugins/TinyPortalMigration/TinyPortalMigration.php b/src/Sources/LightPortal/Plugins/TinyPortalMigration/TinyPortalMigration.php index 9a4cfd8cf..20e121734 100644 --- a/src/Sources/LightPortal/Plugins/TinyPortalMigration/TinyPortalMigration.php +++ b/src/Sources/LightPortal/Plugins/TinyPortalMigration/TinyPortalMigration.php @@ -8,7 +8,7 @@ * @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later * * @category plugin - * @version 22.12.24 + * @version 23.01.25 */ namespace Bugo\LightPortal\Plugins\TinyPortalMigration; @@ -51,17 +51,17 @@ public function updateAdminAreas(Event $e): void public function updateBlockAreas(Event $e): void { - $e->args->areas[self::AREA] = [new BlockImport, 'main']; + $e->args->areas[self::AREA] = [new BlockImport(), 'main']; } public function updatePageAreas(Event $e): void { - $e->args->areas[self::AREA] = [new PageImport, 'main']; + $e->args->areas[self::AREA] = [new PageImport(), 'main']; } public function updateCategoryAreas(Event $e): void { - $e->args->areas[self::AREA] = [new CategoryImport, 'main']; + $e->args->areas[self::AREA] = [new CategoryImport(), 'main']; } public function importPages(Event $e): void diff --git a/src/Sources/LightPortal/PortalApp.php b/src/Sources/LightPortal/PortalApp.php new file mode 100644 index 000000000..e2d1c301d --- /dev/null +++ b/src/Sources/LightPortal/PortalApp.php @@ -0,0 +1,32 @@ + + * @copyright 2019-2025 Bugo + * @license https://spdx.org/licenses/GPL-3.0-or-later.html GPL-3.0-or-later + * + * @version 2.9 + */ + +namespace Bugo\LightPortal; + +use Bugo\LightPortal\Areas\ConfigArea; +use Bugo\LightPortal\Areas\CreditArea; + +if (! defined('SMF')) + die('No direct access...'); + +final class PortalApp +{ + public function __construct() + { + if (SMF === 'BACKGROUND') + return; + + (new Integration())(); + (new ConfigArea())(); + (new CreditArea())(); + } +} diff --git a/src/Sources/LightPortal/ServiceProvider.php b/src/Sources/LightPortal/ServiceProvider.php index 93f79dd68..b129a900f 100644 --- a/src/Sources/LightPortal/ServiceProvider.php +++ b/src/Sources/LightPortal/ServiceProvider.php @@ -68,6 +68,7 @@ class ServiceProvider extends AbstractServiceProvider public function provides(string $id): bool { $services = [ + PortalApp::class, RendererInterface::class, EventManager::class, EventManagerFactory::class, @@ -122,6 +123,7 @@ public function provides(string $id): bool public function register(): void { + $this->getContainer()->add(PortalApp::class); $this->getContainer()->add(RendererInterface::class, Blade::class); $this->getContainer()->add(EventManager::class); diff --git a/src/Sources/LightPortal/Tasks/Maintainer.php b/src/Sources/LightPortal/Tasks/Maintainer.php index 672fa3246..926223606 100644 --- a/src/Sources/LightPortal/Tasks/Maintainer.php +++ b/src/Sources/LightPortal/Tasks/Maintainer.php @@ -14,7 +14,6 @@ use Bugo\Compat\Tasks\BackgroundTask; use Bugo\Compat\Db; - use Bugo\LightPortal\Repositories\CommentRepository; use function array_keys; diff --git a/src/Sources/LightPortal/UI/Partials/EntryTypeSelect.php b/src/Sources/LightPortal/UI/Partials/EntryTypeSelect.php index 0fbea4d08..117067ebb 100644 --- a/src/Sources/LightPortal/UI/Partials/EntryTypeSelect.php +++ b/src/Sources/LightPortal/UI/Partials/EntryTypeSelect.php @@ -31,7 +31,7 @@ public function __invoke(): string $data = []; foreach ($params['data'] as $value => $label) { - if (Utils::$context['user']['is_admin'] === false && $value === 'internal') + if (Utils::$context['user']['is_admin'] === false && $value === EntryType::INTERNAL->name()) continue; $data[] = [ diff --git a/src/Sources/LightPortal/UI/Tables/PageTypeSelectRow.php b/src/Sources/LightPortal/UI/Tables/PageTypeSelectRow.php index 2d326b361..cb187d6c9 100644 --- a/src/Sources/LightPortal/UI/Tables/PageTypeSelectRow.php +++ b/src/Sources/LightPortal/UI/Tables/PageTypeSelectRow.php @@ -16,6 +16,7 @@ use Bugo\Bricks\Tables\RowPosition; use Bugo\Compat\Lang; use Bugo\Compat\Utils; +use Bugo\LightPortal\Enums\EntryType; use Bugo\LightPortal\Utils\Request; use Bugo\LightPortal\Utils\Str; @@ -25,7 +26,7 @@ public static function make(string $value = '', ?string $class = null): static { $types = ''; foreach (Utils::$context['lp_page_types'] as $type => $text) { - if (Utils::$context['user']['is_admin'] === false && $type === 'internal') + if (Utils::$context['user']['is_admin'] === false && $type === EntryType::INTERNAL->name()) continue; $types .= Str::html('option', [ diff --git a/src/Sources/LightPortal/Utils/Setting.php b/src/Sources/LightPortal/Utils/Setting.php index 254fde983..5f32a3e54 100644 --- a/src/Sources/LightPortal/Utils/Setting.php +++ b/src/Sources/LightPortal/Utils/Setting.php @@ -26,7 +26,12 @@ class Setting { - public static function get(string $key, string $type = 'string', mixed $default = null, string $from = 'string'): mixed + public static function get( + string $key, + string $type = 'string', + mixed $default = null, + string $from = 'string' + ): mixed { if (! isset(Config::$modSettings[$key])) { return $default; diff --git a/src/Sources/LightPortal/app.php b/src/Sources/LightPortal/app.php index 50438b8b3..a9eddd6fd 100644 --- a/src/Sources/LightPortal/app.php +++ b/src/Sources/LightPortal/app.php @@ -15,25 +15,8 @@ require_once __DIR__ . '/Libs/autoload.php'; -use Bugo\LightPortal\Areas\ConfigArea; -use Bugo\LightPortal\Areas\CreditArea; use Bugo\LightPortal\Container; -use Bugo\LightPortal\Integration; - -// This is the way -$app = new class { - public function __construct() - { - if (SMF === 'BACKGROUND') - return; - - (new Integration())(); - (new ConfigArea())(); - (new CreditArea())(); - } -}; - -new $app; +use Bugo\LightPortal\PortalApp; // Helper to work with Container function app(string $service, array $params = []): mixed @@ -46,3 +29,6 @@ function app(string $service, array $params = []): mixed return $instance; } + +// This is the way +app(PortalApp::class); diff --git a/src/Sources/LightPortal/composer.json b/src/Sources/LightPortal/composer.json index f70a169a1..18b18f25a 100644 --- a/src/Sources/LightPortal/composer.json +++ b/src/Sources/LightPortal/composer.json @@ -5,8 +5,8 @@ "ext-intl": "*", "ext-simplexml": "*", "ext-zip": "*", - "bugo/fa-php-helper": "^0.4", - "bugo/smf-bricks": "^0.1", + "bugo/fa-php-helper": "^0.5", + "bugo/smf-bricks": "^0.3", "bugo/smf-compat": "^0.2", "doctrine/event-manager": "^2.0", "eftec/bladeone": "^4.13", From 2f9aacdca840a1d0833d7623cf7216be76b2cadf Mon Sep 17 00:00:00 2001 From: Bugo Date: Fri, 24 Jan 2025 14:59:44 +0500 Subject: [PATCH 06/22] Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f3ed2359d..f83e5bd08 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ [![](https://img.shields.io/badge/Demo-Forum-brightgreen.svg)](https://demo.dragomano.ru) [![](https://img.shields.io/badge/Docs-Site-orange.svg)](https://dragomano.github.io/Light-Portal/) -- **Tested on:** 8.1.31, 8.4.1 / MariaDB 11.2.2, PostgreSQL 17.0 +- **Tested on:** 8.2.27 / MariaDB 11.2.2 - **Languages:** Russian, English, Polish, Spanish, French, Turkish, Ukrainian, German, Italian, Portuguese, Greek, Czech, Danish, Dutch, Norwegian, Swedish, Arabic ## Description ([обзор на русском](https://dragomano.ru/mods/light-portal)) From ece643c0969eabb7c8d5dca00326ae4a794db40b Mon Sep 17 00:00:00 2001 From: Bugo Date: Fri, 24 Jan 2025 15:00:15 +0500 Subject: [PATCH 07/22] Update components --- resources/components/BaseButton.svelte | 28 +++++---- .../components/comments/CommentItem.svelte | 37 +++++++----- .../components/comments/CommentList.svelte | 57 +++++++++---------- .../components/comments/Pagination.svelte | 2 +- .../components/comments/ReplyForm.svelte | 4 +- resources/components/globals.d.ts | 11 ++++ .../components/plugins/PluginItem.svelte | 27 ++++----- .../components/plugins/PluginList.svelte | 45 ++++++++------- .../plugins/PluginOptionItem.svelte | 5 +- .../plugins/PluginOptionList.svelte | 6 +- resources/components/types.ts | 35 ++++++++++++ resources/js/app.js | 2 +- resources/js/helpers.js | 9 ++- resources/js/states.svelte.js | 14 +++++ resources/js/stores.js | 26 +-------- 15 files changed, 175 insertions(+), 133 deletions(-) create mode 100644 resources/components/globals.d.ts create mode 100644 resources/components/types.ts create mode 100644 resources/js/states.svelte.js diff --git a/resources/components/BaseButton.svelte b/resources/components/BaseButton.svelte index 297dc4530..b2a889668 100644 --- a/resources/components/BaseButton.svelte +++ b/resources/components/BaseButton.svelte @@ -1,23 +1,21 @@ diff --git a/resources/components/comments/CommentItem.svelte b/resources/components/comments/CommentItem.svelte index 9c725c7de..91f02973e 100644 --- a/resources/components/comments/CommentItem.svelte +++ b/resources/components/comments/CommentItem.svelte @@ -1,22 +1,29 @@ -{#snippet pagination()} - +{#snippet pagination(totalItems, itemsPerPage)} + {/snippet} -{#snippet replies()} - +{#snippet replies(submit)} + {/snippet} diff --git a/resources/components/comments/Pagination.svelte b/resources/components/comments/Pagination.svelte index d23c5eb22..e90c3bff3 100644 --- a/resources/components/comments/Pagination.svelte +++ b/resources/components/comments/Pagination.svelte @@ -2,7 +2,7 @@ import { _ } from 'svelte-i18n'; import Button from '../BaseButton.svelte'; - let { start = 0, totalItems, itemsPerPage, totalVisible = 5 } = $props(); + let { start = $bindable(0), totalItems, itemsPerPage, totalVisible = 5 } = $props(); const showPagination = $derived(Math.ceil(totalItems / itemsPerPage) > 1); const currentPage = $derived(Math.floor(start / itemsPerPage) + 1); diff --git a/resources/components/comments/ReplyForm.svelte b/resources/components/comments/ReplyForm.svelte index a6acc030e..edc7d9039 100644 --- a/resources/components/comments/ReplyForm.svelte +++ b/resources/components/comments/ReplyForm.svelte @@ -1,6 +1,6 @@ -{#if $useUserStore.id} +{#if userState.id}
diff --git a/resources/components/globals.d.ts b/resources/components/globals.d.ts new file mode 100644 index 000000000..f4db15361 --- /dev/null +++ b/resources/components/globals.d.ts @@ -0,0 +1,11 @@ +declare global { + interface Window { + smf_scripturl: string; + smf_default_theme_url: string; + ajax_notification_text: string; + smf_session_id: string; + smf_session_var: string; + } +} + +export {}; diff --git a/resources/components/plugins/PluginItem.svelte b/resources/components/plugins/PluginItem.svelte index 586aca8f3..75bbfd4f4 100644 --- a/resources/components/plugins/PluginItem.svelte +++ b/resources/components/plugins/PluginItem.svelte @@ -1,7 +1,7 @@ -
+

@@ -69,7 +66,7 @@ icon="gear" class={show && 'fa-spin'} data-id={settingsId} - onclick={() => (show = !show)} + onclick={() => show = !show} /> {/if} diff --git a/resources/components/plugins/PluginList.svelte b/resources/components/plugins/PluginList.svelte index 927080bde..4cd0ba84c 100644 --- a/resources/components/plugins/PluginList.svelte +++ b/resources/components/plugins/PluginList.svelte @@ -1,28 +1,31 @@ @@ -33,8 +36,8 @@