move settings to plugins config page
This commit is contained in:
parent
438e57e702
commit
7e6f246756
2 changed files with 196 additions and 280 deletions
201
_config.php
201
_config.php
|
@ -15,13 +15,204 @@ if (!defined('DC_CONTEXT_MODULE')) {
|
|||
return null;
|
||||
}
|
||||
|
||||
if (!activityReport::hasMailer()) {
|
||||
$report =& $core->activityReport;
|
||||
$super = $core->auth->isSuperAdmin() && !empty($_REQUEST['super']);
|
||||
$redir = empty($_REQUEST['redir']) ? $list->getURL() . '#plugins' : $_REQUEST['redir'];
|
||||
|
||||
echo '<p class="error">' . __('This server has no mail function, activityReport not send email report.') . '</p>';
|
||||
$combo_interval = [
|
||||
__('every hour') => 3600,
|
||||
__('every 2 hours') => 7200,
|
||||
__('2 times by day') => 43200,
|
||||
__('every day') => 86400,
|
||||
__('every 2 days') => 172800,
|
||||
__('every week') => 604800
|
||||
];
|
||||
|
||||
$combo_obselete = [
|
||||
__('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
|
||||
];
|
||||
|
||||
$combo_format = [
|
||||
__('Plain text') => 'plain',
|
||||
__('HTML') => 'html'
|
||||
];
|
||||
|
||||
if (!empty($_POST['save'])) {
|
||||
try {
|
||||
$report->setSetting('active', !empty($_POST['active']));
|
||||
$report->setSetting('dashboardItem', !empty($_POST['dashboardItem']));
|
||||
if (in_array($_POST['interval'], $combo_interval)) {
|
||||
$report->setSetting('interval', (integer) $_POST['interval']);
|
||||
}
|
||||
if (in_array($_POST['obsolete'], $combo_obselete)) {
|
||||
$report->setSetting('obsolete',(integer) $_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'] : []);
|
||||
|
||||
if (!empty($_POST['force_report'])) {
|
||||
$core->activityReport->needReport(true);
|
||||
}
|
||||
if (!empty($_POST['force_delete'])) {
|
||||
$core->activityReport->deleteLogs();
|
||||
}
|
||||
|
||||
dcPage::addSuccessNotice(
|
||||
__('Configuration has been successfully updated.')
|
||||
);
|
||||
$core->adminurl->redirect('admin.plugins', ['module' => 'activityReport', 'conf' => 1, 'super' => $super]);
|
||||
} catch (Exception $e) {
|
||||
$core->error->add($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
activityReportLib::settingTab($core, __('Settings'));
|
||||
$last_report_ts = $report->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')
|
||||
);
|
||||
$next_report = dt::str(
|
||||
$core->blog->settings->system->date_format . ', ' . $core->blog->settings->system->time_format,
|
||||
(integer) $report->getSetting('interval') + $next_report_ts,
|
||||
$core->auth->getInfo('user_tz')
|
||||
);
|
||||
}
|
||||
$emails = implode(';', $report->getSetting('mailinglist'));
|
||||
|
||||
if ($core->auth->isSuperAdmin()) {
|
||||
activityReportLib::settingTab($core, __('Super settings'), true);
|
||||
}
|
||||
echo sprintf(
|
||||
'<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]),
|
||||
sprintf(__('Configure activity report for %s'), $super ? __('current blog') : _('all blogs'))
|
||||
);
|
||||
}
|
||||
if (activityReport::hasMailer()) {
|
||||
echo '<p class="message">' .
|
||||
__('This server has no mail function, activityReport does not send email report.') .
|
||||
'</p>';
|
||||
}
|
||||
|
||||
echo '
|
||||
<div class="fieldset two-cols" id="settings"><h4>' . __('Settings') . '</h4>
|
||||
<div class="col">
|
||||
<p><label class="classic" for="active">' .
|
||||
form::checkbox('active', '1', $report->getSetting('active')).' '.
|
||||
($super ?
|
||||
__('Enable super administrator report') :
|
||||
__('Enable report on this blog')
|
||||
) . '</label></p>';
|
||||
|
||||
if (!$super) {
|
||||
echo
|
||||
'<p><label class="classic" for="dashboardItem">' .
|
||||
form::checkbox('dashboardItem', 1, $report->getSetting('dashboardItem')).' '.
|
||||
__('Add activity report on dashboard items') . '</label></p>';
|
||||
}
|
||||
echo '
|
||||
<p><label for="obselete">' . __('Automatic cleaning of old logs:') . '</label>' .
|
||||
form::combo('obsolete', $combo_obselete, $report->getSetting('obsolete')) . '</p>
|
||||
|
||||
<p><label for="dateformat">' . __('Date format:') . '<br />'.
|
||||
form::field('dateformat', 60, 255, $report->getSetting('dateformat')) . '</label></p>
|
||||
<p class="form-note">' . __('Use Dotclear date formaters. ex: %B %d at %H:%M') . '</p>' .
|
||||
|
||||
form::hidden(['super'], $super);
|
||||
|
||||
if (!$super) {
|
||||
echo
|
||||
'<p><img alt="'. __('RSS feed') . '" src="' . dcPage::getPF('activityReport/inc/img/feed.png') . '" />' .
|
||||
'<a title="' . __('RSS feed') . '" href="' .
|
||||
$core->blog->url . $core->url->getBase('activityReport') . '/rss2/' . $report->getUserCode() . '">' .
|
||||
__('Rss2 feed for activity on this blog') . '</a><br />' .
|
||||
'<img alt="' . __('Atom feed') . '" src="' . dcPage::getPF('activityReport/inc/img/feed.png') . '" />' .
|
||||
'<a title="' . __('Atom feed') . '" href="' .
|
||||
$core->blog->url . $core->url->getBase('activityReport') . '/atom/' . $report->getUserCode() . '">' .
|
||||
__('Atom feed for activity on this blog') . '</a></p>';
|
||||
}
|
||||
echo '
|
||||
</div><div class="col">
|
||||
|
||||
<p><label for="interval">' . __('Send report:').'</label>' .
|
||||
form::combo('interval', $combo_interval, $report->getSetting('interval')) . '</p>
|
||||
|
||||
<p><label for="mailinglist">' . __('Recipients:') . '<br />'.
|
||||
form::field('mailinglist', 60, 255, $emails) . '</label></p>
|
||||
<p class="form-note">' . __('Separate multiple email addresses with a semicolon ";"') . '</p>
|
||||
|
||||
<p><label for="mailformat">' . __('Report format:') . '</label>' .
|
||||
form::combo('mailformat', $combo_format, $report->getSetting('mailformat')) . '</p>
|
||||
|
||||
<ul>
|
||||
<li>' . __('Last report by email:') . ' ' . $last_report . '</li>
|
||||
<li>' . __('Next report by email:') . ' ' . $next_report . '</li>
|
||||
</ul>
|
||||
</div><br class="clear"/>
|
||||
</div><br class="clear"/>';
|
||||
|
||||
if ($super) {
|
||||
echo '
|
||||
<div class="fieldset one-box" id="setting_blog"><h4>' . __('Blogs') . '</h4>
|
||||
<p>' . __('Select blogs to add to report') . '</p>';
|
||||
|
||||
$i = $j = 0;
|
||||
$selected_blogs = $report->getSetting('blogs');
|
||||
$blogs = $core->getBlogs();
|
||||
$num_blogs = $blogs->count();
|
||||
while($blogs->fetch()) {
|
||||
$blog_id = $core->con->escape($blogs->blog_id);
|
||||
|
||||
echo '
|
||||
<div class="fieldset box">
|
||||
<p><label class="classic" for="blogs_' . $i . '_">' .
|
||||
form::checkbox(
|
||||
['blogs['.$i.']', 'blogs_' . $i . '_'],
|
||||
$blog_id,
|
||||
in_array($blog_id,$selected_blogs)
|
||||
) . ' ' .
|
||||
$blogs->blog_name . ' (' . $blog_id . ')</label></p>
|
||||
</div>';
|
||||
|
||||
$i++;
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
echo '
|
||||
<div class="fieldset one-box" id="setting_report"><h4>' . __('Report') . '</h4>
|
||||
<p>' . __('Select actions by activity type to add to report') . '</p>';
|
||||
|
||||
$groups = $report->getGroups();
|
||||
$blog_request = $report->getSetting('requests');
|
||||
|
||||
$i = 0;
|
||||
foreach($groups as $group_id => $group) {
|
||||
echo '<div class="fieldset box"><h5>'. __($group['title']) . '</h5>';
|
||||
|
||||
foreach($group['actions'] as $action_id => $action) {
|
||||
echo '
|
||||
<p><label class="classic" for="requests_' . $group_id . '_' . $action_id . '_">' .
|
||||
form::checkbox(
|
||||
['requests[' . $group_id . '][' . $action_id . ']', 'requests_' . $group_id . '_' . $action_id . '_'],
|
||||
1,
|
||||
isset($blog_request[$group_id][$action_id])
|
||||
) . ' ' . __($action['title']) . '</label></p>';
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
echo '</div>';
|
||||
|
||||
$report->unsetGlobal();
|
|
@ -15,281 +15,6 @@ if (!defined('DC_CONTEXT_ADMIN')){return;}
|
|||
|
||||
class activityReportLib
|
||||
{
|
||||
public static function settingTab($core,$title,$global=false)
|
||||
{
|
||||
$O =& $core->activityReport;
|
||||
$section = isset($_REQUEST['section']) ? $_REQUEST['section'] : '';
|
||||
|
||||
if ($global)
|
||||
{
|
||||
$O->setGlobal();
|
||||
$t = 'super';
|
||||
}
|
||||
else
|
||||
{
|
||||
$t = 'blog';
|
||||
}
|
||||
|
||||
$combo_int = array(
|
||||
__('every hour') => 3600,
|
||||
__('every 2 hours') => 7200,
|
||||
__('2 times by day') => 43200,
|
||||
__('every day') => 86400,
|
||||
__('every 2 days') => 172800,
|
||||
__('every week') => 604800
|
||||
);
|
||||
|
||||
$combo_obs = array(
|
||||
__('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
|
||||
);
|
||||
|
||||
$combo_format = array(
|
||||
__('Plain text') => 'plain',
|
||||
__('HTML') => 'html'
|
||||
);
|
||||
|
||||
$redirect = false;
|
||||
if (!empty($_POST[$t.'_settings']))
|
||||
{
|
||||
# Active notification on this blog
|
||||
$O->setSetting('active',isset($_POST['active']));
|
||||
# Add dashboard items
|
||||
$O->setSetting('dashboardItem',isset($_POST['dashboardItem']));
|
||||
# Report interval
|
||||
if (in_array($_POST['interval'],$combo_int))
|
||||
{
|
||||
$O->setSetting('interval',(integer) $_POST['interval']);
|
||||
}
|
||||
# check obsolete logs interval
|
||||
if (in_array($_POST['obsolete'],$combo_obs))
|
||||
{
|
||||
$O->setSetting('obsolete',(integer) $_POST['obsolete']);
|
||||
}
|
||||
# mail list
|
||||
$O->setSetting('mailinglist',explode(';',$_POST['mailinglist']));
|
||||
# mail format
|
||||
$mailformat = isset($_POST['mailformat']) && $_POST['mailformat'] == 'html' ? 'html' : 'plain';
|
||||
$O->setSetting('mailformat',$mailformat);
|
||||
# date format
|
||||
$O->setSetting('dateformat',html::escapeHTML($_POST['dateformat']));
|
||||
# request infos
|
||||
$requests = isset($_POST['requests']) ? $_POST['requests'] : array();
|
||||
$O->setSetting('requests',$requests);
|
||||
#blogs
|
||||
$blogs = isset($_POST['blogs']) ? $_POST['blogs'] : array();
|
||||
$O->setSetting('blogs',$blogs);
|
||||
|
||||
$redirect = true;
|
||||
}
|
||||
|
||||
# force to send report now
|
||||
if (!empty($_POST[$t.'_force_report']))
|
||||
{
|
||||
$core->activityReport->needReport(true);
|
||||
$redirect = true;
|
||||
}
|
||||
|
||||
# force to delete all logs now
|
||||
if (!empty($_POST[$t.'_force_delete']))
|
||||
{
|
||||
$core->activityReport->deleteLogs();
|
||||
$redirect = true;
|
||||
}
|
||||
|
||||
if ($redirect)
|
||||
{
|
||||
http::redirect('plugin.php?p=activityReport&tab='.$t.'_settings&section'.$section);
|
||||
}
|
||||
|
||||
$bl = $O->getSetting('lastreport');
|
||||
$blog_last = !$bl ? __('never') : dt::str($core->blog->settings->system->date_format.', '.$core->blog->settings->system->time_format,$bl,$core->auth->getInfo('user_tz'));
|
||||
|
||||
$bi = $O->getSetting('interval');
|
||||
$blog_next = !$bl ? __('on new activity') : dt::str($core->blog->settings->system->date_format.', '.$core->blog->settings->system->time_format,$bl+$bi,$core->auth->getInfo('user_tz'));
|
||||
|
||||
$emails = implode(';',$O->getSetting('mailinglist'));
|
||||
|
||||
?>
|
||||
<div class="multi-part" id="<?php echo $t; ?>_settings" title="<?php echo $title; ?>">
|
||||
|
||||
<?php if (!$global) { ?>
|
||||
|
||||
<p><img alt="<?php echo __('RSS feed'); ?>" src="index.php?pf=activityReport/inc/img/feed.png" />
|
||||
<a title="<?php echo __('RSS feed'); ?>" href="<?php echo $core->blog->url.$core->url->getBase('activityReport').'/rss2/'.$O->getUserCode(); ?>">
|
||||
<?php echo __('Rss2 feed for activity on this blog'); ?></a>
|
||||
<br />
|
||||
<img alt="<?php echo __('Atom feed'); ?>" src="index.php?pf=activityReport/inc/img/feed.png" />
|
||||
<a title="<?php echo __('Atom feed'); ?>" href="<?php echo $core->blog->url.$core->url->getBase('activityReport').'/atom/'.$O->getUserCode(); ?>">
|
||||
<?php echo __('Atom feed for activity on this blog'); ?></a></p>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
<form id="setting-<?php echo $t; ?>-form" method="post" action="plugin.php">
|
||||
|
||||
<fieldset id="setting-<?php echo $t; ?>-setting"><legend><?php echo __('Settings'); ?></legend>
|
||||
|
||||
<p><label class="classic"><?php echo
|
||||
form::checkbox(array('active'),'1',
|
||||
$O->getSetting('active')).' '.
|
||||
($global ?
|
||||
__('Enable super administrator report') :
|
||||
__('Enable report on this blog')
|
||||
); ?>
|
||||
</label></p>
|
||||
<p><label class="classic"><?php echo __('Automatic cleaning of old logs:').'<br />'.
|
||||
form::combo(array('obsolete'),$combo_obs,$O->getSetting('obsolete')); ?>
|
||||
</label></p>
|
||||
<?php
|
||||
|
||||
if (!$global)
|
||||
{
|
||||
|
||||
?>
|
||||
<p><label class="classic"><?php echo
|
||||
form::checkbox(array('dashboardItem'),'1',
|
||||
$O->getSetting('dashboardItem')).' '.
|
||||
__('Add activity report on dashboard items'); ?>
|
||||
</label></p>
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
<p><label class="classic"><?php echo __('Send report:').'<br />'.
|
||||
form::combo(array('interval'),$combo_int,$O->getSetting('interval')); ?>
|
||||
</label></p>
|
||||
|
||||
<p><label class="classic"><?php echo __('Date format:').'<br />'.
|
||||
form::field(array('dateformat'),60,255,$O->getSetting('dateformat')); ?>
|
||||
</label></p>
|
||||
<p class="form-note"><?php echo __('Use Dotclear date formaters. ex: %B %d at %H:%M'); ?></p>
|
||||
|
||||
<p><label class="classic"><?php echo __('Report format:').'<br />'.
|
||||
form::combo(array('mailformat'),$combo_format,$O->getSetting('mailformat')); ?>
|
||||
</label></p>
|
||||
|
||||
<p><label class="classic"><?php echo __('Recipients:').'<br />'.
|
||||
form::field(array('mailinglist'),60,255,$emails); ?>
|
||||
</label></p>
|
||||
<p class="form-note"><?php echo __('Separate multiple email addresses with a semicolon ";"'); ?></p>
|
||||
|
||||
<ul>
|
||||
<li><?php echo __('Last report by email:').' '.$blog_last; ?></li>
|
||||
<li><?php echo __('Next report by email:').' '.$blog_next; ?></li>
|
||||
</ul>
|
||||
|
||||
</fieldset>
|
||||
<?php
|
||||
|
||||
if ($global)
|
||||
{
|
||||
?>
|
||||
<fieldset id="setting-<?php echo $t; ?>-blog"><legend><?php echo __('Blogs'); ?></legend>
|
||||
<div class="three-cols">
|
||||
<?php
|
||||
|
||||
$i = 0;
|
||||
$selected_blogs = $O->getSetting('blogs');
|
||||
$blogs = $core->getBlogs();
|
||||
while($blogs->fetch())
|
||||
{
|
||||
$blog_id = $core->con->escape($blogs->blog_id);
|
||||
?>
|
||||
<div class="col">
|
||||
<p><label class="classic"><?php echo
|
||||
form::checkbox(array('blogs['.$i.']'),$blog_id,
|
||||
in_array($blog_id,$selected_blogs)).' '.
|
||||
$blogs->blog_name.' ('.$blog_id.')'; ?>
|
||||
</label></p>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
?>
|
||||
</div>
|
||||
</fieldset>
|
||||
<?php
|
||||
}
|
||||
|
||||
?>
|
||||
<fieldset id="setting-<?php echo $t; ?>-report"><legend><?php echo __('Report'); ?></legend>
|
||||
<div class="three-cols">
|
||||
<?php
|
||||
|
||||
$groups = $O->getGroups();
|
||||
$blog_request = $O->getSetting('requests');
|
||||
|
||||
$i = 0;
|
||||
foreach($groups as $k_group => $v_group)
|
||||
{
|
||||
|
||||
?>
|
||||
<div class="col">
|
||||
<h3><?php echo __($v_group['title']); ?></h3>
|
||||
<?php
|
||||
|
||||
foreach($v_group['actions'] as $k_action => $v_action)
|
||||
{
|
||||
?>
|
||||
<p><label class="classic"><?php echo
|
||||
form::checkbox(array('requests['.$k_group.']['.$k_action.']'),'1',
|
||||
isset($blog_request[$k_group][$k_action])).' '.__($v_action['title']); ?>
|
||||
</label></p>
|
||||
<?php
|
||||
}
|
||||
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
$i++;
|
||||
if ($i == 3) {
|
||||
?></div><div class="three-cols"><?php
|
||||
$i = 0;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<p>
|
||||
<input type="submit" name="<?php echo $t; ?>_settings" value="<?php echo __('Save'); ?>" />
|
||||
<?php
|
||||
if (!empty($emails))
|
||||
{
|
||||
?>
|
||||
<input type="submit" name="<?php echo $t; ?>_force_report" value="<?php echo __('Send report by email now'); ?>" />
|
||||
<?php
|
||||
}
|
||||
if ($global)
|
||||
{
|
||||
?>
|
||||
<input type="submit" name="<?php echo $t; ?>_force_delete" value="<?php echo __('Delete all logs'); ?>" />
|
||||
<?php
|
||||
}
|
||||
echo
|
||||
form::hidden(array('p'),'activityReport').
|
||||
form::hidden(array('tab'),$t.'_settings').
|
||||
form::hidden(array('section'),$section).
|
||||
$core->formNonce();
|
||||
?>
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
$O->unsetGlobal();
|
||||
}
|
||||
|
||||
public static function logTab($core,$title,$global=false)
|
||||
{
|
||||
$O =& $core->activityReport;
|
||||
|
|
Loading…
Reference in a new issue