prepare to DC 2.24

This commit is contained in:
Jean-Christian Paul Denis 2022-11-18 21:24:30 +01:00
parent ddf5f74c42
commit c2783c2e15
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
13 changed files with 608 additions and 858 deletions

View File

@ -1,6 +1,11 @@
1.1.1 - dev todo:
- [ ] use sql statment
- [ ] fix and add actitivy - [ ] fix and add actitivy
2.0 - 2022.11.12
- switch to DC 2.24
- use new constant ACTIVTY_REPORT_V2 to not break old install
1.1 - 2021.09.03 1.1 - 2021.09.03
- fix Dotclear 2.19 compatibility - fix Dotclear 2.19 compatibility
- fix pages design - fix pages design

View File

@ -10,69 +10,67 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
if (!defined('ACTIVITY_REPORT')) { if (!defined('ACTIVITY_REPORT_V2')) {
return null; return null;
} }
$_menu['Plugins']->addItem( dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
__('Activity report'), __('Activity report'),
$core->adminurl->get('admin.plugin.activityReport'), dcCore::app()->adminurl->get('admin.plugin.activityReport'),
dcPage::getPF('activityReport/icon.png'), dcPage::getPF('activityReport/icon.png'),
preg_match( preg_match(
'/' . preg_quote($core->adminurl->get('admin.plugin.activityReport')) . '(&.*)?$/', '/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.activityReport')) . '(&.*)?$/',
$_SERVER['REQUEST_URI'] $_SERVER['REQUEST_URI']
), ),
$core->auth->check('admin',$core->blog->id) dcCore::app()->auth->check(dcAuth::PERMISSION_ADMIN, dcCore::app()->blog->id)
); );
if ($core->activityReport->getSetting('active')) { if (dcCore::app()->activityReport->getSetting('active')) {
$core->addBehavior('adminDashboardContents', ['activityReportAdmin', 'adminDashboardContents']); dcCore::app()->addBehavior('adminDashboardContentsV2', ['activityReportAdmin', 'adminDashboardContents']);
$core->addBehavior('adminDashboardOptionsForm', ['activityReportAdmin', 'adminDashboardOptionsForm']); dcCore::app()->addBehavior('adminDashboardOptionsFormV2', ['activityReportAdmin', 'adminDashboardOptionsForm']);
$core->addBehavior('adminAfterDashboardOptionsUpdate', ['activityReportAdmin', 'adminAfterDashboardOptionsUpdate']); dcCore::app()->addBehavior('adminAfterDashboardOptionsUpdate', ['activityReportAdmin', 'adminAfterDashboardOptionsUpdate']);
} }
class activityReportAdmin class activityReportAdmin
{ {
public static function adminDashboardContents(dcCore $core, $items) public static function adminDashboardContents($items)
{ {
$core->auth->user_prefs->addWorkspace('activityReport'); dcCore::app()->auth->user_prefs->addWorkspace('activityReport');
$limit = abs((integer) $core->auth->user_prefs->activityReport->dashboard_item); $limit = abs((int) dcCore::app()->auth->user_prefs->activityReport->dashboard_item);
if (!$limit) { if (!$limit) {
return null; return null;
} }
$p = [ $p = [
'limit' => $limit, 'limit' => $limit,
'order' => 'activity_dt DESC', 'order' => 'activity_dt DESC',
'sql' => $core->activityReport->requests2params($core->activityReport->getSetting('requests')) 'sql' => dcCore::app()->activityReport->requests2params(dcCore::app()->activityReport->getSetting('requests')),
]; ];
$lines = []; $lines = [];
$rs = $core->activityReport->getLogs($p); $rs = dcCore::app()->activityReport->getLogs($p);
if ($rs->isEmpty()) { if ($rs->isEmpty()) {
return null; return null;
} }
$groups = $core->activityReport->getGroups(); $groups = dcCore::app()->activityReport->getGroups();
while($rs->fetch()) { while ($rs->fetch()) {
$group = $rs->activity_group; $group = $rs->activity_group;
if (!isset($groups[$group])) { if (!isset($groups[$group])) {
continue; continue;
} }
$lines[] = $lines[] = '<dt title="' . __($groups[$group]['title']) . '">' .
'<dt title="' . __($groups[$group]['title']) . '">' .
'<strong>' . __($groups[$group]['actions'][$rs->activity_action]['title']) . '</strong>' . '<strong>' . __($groups[$group]['actions'][$rs->activity_action]['title']) . '</strong>' .
'<br />' . dt::str( '<br />' . dt::str(
$core->blog->settings->system->date_format . ', ' . $core->blog->settings->system->time_format, dcCore::app()->blog->settings->system->date_format . ', ' . dcCore::app()->blog->settings->system->time_format,
strtotime($rs->activity_dt), strtotime($rs->activity_dt),
$core->auth->getInfo('user_tz') dcCore::app()->auth->getInfo('user_tz')
) . '<dt>' . ) . '<dt>' .
'<dd><p>' . '<dd><p>' .
'<em>' .vsprintf( '<em>' . vsprintf(
__($groups[$group]['actions'][$rs->activity_action]['msg']), __($groups[$group]['actions'][$rs->activity_action]['msg']),
$core->activityReport->decode($rs->activity_logs) dcCore::app()->activityReport->decode($rs->activity_logs)
) . '</em></p></dd>'; ) . '</em></p></dd>';
} }
if (empty($lines)) { if (empty($lines)) {
@ -82,22 +80,22 @@ class activityReportAdmin
'<div id="activity-report-logs" class="box medium">' . '<div id="activity-report-logs" class="box medium">' .
'<h3>' . __('Activity report') . '</h3>' . '<h3>' . __('Activity report') . '</h3>' .
'<dl id="reports">' . implode('', $lines) . '</dl>' . '<dl id="reports">' . implode('', $lines) . '</dl>' .
'<p class="modules"><a class="module-details" href="'. '<p class="modules"><a class="module-details" href="' .
$core->adminurl->get('admin.plugin.activityReport') .'">' . dcCore::app()->adminurl->get('admin.plugin.activityReport') . '">' .
__('View all logs') . '</a> - <a class="module-config" href="'. __('View all logs') . '</a> - <a class="module-config" href="' .
$core->adminurl->get('admin.plugins', [ dcCore::app()->adminurl->get('admin.plugins', [
'module' => 'activityReport', 'module' => 'activityReport',
'conf' => 1, 'conf' => 1,
'redir' => $core->adminurl->get('admin.home').'#activity-report-logs' 'redir' => dcCore::app()->adminurl->get('admin.home') . '#activity-report-logs',
]) .'">' . ]) . '">' .
__('Configure plugin') . '</a></p>' . __('Configure plugin') . '</a></p>' .
'</div>' '</div>',
]); ]);
} }
public static function adminDashboardOptionsForm(dcCore $core) public static function adminDashboardOptionsForm()
{ {
$core->auth->user_prefs->addWorkspace('activityReport'); dcCore::app()->auth->user_prefs->addWorkspace('activityReport');
echo echo
'<div class="fieldset">' . '<div class="fieldset">' .
@ -107,21 +105,19 @@ class activityReportAdmin
form::combo( form::combo(
'activityReport_dashboard_item', 'activityReport_dashboard_item',
self::comboList(), self::comboList(),
self::comboList($core->auth->user_prefs->activityReport->dashboard_item) self::comboList(dcCore::app()->auth->user_prefs->activityReport->dashboard_item)
) . '</p>' . ) . '</p>' .
'</div>'; '</div>';
} }
public static function adminAfterDashboardOptionsUpdate($user_id = null) public static function adminAfterDashboardOptionsUpdate($user_id = null)
{ {
global $core;
if (is_null($user_id)) { if (is_null($user_id)) {
return; return;
} }
$core->auth->user_prefs->addWorkspace('activityReport'); dcCore::app()->auth->user_prefs->addWorkspace('activityReport');
$core->auth->user_prefs->activityReport->put( dcCore::app()->auth->user_prefs->activityReport->put(
'dashboard_item', 'dashboard_item',
self::comboList(@$_POST['activityReport_dashboard_item']), self::comboList(@$_POST['activityReport_dashboard_item']),
'integer' 'integer'
@ -132,16 +128,20 @@ class activityReportAdmin
{ {
$l = [ $l = [
__('Do not show activity report') => 0, __('Do not show activity report') => 0,
5 => 5, 5 => 5,
10 => 10, 10 => 10,
15 => 15, 15 => 15,
20 => 20, 20 => 20,
50 => 50, 50 => 50,
100 => 100 100 => 100,
]; ];
if (true === $q) { if (true === $q) {
return $l; return $l;
} }
if (!$q) {
$q = -1;
}
return in_array($q, $l) ? $l[$q] : 0; return in_array($q, $l) ? $l[$q] : 0;
} }
} }

View File

@ -10,105 +10,103 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_MODULE')) { if (!defined('DC_CONTEXT_MODULE')) {
return null; return null;
} }
$report =& $core->activityReport; $super = dcCore::app()->auth->isSuperAdmin() && !empty($_REQUEST['super']);
$super = $core->auth->isSuperAdmin() && !empty($_REQUEST['super']); $redir = empty($_REQUEST['redir']) ? dcCore::app()->admin->list->getURL() . '#plugins' : $_REQUEST['redir'];
$redir = empty($_REQUEST['redir']) ? $list->getURL() . '#plugins' : $_REQUEST['redir'];
if ($super) { if ($super) {
$report->setGlobal(); dcCore::app()->activityReport->setGlobal();
} }
$combo_interval = [ $combo_interval = [
__('every hour') => 3600, __('every hour') => 3600,
__('every 2 hours') => 7200, __('every 2 hours') => 7200,
__('2 times by day') => 43200, __('2 times by day') => 43200,
__('every day') => 86400, __('every day') => 86400,
__('every 2 days') => 172800, __('every 2 days') => 172800,
__('every week') => 604800 __('every week') => 604800,
]; ];
$combo_obselete = [ $combo_obselete = [
__('every hour') => 3600, __('every hour') => 3600,
__('every 2 hours') => 7200, __('every 2 hours') => 7200,
__('2 times by day') => 43200, __('2 times by day') => 43200,
__('every day') => 86400, __('every day') => 86400,
__('every 2 days') => 172800, __('every 2 days') => 172800,
__('every week') => 604800, __('every week') => 604800,
__('every 2 weeks') => 1209600, __('every 2 weeks') => 1209600,
__('every 4 weeks') => 2419200 __('every 4 weeks') => 2419200,
]; ];
$combo_format = [ $combo_format = [
__('Plain text') => 'plain', __('Plain text') => 'plain',
__('HTML') => 'html' __('HTML') => 'html',
]; ];
if (!empty($_POST['save'])) { if (!empty($_POST['save'])) {
try { try {
$report->setSetting('active', !empty($_POST['active'])); dcCore::app()->activityReport->setSetting('active', !empty($_POST['active']));
if (in_array($_POST['interval'], $combo_interval)) { if (in_array($_POST['interval'], $combo_interval)) {
$report->setSetting('interval', (integer) $_POST['interval']); dcCore::app()->activityReport->setSetting('interval', (int) $_POST['interval']);
} }
if (in_array($_POST['obsolete'], $combo_obselete)) { if (in_array($_POST['obsolete'], $combo_obselete)) {
$report->setSetting('obsolete',(integer) $_POST['obsolete']); dcCore::app()->activityReport->setSetting('obsolete', (int) $_POST['obsolete']);
} }
$report->setSetting('mailinglist', explode(';',$_POST['mailinglist'])); dcCore::app()->activityReport->setSetting('mailinglist', explode(';', $_POST['mailinglist']));
$report->setSetting('mailformat', isset($_POST['mailformat']) && $_POST['mailformat'] == 'html' ? 'html' : 'plain'); dcCore::app()->activityReport->setSetting('mailformat', isset($_POST['mailformat']) && $_POST['mailformat'] == 'html' ? 'html' : 'plain');
$report->setSetting('dateformat', html::escapeHTML($_POST['dateformat'])); dcCore::app()->activityReport->setSetting('dateformat', html::escapeHTML($_POST['dateformat']));
$report->setSetting('requests', isset($_POST['requests']) ? $_POST['requests'] : []); dcCore::app()->activityReport->setSetting('requests', $_POST['requests'] ?? []);
$report->setSetting('blogs', isset($_POST['blogs']) ? $_POST['blogs'] : []); dcCore::app()->activityReport->setSetting('blogs', $_POST['blogs'] ?? []);
if (!empty($_POST['send_report_now'])) { if (!empty($_POST['send_report_now'])) {
$core->activityReport->needReport(true); dcCore::app()->activityReport->needReport(true);
dcPage::addSuccessNotice( dcAdminNotices::addSuccessNotice(
__('Report successfully sent.') __('Report successfully sent.')
); );
} }
if (!empty($_POST['delete_report_now'])) { if (!empty($_POST['delete_report_now'])) {
$core->activityReport->deleteLogs(); dcCore::app()->activityReport->deleteLogs();
dcPage::addSuccessNotice( dcAdminNotices::addSuccessNotice(
__('Logs successfully deleted.') __('Logs successfully deleted.')
); );
} }
dcPage::addSuccessNotice( dcAdminNotices::addSuccessNotice(
__('Configuration successfully updated.') __('Configuration successfully updated.')
); );
$core->adminurl->redirect('admin.plugins', ['module' => 'activityReport', 'conf' => 1, 'super' => $super]); dcCore::app()->adminurl->redirect('admin.plugins', ['module' => 'activityReport', 'conf' => 1, 'super' => $super]);
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
} }
$last_report_ts = $report->getSetting('lastreport'); $last_report_ts = dcCore::app()->activityReport->getSetting('lastreport');
if (!$last_report_ts) { if (!$last_report_ts) {
$last_report = __('never'); $last_report = __('never');
$next_report = __('on new activity'); $next_report = __('on new activity');
} else { } else {
$last_report = dt::str( $last_report = dt::str(
$core->blog->settings->system->date_format . ', ' . $core->blog->settings->system->time_format, dcCore::app()->blog->settings->system->date_format . ', ' . dcCore::app()->blog->settings->system->time_format,
$last_report_ts, $last_report_ts,
$core->auth->getInfo('user_tz') dcCore::app()->auth->getInfo('user_tz')
); );
$next_report = dt::str( $next_report = dt::str(
$core->blog->settings->system->date_format . ', ' . $core->blog->settings->system->time_format, dcCore::app()->blog->settings->system->date_format . ', ' . dcCore::app()->blog->settings->system->time_format,
(integer) $report->getSetting('interval') + $last_report_ts, (int) dcCore::app()->activityReport->getSetting('interval') + $last_report_ts,
$core->auth->getInfo('user_tz') dcCore::app()->auth->getInfo('user_tz')
); );
} }
$emails = implode(';', $report->getSetting('mailinglist')); $emails = implode(';', dcCore::app()->activityReport->getSetting('mailinglist'));
if ($core->auth->isSuperAdmin()) { if (dcCore::app()->auth->isSuperAdmin()) {
echo sprintf( echo sprintf(
'<p class="modules right"><a class="module-config" href="%s">%s</a><br class="clear"/></p>' , '<p class="modules right"><a class="module-config" href="%s">%s</a><br class="clear"/></p>',
$core->adminurl->get('admin.plugins', ['module' => 'activityReport', 'conf' => 1, 'super' => !$super]), dcCore::app()->adminurl->get('admin.plugins', ['module' => 'activityReport', 'conf' => 1, 'super' => !$super]),
sprintf(__('Configure activity report for %s'), $super ? __('current blog') : _('all blogs')) sprintf(__('Configure activity report for %s'), $super ? __('current blog') : _('all blogs'))
); );
} }
@ -123,44 +121,45 @@ echo '
<div class="col"> <div class="col">
<p><label class="classic" for="active">' . <p><label class="classic" for="active">' .
form::checkbox('active', '1', $report->getSetting('active')).' '. form::checkbox('active', '1', dcCore::app()->activityReport->getSetting('active')) . ' ' .
($super ? (
$super ?
__('Enable super administrator report') : __('Enable super administrator report') :
__('Enable report on this blog') __('Enable report on this blog')
) . '</label></p> ) . '</label></p>
<p><label for="obselete">' . __('Automatic cleaning of old logs:') . '</label>' . <p><label for="obselete">' . __('Automatic cleaning of old logs:') . '</label>' .
form::combo('obsolete', $combo_obselete, $report->getSetting('obsolete')) . '</p> form::combo('obsolete', $combo_obselete, dcCore::app()->activityReport->getSetting('obsolete')) . '</p>
<p><label for="dateformat">' . __('Date format:') . '<br />'. <p><label for="dateformat">' . __('Date format:') . '<br />' .
form::field('dateformat', 60, 255, $report->getSetting('dateformat')) . '</label></p> form::field('dateformat', 60, 255, dcCore::app()->activityReport->getSetting('dateformat')) . '</label></p>
<p class="form-note">' . __('Use Dotclear date formaters. ex: %B %d at %H:%M') . '</p>' . <p class="form-note">' . __('Use Dotclear date formaters. ex: %B %d at %H:%M') . '</p>' .
form::hidden(['super'], $super); form::hidden(['super'], $super);
if (!$super) { if (!$super) {
echo echo
'<p><img alt="'. __('RSS feed') . '" src="' . dcPage::getPF('activityReport/inc/img/feed.png') . '" />' . '<p><img alt="' . __('RSS feed') . '" src="' . dcPage::getPF('activityReport/inc/img/feed.png') . '" />' .
'<a title="' . __('RSS feed') . '" href="' . '<a title="' . __('RSS feed') . '" href="' .
$core->blog->url . $core->url->getBase('activityReport') . '/rss2/' . $report->getUserCode() . '">' . dcCore::app()->blog->url . dcCore::app()->url->getBase('activityReport') . '/rss2/' . dcCore::app()->activityReport->getUserCode() . '">' .
__('Rss2 feed for activity on this blog') . '</a><br />' . __('Rss2 feed for activity on this blog') . '</a><br />' .
'<img alt="' . __('Atom feed') . '" src="' . dcPage::getPF('activityReport/inc/img/feed.png') . '" />' . '<img alt="' . __('Atom feed') . '" src="' . dcPage::getPF('activityReport/inc/img/feed.png') . '" />' .
'<a title="' . __('Atom feed') . '" href="' . '<a title="' . __('Atom feed') . '" href="' .
$core->blog->url . $core->url->getBase('activityReport') . '/atom/' . $report->getUserCode() . '">' . dcCore::app()->blog->url . dcCore::app()->url->getBase('activityReport') . '/atom/' . dcCore::app()->activityReport->getUserCode() . '">' .
__('Atom feed for activity on this blog') . '</a></p>'; __('Atom feed for activity on this blog') . '</a></p>';
} }
echo ' echo '
</div><div class="col"> </div><div class="col">
<p><label for="interval">' . __('Send report:').'</label>' . <p><label for="interval">' . __('Send report:') . '</label>' .
form::combo('interval', $combo_interval, $report->getSetting('interval')) . '</p> form::combo('interval', $combo_interval, dcCore::app()->activityReport->getSetting('interval')) . '</p>
<p><label for="mailinglist">' . __('Recipients:') . '<br />'. <p><label for="mailinglist">' . __('Recipients:') . '<br />' .
form::field('mailinglist', 60, 255, $emails) . '</label></p> form::field('mailinglist', 60, 255, $emails) . '</label></p>
<p class="form-note">' . __('Separate multiple email addresses with a semicolon ";"') . '</p> <p class="form-note">' . __('Separate multiple email addresses with a semicolon ";"') . '</p>
<p><label for="mailformat">' . __('Report format:') . '</label>' . <p><label for="mailformat">' . __('Report format:') . '</label>' .
form::combo('mailformat', $combo_format, $report->getSetting('mailformat')) . '</p> form::combo('mailformat', $combo_format, dcCore::app()->activityReport->getSetting('mailformat')) . '</p>
<ul> <ul>
<li>' . __('Last report by email:') . ' ' . $last_report . '</li> <li>' . __('Last report by email:') . ' ' . $last_report . '</li>
@ -174,20 +173,20 @@ if ($super) {
<div class="fieldset one-box" id="setting_blog"><h4>' . __('Blogs') . '</h4> <div class="fieldset one-box" id="setting_blog"><h4>' . __('Blogs') . '</h4>
<p>' . __('Select blogs to add to report') . '</p>'; <p>' . __('Select blogs to add to report') . '</p>';
$i = $j = 0; $i = $j = 0;
$selected_blogs = $report->getSetting('blogs'); $selected_blogs = dcCore::app()->activityReport->getSetting('blogs');
$blogs = $core->getBlogs(); $blogs = dcCore::app()->getBlogs();
$num_blogs = $blogs->count(); $num_blogs = $blogs->count();
while($blogs->fetch()) { while ($blogs->fetch()) {
$blog_id = $core->con->escape($blogs->blog_id); $blog_id = dcCore::app()->con->escape($blogs->blog_id);
echo ' echo '
<div class="fieldset box"> <div class="fieldset box">
<p><label class="classic" for="blogs_' . $i . '_">' . <p><label class="classic" for="blogs_' . $i . '_">' .
form::checkbox( form::checkbox(
['blogs['.$i.']', 'blogs_' . $i . '_'], ['blogs[' . $i . ']', 'blogs_' . $i . '_'],
$blog_id, $blog_id,
in_array($blog_id,$selected_blogs) in_array($blog_id, $selected_blogs)
) . ' ' . ) . ' ' .
$blogs->blog_name . ' (' . $blog_id . ')</label></p> $blogs->blog_name . ' (' . $blog_id . ')</label></p>
</div>'; </div>';
@ -200,14 +199,14 @@ echo '
<div class="fieldset one-box" id="setting_report"><h4>' . __('Report') . '</h4> <div class="fieldset one-box" id="setting_report"><h4>' . __('Report') . '</h4>
<p>' . __('Select actions by activity type to add to report') . '</p>'; <p>' . __('Select actions by activity type to add to report') . '</p>';
$groups = $report->getGroups(); $groups = dcCore::app()->activityReport->getGroups();
$blog_request = $report->getSetting('requests'); $blog_request = dcCore::app()->activityReport->getSetting('requests');
$i = 0; $i = 0;
foreach($groups as $group_id => $group) { foreach ($groups as $group_id => $group) {
echo '<div class="fieldset box"><h5>'. __($group['title']) . '</h5>'; echo '<div class="fieldset box"><h5>' . __($group['title']) . '</h5>';
foreach($group['actions'] as $action_id => $action) { foreach ($group['actions'] as $action_id => $action) {
echo ' echo '
<p><label class="classic" for="requests_' . $group_id . '_' . $action_id . '_">' . <p><label class="classic" for="requests_' . $group_id . '_' . $action_id . '_">' .
form::checkbox( form::checkbox(
@ -225,14 +224,14 @@ if (1) {
<div class="fieldset" id="settings"><h4>' . __('Special') . '</h4> <div class="fieldset" id="settings"><h4>' . __('Special') . '</h4>
<p><label class="classic" for="send_report_now">' . <p><label class="classic" for="send_report_now">' .
form::checkbox('send_report_now', '1', false).' '. form::checkbox('send_report_now', '1', false) . ' ' .
__('Send report now') . '</label></p> __('Send report now') . '</label></p>
<p><label class="classic" for="delete_report_now">' . <p><label class="classic" for="delete_report_now">' .
form::checkbox('delete_report_now', '1', false).' '. form::checkbox('delete_report_now', '1', false) . ' ' .
__('Delete all logs now') . '</label></p> __('Delete all logs now') . '</label></p>
</div>'; </div>';
} }
$report->unsetGlobal(); dcCore::app()->activityReport->unsetGlobal();

View File

@ -10,7 +10,6 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
@ -19,14 +18,18 @@ $this->registerModule(
'Activity report', 'Activity report',
'Receive your blog activity by email, feed, or on dashboard', 'Receive your blog activity by email, feed, or on dashboard',
'Jean-Christian Denis and contributors', 'Jean-Christian Denis and contributors',
'1.1.1', '2.0-dev',
[ [
'requires' => [['core', '2.19']], 'requires' => [['core', '2.24']],
'permissions' => 'usage,contentadmin,admin', 'permissions' => dcCore::app()->auth->makePermissions([
'priority' => -1000000, dcAuth::PERMISSION_USAGE,
'type' => 'plugin', dcAuth::PERMISSION_CONTENT_ADMIN,
'support' => 'https://github.com/JcDenis/activityReport', dcAuth::PERMISSION_ADMIN,
'details' => 'http://plugins.dotaddict.org/dc2/details/activityReport', ]),
'repository' => 'https://raw.githubusercontent.com/JcDenis/activityReport/master/dcstore.xml' 'priority' => -1000000,
'type' => 'plugin',
'support' => 'https://github.com/JcDenis/activityReport',
'details' => 'http://plugins.dotaddict.org/dc2/details/activityReport',
'repository' => 'https://raw.githubusercontent.com/JcDenis/activityReport/master/dcstore.xml',
] ]
); );

View File

@ -10,30 +10,29 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_ADMIN')) {
if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
$new_version = $core->plugins->moduleInfo('activityReport', 'version'); $new_version = dcCore::app()->plugins->moduleInfo('activityReport', 'version');
$old_version = $core->getVersion('activityReport'); $old_version = dcCore::app()->getVersion('activityReport');
if (version_compare($old_version, $new_version, '>=')) { if (version_compare($old_version, $new_version, '>=')) {
return null; return null;
} }
try { try {
$s = new dbStruct($core->con, $core->prefix); $s = new dbStruct(dcCore::app()->con, dcCore::app()->prefix);
$s->activity $s->activity
->activity_id ('bigint', 0, false) ->activity_id('bigint', 0, false)
->activity_type ('varchar', 32, false, "'activityReport'") ->activity_type('varchar', 32, false, "'activityReport'")
->blog_id ('varchar', 32, true) ->blog_id('varchar', 32, true)
->activity_group('varchar', 32, false) ->activity_group('varchar', 32, false)
->activity_action ('varchar', 32, false) ->activity_action('varchar', 32, false)
->activity_logs ('text', 0, false) ->activity_logs('text', 0, false)
->activity_dt ('timestamp', 0 ,false, 'now()') ->activity_dt('timestamp', 0, false, 'now()')
->activity_blog_status ('smallint', 0, false,0) ->activity_blog_status('smallint', 0, false, 0)
->activity_super_status ('smallint',0, false,0) ->activity_super_status('smallint', 0, false, 0)
->primary('pk_activity', 'activity_id') ->primary('pk_activity', 'activity_id')
->index('idx_activity_type', 'btree', 'activity_type') ->index('idx_activity_type', 'btree', 'activity_type')
@ -44,7 +43,7 @@ try {
$s->activity_setting $s->activity_setting
->setting_id('varchar', 64, false) ->setting_id('varchar', 64, false)
->blog_id ('varchar', 32, true) ->blog_id('varchar', 32, true)
->setting_type('varchar', 32, false) ->setting_type('varchar', 32, false)
->setting_value('text', 0, false) ->setting_value('text', 0, false)
@ -52,13 +51,14 @@ try {
->index('idx_activity_setting_blog_id', 'btree', 'blog_id') ->index('idx_activity_setting_blog_id', 'btree', 'blog_id')
->index('idx_activity_setting_type', 'btree', 'setting_type'); ->index('idx_activity_setting_type', 'btree', 'setting_type');
$si = new dbStruct($core->con, $core->prefix); $si = new dbStruct(dcCore::app()->con, dcCore::app()->prefix);
$changes = $si->synchronize($s); $changes = $si->synchronize($s);
$core->setVersion('activityReport', $new_version); dcCore::app()->setVersion('activityReport', $new_version);
return true; return true;
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
return false; return false;

View File

@ -10,29 +10,27 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
$d = dirname(__FILE__) . '/inc/'; Clearbricks::lib()->autoload(['activityReport' => __DIR__ . '/inc/class.activity.report.php']);
$__autoload['activityReport'] = $d . 'class.activity.report.php'; Clearbricks::lib()->autoload(['activityReportBehaviors' => __DIR__ . '/inc/class.activity.report.behaviors.php']);
$__autoload['activityReportBehaviors'] = $d . 'class.activity.report.behaviors.php';
try { try {
if (!defined('ACTIVITY_REPORT')) { if (!defined('ACTIVITY_REPORT_V2')) {
$core->activityReport = new activityReport($core); dcCore::app()->__set('activityReport', new activityReport());
$core->url->register( dcCore::app()->url->register(
'activityReport', 'activityReport',
'reports', 'reports',
'^reports/((atom|rss2)/(.+))$', '^reports/((atom|rss2)/(.+))$',
['activityReportPublicUrl', 'feed'] ['activityReportPublicUrl', 'feed']
); );
define('ACTIVITY_REPORT', true); define('ACTIVITY_REPORT_V2', true);
activityReportBehaviors::registerBehaviors($core); activityReportBehaviors::registerBehaviors();
} }
} catch (Exception $e) { } catch (Exception $e) {
//throw new Exception('Failed to launch activityReport'); //throw new Exception('Failed to launch activityReport');

View File

@ -10,52 +10,52 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
if (!defined('ACTIVITY_REPORT')) { if (!defined('ACTIVITY_REPORT_V2')) {
return null; return null;
} }
$core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates/tpl'); dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), __DIR__ . '/default-templates/tpl');
$core->tpl->addBlock('activityReports', ['activityReportPublicTpl','activityReports']); dcCore::app()->tpl->addBlock('activityReports', ['activityReportPublicTpl','activityReports']);
$core->tpl->addValue('activityReportFeedID', ['activityReportPublicTpl','activityReportFeedID']); dcCore::app()->tpl->addValue('activityReportFeedID', ['activityReportPublicTpl','activityReportFeedID']);
$core->tpl->addValue('activityReportTitle', ['activityReportPublicTpl','activityReportTitle']); dcCore::app()->tpl->addValue('activityReportTitle', ['activityReportPublicTpl','activityReportTitle']);
$core->tpl->addValue('activityReportDate', ['activityReportPublicTpl','activityReportDate']); dcCore::app()->tpl->addValue('activityReportDate', ['activityReportPublicTpl','activityReportDate']);
$core->tpl->addValue('activityReportContent', ['activityReportPublicTpl','activityReportContent']); dcCore::app()->tpl->addValue('activityReportContent', ['activityReportPublicTpl','activityReportContent']);
class activityReportPublicUrl extends dcUrlHandlers class activityReportPublicUrl extends dcUrlHandlers
{ {
public static function feed($args) public static function feed(?string $args): void
{ {
global $core, $_ctx;
if (!preg_match('/^(atom|rss2)\/(.+)$/', $args, $m)) { if (!preg_match('/^(atom|rss2)\/(.+)$/', $args, $m)) {
self::p404(); self::p404();
return; return;
} }
if (!defined('ACTIVITY_REPORT')) { if (!defined('ACTIVITY_REPORT_V2')) {
self::p404(); self::p404();
return; return;
} }
if (!$core->activityReport->getSetting('active')) { if (!dcCore::app()->activityReport->getSetting('active')) {
self::p404(); self::p404();
return; return;
} }
$mime = $m[1] == 'atom' ? 'application/atom+xml' : 'application/xml'; $mime = $m[1] == 'atom' ? 'application/atom+xml' : 'application/xml';
if (false === $core->activityReport->checkUserCode($m[2])) { if (false === dcCore::app()->activityReport->checkUserCode($m[2])) {
self::p404(); self::p404();
return; return;
} }
$_ctx->nb_entry_per_page = $core->blog->settings->system->nb_post_per_feed; dcCore::app()->ctx->nb_entry_per_page = (int) dcCore::app()->blog->settings->system->nb_post_per_feed;
$_ctx->short_feed_items = $core->blog->settings->system->short_feed_items; dcCore::app()->ctx->short_feed_items = (int) dcCore::app()->blog->settings->system->short_feed_items;
header('X-Robots-Tag: '. context::robotsPolicy($core->blog->settings->system->robots_policy, '')); header('X-Robots-Tag: ' . context::robotsPolicy(dcCore::app()->blog->settings->system->robots_policy, ''));
self::serveDocument('activityreport-' . $m[1] . '.xml', $mime); self::serveDocument('activityreport-' . $m[1] . '.xml', $mime);
return;
} }
} }
@ -65,18 +65,18 @@ class activityReportPublicTpl
{ {
$lastn = 0; $lastn = 0;
if (isset($attr['lastn'])) { if (isset($attr['lastn'])) {
$lastn = abs((integer) $attr['lastn']) + 0; $lastn = abs((int) $attr['lastn']) + 0;
} }
$p = 'if (!isset($_page_number)) { $_page_number = 1; }' . "\n\$params = array();\n"; $p = '$_page_number = dcCore::app()->public->getPageNumber(); if ($_page_number < 1) { $_page_number = 1; }' . "\n\$params = array();\n";
if ($lastn > 0) { if ($lastn > 0) {
$p .= "\$params['limit'] = " . $lastn . ";\n"; $p .= "\$params['limit'] = " . $lastn . ";\n";
} else { } else {
$p .= "\$params['limit'] = \$_ctx->nb_entry_per_page;\n"; $p .= "\$params['limit'] = dcCore::app()->ctx->nb_entry_per_page;\n";
} }
if (!isset($attr['ignore_pagination']) || $attr['ignore_pagination'] == "0") { if (!isset($attr['ignore_pagination']) || $attr['ignore_pagination'] == '0') {
$p .= "\$params['limit'] = array(((\$_page_number-1)*\$params['limit']),\$params['limit']);\n"; $p .= "\$params['limit'] = array(((\$_page_number-1)*\$params['limit']),\$params['limit']);\n";
} else { } else {
$p .= "\$params['limit'] = array(0, \$params['limit']);\n"; $p .= "\$params['limit'] = array(0, \$params['limit']);\n";
@ -85,31 +85,33 @@ class activityReportPublicTpl
return return
"<?php \n" . "<?php \n" .
$p . $p .
'$_ctx->activityreport_params = $params; ' . "\n" . 'dcCore::app()->ctx->activityreport_params = $params; ' . "\n" .
'$_ctx->activityreports = $core->activityReport->getLogs($params); unset($params); ' . "\n" . 'dcCore::app()->ctx->activityreports = dcCore::app()->activityReport->getLogs($params); unset($params); ' . "\n" .
'while ($_ctx->activityreports->fetch()) : ?>'.$content.'<?php endwhile; ' . 'while (dcCore::app()->ctx->activityreports->fetch()) : ?>' . $content . '<?php endwhile; ' .
'$_ctx->activityreports = null; $_ctx->activityreport_params = null; ' . "\n" . 'dcCore::app()->ctx->pop("activityreports"); dcCore::app()->ctx->pop("activityreport_params"); ' . "\n" .
"?>"; '?>';
} }
public static function activityReportFeedID($attr) public static function activityReportFeedID($attr)
{ {
return return
'urn:md5:<?php echo md5($_ctx->activityreports->blog_id.' . 'urn:md5:<?php echo md5(dcCore::app()->ctx->activityreports->blog_id.' .
'$_ctx->activityreports->activity_id.$_ctx->activityreports->activity_dt); ' . 'dcCore::app()->ctx->activityreports->activity_id.dcCore::app()->ctx->activityreports->activity_dt); ' .
'?>'; '?>';
} }
public static function activityReportTitle($attr) public static function activityReportTitle($attr)
{ {
$f = $GLOBALS['core']->tpl->getFilters($attr); $f = dcCore::app()->tpl->getFilters($attr);
return '<?php echo ' . sprintf($f,'activityReportContext::parseTitle()') . '; ?>';
return '<?php echo ' . sprintf($f, 'activityReportContext::parseTitle()') . '; ?>';
} }
public static function activityReportContent($attr) public static function activityReportContent($attr)
{ {
$f = $GLOBALS['core']->tpl->getFilters($attr); $f = dcCore::app()->tpl->getFilters($attr);
return '<?php echo ' . sprintf($f,'activityReportContext::parseContent()') . '; ?>';
return '<?php echo ' . sprintf($f, 'activityReportContext::parseContent()') . '; ?>';
} }
public static function activityReportDate($attr) public static function activityReportDate($attr)
@ -120,19 +122,19 @@ class activityReportPublicTpl
} }
$iso8601 = !empty($attr['iso8601']); $iso8601 = !empty($attr['iso8601']);
$rfc822 = !empty($attr['rfc822']); $rfc822 = !empty($attr['rfc822']);
$f = $GLOBALS['core']->tpl->getFilters($attr); $f = dcCore::app()->tpl->getFilters($attr);
if ($rfc822) { if ($rfc822) {
return '<?php echo ' . sprintf($f,"dt::rfc822(strtotime(\$_ctx->activityreports->activity_dt),\$core->blog->settings->system->blog_timezone)") . '; ?>'; return '<?php echo ' . sprintf($f, 'dt::rfc822(strtotime(dcCore::app()->ctx->activityreports->activity_dt),dcCore::app()->blog->settings->system->blog_timezone)') . '; ?>';
} elseif ($iso8601) { } elseif ($iso8601) {
return '<?php echo ' . sprintf($f,"dt::iso8601(strtotime(\$_ctx->activityreports->activity_dt),\$core->blog->settings->system->blog_timezone)") . '; ?>'; return '<?php echo ' . sprintf($f, 'dt::iso8601(strtotime(dcCore::app()->ctx->activityreports->activity_dt),dcCore::app()->blog->settings->system->blog_timezone)') . '; ?>';
} elseif (!empty($format)) { } elseif (!empty($format)) {
return '<?php echo ' . sprintf($f,"dt::dt2str('" . $format . "',\$_ctx->activityreports->activity_dt)") . '; ?>'; return '<?php echo ' . sprintf($f, "dt::dt2str('" . $format . "',dcCore::app()->ctx->activityreports->activity_dt)") . '; ?>';
} else {
return '<?php echo ' . sprintf($f,"dt::dt2str(\$core->blog->settings->system->date_format,\$_ctx->activityreports->activity_dt)") . '; ?>';
} }
return '<?php echo ' . sprintf($f, 'dt::dt2str(dcCore::app()->blog->settings->system->date_format,dcCore::app()->ctx->activityreports->activity_dt)') . '; ?>';
} }
} }
@ -140,34 +142,33 @@ class activityReportContext
{ {
public static function parseTitle() public static function parseTitle()
{ {
global $core,$_ctx; $groups = dcCore::app()->activityReport->getGroups();
$groups = $core->activityReport->getGroups(); $group = dcCore::app()->ctx->activityreports->activity_group;
$action = dcCore::app()->ctx->activityreports->activity_action;
$group = $_ctx->activityreports->activity_group;
$action = $_ctx->activityreports->activity_action;
if (!empty($groups[$group]['actions'][$action]['title'])) { if (!empty($groups[$group]['actions'][$action]['title'])) {
return __($groups[$group]['actions'][$action]['title']); return __($groups[$group]['actions'][$action]['title']);
} }
return ''; return '';
} }
public static function parseContent() public static function parseContent()
{ {
global $core,$_ctx; $groups = dcCore::app()->activityReport->getGroups();
$groups = $core->activityReport->getGroups(); $group = dcCore::app()->ctx->activityreports->activity_group;
$action = dcCore::app()->ctx->activityreports->activity_action;
$group = $_ctx->activityreports->activity_group; $logs = dcCore::app()->ctx->activityreports->activity_logs;
$action = $_ctx->activityreports->activity_action; $logs = dcCore::app()->activityReport->decode($logs);
$logs = $_ctx->activityreports->activity_logs;
$logs = $core->activityReport->decode($logs);
if (!empty($groups[$group]['actions'][$action]['msg'])) { if (!empty($groups[$group]['actions'][$action]['msg'])) {
$core->initWikiComment(); dcCore::app()->initWikiComment();
return $core->wikiTransform(vsprintf(__($groups[$group]['actions'][$action]['msg']),$logs));
return dcCore::app()->wikiTransform(vsprintf(__($groups[$group]['actions'][$action]['msg']), $logs));
} }
return ''; return '';
} }
} }

View File

@ -10,49 +10,72 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
$this->addUserAction( $this->addUserAction(
/* type */ 'tables', /* type */
/* action */ 'delete', 'tables',
/* ns */ 'activity', /* action */
/* description */ sprintf(__('delete %s table'), '"activity"') 'delete',
/* ns */
'activity',
/* description */
sprintf(__('delete %s table'), '"activity"')
); );
$this->addUserAction( $this->addUserAction(
/* type */ 'tables', /* type */
/* action */ 'delete', 'tables',
/* ns */ 'activity_setting', /* action */
/* description */ sprintf(__('delete %s table'), '"activity_setting"') 'delete',
/* ns */
'activity_setting',
/* description */
sprintf(__('delete %s table'), '"activity_setting"')
); );
$this->addUserAction( $this->addUserAction(
/* type */ 'plugins', /* type */
/* action */ 'delete', 'plugins',
/* ns */ 'activityReport', /* action */
/* description */ __('delete plugin files') 'delete',
/* ns */
'activityReport',
/* description */
__('delete plugin files')
); );
$this->addUserAction( $this->addUserAction(
/* type */ 'versions', /* type */
/* action */ 'delete', 'versions',
/* ns */ 'activityReport', /* action */
/* description */ __('delete the version number') 'delete',
/* ns */
'activityReport',
/* description */
__('delete the version number')
); );
$this->addDirectAction( $this->addDirectAction(
/* type */ 'versions', /* type */
/* action */ 'delete', 'versions',
/* ns */ 'activityReport', /* action */
/* description */ sprintf(__('delete %s version number'), 'activityReport') 'delete',
/* ns */
'activityReport',
/* description */
sprintf(__('delete %s version number'), 'activityReport')
); );
$this->addDirectAction( $this->addDirectAction(
/* type */ 'plugins', /* type */
/* action */ 'delete', 'plugins',
/* ns */ 'activityReport', /* action */
/* description */ sprintf(__('delete %s plugin files'), 'activityReport') 'delete',
/* ns */
'activityReport',
/* description */
sprintf(__('delete %s plugin files'), 'activityReport')
); );

View File

@ -10,24 +10,22 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
if (!defined('ACTIVITY_REPORT')) { if (!defined('ACTIVITY_REPORT_V2')) {
return null; return null;
} }
class activityReportBehaviors class activityReportBehaviors
{ {
public static function registerBehaviors()
public static function registerBehaviors($core)
{ {
// ActivityReport plugin // ActivityReport plugin
$core->activityReport->addGroup('activityReport', __('ActivityReport messages')); dcCore::app()->activityReport->addGroup('activityReport', __('ActivityReport messages'));
$core->activityReport->addAction( dcCore::app()->activityReport->addAction(
'activityReport', 'activityReport',
'message', 'message',
__('Special messages'), __('Special messages'),
@ -37,12 +35,12 @@ class activityReportBehaviors
); );
// Blog // Blog
$core->activityReport->addGroup('blog', __('Actions on blog')); dcCore::app()->activityReport->addGroup('blog', __('Actions on blog'));
// Not use as it is global : BEHAVIOR adminAfterBlogCreate in admin/blog.php // Not use as it is global : BEHAVIOR adminAfterBlogCreate in admin/blog.php
// from BEHAVIOR adminAfterBlogUpdate in admin/blog_pref.php // from BEHAVIOR adminAfterBlogUpdate in admin/blog_pref.php
$core->activityReport->addAction( dcCore::app()->activityReport->addAction(
'blog', 'blog',
'update', 'update',
__('updating blog'), __('updating blog'),
@ -52,7 +50,7 @@ class activityReportBehaviors
); );
// from BEHAVIOR publicHeadContent in template // from BEHAVIOR publicHeadContent in template
$core->activityReport->addAction( dcCore::app()->activityReport->addAction(
'blog', 'blog',
'p404', 'p404',
__('404 error'), __('404 error'),
@ -62,12 +60,12 @@ class activityReportBehaviors
); );
// Post // Post
$core->activityReport->addGroup('post', __('Actions on posts')); dcCore::app()->activityReport->addGroup('post', __('Actions on posts'));
// from BEHAVIOR coreAfterPostCreate in inc/core/class.dc.blog.php (DC 2.2) // from BEHAVIOR coreAfterPostCreate in inc/core/class.dc.blog.php (DC 2.2)
// duplicate adminAfterPostCreate in admin/post.php // duplicate adminAfterPostCreate in admin/post.php
// duplicate adminAfterPostCreate in admin/services.php // duplicate adminAfterPostCreate in admin/services.php
$core->activityReport->addAction( dcCore::app()->activityReport->addAction(
'post', 'post',
'create', 'create',
__('post creation'), __('post creation'),
@ -78,7 +76,7 @@ class activityReportBehaviors
// Plugin contribute // Plugin contribute
// from BEHAVIOR publicAfterPostCreate in plugins/contribute/_public.php // from BEHAVIOR publicAfterPostCreate in plugins/contribute/_public.php
$core->activityReport->addAction( dcCore::app()->activityReport->addAction(
'post', 'post',
'create', 'create',
__('post creation'), __('post creation'),
@ -89,7 +87,7 @@ class activityReportBehaviors
// from BEHAVIOR coreAfterPostUpdate in inc/core/class.dc.blog.php (DC2.2) // from BEHAVIOR coreAfterPostUpdate in inc/core/class.dc.blog.php (DC2.2)
// duplicate adminAfterPostUpdate in admin/post.php // duplicate adminAfterPostUpdate in admin/post.php
$core->activityReport->addAction( dcCore::app()->activityReport->addAction(
'post', 'post',
'update', 'update',
__('updating post'), __('updating post'),
@ -100,7 +98,7 @@ class activityReportBehaviors
// from BEHAVIOR adminBeforePostDelete in admin/posts_actions.php // from BEHAVIOR adminBeforePostDelete in admin/posts_actions.php
// from BEHAVIOR adminBeforePostDelete in admin/post.php // from BEHAVIOR adminBeforePostDelete in admin/post.php
$core->activityReport->addAction( dcCore::app()->activityReport->addAction(
'post', 'post',
'delete', 'delete',
__('post deletion'), __('post deletion'),
@ -111,7 +109,7 @@ class activityReportBehaviors
// Wrong attempt on passworded enrty // Wrong attempt on passworded enrty
// from BEHAVIOR urlHandlerServeDocument in inc/public/lib.urlhandlers.php // from BEHAVIOR urlHandlerServeDocument in inc/public/lib.urlhandlers.php
$core->activityReport->addAction( dcCore::app()->activityReport->addAction(
'post', 'post',
'protection', 'protection',
__('Post protection'), __('Post protection'),
@ -121,12 +119,12 @@ class activityReportBehaviors
); );
// Comment // Comment
$core->activityReport->addGroup('comment',__('Actions on comments')); dcCore::app()->activityReport->addGroup('comment', __('Actions on comments'));
// from BEHAVIOR coreAfterCommentCreate in inc/core/class.dc.blog.php // from BEHAVIOR coreAfterCommentCreate in inc/core/class.dc.blog.php
// duplicate adminAfterCommentCreate in admin/comment.php // duplicate adminAfterCommentCreate in admin/comment.php
// duplicate publicAfterCommentCreate in inc/public/lib.urlhandlers.php // duplicate publicAfterCommentCreate in inc/public/lib.urlhandlers.php
$core->activityReport->addAction( dcCore::app()->activityReport->addAction(
'comment', 'comment',
'create', 'create',
__('comment creation'), __('comment creation'),
@ -137,7 +135,7 @@ class activityReportBehaviors
// from BEHAVIOR coreAfterCommentUpdate in inc/core/class.dc.blog.php // from BEHAVIOR coreAfterCommentUpdate in inc/core/class.dc.blog.php
// duplicate adminAfterCommentUpdate in admin/comment.php // duplicate adminAfterCommentUpdate in admin/comment.php
$core->activityReport->addAction( dcCore::app()->activityReport->addAction(
'comment', 'comment',
'update', 'update',
__('updating comment'), __('updating comment'),
@ -151,7 +149,7 @@ class activityReportBehaviors
// from BEHAVIOR coreAfterCommentCreate in inc/core/class.dc.blog.php // from BEHAVIOR coreAfterCommentCreate in inc/core/class.dc.blog.php
// duplicate publicAfterTrackbackCreate in inc/core/class.dc.trackback.php // duplicate publicAfterTrackbackCreate in inc/core/class.dc.trackback.php
$core->activityReport->addAction( dcCore::app()->activityReport->addAction(
'comment', 'comment',
'trackback', 'trackback',
__('trackback creation'), __('trackback creation'),
@ -161,10 +159,10 @@ class activityReportBehaviors
); );
// Category // Category
$core->activityReport->addGroup('category', __('Actions on categories')); dcCore::app()->activityReport->addGroup('category', __('Actions on categories'));
// from BEHAVIOR adminAfterCategoryCreate in admin/category.php // from BEHAVIOR adminAfterCategoryCreate in admin/category.php
$core->activityReport->addAction( dcCore::app()->activityReport->addAction(
'category', 'category',
'create', 'create',
__('category creation'), __('category creation'),
@ -174,7 +172,7 @@ class activityReportBehaviors
); );
// from BEHAVIOR adminAfterCategoryUpdate in admin/category.php // from BEHAVIOR adminAfterCategoryUpdate in admin/category.php
$core->activityReport->addAction( dcCore::app()->activityReport->addAction(
'category', 'category',
'update', 'update',
__('updating category'), __('updating category'),
@ -186,10 +184,10 @@ class activityReportBehaviors
// Missing adminBeforeCategoryDelete in admin/category.php // Missing adminBeforeCategoryDelete in admin/category.php
// User // User
$core->activityReport->addGroup('user', __('Actions on users')); dcCore::app()->activityReport->addGroup('user', __('Actions on users'));
// from BEHAVIOR adminAfterUserCreate in admin/user.php // from BEHAVIOR adminAfterUserCreate in admin/user.php
$core->activityReport->addAction( dcCore::app()->activityReport->addAction(
'user', 'user',
'create', 'create',
__('user creation'), __('user creation'),
@ -199,7 +197,7 @@ class activityReportBehaviors
); );
// from BEHAVIOR adminAfterUserUpdated in admin/user.php // from BEHAVIOR adminAfterUserUpdated in admin/user.php
$core->activityReport->addAction( dcCore::app()->activityReport->addAction(
'user', 'user',
'update', 'update',
__('updating user'), __('updating user'),
@ -209,7 +207,7 @@ class activityReportBehaviors
); );
// from BEHAVIOR adminBeforeUserDelete in admin/users.php // from BEHAVIOR adminBeforeUserDelete in admin/users.php
$core->activityReport->addAction( dcCore::app()->activityReport->addAction(
'user', 'user',
'delete', 'delete',
__('user deletion'), __('user deletion'),
@ -221,118 +219,109 @@ class activityReportBehaviors
public static function messageActivityReport($message) public static function messageActivityReport($message)
{ {
global $core;
$logs = [$message]; $logs = [$message];
$core->activityReport->addLog('activityReport', 'message', $logs); dcCore::app()->activityReport->addLog('activityReport', 'message', $logs);
} }
public static function blogUpdate($cur, $blog_id) public static function blogUpdate($cur, $blog_id)
{ {
global $core; $logs = [dcCore::app()->auth->getInfo('user_cn')];
$logs = [$core->auth->getInfo('user_cn')]; dcCore::app()->activityReport->addLog('blog', 'update', $logs);
$core->activityReport->addLog('blog', 'update' ,$logs);
} }
public static function blogP404() public static function blogP404()
{ {
global $core; if (dcCore::app()->url->type != '404') {
if ($core->url->type != '404') {
return null; return null;
} }
$logs = [$core->blog->url . $_SERVER['QUERY_STRING']]; $logs = [dcCore::app()->blog->url . $_SERVER['QUERY_STRING']];
$core->activityReport->addLog('blog', 'p404', $logs); dcCore::app()->activityReport->addLog('blog', 'p404', $logs);
} }
public static function postCreate($cur, $post_id) public static function postCreate($cur, $post_id)
{ {
global $core; $type = $cur->post_type ? $cur->post_type : 'post';
$type = $cur->post_type ? $cur->post_type : 'post'; $post_url = dcCore::app()->blog->getPostURL('', $cur->post_dt, $cur->post_title, $post_id);
$post_url = $core->blog->getPostURL('', $cur->post_dt, $cur->post_title, $post_id); $logs = [
$logs = [
$cur->post_title, $cur->post_title,
$core->auth->getInfo('user_cn'), dcCore::app()->auth->getInfo('user_cn'),
$core->blog->url . $core->url->getBase($type) . '/' . $post_url dcCore::app()->blog->url . dcCore::app()->url->getBase($type) . '/' . $post_url,
]; ];
$core->activityReport->addLog('post', 'create', $logs); dcCore::app()->activityReport->addLog('post', 'create', $logs);
} }
public static function postUpdate($cur, $post_id) public static function postUpdate($cur, $post_id)
{ {
global $core; $type = $cur->post_type ? $cur->post_type : 'post';
$type = $cur->post_type ? $cur->post_type : 'post'; $post_url = dcCore::app()->blog->getPostURL('', $cur->post_dt, $cur->post_title, $post_id);
$post_url = $core->blog->getPostURL('', $cur->post_dt, $cur->post_title, $post_id); $logs = [
$logs = [
$cur->post_title, $cur->post_title,
$core->auth->getInfo('user_cn'), dcCore::app()->auth->getInfo('user_cn'),
$core->blog->url . $core->url->getBase($type) . '/' . $post_url dcCore::app()->blog->url . dcCore::app()->url->getBase($type) . '/' . $post_url,
]; ];
$core->activityReport->addLog('post', 'update', $logs); dcCore::app()->activityReport->addLog('post', 'update', $logs);
} }
public static function postDelete($post_id) public static function postDelete($post_id)
{ {
global $core; $posts = dcCore::app()->blog->getPosts(['post_id' => $post_id, 'limit' => 1]);
$posts = $core->blog->getPosts(['post_id' => $post_id, 'limit' => 1]); $logs = [
$logs = [
$posts->post_title, $posts->post_title,
$core->auth->getInfo('user_cn') dcCore::app()->auth->getInfo('user_cn'),
]; ];
$core->activityReport->addLog('post', 'delete', $logs); dcCore::app()->activityReport->addLog('post', 'delete', $logs);
} }
public static function postPasswordAttempt($result) public static function postPasswordAttempt($result)
{ {
global $core;
if ($result['tpl'] != 'password-form.html' || empty($_POST['password'])) { if ($result['tpl'] != 'password-form.html' || empty($_POST['password'])) {
return null; return null;
} }
$logs = [ $logs = [
$_POST['password'], $_POST['password'],
http::getSelfURI() http::getSelfURI(),
]; ];
$core->activityReport->addLog('post', 'protection', $logs); dcCore::app()->activityReport->addLog('post', 'protection', $logs);
} }
public static function commentCreate($blog, $cur) public static function commentCreate($blog, $cur)
{ {
global $core;
if ($cur->comment_trackback) { if ($cur->comment_trackback) {
return null; return null;
} }
$posts = $core->blog->getPosts(['post_id' => $cur->post_id, 'limit' => 1]); $posts = dcCore::app()->blog->getPosts(['post_id' => $cur->post_id, 'limit' => 1]);
$logs = [ $logs = [
$cur->comment_author, $cur->comment_author,
$posts->post_title, $posts->post_title,
$core->blog->url . $core->url->getBase($posts->post_type) . dcCore::app()->blog->url . dcCore::app()->url->getBase($posts->post_type) .
'/' . $posts->post_url . '#c' . $cur->comment_id '/' . $posts->post_url . '#c' . $cur->comment_id,
]; ];
$core->activityReport->addLog('comment', 'create', $logs); dcCore::app()->activityReport->addLog('comment', 'create', $logs);
} }
public static function commentUpdate($blog, $cur, $old) public static function commentUpdate($blog, $cur, $old)
{ {
global $core; $posts = dcCore::app()->blog->getPosts(['post_id' => $old->post_id, 'limit' => 1]);
$posts = $core->blog->getPosts(['post_id' => $old->post_id, 'limit' => 1]);
$logs = [ $logs = [
$core->auth->getInfo('user_cn'), dcCore::app()->auth->getInfo('user_cn'),
$posts->post_title, $posts->post_title,
$core->blog->url . $core->url->getBase($posts->post_type) . dcCore::app()->blog->url . dcCore::app()->url->getBase($posts->post_type) .
'/' . $posts->post_url . '#c' . $old->comment_id '/' . $posts->post_url . '#c' . $old->comment_id,
]; ];
$core->activityReport->addLog('comment', 'update', $logs); dcCore::app()->activityReport->addLog('comment', 'update', $logs);
} }
public static function trackbackCreate($cur, $comment_id) public static function trackbackCreate($cur, $comment_id)
{ {
global $core;
// From blog args are $blog, $cur #thks to bruno // From blog args are $blog, $cur #thks to bruno
$c = $cur instanceOf dcBlog ? $comment_id : $cur; $c = $cur instanceof dcBlog ? $comment_id : $cur;
if (!$c->comment_trackback || !$c->comment_site) { if (!$c->comment_trackback || !$c->comment_site) {
return null; return null;
} }
$posts = $core->blog->getPosts( $posts = dcCore::app()->blog->getPosts(
['post_id' => $c->post_id, 'no_content' => true, 'limit' => 1]); ['post_id' => $c->post_id, 'no_content' => true, 'limit' => 1]
);
if ($posts->isEmpty()) { if ($posts->isEmpty()) {
return null; return null;
} }
@ -340,37 +329,34 @@ class activityReportBehaviors
$c->comment_author, $c->comment_author,
$c->comment_site, $c->comment_site,
$posts->post_title, $posts->post_title,
$core->blog->url . $core->url->getBase($posts->post_type) . dcCore::app()->blog->url . dcCore::app()->url->getBase($posts->post_type) .
'/' . $posts->post_url '/' . $posts->post_url,
]; ];
$core->activityReport->addLog('comment', 'trackback', $logs); dcCore::app()->activityReport->addLog('comment', 'trackback', $logs);
} }
public static function categoryCreate($cur, $cat_id) public static function categoryCreate($cur, $cat_id)
{ {
global $core;
$logs = [ $logs = [
$cur->cat_title, $cur->cat_title,
$core->auth->getInfo('user_cn'), dcCore::app()->auth->getInfo('user_cn'),
$core->blog->url . $core->url->getBase('category') . '/' . $cur->cat_url dcCore::app()->blog->url . dcCore::app()->url->getBase('category') . '/' . $cur->cat_url,
]; ];
$core->activityReport->addLog('category', 'create', $logs); dcCore::app()->activityReport->addLog('category', 'create', $logs);
} }
public static function categoryUpdate($cur, $cat_id) public static function categoryUpdate($cur, $cat_id)
{ {
global $core;
$logs = [ $logs = [
$cur->cat_title, $cur->cat_title,
$core->auth->getInfo('user_cn'), dcCore::app()->auth->getInfo('user_cn'),
$core->blog->url . $core->url->getBase('category') . '/' . $cur->cat_url dcCore::app()->blog->url . dcCore::app()->url->getBase('category') . '/' . $cur->cat_url,
]; ];
$core->activityReport->addLog('category', 'update', $logs); dcCore::app()->activityReport->addLog('category', 'update', $logs);
} }
public static function userCreate($cur, $user_id) public static function userCreate($cur, $user_id)
{ {
global $core;
$user_cn = dcUtils::getUserCN( $user_cn = dcUtils::getUserCN(
$cur->user_id, $cur->user_id,
$cur->user_name, $cur->user_name,
@ -379,14 +365,13 @@ class activityReportBehaviors
); );
$logs = [ $logs = [
$user_cn, $user_cn,
$core->auth->getInfo('user_cn') dcCore::app()->auth->getInfo('user_cn'),
]; ];
$core->activityReport->addLog('user', 'create', $logs); dcCore::app()->activityReport->addLog('user', 'create', $logs);
} }
public static function usertUpdate($cur, $user_id) public static function usertUpdate($cur, $user_id)
{ {
global $core;
$user_cn = dcUtils::getUserCN( $user_cn = dcUtils::getUserCN(
$cur->user_id, $cur->user_id,
$cur->user_name, $cur->user_name,
@ -395,15 +380,14 @@ class activityReportBehaviors
); );
$logs = [ $logs = [
$user_cn, $user_cn,
$core->auth->getInfo('user_cn') dcCore::app()->auth->getInfo('user_cn'),
]; ];
$core->activityReport->addLog('user', 'update', $logs); dcCore::app()->activityReport->addLog('user', 'update', $logs);
} }
public static function userDelete($user_id) public static function userDelete($user_id)
{ {
global $core; $users = dcCore::app()->getUser($user_id);
$users = $core->getUser($id);
$user_cn = dcUtils::getUserCN( $user_cn = dcUtils::getUserCN(
$users->user_id, $users->user_id,
$users->user_name, $users->user_name,
@ -412,8 +396,8 @@ class activityReportBehaviors
); );
$logs = [ $logs = [
$user_cn, $user_cn,
$core->auth->getInfo('user_cn') dcCore::app()->auth->getInfo('user_cn'),
]; ];
$core->activityReport->addLog('user', 'delete', $logs); dcCore::app()->activityReport->addLog('user', 'delete', $logs);
} }
} }

View File

@ -10,30 +10,29 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) {
if (!defined('DC_RC_PATH')){return;} return;
}
class activityReport class activityReport
{ {
public $core;
public $con; public $con;
private $ns = 'activityReport'; private $ns = 'activityReport';
private $_global = 0; private $_global = 0;
private $blog = null; private $blog = null;
private $table = ''; private $table = '';
private $groups = []; private $groups = [];
private $settings = []; private $settings = [];
private $lock_blog = null; private $lock_blog = null;
private $lock_global = null; private $lock_global = null;
public function __construct($core, $ns = 'activityReport') public function __construct($ns = 'activityReport')
{ {
$this->core =& $core; $this->con = dcCore::app()->con;
$this->con = $core->con; $this->table = dcCore::app()->prefix . 'activity';
$this->table = $core->prefix . 'activity'; $this->blog = dcCore::app()->con->escape(dcCore::app()->blog->id);
$this->blog = $core->con->escape($core->blog->id); $this->ns = dcCore::app()->con->escape($ns);
$this->ns = $core->con->escape($ns);
$this->getSettings(); $this->getSettings();
@ -54,49 +53,51 @@ class activityReport
public function getGroups($group = null, $action = null) public function getGroups($group = null, $action = null)
{ {
if ($action !== null) { if ($action !== null) {
return isset($this->groups[$group]['actions'][$action]) ? return $this->groups[$group]['actions'][$action] ?? null;
$this->groups[$group]['actions'][$action] : null;
} elseif ($group !== null) { } elseif ($group !== null) {
return isset($this->groups[$group]) ? return $this->groups[$group] ?? null;
$this->groups[$group] : null;
} else {
return $this->groups;
} }
return $this->groups;
} }
public function addGroup($group, $title) public function addGroup($group, $title)
{ {
$this->groups[$group] = [ $this->groups[$group] = [
'title' => $title, 'title' => $title,
'actions' => [] 'actions' => [],
]; ];
return true; return true;
} }
public function addAction($group, $action, $title, $msg, $behavior, $function) public function addAction($group, $action, $title, $msg, $behavior, $function)
{ {
if (!isset($this->groups[$group])) return false; if (!isset($this->groups[$group])) {
return false;
}
$this->groups[$group]['actions'][$action] = [ $this->groups[$group]['actions'][$action] = [
'title' => $title, 'title' => $title,
'msg' => $msg 'msg' => $msg,
]; ];
$this->core->addBehavior($behavior, $function); dcCore::app()->addBehavior($behavior, $function);
return true; return true;
} }
private function getSettings() private function getSettings()
{ {
$settings = [ $settings = [
'active' => false, 'active' => false,
'obsolete' => 2419200, 'obsolete' => 2419200,
'interval' => 86400, 'interval' => 86400,
'lastreport' => 0, 'lastreport' => 0,
'mailinglist' => [], 'mailinglist' => [],
'mailformat' => 'plain', 'mailformat' => 'plain',
'dateformat' => '%Y-%m-%d %H:%M:%S', 'dateformat' => '%Y-%m-%d %H:%M:%S',
'requests' => [], 'requests' => [],
'blogs' => [] 'blogs' => [],
]; ];
$this->settings[0] = $this->settings[1] = $settings; $this->settings[0] = $this->settings[1] = $settings;
@ -109,7 +110,7 @@ class activityReport
'ORDER BY setting_id DESC ' 'ORDER BY setting_id DESC '
); );
while($rs->fetch()) { while ($rs->fetch()) {
$k = $rs->f('setting_id'); $k = $rs->f('setting_id');
$v = $rs->f('setting_value'); $v = $rs->f('setting_value');
$b = $rs->f('blog_id'); $b = $rs->f('blog_id');
@ -139,9 +140,9 @@ class activityReport
$cur = $this->con->openCursor($this->table . '_setting'); $cur = $this->con->openCursor($this->table . '_setting');
$this->con->writeLock($this->table . '_setting'); $this->con->writeLock($this->table . '_setting');
$cur->blog_id = $this->_global ? null : $this->blog; $cur->blog_id = $this->_global ? null : $this->blog;
$cur->setting_id = $this->con->escape($n); $cur->setting_id = $this->con->escape($n);
$cur->setting_type = $this->ns; $cur->setting_type = $this->ns;
$cur->setting_value = (string) self::encode($v); $cur->setting_value = (string) self::encode($v);
$cur->insert(); $cur->insert();
@ -156,7 +157,7 @@ class activityReport
{ {
return $this->con->execute( return $this->con->execute(
'DELETE FROM ' . $this->table . '_setting ' . 'DELETE FROM ' . $this->table . '_setting ' .
"WHERE blog_id" . ($this->_global ? ' IS NULL' : "='" . $this->blog . "'") . ' ' . 'WHERE blog_id' . ($this->_global ? ' IS NULL' : "='" . $this->blog . "'") . ' ' .
"AND setting_id='" . $this->con->escape($n) . "' " . "AND setting_id='" . $this->con->escape($n) . "' " .
"AND setting_type='" . $this->ns . "' " "AND setting_type='" . $this->ns . "' "
); );
@ -166,11 +167,12 @@ class activityReport
public static function requests2params($requests) public static function requests2params($requests)
{ {
$r = []; $r = [];
foreach($requests as $group => $actions) { foreach ($requests as $group => $actions) {
foreach($actions as $action => $is) { foreach ($actions as $action => $is) {
$r[] = "activity_group='" . $group ."' AND activity_action='" . $action . "' "; $r[] = "activity_group='" . $group . "' AND activity_action='" . $action . "' ";
} }
} }
return empty($r) ? '' : 'AND (' . implode('OR ', $r) . ') '; return empty($r) ? '' : 'AND (' . implode('OR ', $r) . ') ';
} }
@ -181,28 +183,26 @@ class activityReport
} else { } else {
$content_r = empty($p['no_content']) ? 'activity_logs, ' : ''; $content_r = empty($p['no_content']) ? 'activity_logs, ' : '';
if (!empty($params['columns']) && is_array($params['columns'])) { if (!empty($p['columns']) && is_array($p['columns'])) {
$content_r .= implode(', ', $params['columns']) . ', '; $content_r .= implode(', ', $p['columns']) . ', ';
} }
$r = $r = 'SELECT E.activity_id, E.blog_id, B.blog_url, B.blog_name, ' . $content_r .
'SELECT E.activity_id, E.blog_id, B.blog_url, B.blog_name, ' . $content_r .
'E.activity_group, E.activity_action, E.activity_dt, ' . 'E.activity_group, E.activity_action, E.activity_dt, ' .
'E.activity_blog_status, E.activity_super_status '; 'E.activity_blog_status, E.activity_super_status ';
} }
$r .= $r .= 'FROM ' . $this->table . ' E ' .
'FROM ' . $this->table . ' E ' . 'LEFT JOIN ' . dcCore::app()->prefix . 'blog B on E.blog_id=B.blog_id ';
'LEFT JOIN ' . $this->core->prefix . 'blog B on E.blog_id=B.blog_id ';
if (!empty($p['from'])) { if (!empty($p['from'])) {
$r .= $p['from'] . ' '; $r .= $p['from'] . ' ';
} }
if ($this->_global) { if ($this->_global) {
$r .= "WHERE E.activity_super_status = 0 "; $r .= 'WHERE E.activity_super_status = 0 ';
} else { } else {
$r .= "WHERE E.activity_blog_status = 0 "; $r .= 'WHERE E.activity_blog_status = 0 ';
} }
if (!empty($p['activity_type'])) { if (!empty($p['activity_type'])) {
@ -212,12 +212,12 @@ class activityReport
} }
if (!empty($p['blog_id'])) { if (!empty($p['blog_id'])) {
if(is_array($p['blog_id'])) { if (is_array($p['blog_id'])) {
$r .= 'AND E.blog_id' . $this->con->in($p['blog_id']); $r .= 'AND E.blog_id' . $this->con->in($p['blog_id']);
} else { } else {
$r .= "AND E.blog_id = '" . $this->con->escape($p['blog_id']) . "' "; $r .= "AND E.blog_id = '" . $this->con->escape($p['blog_id']) . "' ";
} }
} elseif($this->_global) { } elseif ($this->_global) {
$r .= 'AND E.blog_id IS NOT NULL '; $r .= 'AND E.blog_id IS NOT NULL ';
} else { } else {
$r .= "AND E.blog_id='" . $this->blog . "' "; $r .= "AND E.blog_id='" . $this->blog . "' ";
@ -240,19 +240,19 @@ class activityReport
} }
if (isset($p['activity_blog_status'])) { if (isset($p['activity_blog_status'])) {
$r .= "AND E.activity_blog_status = " . ((integer) $p['activity_blog_status']) . " "; $r .= 'AND E.activity_blog_status = ' . ((int) $p['activity_blog_status']) . ' ';
} }
if (isset($p['activity_super_status'])) { if (isset($p['activity_super_status'])) {
$r .= "AND E.activity_super_status = " . ((integer) $p['activity_super_status']) . " "; $r .= 'AND E.activity_super_status = ' . ((int) $p['activity_super_status']) . ' ';
} }
if (isset($p['from_date_ts'])) { if (isset($p['from_date_ts'])) {
$dt = date('Y-m-d H:i:s',$p['from_date_ts']); $dt = date('Y-m-d H:i:s', $p['from_date_ts']);
$r .= "AND E.activity_dt >= TIMESTAMP '" . $dt . "' "; $r .= "AND E.activity_dt >= TIMESTAMP '" . $dt . "' ";
} }
if (isset($p['to_date_ts'])) { if (isset($p['to_date_ts'])) {
$dt = date('Y-m-d H:i:s',$p['to_date_ts']); $dt = date('Y-m-d H:i:s', $p['to_date_ts']);
$r .= "AND E.activity_dt < TIMESTAMP '" . $dt . "' "; $r .= "AND E.activity_dt < TIMESTAMP '" . $dt . "' ";
} }
@ -281,19 +281,19 @@ class activityReport
$cur = $this->con->openCursor($this->table); $cur = $this->con->openCursor($this->table);
$this->con->writeLock($this->table); $this->con->writeLock($this->table);
$cur->activity_id = $this->getNextId(); $cur->activity_id = $this->getNextId();
$cur->activity_type = $this->ns; $cur->activity_type = $this->ns;
$cur->blog_id = $this->blog; $cur->blog_id = $this->blog;
$cur->activity_group = $this->con->escape((string) $group); $cur->activity_group = $this->con->escape((string) $group);
$cur->activity_action = $this->con->escape((string) $action); $cur->activity_action = $this->con->escape((string) $action);
$cur->activity_logs = self::encode($logs); $cur->activity_logs = self::encode($logs);
$cur->activity_dt = date('Y-m-d H:i:s'); $cur->activity_dt = date('Y-m-d H:i:s');
$cur->insert(); $cur->insert();
$this->con->unlock(); $this->con->unlock();
} catch (Exception $e) { } catch (Exception $e) {
$this->con->unlock(); $this->con->unlock();
$this->core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
// Test if email report is needed // Test if email report is needed
@ -307,12 +307,12 @@ class activityReport
} }
// @todo move this in function // @todo move this in function
include dirname(__FILE__) . '/lib.parselogs.config.php'; include __DIR__ . '/lib.parselogs.config.php';
$from = time(); $from = time();
$to = 0; $to = 0;
$res = $blog = $group = ''; $res = $blog = $group = '';
$tz = $this->_global ? 'UTC' : $this->core->blog->settings->system->blog_timezone; $tz = $this->_global ? 'UTC' : dcCore::app()->blog->settings->system->blog_timezone;
$dt = $this->settings[$this->_global]['dateformat']; $dt = $this->settings[$this->_global]['dateformat'];
$dt = empty($dt) ? '%Y-%m-%d %H:%M:%S' : $dt; $dt = empty($dt) ? '%Y-%m-%d %H:%M:%S' : $dt;
@ -322,7 +322,7 @@ class activityReport
$blog_open = $group_open = false; $blog_open = $group_open = false;
while($rs->fetch()) { while ($rs->fetch()) {
// blog // blog
if ($rs->blog_id != $blog && $this->_global) { if ($rs->blog_id != $blog && $this->_global) {
if ($group_open) { if ($group_open) {
@ -333,7 +333,7 @@ class activityReport
$res .= $tpl['blog_close']; $res .= $tpl['blog_close'];
} }
$blog = $rs->blog_id; $blog = $rs->blog_id;
$group = ''; $group = '';
$res .= str_replace( $res .= str_replace(
@ -410,13 +410,14 @@ class activityReport
$tpl['info'] $tpl['info']
); );
if (!$this->_global) { if (!$this->_global) {
$period .= str_replace('%TEXT%', $rs->blog_name,$tpl['info']); $period .= str_replace('%TEXT%', $rs->blog_name, $tpl['info']);
$period .= str_replace('%TEXT%', $rs->blog_url,$tpl['info']); $period .= str_replace('%TEXT%', $rs->blog_url, $tpl['info']);
} }
$period .= str_replace( $period .= str_replace(
'%TEXT%', '%TEXT%',
sprintf(__('Period from %s to %s'), dt::str($dt, $from, $tz), dt::str($dt, $to, $tz)), sprintf(__('Period from %s to %s'), dt::str($dt, $from, $tz), dt::str($dt, $to, $tz)),
$tpl['info']); $tpl['info']
);
$period .= $tpl['period_close']; $period .= $tpl['period_close'];
$res = str_replace(['%PERIOD%', '%TEXT%'], [$period, $res], $tpl['page']); $res = str_replace(['%PERIOD%', '%TEXT%'], [$period, $res], $tpl['page']);
@ -428,7 +429,7 @@ class activityReport
{ {
// Get blogs and logs count // Get blogs and logs count
$rs = $this->con->select( $rs = $this->con->select(
"SELECT blog_id " . 'SELECT blog_id ' .
'FROM ' . $this->table . ' ' . 'FROM ' . $this->table . ' ' .
"WHERE activity_type='" . $this->ns . "' " . "WHERE activity_type='" . $this->ns . "' " .
'GROUP BY blog_id ' 'GROUP BY blog_id '
@ -439,16 +440,16 @@ class activityReport
} }
while ($rs->fetch()) { while ($rs->fetch()) {
$ts = time(); $ts = time();
$obs_blog = dt::str('%Y-%m-%d %H:%M:%S', $ts - (integer) $this->settings[0]['obsolete']); $obs_blog = dt::str('%Y-%m-%d %H:%M:%S', $ts - (int) $this->settings[0]['obsolete']);
$obs_global = dt::str('%Y-%m-%d %H:%M:%S', $ts - (integer) $this->settings[1]['obsolete']); $obs_global = dt::str('%Y-%m-%d %H:%M:%S', $ts - (int) $this->settings[1]['obsolete']);
$this->con->execute( $this->con->execute(
'DELETE FROM ' . $this->table . ' ' . 'DELETE FROM ' . $this->table . ' ' .
"WHERE activity_type='" . $this->ns . "' " . "WHERE activity_type='" . $this->ns . "' " .
"AND (activity_dt < TIMESTAMP '" . $obs_blog . "' " . "AND (activity_dt < TIMESTAMP '" . $obs_blog . "' " .
"OR activity_dt < TIMESTAMP '" . $obs_global . "') " . "OR activity_dt < TIMESTAMP '" . $obs_global . "') " .
"AND blog_id = '" . $this->con->escape($rs->blog_id) ."' " "AND blog_id = '" . $this->con->escape($rs->blog_id) . "' "
); );
if ($this->con->changes()) { if ($this->con->changes()) {
@ -456,19 +457,19 @@ class activityReport
$cur = $this->con->openCursor($this->table); $cur = $this->con->openCursor($this->table);
$this->con->writeLock($this->table); $this->con->writeLock($this->table);
$cur->activity_id = $this->getNextId(); $cur->activity_id = $this->getNextId();
$cur->activity_type = $this->ns; $cur->activity_type = $this->ns;
$cur->blog_id = $rs->blog_id; $cur->blog_id = $rs->blog_id;
$cur->activity_group = 'activityReport'; $cur->activity_group = 'activityReport';
$cur->activity_action = 'message'; $cur->activity_action = 'message';
$cur->activity_logs = self::encode(__('Activity report deletes some old logs.')); $cur->activity_logs = self::encode(__('Activity report deletes some old logs.'));
$cur->activity_dt = date('Y-m-d H:i:s'); $cur->activity_dt = date('Y-m-d H:i:s');
$cur->insert(); $cur->insert();
$this->con->unlock(); $this->con->unlock();
} catch (Exception $e) { } catch (Exception $e) {
$this->con->unlock(); $this->con->unlock();
$this->core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
} }
} }
@ -479,14 +480,14 @@ class activityReport
$this->con->execute( $this->con->execute(
'DELETE FROM ' . $this->table . ' ' . 'DELETE FROM ' . $this->table . ' ' .
"WHERE activity_type='" . $this->ns . "' " . "WHERE activity_type='" . $this->ns . "' " .
"AND activity_blog_status = 1 " . 'AND activity_blog_status = 1 ' .
"AND activity_super_status = 1 " 'AND activity_super_status = 1 '
); );
} }
public function deleteLogs() public function deleteLogs()
{ {
if (!$this->core->auth->isSuperAdmin()) { if (!dcCore::app()->auth->isSuperAdmin()) {
return null; return null;
} }
@ -501,14 +502,13 @@ class activityReport
$r = 'UPDATE ' . $this->table . ' '; $r = 'UPDATE ' . $this->table . ' ';
if ($this->_global) { if ($this->_global) {
$r .= "SET activity_super_status = 1 WHERE blog_id IS NOT NULL "; $r .= 'SET activity_super_status = 1 WHERE blog_id IS NOT NULL ';
} else { } else {
$r .= "SET activity_blog_status = 1 WHERE blog_id = '" . $this->blog . "' "; $r .= "SET activity_blog_status = 1 WHERE blog_id = '" . $this->blog . "' ";
} }
$r .= $r .= "AND activity_type = '" . $this->ns . "' " .
"AND activity_type = '" . $this->ns . "' " . "AND activity_dt >= TIMESTAMP '" . date('Y-m-d H:i:s', $from_date_ts) . "' " .
"AND activity_dt >= TIMESTAMP '" . date('Y-m-d H:i:s',$from_date_ts) . "' " . "AND activity_dt < TIMESTAMP '" . date('Y-m-d H:i:s', $to_date_ts) . "' ";
"AND activity_dt < TIMESTAMP '" . date('Y-m-d H:i:s',$to_date_ts) . "' ";
$this->con->execute($r); $this->con->execute($r);
} }
@ -526,15 +526,16 @@ class activityReport
try { try {
# Need flock function # Need flock function
if (!function_exists('flock')) { if (!function_exists('flock')) {
throw New Exception("Can't call php function named flock"); throw new Exception("Can't call php function named flock");
} }
# Cache writable ? # Cache writable ?
if (!is_writable(DC_TPL_CACHE)) { if (!is_writable(DC_TPL_CACHE)) {
throw new Exception("Can't write in cache fodler"); throw new Exception("Can't write in cache fodler");
} }
# Set file path # Set file path
$f_md5 = $this->_global ? md5(DC_MASTER_KEY) : md5($this->blog); $f_md5 = $this->_global ? md5(DC_MASTER_KEY) : md5($this->blog);
$cached_file = sprintf('%s/%s/%s/%s/%s.txt', $cached_file = sprintf(
'%s/%s/%s/%s/%s.txt',
DC_TPL_CACHE, DC_TPL_CACHE,
'activityreport', 'activityreport',
substr($f_md5, 0, 2), substr($f_md5, 0, 2),
@ -545,35 +546,37 @@ class activityReport
$cached_file = path::real($cached_file, false); $cached_file = path::real($cached_file, false);
// make dir // make dir
if (!is_dir(dirname($cached_file))) { if (!is_dir(dirname($cached_file))) {
files::makeDir(dirname($cached_file), true); files::makeDir(dirname($cached_file), true);
} }
//ake file //ake file
if (!file_exists($cached_file)) { if (!file_exists($cached_file)) {
!$fp = @fopen($cached_file, 'w'); !$fp = @fopen($cached_file, 'w');
if ($fp === false) { if ($fp === false) {
throw New Exception("Can't create file"); throw new Exception("Can't create file");
} }
fwrite($fp, '1', strlen('1')); fwrite($fp, '1', strlen('1'));
fclose($fp); fclose($fp);
} }
// open file // open file
if (!($fp = @fopen($cached_file, 'r+'))) { if (!($fp = @fopen($cached_file, 'r+'))) {
throw New Exception("Can't open file"); throw new Exception("Can't open file");
} }
// lock file // lock file
if (!flock($fp, LOCK_EX)) { if (!flock($fp, LOCK_EX)) {
throw New Exception("Can't lock file"); throw new Exception("Can't lock file");
} }
if ($this->_global) { if ($this->_global) {
$this->lock_global = $fp; $this->lock_global = $fp;
} else { } else {
$this->lock_blog = $fp; $this->lock_blog = $fp;
} }
return true; return true;
} catch (Exception $e) { } catch (Exception $e) {
// what ? // what ?
throw $e; throw $e;
} }
return false; return false;
} }
@ -605,15 +608,15 @@ class activityReport
$this->lockUpdate(); $this->lockUpdate();
$send = false; $send = false;
$now = time(); $now = time();
$active = (boolean) $this->settings[$this->_global]['active']; $active = (bool) $this->settings[$this->_global]['active'];
$mailinglist = $this->settings[$this->_global]['mailinglist']; $mailinglist = $this->settings[$this->_global]['mailinglist'];
$mailformat = $this->settings[$this->_global]['mailformat']; $mailformat = $this->settings[$this->_global]['mailformat'];
$requests = $this->settings[$this->_global]['requests']; $requests = $this->settings[$this->_global]['requests'];
$lastreport = (integer) $this->settings[$this->_global]['lastreport']; $lastreport = (int) $this->settings[$this->_global]['lastreport'];
$interval = (integer) $this->settings[$this->_global]['interval']; $interval = (int) $this->settings[$this->_global]['interval'];
$blogs = $this->settings[$this->_global]['blogs']; $blogs = $this->settings[$this->_global]['blogs'];
if ($force) { if ($force) {
$lastreport = 0; $lastreport = 0;
@ -621,15 +624,15 @@ class activityReport
// Check if report is needed // Check if report is needed
if ($active && !empty($mailinglist) && !empty($requests) && !empty($blogs) if ($active && !empty($mailinglist) && !empty($requests) && !empty($blogs)
&& ($lastreport + $interval) < $now && ($lastreport + $interval) < $now
) { ) {
// Get datas // Get datas
$params = [ $params = [
'from_date_ts' => $lastreport, 'from_date_ts' => $lastreport,
'to_date_ts' => $now, 'to_date_ts' => $now,
'blog_id' => $blogs, 'blog_id' => $blogs,
'sql' => self::requests2params($requests), 'sql' => self::requests2params($requests),
'order' => 'blog_id ASC, activity_group ASC, activity_action ASC, activity_dt ASC ' 'order' => 'blog_id ASC, activity_group ASC, activity_action ASC, activity_dt ASC ',
]; ];
$logs = $this->getLogs($params); $logs = $this->getLogs($params);
@ -657,7 +660,7 @@ class activityReport
$this->_global = false; $this->_global = false;
if ($send) { if ($send) {
$this->core->callBehavior('messageActivityReport', 'Activity report has been successfully send by mail.'); dcCore::app()->callBehavior('messageActivityReport', 'Activity report has been successfully send by mail.');
} }
} }
$this->unlockUpdate(); $this->unlockUpdate();
@ -665,15 +668,16 @@ class activityReport
$this->unlockUpdate(); $this->unlockUpdate();
//throw $e; //throw $e;
} }
return true; return true;
} }
private function sendReport($recipients, $message, $mailformat =' ') private function sendReport($recipients, $message, $mailformat = ' ')
{ {
if (!is_array($recipients) || empty($message)) { if (!is_array($recipients) || empty($message)) {
return false; return false;
} }
$mailformat = $mailformat == 'html' ? 'html' : 'plain'; $mailformat = $mailformat == 'html' ? 'html' : 'plain';
// Checks recipients addresses // Checks recipients addresses
$rc2 = []; $rc2 = [];
@ -693,19 +697,20 @@ class activityReport
# Sending mails # Sending mails
try { try {
$subject = mb_encode_mimeheader( $subject = mb_encode_mimeheader(
($this->_global ? '[' . $this->core->blog->name . '] ' : '') . __('Blog activity report'), ($this->_global ? '[' . dcCore::app()->blog->name . '] ' : '') . __('Blog activity report'),
'UTF-8', 'B' 'UTF-8',
'B'
); );
$headers = []; $headers = [];
$headers[] = 'From: ' . (defined('DC_ADMIN_MAILFROM') && DC_ADMIN_MAILFROM ? DC_ADMIN_MAILFROM : 'dotclear@local'); $headers[] = 'From: ' . (defined('DC_ADMIN_MAILFROM') && DC_ADMIN_MAILFROM ? DC_ADMIN_MAILFROM : 'dotclear@local');
$headers[] = 'Content-Type: text/' . $mailformat .'; charset=UTF-8;'; $headers[] = 'Content-Type: text/' . $mailformat . '; charset=UTF-8;';
//$headers[] = 'MIME-Version: 1.0'; //$headers[] = 'MIME-Version: 1.0';
//$headers[] = 'X-Originating-IP: ' . mb_encode_mimeheader(http::realIP(), 'UTF-8', 'B'); //$headers[] = 'X-Originating-IP: ' . mb_encode_mimeheader(http::realIP(), 'UTF-8', 'B');
//$headers[] = 'X-Mailer: Dotclear'; //$headers[] = 'X-Mailer: Dotclear';
//$headers[] = 'X-Blog-Id: ' . mb_encode_mimeheader($this->core->blog->id), 'UTF-8', 'B'); //$headers[] = 'X-Blog-Id: ' . mb_encode_mimeheader(dcCore::app()->blog->id), 'UTF-8', 'B');
//$headers[] = 'X-Blog-Name: ' . mb_encode_mimeheader($this->core->blog->name), 'UTF-8', 'B'); //$headers[] = 'X-Blog-Name: ' . mb_encode_mimeheader(dcCore::app()->blog->name), 'UTF-8', 'B');
//$headers[] = 'X-Blog-Url: ' . mb_encode_mimeheader($this->core->blog->url), 'UTF-8', 'B'); //$headers[] = 'X-Blog-Url: ' . mb_encode_mimeheader(dcCore::app()->blog->url), 'UTF-8', 'B');
$done = true; $done = true;
foreach ($recipients as $email) { foreach ($recipients as $email) {
@ -713,17 +718,19 @@ class activityReport
$done = false; $done = false;
} }
} }
} catch (Exception $e) {var_dump($e); } catch (Exception $e) {
var_dump($e);
$done = false; $done = false;
} }
return $done; return $done;
} }
public function getUserCode() public function getUserCode()
{ {
$code = $code = pack('a32', dcCore::app()->auth->userID()) .
pack('a32', $this->core->auth->userID()) . pack('H*', crypt::hmac(DC_MASTER_KEY, dcCore::app()->auth->getInfo('user_pwd')));
pack('H*', crypt::hmac(DC_MASTER_KEY, $this->core->auth->getInfo('user_pwd')));
return bin2hex($code); return bin2hex($code);
} }
@ -732,7 +739,7 @@ class activityReport
$code = pack('H*', $code); $code = pack('H*', $code);
$user_id = trim(@pack('a32', substr($code, 0, 32))); $user_id = trim(@pack('a32', substr($code, 0, 32)));
$pwd = @unpack('H40hex', substr($code, 32, 40)); $pwd = @unpack('H40hex', substr($code, 32, 40));
if ($user_id === false || $pwd === false) { if ($user_id === false || $pwd === false) {
return false; return false;
@ -741,16 +748,16 @@ class activityReport
$pwd = $pwd['hex']; $pwd = $pwd['hex'];
$strReq = 'SELECT user_id, user_pwd ' . $strReq = 'SELECT user_id, user_pwd ' .
'FROM ' . $this->core->prefix . 'user ' . 'FROM ' . dcCore::app()->prefix . 'user ' .
"WHERE user_id = '" . $this->core->con->escape($user_id) . "' "; "WHERE user_id = '" . dcCore::app()->con->escape($user_id) . "' ";
$rs = $this->core->con->select($strReq); $rs = dcCore::app()->con->select($strReq);
if ($rs->isEmpty()) { if ($rs->isEmpty()) {
return false; return false;
} }
if (crypt::hmac(DC_MASTER_KEY,$rs->user_pwd) != $pwd) { if (crypt::hmac(DC_MASTER_KEY, $rs->user_pwd) != $pwd) {
return false; return false;
} }

View File

@ -10,55 +10,52 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
$format = [ $format = [
'html' => [ 'html' => [
'blog_title' => '<h2><a href="%URL%">%TEXT%</a></h2>', 'blog_title' => '<h2><a href="%URL%">%TEXT%</a></h2>',
'blog_open' => '', 'blog_open' => '',
'blog_close' => '', 'blog_close' => '',
'group_title' => '<h3>%TEXT%</h3>', 'group_title' => '<h3>%TEXT%</h3>',
'group_open' => '<ul>', 'group_open' => '<ul>',
'group_close' => '</ul>', 'group_close' => '</ul>',
'action' => '<li><em>%TIME%</em><br />%TEXT%</li>', 'action' => '<li><em>%TIME%</em><br />%TEXT%</li>',
'error' => '<p>%TEXT%</p>', 'error' => '<p>%TEXT%</p>',
'period_title' => '<h1>%TEXT%</h1>', 'period_title' => '<h1>%TEXT%</h1>',
'period_open' => '<ul>', 'period_open' => '<ul>',
'period_close' => '</ul>', 'period_close' => '</ul>',
'info' => '<li>%TEXT%</li>', 'info' => '<li>%TEXT%</li>',
'page' => 'page' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' . "\n" .
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'."\n". '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">' . "\n" .
'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n". '<head><title>' . __('Activity report') . '</title>' .
"<head><title>".__('Activity report')."</title>". '<style type="text/css">' .
'<style type="text/css">'. ' body { color: #303030; background: #FCFCFC; font-size: 0.7em;font-family: Georgia, Tahoma, Arial, Helvetica, sans-serif; }' .
' body { color: #303030; background: #FCFCFC; font-size: 0.7em;font-family: Georgia, Tahoma, Arial, Helvetica, sans-serif; }'. ' a { color: #303030; text-decoration: none; }' .
' a { color: #303030; text-decoration: none; }'. ' h1 { text-align: center; font-size: 2em; }' .
' h1 { text-align: center; font-size: 2em; }'. ' h2 { color: #303030; text-align:center; }' .
' h2 { color: #303030; text-align:center; }'. ' h3 { color: #7F3F3F; }' .
' h3 { color: #7F3F3F; }'. ' li em { color: #303030; }' .
' li em { color: #303030; }'. ' div.info { color: #3F497F; background-color: #F8F8EB; border: 1px solid #888888; margin: 4px; padding: 4px; }' .
' div.info { color: #3F497F; background-color: #F8F8EB; border: 1px solid #888888; margin: 4px; padding: 4px; }'. ' div.content { color: #3F7F47; background-color: #F8F8EB; border: 1px solid #888888; margin: 4px; padding: 4px; }' .
' div.content { color: #3F7F47; background-color: #F8F8EB; border: 1px solid #888888; margin: 4px; padding: 4px; }'. ' div.foot { text-align:center; font-size: 0.9em; }' .
' div.foot { text-align:center; font-size: 0.9em; }'. '</style>' .
'</style>'. '</head><body>' .
"</head><body>". '<div class="info">%PERIOD%</div><div class="content">%TEXT%</div>' .
'<div class="info">%PERIOD%</div><div class="content">%TEXT%</div>'. '<div class="foot"><p>Powered by <a href="http://dotclear.jcdenis.com/go/activityReport">activityReport</a></p></div>' .
'<div class="foot"><p>Powered by <a href="http://dotclear.jcdenis.com/go/activityReport">activityReport</a></p></div>'. '</body></html>',
"</body></html>"
], ],
'plain' => [ 'plain' => [
'blog_title' => "\n--- %TEXT% ---\n", 'blog_title' => "\n--- %TEXT% ---\n",
'blog_open' => '', 'blog_open' => '',
'blog_close' => '', 'blog_close' => '',
'group_title' => "\n-- %TEXT% --\n\n", 'group_title' => "\n-- %TEXT% --\n\n",
'group_open' => '', 'group_open' => '',
'group_close' => '', 'group_close' => '',
'action' => "- %TIME% : %TEXT%\n", 'action' => "- %TIME% : %TEXT%\n",
'error' => '%TEXT%', 'error' => '%TEXT%',
'period_title' => "%TEXT%\n", 'period_title' => "%TEXT%\n",
'period_open' => '', 'period_open' => '',
'period_close' => '', 'period_close' => '',
'info' => "%TEXT%\n", 'info' => "%TEXT%\n",
'page' => 'page' => "%PERIOD%\n-----------------------------------------------------------\n%TEXT%",
"%PERIOD%\n-----------------------------------------------------------\n%TEXT%" ],
]
]; ];

View File

@ -10,44 +10,42 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
if (!defined('ACTIVITY_REPORT')) { if (!defined('ACTIVITY_REPORT_V2')) {
return null; return null;
} }
dcPage::check('admin'); dcPage::check(dcAuth::PERMISSION_ADMIN);
$report =& $core->activityReport; $super = dcCore::app()->auth->isSuperAdmin() && !empty($_REQUEST['super']);
$super = $core->auth->isSuperAdmin() && !empty($_REQUEST['super']);
if ($super) { if ($super) {
$report->setGlobal(); dcCore::app()->activityReport->setGlobal();
} }
$logs = $report->getLogs([]); $logs = dcCore::app()->activityReport->getLogs([]);
if ($super) { if ($super) {
$breadcrumb = [ $breadcrumb = [
__('Current blog') => $core->adminurl->get('admin.plugin.activityReport', ['super' => 0]), __('Current blog') => dcCore::app()->adminurl->get('admin.plugin.activityReport', ['super' => 0]),
'<span class="page-title">' . __('All blogs') . '</span>' => '' '<span class="page-title">' . __('All blogs') . '</span>' => '',
]; ];
} else { } else {
$breadcrumb = ['<span class="page-title">' . __('Current blog') . '</span>' => '']; $breadcrumb = ['<span class="page-title">' . __('Current blog') . '</span>' => ''];
if ($core->auth->isSuperAdmin()) { if (dcCore::app()->auth->isSuperAdmin()) {
$breadcrumb[__('All blogs')] = $core->adminurl->get('admin.plugin.activityReport', ['super' => 1]); $breadcrumb[__('All blogs')] = dcCore::app()->adminurl->get('admin.plugin.activityReport', ['super' => 1]);
} }
} }
echo '<html><head><title>' . __('Activity report') . '</title></head><body>' . echo '<html><head><title>' . __('Activity report') . '</title></head><body>' .
dcPage::breadcrumb(array_merge([__('Activity report') => '', __('Logs') => ''], $breadcrumb),['hl' => false]) . dcPage::breadcrumb(array_merge([__('Activity report') => '', __('Logs') => ''], $breadcrumb), ['hl' => false]) .
dcPage::notices(); dcPage::notices();
if ($logs->isEmpty()) { if ($logs->isEmpty()) {
echo '<p>'.__('No log').'</p>'; echo '<p>' . __('No log') . '</p>';
} else { } else {
echo ' echo '
<div class="table-outer"><table><thead> <div class="table-outer"><table><thead>
@ -56,24 +54,24 @@ if ($logs->isEmpty()) {
<th>' . __('Message') . '</th> <th>' . __('Message') . '</th>
<th>' . __('Date') . '</th>'; <th>' . __('Date') . '</th>';
if ($super) { if ($super) {
echo '<th>' . __('Blog') .'</th>'; echo '<th>' . __('Blog') . '</th>';
} }
echo '</tr></thead><tbody>'; echo '</tr></thead><tbody>';
while($logs->fetch()) { while ($logs->fetch()) {
$action = $report->getGroups($logs->activity_group, $logs->activity_action); $action = dcCore::app()->activityReport->getGroups($logs->activity_group, $logs->activity_action);
if (empty($action)) { if (empty($action)) {
continue; continue;
} }
$off = $super && $logs->activity_blog_status == 1 ? ' offline' : ''; $off = $super && $logs->activity_blog_status == 1 ? ' offline' : '';
$date = dt::str( $date = dt::str(
$core->blog->settings->system->date_format . ', ' . $core->blog->settings->system->time_format, dcCore::app()->blog->settings->system->date_format . ', ' . dcCore::app()->blog->settings->system->time_format,
strtotime($logs->activity_dt), strtotime($logs->activity_dt),
$core->auth->getInfo('user_tz') dcCore::app()->auth->getInfo('user_tz')
); );
$msg = vsprintf(__($action['msg']), $report->decode($logs->activity_logs)); $msg = vsprintf(__($action['msg']), dcCore::app()->activityReport->decode($logs->activity_logs));
echo ' echo '
<tr class="line' . $off . '"> <tr class="line' . $off . '">
@ -87,6 +85,6 @@ if ($logs->isEmpty()) {
} }
echo '</tbody></table></div>'; echo '</tbody></table></div>';
} }
$report->unsetGlobal(); dcCore::app()->activityReport->unsetGlobal();
echo '</body></html>'; echo '</body></html>';

View File

@ -1,265 +0,0 @@
<?php
// Language: Français
// Module: activityReport - 1.0.1
// Date: 2021-09-03 21:33:45
// Translated with dcTranslater - 2021.09.02.1
#_admin.php:22
#_admin.php:83
#_admin.php:97
#inc/class.activity.report.php:405
#inc/lib.parselogs.config.php:31
#index.php:45
#index.php:46
$GLOBALS['__l10n']['Activity report'] = 'Rapport d\'activité';
#_admin.php:86
$GLOBALS['__l10n']['View all logs'] = 'Voir tous les logs';
#_admin.php:99
$GLOBALS['__l10n']['Number of activities to show on dashboard:'] = 'Nombre d\'activités à afficher sur le tableau de bord :';
#_admin.php:127
$GLOBALS['__l10n']['Do not show activity report'] = 'Ne pas afficher le rapport d\'activité';
#_config.php:27
#_config.php:36
$GLOBALS['__l10n']['every hour'] = 'toutes les heures';
#_config.php:28
#_config.php:37
$GLOBALS['__l10n']['every 2 hours'] = 'toutes les 2 heures';
#_config.php:29
#_config.php:38
$GLOBALS['__l10n']['2 times by day'] = '2 fois par jour';
#_config.php:30
#_config.php:39
$GLOBALS['__l10n']['every day'] = 'tous les jours';
#_config.php:31
#_config.php:40
$GLOBALS['__l10n']['every 2 days'] = 'tous les 2 jours';
#_config.php:32
#_config.php:41
$GLOBALS['__l10n']['every week'] = 'toutes les semaines';
#_config.php:42
$GLOBALS['__l10n']['every 2 weeks'] = 'toutes les 2 semaines';
#_config.php:43
$GLOBALS['__l10n']['every 4 weeks'] = 'toutes les 4 semaines';
#_config.php:47
$GLOBALS['__l10n']['Plain text'] = 'Texte brut';
#_config.php:48
$GLOBALS['__l10n']['HTML'] = 'HTML';
#_config.php:84
$GLOBALS['__l10n']['never'] = 'jamais';
#_config.php:85
$GLOBALS['__l10n']['on new activity'] = 'lors d\'une nouvelle activité';
#_config.php:104
$GLOBALS['__l10n']['Configure activity report for %s'] = 'Configurer le rapport d\'activité pour %s';
#_config.php:104
$GLOBALS['__l10n']['current blog'] = 'blog courant';
#_config.php:109
$GLOBALS['__l10n']['This server has no mail function, activityReport does not send email report.'] = 'Ce server n\'a pas de fonction d\'envoie de mail, le rapport ne sera pas envoyer.';
#_config.php:120
$GLOBALS['__l10n']['Enable super administrator report'] = 'Autoriser le rapport de super administrateur';
#_config.php:121
$GLOBALS['__l10n']['Enable report on this blog'] = 'Autoriser le rapport sur ce blog';
#_config.php:124
$GLOBALS['__l10n']['Automatic cleaning of old logs:'] = 'Nettoyage automatique des anciennes activités:';
#_config.php:129
$GLOBALS['__l10n']['Use Dotclear date formaters. ex: %B %d at %H:%M'] = 'Utiliser le formatage des dates de Dotclear. ex: %d %B à %H:%M';
#_config.php:135
#_config.php:136
$GLOBALS['__l10n']['RSS feed'] = 'Flux RSS';
#_config.php:138
$GLOBALS['__l10n']['Rss2 feed for activity on this blog'] = 'Flux Rss2 pour l\'activité de ce blog';
#_config.php:139
#_config.php:140
$GLOBALS['__l10n']['Atom feed'] = 'Flux Atom';
#_config.php:142
$GLOBALS['__l10n']['Atom feed for activity on this blog'] = 'Flux Atom pour l\'activité de ce blog';
#_config.php:147
$GLOBALS['__l10n']['Send report:'] = 'Rapport envoyé :';
#_config.php:150
$GLOBALS['__l10n']['Recipients:'] = 'Destinataires :';
#_config.php:152
$GLOBALS['__l10n']['Separate multiple email addresses with a semicolon ";"'] = 'Séparer les adresses email par un point-virgule ";"';
#_config.php:154
$GLOBALS['__l10n']['Report format:'] = 'Format du rapport :';
#_config.php:158
$GLOBALS['__l10n']['Last report by email:'] = 'Dernier rapport par email :';
#_config.php:159
$GLOBALS['__l10n']['Next report by email:'] = 'Prochain rapport par email :';
#_config.php:167
$GLOBALS['__l10n']['Select blogs to add to report'] = 'Sélectionner les blogs à ajouter au rapport';
#_config.php:192
$GLOBALS['__l10n']['Report'] = 'Rapport';
#_config.php:193
$GLOBALS['__l10n']['Select actions by activity type to add to report'] = 'Sélectionner les actions par type d\'activité à ajouter au rapport';
#inc/class.activity.report.behaviors.php:28
$GLOBALS['__l10n']['ActivityReport messages'] = 'Messages de l\'extension';
#inc/class.activity.report.behaviors.php:33
$GLOBALS['__l10n']['Special messages'] = 'Messages spéciaux';
#inc/class.activity.report.behaviors.php:34
$GLOBALS['__l10n']['%s'] = '%s';
#inc/class.activity.report.behaviors.php:40
$GLOBALS['__l10n']['Actions on blog'] = 'Actions sur le blog';
#inc/class.activity.report.behaviors.php:48
$GLOBALS['__l10n']['updating blog'] = 'Mise à jour du blog';
#inc/class.activity.report.behaviors.php:49
$GLOBALS['__l10n']['Blog was updated by "%s"'] = 'Blog mis à jour par "%s"';
#inc/class.activity.report.behaviors.php:58
$GLOBALS['__l10n']['404 error'] = 'Erreur 404';
#inc/class.activity.report.behaviors.php:59
$GLOBALS['__l10n']['New 404 error page at "%s"'] = 'Nouvelle erreur 404 à l\'adresse "%s"';
#inc/class.activity.report.behaviors.php:65
$GLOBALS['__l10n']['Actions on posts'] = 'Actions sur les billets';
#inc/class.activity.report.behaviors.php:73
#inc/class.activity.report.behaviors.php:84
$GLOBALS['__l10n']['post creation'] = 'Création de billet';
#inc/class.activity.report.behaviors.php:74
#inc/class.activity.report.behaviors.php:85
$GLOBALS['__l10n']['A new post called "%s" was created by "%s" at %s'] = 'Un nouveau billet nommé "%s" a été créé par "%s" à l\'adresse "%s"';
#inc/class.activity.report.behaviors.php:95
$GLOBALS['__l10n']['updating post'] = 'Mise à jour de billet';
#inc/class.activity.report.behaviors.php:96
$GLOBALS['__l10n']['Post called "%s" has been updated by "%s" at %s'] = 'Le billet nommé "%s" a été mis à jour par "%s" à l\'adresse "%s"';
#inc/class.activity.report.behaviors.php:106
$GLOBALS['__l10n']['post deletion'] = 'Suppression de billet';
#inc/class.activity.report.behaviors.php:107
$GLOBALS['__l10n']['Post called "%s" has been deleted by "%s"'] = 'Le billet nommé "%s" a été supprimé par "%s"';
#inc/class.activity.report.behaviors.php:117
$GLOBALS['__l10n']['Post protection'] = 'Protection des billets';
#inc/class.activity.report.behaviors.php:118
$GLOBALS['__l10n']['An attempt failed on a passworded post with password "%s" at "%s"'] = 'Une tentative a échoué sur un billet protégé par mot de passe avec l\'essai "%s" à l\'adresse "%s"';
#inc/class.activity.report.behaviors.php:124
$GLOBALS['__l10n']['Actions on comments'] = 'Actions sur les commentaires';
#inc/class.activity.report.behaviors.php:132
$GLOBALS['__l10n']['comment creation'] = 'Création de commentaire';
#inc/class.activity.report.behaviors.php:133
$GLOBALS['__l10n']['A new comment was created by "%s" on post "%s" at %s'] = 'Un nouveau commentaire a été créé par "%s" sur le billet "%s"';
#inc/class.activity.report.behaviors.php:143
$GLOBALS['__l10n']['updating comment'] = 'Mise à jour de commentaire';
#inc/class.activity.report.behaviors.php:144
$GLOBALS['__l10n']['Comment has been updated by "%s" at %s'] = 'Un commentaire a été mise à jour par "%s" à l\'adresse "%s"';
#inc/class.activity.report.behaviors.php:157
$GLOBALS['__l10n']['trackback creation'] = 'Création de trackback';
#inc/class.activity.report.behaviors.php:158
$GLOBALS['__l10n']['A new trackback to "%" at "%s" was created on post "%s" at %s'] = 'Un nouveau rétrolien vers "%s" a été créé sur le billet "%s" à l\'adresse "%s"';
#inc/class.activity.report.behaviors.php:164
$GLOBALS['__l10n']['Actions on categories'] = 'Actions sur les catégories';
#inc/class.activity.report.behaviors.php:170
$GLOBALS['__l10n']['category creation'] = 'Création de catégorie';
#inc/class.activity.report.behaviors.php:171
$GLOBALS['__l10n']['A new category called "%s" was created by "%s" at %s'] = 'Un nouvelle catégorie nommée "%s" a été créé par "%s" à l\'adresse "%s"';
#inc/class.activity.report.behaviors.php:180
$GLOBALS['__l10n']['updating category'] = 'Mise à jour de catégorie';
#inc/class.activity.report.behaviors.php:181
$GLOBALS['__l10n']['Category called "%s" has been updated by "%s" at %s'] = 'La catégorie nommée "%s" a été mise à jour par "%s" à l\'adresse "%s"';
#inc/class.activity.report.behaviors.php:189
$GLOBALS['__l10n']['Actions on users'] = 'Actions sur les utilisateurs';
#inc/class.activity.report.behaviors.php:195
$GLOBALS['__l10n']['user creation'] = 'Création d\'utilisateur';
#inc/class.activity.report.behaviors.php:196
$GLOBALS['__l10n']['A new user named "%s" was created by "%s"'] = 'Un nouvel utilisateur a été ajouté par "%s"';
#inc/class.activity.report.behaviors.php:205
$GLOBALS['__l10n']['updating user'] = 'Mise à jour d\'utilisateur';
#inc/class.activity.report.behaviors.php:206
$GLOBALS['__l10n']['User named "%s" has been updated by "%s"'] = 'L\'utilisateur "%s" a été mis à jour par "%s"';
#inc/class.activity.report.behaviors.php:215
$GLOBALS['__l10n']['user deletion'] = 'Suppression d\'utilisateur';
#inc/class.activity.report.behaviors.php:216
$GLOBALS['__l10n']['User named "%s" has been deleted by "%"'] = 'L\'utilisateur nommé "%s" a été supprimé par "%s"';
#inc/class.activity.report.php:395
$GLOBALS['__l10n']['An error occured when parsing report.'] = 'Une erreur est survenue lors de la compilation du rapport.';
#inc/class.activity.report.php:411
$GLOBALS['__l10n']['You received a message from your blog\'s activity report module.'] = 'Vous recevez un message du module de rapport d\'activité de votre blog.';
#inc/class.activity.report.php:420
$GLOBALS['__l10n']['Period from %s to %s'] = 'Période du %s au %s';
#inc/class.activity.report.php:466
$GLOBALS['__l10n']['Activity report deletes some old logs.'] = 'L\'extension a automatiquement effacé des anciennes activités.';
#inc/class.activity.report.php:698
$GLOBALS['__l10n']['Activity report module'] = 'Module de rapport d\'activité';
#inc/class.activity.report.php:710
#inc/class.activity.report.php:711
$GLOBALS['__l10n']['Blog activity report'] = 'Rapport d\'activité du blog';
#index.php:46
$GLOBALS['__l10n']['Logs'] = 'Enregistrements';
#index.php:50
$GLOBALS['__l10n']['No log'] = 'Pas d\'enregistrement';
#index.php:56
$GLOBALS['__l10n']['Message'] = 'Message';