PageRenderTime 52ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/forum/posting.php

https://github.com/GreyTeardrop/socionicasys-forum
PHP | 1647 lines | 1258 code | 255 blank | 134 comment | 599 complexity | 56098cf7969bb612f86d27cd381cebfa MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-3.0, MPL-2.0-no-copyleft-exception

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. *
  4. * @package phpBB3
  5. * @version $Id$
  6. * @copyright (c) 2005 phpBB Group
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. * @ignore
  12. */
  13. define('IN_PHPBB', true);
  14. $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
  15. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  16. include($phpbb_root_path . 'common.' . $phpEx);
  17. include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
  18. include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  19. include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
  20. // Start session management
  21. $user->session_begin();
  22. $auth->acl($user->data);
  23. // Grab only parameters needed here
  24. $post_id = request_var('p', 0);
  25. $topic_id = request_var('t', 0);
  26. $forum_id = request_var('f', 0);
  27. $draft_id = request_var('d', 0);
  28. $lastclick = request_var('lastclick', 0);
  29. $submit = (isset($_POST['post'])) ? true : false;
  30. $preview = (isset($_POST['preview'])) ? true : false;
  31. $save = (isset($_POST['save'])) ? true : false;
  32. $load = (isset($_POST['load'])) ? true : false;
  33. $delete = (isset($_POST['delete'])) ? true : false;
  34. $cancel = (isset($_POST['cancel']) && !isset($_POST['save'])) ? true : false;
  35. $refresh = (isset($_POST['add_file']) || isset($_POST['delete_file']) || isset($_POST['full_editor']) || isset($_POST['cancel_unglobalise']) || $save || $load) ? true : false;
  36. $mode = ($delete && !$preview && !$refresh && $submit) ? 'delete' : request_var('mode', '');
  37. $error = $post_data = array();
  38. $current_time = time();
  39. // Was cancel pressed? If so then redirect to the appropriate page
  40. if ($cancel || ($current_time - $lastclick < 2 && $submit))
  41. {
  42. $f = ($forum_id) ? 'f=' . $forum_id . '&amp;' : '';
  43. $redirect = ($post_id) ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", $f . 'p=' . $post_id) . '#p' . $post_id : (($topic_id) ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", $f . 't=' . $topic_id) : (($forum_id) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) : append_sid("{$phpbb_root_path}index.$phpEx")));
  44. redirect($redirect);
  45. }
  46. if (in_array($mode, array('post', 'reply', 'quote', 'edit', 'delete')) && !$forum_id)
  47. {
  48. trigger_error('NO_FORUM');
  49. }
  50. // We need to know some basic information in all cases before we do anything.
  51. switch ($mode)
  52. {
  53. case 'post':
  54. $sql = 'SELECT *
  55. FROM ' . FORUMS_TABLE . "
  56. WHERE forum_id = $forum_id";
  57. break;
  58. case 'bump':
  59. case 'reply':
  60. if (!$topic_id)
  61. {
  62. trigger_error('NO_TOPIC');
  63. }
  64. // Force forum id
  65. $sql = 'SELECT forum_id
  66. FROM ' . TOPICS_TABLE . '
  67. WHERE topic_id = ' . $topic_id;
  68. $result = $db->sql_query($sql);
  69. $f_id = (int) $db->sql_fetchfield('forum_id');
  70. $db->sql_freeresult($result);
  71. $forum_id = (!$f_id) ? $forum_id : $f_id;
  72. $sql = 'SELECT f.*, t.*
  73. FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f
  74. WHERE t.topic_id = $topic_id
  75. AND (f.forum_id = t.forum_id
  76. OR f.forum_id = $forum_id)" .
  77. (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1');
  78. break;
  79. case 'quote':
  80. case 'edit':
  81. case 'delete':
  82. if (!$post_id)
  83. {
  84. $user->setup('posting');
  85. trigger_error('NO_POST');
  86. }
  87. // Force forum id
  88. $sql = 'SELECT forum_id
  89. FROM ' . POSTS_TABLE . '
  90. WHERE post_id = ' . $post_id;
  91. $result = $db->sql_query($sql);
  92. $f_id = (int) $db->sql_fetchfield('forum_id');
  93. $db->sql_freeresult($result);
  94. $forum_id = (!$f_id) ? $forum_id : $f_id;
  95. $sql = 'SELECT f.*, t.*, p.*, u.username, u.username_clean, u.user_sig, u.user_sig_bbcode_uid, u.user_sig_bbcode_bitfield
  96. FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . ' f, ' . USERS_TABLE . " u
  97. WHERE p.post_id = $post_id
  98. AND t.topic_id = p.topic_id
  99. AND u.user_id = p.poster_id
  100. AND (f.forum_id = t.forum_id
  101. OR f.forum_id = $forum_id)" .
  102. (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND p.post_approved = 1');
  103. break;
  104. case 'smilies':
  105. $sql = '';
  106. generate_smilies('window', $forum_id);
  107. break;
  108. case 'popup':
  109. if ($forum_id)
  110. {
  111. $sql = 'SELECT forum_style
  112. FROM ' . FORUMS_TABLE . '
  113. WHERE forum_id = ' . $forum_id;
  114. }
  115. else
  116. {
  117. upload_popup();
  118. return;
  119. }
  120. break;
  121. default:
  122. $sql = '';
  123. break;
  124. }
  125. if (!$sql)
  126. {
  127. $user->setup('posting');
  128. trigger_error('NO_POST_MODE');
  129. }
  130. $result = $db->sql_query($sql);
  131. $post_data = $db->sql_fetchrow($result);
  132. $db->sql_freeresult($result);
  133. if (!$post_data)
  134. {
  135. if (!($mode == 'post' || $mode == 'bump' || $mode == 'reply'))
  136. {
  137. $user->setup('posting');
  138. }
  139. trigger_error(($mode == 'post' || $mode == 'bump' || $mode == 'reply') ? 'NO_TOPIC' : 'NO_POST');
  140. }
  141. // Not able to reply to unapproved posts/topics
  142. // TODO: add more descriptive language key
  143. if ($auth->acl_get('m_approve', $forum_id) && ((($mode == 'reply' || $mode == 'bump') && !$post_data['topic_approved']) || ($mode == 'quote' && !$post_data['post_approved'])))
  144. {
  145. trigger_error(($mode == 'reply' || $mode == 'bump') ? 'TOPIC_UNAPPROVED' : 'POST_UNAPPROVED');
  146. }
  147. if ($mode == 'popup')
  148. {
  149. upload_popup($post_data['forum_style']);
  150. return;
  151. }
  152. $user->setup(array('posting', 'mcp', 'viewtopic'), $post_data['forum_style']);
  153. if ($config['enable_post_confirm'] && !$user->data['is_registered'])
  154. {
  155. include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
  156. $captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']);
  157. $captcha->init(CONFIRM_POST);
  158. }
  159. // Use post_row values in favor of submitted ones...
  160. $forum_id = (!empty($post_data['forum_id'])) ? (int) $post_data['forum_id'] : (int) $forum_id;
  161. $topic_id = (!empty($post_data['topic_id'])) ? (int) $post_data['topic_id'] : (int) $topic_id;
  162. $post_id = (!empty($post_data['post_id'])) ? (int) $post_data['post_id'] : (int) $post_id;
  163. // Need to login to passworded forum first?
  164. if ($post_data['forum_password'])
  165. {
  166. login_forum_box(array(
  167. 'forum_id' => $forum_id,
  168. 'forum_password' => $post_data['forum_password'])
  169. );
  170. }
  171. // Check permissions
  172. if ($user->data['is_bot'])
  173. {
  174. redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
  175. }
  176. // Is the user able to read within this forum?
  177. if (!$auth->acl_get('f_read', $forum_id))
  178. {
  179. if ($user->data['user_id'] != ANONYMOUS)
  180. {
  181. trigger_error('USER_CANNOT_READ');
  182. }
  183. login_box('', $user->lang['LOGIN_EXPLAIN_POST']);
  184. }
  185. // Permission to do the action asked?
  186. $is_authed = false;
  187. switch ($mode)
  188. {
  189. case 'post':
  190. if ($auth->acl_get('f_post', $forum_id))
  191. {
  192. $is_authed = true;
  193. }
  194. break;
  195. case 'bump':
  196. if ($auth->acl_get('f_bump', $forum_id))
  197. {
  198. $is_authed = true;
  199. }
  200. break;
  201. case 'quote':
  202. $post_data['post_edit_locked'] = 0;
  203. // no break;
  204. case 'reply':
  205. if ($auth->acl_get('f_reply', $forum_id))
  206. {
  207. $is_authed = true;
  208. }
  209. break;
  210. case 'edit':
  211. if ($user->data['is_registered'] && $auth->acl_gets('f_edit', 'm_edit', $forum_id))
  212. {
  213. $is_authed = true;
  214. }
  215. break;
  216. case 'delete':
  217. if ($user->data['is_registered'] && $auth->acl_gets('f_delete', 'm_delete', $forum_id))
  218. {
  219. $is_authed = true;
  220. }
  221. break;
  222. }
  223. if (!$is_authed)
  224. {
  225. $check_auth = ($mode == 'quote') ? 'reply' : $mode;
  226. if ($user->data['is_registered'])
  227. {
  228. trigger_error('USER_CANNOT_' . strtoupper($check_auth));
  229. }
  230. login_box('', $user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)]);
  231. }
  232. // Is the user able to post within this forum?
  233. if ($post_data['forum_type'] != FORUM_POST && in_array($mode, array('post', 'bump', 'quote', 'reply')))
  234. {
  235. trigger_error('USER_CANNOT_FORUM_POST');
  236. }
  237. // Forum/Topic locked?
  238. if (($post_data['forum_status'] == ITEM_LOCKED || (isset($post_data['topic_status']) && $post_data['topic_status'] == ITEM_LOCKED)) && !$auth->acl_get('m_edit', $forum_id))
  239. {
  240. trigger_error(($post_data['forum_status'] == ITEM_LOCKED) ? 'FORUM_LOCKED' : 'TOPIC_LOCKED');
  241. }
  242. // Can we edit this post ... if we're a moderator with rights then always yes
  243. // else it depends on editing times, lock status and if we're the correct user
  244. if ($mode == 'edit' && !$auth->acl_get('m_edit', $forum_id))
  245. {
  246. if ($user->data['user_id'] != $post_data['poster_id'])
  247. {
  248. trigger_error('USER_CANNOT_EDIT');
  249. }
  250. if (!($post_data['post_time'] > time() - ($config['edit_time'] * 60) || !$config['edit_time']))
  251. {
  252. trigger_error('CANNOT_EDIT_TIME');
  253. }
  254. if ($post_data['post_edit_locked'])
  255. {
  256. trigger_error('CANNOT_EDIT_POST_LOCKED');
  257. }
  258. }
  259. // Handle delete mode...
  260. if ($mode == 'delete')
  261. {
  262. //-- mod: Prime Trash Bin (Posts) -------------------------------------------//
  263. include($phpbb_root_path . 'includes/prime_trash_bin_b.' . $phpEx);
  264. handle_post_stifle($forum_id, $topic_id, $post_id, $post_data);
  265. //-- end: Prime Trash Bin (Posts) -------------------------------------------//
  266. handle_post_delete($forum_id, $topic_id, $post_id, $post_data);
  267. return;
  268. }
  269. // Handle bump mode...
  270. if ($mode == 'bump')
  271. {
  272. if ($bump_time = bump_topic_allowed($forum_id, $post_data['topic_bumped'], $post_data['topic_last_post_time'], $post_data['topic_poster'], $post_data['topic_last_poster_id'])
  273. && check_link_hash(request_var('hash', ''), "topic_{$post_data['topic_id']}"))
  274. {
  275. $meta_url = phpbb_bump_topic($forum_id, $topic_id, $post_data, $current_time);
  276. meta_refresh(3, $meta_url);
  277. $message = $user->lang['TOPIC_BUMPED'] . '<br /><br />' . sprintf($user->lang['VIEW_MESSAGE'], '<a href="' . $meta_url . '">', '</a>');
  278. $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
  279. trigger_error($message);
  280. }
  281. trigger_error('BUMP_ERROR');
  282. }
  283. // Subject length limiting to 60 characters if first post...
  284. if ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_data['post_id']))
  285. {
  286. $template->assign_var('S_NEW_MESSAGE', true);
  287. }
  288. // Determine some vars
  289. if (isset($post_data['poster_id']) && $post_data['poster_id'] == ANONYMOUS)
  290. {
  291. $post_data['quote_username'] = (!empty($post_data['post_username'])) ? $post_data['post_username'] : $user->lang['GUEST'];
  292. }
  293. else
  294. {
  295. $post_data['quote_username'] = isset($post_data['username']) ? $post_data['username'] : '';
  296. }
  297. $post_data['post_edit_locked'] = (isset($post_data['post_edit_locked'])) ? (int) $post_data['post_edit_locked'] : 0;
  298. $post_data['post_subject_md5'] = (isset($post_data['post_subject']) && $mode == 'edit') ? md5($post_data['post_subject']) : '';
  299. $post_data['post_subject'] = (in_array($mode, array('quote', 'edit'))) ? $post_data['post_subject'] : ((isset($post_data['topic_title'])) ? $post_data['topic_title'] : '');
  300. $post_data['topic_time_limit'] = (isset($post_data['topic_time_limit'])) ? (($post_data['topic_time_limit']) ? (int) $post_data['topic_time_limit'] / 86400 : (int) $post_data['topic_time_limit']) : 0;
  301. $post_data['poll_length'] = (!empty($post_data['poll_length'])) ? (int) $post_data['poll_length'] / 86400 : 0;
  302. $post_data['poll_start'] = (!empty($post_data['poll_start'])) ? (int) $post_data['poll_start'] : 0;
  303. $post_data['icon_id'] = (!isset($post_data['icon_id']) || in_array($mode, array('quote', 'reply'))) ? 0 : (int) $post_data['icon_id'];
  304. $post_data['poll_options'] = array();
  305. // Get Poll Data
  306. if ($post_data['poll_start'])
  307. {
  308. $sql = 'SELECT poll_option_text
  309. FROM ' . POLL_OPTIONS_TABLE . "
  310. WHERE topic_id = $topic_id
  311. ORDER BY poll_option_id";
  312. $result = $db->sql_query($sql);
  313. while ($row = $db->sql_fetchrow($result))
  314. {
  315. $post_data['poll_options'][] = trim($row['poll_option_text']);
  316. }
  317. $db->sql_freeresult($result);
  318. }
  319. if ($mode == 'edit')
  320. {
  321. $original_poll_data = array(
  322. 'poll_title' => $post_data['poll_title'],
  323. 'poll_length' => $post_data['poll_length'],
  324. 'poll_max_options' => $post_data['poll_max_options'],
  325. 'poll_option_text' => implode("\n", $post_data['poll_options']),
  326. 'poll_start' => $post_data['poll_start'],
  327. 'poll_last_vote' => $post_data['poll_last_vote'],
  328. 'poll_vote_change' => $post_data['poll_vote_change'],
  329. );
  330. }
  331. $orig_poll_options_size = sizeof($post_data['poll_options']);
  332. $message_parser = new parse_message();
  333. if (isset($post_data['post_text']))
  334. {
  335. $message_parser->message = &$post_data['post_text'];
  336. unset($post_data['post_text']);
  337. }
  338. // Set some default variables
  339. $uninit = array('post_attachment' => 0, 'poster_id' => $user->data['user_id'], 'enable_magic_url' => 0, 'topic_status' => 0, 'topic_type' => POST_NORMAL, 'post_subject' => '', 'topic_title' => '', 'post_time' => 0, 'post_edit_reason' => '', 'notify_set' => 0);
  340. foreach ($uninit as $var_name => $default_value)
  341. {
  342. if (!isset($post_data[$var_name]))
  343. {
  344. $post_data[$var_name] = $default_value;
  345. }
  346. }
  347. unset($uninit);
  348. // Always check if the submitted attachment data is valid and belongs to the user.
  349. // Further down (especially in submit_post()) we do not check this again.
  350. $message_parser->get_submitted_attachment_data($post_data['poster_id']);
  351. if ($post_data['post_attachment'] && !$submit && !$refresh && !$preview && $mode == 'edit')
  352. {
  353. // Do not change to SELECT *
  354. $sql = 'SELECT attach_id, is_orphan, attach_comment, real_filename
  355. FROM ' . ATTACHMENTS_TABLE . "
  356. WHERE post_msg_id = $post_id
  357. AND in_message = 0
  358. AND is_orphan = 0
  359. ORDER BY filetime DESC";
  360. $result = $db->sql_query($sql);
  361. $message_parser->attachment_data = array_merge($message_parser->attachment_data, $db->sql_fetchrowset($result));
  362. $db->sql_freeresult($result);
  363. }
  364. if ($post_data['poster_id'] == ANONYMOUS)
  365. {
  366. $post_data['username'] = ($mode == 'quote' || $mode == 'edit') ? trim($post_data['post_username']) : '';
  367. }
  368. else
  369. {
  370. $post_data['username'] = ($mode == 'quote' || $mode == 'edit') ? trim($post_data['username']) : '';
  371. }
  372. $post_data['enable_urls'] = $post_data['enable_magic_url'];
  373. if ($mode != 'edit')
  374. {
  375. $post_data['enable_sig'] = ($config['allow_sig'] && $user->optionget('attachsig')) ? true: false;
  376. $post_data['enable_smilies'] = ($config['allow_smilies'] && $user->optionget('smilies')) ? true : false;
  377. $post_data['enable_bbcode'] = ($config['allow_bbcode'] && $user->optionget('bbcode')) ? true : false;
  378. $post_data['enable_urls'] = true;
  379. }
  380. $post_data['enable_magic_url'] = $post_data['drafts'] = false;
  381. // User own some drafts?
  382. if ($user->data['is_registered'] && $auth->acl_get('u_savedrafts') && ($mode == 'reply' || $mode == 'post' || $mode == 'quote'))
  383. {
  384. $sql = 'SELECT draft_id
  385. FROM ' . DRAFTS_TABLE . '
  386. WHERE user_id = ' . $user->data['user_id'] .
  387. (($forum_id) ? ' AND forum_id = ' . (int) $forum_id : '') .
  388. (($topic_id) ? ' AND topic_id = ' . (int) $topic_id : '') .
  389. (($draft_id) ? " AND draft_id <> $draft_id" : '');
  390. $result = $db->sql_query_limit($sql, 1);
  391. if ($db->sql_fetchrow($result))
  392. {
  393. $post_data['drafts'] = true;
  394. }
  395. $db->sql_freeresult($result);
  396. }
  397. $check_value = (($post_data['enable_bbcode']+1) << 8) + (($post_data['enable_smilies']+1) << 4) + (($post_data['enable_urls']+1) << 2) + (($post_data['enable_sig']+1) << 1);
  398. // Check if user is watching this topic
  399. if ($mode != 'post' && $config['allow_topic_notify'] && $user->data['is_registered'])
  400. {
  401. $sql = 'SELECT topic_id
  402. FROM ' . TOPICS_WATCH_TABLE . '
  403. WHERE topic_id = ' . $topic_id . '
  404. AND user_id = ' . $user->data['user_id'];
  405. $result = $db->sql_query($sql);
  406. $post_data['notify_set'] = (int) $db->sql_fetchfield('topic_id');
  407. $db->sql_freeresult($result);
  408. }
  409. // Do we want to edit our post ?
  410. if ($mode == 'edit' && $post_data['bbcode_uid'])
  411. {
  412. $message_parser->bbcode_uid = $post_data['bbcode_uid'];
  413. }
  414. // HTML, BBCode, Smilies, Images and Flash status
  415. $bbcode_status = ($config['allow_bbcode'] && $auth->acl_get('f_bbcode', $forum_id)) ? true : false;
  416. $smilies_status = ($config['allow_smilies'] && $auth->acl_get('f_smilies', $forum_id)) ? true : false;
  417. $img_status = ($bbcode_status && $auth->acl_get('f_img', $forum_id)) ? true : false;
  418. $url_status = ($config['allow_post_links']) ? true : false;
  419. $flash_status = ($bbcode_status && $auth->acl_get('f_flash', $forum_id) && $config['allow_post_flash']) ? true : false;
  420. $quote_status = true;
  421. // Save Draft
  422. if ($save && $user->data['is_registered'] && $auth->acl_get('u_savedrafts') && ($mode == 'reply' || $mode == 'post' || $mode == 'quote'))
  423. {
  424. $subject = utf8_normalize_nfc(request_var('subject', '', true));
  425. $subject = (!$subject && $mode != 'post') ? $post_data['topic_title'] : $subject;
  426. $message = utf8_normalize_nfc(request_var('message', '', true));
  427. if ($subject && $message)
  428. {
  429. if (confirm_box(true))
  430. {
  431. $sql = 'INSERT INTO ' . DRAFTS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
  432. 'user_id' => (int) $user->data['user_id'],
  433. 'topic_id' => (int) $topic_id,
  434. 'forum_id' => (int) $forum_id,
  435. 'save_time' => (int) $current_time,
  436. 'draft_subject' => (string) $subject,
  437. 'draft_message' => (string) $message)
  438. );
  439. $db->sql_query($sql);
  440. $meta_info = ($mode == 'post') ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) : append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id");
  441. meta_refresh(3, $meta_info);
  442. $message = $user->lang['DRAFT_SAVED'] . '<br /><br />';
  443. $message .= ($mode != 'post') ? sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $meta_info . '">', '</a>') . '<br /><br />' : '';
  444. $message .= sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
  445. trigger_error($message);
  446. }
  447. else
  448. {
  449. $s_hidden_fields = build_hidden_fields(array(
  450. 'mode' => $mode,
  451. 'save' => true,
  452. 'f' => $forum_id,
  453. 't' => $topic_id,
  454. 'subject' => $subject,
  455. 'message' => $message,
  456. 'attachment_data' => $message_parser->attachment_data,
  457. )
  458. );
  459. $hidden_fields = array(
  460. 'icon_id' => 0,
  461. 'disable_bbcode' => false,
  462. 'disable_smilies' => false,
  463. 'disable_magic_url' => false,
  464. 'attach_sig' => true,
  465. 'lock_topic' => false,
  466. 'topic_type' => POST_NORMAL,
  467. 'topic_time_limit' => 0,
  468. 'poll_title' => '',
  469. 'poll_option_text' => '',
  470. 'poll_max_options' => 1,
  471. 'poll_length' => 0,
  472. 'poll_vote_change' => false,
  473. );
  474. foreach ($hidden_fields as $name => $default)
  475. {
  476. if (!isset($_POST[$name]))
  477. {
  478. // Don't include it, if its not available
  479. unset($hidden_fields[$name]);
  480. continue;
  481. }
  482. if (is_bool($default))
  483. {
  484. // Use the string representation
  485. $hidden_fields[$name] = request_var($name, '');
  486. }
  487. else
  488. {
  489. $hidden_fields[$name] = request_var($name, $default);
  490. }
  491. }
  492. $s_hidden_fields .= build_hidden_fields($hidden_fields);
  493. confirm_box(false, 'SAVE_DRAFT', $s_hidden_fields);
  494. }
  495. }
  496. else
  497. {
  498. if (utf8_clean_string($subject) === '')
  499. {
  500. $error[] = $user->lang['EMPTY_SUBJECT'];
  501. }
  502. if (utf8_clean_string($message) === '')
  503. {
  504. $error[] = $user->lang['TOO_FEW_CHARS'];
  505. }
  506. }
  507. unset($subject, $message);
  508. }
  509. // Load requested Draft
  510. if ($draft_id && ($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $user->data['is_registered'] && $auth->acl_get('u_savedrafts'))
  511. {
  512. $sql = 'SELECT draft_subject, draft_message
  513. FROM ' . DRAFTS_TABLE . "
  514. WHERE draft_id = $draft_id
  515. AND user_id = " . $user->data['user_id'];
  516. $result = $db->sql_query_limit($sql, 1);
  517. $row = $db->sql_fetchrow($result);
  518. $db->sql_freeresult($result);
  519. if ($row)
  520. {
  521. $post_data['post_subject'] = $row['draft_subject'];
  522. $message_parser->message = $row['draft_message'];
  523. $template->assign_var('S_DRAFT_LOADED', true);
  524. }
  525. else
  526. {
  527. $draft_id = 0;
  528. }
  529. }
  530. // Load draft overview
  531. if ($load && ($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $post_data['drafts'])
  532. {
  533. load_drafts($topic_id, $forum_id);
  534. }
  535. if ($submit || $preview || $refresh)
  536. {
  537. $post_data['topic_cur_post_id'] = request_var('topic_cur_post_id', 0);
  538. $post_data['post_subject'] = utf8_normalize_nfc(request_var('subject', '', true));
  539. $message_parser->message = utf8_normalize_nfc(request_var('message', '', true));
  540. $post_data['username'] = utf8_normalize_nfc(request_var('username', $post_data['username'], true));
  541. $post_data['post_edit_reason'] = (!empty($_POST['edit_reason']) && $mode == 'edit' && $auth->acl_get('m_edit', $forum_id)) ? utf8_normalize_nfc(request_var('edit_reason', '', true)) : '';
  542. $post_data['orig_topic_type'] = $post_data['topic_type'];
  543. $post_data['topic_type'] = request_var('topic_type', (($mode != 'post') ? (int) $post_data['topic_type'] : POST_NORMAL));
  544. $post_data['topic_time_limit'] = request_var('topic_time_limit', (($mode != 'post') ? (int) $post_data['topic_time_limit'] : 0));
  545. if ($post_data['enable_icons'] && $auth->acl_get('f_icons', $forum_id))
  546. {
  547. $post_data['icon_id'] = request_var('icon', (int) $post_data['icon_id']);
  548. }
  549. $post_data['enable_bbcode'] = (!$bbcode_status || isset($_POST['disable_bbcode'])) ? false : true;
  550. $post_data['enable_smilies'] = (!$smilies_status || isset($_POST['disable_smilies'])) ? false : true;
  551. $post_data['enable_urls'] = (isset($_POST['disable_magic_url'])) ? 0 : 1;
  552. $post_data['enable_sig'] = (!$config['allow_sig'] || !$auth->acl_get('f_sigs', $forum_id) || !$auth->acl_get('u_sig')) ? false : ((isset($_POST['attach_sig']) && $user->data['is_registered']) ? true : false);
  553. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  554. if (!empty($phpbb_seo->seo_opt['sql_rewrite'])) {
  555. if ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_id)) {
  556. $phpbb_seo->set_url($post_data['forum_name'], $forum_id, 'forum');
  557. $_parent = $post_data['topic_type'] == POST_GLOBAL ? $phpbb_seo->seo_static['global_announce'] : $phpbb_seo->seo_url['forum'][$forum_id];
  558. $_t = !empty($post_data['topic_id']) ? max(0, (int) $post_data['topic_id'] ) : 0;
  559. $_url = $phpbb_seo->url_can_edit($forum_id) ? utf8_normalize_nfc(request_var('url', '', true)) : ( isset($post_data['topic_url']) ? $post_data['topic_url'] : '' );
  560. if (!$phpbb_seo->check_url('topic', $_url, $_parent)) {
  561. if (!empty($_url)) {
  562. // Here we get rid of the seo delim (-t) and put it back even in simple mod
  563. // to be able to handle all cases at once
  564. $_url = preg_replace('`' . $phpbb_seo->seo_delim['topic'] . '$`i', '', $_url);
  565. $_title = $phpbb_seo->get_url_info('topic', $_url . $phpbb_seo->seo_delim['topic'] . $_t);
  566. } else {
  567. $_title = $phpbb_seo->modrtype > 2 ? censor_text($post_data['post_subject']) : '';
  568. }
  569. unset($phpbb_seo->seo_url['topic'][$_t]);
  570. $_url = $phpbb_seo->get_url_info('topic', $phpbb_seo->prepare_url( 'topic', $_title, $_t, $_parent , (( empty($_title) || ($_title == $phpbb_seo->seo_static['topic']) ) ? true : false)), 'url');
  571. unset($phpbb_seo->seo_url['topic'][$_t]);
  572. }
  573. $post_data['topic_url'] = $_url;
  574. }
  575. }
  576. // www.phpBB-SEO.com SEO TOOLKIT END
  577. if ($config['allow_topic_notify'] && $user->data['is_registered'])
  578. {
  579. $notify = (isset($_POST['notify'])) ? true : false;
  580. }
  581. else
  582. {
  583. $notify = false;
  584. }
  585. $topic_lock = (isset($_POST['lock_topic'])) ? true : false;
  586. $post_lock = (isset($_POST['lock_post'])) ? true : false;
  587. $poll_delete = (isset($_POST['poll_delete'])) ? true : false;
  588. if ($submit)
  589. {
  590. $status_switch = (($post_data['enable_bbcode']+1) << 8) + (($post_data['enable_smilies']+1) << 4) + (($post_data['enable_urls']+1) << 2) + (($post_data['enable_sig']+1) << 1);
  591. $status_switch = ($status_switch != $check_value);
  592. }
  593. else
  594. {
  595. $status_switch = 1;
  596. }
  597. // Delete Poll
  598. if ($poll_delete && $mode == 'edit' && sizeof($post_data['poll_options']) &&
  599. ((!$post_data['poll_last_vote'] && $post_data['poster_id'] == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id)) || $auth->acl_get('m_delete', $forum_id)))
  600. {
  601. if ($submit && check_form_key('posting'))
  602. {
  603. $sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . "
  604. WHERE topic_id = $topic_id";
  605. $db->sql_query($sql);
  606. $sql = 'DELETE FROM ' . POLL_VOTES_TABLE . "
  607. WHERE topic_id = $topic_id";
  608. $db->sql_query($sql);
  609. $topic_sql = array(
  610. 'poll_title' => '',
  611. 'poll_start' => 0,
  612. 'poll_length' => 0,
  613. 'poll_last_vote' => 0,
  614. 'poll_max_options' => 0,
  615. 'poll_vote_change' => 0
  616. );
  617. $sql = 'UPDATE ' . TOPICS_TABLE . '
  618. SET ' . $db->sql_build_array('UPDATE', $topic_sql) . "
  619. WHERE topic_id = $topic_id";
  620. $db->sql_query($sql);
  621. }
  622. $post_data['poll_title'] = $post_data['poll_option_text'] = '';
  623. $post_data['poll_vote_change'] = $post_data['poll_max_options'] = $post_data['poll_length'] = 0;
  624. }
  625. else
  626. {
  627. $post_data['poll_title'] = utf8_normalize_nfc(request_var('poll_title', '', true));
  628. $post_data['poll_length'] = request_var('poll_length', 0);
  629. $post_data['poll_option_text'] = utf8_normalize_nfc(request_var('poll_option_text', '', true));
  630. $post_data['poll_max_options'] = request_var('poll_max_options', 1);
  631. $post_data['poll_vote_change'] = ($auth->acl_get('f_votechg', $forum_id) && $auth->acl_get('f_vote', $forum_id) && isset($_POST['poll_vote_change'])) ? 1 : 0;
  632. }
  633. // If replying/quoting and last post id has changed
  634. // give user option to continue submit or return to post
  635. // notify and show user the post made between his request and the final submit
  636. if (($mode == 'reply' || $mode == 'quote') && $post_data['topic_cur_post_id'] && $post_data['topic_cur_post_id'] != $post_data['topic_last_post_id'])
  637. {
  638. // Only do so if it is allowed forum-wide
  639. if ($post_data['forum_flags'] & FORUM_FLAG_POST_REVIEW)
  640. {
  641. if (topic_review($topic_id, $forum_id, 'post_review', $post_data['topic_cur_post_id']))
  642. {
  643. $template->assign_var('S_POST_REVIEW', true);
  644. }
  645. $submit = false;
  646. $refresh = true;
  647. }
  648. }
  649. // Parse Attachments - before checksum is calculated
  650. $message_parser->parse_attachments('fileupload', $mode, $forum_id, $submit, $preview, $refresh);
  651. // Grab md5 'checksum' of new message
  652. $message_md5 = md5($message_parser->message);
  653. // If editing and checksum has changed we know the post was edited while we're editing
  654. // Notify and show user the changed post
  655. if ($mode == 'edit' && $post_data['forum_flags'] & FORUM_FLAG_POST_REVIEW)
  656. {
  657. $edit_post_message_checksum = request_var('edit_post_message_checksum', '');
  658. $edit_post_subject_checksum = request_var('edit_post_subject_checksum', '');
  659. // $post_data['post_checksum'] is the checksum of the post submitted in the meantime
  660. // $message_md5 is the checksum of the post we're about to submit
  661. // $edit_post_message_checksum is the checksum of the post we're editing
  662. // ...
  663. // We make sure nobody else made exactly the same change
  664. // we're about to submit by also checking $message_md5 != $post_data['post_checksum']
  665. if (($edit_post_message_checksum !== '' && $edit_post_message_checksum != $post_data['post_checksum'] && $message_md5 != $post_data['post_checksum'])
  666. || ($edit_post_subject_checksum !== '' && $edit_post_subject_checksum != $post_data['post_subject_md5'] && md5($post_data['post_subject']) != $post_data['post_subject_md5']))
  667. {
  668. if (topic_review($topic_id, $forum_id, 'post_review_edit', $post_id))
  669. {
  670. $template->assign_vars(array(
  671. 'S_POST_REVIEW' => true,
  672. 'L_POST_REVIEW' => $user->lang['POST_REVIEW_EDIT'],
  673. 'L_POST_REVIEW_EXPLAIN' => $user->lang['POST_REVIEW_EDIT_EXPLAIN'],
  674. ));
  675. }
  676. $submit = false;
  677. $refresh = true;
  678. }
  679. }
  680. // Check checksum ... don't re-parse message if the same
  681. $update_message = ($mode != 'edit' || $message_md5 != $post_data['post_checksum'] || $status_switch || strlen($post_data['bbcode_uid']) < BBCODE_UID_LEN) ? true : false;
  682. // Also check if subject got updated...
  683. $update_subject = $mode != 'edit' || ($post_data['post_subject_md5'] && $post_data['post_subject_md5'] != md5($post_data['post_subject']));
  684. // Parse message
  685. if ($update_message)
  686. {
  687. if (sizeof($message_parser->warn_msg))
  688. {
  689. $error[] = implode('<br />', $message_parser->warn_msg);
  690. $message_parser->warn_msg = array();
  691. }
  692. $message_parser->parse($post_data['enable_bbcode'], ($config['allow_post_links']) ? $post_data['enable_urls'] : false, $post_data['enable_smilies'], $img_status, $flash_status, $quote_status, $config['allow_post_links']);
  693. // On a refresh we do not care about message parsing errors
  694. if (sizeof($message_parser->warn_msg) && $refresh)
  695. {
  696. $message_parser->warn_msg = array();
  697. }
  698. }
  699. else
  700. {
  701. $message_parser->bbcode_bitfield = $post_data['bbcode_bitfield'];
  702. }
  703. if ($mode != 'edit' && !$preview && !$refresh && $config['flood_interval'] && !$auth->acl_get('f_ignoreflood', $forum_id))
  704. {
  705. // Flood check
  706. $last_post_time = 0;
  707. if ($user->data['is_registered'])
  708. {
  709. $last_post_time = $user->data['user_lastpost_time'];
  710. }
  711. else
  712. {
  713. $sql = 'SELECT post_time AS last_post_time
  714. FROM ' . POSTS_TABLE . "
  715. WHERE poster_ip = '" . $user->ip . "'
  716. AND post_time > " . ($current_time - $config['flood_interval']);
  717. $result = $db->sql_query_limit($sql, 1);
  718. if ($row = $db->sql_fetchrow($result))
  719. {
  720. $last_post_time = $row['last_post_time'];
  721. }
  722. $db->sql_freeresult($result);
  723. }
  724. if ($last_post_time && ($current_time - $last_post_time) < intval($config['flood_interval']))
  725. {
  726. $error[] = $user->lang['FLOOD_ERROR'];
  727. }
  728. }
  729. // Validate username
  730. if (($post_data['username'] && !$user->data['is_registered']) || ($mode == 'edit' && $post_data['poster_id'] == ANONYMOUS && $post_data['username'] && $post_data['post_username'] && $post_data['post_username'] != $post_data['username']))
  731. {
  732. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  733. $user->add_lang('ucp');
  734. if (($result = validate_username($post_data['username'], (!empty($post_data['post_username'])) ? $post_data['post_username'] : '')) !== false)
  735. {
  736. $error[] = $user->lang[$result . '_USERNAME'];
  737. }
  738. if (($result = validate_string($post_data['username'], false, $config['min_name_chars'], $config['max_name_chars'])) !== false)
  739. {
  740. $min_max_amount = ($result == 'TOO_SHORT') ? $config['min_name_chars'] : $config['max_name_chars'];
  741. $error[] = sprintf($user->lang['FIELD_' . $result], $user->lang['USERNAME'], $min_max_amount);
  742. }
  743. }
  744. if ($config['enable_post_confirm'] && !$user->data['is_registered'] && in_array($mode, array('quote', 'post', 'reply')))
  745. {
  746. $captcha_data = array(
  747. 'message' => utf8_normalize_nfc(request_var('message', '', true)),
  748. 'subject' => utf8_normalize_nfc(request_var('subject', '', true)),
  749. 'username' => utf8_normalize_nfc(request_var('username', '', true)),
  750. );
  751. $vc_response = $captcha->validate($captcha_data);
  752. if ($vc_response)
  753. {
  754. $error[] = $vc_response;
  755. }
  756. }
  757. // check form
  758. if (($submit || $preview) && !check_form_key('posting'))
  759. {
  760. $error[] = $user->lang['FORM_INVALID'];
  761. }
  762. // Parse subject
  763. if (!$preview && !$refresh && utf8_clean_string($post_data['post_subject']) === '' && ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_id)))
  764. {
  765. $error[] = $user->lang['EMPTY_SUBJECT'];
  766. }
  767. $post_data['poll_last_vote'] = (isset($post_data['poll_last_vote'])) ? $post_data['poll_last_vote'] : 0;
  768. if ($post_data['poll_option_text'] &&
  769. ($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id']/* && (!$post_data['poll_last_vote'] || $auth->acl_get('m_edit', $forum_id))*/))
  770. && $auth->acl_get('f_poll', $forum_id))
  771. {
  772. $poll = array(
  773. 'poll_title' => $post_data['poll_title'],
  774. 'poll_length' => $post_data['poll_length'],
  775. 'poll_max_options' => $post_data['poll_max_options'],
  776. 'poll_option_text' => $post_data['poll_option_text'],
  777. 'poll_start' => $post_data['poll_start'],
  778. 'poll_last_vote' => $post_data['poll_last_vote'],
  779. 'poll_vote_change' => $post_data['poll_vote_change'],
  780. 'enable_bbcode' => $post_data['enable_bbcode'],
  781. 'enable_urls' => $post_data['enable_urls'],
  782. 'enable_smilies' => $post_data['enable_smilies'],
  783. 'img_status' => $img_status
  784. );
  785. $message_parser->parse_poll($poll);
  786. $post_data['poll_options'] = (isset($poll['poll_options'])) ? $poll['poll_options'] : '';
  787. $post_data['poll_title'] = (isset($poll['poll_title'])) ? $poll['poll_title'] : '';
  788. /* We reset votes, therefore also allow removing options
  789. if ($post_data['poll_last_vote'] && ($poll['poll_options_size'] < $orig_poll_options_size))
  790. {
  791. $message_parser->warn_msg[] = $user->lang['NO_DELETE_POLL_OPTIONS'];
  792. }*/
  793. }
  794. else if (!$auth->acl_get('f_poll', $forum_id) && ($mode == 'edit') && ($post_id == $post_data['topic_first_post_id']) && ($original_poll_data['poll_title'] != ''))
  795. {
  796. // We have a poll but the editing user is not permitted to create/edit it.
  797. // So we just keep the original poll-data.
  798. $poll = array_merge($original_poll_data, array(
  799. 'enable_bbcode' => $post_data['enable_bbcode'],
  800. 'enable_urls' => $post_data['enable_urls'],
  801. 'enable_smilies' => $post_data['enable_smilies'],
  802. 'img_status' => $img_status,
  803. ));
  804. $message_parser->parse_poll($poll);
  805. $post_data['poll_options'] = (isset($poll['poll_options'])) ? $poll['poll_options'] : '';
  806. $post_data['poll_title'] = (isset($poll['poll_title'])) ? $poll['poll_title'] : '';
  807. }
  808. else
  809. {
  810. $poll = array();
  811. }
  812. // Check topic type
  813. if ($post_data['topic_type'] != POST_NORMAL && ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_id)))
  814. {
  815. switch ($post_data['topic_type'])
  816. {
  817. case POST_GLOBAL:
  818. case POST_ANNOUNCE:
  819. $auth_option = 'f_announce';
  820. break;
  821. case POST_STICKY:
  822. $auth_option = 'f_sticky';
  823. break;
  824. default:
  825. $auth_option = '';
  826. break;
  827. }
  828. if (!$auth->acl_get($auth_option, $forum_id))
  829. {
  830. // There is a special case where a user edits his post whereby the topic type got changed by an admin/mod.
  831. // Another case would be a mod not having sticky permissions for example but edit permissions.
  832. if ($mode == 'edit')
  833. {
  834. // To prevent non-authed users messing around with the topic type we reset it to the original one.
  835. $post_data['topic_type'] = $post_data['orig_topic_type'];
  836. }
  837. else
  838. {
  839. $error[] = $user->lang['CANNOT_POST_' . str_replace('F_', '', strtoupper($auth_option))];
  840. }
  841. }
  842. }
  843. if (sizeof($message_parser->warn_msg))
  844. {
  845. $error[] = implode('<br />', $message_parser->warn_msg);
  846. }
  847. // DNSBL check
  848. if ($config['check_dnsbl'] && !$refresh)
  849. {
  850. if (($dnsbl = $user->check_dnsbl('post')) !== false)
  851. {
  852. $error[] = sprintf($user->lang['IP_BLACKLISTED'], $user->ip, $dnsbl[1]);
  853. }
  854. }
  855. // Store message, sync counters
  856. if (!sizeof($error) && $submit)
  857. {
  858. // Check if we want to de-globalize the topic... and ask for new forum
  859. if ($post_data['topic_type'] != POST_GLOBAL)
  860. {
  861. $sql = 'SELECT topic_type, forum_id
  862. FROM ' . TOPICS_TABLE . "
  863. WHERE topic_id = $topic_id";
  864. $result = $db->sql_query($sql);
  865. $row = $db->sql_fetchrow($result);
  866. $db->sql_freeresult($result);
  867. if ($row && !$row['forum_id'] && $row['topic_type'] == POST_GLOBAL)
  868. {
  869. $to_forum_id = request_var('to_forum_id', 0);
  870. if ($to_forum_id)
  871. {
  872. $sql = 'SELECT forum_type
  873. FROM ' . FORUMS_TABLE . '
  874. WHERE forum_id = ' . $to_forum_id;
  875. $result = $db->sql_query($sql);
  876. $forum_type = (int) $db->sql_fetchfield('forum_type');
  877. $db->sql_freeresult($result);
  878. if ($forum_type != FORUM_POST || !$auth->acl_get('f_post', $to_forum_id) || (!$auth->acl_get('m_approve', $to_forum_id) && !$auth->acl_get('f_noapprove', $to_forum_id)))
  879. {
  880. $to_forum_id = 0;
  881. }
  882. }
  883. if (!$to_forum_id)
  884. {
  885. include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
  886. $template->assign_vars(array(
  887. 'S_FORUM_SELECT' => make_forum_select(false, false, false, true, true, true),
  888. 'S_UNGLOBALISE' => true)
  889. );
  890. $submit = false;
  891. $refresh = true;
  892. }
  893. else
  894. {
  895. if (!$auth->acl_get('f_post', $to_forum_id))
  896. {
  897. // This will only be triggered if the user tried to trick the forum.
  898. trigger_error('NOT_AUTHORISED');
  899. }
  900. $forum_id = $to_forum_id;
  901. }
  902. }
  903. }
  904. if ($submit)
  905. {
  906. // Lock/Unlock Topic
  907. $change_topic_status = $post_data['topic_status'];
  908. $perm_lock_unlock = ($auth->acl_get('m_lock', $forum_id) || ($auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && !empty($post_data['topic_poster']) && $user->data['user_id'] == $post_data['topic_poster'] && $post_data['topic_status'] == ITEM_UNLOCKED)) ? true : false;
  909. if ($post_data['topic_status'] == ITEM_LOCKED && !$topic_lock && $perm_lock_unlock)
  910. {
  911. $change_topic_status = ITEM_UNLOCKED;
  912. }
  913. else if ($post_data['topic_status'] == ITEM_UNLOCKED && $topic_lock && $perm_lock_unlock)
  914. {
  915. $change_topic_status = ITEM_LOCKED;
  916. }
  917. if ($change_topic_status != $post_data['topic_status'])
  918. {
  919. $sql = 'UPDATE ' . TOPICS_TABLE . "
  920. SET topic_status = $change_topic_status
  921. WHERE topic_id = $topic_id
  922. AND topic_moved_id = 0";
  923. $db->sql_query($sql);
  924. $user_lock = ($auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && $user->data['user_id'] == $post_data['topic_poster']) ? 'USER_' : '';
  925. add_log('mod', $forum_id, $topic_id, 'LOG_' . $user_lock . (($change_topic_status == ITEM_LOCKED) ? 'LOCK' : 'UNLOCK'), $post_data['topic_title']);
  926. }
  927. // Lock/Unlock Post Edit
  928. if ($mode == 'edit' && $post_data['post_edit_locked'] == ITEM_LOCKED && !$post_lock && $auth->acl_get('m_edit', $forum_id))
  929. {
  930. $post_data['post_edit_locked'] = ITEM_UNLOCKED;
  931. }
  932. else if ($mode == 'edit' && $post_data['post_edit_locked'] == ITEM_UNLOCKED && $post_lock && $auth->acl_get('m_edit', $forum_id))
  933. {
  934. $post_data['post_edit_locked'] = ITEM_LOCKED;
  935. }
  936. $data = array(
  937. 'topic_title' => (empty($post_data['topic_title'])) ? $post_data['post_subject'] : $post_data['topic_title'],
  938. 'topic_first_post_id' => (isset($post_data['topic_first_post_id'])) ? (int) $post_data['topic_first_post_id'] : 0,
  939. 'topic_last_post_id' => (isset($post_data['topic_last_post_id'])) ? (int) $post_data['topic_last_post_id'] : 0,
  940. 'topic_time_limit' => (int) $post_data['topic_time_limit'],
  941. 'topic_attachment' => (isset($post_data['topic_attachment'])) ? (int) $post_data['topic_attachment'] : 0,
  942. 'post_id' => (int) $post_id,
  943. 'topic_id' => (int) $topic_id,
  944. 'forum_id' => (int) $forum_id,
  945. 'icon_id' => (int) $post_data['icon_id'],
  946. 'poster_id' => (int) $post_data['poster_id'],
  947. 'enable_sig' => (bool) $post_data['enable_sig'],
  948. 'enable_bbcode' => (bool) $post_data['enable_bbcode'],
  949. 'enable_smilies' => (bool) $post_data['enable_smilies'],
  950. 'enable_urls' => (bool) $post_data['enable_urls'],
  951. 'enable_indexing' => (bool) $post_data['enable_indexing'],
  952. 'message_md5' => (string) $message_md5,
  953. 'post_time' => (isset($post_data['post_time'])) ? (int) $post_data['post_time'] : $current_time,
  954. 'post_checksum' => (isset($post_data['post_checksum'])) ? (string) $post_data['post_checksum'] : '',
  955. 'post_edit_reason' => $post_data['post_edit_reason'],
  956. 'post_edit_user' => ($mode == 'edit') ? $user->data['user_id'] : ((isset($post_data['post_edit_user'])) ? (int) $post_data['post_edit_user'] : 0),
  957. 'forum_parents' => $post_data['forum_parents'],
  958. 'forum_name' => $post_data['forum_name'],
  959. 'notify' => $notify,
  960. 'notify_set' => $post_data['notify_set'],
  961. 'poster_ip' => (isset($post_data['poster_ip'])) ? $post_data['poster_ip'] : $user->ip,
  962. 'post_edit_locked' => (int) $post_data['post_edit_locked'],
  963. 'bbcode_bitfield' => $message_parser->bbcode_bitfield,
  964. 'bbcode_uid' => $message_parser->bbcode_uid,
  965. 'message' => $message_parser->message,
  966. 'attachment_data' => $message_parser->attachment_data,
  967. 'filename_data' => $message_parser->filename_data,
  968. 'topic_approved' => (isset($post_data['topic_approved'])) ? $post_data['topic_approved'] : false,
  969. 'post_approved' => (isset($post_data['post_approved'])) ? $post_data['post_approved'] : false,
  970. );
  971. // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  972. if (!empty($phpbb_seo->seo_opt['sql_rewrite'])) {
  973. $data += array('topic_url' => isset($post_data['topic_url']) ? $post_data['topic_url'] : '');
  974. }
  975. // www.phpBB-SEO.com SEO TOOLKIT END
  976. if ($mode == 'edit')
  977. {
  978. $data['topic_replies_real'] = $post_data['topic_replies_real'];
  979. $data['topic_replies'] = $post_data['topic_replies'];
  980. //-- mod: Prime Post Revisions ----------------------------------------------//
  981. include($phpbb_root_path . 'includes/prime_post_revisions.' . $phpEx);
  982. store_post_revision_info($data, $post_data);
  983. //-- end: Prime Post Revisions ----------------------------------------------//
  984. }
  985. // The last parameter tells submit_post if search indexer has to be run
  986. $redirect_url = submit_post($mode, $post_data['post_subject'], $post_data['username'], $post_data['topic_type'], $poll, $data, $update_message, ($update_message || $update_subject) ? true : false);
  987. if ($config['enable_post_confirm'] && !$user->data['is_registered'] && (isset($captcha) && $captcha->is_solved() === true) && ($mode == 'post' || $mode == 'reply' || $mode == 'quote'))
  988. {
  989. $captcha->reset();
  990. }
  991. // Check the permissions for post approval. Moderators are not affected.
  992. if ((!$auth->acl_get('f_noapprove', $data['forum_id']) && !$auth->acl_get('m_approve', $data['forum_id']) && empty($data['force_approved_state'])) || (isset($data['force_approved_state']) && !$data['force_approved_state']))
  993. {
  994. meta_refresh(10, $redirect_url);
  995. $message = ($mode == 'edit') ? $user->lang['POST_EDITED_MOD'] : $user->lang['POST_STORED_MOD'];
  996. $message .= (($user->data['user_id'] == ANONYMOUS) ? '' : ' '. $user->lang['POST_APPROVAL_NOTIFY']);
  997. }
  998. else
  999. {
  1000. meta_refresh(3, $redirect_url);
  1001. $message = ($mode == 'edit') ? 'POST_EDITED' : 'POST_STORED';
  1002. $message = $user->lang[$message] . '<br /><br />' . sprintf($user->lang['VIEW_MESSAGE'], '<a href="' . $redirect_url . '">', '</a>');
  1003. }
  1004. $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $data['forum_id']) . '">', '</a>');
  1005. trigger_error($message);
  1006. }
  1007. }
  1008. }
  1009. // Preview
  1010. if (!sizeof($error) && $preview)
  1011. {
  1012. $post_data['post_time'] = ($mode == 'edit') ? $post_data['post_time'] : $current_time;
  1013. $preview_message = $message_parser->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies'], false);
  1014. $preview_signature = ($mode == 'edit') ? $post_data['user_sig'] : $user->data['user_sig'];
  1015. $preview_signature_uid = ($mode == 'edit') ? $post_data['user_sig_bbcode_uid'] : $user->data['user_sig_bbcode_uid'];
  1016. $preview_signature_bitfield = ($mode == 'edit') ? $post_data['user_sig_bbcode_bitfield'] : $user->data['user_sig_bbcode_bitfield'];
  1017. // Signature
  1018. if ($post_data['enable_sig'] && $config['allow_sig'] && $preview_signature && $auth->acl_get('f_sigs', $forum_id))
  1019. {
  1020. $parse_sig = new parse_message($preview_signature);
  1021. $parse_sig->bbcode_uid = $preview_signature_uid;
  1022. $parse_sig->bbcode_bitfield = $preview_signature_bitfield;
  1023. // Not sure about parameters for bbcode/smilies/urls... in signatures
  1024. $parse_sig->format_display($config['allow_sig_bbcode'], $config['allow_sig_links'], $config['allow_sig_smilies']);
  1025. $preview_signature = $parse_sig->message;
  1026. unset($parse_sig);
  1027. }
  1028. else
  1029. {
  1030. $preview_signature = '';
  1031. }
  1032. $preview_subject = censor_text($post_data['post_subject']);
  1033. // Poll Preview
  1034. if (!$poll_delete && ($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id']/* && (!$post_data['poll_last_vote'] || $auth->acl_get('m_edit', $forum_id))*/))
  1035. && $auth->acl_get('f_poll', $forum_id))
  1036. {
  1037. $parse_poll = new parse_message($post_data['poll_title']);
  1038. $parse_poll->bbcode_uid = $message_parser->bbcode_uid;
  1039. $parse_poll->bbcode_bitfield = $message_parser->bbcode_bitfield;
  1040. $parse_poll->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies']);
  1041. if ($post_data['poll_length'])
  1042. {
  1043. $poll_end = ($post_data['poll_length'] * 86400) + (($post_data['poll_start']) ? $post_data['poll_start'] : time());
  1044. }
  1045. $template->assign_vars(array(
  1046. 'S_HAS_POLL_OPTIONS' => (sizeof($post_data['poll_options'])),
  1047. 'S_IS_MULTI_CHOICE' => ($post_data['poll_max_options'] > 1) ? true : false,
  1048. 'POLL_QUESTION' => $parse_poll->message,
  1049. 'L_POLL_LENGTH' => ($post_data['poll_length']) ? sprintf($user->lang['POLL_RUN_TILL'], $user->format_date($poll_end)) : '',
  1050. 'L_MAX_VOTES' => ($post_data['poll_max_options'] == 1) ? $user->lang['MAX_OPTION_SELECT'] : sprintf($user->lang['MAX_OPTIONS_SELECT'], $post_data['poll_max_options']))
  1051. );
  1052. $parse_poll->message = implode("\n", $post_data['poll_options']);
  1053. $parse_poll->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies']);
  1054. $preview_poll_options = explode('<br />', $parse_poll->message);
  1055. unset($parse_poll);
  1056. foreach ($preview_poll_options as $key => $option)
  1057. {
  1058. $template->assign_block_vars('poll_option', array(
  1059. 'POLL_OPTION_CAPTION' => $option,
  1060. 'POLL_OPTION_ID' => $key + 1)
  1061. );
  1062. }
  1063. unset($preview_poll_options);
  1064. }
  1065. // Attachment Preview
  1066. if (sizeof($message_parser->attachment_data))
  1067. {
  1068. $template->assign_var('S_HAS_ATTACHMENTS', true);
  1069. $update_count = array();
  1070. $attachment_data = $message_parser->attachment_data;
  1071. parse_attachments($forum_id, $preview_message, $attachment_data, $update_count, true);
  1072. foreach ($attachment_data as $i => $attachment)
  1073. {
  1074. $template->assign_block_vars('attachment', array(
  1075. 'DISPLAY_ATTACHMENT' => $attachment)
  1076. );
  1077. }
  1078. unset($attachment_data);
  1079. }
  1080. if (!sizeof($error))
  1081. {
  1082. $template->assign_vars(array(
  1083. 'PREVIEW_SUBJECT' => $preview_subject,
  1084. 'PREVIEW_MESSAGE' => $preview_message,
  1085. 'PREVIEW_SIGNATURE' => $preview_signature,
  1086. 'S_DISPLAY_PREVIEW' => true)
  1087. );
  1088. }
  1089. }
  1090. // Decode text for message display
  1091. $post_data['bbcode_uid'] = ($mode == 'quote' && !$preview && !$refresh && !sizeof($error)) ? $post_data['bbcode_uid'] : $message_parser->bbcode_uid;
  1092. $message_parser->decode_message($post_data['bbcode_uid']);
  1093. if ($mode == 'quote' && !$submit && !$preview && !$refresh)
  1094. {
  1095. if ($config['allow_bbcode'])
  1096. {
  1097. $message_parser->message = '[quote=&quot;' . $post_data['quote_username'] . '&quot;]' . censor_text(trim($message_parser->message)) . "[/quote]\n";
  1098. }
  1099. else
  1100. {
  1101. $offset = 0;
  1102. $quote_string = "&gt; ";
  1103. $message = censor_text(trim($message_parser->message));
  1104. // see if we are nesting. It's easily tricked but should work for one level of nesting
  1105. if (strpos($message, "&gt;") !== false)
  1106. {
  1107. $offset = 10;
  1108. }
  1109. $message = utf8_wordwrap($message, 75 + $offset, "\n");
  1110. $message = $quote_string . $message;
  1111. $message = str_replace("\n", "\n" . $quote_string, $message);
  1112. $message_parser->message = $post_data['quote_username'] . " " . $user->lang['WROTE'] . ":\n" . $message . "\n";
  1113. }
  1114. }
  1115. if (($mode == 'reply' || $mode == 'quote') && !$submit && !$preview && !$refresh)
  1116. {
  1117. $post_data['post_subject'] = '';
  1118. }
  1119. $attachment_data = $message_parser->attachment_data;
  1120. $filename_data = $message_parser->filename_data;
  1121. $post_data['post_text'] = $message_parser->message;
  1122. if (sizeof($post_data['poll_options']) || !empty($post_data['poll_title']))
  1123. {
  1124. $message_parser->message = $post_data['poll_title'];
  1125. $message_parser->bbcode_uid = $post_data['bbcode_uid'];
  1126. $message_parser->decode_message();
  1127. $post_data['poll_title'] = $message_parser->message;
  1128. $message_parser->message = implode("\n", $post_data['poll_options']);
  1129. $message_parser->decode_message();
  1130. $post_data['poll_options'] = explode("\n", $message_parser->message);
  1131. }
  1132. // MAIN POSTING PAGE BEGINS HERE
  1133. // Forum moderators?
  1134. $moderators = array();
  1135. if ($config['load_moderators'])
  1136. {
  1137. get_moderators($moderators, $forum_id);
  1138. }
  1139. // Generate smiley listing
  1140. generate_smilies('inline', $forum_id);
  1141. // Generate inline attachment select box
  1142. posting_gen_inline_attachments($attachment_data);
  1143. // Do show topic type selection only in first post.
  1144. $topic_type_toggle = false;
  1145. if ($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id']))
  1146. {
  1147. $topic_type_toggle = posting_gen_topic_types($forum_id, $post_data['topic_type']);
  1148. }
  1149. $s_topic_icons = false;
  1150. if ($post_data['enable_icons'] && $auth->acl_get('f_icons', $forum_id))
  1151. {
  1152. $s_topic_icons = posting_gen_topic_icons($mode, $post_data['icon_id']);
  1153. }
  1154. $bbcode_checked = (isset($post_data['enable_bbcode'])) ? !$post_data['enable_bbcode'] : (($config['allow_bbcode']) ? !$user->optionget('bbcode') : 1);
  1155. $smilies_checked = (isset($post_data['enable_smilies'])) ? !$post_data['enable_smilies'] : (($config['allow_smilies']) ? !$user->optionget('smilies') : 1);
  1156. $urls_checked = (isset($post_data['enable_urls'])) ? !$post_data['enable_urls'] : 0;
  1157. $sig_checked = $post_data['enable_sig'];
  1158. $lock_topic_checked = (isset($topic_lock) && $topic_lock) ? $topic_lock : (($post_data['topic_status'] == ITEM_LOCKED) ? 1 : 0);
  1159. $lock_post_checked = (isset($post_lock)) ? $post_lock : $post_data['post_edit_locked'];
  1160. // If the user is replying or posting and not already watching this topic but set to always being notified we need to overwrite this setting
  1161. $notify_set = ($mode != 'edit' && $config['allow_topic_notify'] && $user->data['is_registered'] && !$post_data['notify_set']) ? $user->data['user_notify'] : $post_data['notify_set'];
  1162. $notify_checked = (isset($notify)) ? $notify : (($mode == 'post') ? $user->data['user_notify'] : $notify_set);
  1163. // Page title & action URL
  1164. $s_action = append_sid("{$phpbb_root_path}posting.$phpEx", "mode=$mode&amp;f=$forum_id");
  1165. $s_action .= ($topic_id) ? "&amp;t=$topic_id" : '';
  1166. $s_action .= ($post_id) ? "&amp;p=$post_id" : '';
  1167. switch ($mode)
  1168. {
  1169. case 'post':
  1170. $page_title = $user->lang['POST_TOPIC'];
  1171. break;
  1172. case 'quote':
  1173. case 'reply':
  1174. $page_title = $user->lang['POST_REPLY'];
  1175. break;
  1176. case 'delete':
  1177. case 'edit':
  1178. $page_title = $user->lang['EDIT_POST'];
  1179. break;
  1180. }
  1181. // Build Navigation Links
  1182. generate_forum_nav($post_data);
  1183. // Build Forum Rules
  1184. generate_forum_rules($post_data);
  1185. // Posting uses is_solved for legacy reasons. Plugins have to use is_solved to force themselves to be displayed.
  1186. if ($config['enable_post_confirm']

Large files files are truncated, but you can click here to view the full file