[ Index ] |
PHP Cross Reference of Textpattern 4.0.8 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 This is Textpattern 4 Copyright 2005 by Dean Allen 5 All rights reserved. 6 7 Use of this software indicates acceptance of the Textpattern license agreement 8 9 $HeadURL: https://textpattern.googlecode.com/svn/releases/4.0.8/source/textpattern/include/txp_article.php $ 10 $LastChangedRevision: 3040 $ 11 12 */ 13 14 if (!defined('txpinterface')) die('txpinterface is undefined.'); 15 16 global $vars, $statuses; 17 18 $vars = array( 19 'ID','Title','Title_html','Body','Body_html','Excerpt','textile_excerpt','Image', 20 'textile_body', 'Keywords','Status','Posted','Expires','Section','Category1','Category2', 21 'Annotate','AnnotateInvite','publish_now','reset_time','AuthorID','sPosted', 22 'LastModID','sLastMod','override_form','from_view','year','month','day','hour', 23 'minute','second','url_title','custom_1','custom_2','custom_3','custom_4','custom_5', 24 'custom_6','custom_7','custom_8','custom_9','custom_10','exp_year','exp_month','exp_day','exp_hour', 25 'exp_minute','exp_second','sExpires' 26 ); 27 28 $statuses = array( 29 1 => gTxt('draft'), 30 2 => gTxt('hidden'), 31 3 => gTxt('pending'), 32 4 => strong(gTxt('live')), 33 5 => gTxt('sticky'), 34 ); 35 36 if (!empty($event) and $event == 'article') { 37 require_privs('article'); 38 39 40 $save = gps('save'); 41 if ($save) $step = 'save'; 42 43 $publish = gps('publish'); 44 if ($publish) $step = 'publish'; 45 46 47 switch(strtolower($step)) { 48 case "": article_edit(); break; 49 case "create": article_edit(); break; 50 case "publish": article_post(); break; 51 case "edit": article_edit(); break; 52 case "save": article_save(); break; 53 } 54 } 55 56 //-------------------------------------------------------------- 57 58 function article_post() 59 { 60 global $txp_user, $vars, $txpcfg, $prefs; 61 62 extract($prefs); 63 64 $incoming = psa($vars); 65 $message=''; 66 67 $incoming = textile_main_fields($incoming, $use_textile); 68 69 extract(doSlash($incoming)); 70 71 extract(array_map('assert_int', psa(array( 'Status', 'textile_body', 'textile_excerpt')))); 72 73 $Annotate = (int) $Annotate; 74 75 if ($publish_now==1) { 76 $when = 'now()'; 77 $when_ts = time(); 78 } else { 79 $when = $when_ts = strtotime($year.'-'.$month.'-'.$day.' '.$hour.':'.$minute.':'.$second)-tz_offset(); 80 $when = "from_unixtime($when)"; 81 } 82 83 $Keywords = doSlash(trim(preg_replace('/( ?[\r\n\t,])+ ?/s', ',', preg_replace('/ +/', ' ', ps('Keywords'))), ', ')); 84 85 if (empty($exp_year)) { 86 $expires = 0; 87 $whenexpires = NULLDATETIME; 88 } 89 else { 90 if(empty($exp_month)) $exp_month=1; 91 if(empty($exp_day)) $exp_day=1; 92 if(empty($exp_hour)) $exp_hour=0; 93 if(empty($exp_minute)) $exp_minute=0; 94 if(empty($exp_second)) $exp_second=0; 95 96 $expires = strtotime($exp_year.'-'.$exp_month.'-'.$exp_day.' '. 97 $exp_hour.':'.$exp_minute.':'.$exp_second)-tz_offset(); 98 $whenexpires = "from_unixtime($expires)"; 99 } 100 101 if ($expires) { 102 if ($expires <= $when_ts) { 103 article_edit(gTxt('article_expires_before_postdate')); 104 return; 105 } 106 } 107 108 if ($Title or $Body or $Excerpt) { 109 110 if (!has_privs('article.publish') && $Status>=4) $Status = 3; 111 if (empty($url_title)) $url_title = stripSpace($Title_plain, 1); 112 113 safe_insert( 114 "textpattern", 115 "Title = '$Title', 116 Body = '$Body', 117 Body_html = '$Body_html', 118 Excerpt = '$Excerpt', 119 Excerpt_html = '$Excerpt_html', 120 Image = '$Image', 121 Keywords = '$Keywords', 122 Status = $Status, 123 Posted = $when, 124 Expires = $whenexpires, 125 LastMod = now(), 126 AuthorID = '$txp_user', 127 Section = '$Section', 128 Category1 = '$Category1', 129 Category2 = '$Category2', 130 textile_body = $textile_body, 131 textile_excerpt = $textile_excerpt, 132 Annotate = $Annotate, 133 override_form = '$override_form', 134 url_title = '$url_title', 135 AnnotateInvite = '$AnnotateInvite', 136 custom_1 = '$custom_1', 137 custom_2 = '$custom_2', 138 custom_3 = '$custom_3', 139 custom_4 = '$custom_4', 140 custom_5 = '$custom_5', 141 custom_6 = '$custom_6', 142 custom_7 = '$custom_7', 143 custom_8 = '$custom_8', 144 custom_9 = '$custom_9', 145 custom_10 = '$custom_10', 146 uid = '".md5(uniqid(rand(),true))."', 147 feed_time = now()" 148 ); 149 150 $GLOBALS['ID'] = mysql_insert_id(); 151 152 if ($Status>=4) { 153 154 do_pings(); 155 156 update_lastmod(); 157 } 158 article_edit( 159 get_status_message($Status).check_url_title($url_title) 160 ); 161 } else article_edit(); 162 } 163 164 //-------------------------------------------------------------- 165 166 function article_save() 167 { 168 global $txp_user, $vars, $txpcfg, $prefs; 169 170 extract($prefs); 171 172 $incoming = psa($vars); 173 174 $oldArticle = safe_row('Status, url_title, Title, unix_timestamp(LastMod) as sLastMod, LastModID','textpattern','ID = '.(int)$incoming['ID']); 175 176 if (! ( ($oldArticle['Status'] >= 4 and has_privs('article.edit.published')) 177 or ($oldArticle['Status'] >= 4 and $incoming['AuthorID']==$txp_user and has_privs('article.edit.own.published')) 178 or ($oldArticle['Status'] < 4 and has_privs('article.edit')) 179 or ($oldArticle['Status'] < 4 and $incoming['AuthorID']==$txp_user and has_privs('article.edit.own')))) 180 { 181 // Not allowed, you silly rabbit, you shouldn't even be here. 182 // Show default editing screen. 183 article_edit(); 184 return; 185 } 186 187 if ($oldArticle['sLastMod'] != $incoming['sLastMod']) 188 { 189 article_edit(gTxt('concurrent_edit_by', array('{author}' => htmlspecialchars($oldArticle['LastModID']))), TRUE); 190 return; 191 } 192 193 $incoming = textile_main_fields($incoming, $use_textile); 194 195 extract(doSlash($incoming)); 196 extract(array_map('assert_int', psa(array('ID', 'Status', 'textile_body', 'textile_excerpt')))); 197 198 $Annotate = (int) $Annotate; 199 200 if (!has_privs('article.publish') && $Status>=4) $Status = 3; 201 202 if($reset_time) { 203 $whenposted = "Posted=now()"; 204 $when_ts = time(); 205 } else { 206 $when = $when_ts = strtotime($year.'-'.$month.'-'.$day.' '.$hour.':'.$minute.':'.$second)-tz_offset(); 207 $whenposted = "Posted=from_unixtime($when)"; 208 } 209 210 if (empty($exp_year)) { 211 $expires = 0; 212 $whenexpires = "Expires=".NULLDATETIME; 213 } else { 214 if(empty($exp_month)) $exp_month=1; 215 if(empty($exp_day)) $exp_day=1; 216 if(empty($exp_hour)) $exp_hour=0; 217 if(empty($exp_minute)) $exp_minute=0; 218 if(empty($exp_second)) $exp_second=0; 219 220 $expires = strtotime($exp_year.'-'.$exp_month.'-'.$exp_day.' '.$exp_hour.':'.$exp_minute.':'.$exp_second)-tz_offset(); 221 $whenexpires = "Expires=from_unixtime($expires)"; 222 } 223 224 if ($expires) { 225 if ($expires <= $when_ts) { 226 article_edit(gTxt('article_expires_before_postdate')); 227 return; 228 } 229 } 230 231 //Auto-Update custom-titles according to Title, as long as unpublished and NOT customized 232 if ( empty($url_title) 233 || ( ($oldArticle['Status'] < 4) 234 && ($oldArticle['url_title'] == $url_title ) 235 && ($oldArticle['url_title'] == stripSpace($oldArticle['Title'],1)) 236 && ($oldArticle['Title'] != $Title) 237 ) 238 ) 239 { 240 $url_title = stripSpace($Title_plain, 1); 241 } 242 243 $Keywords = doSlash(trim(preg_replace('/( ?[\r\n\t,])+ ?/s', ',', preg_replace('/ +/', ' ', ps('Keywords'))), ', ')); 244 245 safe_update("textpattern", 246 "Title = '$Title', 247 Body = '$Body', 248 Body_html = '$Body_html', 249 Excerpt = '$Excerpt', 250 Excerpt_html = '$Excerpt_html', 251 Keywords = '$Keywords', 252 Image = '$Image', 253 Status = $Status, 254 LastMod = now(), 255 LastModID = '$txp_user', 256 Section = '$Section', 257 Category1 = '$Category1', 258 Category2 = '$Category2', 259 Annotate = $Annotate, 260 textile_body = $textile_body, 261 textile_excerpt = $textile_excerpt, 262 override_form = '$override_form', 263 url_title = '$url_title', 264 AnnotateInvite = '$AnnotateInvite', 265 custom_1 = '$custom_1', 266 custom_2 = '$custom_2', 267 custom_3 = '$custom_3', 268 custom_4 = '$custom_4', 269 custom_5 = '$custom_5', 270 custom_6 = '$custom_6', 271 custom_7 = '$custom_7', 272 custom_8 = '$custom_8', 273 custom_9 = '$custom_9', 274 custom_10 = '$custom_10', 275 $whenposted, 276 $whenexpires", 277 "ID = $ID" 278 ); 279 280 if($Status >= 4) { 281 if ($oldArticle['Status'] < 4) { 282 do_pings(); 283 } 284 update_lastmod(); 285 } 286 287 article_edit( 288 get_status_message($Status).check_url_title($url_title) 289 ); 290 291 } 292 293 //-------------------------------------------------------------- 294 295 function article_edit($message = '', $concurrent = FALSE) 296 { 297 global $vars, $txp_user, $comments_disabled_after, $txpcfg, $prefs; 298 299 extract($prefs); 300 301 extract(gpsa(array('view','from_view','step'))); 302 303 if(!empty($GLOBALS['ID'])) { // newly-saved article 304 $ID = $GLOBALS['ID']; 305 $step = 'edit'; 306 } else { 307 $ID = gps('ID'); 308 } 309 310 include_once txpath.'/lib/classTextile.php'; 311 $textile = new Textile(); 312 313 // switch to 'text' view upon page load and after article post 314 if(!$view || gps('save') || gps('publish')) { 315 $view = 'text'; 316 } 317 318 if (!$step) $step = "create"; 319 320 if ($step == "edit" 321 && $view=="text" 322 && !empty($ID) 323 && $from_view != 'preview' 324 && $from_view != 'html' 325 && !$concurrent) 326 { 327 $pull = true; //-- it's an existing article - off we go to the db 328 $ID = assert_int($ID); 329 330 $rs = safe_row( 331 "*, unix_timestamp(Posted) as sPosted, 332 unix_timestamp(Expires) as sExpires, 333 unix_timestamp(LastMod) as sLastMod", 334 "textpattern", 335 "ID=$ID" 336 ); 337 338 extract($rs); 339 $reset_time = $publish_now = ($Status < 4); 340 341 } else { 342 343 $pull = false; //-- assume they came from post 344 345 if ($from_view=='preview' or $from_view=='html') 346 { 347 $store_out = array(); 348 $store = unserialize(base64_decode(ps('store'))); 349 350 foreach($vars as $var) 351 { 352 if (isset($store[$var])) $store_out[$var] = $store[$var]; 353 } 354 } 355 356 else 357 { 358 $store_out = gpsa($vars); 359 360 if ($concurrent) 361 { 362 $store_out['sLastMod'] = safe_field('unix_timestamp(LastMod) as sLastMod', 'textpattern', 'ID='.$ID); 363 } 364 } 365 366 extract($store_out); 367 } 368 369 $GLOBALS['step'] = $step; 370 371 if ($step == 'create') 372 { 373 $textile_body = $use_textile; 374 $textile_excerpt = $use_textile; 375 376 } 377 378 if ($step!='create') { 379 380 // Previous record? 381 $prev_id = checkIfNeighbour('prev',$sPosted); 382 383 // Next record? 384 $next_id = checkIfNeighbour('next',$sPosted); 385 } 386 387 $page_title = ($Title) ? $Title : gTxt('write'); 388 389 pagetop($page_title, $message); 390 391 echo n.n.'<form name="article" method="post" action="index.php">'; 392 393 if (!empty($store_out)) 394 { 395 echo hInput('store', base64_encode(serialize($store_out))); 396 } 397 398 echo hInput('ID', $ID). 399 eInput('article'). 400 sInput($step). 401 '<input type="hidden" name="view" />'. 402 403 startTable('edit'). 404 405 '<tr>'.n. 406 '<td id="article-col-1">'; 407 408 if ($view == 'text') 409 { 410 411 //-- markup help -------------- 412 413 echo side_help($textile_body, $textile_excerpt). 414 415 '<h3 class="plain"><a href="#advanced" onclick="toggleDisplay(\'advanced\'); return false;">'.gTxt('advanced_options').'</a></h3>', 416 '<div id="advanced" class="toggle" style="display:none">', 417 418 // markup selection 419 n.graf('<label for="markup-body">'.gTxt('article_markup').'</label>'.br. 420 pref_text('textile_body', $textile_body, 'markup-body')), 421 422 n.graf('<label for="markup-excerpt">'.gTxt('excerpt_markup').'</label>'.br. 423 pref_text('textile_excerpt', $textile_excerpt, 'markup-excerpt')), 424 425 // form override 426 ($allow_form_override) 427 ? graf('<label for="override-form">'.gTxt('override_default_form').'</label>'.sp.popHelp('override_form').br. 428 form_pop($override_form, 'override-form')) 429 : '', 430 431 // custom fields, believe it or not 432 ($custom_1_set) ? custField( 1, $custom_1_set, $custom_1 ) : '', 433 ($custom_2_set) ? custField( 2, $custom_2_set, $custom_2 ) : '', 434 ($custom_3_set) ? custField( 3, $custom_3_set, $custom_3 ) : '', 435 ($custom_4_set) ? custField( 4, $custom_4_set, $custom_4 ) : '', 436 ($custom_5_set) ? custField( 5, $custom_5_set, $custom_5 ) : '', 437 ($custom_6_set) ? custField( 6, $custom_6_set, $custom_6 ) : '', 438 ($custom_7_set) ? custField( 7, $custom_7_set, $custom_7 ) : '', 439 ($custom_8_set) ? custField( 8, $custom_8_set, $custom_8 ) : '', 440 ($custom_9_set) ? custField( 9, $custom_9_set, $custom_9 ) : '', 441 ($custom_10_set) ? custField( 10, $custom_10_set, $custom_10 ) : '', 442 443 // keywords 444 n.graf('<label for="keywords">'.gTxt('keywords').'</label>'.sp.popHelp('keywords').br. 445 n.'<textarea id="keywords" name="Keywords" cols="18" rows="5">'.htmlspecialchars(str_replace(',' ,', ', $Keywords)).'</textarea>'), 446 447 // article image 448 n.graf('<label for="article-image">'.gTxt('article_image').'</label>'.sp.popHelp('article_image').br. 449 fInput('text', 'Image', $Image, 'edit', '', '', 22, '', 'article-image')), 450 451 // url title 452 n.graf('<label for="url-title">'.gTxt('url_title').'</label>'.sp.popHelp('url_title').br. 453 fInput('text', 'url_title', $url_title, 'edit', '', '', 22, '', 'url-title')), 454 455 '</div> 456 457 <h3 class="plain"><a href="#recent" onclick="toggleDisplay(\'recent\'); return false;">'.gTxt('recent_articles').'</a>'.'</h3>'. 458 '<div id="recent" class="toggle" style="display:none">'; 459 460 $recents = safe_rows_start("Title, ID",'textpattern',"1=1 order by LastMod desc limit 10"); 461 462 if ($recents) 463 { 464 echo '<ul class="plain-list">'; 465 466 while($recent = nextRow($recents)) 467 { 468 if (!$recent['Title']) 469 { 470 $recent['Title'] = gTxt('untitled').sp.$recent['ID']; 471 } 472 473 echo n.t.'<li><a href="?event=article'.a.'step=edit'.a.'ID='.$recent['ID'].'">'.escape_title($recent['Title']).'</a></li>'; 474 } 475 476 echo '</ul>'; 477 } 478 479 echo '</div>'; 480 } 481 482 else 483 { 484 echo sp; 485 } 486 487 echo '</td>'.n.'<td id="article-main">'; 488 489 //-- title input -------------- 490 491 if ($view == 'preview') 492 { 493 echo hed(gTxt('preview'), 2).hed($Title, 1); 494 } 495 496 elseif ($view == 'html') 497 { 498 echo hed('XHTML', 2).hed($Title, 1); 499 } 500 501 elseif ($view == 'text') 502 { 503 echo n.'<p><label for="title">'.gTxt('title').'</label>'.sp.popHelp('title').br. 504 '<input type="text" id="title" name="Title" value="'.escape_title($Title).'" class="edit" size="40" tabindex="1" />'; 505 506 if ($step != 'create') 507 { 508 include_once txpath.'/publish/taghandlers.php'; 509 $url = permlinkurl_id($ID); 510 511 if ($Status != 4 and $Status != 5) 512 { 513 $url .= (strpos($url, '?') === FALSE ? '?' : '&') . 'txpreview='.intval($ID).'.'.time(); 514 } 515 516 echo sp.sp.'<a href="'.$url.'" class="article-view">'.gTxt('view').'</a>'; 517 } 518 519 echo '</p>'; 520 } 521 522 //-- body -------------------- 523 524 if ($view == 'preview') 525 { 526 if ($textile_body == USE_TEXTILE) 527 { 528 echo $textile->TextileThis($Body); 529 } 530 531 else if ($textile_body == CONVERT_LINEBREAKS) 532 { 533 echo nl2br($Body); 534 } 535 536 else if ($textile_body == LEAVE_TEXT_UNTOUCHED) 537 { 538 echo $Body; 539 } 540 } 541 542 elseif ($view == 'html') 543 { 544 if ($textile_body == USE_TEXTILE) 545 { 546 $bod = $textile->TextileThis($Body); 547 } 548 549 else if ($textile_body == CONVERT_LINEBREAKS) 550 { 551 $bod = nl2br($Body); 552 } 553 554 else if ($textile_body == LEAVE_TEXT_UNTOUCHED) 555 { 556 $bod = $Body; 557 } 558 559 echo tag(str_replace(array(n,t), array(br,sp.sp.sp.sp), htmlspecialchars($bod)), 'code'); 560 } 561 562 else 563 { 564 echo n.graf('<label for="body">'.gTxt('body').'</label>'.sp.popHelp('body').br. 565 '<textarea id="body" name="Body" cols="55" rows="31" tabindex="2">'.htmlspecialchars($Body).'</textarea>'); 566 } 567 568 //-- excerpt -------------------- 569 570 if ($articles_use_excerpts) 571 { 572 if ($view == 'text') 573 { 574 echo n.graf('<label for="excerpt">'.gTxt('excerpt').'</label>'.sp.popHelp('excerpt').br. 575 '<textarea id="excerpt" name="Excerpt" cols="55" rows="5" tabindex="3">'.htmlspecialchars($Excerpt).'</textarea>'); 576 } 577 578 else 579 { 580 echo n.'<hr width="50%" />'; 581 582 echo ($textile_excerpt == USE_TEXTILE) 583 ? ($view=='preview') 584 ? graf($textile->textileThis($Excerpt)) 585 : tag(str_replace(array(n,t), 586 array(br,sp.sp.sp.sp),htmlspecialchars( 587 $textile->TextileThis($Excerpt))),'code') 588 : graf($Excerpt); 589 } 590 } 591 592 593 //-- author -------------- 594 595 if ($view=="text" && $step != "create") { 596 echo '<p class="small">'.gTxt('posted_by').': '.htmlspecialchars($AuthorID).' · '.safe_strftime('%d %b %Y · %X',$sPosted); 597 if($sPosted != $sLastMod) { 598 echo br.gTxt('modified_by').': '.htmlspecialchars($LastModID).' · '.safe_strftime('%d %b %Y · %X',$sLastMod); 599 } 600 echo '</p>'; 601 } 602 603 echo hInput('from_view',$view), 604 '</td>'; 605 echo '<td id="article-tabs">'; 606 607 //-- layer tabs ------------------- 608 609 echo ($use_textile == USE_TEXTILE || $textile_body == USE_TEXTILE) 610 ? '<ul>'.(tab('text',$view).tab('html',$view).tab('preview',$view)).'</ul>' 611 : ' '; 612 echo '</td>'; 613 echo '<td id="article-col-2">'; 614 615 if ($view == 'text') 616 { 617 if ($step != 'create') 618 { 619 echo n.graf(href(gtxt('create_new'), 'index.php?event=article')); 620 } 621 622 //-- prev/next article links -- 623 624 if ($step!='create' and ($prev_id or $next_id)) { 625 echo '<p>', 626 ($prev_id) 627 ? prevnext_link('‹'.gTxt('prev'),'article','edit', 628 $prev_id,gTxt('prev')) 629 : '', 630 ($next_id) 631 ? prevnext_link(gTxt('next').'›','article','edit', 632 $next_id,gTxt('next')) 633 : '', 634 '</p>'; 635 } 636 637 //-- status radios -------------- 638 639 echo n.n.'<fieldset id="write-status">'. 640 n.'<legend>'.gTxt('status').'</legend>'. 641 n.status_radio($Status). 642 n.'</fieldset>'; 643 644 //-- category selects ----------- 645 646 echo n.n.'<fieldset id="write-sort">'. 647 n.'<legend>'.gTxt('sort_display').'</legend>'. 648 649 n.graf('<label for="category-1">'.gTxt('category1').'</label> '. 650 '<span class="small">['.eLink('category', '', '', '', gTxt('edit')).']</span>'.br. 651 n.category_popup('Category1', $Category1, 'category-1')). 652 653 n.graf('<label for="category-2">'.gTxt('category2').'</label>'.br. 654 n.category_popup('Category2', $Category2, 'category-2')); 655 656 //-- section select -------------- 657 658 if(!$from_view && !$pull) $Section = getDefaultSection(); 659 660 echo n.graf('<label for="section">'.gTxt('section').'</label> '. 661 '<span class="small">['.eLink('section', '', '', '', gTxt('edit')).']</span>'.br. 662 section_popup($Section, 'section')). 663 664 n.'</fieldset>'. 665 666 //-- "More" section 667 n.n.'<h3 class="plain"><a href="#more" onclick="toggleDisplay(\'more\'); return false;">'.gTxt('more').'</a></h3>', 668 '<div id="more" class="toggle" style="display:none">'; 669 670 //-- comments stuff -------------- 671 672 if($step=="create") { 673 //Avoiding invite disappear when previewing 674 $AnnotateInvite = (!empty($store_out['AnnotateInvite']))? $store_out['AnnotateInvite'] : $comments_default_invite; 675 if ($comments_on_default==1) { $Annotate = 1; } 676 } 677 678 if ($use_comments == 1) 679 { 680 echo n.n.'<fieldset id="write-comments">'. 681 n.'<legend>'.gTxt('comments').'</legend>'; 682 683 $comments_expired = false; 684 685 if ($step != 'create' && $comments_disabled_after) 686 { 687 $lifespan = $comments_disabled_after * 86400; 688 $time_since = time() - $sPosted; 689 690 if ($time_since > $lifespan) 691 { 692 $comments_expired = true; 693 } 694 } 695 696 if ($comments_expired) 697 { 698 echo n.n.graf(gTxt('expired')); 699 } 700 701 else 702 { 703 echo n.n.graf( 704 onoffRadio('Annotate', $Annotate) 705 ). 706 707 n.n.graf( 708 '<label for="comment-invite">'.gTxt('comment_invitation').'</label>'.br. 709 fInput('text', 'AnnotateInvite', $AnnotateInvite, 'edit', '', '', '', '', 'comment-invite') 710 ); 711 } 712 713 echo n.n.'</fieldset>'; 714 } 715 716 if ($step == "create" and empty($GLOBALS['ID'])) 717 { 718 //-- timestamp ------------------- 719 720 //Avoiding modified date to disappear 721 $persist_timestamp = (!empty($store_out['year']))? 722 safe_strtotime($store_out['year'].'-'.$store_out['month'].'-'.$store_out['day'].' '.$store_out['hour'].':'.$store_out['minute'].':'.$store_out['second']) 723 : time(); 724 725 echo n.n.'<fieldset id="write-timestamp">'. 726 n.'<legend>'.gTxt('timestamp').'</legend>'. 727 728 n.graf(checkbox('publish_now', '1', $publish_now, '', 'publish_now').'<label for="publish_now">'.gTxt('set_to_now').'</label>'). 729 730 n.graf(gTxt('or_publish_at').sp.popHelp('timestamp')). 731 732 n.graf(gtxt('date').sp. 733 tsi('year', '%Y', $persist_timestamp).' / '. 734 tsi('month', '%m', $persist_timestamp).' / '. 735 tsi('day', '%d', $persist_timestamp) 736 ). 737 738 n.graf(gTxt('time').sp. 739 tsi('hour', '%H', $persist_timestamp).' : '. 740 tsi('minute', '%M', $persist_timestamp).' : '. 741 tsi('second', '%S', $persist_timestamp) 742 ). 743 744 n.'</fieldset>'; 745 746 //-- expires ------------------- 747 748 $persist_timestamp = (!empty($store_out['exp_year']))? 749 safe_strtotime($store_out['exp_year'].'-'.$store_out['exp_month'].'-'.$store_out['exp_day'].' '.$store_out['exp_hour'].':'.$store_out['exp_minute'].':'.$store_out['second']) 750 : NULLDATETIME; 751 752 echo n.n.'<fieldset id="write-expires">'. 753 n.'<legend>'.gTxt('expires').'</legend>'. 754 755 n.graf(gtxt('date').sp. 756 tsi('exp_year', '%Y', $persist_timestamp).' / '. 757 tsi('exp_month', '%m', $persist_timestamp).' / '. 758 tsi('exp_day', '%d', $persist_timestamp) 759 ). 760 761 n.graf(gTxt('time').sp. 762 tsi('exp_hour', '%H', $persist_timestamp).' : '. 763 tsi('exp_minute', '%M', $persist_timestamp).' : '. 764 tsi('exp_second', '%S', $persist_timestamp) 765 ). 766 767 n.'</fieldset>'. 768 // end "More" section 769 n.n.'</div>'; 770 771 //-- publish button -------------- 772 773 echo 774 (has_privs('article.publish')) ? 775 fInput('submit','publish',gTxt('publish'),"publish", '', '', '', 4) : 776 fInput('submit','publish',gTxt('save'),"publish", '', '', '', 4); 777 } 778 779 else 780 { 781 782 //-- timestamp ------------------- 783 784 if (!empty($year)) { 785 $sPosted = safe_strtotime($year.'-'.$month.'-'.$day.' '.$hour.':'.$minute.':'.$second); 786 } 787 788 echo n.n.'<fieldset id="write-timestamp">'. 789 n.'<legend>'.gTxt('timestamp').'</legend>'. 790 791 n.graf(checkbox('reset_time', '1', $reset_time, '', 'reset_time').'<label for="reset_time">'.gTxt('reset_time').'</label>'). 792 793 n.graf(gTxt('published_at').sp.popHelp('timestamp')). 794 795 n.graf(gtxt('date').sp. 796 tsi('year', '%Y', $sPosted).' / '. 797 tsi('month', '%m', $sPosted).' / '. 798 tsi('day', '%d', $sPosted) 799 ). 800 801 n.graf(gTxt('time').sp. 802 tsi('hour', '%H', $sPosted).' : ' . 803 tsi('minute', '%M', $sPosted).' : '. 804 tsi('second', '%S', $sPosted) 805 ). 806 807 n.hInput('sPosted', $sPosted), 808 n.hInput('sLastMod', $sLastMod), 809 n.hInput('AuthorID', $AuthorID), 810 n.hInput('LastModID', $LastModID), 811 812 n.'</fieldset>'; 813 814 //-- expires ------------------- 815 if (!empty($exp_year)) 816 { 817 if(empty($exp_month)) $exp_month=1; 818 if(empty($exp_day)) $exp_day=1; 819 if(empty($exp_hour)) $exp_hour=0; 820 if(empty($exp_minute)) $exp_minute=0; 821 if(empty($exp_second)) $exp_second=0; 822 $sExpires = safe_strtotime($exp_year.'-'.$exp_month.'-'.$exp_day.' '.$exp_hour.':'.$exp_minute.':'.$exp_second); 823 } 824 825 echo n.n.'<fieldset id="write-expires">'. 826 n.'<legend>'.gTxt('expires').'</legend>'. 827 828 n.graf(gtxt('date').sp. 829 tsi('exp_year', '%Y', $sExpires).' / '. 830 tsi('exp_month', '%m', $sExpires).' / '. 831 tsi('exp_day', '%d', $sExpires) 832 ). 833 834 n.graf(gTxt('time').sp. 835 tsi('exp_hour', '%H', $sExpires).' : '. 836 tsi('exp_minute', '%M', $sExpires).' : '. 837 tsi('exp_second', '%S', $sExpires) 838 ). 839 n.hInput('sExpires', $sExpires). 840 841 n.'</fieldset>'. 842 843 // end "More" section 844 n.n.'</div>'; 845 846 //-- save button -------------- 847 848 if ( ($Status >= 4 and has_privs('article.edit.published')) 849 or ($Status >= 4 and $AuthorID==$txp_user and has_privs('article.edit.own.published')) 850 or ($Status < 4 and has_privs('article.edit')) 851 or ($Status < 4 and $AuthorID==$txp_user and has_privs('article.edit.own'))) 852 echo fInput('submit','save',gTxt('save'),"publish", '', '', '', 4); 853 } 854 } 855 856 echo '</td></tr></table></form>'; 857 858 } 859 860 // ------------------------------------------------------------- 861 862 function custField($num, $field, $content) 863 { 864 return n.n.graf('<label for="custom-'.$num.'">'.$field.'</label>'.br. 865 n.fInput('text', 'custom_'.$num, $content, 'edit', '', '', 22, '', 'custom-'.$num)); 866 } 867 868 // ------------------------------------------------------------- 869 function checkIfNeighbour($whichway,$sPosted) 870 { 871 $sPosted = assert_int($sPosted); 872 $dir = ($whichway == 'prev') ? '<' : '>'; 873 $ord = ($whichway == 'prev') ? 'desc' : 'asc'; 874 875 return safe_field("ID", "textpattern", 876 "Posted $dir from_unixtime($sPosted) order by Posted $ord limit 1"); 877 } 878 879 //-------------------------------------------------------------- 880 // remember to show markup help for both body and excerpt 881 // if they are different 882 883 function side_help($textile_body, $textile_excerpt) 884 { 885 if ($textile_body == USE_TEXTILE or $textile_excerpt == USE_TEXTILE) 886 { 887 return n.hed( 888 '<a href="#textile_help" onclick="toggleDisplay(\'textile_help\'); return false;">'.gTxt('textile_help').'</a>' 889 , 3, ' class="plain"'). 890 891 n.'<div id="textile_help" class="toggle" style="display:none">'. 892 893 n.'<ul class="plain-list small">'. 894 n.t.'<li>'.gTxt('header').': <strong>h<em>n</em>.</strong>'.sp. 895 popHelpSubtle('header', 400, 400).'</li>'. 896 n.t.'<li>'.gTxt('blockquote').': <strong>bq.</strong>'.sp. 897 popHelpSubtle('blockquote',400,400).'</li>'. 898 n.t.'<li>'.gTxt('numeric_list').': <strong>#</strong>'.sp. 899 popHelpSubtle('numeric', 400, 400).'</li>'. 900 n.t.'<li>'.gTxt('bulleted_list').': <strong>*</strong>'.sp. 901 popHelpSubtle('bulleted', 400, 400).'</li>'. 902 n.'</ul>'. 903 904 n.'<ul class="plain-list small">'. 905 n.t.'<li>'.'_<em>'.gTxt('emphasis').'</em>_'.sp. 906 popHelpSubtle('italic', 400, 400).'</li>'. 907 n.t.'<li>'.'*<strong>'.gTxt('strong').'</strong>*'.sp. 908 popHelpSubtle('bold', 400, 400).'</li>'. 909 n.t.'<li>'.'??<cite>'.gTxt('citation').'</cite>??'.sp. 910 popHelpSubtle('cite', 500, 300).'</li>'. 911 n.t.'<li>'.'-'.gTxt('deleted_text').'-'.sp. 912 popHelpSubtle('delete', 400, 300).'</li>'. 913 n.t.'<li>'.'+'.gTxt('inserted_text').'+'.sp. 914 popHelpSubtle('insert', 400, 300).'</li>'. 915 n.t.'<li>'.'^'.gTxt('superscript').'^'.sp. 916 popHelpSubtle('super', 400, 300).'</li>'. 917 n.t.'<li>'.'~'.gTxt('subscript').'~'.sp. 918 popHelpSubtle('subscript', 400, 400).'</li>'. 919 n.'</ul>'. 920 921 n.graf( 922 '"'.gTxt('linktext').'":url'.sp.popHelpSubtle('link', 400, 500) 923 , ' class="small"'). 924 925 n.graf( 926 '!'.gTxt('imageurl').'!'.sp.popHelpSubtle('image', 500, 500) 927 , ' class="small"'). 928 929 n.graf( 930 '<a id="textile-docs-link" href="http://textpattern.com/textile-sandbox" target="_blank">'.gTxt('More').'</a>'). 931 932 n.'</div>'; 933 } 934 } 935 936 //-------------------------------------------------------------- 937 938 function status_radio($Status) 939 { 940 global $statuses; 941 942 $Status = (!$Status) ? 4 : $Status; 943 944 foreach ($statuses as $a => $b) 945 { 946 $out[] = n.t.'<li>'.radio('Status', $a, ($Status == $a) ? 1 : 0, 'status-'.$a). 947 '<label for="status-'.$a.'">'.$b.'</label></li>'; 948 } 949 950 return '<ul class="plain-list">'.join('', $out).n.'</ul>'; 951 } 952 953 //-------------------------------------------------------------- 954 955 function category_popup($name, $val, $id) 956 { 957 $rs = getTree('root', 'article'); 958 959 if ($rs) 960 { 961 return treeSelectInput($name,$rs,$val, $id, 35); 962 } 963 964 return false; 965 } 966 967 //-------------------------------------------------------------- 968 969 function section_popup($Section, $id) 970 { 971 $rs = safe_column('name', 'txp_section', "name != 'default'"); 972 973 if ($rs) 974 { 975 return selectInput('Section', $rs, $Section, false, '', $id); 976 } 977 978 return false; 979 } 980 981 //-------------------------------------------------------------- 982 function tab($tabevent,$view) 983 { 984 $state = ($view==$tabevent) ? 'up' : 'down'; 985 $out = "<li id='tab-$tabevent$state'>"; 986 $out.=($tabevent!=$view) ? '<a href="javascript:document.article.view.value=\''.$tabevent.'\';document.article.submit();">'.gTxt($tabevent).'</a>' : gTxt($tabevent); 987 $out.='</li>'; 988 return $out; 989 } 990 991 //-------------------------------------------------------------- 992 function getDefaultSection() 993 { 994 return safe_field("name", "txp_section","is_default=1"); 995 } 996 997 // ------------------------------------------------------------- 998 999 function form_pop($form, $id) 1000 { 1001 $arr = array(' '); 1002 1003 $rs = safe_column('name', 'txp_form', "type = 'article' and name != 'default' order by name"); 1004 1005 if ($rs) 1006 { 1007 return selectInput('override_form', $rs, $form, true, '', $id); 1008 } 1009 } 1010 1011 // ------------------------------------------------------------- 1012 1013 function check_url_title($url_title) 1014 { 1015 // Check for blank or previously used identical url-titles 1016 if (strlen($url_title) === 0) 1017 { 1018 return gTxt('url_title_is_blank'); 1019 } 1020 1021 else 1022 { 1023 $url_title_count = safe_count('textpattern', "url_title = '$url_title'"); 1024 1025 if ($url_title_count > 1) 1026 { 1027 return gTxt('url_title_is_multiple', array('{count}' => $url_title_count)); 1028 } 1029 } 1030 1031 return ''; 1032 } 1033 // ------------------------------------------------------------- 1034 function get_status_message($Status) 1035 { 1036 switch ($Status){ 1037 case 3: return gTxt("article_saved_pending"); 1038 case 2: return gTxt("article_saved_hidden"); 1039 case 1: return gTxt("article_saved_draft"); 1040 default: return gTxt('article_posted'); 1041 } 1042 } 1043 // ------------------------------------------------------------- 1044 function textile_main_fields($incoming, $use_textile) 1045 { 1046 global $txpcfg; 1047 1048 include_once txpath.'/lib/classTextile.php'; 1049 $textile = new Textile(); 1050 1051 $incoming['Title_plain'] = $incoming['Title']; 1052 $incoming['url_title'] = preg_replace('|[\x00-\x1f#%+/?\x7f]|', '', $incoming['url_title']); 1053 1054 if ($incoming['textile_body'] == LEAVE_TEXT_UNTOUCHED) { 1055 1056 $incoming['Body_html'] = trim($incoming['Body']); 1057 1058 }elseif ($incoming['textile_body'] == USE_TEXTILE){ 1059 1060 $incoming['Body_html'] = $textile->TextileThis($incoming['Body']); 1061 $incoming['Title'] = $textile->TextileThis($incoming['Title'],'',1); 1062 1063 }elseif ($incoming['textile_body'] == CONVERT_LINEBREAKS){ 1064 1065 $incoming['Body_html'] = nl2br(trim($incoming['Body'])); 1066 } 1067 1068 if ($incoming['textile_excerpt'] == LEAVE_TEXT_UNTOUCHED) { 1069 1070 $incoming['Excerpt_html'] = trim($incoming['Excerpt']); 1071 1072 }elseif ($incoming['textile_excerpt'] == USE_TEXTILE){ 1073 1074 $incoming['Excerpt_html'] = $textile->TextileThis($incoming['Excerpt']); 1075 1076 }elseif ($incoming['textile_excerpt'] == CONVERT_LINEBREAKS){ 1077 1078 $incoming['Excerpt_html'] = nl2br(trim($incoming['Excerpt'])); 1079 } 1080 1081 return $incoming; 1082 } 1083 // ------------------------------------------------------------- 1084 1085 function do_pings() 1086 { 1087 global $txpcfg, $prefs, $production_status; 1088 1089 # only ping for Live sites 1090 if ($production_status !== 'live') 1091 return; 1092 1093 include_once txpath.'/lib/IXRClass.php'; 1094 1095 callback_event('ping'); 1096 1097 if ($prefs['ping_textpattern_com']) { 1098 $tx_client = new IXR_Client('http://textpattern.com/xmlrpc/'); 1099 $tx_client->query('ping.Textpattern', $prefs['sitename'], hu); 1100 } 1101 1102 if ($prefs['ping_weblogsdotcom']==1) { 1103 $wl_client = new IXR_Client('http://rpc.pingomatic.com/'); 1104 $wl_client->query('weblogUpdates.ping', $prefs['sitename'], hu); 1105 } 1106 } 1107 1108 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu May 21 23:03:01 2009 | Cross-referenced by PHPXref 0.7 |