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 | $posts_ids = array(); |
---|
136 | |
---|
137 | if (isset($_POST['redir']) && strpos($_POST['redir'],'://') === false) |
---|
138 | { |
---|
139 | $redir = $_POST['redir']; |
---|
140 | } |
---|
141 | else |
---|
142 | { |
---|
143 | $redir = |
---|
144 | 'posts.php?user_id='.$_POST['user_id']. |
---|
145 | '&cat_id='.$_POST['cat_id']. |
---|
146 | '&status='.$_POST['status']. |
---|
147 | '&selected='.$_POST['selected']. |
---|
148 | '&month='.$_POST['month']. |
---|
149 | '&lang='.$_POST['lang']. |
---|
150 | '&sortby='.$_POST['sortby']. |
---|
151 | '&order='.$_POST['order']. |
---|
152 | '&page='.$_POST['page']. |
---|
153 | '&nb='.$_POST['nb']; |
---|
154 | } |
---|
155 | $redir_sel = $redir; |
---|
156 | |
---|
157 | if (!empty($_POST['entries'])) |
---|
158 | { |
---|
159 | $entries = $_POST['entries']; |
---|
160 | |
---|
161 | foreach ($entries as $k => $v) { |
---|
162 | $entries[$k] = (integer) $v; |
---|
163 | } |
---|
164 | |
---|
165 | $params['sql'] = 'AND P.post_id IN('.implode(',',$entries).') '; |
---|
166 | |
---|
167 | if (!isset($_POST['full_content']) || empty($_POST['full_content'])) { |
---|
168 | $params['no_content'] = true; |
---|
169 | } |
---|
170 | |
---|
171 | if (isset($_POST['post_type'])) { |
---|
172 | $params['post_type'] = $_POST['post_type']; |
---|
173 | } |
---|
174 | |
---|
175 | $posts = $core->blog->getPosts($params); |
---|
176 | while ($posts->fetch()) { |
---|
177 | $posts_ids[] = $posts->post_id; |
---|
178 | $fields->addEntry($posts->post_id,$posts->post_title); |
---|
179 | } |
---|
180 | // Redirection including selected entries |
---|
181 | $redir_sel = $redir.'&'.$fields->getEntriesQS(); |
---|
182 | |
---|
183 | } else { |
---|
184 | $posts = $core->con->select("SELECT blog_id FROM ".$core->prefix."blog WHERE false");; |
---|
185 | } |
---|
186 | |
---|
187 | /* Actions |
---|
188 | -------------------------------------------------------- */ |
---|
189 | if (!empty($_POST['action'])) |
---|
190 | { |
---|
191 | $action = $_POST['action']; |
---|
192 | } |
---|
193 | else |
---|
194 | { |
---|
195 | $core->error->add(__('No action specified.')); |
---|
196 | dcPage::open( |
---|
197 | __('Entries'),'',dcPage::breadcrumb( |
---|
198 | array( |
---|
199 | html::escapeHTML($core->blog->name) => '', |
---|
200 | __('Entries') => 'posts.php', |
---|
201 | '<span class="page-title">'.__('Entries actions').'</span>' => '' |
---|
202 | )) |
---|
203 | ); |
---|
204 | |
---|
205 | echo '<p><a class="back" href="'.html::escapeURL($redir_sel).'">'.__('Back to entries list').'</a></p>'; |
---|
206 | |
---|
207 | dcPage::close(); |
---|
208 | exit; |
---|
209 | } |
---|
210 | |
---|
211 | # --BEHAVIOR-- adminPostsActions |
---|
212 | $core->callBehavior('adminPostsActions',$core,$posts,$action,$redir); |
---|
213 | |
---|
214 | if (preg_match('/^(publish|unpublish|schedule|pending)$/',$action)) |
---|
215 | { |
---|
216 | switch ($action) { |
---|
217 | case 'unpublish' : $status = 0; break; |
---|
218 | case 'schedule' : $status = -1; break; |
---|
219 | case 'pending' : $status = -2; break; |
---|
220 | default : $status = 1; break; |
---|
221 | } |
---|
222 | |
---|
223 | try |
---|
224 | { |
---|
225 | $core->blog->updPostsStatus($posts_ids,$status); |
---|
226 | |
---|
227 | http::redirect($redir_sel.'&upd=1'); |
---|
228 | } |
---|
229 | catch (Exception $e) |
---|
230 | { |
---|
231 | $core->error->add($e->getMessage()); |
---|
232 | } |
---|
233 | } |
---|
234 | elseif ($action == 'selected' || $action == 'unselected') |
---|
235 | { |
---|
236 | try |
---|
237 | { |
---|
238 | $core->blog->updPostsSelected($posts_ids,$action == 'selected'); |
---|
239 | |
---|
240 | http::redirect($redir_sel."&upd=1"); |
---|
241 | } |
---|
242 | catch (Exception $e) |
---|
243 | { |
---|
244 | $core->error->add($e->getMessage()); |
---|
245 | } |
---|
246 | } |
---|
247 | elseif ($action == 'delete') |
---|
248 | { |
---|
249 | try |
---|
250 | { |
---|
251 | // Backward compatibility |
---|
252 | foreach($posts_ids as $post_id) |
---|
253 | { |
---|
254 | # --BEHAVIOR-- adminBeforePostDelete |
---|
255 | $core->callBehavior('adminBeforePostDelete',(integer) $post_id); |
---|
256 | } |
---|
257 | |
---|
258 | # --BEHAVIOR-- adminBeforePostsDelete |
---|
259 | $core->callBehavior('adminBeforePostsDelete',$posts_ids); |
---|
260 | |
---|
261 | $core->blog->delPosts($posts_ids); |
---|
262 | |
---|
263 | http::redirect($redir."&del=1"); |
---|
264 | } |
---|
265 | catch (Exception $e) |
---|
266 | { |
---|
267 | $core->error->add($e->getMessage()); |
---|
268 | } |
---|
269 | |
---|
270 | } |
---|
271 | elseif ($action == 'category' && isset($_POST['new_cat_id'])) |
---|
272 | { |
---|
273 | $new_cat_id = $_POST['new_cat_id']; |
---|
274 | |
---|
275 | try |
---|
276 | { |
---|
277 | if (!empty($_POST['new_cat_title']) && $core->auth->check('categories', $core->blog->id)) |
---|
278 | { |
---|
279 | $cur_cat = $core->con->openCursor($core->prefix.'category'); |
---|
280 | $cur_cat->cat_title = $_POST['new_cat_title']; |
---|
281 | $cur_cat->cat_url = ''; |
---|
282 | |
---|
283 | $parent_cat = !empty($_POST['new_cat_parent']) ? $_POST['new_cat_parent'] : ''; |
---|
284 | |
---|
285 | # --BEHAVIOR-- adminBeforeCategoryCreate |
---|
286 | $core->callBehavior('adminBeforeCategoryCreate', $cur_cat); |
---|
287 | |
---|
288 | $new_cat_id = $core->blog->addCategory($cur_cat, (integer) $parent_cat); |
---|
289 | |
---|
290 | # --BEHAVIOR-- adminAfterCategoryCreate |
---|
291 | $core->callBehavior('adminAfterCategoryCreate', $cur_cat, $new_cat_id); |
---|
292 | } |
---|
293 | |
---|
294 | $core->blog->updPostsCategory($posts_ids, $new_cat_id); |
---|
295 | |
---|
296 | http::redirect($redir_sel."&upd=1"); |
---|
297 | } |
---|
298 | catch (Exception $e) |
---|
299 | { |
---|
300 | $core->error->add($e->getMessage()); |
---|
301 | } |
---|
302 | } |
---|
303 | elseif ($action == 'author' && isset($_POST['new_auth_id']) |
---|
304 | && $core->auth->check('admin',$core->blog->id)) |
---|
305 | { |
---|
306 | $new_user_id = $_POST['new_auth_id']; |
---|
307 | |
---|
308 | try |
---|
309 | { |
---|
310 | if ($core->getUser($new_user_id)->isEmpty()) { |
---|
311 | throw new Exception(__('This user does not exist')); |
---|
312 | } |
---|
313 | |
---|
314 | $cur = $core->con->openCursor($core->prefix.'post'); |
---|
315 | $cur->user_id = $new_user_id; |
---|
316 | $cur->update('WHERE post_id '.$core->con->in($posts_ids)); |
---|
317 | |
---|
318 | http::redirect($redir_sel."&upd=1"); |
---|
319 | } |
---|
320 | catch (Exception $e) |
---|
321 | { |
---|
322 | $core->error->add($e->getMessage()); |
---|
323 | } |
---|
324 | } |
---|
325 | elseif ($action == 'lang' && isset($_POST['new_lang'])) |
---|
326 | { |
---|
327 | $new_lang = $_POST['new_lang']; |
---|
328 | try |
---|
329 | { |
---|
330 | $cur = $core->con->openCursor($core->prefix.'post'); |
---|
331 | $cur->post_lang = $new_lang; |
---|
332 | $cur->update('WHERE post_id '.$core->con->in($posts_ids)); |
---|
333 | |
---|
334 | http::redirect($redir_sel."&upd=1"); |
---|
335 | } |
---|
336 | catch (Exception $e) |
---|
337 | { |
---|
338 | $core->error->add($e->getMessages()); |
---|
339 | } |
---|
340 | } |
---|
341 | |
---|
342 | /* DISPLAY |
---|
343 | -------------------------------------------------------- */ |
---|
344 | // Get current users list |
---|
345 | $usersList = ''; |
---|
346 | if ($action == 'author' && $core->auth->check('admin',$core->blog->id)) { |
---|
347 | $params = array( |
---|
348 | 'limit' => 100, |
---|
349 | 'order' => 'nb_post DESC' |
---|
350 | ); |
---|
351 | $rs = $core->getUsers($params); |
---|
352 | while ($rs->fetch()) |
---|
353 | { |
---|
354 | $usersList .= ($usersList != '' ? ',' : '').'"'.$rs->user_id.'"'; |
---|
355 | } |
---|
356 | } |
---|
357 | dcPage::open( |
---|
358 | __('Entries'), |
---|
359 | '<script type="text/javascript">'."\n". |
---|
360 | "//<![CDATA[\n". |
---|
361 | 'usersList = ['.$usersList.']'."\n". |
---|
362 | "\n//]]>\n". |
---|
363 | "</script>\n". |
---|
364 | dcPage::jsLoad('js/jquery/jquery.autocomplete.js'). |
---|
365 | dcPage::jsLoad('js/_posts_actions.js'). |
---|
366 | dcPage::jsMetaEditor(). |
---|
367 | # --BEHAVIOR-- adminBeforePostDelete |
---|
368 | $core->callBehavior('adminPostsActionsHeaders') |
---|
369 | ); |
---|
370 | |
---|
371 | if (!isset($action)) { |
---|
372 | dcPage::close(); |
---|
373 | exit; |
---|
374 | } |
---|
375 | |
---|
376 | if (isset($_POST['redir']) && strpos($_POST['redir'],'://') === false) |
---|
377 | { |
---|
378 | $fields->addHidden(array('redir'),html::escapeURL($_POST['redir'])); |
---|
379 | } |
---|
380 | else |
---|
381 | { |
---|
382 | $fields |
---|
383 | ->addHidden(array('user_id'),$_POST['user_id']) |
---|
384 | ->addHidden(array('cat_id'),$_POST['cat_id']) |
---|
385 | ->addHidden(array('status'),$_POST['status']) |
---|
386 | ->addHidden(array('selected'),$_POST['selected']) |
---|
387 | ->addHidden(array('month'),$_POST['month']) |
---|
388 | ->addHidden(array('lang'),$_POST['lang']) |
---|
389 | ->addHidden(array('sortby'),$_POST['sortby']) |
---|
390 | ->addHidden(array('order'),$_POST['order']) |
---|
391 | ->addHidden(array('page'),$_POST['page']) |
---|
392 | ->addHidden(array('nb'),$_POST['nb']) |
---|
393 | ; |
---|
394 | } |
---|
395 | |
---|
396 | if (isset($_POST['post_type'])) { |
---|
397 | $fields->addHidden(array('post_type'),$_POST['post_type']); |
---|
398 | } |
---|
399 | |
---|
400 | # --BEHAVIOR-- adminPostsActionsContent |
---|
401 | $core->callBehavior('adminPostsActionsContent',$core,$action,$fields); |
---|
402 | |
---|
403 | if ($action == 'category') |
---|
404 | { |
---|
405 | echo dcPage::breadcrumb( |
---|
406 | array( |
---|
407 | html::escapeHTML($core->blog->name) => '', |
---|
408 | __('Entries') => 'posts.php', |
---|
409 | '<span class="page-title">'.__('Change category for this selection').'</span>' => '' |
---|
410 | )); |
---|
411 | |
---|
412 | echo '<p><a class="back" href="'.html::escapeURL($redir_sel).'">'.__('Back to entries list').'</a></p>'; |
---|
413 | |
---|
414 | # categories list |
---|
415 | # Getting categories |
---|
416 | $categories_combo = array(__('(No cat)') => ''); |
---|
417 | try { |
---|
418 | $categories = $core->blog->getCategories(array('post_type'=>'post')); |
---|
419 | if (!$categories->isEmpty()) { |
---|
420 | while ($categories->fetch()) { |
---|
421 | $catparents_combo[] = $categories_combo[] = new formSelectOption( |
---|
422 | str_repeat(' ',$categories->level-1).($categories->level-1 == 0 ? '' : '• ').html::escapeHTML($categories->cat_title), |
---|
423 | $categories->cat_id |
---|
424 | ); |
---|
425 | } |
---|
426 | } |
---|
427 | } catch (Exception $e) { } |
---|
428 | |
---|
429 | echo |
---|
430 | '<form action="posts_actions.php" method="post">'. |
---|
431 | $fields->getEntries(). |
---|
432 | '<p><label for="new_cat_id" class="classic">'.__('Category:').'</label> '. |
---|
433 | form::combo('new_cat_id',$categories_combo,''); |
---|
434 | |
---|
435 | if ($core->auth->check('categories', $core->blog->id)) { |
---|
436 | echo |
---|
437 | '<div>'. |
---|
438 | '<p id="new_cat">'.__('Create a new category for the post(s)').'</p>'. |
---|
439 | '<p><label for="new_cat_title">'.__('Title:').'</label> '. |
---|
440 | form::field('new_cat_title',30,255,'','').'</p>'. |
---|
441 | '<p><label for="new_cat_parent">'.__('Parent:').'</label> '. |
---|
442 | form::combo('new_cat_parent',$categories_combo,'',''). |
---|
443 | '</p>'. |
---|
444 | '</div>'; |
---|
445 | } |
---|
446 | |
---|
447 | echo |
---|
448 | $fields->getHidden(). |
---|
449 | $core->formNonce(). |
---|
450 | form::hidden(array('action'),'category'). |
---|
451 | '<input type="submit" value="'.__('Save').'" /></p>'. |
---|
452 | '</form>'; |
---|
453 | } |
---|
454 | elseif ($action == 'lang') |
---|
455 | { |
---|
456 | echo dcPage::breadcrumb( |
---|
457 | array( |
---|
458 | html::escapeHTML($core->blog->name) => '', |
---|
459 | __('Entries') => 'posts.php', |
---|
460 | '<span class="page-title">'.__('Change language for this selection').'</span>' => '' |
---|
461 | )); |
---|
462 | echo '<p><a class="back" href="'.html::escapeURL($redir_sel).'">'.__('Back to entries list').'</a></p>'; |
---|
463 | |
---|
464 | # lang list |
---|
465 | # Languages combo |
---|
466 | $rs = $core->blog->getLangs(array('order'=>'asc')); |
---|
467 | $all_langs = l10n::getISOcodes(0,1); |
---|
468 | $lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(1,1)); |
---|
469 | while ($rs->fetch()) { |
---|
470 | if (isset($all_langs[$rs->post_lang])) { |
---|
471 | $lang_combo[__('Most used')][$all_langs[$rs->post_lang]] = $rs->post_lang; |
---|
472 | unset($lang_combo[__('Available')][$all_langs[$rs->post_lang]]); |
---|
473 | } else { |
---|
474 | $lang_combo[__('Most used')][$rs->post_lang] = $rs->post_lang; |
---|
475 | } |
---|
476 | } |
---|
477 | unset($all_langs); |
---|
478 | unset($rs); |
---|
479 | |
---|
480 | echo |
---|
481 | '<form action="posts_actions.php" method="post">'. |
---|
482 | $fields->getEntries(). |
---|
483 | |
---|
484 | '<p><label for="new_lang" class="classic">'.__('Entry lang:').'</label> '. |
---|
485 | form::combo('new_lang',$lang_combo,''); |
---|
486 | |
---|
487 | echo |
---|
488 | $fields->getHidden(). |
---|
489 | $core->formNonce(). |
---|
490 | form::hidden(array('action'),'lang'). |
---|
491 | '<input type="submit" value="'.__('Save').'" /></p>'. |
---|
492 | '</form>'; |
---|
493 | |
---|
494 | } |
---|
495 | elseif ($action == 'author' && $core->auth->check('admin',$core->blog->id)) |
---|
496 | { |
---|
497 | echo dcPage::breadcrumb( |
---|
498 | array( |
---|
499 | html::escapeHTML($core->blog->name) => '', |
---|
500 | __('Entries') => 'posts.php', |
---|
501 | '<span class="page-title">'.__('Change author for this selection').'</span>' => '' |
---|
502 | )); |
---|
503 | echo '<p><a class="back" href="'.html::escapeURL($redir_sel).'">'.__('Back to entries list').'</a></p>'; |
---|
504 | |
---|
505 | echo |
---|
506 | '<form action="posts_actions.php" method="post">'. |
---|
507 | $fields->getEntries(). |
---|
508 | '<p><label for="new_auth_id" class="classic">'.__('New author (author ID):').'</label> '. |
---|
509 | form::field('new_auth_id',20,255); |
---|
510 | |
---|
511 | echo |
---|
512 | $fields->getHidden(). |
---|
513 | $core->formNonce(). |
---|
514 | form::hidden(array('action'),'author'). |
---|
515 | '<input type="submit" value="'.__('Save').'" /></p>'. |
---|
516 | '</form>'; |
---|
517 | } |
---|
518 | |
---|
519 | dcPage::close(); |
---|
520 | ?> |
---|