2021-09-03 08:04:56 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @brief activityReport, a plugin for Dotclear 2
|
2022-11-18 20:24:30 +00:00
|
|
|
*
|
2021-09-03 08:04:56 +00:00
|
|
|
* @package Dotclear
|
|
|
|
* @subpackage Plugin
|
2022-11-18 20:24:30 +00:00
|
|
|
*
|
2021-09-03 08:04:56 +00:00
|
|
|
* @author Jean-Christian Denis and contributors
|
2022-11-18 20:24:30 +00:00
|
|
|
*
|
2021-09-03 08:04:56 +00:00
|
|
|
* @copyright Jean-Christian Denis
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
*/
|
|
|
|
if (!defined('DC_CONTEXT_MODULE')) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-11-18 20:24:30 +00:00
|
|
|
$super = dcCore::app()->auth->isSuperAdmin() && !empty($_REQUEST['super']);
|
|
|
|
$redir = empty($_REQUEST['redir']) ? dcCore::app()->admin->list->getURL() . '#plugins' : $_REQUEST['redir'];
|
2021-09-03 08:04:56 +00:00
|
|
|
|
2021-09-03 19:07:05 +00:00
|
|
|
if ($super) {
|
2022-11-18 20:24:30 +00:00
|
|
|
dcCore::app()->activityReport->setGlobal();
|
2021-09-03 19:07:05 +00:00
|
|
|
}
|
|
|
|
|
2021-09-03 18:05:28 +00:00
|
|
|
$combo_interval = [
|
2022-11-18 20:24:30 +00:00
|
|
|
__('every hour') => 3600,
|
|
|
|
__('every 2 hours') => 7200,
|
2021-09-03 18:05:28 +00:00
|
|
|
__('2 times by day') => 43200,
|
2022-11-18 20:24:30 +00:00
|
|
|
__('every day') => 86400,
|
|
|
|
__('every 2 days') => 172800,
|
|
|
|
__('every week') => 604800,
|
2021-09-03 18:05:28 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
$combo_obselete = [
|
2022-11-18 20:24:30 +00:00
|
|
|
__('every hour') => 3600,
|
|
|
|
__('every 2 hours') => 7200,
|
2021-09-03 18:05:28 +00:00
|
|
|
__('2 times by day') => 43200,
|
2022-11-18 20:24:30 +00:00
|
|
|
__('every day') => 86400,
|
|
|
|
__('every 2 days') => 172800,
|
|
|
|
__('every week') => 604800,
|
|
|
|
__('every 2 weeks') => 1209600,
|
|
|
|
__('every 4 weeks') => 2419200,
|
2021-09-03 18:05:28 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
$combo_format = [
|
|
|
|
__('Plain text') => 'plain',
|
2022-11-18 20:24:30 +00:00
|
|
|
__('HTML') => 'html',
|
2021-09-03 18:05:28 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
if (!empty($_POST['save'])) {
|
|
|
|
try {
|
2022-11-18 20:24:30 +00:00
|
|
|
dcCore::app()->activityReport->setSetting('active', !empty($_POST['active']));
|
2021-09-03 18:05:28 +00:00
|
|
|
if (in_array($_POST['interval'], $combo_interval)) {
|
2022-11-18 20:24:30 +00:00
|
|
|
dcCore::app()->activityReport->setSetting('interval', (int) $_POST['interval']);
|
2021-09-03 18:05:28 +00:00
|
|
|
}
|
|
|
|
if (in_array($_POST['obsolete'], $combo_obselete)) {
|
2022-11-18 20:24:30 +00:00
|
|
|
dcCore::app()->activityReport->setSetting('obsolete', (int) $_POST['obsolete']);
|
2021-09-03 18:05:28 +00:00
|
|
|
}
|
2022-11-18 20:24:30 +00:00
|
|
|
dcCore::app()->activityReport->setSetting('mailinglist', explode(';', $_POST['mailinglist']));
|
|
|
|
dcCore::app()->activityReport->setSetting('mailformat', isset($_POST['mailformat']) && $_POST['mailformat'] == 'html' ? 'html' : 'plain');
|
|
|
|
dcCore::app()->activityReport->setSetting('dateformat', html::escapeHTML($_POST['dateformat']));
|
|
|
|
dcCore::app()->activityReport->setSetting('requests', $_POST['requests'] ?? []);
|
|
|
|
dcCore::app()->activityReport->setSetting('blogs', $_POST['blogs'] ?? []);
|
2021-09-03 18:05:28 +00:00
|
|
|
|
2021-09-04 13:23:58 +00:00
|
|
|
if (!empty($_POST['send_report_now'])) {
|
2022-11-18 20:24:30 +00:00
|
|
|
dcCore::app()->activityReport->needReport(true);
|
2021-09-04 13:23:58 +00:00
|
|
|
|
2022-11-18 20:24:30 +00:00
|
|
|
dcAdminNotices::addSuccessNotice(
|
2021-09-04 13:23:58 +00:00
|
|
|
__('Report successfully sent.')
|
|
|
|
);
|
2021-09-03 18:05:28 +00:00
|
|
|
}
|
2021-09-04 13:23:58 +00:00
|
|
|
if (!empty($_POST['delete_report_now'])) {
|
2022-11-18 20:24:30 +00:00
|
|
|
dcCore::app()->activityReport->deleteLogs();
|
2021-09-04 13:23:58 +00:00
|
|
|
|
2022-11-18 20:24:30 +00:00
|
|
|
dcAdminNotices::addSuccessNotice(
|
2021-09-04 13:23:58 +00:00
|
|
|
__('Logs successfully deleted.')
|
|
|
|
);
|
2021-09-03 18:05:28 +00:00
|
|
|
}
|
|
|
|
|
2022-11-18 20:24:30 +00:00
|
|
|
dcAdminNotices::addSuccessNotice(
|
2021-09-04 13:23:58 +00:00
|
|
|
__('Configuration successfully updated.')
|
2021-09-03 18:05:28 +00:00
|
|
|
);
|
2022-11-18 20:24:30 +00:00
|
|
|
dcCore::app()->adminurl->redirect('admin.plugins', ['module' => 'activityReport', 'conf' => 1, 'super' => $super]);
|
2021-09-03 18:05:28 +00:00
|
|
|
} catch (Exception $e) {
|
2022-11-18 20:24:30 +00:00
|
|
|
dcCore::app()->error->add($e->getMessage());
|
2021-09-03 18:05:28 +00:00
|
|
|
}
|
2021-09-03 08:04:56 +00:00
|
|
|
}
|
|
|
|
|
2022-11-18 20:24:30 +00:00
|
|
|
$last_report_ts = dcCore::app()->activityReport->getSetting('lastreport');
|
2021-09-03 18:05:28 +00:00
|
|
|
if (!$last_report_ts) {
|
|
|
|
$last_report = __('never');
|
|
|
|
$next_report = __('on new activity');
|
|
|
|
} else {
|
|
|
|
$last_report = dt::str(
|
2022-11-18 20:24:30 +00:00
|
|
|
dcCore::app()->blog->settings->system->date_format . ', ' . dcCore::app()->blog->settings->system->time_format,
|
|
|
|
$last_report_ts,
|
|
|
|
dcCore::app()->auth->getInfo('user_tz')
|
2021-09-03 18:05:28 +00:00
|
|
|
);
|
|
|
|
$next_report = dt::str(
|
2022-11-18 20:24:30 +00:00
|
|
|
dcCore::app()->blog->settings->system->date_format . ', ' . dcCore::app()->blog->settings->system->time_format,
|
|
|
|
(int) dcCore::app()->activityReport->getSetting('interval') + $last_report_ts,
|
|
|
|
dcCore::app()->auth->getInfo('user_tz')
|
2021-09-03 18:05:28 +00:00
|
|
|
);
|
|
|
|
}
|
2022-11-18 20:24:30 +00:00
|
|
|
$emails = implode(';', dcCore::app()->activityReport->getSetting('mailinglist'));
|
2021-09-03 08:04:56 +00:00
|
|
|
|
2022-11-27 21:30:17 +00:00
|
|
|
echo '<h4>' . ($super ? __('All blogs') : __('Current blog')) . '</h4>';
|
|
|
|
|
2022-11-18 20:24:30 +00:00
|
|
|
if (dcCore::app()->auth->isSuperAdmin()) {
|
2021-09-03 18:05:28 +00:00
|
|
|
echo sprintf(
|
2022-11-18 20:24:30 +00:00
|
|
|
'<p class="modules right"><a class="module-config" href="%s">%s</a><br class="clear"/></p>',
|
|
|
|
dcCore::app()->adminurl->get('admin.plugins', ['module' => 'activityReport', 'conf' => 1, 'super' => !$super]),
|
2022-11-27 21:30:17 +00:00
|
|
|
sprintf(__('Configure activity report for %s'), $super ? __('current blog') : __('all blogs'))
|
2021-09-03 18:05:28 +00:00
|
|
|
);
|
|
|
|
}
|
2021-09-04 00:19:12 +00:00
|
|
|
if (!activityReport::hasMailer()) {
|
2021-09-03 18:05:28 +00:00
|
|
|
echo '<p class="message">' .
|
|
|
|
__('This server has no mail function, activityReport does not send email report.') .
|
|
|
|
'</p>';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
|
|
|
<div class="fieldset two-cols" id="settings"><h4>' . __('Settings') . '</h4>
|
|
|
|
<div class="col">
|
2021-09-03 21:16:53 +00:00
|
|
|
|
2021-09-03 18:05:28 +00:00
|
|
|
<p><label class="classic" for="active">' .
|
2022-11-18 20:24:30 +00:00
|
|
|
form::checkbox('active', '1', dcCore::app()->activityReport->getSetting('active')) . ' ' .
|
|
|
|
(
|
|
|
|
$super ?
|
2021-09-03 18:05:28 +00:00
|
|
|
__('Enable super administrator report') :
|
|
|
|
__('Enable report on this blog')
|
2021-09-03 21:16:53 +00:00
|
|
|
) . '</label></p>
|
2021-09-03 18:05:28 +00:00
|
|
|
|
|
|
|
<p><label for="obselete">' . __('Automatic cleaning of old logs:') . '</label>' .
|
2022-11-18 20:24:30 +00:00
|
|
|
form::combo('obsolete', $combo_obselete, dcCore::app()->activityReport->getSetting('obsolete')) . '</p>
|
2021-09-03 18:05:28 +00:00
|
|
|
|
2022-11-18 20:24:30 +00:00
|
|
|
<p><label for="dateformat">' . __('Date format:') . '<br />' .
|
|
|
|
form::field('dateformat', 60, 255, dcCore::app()->activityReport->getSetting('dateformat')) . '</label></p>
|
2021-09-03 18:05:28 +00:00
|
|
|
<p class="form-note">' . __('Use Dotclear date formaters. ex: %B %d at %H:%M') . '</p>' .
|
|
|
|
|
|
|
|
form::hidden(['super'], $super);
|
|
|
|
|
|
|
|
if (!$super) {
|
2022-11-18 20:24:30 +00:00
|
|
|
echo
|
|
|
|
'<p><img alt="' . __('RSS feed') . '" src="' . dcPage::getPF('activityReport/inc/img/feed.png') . '" />' .
|
|
|
|
'<a title="' . __('RSS feed') . '" href="' .
|
|
|
|
dcCore::app()->blog->url . dcCore::app()->url->getBase('activityReport') . '/rss2/' . dcCore::app()->activityReport->getUserCode() . '">' .
|
2021-09-03 18:05:28 +00:00
|
|
|
__('Rss2 feed for activity on this blog') . '</a><br />' .
|
|
|
|
'<img alt="' . __('Atom feed') . '" src="' . dcPage::getPF('activityReport/inc/img/feed.png') . '" />' .
|
2022-11-18 20:24:30 +00:00
|
|
|
'<a title="' . __('Atom feed') . '" href="' .
|
|
|
|
dcCore::app()->blog->url . dcCore::app()->url->getBase('activityReport') . '/atom/' . dcCore::app()->activityReport->getUserCode() . '">' .
|
2021-09-03 18:05:28 +00:00
|
|
|
__('Atom feed for activity on this blog') . '</a></p>';
|
|
|
|
}
|
|
|
|
echo '
|
|
|
|
</div><div class="col">
|
|
|
|
|
2022-11-18 20:24:30 +00:00
|
|
|
<p><label for="interval">' . __('Send report:') . '</label>' .
|
|
|
|
form::combo('interval', $combo_interval, dcCore::app()->activityReport->getSetting('interval')) . '</p>
|
2021-09-03 18:05:28 +00:00
|
|
|
|
2022-11-18 20:24:30 +00:00
|
|
|
<p><label for="mailinglist">' . __('Recipients:') . '<br />' .
|
2021-09-03 18:05:28 +00:00
|
|
|
form::field('mailinglist', 60, 255, $emails) . '</label></p>
|
|
|
|
<p class="form-note">' . __('Separate multiple email addresses with a semicolon ";"') . '</p>
|
|
|
|
|
2022-11-18 20:24:30 +00:00
|
|
|
<p><label for="mailformat">' . __('Report format:') . '</label>' .
|
|
|
|
form::combo('mailformat', $combo_format, dcCore::app()->activityReport->getSetting('mailformat')) . '</p>
|
2021-09-03 18:05:28 +00:00
|
|
|
|
|
|
|
<ul>
|
|
|
|
<li>' . __('Last report by email:') . ' ' . $last_report . '</li>
|
|
|
|
<li>' . __('Next report by email:') . ' ' . $next_report . '</li>
|
|
|
|
</ul>
|
|
|
|
</div><br class="clear"/>
|
|
|
|
</div><br class="clear"/>';
|
|
|
|
|
|
|
|
if ($super) {
|
|
|
|
echo '
|
|
|
|
<div class="fieldset one-box" id="setting_blog"><h4>' . __('Blogs') . '</h4>
|
|
|
|
<p>' . __('Select blogs to add to report') . '</p>';
|
|
|
|
|
2022-11-18 20:24:30 +00:00
|
|
|
$i = $j = 0;
|
|
|
|
$selected_blogs = dcCore::app()->activityReport->getSetting('blogs');
|
|
|
|
$blogs = dcCore::app()->getBlogs();
|
|
|
|
$num_blogs = $blogs->count();
|
|
|
|
while ($blogs->fetch()) {
|
|
|
|
$blog_id = dcCore::app()->con->escape($blogs->blog_id);
|
2021-09-03 18:05:28 +00:00
|
|
|
|
|
|
|
echo '
|
|
|
|
<div class="fieldset box">
|
|
|
|
<p><label class="classic" for="blogs_' . $i . '_">' .
|
|
|
|
form::checkbox(
|
2022-11-18 20:24:30 +00:00
|
|
|
['blogs[' . $i . ']', 'blogs_' . $i . '_'],
|
2021-09-03 18:05:28 +00:00
|
|
|
$blog_id,
|
2022-11-18 20:24:30 +00:00
|
|
|
in_array($blog_id, $selected_blogs)
|
|
|
|
) . ' ' .
|
2021-09-03 18:05:28 +00:00
|
|
|
$blogs->blog_name . ' (' . $blog_id . ')</label></p>
|
|
|
|
</div>';
|
|
|
|
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
echo '</div>';
|
2022-11-27 21:19:52 +00:00
|
|
|
} else {
|
|
|
|
echo form::hidden('blogs[0]', dcCore::app()->blog->id);
|
2021-09-03 18:05:28 +00:00
|
|
|
}
|
|
|
|
echo '
|
|
|
|
<div class="fieldset one-box" id="setting_report"><h4>' . __('Report') . '</h4>
|
|
|
|
<p>' . __('Select actions by activity type to add to report') . '</p>';
|
|
|
|
|
2022-11-18 20:24:30 +00:00
|
|
|
$groups = dcCore::app()->activityReport->getGroups();
|
|
|
|
$blog_request = dcCore::app()->activityReport->getSetting('requests');
|
2021-09-03 18:05:28 +00:00
|
|
|
|
|
|
|
$i = 0;
|
2022-11-18 20:24:30 +00:00
|
|
|
foreach ($groups as $group_id => $group) {
|
|
|
|
echo '<div class="fieldset box"><h5>' . __($group['title']) . '</h5>';
|
2021-09-03 18:05:28 +00:00
|
|
|
|
2022-11-18 20:24:30 +00:00
|
|
|
foreach ($group['actions'] as $action_id => $action) {
|
2021-09-03 18:05:28 +00:00
|
|
|
echo '
|
|
|
|
<p><label class="classic" for="requests_' . $group_id . '_' . $action_id . '_">' .
|
|
|
|
form::checkbox(
|
|
|
|
['requests[' . $group_id . '][' . $action_id . ']', 'requests_' . $group_id . '_' . $action_id . '_'],
|
|
|
|
1,
|
|
|
|
isset($blog_request[$group_id][$action_id])
|
|
|
|
) . ' ' . __($action['title']) . '</label></p>';
|
|
|
|
}
|
|
|
|
echo '</div>';
|
|
|
|
}
|
|
|
|
echo '</div>';
|
|
|
|
|
2021-09-04 13:23:58 +00:00
|
|
|
if (1) {
|
|
|
|
echo '
|
|
|
|
<div class="fieldset" id="settings"><h4>' . __('Special') . '</h4>
|
|
|
|
|
|
|
|
<p><label class="classic" for="send_report_now">' .
|
2022-11-18 20:24:30 +00:00
|
|
|
form::checkbox('send_report_now', '1', false) . ' ' .
|
2021-09-04 13:23:58 +00:00
|
|
|
__('Send report now') . '</label></p>
|
|
|
|
|
|
|
|
<p><label class="classic" for="delete_report_now">' .
|
2022-11-18 20:24:30 +00:00
|
|
|
form::checkbox('delete_report_now', '1', false) . ' ' .
|
2021-09-04 13:23:58 +00:00
|
|
|
__('Delete all logs now') . '</label></p>
|
|
|
|
|
|
|
|
</div>';
|
|
|
|
}
|
|
|
|
|
2022-11-18 20:24:30 +00:00
|
|
|
dcCore::app()->activityReport->unsetGlobal();
|