diff --git a/src/Backend.php b/src/Backend.php index 9b33927..93b6826 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -7,11 +7,35 @@ * * @author Fran6t, Pierre Van Glabeke and Contributors * - * @copyright Jean-Crhistian Denis + * @copyright Jean-Christian Denis * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ -if (!defined('DC_CONTEXT_ADMIN')) { - return; -} +declare(strict_types=1); -require __DIR__ . '/_widgets.php'; +namespace Dotclear\Plugin\bloganniv; + +use dcCore; +use dcNsProcess; + +class Backend extends dcNsProcess +{ + public static function init(): bool + { + static::$init = defined('DC_CONTEXT_ADMIN') && My::phpCompliant(); + + return static::$init; + } + + public static function process(): bool + { + if (!static::$init) { + return false; + } + + dcCore::app()->addBehaviors([ + 'initWidgets' => [Widgets::class, 'initWidgets'], + ]); + + return true; + } +} diff --git a/src/Frontend.php b/src/Frontend.php index 209018d..6488fcd 100644 --- a/src/Frontend.php +++ b/src/Frontend.php @@ -7,11 +7,35 @@ * * @author Fran6t, Pierre Van Glabeke and Contributors * - * @copyright Jean-Crhistian Denis + * @copyright Jean-Christian Denis * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ -if (!defined('DC_RC_PATH')) { - return null; -} +declare(strict_types=1); -require __DIR__ . '/_widgets.php'; +namespace Dotclear\Plugin\bloganniv; + +use dcCore; +use dcNsProcess; + +class Frontend extends dcNsProcess +{ + public static function init(): bool + { + static::$init = My::phpCompliant(); + + return static::$init; + } + + public static function process(): bool + { + if (!static::$init) { + return false; + } + + dcCore::app()->addBehaviors([ + 'initWidgets' => [Widgets::class, 'initWidgets'], + ]); + + return true; + } +} diff --git a/src/My.php b/src/My.php new file mode 100644 index 0000000..d655bb6 --- /dev/null +++ b/src/My.php @@ -0,0 +1,50 @@ +plugins->moduleInfo(self::id(), 'name')); + } + + /** + * Check php version + */ + public static function phpCompliant(): bool + { + return version_compare(phpversion(), self::PHP_MIN, '>='); + } +} diff --git a/src/Widgets.php b/src/Widgets.php index 313634b..357c9ea 100644 --- a/src/Widgets.php +++ b/src/Widgets.php @@ -7,23 +7,26 @@ * * @author Fran6t, Pierre Van Glabeke and Contributors * - * @copyright Jean-Crhistian Denis + * @copyright Jean-Christian Denis * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ -if (!defined('DC_RC_PATH')) { - return null; -} +declare(strict_types=1); -dcCore::app()->addBehavior('initWidgets', ['blogAnnivWidgets', 'initWidgets']); +namespace Dotclear\Plugin\bloganniv; -class blogAnnivWidgets +use dcCore; +use Dotclear\Helper\Html\Html; +use Dotclear\Plugin\widgets\WidgetsStack; +use Dotclear\Plugin\widgets\WidgetsElement; + +class Widgets { - public static function initWidgets($w) + public static function initWidgets(WidgetsStack $w): void { $w->create( - 'blogAnniv', - __('Blog Anniv'), - ['blogAnnivWidgets', 'BlogAnnivWidget'], + My::id(), + My::name(), + [self::class, 'parseWidget'], null, __('Counting the number of days before and after a particular date') ) @@ -37,14 +40,10 @@ class blogAnnivWidgets ->addOffline(); } - public static function BlogAnnivWidget($w) + public static function parseWidget(WidgetsElement $w): string { - if ($w->offline) { - return null; - } - - if (!$w->checkHomeOnly(dcCore::app()->url->type)) { - return null; + if ($w->offline || !$w->checkHomeOnly(dcCore::app()->url->type)) { + return ''; } $ftdatecrea = $w->ftdatecrea; @@ -93,8 +92,8 @@ class blogAnnivWidgets } return $w->renderDiv( - $w->content_only, - 'bloganniv ' . $w->class, + (bool) $w->content_only, + My::id() . ' ' . $w->class, '', ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') . '