Dotclear

source: plugins/antispam/index.php @ 2567:6c11245cbf04

Revision 2567:6c11245cbf04, 7.0 KB checked in by franck <carnet.franck.paul@…>, 12 years ago (diff)

Merge from 2.6

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Antispam, a plugin for Dotclear 2.
5#
6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
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          }
30
31          if (!$filters[$_GET['f']]->hasGUI()) {
32               throw new Exception(__('Filter has no user interface.'));
33          }
34
35          $filter = $filters[$_GET['f']];
36          $filter_gui = $filter->gui($filter->guiURL());
37     }
38
39     # Remove all spam
40     if (!empty($_POST['delete_all']))
41     {
42          $ts = dt::str('%Y-%m-%d %H:%M:%S',$_POST['ts'],$core->blog->settings->system->blog_timezone);
43
44          dcAntispam::delAllSpam($core,$ts);
45
46          dcPage::addSuccessNotice(__('Spam comments have been successfully deleted.'));
47          http::redirect($p_url);
48     }
49
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          }
59
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          }
66
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          }
78
79          if (isset($order)) {
80               foreach ($order as $i => $f) {
81                    $filters_opt[$f][1] = $i;
82               }
83          }
84
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          }
91
92          dcAntispam::$filters->saveFilterOpts($filters_opt);
93
94          dcPage::addSuccessNotice(__('Filters configuration has been successfully saved.'));
95          http::redirect($p_url);
96     }
97}
98catch (Exception $e)
99{
100     $core->error->add($e->getMessage());
101}
102?>
103<html>
104<head>
105  <title><?php echo ($filter_gui !== false ? sprintf(__('%s configuration'),$filter->name).' - ' : '').$page_name; ?></title>
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>
113  <?php
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').
119          dcPage::jsLoad('js/jquery/jquery.ui.touch-punch.js').
120          dcPage::jsLoad('index.php?pf=antispam/antispam.js');
121  }
122  ?>
123  <link rel="stylesheet" type="text/css" href="index.php?pf=antispam/style.css" />
124</head>
125<body>
126<?php
127
128if ($filter_gui !== false)
129{
130     echo dcPage::breadcrumb(
131          array(
132               __('Plugins') => '',
133               $page_name => $p_url,
134               sprintf(__('%s filter configuration'),$filter->name) => ''
135          )).
136          dcPage::notices();
137
138     echo '<p><a href="plugin.php?p=antispam" class="back">'.__('Back to filters list').'</a></p>';
139
140     echo $filter_gui;
141
142     if ($filter->help) {
143          dcPage::helpBlock($filter->help);
144     }
145}
146else
147{
148     echo dcPage::breadcrumb(
149          array(
150               __('Plugins') => '',
151               $page_name => ''
152          )).
153          dcPage::notices();
154
155     # Information
156     $spam_count = dcAntispam::countSpam($core);
157     $published_count = dcAntispam::countPublishedComments($core);
158     $moderationTTL = $core->blog->settings->antispam->antispam_moderation_ttl;
159
160     echo
161     '<form action="'.$p_url.'" method="post" class="fieldset">'.
162     '<h3>'.__('Information').'</h3>';
163
164     echo
165     '<ul class="spaminfo">'.
166     '<li class="spamcount"><a href="comments.php?status=-2">'.__('Junk comments:').'</a> '.
167     '<strong>'.$spam_count.'</strong></li>'.
168     '<li class="hamcount"><a href="comments.php?status=1">'.__('Published comments:').'</a> '.
169     $published_count.'</li>'.
170     '</ul>';
171
172     if ($spam_count > 0)
173     {
174          echo
175          '<p>'.$core->formNonce().
176          form::hidden('ts',time()).
177          '<input name="delete_all" class="delete" type="submit" value="'.__('Delete all spams').'" /></p>';
178     }
179     if ($moderationTTL != null && $moderationTTL >=0) {
180          echo '<p>'.sprintf(__('All spam comments older than %s day(s) will be automatically deleted.'), $moderationTTL).' '.
181          sprintf(__('You can modify this duration in the %s'),'<a href="blog_pref.php#antispam_moderation_ttl"> '.__('Blog settings').'</a>').
182               '.</p>';
183     }
184     echo '</form>';
185
186
187     # Filters
188     echo
189     '<form action="'.$p_url.'" method="post" id="filters-list-form">';
190
191     if (!empty($_GET['upd'])) {
192          dcPage::success(__('Filters configuration has been successfully saved.'));
193     }
194
195     echo
196     '<div class="table-outer">'.
197     '<table class="dragable">'.
198     '<caption class="as_h3">'.__('Available spam filters').'</caption>'.
199     '<thead><tr>'.
200     '<th>'.__('Order').'</th>'.
201     '<th>'.__('Active').'</th>'.
202     '<th>'.__('Auto Del.').'</th>'.
203     '<th class="nowrap">'.__('Filter name').'</th>'.
204     '<th colspan="2">'.__('Description').'</th>'.
205     '</tr></thead>'.
206     '<tbody id="filters-list" >';
207
208     $i = 0;
209     foreach ($filters as $fid => $f)
210     {
211          $gui_link = '&nbsp;';
212          if ($f->hasGUI()) {
213               $gui_link =
214               '<a href="'.html::escapeHTML($f->guiURL()).'">'.
215               '<img src="images/edit-mini.png" alt="'.__('Filter configuration').'" '.
216               'title="'.__('Filter configuration').'" /></a>';
217          }
218
219          echo
220          '<tr class="line'.($f->active ? '' : ' offline').'" id="f_'.$fid.'">'.
221          '<td class="handle">'.form::field(array('f_order['.$fid.']'),2,5,(string) $i, 'position', '', false, 'title="'.__('position').'"').'</td>'.
222          '<td class="nowrap">'.form::checkbox(array('filters_active[]'),$fid,$f->active, '', '', false, 'title="'.__('Active').'"').'</td>'.
223          '<td class="nowrap">'.form::checkbox(array('filters_auto_del[]'),$fid,$f->auto_delete, '', '', false, 'title="'.__('Auto Del.').'"').'</td>'.
224          '<td class="nowrap" scope="row">'.$f->name.'</td>'.
225          '<td class="maximal">'.$f->description.'</td>'.
226          '<td class="status">'.$gui_link.'</td>'.
227          '</tr>';
228          $i++;
229     }
230     echo
231     '</tbody></table></div>'.
232     '<p>'.form::hidden('filters_order','').
233     $core->formNonce().
234     '<input type="submit" name="filters_upd" value="'.__('Save').'" /></p>'.
235     '</form>';
236
237
238     # Syndication
239     if (DC_ADMIN_URL)
240     {
241          $ham_feed = $core->blog->url.$core->url->getURLFor(
242               'hamfeed',
243               $code = dcAntispam::getUserCode($core)
244          );
245          $spam_feed = $core->blog->url.$core->url->getURLFor(
246               'spamfeed',
247               $code = dcAntispam::getUserCode($core)
248          );
249
250          echo
251          '<h3>'.__('Syndication').'</h3>'.
252          '<ul class="spaminfo">'.
253          '<li class="feed"><a href="'.$spam_feed.'">'.__('Junk comments RSS feed').'</a></li>'.
254          '<li class="feed"><a href="'.$ham_feed.'">'.__('Published comments RSS feed').'</a></li>'.
255          '</ul>';
256     }
257
258     dcPage::helpBlock('antispam','antispam-filters');
259}
260
261?>
262
263</body>
264</html>
Note: See TracBrowser for help on using the repository browser.

Sites map