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
|
|
|
|
*/
|
2021-11-13 21:57:51 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace plugins\improve;
|
|
|
|
|
2021-11-05 21:52:46 +00:00
|
|
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-13 21:57:51 +00:00
|
|
|
/* dotclear */
|
|
|
|
use dcCore;
|
|
|
|
use dcPage;
|
2021-11-05 21:52:46 +00:00
|
|
|
|
2021-11-13 21:57:51 +00:00
|
|
|
/* clearbricks */
|
|
|
|
use form;
|
2021-11-05 21:52:46 +00:00
|
|
|
|
2021-11-13 21:57:51 +00:00
|
|
|
/* php */
|
|
|
|
use Exception;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Admin Improve configuration class
|
|
|
|
*
|
|
|
|
* Set preference for this plugin.
|
|
|
|
*/
|
|
|
|
class config
|
|
|
|
{
|
|
|
|
/** @var improve $improve improve core instance */
|
|
|
|
private $improve = null;
|
|
|
|
|
2022-11-12 21:58:44 +00:00
|
|
|
public function __construct()
|
2021-11-13 21:57:51 +00:00
|
|
|
{
|
|
|
|
dcPage::checkSuper();
|
|
|
|
|
2022-11-12 21:58:44 +00:00
|
|
|
$this->improve = new improve();
|
2021-11-13 21:57:51 +00:00
|
|
|
|
|
|
|
$this->saveConfig();
|
|
|
|
$this->displayConfig();
|
|
|
|
}
|
2021-11-05 21:52:46 +00:00
|
|
|
|
2021-11-13 21:57:51 +00:00
|
|
|
private function getModules(): array
|
|
|
|
{
|
|
|
|
$modules = [];
|
|
|
|
foreach ($this->improve->modules() as $action) {
|
|
|
|
$modules[$action->name()] = $action->id();
|
2021-11-05 21:52:46 +00:00
|
|
|
}
|
2021-11-13 21:57:51 +00:00
|
|
|
$modules = array_merge($modules, array_flip($this->improve->disabled()));
|
|
|
|
|
|
|
|
return $modules;
|
2021-11-05 21:52:46 +00:00
|
|
|
}
|
|
|
|
|
2021-11-13 21:57:51 +00:00
|
|
|
private function saveConfig(): void
|
|
|
|
{
|
|
|
|
if (empty($_POST['save'])) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
$pdisabled = '';
|
|
|
|
if (!empty($_POST['disabled']) && is_array($_POST['disabled'])) {
|
|
|
|
$pdisabled = implode(';', $_POST['disabled']);
|
|
|
|
}
|
2022-11-12 21:58:44 +00:00
|
|
|
dcCore::app()->blog->settings->improve->put('disabled', $pdisabled);
|
|
|
|
dcCore::app()->blog->settings->improve->put('nodetails', !empty($_POST['nodetails']));
|
2021-11-13 21:57:51 +00:00
|
|
|
|
|
|
|
dcPage::addSuccessNotice(__('Configuration successfully updated'));
|
|
|
|
|
2022-11-12 21:58:44 +00:00
|
|
|
dcCore::app()->adminurl->redirect(
|
2021-11-13 21:57:51 +00:00
|
|
|
'admin.plugins',
|
2022-12-01 10:09:24 +00:00
|
|
|
['module' => 'improve', 'conf' => 1, 'chk' => 1, 'redir' => dcCore::app()->admin->__get('list')->getRedir()]
|
2021-11-13 21:57:51 +00:00
|
|
|
);
|
|
|
|
} catch (Exception $e) {
|
2022-11-12 21:58:44 +00:00
|
|
|
dcCore::app()->error->add($e->getMessage());
|
2021-11-13 21:57:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function displayConfig(): void
|
|
|
|
{
|
|
|
|
echo '<div class="fieldset"><h4>' . __('List of disabled actions:') . '</h4>';
|
2021-11-05 21:52:46 +00:00
|
|
|
|
2021-11-13 21:57:51 +00:00
|
|
|
foreach ($this->getModules() as $name => $id) {
|
|
|
|
echo
|
|
|
|
'<p><label class="classic" title="' . $id . '">' .
|
|
|
|
form::checkbox(['disabled[]'], $id, ['checked' => array_key_exists($id, $this->improve->disabled())]) .
|
|
|
|
__($name) . '</label></p>';
|
|
|
|
}
|
|
|
|
echo
|
|
|
|
'</div><div class="fieldset"><h4>' . __('Options') . '</h4>' .
|
|
|
|
'<p><label class="classic">' .
|
2022-11-12 21:58:44 +00:00
|
|
|
form::checkbox('nodetails', '1', ['checked' => dcCore::app()->blog->settings->improve->nodetails]) .
|
2021-11-13 21:57:51 +00:00
|
|
|
__('Hide details of rendered actions') . '</label></p>' .
|
|
|
|
'</div>';
|
|
|
|
}
|
2021-11-05 21:52:46 +00:00
|
|
|
}
|
2021-11-13 21:57:51 +00:00
|
|
|
|
|
|
|
/* process */
|
2022-11-12 21:58:44 +00:00
|
|
|
new config();
|