Dotclear

source: admin/comments.php @ 45:282249d3b55d

Revision 45:282249d3b55d, 6.5 KB checked in by kozlika, 14 years ago (diff)

Correction des formulaires, étape 2

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2010 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}
76
77# - Type filter
78if ($type == 'tb' || $type == 'co') {
79     $params['comment_trackback'] = ($type == 'tb');
80     $show_filters = true;
81}
82
83# - Status filter
84if ($status !== '' && in_array($status,$status_combo)) {
85     $params['comment_status'] = $status;
86     $show_filters = true;
87} elseif (!$with_spam) {
88     $params['comment_status_not'] = -2;
89}
90
91# - IP filter
92if ($ip) {
93     $params['comment_ip'] = $ip;
94     $show_filters = true;
95}
96
97# Sortby and order filter
98if ($sortby !== '' && in_array($sortby,$sortby_combo)) {
99     if ($order !== '' && in_array($order,$order_combo)) {
100          $params['order'] = $sortby.' '.$order;
101     }
102     
103     if ($sortby != 'comment_dt' || $order != 'desc') {
104          $show_filters = true;
105     }
106}
107
108# Actions combo box
109$combo_action = array();
110if ($core->auth->check('publish,contentadmin',$core->blog->id))
111{
112     $combo_action[__('publish')] = 'publish';
113     $combo_action[__('unpublish')] = 'unpublish';
114     $combo_action[__('mark as pending')] = 'pending';
115     $combo_action[__('mark as junk')] = 'junk';
116}
117if ($core->auth->check('delete,contentadmin',$core->blog->id))
118{
119     $combo_action[__('delete')] = 'delete';
120}
121
122# --BEHAVIOR-- adminCommentsActionsCombo
123$core->callBehavior('adminCommentsActionsCombo',array(&$combo_action));
124
125/* Get comments
126-------------------------------------------------------- */
127try {
128     $comments = $core->blog->getComments($params);
129     $counter = $core->blog->getComments($params,true);
130     $comment_list = new adminCommentList($core,$comments,$counter->f(0));
131} catch (Exception $e) {
132     $core->error->add($e->getMessage());
133}
134
135/* DISPLAY
136-------------------------------------------------------- */
137$starting_script = dcPage::jsLoad('js/_comments.js');
138if (!$show_filters) {
139     $starting_script .= dcPage::jsLoad('js/filter-controls.js');
140}
141# --BEHAVIOR-- adminCommentsHeaders
142$starting_script .= $core->callBehavior('adminCommentsHeaders');
143
144dcPage::open(__('Comments'),$starting_script);
145
146echo '<h2>'.html::escapeHTML($core->blog->name).' &rsaquo; '.__('Comments').'</h2>';
147
148if (!$core->error->flag())
149{
150     # Filters
151     if (!$show_filters) {
152          echo '<p><a id="filter-control" class="form-control" href="#">'.
153          __('Filters').'</a></p>';
154     }
155     
156     echo
157     '<form action="comments.php" method="get" id="filters-form">'.
158     '<fieldset><legend>'.__('Filters').'</legend>'.
159     '<div class="three-cols">'.
160     '<div class="col">'.
161     '<label for="type">'.__('Type:').' '.
162     form::combo('type',$type_combo,$type).
163     '</label> '.
164     '<label for="status">'.__('Status:').' '.
165     form::combo('status',$status_combo,$status).
166     '</label>'.
167     '</div>'.
168     
169     '<div class="col">'.
170     '<p><label for="sortby">'.__('Order by:').' '.
171     form::combo('sortby',$sortby_combo,$sortby).
172     '</label> '.
173     '<label for="order">'.__('Sort:').' '.
174     form::combo('order',$order_combo,$order).
175     '</label></p>'.
176     '<p><label for="nb" class="classic">'.  form::field('nb',3,3,$nb_per_page).' '.
177     __('Comments per page').'</label></p>'.
178     '</div>'.
179     
180     '<div class="col">'.
181     '<p><label for="author">'.__('Comment author:').' '.
182     form::field('author',20,255,html::escapeHTML($author)).
183     '</label>'.
184     '<label for="ip">'.__('IP address:').' '.
185     form::field('ip',20,39,html::escapeHTML($ip)).
186     '</label></p>'.
187     '<p><input type="submit" value="'.__('Apply filters').'" /></p>'.
188     '</div>'.
189     
190     '</div>'.
191     '<br class="clear" />'. //Opera sucks
192     '</fieldset>'.
193     '</form>';
194     
195     if (!$with_spam) {
196          $spam_count = $core->blog->getComments(array('comment_status'=>-2),true)->f(0);
197          if ($spam_count == 1) {
198               echo '<p>'.sprintf(__('You have one spam comments.'),'<strong>'.$spam_count.'</strong>').' '.
199               '<a href="comments.php?status=-2">'.__('Show it.').'</a></p>';
200          } elseif ($spam_count > 1) {
201               echo '<p>'.sprintf(__('You have %s spam comments.'),'<strong>'.$spam_count.'</strong>').' '.
202               '<a href="comments.php?status=-2">'.__('Show them.').'</a></p>';
203          }
204     }
205     
206     # Show comments
207     $comment_list->display($page,$nb_per_page,
208     '<form action="comments_actions.php" method="post" id="form-comments">'.
209     
210     '%s'.
211     
212     '<div class="two-cols">'.
213     '<p class="col checkboxes-helpers"></p>'.
214     
215     '<p class="col right"><label for="action" class="inline">'.__('Selected comments action:').'</label> '.
216     form::combo('action',$combo_action,'','','','','title="'.__('action: ').'"').
217     $core->formNonce().
218     '<input type="submit" value="'.__('ok').'" /></p>'.
219     form::hidden(array('type'),$type).
220     form::hidden(array('sortby'),$sortby).
221     form::hidden(array('order'),$order).
222     form::hidden(array('author'),preg_replace('/%/','%%',$author)).
223     form::hidden(array('status'),$status).
224     form::hidden(array('ip'),preg_replace('/%/','%%',$ip)).
225     form::hidden(array('page'),$page).
226     form::hidden(array('nb'),$nb_per_page).
227     '</div>'.
228     
229     '</form>'
230     );
231}
232
233dcPage::helpBlock('core_comments');
234dcPage::close();
235?>
Note: See TracBrowser for help on using the repository browser.

Sites map