Dotclear

source: admin/comments.php @ 3874:ab8368569446

Revision 3874:ab8368569446, 9.8 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

short notation for array (array() → [])

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

Sites map