[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 | |
---|
[3725] | 10 | require dirname(__FILE__) . '/../inc/admin/prepend.php'; |
---|
[0] | 11 | |
---|
| 12 | dcPage::check('usage,contentadmin'); |
---|
| 13 | |
---|
| 14 | # Getting categories |
---|
| 15 | try { |
---|
[3725] | 16 | $categories = $core->blog->getCategories(); |
---|
[0] | 17 | } catch (Exception $e) { |
---|
[3725] | 18 | $core->error->add($e->getMessage()); |
---|
[0] | 19 | } |
---|
| 20 | |
---|
| 21 | # Getting authors |
---|
| 22 | try { |
---|
[3725] | 23 | $users = $core->blog->getPostsUsers(); |
---|
[0] | 24 | } catch (Exception $e) { |
---|
[3725] | 25 | $core->error->add($e->getMessage()); |
---|
[0] | 26 | } |
---|
| 27 | |
---|
| 28 | # Getting dates |
---|
| 29 | try { |
---|
[3874] | 30 | $dates = $core->blog->getDates(['type' => 'month']); |
---|
[0] | 31 | } catch (Exception $e) { |
---|
[3725] | 32 | $core->error->add($e->getMessage()); |
---|
[0] | 33 | } |
---|
| 34 | |
---|
| 35 | # Getting langs |
---|
| 36 | try { |
---|
[3725] | 37 | $langs = $core->blog->getLangs(); |
---|
[0] | 38 | } catch (Exception $e) { |
---|
[3725] | 39 | $core->error->add($e->getMessage()); |
---|
[0] | 40 | } |
---|
| 41 | |
---|
| 42 | # Creating filter combo boxes |
---|
[3745] | 43 | $users_combo = dcAdminCombos::getUsersCombo($users); |
---|
| 44 | dcUtils::lexicalKeySort($users_combo); |
---|
| 45 | $users_combo = array_merge( |
---|
[3874] | 46 | ['-' => ''], |
---|
[3745] | 47 | $users_combo |
---|
| 48 | ); |
---|
[1719] | 49 | |
---|
[3745] | 50 | $categories_combo = array_merge( |
---|
[3874] | 51 | [ |
---|
[3745] | 52 | new formSelectOption('-', ''), |
---|
[3874] | 53 | new formSelectOption(__('(No cat)'), 'NULL')], |
---|
[3745] | 54 | dcAdminCombos::getCategoriesCombo($categories, false) |
---|
| 55 | ); |
---|
[3874] | 56 | $categories_values = []; |
---|
[3745] | 57 | foreach ($categories_combo as $cat) { |
---|
| 58 | if (isset($cat->value)) { |
---|
| 59 | $categories_values[$cat->value] = true; |
---|
[3725] | 60 | } |
---|
[3745] | 61 | } |
---|
[2566] | 62 | |
---|
[3745] | 63 | $status_combo = array_merge( |
---|
[3874] | 64 | ['-' => ''], |
---|
[3745] | 65 | dcAdminCombos::getPostStatusesCombo() |
---|
| 66 | ); |
---|
[2566] | 67 | |
---|
[3874] | 68 | $selected_combo = [ |
---|
[3745] | 69 | '-' => '', |
---|
| 70 | __('Selected') => '1', |
---|
| 71 | __('Not selected') => '0' |
---|
[3874] | 72 | ]; |
---|
[2566] | 73 | |
---|
[3874] | 74 | $comment_combo = [ |
---|
[3745] | 75 | '-' => '', |
---|
| 76 | __('Opened') => '1', |
---|
| 77 | __('Closed') => '0' |
---|
[3874] | 78 | ]; |
---|
[3117] | 79 | |
---|
[3874] | 80 | $trackback_combo = [ |
---|
[3745] | 81 | '-' => '', |
---|
| 82 | __('Opened') => '1', |
---|
| 83 | __('Closed') => '0' |
---|
[3874] | 84 | ]; |
---|
[3117] | 85 | |
---|
[3874] | 86 | $attachment_combo = [ |
---|
[3745] | 87 | '-' => '', |
---|
| 88 | __('With attachments') => '1', |
---|
| 89 | __('Without attachments') => '0' |
---|
[3874] | 90 | ]; |
---|
[2309] | 91 | |
---|
[3874] | 92 | $password_combo = [ |
---|
[3745] | 93 | '-' => '', |
---|
| 94 | __('With password') => '1', |
---|
| 95 | __('Without password') => '0' |
---|
[3874] | 96 | ]; |
---|
[3033] | 97 | |
---|
[3745] | 98 | # Months array |
---|
| 99 | $dt_m_combo = array_merge( |
---|
[3874] | 100 | ['-' => ''], |
---|
[3745] | 101 | dcAdminCombos::getDatesCombo($dates) |
---|
| 102 | ); |
---|
[2566] | 103 | |
---|
[3745] | 104 | $lang_combo = array_merge( |
---|
[3874] | 105 | ['-' => ''], |
---|
[3745] | 106 | dcAdminCombos::getLangsCombo($langs, false) |
---|
| 107 | ); |
---|
[2566] | 108 | |
---|
[3745] | 109 | # Post formats |
---|
| 110 | $core_formaters = $core->getFormaters(); |
---|
[3874] | 111 | $available_formats = []; |
---|
[3745] | 112 | foreach ($core_formaters as $editor => $formats) { |
---|
| 113 | foreach ($formats as $format) { |
---|
| 114 | $available_formats[$format] = $format; |
---|
[3725] | 115 | } |
---|
[3745] | 116 | } |
---|
| 117 | $format_combo = array_merge( |
---|
[3874] | 118 | ['-' => ''], |
---|
[3745] | 119 | $available_formats |
---|
| 120 | ); |
---|
[3033] | 121 | |
---|
[3874] | 122 | $sortby_combo = [ |
---|
[3745] | 123 | __('Date') => 'post_dt', |
---|
| 124 | __('Title') => 'post_title', |
---|
| 125 | __('Category') => 'cat_title', |
---|
| 126 | __('Author') => 'user_id', |
---|
| 127 | __('Status') => 'post_status', |
---|
| 128 | __('Selected') => 'post_selected', |
---|
| 129 | __('Number of comments') => 'nb_comment', |
---|
| 130 | __('Number of trackbacks') => 'nb_trackback' |
---|
[3874] | 131 | ]; |
---|
[2566] | 132 | |
---|
[3874] | 133 | $sortby_lex = [ |
---|
[3745] | 134 | // key in sorty_combo (see above) => field in SQL request |
---|
| 135 | 'post_title' => 'post_title', |
---|
| 136 | 'cat_title' => 'cat_title', |
---|
[3874] | 137 | 'user_id' => 'P.user_id']; |
---|
[3360] | 138 | |
---|
[3874] | 139 | $order_combo = [ |
---|
[3745] | 140 | __('Descending') => 'desc', |
---|
| 141 | __('Ascending') => 'asc' |
---|
[3874] | 142 | ]; |
---|
[0] | 143 | |
---|
| 144 | # Actions combo box |
---|
| 145 | |
---|
[3725] | 146 | $posts_actions_page = new dcPostsActionsPage($core, $core->adminurl->get("admin.posts")); |
---|
[1796] | 147 | |
---|
[2072] | 148 | if ($posts_actions_page->process()) { |
---|
[3725] | 149 | return; |
---|
[2072] | 150 | } |
---|
[0] | 151 | |
---|
[2072] | 152 | /* Get posts |
---|
| 153 | -------------------------------------------------------- */ |
---|
[3725] | 154 | $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : ''; |
---|
| 155 | $cat_id = !empty($_GET['cat_id']) ? $_GET['cat_id'] : ''; |
---|
| 156 | $status = isset($_GET['status']) ? $_GET['status'] : ''; |
---|
| 157 | $password = isset($_GET['password']) ? $_GET['password'] : ''; |
---|
| 158 | $selected = isset($_GET['selected']) ? $_GET['selected'] : ''; |
---|
| 159 | $comment = isset($_GET['comment']) ? $_GET['comment'] : ''; |
---|
| 160 | $trackback = isset($_GET['trackback']) ? $_GET['trackback'] : ''; |
---|
[3033] | 161 | $attachment = isset($_GET['attachment']) ? $_GET['attachment'] : ''; |
---|
[3725] | 162 | $month = !empty($_GET['month']) ? $_GET['month'] : ''; |
---|
| 163 | $lang = !empty($_GET['lang']) ? $_GET['lang'] : ''; |
---|
| 164 | $format = !empty($_GET['format']) ? $_GET['format'] : ''; |
---|
| 165 | $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : 'post_dt'; |
---|
| 166 | $order = !empty($_GET['order']) ? $_GET['order'] : 'desc'; |
---|
[0] | 167 | |
---|
[2072] | 168 | $show_filters = false; |
---|
[0] | 169 | |
---|
[3725] | 170 | $page = !empty($_GET['page']) ? max(1, (integer) $_GET['page']) : 1; |
---|
| 171 | $nb_per_page = 30; |
---|
[0] | 172 | |
---|
[2072] | 173 | if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { |
---|
[3725] | 174 | if ($nb_per_page != (integer) $_GET['nb']) { |
---|
| 175 | $show_filters = true; |
---|
| 176 | } |
---|
| 177 | $nb_per_page = (integer) $_GET['nb']; |
---|
[2072] | 178 | } |
---|
[2048] | 179 | |
---|
[3874] | 180 | $params['limit'] = [(($page - 1) * $nb_per_page), $nb_per_page]; |
---|
[2072] | 181 | $params['no_content'] = true; |
---|
[3725] | 182 | $params['where'] = ''; |
---|
[2048] | 183 | |
---|
[2072] | 184 | # - User filter |
---|
[3725] | 185 | if ($user_id !== '' && in_array($user_id, $users_combo)) { |
---|
| 186 | $params['user_id'] = $user_id; |
---|
| 187 | $show_filters = true; |
---|
[2072] | 188 | } else { |
---|
[3725] | 189 | $user_id = ''; |
---|
[2072] | 190 | } |
---|
| 191 | |
---|
| 192 | # - Categories filter |
---|
| 193 | if ($cat_id !== '' && isset($categories_values[$cat_id])) { |
---|
[3725] | 194 | $params['cat_id'] = $cat_id; |
---|
| 195 | $show_filters = true; |
---|
[2072] | 196 | } else { |
---|
[3725] | 197 | $cat_id = ''; |
---|
[2072] | 198 | } |
---|
| 199 | |
---|
| 200 | # - Status filter |
---|
[3725] | 201 | if ($status !== '' && in_array($status, $status_combo)) { |
---|
| 202 | $params['post_status'] = $status; |
---|
| 203 | $show_filters = true; |
---|
[2072] | 204 | } else { |
---|
[3725] | 205 | $status = ''; |
---|
[2072] | 206 | } |
---|
| 207 | |
---|
[3033] | 208 | # - Password filter |
---|
[3725] | 209 | if ($password !== '' && in_array($password, $password_combo)) { |
---|
| 210 | $params['where'] .= ' AND post_password IS ' . ($password ? 'NOT ' : '') . 'NULL '; |
---|
| 211 | $show_filters = true; |
---|
[3033] | 212 | } else { |
---|
[3725] | 213 | $password = ''; |
---|
[3033] | 214 | } |
---|
| 215 | |
---|
[2072] | 216 | # - Selected filter |
---|
[3725] | 217 | if ($selected !== '' && in_array($selected, $selected_combo)) { |
---|
| 218 | $params['post_selected'] = $selected; |
---|
| 219 | $show_filters = true; |
---|
[2072] | 220 | } else { |
---|
[3725] | 221 | $selected = ''; |
---|
[2072] | 222 | } |
---|
| 223 | |
---|
[3117] | 224 | # - Comment filter |
---|
[3725] | 225 | if ($comment !== '' && in_array($comment, $comment_combo)) { |
---|
| 226 | $params['where'] .= " AND post_open_comment = '" . $comment . "' "; |
---|
| 227 | $show_filters = true; |
---|
[3117] | 228 | } else { |
---|
[3725] | 229 | $comment = ''; |
---|
[3117] | 230 | } |
---|
| 231 | |
---|
| 232 | # - Comment filter |
---|
[3725] | 233 | if ($trackback !== '' && in_array($trackback, $trackback_combo)) { |
---|
| 234 | $params['where'] .= " AND post_open_tb = '" . $trackback . "' "; |
---|
| 235 | $show_filters = true; |
---|
[3117] | 236 | } else { |
---|
[3725] | 237 | $trackback = ''; |
---|
[3117] | 238 | } |
---|
| 239 | |
---|
[3033] | 240 | # - Attachment filter |
---|
[3725] | 241 | if ($attachment !== '' && in_array($attachment, $attachment_combo)) { |
---|
| 242 | $params['media'] = $attachment; |
---|
| 243 | $params['link_type'] = 'attachment'; |
---|
| 244 | $show_filters = true; |
---|
[2309] | 245 | } else { |
---|
[3725] | 246 | $attachment = ''; |
---|
[2309] | 247 | } |
---|
| 248 | |
---|
[2072] | 249 | # - Month filter |
---|
[3725] | 250 | if ($month !== '' && in_array($month, $dt_m_combo)) { |
---|
| 251 | $params['post_month'] = substr($month, 4, 2); |
---|
| 252 | $params['post_year'] = substr($month, 0, 4); |
---|
| 253 | $show_filters = true; |
---|
[2072] | 254 | } else { |
---|
[3725] | 255 | $month = ''; |
---|
[2072] | 256 | } |
---|
| 257 | |
---|
| 258 | # - Lang filter |
---|
[3725] | 259 | if ($lang !== '' && in_array($lang, $lang_combo)) { |
---|
| 260 | $params['post_lang'] = $lang; |
---|
| 261 | $show_filters = true; |
---|
[2072] | 262 | } else { |
---|
[3725] | 263 | $lang = ''; |
---|
[2072] | 264 | } |
---|
| 265 | |
---|
[3033] | 266 | # - Format filter |
---|
[3725] | 267 | if ($format !== '' && in_array($format, $format_combo)) { |
---|
| 268 | $params['where'] .= " AND post_format = '" . $format . "' "; |
---|
| 269 | $show_filters = true; |
---|
[3033] | 270 | } else { |
---|
[3725] | 271 | $format = ''; |
---|
[3033] | 272 | } |
---|
| 273 | |
---|
[2072] | 274 | # - Sortby and order filter |
---|
[3725] | 275 | if ($sortby !== '' && in_array($sortby, $sortby_combo)) { |
---|
| 276 | if (array_key_exists($sortby, $sortby_lex)) { |
---|
| 277 | $params['order'] = $core->con->lexFields($sortby_lex[$sortby]); |
---|
| 278 | } else { |
---|
| 279 | $params['order'] = $sortby; |
---|
| 280 | } |
---|
| 281 | if ($order !== '' && in_array($order, $order_combo)) { |
---|
| 282 | $params['order'] .= ' ' . $order; |
---|
| 283 | } else { |
---|
| 284 | $order = 'desc'; |
---|
| 285 | } |
---|
[2566] | 286 | |
---|
[3725] | 287 | if ($sortby != 'post_dt' || $order != 'desc') { |
---|
| 288 | $show_filters = true; |
---|
| 289 | } |
---|
[2072] | 290 | } else { |
---|
[3725] | 291 | $sortby = 'post_dt'; |
---|
| 292 | $order = 'desc'; |
---|
[2072] | 293 | } |
---|
[2048] | 294 | |
---|
[2072] | 295 | # Get posts |
---|
| 296 | try { |
---|
[3725] | 297 | $posts = $core->blog->getPosts($params); |
---|
| 298 | $counter = $core->blog->getPosts($params, true); |
---|
| 299 | $post_list = new adminPostList($core, $posts, $counter->f(0)); |
---|
[2072] | 300 | } catch (Exception $e) { |
---|
[3725] | 301 | $core->error->add($e->getMessage()); |
---|
[2072] | 302 | } |
---|
| 303 | |
---|
| 304 | /* DISPLAY |
---|
| 305 | -------------------------------------------------------- */ |
---|
[2136] | 306 | |
---|
[3397] | 307 | dcPage::open(__('Entries'), |
---|
[3725] | 308 | dcPage::jsLoad('js/_posts_list.js') . dcPage::jsFilterControl($show_filters), |
---|
| 309 | dcPage::breadcrumb( |
---|
[3874] | 310 | [ |
---|
[3725] | 311 | html::escapeHTML($core->blog->name) => '', |
---|
| 312 | __('Entries') => '' |
---|
[3874] | 313 | ]) |
---|
[2072] | 314 | ); |
---|
| 315 | if (!empty($_GET['upd'])) { |
---|
[3725] | 316 | dcPage::success(__('Selected entries have been successfully updated.')); |
---|
[2072] | 317 | } elseif (!empty($_GET['del'])) { |
---|
[3725] | 318 | dcPage::success(__('Selected entries have been successfully deleted.')); |
---|
[2072] | 319 | } |
---|
[3725] | 320 | if (!$core->error->flag()) { |
---|
| 321 | echo |
---|
| 322 | '<p class="top-add"><a class="button add" href="' . $core->adminurl->get("admin.post") . '">' . __('New entry') . '</a></p>' . |
---|
| 323 | '<form action="' . $core->adminurl->get("admin.posts") . '" method="get" id="filters-form">' . |
---|
| 324 | '<h3 class="out-of-screen-if-js">' . __('Show filters and display options') . '</h3>' . |
---|
[2048] | 325 | |
---|
[3725] | 326 | '<div class="table">' . |
---|
| 327 | '<div class="cell">' . |
---|
| 328 | '<h4>' . __('Filters') . '</h4>' . |
---|
| 329 | '<p><label for="user_id" class="ib">' . __('Author:') . '</label> ' . |
---|
| 330 | form::combo('user_id', $users_combo, $user_id) . '</p>' . |
---|
| 331 | '<p><label for="cat_id" class="ib">' . __('Category:') . '</label> ' . |
---|
| 332 | form::combo('cat_id', $categories_combo, $cat_id) . '</p>' . |
---|
| 333 | '<p><label for="status" class="ib">' . __('Status:') . '</label> ' . |
---|
| 334 | form::combo('status', $status_combo, $status) . '</p> ' . |
---|
| 335 | '<p><label for="format" class="ib">' . __('Format:') . '</label> ' . |
---|
| 336 | form::combo('format', $format_combo, $format) . '</p>' . |
---|
| 337 | '<p><label for="password" class="ib">' . __('Password:') . '</label> ' . |
---|
| 338 | form::combo('password', $password_combo, $password) . '</p>' . |
---|
| 339 | '</div>' . |
---|
[2566] | 340 | |
---|
[3725] | 341 | '<div class="cell filters-sibling-cell">' . |
---|
| 342 | '<p><label for="selected" class="ib">' . __('Selected:') . '</label> ' . |
---|
| 343 | form::combo('selected', $selected_combo, $selected) . '</p>' . |
---|
| 344 | '<p><label for="attachment" class="ib">' . __('Attachments:') . '</label> ' . |
---|
| 345 | form::combo('attachment', $attachment_combo, $attachment) . '</p>' . |
---|
| 346 | '<p><label for="month" class="ib">' . __('Month:') . '</label> ' . |
---|
| 347 | form::combo('month', $dt_m_combo, $month) . '</p>' . |
---|
| 348 | '<p><label for="lang" class="ib">' . __('Lang:') . '</label> ' . |
---|
| 349 | form::combo('lang', $lang_combo, $lang) . '</p> ' . |
---|
| 350 | '<p><label for="comment" class="ib">' . __('Comments:') . '</label> ' . |
---|
| 351 | form::combo('comment', $comment_combo, $comment) . '</p>' . |
---|
| 352 | '<p><label for="trackback" class="ib">' . __('Trackbacks:') . '</label> ' . |
---|
| 353 | form::combo('trackback', $trackback_combo, $trackback) . '</p>' . |
---|
| 354 | '</div>' . |
---|
[2566] | 355 | |
---|
[3725] | 356 | '<div class="cell filters-options">' . |
---|
| 357 | '<h4>' . __('Display options') . '</h4>' . |
---|
| 358 | '<p><label for="sortby" class="ib">' . __('Order by:') . '</label> ' . |
---|
| 359 | form::combo('sortby', $sortby_combo, $sortby) . '</p>' . |
---|
| 360 | '<p><label for="order" class="ib">' . __('Sort:') . '</label> ' . |
---|
| 361 | form::combo('order', $order_combo, $order) . '</p>' . |
---|
| 362 | '<p><span class="label ib">' . __('Show') . '</span> <label for="nb" class="classic">' . |
---|
| 363 | form::number('nb', 0, 999, $nb_per_page) . ' ' . |
---|
| 364 | __('entries per page') . '</label></p>' . |
---|
| 365 | '</div>' . |
---|
| 366 | '</div>' . |
---|
[2048] | 367 | |
---|
[3725] | 368 | '<p><input type="submit" value="' . __('Apply filters and display options') . '" />' . |
---|
| 369 | '<br class="clear" /></p>' . //Opera sucks |
---|
| 370 | '</form>'; |
---|
[2566] | 371 | |
---|
[3725] | 372 | # Show posts |
---|
| 373 | $post_list->display($page, $nb_per_page, |
---|
| 374 | '<form action="' . $core->adminurl->get("admin.posts") . '" method="post" id="form-entries">' . |
---|
[2566] | 375 | |
---|
[3725] | 376 | '%s' . |
---|
[2566] | 377 | |
---|
[3725] | 378 | '<div class="two-cols">' . |
---|
| 379 | '<p class="col checkboxes-helpers"></p>' . |
---|
[2566] | 380 | |
---|
[3725] | 381 | '<p class="col right"><label for="action" class="classic">' . __('Selected entries action:') . '</label> ' . |
---|
| 382 | form::combo('action', $posts_actions_page->getCombo()) . |
---|
| 383 | '<input id="do-action" type="submit" value="' . __('ok') . '" disabled /></p>' . |
---|
[3874] | 384 | form::hidden(['user_id'], $user_id) . |
---|
| 385 | form::hidden(['cat_id'], $cat_id) . |
---|
| 386 | form::hidden(['status'], $status) . |
---|
| 387 | form::hidden(['password'], $password) . |
---|
| 388 | form::hidden(['selected'], $selected) . |
---|
| 389 | form::hidden(['comment'], $comment) . |
---|
| 390 | form::hidden(['trackback'], $trackback) . |
---|
| 391 | form::hidden(['attachment'], $attachment) . |
---|
| 392 | form::hidden(['month'], $month) . |
---|
| 393 | form::hidden(['lang'], $lang) . |
---|
| 394 | form::hidden(['sortby'], $sortby) . |
---|
| 395 | form::hidden(['order'], $order) . |
---|
| 396 | form::hidden(['page'], $page) . |
---|
| 397 | form::hidden(['nb'], $nb_per_page) . |
---|
[3725] | 398 | $core->formNonce() . |
---|
| 399 | '</div>' . |
---|
| 400 | '</form>', |
---|
| 401 | $show_filters |
---|
| 402 | ); |
---|
[2072] | 403 | } |
---|
[2048] | 404 | |
---|
[2072] | 405 | dcPage::helpBlock('core_posts'); |
---|
| 406 | dcPage::close(); |
---|