| 1 | <?php | 
|---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- | 
|---|
| 3 | # | 
|---|
| 4 | # This file is part of Dotclear 2. | 
|---|
| 5 | # | 
|---|
| 6 | # Copyright (c) 2003-2011 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 = $categories_combo = array(); | 
|---|
| 50 | $users_combo['-'] = $categories_combo['-'] = ''; | 
|---|
| 51 | while ($users->fetch()) | 
|---|
| 52 | { | 
|---|
| 53 | $user_cn = dcUtils::getUserCN($users->user_id,$users->user_name, | 
|---|
| 54 | $users->user_firstname,$users->user_displayname); | 
|---|
| 55 |  | 
|---|
| 56 | if ($user_cn != $users->user_id) { | 
|---|
| 57 | $user_cn .= ' ('.$users->user_id.')'; | 
|---|
| 58 | } | 
|---|
| 59 |  | 
|---|
| 60 | $users_combo[$user_cn] = $users->user_id; | 
|---|
| 61 | } | 
|---|
| 62 |  | 
|---|
| 63 | $categories_combo[__('None')] = 'NULL'; | 
|---|
| 64 | while ($categories->fetch()) { | 
|---|
| 65 | $categories_combo[str_repeat('  ',$categories->level-1).($categories->level-1 == 0 ? '' : '• '). | 
|---|
| 66 | html::escapeHTML($categories->cat_title). | 
|---|
| 67 | ' ('.$categories->nb_post.')'] = $categories->cat_id; | 
|---|
| 68 | } | 
|---|
| 69 |  | 
|---|
| 70 | $status_combo = array( | 
|---|
| 71 | '-' => '' | 
|---|
| 72 | ); | 
|---|
| 73 | foreach ($core->blog->getAllPostStatus() as $k => $v) { | 
|---|
| 74 | $status_combo[$v] = (string) $k; | 
|---|
| 75 | } | 
|---|
| 76 |  | 
|---|
| 77 | $selected_combo = array( | 
|---|
| 78 | '-' => '', | 
|---|
| 79 | __('selected') => '1', | 
|---|
| 80 | __('not selected') => '0' | 
|---|
| 81 | ); | 
|---|
| 82 |  | 
|---|
| 83 | # Months array | 
|---|
| 84 | $dt_m_combo['-'] = ''; | 
|---|
| 85 | while ($dates->fetch()) { | 
|---|
| 86 | $dt_m_combo[dt::str('%B %Y',$dates->ts())] = $dates->year().$dates->month(); | 
|---|
| 87 | } | 
|---|
| 88 |  | 
|---|
| 89 | $lang_combo['-'] = ''; | 
|---|
| 90 | while ($langs->fetch()) { | 
|---|
| 91 | $lang_combo[$langs->post_lang] = $langs->post_lang; | 
|---|
| 92 | } | 
|---|
| 93 |  | 
|---|
| 94 | $sortby_combo = array( | 
|---|
| 95 | __('Date') => 'post_dt', | 
|---|
| 96 | __('Title') => 'post_title', | 
|---|
| 97 | __('Category') => 'cat_title', | 
|---|
| 98 | __('Author') => 'user_id', | 
|---|
| 99 | __('Status') => 'post_status', | 
|---|
| 100 | __('Selected') => 'post_selected' | 
|---|
| 101 | ); | 
|---|
| 102 |  | 
|---|
| 103 | $order_combo = array( | 
|---|
| 104 | __('Descending') => 'desc', | 
|---|
| 105 | __('Ascending') => 'asc' | 
|---|
| 106 | ); | 
|---|
| 107 | } | 
|---|
| 108 |  | 
|---|
| 109 | # Actions combo box | 
|---|
| 110 | $combo_action = array(); | 
|---|
| 111 | if ($core->auth->check('publish,contentadmin',$core->blog->id)) | 
|---|
| 112 | { | 
|---|
| 113 | $combo_action[__('Status')] = array( | 
|---|
| 114 | __('Publish') => 'publish', | 
|---|
| 115 | __('Unpublish') => 'unpublish', | 
|---|
| 116 | __('Schedule') => 'schedule', | 
|---|
| 117 | __('Mark as pending') => 'pending' | 
|---|
| 118 | ); | 
|---|
| 119 | } | 
|---|
| 120 | $combo_action[__('Mark')] = array( | 
|---|
| 121 | __('Mark as selected') => 'selected', | 
|---|
| 122 | __('Mark as unselected') => 'unselected' | 
|---|
| 123 | ); | 
|---|
| 124 | $combo_action[__('Change')] = array(__('Change category') => 'category'); | 
|---|
| 125 | if ($core->auth->check('admin',$core->blog->id)) | 
|---|
| 126 | { | 
|---|
| 127 | $combo_action[__('Change')] = array_merge($combo_action[__('Change')], | 
|---|
| 128 | array(__('Change author') => 'author')); | 
|---|
| 129 | } | 
|---|
| 130 | if ($core->auth->check('delete,contentadmin',$core->blog->id)) | 
|---|
| 131 | { | 
|---|
| 132 | $combo_action[__('Delete')] = array(__('Delete') => 'delete'); | 
|---|
| 133 | } | 
|---|
| 134 |  | 
|---|
| 135 | # --BEHAVIOR-- adminPostsActionsCombo | 
|---|
| 136 | $core->callBehavior('adminPostsActionsCombo',array(&$combo_action)); | 
|---|
| 137 |  | 
|---|
| 138 | /* Get posts | 
|---|
| 139 | -------------------------------------------------------- */ | 
|---|
| 140 | $user_id = !empty($_GET['user_id']) ?   $_GET['user_id'] : ''; | 
|---|
| 141 | $cat_id = !empty($_GET['cat_id']) ?     $_GET['cat_id'] : ''; | 
|---|
| 142 | $status = isset($_GET['status']) ? $_GET['status'] : ''; | 
|---|
| 143 | $selected = isset($_GET['selected']) ?  $_GET['selected'] : ''; | 
|---|
| 144 | $month = !empty($_GET['month']) ?       $_GET['month'] : ''; | 
|---|
| 145 | $lang = !empty($_GET['lang']) ?         $_GET['lang'] : ''; | 
|---|
| 146 | $sortby = !empty($_GET['sortby']) ?     $_GET['sortby'] : 'post_dt'; | 
|---|
| 147 | $order = !empty($_GET['order']) ?       $_GET['order'] : 'desc'; | 
|---|
| 148 |  | 
|---|
| 149 | $show_filters = false; | 
|---|
| 150 |  | 
|---|
| 151 | $page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1; | 
|---|
| 152 | $nb_per_page =  30; | 
|---|
| 153 |  | 
|---|
| 154 | if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { | 
|---|
| 155 | if ($nb_per_page != $_GET['nb']) { | 
|---|
| 156 | $show_filters = true; | 
|---|
| 157 | } | 
|---|
| 158 | $nb_per_page = (integer) $_GET['nb']; | 
|---|
| 159 | } | 
|---|
| 160 |  | 
|---|
| 161 | $params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page); | 
|---|
| 162 | $params['no_content'] = true; | 
|---|
| 163 |  | 
|---|
| 164 | # - User filter | 
|---|
| 165 | if ($user_id !== '' && in_array($user_id,$users_combo)) { | 
|---|
| 166 | $params['user_id'] = $user_id; | 
|---|
| 167 | $show_filters = true; | 
|---|
| 168 | } else { | 
|---|
| 169 | $user_id=''; | 
|---|
| 170 | } | 
|---|
| 171 |  | 
|---|
| 172 | # - Categories filter | 
|---|
| 173 | if ($cat_id !== '' && in_array($cat_id,$categories_combo)) { | 
|---|
| 174 | $params['cat_id'] = $cat_id; | 
|---|
| 175 | $show_filters = true; | 
|---|
| 176 | } else { | 
|---|
| 177 | $cat_id=''; | 
|---|
| 178 | } | 
|---|
| 179 |  | 
|---|
| 180 | # - Status filter | 
|---|
| 181 | if ($status !== '' && in_array($status,$status_combo)) { | 
|---|
| 182 | $params['post_status'] = $status; | 
|---|
| 183 | $show_filters = true; | 
|---|
| 184 | } else { | 
|---|
| 185 | $status=''; | 
|---|
| 186 | } | 
|---|
| 187 |  | 
|---|
| 188 | # - Selected filter | 
|---|
| 189 | if ($selected !== '' && in_array($selected,$selected_combo)) { | 
|---|
| 190 | $params['post_selected'] = $selected; | 
|---|
| 191 | $show_filters = true; | 
|---|
| 192 | } else { | 
|---|
| 193 | $selected=''; | 
|---|
| 194 | } | 
|---|
| 195 |  | 
|---|
| 196 | # - Month filter | 
|---|
| 197 | if ($month !== '' && in_array($month,$dt_m_combo)) { | 
|---|
| 198 | $params['post_month'] = substr($month,4,2); | 
|---|
| 199 | $params['post_year'] = substr($month,0,4); | 
|---|
| 200 | $show_filters = true; | 
|---|
| 201 | } else { | 
|---|
| 202 | $month=''; | 
|---|
| 203 | } | 
|---|
| 204 |  | 
|---|
| 205 | # - Lang filter | 
|---|
| 206 | if ($lang !== '' && in_array($lang,$lang_combo)) { | 
|---|
| 207 | $params['post_lang'] = $lang; | 
|---|
| 208 | $show_filters = true; | 
|---|
| 209 | } else { | 
|---|
| 210 | $lang=''; | 
|---|
| 211 | } | 
|---|
| 212 |  | 
|---|
| 213 | # - Sortby and order filter | 
|---|
| 214 | if ($sortby !== '' && in_array($sortby,$sortby_combo)) { | 
|---|
| 215 | if ($order !== '' && in_array($order,$order_combo)) { | 
|---|
| 216 | $params['order'] = $sortby.' '.$order; | 
|---|
| 217 | } else { | 
|---|
| 218 | $order='desc'; | 
|---|
| 219 | } | 
|---|
| 220 |  | 
|---|
| 221 | if ($sortby != 'post_dt' || $order != 'desc') { | 
|---|
| 222 | $show_filters = true; | 
|---|
| 223 | } | 
|---|
| 224 | } else { | 
|---|
| 225 | $sortby='post_dt'; | 
|---|
| 226 | $order='desc'; | 
|---|
| 227 | } | 
|---|
| 228 |  | 
|---|
| 229 | # Get posts | 
|---|
| 230 | try { | 
|---|
| 231 | $posts = $core->blog->getPosts($params); | 
|---|
| 232 | $counter = $core->blog->getPosts($params,true); | 
|---|
| 233 | $post_list = new adminPostList($core,$posts,$counter->f(0)); | 
|---|
| 234 | } catch (Exception $e) { | 
|---|
| 235 | $core->error->add($e->getMessage()); | 
|---|
| 236 | } | 
|---|
| 237 |  | 
|---|
| 238 | /* DISPLAY | 
|---|
| 239 | -------------------------------------------------------- */ | 
|---|
| 240 | $starting_script = dcPage::jsLoad('js/_posts_list.js'); | 
|---|
| 241 | if (!$show_filters) { | 
|---|
| 242 | $starting_script .= dcPage::jsLoad('js/filter-controls.js'); | 
|---|
| 243 | } | 
|---|
| 244 |  | 
|---|
| 245 | dcPage::open(__('Entries'),$starting_script); | 
|---|
| 246 |  | 
|---|
| 247 | if (!$core->error->flag()) | 
|---|
| 248 | { | 
|---|
| 249 | echo | 
|---|
| 250 | '<h2>'.html::escapeHTML($core->blog->name).' › <span class="page-title">'.__('Entries').'</span></h2>'. | 
|---|
| 251 | '<p class="top-add"><a class="button add" href="post.php">'.__('New entry').'</a></p>'; | 
|---|
| 252 |  | 
|---|
| 253 | if (!$show_filters) { | 
|---|
| 254 | echo '<p><a id="filter-control" class="form-control" href="#">'. | 
|---|
| 255 | __('Filters').'</a></p>'; | 
|---|
| 256 | } | 
|---|
| 257 |  | 
|---|
| 258 | echo | 
|---|
| 259 | '<form action="posts.php" method="get" id="filters-form">'. | 
|---|
| 260 | '<fieldset><legend>'.__('Filters').'</legend>'. | 
|---|
| 261 | '<div class="three-cols">'. | 
|---|
| 262 | '<div class="col">'. | 
|---|
| 263 | '<label for="user_id">'.__('Author:'). | 
|---|
| 264 | form::combo('user_id',$users_combo,$user_id).'</label> '. | 
|---|
| 265 | '<label for="cat_id">'.__('Category:'). | 
|---|
| 266 | form::combo('cat_id',$categories_combo,$cat_id).'</label> '. | 
|---|
| 267 | '<label for="status">'.__('Status:'). | 
|---|
| 268 | form::combo('status',$status_combo,$status).'</label> '. | 
|---|
| 269 | '</div>'. | 
|---|
| 270 |  | 
|---|
| 271 | '<div class="col">'. | 
|---|
| 272 | '<label for="selected">'.__('Selected:'). | 
|---|
| 273 | form::combo('selected',$selected_combo,$selected).'</label> '. | 
|---|
| 274 | '<label for="month">'.__('Month:'). | 
|---|
| 275 | form::combo('month',$dt_m_combo,$month).'</label> '. | 
|---|
| 276 | '<label for="lang">'.__('Lang:'). | 
|---|
| 277 | form::combo('lang',$lang_combo,$lang).'</label> '. | 
|---|
| 278 | '</div>'. | 
|---|
| 279 |  | 
|---|
| 280 | '<div class="col">'. | 
|---|
| 281 | '<p><label for="sortby">'.__('Order by:'). | 
|---|
| 282 | form::combo('sortby',$sortby_combo,$sortby).'</label> '. | 
|---|
| 283 | '<label for="order">'.__('Sort:'). | 
|---|
| 284 | form::combo('order',$order_combo,$order).'</label></p>'. | 
|---|
| 285 | '<p><label for="nb" class="classic">'.  form::field('nb',3,3,$nb_per_page).' '. | 
|---|
| 286 | __('Entries per page').'</label></p> '. | 
|---|
| 287 | '<p><input type="submit" value="'.__('Apply filters').'" /></p>'. | 
|---|
| 288 | '</div>'. | 
|---|
| 289 | '</div>'. | 
|---|
| 290 | '<br class="clear" />'. //Opera sucks | 
|---|
| 291 | '</fieldset>'. | 
|---|
| 292 | '</form>'; | 
|---|
| 293 |  | 
|---|
| 294 | # Show posts | 
|---|
| 295 | $post_list->display($page,$nb_per_page, | 
|---|
| 296 | '<form action="posts_actions.php" method="post" id="form-entries">'. | 
|---|
| 297 |  | 
|---|
| 298 | '%s'. | 
|---|
| 299 |  | 
|---|
| 300 | '<div class="two-cols">'. | 
|---|
| 301 | '<p class="col checkboxes-helpers"></p>'. | 
|---|
| 302 |  | 
|---|
| 303 | '<p class="col right"><label for="action" class="classic">'.__('Selected entries action:').'</label> '. | 
|---|
| 304 | form::combo('action',$combo_action). | 
|---|
| 305 | '<input type="submit" value="'.__('ok').'" /></p>'. | 
|---|
| 306 | form::hidden(array('user_id'),$user_id). | 
|---|
| 307 | form::hidden(array('cat_id'),$cat_id). | 
|---|
| 308 | form::hidden(array('status'),$status). | 
|---|
| 309 | form::hidden(array('selected'),$selected). | 
|---|
| 310 | form::hidden(array('month'),$month). | 
|---|
| 311 | form::hidden(array('lang'),$lang). | 
|---|
| 312 | form::hidden(array('sortby'),$sortby). | 
|---|
| 313 | form::hidden(array('order'),$order). | 
|---|
| 314 | form::hidden(array('page'),$page). | 
|---|
| 315 | form::hidden(array('nb'),$nb_per_page). | 
|---|
| 316 | $core->formNonce(). | 
|---|
| 317 | '</div>'. | 
|---|
| 318 | '</form>' | 
|---|
| 319 | ); | 
|---|
| 320 | } | 
|---|
| 321 |  | 
|---|
| 322 | dcPage::helpBlock('core_posts'); | 
|---|
| 323 | dcPage::close(); | 
|---|
| 324 | ?> | 
|---|