Dotclear

source: admin/posts_actions.php @ 1520:21493e072441

Revision 1520:21493e072441, 13.4 KB checked in by Anne Kozlika <kozlika@…>, 12 years ago (diff)

post_actions : add span tag to the current page, adjust wording for category creation (need to be confirm by an english-speaker), some css rules.

RevLine 
[0]1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
[1179]6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
[0]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$params = array();
[1399]18
[1472]19/**
20* FieldsList - Compatibility class for hidden fields & entries[] fields
21*
22*/
[1471]23class FieldsList {
[1472]24     /** @var array list of hidden fields */
[1471]25     protected $hidden;
[1472]26     /** @var array list of selected entries */
[1471]27     protected $entries;
[1472]28
29
30   /**
31     * Class constructor
32     */
[1471]33     public function __construct() {
34          $this->hidden=array();
35          $this->entries =array();
36     }
[1472]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) {
[1471]48          $this->hidden[] = form::hidden($name,$value);
49          return $this;
50     }
[1472]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) {
[1471]62          $this->entries[$id]=$title;
63          return $this;
64     }
65
[1472]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() {
[1471]73          return join('',$this->hidden);
74     }
75     
[1472]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     */
[1471]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     
[1472]107    /**
[1476]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    /**
[1472]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     */
[1471]129     public function __toString() {
130          return join('',$this->hidden).$this->getEntries(true);
131     }
132}
133
[1476]134$fields = new FieldsList();
[0]135
136/* Actions
137-------------------------------------------------------- */
138if (!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     
[1030]178     $posts_ids = array();
179     while ($posts->fetch())  {
180          $posts_ids[] = $posts->post_id;
[1476]181          $fields->addEntry($posts->post_id,$posts->post_title);
[1030]182     }
[1476]183     // Redirection including selected entries
184     $redir_sel = $redir.'&'.$fields->getEntriesQS();
[1030]185     
[0]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          {
[1030]200               $core->blog->updPostsStatus($posts_ids,$status);
[0]201               
[1476]202               http::redirect($redir_sel.'&upd=1');
[0]203          }
204          catch (Exception $e)
205          {
206               $core->error->add($e->getMessage());
207          }
208     }
209     elseif ($action == 'selected' || $action == 'unselected')
210     {
211          try
212          {
[1030]213               $core->blog->updPostsSelected($posts_ids,$action == 'selected');
[0]214               
[1476]215               http::redirect($redir_sel."&upd=1");
[0]216          }
217          catch (Exception $e)
218          {
219               $core->error->add($e->getMessage());
220          }
221     }
222     elseif ($action == 'delete')
223     {
224          try
225          {
[1030]226               // Backward compatibility
227               foreach($posts_ids as $post_id)
228               {
[0]229                    # --BEHAVIOR-- adminBeforePostDelete
[1030]230                    $core->callBehavior('adminBeforePostDelete',(integer) $post_id);
[0]231               }
232               
[1030]233               # --BEHAVIOR-- adminBeforePostsDelete
234               $core->callBehavior('adminBeforePostsDelete',$posts_ids);
235               
236               $core->blog->delPosts($posts_ids);
237               
[1476]238               http::redirect($redir."&del=1");
[0]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     {
[1419]248          $new_cat_id = $_POST['new_cat_id'];
249         
[0]250          try
251          {
[1419]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);
[1030]270               
[1476]271               http::redirect($redir_sel."&upd=1");
[0]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               
[1030]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));
[0]292               
[1476]293               http::redirect($redir_sel."&upd=1");
[0]294          }
295          catch (Exception $e)
296          {
297               $core->error->add($e->getMessage());
298          }
299     }
[1102]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               
[1476]309               http::redirect($redir_sel."&upd=1");
[1102]310          }
311          catch (Exception $e)
312          {
313               $core->error->add($e->getMessages());
314          }
315     }
[1471]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     );
[1476]330     
331     echo '<p><a class="back" href="'.html::escapeURL($redir_sel).'">'.__('Back to entries list').'</a></p>';
[1471]332
333     dcPage::close();
334     exit;
[0]335}
336/* DISPLAY
337-------------------------------------------------------- */
[1035]338// Get current users list
339$usersList = '';
340if ($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}
[0]351dcPage::open(
352     __('Entries'),
[1035]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').
[0]360     dcPage::jsMetaEditor().
361     # --BEHAVIOR-- adminBeforePostDelete
362     $core->callBehavior('adminPostsActionsHeaders')
363);
364
365if (!isset($action)) {
366     dcPage::close();
367     exit;
368}
369
370if (isset($_POST['redir']) && strpos($_POST['redir'],'://') === false)
371{
[1471]372     $fields->addHidden(array('redir'),html::escapeURL($_POST['redir']));
[0]373}
374else
375{
[1471]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     ;
[0]388}
389
390if (isset($_POST['post_type'])) {
[1471]391     $fields->addHidden(array('post_type'),$_POST['post_type']);
[0]392}
393
394# --BEHAVIOR-- adminPostsActionsContent
[1471]395$core->callBehavior('adminPostsActionsContent',$core,$action,$fields);
[0]396
397if ($action == 'category')
398{
[1471]399     echo dcPage::breadcrumb(
400          array(
401               html::escapeHTML($core->blog->name) => '',
402               __('Entries') => 'posts.php',
[1520]403               '<span class="page-title">'.__('Change category for entries').'</span>' => ''
[1471]404     ));
[1476]405     
406     echo '<p><a class="back" href="'.html::escapeURL($redir_sel).'">'.__('Back to entries list').'</a></p>';
[1471]407
[1399]408     # categories list
[0]409     # Getting categories
[1389]410     $categories_combo = array(__('(No cat)') => '');
[0]411     try {
412          $categories = $core->blog->getCategories(array('post_type'=>'post'));
[1389]413          if (!$categories->isEmpty()) {
[1399]414          while ($categories->fetch()) {
[1421]415                    $catparents_combo[] = $categories_combo[] = new formSelectOption(
416                         str_repeat('&nbsp;&nbsp;',$categories->level-1).($categories->level-1 == 0 ? '' : '&bull; ').html::escapeHTML($categories->cat_title),
[1399]417                    $categories->cat_id
418               );
419          }
[0]420          }
421     } catch (Exception $e) { }
422     
423     echo
424     '<form action="posts_actions.php" method="post">'.
[1471]425     $fields->getEntries().
[1399]426     '<p><label for="new_cat_id" class="classic">'.__('Category:').'</label> '.
427     form::combo('new_cat_id',$categories_combo,'');
[0]428     
[1419]429     if ($core->auth->check('categories', $core->blog->id)) {
430          echo 
431          '<div>'.
[1520]432          '<p id="new_cat">'.__('Create a new category for the post(s)').'</p>'.
433          '<p><label for="new_cat_title">'.__('Title:').'</label> '.
434          form::field('new_cat_title',30,255,'','').'</p>'.
435          '<p><label for="new_cat_parent">'.__('Parent:').'</label> '.
436          form::combo('new_cat_parent',$categories_combo,'','').
437          '</p>'.
[1419]438          '</div>';
439     }
440     
[0]441     echo
[1471]442     $fields->getHidden().
[0]443     $core->formNonce().
444     form::hidden(array('action'),'category').
[217]445     '<input type="submit" value="'.__('Save').'" /></p>'.
[0]446     '</form>';
447}
[1102]448elseif ($action == 'lang')
449{
[1471]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     ));
[1476]456     echo '<p><a class="back" href="'.html::escapeURL($redir_sel).'">'.__('Back to entries list').'</a></p>';
457
[1102]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">'.
[1473]476     $fields->getEntries().
477     
[1399]478     '<p><label for="new_lang" class="classic">'.__('Entry lang:').'</label> '.
479     form::combo('new_lang',$lang_combo,'');
[1102]480     
481     echo
[1471]482     $fields->getHidden().
[1102]483     $core->formNonce().
484     form::hidden(array('action'),'lang').
485     '<input type="submit" value="'.__('Save').'" /></p>'.
486     '</form>';
487
488}
[0]489elseif ($action == 'author' && $core->auth->check('admin',$core->blog->id))
490{
[1471]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     ));
[1476]497     echo '<p><a class="back" href="'.html::escapeURL($redir_sel).'">'.__('Back to entries list').'</a></p>';
498
[0]499     echo
500     '<form action="posts_actions.php" method="post">'.
[1471]501     $fields->getEntries().
[1518]502     '<p><label for="new_auth_id" class="classic">'.__('New author (author ID):').'</label> '.
[1399]503     form::field('new_auth_id',20,255);
[0]504     
505     echo
[1471]506     $fields->getHidden().
[0]507     $core->formNonce().
508     form::hidden(array('action'),'author').
[217]509     '<input type="submit" value="'.__('Save').'" /></p>'.
[0]510     '</form>';
511}
512
513dcPage::close();
514?>
Note: See TracBrowser for help on using the repository browser.

Sites map