diff --git a/src/Combo.php b/src/Combo.php index 2c7da57..71af346 100644 --- a/src/Combo.php +++ b/src/Combo.php @@ -22,7 +22,7 @@ class Combo /** * Mail content formats. * - * @return array The formats combo + * @return array The formats combo */ public static function mailformat(): array { @@ -37,7 +37,7 @@ class Combo /** * Get report intervals. * - * @return array The intervals combo + * @return array 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 The obsolete period combo */ public static function obselete(): array { diff --git a/src/Config.php b/src/Config.php index 9901812..2246e06 100644 --- a/src/Config.php +++ b/src/Config.php @@ -109,7 +109,8 @@ class Config extends dcNsProcess 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'; 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 ); } diff --git a/src/Context.php b/src/Context.php index 6878204..500e2b5 100644 --- a/src/Context.php +++ b/src/Context.php @@ -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 ''; } diff --git a/src/Format.php b/src/Format.php index 02ee987..37b97af 100644 --- a/src/Format.php +++ b/src/Format.php @@ -58,8 +58,8 @@ class Format /** * Constructor sets format id. * - * @param string $id The format ID - * @param array $format The format values + * @param string $id The format ID + * @param array $format The format values */ public function __construct( public readonly string $id, diff --git a/src/Install.php b/src/Install.php index b326650..04d01db 100644 --- a/src/Install.php +++ b/src/Install.php @@ -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')) { diff --git a/src/ManageList.php b/src/ManageList.php index 6a19874..758b7ca 100644 --- a/src/ManageList.php +++ b/src/ManageList.php @@ -35,7 +35,9 @@ class ManageList extends adminGenericList echo '

' . __('No log') . '

'; } } 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 = '
' . ( @@ -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'); diff --git a/src/Settings.php b/src/Settings.php index c22d1f9..ca6e375 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -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 $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 $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') : []; } /** diff --git a/src/Template.php b/src/Template.php index 419f771..4ab6df6 100644 --- a/src/Template.php +++ b/src/Template.php @@ -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']); } diff --git a/src/UrlHandler.php b/src/UrlHandler.php index 4b8a6cc..962479f 100644 --- a/src/UrlHandler.php +++ b/src/UrlHandler.php @@ -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); } }