From 1741e80aedfebfe08172fee5f00108f9506d3da0 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Mon, 16 Oct 2023 22:03:02 +0200 Subject: [PATCH] upgrade to Dotclear 2.28 --- CHANGELOG.md | 6 ++++ README.md | 30 ++++++++--------- _define.php | 35 ++++++++++---------- dcstore.xml | 6 ++-- src/Backend.php | 32 +++++++++---------- src/BackendBehaviors.php | 24 +++++++------- src/Frontend.php | 69 +++++++++++++++++++--------------------- src/My.php | 21 ++++++------ 8 files changed, 107 insertions(+), 116 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b8ea94..7309569 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +emailNotification 1.7 - 2023.10.16 +=========================================================== +* Require Dotclear 2.28 +* Require PHP 8.1 +* Upgrade to Dotclear 2.28 + emailNotification 1.6 - 2023.08.12 =========================================================== * Require Dotclear 2.27 diff --git a/README.md b/README.md index 5d36cac..a467011 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,21 @@ # README -[![Release](https://img.shields.io/badge/release-1.6-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/emailNotification/releases) -[![Date](https://img.shields.io/badge/date-2023.08.12-c44d58.svg)](https://git.dotclear.watch/JcDenis/emailNotification/releases) -[![Dotclear](https://img.shields.io/badge/dotclear-v2.27-137bbb.svg)](https://fr.dotclear.org/download) +[![Release](https://img.shields.io/badge/release-1.7-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/emailNotification/releases) +![Date](https://img.shields.io/badge/date-2023.10.16-c44d58.svg) +[![Dotclear](https://img.shields.io/badge/dotclear-v2.28-137bbb.svg)](https://fr.dotclear.org/download) [![Dotaddict](https://img.shields.io/badge/dotaddict-official-9ac123.svg)](https://plugins.dotaddict.org/dc2/details/emailNotification) -[![License](https://img.shields.io/github/license/JcDenis/emailNotification)](https://git.dotclear.watch/JcDenis/emailNotification/blob/master/LICENSE) +[![License](https://img.shields.io/badge/license-GPL--2.0-ececec.svg)](https://git.dotclear.watch/JcDenis/emailNotification/src/branch/master/LICENSE) -## WHAT IS EMAILNOTIFICATION ? +## ABOUT -_Email notification_ is a plugin for the open-source -web publishing software called Dotclear. +_emailNotification_ is a plugin for the open-source web publishing software called [Dotclear](https://www.dotclear.org). -It sends email when a new comment is done. +> Send email when a new comment is done. ## REQUIREMENTS -_Email notification_ requires: - -* Dotclear 2.27 -* PHP 7.4+ +* Dotclear 2.28 +* PHP 8.1+ * A working mail service ## USAGE @@ -30,13 +27,14 @@ Go to ''user preferences'' => fieldset ''others options'', fill in form. ## LINKS -* License : [GNU GPL v2](https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html) -* Source & contribution : [Gitea Page](https://git.dotclear.watch/JcDenis/emailNotification) or [GitHub Page](https://github.com/JcDenis/emailNotification) -* Packages & details : [Gitea Page](https://git.dotclear.watch/JcDenis/emailNotification/releases) or [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/emailNotification) +* [License](https://git.dotclear.watch/JcDenis/emailNotification/src/branch/master/LICENSE) +* [Packages & details](https://git.dotclear.watch/JcDenis/emailNotification/releases) (or on [Dotaddict](https://plugins.dotaddict.org/dc2/details/emailNotification)) +* [Sources & contributions](https://git.dotclear.watch/JcDenis/emailNotification) (or on [GitHub](https://github.com/JcDenis/emailNotification)) +* [Issues & security](https://git.dotclear.watch/JcDenis/emailNotification/issues) (or on [GitHub](https://github.com/JcDenis/emailNotification/issues)) ## CONTRIBUTORS * Olivier Meunier (author) -* Jean-Christian Denis +* Jean-Christian Denis (latest) You are welcome to contribute to this code. diff --git a/_define.php b/_define.php index 0865321..faced8a 100644 --- a/_define.php +++ b/_define.php @@ -1,33 +1,30 @@ registerModule( 'Email notification', 'Email notification', 'Olivier Meunier and contributors', - '1.6', + '1.7', [ - 'requires' => [['core', '2.27']], - 'permissions' => dcCore::app()->auth->makePermissions([ - dcCore::app()->auth::PERMISSION_USAGE, - dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, - ]), - 'type' => 'plugin', - 'support' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/issues', - 'details' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/src/branch/master/README.md', - 'repository' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/raw/branch/master/dcstore.xml', + 'requires' => [['core', '2.28']], + 'permissions' => 'My', + 'type' => 'plugin', + 'support' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/issues', + 'details' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/src/branch/master/README.md', + 'repository' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/raw/branch/master/dcstore.xml', ] ); diff --git a/dcstore.xml b/dcstore.xml index c73b246..d76b590 100644 --- a/dcstore.xml +++ b/dcstore.xml @@ -2,11 +2,11 @@ Email notification - 1.6 + 1.7 Olivier Meunier and contributors Email notification - https://git.dotclear.watch/JcDenis/emailNotification/releases/download/v1.6/plugin-emailNotification.zip - 2.27 + https://git.dotclear.watch/JcDenis/emailNotification/releases/download/v1.7/plugin-emailNotification.zip + 2.28 https://git.dotclear.watch/JcDenis/emailNotification/src/branch/master/README.md https://git.dotclear.watch/JcDenis/emailNotification/issues diff --git a/src/Backend.php b/src/Backend.php index 2bd4c10..ca10d26 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -1,22 +1,20 @@ addBehaviors([ - 'adminPreferencesFormV2' => [BackendBehaviors::class, 'adminUserForm'], - 'adminUserForm' => [BackendBehaviors::class, 'adminUserForm'], - 'adminBeforeUserUpdate' => [BackendBehaviors::class, 'adminBeforeUserUpdate'], - 'adminBeforeUserOptionsUpdate' => [BackendBehaviors::class, 'adminBeforeUserUpdate'], + App::behavior()->addBehaviors([ + 'adminPreferencesFormV2' => BackendBehaviors::adminUserForm(...), + 'adminUserForm' => BackendBehaviors::adminUserForm(...), + 'adminBeforeUserUpdate' => BackendBehaviors::adminBeforeUserUpdate(...), + 'adminBeforeUserOptionsUpdate' => BackendBehaviors::adminBeforeUserUpdate(...), ]); return true; diff --git a/src/BackendBehaviors.php b/src/BackendBehaviors.php index 6e870c8..d9dfa79 100644 --- a/src/BackendBehaviors.php +++ b/src/BackendBehaviors.php @@ -1,20 +1,10 @@ auth->getOptions(); + $options = App::auth()->getOptions(); echo '
' . __('Email notification') . '
' . diff --git a/src/Frontend.php b/src/Frontend.php index c3dbb4b..408932c 100644 --- a/src/Frontend.php +++ b/src/Frontend.php @@ -1,22 +1,10 @@ addBehavior('publicAfterCommentCreate', function (Cursor $cur, ?int $comment_id): void { - // nullsafe PHP < 8.0 - if (is_null(dcCore::app()->blog)) { + App::behavior()->addBehavior('publicAfterCommentCreate', function (Cursor $cur, ?int $comment_id): void { + if (!App::blog()->isDefined()) { return; } // We don't want notification for spam - if ((int) $cur->getField('comment_status') == dcBlog::COMMENT_JUNK) { + if ((int) $cur->getField('comment_status') == App::blog()::COMMENT_JUNK) { return; } // Information on comment author and post author - $rs = dcCore::app()->auth->sudo([dcCore::app()->blog, 'getComments'], ['comment_id' => $comment_id]); + $rs = App::auth()->sudo(App::blog()->getComments(...), ['comment_id' => $comment_id]); if (is_null($rs) || $rs->isEmpty()) { return; } $sql = new SelectStatement(); - $users = $sql->from($sql->as(dcCore::app()->blog->prefix . dcAuth::USER_TABLE_NAME, 'U')) + $users = $sql->from($sql->as(App::con()->prefix() . App::auth()::USER_TABLE_NAME, 'U')) ->columns([ 'U.user_id as user_id', 'user_email', @@ -69,11 +64,11 @@ class Frontend extends Process ]) ->join( (new JoinStatement()) - ->from($sql->as(dcCore::app()->blog->prefix . dcAuth::PERMISSIONS_TABLE_NAME, 'P')) + ->from($sql->as(App::con()->prefix() . App::auth()::PERMISSIONS_TABLE_NAME, 'P')) ->on('U.user_id = P.user_id') ->statement() ) - ->where('blog_id = ' . $sql->quote(dcCore::app()->blog->id)) + ->where('blog_id = ' . $sql->quote(App::blog()->id())) ->union( (new SelectStatement()) ->columns([ @@ -81,7 +76,7 @@ class Frontend extends Process 'user_email', 'user_options', ]) - ->from($sql->as(dcCore::app()->blog->prefix . dcAuth::USER_TABLE_NAME, 'U')) + ->from($sql->as(App::con()->prefix() . App::auth()::USER_TABLE_NAME, 'U')) ->where('user_super = 1') ->statement() ) @@ -98,7 +93,7 @@ class Frontend extends Process continue; } - $o = rsExtUser::options($users); + $o = User::options($users); $notification_pref = is_array($o) && isset($o['notify_comments']) ? $o['notify_comments'] : null; unset($o); @@ -114,23 +109,23 @@ class Frontend extends Process 'Reply-To: ' . $rs->f('comment_email'), 'Content-Type: text/plain; charset=UTF-8;', 'X-Mailer: Dotclear', - 'X-Blog-Id: ' . Mail::B64Header(dcCore::app()->blog->id), - 'X-Blog-Name: ' . Mail::B64Header(dcCore::app()->blog->name), - 'X-Blog-Url: ' . Mail::B64Header(dcCore::app()->blog->url), + 'X-Blog-Id: ' . Mail::B64Header(App::blog()->id()), + 'X-Blog-Name: ' . Mail::B64Header(App::blog()->name()), + 'X-Blog-Url: ' . Mail::B64Header(App::blog()->url()), ]; - $subject = '[' . dcCore::app()->blog->name . '] ' . sprintf(__('"%s" - New comment'), $rs->f('post_title')); + $subject = '[' . App::blog()->name() . '] ' . sprintf(__('"%s" - New comment'), $rs->f('post_title')); $subject = Mail::B64Header($subject); $msg = preg_replace('%

\s*

%msu', "\n\n", $rs->f('comment_content')); $msg = Html::clean($msg); $msg = html_entity_decode($msg); - if ((int) $cur->getField('comment_status') == dcBlog::COMMENT_PUBLISHED) { + if ((int) $cur->getField('comment_status') == App::blog()::COMMENT_PUBLISHED) { $status = __('published'); - } elseif ((int) $cur->getField('comment_status') == dcBlog::COMMENT_UNPUBLISHED) { + } elseif ((int) $cur->getField('comment_status') == App::blog()::COMMENT_UNPUBLISHED) { $status = __('unpublished'); - } elseif ((int) $cur->getField('comment_status') == dcBlog::COMMENT_PENDING) { + } elseif ((int) $cur->getField('comment_status') == App::blog()::COMMENT_PENDING) { $status = __('pending'); } else { // unknown status @@ -138,21 +133,21 @@ class Frontend extends Process } $msg .= "\n\n-- \n" . - sprintf(__('Blog: %s'), dcCore::app()->blog->name) . "\n" . + sprintf(__('Blog: %s'), App::blog()->name()) . "\n" . sprintf(__('Entry: %s <%s>'), $rs->f('post_title'), $rs->getPostURL()) . "\n" . sprintf(__('Comment by: %s <%s>'), $rs->f('comment_author'), $rs->f('comment_email')) . "\n" . sprintf(__('Website: %s'), $rs->getAuthorURL()) . "\n" . sprintf(__('Comment status: %s'), $status) . "\n" . - sprintf(__('Edit this comment: <%s>'), DC_ADMIN_URL . - ((substr(DC_ADMIN_URL, -1) != '/') ? '/' : '') . + sprintf(__('Edit this comment: <%s>'), App::config()->adminUrl() . + ((substr(App::config()->adminUrl(), -1) != '/') ? '/' : '') . 'comment.php?id=' . $cur->getField('comment_id') . - '&switchblog=' . dcCore::app()->blog->id) . "\n" . + '&switchblog=' . App::blog()->id()) . "\n" . __('You must log in on the backend before clicking on this link to go directly to the comment.'); $msg = __('You received a new comment on your blog:') . "\n\n" . $msg; // --BEHAVIOR-- emailNotificationAppendToEmail -- Cursor - $msg .= dcCore::app()->callBehavior('emailNotificationAppendToEmail', $cur); + $msg .= App::behavior()->callBehavior('emailNotificationAppendToEmail', $cur); foreach ($ulist as $email) { $h = array_merge(['From: ' . $email], $headers); diff --git a/src/My.php b/src/My.php index 6ffabdc..6d8ca30 100644 --- a/src/My.php +++ b/src/My.php @@ -1,21 +1,20 @@