Dotclear

source: admin/comments.php @ 1334:bbbe0735f18b

Revision 1334:bbbe0735f18b, 7.6 KB checked in by franck <carnet.franck.paul@…>, 11 years ago (diff)

New dcPage::breadcrumb function, better way to use it, to be continued by me…

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
173dcPage::breadcrumb(
174     array(
175          html::escapeHTML($core->blog->name) => '',
176          '<span class="page-title">'.__('Comments and trackbacks').'</span>' => ''
177     ));
178
179if (!$core->error->flag())
180{
181     if (isset($_SESSION['comments_del_spam'])) {
182          dcPage::message(__('Spam comments have been successfully deleted.'));
183          unset($_SESSION['comments_del_spam']);
184     }
185     
186     # Filters
187     if (!$show_filters) {
188          echo '<p><a id="filter-control" class="form-control" href="#">'.
189          __('Filters').'</a></p>';
190     }
191     
192     echo
193     '<form action="comments.php" method="get" id="filters-form">'.
194     '<fieldset><legend>'.__('Filters').'</legend>'.
195     '<div class="three-cols">'.
196     '<div class="col">'.
197     '<label for="type">'.__('Type:').' '.
198     form::combo('type',$type_combo,$type).
199     '</label> '.
200     '<label for="status">'.__('Status:').' '.
201     form::combo('status',$status_combo,$status).
202     '</label>'.
203     '</div>'.
204     
205     '<div class="col">'.
206     '<p><label for="sortby">'.__('Order by:').' '.
207     form::combo('sortby',$sortby_combo,$sortby).
208     '</label> '.
209     '<label for="order">'.__('Sort:').' '.
210     form::combo('order',$order_combo,$order).
211     '</label></p>'.
212     '<p><label for="nb" class="classic">'.  form::field('nb',3,3,$nb_per_page).' '.
213     __('Comments per page').'</label></p>'.
214     '</div>'.
215     
216     '<div class="col">'.
217     '<p><label for="author">'.__('Comment author:').' '.
218     form::field('author',20,255,html::escapeHTML($author)).
219     '</label>'.
220     '<label for="ip">'.__('IP address:').' '.
221     form::field('ip',20,39,html::escapeHTML($ip)).
222     '</label></p>'.
223     '<p><input type="submit" value="'.__('Apply filters').'" /></p>'.
224     '</div>'.
225     
226     '</div>'.
227     '<br class="clear" />'. //Opera sucks
228     '</fieldset>'.
229     '</form>';
230     
231     $spam_count = $core->blog->getComments(array('comment_status'=>-2),true)->f(0);
232     if ($spam_count > 0) {
233         
234          echo 
235               '<form action="comments.php" method="post" class="fieldset">';
236
237          if (!$with_spam || ($status != -2)) {
238               if ($spam_count == 1) {
239                    echo '<p>'.sprintf(__('You have one spam comments.'),'<strong>'.$spam_count.'</strong>').' '.
240                    '<a href="comments.php?status=-2">'.__('Show it.').'</a></p>';
241               } elseif ($spam_count > 1) {
242                    echo '<p>'.sprintf(__('You have %s spam comments.'),'<strong>'.$spam_count.'</strong>').' '.
243                    '<a href="comments.php?status=-2">'.__('Show them.').'</a></p>';
244               }
245          }
246         
247          echo
248               $core->formNonce().
249               '<input name="delete_all_spam" class="delete" type="submit" value="'.__('Delete all spams').'" /></p>';
250
251          # --BEHAVIOR-- adminCommentsSpamForm
252          $core->callBehavior('adminCommentsSpamForm',$core);
253
254          echo '</form>';
255     }
256     
257     # Show comments
258     $comment_list->display($page,$nb_per_page,
259     '<form action="comments_actions.php" method="post" id="form-comments">'.
260     
261     '%s'.
262     
263     '<div class="two-cols">'.
264     '<p class="col checkboxes-helpers"></p>'.
265     
266     '<p class="col right"><label for="action" class="classic">'.__('Selected comments action:').'</label> '.
267     form::combo('action',$combo_action,$default,'','','','title="'.__('action: ').'"').
268     $core->formNonce().
269     '<input type="submit" value="'.__('ok').'" /></p>'.
270     form::hidden(array('type'),$type).
271     form::hidden(array('sortby'),$sortby).
272     form::hidden(array('order'),$order).
273     form::hidden(array('author'),preg_replace('/%/','%%',$author)).
274     form::hidden(array('status'),$status).
275     form::hidden(array('ip'),preg_replace('/%/','%%',$ip)).
276     form::hidden(array('page'),$page).
277     form::hidden(array('nb'),$nb_per_page).
278     '</div>'.
279     
280     '</form>'
281     );
282}
283
284dcPage::helpBlock('core_comments');
285dcPage::close();
286?>
Note: See TracBrowser for help on using the repository browser.

Sites map