1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
3 | # |
---|
4 | # This file is part of 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 ----------------------------------------- |
---|
12 | |
---|
13 | require dirname(__FILE__).'/../inc/admin/prepend.php'; |
---|
14 | |
---|
15 | dcPage::check('usage,contentadmin'); |
---|
16 | |
---|
17 | if (!empty($_POST['delete_all_spam'])) |
---|
18 | { |
---|
19 | try { |
---|
20 | $core->blog->delJunkComments(); |
---|
21 | $_SESSION['comments_del_spam'] = true; |
---|
22 | $core->adminurl->redirect("admin.comments"); |
---|
23 | } catch (Exception $e) { |
---|
24 | $core->error->add($e->getMessage()); |
---|
25 | } |
---|
26 | } |
---|
27 | |
---|
28 | # Creating filter combo boxes |
---|
29 | # Filter form we'll put in html_block |
---|
30 | $status_combo = array_merge( |
---|
31 | array('-' => ''), |
---|
32 | dcAdminCombos::getCommentStatusescombo() |
---|
33 | ); |
---|
34 | |
---|
35 | |
---|
36 | $type_combo = array( |
---|
37 | '-' => '', |
---|
38 | __('Comment') => 'co', |
---|
39 | __('Trackback') => 'tb' |
---|
40 | ); |
---|
41 | |
---|
42 | $sortby_combo = array( |
---|
43 | __('Date') => 'comment_dt', |
---|
44 | __('Entry title') => 'post_title', |
---|
45 | __('Entry date') => 'post_dt', |
---|
46 | __('Author') => 'comment_author', |
---|
47 | __('Status') => 'comment_status' |
---|
48 | ); |
---|
49 | |
---|
50 | $sortby_lex = array( |
---|
51 | // key in sorty_combo (see above) => field in SQL request |
---|
52 | 'post_title' => 'post_title', |
---|
53 | 'comment_author' => 'comment_author', |
---|
54 | 'comment_spam_filter' => 'comment_spam_filter'); |
---|
55 | |
---|
56 | $order_combo = array( |
---|
57 | __('Descending') => 'desc', |
---|
58 | __('Ascending') => 'asc' |
---|
59 | ); |
---|
60 | |
---|
61 | /* Get comments |
---|
62 | -------------------------------------------------------- */ |
---|
63 | $author = isset($_GET['author']) ? $_GET['author'] : ''; |
---|
64 | $status = isset($_GET['status']) ? $_GET['status'] : ''; |
---|
65 | $type = !empty($_GET['type']) ? $_GET['type'] : ''; |
---|
66 | $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : 'comment_dt'; |
---|
67 | $order = !empty($_GET['order']) ? $_GET['order'] : 'desc'; |
---|
68 | $ip = !empty($_GET['ip']) ? $_GET['ip'] : ''; |
---|
69 | $email = !empty($_GET['email']) ? $_GET['email'] : ''; |
---|
70 | $site = !empty($_GET['site']) ? $_GET['site'] : ''; |
---|
71 | |
---|
72 | $with_spam = $author || $status || $type || $sortby != 'comment_dt' || $order != 'desc' || $ip; |
---|
73 | |
---|
74 | $show_filters = false; |
---|
75 | |
---|
76 | $page = !empty($_GET['page']) ? max(1,(integer) $_GET['page']) : 1; |
---|
77 | $nb_per_page = 30; |
---|
78 | |
---|
79 | if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { |
---|
80 | if ($nb_per_page != (integer) $_GET['nb']) { |
---|
81 | $show_filters = true; |
---|
82 | } |
---|
83 | $nb_per_page = (integer) $_GET['nb']; |
---|
84 | } |
---|
85 | |
---|
86 | $params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page); |
---|
87 | $params['no_content'] = true; |
---|
88 | |
---|
89 | # Author filter |
---|
90 | if ($author !== '') { |
---|
91 | $params['q_author'] = $author; |
---|
92 | $show_filters = true; |
---|
93 | } else { |
---|
94 | $author=''; |
---|
95 | } |
---|
96 | |
---|
97 | # - Type filter |
---|
98 | if ($type == 'tb' || $type == 'co') { |
---|
99 | $params['comment_trackback'] = ($type == 'tb'); |
---|
100 | $show_filters = true; |
---|
101 | } else { |
---|
102 | $type=''; |
---|
103 | } |
---|
104 | |
---|
105 | # - Status filter |
---|
106 | if ($status !== '' && in_array($status,$status_combo)) { |
---|
107 | $params['comment_status'] = $status; |
---|
108 | $show_filters = true; |
---|
109 | } elseif (!$with_spam) { |
---|
110 | $params['comment_status_not'] = -2; |
---|
111 | $status=''; |
---|
112 | } else { |
---|
113 | $status=''; |
---|
114 | } |
---|
115 | |
---|
116 | # - IP filter |
---|
117 | if ($ip) { |
---|
118 | $params['comment_ip'] = $ip; |
---|
119 | $show_filters = true; |
---|
120 | } |
---|
121 | |
---|
122 | # - email filter |
---|
123 | if ($email) { |
---|
124 | $params['comment_email'] = $email; |
---|
125 | $show_filters = true; |
---|
126 | } |
---|
127 | |
---|
128 | # - site filter |
---|
129 | if ($site) { |
---|
130 | $params['comment_site'] = $site; |
---|
131 | $show_filters = true; |
---|
132 | } |
---|
133 | |
---|
134 | // Add some sort order if spams displayed |
---|
135 | if ($with_spam || ($status == -2)) { |
---|
136 | $sortby_combo[__('IP')] = 'comment_ip'; |
---|
137 | $sortby_combo[__('Spam filter')] = 'comment_spam_filter'; |
---|
138 | } |
---|
139 | |
---|
140 | # Sortby and order filter |
---|
141 | if ($sortby !== '' && in_array($sortby,$sortby_combo)) { |
---|
142 | if (array_key_exists($sortby,$sortby_lex)) { |
---|
143 | $params['order'] = $core->con->lexFields($sortby_lex[$sortby]); |
---|
144 | } else { |
---|
145 | $params['order'] = $sortby; |
---|
146 | } |
---|
147 | if ($order !== '' && in_array($order,$order_combo)) { |
---|
148 | $params['order'] .= ' '.$order; |
---|
149 | } else { |
---|
150 | $order = 'desc'; |
---|
151 | } |
---|
152 | |
---|
153 | if ($sortby != 'comment_dt' || $order != 'desc') { |
---|
154 | $show_filters = true; |
---|
155 | } |
---|
156 | } else { |
---|
157 | $sortby = 'comment_dt'; |
---|
158 | $order = 'desc'; |
---|
159 | } |
---|
160 | |
---|
161 | # Actions combo box |
---|
162 | $combo_action = array(); |
---|
163 | $default = ''; |
---|
164 | if ($core->auth->check('delete,contentadmin',$core->blog->id) && $status == -2) |
---|
165 | { |
---|
166 | $default = 'delete'; |
---|
167 | } |
---|
168 | |
---|
169 | $comments_actions_page = new dcCommentsActionsPage($core,$core->adminurl->get("admin.comments")); |
---|
170 | |
---|
171 | if ($comments_actions_page->process()) { |
---|
172 | return; |
---|
173 | } |
---|
174 | |
---|
175 | /* Get comments |
---|
176 | -------------------------------------------------------- */ |
---|
177 | try { |
---|
178 | $comments = $core->blog->getComments($params); |
---|
179 | $counter = $core->blog->getComments($params,true); |
---|
180 | $comment_list = new adminCommentList($core,$comments,$counter->f(0)); |
---|
181 | } catch (Exception $e) { |
---|
182 | $core->error->add($e->getMessage()); |
---|
183 | } |
---|
184 | |
---|
185 | /* DISPLAY |
---|
186 | -------------------------------------------------------- */ |
---|
187 | |
---|
188 | dcPage::open(__('Comments and trackbacks'), |
---|
189 | dcPage::jsLoad('js/_comments.js').dcPage::jsFilterControl($show_filters), |
---|
190 | dcPage::breadcrumb( |
---|
191 | array( |
---|
192 | html::escapeHTML($core->blog->name) => '', |
---|
193 | __('Comments and trackbacks') => '' |
---|
194 | )) |
---|
195 | ); |
---|
196 | if (!empty($_GET['upd'])) { |
---|
197 | dcPage::success(__('Selected comments have been successfully updated.')); |
---|
198 | } elseif (!empty($_GET['del'])) { |
---|
199 | dcPage::success(__('Selected comments have been successfully deleted.')); |
---|
200 | } |
---|
201 | |
---|
202 | if (!$core->error->flag()) |
---|
203 | { |
---|
204 | if (isset($_SESSION['comments_del_spam'])) { |
---|
205 | dcPage::message(__('Spam comments have been successfully deleted.')); |
---|
206 | unset($_SESSION['comments_del_spam']); |
---|
207 | } |
---|
208 | |
---|
209 | $spam_count = $core->blog->getComments(array('comment_status'=>-2),true)->f(0); |
---|
210 | if ($spam_count > 0) { |
---|
211 | |
---|
212 | echo |
---|
213 | '<form action="'.$core->adminurl->get("admin.comments").'" method="post" class="fieldset">'; |
---|
214 | |
---|
215 | if (!$with_spam || ($status != -2)) { |
---|
216 | if ($spam_count == 1) { |
---|
217 | echo '<p>'.sprintf(__('You have one spam comment.'),'<strong>'.$spam_count.'</strong>').' '. |
---|
218 | '<a href="'.$core->adminurl->get("admin.comments",array('status' => -2)).'">'.__('Show it.').'</a></p>'; |
---|
219 | } elseif ($spam_count > 1) { |
---|
220 | echo '<p>'.sprintf(__('You have %s spam comments.'),'<strong>'.$spam_count.'</strong>').' '. |
---|
221 | '<a href="'.$core->adminurl->get("admin.comments",array('status' => -2)).'">'.__('Show them.').'</a></p>'; |
---|
222 | } |
---|
223 | } |
---|
224 | |
---|
225 | echo |
---|
226 | '<p>'. |
---|
227 | $core->formNonce(). |
---|
228 | '<input name="delete_all_spam" class="delete" type="submit" value="'.__('Delete all spams').'" /></p>'; |
---|
229 | |
---|
230 | # --BEHAVIOR-- adminCommentsSpamForm |
---|
231 | $core->callBehavior('adminCommentsSpamForm',$core); |
---|
232 | |
---|
233 | echo '</form>'; |
---|
234 | } |
---|
235 | |
---|
236 | echo |
---|
237 | '<form action="'.$core->adminurl->get("admin.comments").'" method="get" id="filters-form">'. |
---|
238 | '<h3 class="out-of-screen-if-js">'.__('Show filters and display options').'</h3>'. |
---|
239 | |
---|
240 | '<div class="table">'. |
---|
241 | '<div class="cell">'. |
---|
242 | '<h4>'.__('Filters').'</h4>'. |
---|
243 | '<p><label for="type" class="ib">'.__('Type:').'</label> '. |
---|
244 | form::combo('type',$type_combo,$type).'</p> '. |
---|
245 | '<p><label for="status" class="ib">'.__('Status:').'</label> '. |
---|
246 | form::combo('status',$status_combo,$status).'</p>'. |
---|
247 | '</div>'. |
---|
248 | |
---|
249 | '<div class="cell filters-sibling-cell">'. |
---|
250 | '<p><label for="author" class="ib">'.__('Author:').'</label> '. |
---|
251 | form::field('author',20,255,html::escapeHTML($author)).'</p>'. |
---|
252 | '<p><label for="ip" class="ib">'.__('IP address:').'</label> '. |
---|
253 | form::field('ip',20,39,html::escapeHTML($ip)).'</p>'. |
---|
254 | '<p><label for="email" class="ib">'.__('Email:').'</label> '. |
---|
255 | form::field('email',20,255,html::escapeHTML($email)).'</p>'. |
---|
256 | '<p><label for="site" class="ib">'.__('Web site:').'</label> '. |
---|
257 | form::field('site',20,255,html::escapeHTML($site)).'</p>'. |
---|
258 | '</div>'. |
---|
259 | |
---|
260 | '<div class="cell filters-options">'. |
---|
261 | '<h4>'.__('Display options').'</h4>'. |
---|
262 | '<p><label for="sortby" class="ib">'.__('Order by:').'</label> '. |
---|
263 | form::combo('sortby',$sortby_combo,$sortby).'</p>'. |
---|
264 | '<p><label for="order" class="ib">'.__('Sort:').'</label> '. |
---|
265 | form::combo('order',$order_combo,$order).'</p>'. |
---|
266 | '<p><span class="label ib">'.__('Show').'</span> <label for="nb" class="classic">'. |
---|
267 | form::field('nb',3,3,$nb_per_page).' '. |
---|
268 | __('comments per page').'</label></p>'. |
---|
269 | '</div>'. |
---|
270 | |
---|
271 | '</div>'. |
---|
272 | '<p><input type="submit" value="'.__('Apply filters and display options').'" />'. |
---|
273 | '<br class="clear" /></p>'. //Opera sucks |
---|
274 | '</form>'; |
---|
275 | |
---|
276 | # Show comments |
---|
277 | $comment_list->display($page,$nb_per_page, |
---|
278 | '<form action="'.$core->adminurl->get("admin.comments").'" method="post" id="form-comments">'. |
---|
279 | |
---|
280 | '%s'. |
---|
281 | |
---|
282 | '<div class="two-cols">'. |
---|
283 | '<p class="col checkboxes-helpers"></p>'. |
---|
284 | |
---|
285 | '<p class="col right"><label for="action" class="classic">'.__('Selected comments action:').'</label> '. |
---|
286 | form::combo('action',$comments_actions_page->getCombo(),$default,'','','','title="'.__('Actions').'"'). |
---|
287 | $core->formNonce(). |
---|
288 | '<input id="do-action" type="submit" value="'.__('ok').'" /></p>'. |
---|
289 | form::hidden(array('type'),$type). |
---|
290 | form::hidden(array('sortby'),$sortby). |
---|
291 | form::hidden(array('order'),$order). |
---|
292 | form::hidden(array('author'),html::escapeHTML(preg_replace('/%/','%%',$author))). |
---|
293 | form::hidden(array('status'),$status). |
---|
294 | form::hidden(array('ip'),preg_replace('/%/','%%',$ip)). |
---|
295 | form::hidden(array('page'),$page). |
---|
296 | form::hidden(array('nb'),$nb_per_page). |
---|
297 | form::hidden(array('email'),html::escapeHTML(preg_replace('/%/','%%',$email))). |
---|
298 | form::hidden(array('site'),html::escapeHTML(preg_replace('/%/','%%',$site))). |
---|
299 | '</div>'. |
---|
300 | |
---|
301 | '</form>', |
---|
302 | $show_filters, |
---|
303 | ($with_spam || ($status == -2)) |
---|
304 | ); |
---|
305 | } |
---|
306 | |
---|
307 | dcPage::helpBlock('core_comments'); |
---|
308 | dcPage::close(); |
---|