Dotclear

source: admin/comments.php @ 1719:b8c48f380463

Revision 1719:b8c48f380463, 7.8 KB checked in by Dsls, 12 years ago (diff)

Added dcAdminCombos utility class, lots of combos available from everywhere now. Closes #1599

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

Sites map