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 $style = ' style="margin-left: '.($size + 14).'px;"'; 309 } else { 310 $style = ' style="margin-left: 20px;"'; 311 } 312 313 echo '</a>'.NL; 314 if ($this->getConf('linkemail') && $comment['mail']){ 315 echo $this->email($comment['email'], $comment['name']); 316 } elseif ($comment['url']){ 317 echo $this->external_link($comment['url'], $comment['name'], 'urlextern'); 318 } else { 319 echo $comment['name']; 320 } 321 if ($comment['address']) echo ', '.htmlentities($comment['address']); 322 echo ', '.date($conf['dformat'], $comment['date']); 323 if ($comment['edited']) echo ' ('.date($conf['dformat'], $comment['edited']).')'; 324 echo ':'.NL; 325 echo '</div>'.NL; // class="comment_head" 326 327 // main comment content 328 echo '<div class="comment_body"'.($this->getConf('usegravatar') ? $style : '').'>'.NL; 329 echo $comment['xhtml'].NL; 330 echo '</div>'.NL; // class="comment_body" 331 332 333 if ($visible){ 334 // show hide/show toogle button? 335 echo '<div class="comment_buttons">'.NL; 336 if ($INFO['perm'] == AUTH_ADMIN){ 337 if (!$comment['show']) $label = $this->getLang('btn_show'); 338 else $label = $this->getLang('btn_hide'); 339 340 $this->_button($cid, $label, 'toogle'); 341 } 342 343 // show reply button? 344 if (($data['status'] == 1) && !$reply && $comment['show']) 345 $this->_button($cid, $this->getLang('btn_reply'), 'reply', true); 346 347 // show edit and delete button? 348 if ((($comment['user'] == $_SERVER['REMOTE_USER']) && ($comment['user'] != '')) 349 || ($INFO['perm'] == AUTH_ADMIN)) 350 $this->_button($cid, $lang['btn_secedit'], 'edit', true); 351 if ($INFO['perm'] == AUTH_ADMIN) 352 $this->_button($cid, $lang['btn_delete'], 'delete'); 353 echo '</div>'.NL; // class="comment_buttons" 354 } 355 356 // replies to this comment entry? 357 if (count($comment['replies'])){ 358 echo '<div class="comment_replies"'.$style.'>'.NL; 359 $visible = ($comment['show'] && $visible); 360 foreach ($comment['replies'] as $rid){ 361 $this->_print($rid, $data, $cid, $reply, $visible); 362 } 363 echo '</div>'.NL; // class="comment_replies" 364 } 365 366 if (!$comment['show']) echo '</div>'.NL; // class="comment_hidden" 367 368 // reply form 369 if ($reply == $cid){ 370 echo '<div class="comment_replies">'.NL; 371 $this->_form('', 'add', $cid); 372 echo '</div>'.NL; // class="comment_replies" 373 } 374 } 375 376 /** 377 * Outputs the comment form 378 */ 379 function _form($raw = '', $act = 'add', $cid = NULL){ 380 global $lang; 381 global $conf; 382 global $ID; 383 global $INFO; 384 385 // not for unregistered users when guest comments aren't allowed 386 if (!$_SERVER['REMOTE_USER'] && !$this->getConf('allowguests')) return false; 387 388 ?> 389 <div class="comment_form"> 390 <form id="discussion__comment_form" method="post" action="<?php echo script() ?>" accept-charset="<?php echo $lang['encoding'] ?>" onsubmit="return validate(this);"> 391 <div class="no"> 392 <input type="hidden" name="id" value="<?php echo $ID ?>" /> 393 <input type="hidden" name="do" value="show" /> 394 <input type="hidden" name="comment" value="<?php echo $act ?>" /> 395 <?php 396 397 // for adding a comment 398 if ($act == 'add'){ 399 ?> 400 <input type="hidden" name="reply" value="<?php echo $cid ?>" /> 401 <?php 402 // for registered user 403 if ($conf['useacl'] && $_SERVER['REMOTE_USER']){ 404 ?> 405 <input type="hidden" name="user" value="<?php echo $_SERVER['REMOTE_USER'] ?>" /> 406 <input type="hidden" name="name" value="<?php echo $INFO['userinfo']['name'] ?>" /> 407 <input type="hidden" name="mail" value="<?php echo $INFO['userinfo']['mail'] ?>" /> 408 <?php 409 // for guest: show name and e-mail entry fields 410 } else { 411 ?> 412 <input type="hidden" name="user" value="<?php echo clientIP() ?>" /> 413 <div class="comment_name"> 414 <label class="block" for="discussion__comment_name"> 415 <span><?php echo $lang['fullname'] ?>:</span> 416 <input type="text" class="edit" name="name" id="discussion__comment_name" size="50" tabindex="1" /> 417 </label> 418 </div> 419 <div class="comment_mail"> 420 <label class="block" for="discussion__comment_mail"> 421 <span><?php echo $lang['email'] ?>:</span> 422 <input type="text" class="edit" name="mail" id="discussion__comment_mail" size="50" tabindex="2" /> 423 </label> 424 </div> 425 <?php 426 } 427 428 // allow entering an URL 429 if ($this->getConf('urlfield')){ 430 ?> 431 <div class="comment_url"> 432 <label class="block" for="discussion__comment_url"> 433 <span><?php echo $this->getLang('url') ?>:</span> 434 <input type="text" class="edit" name="url" id="discussion__comment_url" size="50" tabindex="3" /> 435 </label> 436 </div> 437 <?php 438 } 439 440 // allow entering an address 441 if ($this->getConf('addressfield')){ 442 ?> 443 <div class="comment_address"> 444 <label class="block" for="discussion__comment_address"> 445 <span><?php echo $this->getLang('address') ?>:</span> 446 <input type="text" class="edit" name="address" id="discussion__comment_address" size="50" tabindex="4" /> 447 </label> 448 </div> 449 <?php 450 } 451 452 // allow setting the comment date 453 if ($this->getConf('datefield') && ($INFO['perm'] == AUTH_ADMIN)){ 454 ?> 455 <div class="comment_date"> 456 <label class="block" for="discussion__comment_date"> 457 <span><?php echo $this->getLang('date') ?>:</span> 458 <input type="text" class="edit" name="date" id="discussion__comment_date" size="50" /> 459 </label> 460 </div> 461 <?php 462 } 463 464 // for saving a comment 465 } else { 466 ?> 467 <input type="hidden" name="cid" value="<?php echo $cid ?>" /> 468 <?php 469 } 470 ?> 471 <div class="comment_text"> 472 <textarea class="edit" name="text" cols="80" rows="10" id="discussion__comment_text" tabindex="5"><?php echo $raw ?></textarea> 473 </div> 474 <input class="button" type="submit" name="submit" value="<?php echo $lang['btn_save'] ?>" tabindex="6" /> 475 </div> 476 </form> 477 </div> 478 <?php 479 if ($this->getConf('usecocomment')) echo $this->_coComment(); 480 } 481 482 /** 483 * Adds a javascript to interact with coComments 484 */ 485 function _coComment(){ 486 global $ID; 487 global $conf; 488 global $INFO; 489 490 $user = $_SERVER['REMOTE_USER']; 491 492 ?> 493 <script type="text/javascript"><!--//--><![CDATA[//><!-- 494 var blogTool = "DokuWiki"; 495 var blogURL = "<?php echo DOKU_URL ?>"; 496 var blogTitle = "<?php echo $conf['title'] ?>"; 497 var postURL = "<?php echo wl($ID, '', true) ?>"; 498 var postTitle = "<?php echo tpl_pagetitle($ID, true) ?>"; 499 <?php 500 if ($user){ 501 ?> 502 var commentAuthor = "<?php echo $INFO['userinfo']['name'] ?>"; 503 <?php 504 } else { 505 ?> 506 var commentAuthorFieldName = "name"; 507 <?php 508 } 509 ?> 510 var commentAuthorLoggedIn = <?php echo ($user ? 'true' : 'false') ?>; 511 var commentFormID = "discussion__comment_form"; 512 var commentTextFieldName = "text"; 513 var commentButtonName = "submit"; 514 var cocomment_force = false; 515 //--><!]]></script> 516 <script type="text/javascript" src="http://www.cocomment.com/js/cocomment.js"> 517 </script> 518 <?php 519 } 520 521 /** 522 * General button function 523 */ 524 function _button($cid, $label, $act, $jump = false){ 525 global $ID; 526 $anchor = ($jump ? '#discussion__comment_form' : '' ); 527 528 ?> 529 <form class="button" method="post" action="<?php echo script().$anchor ?>"> 530 <div class="no"> 531 <input type="hidden" name="id" value="<?php echo $ID ?>" /> 532 <input type="hidden" name="do" value="show" /> 533 <input type="hidden" name="comment" value="<?php echo $act ?>" /> 534 <input type="hidden" name="cid" value="<?php echo $cid ?>" /> 535 <input type="submit" value="<?php echo $label ?>" class="button" title="<?php echo $label ?>" /> 536 </div> 537 </form> 538 <?php 539 return true; 540 } 541 542 /** 543 * Adds an entry to the comments changelog 544 * 545 * @author Esther Brunner <wikidesign@gmail.com> 546 * @author Ben Coburn <btcoburn@silicodon.net> 547 */ 548 function _addLogEntry($date, $id, $type = 'cc', $summary = '', $extra = ''){ 549 global $conf; 550 551 $changelog = $conf['metadir'].'/_comments.changes'; 552 553 if(!$date) $date = time(); //use current time if none supplied 554 $remote = $_SERVER['REMOTE_ADDR']; 555 $user = $_SERVER['REMOTE_USER']; 556 557 $strip = array("\t", "\n"); 558 $logline = array( 559 'date' => $date, 560 'ip' => $remote, 561 'type' => str_replace($strip, '', $type), 562 'id' => $id, 563 'user' => $user, 564 'sum' => str_replace($strip, '', $summary), 565 'extra' => str_replace($strip, '', $extra) 566 ); 567 568 // add changelog line 569 $logline = implode("\t", $logline)."\n"; 570 io_saveFile($changelog, $logline, true); //global changelog cache 571 $this->_trimRecentCommentsLog($changelog); 572 } 573 574 /** 575 * Trims the recent comments cache to the last $conf['changes_days'] recent 576 * changes or $conf['recent'] items, which ever is larger. 577 * The trimming is only done once a day. 578 * 579 * @author Ben Coburn <btcoburn@silicodon.net> 580 */ 581 function _trimRecentCommentsLog($changelog){ 582 global $conf; 583 584 if (@file_exists($changelog) && 585 (filectime($changelog) + 86400) < time() && 586 !@file_exists($changelog.'_tmp')){ 587 588 io_lock($changelog); 589 $lines = file($changelog); 590 if (count($lines)<$conf['recent']) { 591 // nothing to trim 592 io_unlock($changelog); 593 return true; 594 } 595 596 io_saveFile($changelog.'_tmp', ''); // presave tmp as 2nd lock 597 $trim_time = time() - $conf['recent_days']*86400; 598 $out_lines = array(); 599 600 for ($i=0; $i<count($lines); $i++) { 601 $log = parseChangelogLine($lines[$i]); 602 if ($log === false) continue; // discard junk 603 if ($log['date'] < $trim_time) { 604 $old_lines[$log['date'].".$i"] = $lines[$i]; // keep old lines for now (append .$i to prevent key collisions) 605 } else { 606 $out_lines[$log['date'].".$i"] = $lines[$i]; // definitely keep these lines 607 } 608 } 609 610 // sort the final result, it shouldn't be necessary, 611 // however the extra robustness in making the changelog cache self-correcting is worth it 612 ksort($out_lines); 613 $extra = $conf['recent'] - count($out_lines); // do we need extra lines do bring us up to minimum 614 if ($extra > 0) { 615 ksort($old_lines); 616 $out_lines = array_merge(array_slice($old_lines,-$extra),$out_lines); 617 } 618 619 // save trimmed changelog 620 io_saveFile($changelog.'_tmp', implode('', $out_lines)); 621 @unlink($changelog); 622 if (!rename($changelog.'_tmp', $changelog)) { 623 // rename failed so try another way... 624 io_unlock($changelog); 625 io_saveFile($changelog, implode('', $out_lines)); 626 @unlink($changelog.'_tmp'); 627 } else { 628 io_unlock($changelog); 629 } 630 return true; 631 } 632 } 633 634 /** 635 * Sends a notify mail on new comment 636 * 637 * @param array $comment data array of the new comment 638 * 639 * @author Andreas Gohr <andi@splitbrain.org> 640 * @author Esther Brunner <wikidesign@gmail.com> 641 */ 642 function _notify($comment){ 643 global $conf; 644 global $ID; 645 646 if (!$conf['subscribers']) return; //subscribers enabled? 647 $bcc = subscriber_addresslist($ID); 648 if (empty($bcc)) return; 649 $to = ''; 650 $text = io_readFile($this->localFN('subscribermail')); 651 652 $text = str_replace('@PAGE@', $ID, $text); 653 $text = str_replace('@TITLE@', $conf['title'], $text); 654 $text = str_replace('@DATE@', date($conf['dformat'], $comment['date']), $text); 655 $text = str_replace('@NAME@', $comment['name'], $text); 656 $text = str_replace('@TEXT@', $comment['raw'], $text); 657 $text = str_replace('@UNSUBSCRIBE@', wl($ID, 'do=unsubscribe', true, '&'), $text); 658 $text = str_replace('@DOKUWIKIURL@', DOKU_URL, $text); 659 660 $subject = '['.$conf['title'].'] '.$this->getLang('mail_newcomment'); 661 662 mail_send($to, $subject, $text, $conf['mailfrom'], '', $bcc); 663 } 664 665 /** 666 * Counts the number of visible comments 667 */ 668 function _count($data){ 669 $number = 0; 670 foreach ($data['comments'] as $cid => $comment){ 671 if ($comment['parent']) continue; 672 if (!$comment['show']) continue; 673 $number++; 674 $rids = $comment['replies']; 675 if (count($rids)) $number = $number + $this->_countReplies($data, $rids); 676 } 677 return $number; 678 } 679 680 function _countReplies(&$data, $rids){ 681 $number = 0; 682 foreach ($rids as $rid){ 683 if (!$data['comments'][$rid]['show']) continue; 684 $number++; 685 $rids = $data['comments'][$rid]['replies']; 686 if (count($rids)) $number = $number + $this->_countReplies($data, $rids); 687 } 688 return $number; 689 } 690 691 /** 692 * Renders the comment text 693 */ 694 function _render($raw){ 695 if ($this->getConf('wikisyntaxok')){ 696 $xhtml = $this->render($raw); 697 } else { // wiki syntax not allowed -> just encode special chars 698 $xhtml = htmlspecialchars(trim($raw)); 699 } 700 return $xhtml; 701 } 702 703 /** 704 * Checks if 'newthread' was given as action, if so we 705 * do handle the event our self and no further checking takes place 706 */ 707 function handle_act_preprocess(&$event, $param){ 708 if ($event->data != 'newthread') return; // nothing to do for us 709 710 global $ACT; 711 global $ID; 712 713 // we can handle it -> prevent others 714 $event->stopPropagation(); 715 $event->preventDefault(); 716 717 $ns = $_REQUEST['ns']; 718 $title = str_replace(':', '', $_REQUEST['title']); 719 $id = ($ns ? $ns.':' : '').cleanID($title); 720 721 // check if we are allowed to create this file 722 if (auth_quickaclcheck($id) >= AUTH_CREATE){ 723 $back = $ID; 724 $ID = $id; 725 $file = wikiFN($ID); 726 727 //check if locked by anyone - if not lock for my self 728 if (checklock($ID)){ 729 $ACT = 'locked'; 730 } else { 731 lock($ID); 732 } 733 734 // prepare the new thread file with default stuff 735 if (!@file_exists($file)){ 736 global $TEXT; 737 global $INFO; 738 global $conf; 739 740 $TEXT = pageTemplate(array($ns.':'.$title)); 741 if (!$TEXT) $TEXT = "<- [[:$back]]\n\n====== $title ======\n\n". 742 "{{gravatar>".$INFO['userinfo']['mail']." }} ". 743 "//".$INFO['userinfo']['name'].", ". 744 date($conf['dformat']).": //\n\n\n\n". 745 "~~DISCUSSION~~\n"; 746 $ACT = 'preview'; 747 } else { 748 $ACT = 'edit'; 749 } 750 } else { 751 $ACT = 'show'; 752 } 753 } 754 755} 756 757//Setup VIM: ex: et ts=4 enc=utf-8 : 758