[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 |
---|
[1719] | 49 | $users_combo = array_merge( |
---|
| 50 | array('-' => ''), |
---|
| 51 | dcAdminCombos::getUsersCombo($users) |
---|
| 52 | ); |
---|
| 53 | |
---|
| 54 | $categories_combo = array_merge( |
---|
[1775] | 55 | array( |
---|
| 56 | new formSelectOption('-',''), |
---|
[2566] | 57 | new formSelectOption(__('(No cat)'),'NULL')), |
---|
[1775] | 58 | dcAdminCombos::getCategoriesCombo($categories,false) |
---|
[1719] | 59 | ); |
---|
[1775] | 60 | $categories_values = array(); |
---|
| 61 | foreach ($categories_combo as $cat) { |
---|
| 62 | if (isset($cat->value)) { |
---|
| 63 | $categories_values[$cat->value]=true; |
---|
[0] | 64 | } |
---|
| 65 | } |
---|
[2566] | 66 | |
---|
[1719] | 67 | $status_combo = array_merge( |
---|
| 68 | array('-' => ''), |
---|
[2566] | 69 | dcAdminCombos::getPostStatusesCombo() |
---|
[0] | 70 | ); |
---|
[2566] | 71 | |
---|
[0] | 72 | $selected_combo = array( |
---|
| 73 | '-' => '', |
---|
[1353] | 74 | __('Selected') => '1', |
---|
| 75 | __('Not selected') => '0' |
---|
[0] | 76 | ); |
---|
[2566] | 77 | |
---|
[2309] | 78 | $attachment_combo = array( |
---|
| 79 | '-' => '', |
---|
| 80 | __('With attachments') => '1', |
---|
| 81 | __('Without attachments') => '0' |
---|
| 82 | ); |
---|
| 83 | |
---|
[3033] | 84 | $password_combo = array( |
---|
| 85 | '-' => '', |
---|
| 86 | __('With password') => '1', |
---|
| 87 | __('Without password') => '0' |
---|
| 88 | ); |
---|
| 89 | |
---|
[0] | 90 | # Months array |
---|
[1719] | 91 | $dt_m_combo = array_merge( |
---|
| 92 | array('-' => ''), |
---|
| 93 | dcAdminCombos::getDatesCombo($dates) |
---|
| 94 | ); |
---|
[2566] | 95 | |
---|
[1719] | 96 | $lang_combo = array_merge( |
---|
| 97 | array('-' => ''), |
---|
[2566] | 98 | dcAdminCombos::getLangsCombo($langs,false) |
---|
[1719] | 99 | ); |
---|
[2566] | 100 | |
---|
[3033] | 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 | |
---|
[0] | 114 | $sortby_combo = array( |
---|
| 115 | __('Date') => 'post_dt', |
---|
| 116 | __('Title') => 'post_title', |
---|
| 117 | __('Category') => 'cat_title', |
---|
| 118 | __('Author') => 'user_id', |
---|
| 119 | __('Status') => 'post_status', |
---|
[2305] | 120 | __('Selected') => 'post_selected', |
---|
| 121 | __('Number of comments') => 'nb_comment', |
---|
[3033] | 122 | __('Number of trackbacks') => 'nb_trackback' |
---|
[0] | 123 | ); |
---|
[2566] | 124 | |
---|
[0] | 125 | $order_combo = array( |
---|
| 126 | __('Descending') => 'desc', |
---|
| 127 | __('Ascending') => 'asc' |
---|
| 128 | ); |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | # Actions combo box |
---|
| 132 | |
---|
[2720] | 133 | $posts_actions_page = new dcPostsActionsPage($core,$core->adminurl->get("admin.posts")); |
---|
[1796] | 134 | |
---|
[2072] | 135 | if ($posts_actions_page->process()) { |
---|
| 136 | return; |
---|
| 137 | } |
---|
[0] | 138 | |
---|
[2072] | 139 | /* Get posts |
---|
| 140 | -------------------------------------------------------- */ |
---|
[3033] | 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'] : ''; |
---|
[2072] | 150 | $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : 'post_dt'; |
---|
[3033] | 151 | $order = !empty($_GET['order']) ? $_GET['order'] : 'desc'; |
---|
[0] | 152 | |
---|
[2072] | 153 | $show_filters = false; |
---|
[0] | 154 | |
---|
[2072] | 155 | $page = !empty($_GET['page']) ? max(1,(integer) $_GET['page']) : 1; |
---|
| 156 | $nb_per_page = 30; |
---|
[0] | 157 | |
---|
[2072] | 158 | if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { |
---|
| 159 | if ($nb_per_page != $_GET['nb']) { |
---|
| 160 | $show_filters = true; |
---|
[2048] | 161 | } |
---|
[2072] | 162 | $nb_per_page = (integer) $_GET['nb']; |
---|
| 163 | } |
---|
[2048] | 164 | |
---|
[2072] | 165 | $params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page); |
---|
| 166 | $params['no_content'] = true; |
---|
[3033] | 167 | $params['where'] = ''; |
---|
[2048] | 168 | |
---|
[2072] | 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 | |
---|
[3033] | 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 | |
---|
[2072] | 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 | |
---|
[3033] | 209 | # - Attachment filter |
---|
[2309] | 210 | if ($attachment !== '' && in_array($attachment,$attachment_combo)) { |
---|
| 211 | $params['media'] = $attachment; |
---|
[2312] | 212 | $params['link_type'] = 'attachment'; |
---|
[2309] | 213 | $show_filters = true; |
---|
| 214 | } else { |
---|
| 215 | $attachment=''; |
---|
| 216 | } |
---|
| 217 | |
---|
[2072] | 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 | |
---|
[3033] | 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 | |
---|
[2072] | 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; |
---|
[2048] | 247 | } else { |
---|
[796] | 248 | $order='desc'; |
---|
[0] | 249 | } |
---|
[2566] | 250 | |
---|
[2072] | 251 | if ($sortby != 'post_dt' || $order != 'desc') { |
---|
| 252 | $show_filters = true; |
---|
| 253 | } |
---|
| 254 | } else { |
---|
| 255 | $sortby='post_dt'; |
---|
| 256 | $order='desc'; |
---|
| 257 | } |
---|
[2048] | 258 | |
---|
[2072] | 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 | -------------------------------------------------------- */ |
---|
[2136] | 270 | |
---|
[2145] | 271 | $form_filter_title = __('Show filters and display options'); |
---|
[2135] | 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". |
---|
[2145] | 279 | dcPage::jsVar('dotclear.msg.cancel_the_filter',__('Cancel filters and display options'))."\n". |
---|
[2135] | 280 | "//]]>". |
---|
| 281 | "</script>"; |
---|
[2072] | 282 | |
---|
[2135] | 283 | dcPage::open(__('Entries'),$starting_script, |
---|
[2072] | 284 | dcPage::breadcrumb( |
---|
| 285 | array( |
---|
| 286 | html::escapeHTML($core->blog->name) => '', |
---|
[2166] | 287 | __('Entries') => '' |
---|
[2072] | 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 |
---|
[2720] | 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">'. |
---|
[2135] | 300 | '<h3 class="out-of-screen-if-js">'.$form_filter_title.'</h3>'. |
---|
[2048] | 301 | |
---|
[2072] | 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> '. |
---|
[3033] | 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>'. |
---|
[2072] | 315 | '</div>'. |
---|
[2566] | 316 | |
---|
[2072] | 317 | '<div class="cell filters-sibling-cell">'. |
---|
| 318 | '<p><label for="selected" class="ib">'.__('Selected:').'</label> '. |
---|
| 319 | form::combo('selected',$selected_combo,$selected).'</p>'. |
---|
[2309] | 320 | '<p><label for="attachment" class="ib">'.__('Attachments:').'</label> '. |
---|
| 321 | form::combo('attachment',$attachment_combo,$attachment).'</p>'. |
---|
[2072] | 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>'. |
---|
[2566] | 327 | |
---|
[2072] | 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>'. |
---|
[2048] | 339 | |
---|
[2072] | 340 | '<p><input type="submit" value="'.__('Apply filters and display options').'" />'. |
---|
| 341 | '<br class="clear" /></p>'. //Opera sucks |
---|
| 342 | '</form>'; |
---|
[2566] | 343 | |
---|
[2072] | 344 | # Show posts |
---|
| 345 | $post_list->display($page,$nb_per_page, |
---|
[2720] | 346 | '<form action="'.$core->adminurl->get("admin.posts").'" method="post" id="form-entries">'. |
---|
[2566] | 347 | |
---|
[2072] | 348 | '%s'. |
---|
[2566] | 349 | |
---|
[2072] | 350 | '<div class="two-cols">'. |
---|
| 351 | '<p class="col checkboxes-helpers"></p>'. |
---|
[2566] | 352 | |
---|
[2072] | 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). |
---|
[3033] | 359 | form::hidden(array('password'),$password). |
---|
[2072] | 360 | form::hidden(array('selected'),$selected). |
---|
[2309] | 361 | form::hidden(array('attachment'),$attachment). |
---|
[2072] | 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>'. |
---|
[2134] | 370 | '</form>', |
---|
| 371 | $show_filters |
---|
[2048] | 372 | ); |
---|
[2072] | 373 | } |
---|
[2048] | 374 | |
---|
[2072] | 375 | dcPage::helpBlock('core_posts'); |
---|
| 376 | dcPage::close(); |
---|