1<?php 2/** 3 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 4 * @author Esther Brunner <wikidesign@gmail.com> 5 */ 6 7// must be run within Dokuwiki 8if (!defined('DOKU_INC')) die(); 9 10if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 11require_once(DOKU_PLUGIN.'action.php'); 12 13if (!defined('NL')) define('NL',"\n"); 14 15class action_plugin_discussion extends DokuWiki_Action_Plugin{ 16 17 /** 18 * Return some info 19 */ 20 function getInfo(){ 21 return array( 22 'author' => 'Esther Brunner', 23 'email' => 'wikidesign@gmail.com', 24 'date' => '2006-11-13', 25 'name' => 'Discussion Plugin', 26 'desc' => 'Enables discussion features', 27 'url' => 'http://wiki:splitbrain.org/plugin:discussion', 28 ); 29 } 30 31 /** 32 * Register the eventhandlers 33 */ 34 function register(&$contr){ 35 $contr->register_hook( 36 'ACTION_ACT_PREPROCESS', 37 'BEFORE', 38 $this, 39 'handle_act_preprocess', 40 array() 41 ); 42 $contr->register_hook( 43 'TPL_ACT_RENDER', 44 'AFTER', 45 $this, 46 'comments', 47 array() 48 ); 49 } 50 51 /** 52 * Main function; dispatches the comment actions 53 */ 54 function comments(&$event, $param){ 55 if ($event->data != 'show') return; // nothing to do for us 56 57 $cid = $_REQUEST['cid']; 58 59 switch ($_REQUEST['comment']){ 60 61 case 'add': 62 $comment = array( 63 'user' => $_REQUEST['user'], 64 'name' => $_REQUEST['name'], 65 'mail' => $_REQUEST['mail'], 66 'url' => $_REQUEST['url'], 67 'address' => $_REQUEST['address'], 68 'date' => $_REQUEST['date'], 69 'raw' => cleanText($_REQUEST['text']) 70 ); 71 $repl = $_REQUEST['reply']; 72 $this->_add($comment, $repl); 73 break; 74 75 case 'edit': 76 $this->_show(NULL, $cid); 77 break; 78 79 case 'save': 80 $raw = cleanText($_REQUEST['text']); 81 $this->_save($cid, $raw); 82 break; 83 84 case 'delete': 85 $this->_save($cid, ''); 86 87 case 'toogle': 88 $this->_save($cid, '', true); 89 break; 90 91 default: // 'show' => $this->_show(), 'reply' => $this->_show($cid) 92 $this->_show($cid); 93 } 94 } 95 96 /** 97 * Shows all comments of the current page 98 */ 99 function _show($reply = NULL, $edit = NULL){ 100 global $ID; 101 102 // get discussion meta file name 103 $file = metaFN($ID, '.comments'); 104 105 if (!file_exists($file)) return true; // no comments at all 106 107 $data = unserialize(io_readFile($file, false)); 108 109 if ($data['status'] == 0) return true; // comments are off 110 111 // section title 112 $title = $this->getLang('discussion'); 113 $secid = cleanID($title); 114 echo '<h2><a name="'.$secid.'" id="'.$secid.'">'.$title.'</a></h2>'; 115 echo '<div class="level2">'; 116 117 // now display the comments 118 if (isset($data['comments'])){ 119 foreach ($data['comments'] as $key => $value){ 120 if ($key == $edit) $this->_form($value['raw'], 'save', $edit); // edit form 121 else $this->_print($key, $data, '', $reply); 122 } 123 } 124 125 // comment form 126 if (($data['status'] == 1) && !$reply && !$edit) $this->_form(''); 127 128 echo '</div>'; 129 130 return true; 131 } 132 133 /** 134 * Adds a new comment and then displays all comments 135 */ 136 function _add($comment, $parent){ 137 global $ID; 138 global $TEXT; 139 140 $otxt = $TEXT; // set $TEXT to comment text for wordblock check 141 $TEXT = $comment['raw']; 142 143 // spamcheck against the DokuWiki blacklist 144 if (checkwordblock()){ 145 msg($this->getLang('wordblock'), -1); 146 $this->_show(); 147 return false; 148 } 149 150 $TEXT = $otxt; // restore global $TEXT 151 152 // get discussion meta file name 153 $file = metaFN($ID, '.comments'); 154 155 $data = array(); 156 $data = unserialize(io_readFile($file, false)); 157 158 if ($data['status'] != 1) return false; // comments off or closed 159 if ((!$this->getConf('allowguests')) 160 && ($comment['user'] != $_SERVER['REMOTE_USER'])) 161 return false; // guest comments not allowed 162 163 if ($comment['date']) $date = strtotime($comment['date']); 164 else $date = time(); 165 if ($date == -1) $date = time(); 166 $cid = md5($comment['user'].$date); // create a unique id 167 168 if (!is_array($data['comments'][$parent])) $parent = NULL; // invalid parent comment 169 170 // render the comment 171 $xhtml = $this->_render($comment['raw']); 172 173 // fill in the new comment 174 $data['comments'][$cid] = array( 175 'user' => htmlspecialchars($comment['user']), 176 'name' => htmlspecialchars($comment['name']), 177 'mail' => htmlspecialchars($comment['mail']), 178 'date' => $date, 179 'show' => true, 180 'raw' => trim($comment['raw']), 181 'xhtml' => $xhtml, 182 'parent' => $parent, 183 'replies' => array() 184 ); 185 if ($comment['url']) 186 $data['comments'][$cid]['url'] = htmlspecialchars($comment['url']); 187 if ($comment['address']) 188 $data['comments'][$cid]['address'] = htmlspecialchars($comment['address']); 189 190 // update parent comment 191 if ($parent) $data['comments'][$parent]['replies'][] = $cid; 192 193 // update the number of comments 194 $data['number']++; 195 196 // save the comment metadata file 197 io_saveFile($file, serialize($data)); 198 $this->_addLogEntry($date, $ID, 'cc', '', $cid); 199 200 // notify subscribers of the page 201 $this->_notify($data['comments'][$cid]); 202 203 $this->_show(); 204 return true; 205 } 206 207 /** 208 * Saves the comment with the given ID and then displays all comments 209 */ 210 function _save($cid, $raw, $toogle = false){ 211 global $ID; 212 global $TEXT; 213 global $INFO; 214 215 $otxt = $TEXT; // set $TEXT to comment text for wordblock check 216 $TEXT = $raw; 217 218 // spamcheck against the DokuWiki blacklist 219 if (checkwordblock()){ 220 msg($this->getLang('wordblock'), -1); 221 $this->_show(); 222 return false; 223 } 224 225 $TEXT = $otxt; // restore global $TEXT 226 227 // get discussion meta file name 228 $file = metaFN($ID, '.comments'); 229 230 $data = array(); 231 $data = unserialize(io_readFile($file, false)); 232 233 // someone else was trying to edit our comment -> abort 234 if (($data['comments'][$cid]['user'] != $_SERVER['REMOTE_USER']) 235 && ($INFO['perm'] != AUTH_ADMIN)) return false; 236 237 $date = time(); 238 239 if ($toogle){ // toogle visibility 240 $now = $data['comments'][$cid]['show']; 241 $data['comments'][$cid]['show'] = !$now; 242 $data['number'] = $this->_count($data); 243 244 $type = ($data['comments'][$cid]['show'] ? 'sc' : 'hc'); 245 246 } elseif (!$raw){ // remove the comment 247 unset($data['comments'][$cid]); 248 $data['number'] = $this->_count($data); 249 250 $type = 'dc'; 251 252 } else { // save changed comment 253 $xhtml = $this->_render($raw); 254 255 // now change the comment's content 256 $data['comments'][$cid]['edited'] = $date; 257 $data['comments'][$cid]['raw'] = trim($raw); 258 $data['comments'][$cid]['xhtml'] = $xhtml; 259 260 $type = 'ec'; 261 } 262 263 // save the comment metadata file 264 io_saveFile($file, serialize($data)); 265 $this->_addLogEntry($date, $ID, $type, '', $cid); 266 267 $this->_show(); 268 return true; 269 } 270 271 /** 272 * Prints an individual comment 273 */ 274 function _print($cid, &$data, $parent = '', $reply = '', $visible = true){ 275 global $conf; 276 global $lang; 277 global $ID; 278 global $INFO; 279 280 $comment = $data['comments'][$cid]; 281 282 if (!is_array($comment)) return false; // corrupt datatype 283 284 if ($comment['parent'] != $parent) return true; // reply to an other comment 285 286 if (!$comment['show']){ // comment hidden 287 if ($INFO['perm'] == AUTH_ADMIN) echo '<div class="comment_hidden">'.NL; 288 else return true; 289 } 290 291 // comment head with date and user data 292 echo '<div class="comment_head">'.NL; 293 echo '<a name="comment__'.$cid.'" id="comment__'.$cid.'">'.NL; 294 295 // show gravatar image 296 if ($this->getConf('usegravatar')){ 297 $default = DOKU_URL.'lib/plugins/discussion/images/default.gif'; 298 $size = $this->getConf('gravatar_size'); 299 if ($comment['mail']) $src = ml('http://www.gravatar.com/avatar.php?'. 300 'gravatar_id='.md5($comment['mail']). 301 '&default='.urlencode($default). 302 '&size='.$size. 303 '&rating='.$this->getConf('gravatar_rating')); 304 else $src = $default; 305 $title = ($comment['name'] ? $comment['name'] : obfuscate($comment['mail'])); 306 echo '<img src="'.$src.'" class="medialeft" title="'.$title.'"'. 307 ' alt="'.$title.'" width="'.$size.'" height="'.$size.'" />'.NL; 308 } 309 310 echo '</a>'.NL; 311 if ($this->getConf('linkemail') && $comment['mail']){ 312 echo $this->email($comment['email'], $comment['name']); 313 } elseif ($comment['url']){ 314 echo $this->external_link($comment['url'], $comment['name'], 'urlextern'); 315 } else { 316 echo $comment['name']; 317 } 318 if ($comment['address']) echo ', '.htmlentities($comment['address']); 319 echo ', '.date($conf['dformat'], $comment['date']); 320 if ($comment['edited']) echo ' ('.date($conf['dformat'], $comment['edited']).')'; 321 echo ':'.NL; 322 echo '</div>'.NL; // class="comment_head" 323 324 // main comment content 325 echo '<div class="comment_body">'.NL; 326 echo $comment['xhtml'].NL; 327 echo '</div>'.NL; // class="comment_body" 328 329 330 if ($visible){ 331 // show hide/show toogle button? 332 echo '<div class="comment_buttons">'.NL; 333 if ($INFO['perm'] == AUTH_ADMIN){ 334 if (!$comment['show']) $label = $this->getLang('btn_show'); 335 else $label = $this->getLang('btn_hide'); 336 337 $this->_button($cid, $label, 'toogle'); 338 } 339 340 // show reply button? 341 if (($data['status'] == 1) && !$reply && $comment['show']) 342 $this->_button($cid, $this->getLang('btn_reply'), 'reply', true); 343 344 // show edit and delete button? 345 if ((($comment['user'] == $_SERVER['REMOTE_USER']) && ($comment['user'] != '')) 346 || ($INFO['perm'] == AUTH_ADMIN)) 347 $this->_button($cid, $lang['btn_secedit'], 'edit', true); 348 if ($INFO['perm'] == AUTH_ADMIN) 349 $this->_button($cid, $lang['btn_delete'], 'delete'); 350 echo '</div>'.NL; // class="comment_buttons" 351 } 352 353 // replies to this comment entry? 354 if (count($comment['replies'])){ 355 echo '<div class="comment_replies">'.NL; 356 $visible = ($comment['show'] && $visible); 357 foreach ($comment['replies'] as $rid){ 358 $this->_print($rid, $data, $cid, $reply, $visible); 359 } 360 echo '</div>'.NL; // class="comment_replies" 361 } 362 363 if (!$comment['show']) echo '</div>'.NL; // class="comment_hidden" 364 365 // reply form 366 if ($reply == $cid){ 367 echo '<div class="comment_replies">'.NL; 368 $this->_form('', 'add', $cid); 369 echo '</div>'.NL; // class="comment_replies" 370 } 371 } 372 373 /** 374 * Outputs the comment form 375 */ 376 function _form($raw = '', $act = 'add', $cid = NULL){ 377 global $lang; 378 global $conf; 379 global $ID; 380 global $INFO; 381 382 // not for unregistered users when guest comments aren't allowed 383 if (!$_SERVER['REMOTE_USER'] && !$this->getConf('allowguests')) return false; 384 385 ?> 386 <div class="comment_form"> 387 <form id="discussion__comment_form" method="post" action="<?php echo script() ?>" accept-charset="<?php echo $lang['encoding'] ?>" onsubmit="return validate(this);"> 388 <div class="no"> 389 <input type="hidden" name="id" value="<?php echo $ID ?>" /> 390 <input type="hidden" name="do" value="show" /> 391 <input type="hidden" name="comment" value="<?php echo $act ?>" /> 392 <?php 393 394 // for adding a comment 395 if ($act == 'add'){ 396 ?> 397 <input type="hidden" name="reply" value="<?php echo $cid ?>" /> 398 <?php 399 // for registered user 400 if ($conf['useacl'] && $_SERVER['REMOTE_USER']){ 401 ?> 402 <input type="hidden" name="user" value="<?php echo $_SERVER['REMOTE_USER'] ?>" /> 403 <input type="hidden" name="name" value="<?php echo $INFO['userinfo']['name'] ?>" /> 404 <input type="hidden" name="mail" value="<?php echo $INFO['userinfo']['mail'] ?>" /> 405 <?php 406 // for guest: show name and e-mail entry fields 407 } else { 408 ?> 409 <input type="hidden" name="user" value="<?php echo clientIP() ?>" /> 410 <div class="comment_name"> 411 <label class="block" for="discussion__comment_name"> 412 <span><?php echo $lang['fullname'] ?>:</span> 413 <input type="text" class="edit" name="name" id="discussion__comment_name" size="50" tabindex="1" /> 414 </label> 415 </div> 416 <div class="comment_mail"> 417 <label class="block" for="discussion__comment_mail"> 418 <span><?php echo $lang['email'] ?>:</span> 419 <input type="text" class="edit" name="mail" id="discussion__comment_mail" size="50" tabindex="2" /> 420 </label> 421 </div> 422 <?php 423 } 424 425 // allow entering an URL 426 if ($this->getConf('urlfield')){ 427 ?> 428 <div class="comment_url"> 429 <label class="block" for="discussion__comment_url"> 430 <span><?php echo $this->getLang('url') ?>:</span> 431 <input type="text" class="edit" name="url" id="discussion__comment_url" size="50" tabindex="3" /> 432 </label> 433 </div> 434 <?php 435 } 436 437 // allow entering an address 438 if ($this->getConf('addressfield')){ 439 ?> 440 <div class="comment_address"> 441 <label class="block" for="discussion__comment_address"> 442 <span><?php echo $this->getLang('address') ?>:</span> 443 <input type="text" class="edit" name="address" id="discussion__comment_address" size="50" tabindex="4" /> 444 </label> 445 </div> 446 <?php 447 } 448 449 // allow setting the comment date 450 if ($this->getConf('datefield') && ($INFO['perm'] == AUTH_ADMIN)){ 451 ?> 452 <div class="comment_date"> 453 <label class="block" for="discussion__comment_date"> 454 <span><?php echo $this->getLang('date') ?>:</span> 455 <input type="text" class="edit" name="date" id="discussion__comment_date" size="50" /> 456 </label> 457 </div> 458 <?php 459 } 460 461 // for saving a comment 462 } else { 463 ?> 464 <input type="hidden" name="cid" value="<?php echo $cid ?>" /> 465 <?php 466 } 467 ?> 468 <div class="comment_text"> 469 <textarea class="edit" name="text" cols="80" rows="10" id="discussion__comment_text" tabindex="5"><?php echo $raw ?></textarea> 470 </div> 471 <input class="button" type="submit" name="submit" value="<?php echo $lang['btn_save'] ?>" tabindex="6" /> 472 </div> 473 </form> 474 </div> 475 <?php 476 if ($this->getConf('usecocomment')) echo $this->_coComment(); 477 } 478 479 /** 480 * Adds a javascript to interact with coComments 481 */ 482 function _coComment(){ 483 global $ID; 484 global $conf; 485 global $INFO; 486 487 $user = $_SERVER['REMOTE_USER']; 488 489 ?> 490 <script type="text/javascript"><!--//--><![CDATA[//><!-- 491 var blogTool = "DokuWiki"; 492 var blogURL = "<?php echo DOKU_URL ?>"; 493 var blogTitle = "<?php echo $conf['title'] ?>"; 494 var postURL = "<?php echo wl($ID, '', true) ?>"; 495 var postTitle = "<?php echo tpl_pagetitle($ID, true) ?>"; 496 <?php 497 if ($user){ 498 ?> 499 var commentAuthor = "<?php echo $INFO['userinfo']['name'] ?>"; 500 <?php 501 } else { 502 ?> 503 var commentAuthorFieldName = "name"; 504 <?php 505 } 506 ?> 507 var commentAuthorLoggedIn = <?php echo ($user ? 'true' : 'false') ?>; 508 var commentFormID = "discussion__comment_form"; 509 var commentTextFieldName = "text"; 510 var commentButtonName = "submit"; 511 var cocomment_force = false; 512 //--><!]]></script> 513 <script type="text/javascript" src="http://www.cocomment.com/js/cocomment.js"> 514 </script> 515 <?php 516 } 517 518 /** 519 * General button function 520 */ 521 function _button($cid, $label, $act, $jump = false){ 522 global $ID; 523 $anchor = ($jump ? '#discussion__comment_form' : '' ); 524 525 ?> 526 <form class="button" method="post" action="<?php echo script().$anchor ?>"> 527 <div class="no"> 528 <input type="hidden" name="id" value="<?php echo $ID ?>" /> 529 <input type="hidden" name="do" value="show" /> 530 <input type="hidden" name="comment" value="<?php echo $act ?>" /> 531 <input type="hidden" name="cid" value="<?php echo $cid ?>" /> 532 <input type="submit" value="<?php echo $label ?>" class="button" title="<?php echo $label ?>" /> 533 </div> 534 </form> 535 <?php 536 return true; 537 } 538 539 /** 540 * Adds an entry to the comments changelog 541 * 542 * @author Esther Brunner <wikidesign@gmail.com> 543 * @author Ben Coburn <btcoburn@silicodon.net> 544 */ 545 function _addLogEntry($date, $id, $type = 'cc', $summary = '', $extra = ''){ 546 global $conf; 547 548 $changelog = $conf['metadir'].'/_comments.changes'; 549 550 if(!$date) $date = time(); //use current time if none supplied 551 $remote = $_SERVER['REMOTE_ADDR']; 552 $user = $_SERVER['REMOTE_USER']; 553 554 $strip = array("\t", "\n"); 555 $logline = array( 556 'date' => $date, 557 'ip' => $remote, 558 'type' => str_replace($strip, '', $type), 559 'id' => $id, 560 'user' => $user, 561 'sum' => str_replace($strip, '', $summary), 562 'extra' => str_replace($strip, '', $extra) 563 ); 564 565 // add changelog line 566 $logline = implode("\t", $logline)."\n"; 567 io_saveFile($changelog, $logline, true); //global changelog cache 568 $this->_trimRecentCommentsLog($changelog); 569 } 570 571 /** 572 * Trims the recent comments cache to the last $conf['changes_days'] recent 573 * changes or $conf['recent'] items, which ever is larger. 574 * The trimming is only done once a day. 575 * 576 * @author Ben Coburn <btcoburn@silicodon.net> 577 */ 578 function _trimRecentCommentsLog($changelog){ 579 global $conf; 580 581 if (@file_exists($changelog) && 582 (filectime($changelog) + 86400) < time() && 583 !@file_exists($changelog.'_tmp')){ 584 585 io_lock($changelog); 586 $lines = file($changelog); 587 if (count($lines)<$conf['recent']) { 588 // nothing to trim 589 io_unlock($changelog); 590 return true; 591 } 592 593 io_saveFile($changelog.'_tmp', ''); // presave tmp as 2nd lock 594 $trim_time = time() - $conf['recent_days']*86400; 595 $out_lines = array(); 596 597 for ($i=0; $i<count($lines); $i++) { 598 $log = parseChangelogLine($lines[$i]); 599 if ($log === false) continue; // discard junk 600 if ($log['date'] < $trim_time) { 601 $old_lines[$log['date'].".$i"] = $lines[$i]; // keep old lines for now (append .$i to prevent key collisions) 602 } else { 603 $out_lines[$log['date'].".$i"] = $lines[$i]; // definitely keep these lines 604 } 605 } 606 607 // sort the final result, it shouldn't be necessary, 608 // however the extra robustness in making the changelog cache self-correcting is worth it 609 ksort($out_lines); 610 $extra = $conf['recent'] - count($out_lines); // do we need extra lines do bring us up to minimum 611 if ($extra > 0) { 612 ksort($old_lines); 613 $out_lines = array_merge(array_slice($old_lines,-$extra),$out_lines); 614 } 615 616 // save trimmed changelog 617 io_saveFile($changelog.'_tmp', implode('', $out_lines)); 618 @unlink($changelog); 619 if (!rename($changelog.'_tmp', $changelog)) { 620 // rename failed so try another way... 621 io_unlock($changelog); 622 io_saveFile($changelog, implode('', $out_lines)); 623 @unlink($changelog.'_tmp'); 624 } else { 625 io_unlock($changelog); 626 } 627 return true; 628 } 629 } 630 631 /** 632 * Sends a notify mail on new comment 633 * 634 * @param array $comment data array of the new comment 635 * 636 * @author Andreas Gohr <andi@splitbrain.org> 637 * @author Esther Brunner <wikidesign@gmail.com> 638 */ 639 function _notify($comment){ 640 global $conf; 641 global $ID; 642 643 if (!$conf['subscribers']) return; //subscribers enabled? 644 $bcc = subscriber_addresslist($ID); 645 if (empty($bcc)) return; 646 $to = ''; 647 $text = io_readFile($this->localFN('subscribermail')); 648 649 $text = str_replace('@PAGE@', $ID, $text); 650 $text = str_replace('@TITLE@', $conf['title'], $text); 651 $text = str_replace('@DATE@', date($conf['dformat'], $comment['date']), $text); 652 $text = str_replace('@NAME@', $comment['name'], $text); 653 $text = str_replace('@TEXT@', $comment['raw'], $text); 654 $text = str_replace('@UNSUBSCRIBE@', wl($ID, 'do=unsubscribe', true, '&'), $text); 655 $text = str_replace('@DOKUWIKIURL@', DOKU_URL, $text); 656 657 $subject = '['.$conf['title'].'] '.$this->getLang('mail_newcomment'); 658 659 mail_send($to, $subject, $text, $conf['mailfrom'], '', $bcc); 660 } 661 662 /** 663 * Counts the number of visible comments 664 */ 665 function _count($data){ 666 $number = 0; 667 foreach ($data['comments'] as $cid => $comment){ 668 if ($comment['parent']) continue; 669 if (!$comment['show']) continue; 670 $number++; 671 $rids = $comment['replies']; 672 if (count($rids)) $number = $number + $this->_countReplies($data, $rids); 673 } 674 return $number; 675 } 676 677 function _countReplies(&$data, $rids){ 678 $number = 0; 679 foreach ($rids as $rid){ 680 if (!$data['comments'][$rid]['show']) continue; 681 $number++; 682 $rids = $data['comments'][$rid]['replies']; 683 if (count($rids)) $number = $number + $this->_countReplies($data, $rids); 684 } 685 return $number; 686 } 687 688 /** 689 * Renders the comment text 690 */ 691 function _render($raw){ 692 if ($this->getConf('wikisyntaxok')){ 693 $xhtml = $this->render($raw); 694 } else { // wiki syntax not allowed -> just encode special chars 695 $xhtml = htmlspecialchars(trim($raw)); 696 } 697 return $xhtml; 698 } 699 700 /** 701 * Checks if 'newthread' was given as action, if so we 702 * do handle the event our self and no further checking takes place 703 */ 704 function handle_act_preprocess(&$event, $param){ 705 if ($event->data != 'newthread') return; // nothing to do for us 706 707 global $ACT; 708 global $ID; 709 710 // we can handle it -> prevent others 711 $event->stopPropagation(); 712 $event->preventDefault(); 713 714 $ns = $_REQUEST['ns']; 715 $title = str_replace(':', '', $_REQUEST['title']); 716 $id = ($ns ? $ns.':' : '').cleanID($title); 717 718 // check if we are allowed to create this file 719 if (auth_quickaclcheck($id) >= AUTH_CREATE){ 720 $back = $ID; 721 $ID = $id; 722 $file = wikiFN($ID); 723 724 //check if locked by anyone - if not lock for my self 725 if (checklock($ID)){ 726 $ACT = 'locked'; 727 } else { 728 lock($ID); 729 } 730 731 // prepare the new thread file with default stuff 732 if (!@file_exists($file)){ 733 global $TEXT; 734 global $INFO; 735 global $conf; 736 737 $TEXT = pageTemplate(array($ns.':'.$title)); 738 if (!$TEXT) $TEXT = "<- [[:$back]]\n\n====== $title ======\n\n". 739 "{{gravatar>".$INFO['userinfo']['mail']." }} ". 740 "//".$INFO['userinfo']['name'].", ". 741 date($conf['dformat']).": //\n\n\n\n". 742 "~~DISCUSSION~~\n"; 743 $ACT = 'preview'; 744 } else { 745 $ACT = 'edit'; 746 } 747 } else { 748 $ACT = 'show'; 749 } 750 } 751 752} 753 754//Setup VIM: ex: et ts=4 enc=utf-8 : 755