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(); |
---|
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 | # Filter form we'll put in html_block |
---|
48 | $users_combo = dcAdminCombos::getUsersCombo($users); |
---|
49 | dcUtils::lexicalKeySort($users_combo); |
---|
50 | $users_combo = array_merge( |
---|
51 | array('-' => ''), |
---|
52 | $users_combo |
---|
53 | ); |
---|
54 | |
---|
55 | $categories_combo = array_merge( |
---|
56 | array( |
---|
57 | new formSelectOption('-', ''), |
---|
58 | new formSelectOption(__('(No cat)'), 'NULL')), |
---|
59 | dcAdminCombos::getCategoriesCombo($categories, false) |
---|
60 | ); |
---|
61 | $categories_values = array(); |
---|
62 | foreach ($categories_combo as $cat) { |
---|
63 | if (isset($cat->value)) { |
---|
64 | $categories_values[$cat->value] = true; |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | $status_combo = array_merge( |
---|
69 | array('-' => ''), |
---|
70 | dcAdminCombos::getPostStatusesCombo() |
---|
71 | ); |
---|
72 | |
---|
73 | $selected_combo = array( |
---|
74 | '-' => '', |
---|
75 | __('Selected') => '1', |
---|
76 | __('Not selected') => '0' |
---|
77 | ); |
---|
78 | |
---|
79 | $comment_combo = array( |
---|
80 | '-' => '', |
---|
81 | __('Opened') => '1', |
---|
82 | __('Closed') => '0' |
---|
83 | ); |
---|
84 | |
---|
85 | $trackback_combo = array( |
---|
86 | '-' => '', |
---|
87 | __('Opened') => '1', |
---|
88 | __('Closed') => '0' |
---|
89 | ); |
---|
90 | |
---|
91 | $attachment_combo = array( |
---|
92 | '-' => '', |
---|
93 | __('With attachments') => '1', |
---|
94 | __('Without attachments') => '0' |
---|
95 | ); |
---|
96 | |
---|
97 | $password_combo = array( |
---|
98 | '-' => '', |
---|
99 | __('With password') => '1', |
---|
100 | __('Without password') => '0' |
---|
101 | ); |
---|
102 | |
---|
103 | # Months array |
---|
104 | $dt_m_combo = array_merge( |
---|
105 | array('-' => ''), |
---|
106 | dcAdminCombos::getDatesCombo($dates) |
---|
107 | ); |
---|
108 | |
---|
109 | $lang_combo = array_merge( |
---|
110 | array('-' => ''), |
---|
111 | dcAdminCombos::getLangsCombo($langs, false) |
---|
112 | ); |
---|
113 | |
---|
114 | # Post formats |
---|
115 | $core_formaters = $core->getFormaters(); |
---|
116 | $available_formats = array(); |
---|
117 | foreach ($core_formaters as $editor => $formats) { |
---|
118 | foreach ($formats as $format) { |
---|
119 | $available_formats[$format] = $format; |
---|
120 | } |
---|
121 | } |
---|
122 | $format_combo = array_merge( |
---|
123 | array('-' => ''), |
---|
124 | $available_formats |
---|
125 | ); |
---|
126 | |
---|
127 | $sortby_combo = array( |
---|
128 | __('Date') => 'post_dt', |
---|
129 | __('Title') => 'post_title', |
---|
130 | __('Category') => 'cat_title', |
---|
131 | __('Author') => 'user_id', |
---|
132 | __('Status') => 'post_status', |
---|
133 | __('Selected') => 'post_selected', |
---|
134 | __('Number of comments') => 'nb_comment', |
---|
135 | __('Number of trackbacks') => 'nb_trackback' |
---|
136 | ); |
---|
137 | |
---|
138 | $sortby_lex = array( |
---|
139 | // key in sorty_combo (see above) => field in SQL request |
---|
140 | 'post_title' => 'post_title', |
---|
141 | 'cat_title' => 'cat_title', |
---|
142 | 'user_id' => 'P.user_id'); |
---|
143 | |
---|
144 | $order_combo = array( |
---|
145 | __('Descending') => 'desc', |
---|
146 | __('Ascending') => 'asc' |
---|
147 | ); |
---|
148 | } |
---|
149 | |
---|
150 | # Actions combo box |
---|
151 | |
---|
152 | $posts_actions_page = new dcPostsActionsPage($core, $core->adminurl->get("admin.posts")); |
---|
153 | |
---|
154 | if ($posts_actions_page->process()) { |
---|
155 | return; |
---|
156 | } |
---|
157 | |
---|
158 | /* Get posts |
---|
159 | -------------------------------------------------------- */ |
---|
160 | $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : ''; |
---|
161 | $cat_id = !empty($_GET['cat_id']) ? $_GET['cat_id'] : ''; |
---|
162 | $status = isset($_GET['status']) ? $_GET['status'] : ''; |
---|
163 | $password = isset($_GET['password']) ? $_GET['password'] : ''; |
---|
164 | $selected = isset($_GET['selected']) ? $_GET['selected'] : ''; |
---|
165 | $comment = isset($_GET['comment']) ? $_GET['comment'] : ''; |
---|
166 | $trackback = isset($_GET['trackback']) ? $_GET['trackback'] : ''; |
---|
167 | $attachment = isset($_GET['attachment']) ? $_GET['attachment'] : ''; |
---|
168 | $month = !empty($_GET['month']) ? $_GET['month'] : ''; |
---|
169 | $lang = !empty($_GET['lang']) ? $_GET['lang'] : ''; |
---|
170 | $format = !empty($_GET['format']) ? $_GET['format'] : ''; |
---|
171 | $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : 'post_dt'; |
---|
172 | $order = !empty($_GET['order']) ? $_GET['order'] : 'desc'; |
---|
173 | |
---|
174 | $show_filters = false; |
---|
175 | |
---|
176 | $page = !empty($_GET['page']) ? max(1, (integer) $_GET['page']) : 1; |
---|
177 | $nb_per_page = 30; |
---|
178 | |
---|
179 | if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { |
---|
180 | if ($nb_per_page != (integer) $_GET['nb']) { |
---|
181 | $show_filters = true; |
---|
182 | } |
---|
183 | $nb_per_page = (integer) $_GET['nb']; |
---|
184 | } |
---|
185 | |
---|
186 | $params['limit'] = array((($page - 1) * $nb_per_page), $nb_per_page); |
---|
187 | $params['no_content'] = true; |
---|
188 | $params['where'] = ''; |
---|
189 | |
---|
190 | # - User filter |
---|
191 | if ($user_id !== '' && in_array($user_id, $users_combo)) { |
---|
192 | $params['user_id'] = $user_id; |
---|
193 | $show_filters = true; |
---|
194 | } else { |
---|
195 | $user_id = ''; |
---|
196 | } |
---|
197 | |
---|
198 | # - Categories filter |
---|
199 | if ($cat_id !== '' && isset($categories_values[$cat_id])) { |
---|
200 | $params['cat_id'] = $cat_id; |
---|
201 | $show_filters = true; |
---|
202 | } else { |
---|
203 | $cat_id = ''; |
---|
204 | } |
---|
205 | |
---|
206 | # - Status filter |
---|
207 | if ($status !== '' && in_array($status, $status_combo)) { |
---|
208 | $params['post_status'] = $status; |
---|
209 | $show_filters = true; |
---|
210 | } else { |
---|
211 | $status = ''; |
---|
212 | } |
---|
213 | |
---|
214 | # - Password filter |
---|
215 | if ($password !== '' && in_array($password, $password_combo)) { |
---|
216 | $params['where'] .= ' AND post_password IS ' . ($password ? 'NOT ' : '') . 'NULL '; |
---|
217 | $show_filters = true; |
---|
218 | } else { |
---|
219 | $password = ''; |
---|
220 | } |
---|
221 | |
---|
222 | # - Selected filter |
---|
223 | if ($selected !== '' && in_array($selected, $selected_combo)) { |
---|
224 | $params['post_selected'] = $selected; |
---|
225 | $show_filters = true; |
---|
226 | } else { |
---|
227 | $selected = ''; |
---|
228 | } |
---|
229 | |
---|
230 | # - Comment filter |
---|
231 | if ($comment !== '' && in_array($comment, $comment_combo)) { |
---|
232 | $params['where'] .= " AND post_open_comment = '" . $comment . "' "; |
---|
233 | $show_filters = true; |
---|
234 | } else { |
---|
235 | $comment = ''; |
---|
236 | } |
---|
237 | |
---|
238 | # - Comment filter |
---|
239 | if ($trackback !== '' && in_array($trackback, $trackback_combo)) { |
---|
240 | $params['where'] .= " AND post_open_tb = '" . $trackback . "' "; |
---|
241 | $show_filters = true; |
---|
242 | } else { |
---|
243 | $trackback = ''; |
---|
244 | } |
---|
245 | |
---|
246 | # - Attachment filter |
---|
247 | if ($attachment !== '' && in_array($attachment, $attachment_combo)) { |
---|
248 | $params['media'] = $attachment; |
---|
249 | $params['link_type'] = 'attachment'; |
---|
250 | $show_filters = true; |
---|
251 | } else { |
---|
252 | $attachment = ''; |
---|
253 | } |
---|
254 | |
---|
255 | # - Month filter |
---|
256 | if ($month !== '' && in_array($month, $dt_m_combo)) { |
---|
257 | $params['post_month'] = substr($month, 4, 2); |
---|
258 | $params['post_year'] = substr($month, 0, 4); |
---|
259 | $show_filters = true; |
---|
260 | } else { |
---|
261 | $month = ''; |
---|
262 | } |
---|
263 | |
---|
264 | # - Lang filter |
---|
265 | if ($lang !== '' && in_array($lang, $lang_combo)) { |
---|
266 | $params['post_lang'] = $lang; |
---|
267 | $show_filters = true; |
---|
268 | } else { |
---|
269 | $lang = ''; |
---|
270 | } |
---|
271 | |
---|
272 | # - Format filter |
---|
273 | if ($format !== '' && in_array($format, $format_combo)) { |
---|
274 | $params['where'] .= " AND post_format = '" . $format . "' "; |
---|
275 | $show_filters = true; |
---|
276 | } else { |
---|
277 | $format = ''; |
---|
278 | } |
---|
279 | |
---|
280 | # - Sortby and order filter |
---|
281 | if ($sortby !== '' && in_array($sortby, $sortby_combo)) { |
---|
282 | if (array_key_exists($sortby, $sortby_lex)) { |
---|
283 | $params['order'] = $core->con->lexFields($sortby_lex[$sortby]); |
---|
284 | } else { |
---|
285 | $params['order'] = $sortby; |
---|
286 | } |
---|
287 | if ($order !== '' && in_array($order, $order_combo)) { |
---|
288 | $params['order'] .= ' ' . $order; |
---|
289 | } else { |
---|
290 | $order = 'desc'; |
---|
291 | } |
---|
292 | |
---|
293 | if ($sortby != 'post_dt' || $order != 'desc') { |
---|
294 | $show_filters = true; |
---|
295 | } |
---|
296 | } else { |
---|
297 | $sortby = 'post_dt'; |
---|
298 | $order = 'desc'; |
---|
299 | } |
---|
300 | |
---|
301 | # Get posts |
---|
302 | try { |
---|
303 | $posts = $core->blog->getPosts($params); |
---|
304 | $counter = $core->blog->getPosts($params, true); |
---|
305 | $post_list = new adminPostList($core, $posts, $counter->f(0)); |
---|
306 | } catch (Exception $e) { |
---|
307 | $core->error->add($e->getMessage()); |
---|
308 | } |
---|
309 | |
---|
310 | /* DISPLAY |
---|
311 | -------------------------------------------------------- */ |
---|
312 | |
---|
313 | dcPage::open(__('Entries'), |
---|
314 | dcPage::jsLoad('js/_posts_list.js') . dcPage::jsFilterControl($show_filters), |
---|
315 | dcPage::breadcrumb( |
---|
316 | array( |
---|
317 | html::escapeHTML($core->blog->name) => '', |
---|
318 | __('Entries') => '' |
---|
319 | )) |
---|
320 | ); |
---|
321 | if (!empty($_GET['upd'])) { |
---|
322 | dcPage::success(__('Selected entries have been successfully updated.')); |
---|
323 | } elseif (!empty($_GET['del'])) { |
---|
324 | dcPage::success(__('Selected entries have been successfully deleted.')); |
---|
325 | } |
---|
326 | if (!$core->error->flag()) { |
---|
327 | echo |
---|
328 | '<p class="top-add"><a class="button add" href="' . $core->adminurl->get("admin.post") . '">' . __('New entry') . '</a></p>' . |
---|
329 | '<form action="' . $core->adminurl->get("admin.posts") . '" method="get" id="filters-form">' . |
---|
330 | '<h3 class="out-of-screen-if-js">' . __('Show filters and display options') . '</h3>' . |
---|
331 | |
---|
332 | '<div class="table">' . |
---|
333 | '<div class="cell">' . |
---|
334 | '<h4>' . __('Filters') . '</h4>' . |
---|
335 | '<p><label for="user_id" class="ib">' . __('Author:') . '</label> ' . |
---|
336 | form::combo('user_id', $users_combo, $user_id) . '</p>' . |
---|
337 | '<p><label for="cat_id" class="ib">' . __('Category:') . '</label> ' . |
---|
338 | form::combo('cat_id', $categories_combo, $cat_id) . '</p>' . |
---|
339 | '<p><label for="status" class="ib">' . __('Status:') . '</label> ' . |
---|
340 | form::combo('status', $status_combo, $status) . '</p> ' . |
---|
341 | '<p><label for="format" class="ib">' . __('Format:') . '</label> ' . |
---|
342 | form::combo('format', $format_combo, $format) . '</p>' . |
---|
343 | '<p><label for="password" class="ib">' . __('Password:') . '</label> ' . |
---|
344 | form::combo('password', $password_combo, $password) . '</p>' . |
---|
345 | '</div>' . |
---|
346 | |
---|
347 | '<div class="cell filters-sibling-cell">' . |
---|
348 | '<p><label for="selected" class="ib">' . __('Selected:') . '</label> ' . |
---|
349 | form::combo('selected', $selected_combo, $selected) . '</p>' . |
---|
350 | '<p><label for="attachment" class="ib">' . __('Attachments:') . '</label> ' . |
---|
351 | form::combo('attachment', $attachment_combo, $attachment) . '</p>' . |
---|
352 | '<p><label for="month" class="ib">' . __('Month:') . '</label> ' . |
---|
353 | form::combo('month', $dt_m_combo, $month) . '</p>' . |
---|
354 | '<p><label for="lang" class="ib">' . __('Lang:') . '</label> ' . |
---|
355 | form::combo('lang', $lang_combo, $lang) . '</p> ' . |
---|
356 | '<p><label for="comment" class="ib">' . __('Comments:') . '</label> ' . |
---|
357 | form::combo('comment', $comment_combo, $comment) . '</p>' . |
---|
358 | '<p><label for="trackback" class="ib">' . __('Trackbacks:') . '</label> ' . |
---|
359 | form::combo('trackback', $trackback_combo, $trackback) . '</p>' . |
---|
360 | '</div>' . |
---|
361 | |
---|
362 | '<div class="cell filters-options">' . |
---|
363 | '<h4>' . __('Display options') . '</h4>' . |
---|
364 | '<p><label for="sortby" class="ib">' . __('Order by:') . '</label> ' . |
---|
365 | form::combo('sortby', $sortby_combo, $sortby) . '</p>' . |
---|
366 | '<p><label for="order" class="ib">' . __('Sort:') . '</label> ' . |
---|
367 | form::combo('order', $order_combo, $order) . '</p>' . |
---|
368 | '<p><span class="label ib">' . __('Show') . '</span> <label for="nb" class="classic">' . |
---|
369 | form::number('nb', 0, 999, $nb_per_page) . ' ' . |
---|
370 | __('entries per page') . '</label></p>' . |
---|
371 | '</div>' . |
---|
372 | '</div>' . |
---|
373 | |
---|
374 | '<p><input type="submit" value="' . __('Apply filters and display options') . '" />' . |
---|
375 | '<br class="clear" /></p>' . //Opera sucks |
---|
376 | '</form>'; |
---|
377 | |
---|
378 | # Show posts |
---|
379 | $post_list->display($page, $nb_per_page, |
---|
380 | '<form action="' . $core->adminurl->get("admin.posts") . '" method="post" id="form-entries">' . |
---|
381 | |
---|
382 | '%s' . |
---|
383 | |
---|
384 | '<div class="two-cols">' . |
---|
385 | '<p class="col checkboxes-helpers"></p>' . |
---|
386 | |
---|
387 | '<p class="col right"><label for="action" class="classic">' . __('Selected entries action:') . '</label> ' . |
---|
388 | form::combo('action', $posts_actions_page->getCombo()) . |
---|
389 | '<input id="do-action" type="submit" value="' . __('ok') . '" disabled /></p>' . |
---|
390 | form::hidden(array('user_id'), $user_id) . |
---|
391 | form::hidden(array('cat_id'), $cat_id) . |
---|
392 | form::hidden(array('status'), $status) . |
---|
393 | form::hidden(array('password'), $password) . |
---|
394 | form::hidden(array('selected'), $selected) . |
---|
395 | form::hidden(array('comment'), $comment) . |
---|
396 | form::hidden(array('trackback'), $trackback) . |
---|
397 | form::hidden(array('attachment'), $attachment) . |
---|
398 | form::hidden(array('month'), $month) . |
---|
399 | form::hidden(array('lang'), $lang) . |
---|
400 | form::hidden(array('sortby'), $sortby) . |
---|
401 | form::hidden(array('order'), $order) . |
---|
402 | form::hidden(array('page'), $page) . |
---|
403 | form::hidden(array('nb'), $nb_per_page) . |
---|
404 | $core->formNonce() . |
---|
405 | '</div>' . |
---|
406 | '</form>', |
---|
407 | $show_filters |
---|
408 | ); |
---|
409 | } |
---|
410 | |
---|
411 | dcPage::helpBlock('core_posts'); |
---|
412 | dcPage::close(); |
---|