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,21 +10,47 @@
* @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;
}
dcCore::app()->menu[dcAdmin::MENU_SYSTEM]->addItem( namespace Dotclear\Plugin\dcLog;
__('Log'),
dcCore::app()->adminurl->get('admin.plugin.dcLog'), use ArrayObject;
dcPage::getPF('dcLog/icon.svg'), use dcAdmin;
preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.dcLog')) . '(&.*)?$/', $_SERVER['REQUEST_URI']), 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()->auth->isSuperAdmin()
); );
dcCore::app()->addBehavior('adminColumnsListsV2', function (ArrayObject $cols) { dcCore::app()->addBehaviors([
$cols['dcloglist'] = [ 'adminColumnsListsV2' => function (ArrayObject $cols): void {
__('Log'), $cols[My::BACKEND_LIST_ID] = [
My::name(),
[ [
'date' => [true, __('Date')], 'date' => [true, __('Date')],
//'msg' => [true, __('Message')], //'msg' => [true, __('Message')],
@ -34,11 +60,11 @@ dcCore::app()->addBehavior('adminColumnsListsV2', function (ArrayObject $cols) {
'ip' => [false, __('IP')], 'ip' => [false, __('IP')],
], ],
]; ];
}); },
dcCore::app()->addBehavior('adminFiltersListsV2', function (ArrayObject $sorts) { 'adminFiltersListsV2' => function (ArrayObject $sorts): void {
$sorts['dcloglist'] = [ $sorts[My::BACKEND_LIST_ID] = [
__('Log'), My::name(),
[ [
__('Date') => 'log_dt', __('Date') => 'log_dt',
__('Message') => 'log_msg', __('Message') => 'log_msg',
@ -51,14 +77,19 @@ dcCore::app()->addBehavior('adminFiltersListsV2', function (ArrayObject $sorts)
'desc', 'desc',
[__('Logs per page'), 30], [__('Logs per page'), 30],
]; ];
}); },
dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs) { 'adminDashboardFavoritesV2' => function (dcFavorites $favs): void {
$favs->register('dcloglist', [ $favs->register(My::BACKEND_LIST_ID, [
'title' => __('Log'), 'title' => My::name(),
'url' => dcCore::app()->adminurl->get('admin.plugin.dcLog'), 'url' => dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
'small-icon' => dcPage::getPF('dcLog/icon.svg'), 'small-icon' => dcPage::getPF(My::id() . '/icon.svg'),
'large-icon' => dcPage::getPF('dcLog/icon.svg'), 'large-icon' => dcPage::getPF(My::id() . '/icon.svg'),
//'permissions' => null, //'permissions' => null,
]); ]);
}); },
]);
return true;
}
}

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);
} }
@ -97,7 +102,7 @@ class dcLogList extends adminGenericListV2
'</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,75 +10,110 @@
* @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
*/
class Manage extends dcNsProcess
{
public static function init(): bool
{
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 { try {
dcCore::app()->log->delLogs($entries, $del_all_log); dcCore::app()->log->delLogs($entries, $del_all_log);
dcAdminNotices::addSuccessNotice( dcPage::addSuccessNotice(
$del_all_log ? $del_all_log ?
__('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.' . basename(__DIR__)); 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());
} }
} }
$filter = new adminGenericFilterV2('dcloglist'); dcCore::app()->admin->logs_filter = new adminGenericFilterV2('dcloglist');
$filter->add(dcAdminFilters::getPageFilter()); dcCore::app()->admin->logs_filter->add(dcAdminFilters::getPageFilter());
$filter->add(dcAdminFilters::getInputFilter('blog_id', __('Blog:'))); dcCore::app()->admin->logs_filter->add(dcAdminFilters::getInputFilter('blog_id', __('Blog:')));
$filter->add(dcAdminFilters::getInputFilter('user_id', __('User:'))); dcCore::app()->admin->logs_filter->add(dcAdminFilters::getInputFilter('user_id', __('User:')));
$filter->add(dcAdminFilters::getInputFilter('log_table', __('Component:'))); dcCore::app()->admin->logs_filter->add(dcAdminFilters::getInputFilter('log_table', __('Component:')));
$filter->add(dcAdminFilters::getInputFilter('log_ip', __('IP:'))); dcCore::app()->admin->logs_filter->add(dcAdminFilters::getInputFilter('log_ip', __('IP:')));
$params = $filter->params(); $params = dcCore::app()->admin->logs_filter->params();
try { try {
$logs = dcCore::app()->log->getLogs($params); dcCore::app()->admin->logs = dcCore::app()->log->getLogs($params);
$logs_counter = $logs->count(); dcCore::app()->admin->logs_list = new BackendList(dcCore::app()->admin->logs, dcCore::app()->admin->logs->count());
$logs_list = new dcLogList($logs, $logs_counter); } catch (Exception $e) {
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
echo return true;
'<html><head><title>' . __('Log') . '</title>' . }
dcPage::jsJson('dclog_list', [
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_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?'),
]) . ]) .
$filter->js(dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__))) . dcCore::app()->admin->logs_filter->js(dcCore::app()->adminurl->get('admin.plugin.' . My::id())) .
dcPage::jsLoad(dcPage::getPF(basename(__DIR__) . '/js/dclog.js')) . dcPage::jsLoad(dcPage::getPF(My::id() . '/js/backend.js'))
'</head><body>' . );
dcPage::breadcrumb([
__('System') => '',
__('Log') => dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__)),
]) .
dcPage::notices();
if (isset($logs) && isset($logs_list)) { echo
if ($logs->isEmpty() && !$filter->show()) { 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>'; echo '<p>' . __('There are no logs') . '</p>';
} else { } else {
$filter->display( dcCore::app()->admin->logs_filter->display(
'admin.plugin.' . basename(__DIR__), 'admin.plugin.' . My::id(),
form::hidden('p', basename(__DIR__)) form::hidden('p', My::id())
); );
$logs_list->display( dcCore::app()->admin->logs_list->display(
$filter->__get('page'), dcCore::app()->admin->logs_filter->__get('page'),
$filter->__get('nb'), dcCore::app()->admin->logs_filter->__get('nb'),
'<form action="' . dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__)) . '" method="post" id="form-entries">' . '<form action="' . dcCore::app()->adminurl->get('admin.plugin.' . My::id()) . '" method="post" id="form-entries">' .
'%s' . '%s' .
@ -90,13 +125,15 @@ if (isset($logs) && isset($logs_list)) {
'<input type="submit" value="' . __('Delete all logs') . '" name="del_all_logs" />' . '<input type="submit" value="' . __('Delete all logs') . '" name="del_all_logs" />' .
'</p>' . '</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() . dcCore::app()->formNonce() .
'</div>' . '</div>' .
'</form>', '</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']);