Changeset 2593:6741802596a0 for admin/posts.php
- Timestamp:
- 11/27/13 16:32:38 (12 years ago)
- Branch:
- twig
- Children:
- 2612:1537212bd291, 2613:014098e27ea0
- Parents:
- 2468:d7fda5a0bd39 (diff), 2589:3d427735ca70 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
admin/posts.php
r2566 r2593 4 4 # This file is part of Dotclear 2. 5 5 # 6 # Copyright (c) 2003-201 3Olivier Meunier & Association Dotclear6 # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 7 7 # Licensed under the GPL version 2.0 license. 8 8 # See LICENSE file or … … 12 12 13 13 require dirname(__FILE__).'/../inc/admin/prepend.php'; 14 14 global $_ctx; 15 15 dcPage::check('usage,contentadmin'); 16 16 … … 47 47 { 48 48 # Filter form we'll put in html_block 49 $users_combo = array_merge( 50 array('-' => ''), 51 dcAdminCombos::getUsersCombo($users) 49 $users_combo = $categories_combo = array(); 50 while ($users->fetch()) 51 { 52 $user_cn = dcUtils::getUserCN($users->user_id,$users->user_name, 53 $users->user_firstname,$users->user_displayname); 54 55 if ($user_cn != $users->user_id) { 56 $user_cn .= ' ('.$users->user_id.')'; 57 } 58 59 $users_combo[$user_cn] = $users->user_id; 60 } 61 62 63 # Getting categories 64 $categories_combo = array(); 65 try { 66 $categories = $core->blog->getCategories(array('post_type'=>'post')); 67 while ($categories->fetch()) { 68 $categories_combo[$categories->cat_id] = 69 str_repeat(' ',$categories->level-1). 70 ($categories->level-1 == 0 ? '' : '• '). 71 html::escapeHTML($categories->cat_title); 72 } 73 } catch (Exception $e) { } 74 $status_combo = array( 52 75 ); 76 foreach ($core->blog->getAllPostStatus() as $k => $v) { 77 $status_combo[(string) $k] = (string)$v; 78 } 79 80 $selected_combo = array( 81 '1' => __('is selected'), 82 '0' => __('is not selected') 83 ); 84 85 # Months array 86 while ($dates->fetch()) { 87 $dt_m_combo[$dates->year().$dates->month()] = dt::str('%B %Y',$dates->ts()); 88 } 89 90 while ($langs->fetch()) { 91 $lang_combo[$langs->post_lang] = $langs->post_lang; 92 } 93 } 94 $form = new dcForm($core,'post','post.php'); 53 95 54 $categories_combo = array_merge( 55 array( 56 new formSelectOption('-',''), 57 new formSelectOption(__('(No cat)'),'NULL')), 58 dcAdminCombos::getCategoriesCombo($categories,false) 96 97 # Actions combo box 98 $combo_action = array(); 99 if ($core->auth->check('publish,contentadmin',$core->blog->id)) 100 { 101 $combo_action[__('Status')] = array( 102 __('Publish') => 'publish', 103 __('Unpublish') => 'unpublish', 104 __('Schedule') => 'schedule', 105 __('Mark as pending') => 'pending' 59 106 ); 60 $categories_values = array(); 61 foreach ($categories_combo as $cat) { 62 if (isset($cat->value)) { 63 $categories_values[$cat->value]=true; 64 } 107 } 108 $combo_action[__('Mark')] = array( 109 __('Mark as selected') => 'selected', 110 __('Mark as unselected') => 'unselected' 111 ); 112 $combo_action[__('Change')] = array( 113 __('Change category') => 'category', 114 __('Change language') => 'lang'); 115 if ($core->auth->check('admin',$core->blog->id)) 116 { 117 $combo_action[__('Change')] = array_merge($combo_action[__('Change')], 118 array(__('Change author') => 'author')); 119 } 120 if ($core->auth->check('delete,contentadmin',$core->blog->id)) 121 { 122 $combo_action[__('Delete')] = array(__('Delete') => 'delete'); 123 } 124 125 # --BEHAVIOR-- adminPostsActionsCombo 126 $core->callBehavior('adminPostsActionsCombo',array(&$combo_action)); 127 128 129 130 class 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); 135 } 136 } 137 138 class PostsFetcher extends dcListFetcher { 139 140 public function getEntries($params,$offset,$limit) { 141 $params['limit'] = array($offset,$limit); 142 return $this->core->blog->getPosts($params); 65 143 } 66 144 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 $attachment_combo = array( 79 '-' => '', 80 __('With attachments') => '1', 81 __('Without attachments') => '0' 82 ); 83 84 # Months array 85 $dt_m_combo = array_merge( 86 array('-' => ''), 87 dcAdminCombos::getDatesCombo($dates) 88 ); 89 90 $lang_combo = array_merge( 91 array('-' => ''), 92 dcAdminCombos::getLangsCombo($langs,false) 93 ); 94 95 $sortby_combo = array( 96 __('Date') => 'post_dt', 97 __('Title') => 'post_title', 98 __('Category') => 'cat_title', 99 __('Author') => 'user_id', 100 __('Status') => 'post_status', 101 __('Selected') => 'post_selected', 102 __('Number of comments') => 'nb_comment', 103 __('Number of trackbacks') => 'nb_trackback' 104 ); 105 106 $order_combo = array( 107 __('Descending') => 'desc', 108 __('Ascending') => 'asc' 109 ); 110 } 111 112 # Actions combo box 113 114 $posts_actions_page = new dcPostsActionsPage($core,'posts.php'); 115 116 if ($posts_actions_page->process()) { 117 return; 118 } 119 120 /* Get posts 121 -------------------------------------------------------- */ 122 $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : ''; 123 $cat_id = !empty($_GET['cat_id']) ? $_GET['cat_id'] : ''; 124 $status = isset($_GET['status']) ? $_GET['status'] : ''; 125 $selected = isset($_GET['selected']) ? $_GET['selected'] : ''; 126 $attachment = isset($_GET['attachment']) ? $_GET['attachment'] : ''; 127 $month = !empty($_GET['month']) ? $_GET['month'] : ''; 128 $lang = !empty($_GET['lang']) ? $_GET['lang'] : ''; 129 $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : 'post_dt'; 130 $order = !empty($_GET['order']) ? $_GET['order'] : 'desc'; 131 132 $show_filters = false; 133 134 $page = !empty($_GET['page']) ? max(1,(integer) $_GET['page']) : 1; 135 $nb_per_page = 30; 136 137 if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { 138 if ($nb_per_page != $_GET['nb']) { 139 $show_filters = true; 145 public function getEntriesCount($params) { 146 $count = $this->core->blog->getPosts($params,true); 147 return $count->f(0); 140 148 } 141 $nb_per_page = (integer) $_GET['nb'];142 }143 144 $params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page);145 $params['no_content'] = true;146 147 # - User filter148 if ($user_id !== '' && in_array($user_id,$users_combo)) {149 $params['user_id'] = $user_id;150 $show_filters = true;151 } else {152 $user_id='';153 }154 155 # - Categories filter156 if ($cat_id !== '' && isset($categories_values[$cat_id])) {157 $params['cat_id'] = $cat_id;158 $show_filters = true;159 } else {160 $cat_id='';161 }162 163 # - Status filter164 if ($status !== '' && in_array($status,$status_combo)) {165 $params['post_status'] = $status;166 $show_filters = true;167 } else {168 $status='';169 }170 171 # - Selected filter172 if ($selected !== '' && in_array($selected,$selected_combo)) {173 $params['post_selected'] = $selected;174 $show_filters = true;175 } else {176 $selected='';177 }178 179 # - Selected filter180 if ($attachment !== '' && in_array($attachment,$attachment_combo)) {181 $params['media'] = $attachment;182 $params['link_type'] = 'attachment';183 $show_filters = true;184 } else {185 $attachment='';186 }187 188 # - Month filter189 if ($month !== '' && in_array($month,$dt_m_combo)) {190 $params['post_month'] = substr($month,4,2);191 $params['post_year'] = substr($month,0,4);192 $show_filters = true;193 } else {194 $month='';195 }196 197 # - Lang filter198 if ($lang !== '' && in_array($lang,$lang_combo)) {199 $params['post_lang'] = $lang;200 $show_filters = true;201 } else {202 $lang='';203 }204 205 # - Sortby and order filter206 if ($sortby !== '' && in_array($sortby,$sortby_combo)) {207 if ($order !== '' && in_array($order,$order_combo)) {208 $params['order'] = $sortby.' '.$order;209 } else {210 $order='desc';211 }212 213 if ($sortby != 'post_dt' || $order != 'desc') {214 $show_filters = true;215 }216 } else {217 $sortby='post_dt';218 $order='desc';219 }220 221 # Get posts222 try {223 $posts = $core->blog->getPosts($params);224 $counter = $core->blog->getPosts($params,true);225 $post_list = new adminPostList($core,$posts,$counter->f(0));226 } catch (Exception $e) {227 $core->error->add($e->getMessage());228 149 } 229 150 230 151 /* DISPLAY 231 152 -------------------------------------------------------- */ 153 $filterSet = new dcFilterSet($core,'fposts','posts.php'); 232 154 233 $form_filter_title = __('Show filters and display options'); 234 $starting_script = dcPage::jsLoad('js/_posts_list.js'); 235 $starting_script .= dcPage::jsLoad('js/filter-controls.js'); 236 $starting_script .= 237 '<script type="text/javascript">'."\n". 238 "//<![CDATA["."\n". 239 dcPage::jsVar('dotclear.msg.show_filters', $show_filters ? 'true':'false')."\n". 240 dcPage::jsVar('dotclear.msg.filter_posts_list',$form_filter_title)."\n". 241 dcPage::jsVar('dotclear.msg.cancel_the_filter',__('Cancel filters and display options'))."\n". 242 "//]]>". 243 "</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,array( 161 'multiple' => true))) 162 ->addFilter(new dcFilterRichCombo( 163 'post_status',__('Status'), __('Status'), 'post_status', $status_combo)) 164 ->addFilter(new dcFilterRichCombo( 165 'lang',__('Lang'), __('Lang'), 'post_lang', $lang_combo)) 166 ->addFilter(new dcFilterCombo( 167 'selected',__('Selected'), __('The post : '),'post_selected', $selected_combo)) 168 ->addFilter(new monthdcFilterCombo( 169 'month',__('Month'),__('Month'), 'post_month', $dt_m_combo,array('singleval' => 1))) 170 ->addFilter(new dcFilterText( 171 'search',__('Contains'),__('The entry contains'), 'search',20,255)); 244 172 245 dcPage::open(__('Entries'),$starting_script,246 dcPage::breadcrumb(247 array(248 html::escapeHTML($core->blog->name) => '',249 __('Entries') => ''250 ))251 );252 if (!empty($_GET['upd'])) {253 dcPage::success(__('Selected entries have been successfully updated.'));254 } elseif (!empty($_GET['del'])) {255 dcPage::success(__('Selected entries have been successfully deleted.'));256 }257 if (!$core->error->flag())258 {259 echo260 '<p class="top-add"><a class="button add" href="post.php">'.__('New entry').'</a></p>'.261 '<form action="posts.php" method="get" id="filters-form">'.262 '<h3 class="out-of-screen-if-js">'.$form_filter_title.'</h3>'.263 173 264 '<div class="table">'. 265 '<div class="cell">'. 266 '<h4>'.__('Filters').'</h4>'. 267 '<p><label for="user_id" class="ib">'.__('Author:').'</label> '. 268 form::combo('user_id',$users_combo,$user_id).'</p>'. 269 '<p><label for="cat_id" class="ib">'.__('Category:').'</label> '. 270 form::combo('cat_id',$categories_combo,$cat_id).'</p>'. 271 '<p><label for="status" class="ib">'.__('Status:').'</label> ' . 272 form::combo('status',$status_combo,$status).'</p> '. 273 '</div>'. 174 $lfetcher = new PostsFetcher($core); 175 $lposts = new dcItemList ($core,array('lposts','form-entries'),$lfetcher,'posts_actions.php'); 176 $lposts->setFilterSet($filterSet); 177 $lposts->addTemplate('posts_cols.html.twig'); 274 178 275 '<div class="cell filters-sibling-cell">'. 276 '<p><label for="selected" class="ib">'.__('Selected:').'</label> '. 277 form::combo('selected',$selected_combo,$selected).'</p>'. 278 '<p><label for="attachment" class="ib">'.__('Attachments:').'</label> '. 279 form::combo('attachment',$attachment_combo,$attachment).'</p>'. 280 '<p><label for="month" class="ib">'.__('Month:').'</label> '. 281 form::combo('month',$dt_m_combo,$month).'</p>'. 282 '<p><label for="lang" class="ib">'.__('Lang:').'</label> '. 283 form::combo('lang',$lang_combo,$lang).'</p> '. 284 '</div>'. 179 $lposts 180 ->addColumn(new dcColumn('title',__('Title'),'post_title')) 181 ->addColumn(new dcColumn('cat',__('Category'),'cat_title')) 182 ->addColumn(new dcColumn('date',__('Date'),'post_date')) 183 ->addColumn(new dcColumn('datetime',__('Date and Time'),'post_dt')) 184 ->addColumn(new dcColumn('author',__('Author'),'user_id')) 185 ->addColumn(new dcColumn('status',__('Status'),'post_status')); 285 186 286 '<div class="cell filters-options">'.287 '<h4>'.__('Display options').'</h4>'.288 '<p><label for="sortby" class="ib">'.__('Order by:').'</label> '.289 form::combo('sortby',$sortby_combo,$sortby).'</p>'.290 '<p><label for="order" class="ib">'.__('Sort:').'</label> '.291 form::combo('order',$order_combo,$order).'</p>'.292 '<p><span class="label ib">'.__('Show').'</span> <label for="nb" class="classic">'.293 form::field('nb',3,3,$nb_per_page).' '.294 __('entries per page').'</label></p>'.295 '</div>'.296 '</div>'.297 187 298 '<p><input type="submit" value="'.__('Apply filters and display options').'" />'. 299 '<br class="clear" /></p>'. //Opera sucks 300 '</form>'; 188 $lposts->setup(); 301 189 302 # Show posts 303 $post_list->display($page,$nb_per_page, 304 '<form action="posts.php" method="post" id="form-entries">'. 190 $_ctx 191 ->setBreadCrumb(array(__('Entries') => 'posts.php')); 305 192 306 '%s'.307 193 308 '<div class="two-cols">'. 309 '<p class="col checkboxes-helpers"></p>'. 194 $core->tpl->display('posts.html.twig'); 310 195 311 '<p class="col right"><label for="action" class="classic">'.__('Selected entries action:').'</label> '.312 form::combo('action',$posts_actions_page->getCombo()).313 '<input type="submit" value="'.__('ok').'" /></p>'.314 form::hidden(array('user_id'),$user_id).315 form::hidden(array('cat_id'),$cat_id).316 form::hidden(array('status'),$status).317 form::hidden(array('selected'),$selected).318 form::hidden(array('attachment'),$attachment).319 form::hidden(array('month'),$month).320 form::hidden(array('lang'),$lang).321 form::hidden(array('sortby'),$sortby).322 form::hidden(array('order'),$order).323 form::hidden(array('page'),$page).324 form::hidden(array('nb'),$nb_per_page).325 $core->formNonce().326 '</div>'.327 '</form>',328 $show_filters329 );330 }331 196 332 dcPage::helpBlock('core_posts'); 333 dcPage::close(); 197 ?>
Note: See TracChangeset
for help on using the changeset viewer.