From 33b3035e11cdcdd26402d149f032dfa1984f1130 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Fri, 10 Jan 2025 17:20:32 +0100 Subject: [PATCH] add exemple of public post status permission --- img/subscriber.svg | 15 +++++++++++++++ src/My.php | 8 +++++--- src/Prepend.php | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 img/subscriber.svg diff --git a/img/subscriber.svg b/img/subscriber.svg new file mode 100644 index 0000000..c16b6a9 --- /dev/null +++ b/img/subscriber.svg @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file diff --git a/src/My.php b/src/My.php index 32d79f5..9629380 100644 --- a/src/My.php +++ b/src/My.php @@ -21,7 +21,9 @@ use Dotclear\Module\MyPlugin; */ class My extends MyPlugin { - public const POST_READY = -100; - public const POST_PROOFREAD = -110; - public const POST_DRAFT = -120; + public const PERMISSION_SUBSCRIBER = 'subscriber'; + public const POST_SUBSCRIBED = -200; + public const POST_READY = -100; + public const POST_PROOFREAD = -110; + public const POST_DRAFT = -120; } diff --git a/src/Prepend.php b/src/Prepend.php index 2e10fe7..ece6bbe 100644 --- a/src/Prepend.php +++ b/src/Prepend.php @@ -3,6 +3,7 @@ declare(strict_types=1); namespace Dotclear\Plugin\Proofreading; +use ArrayObject; use Dotclear\App; use Dotclear\Core\PostType; use Dotclear\Core\Process; @@ -28,7 +29,11 @@ class Prepend extends Process return false; } - return + // subscirber permission + App::auth()->setPermissionType(My::PERMISSION_SUBSCRIBER, __('Posts subscriber')); + + // posts status + $status = App::status()->post()->set( (new Status(My::POST_DRAFT , My::id() . 'draft', 'Draft', 'Draft (>1)', My::fileURL('img/draft.svg'))), ) @@ -37,7 +42,36 @@ class Prepend extends Process ) && App::status()->post()->set( (new Status(My::POST_READY , My::id() . 'ready', 'Fulfilled', 'Fulfilled (>1)', My::fileURL('img/ready.svg'))), + ) + && App::status()->post()->set( + (new Status(My::POST_SUBSCRIBED , My::id() . 'subscriber', 'Subscription', 'Subscription (>1)', My::fileURL('img/subscriber.svg'))), ); + // tweak frontend + if ($status) { + App::behavior()->addBehaviors([ + 'coreBlogBeforeGetPostsAddingParameters' => self::getPosts(...), + ]); + } + + return $status; + } + + /** + * @param array|ArrayObject $params Parameters + */ + public static function getPosts(ArrayObject $params, string|null $arg = null): void + { + if (App::task()->checkContext('FRONTEND') && App::auth()->check(My::PERMISSION_SUBSCRIBER, App::blog()->id()) === true) { + if (!isset($params['psot_status'])) { + $params['post_status'] = []; + } + if (!is_array($params['post_status'])) { + $params['post_status'] = [$params['post_status']]; + } + + //$params['post_status'][] = App::status()->post()::PUBLISHED; + $params['post_status'][] = My::POST_SUBSCRIBED; + } } }