diff --git a/CHANGELOG.md b/CHANGELOG.md index c3da2e5..da95774 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/_define.php b/_define.php index 95eac09..824e882 100644 --- a/_define.php +++ b/_define.php @@ -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__), diff --git a/locales/fr/main.lang.php b/locales/fr/main.lang.php new file mode 100644 index 0000000..b962577 --- /dev/null +++ b/locales/fr/main.lang.php @@ -0,0 +1,30 @@ + 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" + diff --git a/src/Backend.php b/src/Backend.php index 1c7515e..24f47ac 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -10,55 +10,86 @@ * @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( + 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, - ]); -}); diff --git a/src/BackendList.php b/src/BackendList.php index 503759c..c35ef94 100644 --- a/src/BackendList.php +++ b/src/BackendList.php @@ -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 '

' . __('No log matches the filter') . '

'; - } else { - echo '

' . __('No log') . '

'; - } + echo $filter ? + '

' . __('No log matches the filter') . '

' : + '

' . __('No log') . '

'; } else { $pager = new dcPager($page, $this->rs_count, $nb_per_page, 10); $entries = []; @@ -42,16 +47,16 @@ class dcLogList extends adminGenericListV2 'ip' => '' . __('IP') . '', ]; $cols = new ArrayObject($cols); - $this->userColumns('dcloglist', $cols); + $this->userColumns(My::BACKEND_LIST_ID, $cols); - $html_block = '
' . - ''; + $html_block = '
' . implode(iterator_to_array($cols)) . '%s
' . + ( + $filter ? + sprintf(__('List of %s logs matching the filter.'), $this->rs_count) : + sprintf(__('List of logs. (%s)'), $this->rs_count) + ) . + '
%s
'; - if ($filter) { - $html_block .= '' . sprintf(__('List of %s logs matching the filter.'), $this->rs_count) . ''; - } - - $html_block .= '' . implode(iterator_to_array($cols)) . '%s%s'; if ($enclose_block) { $html_block = sprintf($enclose_block, $html_block); } @@ -74,30 +79,30 @@ class dcLogList extends adminGenericListV2 'check' => '' . form::checkbox(['entries[]'], $this->rs->log_id, ['checked' => $checked]) . '', - 'date' => '' . + 'date' => '' . html::escapeHTML(dt::dt2str( __('%Y-%m-%d %H:%M'), $this->rs->log_dt )) . '', - 'msg' => '' . + 'msg' => '' . nl2br(html::escapeHTML($this->rs->log_msg)) . '', - 'blog' => '' . + 'blog' => '' . html::escapeHTML($this->rs->blog_id) . '', 'table' => '' . html::escapeHTML($this->rs->log_table) . '', - 'user' => '' . + 'user' => '' . html::escapeHTML($this->rs->getUserCN()) . '', - 'ip' => '' . + 'ip' => '' . html::escapeHTML($this->rs->log_ip) . '', ]; $cols = new ArrayObject($cols); - $this->userColumns('dcloglist', $cols); + $this->userColumns(My::BACKEND_LIST_ID, $cols); echo '' . diff --git a/src/Manage.php b/src/Manage.php index 064171d..5ad0e04 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -10,93 +10,130 @@ * @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); -if (!dcCore::app()->auth->isSuperAdmin()) { - return null; -} +namespace Dotclear\Plugin\dcLog; -$entries = $_POST['entries'] ?? null; -$del_all_log = isset($_POST['del_all_logs']) ? true : false; +use adminGenericFilterV2; +use dcAdminFilters; +use dcCore; +use dcNsProcess; +use dcPage; +use Exception; +use form; -# Delete logs -if (isset($_POST['del_logs']) || isset($_POST['del_all_logs'])) { - try { - dcCore::app()->log->delLogs($entries, $del_all_log); - dcAdminNotices::addSuccessNotice( - $del_all_log ? - __('All logs have been successfully deleted') : - __('Selected logs have been successfully deleted') +/** + * 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 { + 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) { - dcCore::app()->error->add($e->getMessage()); + + echo + 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 '

' . __('There are no logs') . '

'; + } 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'), + '
' . + + '%s' . + + '
' . + '

' . + + '

' . + ' ' . + '' . + '

' . + + dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.' . My::id(), dcCore::app()->admin->logs_filter->values()) . + dcCore::app()->formNonce() . + '
' . + '
', + 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 -'' . __('Log') . '' . -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')) . -'' . -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 '

' . __('There are no logs') . '

'; - } else { - $filter->display( - 'admin.plugin.' . basename(__DIR__), - form::hidden('p', basename(__DIR__)) - ); - $logs_list->display( - $filter->__get('page'), - $filter->__get('nb'), - '
' . - - '%s' . - - '
' . - '

' . - - '

' . - ' ' . - '' . - '

' . - - dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.' . basename(__DIR__), $filter->values()) . - dcCore::app()->formNonce() . - '
' . - '
', - $filter->show() - ); - } -} - -echo ''; diff --git a/src/My.php b/src/My.php new file mode 100644 index 0000000..fb4b656 --- /dev/null +++ b/src/My.php @@ -0,0 +1,38 @@ +plugins->moduleInfo(self::id(), 'name')); + } +} diff --git a/src/Prepend.php b/src/Prepend.php deleted file mode 100644 index 8175018..0000000 --- a/src/Prepend.php +++ /dev/null @@ -1,17 +0,0 @@ -autoload(['dcLogList' => __DIR__ . '/inc/class.dc.log.list.php']);