diff --git a/_install.php b/_install.php deleted file mode 100644 index dc7be9a..0000000 --- a/_install.php +++ /dev/null @@ -1,34 +0,0 @@ -newVersion( - basename(__DIR__), - dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version') - )) { - return null; - } - - //... - - return true; -} catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); - - return false; -} diff --git a/src/Backend.php b/src/Backend.php new file mode 100644 index 0000000..9830388 --- /dev/null +++ b/src/Backend.php @@ -0,0 +1,56 @@ +auth->check( + dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_CONTENT_ADMIN]), + dcCore::app()->blog->id + ); + + return static::$init; + } + + public static function process(): bool + { + if (!static::$init) { + return false; + } + + dcCore::app()->addBehaviors([ + 'adminPostsActions' => [BackendBehaviors::class, 'adminPostsActions'], + 'adminPagesActions' => [BackendBehaviors::class, 'adminPostsActions'], + 'adminPostHeaders' => [BackendBehaviors::class, 'adminPostHeaders'], + 'adminPageHeaders' => [BackendBehaviors::class, 'adminPostHeaders'], + 'adminPostFormItems' => [BackendBehaviors::class, 'adminPostFormItems'], + 'adminPageFormItems' => [BackendBehaviors::class, 'adminPostFormItems'], + 'adminBeforePostDelete' => [BackendBehaviors::class, 'adminBeforePostDelete'], + 'adminBeforePageDelete' => [BackendBehaviors::class, 'adminBeforePostDelete'], + 'adminAfterPostUpdate' => [BackendBehaviors::class, 'adminAfterPostSave'], + 'adminAfterPageUpdate' => [BackendBehaviors::class, 'adminAfterPostSave'], + 'adminAfterPostCreate' => [BackendBehaviors::class, 'adminAfterPostSave'], + 'adminAfterPageCreate' => [BackendBehaviors::class, 'adminAfterPostSave'], + ]); + + return true; + } +} diff --git a/src/BackendBehaviors.php b/src/BackendBehaviors.php index 886adef..f1f1169 100644 --- a/src/BackendBehaviors.php +++ b/src/BackendBehaviors.php @@ -10,52 +10,35 @@ * @copyright Jean-Christian Denis * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ -if (!defined('DC_CONTEXT_ADMIN')) { - return null; -} +declare(strict_types=1); -# Check plugin version -if (dcCore::app()->getVersion(basename(__DIR__)) != dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version')) { - return null; -} +namespace Dotclear\Plugin\postExpired; -# Check user right -if (!dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([ - dcAuth::PERMISSION_CONTENT_ADMIN, -]), dcCore::app()->blog->id) -) { - return null; -} - -# Admin behaviors -dcCore::app()->addBehaviors([ - 'adminPostsActions' => ['adminBehaviorPostExpired', 'adminPostsActions'], - 'adminPagesActions' => ['adminBehaviorPostExpired', 'adminPostsActions'], - 'adminPostHeaders' => ['adminBehaviorPostExpired', 'adminPostHeaders'], - 'adminPageHeaders' => ['adminBehaviorPostExpired', 'adminPostHeaders'], - 'adminPostFormItems' => ['adminBehaviorPostExpired', 'adminPostFormItems'], - 'adminPageFormItems' => ['adminBehaviorPostExpired', 'adminPostFormItems'], - 'adminBeforePostDelete' => ['adminBehaviorPostExpired', 'adminBeforePostDelete'], - 'adminBeforePageDelete' => ['adminBehaviorPostExpired', 'adminBeforePostDelete'], - 'adminAfterPostUpdate' => ['adminBehaviorPostExpired', 'adminAfterPostSave'], - 'adminAfterPageUpdate' => ['adminBehaviorPostExpired', 'adminAfterPostSave'], - 'adminAfterPostCreate' => ['adminBehaviorPostExpired', 'adminAfterPostSave'], - 'adminAfterPageCreate' => ['adminBehaviorPostExpired', 'adminAfterPostSave'], -]); +use ArrayObject; +use cursor; +use dcCore; +use dcPostsActions; +use dcPage; +use dcRecord; +use Exception; +use dt; +use html; +use form; +use formSelectOption; /** * @ingroup DC_PLUGIN_POSTEXPIRED * @brief Scheduled post change - admin methods. * @since 2.6 */ -class adminBehaviorPostExpired +class BackendBehaviors { /** * Add actions to posts page combo * - * @param dcPostsActionsPage $ap dcPostsActionsPage instance + * @param dcPostsActions $pa dcPostsActions instance */ - public static function adminPostsActions(dcPostsActions $pa) + public static function adminPostsActions(dcPostsActions $pa): void { $pa->addAction( [ @@ -63,7 +46,7 @@ class adminBehaviorPostExpired __('Add expired date') => 'post_expired_add', ], ], - ['adminBehaviorPostExpired', 'callbackAdd'] + [self::class, 'callbackAdd'] ); $pa->addAction( @@ -72,7 +55,7 @@ class adminBehaviorPostExpired __('Remove expired date') => 'post_expired_remove', ], ], - ['adminBehaviorPostExpired', 'callbackRemove'] + [self::class, 'callbackRemove'] ); } @@ -81,9 +64,9 @@ class adminBehaviorPostExpired * * @return string HTML head */ - public static function adminPostHeaders() + public static function adminPostHeaders(): string { - return dcPage::jsModuleLoad(basename(__DIR__) . '/js/postexpired.js'); + return dcPage::jsModuleLoad(My::id() . '/js/backend.js'); } /** @@ -91,19 +74,19 @@ class adminBehaviorPostExpired * * @param ArrayObject $main_items Main items * @param ArrayObject $sidebar_items Sidebar items - * @param record $post Post record or null + * @param ?dcRecord $post Post record or null */ - public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, $post) + public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, ?dcRecord $post): void { if ($post === null) { - return null; + return; } $sidebar_items['post_expired'] = [ 'title' => __('Expired date'), 'items' => self::fieldsPostExpired( - $post->post_type, - $post->post_id + $post->f('post_type'), + (int) $post->f('post_id') ), ]; } @@ -113,7 +96,7 @@ class adminBehaviorPostExpired * * @param integer $post_id Post id */ - public static function adminBeforePostDelete($post_id) + public static function adminBeforePostDelete(int $post_id): void { self::delPostExpired($post_id); } @@ -124,7 +107,7 @@ class adminBehaviorPostExpired * @param cursor $cur Current post cursor * @param integer $post_id Post id */ - public static function adminAfterPostSave(cursor $cur, $post_id) + public static function adminAfterPostSave(cursor $cur, int $post_id): void { self::delPostExpired($post_id); @@ -134,7 +117,7 @@ class adminBehaviorPostExpired || !empty($_POST['post_expired_selected']) || !empty($_POST['post_expired_comment']) || !empty($_POST['post_expired_trackback']))) { - self::setPostExpired($post_id, $_POST); + self::setPostExpired($post_id, new ArrayObject($_POST)); } } @@ -144,7 +127,7 @@ class adminBehaviorPostExpired * @param dcPostsActions $pa dcPostsActions instance * @param ArrayObject $post _POST actions */ - public static function callbackAdd(dcPostsActions $pa, ArrayObject $post) + public static function callbackAdd(dcPostsActions $pa, ArrayObject $post): void { # No entry $posts_ids = $pa->getIDs(); @@ -164,7 +147,7 @@ class adminBehaviorPostExpired self::setPostExpired($post_id, $post); } - dcAdminNotices::addSuccessNotice(__('Expired date added.')); + dcPage::addSuccessNotice(__('Expired date added.')); $pa->redirect(true); # Display form @@ -186,7 +169,7 @@ class adminBehaviorPostExpired '