Compare commits

...

10 Commits

11 changed files with 151 additions and 181 deletions

View File

@ -1,3 +1,20 @@
1.5 - 2023.07.28
- require dotclear 2.27
- require PHP 8.1+
- update to dotclear 2.27-dev
1.4 - 2023.05.13
- require dotclear 2.26
- require PHP 8.1+
- use define php_min
1.3.1 - 2023.04.29
- require dotclear 2.26
- require PHP 8.1+
- use Html Form Component everywhere
- fix submit contidions (js)
- fix phpstan level9 warnings
1.3 - 2023.04.23
- require dotclear 2.26
- require PHP 8.1+

View File

@ -3,7 +3,7 @@
[![Release](https://img.shields.io/github/v/release/JcDenis/dcLog)](https://github.com/JcDenis/dcLog/releases)
[![Date](https://img.shields.io/github/release-date/JcDenis/dcLog)](https://github.com/JcDenis/dcLog/releases)
[![Issues](https://img.shields.io/github/issues/JcDenis/dcLog)](https://github.com/JcDenis/dcLog/issues)
[![Dotclear](https://img.shields.io/badge/dotclear-v2.26-blue.svg)](https://fr.dotclear.org/download)
[![Dotclear](https://img.shields.io/badge/dotclear-v2.27-blue.svg)](https://fr.dotclear.org/download)
[![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/dcLog)
[![License](https://img.shields.io/github/license/JcDenis/dcLog)](https://github.com/JcDenis/dcLog/blob/master/LICENSE)
@ -19,7 +19,7 @@ Display dotclear's logs.
_dcLog_ requires:
* PHP 8.1+
* Dotclear 2.26
* Dotclear 2.27
* super admin permission
## USAGE

View File

@ -18,9 +18,12 @@ $this->registerModule(
"Dotclear's logs",
'Displays Dotclear logs',
'Tomtom and Contributors',
'1.3',
'1.5',
[
'requires' => [['core', '2.26']],
'requires' => [
['php', '8.1'],
['core', '2.27'],
],
'permissions' => null,
'type' => 'plugin',
'support' => 'https://github.com/JcDenis/' . basename(__DIR__),

View File

@ -2,11 +2,11 @@
<modules xmlns:da="http://dotaddict.org/da/">
<module id="dcLog">
<name>Dotclear's logs</name>
<version>1.3</version>
<version>1.5</version>
<author>Tomtom and Contributors</author>
<desc>Displays Dotclear logs</desc>
<file>https://github.com/JcDenis/dcLog/releases/download/v1.3/plugin-dcLog.zip</file>
<da:dcmin>2.26</da:dcmin>
<file>https://github.com/JcDenis/dcLog/releases/download/v1.5/plugin-dcLog.zip</file>
<da:dcmin>2.27</da:dcmin>
<da:details>https://plugins.dotaddict.org/dc2/details/dcLog</da:details>
<da:support>https://github.com/JcDenis/dcLog</da:support>
</module>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Svg Vector Icons : http://www.onlinewebfonts.com/icon -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1000 1000" enable-background="new 0 0 1000 1000" xml:space="preserve">
<metadata> Svg Vector Icons : http://www.onlinewebfonts.com/icon </metadata>
<g><g transform="translate(0.000000,511.000000) scale(0.100000,-0.100000)"><path d="M680,4167.7c-238.6-74.9-411.6-226.9-519.2-458.4L100,3580.6V107.4v-3473.3l60.8-131c86.5-184.8,210.5-311.1,390.6-400l156.7-77.2H5000h4291.9l131,60.8c184.8,86.5,311.1,210.5,400,390.6l77.2,156.7V107.4v3473.3l-77.2,156.7c-88.9,180.1-215.2,304.1-400,390.6l-131,60.8l-4256.8,4.7C1561.8,4195.8,759.6,4191.1,680,4167.7z M1526.7,3524.5c208.2-121.6,259.6-421,100.6-601.1c-95.9-107.6-180.1-149.7-311.1-149.7c-222.2,0-409.3,184.8-409.3,404.6c0,91.2,70.2,247.9,135.7,304.1C1166.5,3594.7,1379.4,3611,1526.7,3524.5z M2663.4,3566.6c184.8-63.1,287.7-222.2,273.6-421c-16.4-240.9-187.1-385.9-430.4-367.2c-219.9,18.7-360.2,170.7-360.2,392.9c0,135.7,35.1,217.5,133.3,306.4C2392.1,3583,2523.1,3613.4,2663.4,3566.6z M3982.6,3524.5c208.2-121.6,259.6-421,100.6-601.1c-93.6-105.2-180.1-149.7-297-149.7c-233.9,0-423.3,182.4-423.3,402.3c0,93.6,70.2,247.9,135.6,306.4C3622.4,3594.7,3835.2,3611,3982.6,3524.5z M9322.3-559.2l-7-2701.4l-65.5-63.2l-63.2-65.5H5000H813.4l-63.2,65.5l-65.5,63.2l-7,2701.4L673,2142.2h4327h4327L9322.3-559.2z"/><path d="M2941.8,1225.4c-114.6-77.2-177.8-233.9-142.7-357.8c14-51.5,39.8-109.9,56.1-128.6c14-21,301.7-257.3,636.2-523.9c334.5-269,615.1-493.5,626.8-502.9c9.4-9.3-259.6-236.2-596.4-505.2c-336.8-271.3-631.5-512.2-654.9-535.6c-166-177.7-51.4-498.2,194.1-547.3c44.4-9.4,109.9-14.1,145-9.4C3280.9-1876,4913.5-587.3,4981.3-482c56.1,84.2,56.1,276,0,360.2c-21.1,32.7-411.7,357.8-867.7,722.7l-825.6,661.9l-133.3,9.4C3047,1279.2,3009.6,1272.1,2941.8,1225.4z"/><path d="M4871.4-1866.7c-95.9-42.1-194.1-161.4-212.8-259.6c-32.7-180.1,109.9-369.5,299.4-397.6c56.1-7,533.3-11.7,1064.2-7c1094.6,7,1043.1-2.4,1148.4,210.5c65.5,131,53.8,243.2-37.4,350.8c-114.6,135.7-121.6,135.7-1202.2,135.7C5161.4-1836.2,4925.2-1843.3,4871.4-1866.7z"/></g></g>
<?xml version="1.0" encoding="utf-8"?>
<svg width="800px" height="800px" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect width="48" height="48" fill="white" fill-opacity="0.01"/>
<rect x="4" y="4" width="40" height="40" rx="2" stroke="#b2b2b2" stroke-width="3" stroke-linejoin="round"/>
<path d="M12 18L19 24L12 30" stroke="#C44D58" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M23 32H36" stroke="#C44D58" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 534 B

View File

@ -1,16 +1,17 @@
/*global $, dotclear */
'use strict';
Object.assign(dotclear.msg, dotclear.getData('dclog_list'));
Object.assign(dotclear.msg, dotclear.getData('dcLog_msg'));
$(function(){
$('.checkboxes-helpers').each(function(){
dotclear.checkboxesHelpers(this)
});
$('input[name="del_logs"]').click(function(){
$('input[name="selected_logs"]').click(function(){
return window.confirm(dotclear.msg.confirm_delete_selected_log)
});
$('input[name="del_all_logs"]').click(function(){
$('input[name="all_logs"]').click(function(){
return window.confirm(dotclear.msg.confirm_delete_all_log)
})
dotclear.condSubmit('#dcLog_form td input[type=checkbox]', '#dcLog_form #selected_logs');
})

View File

@ -15,44 +15,26 @@ declare(strict_types=1);
namespace Dotclear\Plugin\dcLog;
use ArrayObject;
use dcAdmin;
use dcCore;
use dcFavorites;
use dcMenu;
use dcNsProcess;
use dcPage;
use Dotclear\Core\Process;
use Dotclear\Core\Backend\Favorites;
use Dotclear\Core\Backend\Menus;
class Backend extends dcNsProcess
class Backend extends Process
{
public static function init(): bool
{
static::$init = defined('DC_CONTEXT_ADMIN')
&& My::phpCompliant()
&& !is_null(dcCore::app()->auth)
&& dcCore::app()->auth->isSuperAdmin();
return static::$init;
return self::status(My::checkContext(My::BACKEND));
;
}
public static function process(): bool
{
if (!static::$init) {
if (!self::status()) {
return false;
}
// backend sidebar menu icon
if (!is_null(dcCore::app()->auth)
&& !is_null(dcCore::app()->adminurl)
&& (dcCore::app()->menu[dcAdmin::MENU_SYSTEM] instanceof dcMenu)
) {
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((string) dcCore::app()->adminurl->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
dcCore::app()->auth->isSuperAdmin()
);
}
My::addBackendMenuItem(Menus::MENU_SYSTEM);
dcCore::app()->addBehaviors([
// backend user preference for logs list columns
@ -87,12 +69,12 @@ class Backend extends dcNsProcess
];
},
// backend user preference for dashboard icon
'adminDashboardFavoritesV2' => function (dcFavorites $favs): void {
'adminDashboardFavoritesV2' => function (Favorites $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'),
'url' => My::manageUrl(),
'small-icon' => My::icons(),
'large-icon' => My::icons(),
//'permissions' => null,
]);
},

View File

@ -15,8 +15,10 @@ declare(strict_types=1);
namespace Dotclear\Plugin\dcLog;
use ArrayObject;
use adminGenericListV2;
use dcPager;
use Dotclear\Core\Backend\Listing\{
Listing,
Pager
};
use Dotclear\Helper\Date;
use Dotclear\Helper\Html\Html;
use Dotclear\Helper\Html\Form\{
@ -30,7 +32,7 @@ use Dotclear\Helper\Html\Form\{
/**
* Backend logs list helper.
*/
class BackendList extends adminGenericListV2
class BackendList extends Listing
{
/**
* Display logs record.
@ -47,57 +49,58 @@ class BackendList extends adminGenericListV2
(new Text('p', $filter ? __('No log matches the filter') : __('No log')))
->class('info')
->render();
} else {
$pager = new dcPager($page, $this->rs_count, $nb_per_page, 10);
$cols = [
'date' => (new Text('th', __('Date')))
->class('first')
->extra('colspan="2"'),
'msg' => (new Text('th', __('Message')))
->extra('scope="col"'),
'blog' => (new Text('th', __('Blog')))
->extra('scope="col"'),
'table' => (new Text('th', __('Component')))
->extra('scope="col"'),
'user' => (new Text('th', __('User')))
->extra('scope="col"'),
'ip' => (new Text('th', __('IP')))
->extra('scope="col"'),
];
$cols = new ArrayObject($cols);
$this->userColumns(My::BACKEND_LIST_ID, $cols);
$lines = [];
while ($this->rs->fetch()) {
$lines[] = $this->line(isset($_POST['entries']) && in_array($this->rs->log_id, $_POST['entries']));
}
echo
$pager->getLinks() .
sprintf(
$enclose_block,
(new Div())
->class('table-outer')
->items([
(new Para(null, 'table'))
->items([
(new Text(
'caption',
$filter ?
sprintf(__('List of %s logs matching the filter.'), $this->rs_count) :
sprintf(__('List of logs. (%s)'), $this->rs_count)
)),
(new Para(null, 'tr'))
->items(iterator_to_array($cols)),
(new Para(null, 'tbody'))
->items($lines),
]),
])
->render()
) .
$pager->getLinks();
return;
}
$pager = new Pager($page, $this->rs_count, $nb_per_page, 10);
$cols = new ArrayObject([
'date' => (new Text('th', __('Date')))
->class('first')
->extra('colspan="2"'),
'msg' => (new Text('th', __('Message')))
->extra('scope="col"'),
'blog' => (new Text('th', __('Blog')))
->extra('scope="col"'),
'table' => (new Text('th', __('Component')))
->extra('scope="col"'),
'user' => (new Text('th', __('User')))
->extra('scope="col"'),
'ip' => (new Text('th', __('IP')))
->extra('scope="col"'),
]);
$this->userColumns(My::BACKEND_LIST_ID, $cols);
$lines = [];
while ($this->rs->fetch()) {
$lines[] = $this->line(isset($_POST['entries']) && in_array($this->rs->log_id, $_POST['entries']));
}
echo
$pager->getLinks() .
sprintf(
$enclose_block,
(new Div())
->class('table-outer')
->items([
(new Para(null, 'table'))
->items([
(new Text(
'caption',
$filter ?
sprintf(__('List of %s logs matching the filter.'), $this->rs_count) :
sprintf(__('List of logs. (%s)'), $this->rs_count)
)),
(new Para(null, 'tr'))
->items(iterator_to_array($cols)),
(new Para(null, 'tbody'))
->items($lines),
]),
])
->render()
) .
$pager->getLinks();
}
/**
@ -107,14 +110,14 @@ class BackendList extends adminGenericListV2
*/
private function line(bool $checked): Component
{
$cols = [
$cols = new ArrayObject([
'check' => (new Para(null, 'td'))
->class('nowrap minimal')
->items([
(new Checkbox(['entries[]'], $checked))
->value($this->rs->log_id),
]),
'date' => (new Text('td', Html::escapeHTML(Date::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->log_dt))))
'date' => (new Text('td', Html::escapeHTML(Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->log_dt))))
->class('nowrap minimal'),
'msg' => (new Text('td', nl2br(Html::escapeHTML($this->rs->log_msg))))
->class('maximal'),
@ -126,12 +129,12 @@ class BackendList extends adminGenericListV2
->class('nowrap minimal'),
'ip' => (new Text('td', Html::escapeHTML($this->rs->log_ip)))
->class('nowrap minimal'),
];
$cols = new ArrayObject($cols);
]);
$this->userColumns(My::BACKEND_LIST_ID, $cols);
return
(new Para('p' . $this->rs->log_id, 'tr'))
->class('line')
->items(iterator_to_array($cols));
}
}

View File

@ -15,8 +15,11 @@ declare(strict_types=1);
namespace Dotclear\Plugin\dcLog;
use dcCore;
use dcNsProcess;
use dcPage;
use Dotclear\Core\Process;
use Dotclear\Core\Backend\{
Notices,
Page
};
use Dotclear\Helper\Html\Form\{
Div,
Form,
@ -30,21 +33,16 @@ use Exception;
/**
* Manage logs list
*/
class Manage extends dcNsProcess
class Manage extends Process
{
public static function init(): bool
{
static::$init = defined('DC_CONTEXT_ADMIN')
&& My::phpCompliant()
&& !is_null(dcCore::app()->auth)
&& dcCore::app()->auth->isSuperAdmin();
return static::$init;
return self::status(My::checkContext(My::MANAGE));
}
public static function process(): bool
{
if (!static::$init) {
if (!self::status()) {
return false;
}
@ -54,12 +52,12 @@ class Manage extends dcNsProcess
if ($current->selected_logs && !empty($current->entries) || $current->all_logs) {
try {
dcCore::app()->log->delLogs($current->entries, $current->all_logs);
dcPage::addSuccessNotice(
Notices::addSuccessNotice(
$current->all_logs ?
__('All logs have been successfully deleted') :
__('Selected logs have been successfully deleted')
);
dcCore::app()->adminurl?->redirect('admin.plugin.' . My::id());
My::redirect();
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
}
@ -70,30 +68,30 @@ class Manage extends dcNsProcess
public static function render(): void
{
if (!static::$init) {
if (!self::status()) {
return;
}
$current = ManageVars::init();
dcPage::openModule(
__('Pings'),
dcPage::jsJson('dclog_list', [
Page::openModule(
My::name(),
Page::jsJson('dcLog_msg', [
'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?'),
]) .
$current->filter->js((string) dcCore::app()->adminurl?->get('admin.plugin.' . My::id())) .
dcPage::jsLoad(dcPage::getPF(My::id() . '/js/backend.js'))
$current->filter->js((string) My::manageUrl()) .
My::jsLoad('backend')
);
echo
dcPage::breadcrumb(
Page::breadcrumb(
[
__('System') => '',
My::name() => dcCore::app()->adminurl?->get('admin.plugin.' . My::id()),
My::name() => My::manageUrl(),
]
) .
dcPage::notices();
Notices::getNotices();
if ($current->logs !== null && $current->list != null) {
if ($current->logs->isEmpty() && !$current->filter->show()) {
@ -110,7 +108,7 @@ class Manage extends dcNsProcess
is_numeric($current->filter->__get('page')) ? (int) $current->filter->__get('page') : 1,
is_numeric($current->filter->__get('nb')) ? (int) $current->filter->__get('nb') : 10,
(new Form('dcLog_form'))
->action(dcCore::app()->adminurl?->get('admin.plugin.' . My::id()))
->action(My::manageUrl())
->method('post')
->fields([
(new Text('', '%s')),
@ -130,11 +128,11 @@ class Manage extends dcNsProcess
->class('delete')
->value(__('Delete all logs')),
]),
(new Text(
'',
dcCore::app()->adminurl?->getHiddenFormFields('admin.plugin.' . My::id(), $current->filter->values()) .
dcCore::app()->formNonce()
)),
(new Text(
'',
dcCore::app()->admin->url->getHiddenFormFields('admin.plugin.' . My::id(), $current->filter->values()) .
dcCore::app()->formNonce()
)),
]),
])->render(),
$current->filter->show()
@ -142,6 +140,6 @@ class Manage extends dcNsProcess
}
}
dcPage::closeModule();
Page::closeModule();
}
}

View File

@ -14,9 +14,11 @@ declare(strict_types=1);
namespace Dotclear\Plugin\dcLog;
use adminGenericFilterV2;
use dcAdminFilters;
use dcCore;
use Dotclear\Core\Backend\Filter\{
Filters,
FiltersLibrary
};
use Dotclear\Database\MetaRecord;
use Exception;
@ -28,8 +30,8 @@ class ManageVars
/** @var ManageVars $container self instance */
private static $container;
/** @var adminGenericFilterV2 $filter The filter instance */
public readonly adminGenericFilterV2 $filter;
/** @var Filters $filter The filter instance */
public readonly Filters $filter;
/** @var null|MetaRecord $logs The current records */
public readonly ?MetaRecord $logs;
@ -55,12 +57,12 @@ class ManageVars
$this->all_logs = isset($_POST['all_logs']);
$this->selected_logs = isset($_POST['selected_logs']);
$this->filter = new adminGenericFilterV2('dcloglist');
$this->filter->add(dcAdminFilters::getPageFilter());
$this->filter->add(dcAdminFilters::getInputFilter('blog_id', __('Blog:')));
$this->filter->add(dcAdminFilters::getInputFilter('user_id', __('User:')));
$this->filter->add(dcAdminFilters::getInputFilter('log_table', __('Component:')));
$this->filter->add(dcAdminFilters::getInputFilter('log_ip', __('IP:')));
$this->filter = new Filters('dcloglist');
$this->filter->add(FiltersLibrary::getPageFilter());
$this->filter->add(FiltersLibrary::getInputFilter('blog_id', __('Blog:')));
$this->filter->add(FiltersLibrary::getInputFilter('user_id', __('User:')));
$this->filter->add(FiltersLibrary::getInputFilter('log_table', __('Component:')));
$this->filter->add(FiltersLibrary::getInputFilter('log_ip', __('IP:')));
$params = $this->filter->params();
try {

View File

@ -15,51 +15,15 @@ declare(strict_types=1);
namespace Dotclear\Plugin\dcLog;
use dcCore;
use Dotclear\Module\MyPlugin;
/**
* Module definition shortcut.
*/
class My
class My extends MyPlugin
{
/**
* @var string PHP min version
*/
public const PHP_MIN = '8.1';
/**
* @var string Admin list ID
*/
/** @var string Admin list ID */
public const BACKEND_LIST_ID = 'dcloglist';
/**
* This module id.
*
* @return string The module id
*/
public static function id(): string
public static function checkCustomContext(int $context): ?bool
{
return basename(dirname(__DIR__));
}
/**
* This module name.
*
* @return string The module translated name
*/
public static function name(): string
{
$name = dcCore::app()->plugins->moduleInfo(self::id(), 'name');
return __(is_string($name) ? $name : 'Undefined');
}
/**
* Check php version.
*
* @return bool True on supported PHP version
*/
public static function phpCompliant(): bool
{
return version_compare(phpversion(), self::PHP_MIN, '>=');
return dcCore::app()->auth->isSuperAdmin();
}
}