Dotclear

source: admin/comments.php @ 3360:66bc2ca93d56

Revision 3360:66bc2ca93d56, 9.4 KB checked in by franck <carnet.franck.paul@…>, 9 years ago (diff)

Use lexicographic sort if possible in admin lists sort order

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          $core->adminurl->redirect("admin.comments");
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_merge(
31     array('-' => ''),
32     dcAdminCombos::getCommentStatusescombo()
33);
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__('Entry date') => 'post_dt',
46__('Author') => 'comment_author',
47__('Status') => 'comment_status'
48);
49
50$sortby_lex = array(
51     // key in sorty_combo (see above) => field in SQL request
52     'post_title' => 'post_title',
53     'comment_author' => 'comment_author',
54     'comment_spam_filter' => 'comment_spam_filter');
55
56$order_combo = array(
57__('Descending') => 'desc',
58__('Ascending') => 'asc'
59);
60
61/* Get comments
62-------------------------------------------------------- */
63$author = isset($_GET['author']) ? $_GET['author'] : '';
64$status = isset($_GET['status']) ? $_GET['status'] : '';
65$type   = !empty($_GET['type']) ? $_GET['type'] : '';
66$sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : 'comment_dt';
67$order  = !empty($_GET['order']) ? $_GET['order'] : 'desc';
68$ip     = !empty($_GET['ip']) ? $_GET['ip'] : '';
69$email  = !empty($_GET['email']) ? $_GET['email'] : '';
70$site   = !empty($_GET['site']) ? $_GET['site'] : '';
71
72$with_spam = $author || $status || $type || $sortby != 'comment_dt' || $order != 'desc' || $ip;
73
74$show_filters = false;
75
76$page = !empty($_GET['page']) ? max(1,(integer) $_GET['page']) : 1;
77$nb_per_page =  30;
78
79if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) {
80     if ($nb_per_page != $_GET['nb']) {
81          $show_filters = true;
82     }
83     $nb_per_page = (integer) $_GET['nb'];
84}
85
86$params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page);
87$params['no_content'] = true;
88
89# Author filter
90if ($author !== '') {
91     $params['q_author'] = $author;
92     $show_filters = true;
93} else {
94     $author='';
95}
96
97# - Type filter
98if ($type == 'tb' || $type == 'co') {
99     $params['comment_trackback'] = ($type == 'tb');
100     $show_filters = true;
101} else {
102     $type='';
103}
104
105# - Status filter
106if ($status !== '' && in_array($status,$status_combo)) {
107     $params['comment_status'] = $status;
108     $show_filters = true;
109} elseif (!$with_spam) {
110     $params['comment_status_not'] = -2;
111     $status='';
112} else {
113     $status='';
114}
115
116# - IP filter
117if ($ip) {
118     $params['comment_ip'] = $ip;
119     $show_filters = true;
120}
121
122# - email filter
123if ($email) {
124     $params['comment_email'] = $email;
125     $show_filters = true;
126}
127
128# - site filter
129if ($site) {
130     $params['comment_site'] = $site;
131     $show_filters = true;
132}
133
134// Add some sort order if spams displayed
135if ($with_spam || ($status == -2)) {
136     $sortby_combo[__('IP')] = 'comment_ip';
137     $sortby_combo[__('Spam filter')] = 'comment_spam_filter';
138}
139
140# Sortby and order filter
141if ($sortby !== '' && in_array($sortby,$sortby_combo)) {
142     if (array_key_exists($sortby,$sortby_lex)) {
143          $params['order'] = $core->con->lexFields($sortby_lex[$sortby]);
144     } else {
145          $params['order'] = $sortby;
146     }
147     if ($order !== '' && in_array($order,$order_combo)) {
148          $params['order'] .= ' '.$order;
149     } else {
150          $order = 'desc';
151     }
152
153     if ($sortby != 'comment_dt' || $order != 'desc') {
154          $show_filters = true;
155     }
156} else {
157     $sortby = 'comment_dt';
158     $order = 'desc';
159}
160
161# Actions combo box
162$combo_action = array();
163$default = '';
164if ($core->auth->check('delete,contentadmin',$core->blog->id) && $status == -2)
165{
166     $default = 'delete';
167}
168
169$comments_actions_page = new dcCommentsActionsPage($core,$core->adminurl->get("admin.comments"));
170
171if ($comments_actions_page->process()) {
172     return;
173}
174
175/* Get comments
176-------------------------------------------------------- */
177try {
178     $comments = $core->blog->getComments($params);
179     $counter = $core->blog->getComments($params,true);
180     $comment_list = new adminCommentList($core,$comments,$counter->f(0));
181} catch (Exception $e) {
182     $core->error->add($e->getMessage());
183}
184
185/* DISPLAY
186-------------------------------------------------------- */
187
188$form_filter_title = __('Show filters and display options');
189$starting_script  = dcPage::jsLoad('js/_comments.js');
190$starting_script .= dcPage::jsLoad('js/filter-controls.js');
191$starting_script .=
192     '<script type="text/javascript">'."\n".
193     "//<![CDATA["."\n".
194     dcPage::jsVar('dotclear.msg.show_filters', $show_filters ? 'true':'false')."\n".
195     dcPage::jsVar('dotclear.msg.filter_posts_list',$form_filter_title)."\n".
196     dcPage::jsVar('dotclear.msg.cancel_the_filter',__('Cancel filters and display options'))."\n".
197     "//]]>".
198     "</script>";
199
200dcPage::open(__('Comments and trackbacks'),$starting_script,
201     dcPage::breadcrumb(
202          array(
203               html::escapeHTML($core->blog->name) => '',
204               __('Comments and trackbacks') => ''
205          ))
206);
207if (!empty($_GET['upd'])) {
208     dcPage::success(__('Selected comments have been successfully updated.'));
209} elseif (!empty($_GET['del'])) {
210     dcPage::success(__('Selected comments have been successfully deleted.'));
211}
212
213if (!$core->error->flag())
214{
215     if (isset($_SESSION['comments_del_spam'])) {
216          dcPage::message(__('Spam comments have been successfully deleted.'));
217          unset($_SESSION['comments_del_spam']);
218     }
219
220     $spam_count = $core->blog->getComments(array('comment_status'=>-2),true)->f(0);
221     if ($spam_count > 0) {
222
223          echo
224               '<form action="'.$core->adminurl->get("admin.comments").'" method="post" class="fieldset">';
225
226          if (!$with_spam || ($status != -2)) {
227               if ($spam_count == 1) {
228                    echo '<p>'.sprintf(__('You have one spam comment.'),'<strong>'.$spam_count.'</strong>').' '.
229                    '<a href="'.$core->adminurl->get("admin.comments",array('status' => -2)).'">'.__('Show it.').'</a></p>';
230               } elseif ($spam_count > 1) {
231                    echo '<p>'.sprintf(__('You have %s spam comments.'),'<strong>'.$spam_count.'</strong>').' '.
232                    '<a href="'.$core->adminurl->get("admin.comments",array('status' => -2)).'">'.__('Show them.').'</a></p>';
233               }
234          }
235
236          echo
237               '<p>'.
238               $core->formNonce().
239               '<input name="delete_all_spam" class="delete" type="submit" value="'.__('Delete all spams').'" /></p>';
240
241          # --BEHAVIOR-- adminCommentsSpamForm
242          $core->callBehavior('adminCommentsSpamForm',$core);
243
244          echo '</form>';
245     }
246
247     echo
248     '<form action="'.$core->adminurl->get("admin.comments").'" method="get" id="filters-form">'.
249     '<h3 class="hidden">'.__('Filter comments and trackbacks list').'</h3>'.
250     '<div class="table">'.
251
252     '<div class="cell">'.
253     '<h4>'.__('Filters').'</h4>'.
254     '<p><label for="type" class="ib">'.__('Type:').'</label> '.
255     form::combo('type',$type_combo,$type).'</p> '.
256     '<p><label for="status" class="ib">'.__('Status:').'</label> '.
257     form::combo('status',$status_combo,$status).'</p>'.
258     '</div>'.
259
260     '<div class="cell filters-sibling-cell">'.
261     '<p><label for="author" class="ib">'.__('Author:').'</label> '.
262     form::field('author',20,255,html::escapeHTML($author)).'</p>'.
263     '<p><label for="ip" class="ib">'.__('IP address:').'</label> '.
264     form::field('ip',20,39,html::escapeHTML($ip)).'</p>'.
265     '<p><label for="email" class="ib">'.__('Email:').'</label> '.
266     form::field('email',20,255,html::escapeHTML($email)).'</p>'.
267     '<p><label for="site" class="ib">'.__('Web site:').'</label> '.
268     form::field('site',20,255,html::escapeHTML($site)).'</p>'.
269     '</div>'.
270
271     '<div class="cell filters-options">'.
272     '<h4>'.__('Display options').'</h4>'.
273     '<p><label for="sortby" class="ib">'.__('Order by:').'</label> '.
274     form::combo('sortby',$sortby_combo,$sortby).'</p>'.
275     '<p><label for="order" class="ib">'.__('Sort:').'</label> '.
276     form::combo('order',$order_combo,$order).'</p>'.
277     '<p><span class="label ib">'.__('Show').'</span> <label for="nb" class="classic">'.
278     form::field('nb',3,3,$nb_per_page).' '.
279     __('comments per page').'</label></p>'.
280     '</div>'.
281
282     '</div>'.
283     '<p><input type="submit" value="'.__('Apply filters and display options').'" />'.
284     '<br class="clear" /></p>'. //Opera sucks
285     '</form>';
286
287     # Show comments
288     $comment_list->display($page,$nb_per_page,
289     '<form action="'.$core->adminurl->get("admin.comments").'" method="post" id="form-comments">'.
290
291     '%s'.
292
293     '<div class="two-cols">'.
294     '<p class="col checkboxes-helpers"></p>'.
295
296     '<p class="col right"><label for="action" class="classic">'.__('Selected comments action:').'</label> '.
297     form::combo('action',$comments_actions_page->getCombo(),$default,'','','','title="'.__('Actions').'"').
298     $core->formNonce().
299     '<input id="do-action" type="submit" value="'.__('ok').'" /></p>'.
300     form::hidden(array('type'),$type).
301     form::hidden(array('sortby'),$sortby).
302     form::hidden(array('order'),$order).
303     form::hidden(array('author'),html::escapeHTML(preg_replace('/%/','%%',$author))).
304     form::hidden(array('status'),$status).
305     form::hidden(array('ip'),preg_replace('/%/','%%',$ip)).
306     form::hidden(array('page'),$page).
307     form::hidden(array('nb'),$nb_per_page).
308     form::hidden(array('email'),html::escapeHTML(preg_replace('/%/','%%',$email))).
309     form::hidden(array('site'),html::escapeHTML(preg_replace('/%/','%%',$site))).
310     '</div>'.
311
312     '</form>',
313     $show_filters,
314     ($with_spam || ($status == -2))
315     );
316}
317
318dcPage::helpBlock('core_comments');
319dcPage::close();
Note: See TracBrowser for help on using the repository browser.

Sites map