fix and enhance dashboard content

This commit is contained in:
Jean-Christian Paul Denis 2021-09-03 23:16:53 +02:00
parent 9386b1b4cd
commit 54747275eb
3 changed files with 98 additions and 55 deletions

View File

@ -18,69 +18,120 @@ if (!defined('ACTIVITY_REPORT')) {
return null; return null;
} }
# Plugin menu
$_menu['Plugins']->addItem( $_menu['Plugins']->addItem(
__('Activity report'), __('Activity report'),
$core->adminurl->get('admin.plugin.activityReport'), $core->adminurl->get('admin.plugin.activityReport'),
dcPage::getPF('activityReport/icon.png'), 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) $core->auth->check('admin',$core->blog->id)
); );
# Dashboarditems $core->addBehavior('adminDashboardOptionsForm', ['activityReportAdmin', 'adminDashboardOptionsForm']);
if ($core->activityReport->getSetting('dashboardItem')) { $core->addBehavior('adminAfterDashboardOptionsUpdate', ['activityReportAdmin', 'adminAfterDashboardOptionsUpdate']);
$core->addBehavior('adminDashboardHeaders', ['activityReportAdmin', 'dashboardHeaders']);
$core->addBehavior('adminDashboardItems', ['activityReportAdmin', 'dashboardItems']);
}
class activityReportAdmin class activityReportAdmin
{ {
/** public static function adminDashboardContents(dcCore $core, $items)
* Add CSS to dashboardHeaders for items
*/
public static function dashboardHeaders()
{ {
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,
* Add report to dashboardItems 'order' => 'activity_dt DESC',
*/ 'sql' => $core->activityReport->requests2params($core->activityReport->getSetting('requests'))
public static function dashboardItems(dcCore $core, $__dashboard_items) ];
{ $lines = [];
$r = $core->activityReport->getSetting('requests');
$g = $core->activityReport->getGroups();
$p = array();
$p['limit'] = 20;
$p['order'] = 'activity_dt DESC';
$p['sql'] = $core->activityReport->requests2params($r);
$res = '';
$rs = $core->activityReport->getLogs($p); $rs = $core->activityReport->getLogs($p);
if (!$rs->isEmpty()) { if ($rs->isEmpty()) {
return null;
}
$groups = $core->activityReport->getGroups();
while($rs->fetch()) { while($rs->fetch()) {
$group = $rs->activity_group; $group = $rs->activity_group;
if (!isset($g[$group])) { if (!isset($groups[$group])) {
continue; continue;
} }
$lines[] =
$res .= '<dt title="' . __($groups[$group]['title']) . '">' .
'<dd><p title="' . __($g[$group]['title']) . '"><strong>' . '<strong>' . __($groups[$group]['actions'][$rs->activity_action]['title']) . '</strong>' .
__($g[$group]['actions'][$rs->activity_action]['title']) . '<br />' . dt::str(
'</p></strong><em>' . $core->blog->settings->system->date_format . ', ' . $core->blog->settings->system->time_format,
vsprintf( strtotime($rs->activity_dt),
__($g[$group]['actions'][$rs->activity_action]['msg']), $core->auth->getInfo('user_tz')
) . '<dt>' .
'<dd><p>' .
'<em>' .vsprintf(
__($groups[$group]['actions'][$rs->activity_action]['msg']),
$core->activityReport->decode($rs->activity_logs) $core->activityReport->decode($rs->activity_logs)
) . ) . '</em></p></dd>';
'</em></dd>';
} }
if (empty($lines)) {
return null;
} }
if (!empty($res)) { $items[] = new ArrayObject([
$__dashboard_items[1][] = '<div id="activity-report-logs" class="box medium">' .
'<h3>' . __('Activity report') . '</h3>' . '<h3>' . __('Activity report') . '</h3>' .
'<dl id="report">' . $res . '</dl>'; '<dl id="reports">' . implode('', $lines) . '</dl>' .
} '<p><a href="'.$core->adminurl->get('admin.plugin.activityReport') .'">' .
__('View all logs') . '</a></p>' .
'</div>'
]);
}
public static function adminDashboardOptionsForm(dcCore $core)
{
$core->auth->user_prefs->addWorkspace('activityReport');
echo
'<div class="fieldset">' .
'<h4>' . __('Activity report') . '</h4>' .
'<p><label for="activityReport_dashboard_item">' .
__('Number of activities to show on dashboard:') . '</label>' .
form::combo(
'activityReport_dashboard_item',
self::comboList(),
self::comboList($core->auth->user_prefs->activityReport->dashboard_item)
) . '</p>' .
'</div>';
}
public static function adminAfterDashboardOptionsUpdate($user_id = null)
{
global $core;
if (is_null($user_id)) {
return;
}
$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;
} }
} }

View File

@ -51,7 +51,6 @@ $combo_format = [
if (!empty($_POST['save'])) { if (!empty($_POST['save'])) {
try { try {
$report->setSetting('active', !empty($_POST['active'])); $report->setSetting('active', !empty($_POST['active']));
$report->setSetting('dashboardItem', !empty($_POST['dashboardItem']));
if (in_array($_POST['interval'], $combo_interval)) { if (in_array($_POST['interval'], $combo_interval)) {
$report->setSetting('interval', (integer) $_POST['interval']); $report->setSetting('interval', (integer) $_POST['interval']);
} }
@ -114,20 +113,14 @@ if (activityReport::hasMailer()) {
echo ' echo '
<div class="fieldset two-cols" id="settings"><h4>' . __('Settings') . '</h4> <div class="fieldset two-cols" id="settings"><h4>' . __('Settings') . '</h4>
<div class="col"> <div class="col">
<p><label class="classic" for="active">' . <p><label class="classic" for="active">' .
form::checkbox('active', '1', $report->getSetting('active')).' '. form::checkbox('active', '1', $report->getSetting('active')).' '.
($super ? ($super ?
__('Enable super administrator report') : __('Enable super administrator report') :
__('Enable report on this blog') __('Enable report on this blog')
) . '</label></p>'; ) . '</label></p>
if (!$super) {
echo
'<p><label class="classic" for="dashboardItem">' .
form::checkbox('dashboardItem', 1, $report->getSetting('dashboardItem')).' '.
__('Add activity report on dashboard items') . '</label></p>';
}
echo '
<p><label for="obselete">' . __('Automatic cleaning of old logs:') . '</label>' . <p><label for="obselete">' . __('Automatic cleaning of old logs:') . '</label>' .
form::combo('obsolete', $combo_obselete, $report->getSetting('obsolete')) . '</p> form::combo('obsolete', $combo_obselete, $report->getSetting('obsolete')) . '</p>

View File

@ -92,7 +92,6 @@ class activityReport
$settings = [ $settings = [
'active' => false, 'active' => false,
'obsolete' => 2419200, 'obsolete' => 2419200,
'dashboardItem' => false,
'interval' => 86400, 'interval' => 86400,
'lastreport' => 0, 'lastreport' => 0,
'mailinglist' => [], 'mailinglist' => [],