Dotclear

source: admin/posts.php @ 2720:bc400ebfc2e9

Revision 2720:bc400ebfc2e9, 9.1 KB checked in by Dsls, 11 years ago (diff)

One step further towards php hardcoded links annihilation in admin sources, more to come...

Line 
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
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 = array_merge(
50          array('-' => ''),
51          dcAdminCombos::getUsersCombo($users)
52     );
53
54     $categories_combo = array_merge(
55          array(
56               new formSelectOption('-',''),
57               new formSelectOption(__('(No cat)'),'NULL')),
58          dcAdminCombos::getCategoriesCombo($categories,false)
59     );
60     $categories_values = array();
61     foreach ($categories_combo as $cat) {
62          if (isset($cat->value)) {
63               $categories_values[$cat->value]=true;
64          }
65     }
66
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,$core->adminurl->get("admin.posts"));
115
116if ($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
137if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) {
138     if ($nb_per_page != $_GET['nb']) {
139          $show_filters = true;
140     }
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 filter
148if ($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 filter
156if ($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 filter
164if ($status !== '' && in_array($status,$status_combo)) {
165     $params['post_status'] = $status;
166     $show_filters = true;
167} else {
168     $status='';
169}
170
171# - Selected filter
172if ($selected !== '' && in_array($selected,$selected_combo)) {
173     $params['post_selected'] = $selected;
174     $show_filters = true;
175} else {
176     $selected='';
177}
178
179# - Selected filter
180if ($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 filter
189if ($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 filter
198if ($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 filter
206if ($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 posts
222try {
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}
229
230/* DISPLAY
231-------------------------------------------------------- */
232
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>";
244
245dcPage::open(__('Entries'),$starting_script,
246     dcPage::breadcrumb(
247          array(
248               html::escapeHTML($core->blog->name) => '',
249               __('Entries') => ''
250          ))
251);
252if (!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}
257if (!$core->error->flag())
258{
259     echo
260     '<p class="top-add"><a class="button add" href="'.$core->adminurl->get("admin.post").'">'.__('New entry').'</a></p>'.
261     '<form action="'.$core->adminurl->get("admin.posts").'" method="get" id="filters-form">'.
262     '<h3 class="out-of-screen-if-js">'.$form_filter_title.'</h3>'.
263
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>'.
274
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>'.
285
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
298     '<p><input type="submit" value="'.__('Apply filters and display options').'" />'.
299     '<br class="clear" /></p>'. //Opera sucks
300     '</form>';
301
302     # Show posts
303     $post_list->display($page,$nb_per_page,
304     '<form action="'.$core->adminurl->get("admin.posts").'" method="post" id="form-entries">'.
305
306     '%s'.
307
308     '<div class="two-cols">'.
309     '<p class="col checkboxes-helpers"></p>'.
310
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_filters
329     );
330}
331
332dcPage::helpBlock('core_posts');
333dcPage::close();
Note: See TracBrowser for help on using the repository browser.

Sites map