Dotclear

source: plugins/antispam/index.php @ 2849:97e1b334e54b

Revision 2849:97e1b334e54b, 7.2 KB checked in by Dsls, 11 years ago (diff)

Deprecated $core->adminurl->decode, use $core->adminurl->get instead (with urlencode set to false)

Added dcPage::getPF to shortcut plugin file inclusion

RevLine 
[0]1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Antispam, a plugin for Dotclear 2.
5#
[1179]6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
[0]7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
12if (!defined('DC_CONTEXT_ADMIN')) { return; }
13dcPage::check('admin');
14
15dcAntispam::initFilters();
16$filters = dcAntispam::$filters->getFilters();
17
18$page_name = __('Antispam');
19$filter_gui = false;
20$default_tab = null;
21
22try
23{
24     # Show filter configuration GUI
25     if (!empty($_GET['f']))
26     {
27          if (!isset($filters[$_GET['f']])) {
28               throw new Exception(__('Filter does not exist.'));
29          }
[223]30
[0]31          if (!$filters[$_GET['f']]->hasGUI()) {
32               throw new Exception(__('Filter has no user interface.'));
33          }
[223]34
[0]35          $filter = $filters[$_GET['f']];
36          $filter_gui = $filter->gui($filter->guiURL());
37     }
[223]38
[0]39     # Remove all spam
[1052]40     if (!empty($_POST['delete_all']))
[0]41     {
42          $ts = dt::str('%Y-%m-%d %H:%M:%S',$_POST['ts'],$core->blog->settings->system->blog_timezone);
[223]43
[0]44          dcAntispam::delAllSpam($core,$ts);
[2256]45
46          dcPage::addSuccessNotice(__('Spam comments have been successfully deleted.'));
47          http::redirect($p_url);
[0]48     }
[223]49
[0]50     # Update filters
51     if (isset($_POST['filters_upd']))
52     {
53          $filters_opt = array();
54          $i = 0;
55          foreach ($filters as $fid => $f) {
56               $filters_opt[$fid] = array(false,$i);
57               $i++;
58          }
[223]59
[0]60          # Enable active filters
61          if (isset($_POST['filters_active']) && is_array($_POST['filters_active'])) {
62               foreach ($_POST['filters_active'] as $v) {
63                    $filters_opt[$v][0] = true;
64               }
65          }
[223]66
[0]67          # Order filters
68          if (!empty($_POST['f_order']) && empty($_POST['filters_order']))
69          {
70               $order = $_POST['f_order'];
71               asort($order);
72               $order = array_keys($order);
73          }
74          elseif (!empty($_POST['filters_order']))
75          {
76               $order = explode(',',trim($_POST['filters_order'],','));
77          }
[223]78
[0]79          if (isset($order)) {
80               foreach ($order as $i => $f) {
81                    $filters_opt[$f][1] = $i;
82               }
83          }
[223]84
[0]85          # Set auto delete flag
86          if (isset($_POST['filters_auto_del']) && is_array($_POST['filters_auto_del'])) {
87               foreach ($_POST['filters_auto_del'] as $v) {
88                    $filters_opt[$v][2] = true;
89               }
90          }
[223]91
[0]92          dcAntispam::$filters->saveFilterOpts($filters_opt);
[2256]93
94          dcPage::addSuccessNotice(__('Filters configuration has been successfully saved.'));
95          http::redirect($p_url);
[0]96     }
97}
98catch (Exception $e)
99{
100     $core->error->add($e->getMessage());
101}
102?>
103<html>
104<head>
[892]105  <title><?php echo ($filter_gui !== false ? sprintf(__('%s configuration'),$filter->name).' - ' : '').$page_name; ?></title>
[1040]106  <script type="text/javascript">
107  //<![CDATA[
108  <?php
109  echo dcPage::jsVar('dotclear.msg.confirm_spam_delete',__('Are you sure you want to delete all spams?'));
110  ?>
111  //]]>
112  </script>
[0]113  <?php
[1130]114  echo dcPage::jsPageTabs($default_tab);
115  $core->auth->user_prefs->addWorkspace('accessibility');
116  if (!$core->auth->user_prefs->accessibility->nodragdrop) {
117     echo
118          dcPage::jsLoad('js/jquery/jquery-ui.custom.js').
[2495]119          dcPage::jsLoad('js/jquery/jquery.ui.touch-punch.js').
[2849]120          dcPage::jsLoad(dcPage::getPF('antispam/antispam.js'));
[1127]121  }
[0]122  ?>
[2849]123  <link rel="stylesheet" type="text/css" href="<?php echo dcPage::getPF('antispam/style.css'); ?>" />
[0]124</head>
125<body>
126<?php
127
128if ($filter_gui !== false)
129{
[1358]130     echo dcPage::breadcrumb(
[1339]131          array(
132               __('Plugins') => '',
133               $page_name => $p_url,
[2166]134               sprintf(__('%s filter configuration'),$filter->name) => ''
[2256]135          )).
136          dcPage::notices();
[223]137
[2823]138     echo '<p><a href="'.$p_url.'" class="back">'.__('Back to filters list').'</a></p>';
[2122]139
[0]140     echo $filter_gui;
[2322]141
142     if ($filter->help) {
143          dcPage::helpBlock($filter->help);
144     }
[0]145}
146else
147{
[1358]148     echo dcPage::breadcrumb(
[1339]149          array(
150               __('Plugins') => '',
[2166]151               $page_name => ''
[2256]152          )).
153          dcPage::notices();
[505]154
[0]155     # Information
156     $spam_count = dcAntispam::countSpam($core);
157     $published_count = dcAntispam::countPublishedComments($core);
158     $moderationTTL = $core->blog->settings->antispam->antispam_moderation_ttl;
[223]159
[0]160     echo
[536]161     '<form action="'.$p_url.'" method="post" class="fieldset">'.
[1941]162     '<h3>'.__('Information').'</h3>';
[223]163
[0]164     echo
165     '<ul class="spaminfo">'.
[2823]166     '<li class="spamcount"><a href="'.$core->adminurl->get('admin.comments',array('status' => '-2')).'">'.__('Junk comments:').'</a> '.
[0]167     '<strong>'.$spam_count.'</strong></li>'.
[2823]168     '<li class="hamcount"><a href="'.$core->adminurl->get('admin.comments',array('status' => '1')).'">'.__('Published comments:').'</a> '.
[0]169     $published_count.'</li>'.
170     '</ul>';
[223]171
[0]172     if ($spam_count > 0)
173     {
174          echo
175          '<p>'.$core->formNonce().
176          form::hidden('ts',time()).
[1052]177          '<input name="delete_all" class="delete" type="submit" value="'.__('Delete all spams').'" /></p>';
[0]178     }
179     if ($moderationTTL != null && $moderationTTL >=0) {
[565]180          echo '<p>'.sprintf(__('All spam comments older than %s day(s) will be automatically deleted.'), $moderationTTL).' '.
[2823]181          sprintf(__('You can modify this duration in the %s'),'<a href="'.$core->adminurl->get('admin.blog.pref').
182               '#antispam_moderation_ttl"> '.__('Blog settings').'</a>').
[1518]183               '.</p>';
[0]184     }
[536]185     echo '</form>';
[223]186
187
[0]188     # Filters
189     echo
[1423]190     '<form action="'.$p_url.'" method="post" id="filters-list-form">';
[223]191
[0]192     if (!empty($_GET['upd'])) {
[1553]193          dcPage::success(__('Filters configuration has been successfully saved.'));
[0]194     }
[223]195
[0]196     echo
[2002]197     '<div class="table-outer">'.
[0]198     '<table class="dragable">'.
[1341]199     '<caption class="as_h3">'.__('Available spam filters').'</caption>'.
[0]200     '<thead><tr>'.
201     '<th>'.__('Order').'</th>'.
202     '<th>'.__('Active').'</th>'.
[223]203     '<th>'.__('Auto Del.').'</th>'.
[0]204     '<th class="nowrap">'.__('Filter name').'</th>'.
205     '<th colspan="2">'.__('Description').'</th>'.
206     '</tr></thead>'.
207     '<tbody id="filters-list" >';
[223]208
[0]209     $i = 0;
210     foreach ($filters as $fid => $f)
211     {
212          $gui_link = '&nbsp;';
213          if ($f->hasGUI()) {
214               $gui_link =
215               '<a href="'.html::escapeHTML($f->guiURL()).'">'.
216               '<img src="images/edit-mini.png" alt="'.__('Filter configuration').'" '.
217               'title="'.__('Filter configuration').'" /></a>';
218          }
[223]219
[0]220          echo
221          '<tr class="line'.($f->active ? '' : ' offline').'" id="f_'.$fid.'">'.
[1130]222          '<td class="handle">'.form::field(array('f_order['.$fid.']'),2,5,(string) $i, 'position', '', false, 'title="'.__('position').'"').'</td>'.
[223]223          '<td class="nowrap">'.form::checkbox(array('filters_active[]'),$fid,$f->active, '', '', false, 'title="'.__('Active').'"').'</td>'.
224          '<td class="nowrap">'.form::checkbox(array('filters_auto_del[]'),$fid,$f->auto_delete, '', '', false, 'title="'.__('Auto Del.').'"').'</td>'.
[1474]225          '<td class="nowrap" scope="row">'.$f->name.'</td>'.
[0]226          '<td class="maximal">'.$f->description.'</td>'.
227          '<td class="status">'.$gui_link.'</td>'.
228          '</tr>';
229          $i++;
230     }
231     echo
[2002]232     '</tbody></table></div>'.
[0]233     '<p>'.form::hidden('filters_order','').
234     $core->formNonce().
235     '<input type="submit" name="filters_upd" value="'.__('Save').'" /></p>'.
[536]236     '</form>';
[223]237
238
[0]239     # Syndication
240     if (DC_ADMIN_URL)
241     {
[776]242          $ham_feed = $core->blog->url.$core->url->getURLFor(
243               'hamfeed',
244               $code = dcAntispam::getUserCode($core)
245          );
246          $spam_feed = $core->blog->url.$core->url->getURLFor(
247               'spamfeed',
248               $code = dcAntispam::getUserCode($core)
249          );
[223]250
[0]251          echo
[536]252          '<h3>'.__('Syndication').'</h3>'.
[0]253          '<ul class="spaminfo">'.
254          '<li class="feed"><a href="'.$spam_feed.'">'.__('Junk comments RSS feed').'</a></li>'.
255          '<li class="feed"><a href="'.$ham_feed.'">'.__('Published comments RSS feed').'</a></li>'.
[536]256          '</ul>';
[0]257     }
[2322]258
259     dcPage::helpBlock('antispam','antispam-filters');
[0]260}
[2322]261
[0]262?>
263
264</body>
[2566]265</html>
Note: See TracBrowser for help on using the repository browser.

Sites map