PageRenderTime 55ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/update_07-01-04/forum/postnewthread.php

https://github.com/frostzhenya/php
PHP | 251 lines | 225 code | 9 blank | 17 comment | 96 complexity | b9204bb400b4c990339b8138b92b874c MD5 | raw file
  1. <?php
  2. /*-------------------------------------------------------+
  3. | PHP-Fusion Content Management System
  4. | Copyright (C) 2002 - 2010 Nick Jones
  5. | http://www.php-fusion.co.uk/
  6. +--------------------------------------------------------+
  7. | Filename: postnewthread.php
  8. | Author: Nick Jones (Digitanium)
  9. +--------------------------------------------------------+
  10. | This program is released as free software under the
  11. | Affero GPL license. You can redistribute it and/or
  12. | modify it under the terms of this license which you
  13. | can read by viewing the included agpl.txt or online
  14. | at www.gnu.org/licenses/agpl.html. Removal of this
  15. | copyright header is strictly prohibited without
  16. | written permission from the original author(s).
  17. +--------------------------------------------------------*/
  18. if (!defined("IN_FUSION")) { die("Access Denied"); }
  19. if (isset($_POST['previewpost']) || isset($_POST['add_poll_option'])) {
  20. $subject = trim(stripinput(censorwords($_POST['subject'])));
  21. $message = trim(stripinput(censorwords($_POST['message'])));
  22. $sticky_thread_check = isset($_POST['sticky_thread']) ? " checked='checked'" : "";
  23. $lock_thread_check = isset($_POST['lock_thread']) ? " checked='checked'" : "";
  24. $sig_checked = isset($_POST['show_sig']) ? " checked='checked'" : "";
  25. $disable_smileys_check = isset($_POST['disable_smileys']) || preg_match("#(\[code\](.*?)\[/code\]|\[geshi=(.*?)\](.*?)\[/geshi\]|\[php\](.*?)\[/php\])#si", $message) ? " checked='checked'" : "";
  26. if ($settings['thread_notify']) { $notify_checked = isset($_POST['notify_me']) ? " checked='checked'" : ""; }
  27. if ($fdata['forum_poll'] && checkgroup($fdata['forum_poll'])) {
  28. $poll_title = trim(stripinput(censorwords($_POST['poll_title'])));
  29. if (isset($_POST['poll_options']) && is_array($_POST['poll_options'])) {
  30. $poll_opts = array();
  31. foreach ($_POST['poll_options'] as $poll_option) {
  32. if ($poll_option) { $poll_opts[] = stripinput($poll_option); }
  33. }
  34. } else {
  35. $poll_opts = array();
  36. }
  37. if (isset($_POST['add_poll_option'])) {
  38. if (count($poll_opts)) { array_push($poll_opts, ""); }
  39. }
  40. }
  41. if (isset($_POST['previewpost'])) {
  42. if ($subject == "") { $subject = $locale['420']; }
  43. if ($message == "") {
  44. $previewmessage = $locale['421'];
  45. } else {
  46. $previewmessage = $message;
  47. if ($sig_checked) { $previewmessage = $previewmessage."\n\n".$userdata['user_sig']; }
  48. if (!$disable_smileys_check) { $previewmessage = parsesmileys($previewmessage); }
  49. $previewmessage = parseubb($previewmessage);
  50. $previewmessage = nl2br($previewmessage);
  51. }
  52. //$is_mod = iMOD && iUSER < "102" ? true : false;
  53. opentable($locale['400']);
  54. echo "<div class='tbl2 forum_breadcrumbs' style='margin-bottom:5px'><a href='index.php'>".$settings['sitename']."</a> &raquo; ".$caption."</div>\n";
  55. if ($fdata['forum_poll'] && checkgroup($fdata['forum_poll'])) {
  56. if ((isset($poll_title) && $poll_title) && (isset($poll_opts) && is_array($poll_opts))) {
  57. echo "<table cellpadding='0' cellspacing='1' width='100%' class='tbl-border' style='margin-bottom:5px'>\n<tr>\n";
  58. echo "<td align='center' class='tbl2'><strong>".$poll_title."</strong></td>\n</tr>\n<tr>\n<td class='tbl1'>\n";
  59. echo "<table align='center' cellpadding='0' cellspacing='0'>\n";
  60. foreach ($poll_opts as $poll_option) {
  61. echo "<tr>\n<td class='tbl1'><input type='radio' name='poll_option' value='$i' style='vertical-align:middle;' /> ".$poll_option."</td>\n</tr>\n";
  62. $i++;
  63. }
  64. echo "</table>\n</td>\n</tr>\n</table>\n";
  65. }
  66. }
  67. echo "<table cellpadding='0' cellspacing='1' width='100%' class='tbl-border forum_thread_table'>\n<tr>\n";
  68. echo "<td colspan='2' class='tbl2'><strong>".$subject."</strong></td>\n</tr>\n";
  69. echo "<tr>\n<td class='tbl2 forum_thread_user_name' style='width:140px;'>".profile_link($userdata['user_id'], $userdata['user_name'], $userdata['user_status'])."</td>\n";
  70. echo "<td class='tbl2 forum_thread_post_date'>".$locale['426'].showdate("forumdate", time())."</td>\n";
  71. echo "</tr>\n<tr>\n<td valign='top' width='140' class='tbl2 forum_thread_user_info'>\n";
  72. if ($userdata['user_avatar'] && file_exists(IMAGES."avatars/".$userdata['user_avatar'])) {
  73. echo "<img src='".IMAGES."avatars/".$userdata['user_avatar']."' alt='' /><br /><br />\n";
  74. }
  75. echo "<span class='small'>".getuserlevel($userdata['user_level'])."</span><br /><br />\n";
  76. echo "<span class='small'><strong>".$locale['423']."</strong> ".$userdata['user_posts']."</span><br />\n";
  77. echo "<span class='small'><strong>".$locale['425']."</strong> ".showdate("%d.%m.%y", $userdata['user_joined'])."</span><br />\n";
  78. echo "<br /></td>\n<td valign='top' class='tbl1 forum_thread_user_post'>".$previewmessage."</td>\n";
  79. echo "</tr>\n</table>\n";
  80. closetable();
  81. }
  82. }
  83. if (isset($_POST['postnewthread'])) {
  84. $subject = trim(stripinput(censorwords($_POST['subject'])));
  85. $message = trim(stripinput(censorwords($_POST['message'])));
  86. $flood = false; $error = 0;
  87. $sticky_thread = isset($_POST['sticky_thread']) && (iMOD || iSUPERADMIN) ? 1 : 0;
  88. $lock_thread = isset($_POST['lock_thread']) && (iMOD || iSUPERADMIN) ? 1 : 0;
  89. $sig = isset($_POST['show_sig']) ? 1 : 0;
  90. $smileys = isset($_POST['disable_smileys']) || preg_match("#(\[code\](.*?)\[/code\]|\[geshi=(.*?)\](.*?)\[/geshi\]|\[php\](.*?)\[/php\])#si", $message) ? 0 : 1;
  91. $thread_poll = 0;
  92. if ($fdata['forum_poll'] && checkgroup($fdata['forum_poll'])) {
  93. if (isset($_POST['poll_options']) && is_array($_POST['poll_options'])) {
  94. foreach ($_POST['poll_options'] as $poll_option) {
  95. if (trim($poll_option)) { $poll_opts[] = trim(stripinput(censorwords($poll_option))); }
  96. unset($poll_option);
  97. }
  98. }
  99. $thread_poll = (trim($_POST['poll_title']) && (isset($poll_opts) && is_array($poll_opts)) ? 1 : 0);
  100. }
  101. if (iMEMBER) {
  102. if ($subject != "" && $message != "") {
  103. require_once INCLUDES."flood_include.php";
  104. if (!flood_control("post_datestamp", DB_POSTS, "post_author='".$userdata['user_id']."'")) {
  105. $result = dbquery("INSERT INTO ".DB_THREADS." (forum_id, thread_subject, thread_author, thread_views, thread_lastpost, thread_lastpostid, thread_lastuser, thread_postcount, thread_poll, thread_sticky, thread_locked) VALUES('".$_GET['forum_id']."', '$subject', '".$userdata['user_id']."', '0', '".time()."', '0', '".$userdata['user_id']."', '1', '".$thread_poll."', '".$sticky_thread."', '".$lock_thread."')");
  106. $thread_id = mysql_insert_id();
  107. $result = dbquery("INSERT INTO ".DB_POSTS." (forum_id, thread_id, post_message, post_showsig, post_smileys, post_author, post_datestamp, post_ip, post_edituser, post_edittime) VALUES ('".$_GET['forum_id']."', '".$thread_id."', '".$message."', '".$sig."', '".$smileys."', '".$userdata['user_id']."', '".time()."', '".USER_IP."', '0', '0')");
  108. $post_id = mysql_insert_id();
  109. $result = dbquery("UPDATE ".DB_FORUMS." SET forum_lastpost='".time()."', forum_postcount=forum_postcount+1, forum_threadcount=forum_threadcount+1, forum_lastuser='".$userdata['user_id']."' WHERE forum_id='".$_GET['forum_id']."'");
  110. $result = dbquery("UPDATE ".DB_THREADS." SET thread_lastpostid='".$post_id."' WHERE thread_id='".$thread_id."'");
  111. $result = dbquery("UPDATE ".DB_USERS." SET user_posts=user_posts+1 WHERE user_id='".$userdata['user_id']."'");
  112. if ($settings['thread_notify'] && isset($_POST['notify_me'])) { $result = dbquery("INSERT INTO ".DB_THREAD_NOTIFY." (thread_id, notify_datestamp, notify_user, notify_status) VALUES('".$thread_id."', '".time()."', '".$userdata['user_id']."', '1')"); }
  113. if (($fdata['forum_poll'] && checkgroup($fdata['forum_poll'])) && $thread_poll) {
  114. $poll_title = trim(stripinput(censorwords($_POST['poll_title'])));
  115. if ($poll_title && (isset($poll_opts) && is_array($poll_opts))) {
  116. $result = dbquery("INSERT INTO ".DB_FORUM_POLLS." (thread_id, forum_poll_title, forum_poll_start, forum_poll_length, forum_poll_votes) VALUES('".$thread_id."', '".$poll_title."', '".time()."', '0', '0')");
  117. $forum_poll_id = mysql_insert_id();
  118. $i = 1;
  119. foreach ($poll_opts as $poll_option) {
  120. $result = dbquery("INSERT INTO ".DB_FORUM_POLL_OPTIONS." (thread_id, forum_poll_option_id, forum_poll_option_text, forum_poll_option_votes) VALUES('".$thread_id."', '".$i."', '".$poll_option."', '0')");
  121. $i++;
  122. }
  123. }
  124. }
  125. if ($fdata['forum_attach'] && checkgroup($fdata['forum_attach'])) {
  126. $attach = $_FILES['attach'];
  127. if ($attach['name'] != "" && !empty($attach['name']) && is_uploaded_file($attach['tmp_name'])) {
  128. $attachname = stripfilename(substr($attach['name'], 0, strrpos($attach['name'], ".")));
  129. $attachext = strtolower(strrchr($attach['name'],"."));
  130. if (preg_match("/^[-0-9A-Z_\[\]]+$/i", $attachname) && $attach['size'] <= $settings['attachmax']) {
  131. $attachtypes = explode(",", $settings['attachtypes']);
  132. if (in_array($attachext, $attachtypes)) {
  133. $attachname .= $attachext;
  134. move_uploaded_file($attach['tmp_name'], FORUM."attachments/".$attachname);
  135. chmod(FORUM."attachments/".$attachname,0644);
  136. if (in_array($attachext, $imagetypes) && (!@getimagesize(FORUM."attachments/".$attachname) || !@verify_image(FORUM."attachments/".$attachname))) {
  137. unlink(FORUM."attachments/".$attachname);
  138. $error = 1;
  139. }
  140. if (!$error) { $result = dbquery("INSERT INTO ".DB_FORUM_ATTACHMENTS." (thread_id, post_id, attach_name, attach_ext, attach_size) VALUES ('".$thread_id."', '".$post_id."', '$attachname', '$attachext', '".$attach['size']."')"); }
  141. } else {
  142. @unlink($attach['tmp_name']);
  143. $error = 1;
  144. }
  145. } else {
  146. @unlink($attach['tmp_name']);
  147. $error = 2;
  148. }
  149. }
  150. }
  151. } else {
  152. redirect("viewforum.php?forum_id=".$_GET['forum_id']);
  153. }
  154. } else {
  155. $error = 3;
  156. }
  157. } else {
  158. $error = 4;
  159. }
  160. if ($error > 2) {
  161. redirect("postify.php?post=new&error=$error&forum_id=".$_GET['forum_id']);
  162. } else {
  163. redirect("postify.php?post=new&error=$error&forum_id=".$_GET['forum_id']."&thread_id=".$thread_id."");
  164. }
  165. } else {
  166. if (!isset($_POST['previewpost']) && !isset($_POST['add_poll_option'])) {
  167. $subject = "";
  168. $message = "";
  169. $sticky_thread_check = "";
  170. $lock_thread_check = "";
  171. $disable_smileys_check = "";
  172. $sig_checked = " checked='checked'";
  173. if ($settings['thread_notify']) { $notify_checked = ""; }
  174. $poll_title = "";
  175. $poll_opts = array();
  176. }
  177. add_to_title($locale['global_201'].$locale['401']);
  178. echo "<!--pre_postnewthread-->";
  179. opentable($locale['401']);
  180. if (!isset($_POST['previewpost'])) { echo "<div class='tbl2 forum_breadcrumbs' style='margin-bottom:5px'><a href='index.php'>".$settings['sitename']."</a> &raquo; ".$caption."</div>\n"; }
  181. echo "<form id='inputform' method='post' action='".FUSION_SELF."?action=newthread&amp;forum_id=".$_GET['forum_id']."' enctype='multipart/form-data'>\n";
  182. echo "<table cellpadding='0' cellspacing='1' width='100%' class='tbl-border'>\n<tr>\n";
  183. echo "<td width='145' class='tbl2'>".$locale['460']."</td>\n";
  184. echo "<td class='tbl1'><input type='text' name='subject' value='".$subject."' class='textbox' maxlength='255' style='width: 250px' /></td>\n";
  185. echo "</tr>\n<tr>\n";
  186. echo "<td valign='top' width='145' class='tbl2'>".$locale['461']."</td>\n";
  187. echo "<td class='tbl1'><textarea name='message' cols='60' rows='15' class='textbox' style='width:98%'>".$message."</textarea></td>\n";
  188. echo "</tr>\n<tr>\n";
  189. echo "<td width='145' class='tbl2'>&nbsp;</td>\n";
  190. echo "<td class='tbl1'>".display_bbcodes("99%", "message")."</td>\n";
  191. echo "</tr>\n<tr>\n";
  192. echo "<td valign='top' width='145' class='tbl2'>".$locale['463']."</td>\n";
  193. echo "<td class='tbl1'>\n";
  194. if (iMOD || iSUPERADMIN) {
  195. echo "<label><input type='checkbox' name='sticky_thread' value='1'".$sticky_thread_check." /> ".$locale['480']."</label><br />\n";
  196. echo "<label><input type='checkbox' name='lock_thread' value='1'".$lock_thread_check." /> ".$locale['481']."</label><br />\n";
  197. }
  198. echo "<label><input type='checkbox' name='disable_smileys' value='1'".$disable_smileys_check." /> ".$locale['482']."</label>";
  199. if (array_key_exists("user_sig", $userdata) && $userdata['user_sig']) {
  200. echo "<br />\n<label><input type='checkbox' name='show_sig' value='1'".$sig_checked." /> ".$locale['483']."</label>";
  201. }
  202. if ($settings['thread_notify']) { echo "<br />\n<label><input type='checkbox' name='notify_me' value='1'".$notify_checked." /> ".$locale['486']."</label>"; }
  203. echo "</td>\n</tr>\n";
  204. if ($fdata['forum_attach'] && checkgroup($fdata['forum_attach'])) {
  205. echo "<tr>\n<td width='145' class='tbl2'>".$locale['464']."</td>\n";
  206. echo "<td class='tbl1'><input type='file' name='attach' class='textbox' style='width:200px;' /><br />\n";
  207. echo "<span class='small2'>".sprintf($locale['466'], parsebytesize($settings['attachmax']), str_replace(',', ' ', $settings['attachtypes']))."</span></td>\n";
  208. echo "</tr>\n";
  209. }
  210. if ($fdata['forum_poll'] && checkgroup($fdata['forum_poll'])) {
  211. echo "<tr>\n<td align='center' colspan='2' class='tbl2'>".$locale['467']."</td>\n";
  212. echo "</tr>\n<tr>\n";
  213. echo "<td width='145' class='tbl2'>".$locale['469']."</td>\n";
  214. echo "<td class='tbl1'><input type='text' name='poll_title' value='".$poll_title."' class='textbox' maxlength='255' style='width:250px' /></td>\n";
  215. echo "</tr>\n";
  216. $i = 1;
  217. if (isset($poll_opts) && is_array($poll_opts) && count($poll_opts)) {
  218. foreach ($poll_opts as $poll_option) {
  219. echo "<tr>\n<td width='145' class='tbl2'>".$locale['470']." ".$i."</td>\n";
  220. echo "<td class='tbl1'><input type='text' name='poll_options[$i]' value='".$poll_option."' class='textbox' maxlength='255' style='width:250px'>";
  221. if ($i == count($poll_opts)) {
  222. echo " <input type='submit' name='add_poll_option' value='".$locale['471']."' class='button' />";
  223. }
  224. echo "</td>\n</tr>\n";
  225. $i++;
  226. }
  227. } else {
  228. echo "<tr>\n<td width='145' class='tbl2'>".$locale['470']." 1</td>\n";
  229. echo "<td class='tbl1'><input type='text' name='poll_options[1]' value='' class='textbox' maxlength='255' style='width:250px' /></td>\n</tr>\n";
  230. echo "<tr>\n<td width='145' class='tbl2'>".$locale['470']." 2</td>\n";
  231. echo "<td class='tbl1'><input type='text' name='poll_options[2]' value='' class='textbox' maxlength='255' style='width:250px' /> ";
  232. echo "<input type='submit' name='add_poll_option' value='".$locale['471']."' class='button' /></td>\n</tr>\n";
  233. }
  234. }
  235. echo "<tr>\n<td align='center' colspan='2' class='tbl1'>\n";
  236. echo "<input type='submit' name='previewpost' value='".$locale['400']."' class='button' />\n";
  237. echo "<input type='submit' name='postnewthread' value='".$locale['401']."' class='button' />\n";
  238. echo "</td>\n</tr>\n</table>\n</form>\n";
  239. closetable();
  240. echo "<!--sub_postnewthread-->";
  241. }
  242. ?>