activityReport/_admin.php

148 lines
5.2 KiB
PHP
Raw Normal View History

<?php
2021-09-02 22:18:08 +00:00
/**
* @brief activityReport, a plugin for Dotclear 2
2022-11-18 20:24:30 +00:00
*
2021-09-02 22:18:08 +00:00
* @package Dotclear
* @subpackage Plugin
2022-11-18 20:24:30 +00:00
*
2021-09-02 22:18:08 +00:00
* @author Jean-Christian Denis and contributors
2022-11-18 20:24:30 +00:00
*
2021-09-02 22:18:08 +00:00
* @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;
}
2022-11-18 20:24:30 +00:00
if (!defined('ACTIVITY_REPORT_V2')) {
2021-09-02 22:51:23 +00:00
return null;
}
2022-11-18 20:24:30 +00:00
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
2021-09-02 22:18:08 +00:00
__('Activity report'),
2022-11-18 20:24:30 +00:00
dcCore::app()->adminurl->get('admin.plugin.activityReport'),
2021-09-02 22:51:23 +00:00
dcPage::getPF('activityReport/icon.png'),
2021-09-03 21:16:53 +00:00
preg_match(
2022-11-18 20:24:30 +00:00
'/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.activityReport')) . '(&.*)?$/',
2021-09-03 21:16:53 +00:00
$_SERVER['REQUEST_URI']
),
2022-11-18 20:24:30 +00:00
dcCore::app()->auth->check(dcAuth::PERMISSION_ADMIN, dcCore::app()->blog->id)
);
2022-11-18 20:24:30 +00:00
if (dcCore::app()->activityReport->getSetting('active')) {
dcCore::app()->addBehavior('adminDashboardContentsV2', ['activityReportAdmin', 'adminDashboardContents']);
dcCore::app()->addBehavior('adminDashboardOptionsFormV2', ['activityReportAdmin', 'adminDashboardOptionsForm']);
dcCore::app()->addBehavior('adminAfterDashboardOptionsUpdate', ['activityReportAdmin', 'adminAfterDashboardOptionsUpdate']);
2021-09-03 21:27:22 +00:00
}
class activityReportAdmin
{
2022-11-18 20:24:30 +00:00
public static function adminDashboardContents($items)
2021-09-02 22:18:08 +00:00
{
2022-11-18 20:24:30 +00:00
dcCore::app()->auth->user_prefs->addWorkspace('activityReport');
$limit = abs((int) dcCore::app()->auth->user_prefs->activityReport->dashboard_item);
2021-09-03 21:16:53 +00:00
if (!$limit) {
return null;
}
$p = [
'limit' => $limit,
'order' => 'activity_dt DESC',
2022-11-18 20:24:30 +00:00
'sql' => dcCore::app()->activityReport->requests2params(dcCore::app()->activityReport->getSetting('requests')),
2021-09-03 21:16:53 +00:00
];
$lines = [];
2022-11-18 20:24:30 +00:00
$rs = dcCore::app()->activityReport->getLogs($p);
2021-09-03 21:16:53 +00:00
if ($rs->isEmpty()) {
return null;
}
2022-11-18 20:24:30 +00:00
$groups = dcCore::app()->activityReport->getGroups();
while ($rs->fetch()) {
2021-09-03 21:16:53 +00:00
$group = $rs->activity_group;
if (!isset($groups[$group])) {
continue;
}
2022-11-18 20:24:30 +00:00
$lines[] = '<dt title="' . __($groups[$group]['title']) . '">' .
2021-09-03 21:16:53 +00:00
'<strong>' . __($groups[$group]['actions'][$rs->activity_action]['title']) . '</strong>' .
'<br />' . dt::str(
2022-11-18 20:24:30 +00:00
dcCore::app()->blog->settings->system->date_format . ', ' . dcCore::app()->blog->settings->system->time_format,
2021-09-03 21:16:53 +00:00
strtotime($rs->activity_dt),
2022-11-18 20:24:30 +00:00
dcCore::app()->auth->getInfo('user_tz')
2021-09-03 21:16:53 +00:00
) . '<dt>' .
'<dd><p>' .
2022-11-18 20:24:30 +00:00
'<em>' . vsprintf(
2021-09-03 21:16:53 +00:00
__($groups[$group]['actions'][$rs->activity_action]['msg']),
2022-11-18 20:24:30 +00:00
dcCore::app()->activityReport->decode($rs->activity_logs)
2021-09-03 21:16:53 +00:00
) . '</em></p></dd>';
}
if (empty($lines)) {
return null;
}
$items[] = new ArrayObject([
'<div id="activity-report-logs" class="box medium">' .
'<h3>' . __('Activity report') . '</h3>' .
'<dl id="reports">' . implode('', $lines) . '</dl>' .
2022-11-18 20:24:30 +00:00
'<p class="modules"><a class="module-details" href="' .
dcCore::app()->adminurl->get('admin.plugin.activityReport') . '">' .
__('View all logs') . '</a> - <a class="module-config" href="' .
dcCore::app()->adminurl->get('admin.plugins', [
'module' => 'activityReport',
'conf' => 1,
'redir' => dcCore::app()->adminurl->get('admin.home') . '#activity-report-logs',
]) . '">' .
__('Configure plugin') . '</a></p>' .
2022-11-18 20:24:30 +00:00
'</div>',
2021-09-03 21:16:53 +00:00
]);
2021-09-02 22:18:08 +00:00
}
2022-11-18 20:24:30 +00:00
public static function adminDashboardOptionsForm()
2021-09-02 22:18:08 +00:00
{
2022-11-18 20:24:30 +00:00
dcCore::app()->auth->user_prefs->addWorkspace('activityReport');
2021-09-03 21:16:53 +00:00
echo
'<div class="fieldset">' .
'<h4>' . __('Activity report') . '</h4>' .
2022-11-18 20:24:30 +00:00
'<p><label for="activityReport_dashboard_item">' .
2021-09-03 21:16:53 +00:00
__('Number of activities to show on dashboard:') . '</label>' .
form::combo(
2022-11-18 20:24:30 +00:00
'activityReport_dashboard_item',
self::comboList(),
self::comboList(dcCore::app()->auth->user_prefs->activityReport->dashboard_item)
2021-09-03 21:16:53 +00:00
) . '</p>' .
'</div>';
}
2021-09-03 21:16:53 +00:00
public static function adminAfterDashboardOptionsUpdate($user_id = null)
{
if (is_null($user_id)) {
return;
2021-09-02 22:18:08 +00:00
}
2021-09-03 21:16:53 +00:00
2022-11-18 20:24:30 +00:00
dcCore::app()->auth->user_prefs->addWorkspace('activityReport');
dcCore::app()->auth->user_prefs->activityReport->put(
'dashboard_item',
self::comboList(@$_POST['activityReport_dashboard_item']),
2021-09-03 21:16:53 +00:00
'integer'
);
}
private static function comboList($q = true)
{
$l = [
__('Do not show activity report') => 0,
2022-11-18 20:24:30 +00:00
5 => 5,
10 => 10,
15 => 15,
20 => 20,
50 => 50,
100 => 100,
2021-09-03 21:16:53 +00:00
];
if (true === $q) {
return $l;
2021-09-02 22:18:08 +00:00
}
2022-11-18 20:24:30 +00:00
if (!$q) {
$q = -1;
}
2021-09-03 21:16:53 +00:00
return in_array($q, $l) ? $l[$q] : 0;
2021-09-02 22:18:08 +00:00
}
2022-11-18 20:24:30 +00:00
}