Dotclear

source: admin/posts.php @ 764:1f013109b32f

Revision 764:1f013109b32f, 5.8 KB checked in by Dsls <dsls@…>, 14 years ago (diff)

Next step in formfilters : columns now work, sorting still broken...

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2010 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
13require dirname(__FILE__).'/../inc/admin/prepend.php';
14
15dcPage::check('usage,contentadmin');
16
17# Getting categories
18try {
19     $categories = $core->blog->getCategories(array('post_type'=>'post'));
20} catch (Exception $e) {
21     $core->error->add($e->getMessage());
22}
23
24# Getting authors
25try {
26     $users = $core->blog->getPostsUsers();
27} catch (Exception $e) {
28     $core->error->add($e->getMessage());
29}
30
31# Getting dates
32try {
33     $dates = $core->blog->getDates(array('type'=>'month'));
34} catch (Exception $e) {
35     $core->error->add($e->getMessage());
36}
37
38# Getting langs
39try {
40     $langs = $core->blog->getLangs();
41} catch (Exception $e) {
42     $core->error->add($e->getMessage());
43}
44
45# Creating filter combo boxes
46if (!$core->error->flag())
47{
48     # Filter form we'll put in html_block
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     $categories_combo[__('None')] = 'NULL';
63     while ($categories->fetch()) {
64          $categories_combo[str_repeat('&nbsp;&nbsp;',$categories->level-1).'&bull; '.
65               html::escapeHTML($categories->cat_title).
66               ' ('.$categories->nb_post.')'] = $categories->cat_id;
67     }
68     
69     $status_combo = array(
70     );
71     foreach ($core->blog->getAllPostStatus() as $k => $v) {
72          $status_combo[$v] = (string) $k;
73     }
74     
75     $selected_combo = array(
76     __('is selected') => '1',
77     __('is not selected') => '0'
78     );
79     
80     # Months array
81     while ($dates->fetch()) {
82          $dt_m_combo[dt::str('%B %Y',$dates->ts())] = $dates->year().$dates->month();
83     }
84     
85     while ($langs->fetch()) {
86          $lang_combo[$langs->post_lang] = $langs->post_lang;
87     }
88}
89
90# Actions combo box
91$combo_action = array();
92if ($core->auth->check('publish,contentadmin',$core->blog->id))
93{
94     $combo_action[__('Status')] = array(
95          __('Publish') => 'publish',
96          __('Unpublish') => 'unpublish',
97          __('Schedule') => 'schedule',
98          __('Mark as pending') => 'pending'
99     );
100}
101$combo_action[__('Mark')] = array(
102     __('Mark as selected') => 'selected',
103     __('Mark as unselected') => 'unselected'
104);
105$combo_action[__('Change')] = array(__('Change category') => 'category');
106if ($core->auth->check('admin',$core->blog->id))
107{
108     $combo_action[__('Change')] = array_merge($combo_action[__('Change')],
109          array(__('Change author') => 'author'));
110}
111if ($core->auth->check('delete,contentadmin',$core->blog->id))
112{
113     $combo_action[__('Delete')] = array(__('Delete') => 'delete');
114}
115
116# --BEHAVIOR-- adminPostsActionsCombo
117$core->callBehavior('adminPostsActionsCombo',array(&$combo_action));
118
119/* Get posts
120-------------------------------------------------------- */
121$post_list = new adminPostList($core);
122
123$params = new ArrayObject();
124$params['no_content'] = true;
125
126$filterSet = new dcFilterSet('posts','posts.php');
127class monthComboFilter extends comboFilter {
128     public function applyFilter($params) {
129          $month=$this->values[0];
130          $params['post_month'] = substr($month,4,2);
131          $params['post_year'] = substr($month,0,4);
132     }
133}
134$filterSet
135     ->addFilter(new comboFilter(
136          'users',__('Author'), __('Author'), 'user_id', $users_combo))
137     ->addFilter(new categoryFilter(
138          'category',__('Category'), __('Category'), 'cat_id', $categories_combo))
139     ->addFilter(new comboFilter(
140          'post_status',__('Status'), __('Status'), 'post_status', $status_combo))
141     ->addFilter(new booleanFilter(
142          'post_selected',__('Selected'), __('The post : '),'post_selected', $selected_combo))
143     ->addFilter(new comboFilter(
144          'lang',__('Lang'), __('Lang'), 'post_lang', $lang_combo))
145     ->addFilter(new monthComboFilter(
146          'month',__('Month'),__('Month'), 'post_month', $dt_m_combo,array('singleval' => 1)))
147     ->addFilter(new textFilter(
148          'search',__('Contains'),__('The entry contains'), 'search',20,255));
149
150$core->callBehavior('adminPostsFilters',$filterSet);
151$filterSet->setExtra($post_list);
152
153$filterSet->setup($_GET,$_POST);
154
155# Get posts
156try {
157     $nfparams = $params->getArrayCopy();
158     $filtered = $filterSet->applyFilters($params);
159     $core->callBehavior('adminPostsParams',$params);
160     $posts = $core->blog->getPosts($params);
161     $counter = $core->blog->getPosts($params,true);
162     if ($filtered) {
163          $totalcounter = $core->blog->getPosts($nfparams,true);
164          $page_title = sprintf(__('Entries / %s filtered out of %s'),$counter->f(0),$totalcounter->f(0));
165     } else {
166          $page_title = __('Entries');
167          $filters_info = '';
168     }
169     $post_list->setItems($posts,$counter->f(0));
170} catch (Exception $e) {
171     $core->error->add($e->getMessage());
172}
173
174
175/* DISPLAY
176-------------------------------------------------------- */
177$starting_script = dcPage::jsLoad('js/_posts_list.js');
178
179$starting_script .= $filterSet->header();
180
181dcPage::open(__('Entries'),$starting_script);
182
183if (!$core->error->flag())
184{
185     echo 
186     '<h2>'.html::escapeHTML($core->blog->name).' &rsaquo; '.$page_title.'</h2>'.
187     '<p class="top-add"><a class="button add" href="post.php">'.__('New entry').'</a></p>';
188
189     $filterSet->display();
190     # Show posts
191     $post_list->display('<form action="posts_actions.php" method="post" id="form-entries">'.
192     
193     '%s'.
194     
195     '<div class="two-cols">'.
196     '<p class="col checkboxes-helpers"></p>'.
197     
198     '<p class="col right"><span class="filter-title">'.__('Selected entries action:').'</span> '.
199     form::combo('action',$combo_action).
200     '<input type="submit" value="'.__('ok').'" /></p>'.
201     $filterSet->getFormFieldsAsHidden().
202     $core->formNonce().
203     '</div>'.
204     '</form>'
205     );
206
207     
208     }
209
210
211dcPage::helpBlock('core_posts');
212dcPage::close();
213?>
Note: See TracBrowser for help on using the repository browser.

Sites map