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' => '' . __('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'), + '', + 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 -'' . __('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'), - '', - $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']);