diff --git a/_define.php b/_define.php index 64508f1..f50f671 100644 --- a/_define.php +++ b/_define.php @@ -14,7 +14,7 @@ 'Ordering category entries', 'Set category entries order', 'Franck Paul', - '4.0', + '4.1', [ 'requires' => [['core', '2.28']], 'permissions' => '', diff --git a/src/FrontendBehaviors.php b/src/FrontendBehaviors.php index 1d853f0..b38abe1 100644 --- a/src/FrontendBehaviors.php +++ b/src/FrontendBehaviors.php @@ -24,7 +24,7 @@ class FrontendBehaviors */ public static function coreBlogBeforeGetPosts(ArrayObject $params): string { - if (App::url()->type == 'category') { + if (App::url()->getType() == 'category') { $settings = My::settings(); if ($settings->active) { $cat_id = App::frontend()->context()->categories->cat_id; @@ -43,6 +43,7 @@ public static function coreBlogBeforeGetPosts(ArrayObject $params): string break; } + switch ($orders[$cat_id]) { case 'asc': case 'title-asc': @@ -56,6 +57,7 @@ public static function coreBlogBeforeGetPosts(ArrayObject $params): string break; } } + $numbers = $settings->numbers; if (is_array($numbers) && array_key_exists($cat_id, $numbers) && $numbers[$cat_id] != '') { // Specific number of entry per page set for the category diff --git a/src/Install.php b/src/Install.php index dd836ca..7b429a2 100644 --- a/src/Install.php +++ b/src/Install.php @@ -39,12 +39,11 @@ public static function process(): bool // Convert oldschool settings Upgrade::settings2array('catorder', 'orders'); } - if (version_compare((string) $old_version, '2.0', '<')) { - // Rename settings namespace - if (App::blog()->settings()->exists('catorder')) { - App::blog()->settings()->delWorkspace(My::id()); - App::blog()->settings()->renWorkspace('catorder', My::id()); - } + + // Rename settings namespace + if (version_compare((string) $old_version, '2.0', '<') && App::blog()->settings()->exists('catorder')) { + App::blog()->settings()->delWorkspace(My::id()); + App::blog()->settings()->renWorkspace('catorder', My::id()); } // Chech if settings exist, create them if not @@ -52,14 +51,16 @@ public static function process(): bool if (!$settings->getGlobal('active')) { $settings->put('active', false, App::blogWorkspace()::NS_BOOL, 'Active', false, true); } + if (!$settings->getGlobal('orders')) { $settings->put('orders', [], App::blogWorkspace()::NS_ARRAY, 'Categories order', false, true); } + if (!$settings->getGlobal('numbers')) { $settings->put('numbers', [], App::blogWorkspace()::NS_ARRAY, 'Categories nb of entries per page', false, true); } - } catch (Exception $e) { - App::error()->add($e->getMessage()); + } catch (Exception $exception) { + App::error()->add($exception->getMessage()); } return true; diff --git a/src/Manage.php b/src/Manage.php index cb5f980..531b2f8 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -49,18 +49,19 @@ public static function process(): bool return false; } - if (!empty($_POST)) { + if ($_POST !== []) { try { $co_active = (bool) $_POST['co_active']; $co_orders = []; if (!empty($_POST['co_order'])) { - for ($i = 0; $i < (is_countable($_POST['co_order']) ? count($_POST['co_order']) : 0); $i++) { + for ($i = 0; $i < (is_countable($_POST['co_order']) ? count($_POST['co_order']) : 0); ++$i) { $co_orders[$_POST['co_catid'][$i]] = $_POST['co_order'][$i]; } } + $co_numbers = []; if (!empty($_POST['co_number'])) { - for ($i = 0; $i < (is_countable($_POST['co_number']) ? count($_POST['co_number']) : 0); $i++) { + for ($i = 0; $i < (is_countable($_POST['co_number']) ? count($_POST['co_number']) : 0); ++$i) { $co_numbers[$_POST['co_catid'][$i]] = $_POST['co_number'][$i]; } } @@ -99,6 +100,7 @@ public static function render(): void if (!is_array($co_orders)) { $co_orders = []; } + if (!is_array($co_numbers)) { $co_numbers = []; } @@ -139,6 +141,7 @@ public static function render(): void ]), ]); } + $block = (new Para(null, 'table')) ->items([ (new Para(null, 'thead'))->items([