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 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\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 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\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 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()->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');
|
||||
exit;
|
||||
static::$init = My::phpCompliant();
|
||||
|
||||
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 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', ['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
|
||||
->create(
|
||||
'CategoriesPage',
|
||||
__('Categories Page'),
|
||||
['widgetsCategoriesPage', 'categoriesPageWidgets'],
|
||||
My::id(),
|
||||
My::name(),
|
||||
[self::class, 'parseWidget'],
|
||||
null,
|
||||
__('Link to categories')
|
||||
)
|
||||
->addTitle(__('Categories Page'))
|
||||
->addTitle(My::name())
|
||||
->addHomeOnly()
|
||||
->addContentOnly()
|
||||
->addClass()
|
||||
->addOffline();
|
||||
}
|
||||
|
||||
public static function categoriesPageWidgets($w)
|
||||
public static function parseWidget(WidgetsElement $w): string
|
||||
{
|
||||
if ($w->offline) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$w->checkHomeOnly(dcCore::app()->url->type)) {
|
||||
return null;
|
||||
if ($w->offline || !$w->checkHomeOnly(dcCore::app()->url->type)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $w->renderDiv(
|
||||
$w->content_only,
|
||||
'categories ' . $w->class,
|
||||
(bool) $w->content_only,
|
||||
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') . '">' .
|
||||
($w->link_title ? html::escapeHTML($w->link_title) : __('All categories')) .
|
||||
($w->link_title ? Html::escapeHTML($w->link_title) : __('All categories')) .
|
||||
'</a></p>'
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue