2021-09-02 22:04:20 +00:00
|
|
|
<?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;
|
|
|
|
}
|
2021-09-02 22:04:20 +00:00
|
|
|
|
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-12-15 23:32:15 +00:00
|
|
|
dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__)),
|
|
|
|
dcPage::getPF(basename(__DIR__) . '/icon.png'),
|
2021-09-03 21:16:53 +00:00
|
|
|
preg_match(
|
2022-12-15 23:32:15 +00:00
|
|
|
'/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__))) . '(&.*)?$/',
|
2021-09-03 21:16:53 +00:00
|
|
|
$_SERVER['REQUEST_URI']
|
|
|
|
),
|
2022-11-30 21:34:52 +00:00
|
|
|
dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
|
|
|
|
dcAuth::PERMISSION_ADMIN,
|
|
|
|
]), dcCore::app()->blog->id)
|
2021-09-02 22:04:20 +00:00
|
|
|
);
|
|
|
|
|
2022-11-18 20:24:30 +00:00
|
|
|
if (dcCore::app()->activityReport->getSetting('active')) {
|
2022-12-20 19:55:48 +00:00
|
|
|
dcCore::app()->addBehavior('adminDashboardContentsV2', ['activityReportAdmin', 'adminDashboardContentsV2']);
|
|
|
|
dcCore::app()->addBehavior('adminDashboardOptionsFormV2', ['activityReportAdmin', 'adminDashboardOptionsFormV2']);
|
2022-11-18 20:24:30 +00:00
|
|
|
dcCore::app()->addBehavior('adminAfterDashboardOptionsUpdate', ['activityReportAdmin', 'adminAfterDashboardOptionsUpdate']);
|
2021-09-03 21:27:22 +00:00
|
|
|
}
|
2021-09-02 22:04:20 +00:00
|
|
|
|
|
|
|
class activityReportAdmin
|
|
|
|
{
|
2022-12-20 19:55:48 +00:00
|
|
|
public static function adminDashboardContentsV2($items)
|
2021-09-02 22:18:08 +00:00
|
|
|
{
|
2022-12-15 23:32:15 +00:00
|
|
|
dcCore::app()->auth->user_prefs->addWorkspace(basename(__DIR__));
|
|
|
|
$limit = abs((int) dcCore::app()->auth->user_prefs->__get(basename(__DIR__))->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="' .
|
2022-12-15 23:32:15 +00:00
|
|
|
dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__)) . '">' .
|
2022-11-18 20:24:30 +00:00
|
|
|
__('View all logs') . '</a> - <a class="module-config" href="' .
|
|
|
|
dcCore::app()->adminurl->get('admin.plugins', [
|
2022-12-15 23:32:15 +00:00
|
|
|
'module' => basename(__DIR__),
|
2022-11-18 20:24:30 +00:00
|
|
|
'conf' => 1,
|
|
|
|
'redir' => dcCore::app()->adminurl->get('admin.home') . '#activity-report-logs',
|
|
|
|
]) . '">' .
|
2021-09-03 21:59:50 +00:00
|
|
|
__('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
|
|
|
}
|
2021-09-02 22:04:20 +00:00
|
|
|
|
2022-12-20 19:55:48 +00:00
|
|
|
public static function adminDashboardOptionsFormV2()
|
2021-09-02 22:18:08 +00:00
|
|
|
{
|
2022-12-15 23:32:15 +00:00
|
|
|
dcCore::app()->auth->user_prefs->addWorkspace(basename(__DIR__));
|
2021-09-02 22:04:20 +00:00
|
|
|
|
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(),
|
2022-12-15 23:32:15 +00:00
|
|
|
self::comboList(dcCore::app()->auth->user_prefs->__get(basename(__DIR__))->dashboard_item)
|
2021-09-03 21:16:53 +00:00
|
|
|
) . '</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)
|
|
|
|
{
|
|
|
|
if (is_null($user_id)) {
|
|
|
|
return;
|
2021-09-02 22:18:08 +00:00
|
|
|
}
|
2021-09-03 21:16:53 +00:00
|
|
|
|
2022-12-15 23:32:15 +00:00
|
|
|
dcCore::app()->auth->user_prefs->addWorkspace(basename(__DIR__));
|
|
|
|
dcCore::app()->auth->user_prefs->__get(basename(__DIR__))->put(
|
2022-11-18 20:24:30 +00:00
|
|
|
'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
|
|
|
}
|