use namespace

This commit is contained in:
Jean-Christian Denis 2023-04-11 00:09:04 +02:00
parent 92e9631e63
commit 31d713a804
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
4 changed files with 140 additions and 41 deletions

View file

@ -7,11 +7,35 @@
*
* @author annso, 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 null;
declare(strict_types=1);
namespace Dotclear\Plugin\shortArchives;
use dcCore;
use dcNsProcess;
class Backend extends dcNsProcess
{
public static function init(): bool
{
static::$init = defined('DC_CONTEXT_ADMIN') && My::phpCompliant();
return static::$init;
}
require __DIR__ . '/_widgets.php';
public static function process(): bool
{
if (!static::$init) {
return false;
}
dcCore::app()->addBehaviors([
'initWidgets' => [Widgets::class, 'initWidgets'],
]);
return true;
}
}

View file

@ -7,17 +7,41 @@
*
* @author annso, 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);
namespace Dotclear\Plugin\shortArchives;
use dcCore;
use dcNsProcess;
use dcUtils;
class Frontend extends dcNsProcess
{
public static function init(): bool
{
static::$init = My::phpCompliant();
return static::$init;
}
require __DIR__ . '/_widgets.php';
public static function process(): bool
{
if (!static::$init) {
return false;
}
dcCore::app()->addBehavior('publicHeadContent', function () {
dcCore::app()->addBehaviors([
'initWidgets' => [Widgets::class, 'initWidgets'],
'publicHeadContent', function (): void {
echo
dcUtils::jsModuleLoad(basename(__DIR__) . '/js/accordion.js') .
dcUtils::cssModuleLoad(basename(__DIR__) . '/css/shortArchives.css');
});
dcUtils::jsModuleLoad(My::id() . '/js/accordion.js') .
dcUtils::cssModuleLoad(My::id() . '/css/frontend.css');
},
]);
return true;
}
}

50
src/My.php Normal file
View file

@ -0,0 +1,50 @@
<?php
/**
* @brief shortArchives, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author annso, Pierre Van Glabeke 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\shortArchives;
use dcCore;
/**
* Plugin definitions
*/
class My
{
/** @var string Required php version */
public const PHP_MIN = '7.4';
/**
* This module id
*/
public static function id(): string
{
return basename(dirname(__DIR__));
}
/**
* This module name
*/
public static function name(): string
{
return __((string) dcCore::app()->plugins->moduleInfo(self::id(), 'name'));
}
/**
* Check php version
*/
public static function phpCompliant(): bool
{
return version_compare(phpversion(), self::PHP_MIN, '>=');
}
}

View file

@ -7,23 +7,28 @@
*
* @author annso, 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;
}
declare(strict_types=1);
dcCore::app()->addBehavior('initWidgets', ['shortArchivesWidgets','initWidgets']);
namespace Dotclear\Plugin\shortArchives;
class shortArchivesWidgets
use dcCore;
use Dotclear\Helper\Html\Html;
use Dotclear\Plugin\widgets\WidgetsStack;
use Dotclear\Plugin\widgets\WidgetsElement;
use dt;
class Widgets
{
public static function initWidgets($w)
public static function initWidgets(WidgetsStack $w): void
{
#Top c
$w->create(
'shortArchives',
__('Short Archives'),
['shortArchivesWidgets', 'shortArchivesWidgets'],
My::id(),
My::name(),
[self::class, 'parseWidget'],
null,
__('Blog Archive List an accordion menu, sorted by year')
)
@ -36,19 +41,15 @@ class shortArchivesWidgets
->addOffline();
}
public static function shortArchivesWidgets($w)
public static function parseWidget(WidgetsElement $w): string
{
if ($w->offline) {
return;
}
if (!$w->checkHomeOnly(dcCore::app()->url->type)) {
return;
if ($w->offline || !$w->checkHomeOnly(dcCore::app()->url->type)) {
return '';
}
$rs = dcCore::app()->blog->getDates(['type' => 'month']);
if ($rs->isEmpty()) {
return;
return '';
}
$active_year = null;
@ -58,10 +59,10 @@ class shortArchivesWidgets
$posts = [];
while ($rs->fetch()) {
$posts[dt::dt2str(__('%Y'), $rs->dt)][] = [
$posts[dt::dt2str(__('%Y'), $rs->f('dt'))][] = [
'url' => $rs->url(),
'date' => html::escapeHTML(dt::dt2str(__('%B'), $rs->dt)),
'nbpost' => $rs->nb_post,
'date' => Html::escapeHTML(dt::dt2str(__('%B'), $rs->f('dt'))),
'nbpost' => $rs->f('nb_post'),
];
}
@ -85,14 +86,14 @@ class shortArchivesWidgets
if (dcCore::app()->url->getBase('archive') && !is_null($w->allarchivesslinktitle) && $w->allarchivesslinktitle !== '') {
$res .= '<p><strong><a href="' . dcCore::app()->blog->url . dcCore::app()->url->getURLFor('archive') . '">' .
html::escapeHTML($w->allarchivesslinktitle) . '</a></strong></p>';
Html::escapeHTML($w->allarchivesslinktitle) . '</a></strong></p>';
}
return $w->renderDiv(
$w->content_only,
'shortArchives ' . $w->class,
(bool) $w->content_only,
My::id() . ' ' . $w->class,
'',
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') . $res
($w->title ? $w->renderTitle(Html::escapeHTML($w->title)) : '') . $res
);
}
}