Dotclear

source: admin/comments.php @ 3703:53c8bef8608a

Revision 3703:53c8bef8608a, 10.1 KB checked in by franck <carnet.franck.paul@…>, 6 years ago (diff)

Use array form of optionnal parameters for form::combo(), code formatting (PSR-2)

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

Sites map