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 | |
---|
19 | /** |
---|
20 | * FieldsList - Compatibility class for hidden fields & entries[] fields |
---|
21 | * |
---|
22 | */ |
---|
23 | class FieldsList { |
---|
24 | /** @var array list of hidden fields */ |
---|
25 | protected $hidden; |
---|
26 | /** @var array list of selected entries */ |
---|
27 | protected $entries; |
---|
28 | |
---|
29 | |
---|
30 | /** |
---|
31 | * Class constructor |
---|
32 | */ |
---|
33 | public function __construct() { |
---|
34 | $this->hidden=array(); |
---|
35 | $this->entries =array(); |
---|
36 | } |
---|
37 | |
---|
38 | /** |
---|
39 | * addHidden - adds a hidden field |
---|
40 | * |
---|
41 | * @param string $name the field name. |
---|
42 | * @param mixed $value the field value. |
---|
43 | * |
---|
44 | * @access public |
---|
45 | * @return the FieldsList instance, enabling to chain requests |
---|
46 | */ |
---|
47 | public function addHidden($name,$value) { |
---|
48 | $this->hidden[] = form::hidden($name,$value); |
---|
49 | return $this; |
---|
50 | } |
---|
51 | |
---|
52 | /** |
---|
53 | * addEntry - adds a antry field |
---|
54 | * |
---|
55 | * @param string $id the entry id. |
---|
56 | * @param mixed $title the entry title. |
---|
57 | * |
---|
58 | * @access public |
---|
59 | * @return the FieldsList instance, enabling to chain requests |
---|
60 | */ |
---|
61 | public function addEntry($id,$title) { |
---|
62 | $this->entries[$id]=$title; |
---|
63 | return $this; |
---|
64 | } |
---|
65 | |
---|
66 | /** |
---|
67 | * getHidden - returns the list of hidden fields, html encoded |
---|
68 | * |
---|
69 | * @access public |
---|
70 | * @return the list of hidden fields, html encoded |
---|
71 | */ |
---|
72 | public function getHidden() { |
---|
73 | return join('',$this->hidden); |
---|
74 | } |
---|
75 | |
---|
76 | /** |
---|
77 | * getEntries - returns the list of entry fields, html encoded |
---|
78 | * |
---|
79 | * @param boolean $hidden if set to true, returns entries as a list of hidden field |
---|
80 | * if set to false, returns html code displaying the list of entries |
---|
81 | * with a list of checkboxes to enable to select/deselect entries |
---|
82 | * @access public |
---|
83 | * @return the list of entry fields, html encoded |
---|
84 | */ |
---|
85 | public function getEntries ($hidden=false) { |
---|
86 | $ret = ''; |
---|
87 | if ($hidden) { |
---|
88 | foreach ($this->entries as $id=> $e) { |
---|
89 | $ret .= form::hidden('entries[]',$id); |
---|
90 | } |
---|
91 | } else { |
---|
92 | $ret = |
---|
93 | '<table class="posts-list"><tr>'. |
---|
94 | '<th colspan="2">'.__('Title').'</th>'. |
---|
95 | '</tr>'; |
---|
96 | foreach ($this->entries as $id=>$title) { |
---|
97 | $ret .= |
---|
98 | '<tr><td>'. |
---|
99 | form::checkbox(array('entries[]'),$id,true,'','').'</td>'. |
---|
100 | '<td>'. $title.'</td></tr>'; |
---|
101 | } |
---|
102 | $ret .= '</table>'; |
---|
103 | } |
---|
104 | return $ret; |
---|
105 | } |
---|
106 | |
---|
107 | /** |
---|
108 | * getEntriesQS - returns the list of entry fields as query string |
---|
109 | * |
---|
110 | * @access public |
---|
111 | * @return the list of entry fields, html encoded |
---|
112 | */ |
---|
113 | public function getEntriesQS() { |
---|
114 | $ret=array(); |
---|
115 | foreach ($this->entries as $id=>$title) { |
---|
116 | $ret[] = 'entries[]='.$id; |
---|
117 | } |
---|
118 | return join('&',$ret); |
---|
119 | } |
---|
120 | |
---|
121 | /** |
---|
122 | * __toString - magic method. -- DEPRECATED here |
---|
123 | * This method is only used to preserve compatibility with plugins |
---|
124 | * relying on previous versions of adminPostsActionsContent behavior, |
---|
125 | * |
---|
126 | * @access public |
---|
127 | * @return the list of hidden fields and entries (as hidden fields too), html encoded |
---|
128 | */ |
---|
129 | public function __toString() { |
---|
130 | return join('',$this->hidden).$this->getEntries(true); |
---|
131 | } |
---|
132 | } |
---|
133 | |
---|
134 | $fields = new FieldsList(); |
---|
135 | |
---|
136 | /* Actions |
---|
137 | -------------------------------------------------------- */ |
---|
138 | if (!empty($_POST['action']) && !empty($_POST['entries'])) |
---|
139 | { |
---|
140 | $entries = $_POST['entries']; |
---|
141 | $action = $_POST['action']; |
---|
142 | |
---|
143 | if (isset($_POST['redir']) && strpos($_POST['redir'],'://') === false) |
---|
144 | { |
---|
145 | $redir = $_POST['redir']; |
---|
146 | } |
---|
147 | else |
---|
148 | { |
---|
149 | $redir = |
---|
150 | 'posts.php?user_id='.$_POST['user_id']. |
---|
151 | '&cat_id='.$_POST['cat_id']. |
---|
152 | '&status='.$_POST['status']. |
---|
153 | '&selected='.$_POST['selected']. |
---|
154 | '&month='.$_POST['month']. |
---|
155 | '&lang='.$_POST['lang']. |
---|
156 | '&sortby='.$_POST['sortby']. |
---|
157 | '&order='.$_POST['order']. |
---|
158 | '&page='.$_POST['page']. |
---|
159 | '&nb='.$_POST['nb']; |
---|
160 | } |
---|
161 | |
---|
162 | foreach ($entries as $k => $v) { |
---|
163 | $entries[$k] = (integer) $v; |
---|
164 | } |
---|
165 | |
---|
166 | $params['sql'] = 'AND P.post_id IN('.implode(',',$entries).') '; |
---|
167 | |
---|
168 | if (!isset($_POST['full_content']) || empty($_POST['full_content'])) { |
---|
169 | $params['no_content'] = true; |
---|
170 | } |
---|
171 | |
---|
172 | if (isset($_POST['post_type'])) { |
---|
173 | $params['post_type'] = $_POST['post_type']; |
---|
174 | } |
---|
175 | |
---|
176 | $posts = $core->blog->getPosts($params); |
---|
177 | |
---|
178 | $posts_ids = array(); |
---|
179 | while ($posts->fetch()) { |
---|
180 | $posts_ids[] = $posts->post_id; |
---|
181 | $fields->addEntry($posts->post_id,$posts->post_title); |
---|
182 | } |
---|
183 | // Redirection including selected entries |
---|
184 | $redir_sel = $redir.'&'.$fields->getEntriesQS(); |
---|
185 | |
---|
186 | # --BEHAVIOR-- adminPostsActions |
---|
187 | $core->callBehavior('adminPostsActions',$core,$posts,$action,$redir); |
---|
188 | |
---|
189 | if (preg_match('/^(publish|unpublish|schedule|pending)$/',$action)) |
---|
190 | { |
---|
191 | switch ($action) { |
---|
192 | case 'unpublish' : $status = 0; break; |
---|
193 | case 'schedule' : $status = -1; break; |
---|
194 | case 'pending' : $status = -2; break; |
---|
195 | default : $status = 1; break; |
---|
196 | } |
---|
197 | |
---|
198 | try |
---|
199 | { |
---|
200 | $core->blog->updPostsStatus($posts_ids,$status); |
---|
201 | |
---|
202 | http::redirect($redir_sel.'&upd=1'); |
---|
203 | } |
---|
204 | catch (Exception $e) |
---|
205 | { |
---|
206 | $core->error->add($e->getMessage()); |
---|
207 | } |
---|
208 | } |
---|
209 | elseif ($action == 'selected' || $action == 'unselected') |
---|
210 | { |
---|
211 | try |
---|
212 | { |
---|
213 | $core->blog->updPostsSelected($posts_ids,$action == 'selected'); |
---|
214 | |
---|
215 | http::redirect($redir_sel."&upd=1"); |
---|
216 | } |
---|
217 | catch (Exception $e) |
---|
218 | { |
---|
219 | $core->error->add($e->getMessage()); |
---|
220 | } |
---|
221 | } |
---|
222 | elseif ($action == 'delete') |
---|
223 | { |
---|
224 | try |
---|
225 | { |
---|
226 | // Backward compatibility |
---|
227 | foreach($posts_ids as $post_id) |
---|
228 | { |
---|
229 | # --BEHAVIOR-- adminBeforePostDelete |
---|
230 | $core->callBehavior('adminBeforePostDelete',(integer) $post_id); |
---|
231 | } |
---|
232 | |
---|
233 | # --BEHAVIOR-- adminBeforePostsDelete |
---|
234 | $core->callBehavior('adminBeforePostsDelete',$posts_ids); |
---|
235 | |
---|
236 | $core->blog->delPosts($posts_ids); |
---|
237 | |
---|
238 | http::redirect($redir."&del=1"); |
---|
239 | } |
---|
240 | catch (Exception $e) |
---|
241 | { |
---|
242 | $core->error->add($e->getMessage()); |
---|
243 | } |
---|
244 | |
---|
245 | } |
---|
246 | elseif ($action == 'category' && isset($_POST['new_cat_id'])) |
---|
247 | { |
---|
248 | $new_cat_id = $_POST['new_cat_id']; |
---|
249 | |
---|
250 | try |
---|
251 | { |
---|
252 | if (!empty($_POST['new_cat_title']) && $core->auth->check('categories', $core->blog->id)) |
---|
253 | { |
---|
254 | $cur_cat = $core->con->openCursor($core->prefix.'category'); |
---|
255 | $cur_cat->cat_title = $_POST['new_cat_title']; |
---|
256 | $cur_cat->cat_url = ''; |
---|
257 | |
---|
258 | $parent_cat = !empty($_POST['new_cat_parent']) ? $_POST['new_cat_parent'] : ''; |
---|
259 | |
---|
260 | # --BEHAVIOR-- adminBeforeCategoryCreate |
---|
261 | $core->callBehavior('adminBeforeCategoryCreate', $cur_cat); |
---|
262 | |
---|
263 | $new_cat_id = $core->blog->addCategory($cur_cat, (integer) $parent_cat); |
---|
264 | |
---|
265 | # --BEHAVIOR-- adminAfterCategoryCreate |
---|
266 | $core->callBehavior('adminAfterCategoryCreate', $cur_cat, $new_cat_id); |
---|
267 | } |
---|
268 | |
---|
269 | $core->blog->updPostsCategory($posts_ids, $new_cat_id); |
---|
270 | |
---|
271 | http::redirect($redir_sel."&upd=1"); |
---|
272 | } |
---|
273 | catch (Exception $e) |
---|
274 | { |
---|
275 | $core->error->add($e->getMessage()); |
---|
276 | } |
---|
277 | } |
---|
278 | elseif ($action == 'author' && isset($_POST['new_auth_id']) |
---|
279 | && $core->auth->check('admin',$core->blog->id)) |
---|
280 | { |
---|
281 | $new_user_id = $_POST['new_auth_id']; |
---|
282 | |
---|
283 | try |
---|
284 | { |
---|
285 | if ($core->getUser($new_user_id)->isEmpty()) { |
---|
286 | throw new Exception(__('This user does not exist')); |
---|
287 | } |
---|
288 | |
---|
289 | $cur = $core->con->openCursor($core->prefix.'post'); |
---|
290 | $cur->user_id = $new_user_id; |
---|
291 | $cur->update('WHERE post_id '.$core->con->in($posts_ids)); |
---|
292 | |
---|
293 | http::redirect($redir_sel."&upd=1"); |
---|
294 | } |
---|
295 | catch (Exception $e) |
---|
296 | { |
---|
297 | $core->error->add($e->getMessage()); |
---|
298 | } |
---|
299 | } |
---|
300 | elseif ($action == 'lang' && isset($_POST['new_lang'])) |
---|
301 | { |
---|
302 | $new_lang = $_POST['new_lang']; |
---|
303 | try |
---|
304 | { |
---|
305 | $cur = $core->con->openCursor($core->prefix.'post'); |
---|
306 | $cur->post_lang = $new_lang; |
---|
307 | $cur->update('WHERE post_id '.$core->con->in($posts_ids)); |
---|
308 | |
---|
309 | http::redirect($redir_sel."&upd=1"); |
---|
310 | } |
---|
311 | catch (Exception $e) |
---|
312 | { |
---|
313 | $core->error->add($e->getMessages()); |
---|
314 | } |
---|
315 | } |
---|
316 | } else { |
---|
317 | if (empty($_POST['entries'])) { |
---|
318 | $core->error->add(__('At least one entry should be selected')); |
---|
319 | } else { |
---|
320 | $core->error->add(__('No action specified.')); |
---|
321 | } |
---|
322 | dcPage::open( |
---|
323 | __('Entries'),'',dcPage::breadcrumb( |
---|
324 | array( |
---|
325 | html::escapeHTML($core->blog->name) => '', |
---|
326 | __('Entries') => 'posts.php', |
---|
327 | '<span class="page-title">'.__('Entries actions').'</span>' => '' |
---|
328 | )) |
---|
329 | ); |
---|
330 | |
---|
331 | echo '<p><a class="back" href="'.html::escapeURL($redir_sel).'">'.__('Back to entries list').'</a></p>'; |
---|
332 | |
---|
333 | dcPage::close(); |
---|
334 | exit; |
---|
335 | } |
---|
336 | /* DISPLAY |
---|
337 | -------------------------------------------------------- */ |
---|
338 | // Get current users list |
---|
339 | $usersList = ''; |
---|
340 | if ($action == 'author' && $core->auth->check('admin',$core->blog->id)) { |
---|
341 | $params = array( |
---|
342 | 'limit' => 100, |
---|
343 | 'order' => 'nb_post DESC' |
---|
344 | ); |
---|
345 | $rs = $core->getUsers($params); |
---|
346 | while ($rs->fetch()) |
---|
347 | { |
---|
348 | $usersList .= ($usersList != '' ? ',' : '').'"'.$rs->user_id.'"'; |
---|
349 | } |
---|
350 | } |
---|
351 | dcPage::open( |
---|
352 | __('Entries'), |
---|
353 | '<script type="text/javascript">'."\n". |
---|
354 | "//<![CDATA[\n". |
---|
355 | 'usersList = ['.$usersList.']'."\n". |
---|
356 | "\n//]]>\n". |
---|
357 | "</script>\n". |
---|
358 | dcPage::jsLoad('js/jquery/jquery.autocomplete.js'). |
---|
359 | dcPage::jsLoad('js/_posts_actions.js'). |
---|
360 | dcPage::jsMetaEditor(). |
---|
361 | # --BEHAVIOR-- adminBeforePostDelete |
---|
362 | $core->callBehavior('adminPostsActionsHeaders') |
---|
363 | ); |
---|
364 | |
---|
365 | if (!isset($action)) { |
---|
366 | dcPage::close(); |
---|
367 | exit; |
---|
368 | } |
---|
369 | |
---|
370 | if (isset($_POST['redir']) && strpos($_POST['redir'],'://') === false) |
---|
371 | { |
---|
372 | $fields->addHidden(array('redir'),html::escapeURL($_POST['redir'])); |
---|
373 | } |
---|
374 | else |
---|
375 | { |
---|
376 | $fields |
---|
377 | ->addHidden(array('user_id'),$_POST['user_id']) |
---|
378 | ->addHidden(array('cat_id'),$_POST['cat_id']) |
---|
379 | ->addHidden(array('status'),$_POST['status']) |
---|
380 | ->addHidden(array('selected'),$_POST['selected']) |
---|
381 | ->addHidden(array('month'),$_POST['month']) |
---|
382 | ->addHidden(array('lang'),$_POST['lang']) |
---|
383 | ->addHidden(array('sortby'),$_POST['sortby']) |
---|
384 | ->addHidden(array('order'),$_POST['order']) |
---|
385 | ->addHidden(array('page'),$_POST['page']) |
---|
386 | ->addHidden(array('nb'),$_POST['nb']) |
---|
387 | ; |
---|
388 | } |
---|
389 | |
---|
390 | if (isset($_POST['post_type'])) { |
---|
391 | $fields->addHidden(array('post_type'),$_POST['post_type']); |
---|
392 | } |
---|
393 | |
---|
394 | # --BEHAVIOR-- adminPostsActionsContent |
---|
395 | $core->callBehavior('adminPostsActionsContent',$core,$action,$fields); |
---|
396 | |
---|
397 | if ($action == 'category') |
---|
398 | { |
---|
399 | echo dcPage::breadcrumb( |
---|
400 | array( |
---|
401 | html::escapeHTML($core->blog->name) => '', |
---|
402 | __('Entries') => 'posts.php', |
---|
403 | __('Change category for entries') => '' |
---|
404 | )); |
---|
405 | |
---|
406 | echo '<p><a class="back" href="'.html::escapeURL($redir_sel).'">'.__('Back to entries list').'</a></p>'; |
---|
407 | |
---|
408 | # categories list |
---|
409 | # Getting categories |
---|
410 | $categories_combo = array(__('(No cat)') => ''); |
---|
411 | try { |
---|
412 | $categories = $core->blog->getCategories(array('post_type'=>'post')); |
---|
413 | if (!$categories->isEmpty()) { |
---|
414 | while ($categories->fetch()) { |
---|
415 | $catparents_combo[] = $categories_combo[] = new formSelectOption( |
---|
416 | str_repeat(' ',$categories->level-1).($categories->level-1 == 0 ? '' : '• ').html::escapeHTML($categories->cat_title), |
---|
417 | $categories->cat_id |
---|
418 | ); |
---|
419 | } |
---|
420 | } |
---|
421 | } catch (Exception $e) { } |
---|
422 | |
---|
423 | echo |
---|
424 | '<form action="posts_actions.php" method="post">'. |
---|
425 | $fields->getEntries(). |
---|
426 | '<p><label for="new_cat_id" class="classic">'.__('Category:').'</label> '. |
---|
427 | form::combo('new_cat_id',$categories_combo,''); |
---|
428 | |
---|
429 | if ($core->auth->check('categories', $core->blog->id)) { |
---|
430 | echo |
---|
431 | '<div>'. |
---|
432 | '<p id="new_cat">'.__('Add a new category').'</p>'. |
---|
433 | '<p><label for="new_cat_title">'.__('Title:').' '. |
---|
434 | form::field('new_cat_title',30,255,'','maximal').'</label></p>'. |
---|
435 | '<p><label for="new_cat_parent">'.__('Parent:').' '. |
---|
436 | form::combo('new_cat_parent',$categories_combo,'','maximal'). |
---|
437 | '</label></p>'. |
---|
438 | '</div>'; |
---|
439 | } |
---|
440 | |
---|
441 | echo |
---|
442 | $fields->getHidden(). |
---|
443 | $core->formNonce(). |
---|
444 | form::hidden(array('action'),'category'). |
---|
445 | '<input type="submit" value="'.__('Save').'" /></p>'. |
---|
446 | '</form>'; |
---|
447 | } |
---|
448 | elseif ($action == 'lang') |
---|
449 | { |
---|
450 | echo dcPage::breadcrumb( |
---|
451 | array( |
---|
452 | html::escapeHTML($core->blog->name) => '', |
---|
453 | __('Entries') => 'posts.php', |
---|
454 | '<span class="page-title">'.__('Change language for entries').'</span>' => '' |
---|
455 | )); |
---|
456 | echo '<p><a class="back" href="'.html::escapeURL($redir_sel).'">'.__('Back to entries list').'</a></p>'; |
---|
457 | |
---|
458 | # lang list |
---|
459 | # Languages combo |
---|
460 | $rs = $core->blog->getLangs(array('order'=>'asc')); |
---|
461 | $all_langs = l10n::getISOcodes(0,1); |
---|
462 | $lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(1,1)); |
---|
463 | while ($rs->fetch()) { |
---|
464 | if (isset($all_langs[$rs->post_lang])) { |
---|
465 | $lang_combo[__('Most used')][$all_langs[$rs->post_lang]] = $rs->post_lang; |
---|
466 | unset($lang_combo[__('Available')][$all_langs[$rs->post_lang]]); |
---|
467 | } else { |
---|
468 | $lang_combo[__('Most used')][$rs->post_lang] = $rs->post_lang; |
---|
469 | } |
---|
470 | } |
---|
471 | unset($all_langs); |
---|
472 | unset($rs); |
---|
473 | |
---|
474 | echo |
---|
475 | '<form action="posts_actions.php" method="post">'. |
---|
476 | $fields->getEntries(). |
---|
477 | |
---|
478 | '<p><label for="new_lang" class="classic">'.__('Entry lang:').'</label> '. |
---|
479 | form::combo('new_lang',$lang_combo,''); |
---|
480 | |
---|
481 | echo |
---|
482 | $fields->getHidden(). |
---|
483 | $core->formNonce(). |
---|
484 | form::hidden(array('action'),'lang'). |
---|
485 | '<input type="submit" value="'.__('Save').'" /></p>'. |
---|
486 | '</form>'; |
---|
487 | |
---|
488 | } |
---|
489 | elseif ($action == 'author' && $core->auth->check('admin',$core->blog->id)) |
---|
490 | { |
---|
491 | echo dcPage::breadcrumb( |
---|
492 | array( |
---|
493 | html::escapeHTML($core->blog->name) => '', |
---|
494 | __('Entries') => 'posts.php', |
---|
495 | '<span class="page-title">'.__('Change author for entries').'</span>' => '' |
---|
496 | )); |
---|
497 | echo '<p><a class="back" href="'.html::escapeURL($redir_sel).'">'.__('Back to entries list').'</a></p>'; |
---|
498 | |
---|
499 | echo |
---|
500 | '<form action="posts_actions.php" method="post">'. |
---|
501 | $fields->getEntries(). |
---|
502 | '<p><label for="new_auth_id" class="classic">'.__('New author (author ID):').'</label> '. |
---|
503 | form::field('new_auth_id',20,255); |
---|
504 | |
---|
505 | echo |
---|
506 | $fields->getHidden(). |
---|
507 | $core->formNonce(). |
---|
508 | form::hidden(array('action'),'author'). |
---|
509 | '<input type="submit" value="'.__('Save').'" /></p>'. |
---|
510 | '</form>'; |
---|
511 | } |
---|
512 | |
---|
513 | dcPage::close(); |
---|
514 | ?> |
---|