Changeset 992:bbe8a306df16 for admin
- Timestamp:
- 11/12/12 12:46:57 (13 years ago)
- Branch:
- twig
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
admin/post.php
r957 r992 14 14 15 15 dcPage::check('usage,contentadmin'); 16 17 $post_id = '';18 $cat_id = '';19 $post_dt = '';20 $post_format = $core->auth->getOption('post_format');21 $post_password = '';22 $post_url = '';23 $post_lang = $core->auth->getInfo('user_lang');24 $post_title = '';25 $post_excerpt = '';26 $post_excerpt_xhtml = '';27 $post_content = '';28 $post_content_xhtml = '';29 $post_notes = '';30 $post_status = $core->auth->getInfo('user_post_status');31 $post_selected = false;32 $post_open_comment = $core->blog->settings->system->allow_comments;33 $post_open_tb = $core->blog->settings->system->allow_trackbacks;34 35 16 $page_title = __('New entry'); 36 17 … … 47 28 # If user can't publish 48 29 if (!$can_publish) { 49 $ post_status = -2;30 $form->post_status = -2; 50 31 } 51 32 … … 55 36 $categories = $core->blog->getCategories(array('post_type'=>'post')); 56 37 while ($categories->fetch()) { 57 $categories_combo[ ] = new formSelectOption(58 str_repeat(' ',$categories->level-1). ($categories->level-1 == 0 ? '' : '• ').html::escapeHTML($categories->cat_title),59 $categories->cat_id60 );38 $categories_combo[$categories->cat_id] = 39 str_repeat(' ',$categories->level-1). 40 ($categories->level-1 == 0 ? '' : '• '). 41 html::escapeHTML($categories->cat_title);; 61 42 } 62 43 } catch (Exception $e) { } … … 64 45 # Status combo 65 46 foreach ($core->blog->getAllPostStatus() as $k => $v) { 66 $status_combo[$v] = (string) $k; 67 } 68 $img_status_pattern = '<img class="img_select_option" alt="%1$s" title="%1$s" src="images/%2$s" />'; 47 $status_combo[$k] = $v; 48 } 69 49 70 50 # Formaters combo … … 88 68 unset($rs); 89 69 90 # Validation flag 91 $bad_dt = false; 70 71 72 $page = new dcAdminPage($core); 73 74 $form = new dcForm($core,'post','post.php'); 75 $form 76 ->addField( 77 new dcFieldText('post_title','', array( 78 'size' => 20, 79 'required' => true, 80 'label' => __('Title')))) 81 ->addField( 82 new dcFieldTextArea('post_excerpt','', array( 83 'cols' => 50, 84 'rows' => 5, 85 'label' => __("Excerpt:")))) 86 ->addField( 87 new dcFieldTextArea('post_content','', array( 88 'required' => true, 89 'label' => __("Content:")))) 90 ->addField( 91 new dcFieldTextArea('post_notes','', array( 92 'label' => __("Notes")))) 93 ->addField( 94 new dcFieldSubmit('save',__('Save'),array())) 95 ->addField( 96 new dcFieldCombo('post_status',$core->auth->getInfo('user_post_status'),$status_combo,array( 97 'disabled' => !$can_publish, 98 'label' => __('Entry status:')))) 99 ->addField( 100 new dcFieldCombo('cat_id','',$categories_combo,array( 101 "label" => __('Category:')))) 102 ->addField( 103 new dcFieldText('post_dt','',array( 104 "label" => __('Published on:')))) 105 ->addField( 106 new dcFieldCombo('post_format',$core->auth->getOption('post_format'),$formaters_combo,array( 107 "label" => __('Text formating:')))) 108 ->addField( 109 new dcFieldCheckbox ('post_open_comment',$core->blog->settings->system->allow_comments,array( 110 "label" => __('Accept comments')))) 111 ->addField( 112 new dcFieldCheckbox ('post_open_tb',$core->blog->settings->system->allow_trackbacks,array( 113 "label" => __('Accept trackbacks')))) 114 ->addField( 115 new dcFieldCheckbox ('post_selected',false,array( 116 "label" => __('Selected entry')))) 117 ->addField( 118 new dcFieldCombo ('post_lang',$core->auth->getInfo('user_lang'),$lang_combo, array( 119 "label" => __('Entry lang:')))) 120 ; 121 92 122 93 123 # Get entry informations … … 105 135 else 106 136 { 107 $ post_id = $post->post_id;108 $ cat_id = $post->cat_id;109 $ post_dt = date('Y-m-d H:i',strtotime($post->post_dt));110 $ post_format = $post->post_format;111 $ post_password = $post->post_password;112 $ post_url = $post->post_url;113 $ post_lang = $post->post_lang;114 $ post_title = $post->post_title;115 $ post_excerpt = $post->post_excerpt;137 $form->post_id = $post->post_id; 138 $form->cat_id = $post->cat_id; 139 $form->post_dt = date('Y-m-d H:i',strtotime($post->post_dt)); 140 $form->post_format = $post->post_format; 141 $form->post_password = $post->post_password; 142 $form->post_url = $post->post_url; 143 $form->post_lang = $post->post_lang; 144 $form->post_title = $post->post_title; 145 $form->post_excerpt = $post->post_excerpt; 116 146 $post_excerpt_xhtml = $post->post_excerpt_xhtml; 117 $ post_content = $post->post_content;147 $form->post_content = $post->post_content; 118 148 $post_content_xhtml = $post->post_content_xhtml; 119 $ post_notes = $post->post_notes;120 $ post_status = $post->post_status;121 $ post_selected = (boolean) $post->post_selected;122 $ post_open_comment = (boolean) $post->post_open_comment;123 $ post_open_tb = (boolean) $post->post_open_tb;149 $form->post_notes = $post->post_notes; 150 $form->post_status = $post->post_status; 151 $form->post_selected = (boolean) $post->post_selected; 152 $form->post_open_comment = (boolean) $post->post_open_comment; 153 $form->post_open_tb = (boolean) $post->post_open_tb; 124 154 125 155 $page_title = __('Edit entry'); … … 169 199 $post_dt = ''; 170 200 } else { 171 try 172 { 173 $post_dt = strtotime($_POST['post_dt']); 174 if ($post_dt == false || $post_dt == -1) { 175 $bad_dt = true; 176 throw new Exception(__('Invalid publication date')); 177 } 178 $post_dt = date('Y-m-d H:i',$post_dt); 179 } 180 catch (Exception $e) 181 { 182 $core->error->add($e->getMessage()); 183 } 201 $post_dt = strtotime($_POST['post_dt']); 202 $post_dt = date('Y-m-d H:i',$post_dt); 184 203 } 185 204 … … 203 222 204 223 # Create or update post 205 if (!empty($_POST) && !empty($_POST['save']) && $can_edit_post && !$bad_dt)224 if (!empty($_POST) && !empty($_POST['save']) && $can_edit_post) 206 225 { 207 226 $cur = $core->con->openCursor($core->prefix.'post'); … … 293 312 } 294 313 295 dcPage::open($page_title.' - '.__('Entries'), 296 dcPage::jsDatePicker(). 297 dcPage::jsToolBar(). 298 dcPage::jsModal(). 299 dcPage::jsMetaEditor(). 300 dcPage::jsLoad('js/_post.js'). 301 dcPage::jsConfirmClose('entry-form','comment-form'). 302 # --BEHAVIOR-- adminPostHeaders 303 $core->callBehavior('adminPostHeaders'). 304 dcPage::jsPageTabs($default_tab). 305 $next_headlink."\n".$prev_headlink 306 ); 307 308 if (!empty($_GET['upd'])) { 309 dcPage::message(__('Entry has been successfully updated.')); 310 } 311 elseif (!empty($_GET['crea'])) { 312 dcPage::message(__('Entry has been successfully created.')); 313 } 314 elseif (!empty($_GET['attached'])) { 315 dcPage::message(__('File has been successfully attached.')); 316 } 317 elseif (!empty($_GET['rmattach'])) { 318 dcPage::message(__('Attachment has been successfully removed.')); 319 } 320 321 if (!empty($_GET['creaco'])) { 322 dcPage::message(__('Comment has been successfully created.')); 323 } 324 325 # XHTML conversion 326 if (!empty($_GET['xconv'])) 327 { 328 $post_excerpt = $post_excerpt_xhtml; 329 $post_content = $post_content_xhtml; 330 $post_format = 'xhtml'; 331 332 dcPage::message(__('Don\'t forget to validate your XHTML conversion by saving your post.')); 333 } 334 335 echo '<h2>'.html::escapeHTML($core->blog->name).' › '.'<a href="posts.php">'.__('Entries').'</a> › <span class="page-title">'.$page_title; 336 if ($post_id) { 337 switch ($post_status) { 338 case 1: 339 $img_status = sprintf($img_status_pattern,__('published'),'check-on.png'); 340 break; 341 case 0: 342 $img_status = sprintf($img_status_pattern,__('unpublished'),'check-off.png'); 343 break; 344 case -1: 345 $img_status = sprintf($img_status_pattern,__('scheduled'),'scheduled.png'); 346 break; 347 case -2: 348 $img_status = sprintf($img_status_pattern,__('pending'),'check-wrn.png'); 349 break; 350 default: 351 $img_status = ''; 352 } 353 echo ' “'.$post_title.'”'.' '.$img_status; 354 } 355 echo '</span></h2>'; 356 357 if ($post_id && $post->post_status == 1) { 358 echo '<p><a href="'.$post->getURL().'" onclick="window.open(this.href);return false;" title="'.$post_title.' ('.__('new window').')'.'">'.__('Go to this entry on the site').' <img src="images/outgoing-blue.png" alt="" /></a></p>'; 359 } 360 if ($post_id) 361 { 362 echo '<p>'; 363 if ($prev_link) { echo $prev_link; } 364 if ($next_link && $prev_link) { echo ' - '; } 365 if ($next_link) { echo $next_link; } 366 367 # --BEHAVIOR-- adminPostNavLinks 368 $core->callBehavior('adminPostNavLinks',isset($post) ? $post : null); 369 370 echo '</p>'; 371 } 372 373 # Exit if we cannot view page 374 if (!$can_view_page) { 375 dcPage::helpBlock('core_post'); 376 dcPage::close(); 377 exit; 378 } 379 380 /* Post form if we can edit post 381 -------------------------------------------------------- */ 382 if ($can_edit_post) 383 { 384 echo '<div class="multi-part" title="'.__('Edit entry').'" id="edit-entry">'; 385 echo '<form action="post.php" method="post" id="entry-form">'; 386 echo '<div id="entry-wrapper">'; 387 echo '<div id="entry-content"><div class="constrained">'; 388 389 echo 390 '<p class="col"><label class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:'). 391 form::field('post_title',20,255,html::escapeHTML($post_title),'maximal'). 392 '</label></p>'. 393 394 '<p class="area" id="excerpt-area"><label for="post_excerpt">'.__('Excerpt:').'</label> '. 395 form::textarea('post_excerpt',50,5,html::escapeHTML($post_excerpt)). 396 '</p>'. 397 398 '<p class="area"><label class="required" '. 399 'for="post_content"><abbr title="'.__('Required field').'">*</abbr> '.__('Content:').'</label> '. 400 form::textarea('post_content',50,$core->auth->getOption('edit_size'),html::escapeHTML($post_content)). 401 '</p>'. 402 403 '<p class="area" id="notes-area"><label for="post_notes">'.__('Notes:').'</label>'. 404 form::textarea('post_notes',50,5,html::escapeHTML($post_notes)). 405 '</p>'; 406 407 # --BEHAVIOR-- adminPostForm 408 $core->callBehavior('adminPostForm',isset($post) ? $post : null); 409 410 echo 411 '<p>'. 412 ($post_id ? form::hidden('id',$post_id) : ''). 413 '<input type="submit" value="'.__('Save').' (s)" '. 414 'accesskey="s" name="save" /> '; 415 if ($post_id) { 416 $preview_url = 417 $core->blog->url.$core->url->getURLFor('preview',$core->auth->userID().'/'. 418 http::browserUID(DC_MASTER_KEY.$core->auth->userID().$core->auth->getInfo('user_pwd')). 419 '/'.$post->post_url); 420 echo '<a id="post-preview" href="'.$preview_url.'" class="button">'.__('Preview').'</a> '; 421 } 422 echo 423 ($can_delete ? '<input type="submit" class="delete" value="'.__('Delete').'" name="delete" />' : ''). 424 $core->formNonce(). 425 '</p>'; 426 427 echo '</div></div>'; // End #entry-content 428 echo '</div>'; // End #entry-wrapper 429 430 echo '<div id="entry-sidebar">'; 431 432 echo 433 '<p><label for="cat_id">'.__('Category:'). 434 form::combo('cat_id',$categories_combo,$cat_id,'maximal'). 435 '</label></p>'. 436 437 '<p><label for="post_status">'.__('Entry status:'). 438 form::combo('post_status',$status_combo,$post_status,'','',!$can_publish). 439 '</label></p>'. 440 441 '<p><label for="post_dt">'.__('Published on:'). 442 form::field('post_dt',16,16,$post_dt,($bad_dt ? 'invalid' : '')). 443 '</label></p>'. 444 445 '<p><label for="post_format">'.__('Text formating:'). 446 form::combo('post_format',$formaters_combo,$post_format). 447 '</label>'. 448 '</p>'. 449 '<p>'.($post_id && $post_format != 'xhtml' ? '<a id="convert-xhtml" class="button" href="post.php?id='.$post_id.'&xconv=1">'.__('Convert to XHTML').'</a>' : '').'</p>'. 450 451 '<p><label for="post_open_comment" class="classic">'.form::checkbox('post_open_comment',1,$post_open_comment).' '. 452 __('Accept comments').'</label></p>'. 453 ($core->blog->settings->system->allow_comments ? 454 (isContributionAllowed($post_id,strtotime($post_dt),true) ? 455 '' : 456 '<p class="form-note warn">'.__('Warning: Comments are not more accepted for this entry.').'</p>') : 457 '<p class="form-note warn">'.__('Warning: Comments are not accepted on this blog.').'</p>'). 458 459 '<p><label for="post_open_tb" class="classic">'.form::checkbox('post_open_tb',1,$post_open_tb).' '. 460 __('Accept trackbacks').'</label></p>'. 461 ($core->blog->settings->system->allow_trackbacks ? 462 (isContributionAllowed($post_id,strtotime($post_dt),false) ? 463 '' : 464 '<p class="form-note warn">'.__('Warning: Trackbacks are not more accepted for this entry.').'</p>') : 465 '<p class="form-note warn">'.__('Warning: Trackbacks are not accepted on this blog.').'</p>'). 466 467 '<p><label for="post_selected" class="classic">'.form::checkbox('post_selected',1,$post_selected).' '. 468 __('Selected entry').'</label></p>'. 469 470 '<p><label for="post_lang">'.__('Entry lang:'). 471 form::combo('post_lang',$lang_combo,$post_lang). 472 '</label></p>'. 473 474 '<p><label for="post_password">'.__('Entry password:'). 475 form::field('post_password',10,32,html::escapeHTML($post_password),'maximal'). 476 '</label></p>'. 477 478 '<div class="lockable">'. 479 '<p><label for="post_url">'.__('Basename:'). 480 form::field('post_url',10,255,html::escapeHTML($post_url),'maximal'). 481 '</label></p>'. 482 '<p class="form-note warn">'. 483 __('Warning: If you set the URL manually, it may conflict with another entry.'). 484 '</p>'. 485 '</div>'; 486 487 # --BEHAVIOR-- adminPostFormSidebar 488 $core->callBehavior('adminPostFormSidebar',isset($post) ? $post : null); 489 490 echo '</div>'; // End #entry-sidebar 491 492 echo '</form>'; 493 494 # --BEHAVIOR-- adminPostForm 495 $core->callBehavior('adminPostAfterForm',isset($post) ? $post : null); 496 497 echo '</div>'; 498 499 if ($post_id && $post->post_status == 1) { 500 echo '<p><a href="trackbacks.php?id='.$post_id.'" class="multi-part">'. 501 __('Ping blogs').'</a></p>'; 502 } 503 504 } 505 506 507 /* Comments and trackbacks 508 -------------------------------------------------------- */ 509 if ($post_id) 510 { 511 $params = array('post_id' => $post_id, 'order' => 'comment_dt ASC'); 512 513 $comments = $core->blog->getComments(array_merge($params,array('comment_trackback'=>0))); 514 $trackbacks = $core->blog->getComments(array_merge($params,array('comment_trackback'=>1))); 515 516 # Actions combo box 517 $combo_action = array(); 518 if ($can_edit_post && $core->auth->check('publish,contentadmin',$core->blog->id)) 519 { 520 $combo_action[__('publish')] = 'publish'; 521 $combo_action[__('unpublish')] = 'unpublish'; 522 $combo_action[__('mark as pending')] = 'pending'; 523 $combo_action[__('mark as junk')] = 'junk'; 524 } 525 526 if ($can_edit_post && $core->auth->check('delete,contentadmin',$core->blog->id)) 527 { 528 $combo_action[__('Delete')] = 'delete'; 529 } 530 531 # --BEHAVIOR-- adminCommentsActionsCombo 532 $core->callBehavior('adminCommentsActionsCombo',array(&$combo_action)); 533 534 $has_action = !empty($combo_action) && (!$trackbacks->isEmpty() || !$comments->isEmpty()); 535 536 echo 537 '<div id="comments" class="multi-part" title="'.__('Comments').'">'; 538 539 if ($has_action) { 540 echo '<form action="comments_actions.php" id="form-comments" method="post">'; 541 } 542 543 echo '<h3>'.__('Trackbacks').'</h3>'; 544 545 if (!$trackbacks->isEmpty()) { 546 showComments($trackbacks,$has_action,true); 547 } else { 548 echo '<p>'.__('No trackback').'</p>'; 549 } 550 551 echo '<h3>'.__('Comments').'</h3>'; 552 if (!$comments->isEmpty()) { 553 showComments($comments,$has_action); 554 } else { 555 echo '<p>'.__('No comment').'</p>'; 556 } 557 558 if ($has_action) { 559 echo 560 '<div class="two-cols">'. 561 '<p class="col checkboxes-helpers"></p>'. 562 563 '<p class="col right"><label for="action" class="classic">'.__('Selected comments action:').'</label> '. 564 form::combo('action',$combo_action). 565 form::hidden('redir','post.php?id='.$post_id.'&co=1'). 566 $core->formNonce(). 567 '<input type="submit" value="'.__('ok').'" /></p>'. 568 '</div>'. 569 '</form>'; 570 } 571 572 echo '</div>'; 573 } 574 575 /* Add a comment 576 -------------------------------------------------------- */ 577 if ($post_id) 578 { 579 echo 580 '<div class="multi-part" id="add-comment" title="'.__('Add a comment').'">'. 581 '<h3>'.__('Add a comment').'</h3>'. 582 583 '<form action="comment.php" method="post" id="comment-form">'. 584 '<div class="constrained">'. 585 '<p><label for="comment_author" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Name:'). 586 form::field('comment_author',30,255,html::escapeHTML($core->auth->getInfo('user_cn'))). 587 '</label></p>'. 588 589 '<p><label for="comment_email">'.__('Email:'). 590 form::field('comment_email',30,255,html::escapeHTML($core->auth->getInfo('user_email'))). 591 '</label></p>'. 592 593 '<p><label for="comment_site">'.__('Web site:'). 594 form::field('comment_site',30,255,html::escapeHTML($core->auth->getInfo('user_url'))). 595 '</label></p>'. 596 597 '<p class="area"><label for="comment_content" class="required"><abbr title="'.__('Required field').'">*</abbr> '. 598 __('Comment:').'</label> '. 599 form::textarea('comment_content',50,8,html::escapeHTML('')). 600 '</p>'. 601 602 '<p>'.form::hidden('post_id',$post_id). 603 $core->formNonce(). 604 '<input type="submit" name="add" value="'.__('Save').'" /></p>'. 605 '</div>'. 606 '</form>'. 607 '</div>'; 608 } 609 610 # Controls comments or trakbacks capabilities 611 function isContributionAllowed($id,$dt,$com=true) 612 { 613 global $core; 614 615 if (!$id) { 616 return true; 617 } 618 if ($com) { 619 if (($core->blog->settings->system->comments_ttl == 0) || 620 (time() - $core->blog->settings->system->comments_ttl*86400 < $dt)) { 621 return true; 622 } 623 } else { 624 if (($core->blog->settings->system->trackbacks_ttl == 0) || 625 (time() - $core->blog->settings->system->trackbacks_ttl*86400 < $dt)) { 626 return true; 627 } 628 } 629 return false; 630 } 631 632 # Show comments or trackbacks 633 function showComments($rs,$has_action,$tb=false) 634 { 635 echo 636 '<table class="comments-list"><tr>'. 637 '<th colspan="2">'.__('Author').'</th>'. 638 '<th>'.__('Date').'</th>'. 639 '<th class="nowrap">'.__('IP address').'</th>'. 640 '<th>'.__('Status').'</th>'. 641 '<th> </th>'. 642 '</tr>'; 643 644 while($rs->fetch()) 645 { 646 $comment_url = 'comment.php?id='.$rs->comment_id; 647 648 $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; 649 switch ($rs->comment_status) { 650 case 1: 651 $img_status = sprintf($img,__('published'),'check-on.png'); 652 break; 653 case 0: 654 $img_status = sprintf($img,__('unpublished'),'check-off.png'); 655 break; 656 case -1: 657 $img_status = sprintf($img,__('pending'),'check-wrn.png'); 658 break; 659 case -2: 660 $img_status = sprintf($img,__('junk'),'junk.png'); 661 break; 662 } 663 664 echo 665 '<tr class="line'.($rs->comment_status != 1 ? ' offline' : '').'"'. 666 ' id="c'.$rs->comment_id.'">'. 667 668 '<td class="nowrap">'. 669 ($has_action ? form::checkbox(array('comments[]'),$rs->comment_id,'','','',0,'title="'.($tb ? __('select this trackback') : __('select this comment')).'"') : '').'</td>'. 670 '<td class="maximal">'.html::escapeHTML($rs->comment_author).'</td>'. 671 '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$rs->comment_dt).'</td>'. 672 '<td class="nowrap"><a href="comments.php?ip='.$rs->comment_ip.'">'.$rs->comment_ip.'</a></td>'. 673 '<td class="nowrap status">'.$img_status.'</td>'. 674 '<td class="nowrap status"><a href="'.$comment_url.'">'. 675 '<img src="images/edit-mini.png" alt="" title="'.__('Edit this comment').'" /></a></td>'. 676 677 '</tr>'; 678 } 679 680 echo '</table>'; 681 } 682 683 dcPage::helpBlock('core_post','core_wiki'); 684 dcPage::close(); 314 $ctx = $page->getContext(); 315 $ctx 316 ->jsDatePicker() 317 ->jsToolBar() 318 ->jsModal() 319 ->jsMetaEditor() 320 ->jsLoad('js/_post.js') 321 ->jsPageTabs($default_tab) 322 ->jsConfirmClose('entry-form','comment-form'); 323 324 echo $page->render('post.html.twig',array( 325 'edit_size'=> $core->auth->getOption('edit_size'))); 685 326 ?>
Note: See TracChangeset
for help on using the changeset viewer.