use namespace
This commit is contained in:
parent
8bad820fef
commit
f21a5eecfe
6 changed files with 209 additions and 62 deletions
|
@ -10,8 +10,32 @@
|
||||||
* @copyright 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
|
||||||
*/
|
*/
|
||||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
declare(strict_types=1);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
require __DIR__ . '/_widgets.php';
|
namespace Dotclear\Plugin\CategoriesPage;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -10,33 +10,55 @@
|
||||||
* @copyright 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
|
||||||
*/
|
*/
|
||||||
if (!defined('DC_RC_PATH')) {
|
declare(strict_types=1);
|
||||||
return null;
|
|
||||||
|
namespace Dotclear\Plugin\CategoriesPage;
|
||||||
|
|
||||||
|
use ArrayObject;
|
||||||
|
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([
|
||||||
|
// template path
|
||||||
|
'publicBeforeDocumentV2' => function (): void {
|
||||||
|
$tplset = dcCore::app()->themes->moduleInfo(dcCore::app()->blog->settings->get('system')->get('theme'), 'tplset');
|
||||||
|
if (!empty($tplset) && is_dir(implode(DIRECTORY_SEPARATOR, [My::root(), 'default-templates', $tplset]))) {
|
||||||
|
dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), implode(DIRECTORY_SEPARATOR, [My::root(), 'default-templates', $tplset]));
|
||||||
|
} else {
|
||||||
|
dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), implode(DIRECTORY_SEPARATOR, [My::root(), 'default-templates', DC_DEFAULT_TPLSET]));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// breacrumb addon
|
||||||
|
'publicBreadcrumb' => function (string $context, string $separator): string {
|
||||||
|
return $context == 'categories' ? My::name() : '';
|
||||||
|
},
|
||||||
|
// widget
|
||||||
|
'initWidgets' => [Widgets::class, 'initWidgets'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
// tpl values
|
||||||
|
dcCore::app()->tpl->addValue('CategoryCount', function (ArrayObject $attr): string {
|
||||||
|
return '<?php echo ' . sprintf(dcCore::app()->tpl->getFilters($attr), 'dcCore::app()->ctx->categories->nb_post') . '; ?>';
|
||||||
|
});
|
||||||
|
dcCore::app()->tpl->addValue('CategoriesURL', function (ArrayObject $attr): string {
|
||||||
|
return '<?php echo ' . sprintf(dcCore::app()->tpl->getFilters($attr), 'dcCore::app()->blog->url.dcCore::app()->url->getBase("categories")') . '; ?>';
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
require __DIR__ . '/_widgets.php';
|
|
||||||
|
|
||||||
// public behavior
|
|
||||||
dcCore::app()->addBehavior('publicBeforeDocumentV2', function () {
|
|
||||||
$tplset = dcCore::app()->themes->moduleInfo(dcCore::app()->blog->settings->system->theme, 'tplset');
|
|
||||||
if (!empty($tplset) && is_dir(__DIR__ . '/default-templates/' . $tplset)) {
|
|
||||||
dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), __DIR__ . '/default-templates/' . $tplset);
|
|
||||||
} else {
|
|
||||||
dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), __DIR__ . '/default-templates/' . DC_DEFAULT_TPLSET);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// breacrumb addon
|
|
||||||
dcCore::app()->addBehavior('publicBreadcrumb', function ($context, $separator) {
|
|
||||||
if ($context == 'categories') {
|
|
||||||
return __('Categories Page');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// tpl values
|
|
||||||
dcCore::app()->tpl->addValue('CategoryCount', function ($attr) {
|
|
||||||
return '<?php echo ' . sprintf(dcCore::app()->tpl->getFilters($attr), 'dcCore::app()->ctx->categories->nb_post') . '; ?>';
|
|
||||||
});
|
|
||||||
dcCore::app()->tpl->addValue('CategoriesURL', function ($attr) {
|
|
||||||
return '<?php echo ' . sprintf(dcCore::app()->tpl->getFilters($attr), 'dcCore::app()->blog->url.dcCore::app()->url->getBase("categories")') . '; ?>';
|
|
||||||
});
|
|
||||||
|
|
58
src/My.php
Normal file
58
src/My.php
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @brief CategoriesPage, a plugin for Dotclear 2
|
||||||
|
*
|
||||||
|
* @package Dotclear
|
||||||
|
* @subpackage Plugin
|
||||||
|
*
|
||||||
|
* @author Pierre Van Glabeke, Bernard Le Roux 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\CategoriesPage;
|
||||||
|
|
||||||
|
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'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This module root
|
||||||
|
*/
|
||||||
|
public static function root(): string
|
||||||
|
{
|
||||||
|
return dirname(__DIR__);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check php version
|
||||||
|
*/
|
||||||
|
public static function phpCompliant(): bool
|
||||||
|
{
|
||||||
|
return version_compare(phpversion(), self::PHP_MIN, '>=');
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,17 +10,35 @@
|
||||||
* @copyright 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
|
||||||
*/
|
*/
|
||||||
if (!defined('DC_RC_PATH')) {
|
declare(strict_types=1);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
dcCore::app()->url->register('categories', 'categories', '^categories$', ['urlCategoriesPage', 'categories']);
|
namespace Dotclear\Plugin\CategoriesPage;
|
||||||
|
|
||||||
class urlCategoriesPage extends dcUrlHandlers
|
use dcCore;
|
||||||
|
use dcNsProcess;
|
||||||
|
|
||||||
|
class Prepend extends dcNsProcess
|
||||||
{
|
{
|
||||||
public static function categories($args)
|
public static function init(): bool
|
||||||
{
|
{
|
||||||
self::serveDocument('categories.html');
|
static::$init = My::phpCompliant();
|
||||||
exit;
|
|
||||||
|
return static::$init;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function process(): bool
|
||||||
|
{
|
||||||
|
if (!static::$init) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
dcCore::app()->url->register(
|
||||||
|
'categories',
|
||||||
|
'categories',
|
||||||
|
'^categories$',
|
||||||
|
[UrlHandler::class, 'categories']
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
26
src/UrlHandler.php
Normal file
26
src/UrlHandler.php
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @brief CategoriesPage, a plugin for Dotclear 2
|
||||||
|
*
|
||||||
|
* @package Dotclear
|
||||||
|
* @subpackage Plugin
|
||||||
|
*
|
||||||
|
* @author Pierre Van Glabeke, Bernard Le Roux 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\CategoriesPage;
|
||||||
|
|
||||||
|
use dcUrlHandlers;
|
||||||
|
|
||||||
|
class UrlHandler extends dcUrlHandlers
|
||||||
|
{
|
||||||
|
public static function categories(?string $args): void
|
||||||
|
{
|
||||||
|
self::serveDocument('categories.html');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,48 +10,47 @@
|
||||||
* @copyright 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
|
||||||
*/
|
*/
|
||||||
if (!defined('DC_RC_PATH')) {
|
declare(strict_types=1);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
dcCore::app()->addBehavior('initWidgets', ['widgetsCategoriesPage', 'initWidgets']);
|
namespace Dotclear\Plugin\CategoriesPage;
|
||||||
|
|
||||||
class widgetsCategoriesPage
|
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
|
$w
|
||||||
->create(
|
->create(
|
||||||
'CategoriesPage',
|
My::id(),
|
||||||
__('Categories Page'),
|
My::name(),
|
||||||
['widgetsCategoriesPage', 'categoriesPageWidgets'],
|
[self::class, 'parseWidget'],
|
||||||
null,
|
null,
|
||||||
__('Link to categories')
|
__('Link to categories')
|
||||||
)
|
)
|
||||||
->addTitle(__('Categories Page'))
|
->addTitle(My::name())
|
||||||
->addHomeOnly()
|
->addHomeOnly()
|
||||||
->addContentOnly()
|
->addContentOnly()
|
||||||
->addClass()
|
->addClass()
|
||||||
->addOffline();
|
->addOffline();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function categoriesPageWidgets($w)
|
public static function parseWidget(WidgetsElement $w): string
|
||||||
{
|
{
|
||||||
if ($w->offline) {
|
if ($w->offline || !$w->checkHomeOnly(dcCore::app()->url->type)) {
|
||||||
return;
|
return '';
|
||||||
}
|
|
||||||
|
|
||||||
if (!$w->checkHomeOnly(dcCore::app()->url->type)) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $w->renderDiv(
|
return $w->renderDiv(
|
||||||
$w->content_only,
|
(bool) $w->content_only,
|
||||||
'categories ' . $w->class,
|
My::id() . ' ' . $w->class,
|
||||||
'',
|
'',
|
||||||
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') .
|
($w->title ? $w->renderTitle(Html::escapeHTML($w->title)) : '') .
|
||||||
'<p><a href="' . dcCore::app()->blog->url . dcCore::app()->url->getBase('categories') . '">' .
|
'<p><a href="' . dcCore::app()->blog->url . dcCore::app()->url->getBase('categories') . '">' .
|
||||||
($w->link_title ? html::escapeHTML($w->link_title) : __('All categories')) .
|
($w->link_title ? Html::escapeHTML($w->link_title) : __('All categories')) .
|
||||||
'</a></p>'
|
'</a></p>'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue