fix type hint (WIP)

This commit is contained in:
Jean-Christian Paul Denis 2023-05-12 00:37:45 +02:00
parent 043045f373
commit 2b6587d081
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
9 changed files with 66 additions and 39 deletions

View File

@ -22,7 +22,7 @@ class Combo
/**
* Mail content formats.
*
* @return array The formats combo
* @return array<string,string> The formats combo
*/
public static function mailformat(): array
{
@ -37,7 +37,7 @@ class Combo
/**
* Get report intervals.
*
* @return array The intervals combo
* @return array<string,int> The intervals combo
*/
public static function interval(): array
{
@ -54,7 +54,7 @@ class Combo
/**
* Get obsolete period.
*
* @return array The obsolete period combo
* @return array<string,int> The obsolete period combo
*/
public static function obselete(): array
{

View File

@ -110,6 +110,7 @@ class Config extends dcNsProcess
}
$s = ActivityReport::instance()->settings;
$tz = is_string(dcCore::app()->auth?->getInfo('user_tz')) ? dcCore::app()->auth?->getInfo('user_tz') : 'UTC';
if (!$s->lastreport) {
$last_report = __('never');
@ -118,12 +119,12 @@ class Config extends dcNsProcess
$last_report = Date::str(
dcCore::app()->blog?->settings->get('system')->get('date_format') . ', ' . dcCore::app()->blog?->settings->get('system')->get('time_format'),
$s->lastreport,
dcCore::app()->auth?->getInfo('user_tz')
$tz
);
$next_report = Date::str(
dcCore::app()->blog?->settings->get('system')->get('date_format') . ', ' . dcCore::app()->blog?->settings->get('system')->get('time_format'),
$s->interval + $s->lastreport,
dcCore::app()->auth?->getInfo('user_tz')
$tz
);
}

View File

@ -15,6 +15,7 @@ declare(strict_types=1);
namespace Dotclear\Plugin\activityReport;
use dcCore;
use Dotclear\Database\MetaRecord;
/**
* Template helper.
@ -28,14 +29,20 @@ class Context
*/
public static function parseTitle(): string
{
if (!dcCore::app()->ctx || !dcCore::app()->ctx->exists('activityreports')) {
if (!dcCore::app()->ctx
|| !dcCore::app()->ctx->exists('activityreports')
|| !(dcCore::app()->ctx->__get('activityreports') instanceof MetaRecord)
) {
return '';
}
$group = dcCore::app()->ctx->__get('activityreports')->activity_group;
$action = dcCore::app()->ctx->__get('activityreports')->activity_action;
$group = dcCore::app()->ctx->__get('activityreports')->f('activity_group');
$action = dcCore::app()->ctx->__get('activityreports')->f('activity_action');
if (!ActivityReport::instance()->groups->get($group)->has($action)) {
if (!is_string($group)
|| !is_string($action)
|| !ActivityReport::instance()->groups->get($group)->has($action)
) {
return '';
}
@ -49,15 +56,23 @@ class Context
*/
public static function parseContent(): string
{
if (!dcCore::app()->ctx || !dcCore::app()->ctx->exists('activityreports')) {
if (!dcCore::app()->ctx
|| !dcCore::app()->ctx->exists('activityreports')
|| !(dcCore::app()->ctx->__get('activityreports') instanceof MetaRecord)
) {
return '';
}
$group = dcCore::app()->ctx->__get('activityreports')->activity_group;
$action = dcCore::app()->ctx->__get('activityreports')->activity_action;
$logs = json_decode((string) dcCore::app()->ctx->__get('activityreports')->activity_logs, true);
$group = dcCore::app()->ctx->__get('activityreports')->f('activity_group');
$action = dcCore::app()->ctx->__get('activityreports')->f('activity_action');
$logs = dcCore::app()->ctx->__get('activityreports')->f('activity_logs');
$logs = json_decode(is_string($logs) ? $logs : '', true);
if (!is_array($logs) || !ActivityReport::instance()->groups->get($group)->has($action)) {
if (!is_string($group)
|| !is_string($action)
|| !is_array($logs)
|| !ActivityReport::instance()->groups->get($group)->has($action)
) {
return '';
}

View File

@ -59,7 +59,7 @@ class Format
* Constructor sets format id.
*
* @param string $id The format ID
* @param array $format The format values
* @param array<string,string> $format The format values
*/
public function __construct(
public readonly string $id,

View File

@ -31,6 +31,7 @@ class Install extends dcNsProcess
public static function init(): bool
{
static::$init = defined('DC_CONTEXT_ADMIN')
&& is_string(dcCore::app()->plugins->moduleInfo(My::id(), 'version'))
&& dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version'));
return static::$init;
@ -77,10 +78,10 @@ class Install extends dcNsProcess
*/
private static function beforeGrowUp(): void
{
$current = dcCore::app()->getVersion('activityReport');
// sorry not sorry we restart from scratch
if ($current && version_compare($current, '3.0', '<')) {
if (is_string(dcCore::app()->getVersion('activityReport'))
&& version_compare(dcCore::app()->getVersion('activityReport'), '3.0', '<')
) {
$struct = new Structure(dcCore::app()->con, dcCore::app()->prefix);
if ($struct->tableExists('activity')) {

View File

@ -35,7 +35,9 @@ class ManageList extends adminGenericList
echo '<p><strong>' . __('No log') . '</strong></p>';
}
} else {
$pager = new dcPager((int) $filter->value('page'), (int) $this->rs_count, (int) $filter->value('nb'), 10);
$page = $filter->value('page');
$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->var_page = 'page';
$html_block = '<div class="table-outer"><table><caption>' . (
@ -75,12 +77,12 @@ class ManageList extends adminGenericList
$offline = (int) $this->rs->f('activity_status') == ActivityReport::STATUS_REPORTED ? ' offline' : '';
$group = ActivityReport::instance()->groups->get($this->rs->f('activity_group'));
$action = $group->get($this->rs->f('activity_action'));
$message = json_decode((string) $this->rs->f('activity_logs'), true);
$message = ActivityReport::parseMessage(__($action->message), $message);
$data = json_decode((string) $this->rs->f('activity_logs'), true);
$message = ActivityReport::parseMessage(__($action->message), is_array($data) ? $data : []);
$date = Date::str(
dcCore::app()->blog?->settings->get('system')->get('date_format') . ', ' . dcCore::app()->blog?->settings->get('system')->get('time_format'),
(int) strtotime((string) $this->rs->f('activity_dt')),
dcCore::app()->auth?->getInfo('user_tz')
is_string(dcCore::app()->auth?->getInfo('user_tz')) ? dcCore::app()->auth->getInfo('user_tz') : 'UTC'
);
$status = (int) $this->rs->f('activity_status') == ActivityReport::STATUS_PENDING ? __('pending') : __('reported');

View File

@ -34,7 +34,7 @@ class Settings
/** @var int $lastreport The last report time */
public readonly int $lastreport;
/** @var array $mailinglist The mailing list */
/** @var array<int,string> $mailinglist The mailing list */
public readonly array $mailinglist;
/** @var string $mailformat The mail content format */
@ -43,7 +43,7 @@ class Settings
/** @var string $date format The date format */
public readonly string $dateformat;
/** @var array $requests The selected actions list to report */
/** @var array<string,array{string,int}> $requests The selected actions list to report */
public readonly array $requests;
/**
@ -56,13 +56,13 @@ class Settings
}
$this->feed_active = (bool) ($this->get('feed_active') ?? false);
$this->obsolete = (int) ($this->get('obsolete') ?? 2419200);
$this->interval = (int) ($this->get('interval') ?? 86400);
$this->lastreport = (int) ($this->get('lastreport') ?? 0);
$this->mailinglist = (array) ($this->get('mailinglist') ?? []);
$this->mailformat = (string) ($this->get('mailformat') ?? 'plain');
$this->dateformat = (string) ($this->get('dateformat') ?? '%Y-%m-%d %H:%M:%S');
$this->requests = (array) ($this->get('requests') ?? []);
$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->lastreport = is_numeric($this->get('lastreport')) ? (int) $this->get('lastreport') : 0;
$this->mailinglist = is_array($this->get('mailinglist')) ? $this->get('mailinglist') : [];
$this->mailformat = is_string($this->get('mailformat')) ? $this->get('mailformat') : 'plain';
$this->dateformat = is_string($this->get('dateformat')) ? $this->get('dateformat') : '%Y-%m-%d %H:%M:%S';
$this->requests = is_array($this->get('requests')) ? $this->get('requests') : [];
}
/**

View File

@ -39,7 +39,7 @@ class Template
public static function activityReports(ArrayObject $attr, string $content): string
{
$lastn = 0;
if (isset($attr['lastn'])) {
if (isset($attr['lastn']) && is_numeric($attr['lastn'])) {
$lastn = abs((int) $attr['lastn']) + 0;
}
@ -139,7 +139,7 @@ class Template
public static function activityReportDate(ArrayObject $attr): string
{
$format = '';
if (!empty($attr['format'])) {
if (!empty($attr['format']) && is_string($attr['format'])) {
$format = addslashes($attr['format']);
}

View File

@ -38,7 +38,11 @@ class UrlHandler extends dcUrlHandlers
) {
self::p404();
}
/*
if (!is_array($m) || count($m) < 2 || !is_string($m[1]) || !is_string($m[2])) {
self::p404();
}
*/
// get type of feed
$mime = $m[1] == 'atom' ? 'application/atom+xml' : 'application/xml';
if (false === ActivityReport::instance()->checkUserCode($m[2])) {
@ -46,11 +50,15 @@ class UrlHandler extends dcUrlHandlers
}
// feed limits
dcCore::app()->ctx->__set('nb_entry_per_page', (int) dcCore::app()->blog?->settings->get('system')->get('nb_post_per_feed'));
dcCore::app()->ctx->__set('short_feed_items', (int) dcCore::app()->blog?->settings->get('system')->get('short_feed_items'));
$nb = dcCore::app()->blog?->settings->get('system')->get('nb_post_per_feed');
//$it = dcCore::app()->blog?->settings->get('system')->get('short_feed_items');
$rb = dcCore::app()->blog?->settings->get('system')->get('robots_policy');
dcCore::app()->ctx->__set('nb_entry_per_page', is_numeric($nb) ? (int) $nb : 20);
// dcCore::app()->ctx->__set('short_feed_items', is_numerci($it) ? (int) $it : 1);
// serve activity feed template
header('X-Robots-Tag: ' . context::robotsPolicy(dcCore::app()->blog?->settings->get('system')->get('robots_policy'), ''));
header('X-Robots-Tag: ' . context::robotsPolicy(is_string($rb) ? $rb : '', ''));
self::serveDocument('activityreport-' . $m[1] . '.xml', $mime);
}
}