activityReport/_admin.php

86 lines
2.5 KiB
PHP
Raw Normal View History

<?php
2021-09-02 22:18:08 +00:00
/**
* @brief activityReport, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
2021-09-02 22:51:23 +00:00
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
if (!defined('ACTIVITY_REPORT')) {
return null;
}
# Plugin menu
$_menu['Plugins']->addItem(
2021-09-02 22:18:08 +00:00
__('Activity report'),
2021-09-02 22:51:23 +00:00
$core->adminurl->get('admin.plugin.activityReport'),
dcPage::getPF('activityReport/icon.png'),
preg_match('/' . preg_quote($core->adminurl->get('admin.plugin.activityReport')) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
2021-09-02 22:18:08 +00:00
$core->auth->check('admin',$core->blog->id)
);
# Dashboarditems
2021-09-02 22:51:23 +00:00
if ($core->activityReport->getSetting('dashboardItem')) {
$core->addBehavior('adminDashboardHeaders', ['activityReportAdmin', 'dashboardHeaders']);
$core->addBehavior('adminDashboardItems', ['activityReportAdmin', 'dashboardItems']);
}
class activityReportAdmin
{
2021-09-02 22:51:23 +00:00
/**
* Add CSS to dashboardHeaders for items
*/
2021-09-02 22:18:08 +00:00
public static function dashboardHeaders()
{
2021-09-02 22:51:23 +00:00
return dcPage::jsLoad('index.php?pf=activityReport/style.css');
2021-09-02 22:18:08 +00:00
}
2021-09-02 22:51:23 +00:00
/**
* Add report to dashboardItems
*/
public static function dashboardItems(dcCore $core, $__dashboard_items)
2021-09-02 22:18:08 +00:00
{
$r = $core->activityReport->getSetting('requests');
$g = $core->activityReport->getGroups();
2021-09-02 22:18:08 +00:00
$p = array();
$p['limit'] = 20;
$p['order'] = 'activity_dt DESC';
$p['sql'] = $core->activityReport->requests2params($r);
2021-09-02 22:18:08 +00:00
$res = '';
$rs = $core->activityReport->getLogs($p);
2021-09-02 22:51:23 +00:00
if (!$rs->isEmpty()) {
while($rs->fetch()) {
2021-09-02 22:18:08 +00:00
$group = $rs->activity_group;
2021-09-02 22:51:23 +00:00
if (!isset($g[$group])) {
continue;
}
2021-09-02 22:18:08 +00:00
$res .=
2021-09-02 22:51:23 +00:00
'<dd><p title="' . __($g[$group]['title']) . '"><strong>' .
__($g[$group]['actions'][$rs->activity_action]['title']) .
'</p></strong><em>' .
2021-09-02 22:18:08 +00:00
vsprintf(
__($g[$group]['actions'][$rs->activity_action]['msg']),
$core->activityReport->decode($rs->activity_logs)
2021-09-02 22:51:23 +00:00
) .
2021-09-02 22:18:08 +00:00
'</em></dd>';
}
}
2021-09-02 22:51:23 +00:00
if (!empty($res)) {
2021-09-02 22:18:08 +00:00
$__dashboard_items[1][] =
2021-09-02 22:51:23 +00:00
'<h3>' . __('Activity report') . '</h3>' .
'<dl id="report">' . $res . '</dl>';
2021-09-02 22:18:08 +00:00
}
}
}