Dotclear

source: admin/comments.php @ 1179:a43a29427ef3

Revision 1179:a43a29427ef3, 7.5 KB checked in by franck <carnet.franck.paul@…>, 12 years ago (diff)

Update copyright notice

Line 
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
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          $_SESSION['comments_del_spam'] = true;
22          http::redirect('comments.php');
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(
31'-' => ''
32);
33foreach ($core->blog->getAllCommentStatus() as $k => $v) {
34     $status_combo[$v] = (string) $k;
35}
36
37$type_combo = array(
38'-' => '',
39__('comment') => 'co',
40__('trackback') => 'tb'
41);
42
43$sortby_combo = array(
44__('Date') => 'comment_dt',
45__('Entry title') => 'post_title',
46__('Author') => 'comment_author',
47__('Status') => 'comment_status'
48);
49
50$order_combo = array(
51__('Descending') => 'desc',
52__('Ascending') => 'asc'
53);
54
55
56/* Get comments
57-------------------------------------------------------- */
58$author = isset($_GET['author']) ? $_GET['author'] : '';
59$status = isset($_GET['status']) ?      $_GET['status'] : '';
60$type = !empty($_GET['type']) ?         $_GET['type'] : '';
61$sortby = !empty($_GET['sortby']) ?     $_GET['sortby'] : 'comment_dt';
62$order = !empty($_GET['order']) ?       $_GET['order'] : 'desc';
63$ip = !empty($_GET['ip']) ?             $_GET['ip'] : '';
64
65$with_spam = $author || $status || $type || $sortby != 'comment_dt' || $order != 'desc' || $ip;
66
67$show_filters = false;
68
69$page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1;
70$nb_per_page =  30;
71
72if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) {
73     if ($nb_per_page != $_GET['nb']) {
74          $show_filters = true;
75     }
76     $nb_per_page = (integer) $_GET['nb'];
77}
78
79$params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page);
80$params['no_content'] = true;
81
82# Author filter
83if ($author !== '') {
84     $params['q_author'] = $author;
85     $show_filters = true;
86} else {
87     $author='';
88}
89
90# - Type filter
91if ($type == 'tb' || $type == 'co') {
92     $params['comment_trackback'] = ($type == 'tb');
93     $show_filters = true;
94} else {
95     $type='';
96}
97
98# - Status filter
99if ($status !== '' && in_array($status,$status_combo)) {
100     $params['comment_status'] = $status;
101     $show_filters = true;
102} elseif (!$with_spam) {
103     $params['comment_status_not'] = -2;
104     $status='';
105} else {
106     $status='';
107}
108
109# - IP filter
110if ($ip) {
111     $params['comment_ip'] = $ip;
112     $show_filters = true;
113}
114
115# Sortby and order filter
116if ($sortby !== '' && in_array($sortby,$sortby_combo)) {
117     if ($order !== '' && in_array($order,$order_combo)) {
118          $params['order'] = $sortby.' '.$order;
119     } else {
120          $order = 'desc';
121     }
122     
123     if ($sortby != 'comment_dt' || $order != 'desc') {
124          $show_filters = true;
125     }
126} else {
127     $sortby = 'comment_dt';
128     $order = 'desc';
129}
130
131# Actions combo box
132$combo_action = array();
133$default = '';
134if ($core->auth->check('publish,contentadmin',$core->blog->id))
135{
136     $combo_action[__('publish')] = 'publish';
137     $combo_action[__('unpublish')] = 'unpublish';
138     $combo_action[__('mark as pending')] = 'pending';
139     $combo_action[__('mark as junk')] = 'junk';
140}
141if ($core->auth->check('delete,contentadmin',$core->blog->id))
142{
143     $combo_action[__('Delete')] = 'delete';
144     if ($status == -2) {
145          $default = 'delete';
146     }
147}
148
149# --BEHAVIOR-- adminCommentsActionsCombo
150$core->callBehavior('adminCommentsActionsCombo',array(&$combo_action));
151
152/* Get comments
153-------------------------------------------------------- */
154try {
155     $comments = $core->blog->getComments($params);
156     $counter = $core->blog->getComments($params,true);
157     $comment_list = new adminCommentList($core,$comments,$counter->f(0));
158} catch (Exception $e) {
159     $core->error->add($e->getMessage());
160}
161
162/* DISPLAY
163-------------------------------------------------------- */
164$starting_script = dcPage::jsLoad('js/_comments.js');
165if (!$show_filters) {
166     $starting_script .= dcPage::jsLoad('js/filter-controls.js');
167}
168# --BEHAVIOR-- adminCommentsHeaders
169$starting_script .= $core->callBehavior('adminCommentsHeaders');
170
171dcPage::open(__('Comments and trackbacks'),$starting_script);
172
173echo '<h2>'.html::escapeHTML($core->blog->name).' &rsaquo; <span class="page-title">'.__('Comments and trackbacks').'</span></h2>';
174
175if (!$core->error->flag())
176{
177     if (isset($_SESSION['comments_del_spam'])) {
178          dcPage::message(__('Spam comments have been successfully deleted.'));
179          unset($_SESSION['comments_del_spam']);
180     }
181     
182     # Filters
183     if (!$show_filters) {
184          echo '<p><a id="filter-control" class="form-control" href="#">'.
185          __('Filters').'</a></p>';
186     }
187     
188     echo
189     '<form action="comments.php" method="get" id="filters-form">'.
190     '<fieldset><legend>'.__('Filters').'</legend>'.
191     '<div class="three-cols">'.
192     '<div class="col">'.
193     '<label for="type">'.__('Type:').' '.
194     form::combo('type',$type_combo,$type).
195     '</label> '.
196     '<label for="status">'.__('Status:').' '.
197     form::combo('status',$status_combo,$status).
198     '</label>'.
199     '</div>'.
200     
201     '<div class="col">'.
202     '<p><label for="sortby">'.__('Order by:').' '.
203     form::combo('sortby',$sortby_combo,$sortby).
204     '</label> '.
205     '<label for="order">'.__('Sort:').' '.
206     form::combo('order',$order_combo,$order).
207     '</label></p>'.
208     '<p><label for="nb" class="classic">'.  form::field('nb',3,3,$nb_per_page).' '.
209     __('Comments per page').'</label></p>'.
210     '</div>'.
211     
212     '<div class="col">'.
213     '<p><label for="author">'.__('Comment author:').' '.
214     form::field('author',20,255,html::escapeHTML($author)).
215     '</label>'.
216     '<label for="ip">'.__('IP address:').' '.
217     form::field('ip',20,39,html::escapeHTML($ip)).
218     '</label></p>'.
219     '<p><input type="submit" value="'.__('Apply filters').'" /></p>'.
220     '</div>'.
221     
222     '</div>'.
223     '<br class="clear" />'. //Opera sucks
224     '</fieldset>'.
225     '</form>';
226     
227     $spam_count = $core->blog->getComments(array('comment_status'=>-2),true)->f(0);
228     if ($spam_count > 0) {
229         
230          echo 
231               '<form action="comments.php" method="post" class="fieldset">';
232
233          if (!$with_spam || ($status != -2)) {
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         
243          echo
244               $core->formNonce().
245               '<input name="delete_all_spam" class="delete" type="submit" value="'.__('Delete all spams').'" /></p>';
246
247          # --BEHAVIOR-- adminCommentsSpamForm
248          $core->callBehavior('adminCommentsSpamForm',$core);
249
250          echo '</form>';
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