Advertisement
Guest User

newthread.php

a guest
Dec 7th, 2013
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 29.43 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', 'newthread.php');
  14.  
  15. $templatelist = "newthread,previewpost,loginbox,changeuserbox,newthread_postpoll,posticons,codebuttons,smilieinsert,newthread_multiquote_external,post_attachments_attachment_unapproved";
  16. $templatelist .= ",newthread_disablesmilies,newreply_modoptions,post_attachments_new,post_attachments,post_savedraftbutton,post_subscription_method,post_attachments_attachment_remove";
  17. $templatelist .= ",forumdisplay_rules,forumdisplay_rules_link,post_attachments_attachment_postinsert,post_attachments_attachment,newthread_options_signature";
  18. $templatelist .= ",member_register_regimage,member_register_regimage_recaptcha,post_captcha_hidden,post_captcha,post_captcha_recaptcha,postbit_groupimage,postbit_online,postbit_away,postbit_offline";
  19. $templatelist .= ",postbit_avatar,postbit_find,postbit_pm,postbit_rep_button,postbit_www,postbit_email,postbit_reputation,postbit_warn,postbit_warninglevel,postbit_author_user,postbit_author_guest";
  20. $templatelist .= ",postbit_signature,postbit_classic,postbit,postbit_attachments_thumbnails_thumbnail,postbit_attachments_images_image,postbit_attachments_attachment,postbit_attachments_attachment_unapproved";
  21. $templatelist .= ",postbit_attachments_thumbnails,postbit_attachments_images,postbit_attachments,postbit_gotopost,smilieinsert_getmore";
  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.  
  27. // Load global language phrases
  28. $lang->load("newthread");
  29.  
  30. $tid = $pid = "";
  31. if($mybb->input['action'] == "editdraft" || ($mybb->input['savedraft'] && $mybb->input['tid']) || ($mybb->input['tid'] && $mybb->input['pid']))
  32. {
  33.     $thread = get_thread($mybb->input['tid']);
  34.  
  35.     $query = $db->simple_select("posts", "*", "tid='".intval($mybb->input['tid'])."' AND visible='-2'", array('order_by' => 'dateline', 'limit' => 1));
  36.     $post = $db->fetch_array($query);
  37.  
  38.     if(!$thread['tid'] || !$post['pid'] || $thread['visible'] != -2 || $thread['uid'] != $mybb->user['uid'])
  39.     {
  40.         error($lang->invalidthread);
  41.     }
  42.  
  43.     $pid = $post['pid'];
  44.     $fid = $thread['fid'];
  45.     $tid = $thread['tid'];
  46.     $editdraftpid = "<input type=\"hidden\" name=\"pid\" value=\"$pid\" />";
  47. }
  48. else
  49. {
  50.     $fid = intval($mybb->input['fid']);
  51. }
  52.  
  53. // Fetch forum information.
  54. $forum = get_forum($fid);
  55. if(!$forum)
  56. {
  57.     error($lang->error_invalidforum);
  58. }
  59.  
  60. // Draw the navigation
  61. build_forum_breadcrumb($fid);
  62. add_breadcrumb($lang->nav_newthread);
  63.  
  64. $forumpermissions = forum_permissions($fid);
  65.  
  66. if($forum['open'] == 0 || $forum['type'] != "f" || $forum['linkto'] != "")
  67. {
  68.     error($lang->error_closedinvalidforum);
  69. }
  70.  
  71. if($forumpermissions['canview'] == 0 || $forumpermissions['canpostthreads'] == 0 || $mybb->user['suspendposting'] == 1)
  72. {
  73.     error_no_permission();
  74. }
  75.  
  76. // Check if this forum is password protected and we have a valid password
  77. check_forum_password($forum['fid']);
  78.  
  79. // If MyCode is on for this forum and the MyCode editor is enabled in the Admin CP, draw the code buttons and smilie inserter.
  80. if($mybb->settings['bbcodeinserter'] != 0 && $forum['allowmycode'] != 0 && (!$mybb->user['uid'] || $mybb->user['showcodebuttons'] != 0))
  81. {
  82.     $codebuttons = build_mycode_inserter();
  83.     if($forum['allowsmilies'] != 0)
  84.     {
  85.         $smilieinserter = build_clickable_smilies();
  86.     }
  87. }
  88.  
  89. // Does this forum allow post icons? If so, fetch the post icons.
  90. if($forum['allowpicons'] != 0)
  91. {
  92.     $posticons = get_post_icons();
  93. }
  94.  
  95. // If we have a currently logged in user then fetch the change user box.
  96. if($mybb->user['uid'] != 0)
  97. {
  98.     eval("\$loginbox = \"".$templates->get("changeuserbox")."\";");
  99. }
  100.  
  101. // Otherwise we have a guest, determine the "username" and get the login box.
  102. else
  103. {
  104.     if(!$mybb->input['previewpost'] && $mybb->input['action'] != "do_newthread")
  105.     {
  106.         $username = '';
  107.     }
  108.     else
  109.     {
  110.         $username = htmlspecialchars_uni($mybb->input['username']);
  111.     }
  112.     eval("\$loginbox = \"".$templates->get("loginbox")."\";");
  113. }
  114.  
  115. // If we're not performing a new thread insert and not editing a draft then we're posting a new thread.
  116. if($mybb->input['action'] != "do_newthread" && $mybb->input['action'] != "editdraft")
  117. {
  118.     $mybb->input['action'] = "newthread";
  119. }
  120.  
  121. // Previewing a post, overwrite the action to the new thread action.
  122. if($mybb->input['previewpost'])
  123. {
  124.     $mybb->input['action'] = "newthread";
  125. }
  126.  
  127. // Setup a unique posthash for attachment management
  128. if(!$mybb->input['posthash'] && !$pid)
  129. {
  130.     $mybb->input['posthash'] = md5($mybb->user['uid'].random_str());
  131. }
  132.  
  133. if((empty($_POST) && empty($_FILES)) && $mybb->input['processed'] == '1')
  134. {
  135.     error($lang->error_cannot_upload_php_post);
  136. }
  137.  
  138. // Handle attachments if we've got any.
  139. if(!$mybb->input['attachmentaid'] && ($mybb->input['newattachment'] || $mybb->input['updateattachment'] || ($mybb->input['action'] == "do_newthread" && $mybb->input['submit'] && $_FILES['attachment'])))
  140. {
  141.     // Verify incoming POST request
  142.     verify_post_check($mybb->input['my_post_key']);
  143.  
  144.     if($mybb->input['action'] == "editdraft" || ($mybb->input['tid'] && $mybb->input['pid']))
  145.     {
  146.         $attachwhere = "pid='{$pid}'";
  147.     }
  148.     else
  149.     {
  150.         $attachwhere = "posthash='".$db->escape_string($mybb->input['posthash'])."'";
  151.     }
  152.     $query = $db->simple_select("attachments", "COUNT(aid) as numattachs", $attachwhere);
  153.     $attachcount = $db->fetch_field($query, "numattachs");
  154.  
  155.     // If there's an attachment, check it and upload it
  156.     if($_FILES['attachment']['size'] > 0 && $forumpermissions['canpostattachments'] != 0 && ($mybb->settings['maxattachments'] == 0 ||  $attachcount < $mybb->settings['maxattachments']))
  157.     {
  158.         require_once MYBB_ROOT."inc/functions_upload.php";
  159.  
  160.         $update_attachment = false;
  161.         if($mybb->input['updateattachment'])
  162.         {
  163.             $update_attachment = true;
  164.         }
  165.         $attachedfile = upload_attachment($_FILES['attachment'], $update_attachment);
  166.     }
  167.  
  168.     // Error with attachments - should use new inline errors?
  169.     if($attachedfile['error'])
  170.     {
  171.         $errors[] = $attachedfile['error'];
  172.         $mybb->input['action'] = "newthread";
  173.     }
  174.  
  175.     // If we were dealing with an attachment but didn't click 'Post Thread', force the new thread page again.
  176.     if(!$mybb->input['submit'])
  177.     {
  178.         //$editdraftpid = "<input type=\"hidden\" name=\"pid\" value=\"$pid\" />";
  179.         $mybb->input['action'] = "newthread";
  180.     }
  181. }
  182.  
  183. // Are we removing an attachment from the thread?
  184. if($mybb->input['attachmentaid'] && $mybb->input['attachmentact'] == "remove")
  185. {
  186.     // Verify incoming POST request
  187.     verify_post_check($mybb->input['my_post_key']);
  188.  
  189.     require_once MYBB_ROOT."inc/functions_upload.php";
  190.     remove_attachment($pid, $mybb->input['posthash'], $mybb->input['attachmentaid']);
  191.     if(!$mybb->input['submit'])
  192.     {
  193.         $mybb->input['action'] = "newthread";
  194.     }
  195. }
  196.  
  197. $thread_errors = "";
  198. $hide_captcha = false;
  199.  
  200. // Check the maximum posts per day for this user
  201. if($mybb->settings['maxposts'] > 0 && $mybb->usergroup['cancp'] != 1)
  202. {
  203.     $daycut = TIME_NOW-60*60*24;
  204.     $query = $db->simple_select("posts", "COUNT(*) AS posts_today", "uid='{$mybb->user['uid']}' AND visible='1' AND dateline>{$daycut}");
  205.     $post_count = $db->fetch_field($query, "posts_today");
  206.     if($post_count >= $mybb->settings['maxposts'])
  207.     {
  208.         $lang->error_maxposts = $lang->sprintf($lang->error_maxposts, $mybb->settings['maxposts']);
  209.         error($lang->error_maxposts);
  210.     }
  211. }
  212.  
  213. // Performing the posting of a new thread.
  214. if($mybb->input['action'] == "do_newthread" && $mybb->request_method == "post")
  215. {
  216.     // Verify incoming POST request
  217.     verify_post_check($mybb->input['my_post_key']);
  218.  
  219.     $plugins->run_hooks("newthread_do_newthread_start");
  220.  
  221.     // If this isn't a logged in user, then we need to do some special validation.
  222.     if($mybb->user['uid'] == 0)
  223.     {
  224.         $username = htmlspecialchars_uni($mybb->input['username']);
  225.  
  226.         // Check if username exists.
  227.         if(username_exists($mybb->input['username']))
  228.         {
  229.             // If it does throw back "username is taken"
  230.             error($lang->error_usernametaken);
  231.         }
  232.         // This username does not exist.
  233.         else
  234.         {
  235.             // If they didn't specify a username then give them "Guest"
  236.             if(!$mybb->input['username'])
  237.             {
  238.                 $username = $lang->guest;
  239.             }
  240.             // Otherwise use the name they specified.
  241.             else
  242.             {
  243.                 $username = htmlspecialchars_uni($mybb->input['username']);
  244.             }
  245.             $uid = 0;
  246.         }
  247.     }
  248.     // This user is logged in.
  249.     else
  250.     {
  251.         $username = $mybb->user['username'];
  252.         $uid = $mybb->user['uid'];
  253.     }
  254.  
  255.     // Attempt to see if this post is a duplicate or not
  256.     if($uid > 0)
  257.     {
  258.         $user_check = "p.uid='{$uid}'";
  259.     }
  260.     else
  261.     {
  262.         $user_check = "p.ipaddress='".$db->escape_string($session->ipaddress)."'";
  263.     }
  264.     if(!$mybb->input['savedraft'] && !$pid)
  265.     {
  266.         $check_subject = utf8_handle_4byte_string($mybb->input['subject']);
  267.         $check_message = utf8_handle_4byte_string($mybb->input['message']);
  268.         $query = $db->simple_select("posts p", "p.pid", "$user_check AND p.fid='{$forum['fid']}' AND p.subject='".$db->escape_string($check_subject)."' AND p.message='".$db->escape_string($check_message)."' AND p.dateline>".(TIME_NOW-600));
  269.         $duplicate_check = $db->fetch_field($query, "pid");
  270.         if($duplicate_check)
  271.         {
  272.             error($lang->error_post_already_submitted);
  273.         }
  274.     }
  275.  
  276.     // Set up posthandler.
  277.     require_once MYBB_ROOT."inc/datahandlers/post.php";
  278.     $posthandler = new PostDataHandler("insert");
  279.     $posthandler->action = "thread";
  280.  
  281.     // Set the thread data that came from the input to the $thread array.
  282.     $new_thread = array(
  283.         "fid" => $forum['fid'],
  284.         "subject" => $mybb->input['subject'],
  285.         "prefix" => $mybb->input['threadprefix'],
  286.         "icon" => $mybb->input['icon'],
  287.         "uid" => $uid,
  288.         "username" => $username,
  289.         "message" => $mybb->input['message'],
  290.         "ipaddress" => get_ip(),
  291.         "posthash" => $mybb->input['posthash']
  292.     );
  293.     if($pid != '')
  294.     {
  295.         $new_thread['pid'] = $pid;
  296.     }
  297.  
  298.     // Are we saving a draft thread?
  299.     if($mybb->input['savedraft'] && $mybb->user['uid'])
  300.     {
  301.         $new_thread['savedraft'] = 1;
  302.     }
  303.     else
  304.     {
  305.         $new_thread['savedraft'] = 0;
  306.     }
  307.  
  308.     // Is this thread already a draft and we're updating it?
  309.     if(isset($thread['tid']) && $thread['visible'] == -2)
  310.     {
  311.         $new_thread['tid'] = $thread['tid'];
  312.     }
  313.  
  314.     // Set up the thread options from the input.
  315.     $new_thread['options'] = array(
  316.         "signature" => $mybb->input['postoptions']['signature'],
  317.         "subscriptionmethod" => $mybb->input['postoptions']['subscriptionmethod'],
  318.         "disablesmilies" => $mybb->input['postoptions']['disablesmilies']
  319.     );
  320.  
  321.     // Apply moderation options if we have them
  322.     $new_thread['modoptions'] = $mybb->input['modoptions'];
  323.  
  324.     $posthandler->set_data($new_thread);
  325.  
  326.     // Now let the post handler do all the hard work.
  327.     $valid_thread = $posthandler->validate_thread();
  328.  
  329.     $post_errors = array();
  330.     // Fetch friendly error messages if this is an invalid thread
  331.     if(!$valid_thread)
  332.     {
  333.         $post_errors = $posthandler->get_friendly_errors();
  334.     }
  335.  
  336.     // Check captcha image
  337.     if($mybb->settings['captchaimage'] && !$mybb->user['uid'])
  338.     {
  339.         require_once MYBB_ROOT.'inc/class_captcha.php';
  340.         $post_captcha = new captcha;
  341.  
  342.         if($post_captcha->validate_captcha() == false)
  343.         {
  344.             // CAPTCHA validation failed
  345.             foreach($post_captcha->get_errors() as $error)
  346.             {
  347.                 $post_errors[] = $error;
  348.             }
  349.         }
  350.         else
  351.         {
  352.             $hide_captcha = true;
  353.         }
  354.     }
  355.  
  356.     // One or more errors returned, fetch error list and throw to newthread page
  357.     if(count($post_errors) > 0)
  358.     {
  359.         $thread_errors = inline_error($post_errors);
  360.         $mybb->input['action'] = "newthread";
  361.     }
  362.     // No errors were found, it is safe to insert the thread.
  363.     else
  364.     {
  365.         $thread_info = $posthandler->insert_thread();
  366.         $tid = $thread_info['tid'];
  367.         $visible = $thread_info['visible'];
  368.  
  369.         // Invalidate solved captcha
  370.         if($mybb->settings['captchaimage'] && !$mybb->user['uid'])
  371.         {
  372.             $post_captcha->invalidate_captcha();
  373.         }
  374.  
  375.         // Mark thread as read
  376.         require_once MYBB_ROOT."inc/functions_indicators.php";
  377.         mark_thread_read($tid, $fid);
  378.  
  379.         // We were updating a draft thread, send them back to the draft listing.
  380.         if($new_thread['savedraft'] == 1)
  381.         {
  382.             $lang->redirect_newthread = $lang->draft_saved;
  383.             $url = "usercp.php?action=drafts";
  384.         }
  385.  
  386.         // A poll was being posted with this thread, throw them to poll posting page.
  387.         else if($mybb->input['postpoll'] && $forumpermissions['canpostpolls'])
  388.         {
  389.             $url = "polls.php?action=newpoll&tid=$tid&polloptions=".intval($mybb->input['numpolloptions']);
  390.             $lang->redirect_newthread .= $lang->redirect_newthread_poll;
  391.         }
  392.  
  393.         // This thread is stuck in the moderation queue, send them back to the forum.
  394.         else if(!$visible)
  395.         {
  396.             // Moderated thread
  397.             if($mybb->user['showredirect'] != 1)
  398.             {
  399.                 // User must see moderation notice, regardless of redirect settings
  400.                 $mybb->user['showredirect'] = 1;
  401.             }
  402.  
  403.             $lang->redirect_newthread .= $lang->redirect_newthread_moderation;
  404.             $url = get_forum_link($fid);
  405.         }
  406.  
  407.         // This is just a normal thread - send them to it.
  408.         else
  409.         {
  410.             // Visible thread
  411.             $lang->redirect_newthread .= $lang->redirect_newthread_thread;
  412.             $url = get_thread_link($tid);
  413.         }
  414.  
  415.         // Mark any quoted posts so they're no longer selected - attempts to maintain those which weren't selected
  416.         if($mybb->input['quoted_ids'] && $mybb->cookies['multiquote'] && $mybb->settings['multiquote'] != 0)
  417.         {
  418.             // We quoted all posts - remove the entire cookie
  419.             if($mybb->input['quoted_ids'] == "all")
  420.             {
  421.                 my_unsetcookie("multiquote");
  422.             }
  423.         }
  424.  
  425.         $plugins->run_hooks("newthread_do_newthread_end");
  426.  
  427.         // Hop to it! Send them to the next page.
  428.         if(!$mybb->input['postpoll'])
  429.         {
  430.             $lang->redirect_newthread .= $lang->sprintf($lang->redirect_return_forum, get_forum_link($fid));
  431.         }
  432.         redirect($url, $lang->redirect_newthread);
  433.     }
  434. }
  435.  
  436. if($mybb->input['action'] == "newthread" || $mybb->input['action'] == "editdraft")
  437. {
  438.  
  439.     $plugins->run_hooks("newthread_start");
  440.  
  441.     // If this isn't a preview and we're not editing a draft, then handle quoted posts
  442.     if(!$mybb->input['previewpost'] && !$thread_errors && $mybb->input['action'] != "editdraft")
  443.     {
  444.         $message = '';
  445.         $quoted_posts = array();
  446.         // Handle multiquote
  447.         if($mybb->cookies['multiquote'] && $mybb->settings['multiquote'] != 0)
  448.         {
  449.             $multiquoted = explode("|", $mybb->cookies['multiquote']);
  450.             foreach($multiquoted as $post)
  451.             {
  452.                 $quoted_posts[$post] = intval($post);
  453.             }
  454.         }
  455.  
  456.         // Quoting more than one post - fetch them
  457.         if(count($quoted_posts) > 0)
  458.         {
  459.             $external_quotes = 0;
  460.             $quoted_posts = implode(",", $quoted_posts);
  461.             $unviewable_forums = get_unviewable_forums();
  462.             if($unviewable_forums)
  463.             {
  464.                 $unviewable_forums = "AND t.fid NOT IN ({$unviewable_forums})";
  465.             }
  466.  
  467.             if(is_moderator($fid))
  468.             {
  469.                 $visible_where = "AND p.visible != 2";
  470.             }
  471.             else
  472.             {
  473.                 $visible_where = "AND p.visible > 0";
  474.             }
  475.  
  476.             if(intval($mybb->input['load_all_quotes']) == 1)
  477.             {
  478.                 $query = $db->query("
  479.                     SELECT p.subject, p.message, p.pid, p.tid, p.username, p.dateline, u.username AS userusername
  480.                     FROM ".TABLE_PREFIX."posts p
  481.                     LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
  482.                     LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
  483.                     WHERE p.pid IN ($quoted_posts) {$unviewable_forums} {$visible_where}
  484.                     ORDER BY p.dateline
  485.                 ");
  486.                 while($quoted_post = $db->fetch_array($query))
  487.                 {
  488.                     if($quoted_post['userusername'])
  489.                     {
  490.                         $quoted_post['username'] = $quoted_post['userusername'];
  491.                     }
  492.                     $quoted_post['message'] = preg_replace('#(^|\r|\n)/me ([^\r\n<]*)#i', "\\1* {$quoted_post['username']} \\2", $quoted_post['message']);
  493.                     $quoted_post['message'] = preg_replace('#(^|\r|\n)/slap ([^\r\n<]*)#i', "\\1* {$quoted_post['username']} {$lang->slaps} \\2 {$lang->with_trout}", $quoted_post['message']);
  494.                     $quoted_post['message'] = preg_replace("#\[attachment=([0-9]+?)\]#i", '', $quoted_post['message']);
  495.                     $message .= "[quote='{$quoted_post['username']}' pid='{$quoted_post['pid']}' dateline='{$quoted_post['dateline']}']\n{$quoted_post['message']}\n[/quote]\n\n";
  496.                 }
  497.  
  498.                 $quoted_ids = "all";
  499.             }
  500.             else
  501.             {
  502.                 $query = $db->query("
  503.                     SELECT COUNT(*) AS quotes
  504.                     FROM ".TABLE_PREFIX."posts p
  505.                     LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
  506.                     WHERE p.pid IN ($quoted_posts) {$unviewable_forums} {$visible_where}
  507.                 ");
  508.                 $external_quotes = $db->fetch_field($query, 'quotes');
  509.  
  510.                 if($external_quotes > 0)
  511.                 {
  512.                     if($external_quotes == 1)
  513.                     {
  514.                         $multiquote_text = $lang->multiquote_external_one;
  515.                         $multiquote_deselect = $lang->multiquote_external_one_deselect;
  516.                         $multiquote_quote = $lang->multiquote_external_one_quote;
  517.                     }
  518.                     else
  519.                     {
  520.                         $multiquote_text = $lang->sprintf($lang->multiquote_external, $external_quotes);
  521.                         $multiquote_deselect = $lang->multiquote_external_deselect;
  522.                         $multiquote_quote = $lang->multiquote_external_quote;
  523.                     }
  524.                     eval("\$multiquote_external = \"".$templates->get("newthread_multiquote_external")."\";");
  525.                 }
  526.             }
  527.         }
  528.     }
  529.  
  530.     if($mybb->input['quoted_ids'])
  531.     {
  532.         $quoted_ids = htmlspecialchars_uni($mybb->input['quoted_ids']);
  533.     }
  534.  
  535.     // Check the various post options if we're
  536.     // a -> previewing a post
  537.     // b -> removing an attachment
  538.     // c -> adding a new attachment
  539.     // d -> have errors from posting
  540.  
  541.     if($mybb->input['previewpost'] || $mybb->input['attachmentaid'] || $mybb->input['newattachment'] || $mybb->input['updateattachment'] || $thread_errors)
  542.     {
  543.         $postoptions = $mybb->input['postoptions'];
  544.         if($postoptions['signature'] == 1)
  545.         {
  546.             $postoptionschecked['signature'] = " checked=\"checked\"";
  547.         }
  548.         if($postoptions['subscriptionmethod'] == "none")
  549.         {
  550.             $postoptions_subscriptionmethod_none = "checked=\"checked\"";
  551.         }
  552.         else if($postoptions['subscriptionmethod'] == "instant")
  553.         {
  554.             $postoptions_subscriptionmethod_instant = "checked=\"checked\"";
  555.         }
  556.         else
  557.         {
  558.             $postoptions_subscriptionmethod_dont = "checked=\"checked\"";
  559.         }
  560.         if($postoptions['disablesmilies'] == 1)
  561.         {
  562.             $postoptionschecked['disablesmilies'] = " checked=\"checked\"";
  563.         }
  564.         if($mybb->input['postpoll'] == 1)
  565.         {
  566.             $postpollchecked = "checked=\"checked\"";
  567.         }
  568.         $numpolloptions = intval($mybb->input['numpolloptions']);
  569.     }
  570.  
  571.     // Editing a draft thread
  572.     else if($mybb->input['action'] == "editdraft" && $mybb->user['uid'])
  573.     {
  574.         $mybb->input['threadprefix'] = $thread['prefix'];
  575.         $message = htmlspecialchars_uni($post['message']);
  576.         $subject = htmlspecialchars_uni($post['subject']);
  577.         if($post['includesig'] != 0)
  578.         {
  579.             $postoptionschecked['signature'] = " checked=\"checked\"";
  580.         }
  581.         if($post['smilieoff'] == 1)
  582.         {
  583.             $postoptionschecked['disablesmilies'] = " checked=\"checked\"";
  584.         }
  585.         $icon = $post['icon'];
  586.         if($forum['allowpicons'] != 0)
  587.         {
  588.             $posticons = get_post_icons();
  589.         }
  590.         if($postoptions['subscriptionmethod'] == "none")
  591.         {
  592.             $postoptions_subscriptionmethod_none = "checked=\"checked\"";
  593.         }
  594.         else if($postoptions['subscriptionmethod'] == "instant")
  595.         {
  596.             $postoptions_subscriptionmethod_instant = "checked=\"checked\"";
  597.         }
  598.         else
  599.         {
  600.             $postoptions_subscriptionmethod_dont = "checked=\"checked\"";
  601.         }
  602.     }
  603.  
  604.     // Otherwise, this is our initial visit to this page.
  605.     else
  606.     {
  607.         if($mybb->user['signature'] != '')
  608.         {
  609.             $postoptionschecked['signature'] = " checked=\"checked\"";
  610.         }
  611.         if($mybb->user['subscriptionmethod'] ==  1)
  612.         {
  613.             $postoptions_subscriptionmethod_none = "checked=\"checked\"";
  614.         }
  615.         else if($mybb->user['subscriptionmethod'] == 2)
  616.         {
  617.             $postoptions_subscriptionmethod_instant = "checked=\"checked\"";
  618.         }
  619.         else
  620.         {
  621.             $postoptions_subscriptionmethod_dont = "checked=\"checked\"";
  622.         }
  623.         $numpolloptions = "2";
  624.     }
  625.  
  626.     // If we're preving a post then generate the preview.
  627.     if($mybb->input['previewpost'])
  628.     {
  629.         // Set up posthandler.
  630.         require_once MYBB_ROOT."inc/datahandlers/post.php";
  631.         $posthandler = new PostDataHandler("insert");
  632.         $posthandler->action = "thread";
  633.  
  634.         // Set the thread data that came from the input to the $thread array.
  635.         $new_thread = array(
  636.             "fid" => $forum['fid'],
  637.             "prefix" => $mybb->input['threadprefix'],
  638.             "subject" => $mybb->input['subject'],
  639.             "icon" => $mybb->input['icon'],
  640.             "uid" => $uid,
  641.             "username" => $username,
  642.             "message" => $mybb->input['message'],
  643.             "ipaddress" => get_ip(),
  644.             "posthash" => $mybb->input['posthash']
  645.         );
  646.  
  647.         if($pid != '')
  648.         {
  649.             $new_thread['pid'] = $pid;
  650.         }
  651.  
  652.         $posthandler->set_data($new_thread);
  653.  
  654.         // Now let the post handler do all the hard work.
  655.         $valid_thread = $posthandler->verify_message();
  656.         $valid_subject = $posthandler->verify_subject();
  657.  
  658.         $post_errors = array();
  659.         // Fetch friendly error messages if this is an invalid post
  660.         if(!$valid_thread || !$valid_subject)
  661.         {
  662.             $post_errors = $posthandler->get_friendly_errors();
  663.         }
  664.  
  665.         // One or more errors returned, fetch error list and throw to newreply page
  666.         if(count($post_errors) > 0)
  667.         {
  668.             $thread_errors = inline_error($post_errors);
  669.         }
  670.         else
  671.         {
  672.             if(!$mybb->input['username'])
  673.             {
  674.                 $mybb->input['username'] = $lang->guest;
  675.             }
  676.             $query = $db->query("
  677.                 SELECT u.*, f.*
  678.                 FROM ".TABLE_PREFIX."users u
  679.                 LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid)
  680.                 WHERE u.uid='".$mybb->user['uid']."'
  681.             ");
  682.             $post = $db->fetch_array($query);
  683.             if(!$mybb->user['uid'] || !$post['username'])
  684.             {
  685.                 $post['username'] = htmlspecialchars_uni($mybb->input['username']);
  686.             }
  687.             else
  688.             {
  689.                 $post['userusername'] = $mybb->user['username'];
  690.                 $post['username'] = $mybb->user['username'];
  691.             }
  692.             $previewmessage = $mybb->input['message'];
  693.             $post['message'] = $previewmessage;
  694.             $post['subject'] = $mybb->input['subject'];
  695.             $post['icon'] = $mybb->input['icon'];
  696.             $post['smilieoff'] = $postoptions['disablesmilies'];
  697.             $post['dateline'] = TIME_NOW;
  698.             $post['includesig'] = $mybb->input['postoptions']['signature'];
  699.             if($post['includesig'] != 1)
  700.             {
  701.                 $post['includesig'] = 0;
  702.             }
  703.  
  704.             // Fetch attachments assigned to this post
  705.             if($mybb->input['pid'])
  706.             {
  707.                 $attachwhere = "pid='".intval($mybb->input['pid'])."'";
  708.             }
  709.             else
  710.             {
  711.                 $attachwhere = "posthash='".$db->escape_string($mybb->input['posthash'])."'";
  712.             }
  713.  
  714.             $query = $db->simple_select("attachments", "*", $attachwhere);
  715.             while($attachment = $db->fetch_array($query))
  716.             {
  717.                 $attachcache[0][$attachment['aid']] = $attachment;
  718.             }
  719.  
  720.             $postbit = build_postbit($post, 1);
  721.             eval("\$preview = \"".$templates->get("previewpost")."\";");
  722.         }
  723.         $message = htmlspecialchars_uni($mybb->input['message']);
  724.         $subject = htmlspecialchars_uni($mybb->input['subject']);
  725.     }
  726.  
  727.     // Removing an attachment or adding a new one, or showting thread errors.
  728.     else if($mybb->input['attachmentaid'] || $mybb->input['newattachment'] || $mybb->input['updateattachment'] || $thread_errors)
  729.     {
  730.         $message = htmlspecialchars_uni($mybb->input['message']);
  731.         $subject = htmlspecialchars_uni($mybb->input['subject']);
  732.     }
  733.  
  734.     // Do we have attachment errors?
  735.     if(count($errors) > 0)
  736.     {
  737.         $thread_errors = inline_error($errors);
  738.     }
  739.  
  740.     // Generate thread prefix selector
  741.     if(!intval($mybb->input['threadprefix']))
  742.     {
  743.         $mybb->input['threadprefix'] = 0;
  744.     }
  745.  
  746.     $prefixselect = build_prefix_select($forum['fid'], $mybb->input['threadprefix']);
  747.  
  748.     $posthash = htmlspecialchars_uni($mybb->input['posthash']);
  749.  
  750.     // Can we disable smilies or are they disabled already?
  751.     if($forum['allowsmilies'] != 0)
  752.     {
  753.         eval("\$disablesmilies = \"".$templates->get("newthread_disablesmilies")."\";");
  754.     }
  755.     else
  756.     {
  757.         $disablesmilies = "<input type=\"hidden\" name=\"postoptions[disablesmilies]\" value=\"no\" />";
  758.     }
  759.  
  760.     // Show the moderator options
  761.     if(is_moderator($fid))
  762.     {
  763.         $modoptions = $mybb->input['modoptions'];
  764.         if($modoptions['closethread'] == 1)
  765.         {
  766.             $closecheck = "checked=\"checked\"";
  767.         }
  768.         else
  769.         {
  770.             $closecheck = '';
  771.         }
  772.         if($modoptions['stickthread'] == 1)
  773.         {
  774.             $stickycheck = "checked=\"checked\"";
  775.         }
  776.         else
  777.         {
  778.             $stickycheck = '';
  779.         }
  780.         unset($modoptions);
  781.         eval("\$modoptions = \"".$templates->get("newreply_modoptions")."\";");
  782.         $bgcolor = "trow1";
  783.         $bgcolor2 = "trow2";
  784.     }
  785.     else
  786.     {
  787.         $bgcolor = "trow2";
  788.         $bgcolor2 = "trow1";
  789.     }
  790.  
  791.     // Fetch subscription select box
  792.     eval("\$subscriptionmethod = \"".$templates->get("post_subscription_method")."\";");
  793.  
  794.     if($forumpermissions['canpostattachments'] != 0)
  795.     { // Get a listing of the current attachments, if there are any
  796.         $attachcount = 0;
  797.         if($mybb->input['action'] == "editdraft" || ($mybb->input['tid'] && $mybb->input['pid']))
  798.         {
  799.             $attachwhere = "pid='$pid'";
  800.         }
  801.         else
  802.         {
  803.             $attachwhere = "posthash='".$db->escape_string($posthash)."'";
  804.         }
  805.         $query = $db->simple_select("attachments", "*", $attachwhere);
  806.         $attachments = '';
  807.         while($attachment = $db->fetch_array($query))
  808.         {
  809.             $attachment['size'] = get_friendly_size($attachment['filesize']);
  810.             $attachment['icon'] = get_attachment_icon(get_extension($attachment['filename']));
  811.             $attachment['filename'] = htmlspecialchars_uni($attachment['filename']);
  812.  
  813.             if($mybb->settings['bbcodeinserter'] != 0 && $forum['allowmycode'] != 0 && (!$mybb->user['uid'] || $mybb->user['showcodebuttons'] != 0))
  814.             {
  815.                 eval("\$postinsert = \"".$templates->get("post_attachments_attachment_postinsert")."\";");
  816.             }
  817.  
  818.             eval("\$attach_rem_options = \"".$templates->get("post_attachments_attachment_remove")."\";");
  819.  
  820.             $attach_mod_options = '';
  821.             if($attachment['visible'] != 1)
  822.             {
  823.                 eval("\$attachments .= \"".$templates->get("post_attachments_attachment_unapproved")."\";");
  824.             }
  825.             else
  826.             {
  827.                 eval("\$attachments .= \"".$templates->get("post_attachments_attachment")."\";");
  828.             }
  829.             $attachcount++;
  830.         }
  831.         $query = $db->simple_select("attachments", "SUM(filesize) AS ausage", "uid='".$mybb->user['uid']."'");
  832.         $usage = $db->fetch_array($query);
  833.         if($usage['ausage'] > ($mybb->usergroup['attachquota']*1024) && $mybb->usergroup['attachquota'] != 0)
  834.         {
  835.             $noshowattach = 1;
  836.         }
  837.         if($mybb->usergroup['attachquota'] == 0)
  838.         {
  839.             $friendlyquota = $lang->unlimited;
  840.         }
  841.         else
  842.         {
  843.             $friendlyquota = get_friendly_size($mybb->usergroup['attachquota']*1024);
  844.         }
  845.         $friendlyusage = get_friendly_size($usage['ausage']);
  846.         $lang->attach_quota = $lang->sprintf($lang->attach_quota, $friendlyusage, $friendlyquota);
  847.         if($mybb->settings['maxattachments'] == 0 || ($mybb->settings['maxattachments'] != 0 && $attachcount < $mybb->settings['maxattachments']) && !$noshowattach)
  848.         {
  849.             eval("\$newattach = \"".$templates->get("post_attachments_new")."\";");
  850.         }
  851.         eval("\$attachbox = \"".$templates->get("post_attachments")."\";");
  852.  
  853.         $bgcolor = alt_trow();
  854.     }
  855.  
  856.     if($mybb->user['uid'])
  857.     {
  858.         eval("\$savedraftbutton = \"".$templates->get("post_savedraftbutton", 1, 0)."\";");
  859.     }
  860.  
  861.     // Show captcha image for guests if enabled
  862.     if($mybb->settings['captchaimage'] && !$mybb->user['uid'])
  863.     {
  864.         $correct = false;
  865.         require_once MYBB_ROOT.'inc/class_captcha.php';
  866.         $post_captcha = new captcha(false, "post_captcha");
  867.  
  868.         if($mybb->input['previewpost'] || $hide_captcha == true && $post_captcha->type == 1)
  869.         {
  870.             // If previewing a post - check their current captcha input - if correct, hide the captcha input area
  871.             // ... but only if it's a default one, reCAPTCHAs must be filled in every time due to draconian limits
  872.             if($post_captcha->validate_captcha() == true)
  873.             {
  874.                 $correct = true;
  875.  
  876.                 // Generate a hidden list of items for our captcha
  877.                 $captcha = $post_captcha->build_hidden_captcha();
  878.             }
  879.         }
  880.  
  881.         if(!$correct)
  882.         {
  883.             if($post_captcha->type == 1)
  884.             {
  885.                 $post_captcha->build_captcha();
  886.             }
  887.             elseif($post_captcha->type == 2)
  888.             {
  889.                 $post_captcha->build_recaptcha();
  890.             }
  891.  
  892.             if($post_captcha->html)
  893.             {
  894.                 $captcha = $post_captcha->html;
  895.             }
  896.         }
  897.         else if($correct && $post_captcha->type == 2)
  898.         {
  899.             $post_captcha->build_recaptcha();
  900.  
  901.             if($post_captcha->html)
  902.             {
  903.                 $captcha = $post_captcha->html;
  904.             }
  905.         }
  906.     }
  907.  
  908.     if($forumpermissions['canpostpolls'] != 0)
  909.     {
  910.         $lang->max_options = $lang->sprintf($lang->max_options, $mybb->settings['maxpolloptions']);
  911.         eval("\$pollbox = \"".$templates->get("newthread_postpoll")."\";");
  912.     }
  913.  
  914.     // Do we have any forum rules to show for this forum?
  915.     $forumrules = '';
  916.     if($forum['rulestype'] >= 2 && $forum['rules'])
  917.     {
  918.         if(!$forum['rulestitle'])
  919.         {
  920.             $forum['rulestitle'] = $lang->sprintf($lang->forum_rules, $forum['name']);
  921.         }
  922.  
  923.         if(!$parser)
  924.         {
  925.             require_once MYBB_ROOT.'inc/class_parser.php';
  926.             $parser = new postParser;
  927.         }
  928.  
  929.         $rules_parser = array(
  930.             "allow_html" => 1,
  931.             "allow_mycode" => 1,
  932.             "allow_smilies" => 1,
  933.             "allow_imgcode" => 1
  934.         );
  935.  
  936.         $forum['rules'] = $parser->parse_message($forum['rules'], $rules_parser);
  937.         $foruminfo = $forum;
  938.  
  939.         if($forum['rulestype'] == 3)
  940.         {
  941.             eval("\$forumrules = \"".$templates->get("forumdisplay_rules")."\";");
  942.         }
  943.         else if($forum['rulestype'] == 2)
  944.         {
  945.             eval("\$forumrules = \"".$templates->get("forumdisplay_rules_link")."\";");
  946.         }
  947.     }
  948.  
  949.     $plugins->run_hooks("newthread_end");
  950.  
  951.     $forum['name'] = strip_tags($forum['name']);
  952.     $lang->newthread_in = $lang->sprintf($lang->newthread_in, $forum['name']);
  953.  
  954.     $newthread_template = $templates->get("newthread");
  955.  
  956.     // Hide signature option if no permission
  957.     $option_signature = '';
  958.     if($mybb->usergroup['canusesig'] && !$mybb->user['suspendsignature'])
  959.     {
  960.         $option_signature = $templates->get('newthread_options_signature');
  961.     }
  962.     eval("\$option_signature = \"".$option_signature."\";");
  963.  
  964.     eval("\$newthread = \"".$newthread_template."\";");
  965.     output_page($newthread);
  966. }
  967. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement