1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
3 | # |
---|
4 | # This file is part of Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2003-2011 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 | global $_ctx; |
---|
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 | 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 | |
---|
63 | # Getting categories |
---|
64 | $categories_combo = array(); |
---|
65 | try { |
---|
66 | $categories = $core->blog->getCategories(array('post_type'=>'post')); |
---|
67 | while ($categories->fetch()) { |
---|
68 | $categories_combo[$categories->cat_id] = |
---|
69 | str_repeat(' ',$categories->level-1). |
---|
70 | ($categories->level-1 == 0 ? '' : '• '). |
---|
71 | html::escapeHTML($categories->cat_title); |
---|
72 | } |
---|
73 | } catch (Exception $e) { } |
---|
74 | $status_combo = array( |
---|
75 | ); |
---|
76 | foreach ($core->blog->getAllPostStatus() as $k => $v) { |
---|
77 | $status_combo[(string) $k] = (string)$v; |
---|
78 | } |
---|
79 | |
---|
80 | $selected_combo = array( |
---|
81 | '1' => __('is selected'), |
---|
82 | '0' => __('is not selected') |
---|
83 | ); |
---|
84 | |
---|
85 | # Months array |
---|
86 | while ($dates->fetch()) { |
---|
87 | $dt_m_combo[$dates->year().$dates->month()] = dt::str('%B %Y',$dates->ts()); |
---|
88 | } |
---|
89 | |
---|
90 | while ($langs->fetch()) { |
---|
91 | $lang_combo[$langs->post_lang] = $langs->post_lang; |
---|
92 | } |
---|
93 | } |
---|
94 | $form = new dcForm($core,'post','post.php'); |
---|
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 | |
---|
129 | |
---|
130 | class monthdcFilterCombo extends dcFilterCombo { |
---|
131 | public function applyFilter($params) { |
---|
132 | $month=$this->avalues['values'][0]; |
---|
133 | $params['post_month'] = substr($month,4,2); |
---|
134 | $params['post_year'] = substr($month,0,4); |
---|
135 | } |
---|
136 | } |
---|
137 | |
---|
138 | class PostsFetcher extends dcListFetcher { |
---|
139 | |
---|
140 | public function getEntries($params,$offset,$limit) { |
---|
141 | $params['limit'] = array($offset,$limit); |
---|
142 | return $this->core->blog->getPosts($params); |
---|
143 | } |
---|
144 | |
---|
145 | public function getEntriesCount($params) { |
---|
146 | $count = $this->core->blog->getPosts($params,true); |
---|
147 | return $count->f(0); |
---|
148 | } |
---|
149 | } |
---|
150 | |
---|
151 | /* DISPLAY |
---|
152 | -------------------------------------------------------- */ |
---|
153 | $filterSet = new dcFilterSet($core,'fposts','posts.php'); |
---|
154 | |
---|
155 | $filterSet |
---|
156 | ->addFilter(new dcFilterRichCombo( |
---|
157 | 'users',__('Author'), __('Author'), 'user_id', $users_combo,array( |
---|
158 | 'multiple' => true))) |
---|
159 | ->addFilter(new dcFilterRichCombo( |
---|
160 | 'category',__('Category'), __('Category'), 'cat_id', $categories_combo)) |
---|
161 | ->addFilter(new dcFilterRichCombo( |
---|
162 | 'post_status',__('Status'), __('Status'), 'post_status', $status_combo)) |
---|
163 | ->addFilter(new dcFilterRichCombo( |
---|
164 | 'lang',__('Lang'), __('Lang'), 'post_lang', $lang_combo)) |
---|
165 | ->addFilter(new dcFilterCombo( |
---|
166 | 'selected',__('Selected'), __('The post : '),'post_selected', $selected_combo)) |
---|
167 | ->addFilter(new monthdcFilterCombo( |
---|
168 | 'month',__('Month'),__('Month'), 'post_month', $dt_m_combo,array('singleval' => 1))) |
---|
169 | ->addFilter(new dcFilterText( |
---|
170 | 'search',__('Contains'),__('The entry contains'), 'search',20,255)); |
---|
171 | |
---|
172 | |
---|
173 | $lfetcher = new PostsFetcher($core); |
---|
174 | $lposts = new dcItemList ($core,array('lposts','form-entries'),$filterSet,$lfetcher,'posts_actions.php'); |
---|
175 | $lposts->addTemplate('posts_cols.html.twig'); |
---|
176 | |
---|
177 | $lposts |
---|
178 | ->addColumn(new dcColumn('title',__('Title'),'post_title')) |
---|
179 | ->addColumn(new dcColumn('cat',__('Category'),'cat_title')) |
---|
180 | ->addColumn(new dcColumn('date',__('Date'),'post_date')) |
---|
181 | ->addColumn(new dcColumn('datetime',__('Date and Time'),'post_dt')) |
---|
182 | ->addColumn(new dcColumn('author',__('Author'),'user_id')) |
---|
183 | ->addColumn(new dcColumn('status',__('Status'),'post_status')); |
---|
184 | |
---|
185 | |
---|
186 | $lposts->setup(); |
---|
187 | |
---|
188 | $_ctx |
---|
189 | ->fillPageTitle(__('Entries'),'posts.php'); |
---|
190 | |
---|
191 | |
---|
192 | $core->tpl->display('posts.html.twig'); |
---|
193 | |
---|
194 | |
---|
195 | ?> |
---|