| 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 |  | 
|---|
| 215 | $form_filter_title = __('Show filters and display options'); | 
|---|
| 216 | $starting_script  = dcPage::jsLoad('js/_posts_list.js'); | 
|---|
| 217 | $starting_script .= dcPage::jsLoad('js/filter-controls.js'); | 
|---|
| 218 | $starting_script .= | 
|---|
| 219 |      '<script type="text/javascript">'."\n". | 
|---|
| 220 |      "//<![CDATA["."\n". | 
|---|
| 221 |      dcPage::jsVar('dotclear.msg.show_filters', $show_filters ? 'true':'false')."\n". | 
|---|
| 222 |      dcPage::jsVar('dotclear.msg.filter_posts_list',$form_filter_title)."\n". | 
|---|
| 223 |      dcPage::jsVar('dotclear.msg.cancel_the_filter',__('Cancel filters and display options'))."\n". | 
|---|
| 224 |      "//]]>". | 
|---|
| 225 |      "</script>"; | 
|---|
| 226 |  | 
|---|
| 227 | dcPage::open(__('Entries'),$starting_script, | 
|---|
| 228 |      dcPage::breadcrumb( | 
|---|
| 229 |           array( | 
|---|
| 230 |                html::escapeHTML($core->blog->name) => '', | 
|---|
| 231 |                __('Entries') => '' | 
|---|
| 232 |           )) | 
|---|
| 233 | ); | 
|---|
| 234 | if (!empty($_GET['upd'])) { | 
|---|
| 235 |      dcPage::success(__('Selected entries have been successfully updated.')); | 
|---|
| 236 | } elseif (!empty($_GET['del'])) { | 
|---|
| 237 |      dcPage::success(__('Selected entries have been successfully deleted.')); | 
|---|
| 238 | } | 
|---|
| 239 | if (!$core->error->flag()) | 
|---|
| 240 | { | 
|---|
| 241 |      echo | 
|---|
| 242 |      '<p class="top-add"><a class="button add" href="post.php">'.__('New entry').'</a></p>'. | 
|---|
| 243 |      '<form action="posts.php" method="get" id="filters-form">'. | 
|---|
| 244 |      '<h3 class="out-of-screen-if-js">'.$form_filter_title.'</h3>'. | 
|---|
| 245 |  | 
|---|
| 246 |      '<div class="table">'. | 
|---|
| 247 |      '<div class="cell">'. | 
|---|
| 248 |      '<h4>'.__('Filters').'</h4>'. | 
|---|
| 249 |      '<p><label for="user_id" class="ib">'.__('Author:').'</label> '. | 
|---|
| 250 |      form::combo('user_id',$users_combo,$user_id).'</p>'. | 
|---|
| 251 |      '<p><label for="cat_id" class="ib">'.__('Category:').'</label> '. | 
|---|
| 252 |      form::combo('cat_id',$categories_combo,$cat_id).'</p>'. | 
|---|
| 253 |      '<p><label for="status" class="ib">'.__('Status:').'</label> ' . | 
|---|
| 254 |      form::combo('status',$status_combo,$status).'</p> '. | 
|---|
| 255 |      '</div>'. | 
|---|
| 256 |       | 
|---|
| 257 |      '<div class="cell filters-sibling-cell">'. | 
|---|
| 258 |      '<p><label for="selected" class="ib">'.__('Selected:').'</label> '. | 
|---|
| 259 |      form::combo('selected',$selected_combo,$selected).'</p>'. | 
|---|
| 260 |      '<p><label for="month" class="ib">'.__('Month:').'</label> '. | 
|---|
| 261 |      form::combo('month',$dt_m_combo,$month).'</p>'. | 
|---|
| 262 |      '<p><label for="lang" class="ib">'.__('Lang:').'</label> '. | 
|---|
| 263 |      form::combo('lang',$lang_combo,$lang).'</p> '. | 
|---|
| 264 |      '</div>'. | 
|---|
| 265 |       | 
|---|
| 266 |      '<div class="cell filters-options">'. | 
|---|
| 267 |      '<h4>'.__('Display options').'</h4>'. | 
|---|
| 268 |      '<p><label for="sortby" class="ib">'.__('Order by:').'</label> '. | 
|---|
| 269 |      form::combo('sortby',$sortby_combo,$sortby).'</p>'. | 
|---|
| 270 |      '<p><label for="order" class="ib">'.__('Sort:').'</label> '. | 
|---|
| 271 |      form::combo('order',$order_combo,$order).'</p>'. | 
|---|
| 272 |      '<p><span class="label ib">'.__('Show').'</span> <label for="nb" class="classic">'. | 
|---|
| 273 |      form::field('nb',3,3,$nb_per_page).' '. | 
|---|
| 274 |      __('entries per page').'</label></p>'. | 
|---|
| 275 |      '</div>'. | 
|---|
| 276 |      '</div>'. | 
|---|
| 277 |  | 
|---|
| 278 |      '<p><input type="submit" value="'.__('Apply filters and display options').'" />'. | 
|---|
| 279 |      '<br class="clear" /></p>'. //Opera sucks | 
|---|
| 280 |      '</form>'; | 
|---|
| 281 |       | 
|---|
| 282 |      # Show posts | 
|---|
| 283 |      $post_list->display($page,$nb_per_page, | 
|---|
| 284 |      '<form action="posts.php" method="post" id="form-entries">'. | 
|---|
| 285 |       | 
|---|
| 286 |      '%s'. | 
|---|
| 287 |       | 
|---|
| 288 |      '<div class="two-cols">'. | 
|---|
| 289 |      '<p class="col checkboxes-helpers"></p>'. | 
|---|
| 290 |       | 
|---|
| 291 |      '<p class="col right"><label for="action" class="classic">'.__('Selected entries action:').'</label> '. | 
|---|
| 292 |      form::combo('action',$posts_actions_page->getCombo()). | 
|---|
| 293 |      '<input type="submit" value="'.__('ok').'" /></p>'. | 
|---|
| 294 |      form::hidden(array('user_id'),$user_id). | 
|---|
| 295 |      form::hidden(array('cat_id'),$cat_id). | 
|---|
| 296 |      form::hidden(array('status'),$status). | 
|---|
| 297 |      form::hidden(array('selected'),$selected). | 
|---|
| 298 |      form::hidden(array('month'),$month). | 
|---|
| 299 |      form::hidden(array('lang'),$lang). | 
|---|
| 300 |      form::hidden(array('sortby'),$sortby). | 
|---|
| 301 |      form::hidden(array('order'),$order). | 
|---|
| 302 |      form::hidden(array('page'),$page). | 
|---|
| 303 |      form::hidden(array('nb'),$nb_per_page). | 
|---|
| 304 |      $core->formNonce(). | 
|---|
| 305 |      '</div>'. | 
|---|
| 306 |      '</form>', | 
|---|
| 307 |      $show_filters | 
|---|
| 308 |      ); | 
|---|
| 309 | } | 
|---|
| 310 |  | 
|---|
| 311 | dcPage::helpBlock('core_posts'); | 
|---|
| 312 | dcPage::close(); | 
|---|
| 313 |  | 
|---|
| 314 | ?> | 
|---|