diff --git a/src/Backend.php b/src/Backend.php index 5cebee8..6820a9d 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -10,8 +10,32 @@ * @copyright Jean-Christian Denis * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ -if (!defined('DC_CONTEXT_ADMIN')) { - return null; -} +declare(strict_types=1); -require __DIR__ . '/_widgets.php'; +namespace Dotclear\Plugin\lastpostsExtend; + +use dcCore; +use dcNsProcess; + +class Backend extends dcNsProcess +{ + public static function init(): bool + { + static::$init = defined('DC_CONTEXT_ADMIN'); + + 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 20c89a4..5cb13ce 100644 --- a/src/Frontend.php +++ b/src/Frontend.php @@ -10,8 +10,32 @@ * @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\lastpostsExtend; + +use dcCore; +use dcNsProcess; + +class Frontend extends dcNsProcess +{ + public static function init(): bool + { + static::$init = true; + + 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/Widgets.php b/src/Widgets.php index 61dfd4e..2eb08c9 100644 --- a/src/Widgets.php +++ b/src/Widgets.php @@ -10,24 +10,29 @@ * @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', - ['lastpostsextendWidget', 'initWidget'] -); +namespace Dotclear\Plugin\lastpostsExtend; -class lastpostsextendWidget +use dcBlog; +use dcCore; +use dcMeta; +use Dotclear\Helper\Text; +use Dotclear\Helper\File\Path; +use Dotclear\Helper\Html\Html; +use Dotclear\Plugin\widgets\WidgetsStack; +use Dotclear\Plugin\widgets\WidgetsElement; +use dt; + +class Widgets { - public static function initWidget($w) + public static function initWidgets(WidgetsStack $w): void { # Create widget $w->create( 'lastpostsextend', __('Last entries (Extended)'), - ['lastpostsextendWidget', 'parseWidget'], + [self::class, 'parseWidget'], null, __('Extended list of entries') ); @@ -66,8 +71,8 @@ class lastpostsextendWidget while ($rs->fetch()) { $categories[str_repeat( ' ', - $rs->level - 1 - ) . '• ' . html::escapeHTML($rs->cat_title)] = $rs->cat_id; + (int) $rs->f('level') - 1 + ) . '• ' . Html::escapeHTML($rs->f('cat_title'))] = $rs->f('cat_id'); } $w->lastpostsextend->setting( 'category', @@ -207,7 +212,7 @@ class lastpostsextendWidget ->addOffline(); } - public static function parseWidget($w) + public static function parseWidget(WidgetsElement $w): string { $params = [ 'sql' => '', @@ -215,14 +220,9 @@ class lastpostsextendWidget 'from' => '', ]; - # Widget is offline - if ($w->offline) { - return; - } - - # Home page only - if (!$w->checkHomeOnly(dcCore::app()->url->type)) { - return null; + # Widget is offline & Home page only + if ($w->offline || !$w->checkHomeOnly(dcCore::app()->url->type)) { + return ''; } # Need posts excerpt @@ -305,51 +305,53 @@ class lastpostsextendWidget # No result if ($rs->isEmpty()) { - return null; + return ''; } # Return - $res = $w->title ? $w->renderTitle(html::escapeHTML($w->title)) : ''; + $res = $w->title ? $w->renderTitle(Html::escapeHTML($w->title)) : ''; while ($rs->fetch()) { + $published = ((int) $rs->f('post_status')) == dcBlog::POST_PUBLISHED; + $res .= '