upgrade to Dotclear 2.27
parent
12fb9cd689
commit
b89a21f101
|
@ -14,39 +14,22 @@ declare(strict_types=1);
|
|||
|
||||
namespace Dotclear\Plugin\httpPassword;
|
||||
|
||||
use dcAdmin;
|
||||
use dcCore;
|
||||
use dcPage;
|
||||
use dcMenu;
|
||||
use dcNsProcess;
|
||||
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 || is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// add backend sidebar menu icon
|
||||
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)
|
||||
);
|
||||
}
|
||||
My::addBackendMenuItem();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -16,20 +16,18 @@ namespace Dotclear\Plugin\httpPassword;
|
|||
|
||||
use dcCore;
|
||||
use dcLog;
|
||||
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 || !Utils::isActive()) {
|
||||
if (!self::status() || !Utils::isActive()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,30 +15,25 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\httpPassword;
|
||||
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use Dotclear\Core\Process;
|
||||
use Exception;
|
||||
|
||||
class Install extends dcNsProcess
|
||||
class Install extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
if (defined('DC_CONTEXT_ADMIN')) {
|
||||
$version = dcCore::app()->plugins->moduleInfo(My::id(), 'version');
|
||||
static::$init = is_string($version) ? dcCore::app()->newVersion(My::id(), $version) : true;
|
||||
}
|
||||
|
||||
return static::$init;
|
||||
return self::status(My::checkContext(My::INSTALL));
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init || is_null(dcCore::app()->blog)) {
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
// Set settings
|
||||
$s = dcCore::app()->blog->settings->get(My::id());
|
||||
$s = My::settings();
|
||||
$s->put('active', false, 'boolean', 'Enable plugin', 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);
|
||||
|
|
|
@ -15,8 +15,11 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\httpPassword;
|
||||
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use dcPage;
|
||||
use Dotclear\Core\Backend\{
|
||||
Notices,
|
||||
Page
|
||||
};
|
||||
use Dotclear\Core\Process;
|
||||
use Dotclear\Helper\Date;
|
||||
use Dotclear\Helper\Html\Html;
|
||||
use Dotclear\Helper\Html\Form\{
|
||||
|
@ -36,30 +39,21 @@ use Dotclear\Helper\Html\Form\{
|
|||
/**
|
||||
* Manage contributions list
|
||||
*/
|
||||
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) // nullsafe
|
||||
&& dcCore::app()->auth->check(
|
||||
dcCore::app()->auth->makePermissions([
|
||||
My::PERMISSION,
|
||||
]),
|
||||
dcCore::app()->blog->id
|
||||
);
|
||||
|
||||
return static::$init;
|
||||
return self::status(My::checkContext(My::MANAGE));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (!Utils::isWritable()) {
|
||||
dcPage::addWarningNotice(
|
||||
Notices::addWarningNotice(
|
||||
__('No write permissions on blogs directories.')
|
||||
);
|
||||
}
|
||||
|
@ -72,21 +66,18 @@ class Manage extends dcNsProcess
|
|||
|
||||
// save settings
|
||||
if ('savesettings' == $action) {
|
||||
$s = dcCore::app()->blog->settings->get(My::id());
|
||||
$s = My::settings();
|
||||
$s->put('active', !empty($_POST['active']));
|
||||
$s->put('crypt', in_array((string) $_POST['crypt'], My::cryptCombo()) ? $_POST['crypt'] : 'paintext');
|
||||
$s->put('message', (string) $_POST['message']);
|
||||
|
||||
dcCore::app()->blog->triggerBlog();
|
||||
|
||||
dcPage::addSuccessNotice(
|
||||
Notices::addSuccessNotice(
|
||||
__('Settings successfully updated.')
|
||||
);
|
||||
|
||||
dcCore::app()->adminurl->redirect(
|
||||
'admin.plugin.' . My::id(),
|
||||
['part' => $part]
|
||||
);
|
||||
My::redirect(['part' => $part]);
|
||||
}
|
||||
|
||||
// delete users logins
|
||||
|
@ -99,14 +90,11 @@ class Manage extends dcNsProcess
|
|||
}
|
||||
$logs = dcCore::app()->log->delLogs($ids);
|
||||
|
||||
dcPage::addSuccessNotice(
|
||||
Notices::addSuccessNotice(
|
||||
__('Logs successfully cleared.')
|
||||
);
|
||||
|
||||
dcCore::app()->adminurl->redirect(
|
||||
'admin.plugin.' . My::id(),
|
||||
['part' => $part]
|
||||
);
|
||||
My::redirect(['part' => $part]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,14 +132,11 @@ class Manage extends dcNsProcess
|
|||
|
||||
dcCore::app()->blog->triggerBlog();
|
||||
|
||||
dcPage::addSuccessNotice(
|
||||
Notices::addSuccessNotice(
|
||||
__('Logins successfully updated.')
|
||||
);
|
||||
|
||||
dcCore::app()->adminurl->redirect(
|
||||
'admin.plugin.' . My::id(),
|
||||
['part' => $part]
|
||||
);
|
||||
My::redirect(['part' => $part]);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -159,33 +144,33 @@ class Manage extends dcNsProcess
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
$part = self::getSection();
|
||||
|
||||
dcPage::openModule(
|
||||
Page::openModule(
|
||||
My::name(),
|
||||
dcPage::jsPageTabs() .
|
||||
dcPage::jsModuleLoad(My::id() . '/js/backend.js')
|
||||
Page::jsPageTabs() .
|
||||
My::jsLoad('backend')
|
||||
);
|
||||
|
||||
echo
|
||||
dcPage::breadcrumb([
|
||||
Page::breadcrumb([
|
||||
__('Plugins') => '',
|
||||
My::name() => dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
|
||||
My::name() => My::manageUrl(),
|
||||
array_search($part, My::sectionCombo()) => '',
|
||||
]) .
|
||||
dcPage::notices() .
|
||||
Notices::getNotices() .
|
||||
|
||||
// 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 Label(__('Select section:')))->for('part')->class('classic'),
|
||||
(new Select('part'))->default($part)->items(My::sectionCombo()),
|
||||
(new Submit(['go']))->value(__('Ok')),
|
||||
(new Hidden(['p'], My::id())),
|
||||
... My::hiddenFields(),
|
||||
]),
|
||||
])->render() .
|
||||
|
||||
|
@ -194,7 +179,7 @@ class Manage extends dcNsProcess
|
|||
// settigns form
|
||||
if ('settings' == $part) {
|
||||
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
|
||||
(new Para())->items([
|
||||
(new Checkbox('active', Utils::isActive()))->value(1),
|
||||
|
@ -215,8 +200,7 @@ class Manage extends dcNsProcess
|
|||
(new Div())->class('clear')->items([
|
||||
(new Submit(['save']))->value(__('Save')),
|
||||
(new Hidden(['action'], 'savesettings')),
|
||||
(new Hidden(['part'], $part)),
|
||||
dcCore::app()->formNonce(false),
|
||||
... My::hiddenFields(['part' => $part]),
|
||||
]),
|
||||
])->render();
|
||||
}
|
||||
|
@ -229,12 +213,13 @@ class Manage extends dcNsProcess
|
|||
'<p>' . __('Logins history is empty.') . '</p>';
|
||||
} else {
|
||||
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 Submit(['save']))->value(__('Clear logs')),
|
||||
(new Hidden(['action'], 'savelogins')),
|
||||
(new Hidden(['part'], $part)),
|
||||
dcCore::app()->formNonce(false),
|
||||
... My::hiddenFields([
|
||||
'action' => 'savelogins',
|
||||
'part' => $part,
|
||||
]),
|
||||
]),
|
||||
])->render() .
|
||||
|
||||
|
@ -285,7 +270,7 @@ class Manage extends dcNsProcess
|
|||
}
|
||||
|
||||
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(
|
||||
'',
|
||||
'<div class="table-outer"><table>' .
|
||||
|
@ -300,15 +285,14 @@ class Manage extends dcNsProcess
|
|||
)),
|
||||
(new Para())->items([
|
||||
(new Hidden(['action'], 'savepasswords')),
|
||||
(new Hidden(['part'], $part)),
|
||||
dcCore::app()->formNonce(false),
|
||||
... My::hiddenFields(['part' => $part]),
|
||||
]),
|
||||
])->render();
|
||||
}
|
||||
|
||||
// new login form
|
||||
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')))),
|
||||
// login
|
||||
(new Para())->items([
|
||||
|
@ -322,14 +306,15 @@ class Manage extends dcNsProcess
|
|||
]),
|
||||
(new Para())->items([
|
||||
(new Submit(['add']))->value(__('Save')),
|
||||
(new Hidden(['action'], 'savepasswords')),
|
||||
(new Hidden(['part'], $part)),
|
||||
dcCore::app()->formNonce(false),
|
||||
... My::hiddenFields([
|
||||
'action' => 'savepasswords',
|
||||
'part' => $part,
|
||||
]),
|
||||
]),
|
||||
])->render();
|
||||
}
|
||||
|
||||
dcPage::closeModule();
|
||||
Page::closeModule();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
33
src/My.php
33
src/My.php
|
@ -14,45 +14,16 @@ declare(strict_types=1);
|
|||
|
||||
namespace Dotclear\Plugin\httpPassword;
|
||||
|
||||
use dcCore;
|
||||
use Dotclear\Module\MyPlugin;
|
||||
|
||||
/**
|
||||
* This module definitions.
|
||||
*/
|
||||
class My
|
||||
class My extends MyPlugin
|
||||
{
|
||||
/** @var string This plugin permissions */
|
||||
public const PERMISSION = 'httpPassword';
|
||||
|
||||
/** @var string Passwords file name */
|
||||
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.
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -15,21 +15,19 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\httpPassword;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ class Utils
|
|||
*/
|
||||
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
|
||||
{
|
||||
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
|
||||
{
|
||||
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') : '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue