Dotclear


Ignore:
Timestamp:
08/09/13 08:01:31 (11 years ago)
Author:
Dsls
Branch:
twig
Parents:
1158:9d7267aec27b (diff), 1314:99a1319b79fc (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge with default

File:
1 edited

Legend:

Unmodified
Added
Removed
  • admin/posts.php

    r1179 r1315  
    44# This file is part of Dotclear 2. 
    55# 
    6 # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    1212 
    1313require dirname(__FILE__).'/../inc/admin/prepend.php'; 
    14  
     14global $_ctx; 
    1515dcPage::check('usage,contentadmin'); 
    1616 
     
    4848     # Filter form we'll put in html_block 
    4949     $users_combo = $categories_combo = array(); 
    50      $users_combo['-'] = $categories_combo['-'] = ''; 
    5150     while ($users->fetch()) 
    5251     { 
     
    6160     } 
    6261      
    63      $categories_combo[__('None')] = 'NULL'; 
     62 
     63# Getting categories 
     64$categories_combo = array(); 
     65try { 
     66     $categories = $core->blog->getCategories(array('post_type'=>'post')); 
    6467     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          $categories_combo[$categories->cat_id] =  
     69               str_repeat('  ',$categories->level-1). 
     70               ($categories->level-1 == 0 ? '' : '• '). 
     71               html::escapeHTML($categories->cat_title); 
    6872     } 
    69       
     73} catch (Exception $e) { } 
    7074     $status_combo = array( 
    71      '-' => '' 
    7275     ); 
    7376     foreach ($core->blog->getAllPostStatus() as $k => $v) { 
    74           $status_combo[$v] = (string) $k; 
     77          $status_combo[(string) $k] = (string)$v; 
    7578     } 
    7679      
    7780     $selected_combo = array( 
    78      '-' => '', 
    79      __('selected') => '1', 
    80      __('not selected') => '0' 
     81     '1' => __('is selected'), 
     82     '0' => __('is not selected') 
    8183     ); 
    8284      
    8385     # Months array 
    84      $dt_m_combo['-'] = ''; 
    8586     while ($dates->fetch()) { 
    86           $dt_m_combo[dt::str('%B %Y',$dates->ts())] = $dates->year().$dates->month(); 
     87          $dt_m_combo[$dates->year().$dates->month()] = dt::str('%B %Y',$dates->ts()); 
    8788     } 
    8889      
    89      $lang_combo['-'] = ''; 
    9090     while ($langs->fetch()) { 
    9191          $lang_combo[$langs->post_lang] = $langs->post_lang; 
    9292     } 
    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      ); 
    10793} 
     94$form = new dcForm($core,'post','post.php'); 
     95 
    10896 
    10997# Actions combo box 
     
    138126$core->callBehavior('adminPostsActionsCombo',array(&$combo_action)); 
    139127 
    140 /* Get posts 
    141 -------------------------------------------------------- */ 
    142 $user_id = !empty($_GET['user_id']) ?   $_GET['user_id'] : ''; 
    143 $cat_id = !empty($_GET['cat_id']) ?     $_GET['cat_id'] : ''; 
    144 $status = isset($_GET['status']) ? $_GET['status'] : ''; 
    145 $selected = isset($_GET['selected']) ?  $_GET['selected'] : ''; 
    146 $month = !empty($_GET['month']) ?       $_GET['month'] : ''; 
    147 $lang = !empty($_GET['lang']) ?         $_GET['lang'] : ''; 
    148 $sortby = !empty($_GET['sortby']) ?     $_GET['sortby'] : 'post_dt'; 
    149 $order = !empty($_GET['order']) ?       $_GET['order'] : 'desc'; 
    150128 
    151 $show_filters = false; 
    152129 
    153 $page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1; 
    154 $nb_per_page =  30; 
    155  
    156 if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { 
    157      if ($nb_per_page != $_GET['nb']) { 
    158           $show_filters = true; 
     130class monthdcFilterCombo extends dcFilterCombo { 
     131     public function applyFilter($params) { 
     132          $month=$this->avalues['values'][0]; 
     133          $params['post_month'] = substr($month,4,2); 
     134          $params['post_year'] = substr($month,0,4); 
    159135     } 
    160      $nb_per_page = (integer) $_GET['nb']; 
    161136} 
    162137 
    163 $params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page); 
    164 $params['no_content'] = true; 
     138class PostsFetcher extends dcListFetcher { 
    165139 
    166 # - User filter 
    167 if ($user_id !== '' && in_array($user_id,$users_combo)) { 
    168      $params['user_id'] = $user_id; 
    169      $show_filters = true; 
    170 } else { 
    171      $user_id=''; 
    172 } 
     140     public function getEntries($params,$offset,$limit) { 
     141          $params['limit'] = array($offset,$limit); 
     142          return $this->core->blog->getPosts($params); 
     143     } 
    173144 
    174 # - Categories filter 
    175 if ($cat_id !== '' && in_array($cat_id,$categories_combo)) { 
    176      $params['cat_id'] = $cat_id; 
    177      $show_filters = true; 
    178 } else { 
    179      $cat_id=''; 
    180 } 
    181  
    182 # - Status filter 
    183 if ($status !== '' && in_array($status,$status_combo)) { 
    184      $params['post_status'] = $status; 
    185      $show_filters = true; 
    186 } else { 
    187      $status=''; 
    188 } 
    189  
    190 # - Selected filter 
    191 if ($selected !== '' && in_array($selected,$selected_combo)) { 
    192      $params['post_selected'] = $selected; 
    193      $show_filters = true; 
    194 } else { 
    195      $selected=''; 
    196 } 
    197  
    198 # - Month filter 
    199 if ($month !== '' && in_array($month,$dt_m_combo)) { 
    200      $params['post_month'] = substr($month,4,2); 
    201      $params['post_year'] = substr($month,0,4); 
    202      $show_filters = true; 
    203 } else { 
    204      $month=''; 
    205 } 
    206  
    207 # - Lang filter 
    208 if ($lang !== '' && in_array($lang,$lang_combo)) { 
    209      $params['post_lang'] = $lang; 
    210      $show_filters = true; 
    211 } else { 
    212      $lang=''; 
    213 } 
    214  
    215 # - Sortby and order filter 
    216 if ($sortby !== '' && in_array($sortby,$sortby_combo)) { 
    217      if ($order !== '' && in_array($order,$order_combo)) { 
    218           $params['order'] = $sortby.' '.$order; 
    219      } else { 
    220           $order='desc'; 
     145     public function getEntriesCount($params) { 
     146          $count = $this->core->blog->getPosts($params,true); 
     147          return $count->f(0); 
    221148     } 
    222       
    223      if ($sortby != 'post_dt' || $order != 'desc') { 
    224           $show_filters = true; 
    225      } 
    226 } else { 
    227      $sortby='post_dt'; 
    228      $order='desc'; 
    229 } 
    230  
    231 # Get posts 
    232 try { 
    233      $posts = $core->blog->getPosts($params); 
    234      $counter = $core->blog->getPosts($params,true); 
    235      $post_list = new adminPostList($core,$posts,$counter->f(0)); 
    236 } catch (Exception $e) { 
    237      $core->error->add($e->getMessage()); 
    238149} 
    239150 
    240151/* DISPLAY 
    241152-------------------------------------------------------- */ 
    242 $starting_script = dcPage::jsLoad('js/_posts_list.js'); 
    243 if (!$show_filters) { 
    244      $starting_script .= dcPage::jsLoad('js/filter-controls.js'); 
    245 } 
     153$filterSet = new dcFilterSet($core,'fposts','posts.php'); 
    246154 
    247 dcPage::open(__('Entries'),$starting_script); 
     155$filterSet 
     156     ->addFilter(new dcFilterRichCombo( 
     157          'users',__('Author'), __('Author'), 'user_id', $users_combo,array( 
     158               'multiple' => true))) 
     159     ->addFilter(new dcFilterRichCombo( 
     160          'category',__('Category'), __('Category'), 'cat_id', $categories_combo)) 
     161     ->addFilter(new dcFilterRichCombo( 
     162          'post_status',__('Status'), __('Status'), 'post_status', $status_combo)) 
     163     ->addFilter(new dcFilterRichCombo( 
     164          'lang',__('Lang'), __('Lang'), 'post_lang', $lang_combo)) 
     165     ->addFilter(new dcFilterCombo( 
     166          'selected',__('Selected'), __('The post : '),'post_selected', $selected_combo)) 
     167     ->addFilter(new monthdcFilterCombo( 
     168          'month',__('Month'),__('Month'), 'post_month', $dt_m_combo,array('singleval' => 1))) 
     169     ->addFilter(new dcFilterText( 
     170          'search',__('Contains'),__('The entry contains'), 'search',20,255)); 
    248171 
    249 if (!$core->error->flag()) 
    250 { 
    251      echo  
    252      '<h2>'.html::escapeHTML($core->blog->name).' &rsaquo; <span class="page-title">'.__('Entries').'</span></h2>'. 
    253      '<p class="top-add"><a class="button add" href="post.php">'.__('New entry').'</a></p>'; 
    254       
    255      if (!$show_filters) { 
    256           echo '<p><a id="filter-control" class="form-control" href="#">'. 
    257           __('Filters').'</a></p>'; 
    258      } 
    259       
    260      echo 
    261      '<form action="posts.php" method="get" id="filters-form">'. 
    262      '<fieldset><legend>'.__('Filters').'</legend>'. 
    263      '<div class="three-cols">'. 
    264      '<div class="col">'. 
    265      '<label for="user_id">'.__('Author:'). 
    266      form::combo('user_id',$users_combo,$user_id).'</label> '. 
    267      '<label for="cat_id">'.__('Category:'). 
    268      form::combo('cat_id',$categories_combo,$cat_id).'</label> '. 
    269      '<label for="status">'.__('Status:'). 
    270      form::combo('status',$status_combo,$status).'</label> '. 
    271      '</div>'. 
    272       
    273      '<div class="col">'. 
    274      '<label for="selected">'.__('Selected:'). 
    275      form::combo('selected',$selected_combo,$selected).'</label> '. 
    276      '<label for="month">'.__('Month:'). 
    277      form::combo('month',$dt_m_combo,$month).'</label> '. 
    278      '<label for="lang">'.__('Lang:'). 
    279      form::combo('lang',$lang_combo,$lang).'</label> '. 
    280      '</div>'. 
    281       
    282      '<div class="col">'. 
    283      '<p><label for="sortby">'.__('Order by:'). 
    284      form::combo('sortby',$sortby_combo,$sortby).'</label> '. 
    285      '<label for="order">'.__('Sort:'). 
    286      form::combo('order',$order_combo,$order).'</label></p>'. 
    287      '<p><label for="nb" class="classic">'.  form::field('nb',3,3,$nb_per_page).' '. 
    288      __('Entries per page').'</label></p> '. 
    289      '<p><input type="submit" value="'.__('Apply filters').'" /></p>'. 
    290      '</div>'. 
    291      '</div>'. 
    292      '<br class="clear" />'. //Opera sucks 
    293      '</fieldset>'. 
    294      '</form>'; 
    295       
    296      # Show posts 
    297      $post_list->display($page,$nb_per_page, 
    298      '<form action="posts_actions.php" method="post" id="form-entries">'. 
    299       
    300      '%s'. 
    301       
    302      '<div class="two-cols">'. 
    303      '<p class="col checkboxes-helpers"></p>'. 
    304       
    305      '<p class="col right"><label for="action" class="classic">'.__('Selected entries action:').'</label> '. 
    306      form::combo('action',$combo_action). 
    307      '<input type="submit" value="'.__('ok').'" /></p>'. 
    308      form::hidden(array('user_id'),$user_id). 
    309      form::hidden(array('cat_id'),$cat_id). 
    310      form::hidden(array('status'),$status). 
    311      form::hidden(array('selected'),$selected). 
    312      form::hidden(array('month'),$month). 
    313      form::hidden(array('lang'),$lang). 
    314      form::hidden(array('sortby'),$sortby). 
    315      form::hidden(array('order'),$order). 
    316      form::hidden(array('page'),$page). 
    317      form::hidden(array('nb'),$nb_per_page). 
    318      $core->formNonce(). 
    319      '</div>'. 
    320      '</form>' 
    321      ); 
    322 } 
    323172 
    324 dcPage::helpBlock('core_posts'); 
    325 dcPage::close(); 
     173$lfetcher = new PostsFetcher($core); 
     174$lposts = new dcItemList ($core,array('lposts','form-entries'),$filterSet,$lfetcher,'posts_actions.php'); 
     175$lposts->addTemplate('posts_cols.html.twig'); 
     176 
     177$lposts 
     178     ->addColumn(new dcColumn('title',__('Title'),'post_title')) 
     179     ->addColumn(new dcColumn('cat',__('Category'),'cat_title')) 
     180     ->addColumn(new dcColumn('date',__('Date'),'post_date')) 
     181     ->addColumn(new dcColumn('datetime',__('Date and Time'),'post_dt')) 
     182     ->addColumn(new dcColumn('author',__('Author'),'user_id')) 
     183     ->addColumn(new dcColumn('status',__('Status'),'post_status')); 
     184 
     185 
     186$lposts->setup(); 
     187 
     188$_ctx 
     189     ->fillPageTitle(__('Entries'),'posts.php'); 
     190 
     191 
     192$core->tpl->display('posts.html.twig'); 
     193 
     194 
    326195?> 
Note: See TracChangeset for help on using the changeset viewer.

Sites map