Dotclear

source: admin/comments.php @ 1049:1d17674d50ad

Revision 1049:1d17674d50ad, 7.9 KB checked in by JcDenis, 13 years ago (diff)

Fix #903 : Added action "Delete all spam" to comments page.

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

Sites map