move to namespace

This commit is contained in:
Jean-Christian Paul Denis 2023-03-11 15:53:06 +01:00
parent 5e6125eb85
commit eeceb3ee92
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
9 changed files with 317 additions and 184 deletions

View File

@ -1,3 +1,9 @@
1.2 - xxxx.xx.xx
- Update to Dotclear 2.26
- use abstract plugin id
- use php namespace
- use dcPage open/close method
1.1.1
- use abstract plugin name
- fix permissions

View File

@ -15,12 +15,12 @@ if (!defined('DC_RC_PATH')) {
}
$this->registerModule(
'dcLog',
'Logs',
'Displays Dotclear logs',
'Tomtom and Contributors',
'1.1.1',
'1.2',
[
'requires' => [['core', '2.24']],
'requires' => [['core', '2.26']],
'permissions' => null,
'type' => 'plugin',
'support' => 'https://github.com/JcDenis/' . basename(__DIR__),

30
locales/fr/main.lang.php Normal file
View File

@ -0,0 +1,30 @@
<?php
/**
* @package Dotclear
*
* @copyright Olivier Meunier & Association Dotclear
* @copyright GPL-2.0-only
*/
#
# DOT NOT MODIFY THIS FILE !
#
l10n::$locales['Message'] = 'Message';
l10n::$locales['Component'] = 'Composant';
l10n::$locales['User'] = 'Utilisateur';
l10n::$locales['Logs per page'] = 'Logs par page';
l10n::$locales['No log matches the filter'] = 'Aucun log ne correspond au filtre';
l10n::$locales['No log'] = 'Aucun log';
l10n::$locales['List of %s logs matching the filter.'] = 'Liste des %s logs correspondants au filtre.';
l10n::$locales['List of logs. (%s)'] = 'Liste des logs. (%s)';
l10n::$locales['All logs have been successfully deleted'] = 'Tous les logs ont été supprimé avec succès';
l10n::$locales['Selected logs have been successfully deleted'] = 'Les logs sélectionnés ont été supprimé avec succès';
l10n::$locales['User:'] = 'Utilisateur :';
l10n::$locales['Component:'] = 'Composant :';
l10n::$locales['IP:'] = 'IP :';
l10n::$locales['Are you sure you want to delete selected logs?'] = 'Êtes vous sur de vouloir supprimer les logs sélectionnés?';
l10n::$locales['Are you sure you want to delete all logs?'] = 'Êtes vous sur de vouloir supprimer tous les logs';
l10n::$locales['There are no logs'] = 'Il n\'y a aucun log';
l10n::$locales['Delete selected logs'] = 'Supprimer les logs sélectionnés';
l10n::$locales['Delete all logs'] = 'Supprimer tous les logs';
l10n::$locales['Logs'] = 'Enregistrements';

View File

@ -1,18 +1,15 @@
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Project-Id-Version: dcLog 1.1\n"
"Project-Id-Version: dcLog 1.2\n"
"POT-Creation-Date: \n"
"PO-Revision-Date: 2022-11-27T20:16:51+00:00\n"
"Last-Translator: Jean-Crhistian Denis\n"
"PO-Revision-Date: 2023-03-11T14:48:16+00:00\n"
"Last-Translator: Jean-Christian Denis\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
msgid "Log"
msgstr "Log"
msgid "Message"
msgstr "Message"
@ -34,6 +31,9 @@ msgstr "Aucun log"
msgid "List of %s logs matching the filter."
msgstr "Liste des %s logs correspondants au filtre."
msgid "List of logs. (%s)"
msgstr "Liste des logs. (%s)"
msgid "All logs have been successfully deleted"
msgstr "Tous les logs ont été supprimé avec succès"
@ -64,3 +64,6 @@ msgstr "Supprimer les logs sélectionnés"
msgid "Delete all logs"
msgstr "Supprimer tous les logs"
msgid "Logs"
msgstr "Enregistrements"

View File

@ -10,21 +10,47 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
declare(strict_types=1);
namespace Dotclear\Plugin\dcLog;
use ArrayObject;
use dcAdmin;
use dcCore;
use dcFavorites;
use dcNsProcess;
use dcPage;
/**
* Manage contributions list
*/
class Backend extends dcNsProcess
{
public static function init(): bool
{
self::$init = defined('DC_CONTEXT_ADMIN');
return self::$init;
}
public static function process(): bool
{
if (!self::$init) {
return false;
}
dcCore::app()->menu[dcAdmin::MENU_SYSTEM]->addItem(
__('Log'),
dcCore::app()->adminurl->get('admin.plugin.dcLog'),
dcPage::getPF('dcLog/icon.svg'),
preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.dcLog')) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
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->isSuperAdmin()
);
dcCore::app()->addBehavior('adminColumnsListsV2', function (ArrayObject $cols) {
$cols['dcloglist'] = [
__('Log'),
dcCore::app()->addBehaviors([
'adminColumnsListsV2' => function (ArrayObject $cols): void {
$cols[My::BACKEND_LIST_ID] = [
My::name(),
[
'date' => [true, __('Date')],
//'msg' => [true, __('Message')],
@ -34,11 +60,11 @@ dcCore::app()->addBehavior('adminColumnsListsV2', function (ArrayObject $cols) {
'ip' => [false, __('IP')],
],
];
});
},
dcCore::app()->addBehavior('adminFiltersListsV2', function (ArrayObject $sorts) {
$sorts['dcloglist'] = [
__('Log'),
'adminFiltersListsV2' => function (ArrayObject $sorts): void {
$sorts[My::BACKEND_LIST_ID] = [
My::name(),
[
__('Date') => 'log_dt',
__('Message') => 'log_msg',
@ -51,14 +77,19 @@ dcCore::app()->addBehavior('adminFiltersListsV2', function (ArrayObject $sorts)
'desc',
[__('Logs per page'), 30],
];
});
},
dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs) {
$favs->register('dcloglist', [
'title' => __('Log'),
'url' => dcCore::app()->adminurl->get('admin.plugin.dcLog'),
'small-icon' => dcPage::getPF('dcLog/icon.svg'),
'large-icon' => dcPage::getPF('dcLog/icon.svg'),
'adminDashboardFavoritesV2' => function (dcFavorites $favs): void {
$favs->register(My::BACKEND_LIST_ID, [
'title' => My::name(),
'url' => dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
'small-icon' => dcPage::getPF(My::id() . '/icon.svg'),
'large-icon' => dcPage::getPF(My::id() . '/icon.svg'),
//'permissions' => null,
]);
});
},
]);
return true;
}
}

View File

@ -10,20 +10,25 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
}
declare(strict_types=1);
class dcLogList extends adminGenericListV2
namespace Dotclear\Plugin\dcLog;
use ArrayObject;
use adminGenericListV2;
use dcPager;
use dt;
use form;
use html;
class BackendList extends adminGenericListV2
{
public function display($page, $nb_per_page, $enclose_block = '', $filter = false)
{
if ($this->rs->isEmpty()) {
if ($filter) {
echo '<p><strong>' . __('No log matches the filter') . '</strong></p>';
} else {
echo '<p><strong>' . __('No log') . '</strong></p>';
}
echo $filter ?
'<p><strong>' . __('No log matches the filter') . '</strong></p>' :
'<p><strong>' . __('No log') . '</strong></p>';
} else {
$pager = new dcPager($page, $this->rs_count, $nb_per_page, 10);
$entries = [];
@ -42,16 +47,16 @@ class dcLogList extends adminGenericListV2
'ip' => '<th scope="col">' . __('IP') . '</th>',
];
$cols = new ArrayObject($cols);
$this->userColumns('dcloglist', $cols);
$this->userColumns(My::BACKEND_LIST_ID, $cols);
$html_block = '<div class="table-outer">' .
'<table>';
$html_block = '<div class="table-outer"><table><caption>' .
(
$filter ?
sprintf(__('List of %s logs matching the filter.'), $this->rs_count) :
sprintf(__('List of logs. (%s)'), $this->rs_count)
) .
'</caption><tr>' . implode(iterator_to_array($cols)) . '</tr>%s</table>%s</div>';
if ($filter) {
$html_block .= '<caption>' . sprintf(__('List of %s logs matching the filter.'), $this->rs_count) . '</caption>';
}
$html_block .= '<tr>' . implode(iterator_to_array($cols)) . '</tr>%s</table>%s</div>';
if ($enclose_block) {
$html_block = sprintf($enclose_block, $html_block);
}
@ -97,7 +102,7 @@ class dcLogList extends adminGenericListV2
'</td>',
];
$cols = new ArrayObject($cols);
$this->userColumns('dcloglist', $cols);
$this->userColumns(My::BACKEND_LIST_ID, $cols);
echo
'<tr class="line" id="p' . $this->rs->log_id . '">' .

View File

@ -10,14 +10,41 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
declare(strict_types=1);
namespace Dotclear\Plugin\dcLog;
use adminGenericFilterV2;
use dcAdminFilters;
use dcCore;
use dcNsProcess;
use dcPage;
use Exception;
use form;
/**
* Manage logs list
*/
class Manage extends dcNsProcess
{
public static function init(): bool
{
if (defined('DC_CONTEXT_ADMIN')) {
dcPage::checkSuper();
self::$init = true;
}
if (!dcCore::app()->auth->isSuperAdmin()) {
return null;
return self::$init;
}
public static function process(): bool
{
if (!self::$init) {
return false;
}
dcCore::app()->admin->logs = dcCore::app()->admin->logs_list = dcCore::app()->admin->logs_filter = null;
$entries = $_POST['entries'] ?? null;
$del_all_log = isset($_POST['del_all_logs']) ? true : false;
@ -25,60 +52,68 @@ $del_all_log = isset($_POST['del_all_logs']) ? true : false;
if (isset($_POST['del_logs']) || isset($_POST['del_all_logs'])) {
try {
dcCore::app()->log->delLogs($entries, $del_all_log);
dcAdminNotices::addSuccessNotice(
dcPage::addSuccessNotice(
$del_all_log ?
__('All logs have been successfully deleted') :
__('Selected logs have been successfully deleted')
);
dcCore::app()->adminurl->redirect('admin.plugin.' . basename(__DIR__));
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id());
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
}
}
$filter = new adminGenericFilterV2('dcloglist');
$filter->add(dcAdminFilters::getPageFilter());
$filter->add(dcAdminFilters::getInputFilter('blog_id', __('Blog:')));
$filter->add(dcAdminFilters::getInputFilter('user_id', __('User:')));
$filter->add(dcAdminFilters::getInputFilter('log_table', __('Component:')));
$filter->add(dcAdminFilters::getInputFilter('log_ip', __('IP:')));
$params = $filter->params();
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 {
$logs = dcCore::app()->log->getLogs($params);
$logs_counter = $logs->count();
$logs_list = new dcLogList($logs, $logs_counter);
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());
}
echo
'<html><head><title>' . __('Log') . '</title>' .
return true;
}
public static function render(): void
{
dcPage::openModule(
__('Pings'),
dcPage::jsJson('dclog_list', [
'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?'),
]) .
$filter->js(dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__))) .
dcPage::jsLoad(dcPage::getPF(basename(__DIR__) . '/js/dclog.js')) .
'</head><body>' .
dcPage::breadcrumb([
dcCore::app()->admin->logs_filter->js(dcCore::app()->adminurl->get('admin.plugin.' . My::id())) .
dcPage::jsLoad(dcPage::getPF(My::id() . '/js/backend.js'))
);
echo
dcPage::breadcrumb(
[
__('System') => '',
__('Log') => dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__)),
]) .
My::name() => dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
]
) .
dcPage::notices();
if (isset($logs) && isset($logs_list)) {
if ($logs->isEmpty() && !$filter->show()) {
if (isset(dcCore::app()->admin->logs) && isset(dcCore::app()->admin->logs_list)) {
if (dcCore::app()->admin->logs->isEmpty() && !dcCore::app()->admin->logs_filter->show()) {
echo '<p>' . __('There are no logs') . '</p>';
} else {
$filter->display(
'admin.plugin.' . basename(__DIR__),
form::hidden('p', basename(__DIR__))
dcCore::app()->admin->logs_filter->display(
'admin.plugin.' . My::id(),
form::hidden('p', My::id())
);
$logs_list->display(
$filter->__get('page'),
$filter->__get('nb'),
'<form action="' . dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__)) . '" method="post" id="form-entries">' .
dcCore::app()->admin->logs_list->display(
dcCore::app()->admin->logs_filter->__get('page'),
dcCore::app()->admin->logs_filter->__get('nb'),
'<form action="' . dcCore::app()->adminurl->get('admin.plugin.' . My::id()) . '" method="post" id="form-entries">' .
'%s' .
@ -90,13 +125,15 @@ if (isset($logs) && isset($logs_list)) {
'<input type="submit" value="' . __('Delete all logs') . '" name="del_all_logs" />' .
'</p>' .
dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.' . basename(__DIR__), $filter->values()) .
dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.' . My::id(), dcCore::app()->admin->logs_filter->values()) .
dcCore::app()->formNonce() .
'</div>' .
'</form>',
$filter->show()
dcCore::app()->admin->logs_filter->show()
);
}
}
echo '</body></html>';
dcPage::closeModule();
}
}

38
src/My.php Normal file
View File

@ -0,0 +1,38 @@
<?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 dcCore;
class My
{
public const BACKEND_LIST_ID = 'dcloglist';
/**
* This module id
*/
public static function id(): string
{
return basename(dirname(__DIR__));
}
/**
* This module name
*/
public static function name(): string
{
return __((string) dcCore::app()->plugins->moduleInfo(self::id(), 'name'));
}
}

View File

@ -1,17 +0,0 @@
<?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
*/
if (!defined('DC_RC_PATH')) {
return null;
}
Clearbricks::lib()->autoload(['dcLogList' => __DIR__ . '/inc/class.dc.log.list.php']);