[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('-',''), |
---|
| 57 | new formSelectOption(__('(No cat)'),'NULL')), |
---|
| 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 | } |
---|
| 66 | |
---|
[1719] | 67 | $status_combo = array_merge( |
---|
| 68 | array('-' => ''), |
---|
| 69 | dcAdminCombos::getPostStatusesCombo() |
---|
[0] | 70 | ); |
---|
| 71 | |
---|
| 72 | $selected_combo = array( |
---|
| 73 | '-' => '', |
---|
[1353] | 74 | __('Selected') => '1', |
---|
| 75 | __('Not selected') => '0' |
---|
[0] | 76 | ); |
---|
| 77 | |
---|
| 78 | # Months array |
---|
[1719] | 79 | $dt_m_combo = array_merge( |
---|
| 80 | array('-' => ''), |
---|
| 81 | dcAdminCombos::getDatesCombo($dates) |
---|
| 82 | ); |
---|
[0] | 83 | |
---|
[1719] | 84 | $lang_combo = array_merge( |
---|
| 85 | array('-' => ''), |
---|
| 86 | dcAdminCombos::getLangsCombo($langs,false) |
---|
| 87 | ); |
---|
[0] | 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 | $combo_action = array(); |
---|
| 106 | if ($core->auth->check('publish,contentadmin',$core->blog->id)) |
---|
| 107 | { |
---|
| 108 | $combo_action[__('Status')] = array( |
---|
| 109 | __('Publish') => 'publish', |
---|
| 110 | __('Unpublish') => 'unpublish', |
---|
| 111 | __('Schedule') => 'schedule', |
---|
| 112 | __('Mark as pending') => 'pending' |
---|
| 113 | ); |
---|
| 114 | } |
---|
| 115 | $combo_action[__('Mark')] = array( |
---|
| 116 | __('Mark as selected') => 'selected', |
---|
| 117 | __('Mark as unselected') => 'unselected' |
---|
| 118 | ); |
---|
[1102] | 119 | $combo_action[__('Change')] = array( |
---|
| 120 | __('Change category') => 'category', |
---|
| 121 | __('Change language') => 'lang'); |
---|
[0] | 122 | if ($core->auth->check('admin',$core->blog->id)) |
---|
| 123 | { |
---|
| 124 | $combo_action[__('Change')] = array_merge($combo_action[__('Change')], |
---|
| 125 | array(__('Change author') => 'author')); |
---|
| 126 | } |
---|
| 127 | if ($core->auth->check('delete,contentadmin',$core->blog->id)) |
---|
| 128 | { |
---|
| 129 | $combo_action[__('Delete')] = array(__('Delete') => 'delete'); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | # --BEHAVIOR-- adminPostsActionsCombo |
---|
| 133 | $core->callBehavior('adminPostsActionsCombo',array(&$combo_action)); |
---|
| 134 | |
---|
| 135 | /* Get posts |
---|
| 136 | -------------------------------------------------------- */ |
---|
[796] | 137 | $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : ''; |
---|
| 138 | $cat_id = !empty($_GET['cat_id']) ? $_GET['cat_id'] : ''; |
---|
| 139 | $status = isset($_GET['status']) ? $_GET['status'] : ''; |
---|
| 140 | $selected = isset($_GET['selected']) ? $_GET['selected'] : ''; |
---|
| 141 | $month = !empty($_GET['month']) ? $_GET['month'] : ''; |
---|
| 142 | $lang = !empty($_GET['lang']) ? $_GET['lang'] : ''; |
---|
| 143 | $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : 'post_dt'; |
---|
| 144 | $order = !empty($_GET['order']) ? $_GET['order'] : 'desc'; |
---|
[0] | 145 | |
---|
| 146 | $show_filters = false; |
---|
| 147 | |
---|
[1912] | 148 | $page = !empty($_GET['page']) ? max(1,(integer) $_GET['page']) : 1; |
---|
[0] | 149 | $nb_per_page = 30; |
---|
| 150 | |
---|
| 151 | if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { |
---|
| 152 | if ($nb_per_page != $_GET['nb']) { |
---|
| 153 | $show_filters = true; |
---|
| 154 | } |
---|
| 155 | $nb_per_page = (integer) $_GET['nb']; |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | $params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page); |
---|
| 159 | $params['no_content'] = true; |
---|
| 160 | |
---|
| 161 | # - User filter |
---|
| 162 | if ($user_id !== '' && in_array($user_id,$users_combo)) { |
---|
| 163 | $params['user_id'] = $user_id; |
---|
| 164 | $show_filters = true; |
---|
[796] | 165 | } else { |
---|
| 166 | $user_id=''; |
---|
[0] | 167 | } |
---|
| 168 | |
---|
| 169 | # - Categories filter |
---|
[1772] | 170 | if ($cat_id !== '' && isset($categories_values[$cat_id])) { |
---|
[0] | 171 | $params['cat_id'] = $cat_id; |
---|
| 172 | $show_filters = true; |
---|
[796] | 173 | } else { |
---|
| 174 | $cat_id=''; |
---|
[0] | 175 | } |
---|
| 176 | |
---|
| 177 | # - Status filter |
---|
| 178 | if ($status !== '' && in_array($status,$status_combo)) { |
---|
| 179 | $params['post_status'] = $status; |
---|
| 180 | $show_filters = true; |
---|
[796] | 181 | } else { |
---|
| 182 | $status=''; |
---|
[0] | 183 | } |
---|
| 184 | |
---|
| 185 | # - Selected filter |
---|
| 186 | if ($selected !== '' && in_array($selected,$selected_combo)) { |
---|
| 187 | $params['post_selected'] = $selected; |
---|
| 188 | $show_filters = true; |
---|
[796] | 189 | } else { |
---|
| 190 | $selected=''; |
---|
[0] | 191 | } |
---|
| 192 | |
---|
| 193 | # - Month filter |
---|
| 194 | if ($month !== '' && in_array($month,$dt_m_combo)) { |
---|
| 195 | $params['post_month'] = substr($month,4,2); |
---|
| 196 | $params['post_year'] = substr($month,0,4); |
---|
| 197 | $show_filters = true; |
---|
[796] | 198 | } else { |
---|
| 199 | $month=''; |
---|
[0] | 200 | } |
---|
| 201 | |
---|
| 202 | # - Lang filter |
---|
| 203 | if ($lang !== '' && in_array($lang,$lang_combo)) { |
---|
| 204 | $params['post_lang'] = $lang; |
---|
| 205 | $show_filters = true; |
---|
[796] | 206 | } else { |
---|
| 207 | $lang=''; |
---|
[0] | 208 | } |
---|
| 209 | |
---|
| 210 | # - Sortby and order filter |
---|
| 211 | if ($sortby !== '' && in_array($sortby,$sortby_combo)) { |
---|
| 212 | if ($order !== '' && in_array($order,$order_combo)) { |
---|
| 213 | $params['order'] = $sortby.' '.$order; |
---|
[796] | 214 | } else { |
---|
| 215 | $order='desc'; |
---|
[0] | 216 | } |
---|
| 217 | |
---|
| 218 | if ($sortby != 'post_dt' || $order != 'desc') { |
---|
| 219 | $show_filters = true; |
---|
| 220 | } |
---|
[796] | 221 | } else { |
---|
| 222 | $sortby='post_dt'; |
---|
| 223 | $order='desc'; |
---|
[0] | 224 | } |
---|
| 225 | |
---|
| 226 | # Get posts |
---|
| 227 | try { |
---|
| 228 | $posts = $core->blog->getPosts($params); |
---|
| 229 | $counter = $core->blog->getPosts($params,true); |
---|
| 230 | $post_list = new adminPostList($core,$posts,$counter->f(0)); |
---|
| 231 | } catch (Exception $e) { |
---|
| 232 | $core->error->add($e->getMessage()); |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | /* DISPLAY |
---|
| 236 | -------------------------------------------------------- */ |
---|
| 237 | $starting_script = dcPage::jsLoad('js/_posts_list.js'); |
---|
| 238 | if (!$show_filters) { |
---|
| 239 | $starting_script .= dcPage::jsLoad('js/filter-controls.js'); |
---|
| 240 | } |
---|
| 241 | |
---|
[1358] | 242 | dcPage::open(__('Entries'),$starting_script, |
---|
[1334] | 243 | dcPage::breadcrumb( |
---|
[1328] | 244 | array( |
---|
| 245 | html::escapeHTML($core->blog->name) => '', |
---|
| 246 | '<span class="page-title">'.__('Entries').'</span>' => '' |
---|
[1358] | 247 | )) |
---|
| 248 | ); |
---|
[1476] | 249 | if (!empty($_GET['upd'])) { |
---|
[1553] | 250 | dcPage::success(__('Selected entries have been successfully updated.')); |
---|
[1476] | 251 | } elseif (!empty($_GET['del'])) { |
---|
[1553] | 252 | dcPage::success(__('Selected entries have been successfully deleted.')); |
---|
[1476] | 253 | } |
---|
[0] | 254 | if (!$core->error->flag()) |
---|
| 255 | { |
---|
[1328] | 256 | echo |
---|
[158] | 257 | '<p class="top-add"><a class="button add" href="post.php">'.__('New entry').'</a></p>'; |
---|
[0] | 258 | |
---|
| 259 | if (!$show_filters) { |
---|
| 260 | echo '<p><a id="filter-control" class="form-control" href="#">'. |
---|
[1415] | 261 | __('Filter posts list').'</a></p>'; |
---|
[0] | 262 | } |
---|
| 263 | |
---|
| 264 | echo |
---|
| 265 | '<form action="posts.php" method="get" id="filters-form">'. |
---|
[1514] | 266 | '<h3 class="hidden">'.__('Filter posts list').'</h3>'. |
---|
[1415] | 267 | |
---|
| 268 | '<div class="table">'. |
---|
| 269 | '<div class="cell">'. |
---|
[1514] | 270 | '<h4>'.__('Filters').'</h4>'. |
---|
[1415] | 271 | '<p><label for="user_id" class="ib">'.__('Author:').'</label> '. |
---|
| 272 | form::combo('user_id',$users_combo,$user_id).'</p>'. |
---|
| 273 | '<p><label for="cat_id" class="ib">'.__('Category:').'</label> '. |
---|
| 274 | form::combo('cat_id',$categories_combo,$cat_id).'</p>'. |
---|
[1420] | 275 | '<p><label for="status" class="ib">'.__('Status:').'</label> ' . |
---|
[1415] | 276 | form::combo('status',$status_combo,$status).'</p> '. |
---|
[0] | 277 | '</div>'. |
---|
| 278 | |
---|
[1514] | 279 | '<div class="cell filters-sibling-cell">'. |
---|
[1415] | 280 | '<p><label for="selected" class="ib">'.__('Selected:').'</label> '. |
---|
| 281 | form::combo('selected',$selected_combo,$selected).'</p>'. |
---|
| 282 | '<p><label for="month" class="ib">'.__('Month:').'</label> '. |
---|
| 283 | form::combo('month',$dt_m_combo,$month).'</p>'. |
---|
[1474] | 284 | '<p><label for="lang" class="ib">'.__('Lang:').'</label> '. |
---|
[1415] | 285 | form::combo('lang',$lang_combo,$lang).'</p> '. |
---|
[0] | 286 | '</div>'. |
---|
| 287 | |
---|
[1415] | 288 | '<div class="cell filters-options">'. |
---|
[1514] | 289 | '<h4>'.__('Display options').'</h4>'. |
---|
[1415] | 290 | '<p><label for="sortby" class="ib">'.__('Order by:').'</label> '. |
---|
| 291 | form::combo('sortby',$sortby_combo,$sortby).'</p>'. |
---|
| 292 | '<p><label for="order" class="ib">'.__('Sort:').'</label> '. |
---|
| 293 | form::combo('order',$order_combo,$order).'</p>'. |
---|
[1426] | 294 | '<p><span class="label ib">'.__('Show').'</span> <label for="nb" class="classic">'. |
---|
[1424] | 295 | form::field('nb',3,3,$nb_per_page).' '. |
---|
[1415] | 296 | __('entries per page').'</label></p>'. |
---|
[0] | 297 | '</div>'. |
---|
| 298 | '</div>'. |
---|
[1415] | 299 | |
---|
[1514] | 300 | '<p><input type="submit" value="'.__('Apply filters and display options').'" />'. |
---|
[1424] | 301 | '<br class="clear" /></p>'. //Opera sucks |
---|
[0] | 302 | '</form>'; |
---|
| 303 | |
---|
| 304 | # Show posts |
---|
| 305 | $post_list->display($page,$nb_per_page, |
---|
| 306 | '<form action="posts_actions.php" method="post" id="form-entries">'. |
---|
| 307 | |
---|
| 308 | '%s'. |
---|
| 309 | |
---|
| 310 | '<div class="two-cols">'. |
---|
| 311 | '<p class="col checkboxes-helpers"></p>'. |
---|
| 312 | |
---|
[96] | 313 | '<p class="col right"><label for="action" class="classic">'.__('Selected entries action:').'</label> '. |
---|
[0] | 314 | form::combo('action',$combo_action). |
---|
| 315 | '<input type="submit" value="'.__('ok').'" /></p>'. |
---|
| 316 | form::hidden(array('user_id'),$user_id). |
---|
| 317 | form::hidden(array('cat_id'),$cat_id). |
---|
| 318 | form::hidden(array('status'),$status). |
---|
| 319 | form::hidden(array('selected'),$selected). |
---|
| 320 | form::hidden(array('month'),$month). |
---|
| 321 | form::hidden(array('lang'),$lang). |
---|
| 322 | form::hidden(array('sortby'),$sortby). |
---|
| 323 | form::hidden(array('order'),$order). |
---|
| 324 | form::hidden(array('page'),$page). |
---|
| 325 | form::hidden(array('nb'),$nb_per_page). |
---|
| 326 | $core->formNonce(). |
---|
| 327 | '</div>'. |
---|
| 328 | '</form>' |
---|
| 329 | ); |
---|
| 330 | } |
---|
| 331 | |
---|
| 332 | dcPage::helpBlock('core_posts'); |
---|
| 333 | dcPage::close(); |
---|
[795] | 334 | ?> |
---|