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