upgrade to Dotclear 2.27

This commit is contained in:
Jean-Christian Paul Denis 2023-08-13 00:15:04 +02:00
parent 12fb9cd689
commit b89a21f101
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
8 changed files with 63 additions and 176 deletions

View File

@ -14,39 +14,22 @@ declare(strict_types=1);
namespace Dotclear\Plugin\httpPassword; namespace Dotclear\Plugin\httpPassword;
use dcAdmin; use Dotclear\Core\Process;
use dcCore;
use dcPage;
use dcMenu;
use dcNsProcess;
class Backend extends dcNsProcess class Backend extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN'); return self::status(My::checkContext(My::BACKEND));
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init || is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) { if (!self::status()) {
return false; return false;
} }
// add backend sidebar menu icon My::addBackendMenuItem();
if ((dcCore::app()->menu[dcAdmin::MENU_PLUGINS] instanceof dcMenu)) {
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
My::name(),
dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
dcPage::getPF(My::id() . '/icon.svg'),
preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
My::PERMISSION,
]), dcCore::app()->blog->id)
);
}
return true; return true;
} }

View File

@ -16,20 +16,18 @@ namespace Dotclear\Plugin\httpPassword;
use dcCore; use dcCore;
use dcLog; use dcLog;
use dcNsProcess; use Dotclear\Core\Process;
class Frontend extends dcNsProcess class Frontend extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_RC_PATH'); return self::status(My::checkContext(My::FRONTEND));
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init || !Utils::isActive()) { if (!self::status() || !Utils::isActive()) {
return false; return false;
} }

View File

@ -15,30 +15,25 @@ declare(strict_types=1);
namespace Dotclear\Plugin\httpPassword; namespace Dotclear\Plugin\httpPassword;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process;
use Exception; use Exception;
class Install extends dcNsProcess class Install extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
if (defined('DC_CONTEXT_ADMIN')) { return self::status(My::checkContext(My::INSTALL));
$version = dcCore::app()->plugins->moduleInfo(My::id(), 'version');
static::$init = is_string($version) ? dcCore::app()->newVersion(My::id(), $version) : true;
}
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init || is_null(dcCore::app()->blog)) { if (!self::status()) {
return false; return false;
} }
try { try {
// Set settings // Set settings
$s = dcCore::app()->blog->settings->get(My::id()); $s = My::settings();
$s->put('active', false, 'boolean', 'Enable plugin', false, false); $s->put('active', false, 'boolean', 'Enable plugin', false, false);
$s->put('crypt', 'crypt_md5', 'string', 'Crypt algorithm', false, false); $s->put('crypt', 'crypt_md5', 'string', 'Crypt algorithm', false, false);
$s->put('message', 'Private space', 'String', 'Personalized message on Authentication popup', false, false); $s->put('message', 'Private space', 'String', 'Personalized message on Authentication popup', false, false);

View File

@ -15,8 +15,11 @@ declare(strict_types=1);
namespace Dotclear\Plugin\httpPassword; namespace Dotclear\Plugin\httpPassword;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Backend\{
use dcPage; Notices,
Page
};
use Dotclear\Core\Process;
use Dotclear\Helper\Date; use Dotclear\Helper\Date;
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
@ -36,30 +39,21 @@ use Dotclear\Helper\Html\Form\{
/** /**
* Manage contributions list * Manage contributions list
*/ */
class Manage extends dcNsProcess class Manage extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN') return self::status(My::checkContext(My::MANAGE));
&& !is_null(dcCore::app()->auth) && !is_null(dcCore::app()->blog) // nullsafe
&& dcCore::app()->auth->check(
dcCore::app()->auth->makePermissions([
My::PERMISSION,
]),
dcCore::app()->blog->id
);
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init || is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) { if (!self::status() || is_null(dcCore::app()->blog)) {
return false; return false;
} }
if (!Utils::isWritable()) { if (!Utils::isWritable()) {
dcPage::addWarningNotice( Notices::addWarningNotice(
__('No write permissions on blogs directories.') __('No write permissions on blogs directories.')
); );
} }
@ -72,21 +66,18 @@ class Manage extends dcNsProcess
// save settings // save settings
if ('savesettings' == $action) { if ('savesettings' == $action) {
$s = dcCore::app()->blog->settings->get(My::id()); $s = My::settings();
$s->put('active', !empty($_POST['active'])); $s->put('active', !empty($_POST['active']));
$s->put('crypt', in_array((string) $_POST['crypt'], My::cryptCombo()) ? $_POST['crypt'] : 'paintext'); $s->put('crypt', in_array((string) $_POST['crypt'], My::cryptCombo()) ? $_POST['crypt'] : 'paintext');
$s->put('message', (string) $_POST['message']); $s->put('message', (string) $_POST['message']);
dcCore::app()->blog->triggerBlog(); dcCore::app()->blog->triggerBlog();
dcPage::addSuccessNotice( Notices::addSuccessNotice(
__('Settings successfully updated.') __('Settings successfully updated.')
); );
dcCore::app()->adminurl->redirect( My::redirect(['part' => $part]);
'admin.plugin.' . My::id(),
['part' => $part]
);
} }
// delete users logins // delete users logins
@ -99,14 +90,11 @@ class Manage extends dcNsProcess
} }
$logs = dcCore::app()->log->delLogs($ids); $logs = dcCore::app()->log->delLogs($ids);
dcPage::addSuccessNotice( Notices::addSuccessNotice(
__('Logs successfully cleared.') __('Logs successfully cleared.')
); );
dcCore::app()->adminurl->redirect( My::redirect(['part' => $part]);
'admin.plugin.' . My::id(),
['part' => $part]
);
} }
} }
@ -144,14 +132,11 @@ class Manage extends dcNsProcess
dcCore::app()->blog->triggerBlog(); dcCore::app()->blog->triggerBlog();
dcPage::addSuccessNotice( Notices::addSuccessNotice(
__('Logins successfully updated.') __('Logins successfully updated.')
); );
dcCore::app()->adminurl->redirect( My::redirect(['part' => $part]);
'admin.plugin.' . My::id(),
['part' => $part]
);
} }
return true; return true;
@ -159,33 +144,33 @@ class Manage extends dcNsProcess
public static function render(): void public static function render(): void
{ {
if (!static::$init || is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) { if (!self::status() || is_null(dcCore::app()->blog)) {
return; return;
} }
$part = self::getSection(); $part = self::getSection();
dcPage::openModule( Page::openModule(
My::name(), My::name(),
dcPage::jsPageTabs() . Page::jsPageTabs() .
dcPage::jsModuleLoad(My::id() . '/js/backend.js') My::jsLoad('backend')
); );
echo echo
dcPage::breadcrumb([ Page::breadcrumb([
__('Plugins') => '', __('Plugins') => '',
My::name() => dcCore::app()->adminurl->get('admin.plugin.' . My::id()), My::name() => My::manageUrl(),
array_search($part, My::sectionCombo()) => '', array_search($part, My::sectionCombo()) => '',
]) . ]) .
dcPage::notices() . Notices::getNotices() .
// Filters select menu list // Filters select menu list
(new Form('section_menu'))->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id()))->method('get')->fields([ (new Form('section_menu'))->action(My::manageUrl())->method('get')->fields([
(new Para())->class('anchor-nav')->items([ (new Para())->class('anchor-nav')->items([
(new Label(__('Select section:')))->for('part')->class('classic'), (new Label(__('Select section:')))->for('part')->class('classic'),
(new Select('part'))->default($part)->items(My::sectionCombo()), (new Select('part'))->default($part)->items(My::sectionCombo()),
(new Submit(['go']))->value(__('Ok')), (new Submit(['go']))->value(__('Ok')),
(new Hidden(['p'], My::id())), ... My::hiddenFields(),
]), ]),
])->render() . ])->render() .
@ -194,7 +179,7 @@ class Manage extends dcNsProcess
// settigns form // settigns form
if ('settings' == $part) { if ('settings' == $part) {
echo echo
(new Form('section_settings'))->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'settings']))->method('post')->fields([ (new Form('section_settings'))->action(My::manageUrl())->method('post')->fields([
// active // active
(new Para())->items([ (new Para())->items([
(new Checkbox('active', Utils::isActive()))->value(1), (new Checkbox('active', Utils::isActive()))->value(1),
@ -215,8 +200,7 @@ class Manage extends dcNsProcess
(new Div())->class('clear')->items([ (new Div())->class('clear')->items([
(new Submit(['save']))->value(__('Save')), (new Submit(['save']))->value(__('Save')),
(new Hidden(['action'], 'savesettings')), (new Hidden(['action'], 'savesettings')),
(new Hidden(['part'], $part)), ... My::hiddenFields(['part' => $part]),
dcCore::app()->formNonce(false),
]), ]),
])->render(); ])->render();
} }
@ -229,12 +213,13 @@ class Manage extends dcNsProcess
'<p>' . __('Logins history is empty.') . '</p>'; '<p>' . __('Logins history is empty.') . '</p>';
} else { } else {
echo echo
(new Form('section_logins'))->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => 'logins']))->method('post')->fields([ (new Form('section_logins'))->action(My::manageUrl())->method('post')->fields([
(new Para())->items([ (new Para())->items([
(new Submit(['save']))->value(__('Clear logs')), (new Submit(['save']))->value(__('Clear logs')),
(new Hidden(['action'], 'savelogins')), ... My::hiddenFields([
(new Hidden(['part'], $part)), 'action' => 'savelogins',
dcCore::app()->formNonce(false), 'part' => $part,
]),
]), ]),
])->render() . ])->render() .
@ -285,7 +270,7 @@ class Manage extends dcNsProcess
} }
echo echo
(new Form('section_passwords'))->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => $part]))->method('post')->fields([ (new Form('section_passwords'))->action(My::manageUrl())->method('post')->fields([
(new Text( (new Text(
'', '',
'<div class="table-outer"><table>' . '<div class="table-outer"><table>' .
@ -300,15 +285,14 @@ class Manage extends dcNsProcess
)), )),
(new Para())->items([ (new Para())->items([
(new Hidden(['action'], 'savepasswords')), (new Hidden(['action'], 'savepasswords')),
(new Hidden(['part'], $part)), ... My::hiddenFields(['part' => $part]),
dcCore::app()->formNonce(false),
]), ]),
])->render(); ])->render();
} }
// new login form // new login form
echo echo
(new Form('section_new'))->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['part' => $part]))->method('post')->fields([ (new Form('section_new'))->action(My::manageUrl())->method('post')->fields([
(new Text('h3', Html::escapeHTML(__('Add a user')))), (new Text('h3', Html::escapeHTML(__('Add a user')))),
// login // login
(new Para())->items([ (new Para())->items([
@ -322,14 +306,15 @@ class Manage extends dcNsProcess
]), ]),
(new Para())->items([ (new Para())->items([
(new Submit(['add']))->value(__('Save')), (new Submit(['add']))->value(__('Save')),
(new Hidden(['action'], 'savepasswords')), ... My::hiddenFields([
(new Hidden(['part'], $part)), 'action' => 'savepasswords',
dcCore::app()->formNonce(false), 'part' => $part,
]),
]), ]),
])->render(); ])->render();
} }
dcPage::closeModule(); Page::closeModule();
} }
/** /**

View File

@ -14,45 +14,16 @@ declare(strict_types=1);
namespace Dotclear\Plugin\httpPassword; namespace Dotclear\Plugin\httpPassword;
use dcCore; use Dotclear\Module\MyPlugin;
/** /**
* This module definitions. * This module definitions.
*/ */
class My class My extends MyPlugin
{ {
/** @var string This plugin permissions */
public const PERMISSION = 'httpPassword';
/** @var string Passwords file name */ /** @var string Passwords file name */
public const FILE_PASSWORD = '.htpasswd'; public const FILE_PASSWORD = '.htpasswd';
/**
* 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__);
}
/** /**
* Encryption methods combo. * Encryption methods combo.
* *

View File

@ -1,43 +0,0 @@
<?php
/**
* @brief httpPassword, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Frederic PLE 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\httpPassword;
use dcCore;
use dcNsProcess;
class Prepend extends dcNsProcess
{
public static function init(): bool
{
static::$init = true;
return static::$init;
}
public static function process(): bool
{
if (!static::$init || is_null(dcCore::app()->auth)) {
return false;
}
// register module permission
dcCore::app()->auth->setPermissionType(
My::PERMISSION,
__('Manage http password blog protection')
);
return true;
}
}

View File

@ -15,21 +15,19 @@ declare(strict_types=1);
namespace Dotclear\Plugin\httpPassword; namespace Dotclear\Plugin\httpPassword;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process;
use Dotclear\Plugin\Uninstaller\Uninstaller; use Dotclear\Plugin\Uninstaller\Uninstaller;
class Uninstall extends dcNsProcess class Uninstall extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN'); return self::status(My::checkContext(My::UNINSTALL));
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init || !dcCore::app()->plugins->moduleExists('Uninstaller')) { if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
return false; return false;
} }

View File

@ -88,7 +88,7 @@ class Utils
*/ */
public static function isActive(): bool public static function isActive(): bool
{ {
return !is_null(dcCore::app()->blog) && (bool) dcCore::app()->blog->settings->get(My::id())->get('active'); return (bool) My::settings()->get('active');
} }
/** /**
@ -98,7 +98,7 @@ class Utils
*/ */
public static function cryptMethod(): string public static function cryptMethod(): string
{ {
return !is_null(dcCore::app()->blog) && is_string(dcCore::app()->blog->settings->get(My::id())->get('crypt')) ? dcCore::app()->blog->settings->get(My::id())->get('crypt') : ''; return is_string(My::settings()->get('crypt')) ? My::settings()->get('crypt') : '';
} }
/** /**
@ -108,7 +108,7 @@ class Utils
*/ */
public static function httpMessage(): string public static function httpMessage(): string
{ {
return !is_null(dcCore::app()->blog) && is_string(dcCore::app()->blog->settings->get(My::id())->get('message')) ? dcCore::app()->blog->settings->get(My::id())->get('message') : ''; return is_string(My::settings()->get('message')) ? My::settings()->get('message') : '';
} }
/** /**