diff --git a/src/ActivityReport.php b/src/ActivityReport.php index 09758c1..ead177b 100644 --- a/src/ActivityReport.php +++ b/src/ActivityReport.php @@ -303,21 +303,22 @@ class ActivityReport { $from = time(); $to = 0; - $res = $blog = $group = ''; + $res = $blog_name = $blog_url = $group = ''; $tz = dcCore::app()->blog?->settings->get('system')->get('blog_timezone'); $dt = empty($this->settings->dateformat) ? '%Y-%m-%d %H:%M:%S' : $this->settings->dateformat; $format = $this->formats->get($this->formats->has($this->settings->mailformat) ? $this->settings->mailformat : 'plain'); $group_open = false; while ($rs->fetch()) { - if ($this->groups->has($rs->f('activity_group')) && $this->groups->get($rs->f('activity_group'))->has($rs->f('activity_action'))) { + $row = new ActivityRow($rs); + if ($this->groups->has($row->group) && $this->groups->get($row->group)->has($row->action)) { // Type - if ($rs->f('activity_group') != $group) { + if ($row->group != $group) { if ($group_open) { $res .= $format->group_close; } - $group = $rs->f('activity_group'); + $group = $row->group; $res .= str_replace( '%TEXT%', @@ -329,12 +330,11 @@ class ActivityReport } // Action - $time = strtotime($rs->f('activity_dt')); - $data = json_decode($rs->f('activity_logs'), true); + $time = strtotime($row->dt); $res .= str_replace( ['%TIME%', '%TEXT%'], - [Date::str($dt, (int) $time, $tz), vsprintf(__($this->groups->get($group)->get($rs->f('activity_action'))->message), $data)], + [Date::str($dt, (int) $time, $tz), vsprintf(__($this->groups->get($group)->get($row->action)->message), $row->logs)], $format->action ); @@ -346,6 +346,8 @@ class ActivityReport $to = $time; } } + $blog_name = $row->blog_name; + $blog_url = $row->blog_url; } if ($group_open) { @@ -372,8 +374,8 @@ class ActivityReport $format->info ); - $period .= str_replace('%TEXT%', $rs->f('blog_name'), $format->info); - $period .= str_replace('%TEXT%', $rs->f('blog_url'), $format->info); + $period .= str_replace('%TEXT%', $blog_name, $format->info); + $period .= str_replace('%TEXT%', $blog_url, $format->info); $period .= str_replace( '%TEXT%', diff --git a/src/ActivityRow.php b/src/ActivityRow.php new file mode 100644 index 0000000..d4cb196 --- /dev/null +++ b/src/ActivityRow.php @@ -0,0 +1,71 @@ + The log data */ + public readonly array $logs; + + /** + * Constructor sets properties. + * + * @param MetaRecord $rs The record + */ + public function __construct( + public readonly MetaRecord $rs + ) { + $this->id = is_numeric($this->rs->f('activity_id')) ? (int) $this->rs->f('activity_id') : 0; + $this->blog_id = is_string($this->rs->f('blog_id')) ? $this->rs->f('blog_id') : null; + $this->blog_url = is_string($this->rs->f('blog_url')) ? $this->rs->f('blog_url') : ''; + $this->blog_name = is_string($this->rs->f('blog_name')) ? $this->rs->f('blog_name') : ''; + $this->group = is_string($this->rs->f('activity_group')) ? $this->rs->f('activity_group') : ''; + $this->action = is_string($this->rs->f('activity_action')) ? $this->rs->f('activity_action') : ''; + $this->dt = is_string($this->rs->f('activity_dt')) ? $this->rs->f('activity_dt') : ''; + $this->status = is_numeric($this->rs->f('activity_status')) ? (int) $this->rs->f('activity_status') : 0; + + $logs = json_decode(is_string($this->rs->f('activity_logs')) ? $this->rs->f('activity_logs') : '', true); + $this->logs = is_array($logs) ? $logs : []; + } +} diff --git a/src/Backend.php b/src/Backend.php index 850b2b6..8ef3d49 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -19,6 +19,7 @@ use dcAdmin; use dcAuth; use dcCore; use dcFavorites; +use dcMenu; use dcNsProcess; use dcPage; use Dotclear\Helper\Date; @@ -50,18 +51,20 @@ class Backend extends dcNsProcess return false; } - dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->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?->check(dcCore::app()->auth->makePermissions([ - dcAuth::PERMISSION_ADMIN, - ]), dcCore::app()->blog?->id) - ); + if ((dcCore::app()->menu[dcAdmin::MENU_PLUGINS] instanceof dcMenu)) { + 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([ // dashboard favorites icon @@ -78,7 +81,8 @@ class Backend extends dcNsProcess }, // dashboard content display 'adminDashboardContentsV2' => function (ArrayObject $items): void { - $limit = abs((int) 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); if (!$limit) { return ; } @@ -95,20 +99,20 @@ class Backend extends dcNsProcess $lines = []; $groups = ActivityReport::instance()->groups; while ($rs->fetch()) { - if (!$groups->has($rs->f('activity_group'))) { + $row = new ActivityRow($rs); + if (!$groups->has($row->group)) { continue; } - $group = $groups->get($rs->f('activity_group')); - $data = json_decode($rs->f('activity_logs'), true); + $group = $groups->get($row->group); $lines[] = '
' . - '' . ActivityReport::parseMessage(__($group->get($rs->f('activity_action'))->message), $data) . '