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