Dotclear

source: plugins/antispam/index.php @ 2166:6f409aa25386

Revision 2166:6f409aa25386, 6.8 KB checked in by Dsls, 12 years ago (diff)

revamped dcPage::breadcrumb, closes #1559

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          http::redirect($p_url.'&del=1');
46     }
47
48     # Update filters
49     if (isset($_POST['filters_upd']))
50     {
51          $filters_opt = array();
52          $i = 0;
53          foreach ($filters as $fid => $f) {
54               $filters_opt[$fid] = array(false,$i);
55               $i++;
56          }
57
58          # Enable active filters
59          if (isset($_POST['filters_active']) && is_array($_POST['filters_active'])) {
60               foreach ($_POST['filters_active'] as $v) {
61                    $filters_opt[$v][0] = true;
62               }
63          }
64
65          # Order filters
66          if (!empty($_POST['f_order']) && empty($_POST['filters_order']))
67          {
68               $order = $_POST['f_order'];
69               asort($order);
70               $order = array_keys($order);
71          }
72          elseif (!empty($_POST['filters_order']))
73          {
74               $order = explode(',',trim($_POST['filters_order'],','));
75          }
76
77          if (isset($order)) {
78               foreach ($order as $i => $f) {
79                    $filters_opt[$f][1] = $i;
80               }
81          }
82
83          # Set auto delete flag
84          if (isset($_POST['filters_auto_del']) && is_array($_POST['filters_auto_del'])) {
85               foreach ($_POST['filters_auto_del'] as $v) {
86                    $filters_opt[$v][2] = true;
87               }
88          }
89
90          dcAntispam::$filters->saveFilterOpts($filters_opt);
91          http::redirect($p_url.'&upd=1');
92     }
93}
94catch (Exception $e)
95{
96     $core->error->add($e->getMessage());
97}
98?>
99<html>
100<head>
101  <title><?php echo ($filter_gui !== false ? sprintf(__('%s configuration'),$filter->name).' - ' : '').$page_name; ?></title>
102  <script type="text/javascript">
103  //<![CDATA[
104  <?php
105  echo dcPage::jsVar('dotclear.msg.confirm_spam_delete',__('Are you sure you want to delete all spams?'));
106  ?>
107  //]]>
108  </script>
109  <?php
110  echo dcPage::jsPageTabs($default_tab);
111  $core->auth->user_prefs->addWorkspace('accessibility');
112  if (!$core->auth->user_prefs->accessibility->nodragdrop) {
113     echo
114          dcPage::jsLoad('js/jquery/jquery-ui.custom.js').
115          dcPage::jsLoad('index.php?pf=antispam/antispam.js');
116  }
117  ?>
118  <link rel="stylesheet" type="text/css" href="index.php?pf=antispam/style.css" />
119</head>
120<body>
121<?php
122
123if ($filter_gui !== false)
124{
125     echo dcPage::breadcrumb(
126          array(
127               __('Plugins') => '',
128               $page_name => $p_url,
129               sprintf(__('%s filter configuration'),$filter->name) => ''
130          ));
131
132     echo '<p><a href="plugin.php?p=antispam" class="back">'.__('Back to filters list').'</a></p>';
133
134     echo $filter_gui;
135}
136else
137{
138     echo dcPage::breadcrumb(
139          array(
140               __('Plugins') => '',
141               $page_name => ''
142          ));
143
144     # Information
145     $spam_count = dcAntispam::countSpam($core);
146     $published_count = dcAntispam::countPublishedComments($core);
147     $moderationTTL = $core->blog->settings->antispam->antispam_moderation_ttl;
148
149     echo
150     '<form action="'.$p_url.'" method="post" class="fieldset">'.
151     '<h3>'.__('Information').'</h3>';
152
153     if (!empty($_GET['del'])) {
154          dcPage::success(__('Spam comments have been successfully deleted.'));
155     }
156
157     echo
158     '<ul class="spaminfo">'.
159     '<li class="spamcount"><a href="comments.php?status=-2">'.__('Junk comments:').'</a> '.
160     '<strong>'.$spam_count.'</strong></li>'.
161     '<li class="hamcount"><a href="comments.php?status=1">'.__('Published comments:').'</a> '.
162     $published_count.'</li>'.
163     '</ul>';
164
165     if ($spam_count > 0)
166     {
167          echo
168          '<p>'.$core->formNonce().
169          form::hidden('ts',time()).
170          '<input name="delete_all" class="delete" type="submit" value="'.__('Delete all spams').'" /></p>';
171     }
172     if ($moderationTTL != null && $moderationTTL >=0) {
173          echo '<p>'.sprintf(__('All spam comments older than %s day(s) will be automatically deleted.'), $moderationTTL).' '.
174          sprintf(__('You can modify this duration in the %s'),'<a href="blog_pref.php#antispam_moderation_ttl"> '.__('Blog settings').'</a>').
175               '.</p>';
176     }
177     echo '</form>';
178
179
180     # Filters
181     echo
182     '<form action="'.$p_url.'" method="post" id="filters-list-form">';
183
184     if (!empty($_GET['upd'])) {
185          dcPage::success(__('Filters configuration has been successfully saved.'));
186     }
187
188     echo
189     '<div class="table-outer">'.
190     '<table class="dragable">'.
191     '<caption class="as_h3">'.__('Available spam filters').'</caption>'.
192     '<thead><tr>'.
193     '<th>'.__('Order').'</th>'.
194     '<th>'.__('Active').'</th>'.
195     '<th>'.__('Auto Del.').'</th>'.
196     '<th class="nowrap">'.__('Filter name').'</th>'.
197     '<th colspan="2">'.__('Description').'</th>'.
198     '</tr></thead>'.
199     '<tbody id="filters-list" >';
200
201     $i = 0;
202     foreach ($filters as $fid => $f)
203     {
204          $gui_link = '&nbsp;';
205          if ($f->hasGUI()) {
206               $gui_link =
207               '<a href="'.html::escapeHTML($f->guiURL()).'">'.
208               '<img src="images/edit-mini.png" alt="'.__('Filter configuration').'" '.
209               'title="'.__('Filter configuration').'" /></a>';
210          }
211
212          echo
213          '<tr class="line'.($f->active ? '' : ' offline').'" id="f_'.$fid.'">'.
214          '<td class="handle">'.form::field(array('f_order['.$fid.']'),2,5,(string) $i, 'position', '', false, 'title="'.__('position').'"').'</td>'.
215          '<td class="nowrap">'.form::checkbox(array('filters_active[]'),$fid,$f->active, '', '', false, 'title="'.__('Active').'"').'</td>'.
216          '<td class="nowrap">'.form::checkbox(array('filters_auto_del[]'),$fid,$f->auto_delete, '', '', false, 'title="'.__('Auto Del.').'"').'</td>'.
217          '<td class="nowrap" scope="row">'.$f->name.'</td>'.
218          '<td class="maximal">'.$f->description.'</td>'.
219          '<td class="status">'.$gui_link.'</td>'.
220          '</tr>';
221          $i++;
222     }
223     echo
224     '</tbody></table></div>'.
225     '<p>'.form::hidden('filters_order','').
226     $core->formNonce().
227     '<input type="submit" name="filters_upd" value="'.__('Save').'" /></p>'.
228     '</form>';
229
230
231     # Syndication
232     if (DC_ADMIN_URL)
233     {
234          $ham_feed = $core->blog->url.$core->url->getURLFor(
235               'hamfeed',
236               $code = dcAntispam::getUserCode($core)
237          );
238          $spam_feed = $core->blog->url.$core->url->getURLFor(
239               'spamfeed',
240               $code = dcAntispam::getUserCode($core)
241          );
242
243          echo
244          '<h3>'.__('Syndication').'</h3>'.
245          '<ul class="spaminfo">'.
246          '<li class="feed"><a href="'.$spam_feed.'">'.__('Junk comments RSS feed').'</a></li>'.
247          '<li class="feed"><a href="'.$ham_feed.'">'.__('Published comments RSS feed').'</a></li>'.
248          '</ul>';
249     }
250}
251?>
252
253</body>
254</html>
Note: See TracBrowser for help on using the repository browser.

Sites map