Changeset 1473:be1c768e98cc for admin/posts_actions.php
- Timestamp:
- 08/19/13 12:17:53 (11 years ago)
- 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. - Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
admin/posts_actions.php
r1468 r1473 16 16 17 17 $params = array(); 18 $action = ''; 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 * __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 121 function 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 } 19 135 20 136 /* Actions … … 195 311 } 196 312 } 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 } 199 331 /* DISPLAY 200 332 -------------------------------------------------------- */ … … 231 363 } 232 364 233 $ hidden_fields = '';365 $fields = new FieldsList(); 234 366 while ($posts->fetch()) { 235 $ hidden_fields .= form::hidden(array('entries[]'),$posts->post_id);367 $fields->addEntry($posts->post_id,$posts->post_title); 236 368 } 237 369 238 370 if (isset($_POST['redir']) && strpos($_POST['redir'],'://') === false) 239 371 { 240 $ hidden_fields .= form::hidden(array('redir'),html::escapeURL($_POST['redir']));372 $fields->addHidden(array('redir'),html::escapeURL($_POST['redir'])); 241 373 } 242 374 else 243 375 { 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 ; 255 388 } 256 389 257 390 if (isset($_POST['post_type'])) { 258 $ hidden_fields .= form::hidden(array('post_type'),$_POST['post_type']);391 $fields->addHidden(array('post_type'),$_POST['post_type']); 259 392 } 260 393 261 394 # --BEHAVIOR-- adminPostsActionsContent 262 $core->callBehavior('adminPostsActionsContent',$core,$action,$ hidden_fields);395 $core->callBehavior('adminPostsActionsContent',$core,$action,$fields); 263 396 264 397 if ($action == 'category') 265 398 { 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 268 407 # Getting categories 269 408 $categories_combo = array(__('(No cat)') => ''); … … 271 410 $categories = $core->blog->getCategories(array('post_type'=>'post')); 272 411 if (!$categories->isEmpty()) { 273 412 while ($categories->fetch()) { 274 413 $catparents_combo[] = $categories_combo[] = new formSelectOption( 275 414 str_repeat(' ',$categories->level-1).($categories->level-1 == 0 ? '' : '• ').html::escapeHTML($categories->cat_title), 276 277 278 415 $categories->cat_id 416 ); 417 } 279 418 } 280 419 } catch (Exception $e) { } … … 282 421 echo 283 422 '<form action="posts_actions.php" method="post">'. 423 $fields->getEntries(). 284 424 '<p><label for="new_cat_id" class="classic">'.__('Category:').'</label> '. 285 425 form::combo('new_cat_id',$categories_combo,''); … … 298 438 299 439 echo 300 $ hidden_fields.440 $fields->getHidden(). 301 441 $core->formNonce(). 302 442 form::hidden(array('action'),'category'). … … 306 446 elseif ($action == 'lang') 307 447 { 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 )); 309 454 310 455 # lang list … … 326 471 echo 327 472 '<form action="posts_actions.php" method="post">'. 473 $fields->getEntries(). 474 328 475 '<p><label for="new_lang" class="classic">'.__('Entry lang:').'</label> '. 329 476 form::combo('new_lang',$lang_combo,''); 330 477 331 478 echo 332 $ hidden_fields.479 $fields->getHidden(). 333 480 $core->formNonce(). 334 481 form::hidden(array('action'),'lang'). … … 339 486 elseif ($action == 'author' && $core->auth->check('admin',$core->blog->id)) 340 487 { 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 )); 342 494 343 495 echo 344 496 '<form action="posts_actions.php" method="post">'. 497 $fields->getEntries(). 345 498 '<p><label for="new_auth_id" class="classic">'.__('Author ID:').'</label> '. 346 499 form::field('new_auth_id',20,255); 347 500 348 501 echo 349 $ hidden_fields.502 $fields->getHidden(). 350 503 $core->formNonce(). 351 504 form::hidden(array('action'),'author'). -
admin/posts_actions.php
r1472 r1473 243 243 elseif ($action == 'category' && isset($_POST['new_cat_id'])) 244 244 { 245 $new_cat_id = $_POST['new_cat_id']; 246 245 247 try 246 248 { 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); 248 267 249 268 http::redirect($redir); … … 387 406 # categories list 388 407 # Getting categories 389 $categories_combo = array( ' '=> '');408 $categories_combo = array(__('(No cat)') => ''); 390 409 try { 391 410 $categories = $core->blog->getCategories(array('post_type'=>'post')); 411 if (!$categories->isEmpty()) { 392 412 while ($categories->fetch()) { 393 $categories_combo[] = new formSelectOption( 394 str_repeat(' ',$categories->level-1). 395 ($categories->level-1 == 0 ? '' : '• ').html::escapeHTML($categories->cat_title), 413 $catparents_combo[] = $categories_combo[] = new formSelectOption( 414 str_repeat(' ',$categories->level-1).($categories->level-1 == 0 ? '' : '• ').html::escapeHTML($categories->cat_title), 396 415 $categories->cat_id 397 416 ); 417 } 398 418 } 399 419 } catch (Exception $e) { } … … 402 422 '<form action="posts_actions.php" method="post">'. 403 423 $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 } 407 438 408 439 echo … … 440 471 echo 441 472 '<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,''); 446 477 447 478 echo … … 465 496 '<form action="posts_actions.php" method="post">'. 466 497 $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); 470 500 471 501 echo
Note: See TracChangeset
for help on using the changeset viewer.