| 1 | <?php |
|---|
| 2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
|---|
| 3 | # |
|---|
| 4 | # This file is part of megapost, a plugin for Dotclear 2. |
|---|
| 5 | # |
|---|
| 6 | # Copyright (c) 2010 Osku and contributors |
|---|
| 7 | # |
|---|
| 8 | # Licensed under the GPL version 2.0 license. |
|---|
| 9 | # A copy of this license is available in LICENSE at |
|---|
| 10 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
|---|
| 11 | # |
|---|
| 12 | # -- END LICENSE BLOCK ------------------------------------ |
|---|
| 13 | if (!defined('DC_CONTEXT_ADMIN')) { return; } |
|---|
| 14 | $type = (!empty($_REQUEST['type'])) ? $_REQUEST['type'] : ''; |
|---|
| 15 | |
|---|
| 16 | if (!muppet::typeExists($type)) |
|---|
| 17 | { |
|---|
| 18 | return; |
|---|
| 19 | } |
|---|
| 20 | |
|---|
| 21 | dcPage::check($my_types[$type]['perm'].',contentadmin'); |
|---|
| 22 | |
|---|
| 23 | $plural = empty($my_types[$type]['plural']) ? $my_types[$type]['name'].'s' : $my_types[$type]['plural']; |
|---|
| 24 | |
|---|
| 25 | /* Pager class |
|---|
| 26 | -------------------------------------------------------- */ |
|---|
| 27 | class adminItemList extends adminGenericList |
|---|
| 28 | { |
|---|
| 29 | public function display($page,$nb_per_page,$enclose_block='') |
|---|
| 30 | { |
|---|
| 31 | if ($this->rs->isEmpty()) |
|---|
| 32 | { |
|---|
| 33 | echo '<p><strong>'.__('No entry').'</strong></p>'; |
|---|
| 34 | } |
|---|
| 35 | else |
|---|
| 36 | { |
|---|
| 37 | $pager = new pager($page,$this->rs_count,$nb_per_page,10); |
|---|
| 38 | $pager->html_prev = $this->html_prev; |
|---|
| 39 | $pager->html_next = $this->html_next; |
|---|
| 40 | $pager->var_page = 'page'; |
|---|
| 41 | |
|---|
| 42 | $html_block = |
|---|
| 43 | '<table class="clear"><tr>'. |
|---|
| 44 | '<th colspan="2">'.__('Title').'</th>'. |
|---|
| 45 | '<th>'.__('Date').'</th>'. |
|---|
| 46 | '<th>'.__('Category').'</th>'. |
|---|
| 47 | '<th>'.__('Author').'</th>'. |
|---|
| 48 | '<th>'.__('Comments').'</th>'. |
|---|
| 49 | '<th>'.__('Trackbacks').'</th>'. |
|---|
| 50 | '<th>'.__('Status').'</th>'. |
|---|
| 51 | '</tr>%s</table>'; |
|---|
| 52 | |
|---|
| 53 | if ($enclose_block) { |
|---|
| 54 | $html_block = sprintf($enclose_block,$html_block); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>'; |
|---|
| 58 | |
|---|
| 59 | $blocks = explode('%s',$html_block); |
|---|
| 60 | |
|---|
| 61 | echo $blocks[0]; |
|---|
| 62 | |
|---|
| 63 | while ($this->rs->fetch()) |
|---|
| 64 | { |
|---|
| 65 | echo $this->postLine(); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | echo $blocks[1]; |
|---|
| 69 | |
|---|
| 70 | echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>'; |
|---|
| 71 | } |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | private function postLine() |
|---|
| 75 | { |
|---|
| 76 | if ($this->core->auth->check('categories',$this->core->blog->id)) { |
|---|
| 77 | $cat_link = '<a href="category.php?id=%s">%s</a>'; |
|---|
| 78 | } else { |
|---|
| 79 | $cat_link = '%2$s'; |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; |
|---|
| 83 | switch ($this->rs->post_status) { |
|---|
| 84 | case 1: |
|---|
| 85 | $img_status = sprintf($img,__('published'),'check-on.png'); |
|---|
| 86 | break; |
|---|
| 87 | case 0: |
|---|
| 88 | $img_status = sprintf($img,__('unpublished'),'check-off.png'); |
|---|
| 89 | break; |
|---|
| 90 | case -1: |
|---|
| 91 | $img_status = sprintf($img,__('scheduled'),'scheduled.png'); |
|---|
| 92 | break; |
|---|
| 93 | case -2: |
|---|
| 94 | $img_status = sprintf($img,__('pending'),'check-wrn.png'); |
|---|
| 95 | break; |
|---|
| 96 | } |
|---|
| 97 | if ($this->rs->cat_title) { |
|---|
| 98 | $cat_title = sprintf($cat_link,$this->rs->cat_id, |
|---|
| 99 | html::escapeHTML($this->rs->cat_title)); |
|---|
| 100 | } else { |
|---|
| 101 | $cat_title = __('None'); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | $protected = ''; |
|---|
| 105 | if ($this->rs->post_password) { |
|---|
| 106 | $protected = sprintf($img,__('protected'),'locker.png'); |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | $selected = ''; |
|---|
| 110 | if ($this->rs->post_selected) { |
|---|
| 111 | $selected = sprintf($img,__('selected'),'selected.png'); |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | $attach = ''; |
|---|
| 115 | $nb_media = $this->rs->countMedia(); |
|---|
| 116 | if ($nb_media > 0) { |
|---|
| 117 | $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments'); |
|---|
| 118 | $attach = sprintf($img,sprintf($attach_str,$nb_media),'attach.png'); |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | $res = '<tr class="line'.($this->rs->post_status != 1 ? ' offline' : '').'"'. |
|---|
| 122 | ' id="p'.$this->rs->post_id.'">'; |
|---|
| 123 | |
|---|
| 124 | $res .= |
|---|
| 125 | '<td class="nowrap">'. |
|---|
| 126 | form::checkbox(array('entries[]'),$this->rs->post_id,'','','',!$this->rs->isEditable()).'</td>'. |
|---|
| 127 | '<td class="maximal"><a href="'.$this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'">'. |
|---|
| 128 | html::escapeHTML($this->rs->post_title).'</a></td>'. |
|---|
| 129 | '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>'. |
|---|
| 130 | '<td class="nowrap">'.$cat_title.'</td>'. |
|---|
| 131 | '<td class="nowrap">'.$this->rs->user_id.'</td>'. |
|---|
| 132 | '<td class="nowrap">'.$this->rs->nb_comment.'</td>'. |
|---|
| 133 | '<td class="nowrap">'.$this->rs->nb_trackback.'</td>'. |
|---|
| 134 | '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>'. |
|---|
| 135 | '</tr>'; |
|---|
| 136 | |
|---|
| 137 | return $res; |
|---|
| 138 | } |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | /* Getting threads |
|---|
| 142 | -------------------------------------------------------- */ |
|---|
| 143 | $params = array( |
|---|
| 144 | 'post_type' => $type |
|---|
| 145 | ); |
|---|
| 146 | |
|---|
| 147 | # Getting categories |
|---|
| 148 | try { |
|---|
| 149 | $categories = $core->blog->getCategories(array('post_type'=>$type)); |
|---|
| 150 | } catch (Exception $e) { |
|---|
| 151 | $core->error->add($e->getMessage()); |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | # Getting authors |
|---|
| 155 | try { |
|---|
| 156 | $users = $core->blog->getPostsUsers($type); |
|---|
| 157 | } catch (Exception $e) { |
|---|
| 158 | $core->error->add($e->getMessage()); |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | # Getting dates |
|---|
| 162 | try { |
|---|
| 163 | $dates = $core->blog->getDates(array('type'=>'month','post_type'=>$type)); |
|---|
| 164 | } catch (Exception $e) { |
|---|
| 165 | $core->error->add($e->getMessage()); |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | # Getting langs |
|---|
| 169 | try { |
|---|
| 170 | $langs = $core->blog->getLangs(); |
|---|
| 171 | } catch (Exception $e) { |
|---|
| 172 | $core->error->add($e->getMessage()); |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | # Creating filter combo boxes |
|---|
| 176 | if (!$core->error->flag()) |
|---|
| 177 | { |
|---|
| 178 | # Filter form we'll put in html_block |
|---|
| 179 | $users_combo = $categories_combo = array(); |
|---|
| 180 | $users_combo['-'] = $categories_combo['-'] = ''; |
|---|
| 181 | while ($users->fetch()) |
|---|
| 182 | { |
|---|
| 183 | $user_cn = dcUtils::getUserCN($users->user_id,$users->user_name, |
|---|
| 184 | $users->user_firstname,$users->user_displayname); |
|---|
| 185 | |
|---|
| 186 | if ($user_cn != $users->user_id) { |
|---|
| 187 | $user_cn .= ' ('.$users->user_id.')'; |
|---|
| 188 | } |
|---|
| 189 | |
|---|
| 190 | $users_combo[$user_cn] = $users->user_id; |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | while ($categories->fetch()) { |
|---|
| 194 | $categories_combo[str_repeat(' ',$categories->level-1).'• '. |
|---|
| 195 | html::escapeHTML($categories->cat_title). |
|---|
| 196 | ' ('.$categories->nb_post.')'] = $categories->cat_id; |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | $status_combo = array( |
|---|
| 200 | '-' => '' |
|---|
| 201 | ); |
|---|
| 202 | foreach ($core->blog->getAllPostStatus() as $k => $v) { |
|---|
| 203 | $status_combo[$v] = (string) $k; |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | $selected_combo = array( |
|---|
| 207 | '-' => '', |
|---|
| 208 | __('selected') => '1', |
|---|
| 209 | __('not selected') => '0' |
|---|
| 210 | ); |
|---|
| 211 | |
|---|
| 212 | # Months array |
|---|
| 213 | $dt_m_combo['-'] = ''; |
|---|
| 214 | while ($dates->fetch()) { |
|---|
| 215 | $dt_m_combo[dt::str('%B %Y',$dates->ts())] = $dates->year().$dates->month(); |
|---|
| 216 | } |
|---|
| 217 | |
|---|
| 218 | $lang_combo['-'] = ''; |
|---|
| 219 | while ($langs->fetch()) { |
|---|
| 220 | $lang_combo[$langs->post_lang] = $langs->post_lang; |
|---|
| 221 | } |
|---|
| 222 | |
|---|
| 223 | $sortby_combo = array( |
|---|
| 224 | __('Date') => 'post_dt', |
|---|
| 225 | __('Title') => 'post_title', |
|---|
| 226 | __('Category') => 'cat_title', |
|---|
| 227 | __('Author') => 'user_id', |
|---|
| 228 | __('Status') => 'post_status', |
|---|
| 229 | __('Selected') => 'post_selected' |
|---|
| 230 | ); |
|---|
| 231 | |
|---|
| 232 | $order_combo = array( |
|---|
| 233 | __('Descending') => 'desc', |
|---|
| 234 | __('Ascending') => 'asc' |
|---|
| 235 | ); |
|---|
| 236 | } |
|---|
| 237 | |
|---|
| 238 | # Actions combo box |
|---|
| 239 | $combo_action = array(); |
|---|
| 240 | if ($core->auth->check('publish,contentadmin',$core->blog->id)) |
|---|
| 241 | { |
|---|
| 242 | $combo_action[__('Status')] = array( |
|---|
| 243 | __('Publish') => 'publish', |
|---|
| 244 | __('Unpublish') => 'unpublish', |
|---|
| 245 | __('Schedule') => 'schedule', |
|---|
| 246 | __('Mark as pending') => 'pending' |
|---|
| 247 | ); |
|---|
| 248 | } |
|---|
| 249 | $combo_action[__('Mark')] = array( |
|---|
| 250 | __('Mark as selected') => 'selected', |
|---|
| 251 | __('Mark as unselected') => 'unselected' |
|---|
| 252 | ); |
|---|
| 253 | $combo_action[__('Change')] = array(__('Change category') => 'category'); |
|---|
| 254 | if ($core->auth->check('admin',$core->blog->id)) |
|---|
| 255 | { |
|---|
| 256 | $combo_action[__('Change')] = array_merge($combo_action[__('Change')], |
|---|
| 257 | array(__('Change author') => 'author')); |
|---|
| 258 | } |
|---|
| 259 | if ($core->auth->check('delete,contentadmin',$core->blog->id)) |
|---|
| 260 | { |
|---|
| 261 | $combo_action[__('Delete')] = array(__('Delete') => 'delete'); |
|---|
| 262 | } |
|---|
| 263 | |
|---|
| 264 | /* Get posts |
|---|
| 265 | -------------------------------------------------------- */ |
|---|
| 266 | $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : ''; |
|---|
| 267 | $cat_id = !empty($_GET['cat_id']) ? $_GET['cat_id'] : ''; |
|---|
| 268 | $status = isset($_GET['status']) ? $_GET['status'] : ''; |
|---|
| 269 | $selected = isset($_GET['selected']) ? $_GET['selected'] : ''; |
|---|
| 270 | $month = !empty($_GET['month']) ? $_GET['month'] : ''; |
|---|
| 271 | $lang = !empty($_GET['lang']) ? $_GET['lang'] : ''; |
|---|
| 272 | $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : 'post_dt'; |
|---|
| 273 | $order = !empty($_GET['order']) ? $_GET['order'] : 'desc'; |
|---|
| 274 | |
|---|
| 275 | $show_filters = false; |
|---|
| 276 | |
|---|
| 277 | $page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1; |
|---|
| 278 | $nb_per_page = 30; |
|---|
| 279 | |
|---|
| 280 | if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { |
|---|
| 281 | if ($nb_per_page != $_GET['nb']) { |
|---|
| 282 | $show_filters = true; |
|---|
| 283 | } |
|---|
| 284 | $nb_per_page = (integer) $_GET['nb']; |
|---|
| 285 | } |
|---|
| 286 | |
|---|
| 287 | $params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page); |
|---|
| 288 | $params['no_content'] = true; |
|---|
| 289 | |
|---|
| 290 | # - User filter |
|---|
| 291 | if ($user_id !== '' && in_array($user_id,$users_combo)) { |
|---|
| 292 | $params['user_id'] = $user_id; |
|---|
| 293 | $show_filters = true; |
|---|
| 294 | } |
|---|
| 295 | |
|---|
| 296 | # - Categories filter |
|---|
| 297 | if ($cat_id !== '' && in_array($cat_id,$categories_combo)) { |
|---|
| 298 | $params['cat_id'] = $cat_id; |
|---|
| 299 | $show_filters = true; |
|---|
| 300 | } |
|---|
| 301 | |
|---|
| 302 | # - Status filter |
|---|
| 303 | if ($status !== '' && in_array($status,$status_combo)) { |
|---|
| 304 | $params['post_status'] = $status; |
|---|
| 305 | $show_filters = true; |
|---|
| 306 | } |
|---|
| 307 | |
|---|
| 308 | # - Selected filter |
|---|
| 309 | if ($selected !== '' && in_array($selected,$selected_combo)) { |
|---|
| 310 | $params['post_selected'] = $selected; |
|---|
| 311 | $show_filters = true; |
|---|
| 312 | } |
|---|
| 313 | |
|---|
| 314 | # - Month filter |
|---|
| 315 | if ($month !== '' && in_array($month,$dt_m_combo)) { |
|---|
| 316 | $params['post_month'] = substr($month,4,2); |
|---|
| 317 | $params['post_year'] = substr($month,0,4); |
|---|
| 318 | $show_filters = true; |
|---|
| 319 | } |
|---|
| 320 | |
|---|
| 321 | # - Lang filter |
|---|
| 322 | if ($lang !== '' && in_array($lang,$lang_combo)) { |
|---|
| 323 | $params['post_lang'] = $lang; |
|---|
| 324 | $show_filters = true; |
|---|
| 325 | } |
|---|
| 326 | |
|---|
| 327 | # - Sortby and order filter |
|---|
| 328 | if ($sortby !== '' && in_array($sortby,$sortby_combo)) { |
|---|
| 329 | if ($order !== '' && in_array($order,$order_combo)) { |
|---|
| 330 | $params['order'] = $sortby.' '.$order; |
|---|
| 331 | } |
|---|
| 332 | |
|---|
| 333 | if ($sortby != 'post_dt' || $order != 'desc') { |
|---|
| 334 | $show_filters = true; |
|---|
| 335 | } |
|---|
| 336 | } |
|---|
| 337 | |
|---|
| 338 | $params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page); |
|---|
| 339 | $params['no_content'] = true; |
|---|
| 340 | //$params['order'] = 'post_position ASC, post_title ASC'; |
|---|
| 341 | |
|---|
| 342 | try { |
|---|
| 343 | $pages = $core->blog->getPosts($params); |
|---|
| 344 | $counter = $core->blog->getPosts($params,true); |
|---|
| 345 | $post_list = new adminItemList($core,$pages,$counter->f(0)); |
|---|
| 346 | } catch (Exception $e) { |
|---|
| 347 | $core->error->add($e->getMessage()); |
|---|
| 348 | } |
|---|
| 349 | |
|---|
| 350 | /* DISPLAY |
|---|
| 351 | -------------------------------------------------------- */ |
|---|
| 352 | |
|---|
| 353 | # --BEHAVIOR-- adminPagesActionsCombo |
|---|
| 354 | $core->callBehavior('adminPostsActionsCombo',array(&$combo_action)); |
|---|
| 355 | |
|---|
| 356 | /* Display |
|---|
| 357 | -------------------------------------------------------- */ |
|---|
| 358 | ?> |
|---|
| 359 | <html> |
|---|
| 360 | <head> |
|---|
| 361 | <title><?php echo $plural; ?></title> |
|---|
| 362 | <?php |
|---|
| 363 | echo dcPage::jsLoad('js/_posts_list.js'); |
|---|
| 364 | if (!$show_filters) { |
|---|
| 365 | echo dcPage::jsLoad('js/filter-controls.js'); |
|---|
| 366 | }?> |
|---|
| 367 | <script type="text/javascript"> |
|---|
| 368 | //<![CDATA[ |
|---|
| 369 | <?php echo dcPage::jsVar('dotclear.msg.confirm_delete_posts',__("Are you sure you want to delete selected entries?")); ?> |
|---|
| 370 | //]]> |
|---|
| 371 | </script> |
|---|
| 372 | </head> |
|---|
| 373 | <body> |
|---|
| 374 | <?php |
|---|
| 375 | |
|---|
| 376 | echo '<h2>'.html::escapeHTML($core->blog->name).' › '.$plural. |
|---|
| 377 | ' - <a class="button" href="'.$p_url.'&type='.$type.'">'.__('New').'</a></h2>'; |
|---|
| 378 | |
|---|
| 379 | if (!$core->error->flag()) |
|---|
| 380 | { |
|---|
| 381 | if (!$show_filters) { |
|---|
| 382 | echo '<p><a id="filter-control" class="form-control" href="#">'. |
|---|
| 383 | __('Filters').'</a></p>'; |
|---|
| 384 | } |
|---|
| 385 | |
|---|
| 386 | echo |
|---|
| 387 | '<form action="'.$p_url.'" method="get" id="filters-form">'. |
|---|
| 388 | '<fieldset><legend>'.__('Filters').'</legend>'. |
|---|
| 389 | '<div class="three-cols">'. |
|---|
| 390 | '<div class="col">'. |
|---|
| 391 | '<label>'.__('Author:'). |
|---|
| 392 | form::combo('user_id',$users_combo,$user_id).'</label> '. |
|---|
| 393 | '<label>'.__('Category:'). |
|---|
| 394 | form::combo('cat_id',$categories_combo,$cat_id).'</label> '. |
|---|
| 395 | '<label>'.__('Status:'). |
|---|
| 396 | form::combo('status',$status_combo,$status).'</label> '. |
|---|
| 397 | '</div>'. |
|---|
| 398 | |
|---|
| 399 | '<div class="col">'. |
|---|
| 400 | '<label>'.__('Selected:'). |
|---|
| 401 | form::combo('selected',$selected_combo,$selected).'</label> '. |
|---|
| 402 | '<label>'.__('Month:'). |
|---|
| 403 | form::combo('month',$dt_m_combo,$month).'</label> '. |
|---|
| 404 | '<label>'.__('Lang:'). |
|---|
| 405 | form::combo('lang',$lang_combo,$lang).'</label> '. |
|---|
| 406 | '</div>'. |
|---|
| 407 | |
|---|
| 408 | '<div class="col">'. |
|---|
| 409 | '<p><label>'.__('Order by:'). |
|---|
| 410 | form::combo('sortby',$sortby_combo,$sortby).'</label> '. |
|---|
| 411 | '<label>'.__('Sort:'). |
|---|
| 412 | form::combo('order',$order_combo,$order).'</label></p>'. |
|---|
| 413 | '<p><label class="classic">'. form::field('nb',3,3,$nb_per_page).' '. |
|---|
| 414 | __('Entries per page').'</label> '. |
|---|
| 415 | '<p><input type="hidden" name="p" value="megapost" />'. |
|---|
| 416 | '<input type="hidden" name="type" value="'.$type.'" />'. |
|---|
| 417 | '<input type="hidden" name="list" value="ok" />'. |
|---|
| 418 | '<input type="submit" value="'.__('filter').'" /></p>'. |
|---|
| 419 | '</div>'. |
|---|
| 420 | '</div>'. |
|---|
| 421 | '<br class="clear" />'. //Opera sucks |
|---|
| 422 | '</fieldset>'. |
|---|
| 423 | '</form>'; |
|---|
| 424 | |
|---|
| 425 | # Show pages |
|---|
| 426 | $post_list->display($page,$nb_per_page, |
|---|
| 427 | '<form action="posts_actions.php" method="post" id="form-entries">'. |
|---|
| 428 | |
|---|
| 429 | '%s'. |
|---|
| 430 | |
|---|
| 431 | '<div class="two-cols">'. |
|---|
| 432 | '<p class="col checkboxes-helpers"></p>'. |
|---|
| 433 | |
|---|
| 434 | '<p class="col right">'.__('Selected threads action:').' '. |
|---|
| 435 | form::combo('action',$combo_action). |
|---|
| 436 | '<input type="submit" value="'.__('ok').'" /></p>'. |
|---|
| 437 | form::hidden(array('post_type'),$type). |
|---|
| 438 | form::hidden(array('redir'),html::escapeHTML($_SERVER['REQUEST_URI'])). |
|---|
| 439 | $core->formNonce(). |
|---|
| 440 | '</div>'. |
|---|
| 441 | '</form>'); |
|---|
| 442 | } |
|---|
| 443 | ?> |
|---|
| 444 | </body> |
|---|
| 445 | </html> |
|---|