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