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 | |
---|
13 | require dirname(__FILE__).'/../inc/admin/prepend.php'; |
---|
14 | |
---|
15 | dcPage::check('usage,contentadmin'); |
---|
16 | |
---|
17 | if (!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 | ); |
---|
33 | foreach ($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 | |
---|
72 | if (!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 |
---|
83 | if ($author !== '') { |
---|
84 | $params['q_author'] = $author; |
---|
85 | $show_filters = true; |
---|
86 | } else { |
---|
87 | $author=''; |
---|
88 | } |
---|
89 | |
---|
90 | # - Type filter |
---|
91 | if ($type == 'tb' || $type == 'co') { |
---|
92 | $params['comment_trackback'] = ($type == 'tb'); |
---|
93 | $show_filters = true; |
---|
94 | } else { |
---|
95 | $type=''; |
---|
96 | } |
---|
97 | |
---|
98 | # - Status filter |
---|
99 | if ($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 |
---|
110 | if ($ip) { |
---|
111 | $params['comment_ip'] = $ip; |
---|
112 | $show_filters = true; |
---|
113 | } |
---|
114 | |
---|
115 | # Sortby and order filter |
---|
116 | if ($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 = ''; |
---|
134 | if ($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 | } |
---|
141 | if ($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 | -------------------------------------------------------- */ |
---|
154 | try { |
---|
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'); |
---|
165 | if (!$show_filters) { |
---|
166 | $starting_script .= dcPage::jsLoad('js/filter-controls.js'); |
---|
167 | } |
---|
168 | # --BEHAVIOR-- adminCommentsHeaders |
---|
169 | $starting_script .= $core->callBehavior('adminCommentsHeaders'); |
---|
170 | |
---|
171 | dcPage::open(__('Comments and trackbacks'),$starting_script, |
---|
172 | dcPage::breadcrumb( |
---|
173 | array( |
---|
174 | html::escapeHTML($core->blog->name) => '', |
---|
175 | '<span class="page-title">'.__('Comments and trackbacks').'</span>' => '' |
---|
176 | )) |
---|
177 | ); |
---|
178 | |
---|
179 | if (!$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 | $spam_count = $core->blog->getComments(array('comment_status'=>-2),true)->f(0); |
---|
187 | if ($spam_count > 0) { |
---|
188 | |
---|
189 | echo |
---|
190 | '<form action="comments.php" method="post" class="fieldset">'; |
---|
191 | |
---|
192 | if (!$with_spam || ($status != -2)) { |
---|
193 | if ($spam_count == 1) { |
---|
194 | echo '<p>'.sprintf(__('You have one spam comment.'),'<strong>'.$spam_count.'</strong>').' '. |
---|
195 | '<a href="comments.php?status=-2">'.__('Show it.').'</a></p>'; |
---|
196 | } elseif ($spam_count > 1) { |
---|
197 | echo '<p>'.sprintf(__('You have %s spam comments.'),'<strong>'.$spam_count.'</strong>').' '. |
---|
198 | '<a href="comments.php?status=-2">'.__('Show them.').'</a></p>'; |
---|
199 | } |
---|
200 | } |
---|
201 | |
---|
202 | echo |
---|
203 | '<p class="no-margin">'. |
---|
204 | $core->formNonce(). |
---|
205 | '<input name="delete_all_spam" class="delete" type="submit" value="'.__('Delete all spams').'" /></p>'; |
---|
206 | |
---|
207 | # --BEHAVIOR-- adminCommentsSpamForm |
---|
208 | $core->callBehavior('adminCommentsSpamForm',$core); |
---|
209 | |
---|
210 | echo '</form>'; |
---|
211 | } |
---|
212 | |
---|
213 | # Filters |
---|
214 | if (!$show_filters) { |
---|
215 | echo '<p><a id="filter-control" class="form-control" href="#">'. |
---|
216 | __('Filter comments and trackbacks list').'</a></p>'; |
---|
217 | } |
---|
218 | |
---|
219 | echo |
---|
220 | '<form action="comments.php" method="get" id="filters-form">'. |
---|
221 | '<h3>'.__('Filter comments and trackbacks list').'</h3>'. |
---|
222 | '<div class="table">'. |
---|
223 | |
---|
224 | '<div class="cell">'. |
---|
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">'. |
---|
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 | '<p><label for="sortby" class="ib">'.__('Order by:').'</label> '. |
---|
240 | form::combo('sortby',$sortby_combo,$sortby).'</p>'. |
---|
241 | '<p><label for="order" class="ib">'.__('Sort:').'</label> '. |
---|
242 | form::combo('order',$order_combo,$order).'</p>'. |
---|
243 | '<p><span class="label ib">Afficher</span> <label for="nb" class="classic">'. |
---|
244 | form::field('nb',3,3,$nb_per_page).' '. |
---|
245 | __('comments per page').'</label></p>'. |
---|
246 | '</div>'. |
---|
247 | |
---|
248 | '</div>'. |
---|
249 | '<p><input type="submit" value="'.__('Apply filters').'" />'. |
---|
250 | '<br class="clear" /></p>'. //Opera sucks |
---|
251 | '</form>'; |
---|
252 | |
---|
253 | # Show comments |
---|
254 | $comment_list->display($page,$nb_per_page, |
---|
255 | '<form action="comments_actions.php" method="post" id="form-comments">'. |
---|
256 | |
---|
257 | '%s'. |
---|
258 | |
---|
259 | '<div class="two-cols">'. |
---|
260 | '<p class="col checkboxes-helpers"></p>'. |
---|
261 | |
---|
262 | '<p class="col right"><label for="action" class="classic">'.__('Selected comments action:').'</label> '. |
---|
263 | form::combo('action',$combo_action,$default,'','','','title="'.__('action: ').'"'). |
---|
264 | $core->formNonce(). |
---|
265 | '<input type="submit" value="'.__('ok').'" /></p>'. |
---|
266 | form::hidden(array('type'),$type). |
---|
267 | form::hidden(array('sortby'),$sortby). |
---|
268 | form::hidden(array('order'),$order). |
---|
269 | form::hidden(array('author'),preg_replace('/%/','%%',$author)). |
---|
270 | form::hidden(array('status'),$status). |
---|
271 | form::hidden(array('ip'),preg_replace('/%/','%%',$ip)). |
---|
272 | form::hidden(array('page'),$page). |
---|
273 | form::hidden(array('nb'),$nb_per_page). |
---|
274 | '</div>'. |
---|
275 | |
---|
276 | '</form>' |
---|
277 | ); |
---|
278 | } |
---|
279 | |
---|
280 | dcPage::helpBlock('core_comments'); |
---|
281 | dcPage::close(); |
---|
282 | ?> |
---|