From 54747275eb0c46a3d3270e8a4b0be82840fdb49e Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Fri, 3 Sep 2021 23:16:53 +0200 Subject: [PATCH] fix and enhance dashboard content --- _admin.php | 141 +++++++++++++++++++++++----------- _config.php | 11 +-- inc/class.activity.report.php | 1 - 3 files changed, 98 insertions(+), 55 deletions(-) diff --git a/_admin.php b/_admin.php index 4d11688..b41f5f3 100644 --- a/_admin.php +++ b/_admin.php @@ -18,69 +18,120 @@ if (!defined('ACTIVITY_REPORT')) { return null; } -# Plugin menu $_menu['Plugins']->addItem( __('Activity report'), $core->adminurl->get('admin.plugin.activityReport'), dcPage::getPF('activityReport/icon.png'), - preg_match('/' . preg_quote($core->adminurl->get('admin.plugin.activityReport')) . '(&.*)?$/', $_SERVER['REQUEST_URI']), + preg_match( + '/' . preg_quote($core->adminurl->get('admin.plugin.activityReport')) . '(&.*)?$/', + $_SERVER['REQUEST_URI'] + ), $core->auth->check('admin',$core->blog->id) ); -# Dashboarditems -if ($core->activityReport->getSetting('dashboardItem')) { - $core->addBehavior('adminDashboardHeaders', ['activityReportAdmin', 'dashboardHeaders']); - $core->addBehavior('adminDashboardItems', ['activityReportAdmin', 'dashboardItems']); -} +$core->addBehavior('adminDashboardOptionsForm', ['activityReportAdmin', 'adminDashboardOptionsForm']); +$core->addBehavior('adminAfterDashboardOptionsUpdate', ['activityReportAdmin', 'adminAfterDashboardOptionsUpdate']); class activityReportAdmin { - /** - * Add CSS to dashboardHeaders for items - */ - public static function dashboardHeaders() + public static function adminDashboardContents(dcCore $core, $items) { - return dcPage::jsLoad('index.php?pf=activityReport/style.css'); + $core->auth->user_prefs->addWorkspace('activityReport'); + $limit = abs((integer) $core->auth->user_prefs->activityReport->dashboard_item); + if (!$limit) { + return null; + } + $p = [ + 'limit' => $limit, + 'order' => 'activity_dt DESC', + 'sql' => $core->activityReport->requests2params($core->activityReport->getSetting('requests')) + ]; + $lines = []; + $rs = $core->activityReport->getLogs($p); + if ($rs->isEmpty()) { + return null; + } + $groups = $core->activityReport->getGroups(); + while($rs->fetch()) { + $group = $rs->activity_group; + + if (!isset($groups[$group])) { + continue; + } + $lines[] = + '
' . + '' . __($groups[$group]['actions'][$rs->activity_action]['title']) . '' . + '
' . dt::str( + $core->blog->settings->system->date_format . ', ' . $core->blog->settings->system->time_format, + strtotime($rs->activity_dt), + $core->auth->getInfo('user_tz') + ) . '
' . + '

' . + '' .vsprintf( + __($groups[$group]['actions'][$rs->activity_action]['msg']), + $core->activityReport->decode($rs->activity_logs) + ) . '

'; + } + if (empty($lines)) { + return null; + } + $items[] = new ArrayObject([ + '
' . + '

' . __('Activity report') . '

' . + '
' . implode('', $lines) . '
' . + '

' . + __('View all logs') . '

' . + '
' + ]); } - /** - * Add report to dashboardItems - */ - public static function dashboardItems(dcCore $core, $__dashboard_items) + public static function adminDashboardOptionsForm(dcCore $core) { - $r = $core->activityReport->getSetting('requests'); - $g = $core->activityReport->getGroups(); + $core->auth->user_prefs->addWorkspace('activityReport'); - $p = array(); - $p['limit'] = 20; - $p['order'] = 'activity_dt DESC'; - $p['sql'] = $core->activityReport->requests2params($r); + echo + '
' . + '

' . __('Activity report') . '

' . + '

' . + form::combo( + 'activityReport_dashboard_item', + self::comboList(), + self::comboList($core->auth->user_prefs->activityReport->dashboard_item) + ) . '

' . + '
'; + } - $res = ''; - $rs = $core->activityReport->getLogs($p); - if (!$rs->isEmpty()) { - while($rs->fetch()) { - $group = $rs->activity_group; + public static function adminAfterDashboardOptionsUpdate($user_id = null) + { + global $core; - if (!isset($g[$group])) { - continue; - } - - $res .= - '

' . - __($g[$group]['actions'][$rs->activity_action]['title']) . - '

' . - vsprintf( - __($g[$group]['actions'][$rs->activity_action]['msg']), - $core->activityReport->decode($rs->activity_logs) - ) . - '
'; - } + if (is_null($user_id)) { + return; } - if (!empty($res)) { - $__dashboard_items[1][] = - '

' . __('Activity report') . '

' . - '
' . $res . '
'; + + $core->auth->user_prefs->addWorkspace('activityReport'); + $core->auth->user_prefs->activityReport->put( + 'dashboard_item', + self::comboList(@$_POST['activityReport_dashboard_item']), + 'integer' + ); + } + + private static function comboList($q = true) + { + $l = [ + __('Do not show activity report') => 0, + 5 => 5, + 10 => 10, + 15 => 15, + 20 => 20, + 50 => 50, + 100 => 100 + ]; + if (true === $q) { + return $l; } + return in_array($q, $l) ? $l[$q] : 0; } } \ No newline at end of file diff --git a/_config.php b/_config.php index d280339..2ddbc37 100644 --- a/_config.php +++ b/_config.php @@ -51,7 +51,6 @@ $combo_format = [ if (!empty($_POST['save'])) { try { $report->setSetting('active', !empty($_POST['active'])); - $report->setSetting('dashboardItem', !empty($_POST['dashboardItem'])); if (in_array($_POST['interval'], $combo_interval)) { $report->setSetting('interval', (integer) $_POST['interval']); } @@ -114,20 +113,14 @@ if (activityReport::hasMailer()) { echo '

' . __('Settings') . '

+

'; +) . '

-if (!$super) { - echo - '

'; -} -echo '

' . form::combo('obsolete', $combo_obselete, $report->getSetting('obsolete')) . '

diff --git a/inc/class.activity.report.php b/inc/class.activity.report.php index 9a8a76a..8191fa6 100644 --- a/inc/class.activity.report.php +++ b/inc/class.activity.report.php @@ -92,7 +92,6 @@ class activityReport $settings = [ 'active' => false, 'obsolete' => 2419200, - 'dashboardItem' => false, 'interval' => 86400, 'lastreport' => 0, 'mailinglist' => [],