upgrade to Dotclear 2.27
This commit is contained in:
parent
20747525e7
commit
d00cca50a9
10 changed files with 59 additions and 127 deletions
|
@ -15,51 +15,34 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\comListe;
|
||||
|
||||
use ArrayObject;
|
||||
use dcAdmin;
|
||||
use dcCore;
|
||||
use dcPage;
|
||||
use dcFavorites;
|
||||
use dcNsProcess;
|
||||
use Dotclear\Core\Backend\Favorites;
|
||||
use Dotclear\Core\Process;
|
||||
|
||||
class Backend extends dcNsProcess
|
||||
class Backend extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init = defined('DC_CONTEXT_ADMIN');
|
||||
|
||||
return static::$init;
|
||||
return self::status(My::checkContext(My::BACKEND));
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->auth) || is_null(dcCore::app()->adminurl)) {
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Admin menu
|
||||
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
|
||||
My::name(),
|
||||
dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
|
||||
dcPage::getPF(My::id() . '/icon.png'),
|
||||
preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
|
||||
dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_ADMIN]), dcCore::app()->blog->id)
|
||||
);
|
||||
My::addBackendMenuItem();
|
||||
|
||||
dcCore::app()->addBehaviors([
|
||||
// Dashboard favorites
|
||||
'adminDashboardFavoritesV2' => function (dcFavorites $favs): void {
|
||||
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->adminurl)) {
|
||||
return;
|
||||
}
|
||||
'adminDashboardFavoritesV2' => function (Favorites $favs): void {
|
||||
$favs->register(My::id(), [
|
||||
'title' => My::name(),
|
||||
'url' => dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
|
||||
'small-icon' => dcPage::getPF(My::id() . '/icon.png'),
|
||||
'large-icon' => dcPage::getPF(My::id() . '/icon-big.png'),
|
||||
'url' => My::manageUrl(),
|
||||
'small-icon' => My::icons(),
|
||||
'large-icon' => My::icons(),
|
||||
'permissions' => dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_ADMIN]),
|
||||
]);
|
||||
},
|
||||
|
@ -67,12 +50,9 @@ class Backend extends dcNsProcess
|
|||
$items[My::id()] = new ArrayObject([My::name(), false]);
|
||||
},
|
||||
'adminSimpleMenuBeforeEdit' => function (string $type, string $select, array &$item): void {
|
||||
if (is_null(dcCore::app()->blog)) {
|
||||
return;
|
||||
}
|
||||
if (My::id() == $type) {
|
||||
$item[0] = My::name();
|
||||
$item[1] = dcCore::app()->blog->settings->get(My::id())->get('page_title') ?? My::name();
|
||||
$item[1] = My::settings()->get('page_title') ?? My::name();
|
||||
$item[2] = dcCore::app()->admin->__get('blog_url') . dcCore::app()->url->getURLFor(My::id());
|
||||
}
|
||||
},
|
||||
|
|
|
@ -15,28 +15,22 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\comListe;
|
||||
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use Dotclear\Core\Process;
|
||||
|
||||
class Frontend extends dcNsProcess
|
||||
class Frontend extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init = defined('DC_RC_PATH');
|
||||
|
||||
return static::$init;
|
||||
return self::status(My::checkContext(My::FRONTEND));
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init) {
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_null(dcCore::app()->blog)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!dcCore::app()->blog->settings->get(My::id())->get('enable')) {
|
||||
if (!My::settings()->get('enable')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,22 +15,19 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\comListe;
|
||||
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use Dotclear\Core\Process;
|
||||
use Exception;
|
||||
|
||||
class Install extends dcNsProcess
|
||||
class Install extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init = defined('DC_CONTEXT_ADMIN')
|
||||
&& dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version'));
|
||||
|
||||
return static::$init;
|
||||
return self::status(My::checkContext(My::INSTALL));
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init) {
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -39,7 +36,7 @@ class Install extends dcNsProcess
|
|||
}
|
||||
|
||||
try {
|
||||
$s = dcCore::app()->blog->settings->get(My::id());
|
||||
$s = My::settings();
|
||||
$s->put('enable', false, 'boolean', 'Enable comListe', false, true);
|
||||
$s->put('page_title', 'Comments list', 'string', 'Public page title', false, true);
|
||||
$s->put('nb_comments_per_page', 10, 'integer', 'Number of comments per page', false, true);
|
||||
|
|
|
@ -15,8 +15,11 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\comListe;
|
||||
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use dcPage;
|
||||
use Dotclear\Core\Backend\{
|
||||
Notices,
|
||||
Page
|
||||
};
|
||||
use Dotclear\Core\Process;
|
||||
use Dotclear\Helper\Html\Form\{
|
||||
Checkbox,
|
||||
Div,
|
||||
|
@ -33,26 +36,20 @@ use Dotclear\Helper\Html\Form\{
|
|||
use Dotclear\Helper\Html\Html;
|
||||
use Exception;
|
||||
|
||||
class Manage extends dcNsProcess
|
||||
class Manage extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init = defined('DC_CONTEXT_ADMIN')
|
||||
&& !is_null(dcCore::app()->auth) && !is_null(dcCore::app()->blog)
|
||||
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
|
||||
dcCore::app()->auth::PERMISSION_ADMIN,
|
||||
]), dcCore::app()->blog->id);
|
||||
|
||||
return static::$init;
|
||||
return self::status(My::checkContext(My::MANAGE));
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init) {
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
|
||||
if (is_null(dcCore::app()->blog)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -64,21 +61,15 @@ class Manage extends dcNsProcess
|
|||
if (empty($_POST['comliste_page_title'])) {
|
||||
throw new Exception(__('No page title.'));
|
||||
}
|
||||
$s = dcCore::app()->blog->settings->get(My::id());
|
||||
$s = My::settings();
|
||||
$s->put('enable', !empty($_POST['comliste_enable']));
|
||||
$s->put('page_title', $_POST['comliste_page_title']);
|
||||
$s->put('nb_comments_per_page', $_POST['comliste_nb_comments_per_page'] ?? 10);
|
||||
$s->put('comments_order', $_POST['comliste_comments_order'] == 'asc' ? 'asc' : 'desc');
|
||||
|
||||
dcCore::app()->blog->triggerBlog();
|
||||
|
||||
dcPage::addSuccessNotice(
|
||||
__('Configuration successfully updated.')
|
||||
);
|
||||
|
||||
dcCore::app()->adminurl->redirect(
|
||||
'admin.plugin.' . My::id()
|
||||
);
|
||||
Notices::addSuccessNotice(__('Configuration successfully updated.'));
|
||||
My::redirect();
|
||||
} catch (Exception $e) {
|
||||
dcCore::app()->error->add($e->getMessage());
|
||||
}
|
||||
|
@ -88,25 +79,25 @@ class Manage extends dcNsProcess
|
|||
|
||||
public static function render(): void
|
||||
{
|
||||
if (!static::$init) {
|
||||
if (!self::status()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
|
||||
if (is_null(dcCore::app()->blog)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$s = dcCore::app()->blog->settings->get(My::id());
|
||||
$s = My::settings();
|
||||
|
||||
dcPage::openModule(My::name());
|
||||
Page::openModule(My::name());
|
||||
|
||||
echo dcPage::breadcrumb([
|
||||
echo Page::breadcrumb([
|
||||
Html::escapeHTML(dcCore::app()->blog->name) => '',
|
||||
My::name() => '',
|
||||
]) .
|
||||
dcPage::notices() .
|
||||
Notices::getNotices() .
|
||||
|
||||
(new Form('setting_form'))->method('post')->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id()))->separator('')->fields([
|
||||
(new Form('setting_form'))->method('post')->action(My::manageUrl())->separator('')->fields([
|
||||
(new Div())->class('fieldset')->items([
|
||||
(new Text('h4', __('Plugin activation'))),
|
||||
(new Para())->items([
|
||||
|
@ -132,13 +123,12 @@ class Manage extends dcNsProcess
|
|||
(new Para())->class('clear')->items([
|
||||
(new Submit(['do']))->value(__('Save')),
|
||||
(new Hidden(['action'], 'saveconfig')),
|
||||
(new Hidden(['p'], My::id())),
|
||||
dcCOre::app()->formNonce(false),
|
||||
... My::hiddenFields(),
|
||||
]),
|
||||
])->render();
|
||||
|
||||
dcPage::helpBlock('comListe');
|
||||
Page::helpBlock('comListe');
|
||||
|
||||
dcPage::closeModule();
|
||||
Page::closeModule();
|
||||
}
|
||||
}
|
||||
|
|
29
src/My.php
29
src/My.php
|
@ -14,36 +14,11 @@ declare(strict_types=1);
|
|||
|
||||
namespace Dotclear\Plugin\comListe;
|
||||
|
||||
use dcCore;
|
||||
use Dotclear\Module\MyPlugin;
|
||||
|
||||
/**
|
||||
* This module definitions.
|
||||
*/
|
||||
class My
|
||||
class My extends MyPlugin
|
||||
{
|
||||
/**
|
||||
* This module id.
|
||||
*/
|
||||
public static function id(): string
|
||||
{
|
||||
return basename(dirname(__DIR__));
|
||||
}
|
||||
|
||||
/**
|
||||
* This module name.
|
||||
*/
|
||||
public static function name(): string
|
||||
{
|
||||
$name = dcCore::app()->plugins->moduleInfo(self::id(), 'name');
|
||||
|
||||
return __(is_string($name) ? $name : self::id());
|
||||
}
|
||||
|
||||
/**
|
||||
* This module path.
|
||||
*/
|
||||
public static function path(): string
|
||||
{
|
||||
return dirname(__DIR__);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,20 +15,18 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\comListe;
|
||||
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use Dotclear\Core\Process;
|
||||
|
||||
class Prepend extends dcNsProcess
|
||||
class Prepend extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init = defined('DC_RC_PATH');
|
||||
|
||||
return static::$init;
|
||||
return self::status(My::checkContext(My::PREPEND));
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init) {
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ class Template
|
|||
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->ctx)) {
|
||||
return '10';
|
||||
}
|
||||
dcCore::app()->ctx->__set('nb_comment_per_page', (int) dcCore::app()->blog->settings->get(My::id())->get('nb_comments_per_page'));
|
||||
dcCore::app()->ctx->__set('nb_comment_per_page', (int) My::settings()->get('nb_comments_per_page'));
|
||||
|
||||
return Html::escapeHTML((string) dcCore::app()->ctx->__get('nb_comment_per_page'));
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ class Template
|
|||
}
|
||||
|
||||
// Sens de tri issu des paramètres du plugin
|
||||
$order = is_null(dcCore::app()->blog) ? 'desc' : dcCore::app()->blog->settings->get(My::id())->get('comments_order');
|
||||
$order = is_null(dcCore::app()->blog) ? 'desc' : My::settings()->get('comments_order');
|
||||
if (isset($attr['order']) && preg_match('/^(desc|asc)$/i', $attr['order'])) {
|
||||
$order = $attr['order'];
|
||||
}
|
||||
|
|
|
@ -15,21 +15,19 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\comListe;
|
||||
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use Dotclear\Core\Process;
|
||||
use Dotclear\Plugin\Uninstaller\Uninstaller;
|
||||
|
||||
class Uninstall extends dcNsProcess
|
||||
class Uninstall extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init = defined('DC_CONTEXT_ADMIN');
|
||||
|
||||
return static::$init;
|
||||
return self::status(My::checkContext(My::UNINSTALL));
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
|
||||
if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,13 +25,13 @@ class UrlHandler extends dcUrlHandlers
|
|||
|
||||
if (is_null(dcCore::app()->blog)
|
||||
|| is_null(dcCore::app()->ctx)
|
||||
|| !dcCore::app()->blog->settings->get(My::id())->get('enable')
|
||||
|| !My::settings()->get('enable')
|
||||
) {
|
||||
self::p404();
|
||||
}
|
||||
|
||||
dcCore::app()->public->setPageNumber(self::getPageNumber($args) ?: 1);
|
||||
dcCore::app()->ctx->__set('nb_comment_per_page', (int) dcCore::app()->blog->settings->get(My::id())->get('nb_comments_per_page'));
|
||||
dcCore::app()->ctx->__set('nb_comment_per_page', (int) My::settings()->get('nb_comments_per_page'));
|
||||
|
||||
$tplset = dcCore::app()->themes->moduleInfo(dcCore::app()->blog->settings->get('system')->get('theme'), 'tplset');
|
||||
if (!empty($tplset) && is_dir(implode(DIRECTORY_SEPARATOR, [My::path(), 'default-templates', $tplset]))) {
|
||||
|
|
|
@ -47,7 +47,7 @@ class Widgets
|
|||
if (is_null(dcCore::app()->blog)
|
||||
|| $w->__get('offline')
|
||||
|| !$w->checkHomeOnly(dcCore::app()->url->type)
|
||||
|| !dcCore::app()->blog->settings->get(My::id())->get('enable')
|
||||
|| !My::settings()->get('enable')
|
||||
) {
|
||||
return '';
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ class Widgets
|
|||
sprintf(
|
||||
'<p><a href="%s">%s</a></p>',
|
||||
dcCore::app()->blog->url . dcCore::app()->url->getBase('comListe'),
|
||||
$w->__get('link_title') ? Html::escapeHTML($w->__get('link_title')) : (dcCore::app()->blog->settings->get(My::id())->get('page_title') ?? My::name())
|
||||
$w->__get('link_title') ? Html::escapeHTML($w->__get('link_title')) : (My::settings()->get('page_title') ?? My::name())
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue