cosmetic nullsafe fix

This commit is contained in:
Jean-Christian Denis 2023-04-21 01:04:36 +02:00
parent 724aa79291
commit 07328d6acd
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
2 changed files with 29 additions and 3 deletions

View file

@ -39,6 +39,11 @@ 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>' .

View file

@ -14,6 +14,7 @@ declare(strict_types=1);
namespace Dotclear\Plugin\emailOptionnel; namespace Dotclear\Plugin\emailOptionnel;
use ArrayObject;
use cursor; use cursor;
use dcCore; use dcCore;
use dcNsProcess; use 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'),