code review

This commit is contained in:
Jean-Christian Denis 2023-10-16 22:36:53 +02:00
parent b1f644a8f3
commit ff2e09e743
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
19 changed files with 68 additions and 106 deletions

View file

@ -1,3 +1,9 @@
enhancePostContent 2023.10.16
===========================================================
* Require Dotclear 2.28
* Require PHP 8.1
* Code review
enhancePostContent 2023.10.13 enhancePostContent 2023.10.13
=========================================================== ===========================================================
* Require Dotclear 2.28 * Require Dotclear 2.28

View file

@ -1,7 +1,7 @@
# README # README
[![Release](https://img.shields.io/badge/release-2023.10.13-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/enhancePostContent/releases) [![Release](https://img.shields.io/badge/release-2023.10.16-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/enhancePostContent/releases)
![Date](https://img.shields.io/badge/date-2023.10.13-c44d58.svg) ![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) [![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/enhancePostContent) [![Dotaddict](https://img.shields.io/badge/dotaddict-official-9ac123.svg)](https://plugins.dotaddict.org/dc2/details/enhancePostContent)
[![License](https://img.shields.io/badge/license-GPL--2.0-ececec.svg)](https://git.dotclear.watch/JcDenis/enhancePostContent/src/branch/master/LICENSE) [![License](https://img.shields.io/badge/license-GPL--2.0-ececec.svg)](https://git.dotclear.watch/JcDenis/enhancePostContent/src/branch/master/LICENSE)
@ -14,10 +14,10 @@ _enhancePostContent_ is a plugin for the open-source web publishing software cal
## REQUIREMENTS ## REQUIREMENTS
* admin permissions to set up plugin
* content admin permissions to manage fitlers
* Dotclear 2.28 * Dotclear 2.28
* PHP 8.1+ * PHP 8.1+
* Dotclear admin permissions to set up plugin
* Dotclear content admin permissions to manage fitlers
## USAGE ## USAGE

View file

@ -9,14 +9,13 @@
* Add features to words in post content. * Add features to words in post content.
* *
* @author Jean-Christian Denis * @author 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
*/ */
$this->registerModule( $this->registerModule(
'Enhance post content', 'Enhance post content',
'Add features to words in post content', 'Add features to words in post content',
'Jean-Christian Denis and Contributors', 'Jean-Christian Denis and Contributors',
'2023.10.13', '2023.10.16',
[ [
'type' => 'plugin', 'type' => 'plugin',
'requires' => [['core', '2.28']], 'requires' => [['core', '2.28']],

View file

@ -2,10 +2,10 @@
<modules xmlns:da="http://dotaddict.org/da/"> <modules xmlns:da="http://dotaddict.org/da/">
<module id="enhancePostContent"> <module id="enhancePostContent">
<name>Enhance post content</name> <name>Enhance post content</name>
<version>2023.10.13</version> <version>2023.10.16</version>
<author>Jean-Christian Denis and Contributors</author> <author>Jean-Christian Denis and Contributors</author>
<desc>Add features to words in post content</desc> <desc>Add features to words in post content</desc>
<file>https://git.dotclear.watch/JcDenis/enhancePostContent/releases/download/v2023.10.13/plugin-enhancePostContent.zip</file> <file>https://git.dotclear.watch/JcDenis/enhancePostContent/releases/download/v2023.10.16/plugin-enhancePostContent.zip</file>
<da:dcmin>2.28</da:dcmin> <da:dcmin>2.28</da:dcmin>
<da:details>https://git.dotclear.watch/JcDenis/enhancePostContent/src/branch/master/README.md</da:details> <da:details>https://git.dotclear.watch/JcDenis/enhancePostContent/src/branch/master/README.md</da:details>
<da:support>https://git.dotclear.watch/JcDenis/enhancePostContent/issues</da:support> <da:support>https://git.dotclear.watch/JcDenis/enhancePostContent/issues</da:support>

View file

@ -1,17 +1,10 @@
<?php <?php
/** /**
* @brief enhancePostContent, a plugin for Dotclear 2 * @file
* @brief The plugin enhancePostContent resources
* @ingroup enhancePostContent
* *
* @package Dotclear * @author Jean-Christian Denis
* @subpackage Plugin * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*
* @author Jean-Christian Denis and Contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { \Dotclear\App::backend()->resources()->set('help', 'enhancePostContent', __DIR__ . '/help/help.html');
return;
}
dcCore::app()->resources['help']['enhancePostContent'] = __DIR__ . '/help/help.html';

View file

@ -1,17 +1,10 @@
<?php <?php
/** /**
* @brief enhancePostContent, a plugin for Dotclear 2 * @file
* @brief The plugin enhancePostContent resources
* @ingroup enhancePostContent
* *
* @package Dotclear * @author Jean-Christian Denis
* @subpackage Plugin * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*
* @author Jean-Christian Denis and Contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { \Dotclear\App::backend()->resources()->set('help', 'enhancePostContent', __DIR__ . '/help/help.html');
return;
}
dcCore::app()->resources['help']['enhancePostContent'] = __DIR__ . '/help/help.html';

View file

@ -7,7 +7,6 @@ namespace Dotclear\Plugin\enhancePostContent;
use ArrayObject; use ArrayObject;
use Dotclear\App; use Dotclear\App;
use Dotclear\Core\Backend\Favorites; use Dotclear\Core\Backend\Favorites;
use Dotclear\Core\BlogSettings;
use Dotclear\Core\Process; use Dotclear\Core\Process;
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Checkbox, Checkbox,
@ -19,13 +18,13 @@ use Dotclear\Helper\Html\Form\{
Para, Para,
Text Text
}; };
use Dotclear\Interface\Core\BlogSettingsInterface;
/** /**
* @brief enhancePostContent backend class. * @brief enhancePostContent backend class.
* @ingroup enhancePostContent * @ingroup enhancePostContent
* *
* @author Jean-Christian Denis * @author 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
*/ */
class Backend extends Process class Backend extends Process
@ -55,7 +54,7 @@ class Backend extends Process
]); ]);
}, },
// backend user preference form // backend user preference form
'adminBlogPreferencesFormV2' => function (BlogSettings $blog_settings): void { 'adminBlogPreferencesFormV2' => function (BlogSettingsInterface $blog_settings): void {
$active = (bool) $blog_settings->get(My::id())->get('active'); $active = (bool) $blog_settings->get(My::id())->get('active');
$allowedtplvalues = Epc::blogAllowedTemplateValue(); $allowedtplvalues = Epc::blogAllowedTemplateValue();
$allowedpubpages = Epc::blogAllowedTemplatePage(); $allowedpubpages = Epc::blogAllowedTemplatePage();
@ -121,7 +120,7 @@ class Backend extends Process
->render(); ->render();
}, },
// backend user preference save // backend user preference save
'adminBeforeBlogSettingsUpdate' => function (BlogSettings $blog_settings): void { 'adminBeforeBlogSettingsUpdate' => function (BlogSettingsInterface $blog_settings): void {
$active = !empty($_POST['epc_active']); $active = !empty($_POST['epc_active']);
$allowedtplvalues = Epc::decodeMulti($_POST['epc_allowedtplvalues']); $allowedtplvalues = Epc::decodeMulti($_POST['epc_allowedtplvalues']);
$allowedpubpages = Epc::decodeMulti($_POST['epc_allowedpubpages']); $allowedpubpages = Epc::decodeMulti($_POST['epc_allowedpubpages']);
@ -146,7 +145,7 @@ class Backend extends Process
]; ];
}, },
// widgets registration // widgets registration
'initWidgets' => [Widgets::class, 'initWidgets'], 'initWidgets' => Widgets::initWidgets(...),
]); ]);
return true; return true;

View file

@ -14,11 +14,10 @@ use Dotclear\Helper\Html\Form\Checkbox;
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
/** /**
* @brief enhancePostContent filters list class. * @brief enhancePostContent filters list class.
* @ingroup enhancePostContent * @ingroup enhancePostContent
* *
* @author Jean-Christian Denis * @author 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
*/ */
class BackendList extends Listing class BackendList extends Listing

View file

@ -1,15 +1,5 @@
<?php <?php
/**
* @brief enhancePostContent, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis 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\enhancePostContent; namespace Dotclear\Plugin\enhancePostContent;
@ -32,11 +22,10 @@ __('atom feeds');
__('RSS feeds'); __('RSS feeds');
/** /**
* @brief enhancePostContent main class. * @brief enhancePostContent main class.
* @ingroup enhancePostContent * @ingroup enhancePostContent
* *
* @author Jean-Christian Denis * @author 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
*/ */
class Epc class Epc
@ -128,15 +117,15 @@ class Epc
$list = new ArrayObject([ $list = new ArrayObject([
'entry excerpt' => [ 'entry excerpt' => [
'id' => 'entryexcerpt', 'id' => 'entryexcerpt',
'cb' => [self::class, 'widgetContentEntryExcerpt'], 'cb' => self::widgetContentEntryExcerpt(...),
], ],
'entry content' => [ 'entry content' => [
'id' => 'entrycontent', 'id' => 'entrycontent',
'cb' => [self::class, 'widgetContentEntryContent'], 'cb' => self::widgetContentEntryContent(...),
], ],
'comment content' => [ 'comment content' => [
'id' => 'commentcontent', 'id' => 'commentcontent',
'cb' => [self::class, 'widgetContentCommentContent'], 'cb' => self::widgetContentCommentContent(...),
], ],
]); ]);

View file

@ -10,13 +10,12 @@ use Dotclear\Plugin\widgets\WidgetsElement;
use Exception; use Exception;
/** /**
* @brief enhancePostContent abstract filter class. * @brief enhancePostContent abstract filter class.
* @ingroup enhancePostContent * @ingroup enhancePostContent
* *
* All filter must extends this class. * All filter must extends this class.
* *
* @author Jean-Christian Denis * @author 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
*/ */
abstract class EpcFilter abstract class EpcFilter

View file

@ -5,18 +5,21 @@ declare(strict_types=1);
namespace Dotclear\Plugin\enhancePostContent; namespace Dotclear\Plugin\enhancePostContent;
/** /**
* @brief enhancePostContent filters stack. * @brief enhancePostContent filters stack.
* @ingroup enhancePostContent * @ingroup enhancePostContent
* *
* Use Epc::getFilters() to get loaded stack * Use Epc::getFilters() to get loaded stack
* *
* @author Jean-Christian Denis * @author 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
*/ */
class EpcFilters class EpcFilters
{ {
/** @var array<int,EpcFilter> $satck The filters stack */ /**
* The filters stack.
*
* @var array<int, EpcFilter> $stack
*/
private array $stack = []; private array $stack = [];
/** /**

View file

@ -12,11 +12,10 @@ use Dotclear\Database\{
use Exception; use Exception;
/** /**
* @brief enhancePostContent filters records. * @brief enhancePostContent filters records.
* @ingroup enhancePostContent * @ingroup enhancePostContent
* *
* @author Jean-Christian Denis * @author 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
*/ */
class EpcRecord class EpcRecord

View file

@ -8,11 +8,10 @@ use Dotclear\App;
use Dotclear\Core\Process; use Dotclear\Core\Process;
/** /**
* @brief enhancePostContent frontend class. * @brief enhancePostContent frontend class.
* @ingroup enhancePostContent * @ingroup enhancePostContent
* *
* @author Jean-Christian Denis * @author 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
*/ */
class Frontend extends Process class Frontend extends Process
@ -50,7 +49,7 @@ class Frontend extends Process
} }
}, },
// Widgets // Widgets
'initWidgets' => [Widgets::class, 'initWidgets'], 'initWidgets' => Widgets::initWidgets(...),
]); ]);
return true; return true;

View file

@ -10,11 +10,10 @@ use Dotclear\Database\Structure;
use Exception; use Exception;
/** /**
* @brief enhancePostContent installation class. * @brief enhancePostContent installation class.
* @ingroup enhancePostContent * @ingroup enhancePostContent
* *
* @author Jean-Christian Denis * @author 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
*/ */
class Install extends Process class Install extends Process

View file

@ -1,15 +1,5 @@
<?php <?php
/**
* @brief enhancePostContent, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis 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\enhancePostContent; namespace Dotclear\Plugin\enhancePostContent;
@ -43,11 +33,10 @@ use Dotclear\Helper\Network\Http;
use Exception; use Exception;
/** /**
* @brief enhancePostContent manage class. * @brief enhancePostContent manage class.
* @ingroup enhancePostContent * @ingroup enhancePostContent
* *
* @author Jean-Christian Denis * @author 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
*/ */
class Manage extends Process class Manage extends Process

View file

@ -8,11 +8,10 @@ use Dotclear\App;
use Dotclear\Module\MyPlugin; use Dotclear\Module\MyPlugin;
/** /**
* @brief enhancePostContent My helper. * @brief enhancePostContent My helper.
* @ingroup enhancePostContent * @ingroup enhancePostContent
* *
* @author Jean-Christian Denis * @author 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
*/ */
class My extends MyPlugin class My extends MyPlugin

View file

@ -9,11 +9,10 @@ use Dotclear\Core\Process;
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
/** /**
* @brief enhancePostContent prepend class. * @brief enhancePostContent prepend class.
* @ingroup enhancePostContent * @ingroup enhancePostContent
* *
* @author Jean-Christian Denis * @author 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
*/ */
class Prepend extends Process class Prepend extends Process
@ -30,7 +29,7 @@ class Prepend extends Process
} }
// register epc filters // register epc filters
app::behavior()->addBehavior('enhancePostContentFilters', function (EpcFilters $stack): void { App::behavior()->addBehavior('enhancePostContentFilters', function (EpcFilters $stack): void {
foreach (Epc::DEFAULT_FILTERS as $class) { foreach (Epc::DEFAULT_FILTERS as $class) {
$stack->add(new $class()); $stack->add(new $class());
} }

View file

@ -8,11 +8,10 @@ use Dotclear\Core\Process;
use Dotclear\Plugin\Uninstaller\Uninstaller; use Dotclear\Plugin\Uninstaller\Uninstaller;
/** /**
* @brief enhancePostContent uninstall class. * @brief enhancePostContent uninstall class.
* @ingroup enhancePostContent * @ingroup enhancePostContent
* *
* @author Jean-Christian Denis * @author 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
*/ */
class Uninstall extends Process class Uninstall extends Process

View file

@ -11,11 +11,10 @@ use Dotclear\Plugin\widgets\WidgetsStack;
use Dotclear\Plugin\widgets\WidgetsElement; use Dotclear\Plugin\widgets\WidgetsElement;
/** /**
* @brief enhancePostContent widgets class. * @brief enhancePostContent widgets class.
* @ingroup enhancePostContent * @ingroup enhancePostContent
* *
* @author Jean-Christian Denis * @author 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
*/ */
class Widgets class Widgets
@ -30,7 +29,7 @@ class Widgets
$w->create( $w->create(
'epclist', 'epclist',
My::name(), My::name(),
[self::class, 'parseWidget'], self::parseWidget(...),
null, null,
__('List filtered contents.') __('List filtered contents.')
); );