Dotclear

source: admin/comments.php @ 1051:d65efdccc4fb

Revision 1051:d65efdccc4fb, 8.0 KB checked in by franck <carnet.franck.paul@…>, 13 years ago (diff)

Direct access to blog pref only if antispam plugin is activated (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
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               
220               if ($core->plugins->moduleExists('antispam')) {
221                    echo 
222                    '<form action="plugin.php?p=antispam" method="post" class="fieldset">';
223               }
224
225               if ($spam_count == 1) {
226                    echo '<p>'.sprintf(__('You have one spam comments.'),'<strong>'.$spam_count.'</strong>').' '.
227                    '<a href="comments.php?status=-2">'.__('Show it.').'</a></p>';
228               } elseif ($spam_count > 1) {
229                    echo '<p>'.sprintf(__('You have %s spam comments.'),'<strong>'.$spam_count.'</strong>').' '.
230                    '<a href="comments.php?status=-2">'.__('Show them.').'</a></p>';
231               }
232               
233               if ($core->plugins->moduleExists('antispam')) {
234
235                    $moderationTTL = $core->blog->settings->antispam->antispam_moderation_ttl;
236                    $spam_redir =
237                         'comments.php?type='.$type.
238                         '&author='.preg_replace('/%/','%%',$author).
239                         '&status='.$status.
240                         '&sortby='.$sortby.
241                         '&ip='.preg_replace('/%/','%%',$ip).
242                         '&order='.$order.
243                         '&page='.$page.
244                         '&nb='.$nb_per_page;
245                   
246                    echo
247                    $core->formNonce().
248                    form::hidden('ts',time()).
249                    form::hidden('redir',$spam_redir).
250                    '<input name="delete_all_spam" class="delete" type="submit" value="'.__('Delete all spams').'" /></p>';
251
252                    if ($moderationTTL != null && $moderationTTL >=0) {
253                         echo '<p>'.sprintf(__('All spam comments older than %s day(s) will be automatically deleted.'), $moderationTTL).' '.
254                         sprintf(__('You can modify this duration in the %s'),'<a href="blog_pref.php"> '.__('Blog preferences').'</a>').
255                         '</p>';
256                    }
257
258                    echo '</form>';
259               }
260          }
261     }
262     
263     # Show comments
264     $comment_list->display($page,$nb_per_page,
265     '<form action="comments_actions.php" method="post" id="form-comments">'.
266     
267     '%s'.
268     
269     '<div class="two-cols">'.
270     '<p class="col checkboxes-helpers"></p>'.
271     
272     '<p class="col right"><label for="action" class="classic">'.__('Selected comments action:').'</label> '.
273     form::combo('action',$combo_action,$default,'','','','title="'.__('action: ').'"').
274     $core->formNonce().
275     '<input type="submit" value="'.__('ok').'" /></p>'.
276     form::hidden(array('type'),$type).
277     form::hidden(array('sortby'),$sortby).
278     form::hidden(array('order'),$order).
279     form::hidden(array('author'),preg_replace('/%/','%%',$author)).
280     form::hidden(array('status'),$status).
281     form::hidden(array('ip'),preg_replace('/%/','%%',$ip)).
282     form::hidden(array('page'),$page).
283     form::hidden(array('nb'),$nb_per_page).
284     '</div>'.
285     
286     '</form>'
287     );
288}
289
290dcPage::helpBlock('core_comments');
291dcPage::close();
292?>
Note: See TracBrowser for help on using the repository browser.

Sites map