upgrade to Dotclear 2.27

This commit is contained in:
Jean-Christian Paul Denis 2023-08-17 16:25:19 +02:00
parent d6cc7fca09
commit 0ef7f22f9b
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
13 changed files with 118 additions and 171 deletions

View File

@ -274,7 +274,7 @@ class ActivityBehaviors
public static function blogUpdate(Cursor $cur, string $blog_id): void public static function blogUpdate(Cursor $cur, string $blog_id): void
{ {
$logs = [self::str(dcCore::app()->auth?->getInfo('user_cn'))]; $logs = [self::str(dcCore::app()->auth->getInfo('user_cn'))];
ActivityReport::instance()->addLog('blog', 'update', $logs); ActivityReport::instance()->addLog('blog', 'update', $logs);
} }
@ -292,18 +292,19 @@ class ActivityBehaviors
$post_url = dcCore::app()->blog?->getPostURL('', self::str($cur->getField('post_dt')), self::str($cur->getField('post_title')), $post_id); $post_url = dcCore::app()->blog?->getPostURL('', self::str($cur->getField('post_dt')), self::str($cur->getField('post_title')), $post_id);
$logs = [ $logs = [
self::str($cur->getField('post_title')), self::str($cur->getField('post_title')),
self::str(dcCore::app()->auth?->getInfo('user_cn')), self::str(dcCore::app()->auth->getInfo('user_cn')),
self::str(dcCore::app()->blog?->url) . dcCore::app()->url->getBase(self::str($cur->getField('post_type'))) . '/' . $post_url, self::str(dcCore::app()->blog?->url) . dcCore::app()->url->getBase(self::str($cur->getField('post_type'))) . '/' . $post_url,
]; ];
ActivityReport::instance()->addLog('post', 'create', $logs); ActivityReport::instance()->addLog('post', 'create', $logs);
} }
public static function postUpdate(Cursor $cur, int $post_id): void public static function postUpdate(Cursor $cur, int|string $post_id): void
{ {
$post_id = is_numeric($post_id) ? (int) $post_id : 0;
$post_url = dcCore::app()->blog?->getPostURL('', self::str($cur->getField('post_dt')), self::str($cur->getField('post_title')), $post_id); $post_url = dcCore::app()->blog?->getPostURL('', self::str($cur->getField('post_dt')), self::str($cur->getField('post_title')), $post_id);
$logs = [ $logs = [
self::str($cur->getField('post_title')), self::str($cur->getField('post_title')),
self::str(dcCore::app()->auth?->getInfo('user_cn')), self::str(dcCore::app()->auth->getInfo('user_cn')),
self::str(dcCore::app()->blog?->url) . dcCore::app()->url->getBase(self::str($cur->getField('post_type'))) . '/' . $post_url, self::str(dcCore::app()->blog?->url) . dcCore::app()->url->getBase(self::str($cur->getField('post_type'))) . '/' . $post_url,
]; ];
ActivityReport::instance()->addLog('post', 'update', $logs); ActivityReport::instance()->addLog('post', 'update', $logs);
@ -317,7 +318,7 @@ class ActivityBehaviors
} }
$logs = [ $logs = [
self::str($posts->f('post_title')), self::str($posts->f('post_title')),
self::str(dcCore::app()->auth?->getInfo('user_cn')), self::str(dcCore::app()->auth->getInfo('user_cn')),
]; ];
ActivityReport::instance()->addLog('post', 'delete', $logs); ActivityReport::instance()->addLog('post', 'delete', $logs);
} }
@ -365,7 +366,7 @@ class ActivityBehaviors
} }
$logs = [ $logs = [
self::str(dcCore::app()->auth?->getInfo('user_cn')), self::str(dcCore::app()->auth->getInfo('user_cn')),
self::str($posts->f('post_title')), self::str($posts->f('post_title')),
self::str(dcCore::app()->blog?->url) . dcCore::app()->url->getBase(self::str($posts->f('post_type'))) . self::str(dcCore::app()->blog?->url) . dcCore::app()->url->getBase(self::str($posts->f('post_type'))) .
'/' . self::str($posts->f('post_url')) . '#c' . self::str($old->f('comment_id')), '/' . self::str($posts->f('post_url')) . '#c' . self::str($old->f('comment_id')),
@ -400,7 +401,7 @@ class ActivityBehaviors
{ {
$logs = [ $logs = [
self::str($cur->getField('cat_title')), self::str($cur->getField('cat_title')),
self::str(dcCore::app()->auth?->getInfo('user_cn')), self::str(dcCore::app()->auth->getInfo('user_cn')),
self::str(dcCore::app()->blog?->url) . dcCore::app()->url->getBase('category') . '/' . self::str($cur->getField('cat_url')), self::str(dcCore::app()->blog?->url) . dcCore::app()->url->getBase('category') . '/' . self::str($cur->getField('cat_url')),
]; ];
ActivityReport::instance()->addLog('category', 'create', $logs); ActivityReport::instance()->addLog('category', 'create', $logs);
@ -410,7 +411,7 @@ class ActivityBehaviors
{ {
$logs = [ $logs = [
self::str($cur->getField('cat_title')), self::str($cur->getField('cat_title')),
self::str(dcCore::app()->auth?->getInfo('user_cn')), self::str(dcCore::app()->auth->getInfo('user_cn')),
self::str(dcCore::app()->blog?->url) . dcCore::app()->url->getBase('category') . '/' . self::str($cur->getField('cat_url')), self::str(dcCore::app()->blog?->url) . dcCore::app()->url->getBase('category') . '/' . self::str($cur->getField('cat_url')),
]; ];
ActivityReport::instance()->addLog('category', 'update', $logs); ActivityReport::instance()->addLog('category', 'update', $logs);
@ -426,7 +427,7 @@ class ActivityBehaviors
); );
$logs = [ $logs = [
self::str($user_cn), self::str($user_cn),
self::str(dcCore::app()->auth?->getInfo('user_cn')), self::str(dcCore::app()->auth->getInfo('user_cn')),
]; ];
ActivityReport::instance()->addLog('user', 'create', $logs); ActivityReport::instance()->addLog('user', 'create', $logs);
} }
@ -441,7 +442,7 @@ class ActivityBehaviors
); );
$logs = [ $logs = [
self::str($user_cn), self::str($user_cn),
self::str(dcCore::app()->auth?->getInfo('user_cn')), self::str(dcCore::app()->auth->getInfo('user_cn')),
]; ];
ActivityReport::instance()->addLog('user', 'update', $logs); ActivityReport::instance()->addLog('user', 'update', $logs);
} }
@ -480,7 +481,7 @@ class ActivityBehaviors
); );
$logs = [ $logs = [
self::str($user_cn), self::str($user_cn),
self::str(dcCore::app()->auth?->getInfo('user_cn')), self::str(dcCore::app()->auth->getInfo('user_cn')),
]; ];
ActivityReport::instance()->addLog('user', 'delete', $logs); ActivityReport::instance()->addLog('user', 'delete', $logs);
} }

View File

@ -667,7 +667,7 @@ class ActivityReport
$headers[] = 'From: ' . (defined('DC_ADMIN_MAILFROM') && str_contains(DC_ADMIN_MAILFROM, '@') ? DC_ADMIN_MAILFROM : 'dotclear@local'); $headers[] = 'From: ' . (defined('DC_ADMIN_MAILFROM') && str_contains(DC_ADMIN_MAILFROM, '@') ? DC_ADMIN_MAILFROM : 'dotclear@local');
$headers[] = 'Content-Type: text/' . $mailformat . '; charset=UTF-8;'; $headers[] = 'Content-Type: text/' . $mailformat . '; charset=UTF-8;';
//$headers[] = 'MIME-Version: 1.0'; //$headers[] = 'MIME-Version: 1.0';
//$headers[] = 'X-Originating-IP: ' . mb_encode_mimeheader(http::realIP(), 'UTF-8', 'B'); //$headers[] = 'X-Originating-IP: ' . mb_encode_mimeheader(Http::realIP(), 'UTF-8', 'B');
//$headers[] = 'X-Mailer: Dotclear'; //$headers[] = 'X-Mailer: Dotclear';
//$headers[] = 'X-Blog-Id: ' . mb_encode_mimeheader(dcCore::app()->blog->id), 'UTF-8', 'B'); //$headers[] = 'X-Blog-Id: ' . mb_encode_mimeheader(dcCore::app()->blog->id), 'UTF-8', 'B');
//$headers[] = 'X-Blog-Name: ' . mb_encode_mimeheader(dcCore::app()->blog->name), 'UTF-8', 'B'); //$headers[] = 'X-Blog-Name: ' . mb_encode_mimeheader(dcCore::app()->blog->name), 'UTF-8', 'B');
@ -693,8 +693,8 @@ class ActivityReport
*/ */
public function getUserCode(): string public function getUserCode(): string
{ {
$id = is_string(dcCore::app()->auth?->userID()) ? dcCore::app()->auth->userID() : ''; $id = is_string(dcCore::app()->auth->userID()) ? dcCore::app()->auth->userID() : '';
$pw = is_string(dcCore::app()->auth?->getInfo('user_pwd')) ? dcCore::app()->auth->getInfo('user_pwd') : ''; $pw = is_string(dcCore::app()->auth->getInfo('user_pwd')) ? dcCore::app()->auth->getInfo('user_pwd') : '';
$code = pack('a32', $id) . pack('H*', Crypt::hmac(DC_MASTER_KEY, $pw)); $code = pack('a32', $id) . pack('H*', Crypt::hmac(DC_MASTER_KEY, $pw));
return bin2hex($code); return bin2hex($code);

View File

@ -15,13 +15,10 @@ declare(strict_types=1);
namespace Dotclear\Plugin\activityReport; namespace Dotclear\Plugin\activityReport;
use ArrayObject; use ArrayObject;
use dcAdmin;
use dcAuth; use dcAuth;
use dcCore; use dcCore;
use dcFavorites; use Dotclear\Core\Backend\Favorites;
use dcMenu; use Dotclear\Core\Process;
use dcNsProcess;
use dcPage;
use Dotclear\Helper\Date; use Dotclear\Helper\Date;
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Div, Div,
@ -34,54 +31,37 @@ use Dotclear\Helper\Html\Form\{
/** /**
* Backend process * Backend process
*/ */
class Backend extends dcNsProcess class Backend extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN') return self::status(My::checkContext(My::BACKEND));
&& defined('ACTIVITY_REPORT')
&& My::isInstalled();
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false; return false;
} }
if ((dcCore::app()->menu[dcAdmin::MENU_PLUGINS] instanceof dcMenu)) { My::addBackendMenuItem();
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
My::name(),
(string) 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']
),
(bool) dcCore::app()->auth?->check(dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_ADMIN,
]), dcCore::app()->blog?->id)
);
}
dcCore::app()->addBehaviors([ dcCore::app()->addBehaviors([
// dashboard favorites icon // dashboard favorites icon
'adminDashboardFavoritesV2' => function (dcFavorites $favs): void { 'adminDashboardFavoritesV2' => function (Favorites $favs): void {
$favs->register(My::id(), [ $favs->register(My::id(), [
'title' => My::name(), 'title' => My::name(),
'url' => dcCore::app()->adminurl?->get('admin.plugin.' . My::id()), 'url' => My::manageUrl(),
'small-icon' => dcPage::getPF(My::id() . '/icon.svg'), 'small-icon' => My::icons(),
'large-icon' => dcPage::getPF(My::id() . '/icon.svg'), 'large-icon' => My::icons(),
'permissions' => dcCore::app()->auth?->makePermissions([ 'permissions' => dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_ADMIN, dcAuth::PERMISSION_ADMIN,
]), ]),
]); ]);
}, },
// dashboard content display // dashboard content display
'adminDashboardContentsV2' => function (ArrayObject $items): void { 'adminDashboardContentsV2' => function (ArrayObject $items): void {
$db = dcCore::app()->auth?->user_prefs?->get(My::id())->get('dashboard_item'); $db = dcCore::app()->auth->user_prefs?->get(My::id())->get('dashboard_item');
$limit = abs(is_numeric($db) ? (int) $db : 0); $limit = abs(is_numeric($db) ? (int) $db : 0);
if (!$limit) { if (!$limit) {
return ; return ;
@ -109,7 +89,7 @@ class Backend extends dcNsProcess
'<br />' . Date::str( '<br />' . Date::str(
dcCore::app()->blog?->settings->get('system')->get('date_format') . ', ' . dcCore::app()->blog?->settings->get('system')->get('time_format'), dcCore::app()->blog?->settings->get('system')->get('date_format') . ', ' . dcCore::app()->blog?->settings->get('system')->get('time_format'),
(int) strtotime($row->dt), (int) strtotime($row->dt),
is_string(dcCore::app()->auth?->getInfo('user_tz')) ? dcCore::app()->auth->getInfo('user_tz') : 'UTC' is_string(dcCore::app()->auth->getInfo('user_tz')) ? dcCore::app()->auth->getInfo('user_tz') : 'UTC'
) . '<dt>' . ) . '<dt>' .
'<dd><p>' . '<dd><p>' .
'<em>' . ActivityReport::parseMessage(__($group->get($row->action)->message), $row->logs) . '</em></p></dd>'; '<em>' . ActivityReport::parseMessage(__($group->get($row->action)->message), $row->logs) . '</em></p></dd>';
@ -123,12 +103,12 @@ class Backend extends dcNsProcess
'<h3>' . My::name() . '</h3>' . '<h3>' . My::name() . '</h3>' .
'<dl id="reports">' . implode('', $lines) . '</dl>' . '<dl id="reports">' . implode('', $lines) . '</dl>' .
'<p class="modules"><a class="module-details" href="' . '<p class="modules"><a class="module-details" href="' .
dcCore::app()->adminurl?->get('admin.plugin.' . My::id()) . '">' . My::manageUrl() . '">' .
__('View all logs') . '</a> - <a class="module-config" href="' . __('View all logs') . '</a> - <a class="module-config" href="' .
dcCore::app()->adminurl?->get('admin.plugins', [ dcCore::app()->admin->url->get('admin.plugins', [
'module' => My::id(), 'module' => My::id(),
'conf' => 1, 'conf' => 1,
'redir' => dcCore::app()->adminurl->get('admin.home'), 'redir' => dcCore::app()->admin->url->get('admin.home'),
]) . '">' . ]) . '">' .
__('Configure plugin') . '</a></p>' . __('Configure plugin') . '</a></p>' .
'</div>', '</div>',
@ -136,7 +116,7 @@ class Backend extends dcNsProcess
}, },
// dashboard content user preference form // dashboard content user preference form
'adminDashboardOptionsFormV2' => function (): void { 'adminDashboardOptionsFormV2' => function (): void {
$db = dcCore::app()->auth?->user_prefs?->get(My::id())->get('dashboard_item'); $db = dcCore::app()->auth->user_prefs?->get(My::id())->get('dashboard_item');
echo echo
(new Div())->class('fieldset')->items([ (new Div())->class('fieldset')->items([
(new Text('h4', My::name())), (new Text('h4', My::name())),
@ -157,7 +137,7 @@ class Backend extends dcNsProcess
// save dashboard content user preference // save dashboard content user preference
'adminAfterDashboardOptionsUpdate' => function (?string $user_id = null): void { 'adminAfterDashboardOptionsUpdate' => function (?string $user_id = null): void {
if (!is_null($user_id)) { if (!is_null($user_id)) {
dcCore::app()->auth?->user_prefs?->get(My::id())->put( dcCore::app()->auth->user_prefs?->get(My::id())->put(
'dashboard_item', 'dashboard_item',
(int) $_POST[My::id() . '_dashboard_item'], (int) $_POST[My::id() . '_dashboard_item'],
'integer' 'integer'

View File

@ -56,7 +56,7 @@ class Combo
* *
* @return array<string,int> The obsolete period combo * @return array<string,int> The obsolete period combo
*/ */
public static function obselete(): array public static function obsolete(): array
{ {
return [ return [
__('every hour') => 3600, __('every hour') => 3600,

View File

@ -14,10 +14,9 @@ declare(strict_types=1);
namespace Dotclear\Plugin\activityReport; namespace Dotclear\Plugin\activityReport;
use dcAuth;
use dcCore; use dcCore;
use dcPage; use Dotclear\Core\Backend\Notices;
use dcNsProcess; use Dotclear\Core\Process;
use Dotclear\Helper\Date; use Dotclear\Helper\Date;
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Checkbox, Checkbox,
@ -35,22 +34,16 @@ use Exception;
/** /**
* Config process. * Config process.
*/ */
class Config extends dcNsProcess class Config extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init == defined('DC_CONTEXT_ADMIN') return self::status(My::checkContext(My::CONFIG));
&& defined('ACTIVITY_REPORT')
&& dcCore::app()->auth?->check(dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_ADMIN,
]), dcCore::app()->blog?->id);
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false; return false;
} }
@ -65,7 +58,7 @@ class Config extends dcNsProcess
if (in_array($_POST['interval'], Combo::interval())) { if (in_array($_POST['interval'], Combo::interval())) {
$s->set('interval', (int) $_POST['interval']); $s->set('interval', (int) $_POST['interval']);
} }
if (in_array($_POST['obsolete'], Combo::obselete())) { if (in_array($_POST['obsolete'], Combo::obsolete())) {
$s->set('obsolete', (int) $_POST['obsolete']); $s->set('obsolete', (int) $_POST['obsolete']);
} }
$s->set('mailinglist', explode(';', $_POST['mailinglist'])); $s->set('mailinglist', explode(';', $_POST['mailinglist']));
@ -73,26 +66,26 @@ class Config extends dcNsProcess
$s->set('dateformat', $_POST['dateformat']); $s->set('dateformat', $_POST['dateformat']);
$s->set('requests', $_POST['requests'] ?? []); $s->set('requests', $_POST['requests'] ?? []);
dcPage::addSuccessNotice( Notices::addSuccessNotice(
__('Configuration successfully updated.') __('Configuration successfully updated.')
); );
if (!empty($_POST['send_report_now'])) { if (!empty($_POST['send_report_now'])) {
ActivityReport::instance()->needReport(true); ActivityReport::instance()->needReport(true);
dcPage::addSuccessNotice( Notices::addSuccessNotice(
__('Report successfully sent.') __('Report successfully sent.')
); );
} }
if (!empty($_POST['delete_report_now'])) { if (!empty($_POST['delete_report_now'])) {
ActivityReport::instance()->deleteLogs(); ActivityReport::instance()->deleteLogs();
dcPage::addSuccessNotice( Notices::addSuccessNotice(
__('Logs successfully deleted.') __('Logs successfully deleted.')
); );
} }
dcCore::app()->adminurl?->redirect('admin.plugins', [ dcCore::app()->admin->url->redirect('admin.plugins', [
'module' => My::id(), 'module' => My::id(),
'conf' => 1, 'conf' => 1,
]); ]);
@ -105,12 +98,12 @@ class Config extends dcNsProcess
public static function render(): void public static function render(): void
{ {
if (!static::$init) { if (!self::status()) {
return; return;
} }
$s = ActivityReport::instance()->settings; $s = ActivityReport::instance()->settings;
$tz = is_string(dcCore::app()->auth?->getInfo('user_tz')) ? dcCore::app()->auth->getInfo('user_tz') : 'UTC'; $tz = is_string(dcCore::app()->auth->getInfo('user_tz')) ? dcCore::app()->auth->getInfo('user_tz') : 'UTC';
if (!$s->lastreport) { if (!$s->lastreport) {
$last_report = __('never'); $last_report = __('never');
@ -171,11 +164,11 @@ class Config extends dcNsProcess
]), ]),
(new Text( (new Text(
'ul', 'ul',
'<li><img alt="' . __('RSS feed') . '" src="' . dcPage::getPF(My::id() . '/img/feed.png') . '" /> ' . '<li><img alt="' . __('RSS feed') . '" src="' . My::fileURL('img/feed.png') . '" /> ' .
'<a title="' . __('RSS feed') . '" href="' . '<a title="' . __('RSS feed') . '" href="' .
dcCore::app()->blog?->url . dcCore::app()->url->getBase(My::id()) . '/rss2/' . ActivityReport::instance()->getUserCode() . '">' . dcCore::app()->blog?->url . dcCore::app()->url->getBase(My::id()) . '/rss2/' . ActivityReport::instance()->getUserCode() . '">' .
__('Rss2 activities feed') . '</a></li>' . __('Rss2 activities feed') . '</a></li>' .
'<li><img alt="' . __('Atom feed') . '" src="' . dcPage::getPF(My::id() . '/img/feed.png') . '" /> ' . '<li><img alt="' . __('Atom feed') . '" src="' . My::fileURL('img/feed.png') . '" /> ' .
'<a title="' . __('Atom feed') . '" href="' . '<a title="' . __('Atom feed') . '" href="' .
dcCore::app()->blog?->url . dcCore::app()->url->getBase(My::id()) . '/atom/' . ActivityReport::instance()->getUserCode() . '">' . dcCore::app()->blog?->url . dcCore::app()->url->getBase(My::id()) . '/atom/' . ActivityReport::instance()->getUserCode() . '">' .
__('Atom activities feed') . '</a></li>' __('Atom activities feed') . '</a></li>'
@ -211,8 +204,8 @@ class Config extends dcNsProcess
(new Div('settings'))->class('fieldset')->items([ (new Div('settings'))->class('fieldset')->items([
(new Text('h4', __('Maintenance'))), (new Text('h4', __('Maintenance'))),
(new Para())->items([ (new Para())->items([
(new Label(__('Automatic cleaning of old logs:'), Label::OUTSIDE_LABEL_BEFORE))->for('obselete'), (new Label(__('Automatic cleaning of old logs:'), Label::OUTSIDE_LABEL_BEFORE))->for('obsolete'),
(new Select('obselete'))->default((string) $s->obsolete)->items(Combo::obselete()), (new Select('obsolete'))->default((string) $s->obsolete)->items(Combo::obsolete()),
]), ]),
(new Para())->items([ (new Para())->items([
(new Checkbox('send_report_now'))->value(1), (new Checkbox('send_report_now'))->value(1),

View File

@ -15,24 +15,21 @@ declare(strict_types=1);
namespace Dotclear\Plugin\activityReport; namespace Dotclear\Plugin\activityReport;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process;
/** /**
* Front end process. * Front end process.
*/ */
class Frontend extends dcNsProcess class Frontend extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('ACTIVITY_REPORT') return self::status(My::checkContext(My::FRONTEND));
&& My::isInstalled();
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false; return false;
} }

View File

@ -15,7 +15,7 @@ declare(strict_types=1);
namespace Dotclear\Plugin\activityReport; namespace Dotclear\Plugin\activityReport;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process;
use Dotclear\Database\Structure; use Dotclear\Database\Structure;
use Dotclear\Database\Statement\{ use Dotclear\Database\Statement\{
DropStatement, DropStatement,
@ -26,20 +26,16 @@ use Exception;
/** /**
* Install process. * Install process.
*/ */
class Install extends dcNsProcess class Install extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN') return self::status(My::checkContext(My::INSTALL));
&& is_string(dcCore::app()->plugins->moduleInfo(My::id(), 'version'))
&& dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version'));
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false; return false;
} }

View File

@ -15,11 +15,13 @@ declare(strict_types=1);
namespace Dotclear\Plugin\activityReport; namespace Dotclear\Plugin\activityReport;
use ArrayObject; use ArrayObject;
use adminGenericFilter;
use dcAuth;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Backend\Filter\Filters;
use dcPage; use Dotclear\Core\Backend\{
Notices,
Page
};
use Dotclear\Core\Process;
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Form, Form,
Hidden, Hidden,
@ -32,30 +34,24 @@ use Exception;
/** /**
* Manage process (admin logs list). * Manage process (admin logs list).
*/ */
class Manage extends dcNsProcess class Manage extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN') return self::status(My::checkContext(My::MANAGE));
&& defined('ACTIVITY_REPORT')
&& dcCore::app()->auth?->check(dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_ADMIN,
]), dcCore::app()->blog?->id);
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false; return false;
} }
if (!empty($_POST['delete_all_logs']) || !empty($_POST['delete_reported_logs'])) { if (!empty($_POST['delete_all_logs']) || !empty($_POST['delete_reported_logs'])) {
try { try {
ActivityReport::instance()->deleteLogs(!empty($_POST['delete_reported_logs'])); ActivityReport::instance()->deleteLogs(!empty($_POST['delete_reported_logs']));
dcPage::addSuccessNotice(__('Logs successfully deleted')); Notices::addSuccessNotice(__('Logs successfully deleted'));
dcCore::app()->adminurl?->redirect('admin.plugin.' . My::id()); My::redirect();
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
@ -66,40 +62,40 @@ class Manage extends dcNsProcess
public static function render(): void public static function render(): void
{ {
if (!static::$init) { if (!self::status()) {
return; return;
} }
$logs = $counter = $list = null; $logs = $counter = $list = null;
$filter = new adminGenericFilter(dcCore::app(), My::id()); $filter = new Filters(My::id());
$params = new ArrayObject($filter->params()); $params = new ArrayObject($filter->params());
try { try {
$logs = ActivityReport::instance()->getLogs($params); $logs = ActivityReport::instance()->getLogs($params);
$counter = ActivityReport::instance()->getLogs($params, true); $counter = ActivityReport::instance()->getLogs($params, true);
if (!is_null($logs) && !is_null($counter)) { if (!is_null($logs) && !is_null($counter)) {
$list = new ManageList(dcCore::app(), $logs, $counter->f(0)); $list = new ManageList($logs, $counter->f(0));
} }
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
dcPage::openModule( Page::openModule(
My::name(), My::name(),
$filter->js((string) dcCore::app()->adminurl?->get('admin.plugin.' . My::id())) . $filter->js((string) My::manageUrl()) .
dcPage::jsJson(My::id(), ['confirm_delete' => __('Are you sure you want to delete logs?')]) . Page::jsJson(My::id(), ['confirm_delete' => __('Are you sure you want to delete logs?')]) .
dcPage::jsModuleLoad(My::id() . '/js/backend.js') . My::jsLoad('backend') .
# --BEHAVIOR-- activityReportListHeader -- # --BEHAVIOR-- activityReportListHeader --
dcCore::app()->callBehavior('activityReportListHeader') dcCore::app()->callBehavior('activityReportListHeader')
); );
echo echo
dcPage::breadcrumb([ Page::breadcrumb([
__('Plugins') => '', __('Plugins') => '',
My::name() => '', My::name() => '',
]) . ]) .
dcPage::notices(); Notices::getNotices();
if (!is_null($list)) { if (!is_null($list)) {
$filter->display('admin.plugin.' . My::id(), (new Hidden('p', My::id()))->render()); $filter->display('admin.plugin.' . My::id(), (new Hidden('p', My::id()))->render());
@ -112,11 +108,11 @@ class Manage extends dcNsProcess
(new Para())->class('right')->separator(' ')->items([ (new Para())->class('right')->separator(' ')->items([
(new Submit('delete_all_logs'))->class('delete')->value(__('Delete all aticivity logs')), (new Submit('delete_all_logs'))->class('delete')->value(__('Delete all aticivity logs')),
(new Submit('delete_reported_logs'))->class('delete')->value(__('Delete all allready reported logs')), (new Submit('delete_reported_logs'))->class('delete')->value(__('Delete all allready reported logs')),
dcCore::app()->formNonce(false), ... My::hiddenFields(),
]), ]),
])->render(); ])->render();
} }
dcPage::closeModule(); Page::closeModule();
} }
} }

View File

@ -15,18 +15,20 @@ declare(strict_types=1);
namespace Dotclear\Plugin\activityReport; namespace Dotclear\Plugin\activityReport;
use ArrayObject; use ArrayObject;
use adminGenericFilter;
use adminGenericList;
use dcCore; use dcCore;
use dcPager; use Dotclear\Core\Backend\Filter\Filters;
use Dotclear\Core\Backend\Listing\{
Listing,
Pager
};
use Dotclear\Helper\Date; use Dotclear\Helper\Date;
/** /**
* Logs admin list helper. * Logs admin list helper.
*/ */
class ManageList extends adminGenericList class ManageList extends Listing
{ {
public function logsDisplay(adminGenericFilter $filter, string $enclose_block = ''): void public function logsDisplay(Filters $filter, string $enclose_block = ''): void
{ {
if (!$this->rs || $this->rs->isEmpty()) { if (!$this->rs || $this->rs->isEmpty()) {
if ($filter->show()) { if ($filter->show()) {
@ -37,7 +39,7 @@ class ManageList extends adminGenericList
} else { } else {
$page = $filter->value('page'); $page = $filter->value('page');
$nbpp = $filter->value('nb'); $nbpp = $filter->value('nb');
$pager = new dcPager(is_numeric($page) ? (int) $page : 1, (int) $this->rs_count, is_numeric($nbpp) ? (int) $nbpp : 20, 10); $pager = new Pager(is_numeric($page) ? (int) $page : 1, (int) $this->rs_count, is_numeric($nbpp) ? (int) $nbpp : 20, 10);
$pager->var_page = 'page'; $pager->var_page = 'page';
$html_block = '<div class="table-outer"><table><caption>' . ( $html_block = '<div class="table-outer"><table><caption>' . (
@ -83,7 +85,7 @@ class ManageList extends adminGenericList
$date = Date::str( $date = Date::str(
dcCore::app()->blog?->settings->get('system')->get('date_format') . ', ' . dcCore::app()->blog?->settings->get('system')->get('time_format'), dcCore::app()->blog?->settings->get('system')->get('date_format') . ', ' . dcCore::app()->blog?->settings->get('system')->get('time_format'),
(int) strtotime($row->dt), (int) strtotime($row->dt),
is_string(dcCore::app()->auth?->getInfo('user_tz')) ? dcCore::app()->auth->getInfo('user_tz') : 'UTC' is_string(dcCore::app()->auth->getInfo('user_tz')) ? dcCore::app()->auth->getInfo('user_tz') : 'UTC'
); );
$status = $row->status == ActivityReport::STATUS_PENDING ? __('pending') : __('reported'); $status = $row->status == ActivityReport::STATUS_PENDING ? __('pending') : __('reported');

View File

@ -15,11 +15,12 @@ declare(strict_types=1);
namespace Dotclear\Plugin\activityReport; namespace Dotclear\Plugin\activityReport;
use dcCore; use dcCore;
use Dotclear\Module\MyPlugin;
/** /**
* This module definitions. * This module definitions.
*/ */
class My class My extends MyPlugin
{ {
/** @var string Activity database table name */ /** @var string Activity database table name */
public const ACTIVITY_TABLE_NAME = 'activity'; public const ACTIVITY_TABLE_NAME = 'activity';
@ -27,30 +28,23 @@ class My
/** @var int Incremental version by breaking changes */ /** @var int Incremental version by breaking changes */
public const COMPATIBILITY_VERSION = 3; public const COMPATIBILITY_VERSION = 3;
/** public static function checkCustomContext(int $context): ?bool
* This module id.
*/
public static function id(): string
{ {
return basename(dirname(__DIR__)); switch($context) {
} case My::FRONTEND:
return defined('ACTIVITY_REPORT') && My::isInstalled();
/** case My::BACKEND:
* This module name. return defined('DC_CONTEXT_ADMIN') && defined('ACTIVITY_REPORT') && My::isInstalled();
*/ case My::CONFIG:
public static function name(): string case My::MANAGE:
{ return defined('DC_CONTEXT_ADMIN')
$name = dcCore::app()->plugins->moduleInfo(self::id(), 'name'); && defined('ACTIVITY_REPORT')
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
return __(is_string($name) ? $name : self::id()); dcCore::app()->auth::PERMISSION_ADMIN,
} ]), dcCore::app()->blog?->id);
default:
/** return null;
* This module path. }
*/
public static function path(): string
{
return dirname(__DIR__);
} }
/** /**
@ -60,6 +54,6 @@ class My
*/ */
public static function isInstalled(): bool public static function isInstalled(): bool
{ {
return dcCore::app()->getVersion(self::id()) == dcCore::app()->plugins->moduleInfo(self::id(), 'version'); return dcCore::app()->getVersion(self::id()) == (string) dcCore::app()->plugins->getDefine(self::id())->get('version');
} }
} }

View File

@ -15,25 +15,22 @@ declare(strict_types=1);
namespace Dotclear\Plugin\activityReport; namespace Dotclear\Plugin\activityReport;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process;
use Exception; use Exception;
/** /**
* Prepend process. * Prepend process.
*/ */
class Prepend extends dcNsProcess class Prepend extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_RC_PATH') return self::status(My::checkContext(My::PREPEND));
&& My::isInstalled();
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false; return false;
} }

View File

@ -14,9 +14,6 @@ declare(strict_types=1);
namespace Dotclear\Plugin\activityReport; namespace Dotclear\Plugin\activityReport;
use dcCore;
use Exception;
/** /**
* Module settings helper. * Module settings helper.
*/ */
@ -51,10 +48,6 @@ class Settings
*/ */
public function __construct() public function __construct()
{ {
if (is_null(dcCore::app()->blog)) {
throw new Exception('Blog is not set');
}
$this->feed_active = (bool) ($this->get('feed_active') ?? false); $this->feed_active = (bool) ($this->get('feed_active') ?? false);
$this->obsolete = is_numeric($this->get('obsolete')) ? (int) $this->get('obsolete') : 2419200; $this->obsolete = is_numeric($this->get('obsolete')) ? (int) $this->get('obsolete') : 2419200;
$this->interval = is_numeric($this->get('interval')) ? (int) $this->get('interval') : 86400; $this->interval = is_numeric($this->get('interval')) ? (int) $this->get('interval') : 86400;
@ -86,7 +79,7 @@ class Settings
public function set(string $key, mixed $value): void public function set(string $key, mixed $value): void
{ {
if (property_exists($this, $key) && gettype($value) == gettype($this->{$key})) { if (property_exists($this, $key) && gettype($value) == gettype($this->{$key})) {
dcCore::app()->blog?->settings->get(My::id())->put( My::settings()->put(
$key, $key,
$value, $value,
gettype($value), gettype($value),
@ -106,6 +99,6 @@ class Settings
*/ */
private function get(string $key): mixed private function get(string $key): mixed
{ {
return dcCore::app()->blog?->settings->get(My::id())->get($key); return My::settings()->get($key);
} }
} }

View File

@ -15,7 +15,7 @@ declare(strict_types=1);
namespace Dotclear\Plugin\activityReport; namespace Dotclear\Plugin\activityReport;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process;
use Dotclear\Plugin\Uninstaller\Uninstaller; use Dotclear\Plugin\Uninstaller\Uninstaller;
/** /**
@ -23,18 +23,16 @@ use Dotclear\Plugin\Uninstaller\Uninstaller;
* *
* Using plugin Uninstaller * Using plugin Uninstaller
*/ */
class Uninstall extends dcNsProcess class Uninstall extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN'); return self::status(My::checkContext(My::UNINSTALL));
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init || !dcCore::app()->plugins->moduleExists('Uninstaller')) { if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
return false; return false;
} }