| 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 | # Months array |
|---|
| 79 | $dt_m_combo = array_merge( |
|---|
| 80 | array('-' => ''), |
|---|
| 81 | dcAdminCombos::getDatesCombo($dates) |
|---|
| 82 | ); |
|---|
| 83 | |
|---|
| 84 | $lang_combo = array_merge( |
|---|
| 85 | array('-' => ''), |
|---|
| 86 | dcAdminCombos::getLangsCombo($langs,false) |
|---|
| 87 | ); |
|---|
| 88 | |
|---|
| 89 | $sortby_combo = array( |
|---|
| 90 | __('Date') => 'post_dt', |
|---|
| 91 | __('Title') => 'post_title', |
|---|
| 92 | __('Category') => 'cat_title', |
|---|
| 93 | __('Author') => 'user_id', |
|---|
| 94 | __('Status') => 'post_status', |
|---|
| 95 | __('Selected') => 'post_selected' |
|---|
| 96 | ); |
|---|
| 97 | |
|---|
| 98 | $order_combo = array( |
|---|
| 99 | __('Descending') => 'desc', |
|---|
| 100 | __('Ascending') => 'asc' |
|---|
| 101 | ); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | # Actions combo box |
|---|
| 105 | |
|---|
| 106 | $posts_actions_page = new dcPostsActionsPage($core,'posts.php'); |
|---|
| 107 | |
|---|
| 108 | if ($posts_actions_page->process()) { |
|---|
| 109 | return; |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | /* Get posts |
|---|
| 113 | -------------------------------------------------------- */ |
|---|
| 114 | $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : ''; |
|---|
| 115 | $cat_id = !empty($_GET['cat_id']) ? $_GET['cat_id'] : ''; |
|---|
| 116 | $status = isset($_GET['status']) ? $_GET['status'] : ''; |
|---|
| 117 | $selected = isset($_GET['selected']) ? $_GET['selected'] : ''; |
|---|
| 118 | $month = !empty($_GET['month']) ? $_GET['month'] : ''; |
|---|
| 119 | $lang = !empty($_GET['lang']) ? $_GET['lang'] : ''; |
|---|
| 120 | $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : 'post_dt'; |
|---|
| 121 | $order = !empty($_GET['order']) ? $_GET['order'] : 'desc'; |
|---|
| 122 | |
|---|
| 123 | $show_filters = false; |
|---|
| 124 | |
|---|
| 125 | $page = !empty($_GET['page']) ? max(1,(integer) $_GET['page']) : 1; |
|---|
| 126 | $nb_per_page = 30; |
|---|
| 127 | |
|---|
| 128 | if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { |
|---|
| 129 | if ($nb_per_page != $_GET['nb']) { |
|---|
| 130 | $show_filters = true; |
|---|
| 131 | } |
|---|
| 132 | $nb_per_page = (integer) $_GET['nb']; |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | $params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page); |
|---|
| 136 | $params['no_content'] = true; |
|---|
| 137 | |
|---|
| 138 | # - User filter |
|---|
| 139 | if ($user_id !== '' && in_array($user_id,$users_combo)) { |
|---|
| 140 | $params['user_id'] = $user_id; |
|---|
| 141 | $show_filters = true; |
|---|
| 142 | } else { |
|---|
| 143 | $user_id=''; |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | # - Categories filter |
|---|
| 147 | if ($cat_id !== '' && isset($categories_values[$cat_id])) { |
|---|
| 148 | $params['cat_id'] = $cat_id; |
|---|
| 149 | $show_filters = true; |
|---|
| 150 | } else { |
|---|
| 151 | $cat_id=''; |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | # - Status filter |
|---|
| 155 | if ($status !== '' && in_array($status,$status_combo)) { |
|---|
| 156 | $params['post_status'] = $status; |
|---|
| 157 | $show_filters = true; |
|---|
| 158 | } else { |
|---|
| 159 | $status=''; |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | # - Selected filter |
|---|
| 163 | if ($selected !== '' && in_array($selected,$selected_combo)) { |
|---|
| 164 | $params['post_selected'] = $selected; |
|---|
| 165 | $show_filters = true; |
|---|
| 166 | } else { |
|---|
| 167 | $selected=''; |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | # - Month filter |
|---|
| 171 | if ($month !== '' && in_array($month,$dt_m_combo)) { |
|---|
| 172 | $params['post_month'] = substr($month,4,2); |
|---|
| 173 | $params['post_year'] = substr($month,0,4); |
|---|
| 174 | $show_filters = true; |
|---|
| 175 | } else { |
|---|
| 176 | $month=''; |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | # - Lang filter |
|---|
| 180 | if ($lang !== '' && in_array($lang,$lang_combo)) { |
|---|
| 181 | $params['post_lang'] = $lang; |
|---|
| 182 | $show_filters = true; |
|---|
| 183 | } else { |
|---|
| 184 | $lang=''; |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | # - Sortby and order filter |
|---|
| 188 | if ($sortby !== '' && in_array($sortby,$sortby_combo)) { |
|---|
| 189 | if ($order !== '' && in_array($order,$order_combo)) { |
|---|
| 190 | $params['order'] = $sortby.' '.$order; |
|---|
| 191 | } else { |
|---|
| 192 | $order='desc'; |
|---|
| 193 | } |
|---|
| 194 | |
|---|
| 195 | if ($sortby != 'post_dt' || $order != 'desc') { |
|---|
| 196 | $show_filters = true; |
|---|
| 197 | } |
|---|
| 198 | } else { |
|---|
| 199 | $sortby='post_dt'; |
|---|
| 200 | $order='desc'; |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | # Get posts |
|---|
| 204 | try { |
|---|
| 205 | $posts = $core->blog->getPosts($params); |
|---|
| 206 | $counter = $core->blog->getPosts($params,true); |
|---|
| 207 | $post_list = new adminPostList($core,$posts,$counter->f(0)); |
|---|
| 208 | } catch (Exception $e) { |
|---|
| 209 | $core->error->add($e->getMessage()); |
|---|
| 210 | } |
|---|
| 211 | |
|---|
| 212 | /* DISPLAY |
|---|
| 213 | -------------------------------------------------------- */ |
|---|
| 214 | $starting_script = dcPage::jsLoad('js/_posts_list.js'); |
|---|
| 215 | if (!$show_filters) { |
|---|
| 216 | $starting_script .= dcPage::jsLoad('js/filter-controls.js'); |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | dcPage::open(__('Entries'),$starting_script, |
|---|
| 220 | dcPage::breadcrumb( |
|---|
| 221 | array( |
|---|
| 222 | html::escapeHTML($core->blog->name) => '', |
|---|
| 223 | '<span class="page-title">'.__('Entries').'</span>' => '' |
|---|
| 224 | )) |
|---|
| 225 | ); |
|---|
| 226 | if (!empty($_GET['upd'])) { |
|---|
| 227 | dcPage::success(__('Selected entries have been successfully updated.')); |
|---|
| 228 | } elseif (!empty($_GET['del'])) { |
|---|
| 229 | dcPage::success(__('Selected entries have been successfully deleted.')); |
|---|
| 230 | } |
|---|
| 231 | if (!$core->error->flag()) |
|---|
| 232 | { |
|---|
| 233 | echo |
|---|
| 234 | '<p class="top-add"><a class="button add" href="post.php">'.__('New entry').'</a></p>'; |
|---|
| 235 | |
|---|
| 236 | if (!$show_filters) { |
|---|
| 237 | echo '<p><a id="filter-control" class="form-control" href="#">'. |
|---|
| 238 | __('Filter posts list').'</a></p>'; |
|---|
| 239 | } |
|---|
| 240 | |
|---|
| 241 | echo |
|---|
| 242 | '<form action="posts.php" method="get" id="filters-form">'. |
|---|
| 243 | '<h3 class="hidden">'.__('Filter posts list').'</h3>'. |
|---|
| 244 | |
|---|
| 245 | '<div class="table">'. |
|---|
| 246 | '<div class="cell">'. |
|---|
| 247 | '<h4>'.__('Filters').'</h4>'. |
|---|
| 248 | '<p><label for="user_id" class="ib">'.__('Author:').'</label> '. |
|---|
| 249 | form::combo('user_id',$users_combo,$user_id).'</p>'. |
|---|
| 250 | '<p><label for="cat_id" class="ib">'.__('Category:').'</label> '. |
|---|
| 251 | form::combo('cat_id',$categories_combo,$cat_id).'</p>'. |
|---|
| 252 | '<p><label for="status" class="ib">'.__('Status:').'</label> ' . |
|---|
| 253 | form::combo('status',$status_combo,$status).'</p> '. |
|---|
| 254 | '</div>'. |
|---|
| 255 | |
|---|
| 256 | '<div class="cell filters-sibling-cell">'. |
|---|
| 257 | '<p><label for="selected" class="ib">'.__('Selected:').'</label> '. |
|---|
| 258 | form::combo('selected',$selected_combo,$selected).'</p>'. |
|---|
| 259 | '<p><label for="month" class="ib">'.__('Month:').'</label> '. |
|---|
| 260 | form::combo('month',$dt_m_combo,$month).'</p>'. |
|---|
| 261 | '<p><label for="lang" class="ib">'.__('Lang:').'</label> '. |
|---|
| 262 | form::combo('lang',$lang_combo,$lang).'</p> '. |
|---|
| 263 | '</div>'. |
|---|
| 264 | |
|---|
| 265 | '<div class="cell filters-options">'. |
|---|
| 266 | '<h4>'.__('Display options').'</h4>'. |
|---|
| 267 | '<p><label for="sortby" class="ib">'.__('Order by:').'</label> '. |
|---|
| 268 | form::combo('sortby',$sortby_combo,$sortby).'</p>'. |
|---|
| 269 | '<p><label for="order" class="ib">'.__('Sort:').'</label> '. |
|---|
| 270 | form::combo('order',$order_combo,$order).'</p>'. |
|---|
| 271 | '<p><span class="label ib">'.__('Show').'</span> <label for="nb" class="classic">'. |
|---|
| 272 | form::field('nb',3,3,$nb_per_page).' '. |
|---|
| 273 | __('entries per page').'</label></p>'. |
|---|
| 274 | '</div>'. |
|---|
| 275 | '</div>'. |
|---|
| 276 | |
|---|
| 277 | '<p><input type="submit" value="'.__('Apply filters and display options').'" />'. |
|---|
| 278 | '<br class="clear" /></p>'. //Opera sucks |
|---|
| 279 | '</form>'; |
|---|
| 280 | |
|---|
| 281 | # Show posts |
|---|
| 282 | $post_list->display($page,$nb_per_page, |
|---|
| 283 | '<form action="posts.php" method="post" id="form-entries">'. |
|---|
| 284 | |
|---|
| 285 | '%s'. |
|---|
| 286 | |
|---|
| 287 | '<div class="two-cols">'. |
|---|
| 288 | '<p class="col checkboxes-helpers"></p>'. |
|---|
| 289 | |
|---|
| 290 | '<p class="col right"><label for="action" class="classic">'.__('Selected entries action:').'</label> '. |
|---|
| 291 | form::combo('action',$posts_actions_page->getCombo()). |
|---|
| 292 | '<input type="submit" value="'.__('ok').'" /></p>'. |
|---|
| 293 | form::hidden(array('user_id'),$user_id). |
|---|
| 294 | form::hidden(array('cat_id'),$cat_id). |
|---|
| 295 | form::hidden(array('status'),$status). |
|---|
| 296 | form::hidden(array('selected'),$selected). |
|---|
| 297 | form::hidden(array('month'),$month). |
|---|
| 298 | form::hidden(array('lang'),$lang). |
|---|
| 299 | form::hidden(array('sortby'),$sortby). |
|---|
| 300 | form::hidden(array('order'),$order). |
|---|
| 301 | form::hidden(array('page'),$page). |
|---|
| 302 | form::hidden(array('nb'),$nb_per_page). |
|---|
| 303 | $core->formNonce(). |
|---|
| 304 | '</div>'. |
|---|
| 305 | '</form>' |
|---|
| 306 | ); |
|---|
| 307 | } |
|---|
| 308 | |
|---|
| 309 | dcPage::helpBlock('core_posts'); |
|---|
| 310 | dcPage::close(); |
|---|
| 311 | |
|---|
| 312 | ?> |
|---|