diff --git a/CHANGELOG.md b/CHANGELOG.md index 66598d9..15fc4bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ -1.1.1 - dev +todo: +- [ ] use sql statment - [ ] 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 - fix Dotclear 2.19 compatibility - fix pages design diff --git a/_admin.php b/_admin.php index 20572e5..5f4dfac 100644 --- a/_admin.php +++ b/_admin.php @@ -1,78 +1,76 @@ addItem( +dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( __('Activity report'), - $core->adminurl->get('admin.plugin.activityReport'), + dcCore::app()->adminurl->get('admin.plugin.activityReport'), dcPage::getPF('activityReport/icon.png'), preg_match( - '/' . preg_quote($core->adminurl->get('admin.plugin.activityReport')) . '(&.*)?$/', + '/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.activityReport')) . '(&.*)?$/', $_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')) { - $core->addBehavior('adminDashboardContents', ['activityReportAdmin', 'adminDashboardContents']); - $core->addBehavior('adminDashboardOptionsForm', ['activityReportAdmin', 'adminDashboardOptionsForm']); - $core->addBehavior('adminAfterDashboardOptionsUpdate', ['activityReportAdmin', 'adminAfterDashboardOptionsUpdate']); +if (dcCore::app()->activityReport->getSetting('active')) { + dcCore::app()->addBehavior('adminDashboardContentsV2', ['activityReportAdmin', 'adminDashboardContents']); + dcCore::app()->addBehavior('adminDashboardOptionsFormV2', ['activityReportAdmin', 'adminDashboardOptionsForm']); + dcCore::app()->addBehavior('adminAfterDashboardOptionsUpdate', ['activityReportAdmin', 'adminAfterDashboardOptionsUpdate']); } class activityReportAdmin { - public static function adminDashboardContents(dcCore $core, $items) + public static function adminDashboardContents($items) { - $core->auth->user_prefs->addWorkspace('activityReport'); - $limit = abs((integer) $core->auth->user_prefs->activityReport->dashboard_item); + dcCore::app()->auth->user_prefs->addWorkspace('activityReport'); + $limit = abs((int) dcCore::app()->auth->user_prefs->activityReport->dashboard_item); if (!$limit) { return null; } $p = [ 'limit' => $limit, 'order' => 'activity_dt DESC', - 'sql' => $core->activityReport->requests2params($core->activityReport->getSetting('requests')) + 'sql' => dcCore::app()->activityReport->requests2params(dcCore::app()->activityReport->getSetting('requests')), ]; $lines = []; - $rs = $core->activityReport->getLogs($p); + $rs = dcCore::app()->activityReport->getLogs($p); if ($rs->isEmpty()) { return null; } - $groups = $core->activityReport->getGroups(); - while($rs->fetch()) { + $groups = dcCore::app()->activityReport->getGroups(); + while ($rs->fetch()) { $group = $rs->activity_group; if (!isset($groups[$group])) { continue; } - $lines[] = - '
' . + $lines[] = '
' . '' . __($groups[$group]['actions'][$rs->activity_action]['title']) . '' . '
' . 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), - $core->auth->getInfo('user_tz') + dcCore::app()->auth->getInfo('user_tz') ) . '
' . '

' . - '' .vsprintf( + '' . vsprintf( __($groups[$group]['actions'][$rs->activity_action]['msg']), - $core->activityReport->decode($rs->activity_logs) + dcCore::app()->activityReport->decode($rs->activity_logs) ) . '

'; } if (empty($lines)) { @@ -82,48 +80,46 @@ class activityReportAdmin '
' . '

' . __('Activity report') . '

' . '
' . implode('', $lines) . '
' . - '

' . - __('View all logs') . ' - ' . + '

' . + __('View all logs') . ' - ' . __('Configure plugin') . '

' . - '
' + '', ]); } - public static function adminDashboardOptionsForm(dcCore $core) + public static function adminDashboardOptionsForm() { - $core->auth->user_prefs->addWorkspace('activityReport'); + dcCore::app()->auth->user_prefs->addWorkspace('activityReport'); echo '
' . '

' . __('Activity report') . '

' . - '

' . form::combo( - 'activityReport_dashboard_item', - self::comboList(), - self::comboList($core->auth->user_prefs->activityReport->dashboard_item) + 'activityReport_dashboard_item', + self::comboList(), + self::comboList(dcCore::app()->auth->user_prefs->activityReport->dashboard_item) ) . '

' . '
'; } public static function adminAfterDashboardOptionsUpdate($user_id = null) { - global $core; - if (is_null($user_id)) { return; } - $core->auth->user_prefs->addWorkspace('activityReport'); - $core->auth->user_prefs->activityReport->put( - 'dashboard_item', - self::comboList(@$_POST['activityReport_dashboard_item']), + dcCore::app()->auth->user_prefs->addWorkspace('activityReport'); + dcCore::app()->auth->user_prefs->activityReport->put( + 'dashboard_item', + self::comboList(@$_POST['activityReport_dashboard_item']), 'integer' ); } @@ -132,16 +128,20 @@ class activityReportAdmin { $l = [ __('Do not show activity report') => 0, - 5 => 5, - 10 => 10, - 15 => 15, - 20 => 20, - 50 => 50, - 100 => 100 + 5 => 5, + 10 => 10, + 15 => 15, + 20 => 20, + 50 => 50, + 100 => 100, ]; if (true === $q) { return $l; } + if (!$q) { + $q = -1; + } + return in_array($q, $l) ? $l[$q] : 0; } -} \ No newline at end of file +} diff --git a/_config.php b/_config.php index 9e99834..9a46def 100644 --- a/_config.php +++ b/_config.php @@ -1,114 +1,112 @@ activityReport; -$super = $core->auth->isSuperAdmin() && !empty($_REQUEST['super']); -$redir = empty($_REQUEST['redir']) ? $list->getURL() . '#plugins' : $_REQUEST['redir']; +$super = dcCore::app()->auth->isSuperAdmin() && !empty($_REQUEST['super']); +$redir = empty($_REQUEST['redir']) ? dcCore::app()->admin->list->getURL() . '#plugins' : $_REQUEST['redir']; if ($super) { - $report->setGlobal(); + dcCore::app()->activityReport->setGlobal(); } $combo_interval = [ - __('every hour') => 3600, - __('every 2 hours') => 7200, + __('every hour') => 3600, + __('every 2 hours') => 7200, __('2 times by day') => 43200, - __('every day') => 86400, - __('every 2 days') => 172800, - __('every week') => 604800 + __('every day') => 86400, + __('every 2 days') => 172800, + __('every week') => 604800, ]; $combo_obselete = [ - __('every hour') => 3600, - __('every 2 hours') => 7200, + __('every hour') => 3600, + __('every 2 hours') => 7200, __('2 times by day') => 43200, - __('every day') => 86400, - __('every 2 days') => 172800, - __('every week') => 604800, - __('every 2 weeks') => 1209600, - __('every 4 weeks') => 2419200 + __('every day') => 86400, + __('every 2 days') => 172800, + __('every week') => 604800, + __('every 2 weeks') => 1209600, + __('every 4 weeks') => 2419200, ]; $combo_format = [ __('Plain text') => 'plain', - __('HTML') => 'html' + __('HTML') => 'html', ]; if (!empty($_POST['save'])) { try { - $report->setSetting('active', !empty($_POST['active'])); + dcCore::app()->activityReport->setSetting('active', !empty($_POST['active'])); 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)) { - $report->setSetting('obsolete',(integer) $_POST['obsolete']); + dcCore::app()->activityReport->setSetting('obsolete', (int) $_POST['obsolete']); } - $report->setSetting('mailinglist', explode(';',$_POST['mailinglist'])); - $report->setSetting('mailformat', isset($_POST['mailformat']) && $_POST['mailformat'] == 'html' ? 'html' : 'plain'); - $report->setSetting('dateformat', html::escapeHTML($_POST['dateformat'])); - $report->setSetting('requests', isset($_POST['requests']) ? $_POST['requests'] : []); - $report->setSetting('blogs', isset($_POST['blogs']) ? $_POST['blogs'] : []); + dcCore::app()->activityReport->setSetting('mailinglist', explode(';', $_POST['mailinglist'])); + dcCore::app()->activityReport->setSetting('mailformat', isset($_POST['mailformat']) && $_POST['mailformat'] == 'html' ? 'html' : 'plain'); + dcCore::app()->activityReport->setSetting('dateformat', html::escapeHTML($_POST['dateformat'])); + dcCore::app()->activityReport->setSetting('requests', $_POST['requests'] ?? []); + dcCore::app()->activityReport->setSetting('blogs', $_POST['blogs'] ?? []); if (!empty($_POST['send_report_now'])) { - $core->activityReport->needReport(true); + dcCore::app()->activityReport->needReport(true); - dcPage::addSuccessNotice( + dcAdminNotices::addSuccessNotice( __('Report successfully sent.') ); } if (!empty($_POST['delete_report_now'])) { - $core->activityReport->deleteLogs(); + dcCore::app()->activityReport->deleteLogs(); - dcPage::addSuccessNotice( + dcAdminNotices::addSuccessNotice( __('Logs successfully deleted.') ); } - dcPage::addSuccessNotice( + dcAdminNotices::addSuccessNotice( __('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) { - $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) { $last_report = __('never'); $next_report = __('on new activity'); } else { $last_report = dt::str( - $core->blog->settings->system->date_format . ', ' . $core->blog->settings->system->time_format, - $last_report_ts, - $core->auth->getInfo('user_tz') + dcCore::app()->blog->settings->system->date_format . ', ' . dcCore::app()->blog->settings->system->time_format, + $last_report_ts, + dcCore::app()->auth->getInfo('user_tz') ); $next_report = dt::str( - $core->blog->settings->system->date_format . ', ' . $core->blog->settings->system->time_format, - (integer) $report->getSetting('interval') + $last_report_ts, - $core->auth->getInfo('user_tz') + dcCore::app()->blog->settings->system->date_format . ', ' . dcCore::app()->blog->settings->system->time_format, + (int) dcCore::app()->activityReport->getSetting('interval') + $last_report_ts, + dcCore::app()->auth->getInfo('user_tz') ); } -$emails = implode(';', $report->getSetting('mailinglist')); +$emails = implode(';', dcCore::app()->activityReport->getSetting('mailinglist')); -if ($core->auth->isSuperAdmin()) { +if (dcCore::app()->auth->isSuperAdmin()) { echo sprintf( - '

%s

' , - $core->adminurl->get('admin.plugins', ['module' => 'activityReport', 'conf' => 1, 'super' => !$super]), + '

%s

', + dcCore::app()->adminurl->get('admin.plugins', ['module' => 'activityReport', 'conf' => 1, 'super' => !$super]), sprintf(__('Configure activity report for %s'), $super ? __('current blog') : _('all blogs')) ); } @@ -123,44 +121,45 @@ echo '

' . -form::combo('obsolete', $combo_obselete, $report->getSetting('obsolete')) . '

+form::combo('obsolete', $combo_obselete, dcCore::app()->activityReport->getSetting('obsolete')) . '

-

+

' . __('Use Dotclear date formaters. ex: %B %d at %H:%M') . '

' . form::hidden(['super'], $super); if (!$super) { - echo - '

'. __('RSS feed') . '' . - '' . + echo + '

' . __('RSS feed') . '' . + '' . __('Rss2 feed for activity on this blog') . '
' . '' . __('Atom feed') . '' . - '' . + '' . __('Atom feed for activity on this blog') . '

'; } echo '
-

' . -form::combo('interval', $combo_interval, $report->getSetting('interval')) . '

+

' . +form::combo('interval', $combo_interval, dcCore::app()->activityReport->getSetting('interval')) . '

-

' . __('Separate multiple email addresses with a semicolon ";"') . '

-

' . -form::combo('mailformat', $combo_format, $report->getSetting('mailformat')) . '

+

' . +form::combo('mailformat', $combo_format, dcCore::app()->activityReport->getSetting('mailformat')) . '