[ Index ] |
PHP Cross Reference of MyBB |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * MyBB 1.6 4 * Copyright 2010 MyBB Group, All Rights Reserved 5 * 6 * Website: http://mybb.com 7 * License: http://mybb.com/about/license 8 * 9 * $Id$ 10 */ 11 12 define("IN_MYBB", 1); 13 define('THIS_SCRIPT', 'newreply.php'); 14 15 $templatelist = "newreply,previewpost,loginbox,changeuserbox,posticons,newreply_threadreview,newreply_threadreview_post,forumdisplay_rules,forumdisplay_rules_link,newreply_multiquote_external"; 16 $templatelist .= ",smilieinsert,smilieinsert_getmore,codebuttons,post_attachments_new,post_attachments,post_savedraftbutton,newreply_modoptions,newreply_threadreview_more,newreply_disablesmilies,postbit_online,postbit_find,postbit_pm"; 17 $templatelist .= ",postbit_www,postbit_email,postbit_reputation,postbit_warninglevel,postbit_author_user,postbit_edit,postbit_quickdelete,postbit_inlinecheck,postbit_posturl,postbit_quote,postbit_multiquote,postbit_report,postbit_ignored,postbit,post_subscription_method"; 18 $templatelist .= ",post_attachments_attachment_postinsert,post_attachments_attachment_remove,post_attachments_attachment_unapproved,post_attachments_attachment,postbit_attachments_attachment,postbit_attachments,newreply_options_signature"; 19 $templatelist .= ",member_register_regimage,member_register_regimage_recaptcha,post_captcha_hidden,post_captcha,post_captcha_recaptcha,postbit_groupimage,postbit_away,postbit_offline,postbit_avatar"; 20 $templatelist .= ",postbit_rep_button,postbit_warn,postbit_author_guest,postbit_signature,postbit_classic,postbit_attachments_thumbnails_thumbnailpostbit_attachments_images_image,postbit_attachments_attachment_unapproved"; 21 $templatelist .= ",postbit_attachments_thumbnails,postbit_attachments_images,postbit_gotopost,forumdisplay_password_wrongpass,forumdisplay_password"; 22 23 require_once "./global.php"; 24 require_once MYBB_ROOT."inc/functions_post.php"; 25 require_once MYBB_ROOT."inc/functions_user.php"; 26 require_once MYBB_ROOT."inc/class_parser.php"; 27 $parser = new postParser; 28 29 // Load global language phrases 30 $lang->load("newreply"); 31 32 // Check to see if we are missing any indexes 33 $options = array('pid', 'tid', 'replyto', 'ajax', 'action', 'attachmentaid', 'newattachment', 'updateattachment', 'attachmentaid', 'subject', 'message', 'previewpost', 'processed', 'method', 'posthash', 'rem', 'quoted_ids', 'icon'); 34 foreach($options as $option) 35 { 36 if(!isset($mybb->input[$option])) 37 { 38 $mybb->input[$option] = ''; 39 } 40 } 41 42 // Get the pid and tid and replyto from the input. 43 $tid = intval($mybb->input['tid']); 44 45 $replyto = 0; 46 if($mybb->input['replyto']) 47 { 48 $replyto = intval($mybb->input['replyto']); 49 } 50 51 // AJAX quick reply? 52 if($mybb->input['ajax']) 53 { 54 unset($mybb->input['previewpost']); 55 } 56 57 // Edit a draft post. 58 $pid = 0; 59 $editdraftpid = ''; 60 if(($mybb->input['action'] == "editdraft" || $mybb->input['action'] == "do_newreply") && $mybb->input['pid']) 61 { 62 $options = array( 63 "limit" => 1 64 ); 65 $query = $db->simple_select("posts", "*", "pid='".intval($mybb->input['pid'])."'", $options); 66 $post = $db->fetch_array($query); 67 if(!$post['pid']) 68 { 69 error($lang->error_invalidpost); 70 } 71 else if($mybb->user['uid'] != $post['uid']) 72 { 73 error($lang->error_post_noperms); 74 } 75 $pid = $post['pid']; 76 $tid = $post['tid']; 77 $editdraftpid = "<input type=\"hidden\" name=\"pid\" value=\"$pid\" />"; 78 } 79 80 // Set up $thread and $forum for later use. 81 $options = array( 82 "limit" => 1 83 ); 84 $query = $db->simple_select("threads", "*", "tid='".$tid."'"); 85 if($db->num_rows($query) == 0) 86 { 87 error($lang->error_invalidthread); 88 } 89 90 $thread = $db->fetch_array($query); 91 $fid = $thread['fid']; 92 93 // Get forum info 94 $forum = get_forum($fid); 95 if(!$forum) 96 { 97 error($lang->error_invalidforum); 98 } 99 100 // Make navigation 101 build_forum_breadcrumb($fid); 102 $thread['subject'] = htmlspecialchars_uni($thread['subject']); 103 add_breadcrumb($thread['subject'], get_thread_link($thread['tid'])); 104 add_breadcrumb($lang->nav_newreply); 105 106 $forumpermissions = forum_permissions($fid); 107 108 // See if everything is valid up to here. 109 if(isset($post) && (($post['visible'] == 0 && !is_moderator($fid)) || ($post['visible'] < 0 && $post['uid'] != $mybb->user['uid']))) 110 { 111 error($lang->error_invalidpost); 112 } 113 if(($thread['visible'] == 0 && !is_moderator($fid)) || $thread['visible'] < 0) 114 { 115 error($lang->error_invalidthread); 116 } 117 if($forum['open'] == 0 || $forum['type'] != "f") 118 { 119 error($lang->error_closedinvalidforum); 120 } 121 if($forumpermissions['canview'] == 0 || $forumpermissions['canpostreplys'] == 0 || $mybb->user['suspendposting'] == 1) 122 { 123 error_no_permission(); 124 } 125 126 if(isset($forumpermissions['canonlyviewownthreads']) && $forumpermissions['canonlyviewownthreads'] == 1 && $thread['uid'] != $mybb->user['uid']) 127 { 128 error_no_permission(); 129 } 130 131 // Coming from quick reply? Set some defaults 132 if($mybb->input['method'] == "quickreply") 133 { 134 if($mybb->user['subscriptionmethod'] == 1) 135 { 136 $mybb->input['postoptions']['subscriptionmethod'] = "none"; 137 } 138 else if($mybb->user['subscriptionmethod'] == 2) 139 { 140 $mybb->input['postoptions']['subscriptionmethod'] = "instant"; 141 } 142 } 143 144 // Check if this forum is password protected and we have a valid password 145 check_forum_password($forum['fid']); 146 147 if($mybb->settings['bbcodeinserter'] != 0 && $forum['allowmycode'] != 0 && (!$mybb->user['uid'] || $mybb->user['showcodebuttons'] != 0)) 148 { 149 $codebuttons = build_mycode_inserter(); 150 if($forum['allowsmilies'] != 0) 151 { 152 $smilieinserter = build_clickable_smilies(); 153 } 154 } 155 156 // Display a login box or change user box? 157 if($mybb->user['uid'] != 0) 158 { 159 eval("\$loginbox = \"".$templates->get("changeuserbox")."\";"); 160 } 161 else 162 { 163 if(!$mybb->input['previewpost'] && $mybb->input['action'] != "do_newreply") 164 { 165 $username = ''; 166 } 167 else 168 { 169 $username = htmlspecialchars_uni($mybb->input['username']); 170 } 171 eval("\$loginbox = \"".$templates->get("loginbox")."\";"); 172 } 173 174 // Check to see if the thread is closed, and if the user is a mod. 175 if(!is_moderator($fid, "caneditposts")) 176 { 177 if($thread['closed'] == 1) 178 { 179 error($lang->redirect_threadclosed); 180 } 181 } 182 183 // Is the currently logged in user a moderator of this forum? 184 if(is_moderator($fid)) 185 { 186 $ismod = true; 187 } 188 else 189 { 190 $ismod = false; 191 } 192 193 // No weird actions allowed, show new reply form if no regular action. 194 if($mybb->input['action'] != "do_newreply" && $mybb->input['action'] != "editdraft") 195 { 196 $mybb->input['action'] = "newreply"; 197 } 198 199 // Even if we are previewing, still show the new reply form. 200 if($mybb->input['previewpost']) 201 { 202 $mybb->input['action'] = "newreply"; 203 } 204 205 // Setup a unique posthash for attachment management 206 if(!$mybb->input['posthash'] && !$pid) 207 { 208 $mybb->input['posthash'] = md5($thread['tid'].$mybb->user['uid'].random_str()); 209 } 210 211 if((empty($_POST) && empty($_FILES)) && $mybb->input['processed'] == '1') 212 { 213 error($lang->error_cannot_upload_php_post); 214 } 215 216 $errors = array(); 217 $maximageserror = $attacherror = ''; 218 if(!$mybb->input['attachmentaid'] && ($mybb->input['newattachment'] || $mybb->input['updateattachment'] || ($mybb->input['action'] == "do_newreply" && $mybb->input['submit'] && $_FILES['attachment']))) 219 { 220 // Verify incoming POST request 221 verify_post_check($mybb->input['my_post_key']); 222 223 if($pid) 224 { 225 $attachwhere = "pid='{$pid}'"; 226 } 227 else 228 { 229 $attachwhere = "posthash='".$db->escape_string($mybb->input['posthash'])."'"; 230 } 231 $query = $db->simple_select("attachments", "COUNT(aid) as numattachs", $attachwhere); 232 $attachcount = $db->fetch_field($query, "numattachs"); 233 234 // If there's an attachment, check it and upload it 235 if($_FILES['attachment']['size'] > 0 && $forumpermissions['canpostattachments'] != 0 && ($mybb->settings['maxattachments'] == 0 || $attachcount < $mybb->settings['maxattachments'])) 236 { 237 require_once MYBB_ROOT."inc/functions_upload.php"; 238 239 $update_attachment = false; 240 if($mybb->input['updateattachment']) 241 { 242 $update_attachment = true; 243 } 244 $attachedfile = upload_attachment($_FILES['attachment'], $update_attachment); 245 } 246 247 if($attachedfile['error']) 248 { 249 $errors[] = $attachedfile['error']; 250 $mybb->input['action'] = "newreply"; 251 } 252 253 if(!$mybb->input['submit']) 254 { 255 $editdraftpid = "<input type=\"hidden\" name=\"pid\" value=\"$pid\" />"; 256 $mybb->input['action'] = "newreply"; 257 } 258 } 259 260 // Remove an attachment. 261 if($mybb->input['attachmentaid'] && $mybb->input['attachmentact'] == "remove") 262 { 263 // Verify incoming POST request 264 verify_post_check($mybb->input['my_post_key']); 265 266 require_once MYBB_ROOT."inc/functions_upload.php"; 267 remove_attachment($pid, $mybb->input['posthash'], $mybb->input['attachmentaid']); 268 if(!$mybb->input['submit']) 269 { 270 $editdraftpid = "<input type=\"hidden\" name=\"pid\" value=\"$pid\" />"; 271 $mybb->input['action'] = "newreply"; 272 } 273 } 274 275 $reply_errors = $quoted_ids = ''; 276 $hide_captcha = false; 277 278 // Check the maximum posts per day for this user 279 if($mybb->settings['maxposts'] > 0 && $mybb->usergroup['cancp'] != 1) 280 { 281 $daycut = TIME_NOW-60*60*24; 282 $query = $db->simple_select("posts", "COUNT(*) AS posts_today", "uid='{$mybb->user['uid']}' AND visible='1' AND dateline>{$daycut}"); 283 $post_count = $db->fetch_field($query, "posts_today"); 284 if($post_count >= $mybb->settings['maxposts']) 285 { 286 $lang->error_maxposts = $lang->sprintf($lang->error_maxposts, $mybb->settings['maxposts']); 287 error($lang->error_maxposts); 288 } 289 } 290 291 if($mybb->input['action'] == "do_newreply" && $mybb->request_method == "post") 292 { 293 // Verify incoming POST request 294 verify_post_check($mybb->input['my_post_key']); 295 296 $plugins->run_hooks("newreply_do_newreply_start"); 297 298 // If this isn't a logged in user, then we need to do some special validation. 299 if($mybb->user['uid'] == 0) 300 { 301 $username = htmlspecialchars_uni($mybb->input['username']); 302 303 // Check if username exists. 304 if(username_exists($mybb->input['username'])) 305 { 306 // If it does throw back "username is taken" 307 error($lang->error_usernametaken); 308 } 309 // This username does not exist. 310 else 311 { 312 // If they didn't specify a username then give them "Guest" 313 if(!$mybb->input['username']) 314 { 315 $username = $lang->guest; 316 } 317 // Otherwise use the name they specified. 318 else 319 { 320 $username = htmlspecialchars_uni($mybb->input['username']); 321 } 322 $uid = 0; 323 } 324 } 325 // This user is logged in. 326 else 327 { 328 $username = $mybb->user['username']; 329 $uid = $mybb->user['uid']; 330 } 331 332 // Attempt to see if this post is a duplicate or not 333 if($uid > 0) 334 { 335 $user_check = "p.uid='{$uid}'"; 336 } 337 else 338 { 339 $user_check = "p.ipaddress='".$db->escape_string($session->ipaddress)."'"; 340 } 341 if(!$mybb->input['savedraft']) 342 { 343 $query = $db->simple_select("posts p", "p.pid, p.visible", "{$user_check} AND p.tid='{$thread['tid']}' AND p.subject='".$db->escape_string($mybb->input['subject'])."' AND p.message='".$db->escape_string($mybb->input['message'])."' AND p.visible != '-2' AND p.dateline>".(TIME_NOW-600)); 344 $duplicate_check = $db->fetch_field($query, "pid"); 345 if($duplicate_check) 346 { 347 error($lang->error_post_already_submitted); 348 } 349 } 350 351 // Set up posthandler. 352 require_once MYBB_ROOT."inc/datahandlers/post.php"; 353 $posthandler = new PostDataHandler("insert"); 354 355 // Set the post data that came from the input to the $post array. 356 $post = array( 357 "tid" => $mybb->input['tid'], 358 "replyto" => $mybb->input['replyto'], 359 "fid" => $thread['fid'], 360 "subject" => $mybb->input['subject'], 361 "icon" => $mybb->input['icon'], 362 "uid" => $uid, 363 "username" => $username, 364 "message" => $mybb->input['message'], 365 "ipaddress" => get_ip(), 366 "posthash" => $mybb->input['posthash'] 367 ); 368 369 if($mybb->input['pid']) 370 { 371 $post['pid'] = $mybb->input['pid']; 372 } 373 374 // Are we saving a draft post? 375 if($mybb->input['savedraft'] && $mybb->user['uid']) 376 { 377 $post['savedraft'] = 1; 378 } 379 else 380 { 381 $post['savedraft'] = 0; 382 } 383 384 // Set up the post options from the input. 385 $post['options'] = array( 386 "signature" => $mybb->input['postoptions']['signature'], 387 "subscriptionmethod" => $mybb->input['postoptions']['subscriptionmethod'], 388 "disablesmilies" => $mybb->input['postoptions']['disablesmilies'] 389 ); 390 391 // Apply moderation options if we have them 392 $post['modoptions'] = $mybb->input['modoptions']; 393 394 $posthandler->set_data($post); 395 396 // Now let the post handler do all the hard work. 397 $valid_post = $posthandler->validate_post(); 398 399 $post_errors = array(); 400 // Fetch friendly error messages if this is an invalid post 401 if(!$valid_post) 402 { 403 $post_errors = $posthandler->get_friendly_errors(); 404 } 405 406 // Mark thread as read 407 require_once MYBB_ROOT."inc/functions_indicators.php"; 408 mark_thread_read($tid, $fid); 409 410 // Check captcha image 411 if($mybb->settings['captchaimage'] && !$mybb->user['uid']) 412 { 413 require_once MYBB_ROOT.'inc/class_captcha.php'; 414 $post_captcha = new captcha(false, "post_captcha"); 415 416 if($post_captcha->validate_captcha() == false) 417 { 418 // CAPTCHA validation failed 419 foreach($post_captcha->get_errors() as $error) 420 { 421 $post_errors[] = $error; 422 } 423 } 424 else 425 { 426 $hide_captcha = true; 427 } 428 429 if($mybb->input['ajax']) 430 { 431 if($post_captcha->type == 1) 432 { 433 $randomstr = random_str(5); 434 $imagehash = md5(random_str(12)); 435 436 $imagearray = array( 437 "imagehash" => $imagehash, 438 "imagestring" => $randomstr, 439 "dateline" => TIME_NOW 440 ); 441 442 $db->insert_query("captcha", $imagearray); 443 444 header("Content-type: text/html; charset={$lang->settings['charset']}"); 445 echo "<captcha>$imagehash"; 446 447 if($hide_captcha) 448 { 449 echo "|$randomstr"; 450 } 451 452 echo "</captcha>"; 453 } 454 else if($post_captcha->type == 2) 455 { 456 header("Content-type: text/html; charset={$lang->settings['charset']}"); 457 echo "<captcha>reload</captcha>"; 458 } 459 } 460 } 461 462 // One or more errors returned, fetch error list and throw to newreply page 463 if(count($post_errors) > 0) 464 { 465 $reply_errors = inline_error($post_errors); 466 $mybb->input['action'] = "newreply"; 467 } 468 else 469 { 470 $postinfo = $posthandler->insert_post(); 471 $pid = $postinfo['pid']; 472 $visible = $postinfo['visible']; 473 474 // Invalidate solved captcha 475 if($mybb->settings['captchaimage'] && !$mybb->user['uid']) 476 { 477 $post_captcha->invalidate_captcha(); 478 } 479 480 // Deciding the fate 481 if($visible == -2) 482 { 483 // Draft post 484 $lang->redirect_newreply = $lang->draft_saved; 485 $url = "usercp.php?action=drafts"; 486 } 487 elseif($visible == 1) 488 { 489 // Visible post 490 $lang->redirect_newreply .= $lang->redirect_newreply_post; 491 $url = get_post_link($pid, $tid)."#pid{$pid}"; 492 } 493 else 494 { 495 // Moderated post 496 if($mybb->user['showredirect'] != 1) 497 { 498 // User must see moderation notice, regardless of redirect settings 499 $mybb->user['showredirect'] = 1; 500 } 501 502 $lang->redirect_newreply .= '<br />'.$lang->redirect_newreply_moderation; 503 $url = get_thread_link($tid); 504 } 505 506 // Mark any quoted posts so they're no longer selected - attempts to maintain those which weren't selected 507 if($mybb->input['quoted_ids'] && $mybb->cookies['multiquote'] && $mybb->settings['multiquote'] != 0) 508 { 509 // We quoted all posts - remove the entire cookie 510 if($mybb->input['quoted_ids'] == "all") 511 { 512 my_unsetcookie("multiquote"); 513 } 514 // Only quoted a few - attempt to remove them from the cookie 515 else 516 { 517 $quoted_ids = explode("|", $mybb->input['quoted_ids']); 518 $multiquote = explode("|", $mybb->cookies['multiquote']); 519 if(is_array($multiquote) && is_array($quoted_ids)) 520 { 521 foreach($multiquote as $key => $quoteid) 522 { 523 // If this ID was quoted, remove it from the multiquote list 524 if(in_array($quoteid, $quoted_ids)) 525 { 526 unset($multiquote[$key]); 527 } 528 } 529 // Still have an array - set the new cookie 530 if(is_array($multiquote)) 531 { 532 $new_multiquote = implode(",", $multiquote); 533 my_setcookie("multiquote", $new_multiquote); 534 } 535 // Otherwise, unset it 536 else 537 { 538 my_unsetcookie("multiquote"); 539 } 540 } 541 } 542 } 543 544 $plugins->run_hooks("newreply_do_newreply_end"); 545 546 // This was a post made via the ajax quick reply - we need to do some special things here 547 if($mybb->input['ajax']) 548 { 549 // Visible post 550 if($visible == 1) 551 { 552 // Set post counter 553 if($ismod == true) 554 { 555 $postcounter = $thread['replies'] + $thread['unapprovedposts'] + 1; 556 } 557 else 558 { 559 $postcounter = $thread['replies'] + 1; 560 } 561 562 // Was there a new post since we hit the quick reply button? 563 if($mybb->input['lastpid']) 564 { 565 $query = $db->simple_select("posts", "pid", "tid = '{$tid}' AND pid != '{$pid}'", array("order_by" => "pid", "order_dir" => "desc")); 566 $new_post = $db->fetch_array($query); 567 if($new_post['pid'] != $mybb->input['lastpid']) 568 { 569 redirect(get_thread_link($tid, 0, "lastpost")); 570 } 571 } 572 573 // Lets see if this post is on the same page as the one we're viewing or not 574 // if it isn't, redirect us 575 if($perpage > 0 && (($postcounter) % $perpage) == 0) 576 { 577 $post_page = ($postcounter) / $mybb->settings['postsperpage']; 578 } 579 else 580 { 581 $post_page = intval(($postcounter) / $mybb->settings['postsperpage']) + 1; 582 } 583 584 if($mybb->input['from_page'] && $post_page > $mybb->input['from_page']) 585 { 586 redirect(get_thread_link($tid, 0, "lastpost")); 587 exit; 588 } 589 590 // Return the post HTML and display it inline 591 $query = $db->query(" 592 SELECT u.*, u.username AS userusername, p.*, f.*, eu.username AS editusername 593 FROM ".TABLE_PREFIX."posts p 594 LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid) 595 LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid) 596 LEFT JOIN ".TABLE_PREFIX."users eu ON (eu.uid=p.edituid) 597 WHERE p.pid='{$pid}' 598 "); 599 $post = $db->fetch_array($query); 600 601 // Now lets fetch all of the attachments for this post 602 $query = $db->simple_select("attachments", "*", "pid='{$pid}'"); 603 while($attachment = $db->fetch_array($query)) 604 { 605 $attachcache[$attachment['pid']][$attachment['aid']] = $attachment; 606 } 607 608 // Establish altbg - may seem like this is backwards, but build_postbit reverses it 609 if(($postcounter - $mybb->settings['postsperpage']) % 2 != 0) 610 { 611 $altbg = "trow1"; 612 } 613 else 614 { 615 $altbg = "trow2"; 616 } 617 618 $charset = "UTF-8"; 619 if($lang->settings['charset']) 620 { 621 $charset = $lang->settings['charset']; 622 } 623 624 require_once MYBB_ROOT."inc/functions_post.php"; 625 $pid = $post['pid']; 626 $post = build_postbit($post); 627 628 header("Content-type: text/plain; charset={$charset}"); 629 echo $post; 630 631 // Build a new posthash incase the user wishes to quick reply again 632 $new_posthash = md5($mybb->user['uid'].random_str()); 633 echo "<script type=\"text/javascript\">\n"; 634 echo "var hash = document.getElementById('posthash'); if(hash) { hash.value = '{$new_posthash}'; }\n"; 635 echo "if(typeof(inlineModeration) != 'undefined') { Event.observe($('inlinemod_{$pid}'), 'click', inlineModeration.checkItem); }\n"; 636 echo "</script>\n"; 637 exit; 638 } 639 // Post is in the moderation queue 640 else 641 { 642 redirect(get_thread_link($tid, 0, "lastpost"), $lang->redirect_newreply_moderation); 643 exit; 644 } 645 } 646 else 647 { 648 $lang->redirect_newreply .= $lang->sprintf($lang->redirect_return_thread, get_forum_link($fid)); 649 redirect($url, $lang->redirect_newreply); 650 exit; 651 } 652 } 653 } 654 655 // Show the newreply form. 656 if($mybb->input['action'] == "newreply" || $mybb->input['action'] == "editdraft") 657 { 658 $plugins->run_hooks("newreply_start"); 659 660 $quote_ids = $multiquote_external = ''; 661 // If this isn't a preview and we're not editing a draft, then handle quoted posts 662 if(!$mybb->input['previewpost'] && !$reply_errors && $mybb->input['action'] != "editdraft" && !$mybb->input['attachmentaid'] && !$mybb->input['newattachment'] && !$mybb->input['updateattachment'] && !$mybb->input['rem']) 663 { 664 $message = ''; 665 $quoted_posts = array(); 666 // Handle multiquote 667 if(isset($mybb->cookies['multiquote']) && $mybb->settings['multiquote'] != 0) 668 { 669 $multiquoted = explode("|", $mybb->cookies['multiquote']); 670 foreach($multiquoted as $post) 671 { 672 $quoted_posts[$post] = intval($post); 673 } 674 } 675 // Handle incoming 'quote' button 676 if($replyto) 677 { 678 $quoted_posts[$replyto] = $replyto; 679 } 680 681 // Quoting more than one post - fetch them 682 if(count($quoted_posts) > 0) 683 { 684 $external_quotes = 0; 685 $quoted_posts = implode(",", $quoted_posts); 686 $unviewable_forums = get_unviewable_forums(); 687 if($unviewable_forums) 688 { 689 $unviewable_forums = "AND t.fid NOT IN ({$unviewable_forums})"; 690 } 691 if(is_moderator($fid)) 692 { 693 $visible_where = "AND p.visible != 2"; 694 } 695 else 696 { 697 $visible_where = "AND p.visible > 0"; 698 } 699 700 require_once MYBB_ROOT."inc/functions_posting.php"; 701 $query = $db->query(" 702 SELECT p.subject, p.message, p.pid, p.tid, p.username, p.dateline, u.username AS userusername 703 FROM ".TABLE_PREFIX."posts p 704 LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid) 705 LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid) 706 WHERE p.pid IN ($quoted_posts) {$unviewable_forums} {$visible_where} 707 "); 708 $load_all = intval($mybb->input['load_all_quotes']); 709 while($quoted_post = $db->fetch_array($query)) 710 { 711 // Only show messages for the current thread 712 if($quoted_post['tid'] == $tid || $load_all == 1) 713 { 714 // If this post was the post for which a quote button was clicked, set the subject 715 if($pid == $quoted_post['pid']) 716 { 717 $subject = preg_replace('#RE:\s?#i', '', $quoted_post['subject']); 718 // Subject too long? Shorten it to avoid error message 719 if(my_strlen($subject) > 85) 720 { 721 $subject = my_substr($subject, 0, 82).'...'; 722 } 723 $subject = "RE: ".$subject; 724 } 725 $message .= parse_quoted_message($quoted_post); 726 $quoted_ids[] = $quoted_post['pid']; 727 } 728 // Count the rest 729 else 730 { 731 ++$external_quotes; 732 } 733 } 734 if($mybb->settings['maxquotedepth'] != '0') 735 { 736 $message = remove_message_quotes($message); 737 } 738 if($external_quotes > 0) 739 { 740 if($external_quotes == 1) 741 { 742 $multiquote_text = $lang->multiquote_external_one; 743 $multiquote_deselect = $lang->multiquote_external_one_deselect; 744 $multiquote_quote = $lang->multiquote_external_one_quote; 745 } 746 else 747 { 748 $multiquote_text = $lang->sprintf($lang->multiquote_external, $external_quotes); 749 $multiquote_deselect = $lang->multiquote_external_deselect; 750 $multiquote_quote = $lang->multiquote_external_quote; 751 } 752 eval("\$multiquote_external = \"".$templates->get("newreply_multiquote_external")."\";"); 753 } 754 if(is_array($quoted_ids) && count($quoted_ids) > 0) 755 { 756 $quoted_ids = implode("|", $quoted_ids); 757 } 758 } 759 } 760 761 if($mybb->input['quoted_ids']) 762 { 763 $quoted_ids = htmlspecialchars_uni($mybb->input['quoted_ids']); 764 } 765 766 if($mybb->input['previewpost']) 767 { 768 $previewmessage = $mybb->input['message']; 769 } 770 if(!$message) 771 { 772 $message = $mybb->input['message']; 773 } 774 $message = htmlspecialchars_uni($message); 775 776 // Set up the post options. 777 if($mybb->input['previewpost'] || $reply_errors != '') 778 { 779 $postoptions = $mybb->input['postoptions']; 780 $postoptions_subscriptionmethod_dont = $postoptions_subscriptionmethod_none = $postoptions_subscriptionmethod_instant = ''; 781 782 if($postoptions['signature'] == 1) 783 { 784 $postoptionschecked['signature'] = " checked=\"checked\""; 785 } 786 if($postoptions['subscriptionmethod'] == "none") 787 { 788 $postoptions_subscriptionmethod_none = "checked=\"checked\""; 789 } 790 else if($postoptions['subscriptionmethod'] == "instant") 791 { 792 $postoptions_subscriptionmethod_instant = "checked=\"checked\""; 793 } 794 else 795 { 796 $postoptions_subscriptionmethod_dont = "checked=\"checked\""; 797 } 798 if($postoptions['disablesmilies'] == 1) 799 { 800 $postoptionschecked['disablesmilies'] = " checked=\"checked\""; 801 } 802 $subject = $mybb->input['subject']; 803 } 804 elseif($mybb->input['action'] == "editdraft" && $mybb->user['uid']) 805 { 806 $postoptionschecked = array('signature' => '', 'disablesmilies' => ''); 807 $postoptions_subscriptionmethod_dont = $postoptions_subscriptionmethod_none = $postoptions_subscriptionmethod_instant = ''; 808 809 $message = htmlspecialchars_uni($post['message']); 810 $subject = $post['subject']; 811 if($post['includesig'] != 0) 812 { 813 $postoptionschecked['signature'] = " checked=\"checked\""; 814 } 815 if($post['smilieoff'] == 1) 816 { 817 $postoptionschecked['disablesmilies'] = " checked=\"checked\""; 818 } 819 if($postoptions['subscriptionmethod'] == "none") 820 { 821 $postoptions_subscriptionmethod_none = "checked=\"checked\""; 822 } 823 else if($postoptions['subscriptionmethod'] == "instant") 824 { 825 $postoptions_subscriptionmethod_instant = "checked=\"checked\""; 826 } 827 else 828 { 829 $postoptions_subscriptionmethod_dont = "checked=\"checked\""; 830 } 831 $mybb->input['icon'] = $post['icon']; 832 } 833 else 834 { 835 $postoptionschecked = array('signature' => '', 'disablesmilies' => ''); 836 $postoptions_subscriptionmethod_dont = $postoptions_subscriptionmethod_none = $postoptions_subscriptionmethod_instant = ''; 837 838 if($mybb->user['signature'] != '') 839 { 840 $postoptionschecked['signature'] = " checked=\"checked\""; 841 } 842 if($mybb->user['subscriptionmethod'] == 1) 843 { 844 $postoptions_subscriptionmethod_none = "checked=\"checked\""; 845 } 846 else if($mybb->user['subscriptionmethod'] == 2) 847 { 848 $postoptions_subscriptionmethod_instant = "checked=\"checked\""; 849 } 850 else 851 { 852 $postoptions_subscriptionmethod_dont = "checked=\"checked\""; 853 } 854 } 855 856 if($forum['allowpicons'] != 0) 857 { 858 $posticons = get_post_icons(); 859 } 860 861 // No subject? 862 if(!isset($subject)) 863 { 864 if($mybb->input['subject']) 865 { 866 $subject = $mybb->input['subject']; 867 } 868 else 869 { 870 $subject = $thread['subject']; 871 } 872 } 873 874 // Preview a post that was written. 875 $preview = ''; 876 if($mybb->input['previewpost']) 877 { 878 // Set up posthandler. 879 require_once MYBB_ROOT."inc/datahandlers/post.php"; 880 $posthandler = new PostDataHandler("insert"); 881 882 // Set the post data that came from the input to the $post array. 883 $post = array( 884 "tid" => $mybb->input['tid'], 885 "replyto" => $mybb->input['replyto'], 886 "fid" => $thread['fid'], 887 "subject" => $mybb->input['subject'], 888 "icon" => $mybb->input['icon'], 889 "uid" => $uid, 890 "username" => $username, 891 "message" => $mybb->input['message'], 892 "ipaddress" => get_ip(), 893 "posthash" => $mybb->input['posthash'] 894 ); 895 896 if($mybb->input['pid']) 897 { 898 $post['pid'] = $mybb->input['pid']; 899 } 900 901 $posthandler->set_data($post); 902 903 // Now let the post handler do all the hard work. 904 $valid_post = $posthandler->verify_message(); 905 $valid_subject = $posthandler->verify_subject(); 906 907 $post_errors = array(); 908 // Fetch friendly error messages if this is an invalid post 909 if(!$valid_post || !$valid_subject) 910 { 911 $post_errors = $posthandler->get_friendly_errors(); 912 } 913 914 // One or more errors returned, fetch error list and throw to newreply page 915 if(count($post_errors) > 0) 916 { 917 $reply_errors = inline_error($post_errors); 918 } 919 else 920 { 921 $quote_ids = htmlspecialchars_uni($mybb->input['quote_ids']); 922 if(!$mybb->input['username']) 923 { 924 $mybb->input['username'] = $lang->guest; 925 } 926 $mybb->input['icon'] = intval($mybb->input['icon']); 927 $query = $db->query(" 928 SELECT u.*, f.* 929 FROM ".TABLE_PREFIX."users u 930 LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid) 931 WHERE u.uid='".$mybb->user['uid']."' 932 "); 933 $post = $db->fetch_array($query); 934 if(!$mybb->user['uid'] || !$post['username']) 935 { 936 $post['username'] = $mybb->input['username']; 937 } 938 else 939 { 940 $post['userusername'] = $mybb->user['username']; 941 $post['username'] = $mybb->user['username']; 942 } 943 $post['message'] = $previewmessage; 944 $post['subject'] = $subject; 945 $post['icon'] = $mybb->input['icon']; 946 $post['smilieoff'] = $postoptions['disablesmilies']; 947 $post['dateline'] = TIME_NOW; 948 $post['includesig'] = $mybb->input['postoptions']['signature']; 949 if($post['includesig'] != 1) 950 { 951 $post['includesig'] = 0; 952 } 953 954 // Fetch attachments assigned to this post. 955 if($mybb->input['pid']) 956 { 957 $attachwhere = "pid='".intval($mybb->input['pid'])."'"; 958 } 959 else 960 { 961 $attachwhere = "posthash='".$db->escape_string($mybb->input['posthash'])."'"; 962 } 963 964 $query = $db->simple_select("attachments", "*", $attachwhere); 965 while($attachment = $db->fetch_array($query)) 966 { 967 $attachcache[0][$attachment['aid']] = $attachment; 968 } 969 970 $postbit = build_postbit($post, 1); 971 eval("\$preview = \"".$templates->get("previewpost")."\";"); 972 } 973 } 974 975 $subject = htmlspecialchars_uni($parser->parse_badwords($subject)); 976 977 if(!$pid && !$mybb->input['previewpost']) 978 { 979 $subject = $thread['subject']; 980 // Subject too long? Shorten it to avoid error message 981 if(my_strlen($subject) > 85) 982 { 983 $subject = my_substr($subject, 0, 82).'...'; 984 } 985 $subject = "RE: ".$subject; 986 } 987 988 $posthash = htmlspecialchars_uni($mybb->input['posthash']); 989 990 // Do we have attachment errors? 991 if(count($errors) > 0) 992 { 993 $reply_errors = inline_error($errors); 994 } 995 996 // Get a listing of the current attachments. 997 if($forumpermissions['canpostattachments'] != 0) 998 { 999 $attachcount = 0; 1000 if($pid) 1001 { 1002 $attachwhere = "pid='$pid'"; 1003 } 1004 else 1005 { 1006 $attachwhere = "posthash='".$db->escape_string($posthash)."'"; 1007 } 1008 $attachments = ''; 1009 $query = $db->simple_select("attachments", "*", $attachwhere); 1010 while($attachment = $db->fetch_array($query)) 1011 { 1012 $attachment['size'] = get_friendly_size($attachment['filesize']); 1013 $attachment['icon'] = get_attachment_icon(get_extension($attachment['filename'])); 1014 $attachment['filename'] = htmlspecialchars_uni($attachment['filename']); 1015 1016 if($mybb->settings['bbcodeinserter'] != 0 && $forum['allowmycode'] != 0 && (!$mybb->user['uid'] || $mybb->user['showcodebuttons'] != 0)) 1017 { 1018 eval("\$postinsert = \"".$templates->get("post_attachments_attachment_postinsert")."\";"); 1019 } 1020 1021 eval("\$attach_rem_options = \"".$templates->get("post_attachments_attachment_remove")."\";"); 1022 1023 if($attachment['visible'] != 1) 1024 { 1025 eval("\$attachments .= \"".$templates->get("post_attachments_attachment_unapproved")."\";"); 1026 } 1027 else 1028 { 1029 eval("\$attachments .= \"".$templates->get("post_attachments_attachment")."\";"); 1030 } 1031 $attachcount++; 1032 } 1033 1034 $noshowattach = ''; 1035 $query = $db->simple_select("attachments", "SUM(filesize) AS ausage", "uid='".$mybb->user['uid']."'"); 1036 $usage = $db->fetch_array($query); 1037 1038 if($usage['ausage'] > ($mybb->usergroup['attachquota']*1024) && $mybb->usergroup['attachquota'] != 0) 1039 { 1040 $noshowattach = 1; 1041 } 1042 1043 if($mybb->usergroup['attachquota'] == 0) 1044 { 1045 $friendlyquota = $lang->unlimited; 1046 } 1047 else 1048 { 1049 $friendlyquota = get_friendly_size($mybb->usergroup['attachquota']*1024); 1050 } 1051 1052 $friendlyusage = get_friendly_size($usage['ausage']); 1053 $lang->attach_quota = $lang->sprintf($lang->attach_quota, $friendlyusage, $friendlyquota); 1054 1055 if($mybb->settings['maxattachments'] == 0 || ($mybb->settings['maxattachments'] != 0 && $attachcount < $mybb->settings['maxattachments']) && !$noshowattach) 1056 { 1057 eval("\$newattach = \"".$templates->get("post_attachments_new")."\";"); 1058 } 1059 1060 eval("\$attachbox = \"".$templates->get("post_attachments")."\";"); 1061 } 1062 1063 // If the user is logged in, provide a save draft button. 1064 if($mybb->user['uid']) 1065 { 1066 eval("\$savedraftbutton = \"".$templates->get("post_savedraftbutton", 1, 0)."\";"); 1067 } 1068 1069 // Show captcha image for guests if enabled 1070 $captcha = ''; 1071 if($mybb->settings['captchaimage'] && !$mybb->user['uid']) 1072 { 1073 $correct = false; 1074 require_once MYBB_ROOT.'inc/class_captcha.php'; 1075 $post_captcha = new captcha(false, "post_captcha"); 1076 1077 if($mybb->input['previewpost'] || $hide_captcha == true && $post_captcha->type == 1) 1078 { 1079 // If previewing a post - check their current captcha input - if correct, hide the captcha input area 1080 // ... but only if it's a default one, reCAPTCHAs must be filled in every time due to draconian limits 1081 if($post_captcha->validate_captcha() == true) 1082 { 1083 $correct = true; 1084 1085 // Generate a hidden list of items for our captcha 1086 $captcha = $post_captcha->build_hidden_captcha(); 1087 } 1088 } 1089 1090 if(!$correct) 1091 { 1092 if($post_captcha->type == 1) 1093 { 1094 $post_captcha->build_captcha(); 1095 } 1096 elseif($post_captcha->type == 2) 1097 { 1098 $post_captcha->build_recaptcha(); 1099 } 1100 1101 if($post_captcha->html) 1102 { 1103 $captcha = $post_captcha->html; 1104 } 1105 } 1106 elseif($correct && $post_captcha->type == 2) 1107 { 1108 $post_captcha->build_recaptcha(); 1109 1110 if($post_captcha->html) 1111 { 1112 $captcha = $post_captcha->html; 1113 } 1114 } 1115 } 1116 1117 if($mybb->settings['threadreview'] != 0) 1118 { 1119 if(!$mybb->settings['postsperpage']) 1120 { 1121 $mybb->settings['postperpage'] = 20; 1122 } 1123 1124 if(is_moderator($fid)) 1125 { 1126 $visibility = "(visible='1' OR visible='0')"; 1127 } 1128 else 1129 { 1130 $visibility = "visible='1'"; 1131 } 1132 $query = $db->simple_select("posts", "COUNT(pid) AS post_count", "tid='{$tid}' AND {$visibility}"); 1133 $numposts = $db->fetch_field($query, "post_count"); 1134 1135 if($numposts > $mybb->settings['postsperpage']) 1136 { 1137 $numposts = $mybb->settings['postsperpage']; 1138 $lang->thread_review_more = $lang->sprintf($lang->thread_review_more, $mybb->settings['postsperpage'], get_thread_link($tid)); 1139 eval("\$reviewmore = \"".$templates->get("newreply_threadreview_more")."\";"); 1140 } 1141 1142 $query = $db->simple_select("posts", "pid", "tid='{$tid}' AND {$visibility}", array("order_by" => "dateline", "order_dir" => "desc", "limit" => $mybb->settings['postsperpage'])); 1143 while($post = $db->fetch_array($query)) 1144 { 1145 $pidin[] = $post['pid']; 1146 } 1147 1148 $pidin = implode(",", $pidin); 1149 1150 // Fetch attachments 1151 $query = $db->simple_select("attachments", "*", "pid IN ($pidin)"); 1152 while($attachment = $db->fetch_array($query)) 1153 { 1154 $attachcache[$attachment['pid']][$attachment['aid']] = $attachment; 1155 } 1156 $query = $db->query(" 1157 SELECT p.*, u.username AS userusername 1158 FROM ".TABLE_PREFIX."posts p 1159 LEFT JOIN ".TABLE_PREFIX."users u ON (p.uid=u.uid) 1160 WHERE pid IN ($pidin) 1161 ORDER BY dateline DESC 1162 "); 1163 $postsdone = 0; 1164 $altbg = "trow1"; 1165 $reviewbits = ''; 1166 while($post = $db->fetch_array($query)) 1167 { 1168 if($post['userusername']) 1169 { 1170 $post['username'] = $post['userusername']; 1171 } 1172 $reviewpostdate = my_date($mybb->settings['dateformat'], $post['dateline']); 1173 $reviewposttime = my_date($mybb->settings['timeformat'], $post['dateline']); 1174 $parser_options = array( 1175 "allow_html" => $forum['allowhtml'], 1176 "allow_mycode" => $forum['allowmycode'], 1177 "allow_smilies" => $forum['allowsmilies'], 1178 "allow_imgcode" => $forum['allowimgcode'], 1179 "allow_videocode" => $forum['allowvideocode'], 1180 "me_username" => $post['username'], 1181 "filter_badwords" => 1 1182 ); 1183 if($post['smilieoff'] == 1) 1184 { 1185 $parser_options['allow_smilies'] = 0; 1186 } 1187 1188 if($post['visible'] != 1) 1189 { 1190 $altbg = "trow_shaded"; 1191 } 1192 1193 $post['message'] = $parser->parse_message($post['message'], $parser_options); 1194 get_post_attachments($post['pid'], $post); 1195 $reviewmessage = $post['message']; 1196 eval("\$reviewbits .= \"".$templates->get("newreply_threadreview_post")."\";"); 1197 if($altbg == "trow1") 1198 { 1199 $altbg = "trow2"; 1200 } 1201 else 1202 { 1203 $altbg = "trow1"; 1204 } 1205 } 1206 eval("\$threadreview = \"".$templates->get("newreply_threadreview")."\";"); 1207 } 1208 // Can we disable smilies or are they disabled already? 1209 if($forum['allowsmilies'] != 0) 1210 { 1211 eval("\$disablesmilies = \"".$templates->get("newreply_disablesmilies")."\";"); 1212 } 1213 else 1214 { 1215 $disablesmilies = "<input type=\"hidden\" name=\"postoptions[disablesmilies]\" value=\"no\" />"; 1216 } 1217 // Show the moderator options. 1218 if(is_moderator($fid)) 1219 { 1220 if($mybb->input['processed']) 1221 { 1222 $closed = intval($mybb->input['modoptions']['closethread']); 1223 $stuck = intval($mybb->input['modoptions']['stickthread']); 1224 } 1225 else 1226 { 1227 $closed = $thread['closed']; 1228 $stuck = $thread['sticky']; 1229 } 1230 1231 if($closed) 1232 { 1233 $closecheck = ' checked="checked"'; 1234 } 1235 else 1236 { 1237 $closecheck = ''; 1238 } 1239 1240 if($stuck) 1241 { 1242 $stickycheck = ' checked="checked"'; 1243 } 1244 else 1245 { 1246 $stickycheck = ''; 1247 } 1248 1249 eval("\$modoptions = \"".$templates->get("newreply_modoptions")."\";"); 1250 $bgcolor = "trow1"; 1251 } 1252 else 1253 { 1254 $bgcolor = "trow2"; 1255 } 1256 1257 // Fetch subscription select box 1258 eval("\$subscriptionmethod = \"".$templates->get("post_subscription_method")."\";"); 1259 1260 $lang->post_reply_to = $lang->sprintf($lang->post_reply_to, $thread['subject']); 1261 $lang->reply_to = $lang->sprintf($lang->reply_to, $thread['subject']); 1262 1263 // Do we have any forum rules to show for this forum? 1264 $forumrules = ''; 1265 if($forum['rulestype'] >= 2 && $forum['rules']) 1266 { 1267 if(!$forum['rulestitle']) 1268 { 1269 $forum['rulestitle'] = $lang->sprintf($lang->forum_rules, $forum['name']); 1270 } 1271 1272 if(!$parser) 1273 { 1274 require_once MYBB_ROOT.'inc/class_parser.php'; 1275 $parser = new postParser; 1276 } 1277 1278 $rules_parser = array( 1279 "allow_html" => 1, 1280 "allow_mycode" => 1, 1281 "allow_smilies" => 1, 1282 "allow_imgcode" => 1 1283 ); 1284 1285 $forum['rules'] = $parser->parse_message($forum['rules'], $rules_parser); 1286 $foruminfo = $forum; 1287 1288 if($forum['rulestype'] == 3) 1289 { 1290 eval("\$forumrules = \"".$templates->get("forumdisplay_rules")."\";"); 1291 } 1292 else if($forum['rulestype'] == 2) 1293 { 1294 eval("\$forumrules = \"".$templates->get("forumdisplay_rules_link")."\";"); 1295 } 1296 } 1297 1298 $plugins->run_hooks("newreply_end"); 1299 1300 $forum['name'] = strip_tags($forum['name']); 1301 1302 $newreply_template = $templates->get("newreply"); 1303 1304 // Hide signature option if no permission 1305 $option_signature = ''; 1306 if($mybb->usergroup['canusesig'] && !$mybb->user['suspendsignature']) 1307 { 1308 $option_signature = $templates->get('newreply_options_signature'); 1309 } 1310 eval("\$option_signature = \"".$option_signature."\";"); 1311 1312 eval("\$newreply = \"".$newreply_template."\";"); 1313 output_page($newreply); 1314 } 1315 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Oct 8 19:19:50 2013 | Cross-referenced by PHPXref 0.7.1 |