add container for admin vars (and fix phpstan lvl 8 warnings)
This commit is contained in:
parent
cb52f33cd1
commit
5c20252fa9
@ -43,10 +43,10 @@ class Backend extends dcNsProcess
|
|||||||
|
|
||||||
dcCore::app()->menu[dcAdmin::MENU_SYSTEM]->addItem(
|
dcCore::app()->menu[dcAdmin::MENU_SYSTEM]->addItem(
|
||||||
My::name(),
|
My::name(),
|
||||||
dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
|
dcCore::app()->adminurl?->get('admin.plugin.' . My::id()),
|
||||||
dcPage::getPF(My::id() . '/icon.svg'),
|
dcPage::getPF(My::id() . '/icon.svg'),
|
||||||
preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
|
preg_match('/' . preg_quote((string) dcCore::app()->adminurl?->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
|
||||||
dcCore::app()->auth->isSuperAdmin()
|
dcCore::app()->auth?->isSuperAdmin()
|
||||||
);
|
);
|
||||||
|
|
||||||
dcCore::app()->addBehaviors([
|
dcCore::app()->addBehaviors([
|
||||||
@ -84,7 +84,7 @@ class Backend extends dcNsProcess
|
|||||||
'adminDashboardFavoritesV2' => function (dcFavorites $favs): void {
|
'adminDashboardFavoritesV2' => function (dcFavorites $favs): void {
|
||||||
$favs->register(My::BACKEND_LIST_ID, [
|
$favs->register(My::BACKEND_LIST_ID, [
|
||||||
'title' => My::name(),
|
'title' => My::name(),
|
||||||
'url' => dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
|
'url' => dcCore::app()->adminurl?->get('admin.plugin.' . My::id()),
|
||||||
'small-icon' => dcPage::getPF(My::id() . '/icon.svg'),
|
'small-icon' => dcPage::getPF(My::id() . '/icon.svg'),
|
||||||
'large-icon' => dcPage::getPF(My::id() . '/icon.svg'),
|
'large-icon' => dcPage::getPF(My::id() . '/icon.svg'),
|
||||||
//'permissions' => null,
|
//'permissions' => null,
|
||||||
|
@ -23,7 +23,7 @@ use html;
|
|||||||
|
|
||||||
class BackendList extends adminGenericListV2
|
class BackendList extends adminGenericListV2
|
||||||
{
|
{
|
||||||
public function display($page, $nb_per_page, $enclose_block = '', $filter = false)
|
public function display(int $page, int $nb_per_page, string $enclose_block = '', bool $filter = false): void
|
||||||
{
|
{
|
||||||
if ($this->rs->isEmpty()) {
|
if ($this->rs->isEmpty()) {
|
||||||
echo $filter ?
|
echo $filter ?
|
||||||
@ -73,7 +73,7 @@ class BackendList extends adminGenericListV2
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function logLine($checked)
|
private function logLine(bool $checked): void
|
||||||
{
|
{
|
||||||
$cols = [
|
$cols = [
|
||||||
'check' => '<td class="nowrap minimal">' .
|
'check' => '<td class="nowrap minimal">' .
|
||||||
|
@ -14,8 +14,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Dotclear\Plugin\dcLog;
|
namespace Dotclear\Plugin\dcLog;
|
||||||
|
|
||||||
use adminGenericFilterV2;
|
|
||||||
use dcAdminFilters;
|
|
||||||
use dcCore;
|
use dcCore;
|
||||||
use dcNsProcess;
|
use dcNsProcess;
|
||||||
use dcPage;
|
use dcPage;
|
||||||
@ -42,41 +40,23 @@ class Manage extends dcNsProcess
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
dcCore::app()->admin->logs = dcCore::app()->admin->logs_list = dcCore::app()->admin->logs_filter = null;
|
$current = ManageVars::init();
|
||||||
|
|
||||||
$entries = $_POST['entries'] ?? null;
|
|
||||||
$del_all_log = isset($_POST['del_all_logs']) ? true : false;
|
|
||||||
|
|
||||||
# Delete logs
|
# Delete logs
|
||||||
if (isset($_POST['del_logs']) || isset($_POST['del_all_logs'])) {
|
if ($current->selected_logs || $current->all_logs) {
|
||||||
try {
|
try {
|
||||||
dcCore::app()->log->delLogs($entries, $del_all_log);
|
dcCore::app()->log->delLogs($current->entries, $current->all_logs);
|
||||||
dcPage::addSuccessNotice(
|
dcPage::addSuccessNotice(
|
||||||
$del_all_log ?
|
$current->all_logs ?
|
||||||
__('All logs have been successfully deleted') :
|
__('All logs have been successfully deleted') :
|
||||||
__('Selected logs have been successfully deleted')
|
__('Selected logs have been successfully deleted')
|
||||||
);
|
);
|
||||||
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id());
|
dcCore::app()->adminurl?->redirect('admin.plugin.' . My::id());
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
dcCore::app()->error->add($e->getMessage());
|
dcCore::app()->error->add($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dcCore::app()->admin->logs_filter = new adminGenericFilterV2('dcloglist');
|
|
||||||
dcCore::app()->admin->logs_filter->add(dcAdminFilters::getPageFilter());
|
|
||||||
dcCore::app()->admin->logs_filter->add(dcAdminFilters::getInputFilter('blog_id', __('Blog:')));
|
|
||||||
dcCore::app()->admin->logs_filter->add(dcAdminFilters::getInputFilter('user_id', __('User:')));
|
|
||||||
dcCore::app()->admin->logs_filter->add(dcAdminFilters::getInputFilter('log_table', __('Component:')));
|
|
||||||
dcCore::app()->admin->logs_filter->add(dcAdminFilters::getInputFilter('log_ip', __('IP:')));
|
|
||||||
$params = dcCore::app()->admin->logs_filter->params();
|
|
||||||
|
|
||||||
try {
|
|
||||||
dcCore::app()->admin->logs = dcCore::app()->log->getLogs($params);
|
|
||||||
dcCore::app()->admin->logs_list = new BackendList(dcCore::app()->admin->logs, dcCore::app()->admin->logs->count());
|
|
||||||
} catch (Exception $e) {
|
|
||||||
dcCore::app()->error->add($e->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,13 +66,15 @@ class Manage extends dcNsProcess
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$current = ManageVars::init();
|
||||||
|
|
||||||
dcPage::openModule(
|
dcPage::openModule(
|
||||||
__('Pings'),
|
__('Pings'),
|
||||||
dcPage::jsJson('dclog_list', [
|
dcPage::jsJson('dclog_list', [
|
||||||
'confirm_delete_selected_log' => __('Are you sure you want to delete selected logs?'),
|
'confirm_delete_selected_log' => __('Are you sure you want to delete selected logs?'),
|
||||||
'confirm_delete_all_log' => __('Are you sure you want to delete all logs?'),
|
'confirm_delete_all_log' => __('Are you sure you want to delete all logs?'),
|
||||||
]) .
|
]) .
|
||||||
dcCore::app()->admin->logs_filter->js(dcCore::app()->adminurl->get('admin.plugin.' . My::id())) .
|
$current->filter->js((string) dcCore::app()->adminurl?->get('admin.plugin.' . My::id())) .
|
||||||
dcPage::jsLoad(dcPage::getPF(My::id() . '/js/backend.js'))
|
dcPage::jsLoad(dcPage::getPF(My::id() . '/js/backend.js'))
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -100,23 +82,23 @@ class Manage extends dcNsProcess
|
|||||||
dcPage::breadcrumb(
|
dcPage::breadcrumb(
|
||||||
[
|
[
|
||||||
__('System') => '',
|
__('System') => '',
|
||||||
My::name() => dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
|
My::name() => dcCore::app()->adminurl?->get('admin.plugin.' . My::id()),
|
||||||
]
|
]
|
||||||
) .
|
) .
|
||||||
dcPage::notices();
|
dcPage::notices();
|
||||||
|
|
||||||
if (isset(dcCore::app()->admin->logs) && isset(dcCore::app()->admin->logs_list)) {
|
if ($current->logs !== null && $current->list != null) {
|
||||||
if (dcCore::app()->admin->logs->isEmpty() && !dcCore::app()->admin->logs_filter->show()) {
|
if ($current->logs->isEmpty() && !$current->filter->show()) {
|
||||||
echo '<p>' . __('There are no logs') . '</p>';
|
echo '<p>' . __('There are no logs') . '</p>';
|
||||||
} else {
|
} else {
|
||||||
dcCore::app()->admin->logs_filter->display(
|
$current->filter->display(
|
||||||
'admin.plugin.' . My::id(),
|
'admin.plugin.' . My::id(),
|
||||||
form::hidden('p', My::id())
|
form::hidden('p', My::id())
|
||||||
);
|
);
|
||||||
dcCore::app()->admin->logs_list->display(
|
$current->list->display(
|
||||||
dcCore::app()->admin->logs_filter->__get('page'),
|
(int) $current->filter->__get('page'),
|
||||||
dcCore::app()->admin->logs_filter->__get('nb'),
|
(int) $current->filter->__get('nb'),
|
||||||
'<form action="' . dcCore::app()->adminurl->get('admin.plugin.' . My::id()) . '" method="post" id="form-entries">' .
|
'<form action="' . dcCore::app()->adminurl?->get('admin.plugin.' . My::id()) . '" method="post" id="form-entries">' .
|
||||||
|
|
||||||
'%s' .
|
'%s' .
|
||||||
|
|
||||||
@ -124,15 +106,15 @@ class Manage extends dcNsProcess
|
|||||||
'<p class="col checkboxes-helpers"></p>' .
|
'<p class="col checkboxes-helpers"></p>' .
|
||||||
|
|
||||||
'<p class="col right">' .
|
'<p class="col right">' .
|
||||||
'<input type="submit" value="' . __('Delete selected logs') . '" name="del_logs" /> ' .
|
'<input type="submit" value="' . __('Delete selected logs') . '" name="selected_logs" /> ' .
|
||||||
'<input type="submit" value="' . __('Delete all logs') . '" name="del_all_logs" />' .
|
'<input type="submit" value="' . __('Delete all logs') . '" name="all_logs" />' .
|
||||||
'</p>' .
|
'</p>' .
|
||||||
|
|
||||||
dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.' . My::id(), dcCore::app()->admin->logs_filter->values()) .
|
dcCore::app()->adminurl?->getHiddenFormFields('admin.plugin.' . My::id(), $current->filter->values()) .
|
||||||
dcCore::app()->formNonce() .
|
dcCore::app()->formNonce() .
|
||||||
'</div>' .
|
'</div>' .
|
||||||
'</form>',
|
'</form>',
|
||||||
dcCore::app()->admin->logs_filter->show()
|
$current->filter->show()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
67
src/ManageVars.php
Normal file
67
src/ManageVars.php
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @brief dcLog, a plugin for Dotclear 2
|
||||||
|
*
|
||||||
|
* @package Dotclear
|
||||||
|
* @subpackage Plugin
|
||||||
|
*
|
||||||
|
* @author Tomtom 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\dcLog;
|
||||||
|
|
||||||
|
use adminGenericFilterV2;
|
||||||
|
use dcAdminFilters;
|
||||||
|
use dcCore;
|
||||||
|
use dcRecord;
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class ManageVars
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var ManageVars self instance
|
||||||
|
*/
|
||||||
|
private static $container;
|
||||||
|
|
||||||
|
public readonly adminGenericFilterV2 $filter;
|
||||||
|
public readonly ?dcRecord $logs;
|
||||||
|
public readonly ?BackendList $list;
|
||||||
|
public readonly array $entries;
|
||||||
|
public readonly bool $selected_logs;
|
||||||
|
public readonly bool $all_logs;
|
||||||
|
|
||||||
|
protected function __construct()
|
||||||
|
{
|
||||||
|
$this->entries = !empty($_POST['entries']) && is_array($_POST['entries']) ? $_POST['entries'] : [];
|
||||||
|
$this->all_logs = isset($_POST['all_logs']);
|
||||||
|
$this->selected_logs = isset($_POST['selected_logs']);
|
||||||
|
|
||||||
|
$this->filter = new adminGenericFilterV2('dcloglist');
|
||||||
|
$this->filter->add(dcAdminFilters::getPageFilter());
|
||||||
|
$this->filter->add(dcAdminFilters::getInputFilter('blog_id', __('Blog:')));
|
||||||
|
$this->filter->add(dcAdminFilters::getInputFilter('user_id', __('User:')));
|
||||||
|
$this->filter->add(dcAdminFilters::getInputFilter('log_table', __('Component:')));
|
||||||
|
$this->filter->add(dcAdminFilters::getInputFilter('log_ip', __('IP:')));
|
||||||
|
$params = $this->filter->params();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->logs = dcCore::app()->log->getLogs($params);
|
||||||
|
$this->list = new BackendList($this->logs, $this->logs->count());
|
||||||
|
} catch (Exception $e) {
|
||||||
|
dcCore::app()->error->add($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function init(): ManageVars
|
||||||
|
{
|
||||||
|
if (!(self::$container instanceof self)) {
|
||||||
|
self::$container = new self();
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$container;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user