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 = $categories_combo = array(); |
---|
50 | $users_combo['-'] = $categories_combo['-'] = ''; |
---|
51 | while ($users->fetch()) |
---|
52 | { |
---|
53 | $user_cn = dcUtils::getUserCN($users->user_id,$users->user_name, |
---|
54 | $users->user_firstname,$users->user_displayname); |
---|
55 | |
---|
56 | if ($user_cn != $users->user_id) { |
---|
57 | $user_cn .= ' ('.$users->user_id.')'; |
---|
58 | } |
---|
59 | |
---|
60 | $users_combo[$user_cn] = $users->user_id; |
---|
61 | } |
---|
62 | |
---|
63 | $categories_combo[__('None')] = 'NULL'; |
---|
64 | 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 | } |
---|
69 | |
---|
70 | $status_combo = array( |
---|
71 | '-' => '' |
---|
72 | ); |
---|
73 | foreach ($core->blog->getAllPostStatus() as $k => $v) { |
---|
74 | $status_combo[$v] = (string) $k; |
---|
75 | } |
---|
76 | |
---|
77 | $selected_combo = array( |
---|
78 | '-' => '', |
---|
79 | __('Selected') => '1', |
---|
80 | __('Not selected') => '0' |
---|
81 | ); |
---|
82 | |
---|
83 | # Months array |
---|
84 | $dt_m_combo['-'] = ''; |
---|
85 | while ($dates->fetch()) { |
---|
86 | $dt_m_combo[dt::str('%B %Y',$dates->ts())] = $dates->year().$dates->month(); |
---|
87 | } |
---|
88 | |
---|
89 | $lang_combo['-'] = ''; |
---|
90 | while ($langs->fetch()) { |
---|
91 | $lang_combo[$langs->post_lang] = $langs->post_lang; |
---|
92 | } |
---|
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 | ); |
---|
107 | } |
---|
108 | |
---|
109 | # Actions combo box |
---|
110 | $combo_action = array(); |
---|
111 | if ($core->auth->check('publish,contentadmin',$core->blog->id)) |
---|
112 | { |
---|
113 | $combo_action[__('Status')] = array( |
---|
114 | __('Publish') => 'publish', |
---|
115 | __('Unpublish') => 'unpublish', |
---|
116 | __('Schedule') => 'schedule', |
---|
117 | __('Mark as pending') => 'pending' |
---|
118 | ); |
---|
119 | } |
---|
120 | $combo_action[__('Mark')] = array( |
---|
121 | __('Mark as selected') => 'selected', |
---|
122 | __('Mark as unselected') => 'unselected' |
---|
123 | ); |
---|
124 | $combo_action[__('Change')] = array( |
---|
125 | __('Change category') => 'category', |
---|
126 | __('Change language') => 'lang'); |
---|
127 | if ($core->auth->check('admin',$core->blog->id)) |
---|
128 | { |
---|
129 | $combo_action[__('Change')] = array_merge($combo_action[__('Change')], |
---|
130 | array(__('Change author') => 'author')); |
---|
131 | } |
---|
132 | if ($core->auth->check('delete,contentadmin',$core->blog->id)) |
---|
133 | { |
---|
134 | $combo_action[__('Delete')] = array(__('Delete') => 'delete'); |
---|
135 | } |
---|
136 | |
---|
137 | # --BEHAVIOR-- adminPostsActionsCombo |
---|
138 | $core->callBehavior('adminPostsActionsCombo',array(&$combo_action)); |
---|
139 | |
---|
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'; |
---|
150 | |
---|
151 | $show_filters = false; |
---|
152 | |
---|
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; |
---|
159 | } |
---|
160 | $nb_per_page = (integer) $_GET['nb']; |
---|
161 | } |
---|
162 | |
---|
163 | $params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page); |
---|
164 | $params['no_content'] = true; |
---|
165 | |
---|
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 | } |
---|
173 | |
---|
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'; |
---|
221 | } |
---|
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()); |
---|
238 | } |
---|
239 | |
---|
240 | /* DISPLAY |
---|
241 | -------------------------------------------------------- */ |
---|
242 | $starting_script = dcPage::jsLoad('js/_posts_list.js'); |
---|
243 | if (!$show_filters) { |
---|
244 | $starting_script .= dcPage::jsLoad('js/filter-controls.js'); |
---|
245 | } |
---|
246 | |
---|
247 | dcPage::open(__('Entries'),$starting_script, |
---|
248 | dcPage::breadcrumb( |
---|
249 | array( |
---|
250 | html::escapeHTML($core->blog->name) => '', |
---|
251 | '<span class="page-title">'.__('Entries').'</span>' => '' |
---|
252 | )) |
---|
253 | ); |
---|
254 | if (!empty($_GET['upd'])) { |
---|
255 | dcPage::message(__('Selected entries have been successfully updated.')); |
---|
256 | } elseif (!empty($_GET['del'])) { |
---|
257 | dcPage::message(__('Selected entries have been successfully deleted.')); |
---|
258 | } |
---|
259 | if (!$core->error->flag()) |
---|
260 | { |
---|
261 | echo |
---|
262 | '<p class="top-add"><a class="button add" href="post.php">'.__('New entry').'</a></p>'; |
---|
263 | |
---|
264 | if (!$show_filters) { |
---|
265 | echo '<p><a id="filter-control" class="form-control" href="#">'. |
---|
266 | __('Filter posts list').'</a></p>'; |
---|
267 | } |
---|
268 | |
---|
269 | echo |
---|
270 | '<form action="posts.php" method="get" id="filters-form">'. |
---|
271 | '<h3 class="hidden">'.__('Filter posts list').'</h3>'. |
---|
272 | |
---|
273 | '<div class="table">'. |
---|
274 | '<div class="cell">'. |
---|
275 | '<h4>'.__('Filters').'</h4>'. |
---|
276 | '<p><label for="user_id" class="ib">'.__('Author:').'</label> '. |
---|
277 | form::combo('user_id',$users_combo,$user_id).'</p>'. |
---|
278 | '<p><label for="cat_id" class="ib">'.__('Category:').'</label> '. |
---|
279 | form::combo('cat_id',$categories_combo,$cat_id).'</p>'. |
---|
280 | '<p><label for="status" class="ib">'.__('Status:').'</label> ' . |
---|
281 | form::combo('status',$status_combo,$status).'</p> '. |
---|
282 | '</div>'. |
---|
283 | |
---|
284 | '<div class="cell filters-sibling-cell">'. |
---|
285 | '<p><label for="selected" class="ib">'.__('Selected:').'</label> '. |
---|
286 | form::combo('selected',$selected_combo,$selected).'</p>'. |
---|
287 | '<p><label for="month" class="ib">'.__('Month:').'</label> '. |
---|
288 | form::combo('month',$dt_m_combo,$month).'</p>'. |
---|
289 | '<p><label for="lang" class="ib">'.__('Lang:').'</label> '. |
---|
290 | form::combo('lang',$lang_combo,$lang).'</p> '. |
---|
291 | '</div>'. |
---|
292 | |
---|
293 | '<div class="cell filters-options">'. |
---|
294 | '<h4>'.__('Display options').'</h4>'. |
---|
295 | '<p><label for="sortby" class="ib">'.__('Order by:').'</label> '. |
---|
296 | form::combo('sortby',$sortby_combo,$sortby).'</p>'. |
---|
297 | '<p><label for="order" class="ib">'.__('Sort:').'</label> '. |
---|
298 | form::combo('order',$order_combo,$order).'</p>'. |
---|
299 | '<p><span class="label ib">'.__('Show').'</span> <label for="nb" class="classic">'. |
---|
300 | form::field('nb',3,3,$nb_per_page).' '. |
---|
301 | __('entries per page').'</label></p>'. |
---|
302 | '</div>'. |
---|
303 | '</div>'. |
---|
304 | |
---|
305 | '<p><input type="submit" value="'.__('Apply filters and display options').'" />'. |
---|
306 | '<br class="clear" /></p>'. //Opera sucks |
---|
307 | '</form>'; |
---|
308 | |
---|
309 | # Show posts |
---|
310 | $post_list->display($page,$nb_per_page, |
---|
311 | '<form action="posts_actions.php" method="post" id="form-entries">'. |
---|
312 | |
---|
313 | '%s'. |
---|
314 | |
---|
315 | '<div class="two-cols">'. |
---|
316 | '<p class="col checkboxes-helpers"></p>'. |
---|
317 | |
---|
318 | '<p class="col right"><label for="action" class="classic">'.__('Selected entries action:').'</label> '. |
---|
319 | form::combo('action',$combo_action). |
---|
320 | '<input type="submit" value="'.__('ok').'" /></p>'. |
---|
321 | form::hidden(array('user_id'),$user_id). |
---|
322 | form::hidden(array('cat_id'),$cat_id). |
---|
323 | form::hidden(array('status'),$status). |
---|
324 | form::hidden(array('selected'),$selected). |
---|
325 | form::hidden(array('month'),$month). |
---|
326 | form::hidden(array('lang'),$lang). |
---|
327 | form::hidden(array('sortby'),$sortby). |
---|
328 | form::hidden(array('order'),$order). |
---|
329 | form::hidden(array('page'),$page). |
---|
330 | form::hidden(array('nb'),$nb_per_page). |
---|
331 | $core->formNonce(). |
---|
332 | '</div>'. |
---|
333 | '</form>' |
---|
334 | ); |
---|
335 | } |
---|
336 | |
---|
337 | dcPage::helpBlock('core_posts'); |
---|
338 | dcPage::close(); |
---|
339 | ?> |
---|