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 | $params = array(); |
---|
18 | $action = ''; |
---|
19 | |
---|
20 | /* Actions |
---|
21 | -------------------------------------------------------- */ |
---|
22 | if (!empty($_POST['action']) && !empty($_POST['entries'])) |
---|
23 | { |
---|
24 | $entries = $_POST['entries']; |
---|
25 | $action = $_POST['action']; |
---|
26 | |
---|
27 | if (isset($_POST['redir']) && strpos($_POST['redir'],'://') === false) |
---|
28 | { |
---|
29 | $redir = $_POST['redir']; |
---|
30 | } |
---|
31 | else |
---|
32 | { |
---|
33 | $redir = |
---|
34 | 'posts.php?user_id='.$_POST['user_id']. |
---|
35 | '&cat_id='.$_POST['cat_id']. |
---|
36 | '&status='.$_POST['status']. |
---|
37 | '&selected='.$_POST['selected']. |
---|
38 | '&month='.$_POST['month']. |
---|
39 | '&lang='.$_POST['lang']. |
---|
40 | '&sortby='.$_POST['sortby']. |
---|
41 | '&order='.$_POST['order']. |
---|
42 | '&page='.$_POST['page']. |
---|
43 | '&nb='.$_POST['nb']; |
---|
44 | } |
---|
45 | |
---|
46 | foreach ($entries as $k => $v) { |
---|
47 | $entries[$k] = (integer) $v; |
---|
48 | } |
---|
49 | |
---|
50 | $params['sql'] = 'AND P.post_id IN('.implode(',',$entries).') '; |
---|
51 | |
---|
52 | if (!isset($_POST['full_content']) || empty($_POST['full_content'])) { |
---|
53 | $params['no_content'] = true; |
---|
54 | } |
---|
55 | |
---|
56 | if (isset($_POST['post_type'])) { |
---|
57 | $params['post_type'] = $_POST['post_type']; |
---|
58 | } |
---|
59 | |
---|
60 | $posts = $core->blog->getPosts($params); |
---|
61 | |
---|
62 | $posts_ids = array(); |
---|
63 | while ($posts->fetch()) { |
---|
64 | $posts_ids[] = $posts->post_id; |
---|
65 | } |
---|
66 | |
---|
67 | # --BEHAVIOR-- adminPostsActions |
---|
68 | $core->callBehavior('adminPostsActions',$core,$posts,$action,$redir); |
---|
69 | |
---|
70 | if (preg_match('/^(publish|unpublish|schedule|pending)$/',$action)) |
---|
71 | { |
---|
72 | switch ($action) { |
---|
73 | case 'unpublish' : $status = 0; break; |
---|
74 | case 'schedule' : $status = -1; break; |
---|
75 | case 'pending' : $status = -2; break; |
---|
76 | default : $status = 1; break; |
---|
77 | } |
---|
78 | |
---|
79 | try |
---|
80 | { |
---|
81 | $core->blog->updPostsStatus($posts_ids,$status); |
---|
82 | |
---|
83 | http::redirect($redir); |
---|
84 | } |
---|
85 | catch (Exception $e) |
---|
86 | { |
---|
87 | $core->error->add($e->getMessage()); |
---|
88 | } |
---|
89 | } |
---|
90 | elseif ($action == 'selected' || $action == 'unselected') |
---|
91 | { |
---|
92 | try |
---|
93 | { |
---|
94 | $core->blog->updPostsSelected($posts_ids,$action == 'selected'); |
---|
95 | |
---|
96 | http::redirect($redir); |
---|
97 | } |
---|
98 | catch (Exception $e) |
---|
99 | { |
---|
100 | $core->error->add($e->getMessage()); |
---|
101 | } |
---|
102 | } |
---|
103 | elseif ($action == 'delete') |
---|
104 | { |
---|
105 | try |
---|
106 | { |
---|
107 | // Backward compatibility |
---|
108 | foreach($posts_ids as $post_id) |
---|
109 | { |
---|
110 | # --BEHAVIOR-- adminBeforePostDelete |
---|
111 | $core->callBehavior('adminBeforePostDelete',(integer) $post_id); |
---|
112 | } |
---|
113 | |
---|
114 | # --BEHAVIOR-- adminBeforePostsDelete |
---|
115 | $core->callBehavior('adminBeforePostsDelete',$posts_ids); |
---|
116 | |
---|
117 | $core->blog->delPosts($posts_ids); |
---|
118 | |
---|
119 | http::redirect($redir); |
---|
120 | } |
---|
121 | catch (Exception $e) |
---|
122 | { |
---|
123 | $core->error->add($e->getMessage()); |
---|
124 | } |
---|
125 | |
---|
126 | } |
---|
127 | elseif ($action == 'category' && isset($_POST['new_cat_id'])) |
---|
128 | { |
---|
129 | $new_cat_id = $_POST['new_cat_id']; |
---|
130 | |
---|
131 | try |
---|
132 | { |
---|
133 | if (!empty($_POST['new_cat_title']) && $core->auth->check('categories', $core->blog->id)) |
---|
134 | { |
---|
135 | $cur_cat = $core->con->openCursor($core->prefix.'category'); |
---|
136 | $cur_cat->cat_title = $_POST['new_cat_title']; |
---|
137 | $cur_cat->cat_url = ''; |
---|
138 | |
---|
139 | $parent_cat = !empty($_POST['new_cat_parent']) ? $_POST['new_cat_parent'] : ''; |
---|
140 | |
---|
141 | # --BEHAVIOR-- adminBeforeCategoryCreate |
---|
142 | $core->callBehavior('adminBeforeCategoryCreate', $cur_cat); |
---|
143 | |
---|
144 | $new_cat_id = $core->blog->addCategory($cur_cat, (integer) $parent_cat); |
---|
145 | |
---|
146 | # --BEHAVIOR-- adminAfterCategoryCreate |
---|
147 | $core->callBehavior('adminAfterCategoryCreate', $cur_cat, $new_cat_id); |
---|
148 | } |
---|
149 | |
---|
150 | $core->blog->updPostsCategory($posts_ids, $new_cat_id); |
---|
151 | |
---|
152 | http::redirect($redir); |
---|
153 | } |
---|
154 | catch (Exception $e) |
---|
155 | { |
---|
156 | $core->error->add($e->getMessage()); |
---|
157 | } |
---|
158 | } |
---|
159 | elseif ($action == 'author' && isset($_POST['new_auth_id']) |
---|
160 | && $core->auth->check('admin',$core->blog->id)) |
---|
161 | { |
---|
162 | $new_user_id = $_POST['new_auth_id']; |
---|
163 | |
---|
164 | try |
---|
165 | { |
---|
166 | if ($core->getUser($new_user_id)->isEmpty()) { |
---|
167 | throw new Exception(__('This user does not exist')); |
---|
168 | } |
---|
169 | |
---|
170 | $cur = $core->con->openCursor($core->prefix.'post'); |
---|
171 | $cur->user_id = $new_user_id; |
---|
172 | $cur->update('WHERE post_id '.$core->con->in($posts_ids)); |
---|
173 | |
---|
174 | http::redirect($redir); |
---|
175 | } |
---|
176 | catch (Exception $e) |
---|
177 | { |
---|
178 | $core->error->add($e->getMessage()); |
---|
179 | } |
---|
180 | } |
---|
181 | elseif ($action == 'lang' && isset($_POST['new_lang'])) |
---|
182 | { |
---|
183 | $new_lang = $_POST['new_lang']; |
---|
184 | try |
---|
185 | { |
---|
186 | $cur = $core->con->openCursor($core->prefix.'post'); |
---|
187 | $cur->post_lang = $new_lang; |
---|
188 | $cur->update('WHERE post_id '.$core->con->in($posts_ids)); |
---|
189 | |
---|
190 | http::redirect($redir); |
---|
191 | } |
---|
192 | catch (Exception $e) |
---|
193 | { |
---|
194 | $core->error->add($e->getMessages()); |
---|
195 | } |
---|
196 | } |
---|
197 | } |
---|
198 | |
---|
199 | /* DISPLAY |
---|
200 | -------------------------------------------------------- */ |
---|
201 | // Get current users list |
---|
202 | $usersList = ''; |
---|
203 | if ($action == 'author' && $core->auth->check('admin',$core->blog->id)) { |
---|
204 | $params = array( |
---|
205 | 'limit' => 100, |
---|
206 | 'order' => 'nb_post DESC' |
---|
207 | ); |
---|
208 | $rs = $core->getUsers($params); |
---|
209 | while ($rs->fetch()) |
---|
210 | { |
---|
211 | $usersList .= ($usersList != '' ? ',' : '').'"'.$rs->user_id.'"'; |
---|
212 | } |
---|
213 | } |
---|
214 | dcPage::open( |
---|
215 | __('Entries'), |
---|
216 | '<script type="text/javascript">'."\n". |
---|
217 | "//<![CDATA[\n". |
---|
218 | 'usersList = ['.$usersList.']'."\n". |
---|
219 | "\n//]]>\n". |
---|
220 | "</script>\n". |
---|
221 | dcPage::jsLoad('js/jquery/jquery.autocomplete.js'). |
---|
222 | dcPage::jsLoad('js/_posts_actions.js'). |
---|
223 | dcPage::jsMetaEditor(). |
---|
224 | # --BEHAVIOR-- adminBeforePostDelete |
---|
225 | $core->callBehavior('adminPostsActionsHeaders') |
---|
226 | ); |
---|
227 | |
---|
228 | if (!isset($action)) { |
---|
229 | dcPage::close(); |
---|
230 | exit; |
---|
231 | } |
---|
232 | |
---|
233 | $hidden_fields = ''; |
---|
234 | while ($posts->fetch()) { |
---|
235 | $hidden_fields .= form::hidden(array('entries[]'),$posts->post_id); |
---|
236 | } |
---|
237 | |
---|
238 | if (isset($_POST['redir']) && strpos($_POST['redir'],'://') === false) |
---|
239 | { |
---|
240 | $hidden_fields .= form::hidden(array('redir'),html::escapeURL($_POST['redir'])); |
---|
241 | } |
---|
242 | else |
---|
243 | { |
---|
244 | $hidden_fields .= |
---|
245 | form::hidden(array('user_id'),$_POST['user_id']). |
---|
246 | form::hidden(array('cat_id'),$_POST['cat_id']). |
---|
247 | form::hidden(array('status'),$_POST['status']). |
---|
248 | form::hidden(array('selected'),$_POST['selected']). |
---|
249 | form::hidden(array('month'),$_POST['month']). |
---|
250 | form::hidden(array('lang'),$_POST['lang']). |
---|
251 | form::hidden(array('sortby'),$_POST['sortby']). |
---|
252 | form::hidden(array('order'),$_POST['order']). |
---|
253 | form::hidden(array('page'),$_POST['page']). |
---|
254 | form::hidden(array('nb'),$_POST['nb']); |
---|
255 | } |
---|
256 | |
---|
257 | if (isset($_POST['post_type'])) { |
---|
258 | $hidden_fields .= form::hidden(array('post_type'),$_POST['post_type']); |
---|
259 | } |
---|
260 | |
---|
261 | # --BEHAVIOR-- adminPostsActionsContent |
---|
262 | $core->callBehavior('adminPostsActionsContent',$core,$action,$hidden_fields); |
---|
263 | |
---|
264 | if ($action == 'category') |
---|
265 | { |
---|
266 | echo '<h2 class="page-title">'.__('Change category for entries').'</h2>'; |
---|
267 | |
---|
268 | # Getting categories |
---|
269 | $categories_combo = array(__('(No cat)') => ''); |
---|
270 | try { |
---|
271 | $categories = $core->blog->getCategories(array('post_type'=>'post')); |
---|
272 | if (!$categories->isEmpty()) { |
---|
273 | $l = $categories->level; |
---|
274 | $full_name = array($categories->cat_title); |
---|
275 | |
---|
276 | while ($categories->fetch()) { |
---|
277 | if ($categories->level < $l) { |
---|
278 | $full_name = array(); |
---|
279 | } elseif ($categories->level == $l) { |
---|
280 | array_pop($full_name); |
---|
281 | } |
---|
282 | $full_name[] = html::escapeHTML($categories->cat_title); |
---|
283 | $categories_combo[implode(' / ',$full_name)] = $categories->cat_id; |
---|
284 | $l = $categories->level; |
---|
285 | } |
---|
286 | } |
---|
287 | } catch (Exception $e) { } |
---|
288 | |
---|
289 | echo |
---|
290 | '<form action="posts_actions.php" method="post">'. |
---|
291 | '<p><label for="new_cat_id" class="classic">'.__('Category:').' '. |
---|
292 | form::combo('new_cat_id',$categories_combo,''). |
---|
293 | '</label> '; |
---|
294 | |
---|
295 | if ($core->auth->check('categories', $core->blog->id)) { |
---|
296 | echo |
---|
297 | '<div>'. |
---|
298 | '<p id="new_cat">'.__('Add a new category').'</p>'. |
---|
299 | '<p><label for="new_cat_title">'.__('Title:').' '. |
---|
300 | form::field('new_cat_title',30,255,'','maximal').'</label></p>'. |
---|
301 | '<p><label for="new_cat_parent">'.__('Parent:').' '. |
---|
302 | form::combo('new_cat_parent',$categories_combo,'','maximal'). |
---|
303 | '</label></p>'. |
---|
304 | '</div>'; |
---|
305 | } |
---|
306 | |
---|
307 | echo |
---|
308 | $hidden_fields. |
---|
309 | $core->formNonce(). |
---|
310 | form::hidden(array('action'),'category'). |
---|
311 | '<input type="submit" value="'.__('Save').'" /></p>'. |
---|
312 | '</form>'; |
---|
313 | } |
---|
314 | elseif ($action == 'lang') |
---|
315 | { |
---|
316 | echo '<h2 class="page-title">'.__('Change language for entries').'</h2>'; |
---|
317 | |
---|
318 | # lang list |
---|
319 | # Languages combo |
---|
320 | $rs = $core->blog->getLangs(array('order'=>'asc')); |
---|
321 | $all_langs = l10n::getISOcodes(0,1); |
---|
322 | $lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(1,1)); |
---|
323 | while ($rs->fetch()) { |
---|
324 | if (isset($all_langs[$rs->post_lang])) { |
---|
325 | $lang_combo[__('Most used')][$all_langs[$rs->post_lang]] = $rs->post_lang; |
---|
326 | unset($lang_combo[__('Available')][$all_langs[$rs->post_lang]]); |
---|
327 | } else { |
---|
328 | $lang_combo[__('Most used')][$rs->post_lang] = $rs->post_lang; |
---|
329 | } |
---|
330 | } |
---|
331 | unset($all_langs); |
---|
332 | unset($rs); |
---|
333 | |
---|
334 | echo |
---|
335 | '<form action="posts_actions.php" method="post">'. |
---|
336 | '<p><label for="new_lang" class="classic">'.__('Entry lang:').' '. |
---|
337 | form::combo('new_lang',$lang_combo,''). |
---|
338 | '</label> '; |
---|
339 | |
---|
340 | echo |
---|
341 | $hidden_fields. |
---|
342 | $core->formNonce(). |
---|
343 | form::hidden(array('action'),'lang'). |
---|
344 | '<input type="submit" value="'.__('Save').'" /></p>'. |
---|
345 | '</form>'; |
---|
346 | |
---|
347 | } |
---|
348 | elseif ($action == 'author' && $core->auth->check('admin',$core->blog->id)) |
---|
349 | { |
---|
350 | echo '<h2 class="page-title">'.__('Change author for entries').'</h2>'; |
---|
351 | |
---|
352 | echo |
---|
353 | '<form action="posts_actions.php" method="post">'. |
---|
354 | '<p><label for="new_auth_id" class="classic">'.__('Author ID:').' '. |
---|
355 | form::field('new_auth_id',20,255). |
---|
356 | '</label> '; |
---|
357 | |
---|
358 | echo |
---|
359 | $hidden_fields. |
---|
360 | $core->formNonce(). |
---|
361 | form::hidden(array('action'),'author'). |
---|
362 | '<input type="submit" value="'.__('Save').'" /></p>'. |
---|
363 | '</form>'; |
---|
364 | } |
---|
365 | |
---|
366 | echo '<p><a class="back" href="'.html::escapeURL($redir).'">'.__('back').'</a></p>'; |
---|
367 | |
---|
368 | dcPage::close(); |
---|
369 | ?> |
---|