1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
3 | # |
---|
4 | # This file is part of Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2003-2013 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 categories |
---|
18 | try { |
---|
19 | $categories = $core->blog->getCategories(array('post_type'=>'post')); |
---|
20 | } catch (Exception $e) { |
---|
21 | $core->error->add($e->getMessage()); |
---|
22 | } |
---|
23 | |
---|
24 | # Getting authors |
---|
25 | try { |
---|
26 | $users = $core->blog->getPostsUsers(); |
---|
27 | } catch (Exception $e) { |
---|
28 | $core->error->add($e->getMessage()); |
---|
29 | } |
---|
30 | |
---|
31 | # Getting dates |
---|
32 | try { |
---|
33 | $dates = $core->blog->getDates(array('type'=>'month')); |
---|
34 | } catch (Exception $e) { |
---|
35 | $core->error->add($e->getMessage()); |
---|
36 | } |
---|
37 | |
---|
38 | # Getting langs |
---|
39 | try { |
---|
40 | $langs = $core->blog->getLangs(); |
---|
41 | } catch (Exception $e) { |
---|
42 | $core->error->add($e->getMessage()); |
---|
43 | } |
---|
44 | |
---|
45 | # Creating filter combo boxes |
---|
46 | if (!$core->error->flag()) |
---|
47 | { |
---|
48 | # Filter form we'll put in html_block |
---|
49 | $users_combo = array_merge( |
---|
50 | array('-' => ''), |
---|
51 | dcAdminCombos::getUsersCombo($users) |
---|
52 | ); |
---|
53 | |
---|
54 | $categories_combo = array_merge( |
---|
55 | array('-' => ''), |
---|
56 | dcAdminCombos::getCategoriesCombo($categories) |
---|
57 | ); |
---|
58 | $categories_combo[__('(No cat)')] = 'NULL'; |
---|
59 | |
---|
60 | $status_combo = array_merge( |
---|
61 | array('-' => ''), |
---|
62 | dcAdminCombos::getPostStatusesCombo() |
---|
63 | ); |
---|
64 | |
---|
65 | $selected_combo = array( |
---|
66 | '-' => '', |
---|
67 | __('Selected') => '1', |
---|
68 | __('Not selected') => '0' |
---|
69 | ); |
---|
70 | |
---|
71 | # Months array |
---|
72 | $dt_m_combo = array_merge( |
---|
73 | array('-' => ''), |
---|
74 | dcAdminCombos::getDatesCombo($dates) |
---|
75 | ); |
---|
76 | |
---|
77 | $lang_combo = array_merge( |
---|
78 | array('-' => ''), |
---|
79 | dcAdminCombos::getLangsCombo($langs,false) |
---|
80 | ); |
---|
81 | |
---|
82 | $sortby_combo = array( |
---|
83 | __('Date') => 'post_dt', |
---|
84 | __('Title') => 'post_title', |
---|
85 | __('Category') => 'cat_title', |
---|
86 | __('Author') => 'user_id', |
---|
87 | __('Status') => 'post_status', |
---|
88 | __('Selected') => 'post_selected' |
---|
89 | ); |
---|
90 | |
---|
91 | $order_combo = array( |
---|
92 | __('Descending') => 'desc', |
---|
93 | __('Ascending') => 'asc' |
---|
94 | ); |
---|
95 | } |
---|
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' |
---|
106 | ); |
---|
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 | /* Get posts |
---|
129 | -------------------------------------------------------- */ |
---|
130 | $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : ''; |
---|
131 | $cat_id = !empty($_GET['cat_id']) ? $_GET['cat_id'] : ''; |
---|
132 | $status = isset($_GET['status']) ? $_GET['status'] : ''; |
---|
133 | $selected = isset($_GET['selected']) ? $_GET['selected'] : ''; |
---|
134 | $month = !empty($_GET['month']) ? $_GET['month'] : ''; |
---|
135 | $lang = !empty($_GET['lang']) ? $_GET['lang'] : ''; |
---|
136 | $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : 'post_dt'; |
---|
137 | $order = !empty($_GET['order']) ? $_GET['order'] : 'desc'; |
---|
138 | |
---|
139 | $show_filters = false; |
---|
140 | |
---|
141 | $page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1; |
---|
142 | $nb_per_page = 30; |
---|
143 | |
---|
144 | if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { |
---|
145 | if ($nb_per_page != $_GET['nb']) { |
---|
146 | $show_filters = true; |
---|
147 | } |
---|
148 | $nb_per_page = (integer) $_GET['nb']; |
---|
149 | } |
---|
150 | |
---|
151 | $params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page); |
---|
152 | $params['no_content'] = true; |
---|
153 | |
---|
154 | # - User filter |
---|
155 | if ($user_id !== '' && in_array($user_id,$users_combo)) { |
---|
156 | $params['user_id'] = $user_id; |
---|
157 | $show_filters = true; |
---|
158 | } else { |
---|
159 | $user_id=''; |
---|
160 | } |
---|
161 | |
---|
162 | # - Categories filter |
---|
163 | if ($cat_id !== '' && in_array($cat_id,$categories_combo)) { |
---|
164 | $params['cat_id'] = $cat_id; |
---|
165 | $show_filters = true; |
---|
166 | } else { |
---|
167 | $cat_id=''; |
---|
168 | } |
---|
169 | |
---|
170 | # - Status filter |
---|
171 | if ($status !== '' && in_array($status,$status_combo)) { |
---|
172 | $params['post_status'] = $status; |
---|
173 | $show_filters = true; |
---|
174 | } else { |
---|
175 | $status=''; |
---|
176 | } |
---|
177 | |
---|
178 | # - Selected filter |
---|
179 | if ($selected !== '' && in_array($selected,$selected_combo)) { |
---|
180 | $params['post_selected'] = $selected; |
---|
181 | $show_filters = true; |
---|
182 | } else { |
---|
183 | $selected=''; |
---|
184 | } |
---|
185 | |
---|
186 | # - Month filter |
---|
187 | if ($month !== '' && in_array($month,$dt_m_combo)) { |
---|
188 | $params['post_month'] = substr($month,4,2); |
---|
189 | $params['post_year'] = substr($month,0,4); |
---|
190 | $show_filters = true; |
---|
191 | } else { |
---|
192 | $month=''; |
---|
193 | } |
---|
194 | |
---|
195 | # - Lang filter |
---|
196 | if ($lang !== '' && in_array($lang,$lang_combo)) { |
---|
197 | $params['post_lang'] = $lang; |
---|
198 | $show_filters = true; |
---|
199 | } else { |
---|
200 | $lang=''; |
---|
201 | } |
---|
202 | |
---|
203 | # - Sortby and order filter |
---|
204 | if ($sortby !== '' && in_array($sortby,$sortby_combo)) { |
---|
205 | if ($order !== '' && in_array($order,$order_combo)) { |
---|
206 | $params['order'] = $sortby.' '.$order; |
---|
207 | } else { |
---|
208 | $order='desc'; |
---|
209 | } |
---|
210 | |
---|
211 | if ($sortby != 'post_dt' || $order != 'desc') { |
---|
212 | $show_filters = true; |
---|
213 | } |
---|
214 | } else { |
---|
215 | $sortby='post_dt'; |
---|
216 | $order='desc'; |
---|
217 | } |
---|
218 | |
---|
219 | # Get posts |
---|
220 | try { |
---|
221 | $posts = $core->blog->getPosts($params); |
---|
222 | $counter = $core->blog->getPosts($params,true); |
---|
223 | $post_list = new adminPostList($core,$posts,$counter->f(0)); |
---|
224 | } catch (Exception $e) { |
---|
225 | $core->error->add($e->getMessage()); |
---|
226 | } |
---|
227 | |
---|
228 | /* DISPLAY |
---|
229 | -------------------------------------------------------- */ |
---|
230 | $starting_script = dcPage::jsLoad('js/_posts_list.js'); |
---|
231 | if (!$show_filters) { |
---|
232 | $starting_script .= dcPage::jsLoad('js/filter-controls.js'); |
---|
233 | } |
---|
234 | |
---|
235 | dcPage::open(__('Entries'),$starting_script, |
---|
236 | dcPage::breadcrumb( |
---|
237 | array( |
---|
238 | html::escapeHTML($core->blog->name) => '', |
---|
239 | '<span class="page-title">'.__('Entries').'</span>' => '' |
---|
240 | )) |
---|
241 | ); |
---|
242 | if (!empty($_GET['upd'])) { |
---|
243 | dcPage::success(__('Selected entries have been successfully updated.')); |
---|
244 | } elseif (!empty($_GET['del'])) { |
---|
245 | dcPage::success(__('Selected entries have been successfully deleted.')); |
---|
246 | } |
---|
247 | if (!$core->error->flag()) |
---|
248 | { |
---|
249 | echo |
---|
250 | '<p class="top-add"><a class="button add" href="post.php">'.__('New entry').'</a></p>'; |
---|
251 | |
---|
252 | if (!$show_filters) { |
---|
253 | echo '<p><a id="filter-control" class="form-control" href="#">'. |
---|
254 | __('Filter posts list').'</a></p>'; |
---|
255 | } |
---|
256 | |
---|
257 | echo |
---|
258 | '<form action="posts.php" method="get" id="filters-form">'. |
---|
259 | '<h3 class="hidden">'.__('Filter posts list').'</h3>'. |
---|
260 | |
---|
261 | '<div class="table">'. |
---|
262 | '<div class="cell">'. |
---|
263 | '<h4>'.__('Filters').'</h4>'. |
---|
264 | '<p><label for="user_id" class="ib">'.__('Author:').'</label> '. |
---|
265 | form::combo('user_id',$users_combo,$user_id).'</p>'. |
---|
266 | '<p><label for="cat_id" class="ib">'.__('Category:').'</label> '. |
---|
267 | form::combo('cat_id',$categories_combo,$cat_id).'</p>'. |
---|
268 | '<p><label for="status" class="ib">'.__('Status:').'</label> ' . |
---|
269 | form::combo('status',$status_combo,$status).'</p> '. |
---|
270 | '</div>'. |
---|
271 | |
---|
272 | '<div class="cell filters-sibling-cell">'. |
---|
273 | '<p><label for="selected" class="ib">'.__('Selected:').'</label> '. |
---|
274 | form::combo('selected',$selected_combo,$selected).'</p>'. |
---|
275 | '<p><label for="month" class="ib">'.__('Month:').'</label> '. |
---|
276 | form::combo('month',$dt_m_combo,$month).'</p>'. |
---|
277 | '<p><label for="lang" class="ib">'.__('Lang:').'</label> '. |
---|
278 | form::combo('lang',$lang_combo,$lang).'</p> '. |
---|
279 | '</div>'. |
---|
280 | |
---|
281 | '<div class="cell filters-options">'. |
---|
282 | '<h4>'.__('Display options').'</h4>'. |
---|
283 | '<p><label for="sortby" class="ib">'.__('Order by:').'</label> '. |
---|
284 | form::combo('sortby',$sortby_combo,$sortby).'</p>'. |
---|
285 | '<p><label for="order" class="ib">'.__('Sort:').'</label> '. |
---|
286 | form::combo('order',$order_combo,$order).'</p>'. |
---|
287 | '<p><span class="label ib">'.__('Show').'</span> <label for="nb" class="classic">'. |
---|
288 | form::field('nb',3,3,$nb_per_page).' '. |
---|
289 | __('entries per page').'</label></p>'. |
---|
290 | '</div>'. |
---|
291 | '</div>'. |
---|
292 | |
---|
293 | '<p><input type="submit" value="'.__('Apply filters and display options').'" />'. |
---|
294 | '<br class="clear" /></p>'. //Opera sucks |
---|
295 | '</form>'; |
---|
296 | |
---|
297 | # Show posts |
---|
298 | $post_list->display($page,$nb_per_page, |
---|
299 | '<form action="posts_actions.php" method="post" id="form-entries">'. |
---|
300 | |
---|
301 | '%s'. |
---|
302 | |
---|
303 | '<div class="two-cols">'. |
---|
304 | '<p class="col checkboxes-helpers"></p>'. |
---|
305 | |
---|
306 | '<p class="col right"><label for="action" class="classic">'.__('Selected entries action:').'</label> '. |
---|
307 | form::combo('action',$combo_action). |
---|
308 | '<input type="submit" value="'.__('ok').'" /></p>'. |
---|
309 | form::hidden(array('user_id'),$user_id). |
---|
310 | form::hidden(array('cat_id'),$cat_id). |
---|
311 | form::hidden(array('status'),$status). |
---|
312 | form::hidden(array('selected'),$selected). |
---|
313 | form::hidden(array('month'),$month). |
---|
314 | form::hidden(array('lang'),$lang). |
---|
315 | form::hidden(array('sortby'),$sortby). |
---|
316 | form::hidden(array('order'),$order). |
---|
317 | form::hidden(array('page'),$page). |
---|
318 | form::hidden(array('nb'),$nb_per_page). |
---|
319 | $core->formNonce(). |
---|
320 | '</div>'. |
---|
321 | '</form>' |
---|
322 | ); |
---|
323 | } |
---|
324 | |
---|
325 | dcPage::helpBlock('core_posts'); |
---|
326 | dcPage::close(); |
---|
327 | ?> |
---|