[0] | 1 | <?php |
---|
[3731] | 2 | /** |
---|
| 3 | * @package Dotclear |
---|
| 4 | * @subpackage Backend |
---|
| 5 | * |
---|
| 6 | * @copyright Olivier Meunier & Association Dotclear |
---|
| 7 | * @copyright GPL-2.0-only |
---|
| 8 | */ |
---|
[0] | 9 | |
---|
[3703] | 10 | require dirname(__FILE__) . '/../inc/admin/prepend.php'; |
---|
[0] | 11 | |
---|
| 12 | dcPage::check('usage,contentadmin'); |
---|
| 13 | |
---|
[3703] | 14 | if (!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 | } |
---|
[1052] | 22 | } |
---|
| 23 | |
---|
[0] | 24 | # Creating filter combo boxes |
---|
| 25 | # Filter form we'll put in html_block |
---|
[1719] | 26 | $status_combo = array_merge( |
---|
[3703] | 27 | array('-' => ''), |
---|
| 28 | dcAdminCombos::getCommentStatusescombo() |
---|
[0] | 29 | ); |
---|
[1719] | 30 | |
---|
[0] | 31 | $type_combo = array( |
---|
[3703] | 32 | '-' => '', |
---|
| 33 | __('Comment') => 'co', |
---|
| 34 | __('Trackback') => 'tb' |
---|
[0] | 35 | ); |
---|
| 36 | |
---|
| 37 | $sortby_combo = array( |
---|
[3703] | 38 | __('Date') => 'comment_dt', |
---|
| 39 | __('Entry title') => 'post_title', |
---|
| 40 | __('Entry date') => 'post_dt', |
---|
| 41 | __('Author') => 'comment_author', |
---|
| 42 | __('Status') => 'comment_status' |
---|
[0] | 43 | ); |
---|
| 44 | |
---|
[3360] | 45 | $sortby_lex = array( |
---|
[3703] | 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'); |
---|
[3360] | 50 | |
---|
[0] | 51 | $order_combo = array( |
---|
[3703] | 52 | __('Descending') => 'desc', |
---|
| 53 | __('Ascending') => 'asc' |
---|
[0] | 54 | ); |
---|
| 55 | |
---|
| 56 | /* Get comments |
---|
| 57 | -------------------------------------------------------- */ |
---|
[3263] | 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'] : ''; |
---|
[0] | 66 | |
---|
| 67 | $with_spam = $author || $status || $type || $sortby != 'comment_dt' || $order != 'desc' || $ip; |
---|
| 68 | |
---|
| 69 | $show_filters = false; |
---|
| 70 | |
---|
[3703] | 71 | $page = !empty($_GET['page']) ? max(1, (integer) $_GET['page']) : 1; |
---|
| 72 | $nb_per_page = 30; |
---|
[0] | 73 | |
---|
[2888] | 74 | if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { |
---|
[3703] | 75 | if ($nb_per_page != (integer) $_GET['nb']) { |
---|
| 76 | $show_filters = true; |
---|
| 77 | } |
---|
| 78 | $nb_per_page = (integer) $_GET['nb']; |
---|
[0] | 79 | } |
---|
| 80 | |
---|
[3703] | 81 | $params['limit'] = array((($page - 1) * $nb_per_page), $nb_per_page); |
---|
[0] | 82 | $params['no_content'] = true; |
---|
| 83 | |
---|
| 84 | # Author filter |
---|
| 85 | if ($author !== '') { |
---|
[3703] | 86 | $params['q_author'] = $author; |
---|
| 87 | $show_filters = true; |
---|
[796] | 88 | } else { |
---|
[3703] | 89 | $author = ''; |
---|
[0] | 90 | } |
---|
| 91 | |
---|
| 92 | # - Type filter |
---|
| 93 | if ($type == 'tb' || $type == 'co') { |
---|
[3703] | 94 | $params['comment_trackback'] = ($type == 'tb'); |
---|
| 95 | $show_filters = true; |
---|
[796] | 96 | } else { |
---|
[3703] | 97 | $type = ''; |
---|
[0] | 98 | } |
---|
| 99 | |
---|
| 100 | # - Status filter |
---|
[3703] | 101 | if ($status !== '' && in_array($status, $status_combo)) { |
---|
| 102 | $params['comment_status'] = $status; |
---|
| 103 | $show_filters = true; |
---|
[0] | 104 | } elseif (!$with_spam) { |
---|
[3703] | 105 | $params['comment_status_not'] = -2; |
---|
| 106 | $status = ''; |
---|
[796] | 107 | } else { |
---|
[3703] | 108 | $status = ''; |
---|
[0] | 109 | } |
---|
| 110 | |
---|
| 111 | # - IP filter |
---|
| 112 | if ($ip) { |
---|
[3703] | 113 | $params['comment_ip'] = $ip; |
---|
| 114 | $show_filters = true; |
---|
[0] | 115 | } |
---|
| 116 | |
---|
[3263] | 117 | # - email filter |
---|
| 118 | if ($email) { |
---|
[3703] | 119 | $params['comment_email'] = $email; |
---|
| 120 | $show_filters = true; |
---|
[3263] | 121 | } |
---|
| 122 | |
---|
| 123 | # - site filter |
---|
| 124 | if ($site) { |
---|
[3703] | 125 | $params['comment_site'] = $site; |
---|
| 126 | $show_filters = true; |
---|
[3263] | 127 | } |
---|
| 128 | |
---|
[3044] | 129 | // Add some sort order if spams displayed |
---|
| 130 | if ($with_spam || ($status == -2)) { |
---|
[3703] | 131 | $sortby_combo[__('IP')] = 'comment_ip'; |
---|
| 132 | $sortby_combo[__('Spam filter')] = 'comment_spam_filter'; |
---|
[3044] | 133 | } |
---|
| 134 | |
---|
[0] | 135 | # Sortby and order filter |
---|
[3703] | 136 | if ($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 | } |
---|
[2566] | 147 | |
---|
[3703] | 148 | if ($sortby != 'comment_dt' || $order != 'desc') { |
---|
| 149 | $show_filters = true; |
---|
| 150 | } |
---|
[796] | 151 | } else { |
---|
[3703] | 152 | $sortby = 'comment_dt'; |
---|
| 153 | $order = 'desc'; |
---|
[0] | 154 | } |
---|
| 155 | |
---|
| 156 | # Actions combo box |
---|
| 157 | $combo_action = array(); |
---|
[3703] | 158 | $default = ''; |
---|
| 159 | if ($core->auth->check('delete,contentadmin', $core->blog->id) && $status == -2) { |
---|
| 160 | $default = 'delete'; |
---|
[0] | 161 | } |
---|
| 162 | |
---|
[3703] | 163 | $comments_actions_page = new dcCommentsActionsPage($core, $core->adminurl->get("admin.comments")); |
---|
[1905] | 164 | |
---|
[2498] | 165 | if ($comments_actions_page->process()) { |
---|
[3703] | 166 | return; |
---|
[2498] | 167 | } |
---|
[0] | 168 | |
---|
| 169 | /* Get comments |
---|
| 170 | -------------------------------------------------------- */ |
---|
| 171 | try { |
---|
[3703] | 172 | $comments = $core->blog->getComments($params); |
---|
| 173 | $counter = $core->blog->getComments($params, true); |
---|
| 174 | $comment_list = new adminCommentList($core, $comments, $counter->f(0)); |
---|
[0] | 175 | } catch (Exception $e) { |
---|
[3703] | 176 | $core->error->add($e->getMessage()); |
---|
[0] | 177 | } |
---|
| 178 | |
---|
| 179 | /* DISPLAY |
---|
| 180 | -------------------------------------------------------- */ |
---|
[2136] | 181 | |
---|
[3397] | 182 | dcPage::open(__('Comments and trackbacks'), |
---|
[3703] | 183 | dcPage::jsLoad('js/_comments.js') . dcPage::jsFilterControl($show_filters), |
---|
| 184 | dcPage::breadcrumb( |
---|
| 185 | array( |
---|
| 186 | html::escapeHTML($core->blog->name) => '', |
---|
| 187 | __('Comments and trackbacks') => '' |
---|
| 188 | )) |
---|
[1358] | 189 | ); |
---|
[2888] | 190 | if (!empty($_GET['upd'])) { |
---|
[3703] | 191 | dcPage::success(__('Selected comments have been successfully updated.')); |
---|
[2888] | 192 | } elseif (!empty($_GET['del'])) { |
---|
[3703] | 193 | dcPage::success(__('Selected comments have been successfully deleted.')); |
---|
[1905] | 194 | } |
---|
[0] | 195 | |
---|
[3703] | 196 | if (!$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 | } |
---|
[2566] | 201 | |
---|
[3703] | 202 | $spam_count = $core->blog->getComments(array('comment_status' => -2), true)->f(0); |
---|
| 203 | if ($spam_count > 0) { |
---|
[2566] | 204 | |
---|
[3703] | 205 | echo |
---|
| 206 | '<form action="' . $core->adminurl->get("admin.comments") . '" method="post" class="fieldset">'; |
---|
[1052] | 207 | |
---|
[3703] | 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", array('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", array('status' => -2)) . '">' . __('Show them.') . '</a></p>'; |
---|
| 215 | } |
---|
| 216 | } |
---|
[2566] | 217 | |
---|
[3703] | 218 | echo |
---|
| 219 | '<p>' . |
---|
| 220 | $core->formNonce() . |
---|
| 221 | '<input name="delete_all_spam" class="delete" type="submit" value="' . __('Delete all spams') . '" /></p>'; |
---|
[1051] | 222 | |
---|
[3703] | 223 | # --BEHAVIOR-- adminCommentsSpamForm |
---|
| 224 | $core->callBehavior('adminCommentsSpamForm', $core); |
---|
[1051] | 225 | |
---|
[3703] | 226 | echo '</form>'; |
---|
| 227 | } |
---|
[2566] | 228 | |
---|
[3703] | 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>' . |
---|
[3397] | 232 | |
---|
[3703] | 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>' . |
---|
[2566] | 241 | |
---|
[3703] | 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>' . |
---|
[2566] | 252 | |
---|
[3703] | 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">' . |
---|
[3725] | 260 | form::number('nb', 0, 999, $nb_per_page) . ' ' . |
---|
[3703] | 261 | __('comments per page') . '</label></p>' . |
---|
| 262 | '</div>' . |
---|
[2566] | 263 | |
---|
[3703] | 264 | '</div>' . |
---|
| 265 | '<p><input type="submit" value="' . __('Apply filters and display options') . '" />' . |
---|
| 266 | '<br class="clear" /></p>' . //Opera sucks |
---|
| 267 | '</form>'; |
---|
[2566] | 268 | |
---|
[3703] | 269 | # Show comments |
---|
| 270 | $comment_list->display($page, $nb_per_page, |
---|
| 271 | '<form action="' . $core->adminurl->get("admin.comments") . '" method="post" id="form-comments">' . |
---|
[2566] | 272 | |
---|
[3703] | 273 | '%s' . |
---|
[2566] | 274 | |
---|
[3703] | 275 | '<div class="two-cols">' . |
---|
| 276 | '<p class="col checkboxes-helpers"></p>' . |
---|
[2566] | 277 | |
---|
[3703] | 278 | '<p class="col right"><label for="action" class="classic">' . __('Selected comments action:') . '</label> ' . |
---|
| 279 | form::combo('action', $comments_actions_page->getCombo(), |
---|
| 280 | array('default' => $default, 'extra_html' => 'title="' . __('Actions') . '"')) . |
---|
| 281 | $core->formNonce() . |
---|
| 282 | '<input id="do-action" type="submit" value="' . __('ok') . '" /></p>' . |
---|
| 283 | form::hidden(array('type'), $type) . |
---|
| 284 | form::hidden(array('sortby'), $sortby) . |
---|
| 285 | form::hidden(array('order'), $order) . |
---|
| 286 | form::hidden(array('author'), html::escapeHTML(preg_replace('/%/', '%%', $author))) . |
---|
| 287 | form::hidden(array('status'), $status) . |
---|
| 288 | form::hidden(array('ip'), preg_replace('/%/', '%%', $ip)) . |
---|
| 289 | form::hidden(array('page'), $page) . |
---|
| 290 | form::hidden(array('nb'), $nb_per_page) . |
---|
| 291 | form::hidden(array('email'), html::escapeHTML(preg_replace('/%/', '%%', $email))) . |
---|
| 292 | form::hidden(array('site'), html::escapeHTML(preg_replace('/%/', '%%', $site))) . |
---|
| 293 | '</div>' . |
---|
[2566] | 294 | |
---|
[3703] | 295 | '</form>', |
---|
| 296 | $show_filters, |
---|
| 297 | ($with_spam || ($status == -2)) |
---|
| 298 | ); |
---|
[0] | 299 | } |
---|
| 300 | |
---|
| 301 | dcPage::helpBlock('core_comments'); |
---|
| 302 | dcPage::close(); |
---|