Dotclear

source: plugins/antispam/index.php @ 2322:a75984c93a86

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

Second step of contextual helps, closes #1760, now the help has to be completed.

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('index.php?pf=antispam/antispam.js');
120  }
121  ?>
122  <link rel="stylesheet" type="text/css" href="index.php?pf=antispam/style.css" />
123</head>
124<body>
125<?php
126
127if ($filter_gui !== false)
128{
129     echo dcPage::breadcrumb(
130          array(
131               __('Plugins') => '',
132               $page_name => $p_url,
133               sprintf(__('%s filter configuration'),$filter->name) => ''
134          )).
135          dcPage::notices();
136
137     echo '<p><a href="plugin.php?p=antispam" class="back">'.__('Back to filters list').'</a></p>';
138
139     echo $filter_gui;
140
141     if ($filter->help) {
142          dcPage::helpBlock($filter->help);
143     }
144}
145else
146{
147     echo dcPage::breadcrumb(
148          array(
149               __('Plugins') => '',
150               $page_name => ''
151          )).
152          dcPage::notices();
153
154     # Information
155     $spam_count = dcAntispam::countSpam($core);
156     $published_count = dcAntispam::countPublishedComments($core);
157     $moderationTTL = $core->blog->settings->antispam->antispam_moderation_ttl;
158
159     echo
160     '<form action="'.$p_url.'" method="post" class="fieldset">'.
161     '<h3>'.__('Information').'</h3>';
162
163     echo
164     '<ul class="spaminfo">'.
165     '<li class="spamcount"><a href="comments.php?status=-2">'.__('Junk comments:').'</a> '.
166     '<strong>'.$spam_count.'</strong></li>'.
167     '<li class="hamcount"><a href="comments.php?status=1">'.__('Published comments:').'</a> '.
168     $published_count.'</li>'.
169     '</ul>';
170
171     if ($spam_count > 0)
172     {
173          echo
174          '<p>'.$core->formNonce().
175          form::hidden('ts',time()).
176          '<input name="delete_all" class="delete" type="submit" value="'.__('Delete all spams').'" /></p>';
177     }
178     if ($moderationTTL != null && $moderationTTL >=0) {
179          echo '<p>'.sprintf(__('All spam comments older than %s day(s) will be automatically deleted.'), $moderationTTL).' '.
180          sprintf(__('You can modify this duration in the %s'),'<a href="blog_pref.php#antispam_moderation_ttl"> '.__('Blog settings').'</a>').
181               '.</p>';
182     }
183     echo '</form>';
184
185
186     # Filters
187     echo
188     '<form action="'.$p_url.'" method="post" id="filters-list-form">';
189
190     if (!empty($_GET['upd'])) {
191          dcPage::success(__('Filters configuration has been successfully saved.'));
192     }
193
194     echo
195     '<div class="table-outer">'.
196     '<table class="dragable">'.
197     '<caption class="as_h3">'.__('Available spam filters').'</caption>'.
198     '<thead><tr>'.
199     '<th>'.__('Order').'</th>'.
200     '<th>'.__('Active').'</th>'.
201     '<th>'.__('Auto Del.').'</th>'.
202     '<th class="nowrap">'.__('Filter name').'</th>'.
203     '<th colspan="2">'.__('Description').'</th>'.
204     '</tr></thead>'.
205     '<tbody id="filters-list" >';
206
207     $i = 0;
208     foreach ($filters as $fid => $f)
209     {
210          $gui_link = '&nbsp;';
211          if ($f->hasGUI()) {
212               $gui_link =
213               '<a href="'.html::escapeHTML($f->guiURL()).'">'.
214               '<img src="images/edit-mini.png" alt="'.__('Filter configuration').'" '.
215               'title="'.__('Filter configuration').'" /></a>';
216          }
217
218          echo
219          '<tr class="line'.($f->active ? '' : ' offline').'" id="f_'.$fid.'">'.
220          '<td class="handle">'.form::field(array('f_order['.$fid.']'),2,5,(string) $i, 'position', '', false, 'title="'.__('position').'"').'</td>'.
221          '<td class="nowrap">'.form::checkbox(array('filters_active[]'),$fid,$f->active, '', '', false, 'title="'.__('Active').'"').'</td>'.
222          '<td class="nowrap">'.form::checkbox(array('filters_auto_del[]'),$fid,$f->auto_delete, '', '', false, 'title="'.__('Auto Del.').'"').'</td>'.
223          '<td class="nowrap" scope="row">'.$f->name.'</td>'.
224          '<td class="maximal">'.$f->description.'</td>'.
225          '<td class="status">'.$gui_link.'</td>'.
226          '</tr>';
227          $i++;
228     }
229     echo
230     '</tbody></table></div>'.
231     '<p>'.form::hidden('filters_order','').
232     $core->formNonce().
233     '<input type="submit" name="filters_upd" value="'.__('Save').'" /></p>'.
234     '</form>';
235
236
237     # Syndication
238     if (DC_ADMIN_URL)
239     {
240          $ham_feed = $core->blog->url.$core->url->getURLFor(
241               'hamfeed',
242               $code = dcAntispam::getUserCode($core)
243          );
244          $spam_feed = $core->blog->url.$core->url->getURLFor(
245               'spamfeed',
246               $code = dcAntispam::getUserCode($core)
247          );
248
249          echo
250          '<h3>'.__('Syndication').'</h3>'.
251          '<ul class="spaminfo">'.
252          '<li class="feed"><a href="'.$spam_feed.'">'.__('Junk comments RSS feed').'</a></li>'.
253          '<li class="feed"><a href="'.$ham_feed.'">'.__('Published comments RSS feed').'</a></li>'.
254          '</ul>';
255     }
256
257     dcPage::helpBlock('antispam','antispam-filters');
258}
259
260?>
261
262</body>
263</html>
Note: See TracBrowser for help on using the repository browser.

Sites map