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