Dotclear


Ignore:
Timestamp:
08/19/13 12:17:53 (11 years ago)
Author:
Dsls
Branch:
default
Parents:
1472:994f097572a6 (diff), 1470:e0422863bf62 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Fusion

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • admin/posts_actions.php

    r1468 r1473  
    1616 
    1717$params = array(); 
    18 $action = ''; 
     18 
     19/** 
     20* FieldsList - Compatibility class for hidden fields & entries[] fields 
     21* 
     22*/ 
     23class 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     * __toString - magic method. -- DEPRECATED here 
     109      *              This method is only used to preserve compatibility with plugins  
     110      *                  relying on previous versions of adminPostsActionsContent behavior,  
     111      * 
     112     * @access public 
     113      * @return the list of hidden fields and entries (as hidden fields too), html encoded 
     114     */ 
     115     public function __toString() { 
     116          return join('',$this->hidden).$this->getEntries(true); 
     117     } 
     118} 
     119 
     120 
     121function listEntries($titles) { 
     122     $ret =  
     123          '<table class="posts-list"><tr>'. 
     124          '<th colspan="2">'.__('Title').'</th>'. 
     125          '</tr>'; 
     126     foreach ($titles as $id=>$title) { 
     127          $ret .=  
     128               '<tr><td>'. 
     129               form::checkbox(array('entries[]'),$id,true,'','').'</td>'. 
     130               '<td>'.   $title.'</td></tr>'; 
     131     } 
     132     $ret .= '</table>'; 
     133     return $ret; 
     134} 
    19135 
    20136/* Actions 
     
    195311          } 
    196312     } 
    197 } 
    198  
     313} else { 
     314     if (empty($_POST['entries'])) { 
     315          $core->error->add(__('At least one entry should be selected')); 
     316     } else { 
     317          $core->error->add(__('No action specified.')); 
     318     } 
     319     dcPage::open( 
     320          __('Entries'),'',dcPage::breadcrumb( 
     321          array( 
     322               html::escapeHTML($core->blog->name) => '', 
     323               __('Entries') => 'posts.php', 
     324               '<span class="page-title">'.__('Entries actions').'</span>' => '' 
     325          )) 
     326     ); 
     327 
     328     dcPage::close(); 
     329     exit; 
     330} 
    199331/* DISPLAY 
    200332-------------------------------------------------------- */ 
     
    231363} 
    232364 
    233 $hidden_fields = ''; 
     365$fields = new FieldsList(); 
    234366while ($posts->fetch()) { 
    235      $hidden_fields .= form::hidden(array('entries[]'),$posts->post_id); 
     367     $fields->addEntry($posts->post_id,$posts->post_title); 
    236368} 
    237369 
    238370if (isset($_POST['redir']) && strpos($_POST['redir'],'://') === false) 
    239371{ 
    240      $hidden_fields .= form::hidden(array('redir'),html::escapeURL($_POST['redir'])); 
     372     $fields->addHidden(array('redir'),html::escapeURL($_POST['redir'])); 
    241373} 
    242374else 
    243375{ 
    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']); 
     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     ; 
    255388} 
    256389 
    257390if (isset($_POST['post_type'])) { 
    258      $hidden_fields .= form::hidden(array('post_type'),$_POST['post_type']); 
     391     $fields->addHidden(array('post_type'),$_POST['post_type']); 
    259392} 
    260393 
    261394# --BEHAVIOR-- adminPostsActionsContent 
    262 $core->callBehavior('adminPostsActionsContent',$core,$action,$hidden_fields); 
     395$core->callBehavior('adminPostsActionsContent',$core,$action,$fields); 
    263396 
    264397if ($action == 'category') 
    265398{ 
    266      echo '<h2 class="page-title">'.__('Change category for entries').'</h2>'; 
    267       
     399     echo dcPage::breadcrumb( 
     400          array( 
     401               html::escapeHTML($core->blog->name) => '', 
     402               __('Entries') => 'posts.php', 
     403               __('Change category for entries') => '' 
     404     )); 
     405 
     406     # categories list 
    268407     # Getting categories 
    269408     $categories_combo = array(__('(No cat)') => ''); 
     
    271410          $categories = $core->blog->getCategories(array('post_type'=>'post')); 
    272411          if (!$categories->isEmpty()) { 
    273                while ($categories->fetch()) { 
     412          while ($categories->fetch()) { 
    274413                    $catparents_combo[] = $categories_combo[] = new formSelectOption( 
    275414                         str_repeat('&nbsp;&nbsp;',$categories->level-1).($categories->level-1 == 0 ? '' : '&bull; ').html::escapeHTML($categories->cat_title), 
    276                          $categories->cat_id 
    277                     ); 
    278                } 
     415                    $categories->cat_id 
     416               ); 
     417          } 
    279418          } 
    280419     } catch (Exception $e) { } 
     
    282421     echo 
    283422     '<form action="posts_actions.php" method="post">'. 
     423     $fields->getEntries(). 
    284424     '<p><label for="new_cat_id" class="classic">'.__('Category:').'</label> '. 
    285425     form::combo('new_cat_id',$categories_combo,''); 
     
    298438      
    299439     echo 
    300      $hidden_fields. 
     440     $fields->getHidden(). 
    301441     $core->formNonce(). 
    302442     form::hidden(array('action'),'category'). 
     
    306446elseif ($action == 'lang') 
    307447{ 
    308      echo '<h2 class="page-title">'.__('Change language for entries').'</h2>'; 
     448     echo dcPage::breadcrumb( 
     449          array( 
     450               html::escapeHTML($core->blog->name) => '', 
     451               __('Entries') => 'posts.php', 
     452               '<span class="page-title">'.__('Change language for entries').'</span>' => '' 
     453     )); 
    309454      
    310455     # lang list 
     
    326471     echo 
    327472     '<form action="posts_actions.php" method="post">'. 
     473     $fields->getEntries(). 
     474      
    328475     '<p><label for="new_lang" class="classic">'.__('Entry lang:').'</label> '. 
    329476     form::combo('new_lang',$lang_combo,''); 
    330477      
    331478     echo 
    332      $hidden_fields. 
     479     $fields->getHidden(). 
    333480     $core->formNonce(). 
    334481     form::hidden(array('action'),'lang'). 
     
    339486elseif ($action == 'author' && $core->auth->check('admin',$core->blog->id)) 
    340487{ 
    341      echo '<h2 class="page-title">'.__('Change author for entries').'</h2>'; 
     488     echo dcPage::breadcrumb( 
     489          array( 
     490               html::escapeHTML($core->blog->name) => '', 
     491               __('Entries') => 'posts.php', 
     492               '<span class="page-title">'.__('Change author for entries').'</span>' => '' 
     493     )); 
    342494      
    343495     echo 
    344496     '<form action="posts_actions.php" method="post">'. 
     497     $fields->getEntries(). 
    345498     '<p><label for="new_auth_id" class="classic">'.__('Author ID:').'</label> '. 
    346499     form::field('new_auth_id',20,255); 
    347500      
    348501     echo 
    349      $hidden_fields. 
     502     $fields->getHidden(). 
    350503     $core->formNonce(). 
    351504     form::hidden(array('action'),'author'). 
  • admin/posts_actions.php

    r1472 r1473  
    243243     elseif ($action == 'category' && isset($_POST['new_cat_id'])) 
    244244     { 
     245          $new_cat_id = $_POST['new_cat_id']; 
     246           
    245247          try 
    246248          { 
    247                $core->blog->updPostsCategory($posts_ids,$_POST['new_cat_id']); 
     249               if (!empty($_POST['new_cat_title']) && $core->auth->check('categories', $core->blog->id)) 
     250               { 
     251                    $cur_cat = $core->con->openCursor($core->prefix.'category'); 
     252                    $cur_cat->cat_title = $_POST['new_cat_title']; 
     253                    $cur_cat->cat_url = ''; 
     254                     
     255                    $parent_cat = !empty($_POST['new_cat_parent']) ? $_POST['new_cat_parent'] : ''; 
     256                     
     257                    # --BEHAVIOR-- adminBeforeCategoryCreate 
     258                    $core->callBehavior('adminBeforeCategoryCreate', $cur_cat); 
     259                     
     260                    $new_cat_id = $core->blog->addCategory($cur_cat, (integer) $parent_cat); 
     261                     
     262                    # --BEHAVIOR-- adminAfterCategoryCreate 
     263                    $core->callBehavior('adminAfterCategoryCreate', $cur_cat, $new_cat_id); 
     264               } 
     265                
     266               $core->blog->updPostsCategory($posts_ids, $new_cat_id); 
    248267                
    249268               http::redirect($redir); 
     
    387406     # categories list 
    388407     # Getting categories 
    389      $categories_combo = array('&nbsp;' => ''); 
     408     $categories_combo = array(__('(No cat)') => ''); 
    390409     try { 
    391410          $categories = $core->blog->getCategories(array('post_type'=>'post')); 
     411          if (!$categories->isEmpty()) { 
    392412          while ($categories->fetch()) { 
    393                $categories_combo[] = new formSelectOption( 
    394                     str_repeat('&nbsp;&nbsp;',$categories->level-1). 
    395                     ($categories->level-1 == 0 ? '' : '&bull; ').html::escapeHTML($categories->cat_title), 
     413                    $catparents_combo[] = $categories_combo[] = new formSelectOption( 
     414                         str_repeat('&nbsp;&nbsp;',$categories->level-1).($categories->level-1 == 0 ? '' : '&bull; ').html::escapeHTML($categories->cat_title), 
    396415                    $categories->cat_id 
    397416               ); 
     417          } 
    398418          } 
    399419     } catch (Exception $e) { } 
     
    402422     '<form action="posts_actions.php" method="post">'. 
    403423     $fields->getEntries(). 
    404      '<p><label for="new_cat_id" class="classic">'.__('Category:').' '. 
    405      form::combo('new_cat_id',$categories_combo,''). 
    406      '</label> '; 
     424     '<p><label for="new_cat_id" class="classic">'.__('Category:').'</label> '. 
     425     form::combo('new_cat_id',$categories_combo,''); 
     426      
     427     if ($core->auth->check('categories', $core->blog->id)) { 
     428          echo  
     429          '<div>'. 
     430          '<p id="new_cat">'.__('Add a new category').'</p>'. 
     431          '<p><label for="new_cat_title">'.__('Title:').' '. 
     432          form::field('new_cat_title',30,255,'','maximal').'</label></p>'. 
     433          '<p><label for="new_cat_parent">'.__('Parent:').' '. 
     434          form::combo('new_cat_parent',$categories_combo,'','maximal'). 
     435          '</label></p>'. 
     436          '</div>'; 
     437     } 
    407438      
    408439     echo 
     
    440471     echo 
    441472     '<form action="posts_actions.php" method="post">'. 
    442      $fields->getEntries().    
    443      '<p><label for="new_lang" class="classic">'.__('Entry lang:').' '. 
    444      form::combo('new_lang',$lang_combo,''). 
    445      '</label> '; 
     473     $fields->getEntries(). 
     474      
     475     '<p><label for="new_lang" class="classic">'.__('Entry lang:').'</label> '. 
     476     form::combo('new_lang',$lang_combo,''); 
    446477      
    447478     echo 
     
    465496     '<form action="posts_actions.php" method="post">'. 
    466497     $fields->getEntries(). 
    467      '<p><label for="new_auth_id" class="classic">'.__('Author ID:').' '. 
    468      form::field('new_auth_id',20,255). 
    469      '</label> '; 
     498     '<p><label for="new_auth_id" class="classic">'.__('Author ID:').'</label> '. 
     499     form::field('new_auth_id',20,255); 
    470500      
    471501     echo 
Note: See TracChangeset for help on using the changeset viewer.

Sites map