Dotclear

source: admin/comments.php @ 796:43a9cace0f39

Revision 796:43a9cace0f39, 6.8 KB checked in by Dsls <dsls@…>, 13 years ago (diff)

Far cleaner this way...

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          if ($spam_count == 1) {
214               echo '<p>'.sprintf(__('You have one spam comments.'),'<strong>'.$spam_count.'</strong>').' '.
215               '<a href="comments.php?status=-2">'.__('Show it.').'</a></p>';
216          } elseif ($spam_count > 1) {
217               echo '<p>'.sprintf(__('You have %s spam comments.'),'<strong>'.$spam_count.'</strong>').' '.
218               '<a href="comments.php?status=-2">'.__('Show them.').'</a></p>';
219          }
220     }
221     
222     # Show comments
223     $comment_list->display($page,$nb_per_page,
224     '<form action="comments_actions.php" method="post" id="form-comments">'.
225     
226     '%s'.
227     
228     '<div class="two-cols">'.
229     '<p class="col checkboxes-helpers"></p>'.
230     
231     '<p class="col right"><label for="action" class="classic">'.__('Selected comments action:').'</label> '.
232     form::combo('action',$combo_action,$default,'','','','title="'.__('action: ').'"').
233     $core->formNonce().
234     '<input type="submit" value="'.__('ok').'" /></p>'.
235     form::hidden(array('type'),$type).
236     form::hidden(array('sortby'),$sortby).
237     form::hidden(array('order'),$order).
238     form::hidden(array('author'),preg_replace('/%/','%%',$author)).
239     form::hidden(array('status'),$status).
240     form::hidden(array('ip'),preg_replace('/%/','%%',$ip)).
241     form::hidden(array('page'),$page).
242     form::hidden(array('nb'),$nb_per_page).
243     '</div>'.
244     
245     '</form>'
246     );
247}
248
249dcPage::helpBlock('core_comments');
250dcPage::close();
251?>
Note: See TracBrowser for help on using the repository browser.

Sites map