Code review
This commit is contained in:
parent
099902c32e
commit
15eb8f7676
@ -1,3 +1,9 @@
|
||||
activityReport 3.4.1 - 2023.10.24
|
||||
===========================================================
|
||||
* Require Dotclear 2.28
|
||||
* Require PHP 8.1
|
||||
* Code review
|
||||
|
||||
activityReport 3.4 - 2023.10.18
|
||||
===========================================================
|
||||
* Require Dotclear 2.28
|
||||
|
@ -1,7 +1,7 @@
|
||||
# README
|
||||
|
||||
[![Release](https://img.shields.io/badge/release-3.4-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/activityReport/releases)
|
||||
![Date](https://img.shields.io/badge/date-2023.10.18-c44d58.svg)
|
||||
[![Release](https://img.shields.io/badge/release-3.4.1-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/activityReport/releases)
|
||||
![Date](https://img.shields.io/badge/date-2023.10.24-c44d58.svg)
|
||||
[![Dotclear](https://img.shields.io/badge/dotclear-v2.28-137bbb.svg)](https://fr.dotclear.org/download)
|
||||
[![Dotaddict](https://img.shields.io/badge/dotaddict-official-9ac123.svg)](https://plugins.dotaddict.org/dc2/details/activityReport)
|
||||
[![License](https://img.shields.io/badge/license-GPL--2.0-ececec.svg)](https://git.dotclear.watch/JcDenis/activityReport/src/branch/master/LICENSE)
|
||||
@ -17,7 +17,7 @@ _activityReport_ is a plugin for the open-source web publishing software called
|
||||
* Dotclear 2.28
|
||||
* PHP 8.1+
|
||||
* System permissions to add table on database
|
||||
* System permissions to send email
|
||||
* System permissions to send email (optionnal)
|
||||
* Dotclear admin permissions
|
||||
|
||||
## USAGE
|
||||
@ -37,6 +37,7 @@ Once it's done you can manage your reports from menu
|
||||
* [Packages & details](https://git.dotclear.watch/JcDenis/activityReport/releases) (or on [Dotaddict](https://plugins.dotaddict.org/dc2/details/activityReport))
|
||||
* [Sources & contributions](https://git.dotclear.watch/JcDenis/activityReport) (or on [GitHub](https://github.com/JcDenis/activityReport))
|
||||
* [Issues & security](https://git.dotclear.watch/JcDenis/activityReport/issues) (or on [GitHub](https://github.com/JcDenis/activityReport/issues))
|
||||
* [Discuss & help](https://forum.dotclear.org/viewtopic.php?id=40504)
|
||||
|
||||
## CONTRIBUTORS
|
||||
|
||||
|
@ -17,7 +17,7 @@ $this->registerModule(
|
||||
'Activity log',
|
||||
'Log and receive your blog activity by email, feed, or on dashboard',
|
||||
'Jean-Christian Denis and contributors',
|
||||
'3.4',
|
||||
'3.4.1',
|
||||
[
|
||||
'requires' => [['core', '2.28']],
|
||||
'permissions' => 'My',
|
||||
|
@ -2,10 +2,10 @@
|
||||
<modules xmlns:da="http://dotaddict.org/da/">
|
||||
<module id="activityReport">
|
||||
<name>Activity log</name>
|
||||
<version>3.4</version>
|
||||
<version>3.4.1</version>
|
||||
<author>Jean-Christian Denis and contributors</author>
|
||||
<desc>Log and receive your blog activity by email, feed, or on dashboard</desc>
|
||||
<file>https://git.dotclear.watch/JcDenis/activityReport/releases/download/v3.4/plugin-activityReport.zip</file>
|
||||
<file>https://git.dotclear.watch/JcDenis/activityReport/releases/download/v3.4.1/plugin-activityReport.zip</file>
|
||||
<da:dcmin>2.28</da:dcmin>
|
||||
<da:details>https://git.dotclear.watch/JcDenis/activityReport/src/branch/master/README.md</da:details>
|
||||
<da:support>https://git.dotclear.watch/JcDenis/activityReport/issues</da:support>
|
||||
|
@ -41,28 +41,60 @@ class ActivityReport
|
||||
*/
|
||||
public const ACTIVITYREPORT_CLASS_NAME = 'ActivityReportAction';
|
||||
|
||||
/** @var int activity marked as pending mail report */
|
||||
/**
|
||||
* Activity marked as pending mail report.
|
||||
*
|
||||
* @var int STATUS_PENDING
|
||||
*/
|
||||
public const STATUS_PENDING = 0;
|
||||
|
||||
/** @var int activity marked as reported by mail */
|
||||
/**
|
||||
* Activity marked as reported by mail.
|
||||
*
|
||||
* @var int STATUS_REPORTED
|
||||
*/
|
||||
public const STATUS_REPORTED = 1;
|
||||
|
||||
/** @var string $type Activity report type (by default activityReport) */
|
||||
/**
|
||||
* Activity report type (by default activityReport).
|
||||
*
|
||||
* @var string $type
|
||||
*/
|
||||
public readonly string $type;
|
||||
|
||||
/** @var Settings $settings Activity report settings for current blog */
|
||||
/**
|
||||
* Activity report settings for current blog.
|
||||
*
|
||||
* @var Settings $settings
|
||||
*/
|
||||
public readonly Settings $settings;
|
||||
|
||||
/** @var Groups $groups Groups of actions */
|
||||
/**
|
||||
* Groups of actions.
|
||||
*
|
||||
* @var Groups $groups
|
||||
*/
|
||||
public readonly Groups $groups;
|
||||
|
||||
/** @var Formats $formats Export available formats */
|
||||
/**
|
||||
* Export available formats.
|
||||
*
|
||||
* @var Formats $formats
|
||||
*/
|
||||
public readonly Formats $formats;
|
||||
|
||||
/** @var ActivityReport $instance ActivityReport instance */
|
||||
/**
|
||||
* ActivityReport instance.
|
||||
*
|
||||
* @var ActivityReport $instance
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/** @var null|string $lock File lock for update */
|
||||
/**
|
||||
* File lock for update.
|
||||
*
|
||||
* @var null|string $lock
|
||||
*/
|
||||
private static $lock = null;
|
||||
|
||||
/**
|
||||
@ -115,13 +147,13 @@ class ActivityReport
|
||||
/**
|
||||
* Get logs record.
|
||||
*
|
||||
* @param null|ArrayObject $params The query params
|
||||
* @param null|ArrayObject<string, mixed> $params The query params
|
||||
* @param bool $count_only Count only
|
||||
* @param null|SelectStatement $ext_sql The sql select statement
|
||||
*
|
||||
* @return null|MetaRecord The logs record
|
||||
* @return MetaRecord The logs record
|
||||
*/
|
||||
public function getLogs(ArrayObject $params = null, bool $count_only = false, ?SelectStatement $ext_sql = null): ?MetaRecord
|
||||
public function getLogs(ArrayObject $params = null, bool $count_only = false, ?SelectStatement $ext_sql = null): MetaRecord
|
||||
{
|
||||
if (is_null($params)) {
|
||||
$params = new ArrayObject();
|
||||
@ -179,7 +211,7 @@ class ActivityReport
|
||||
$sql->where('E.activity_type = ' . $sql->quote($this->type));
|
||||
}
|
||||
|
||||
if (isset($params['blog_id']) && is_null($params['blog_id'])) {
|
||||
if (isset($params['blog_id']) && $params['blog_id'] != '') {
|
||||
$sql->and('E.blog_id IS NOT NULL');
|
||||
} elseif (!empty($params['blog_id'])) {
|
||||
if (!is_array($params['blog_id'])) {
|
||||
@ -243,9 +275,10 @@ class ActivityReport
|
||||
if (!$count_only && !empty($params['limit'])) {
|
||||
$sql->limit($params['limit']);
|
||||
}
|
||||
|
||||
$rs = $sql->select();
|
||||
|
||||
return $sql->select();
|
||||
return is_null($rs) ? MetaRecord::newFromArray([]) : $rs;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -616,7 +649,7 @@ class ActivityReport
|
||||
]);
|
||||
|
||||
$logs = $this->getLogs($params);
|
||||
if (!is_null($logs) && !$logs->isEmpty()) {
|
||||
if (!$logs->isEmpty()) {
|
||||
// Datas to readable text
|
||||
$content = $this->parseLogs($logs);
|
||||
if (!empty($content)) {
|
||||
|
@ -330,6 +330,9 @@ class ActivityReportAction extends Process
|
||||
ActivityReport::instance()->addLog('post', 'delete', $logs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $result
|
||||
*/
|
||||
public static function postPasswordAttempt(ArrayObject $result): void
|
||||
{
|
||||
if ($result['tpl'] != 'password-form.html' || empty($_POST['password'])) {
|
||||
|
146
src/Backend.php
146
src/Backend.php
@ -4,18 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\activityReport;
|
||||
|
||||
use ArrayObject;
|
||||
use Dotclear\App;
|
||||
use Dotclear\Core\Backend\Favorites;
|
||||
use Dotclear\Core\Process;
|
||||
use Dotclear\Helper\Date;
|
||||
use Dotclear\Helper\Html\Form\{
|
||||
Div,
|
||||
Label,
|
||||
Para,
|
||||
Select,
|
||||
Text
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief activityReport backend class.
|
||||
@ -33,142 +23,22 @@ class Backend extends Process
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (self::status()) {
|
||||
// be sure to init report
|
||||
ActivityReport::init();
|
||||
|
||||
My::addBackendMenuItem();
|
||||
|
||||
App::behavior()->addBehaviors([
|
||||
// dashboard favorites icon
|
||||
'adminDashboardFavoritesV2' => function (Favorites $favs): void {
|
||||
$favs->register(My::id(), [
|
||||
'title' => My::name(),
|
||||
'url' => My::manageUrl(),
|
||||
'small-icon' => My::icons(),
|
||||
'large-icon' => My::icons(),
|
||||
'permissions' => App::auth()->makePermissions([
|
||||
App::auth()::PERMISSION_ADMIN,
|
||||
]),
|
||||
'adminDashboardFavoritesV2' => BackendBehaviors::adminDashboardFavoritesV2(...),
|
||||
'adminDashboardContentsV2' => BackendBehaviors::adminDashboardContentsV2(...),
|
||||
'adminDashboardOptionsFormV2' => BackendBehaviors::adminDashboardOptionsFormV2(...),
|
||||
'adminAfterDashboardOptionsUpdate' => BackendBehaviors::adminAfterDashboardOptionsUpdate(...),
|
||||
'adminFiltersListsV2' => BackendBehaviors::adminFiltersListsV2(...),
|
||||
'adminColumnsListsV2' => BackendBehaviors::adminColumnsListsV2(...),
|
||||
]);
|
||||
},
|
||||
// dashboard content display
|
||||
'adminDashboardContentsV2' => function (ArrayObject $items): void {
|
||||
$db = App::auth()->prefs()->get(My::id())->get('dashboard_item');
|
||||
$limit = abs(is_numeric($db) ? (int) $db : 0);
|
||||
if (!$limit) {
|
||||
return ;
|
||||
}
|
||||
|
||||
$params = new ArrayObject([
|
||||
'limit' => $limit,
|
||||
'requests' => true,
|
||||
]);
|
||||
$rs = ActivityReport::instance()->getLogs($params);
|
||||
if (!$rs || $rs->isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$lines = [];
|
||||
$groups = ActivityReport::instance()->groups;
|
||||
while ($rs->fetch()) {
|
||||
$row = new ActivityRow($rs);
|
||||
if (!$groups->has($row->group)) {
|
||||
continue;
|
||||
}
|
||||
$group = $groups->get($row->group);
|
||||
$lines[] = '<dt title="' . __($group->title) . '">' .
|
||||
'<strong>' . __($group->get($row->action)->title) . '</strong>' .
|
||||
'<br />' . Date::str(
|
||||
App::blog()->settings()->get('system')->get('date_format') . ', ' . App::blog()->settings()->get('system')->get('time_format'),
|
||||
(int) strtotime($row->dt),
|
||||
is_string(App::auth()->getInfo('user_tz')) ? App::auth()->getInfo('user_tz') : 'UTC'
|
||||
) . '<dt>' .
|
||||
'<dd><p>' .
|
||||
'<em>' . ActivityReport::parseMessage(__($group->get($row->action)->message), $row->logs) . '</em></p></dd>';
|
||||
}
|
||||
if (empty($lines)) {
|
||||
return ;
|
||||
}
|
||||
|
||||
$items[] = new ArrayObject([
|
||||
'<div id="activity-report-logs" class="box medium">' .
|
||||
'<h3>' . My::name() . '</h3>' .
|
||||
'<dl id="reports">' . implode('', $lines) . '</dl>' .
|
||||
'<p class="modules"><a class="module-details" href="' .
|
||||
My::manageUrl() . '">' .
|
||||
__('View all logs') . '</a> - <a class="module-config" href="' .
|
||||
App::backend()->url()->get('admin.plugins', [
|
||||
'module' => My::id(),
|
||||
'conf' => 1,
|
||||
'redir' => App::backend()->url()->get('admin.home'),
|
||||
]) . '">' .
|
||||
__('Configure plugin') . '</a></p>' .
|
||||
'</div>',
|
||||
]);
|
||||
},
|
||||
// dashboard content user preference form
|
||||
'adminDashboardOptionsFormV2' => function (): void {
|
||||
$db = App::auth()->prefs()->get(My::id())->get('dashboard_item');
|
||||
echo
|
||||
(new Div())->class('fieldset')->items([
|
||||
(new Text('h4', My::name())),
|
||||
(new Para())->items([
|
||||
(new Label(__('Number of activities to show on dashboard:'), Label::OUTSIDE_LABEL_BEFORE))->for(My::id() . '_dashboard_item'),
|
||||
(new Select(My::id() . '_dashboard_item'))->default(is_string($db) ? $db : '')->items([
|
||||
__('Do not show activity report') => 0,
|
||||
5 => 5,
|
||||
10 => 10,
|
||||
15 => 15,
|
||||
20 => 20,
|
||||
50 => 50,
|
||||
100 => 100,
|
||||
]),
|
||||
]),
|
||||
])->render();
|
||||
},
|
||||
// save dashboard content user preference
|
||||
'adminAfterDashboardOptionsUpdate' => function (?string $user_id = null): void {
|
||||
if (!is_null($user_id)) {
|
||||
App::auth()->prefs()->get(My::id())->put(
|
||||
'dashboard_item',
|
||||
(int) $_POST[My::id() . '_dashboard_item'],
|
||||
'integer'
|
||||
);
|
||||
}
|
||||
},
|
||||
// list filters
|
||||
'adminFiltersListsV2' => function (ArrayObject $sorts): void {
|
||||
$sorts[My::id()] = [
|
||||
My::name(),
|
||||
[
|
||||
__('Group') => 'activity_group',
|
||||
__('Action') => 'activity_action',
|
||||
__('Date') => 'activity_dt',
|
||||
__('Status') => 'activity_status',
|
||||
],
|
||||
'activity_dt',
|
||||
'desc',
|
||||
[__('logs per page'), 30],
|
||||
];
|
||||
},
|
||||
// list columns user preference
|
||||
'adminColumnsListsV2' => function (ArrayObject $cols): void {
|
||||
$cols[My::id()] = [
|
||||
My::name(),
|
||||
[
|
||||
'activity_group' => [true, __('Group')],
|
||||
'activity_action' => [true, __('Action')],
|
||||
'activity_dt' => [true, __('Date')],
|
||||
'activity_status' => [false, __('Status')],
|
||||
],
|
||||
];
|
||||
},
|
||||
]);
|
||||
|
||||
return true;
|
||||
return self::status();
|
||||
}
|
||||
}
|
||||
|
181
src/BackendBehaviors.php
Normal file
181
src/BackendBehaviors.php
Normal file
@ -0,0 +1,181 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\activityReport;
|
||||
|
||||
use ArrayObject;
|
||||
use Dotclear\App;
|
||||
use Dotclear\Core\Backend\Favorites;
|
||||
use Dotclear\Helper\Date;
|
||||
use Dotclear\Helper\Html\Form\{
|
||||
Div,
|
||||
Label,
|
||||
Para,
|
||||
Select,
|
||||
Text
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief activityReport backend behaviors class.
|
||||
* @ingroup activityReport
|
||||
*
|
||||
* @author Jean-Christian Denis (author)
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
class BackendBehaviors
|
||||
{
|
||||
/**
|
||||
* Dashboard favorites icon.
|
||||
*/
|
||||
public static function adminDashboardFavoritesV2(Favorites $favs): void
|
||||
{
|
||||
$favs->register(My::id(), [
|
||||
'title' => My::name(),
|
||||
'url' => My::manageUrl(),
|
||||
'small-icon' => My::icons(),
|
||||
'large-icon' => My::icons(),
|
||||
'permissions' => App::auth()->makePermissions([
|
||||
App::auth()::PERMISSION_ADMIN,
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dashboard content display.
|
||||
*
|
||||
* @param ArrayObject<int, mixed> $items
|
||||
*/
|
||||
public static function adminDashboardContentsV2(ArrayObject $items): void
|
||||
{
|
||||
$db = App::auth()->prefs()->get(My::id())->get('dashboard_item');
|
||||
$limit = abs(is_numeric($db) ? (int) $db : 0);
|
||||
if (!$limit) {
|
||||
return ;
|
||||
}
|
||||
|
||||
$params = new ArrayObject([
|
||||
'limit' => $limit,
|
||||
'requests' => true,
|
||||
]);
|
||||
$rs = ActivityReport::instance()->getLogs($params);
|
||||
if ($rs->isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$lines = [];
|
||||
$groups = ActivityReport::instance()->groups;
|
||||
while ($rs->fetch()) {
|
||||
$row = new ActivityRow($rs);
|
||||
if (!$groups->has($row->group)) {
|
||||
continue;
|
||||
}
|
||||
$group = $groups->get($row->group);
|
||||
$lines[] = '<dt title="' . __($group->title) . '">' .
|
||||
'<strong>' . __($group->get($row->action)->title) . '</strong>' .
|
||||
'<br />' . Date::str(
|
||||
App::blog()->settings()->get('system')->get('date_format') . ', ' . App::blog()->settings()->get('system')->get('time_format'),
|
||||
(int) strtotime($row->dt),
|
||||
is_string(App::auth()->getInfo('user_tz')) ? App::auth()->getInfo('user_tz') : 'UTC'
|
||||
) . '<dt>' .
|
||||
'<dd><p>' .
|
||||
'<em>' . ActivityReport::parseMessage(__($group->get($row->action)->message), $row->logs) . '</em></p></dd>';
|
||||
}
|
||||
if (empty($lines)) {
|
||||
return ;
|
||||
}
|
||||
|
||||
$items[] = new ArrayObject([
|
||||
'<div id="activity-report-logs" class="box medium">' .
|
||||
'<h3>' . My::name() . '</h3>' .
|
||||
'<dl id="reports">' . implode('', $lines) . '</dl>' .
|
||||
'<p class="modules"><a class="module-details" href="' .
|
||||
My::manageUrl() . '">' .
|
||||
__('View all logs') . '</a> - <a class="module-config" href="' .
|
||||
App::backend()->url()->get('admin.plugins', [
|
||||
'module' => My::id(),
|
||||
'conf' => 1,
|
||||
'redir' => App::backend()->url()->get('admin.home'),
|
||||
]) . '">' .
|
||||
__('Configure plugin') . '</a></p>' .
|
||||
'</div>',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dashboard content user preference form.
|
||||
*/
|
||||
public static function adminDashboardOptionsFormV2(): void
|
||||
{
|
||||
$db = App::auth()->prefs()->get(My::id())->get('dashboard_item');
|
||||
echo
|
||||
(new Div())->class('fieldset')->items([
|
||||
(new Text('h4', My::name())),
|
||||
(new Para())->items([
|
||||
(new Label(__('Number of activities to show on dashboard:'), Label::OUTSIDE_LABEL_BEFORE))->for(My::id() . '_dashboard_item'),
|
||||
(new Select(My::id() . '_dashboard_item'))->default(is_string($db) ? $db : '')->items([
|
||||
__('Do not show activity report') => 0,
|
||||
5 => 5,
|
||||
10 => 10,
|
||||
15 => 15,
|
||||
20 => 20,
|
||||
50 => 50,
|
||||
100 => 100,
|
||||
]),
|
||||
]),
|
||||
])->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save dashboard content user preference.
|
||||
*/
|
||||
public static function adminAfterDashboardOptionsUpdate(?string $user_id = null): void
|
||||
{
|
||||
if (!is_null($user_id)) {
|
||||
App::auth()->prefs()->get(My::id())->put(
|
||||
'dashboard_item',
|
||||
(int) $_POST[My::id() . '_dashboard_item'],
|
||||
'integer'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List filters.
|
||||
*
|
||||
* @param ArrayObject<string, mixed> $sorts
|
||||
*/
|
||||
public static function adminFiltersListsV2(ArrayObject $sorts): void
|
||||
{
|
||||
$sorts[My::id()] = [
|
||||
My::name(),
|
||||
[
|
||||
__('Group') => 'activity_group',
|
||||
__('Action') => 'activity_action',
|
||||
__('Date') => 'activity_dt',
|
||||
__('Status') => 'activity_status',
|
||||
],
|
||||
'activity_dt',
|
||||
'desc',
|
||||
[__('logs per page'), 30],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* List columns user preference.
|
||||
*
|
||||
* @param ArrayObject<string, mixed> $cols
|
||||
*/
|
||||
public static function adminColumnsListsV2(ArrayObject $cols): void
|
||||
{
|
||||
$cols[My::id()] = [
|
||||
My::name(),
|
||||
[
|
||||
'activity_group' => [true, __('Group')],
|
||||
'activity_action' => [true, __('Action')],
|
||||
'activity_dt' => [true, __('Date')],
|
||||
'activity_status' => [false, __('Status')],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
@ -131,13 +131,13 @@ class Config extends Process
|
||||
]),
|
||||
(new Para())->items([
|
||||
(new Label(__('Recipients:'), Label::OUTSIDE_LABEL_BEFORE))->for('mailinglist'),
|
||||
(new Input('mailinglist'))->size(60)->maxlenght(255)->value(implode(';', $s->mailinglist)),
|
||||
(new Input('mailinglist'))->size(60)->maxlength(255)->value(implode(';', $s->mailinglist)),
|
||||
]),
|
||||
(new Note())->class('form-note')->text(__('Separate multiple email addresses with a semicolon ";"')),
|
||||
(new Note())->class('form-note')->text(__('Leave it empty to disable mail report.')),
|
||||
(new Para())->items([
|
||||
(new Label(__('Date format:'), Label::OUTSIDE_LABEL_BEFORE))->for('dateformat'),
|
||||
(new Input('dateformat'))->size(60)->maxlenght(255)->value($s->dateformat),
|
||||
(new Input('dateformat'))->size(60)->maxlength(255)->value($s->dateformat),
|
||||
]),
|
||||
(new Note())->class('form-note')->text(__('Use Dotclear date formaters. ex: %B %d at %H:%M')),
|
||||
(new Para())->items([
|
||||
|
@ -23,21 +23,19 @@ class Frontend extends Process
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (self::status()) {
|
||||
// be sure to init report
|
||||
ActivityReport::init();
|
||||
|
||||
App::frontend()->template()->setPath(App::frontend()->template()->getPath(), implode(DIRECTORY_SEPARATOR, [My::path(), 'default-templates', 'tpl']));
|
||||
$tpl = App::frontend()->template();
|
||||
$tpl->setPath($tpl->getPath(), implode(DIRECTORY_SEPARATOR, [My::path(), 'default-templates', 'tpl']));
|
||||
$tpl->addBlock('activityReports', FrontendTemplate::activityReports(...));
|
||||
$tpl->addValue('activityReportFeedID', FrontendTemplate::activityReportFeedID(...));
|
||||
$tpl->addValue('activityReportTitle', FrontendTemplate::activityReportTitle(...));
|
||||
$tpl->addValue('activityReportDate', FrontendTemplate::activityReportDate(...));
|
||||
$tpl->addValue('activityReportContent', FrontendTemplate::activityReportContent(...));
|
||||
}
|
||||
|
||||
App::frontend()->template()->addBlock('activityReports', Template::activityReports(...));
|
||||
App::frontend()->template()->addValue('activityReportFeedID', Template::activityReportFeedID(...));
|
||||
App::frontend()->template()->addValue('activityReportTitle', Template::activityReportTitle(...));
|
||||
App::frontend()->template()->addValue('activityReportDate', Template::activityReportDate(...));
|
||||
App::frontend()->template()->addValue('activityReportContent', Template::activityReportContent(...));
|
||||
|
||||
return true;
|
||||
return self::status();
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ use Dotclear\Database\MetaRecord;
|
||||
* @author Jean-Christian Denis (author)
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
class Context
|
||||
class FrontendContext
|
||||
{
|
||||
/**
|
||||
* Parse title.
|
@ -15,7 +15,7 @@ use Dotclear\Helper\Date;
|
||||
* @author Jean-Christian Denis (author)
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
class Template
|
||||
class FrontendTemplate
|
||||
{
|
||||
/**
|
||||
* tpl:activityReports [attributes] : Activity report logs (tpl block)
|
||||
@ -25,7 +25,7 @@ class Template
|
||||
* - lastn integer Limit to last n logs
|
||||
* - ingnore_pagination 1|0 Ignore pagination paramaters
|
||||
*
|
||||
* @param ArrayObject $attr The attributes
|
||||
* @param ArrayObject<string, mixed> $attr The attributes
|
||||
* @param string $content The content
|
||||
*
|
||||
* @return string The code
|
||||
@ -37,7 +37,7 @@ class Template
|
||||
$lastn = abs((int) $attr['lastn']) + 0;
|
||||
}
|
||||
|
||||
$p = '$_page_number = App::frontend()->getPageNumber(); if ($_page_number < 1) { $_page_number = 1; }' . "\n\$params = new ArrayObject();\n";
|
||||
$p = '$page_number = App::frontend()->getPageNumber(); if ($page_number < 1) { $page_number = 1; }' . "\n\$params = new ArrayObject();\n";
|
||||
|
||||
if ($lastn > 0) {
|
||||
$p .= "\$params['limit'] = " . $lastn . ";\n";
|
||||
@ -46,7 +46,7 @@ class Template
|
||||
}
|
||||
|
||||
if (!isset($attr['ignore_pagination']) || $attr['ignore_pagination'] == '0') {
|
||||
$p .= "\$params['limit'] = array(((\$_page_number-1)*\$params['limit']),\$params['limit']);\n";
|
||||
$p .= "\$params['limit'] = array(((\$page_number-1)*\$params['limit']),\$params['limit']);\n";
|
||||
} else {
|
||||
$p .= "\$params['limit'] = array(0, \$params['limit']);\n";
|
||||
}
|
||||
@ -68,7 +68,7 @@ class Template
|
||||
*
|
||||
* - any filters See self::getFilters()
|
||||
*
|
||||
* @param ArrayObject $attr The attributes
|
||||
* @param ArrayObject<string, mixed> $attr The attributes
|
||||
*
|
||||
* @return string The code
|
||||
*/
|
||||
@ -87,7 +87,7 @@ class Template
|
||||
*
|
||||
* - any filters See self::getFilters()
|
||||
*
|
||||
* @param ArrayObject $attr The attributes
|
||||
* @param ArrayObject<string, mixed> $attr The attributes
|
||||
*
|
||||
* @return string The code
|
||||
*/
|
||||
@ -95,7 +95,7 @@ class Template
|
||||
{
|
||||
$f = App::frontend()->template()->getFilters($attr);
|
||||
|
||||
return '<?php echo ' . sprintf($f, Context::class . '::parseTitle()') . '; ?>';
|
||||
return '<?php echo ' . sprintf($f, FrontendContext::class . '::parseTitle()') . '; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -105,7 +105,7 @@ class Template
|
||||
*
|
||||
* - any filters See self::getFilters()
|
||||
*
|
||||
* @param ArrayObject $attr The attributes
|
||||
* @param ArrayObject<string, mixed> $attr The attributes
|
||||
*
|
||||
* @return string The code
|
||||
*/
|
||||
@ -113,7 +113,7 @@ class Template
|
||||
{
|
||||
$f = App::frontend()->template()->getFilters($attr);
|
||||
|
||||
return '<?php echo ' . sprintf($f, Context::class . '::parseContent()') . '; ?>';
|
||||
return '<?php echo ' . sprintf($f, FrontendContext::class . '::parseContent()') . '; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -126,7 +126,7 @@ class Template
|
||||
* - rfc822 (1|0) Use Date::rfc822()
|
||||
* - any filters See self::getFilters()
|
||||
*
|
||||
* @param ArrayObject $attr The attributes
|
||||
* @param ArrayObject<string, mixed> $attr The attributes
|
||||
*
|
||||
* @return string The code
|
||||
*/
|
@ -14,7 +14,7 @@ use Dotclear\Core\Frontend\Url;
|
||||
* @author Jean-Christian Denis (author)
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
class UrlHandler extends Url
|
||||
class FrontendUrl extends Url
|
||||
{
|
||||
/**
|
||||
* Get activity logs feed.
|
@ -6,7 +6,10 @@ namespace Dotclear\Plugin\activityReport;
|
||||
|
||||
use ArrayObject;
|
||||
use Dotclear\App;
|
||||
use Dotclear\Core\Backend\Filter\Filters;
|
||||
use Dotclear\Core\Backend\Filter\{
|
||||
Filters,
|
||||
FiltersLibrary
|
||||
};
|
||||
use Dotclear\Core\Backend\{
|
||||
Notices,
|
||||
Page
|
||||
@ -62,14 +65,13 @@ class Manage extends Process
|
||||
|
||||
$logs = $counter = $list = null;
|
||||
$filter = new Filters(My::id());
|
||||
$filter->add(FiltersLibrary::getPageFilter());
|
||||
$params = new ArrayObject($filter->params());
|
||||
|
||||
try {
|
||||
$logs = ActivityReport::instance()->getLogs($params);
|
||||
$counter = ActivityReport::instance()->getLogs($params, true);
|
||||
if (!is_null($logs) && !is_null($counter)) {
|
||||
$list = new ManageList($logs, $counter->f(0));
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
App::error()->add($e->getMessage());
|
||||
}
|
||||
|
@ -12,6 +12,18 @@ use Dotclear\Core\Backend\Listing\{
|
||||
Pager
|
||||
};
|
||||
use Dotclear\Helper\Date;
|
||||
use Dotclear\Helper\Html\Form\{
|
||||
Caption,
|
||||
Div,
|
||||
Note,
|
||||
Table,
|
||||
Tbody,
|
||||
Td,
|
||||
Text,
|
||||
Th,
|
||||
Tr
|
||||
};
|
||||
use Dotclear\Helper\Html\Html;
|
||||
|
||||
/**
|
||||
* @brief activityReport manage logs list class.
|
||||
@ -25,50 +37,71 @@ class ManageList extends Listing
|
||||
public function logsDisplay(Filters $filter, string $enclose_block = ''): void
|
||||
{
|
||||
if ($this->rs->isEmpty()) {
|
||||
if ($filter->show()) {
|
||||
echo '<p><strong>' . __('No log matches the filter') . '</strong></p>';
|
||||
} else {
|
||||
echo '<p><strong>' . __('No log') . '</strong></p>';
|
||||
echo (new Note())
|
||||
->text($filter->show() ? __('No log matches the filter') : __('No log'))
|
||||
->class('info')
|
||||
->render();
|
||||
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
$page = $filter->value('page');
|
||||
$nbpp = $filter->value('nb');
|
||||
$pager = new Pager(is_numeric($page) ? (int) $page : 1, (int) $this->rs_count, is_numeric($nbpp) ? (int) $nbpp : 20, 10);
|
||||
|
||||
$page = is_numeric($filter->value('page')) ? (int) $filter->value('page') : 1;
|
||||
$nbpp = is_numeric($filter->value('nb')) ? (int) $filter->value('nb') : 20;
|
||||
$count = (int) $this->rs_count;
|
||||
$pager = new Pager($page, $count, $nbpp, 10);
|
||||
$pager->var_page = 'page';
|
||||
|
||||
$html_block = '<div class="table-outer"><table><caption>' . (
|
||||
$filter->show() ?
|
||||
sprintf(__('List of %s logs matching the filter.'), $this->rs_count) :
|
||||
sprintf(__('List of %s logs.'), $this->rs_count)
|
||||
) . '</caption>';
|
||||
|
||||
$cols = new ArrayObject([
|
||||
'activity_group' => '<th scope="col" class="nowrap">' . __('Group') . '</th>',
|
||||
'activity_action' => '<th scope="col" class="nowrap">' . __('Action') . '</th>',
|
||||
'activity_logs' => '<th scope="col" class="nowrap">' . __('Message') . '</th>',
|
||||
'activity_date' => '<th scope="col" class="nowrap">' . __('Date') . '</th>',
|
||||
'activity_status' => '<th scope="col" class="nowrap">' . __('Status') . '</th>',
|
||||
'activity_group' => (new Th())
|
||||
->text(__('Group'))
|
||||
->scope('col'),
|
||||
'activity_action' => (new Th())
|
||||
->text(__('Action'))
|
||||
->scope('col'),
|
||||
'activity_logs' => (new Th())
|
||||
->text(__('Message'))
|
||||
->scope('col'),
|
||||
'activity_date' => (new Th())
|
||||
->text(__('Date'))
|
||||
->scope('col'),
|
||||
'activity_status' => (new Th())
|
||||
->text(__('Status'))
|
||||
->scope('col'),
|
||||
]);
|
||||
|
||||
$this->userColumns(My::id(), $cols);
|
||||
|
||||
$html_block .= '<tr>' . implode(iterator_to_array($cols)) . '</tr>%s</table>%s</div>';
|
||||
if ($enclose_block) {
|
||||
$html_block = sprintf($enclose_block, $html_block);
|
||||
}
|
||||
$blocks = explode('%s', $html_block);
|
||||
|
||||
echo $pager->getLinks() . $blocks[0];
|
||||
|
||||
$lines = [];
|
||||
while ($this->rs->fetch()) {
|
||||
echo $this->logsLine();
|
||||
$lines[] = $this->line();
|
||||
}
|
||||
|
||||
echo $blocks[1] . $blocks[2] . $pager->getLinks();
|
||||
}
|
||||
echo
|
||||
$pager->getLinks() .
|
||||
sprintf(
|
||||
$enclose_block,
|
||||
(new Div())
|
||||
->class('table-outer')
|
||||
->items([
|
||||
(new Table())
|
||||
->items([
|
||||
(new Caption(
|
||||
$filter->show() ?
|
||||
sprintf(__('List of %s logs matching the filter.'), $count) :
|
||||
sprintf(__('List of logs. (%s)'), $count)
|
||||
)),
|
||||
(new Tr())
|
||||
->items(iterator_to_array($cols)),
|
||||
(new Tbody())
|
||||
->items($lines),
|
||||
]),
|
||||
])
|
||||
->render()
|
||||
) .
|
||||
$pager->getLinks();
|
||||
}
|
||||
|
||||
private function logsLine(): string
|
||||
private function line(): Tr
|
||||
{
|
||||
$row = new ActivityRow($this->rs);
|
||||
|
||||
@ -84,18 +117,27 @@ class ManageList extends Listing
|
||||
$status = $row->status == ActivityReport::STATUS_PENDING ? __('pending') : __('reported');
|
||||
|
||||
$cols = new ArrayObject([
|
||||
'activity_group' => '<td class="nowrap">' . __($group->title) . '</td>',
|
||||
'activity_action' => '<td class="nowrap">' . __($action->title) . '</td>',
|
||||
'activity_logs' => '<td class="maximal">' . $message . '</td>',
|
||||
'activity_date' => '<td class="nowrap">' . $date . '</td>',
|
||||
'activity_status' => '<td class="nowrap">' . $status . '</td>',
|
||||
'activity_group' => (new Td())
|
||||
->text(Html::escapeHTML(__($group->title)))
|
||||
->class('nowrap'),
|
||||
'activity_action' => (new Td())
|
||||
->text(Html::escapeHTML(__($action->title)))
|
||||
->class('nowrap'),
|
||||
'activity_logs' => (new Td())
|
||||
->text(Html::escapeHTML($message))
|
||||
->class('maximal'),
|
||||
'activity_date' => (new Td())
|
||||
->text(Html::escapeHTML($date))
|
||||
->class('nowrap'),
|
||||
'activity_status' => (new Td())
|
||||
->text(Html::escapeHTML($status))
|
||||
->class('nowrap'),
|
||||
]);
|
||||
|
||||
$this->userColumns(My::id(), $cols);
|
||||
|
||||
return
|
||||
'<tr class="line ' . $offline . '" id="l' . $row->id . '">' .
|
||||
implode(iterator_to_array($cols)) .
|
||||
'</tr>';
|
||||
return (new Tr('l' . $row->id))
|
||||
->class('line' . $offline)
|
||||
->items(iterator_to_array($cols));
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ class Prepend extends Process
|
||||
My::id(),
|
||||
'reports',
|
||||
'^reports/((atom|rss2)/(.+))$',
|
||||
UrlHandler::feed(...)
|
||||
FrontendUrl::feed(...)
|
||||
);
|
||||
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user