Dotclear


Ignore:
Timestamp:
09/22/13 11:38:22 (12 years ago)
Author:
Dsls
Branch:
default
Parents:
1998:dae906985ebb (diff), 1905:d72d24250853 (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 avec actionsreloaded

File:
1 edited

Legend:

Unmodified
Added
Removed
  • admin/posts_actions.php

    r1964 r1999  
    1111# -- END LICENSE BLOCK ----------------------------------------- 
    1212 
     13/* ### THIS FILE IS DEPRECATED                         ### */ 
     14/* ### IT IS ONLY USED FOR PLUGINS COMPATIBILITY ### */ 
     15 
    1316require dirname(__FILE__).'/../inc/admin/prepend.php'; 
    1417 
    1518dcPage::check('usage,contentadmin'); 
    1619 
    17 $params = array(); 
     20$posts_actions_page = new dcPostsActionsPage($core,'posts.php'); 
    1821 
    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; 
     22$posts_actions_page->process(); 
    2823 
    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 = dcAdminCombos::getCategoriesCombo( 
    417           $core->blog->getCategories(array('post_type'=>'post')) 
    418      ); 
    419       
    420      echo 
    421      '<form action="posts_actions.php" method="post">'. 
    422      $fields->getEntries(). 
    423      '<p><label for="new_cat_id" class="classic">'.__('Category:').'</label> '. 
    424      form::combo('new_cat_id',$categories_combo,''); 
    425       
    426      if ($core->auth->check('categories', $core->blog->id)) { 
    427           echo  
    428           '<div>'. 
    429           '<p id="new_cat">'.__('Create a new category for the post(s)').'</p>'. 
    430           '<p><label for="new_cat_title">'.__('Title:').'</label> '. 
    431           form::field('new_cat_title',30,255,'','').'</p>'. 
    432           '<p><label for="new_cat_parent">'.__('Parent:').'</label> '. 
    433           form::combo('new_cat_parent',$categories_combo,'',''). 
    434           '</p>'. 
    435           '</div>'; 
    436      } 
    437       
    438      echo 
    439      $fields->getHidden(). 
    440      $core->formNonce(). 
    441      form::hidden(array('action'),'category'). 
    442      '<input type="submit" value="'.__('Save').'" /></p>'. 
    443      '</form>'; 
    444 } 
    445 elseif ($action == 'lang') 
    446 { 
    447      echo dcPage::breadcrumb( 
    448           array( 
    449                html::escapeHTML($core->blog->name) => '', 
    450                __('Entries') => 'posts.php', 
    451                '<span class="page-title">'.__('Change language for this selection').'</span>' => '' 
    452      )); 
    453      echo '<p><a class="back" href="'.html::escapeURL($redir_sel).'">'.__('Back to entries list').'</a></p>'; 
    454  
    455      # lang list 
    456      # Languages combo 
    457      $rs = $core->blog->getLangs(array('order'=>'asc')); 
    458      $lang_combo = dcAdminCombos::getLangsCombo($rs,true); 
    459       
    460      echo 
    461      '<form action="posts_actions.php" method="post">'. 
    462      $fields->getEntries(). 
    463       
    464      '<p><label for="new_lang" class="classic">'.__('Entry language:').'</label> '. 
    465      form::combo('new_lang',$lang_combo,''); 
    466       
    467      echo 
    468      $fields->getHidden(). 
    469      $core->formNonce(). 
    470      form::hidden(array('action'),'lang'). 
    471      '<input type="submit" value="'.__('Save').'" /></p>'. 
    472      '</form>'; 
    473  
    474 } 
    475 elseif ($action == 'author' && $core->auth->check('admin',$core->blog->id)) 
    476 { 
    477      echo dcPage::breadcrumb( 
    478           array( 
    479                html::escapeHTML($core->blog->name) => '', 
    480                __('Entries') => 'posts.php', 
    481                '<span class="page-title">'.__('Change author for this selection').'</span>' => '' 
    482      )); 
    483      echo '<p><a class="back" href="'.html::escapeURL($redir_sel).'">'.__('Back to entries list').'</a></p>'; 
    484  
    485      echo 
    486      '<form action="posts_actions.php" method="post">'. 
    487      $fields->getEntries(). 
    488      '<p><label for="new_auth_id" class="classic">'.__('New author (author ID):').'</label> '. 
    489      form::field('new_auth_id',20,255); 
    490       
    491      echo 
    492      $fields->getHidden(). 
    493      $core->formNonce(). 
    494      form::hidden(array('action'),'author'). 
    495      '<input type="submit" value="'.__('Save').'" /></p>'. 
    496      '</form>'; 
    497 } 
    498  
    499 dcPage::close(); 
    50024?> 
Note: See TracChangeset for help on using the changeset viewer.

Sites map