Dotclear

source: admin/comments.php @ 1052:de274bbd7b80

Revision 1052:de274bbd7b80, 7.5 KB checked in by franck <carnet.franck.paul@…>, 13 years ago (diff)

Cope with junk comments without antispam plugin enabled (addresses #903)

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2011 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
13require dirname(__FILE__).'/../inc/admin/prepend.php';
14
15dcPage::check('usage,contentadmin');
16
17if (!empty($_POST['delete_all_spam']))
18{
19     try {
20          $core->blog->delJunkComments();
21          http::redirect('comments.php?delspam=1');
22     } catch (Exception $e) {
23          $core->error->add($e->getMessage());
24     }
25}
26
27# Creating filter combo boxes
28# Filter form we'll put in html_block
29$status_combo = array(
30'-' => ''
31);
32foreach ($core->blog->getAllCommentStatus() as $k => $v) {
33     $status_combo[$v] = (string) $k;
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__('Author') => 'comment_author',
46__('Status') => 'comment_status'
47);
48
49$order_combo = array(
50__('Descending') => 'desc',
51__('Ascending') => 'asc'
52);
53
54
55/* Get comments
56-------------------------------------------------------- */
57$author = isset($_GET['author']) ? $_GET['author'] : '';
58$status = isset($_GET['status']) ?      $_GET['status'] : '';
59$type = !empty($_GET['type']) ?         $_GET['type'] : '';
60$sortby = !empty($_GET['sortby']) ?     $_GET['sortby'] : 'comment_dt';
61$order = !empty($_GET['order']) ?       $_GET['order'] : 'desc';
62$ip = !empty($_GET['ip']) ?             $_GET['ip'] : '';
63
64$with_spam = $author || $status || $type || $sortby != 'comment_dt' || $order != 'desc' || $ip;
65
66$show_filters = false;
67
68$page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1;
69$nb_per_page =  30;
70
71if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) {
72     if ($nb_per_page != $_GET['nb']) {
73          $show_filters = true;
74     }
75     $nb_per_page = (integer) $_GET['nb'];
76}
77
78$params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page);
79$params['no_content'] = true;
80
81# Author filter
82if ($author !== '') {
83     $params['q_author'] = $author;
84     $show_filters = true;
85} else {
86     $author='';
87}
88
89# - Type filter
90if ($type == 'tb' || $type == 'co') {
91     $params['comment_trackback'] = ($type == 'tb');
92     $show_filters = true;
93} else {
94     $type='';
95}
96
97# - Status filter
98if ($status !== '' && in_array($status,$status_combo)) {
99     $params['comment_status'] = $status;
100     $show_filters = true;
101} elseif (!$with_spam) {
102     $params['comment_status_not'] = -2;
103     $status='';
104} else {
105     $status='';
106}
107
108# - IP filter
109if ($ip) {
110     $params['comment_ip'] = $ip;
111     $show_filters = true;
112}
113
114# Sortby and order filter
115if ($sortby !== '' && in_array($sortby,$sortby_combo)) {
116     if ($order !== '' && in_array($order,$order_combo)) {
117          $params['order'] = $sortby.' '.$order;
118     } else {
119          $order = 'desc';
120     }
121     
122     if ($sortby != 'comment_dt' || $order != 'desc') {
123          $show_filters = true;
124     }
125} else {
126     $sortby = 'comment_dt';
127     $order = 'desc';
128}
129
130# Actions combo box
131$combo_action = array();
132$default = '';
133if ($core->auth->check('publish,contentadmin',$core->blog->id))
134{
135     $combo_action[__('publish')] = 'publish';
136     $combo_action[__('unpublish')] = 'unpublish';
137     $combo_action[__('mark as pending')] = 'pending';
138     $combo_action[__('mark as junk')] = 'junk';
139}
140if ($core->auth->check('delete,contentadmin',$core->blog->id))
141{
142     $combo_action[__('Delete')] = 'delete';
143     if ($status == -2) {
144          $default = 'delete';
145     }
146}
147
148# --BEHAVIOR-- adminCommentsActionsCombo
149$core->callBehavior('adminCommentsActionsCombo',array(&$combo_action));
150
151/* Get comments
152-------------------------------------------------------- */
153try {
154     $comments = $core->blog->getComments($params);
155     $counter = $core->blog->getComments($params,true);
156     $comment_list = new adminCommentList($core,$comments,$counter->f(0));
157} catch (Exception $e) {
158     $core->error->add($e->getMessage());
159}
160
161/* DISPLAY
162-------------------------------------------------------- */
163$starting_script = dcPage::jsLoad('js/_comments.js');
164if (!$show_filters) {
165     $starting_script .= dcPage::jsLoad('js/filter-controls.js');
166}
167# --BEHAVIOR-- adminCommentsHeaders
168$starting_script .= $core->callBehavior('adminCommentsHeaders');
169
170dcPage::open(__('Comments and trackbacks'),$starting_script);
171
172echo '<h2>'.html::escapeHTML($core->blog->name).' &rsaquo; <span class="page-title">'.__('Comments and trackbacks').'</span></h2>';
173
174if (!$core->error->flag())
175{
176     if (!empty($_GET['delspam'])) {
177          dcPage::message(__('Spam comments have been successfully deleted.'));
178     }
179     
180     # Filters
181     if (!$show_filters) {
182          echo '<p><a id="filter-control" class="form-control" href="#">'.
183          __('Filters').'</a></p>';
184     }
185     
186     echo
187     '<form action="comments.php" method="get" id="filters-form">'.
188     '<fieldset><legend>'.__('Filters').'</legend>'.
189     '<div class="three-cols">'.
190     '<div class="col">'.
191     '<label for="type">'.__('Type:').' '.
192     form::combo('type',$type_combo,$type).
193     '</label> '.
194     '<label for="status">'.__('Status:').' '.
195     form::combo('status',$status_combo,$status).
196     '</label>'.
197     '</div>'.
198     
199     '<div class="col">'.
200     '<p><label for="sortby">'.__('Order by:').' '.
201     form::combo('sortby',$sortby_combo,$sortby).
202     '</label> '.
203     '<label for="order">'.__('Sort:').' '.
204     form::combo('order',$order_combo,$order).
205     '</label></p>'.
206     '<p><label for="nb" class="classic">'.  form::field('nb',3,3,$nb_per_page).' '.
207     __('Comments per page').'</label></p>'.
208     '</div>'.
209     
210     '<div class="col">'.
211     '<p><label for="author">'.__('Comment author:').' '.
212     form::field('author',20,255,html::escapeHTML($author)).
213     '</label>'.
214     '<label for="ip">'.__('IP address:').' '.
215     form::field('ip',20,39,html::escapeHTML($ip)).
216     '</label></p>'.
217     '<p><input type="submit" value="'.__('Apply filters').'" /></p>'.
218     '</div>'.
219     
220     '</div>'.
221     '<br class="clear" />'. //Opera sucks
222     '</fieldset>'.
223     '</form>';
224     
225     if (!$with_spam) {
226
227          $spam_count = $core->blog->getComments(array('comment_status'=>-2),true)->f(0);
228         
229          if ($spam_count > 0) {
230               
231               echo 
232                    '<form action="comments.php" method="post" class="fieldset">';
233
234               if ($spam_count == 1) {
235                    echo '<p>'.sprintf(__('You have one spam comments.'),'<strong>'.$spam_count.'</strong>').' '.
236                    '<a href="comments.php?status=-2">'.__('Show it.').'</a></p>';
237               } elseif ($spam_count > 1) {
238                    echo '<p>'.sprintf(__('You have %s spam comments.'),'<strong>'.$spam_count.'</strong>').' '.
239                    '<a href="comments.php?status=-2">'.__('Show them.').'</a></p>';
240               }
241               
242               echo
243                    $core->formNonce().
244                    '<input name="delete_all_spam" class="delete" type="submit" value="'.__('Delete all spams').'" /></p>';
245
246               # --BEHAVIOR-- adminCommentsSpamForm
247               $core->callBehavior('adminCommentsSpamForm',$core);
248
249               echo '</form>';
250          }
251     }
252     
253     # Show comments
254     $comment_list->display($page,$nb_per_page,
255     '<form action="comments_actions.php" method="post" id="form-comments">'.
256     
257     '%s'.
258     
259     '<div class="two-cols">'.
260     '<p class="col checkboxes-helpers"></p>'.
261     
262     '<p class="col right"><label for="action" class="classic">'.__('Selected comments action:').'</label> '.
263     form::combo('action',$combo_action,$default,'','','','title="'.__('action: ').'"').
264     $core->formNonce().
265     '<input type="submit" value="'.__('ok').'" /></p>'.
266     form::hidden(array('type'),$type).
267     form::hidden(array('sortby'),$sortby).
268     form::hidden(array('order'),$order).
269     form::hidden(array('author'),preg_replace('/%/','%%',$author)).
270     form::hidden(array('status'),$status).
271     form::hidden(array('ip'),preg_replace('/%/','%%',$ip)).
272     form::hidden(array('page'),$page).
273     form::hidden(array('nb'),$nb_per_page).
274     '</div>'.
275     
276     '</form>'
277     );
278}
279
280dcPage::helpBlock('core_comments');
281dcPage::close();
282?>
Note: See TracBrowser for help on using the repository browser.

Sites map