improve/inc/Config.php

107 lines
2.8 KiB
PHP
Raw Normal View History

2021-11-05 21:52:46 +00:00
<?php
/**
* @brief improve, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
2022-12-21 14:41:27 +00:00
namespace Dotclear\Plugin\improve;
2021-11-05 21:52:46 +00:00
/* dotclear */
use dcCore;
use dcPage;
2021-11-05 21:52:46 +00:00
/* clearbricks */
use form;
2021-11-05 21:52:46 +00:00
/* php */
use Exception;
/**
* Admin Improve configuration class
*
* Set preference for this plugin.
*/
2022-12-21 14:41:27 +00:00
class Config
{
2022-12-21 14:41:27 +00:00
private static $init = false;
2022-12-21 14:41:27 +00:00
public static function init(): bool
{
2022-12-21 14:41:27 +00:00
if (defined('DC_CONTEXT_ADMIN')) {
dcPage::checkSuper();
2022-12-21 14:41:27 +00:00
dcCore::app()->blog->settings->addNamespace(Core::id());
self::$init = true;
}
2022-12-21 14:41:27 +00:00
return self::$init;
}
2021-11-05 21:52:46 +00:00
2022-12-21 14:41:27 +00:00
public static function process(): void
{
2022-12-21 14:41:27 +00:00
if (!self::$init) {
return;
2021-11-05 21:52:46 +00:00
}
if (empty($_POST['save'])) {
return;
}
try {
$pdisabled = '';
if (!empty($_POST['disabled']) && is_array($_POST['disabled'])) {
$pdisabled = implode(';', $_POST['disabled']);
}
2022-12-21 14:41:27 +00:00
dcCore::app()->blog->settings->get(Core::id())->put('disabled', $pdisabled);
dcCore::app()->blog->settings->get(Core::id())->put('nodetails', !empty($_POST['nodetails']));
dcPage::addSuccessNotice(__('Configuration successfully updated'));
dcCore::app()->adminurl->redirect(
'admin.plugins',
2022-12-01 10:09:24 +00:00
['module' => 'improve', 'conf' => 1, 'chk' => 1, 'redir' => dcCore::app()->admin->__get('list')->getRedir()]
);
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
}
}
2022-12-21 14:41:27 +00:00
public static function render()
{
2022-12-21 14:41:27 +00:00
if (!self::$init) {
return;
}
$improve = new Core();
$modules = [];
foreach ($improve->modules() as $action) {
$modules[$action->name()] = $action->id();
}
$modules = array_merge($modules, array_flip($improve->disabled()));
echo '<div class="fieldset"><h4>' . __('List of disabled actions:') . '</h4>';
2021-11-05 21:52:46 +00:00
2022-12-21 14:41:27 +00:00
foreach ($modules as $name => $id) {
echo
'<p><label class="classic" title="' . $id . '">' .
2022-12-21 14:41:27 +00:00
form::checkbox(['disabled[]'], $id, ['checked' => array_key_exists($id, $improve->disabled())]) .
__($name) . '</label></p>';
}
echo
'</div><div class="fieldset"><h4>' . __('Options') . '</h4>' .
'<p><label class="classic">' .
2022-12-21 14:41:27 +00:00
form::checkbox('nodetails', '1', ['checked' => dcCore::app()->blog->settings->get(Core::id())->get('nodetails')]) .
__('Hide details of rendered actions') . '</label></p>' .
'</div>';
}
2021-11-05 21:52:46 +00:00
}