Compare commits

...

10 Commits

7 changed files with 134 additions and 17 deletions

View File

@ -1,3 +1,12 @@
1.3 - 2023.05.13
* require dotclear 2.26
* some cleaning for dc2.26 stable
1.2 - 2023.04.23
* require dotclear 2.26
* use latest dotclear namespace
* fix nullsafe warnings
1.1 - 2023.03.26 1.1 - 2023.03.26
* require Dotclear 2.26 * require Dotclear 2.26
* use namespace * use namespace

View File

@ -10,7 +10,7 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH') || is_null(dcCore::app()->auth)) {
return null; return null;
} }
@ -18,11 +18,11 @@ $this->registerModule(
'emailOptionnel', 'emailOptionnel',
'Make e-mail address optional in comments', 'Make e-mail address optional in comments',
'Oleksandr Syenchuk, Pierre Van Glabeke, Gvx and Contributors', 'Oleksandr Syenchuk, Pierre Van Glabeke, Gvx and Contributors',
'1.1', '1.3',
[ [
'requires' => [['core', '2.26']], 'requires' => [['core', '2.26']],
'permissions' => dcCore::app()->auth->makePermissions([ 'permissions' => dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_ADMIN, dcCore::app()->auth::PERMISSION_ADMIN,
]), ]),
'type' => 'plugin', 'type' => 'plugin',
'support' => 'http://forum.dotclear.org/viewtopic.php?pid=332948#p332948', 'support' => 'http://forum.dotclear.org/viewtopic.php?pid=332948#p332948',

View File

@ -2,10 +2,10 @@
<modules xmlns:da="http://dotaddict.org/da/"> <modules xmlns:da="http://dotaddict.org/da/">
<module id="emailOptionnel"> <module id="emailOptionnel">
<name>emailOptionnel</name> <name>emailOptionnel</name>
<version>1.1</version> <version>1.3</version>
<author>Oleksandr Syenchuk, Pierre Van Glabeke, Gvx and Contributors</author> <author>Oleksandr Syenchuk, Pierre Van Glabeke, Gvx and Contributors</author>
<desc>Make e-mail address optional in comments</desc> <desc>Make e-mail address optional in comments</desc>
<file>https://github.com/JcDenis/emailOptionnel/releases/download/v1.1/plugin-emailOptionnel.zip</file> <file>https://github.com/JcDenis/emailOptionnel/releases/download/v1.3/plugin-emailOptionnel.zip</file>
<da:dcmin>2.26</da:dcmin> <da:dcmin>2.26</da:dcmin>
<da:details>https://plugins.dotaddict.org/dc2/details/emailOptionnel</da:details> <da:details>https://plugins.dotaddict.org/dc2/details/emailOptionnel</da:details>
<da:support>http://forum.dotclear.org/viewtopic.php?pid=332948#p332948</da:support> <da:support>http://forum.dotclear.org/viewtopic.php?pid=332948#p332948</da:support>

View File

@ -39,13 +39,18 @@ class Backend extends dcNsProcess
} }
dcCore::app()->addBehavior('adminBlogPreferencesFormV2', function (): void { dcCore::app()->addBehavior('adminBlogPreferencesFormV2', function (): void {
// nullsafe PHP < 8.0
if (is_null(dcCore::app()->blog)) {
return;
}
echo echo
'<div class="fieldset">' . '<div class="fieldset">' .
'<h4 id="emailOptionnelParam">' . __('Optional e-mail address') . '</h4>' . '<h4 id="emailOptionnelParam">' . __('Optional e-mail address') . '</h4>' .
(new Para())->items([ (new Para())->__call('items', [[
(new Checkbox(My::SETTING_NAME, (bool) dcCore::app()->blog->settings->get(My::SETTING_NAME)->get('enabled')))->value(1), (new Checkbox(My::SETTING_NAME, (bool) dcCore::app()->blog->settings->get(My::SETTING_NAME)->get('enabled')))->__call('value', [1]),
(new Label(__('Make e-mail address optional in comments'), Label::OUTSIDE_LABEL_AFTER))->for(My::SETTING_NAME)->class('classic'), (new Label(__('Make e-mail address optional in comments'), Label::OUTSIDE_LABEL_AFTER))->__call('for', [My::SETTING_NAME])->__call('class', ['classic']),
])->render() . ]])->render() .
'</div>'; '</div>';
}); });

View File

@ -14,10 +14,11 @@ declare(strict_types=1);
namespace Dotclear\Plugin\emailOptionnel; namespace Dotclear\Plugin\emailOptionnel;
use cursor; use ArrayObject;
use dcCore; use dcCore;
use dcNsProcess; use dcNsProcess;
use dcUtils; use dcUtils;
use Dotclear\Database\Cursor;
class Frontend extends dcNsProcess class Frontend extends dcNsProcess
{ {
@ -36,6 +37,11 @@ class Frontend extends dcNsProcess
dcCore::app()->addBehaviors([ dcCore::app()->addBehaviors([
'publicPrependV2' => function (): void { 'publicPrependV2' => function (): void {
// nullsafe PHP < 8.0
if (is_null(dcCore::app()->blog)) {
return;
}
if (!isset($_POST['c_content']) if (!isset($_POST['c_content'])
|| !empty($_POST['preview']) || !empty($_POST['preview'])
|| !empty($_POST['c_mail']) || !empty($_POST['c_mail'])
@ -45,12 +51,22 @@ class Frontend extends dcNsProcess
} }
$_POST['c_mail'] = My::DEFAULT_EMAIL; $_POST['c_mail'] = My::DEFAULT_EMAIL;
}, },
'publicBeforeCommentCreate' => function (cursor $cur) { 'publicBeforeCommentCreate' => function (Cursor $cur): void {
// nullsafe PHP < 8.0
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->ctx)) {
return;
}
if (dcCore::app()->blog->settings->get(My::SETTING_NAME)->get('enabled') if (dcCore::app()->blog->settings->get(My::SETTING_NAME)->get('enabled')
&& $cur->getField('comment_email') == My::DEFAULT_EMAIL && $cur->getField('comment_email') == My::DEFAULT_EMAIL
) { ) {
# désactive l'affichage du mail dans le template # désactive l'affichage du mail dans le template
dcCore::app()->ctx->comment_preview['mail'] = ''; $cp = dcCore::app()->ctx->__get('comment_preview');
if (is_a($cp, 'ArrayObject')) {
$cp = new ArrayObject([]);
}
$cp['mail'] = '';
dcCore::app()->ctx->__set('comment_preview', $cp);
# n'enregistre pas de mail dans la BDD # n'enregistre pas de mail dans la BDD
$cur->setField('comment_email', ''); $cur->setField('comment_email', '');
# n'enregistre pas le mail dans le cookie # n'enregistre pas le mail dans le cookie
@ -68,7 +84,12 @@ class Frontend extends dcNsProcess
setcookie('comment_info', $c_cookie, strtotime('+3 month'), '/'); setcookie('comment_info', $c_cookie, strtotime('+3 month'), '/');
} }
}, },
'publicHeadContent' => function () { 'publicHeadContent' => function (): void {
// nullsafe PHP < 8.0
if (is_null(dcCore::app()->blog)) {
return;
}
if (dcCore::app()->blog->settings->get(My::SETTING_NAME)->get('enabled')) { if (dcCore::app()->blog->settings->get(My::SETTING_NAME)->get('enabled')) {
echo dcUtils::jsLoad( echo dcUtils::jsLoad(
dcCore::app()->blog->getPF(My::id() . '/js/frontend.js'), dcCore::app()->blog->getPF(My::id() . '/js/frontend.js'),

View File

@ -17,12 +17,12 @@ namespace Dotclear\Plugin\emailOptionnel;
use dcCore; use dcCore;
/** /**
* Plugin definitions * This module definitions.
*/ */
class My extends \initEmailOptionnel class My extends \initEmailOptionnel
{ {
/** /**
* This module id * This module id.
*/ */
public static function id(): string public static function id(): string
{ {
@ -30,10 +30,20 @@ class My extends \initEmailOptionnel
} }
/** /**
* This module name * This module name.
*/ */
public static function name(): string public static function name(): string
{ {
return __((string) dcCore::app()->plugins->moduleInfo(self::id(), 'name')); $name = dcCore::app()->plugins->moduleInfo(self::id(), 'name');
return __(is_string($name) ? $name : self::id());
}
/**
* This module path.
*/
public static function path(): string
{
return dirname(__DIR__);
} }
} }

72
src/Uninstall.php 100644
View File

@ -0,0 +1,72 @@
<?php
/**
* @brief emailOptionnel, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Oleksandr Syenchuk, Pierre Van Glabeke, Gvx and Contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
namespace Dotclear\Plugin\emailOptionnel;
use dcCore;
use dcNsProcess;
use Dotclear\Plugin\Uninstaller\Uninstaller;
class Uninstall extends dcNsProcess
{
public static function init(): bool
{
static::$init = defined('DC_CONTEXT_ADMIN');
return static::$init;
}
public static function process(): bool
{
if (!static::$init || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
return false;
}
Uninstaller::instance()
->addUserAction(
'settings',
'delete_all',
My::SETTING_NAME
)
->addUserAction(
'plugins',
'delete',
My::id()
)
->addUserAction(
'versions',
'delete',
My::id()
)
->addDirectAction(
'settings',
'delete_all',
My::SETTING_NAME
)
->addDirectAction(
'plugins',
'delete',
My::id()
)
->addDirectAction(
'versions',
'delete',
My::id()
)
;
// no custom action
return false;
}
}