Advertisement
Guest User

newreply.php

a guest
Dec 7th, 2013
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 38.36 KB | None | 0 0
  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['postoptions']['anonymous']  == 1)
  370.     {
  371.     $post = array(
  372.         "tid" => $mybb->input['tid'],
  373.         "replyto" => $mybb->input['replyto'],
  374.         "fid" => $thread['fid'],
  375.         "subject" => $mybb->input['subject'],
  376.         "icon" => $mybb->input['icon'],
  377.         "uid" => 2,
  378.         "username" => 'Anonymous',
  379.         "message" => $mybb->input['message'],
  380.         "ipaddress" => get_ip(),
  381.         "posthash" => $mybb->input['posthash']
  382.     );
  383.     }
  384.        
  385.     if($mybb->input['pid'])
  386.     {
  387.         $post['pid'] = $mybb->input['pid'];
  388.     }
  389.  
  390.     // Are we saving a draft post?
  391.     if($mybb->input['savedraft'] && $mybb->user['uid'])
  392.     {
  393.         $post['savedraft'] = 1;
  394.     }
  395.     else
  396.     {
  397.         $post['savedraft'] = 0;
  398.     }
  399.  
  400.     // Set up the post options from the input.
  401.     $post['options'] = array(
  402.         "signature" => $mybb->input['postoptions']['signature'],
  403.         "subscriptionmethod" => $mybb->input['postoptions']['subscriptionmethod'],
  404.         "disablesmilies" => $mybb->input['postoptions']['disablesmilies']
  405.     );
  406.  
  407.     // Apply moderation options if we have them
  408.     $post['modoptions'] = $mybb->input['modoptions'];
  409.  
  410.     $posthandler->set_data($post);
  411.  
  412.     // Now let the post handler do all the hard work.
  413.     $valid_post = $posthandler->validate_post();
  414.  
  415.     $post_errors = array();
  416.     // Fetch friendly error messages if this is an invalid post
  417.     if(!$valid_post)
  418.     {
  419.         $post_errors = $posthandler->get_friendly_errors();
  420.     }
  421.  
  422.     // Mark thread as read
  423.     require_once MYBB_ROOT."inc/functions_indicators.php";
  424.     mark_thread_read($tid, $fid);
  425.  
  426.     // Check captcha image
  427.     if($mybb->settings['captchaimage'] && !$mybb->user['uid'])
  428.     {
  429.         require_once MYBB_ROOT.'inc/class_captcha.php';
  430.         $post_captcha = new captcha(false, "post_captcha");
  431.  
  432.         if($post_captcha->validate_captcha() == false)
  433.         {
  434.             // CAPTCHA validation failed
  435.             foreach($post_captcha->get_errors() as $error)
  436.             {
  437.                 $post_errors[] = $error;
  438.             }
  439.         }
  440.         else
  441.         {
  442.             $hide_captcha = true;
  443.         }
  444.  
  445.         if($mybb->input['ajax'])
  446.         {
  447.             if($post_captcha->type == 1)
  448.             {
  449.                 $randomstr = random_str(5);
  450.                 $imagehash = md5(random_str(12));
  451.  
  452.                 $imagearray = array(
  453.                     "imagehash" => $imagehash,
  454.                     "imagestring" => $randomstr,
  455.                     "dateline" => TIME_NOW
  456.                 );
  457.  
  458.                 $db->insert_query("captcha", $imagearray);
  459.  
  460.                 header("Content-type: text/html; charset={$lang->settings['charset']}");
  461.                 echo "<captcha>$imagehash";
  462.  
  463.                 if($hide_captcha)
  464.                 {
  465.                     echo "|$randomstr";
  466.                 }
  467.  
  468.                 echo "</captcha>";
  469.             }
  470.             else if($post_captcha->type == 2)
  471.             {
  472.                 header("Content-type: text/html; charset={$lang->settings['charset']}");
  473.                 echo "<captcha>reload</captcha>";
  474.             }
  475.         }
  476.     }
  477.  
  478.     // One or more errors returned, fetch error list and throw to newreply page
  479.     if(count($post_errors) > 0)
  480.     {
  481.         $reply_errors = inline_error($post_errors);
  482.         $mybb->input['action'] = "newreply";
  483.     }
  484.     else
  485.     {
  486.         $postinfo = $posthandler->insert_post();
  487.         $pid = $postinfo['pid'];
  488.         $visible = $postinfo['visible'];
  489.  
  490.         // Invalidate solved captcha
  491.         if($mybb->settings['captchaimage'] && !$mybb->user['uid'])
  492.         {
  493.             $post_captcha->invalidate_captcha();
  494.         }
  495.  
  496.         // Deciding the fate
  497.         if($visible == -2)
  498.         {
  499.             // Draft post
  500.             $lang->redirect_newreply = $lang->draft_saved;
  501.             $url = "usercp.php?action=drafts";
  502.         }
  503.         elseif($visible == 1)
  504.         {
  505.             // Visible post
  506.             $lang->redirect_newreply .= $lang->redirect_newreply_post;
  507.             $url = get_post_link($pid, $tid)."#pid{$pid}";
  508.         }
  509.         else
  510.         {
  511.             // Moderated post
  512.             if($mybb->user['showredirect'] != 1)
  513.             {
  514.                 // User must see moderation notice, regardless of redirect settings
  515.                 $mybb->user['showredirect'] = 1;
  516.             }
  517.  
  518.             $lang->redirect_newreply .= '<br />'.$lang->redirect_newreply_moderation;
  519.             $url = get_thread_link($tid);
  520.         }
  521.  
  522.         // Mark any quoted posts so they're no longer selected - attempts to maintain those which weren't selected
  523.         if($mybb->input['quoted_ids'] && $mybb->cookies['multiquote'] && $mybb->settings['multiquote'] != 0)
  524.         {
  525.             // We quoted all posts - remove the entire cookie
  526.             if($mybb->input['quoted_ids'] == "all")
  527.             {
  528.                 my_unsetcookie("multiquote");
  529.             }
  530.             // Only quoted a few - attempt to remove them from the cookie
  531.             else
  532.             {
  533.                 $quoted_ids = explode("|", $mybb->input['quoted_ids']);
  534.                 $multiquote = explode("|", $mybb->cookies['multiquote']);
  535.                 if(is_array($multiquote) && is_array($quoted_ids))
  536.                 {
  537.                     foreach($multiquote as $key => $quoteid)
  538.                     {
  539.                         // If this ID was quoted, remove it from the multiquote list
  540.                         if(in_array($quoteid, $quoted_ids))
  541.                         {
  542.                             unset($multiquote[$key]);
  543.                         }
  544.                     }
  545.                     // Still have an array - set the new cookie
  546.                     if(is_array($multiquote))
  547.                     {
  548.                         $new_multiquote = implode(",", $multiquote);
  549.                         my_setcookie("multiquote", $new_multiquote);
  550.                     }
  551.                     // Otherwise, unset it
  552.                     else
  553.                     {
  554.                         my_unsetcookie("multiquote");
  555.                     }
  556.                 }
  557.             }
  558.         }
  559.  
  560.         $plugins->run_hooks("newreply_do_newreply_end");
  561.  
  562.         // This was a post made via the ajax quick reply - we need to do some special things here
  563.         if($mybb->input['ajax'])
  564.         {
  565.             // Visible post
  566.             if($visible == 1)
  567.             {
  568.                 // Set post counter
  569.                 if($ismod == true)
  570.                 {
  571.                     $postcounter = $thread['replies'] + $thread['unapprovedposts'] + 1;
  572.                 }
  573.                 else
  574.                 {
  575.                     $postcounter = $thread['replies'] + 1;
  576.                 }
  577.  
  578.                 // Was there a new post since we hit the quick reply button?
  579.                 if($mybb->input['lastpid'])
  580.                 {
  581.                     $query = $db->simple_select("posts", "pid", "tid = '{$tid}' AND pid != '{$pid}'", array("order_by" => "pid", "order_dir" => "desc"));
  582.                     $new_post = $db->fetch_array($query);
  583.                     if($new_post['pid'] != $mybb->input['lastpid'])
  584.                     {
  585.                         redirect(get_thread_link($tid, 0, "lastpost"));
  586.                     }
  587.                 }
  588.  
  589.                 // Lets see if this post is on the same page as the one we're viewing or not
  590.                 // if it isn't, redirect us
  591.                 if($perpage > 0 && (($postcounter) % $perpage) == 0)
  592.                 {
  593.                     $post_page = ($postcounter) / $mybb->settings['postsperpage'];
  594.                 }
  595.                 else
  596.                 {
  597.                     $post_page = intval(($postcounter) / $mybb->settings['postsperpage']) + 1;
  598.                 }
  599.  
  600.                 if($mybb->input['from_page'] && $post_page > $mybb->input['from_page'])
  601.                 {
  602.                     redirect(get_thread_link($tid, 0, "lastpost"));
  603.                     exit;
  604.                 }
  605.  
  606.                 // Return the post HTML and display it inline
  607.                 $query = $db->query("
  608.                     SELECT u.*, u.username AS userusername, p.*, f.*, eu.username AS editusername
  609.                     FROM ".TABLE_PREFIX."posts p
  610.                     LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
  611.                     LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid)
  612.                     LEFT JOIN ".TABLE_PREFIX."users eu ON (eu.uid=p.edituid)
  613.                     WHERE p.pid='{$pid}'
  614.                 ");
  615.                 $post = $db->fetch_array($query);
  616.  
  617.                 // Now lets fetch all of the attachments for this post
  618.                 $query = $db->simple_select("attachments", "*", "pid='{$pid}'");
  619.                 while($attachment = $db->fetch_array($query))
  620.                 {
  621.                     $attachcache[$attachment['pid']][$attachment['aid']] = $attachment;
  622.                 }
  623.  
  624.                 // Establish altbg - may seem like this is backwards, but build_postbit reverses it
  625.                 if(($postcounter - $mybb->settings['postsperpage']) % 2 != 0)
  626.                 {
  627.                     $altbg = "trow1";
  628.                 }
  629.                 else
  630.                 {
  631.                     $altbg = "trow2";
  632.                 }
  633.  
  634.                 $charset = "UTF-8";
  635.                 if($lang->settings['charset'])
  636.                 {
  637.                     $charset = $lang->settings['charset'];
  638.                 }
  639.  
  640.                 require_once MYBB_ROOT."inc/functions_post.php";
  641.                 $pid = $post['pid'];
  642.                 $post = build_postbit($post);
  643.  
  644.                 header("Content-type: text/plain; charset={$charset}");
  645.                 echo $post;
  646.  
  647.                 // Build a new posthash incase the user wishes to quick reply again
  648.                 $new_posthash = md5($mybb->user['uid'].random_str());
  649.                 echo "<script type=\"text/javascript\">\n";
  650.                 echo "var hash = document.getElementById('posthash'); if(hash) { hash.value = '{$new_posthash}'; }\n";
  651.                 echo "if(typeof(inlineModeration) != 'undefined') { Event.observe($('inlinemod_{$pid}'), 'click', inlineModeration.checkItem); }\n";
  652.                 echo "</script>\n";
  653.                 exit;
  654.             }
  655.             // Post is in the moderation queue
  656.             else
  657.             {
  658.                 redirect(get_thread_link($tid, 0, "lastpost"), $lang->redirect_newreply_moderation);
  659.                 exit;
  660.             }
  661.         }
  662.         else
  663.         {
  664.             $lang->redirect_newreply .= $lang->sprintf($lang->redirect_return_thread, get_forum_link($fid));
  665.             redirect($url, $lang->redirect_newreply);
  666.             exit;
  667.         }
  668.     }
  669. }
  670.  
  671. // Show the newreply form.
  672. if($mybb->input['action'] == "newreply" || $mybb->input['action'] == "editdraft")
  673. {
  674.     $plugins->run_hooks("newreply_start");
  675.  
  676.     $quote_ids = $multiquote_external = '';
  677.     // If this isn't a preview and we're not editing a draft, then handle quoted posts
  678.     if(!$mybb->input['previewpost'] && !$reply_errors && $mybb->input['action'] != "editdraft" && !$mybb->input['attachmentaid'] && !$mybb->input['newattachment'] && !$mybb->input['updateattachment'] && !$mybb->input['rem'])
  679.     {
  680.         $message = '';
  681.         $quoted_posts = array();
  682.         // Handle multiquote
  683.         if(isset($mybb->cookies['multiquote']) && $mybb->settings['multiquote'] != 0)
  684.         {
  685.             $multiquoted = explode("|", $mybb->cookies['multiquote']);
  686.             foreach($multiquoted as $post)
  687.             {
  688.                 $quoted_posts[$post] = intval($post);
  689.             }
  690.         }
  691.         // Handle incoming 'quote' button
  692.         if($replyto)
  693.         {
  694.             $quoted_posts[$replyto] = $replyto;
  695.         }
  696.  
  697.         // Quoting more than one post - fetch them
  698.         if(count($quoted_posts) > 0)
  699.         {
  700.             $external_quotes = 0;
  701.             $quoted_posts = implode(",", $quoted_posts);
  702.             $unviewable_forums = get_unviewable_forums();
  703.             if($unviewable_forums)
  704.             {
  705.                 $unviewable_forums = "AND t.fid NOT IN ({$unviewable_forums})";
  706.             }
  707.             if(is_moderator($fid))
  708.             {
  709.                 $visible_where = "AND p.visible != 2";
  710.             }
  711.             else
  712.             {
  713.                 $visible_where = "AND p.visible > 0";
  714.             }
  715.  
  716.             require_once MYBB_ROOT."inc/functions_posting.php";
  717.             $query = $db->query("
  718.                 SELECT p.subject, p.message, p.pid, p.tid, p.username, p.dateline, u.username AS userusername
  719.                 FROM ".TABLE_PREFIX."posts p
  720.                 LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
  721.                 LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
  722.                 WHERE p.pid IN ($quoted_posts) {$unviewable_forums} {$visible_where}
  723.             ");
  724.             $load_all = intval($mybb->input['load_all_quotes']);
  725.             while($quoted_post = $db->fetch_array($query))
  726.             {
  727.                 // Only show messages for the current thread
  728.                 if($quoted_post['tid'] == $tid || $load_all == 1)
  729.                 {
  730.                     // If this post was the post for which a quote button was clicked, set the subject
  731.                     if($pid == $quoted_post['pid'])
  732.                     {
  733.                         $subject = preg_replace('#RE:\s?#i', '', $quoted_post['subject']);
  734.                         // Subject too long? Shorten it to avoid error message
  735.                         if(my_strlen($subject) > 85)
  736.                         {
  737.                             $subject = my_substr($subject, 0, 82).'...';
  738.                         }
  739.                         $subject = "RE: ".$subject;
  740.                     }
  741.                     $message .= parse_quoted_message($quoted_post);
  742.                     $quoted_ids[] = $quoted_post['pid'];
  743.                 }
  744.                 // Count the rest
  745.                 else
  746.                 {
  747.                     ++$external_quotes;
  748.                 }
  749.             }
  750.             if($mybb->settings['maxquotedepth'] != '0')
  751.             {
  752.                 $message = remove_message_quotes($message);
  753.             }
  754.             if($external_quotes > 0)
  755.             {
  756.                 if($external_quotes == 1)
  757.                 {
  758.                     $multiquote_text = $lang->multiquote_external_one;
  759.                     $multiquote_deselect = $lang->multiquote_external_one_deselect;
  760.                     $multiquote_quote = $lang->multiquote_external_one_quote;
  761.                 }
  762.                 else
  763.                 {
  764.                     $multiquote_text = $lang->sprintf($lang->multiquote_external, $external_quotes);
  765.                     $multiquote_deselect = $lang->multiquote_external_deselect;
  766.                     $multiquote_quote = $lang->multiquote_external_quote;
  767.                 }
  768.                 eval("\$multiquote_external = \"".$templates->get("newreply_multiquote_external")."\";");
  769.             }
  770.             if(is_array($quoted_ids) && count($quoted_ids) > 0)
  771.             {
  772.                 $quoted_ids = implode("|", $quoted_ids);
  773.             }
  774.         }
  775.     }
  776.  
  777.     if($mybb->input['quoted_ids'])
  778.     {
  779.         $quoted_ids = htmlspecialchars_uni($mybb->input['quoted_ids']);
  780.     }
  781.  
  782.     if($mybb->input['previewpost'])
  783.     {
  784.         $previewmessage = $mybb->input['message'];
  785.     }
  786.     if(!$message)
  787.     {
  788.         $message = $mybb->input['message'];
  789.     }
  790.     $message = htmlspecialchars_uni($message);
  791.  
  792.     // Set up the post options.
  793.     if($mybb->input['previewpost'] || $reply_errors != '')
  794.     {
  795.         $postoptions = $mybb->input['postoptions'];
  796.         $postoptions_subscriptionmethod_dont = $postoptions_subscriptionmethod_none = $postoptions_subscriptionmethod_instant = '';
  797.  
  798.         if($postoptions['signature'] == 1)
  799.         {
  800.             $postoptionschecked['signature'] = " checked=\"checked\"";
  801.         }
  802.         if($postoptions['subscriptionmethod'] == "none")
  803.         {
  804.             $postoptions_subscriptionmethod_none = "checked=\"checked\"";
  805.         }
  806.         else if($postoptions['subscriptionmethod'] == "instant")
  807.         {
  808.             $postoptions_subscriptionmethod_instant = "checked=\"checked\"";
  809.         }
  810.         else
  811.         {
  812.             $postoptions_subscriptionmethod_dont = "checked=\"checked\"";
  813.         }
  814.         if($postoptions['disablesmilies'] == 1)
  815.         {
  816.             $postoptionschecked['disablesmilies'] = " checked=\"checked\"";
  817.         }
  818.         $subject = $mybb->input['subject'];
  819.     }
  820.     elseif($mybb->input['action'] == "editdraft" && $mybb->user['uid'])
  821.     {
  822.         $postoptionschecked = array('signature' => '', 'disablesmilies' => '');
  823.         $postoptions_subscriptionmethod_dont = $postoptions_subscriptionmethod_none = $postoptions_subscriptionmethod_instant = '';
  824.  
  825.         $message = htmlspecialchars_uni($post['message']);
  826.         $subject = $post['subject'];
  827.         if($post['includesig'] != 0)
  828.         {
  829.             $postoptionschecked['signature'] = " checked=\"checked\"";
  830.         }
  831.         if($post['smilieoff'] == 1)
  832.         {
  833.             $postoptionschecked['disablesmilies'] = " checked=\"checked\"";
  834.         }
  835.         if($postoptions['subscriptionmethod'] == "none")
  836.         {
  837.             $postoptions_subscriptionmethod_none = "checked=\"checked\"";
  838.         }
  839.         else if($postoptions['subscriptionmethod'] == "instant")
  840.         {
  841.             $postoptions_subscriptionmethod_instant = "checked=\"checked\"";
  842.         }
  843.         else
  844.         {
  845.             $postoptions_subscriptionmethod_dont = "checked=\"checked\"";
  846.         }
  847.         $mybb->input['icon'] = $post['icon'];
  848.     }
  849.     else
  850.     {
  851.         $postoptionschecked = array('signature' => '', 'disablesmilies' => '');
  852.         $postoptions_subscriptionmethod_dont = $postoptions_subscriptionmethod_none = $postoptions_subscriptionmethod_instant = '';
  853.  
  854.         if($mybb->user['signature'] != '')
  855.         {
  856.             $postoptionschecked['signature'] = " checked=\"checked\"";
  857.         }
  858.         if($mybb->user['subscriptionmethod'] ==  1)
  859.         {
  860.             $postoptions_subscriptionmethod_none = "checked=\"checked\"";
  861.         }
  862.         else if($mybb->user['subscriptionmethod'] == 2)
  863.         {
  864.             $postoptions_subscriptionmethod_instant = "checked=\"checked\"";
  865.         }
  866.         else
  867.         {
  868.             $postoptions_subscriptionmethod_dont = "checked=\"checked\"";
  869.         }
  870.     }
  871.  
  872.     if($forum['allowpicons'] != 0)
  873.     {
  874.         $posticons = get_post_icons();
  875.     }
  876.  
  877.     // No subject?
  878.     if(!isset($subject))
  879.     {
  880.         if($mybb->input['subject'])
  881.         {
  882.             $subject = $mybb->input['subject'];
  883.         }
  884.         else
  885.         {
  886.             $subject = $thread['subject'];
  887.         }
  888.     }
  889.  
  890.     // Preview a post that was written.
  891.     $preview = '';
  892.     if($mybb->input['previewpost'])
  893.     {
  894.         // Set up posthandler.
  895.         require_once MYBB_ROOT."inc/datahandlers/post.php";
  896.         $posthandler = new PostDataHandler("insert");
  897.  
  898.         // Set the post data that came from the input to the $post array.
  899.         $post = array(
  900.             "tid" => $mybb->input['tid'],
  901.             "replyto" => $mybb->input['replyto'],
  902.             "fid" => $thread['fid'],
  903.             "subject" => $mybb->input['subject'],
  904.             "icon" => $mybb->input['icon'],
  905.             "uid" => $uid,
  906.             "username" => $username,
  907.             "message" => $mybb->input['message'],
  908.             "ipaddress" => get_ip(),
  909.             "posthash" => $mybb->input['posthash']
  910.         );
  911.  
  912.         if($mybb->input['pid'])
  913.         {
  914.             $post['pid'] = $mybb->input['pid'];
  915.         }
  916.  
  917.         $posthandler->set_data($post);
  918.  
  919.         // Now let the post handler do all the hard work.
  920.         $valid_post = $posthandler->verify_message();
  921.         $valid_subject = $posthandler->verify_subject();
  922.  
  923.         $post_errors = array();
  924.         // Fetch friendly error messages if this is an invalid post
  925.         if(!$valid_post || !$valid_subject)
  926.         {
  927.             $post_errors = $posthandler->get_friendly_errors();
  928.         }
  929.  
  930.         // One or more errors returned, fetch error list and throw to newreply page
  931.         if(count($post_errors) > 0)
  932.         {
  933.             $reply_errors = inline_error($post_errors);
  934.         }
  935.         else
  936.         {
  937.             $quote_ids = htmlspecialchars_uni($mybb->input['quote_ids']);
  938.             if(!$mybb->input['username'])
  939.             {
  940.                 $mybb->input['username'] = $lang->guest;
  941.             }
  942.             $mybb->input['icon'] = intval($mybb->input['icon']);
  943.             $query = $db->query("
  944.                 SELECT u.*, f.*
  945.                 FROM ".TABLE_PREFIX."users u
  946.                 LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid)
  947.                 WHERE u.uid='".$mybb->user['uid']."'
  948.             ");
  949.             $post = $db->fetch_array($query);
  950.             if(!$mybb->user['uid'] || !$post['username'])
  951.             {
  952.                 $post['username'] = $mybb->input['username'];
  953.             }
  954.             else
  955.             {
  956.                 $post['userusername'] = $mybb->user['username'];
  957.                 $post['username'] = $mybb->user['username'];
  958.             }
  959.             $post['message'] = $previewmessage;
  960.             $post['subject'] = $subject;
  961.             $post['icon'] = $mybb->input['icon'];
  962.             $post['smilieoff'] = $postoptions['disablesmilies'];
  963.             $post['dateline'] = TIME_NOW;
  964.             $post['includesig'] = $mybb->input['postoptions']['signature'];
  965.             if($post['includesig'] != 1)
  966.             {
  967.                 $post['includesig'] = 0;
  968.             }
  969.  
  970.             // Fetch attachments assigned to this post.
  971.             if($mybb->input['pid'])
  972.             {
  973.                 $attachwhere = "pid='".intval($mybb->input['pid'])."'";
  974.             }
  975.             else
  976.             {
  977.                 $attachwhere = "posthash='".$db->escape_string($mybb->input['posthash'])."'";
  978.             }
  979.  
  980.             $query = $db->simple_select("attachments", "*", $attachwhere);
  981.             while($attachment = $db->fetch_array($query))
  982.             {
  983.                 $attachcache[0][$attachment['aid']] = $attachment;
  984.             }
  985.  
  986.             $postbit = build_postbit($post, 1);
  987.             eval("\$preview = \"".$templates->get("previewpost")."\";");
  988.         }
  989.     }
  990.  
  991.     $subject = htmlspecialchars_uni($parser->parse_badwords($subject));
  992.  
  993.     if(!$pid && !$mybb->input['previewpost'])
  994.     {
  995.         $subject = $thread['subject'];
  996.         // Subject too long? Shorten it to avoid error message
  997.         if(my_strlen($subject) > 85)
  998.         {
  999.             $subject = my_substr($subject, 0, 82).'...';
  1000.         }
  1001.         $subject = "RE: ".$subject;
  1002.     }
  1003.  
  1004.     $posthash = htmlspecialchars_uni($mybb->input['posthash']);
  1005.  
  1006.     // Do we have attachment errors?
  1007.     if(count($errors) > 0)
  1008.     {
  1009.         $reply_errors = inline_error($errors);
  1010.     }
  1011.  
  1012.     // Get a listing of the current attachments.
  1013.     if($forumpermissions['canpostattachments'] != 0)
  1014.     {
  1015.         $attachcount = 0;
  1016.         if($pid)
  1017.         {
  1018.             $attachwhere = "pid='$pid'";
  1019.         }
  1020.         else
  1021.         {
  1022.             $attachwhere = "posthash='".$db->escape_string($posthash)."'";
  1023.         }
  1024.         $attachments = '';
  1025.         $query = $db->simple_select("attachments", "*", $attachwhere);
  1026.         while($attachment = $db->fetch_array($query))
  1027.         {
  1028.             $attachment['size'] = get_friendly_size($attachment['filesize']);
  1029.             $attachment['icon'] = get_attachment_icon(get_extension($attachment['filename']));
  1030.             $attachment['filename'] = htmlspecialchars_uni($attachment['filename']);
  1031.  
  1032.             if($mybb->settings['bbcodeinserter'] != 0 && $forum['allowmycode'] != 0 && (!$mybb->user['uid'] || $mybb->user['showcodebuttons'] != 0))
  1033.             {
  1034.                 eval("\$postinsert = \"".$templates->get("post_attachments_attachment_postinsert")."\";");
  1035.             }
  1036.  
  1037.             eval("\$attach_rem_options = \"".$templates->get("post_attachments_attachment_remove")."\";");
  1038.  
  1039.             if($attachment['visible'] != 1)
  1040.             {
  1041.                 eval("\$attachments .= \"".$templates->get("post_attachments_attachment_unapproved")."\";");
  1042.             }
  1043.             else
  1044.             {
  1045.                 eval("\$attachments .= \"".$templates->get("post_attachments_attachment")."\";");
  1046.             }
  1047.             $attachcount++;
  1048.         }
  1049.  
  1050.         $noshowattach = '';
  1051.         $query = $db->simple_select("attachments", "SUM(filesize) AS ausage", "uid='".$mybb->user['uid']."'");
  1052.         $usage = $db->fetch_array($query);
  1053.  
  1054.         if($usage['ausage'] > ($mybb->usergroup['attachquota']*1024) && $mybb->usergroup['attachquota'] != 0)
  1055.         {
  1056.             $noshowattach = 1;
  1057.         }
  1058.  
  1059.         if($mybb->usergroup['attachquota'] == 0)
  1060.         {
  1061.             $friendlyquota = $lang->unlimited;
  1062.         }
  1063.         else
  1064.         {
  1065.             $friendlyquota = get_friendly_size($mybb->usergroup['attachquota']*1024);
  1066.         }
  1067.  
  1068.         $friendlyusage = get_friendly_size($usage['ausage']);
  1069.         $lang->attach_quota = $lang->sprintf($lang->attach_quota, $friendlyusage, $friendlyquota);
  1070.  
  1071.         if($mybb->settings['maxattachments'] == 0 || ($mybb->settings['maxattachments'] != 0 && $attachcount < $mybb->settings['maxattachments']) && !$noshowattach)
  1072.         {
  1073.             eval("\$newattach = \"".$templates->get("post_attachments_new")."\";");
  1074.         }
  1075.  
  1076.         eval("\$attachbox = \"".$templates->get("post_attachments")."\";");
  1077.     }
  1078.  
  1079.     // If the user is logged in, provide a save draft button.
  1080.     if($mybb->user['uid'])
  1081.     {
  1082.         eval("\$savedraftbutton = \"".$templates->get("post_savedraftbutton", 1, 0)."\";");
  1083.     }
  1084.  
  1085.     // Show captcha image for guests if enabled
  1086.     $captcha = '';
  1087.     if($mybb->settings['captchaimage'] && !$mybb->user['uid'])
  1088.     {
  1089.         $correct = false;
  1090.         require_once MYBB_ROOT.'inc/class_captcha.php';
  1091.         $post_captcha = new captcha(false, "post_captcha");
  1092.  
  1093.         if($mybb->input['previewpost'] || $hide_captcha == true && $post_captcha->type == 1)
  1094.         {
  1095.             // If previewing a post - check their current captcha input - if correct, hide the captcha input area
  1096.             // ... but only if it's a default one, reCAPTCHAs must be filled in every time due to draconian limits
  1097.             if($post_captcha->validate_captcha() == true)
  1098.             {
  1099.                 $correct = true;
  1100.  
  1101.                 // Generate a hidden list of items for our captcha
  1102.                 $captcha = $post_captcha->build_hidden_captcha();
  1103.             }
  1104.         }
  1105.  
  1106.         if(!$correct)
  1107.         {
  1108.             if($post_captcha->type == 1)
  1109.             {
  1110.                 $post_captcha->build_captcha();
  1111.             }
  1112.             elseif($post_captcha->type == 2)
  1113.             {
  1114.                 $post_captcha->build_recaptcha();
  1115.             }
  1116.  
  1117.             if($post_captcha->html)
  1118.             {
  1119.                 $captcha = $post_captcha->html;
  1120.             }
  1121.         }
  1122.         elseif($correct && $post_captcha->type == 2)
  1123.         {
  1124.             $post_captcha->build_recaptcha();
  1125.  
  1126.             if($post_captcha->html)
  1127.             {
  1128.                 $captcha = $post_captcha->html;
  1129.             }
  1130.         }
  1131.     }
  1132.  
  1133.     if($mybb->settings['threadreview'] != 0)
  1134.     {
  1135.         if(!$mybb->settings['postsperpage'])
  1136.         {
  1137.             $mybb->settings['postperpage'] = 20;
  1138.         }
  1139.  
  1140.         if(is_moderator($fid))
  1141.         {
  1142.             $visibility = "(visible='1' OR visible='0')";
  1143.         }
  1144.         else
  1145.         {
  1146.             $visibility = "visible='1'";
  1147.         }
  1148.         $query = $db->simple_select("posts", "COUNT(pid) AS post_count", "tid='{$tid}' AND {$visibility}");
  1149.         $numposts = $db->fetch_field($query, "post_count");
  1150.  
  1151.         if($numposts > $mybb->settings['postsperpage'])
  1152.         {
  1153.             $numposts = $mybb->settings['postsperpage'];
  1154.             $lang->thread_review_more = $lang->sprintf($lang->thread_review_more, $mybb->settings['postsperpage'], get_thread_link($tid));
  1155.             eval("\$reviewmore = \"".$templates->get("newreply_threadreview_more")."\";");
  1156.         }
  1157.  
  1158.         $query = $db->simple_select("posts", "pid", "tid='{$tid}' AND {$visibility}", array("order_by" => "dateline", "order_dir" => "desc", "limit" => $mybb->settings['postsperpage']));
  1159.         while($post = $db->fetch_array($query))
  1160.         {
  1161.             $pidin[] = $post['pid'];
  1162.         }
  1163.  
  1164.         $pidin = implode(",", $pidin);
  1165.  
  1166.         // Fetch attachments
  1167.         $query = $db->simple_select("attachments", "*", "pid IN ($pidin)");
  1168.         while($attachment = $db->fetch_array($query))
  1169.         {
  1170.             $attachcache[$attachment['pid']][$attachment['aid']] = $attachment;
  1171.         }
  1172.         $query = $db->query("
  1173.             SELECT p.*, u.username AS userusername
  1174.             FROM ".TABLE_PREFIX."posts p
  1175.             LEFT JOIN ".TABLE_PREFIX."users u ON (p.uid=u.uid)
  1176.             WHERE pid IN ($pidin)
  1177.             ORDER BY dateline DESC
  1178.         ");
  1179.         $postsdone = 0;
  1180.         $altbg = "trow1";
  1181.         $reviewbits = '';
  1182.         while($post = $db->fetch_array($query))
  1183.         {
  1184.             if($post['userusername'])
  1185.             {
  1186.                 $post['username'] = $post['userusername'];
  1187.             }
  1188.             $reviewpostdate = my_date($mybb->settings['dateformat'], $post['dateline']);
  1189.             $reviewposttime = my_date($mybb->settings['timeformat'], $post['dateline']);
  1190.             $parser_options = array(
  1191.                 "allow_html" => $forum['allowhtml'],
  1192.                 "allow_mycode" => $forum['allowmycode'],
  1193.                 "allow_smilies" => $forum['allowsmilies'],
  1194.                 "allow_imgcode" => $forum['allowimgcode'],
  1195.                 "allow_videocode" => $forum['allowvideocode'],
  1196.                 "me_username" => $post['username'],
  1197.                 "filter_badwords" => 1
  1198.             );
  1199.             if($post['smilieoff'] == 1)
  1200.             {
  1201.                 $parser_options['allow_smilies'] = 0;
  1202.             }
  1203.  
  1204.             if($post['visible'] != 1)
  1205.             {
  1206.                 $altbg = "trow_shaded";
  1207.             }
  1208.  
  1209.             $post['message'] = $parser->parse_message($post['message'], $parser_options);
  1210.             get_post_attachments($post['pid'], $post);
  1211.             $reviewmessage = $post['message'];
  1212.             eval("\$reviewbits .= \"".$templates->get("newreply_threadreview_post")."\";");
  1213.             if($altbg == "trow1")
  1214.             {
  1215.                 $altbg = "trow2";
  1216.             }
  1217.             else
  1218.             {
  1219.                 $altbg = "trow1";
  1220.             }
  1221.         }
  1222.         eval("\$threadreview = \"".$templates->get("newreply_threadreview")."\";");
  1223.     }
  1224.     // Can we disable smilies or are they disabled already?
  1225.     if($forum['allowsmilies'] != 0)
  1226.     {
  1227.         eval("\$disablesmilies = \"".$templates->get("newreply_disablesmilies")."\";");
  1228.     }
  1229.     else
  1230.     {
  1231.         $disablesmilies = "<input type=\"hidden\" name=\"postoptions[disablesmilies]\" value=\"no\" />";
  1232.     }
  1233.     // Show the moderator options.
  1234.     if(is_moderator($fid))
  1235.     {
  1236.         if($mybb->input['processed'])
  1237.         {
  1238.             $closed = intval($mybb->input['modoptions']['closethread']);
  1239.             $stuck = intval($mybb->input['modoptions']['stickthread']);
  1240.         }
  1241.         else
  1242.         {
  1243.             $closed = $thread['closed'];
  1244.             $stuck = $thread['sticky'];
  1245.         }
  1246.  
  1247.         if($closed)
  1248.         {
  1249.             $closecheck = ' checked="checked"';
  1250.         }
  1251.         else
  1252.         {
  1253.             $closecheck = '';
  1254.         }
  1255.  
  1256.         if($stuck)
  1257.         {
  1258.             $stickycheck = ' checked="checked"';
  1259.         }
  1260.         else
  1261.         {
  1262.             $stickycheck = '';
  1263.         }
  1264.  
  1265.         eval("\$modoptions = \"".$templates->get("newreply_modoptions")."\";");
  1266.         $bgcolor = "trow1";
  1267.     }
  1268.     else
  1269.     {
  1270.         $bgcolor = "trow2";
  1271.     }
  1272.  
  1273.     // Fetch subscription select box
  1274.     eval("\$subscriptionmethod = \"".$templates->get("post_subscription_method")."\";");
  1275.  
  1276.     $lang->post_reply_to = $lang->sprintf($lang->post_reply_to, $thread['subject']);
  1277.     $lang->reply_to = $lang->sprintf($lang->reply_to, $thread['subject']);
  1278.  
  1279.     // Do we have any forum rules to show for this forum?
  1280.     $forumrules = '';
  1281.     if($forum['rulestype'] >= 2 && $forum['rules'])
  1282.     {
  1283.         if(!$forum['rulestitle'])
  1284.         {
  1285.             $forum['rulestitle'] = $lang->sprintf($lang->forum_rules, $forum['name']);
  1286.         }
  1287.  
  1288.         if(!$parser)
  1289.         {
  1290.             require_once MYBB_ROOT.'inc/class_parser.php';
  1291.             $parser = new postParser;
  1292.         }
  1293.  
  1294.         $rules_parser = array(
  1295.             "allow_html" => 1,
  1296.             "allow_mycode" => 1,
  1297.             "allow_smilies" => 1,
  1298.             "allow_imgcode" => 1
  1299.         );
  1300.  
  1301.         $forum['rules'] = $parser->parse_message($forum['rules'], $rules_parser);
  1302.         $foruminfo = $forum;
  1303.  
  1304.         if($forum['rulestype'] == 3)
  1305.         {
  1306.             eval("\$forumrules = \"".$templates->get("forumdisplay_rules")."\";");
  1307.         }
  1308.         else if($forum['rulestype'] == 2)
  1309.         {
  1310.             eval("\$forumrules = \"".$templates->get("forumdisplay_rules_link")."\";");
  1311.         }
  1312.     }
  1313.  
  1314.     $plugins->run_hooks("newreply_end");
  1315.  
  1316.     $forum['name'] = strip_tags($forum['name']);
  1317.  
  1318.     $newreply_template = $templates->get("newreply");
  1319.  
  1320.     // Hide signature option if no permission
  1321.     $option_signature = '';
  1322.     if($mybb->usergroup['canusesig'] && !$mybb->user['suspendsignature'])
  1323.     {
  1324.         $option_signature = $templates->get('newreply_options_signature');
  1325.     }
  1326.     eval("\$option_signature = \"".$option_signature."\";");
  1327.  
  1328.     eval("\$newreply = \"".$newreply_template."\";");
  1329.     output_page($newreply);
  1330. }
  1331. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement