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 1.1.1
- use abstract plugin name - use abstract plugin name
- fix permissions - fix permissions

View File

@ -15,12 +15,12 @@ if (!defined('DC_RC_PATH')) {
} }
$this->registerModule( $this->registerModule(
'dcLog', 'Logs',
'Displays Dotclear logs', 'Displays Dotclear logs',
'Tomtom and Contributors', 'Tomtom and Contributors',
'1.1.1', '1.2',
[ [
'requires' => [['core', '2.24']], 'requires' => [['core', '2.26']],
'permissions' => null, 'permissions' => null,
'type' => 'plugin', 'type' => 'plugin',
'support' => 'https://github.com/JcDenis/' . basename(__DIR__), '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 "" msgid ""
msgstr "" msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "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" "POT-Creation-Date: \n"
"PO-Revision-Date: 2022-11-27T20:16:51+00:00\n" "PO-Revision-Date: 2023-03-11T14:48:16+00:00\n"
"Last-Translator: Jean-Crhistian Denis\n" "Last-Translator: Jean-Christian Denis\n"
"Language-Team: \n" "Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n"
msgid "Log"
msgstr "Log"
msgid "Message" msgid "Message"
msgstr "Message" msgstr "Message"
@ -34,6 +31,9 @@ msgstr "Aucun log"
msgid "List of %s logs matching the filter." msgid "List of %s logs matching the filter."
msgstr "Liste des %s logs correspondants au filtre." 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" msgid "All logs have been successfully deleted"
msgstr "Tous les logs ont été supprimé avec succès" 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" msgid "Delete all logs"
msgstr "Supprimer tous les logs" msgstr "Supprimer tous les logs"
msgid "Logs"
msgstr "Enregistrements"

View File

@ -10,55 +10,86 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { declare(strict_types=1);
return null;
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(
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()->addBehaviors([
'adminColumnsListsV2' => function (ArrayObject $cols): void {
$cols[My::BACKEND_LIST_ID] = [
My::name(),
[
'date' => [true, __('Date')],
//'msg' => [true, __('Message')],
'blog' => [true, __('Blog')],
'table' => [true, __('Component')],
'user' => [true, __('User')],
'ip' => [false, __('IP')],
],
];
},
'adminFiltersListsV2' => function (ArrayObject $sorts): void {
$sorts[My::BACKEND_LIST_ID] = [
My::name(),
[
__('Date') => 'log_dt',
__('Message') => 'log_msg',
__('Blog') => 'blog_id',
__('Component') => 'log_table',
__('User') => 'user_id',
__('IP') => 'log_ip',
],
'log_dt',
'desc',
[__('Logs per page'), 30],
];
},
'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;
}
} }
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']),
dcCore::app()->auth->isSuperAdmin()
);
dcCore::app()->addBehavior('adminColumnsListsV2', function (ArrayObject $cols) {
$cols['dcloglist'] = [
__('Log'),
[
'date' => [true, __('Date')],
//'msg' => [true, __('Message')],
'blog' => [true, __('Blog')],
'table' => [true, __('Component')],
'user' => [true, __('User')],
'ip' => [false, __('IP')],
],
];
});
dcCore::app()->addBehavior('adminFiltersListsV2', function (ArrayObject $sorts) {
$sorts['dcloglist'] = [
__('Log'),
[
__('Date') => 'log_dt',
__('Message') => 'log_msg',
__('Blog') => 'blog_id',
__('Component') => 'log_table',
__('User') => 'user_id',
__('IP') => 'log_ip',
],
'log_dt',
'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'),
//'permissions' => null,
]);
});

View File

@ -10,20 +10,25 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { declare(strict_types=1);
return null;
}
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) public function display($page, $nb_per_page, $enclose_block = '', $filter = false)
{ {
if ($this->rs->isEmpty()) { if ($this->rs->isEmpty()) {
if ($filter) { echo $filter ?
echo '<p><strong>' . __('No log matches the filter') . '</strong></p>'; '<p><strong>' . __('No log matches the filter') . '</strong></p>' :
} else { '<p><strong>' . __('No log') . '</strong></p>';
echo '<p><strong>' . __('No log') . '</strong></p>';
}
} else { } else {
$pager = new dcPager($page, $this->rs_count, $nb_per_page, 10); $pager = new dcPager($page, $this->rs_count, $nb_per_page, 10);
$entries = []; $entries = [];
@ -42,16 +47,16 @@ class dcLogList extends adminGenericListV2
'ip' => '<th scope="col">' . __('IP') . '</th>', 'ip' => '<th scope="col">' . __('IP') . '</th>',
]; ];
$cols = new ArrayObject($cols); $cols = new ArrayObject($cols);
$this->userColumns('dcloglist', $cols); $this->userColumns(My::BACKEND_LIST_ID, $cols);
$html_block = '<div class="table-outer">' . $html_block = '<div class="table-outer"><table><caption>' .
'<table>'; (
$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) { if ($enclose_block) {
$html_block = sprintf($enclose_block, $html_block); $html_block = sprintf($enclose_block, $html_block);
} }
@ -74,30 +79,30 @@ class dcLogList extends adminGenericListV2
'check' => '<td class="nowrap minimal">' . 'check' => '<td class="nowrap minimal">' .
form::checkbox(['entries[]'], $this->rs->log_id, ['checked' => $checked]) . form::checkbox(['entries[]'], $this->rs->log_id, ['checked' => $checked]) .
'</td>', '</td>',
'date' => '<td class="nowrap minimal">' . 'date' => '<td class="nowrap minimal">' .
html::escapeHTML(dt::dt2str( html::escapeHTML(dt::dt2str(
__('%Y-%m-%d %H:%M'), __('%Y-%m-%d %H:%M'),
$this->rs->log_dt $this->rs->log_dt
)) . )) .
'</td>', '</td>',
'msg' => '<td class="maximal">' . 'msg' => '<td class="maximal">' .
nl2br(html::escapeHTML($this->rs->log_msg)) . nl2br(html::escapeHTML($this->rs->log_msg)) .
'</td>', '</td>',
'blog' => '<td class="minimal nowrap">' . 'blog' => '<td class="minimal nowrap">' .
html::escapeHTML($this->rs->blog_id) . html::escapeHTML($this->rs->blog_id) .
'</td>', '</td>',
'table' => '<td class="minimal nowrap">' . 'table' => '<td class="minimal nowrap">' .
html::escapeHTML($this->rs->log_table) . html::escapeHTML($this->rs->log_table) .
'</td>', '</td>',
'user' => '<td class="minimal nowrap">' . 'user' => '<td class="minimal nowrap">' .
html::escapeHTML($this->rs->getUserCN()) . html::escapeHTML($this->rs->getUserCN()) .
'</td>', '</td>',
'ip' => '<td class="minimal nowrap">' . 'ip' => '<td class="minimal nowrap">' .
html::escapeHTML($this->rs->log_ip) . html::escapeHTML($this->rs->log_ip) .
'</td>', '</td>',
]; ];
$cols = new ArrayObject($cols); $cols = new ArrayObject($cols);
$this->userColumns('dcloglist', $cols); $this->userColumns(My::BACKEND_LIST_ID, $cols);
echo echo
'<tr class="line" id="p' . $this->rs->log_id . '">' . '<tr class="line" id="p' . $this->rs->log_id . '">' .

View File

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

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']);