upgrade to Dotclear 2.28

This commit is contained in:
Jean-Christian Denis 2023-10-16 22:03:02 +02:00
parent 97a50c02b8
commit 1741e80aed
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
8 changed files with 107 additions and 116 deletions

View file

@ -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 emailNotification 1.6 - 2023.08.12
=========================================================== ===========================================================
* Require Dotclear 2.27 * Require Dotclear 2.27

View file

@ -1,24 +1,21 @@
# README # README
[![Release](https://img.shields.io/badge/release-1.6-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/emailNotification/releases) [![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.08.12-c44d58.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.27-137bbb.svg)](https://fr.dotclear.org/download) [![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) [![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 _emailNotification_ is a plugin for the open-source web publishing software called [Dotclear](https://www.dotclear.org).
web publishing software called Dotclear.
It sends email when a new comment is done. > Send email when a new comment is done.
## REQUIREMENTS ## REQUIREMENTS
_Email notification_ requires: * Dotclear 2.28
* PHP 8.1+
* Dotclear 2.27
* PHP 7.4+
* A working mail service * A working mail service
## USAGE ## USAGE
@ -30,13 +27,14 @@ Go to ''user preferences'' => fieldset ''others options'', fill in form.
## LINKS ## LINKS
* License : [GNU GPL v2](https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html) * [License](https://git.dotclear.watch/JcDenis/emailNotification/src/branch/master/LICENSE)
* Source & contribution : [Gitea Page](https://git.dotclear.watch/JcDenis/emailNotification) or [GitHub Page](https://github.com/JcDenis/emailNotification) * [Packages & details](https://git.dotclear.watch/JcDenis/emailNotification/releases) (or on [Dotaddict](https://plugins.dotaddict.org/dc2/details/emailNotification))
* Packages & details : [Gitea Page](https://git.dotclear.watch/JcDenis/emailNotification/releases) or [Dotaddict Page](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 ## CONTRIBUTORS
* Olivier Meunier (author) * Olivier Meunier (author)
* Jean-Christian Denis * Jean-Christian Denis (latest)
You are welcome to contribute to this code. You are welcome to contribute to this code.

View file

@ -1,33 +1,30 @@
<?php <?php
/** /**
* @brief emailNotification, a plugin for Dotclear 2 * @file
* @brief The plugin emailNotification definition
* @ingroup emailNotification
* *
* @package Dotclear * @defgroup emailNotification Plugin emailNotification.
* @subpackage Plugin
* *
* @author Olivier Meunier and contributors * Email notification.
* *
* @copyright Jean-Christian Denis * @author Olivier Meunier (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { declare(strict_types=1);
return null;
}
$this->registerModule( $this->registerModule(
'Email notification', 'Email notification',
'Email notification', 'Email notification',
'Olivier Meunier and contributors', 'Olivier Meunier and contributors',
'1.6', '1.7',
[ [
'requires' => [['core', '2.27']], 'requires' => [['core', '2.28']],
'permissions' => dcCore::app()->auth->makePermissions([ 'permissions' => 'My',
dcCore::app()->auth::PERMISSION_USAGE, 'type' => 'plugin',
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, 'support' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/issues',
]), 'details' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/src/branch/master/README.md',
'type' => 'plugin', 'repository' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/raw/branch/master/dcstore.xml',
'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',
] ]
); );

View file

@ -2,11 +2,11 @@
<modules xmlns:da="http://dotaddict.org/da/"> <modules xmlns:da="http://dotaddict.org/da/">
<module id="emailNotification"> <module id="emailNotification">
<name>Email notification</name> <name>Email notification</name>
<version>1.6</version> <version>1.7</version>
<author>Olivier Meunier and contributors</author> <author>Olivier Meunier and contributors</author>
<desc>Email notification</desc> <desc>Email notification</desc>
<file>https://git.dotclear.watch/JcDenis/emailNotification/releases/download/v1.6/plugin-emailNotification.zip</file> <file>https://git.dotclear.watch/JcDenis/emailNotification/releases/download/v1.7/plugin-emailNotification.zip</file>
<da:dcmin>2.27</da:dcmin> <da:dcmin>2.28</da:dcmin>
<da:details>https://git.dotclear.watch/JcDenis/emailNotification/src/branch/master/README.md</da:details> <da:details>https://git.dotclear.watch/JcDenis/emailNotification/src/branch/master/README.md</da:details>
<da:support>https://git.dotclear.watch/JcDenis/emailNotification/issues</da:support> <da:support>https://git.dotclear.watch/JcDenis/emailNotification/issues</da:support>
</module> </module>

View file

@ -1,22 +1,20 @@
<?php <?php
/**
* @brief emailNotification, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Olivier Meunier and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\emailNotification; namespace Dotclear\Plugin\emailNotification;
use dcCore; use Dotclear\App;
use Dotclear\Core\Process; use Dotclear\Core\Process;
/**
* @brief emailNotification backend class.
* @ingroup emailNotification
*
* @author Olivier Meunier (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Backend extends Process class Backend extends Process
{ {
public static function init(): bool public static function init(): bool
@ -30,11 +28,11 @@ class Backend extends Process
return false; return false;
} }
dcCore::app()->addBehaviors([ App::behavior()->addBehaviors([
'adminPreferencesFormV2' => [BackendBehaviors::class, 'adminUserForm'], 'adminPreferencesFormV2' => BackendBehaviors::adminUserForm(...),
'adminUserForm' => [BackendBehaviors::class, 'adminUserForm'], 'adminUserForm' => BackendBehaviors::adminUserForm(...),
'adminBeforeUserUpdate' => [BackendBehaviors::class, 'adminBeforeUserUpdate'], 'adminBeforeUserUpdate' => BackendBehaviors::adminBeforeUserUpdate(...),
'adminBeforeUserOptionsUpdate' => [BackendBehaviors::class, 'adminBeforeUserUpdate'], 'adminBeforeUserOptionsUpdate' => BackendBehaviors::adminBeforeUserUpdate(...),
]); ]);
return true; return true;

View file

@ -1,20 +1,10 @@
<?php <?php
/**
* @brief emailNotification, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Olivier Meunier and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\emailNotification; namespace Dotclear\Plugin\emailNotification;
use dcCore; use Dotclear\App;
use Dotclear\Database\Cursor; use Dotclear\Database\Cursor;
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Label, Label,
@ -22,11 +12,19 @@ use Dotclear\Helper\Html\Form\{
Select Select
}; };
/**
* @brief emailNotification backend behaviors.
* @ingroup emailNotification
*
* @author Olivier Meunier (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class BackendBehaviors class BackendBehaviors
{ {
public static function adminUserForm(): void public static function adminUserForm(): void
{ {
$options = dcCore::app()->auth->getOptions(); $options = App::auth()->getOptions();
echo echo
'<div class="fieldset"><h5>' . __('Email notification') . '</h5>' . '<div class="fieldset"><h5>' . __('Email notification') . '</h5>' .

View file

@ -1,22 +1,10 @@
<?php <?php
/**
* @brief emailNotification, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Olivier Meunier and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\emailNotification; namespace Dotclear\Plugin\emailNotification;
use dcAuth; use Dotclear\App;
use dcBlog;
use dcCore;
use Dotclear\Core\Process; use Dotclear\Core\Process;
use Dotclear\Database\{ use Dotclear\Database\{
Cursor, Cursor,
@ -28,8 +16,16 @@ use Dotclear\Database\Statement\{
}; };
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
use Dotclear\Helper\Network\Mail\Mail; use Dotclear\Helper\Network\Mail\Mail;
use rsExtUser; use Dotclear\Schema\Extension\User;
/**
* @brief emailNotification frontend class.
* @ingroup emailNotification
*
* @author Olivier Meunier (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Frontend extends Process class Frontend extends Process
{ {
public static function init(): bool public static function init(): bool
@ -43,25 +39,24 @@ class Frontend extends Process
return false; return false;
} }
dcCore::app()->addBehavior('publicAfterCommentCreate', function (Cursor $cur, ?int $comment_id): void { App::behavior()->addBehavior('publicAfterCommentCreate', function (Cursor $cur, ?int $comment_id): void {
// nullsafe PHP < 8.0 if (!App::blog()->isDefined()) {
if (is_null(dcCore::app()->blog)) {
return; return;
} }
// We don't want notification for spam // 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; return;
} }
// Information on comment author and post author // 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()) { if (is_null($rs) || $rs->isEmpty()) {
return; return;
} }
$sql = new SelectStatement(); $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([ ->columns([
'U.user_id as user_id', 'U.user_id as user_id',
'user_email', 'user_email',
@ -69,11 +64,11 @@ class Frontend extends Process
]) ])
->join( ->join(
(new JoinStatement()) (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') ->on('U.user_id = P.user_id')
->statement() ->statement()
) )
->where('blog_id = ' . $sql->quote(dcCore::app()->blog->id)) ->where('blog_id = ' . $sql->quote(App::blog()->id()))
->union( ->union(
(new SelectStatement()) (new SelectStatement())
->columns([ ->columns([
@ -81,7 +76,7 @@ class Frontend extends Process
'user_email', 'user_email',
'user_options', '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') ->where('user_super = 1')
->statement() ->statement()
) )
@ -98,7 +93,7 @@ class Frontend extends Process
continue; continue;
} }
$o = rsExtUser::options($users); $o = User::options($users);
$notification_pref = is_array($o) && isset($o['notify_comments']) ? $o['notify_comments'] : null; $notification_pref = is_array($o) && isset($o['notify_comments']) ? $o['notify_comments'] : null;
unset($o); unset($o);
@ -114,23 +109,23 @@ class Frontend extends Process
'Reply-To: ' . $rs->f('comment_email'), 'Reply-To: ' . $rs->f('comment_email'),
'Content-Type: text/plain; charset=UTF-8;', 'Content-Type: text/plain; charset=UTF-8;',
'X-Mailer: Dotclear', 'X-Mailer: Dotclear',
'X-Blog-Id: ' . Mail::B64Header(dcCore::app()->blog->id), 'X-Blog-Id: ' . Mail::B64Header(App::blog()->id()),
'X-Blog-Name: ' . Mail::B64Header(dcCore::app()->blog->name), 'X-Blog-Name: ' . Mail::B64Header(App::blog()->name()),
'X-Blog-Url: ' . Mail::B64Header(dcCore::app()->blog->url), '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); $subject = Mail::B64Header($subject);
$msg = preg_replace('%</p>\s*<p>%msu', "\n\n", $rs->f('comment_content')); $msg = preg_replace('%</p>\s*<p>%msu', "\n\n", $rs->f('comment_content'));
$msg = Html::clean($msg); $msg = Html::clean($msg);
$msg = html_entity_decode($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'); $status = __('published');
} elseif ((int) $cur->getField('comment_status') == dcBlog::COMMENT_UNPUBLISHED) { } elseif ((int) $cur->getField('comment_status') == App::blog()::COMMENT_UNPUBLISHED) {
$status = __('unpublished'); $status = __('unpublished');
} elseif ((int) $cur->getField('comment_status') == dcBlog::COMMENT_PENDING) { } elseif ((int) $cur->getField('comment_status') == App::blog()::COMMENT_PENDING) {
$status = __('pending'); $status = __('pending');
} else { } else {
// unknown status // unknown status
@ -138,21 +133,21 @@ class Frontend extends Process
} }
$msg .= "\n\n-- \n" . $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(__('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(__('Comment by: %s <%s>'), $rs->f('comment_author'), $rs->f('comment_email')) . "\n" .
sprintf(__('Website: %s'), $rs->getAuthorURL()) . "\n" . sprintf(__('Website: %s'), $rs->getAuthorURL()) . "\n" .
sprintf(__('Comment status: %s'), $status) . "\n" . sprintf(__('Comment status: %s'), $status) . "\n" .
sprintf(__('Edit this comment: <%s>'), DC_ADMIN_URL . sprintf(__('Edit this comment: <%s>'), App::config()->adminUrl() .
((substr(DC_ADMIN_URL, -1) != '/') ? '/' : '') . ((substr(App::config()->adminUrl(), -1) != '/') ? '/' : '') .
'comment.php?id=' . $cur->getField('comment_id') . '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.'); __('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; $msg = __('You received a new comment on your blog:') . "\n\n" . $msg;
// --BEHAVIOR-- emailNotificationAppendToEmail -- Cursor // --BEHAVIOR-- emailNotificationAppendToEmail -- Cursor
$msg .= dcCore::app()->callBehavior('emailNotificationAppendToEmail', $cur); $msg .= App::behavior()->callBehavior('emailNotificationAppendToEmail', $cur);
foreach ($ulist as $email) { foreach ($ulist as $email) {
$h = array_merge(['From: ' . $email], $headers); $h = array_merge(['From: ' . $email], $headers);

View file

@ -1,21 +1,20 @@
<?php <?php
/**
* @brief emailNotification, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Olivier Meunier and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\emailNotification; namespace Dotclear\Plugin\emailNotification;
use Dotclear\Module\MyPlugin; use Dotclear\Module\MyPlugin;
/**
* @brief emailNotification My helper.
* @ingroup emailNotification
*
* @author Olivier Meunier (author)
* @author Jean-Christian Denis (latest)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class My extends MyPlugin class My extends MyPlugin
{ {
// Use default permissions
} }