2021-09-02 22:04:20 +00:00
|
|
|
<?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:04:20 +00:00
|
|
|
|
2021-09-02 22:51:23 +00:00
|
|
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (!defined('ACTIVITY_REPORT')) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-09-02 22:04:20 +00:00
|
|
|
|
|
|
|
$_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'),
|
2021-09-03 21:16:53 +00:00
|
|
|
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)
|
2021-09-02 22:04:20 +00:00
|
|
|
);
|
|
|
|
|
2021-09-03 21:27:22 +00:00
|
|
|
if ($core->activityReport->getSetting('active')) {
|
|
|
|
$core->addBehavior('adminDashboardContents', ['activityReportAdmin', 'adminDashboardContents']);
|
|
|
|
$core->addBehavior('adminDashboardOptionsForm', ['activityReportAdmin', 'adminDashboardOptionsForm']);
|
|
|
|
$core->addBehavior('adminAfterDashboardOptionsUpdate', ['activityReportAdmin', 'adminAfterDashboardOptionsUpdate']);
|
|
|
|
}
|
2021-09-02 22:04:20 +00:00
|
|
|
|
|
|
|
class activityReportAdmin
|
|
|
|
{
|
2021-09-03 21:16:53 +00:00
|
|
|
public static function adminDashboardContents(dcCore $core, $items)
|
2021-09-02 22:18:08 +00:00
|
|
|
{
|
2021-09-03 21:16:53 +00:00
|
|
|
$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[] =
|
|
|
|
'<dt title="' . __($groups[$group]['title']) . '">' .
|
|
|
|
'<strong>' . __($groups[$group]['actions'][$rs->activity_action]['title']) . '</strong>' .
|
|
|
|
'<br />' . dt::str(
|
|
|
|
$core->blog->settings->system->date_format . ', ' . $core->blog->settings->system->time_format,
|
|
|
|
strtotime($rs->activity_dt),
|
|
|
|
$core->auth->getInfo('user_tz')
|
|
|
|
) . '<dt>' .
|
|
|
|
'<dd><p>' .
|
|
|
|
'<em>' .vsprintf(
|
|
|
|
__($groups[$group]['actions'][$rs->activity_action]['msg']),
|
|
|
|
$core->activityReport->decode($rs->activity_logs)
|
|
|
|
) . '</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>' .
|
2021-09-03 21:59:50 +00:00
|
|
|
'<p class="modules"><a class="module-details" href="'.
|
|
|
|
$core->adminurl->get('admin.plugin.activityReport') .'">' .
|
|
|
|
__('View all logs') . '</a> - <a class="module-config" href="'.
|
|
|
|
$core->adminurl->get('admin.plugins', [
|
|
|
|
'module' => 'activityReport',
|
|
|
|
'conf' => 1,
|
|
|
|
'redir' => $core->adminurl->get('admin.home').'#activity-report-logs'
|
|
|
|
]) .'">' .
|
|
|
|
__('Configure plugin') . '</a></p>' .
|
2021-09-03 21:16:53 +00:00
|
|
|
'</div>'
|
|
|
|
]);
|
2021-09-02 22:18:08 +00:00
|
|
|
}
|
2021-09-02 22:04:20 +00:00
|
|
|
|
2021-09-03 21:16:53 +00:00
|
|
|
public static function adminDashboardOptionsForm(dcCore $core)
|
2021-09-02 22:18:08 +00:00
|
|
|
{
|
2021-09-03 21:16:53 +00:00
|
|
|
$core->auth->user_prefs->addWorkspace('activityReport');
|
2021-09-02 22:04:20 +00:00
|
|
|
|
2021-09-03 21:16:53 +00:00
|
|
|
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>';
|
|
|
|
}
|
2021-09-02 22:04:20 +00:00
|
|
|
|
2021-09-03 21:16:53 +00:00
|
|
|
public static function adminAfterDashboardOptionsUpdate($user_id = null)
|
|
|
|
{
|
|
|
|
global $core;
|
2021-09-02 22:04:20 +00:00
|
|
|
|
2021-09-03 21:16:53 +00:00
|
|
|
if (is_null($user_id)) {
|
|
|
|
return;
|
2021-09-02 22:18:08 +00:00
|
|
|
}
|
2021-09-03 21:16:53 +00:00
|
|
|
|
|
|
|
$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;
|
2021-09-02 22:18:08 +00:00
|
|
|
}
|
2021-09-03 21:16:53 +00:00
|
|
|
return in_array($q, $l) ? $l[$q] : 0;
|
2021-09-02 22:18:08 +00:00
|
|
|
}
|
|
|
|
}
|