PageRenderTime 34ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/posting.php

https://code.google.com/p/phpbbex/
PHP | 1666 lines | 1278 code | 262 blank | 126 comment | 629 complexity | b2cf437935358b93e54a4053160c4cfd MD5 | raw file
Possible License(s): AGPL-1.0

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['update_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'] || $auth->acl_get('u_ignoreedittime')))
  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. handle_post_delete($forum_id, $topic_id, $post_id, $post_data);
  263. return;
  264. }
  265. // Handle bump mode...
  266. if ($mode == 'bump')
  267. {
  268. 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'])
  269. && check_link_hash(request_var('hash', ''), "topic_{$post_data['topic_id']}"))
  270. {
  271. $meta_url = phpbb_bump_topic($forum_id, $topic_id, $post_data, $current_time);
  272. meta_refresh(3, $meta_url);
  273. $message = $user->lang['TOPIC_BUMPED'] . '<br /><br />' . sprintf($user->lang['VIEW_MESSAGE'], '<a href="' . $meta_url . '">', '</a>');
  274. $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
  275. trigger_error($message);
  276. }
  277. trigger_error('BUMP_ERROR');
  278. }
  279. // Subject length limiting to 60 characters if first post...
  280. if ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_data['post_id']))
  281. {
  282. $template->assign_var('S_NEW_MESSAGE', true);
  283. }
  284. // Determine some vars
  285. if (isset($post_data['poster_id']) && $post_data['poster_id'] == ANONYMOUS)
  286. {
  287. $post_data['quote_username'] = (!empty($post_data['post_username'])) ? $post_data['post_username'] : $user->lang['GUEST'];
  288. }
  289. else
  290. {
  291. $post_data['quote_username'] = isset($post_data['username']) ? $post_data['username'] : '';
  292. }
  293. $post_data['post_edit_locked'] = (isset($post_data['post_edit_locked'])) ? (int) $post_data['post_edit_locked'] : 0;
  294. $post_data['post_subject_md5'] = (isset($post_data['post_subject']) && $mode == 'edit') ? md5($post_data['post_subject']) : '';
  295. $post_data['post_subject'] = (in_array($mode, array('quote', 'edit'))) ? $post_data['post_subject'] : ((isset($post_data['topic_title'])) ? $post_data['topic_title'] : '');
  296. $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;
  297. $post_data['poll_length'] = (!empty($post_data['poll_length'])) ? (int) $post_data['poll_length'] / 86400 : 0;
  298. $post_data['poll_start'] = (!empty($post_data['poll_start'])) ? (int) $post_data['poll_start'] : 0;
  299. $post_data['icon_id'] = (!isset($post_data['icon_id']) || in_array($mode, array('quote', 'reply'))) ? 0 : (int) $post_data['icon_id'];
  300. $post_data['poll_options'] = array();
  301. $post_data['topic_first_post_show'] = (isset($post_data['topic_first_post_show'])) ? $post_data['topic_first_post_show'] : 0;
  302. // Get Poll Data
  303. if ($post_data['poll_start'])
  304. {
  305. $sql = 'SELECT poll_option_text
  306. FROM ' . POLL_OPTIONS_TABLE . "
  307. WHERE topic_id = $topic_id
  308. ORDER BY poll_option_id";
  309. $result = $db->sql_query($sql);
  310. while ($row = $db->sql_fetchrow($result))
  311. {
  312. $post_data['poll_options'][] = trim($row['poll_option_text']);
  313. }
  314. $db->sql_freeresult($result);
  315. }
  316. if ($mode == 'edit')
  317. {
  318. $original_poll_data = array(
  319. 'poll_title' => $post_data['poll_title'],
  320. 'poll_length' => $post_data['poll_length'],
  321. 'poll_max_options' => $post_data['poll_max_options'],
  322. 'poll_option_text' => implode("\n", $post_data['poll_options']),
  323. 'poll_start' => $post_data['poll_start'],
  324. 'poll_last_vote' => $post_data['poll_last_vote'],
  325. 'poll_vote_change' => $post_data['poll_vote_change'],
  326. );
  327. }
  328. $orig_poll_options_size = sizeof($post_data['poll_options']);
  329. $message_parser = new parse_message();
  330. if (isset($post_data['post_text']))
  331. {
  332. $message_parser->message = &$post_data['post_text'];
  333. unset($post_data['post_text']);
  334. }
  335. // Set some default variables
  336. $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);
  337. foreach ($uninit as $var_name => $default_value)
  338. {
  339. if (!isset($post_data[$var_name]))
  340. {
  341. $post_data[$var_name] = $default_value;
  342. }
  343. }
  344. unset($uninit);
  345. // Always check if the submitted attachment data is valid and belongs to the user.
  346. // Further down (especially in submit_post()) we do not check this again.
  347. $message_parser->get_submitted_attachment_data($post_data['poster_id']);
  348. if ($post_data['post_attachment'] && !$submit && !$refresh && !$preview && $mode == 'edit')
  349. {
  350. // Do not change to SELECT *
  351. $sql = 'SELECT attach_id, is_orphan, attach_comment, real_filename
  352. FROM ' . ATTACHMENTS_TABLE . "
  353. WHERE post_msg_id = $post_id
  354. AND in_message = 0
  355. AND is_orphan = 0
  356. ORDER BY filetime DESC";
  357. $result = $db->sql_query($sql);
  358. $message_parser->attachment_data = array_merge($message_parser->attachment_data, $db->sql_fetchrowset($result));
  359. $db->sql_freeresult($result);
  360. }
  361. if ($post_data['poster_id'] == ANONYMOUS)
  362. {
  363. $post_data['username'] = ($mode == 'quote' || $mode == 'edit') ? trim($post_data['post_username']) : '';
  364. }
  365. else
  366. {
  367. $post_data['username'] = ($mode == 'quote' || $mode == 'edit') ? trim($post_data['username']) : '';
  368. }
  369. $post_data['enable_urls'] = $post_data['enable_magic_url'];
  370. if ($mode != 'edit')
  371. {
  372. $post_data['enable_sig'] = ($config['allow_sig'] && $user->optionget('attachsig')) ? true: false;
  373. $post_data['enable_smilies'] = ($config['allow_smilies'] && $user->optionget('smilies')) ? true : false;
  374. $post_data['enable_bbcode'] = ($config['allow_bbcode'] && $user->optionget('bbcode')) ? true : false;
  375. $post_data['enable_urls'] = true;
  376. }
  377. $post_data['enable_magic_url'] = $post_data['drafts'] = false;
  378. // User own some drafts?
  379. if ($user->data['is_registered'] && $auth->acl_get('u_savedrafts') && ($mode == 'reply' || $mode == 'post' || $mode == 'quote'))
  380. {
  381. $sql = 'SELECT draft_id
  382. FROM ' . DRAFTS_TABLE . '
  383. WHERE user_id = ' . $user->data['user_id'] .
  384. (($forum_id) ? ' AND forum_id = ' . (int) $forum_id : '') .
  385. (($topic_id) ? ' AND topic_id = ' . (int) $topic_id : '') .
  386. (($draft_id) ? " AND draft_id <> $draft_id" : '');
  387. $result = $db->sql_query_limit($sql, 1);
  388. if ($db->sql_fetchrow($result))
  389. {
  390. $post_data['drafts'] = true;
  391. }
  392. $db->sql_freeresult($result);
  393. }
  394. $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);
  395. // Check if user is watching this topic
  396. if ($mode != 'post' && $config['allow_topic_notify'] && $user->data['is_registered'])
  397. {
  398. $sql = 'SELECT topic_id
  399. FROM ' . TOPICS_WATCH_TABLE . '
  400. WHERE topic_id = ' . $topic_id . '
  401. AND user_id = ' . $user->data['user_id'];
  402. $result = $db->sql_query($sql);
  403. $post_data['notify_set'] = (int) $db->sql_fetchfield('topic_id');
  404. $db->sql_freeresult($result);
  405. }
  406. // Do we want to edit our post ?
  407. if ($mode == 'edit' && $post_data['bbcode_uid'])
  408. {
  409. $message_parser->bbcode_uid = $post_data['bbcode_uid'];
  410. }
  411. // HTML, BBCode, Smilies, Images and Flash status
  412. $bbcode_status = ($config['allow_bbcode'] && $auth->acl_get('f_bbcode', $forum_id)) ? true : false;
  413. $smilies_status = ($config['allow_smilies'] && $auth->acl_get('f_smilies', $forum_id)) ? true : false;
  414. $img_status = ($bbcode_status && $auth->acl_get('f_img', $forum_id)) ? true : false;
  415. $url_status = ($config['allow_post_links']) ? true : false;
  416. $flash_status = ($bbcode_status && $auth->acl_get('f_flash', $forum_id) && $config['allow_post_flash']) ? true : false;
  417. $quote_status = true;
  418. // Save Draft
  419. if ($save && $user->data['is_registered'] && $auth->acl_get('u_savedrafts') && ($mode == 'reply' || $mode == 'post' || $mode == 'quote'))
  420. {
  421. $subject = utf8_normalize_nfc(request_var('subject', '', true));
  422. $subject = (!$subject && $mode != 'post') ? $post_data['topic_title'] : $subject;
  423. $message = utf8_normalize_nfc(request_var('message', '', true));
  424. if ($subject && $message)
  425. {
  426. if (confirm_box(true))
  427. {
  428. $sql = 'INSERT INTO ' . DRAFTS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
  429. 'user_id' => (int) $user->data['user_id'],
  430. 'topic_id' => (int) $topic_id,
  431. 'forum_id' => (int) $forum_id,
  432. 'save_time' => (int) $current_time,
  433. 'draft_subject' => (string) $subject,
  434. 'draft_message' => (string) $message)
  435. );
  436. $db->sql_query($sql);
  437. $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");
  438. meta_refresh(3, $meta_info);
  439. $message = $user->lang['DRAFT_SAVED'] . '<br /><br />';
  440. $message .= ($mode != 'post') ? sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $meta_info . '">', '</a>') . '<br /><br />' : '';
  441. $message .= sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
  442. trigger_error($message);
  443. }
  444. else
  445. {
  446. $s_hidden_fields = build_hidden_fields(array(
  447. 'mode' => $mode,
  448. 'save' => true,
  449. 'f' => $forum_id,
  450. 't' => $topic_id,
  451. 'subject' => $subject,
  452. 'message' => $message,
  453. 'attachment_data' => $message_parser->attachment_data,
  454. )
  455. );
  456. $hidden_fields = array(
  457. 'icon_id' => 0,
  458. 'disable_bbcode' => false,
  459. 'disable_smilies' => false,
  460. 'disable_magic_url' => false,
  461. 'attach_sig' => true,
  462. 'lock_topic' => false,
  463. 'topic_type' => POST_NORMAL,
  464. 'topic_time_limit' => 0,
  465. 'poll_title' => '',
  466. 'poll_option_text' => '',
  467. 'poll_max_options' => 1,
  468. 'poll_length' => 0,
  469. 'poll_vote_change' => false,
  470. );
  471. foreach ($hidden_fields as $name => $default)
  472. {
  473. if (!isset($_POST[$name]))
  474. {
  475. // Don't include it, if its not available
  476. unset($hidden_fields[$name]);
  477. continue;
  478. }
  479. if (is_bool($default))
  480. {
  481. // Use the string representation
  482. $hidden_fields[$name] = request_var($name, '');
  483. }
  484. else
  485. {
  486. $hidden_fields[$name] = request_var($name, $default);
  487. }
  488. }
  489. $s_hidden_fields .= build_hidden_fields($hidden_fields);
  490. confirm_box(false, 'SAVE_DRAFT', $s_hidden_fields);
  491. }
  492. }
  493. else
  494. {
  495. if (utf8_clean_string($subject) === '')
  496. {
  497. $error[] = $user->lang['EMPTY_SUBJECT'];
  498. }
  499. if (utf8_clean_string($message) === '')
  500. {
  501. $error[] = $user->lang['TOO_FEW_CHARS'];
  502. }
  503. }
  504. unset($subject, $message);
  505. }
  506. // Load requested Draft
  507. if ($draft_id && ($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $user->data['is_registered'] && $auth->acl_get('u_savedrafts'))
  508. {
  509. $sql = 'SELECT draft_subject, draft_message
  510. FROM ' . DRAFTS_TABLE . "
  511. WHERE draft_id = $draft_id
  512. AND user_id = " . $user->data['user_id'];
  513. $result = $db->sql_query_limit($sql, 1);
  514. $row = $db->sql_fetchrow($result);
  515. $db->sql_freeresult($result);
  516. if ($row)
  517. {
  518. $post_data['post_subject'] = $row['draft_subject'];
  519. $message_parser->message = $row['draft_message'];
  520. $template->assign_var('S_DRAFT_LOADED', true);
  521. }
  522. else
  523. {
  524. $draft_id = 0;
  525. }
  526. }
  527. // Load draft overview
  528. if ($load && ($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $post_data['drafts'])
  529. {
  530. load_drafts($topic_id, $forum_id);
  531. }
  532. if ($submit || $preview || $refresh)
  533. {
  534. $post_data['topic_cur_post_id'] = request_var('topic_cur_post_id', 0);
  535. $post_data['post_subject'] = utf8_normalize_nfc(request_var('subject', '', true));
  536. $message_parser->message = utf8_normalize_nfc(request_var('message', '', true));
  537. $post_data['username'] = utf8_normalize_nfc(request_var('username', $post_data['username'], true));
  538. $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)) : '';
  539. $post_data['orig_topic_type'] = $post_data['topic_type'];
  540. $post_data['topic_type'] = request_var('topic_type', (($mode != 'post') ? (int) $post_data['topic_type'] : POST_NORMAL));
  541. $post_data['topic_time_limit'] = request_var('topic_time_limit', (($mode != 'post') ? (int) $post_data['topic_time_limit'] : 0));
  542. if ($post_data['enable_icons'] && $auth->acl_get('f_icons', $forum_id))
  543. {
  544. $post_data['icon_id'] = request_var('icon', (int) $post_data['icon_id']);
  545. }
  546. $post_data['enable_bbcode'] = (!$bbcode_status || isset($_POST['disable_bbcode'])) ? false : true;
  547. $post_data['enable_smilies'] = (!$smilies_status || isset($_POST['disable_smilies'])) ? false : true;
  548. $post_data['enable_urls'] = (isset($_POST['disable_magic_url'])) ? 0 : 1;
  549. $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);
  550. if ($config['allow_topic_notify'] && $user->data['is_registered'])
  551. {
  552. $notify = (isset($_POST['notify'])) ? true : false;
  553. }
  554. else
  555. {
  556. $notify = false;
  557. }
  558. $topic_lock = (isset($_POST['lock_topic'])) ? true : false;
  559. $post_lock = (isset($_POST['lock_post'])) ? true : false;
  560. $poll_delete = (isset($_POST['poll_delete'])) ? true : false;
  561. $topic_first_post_show = (isset($_POST['topic_first_post_show'])) ? true : false;
  562. if ($submit)
  563. {
  564. $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);
  565. $status_switch = ($status_switch != $check_value);
  566. }
  567. else
  568. {
  569. $status_switch = 1;
  570. }
  571. // Delete Poll
  572. if ($poll_delete && $mode == 'edit' && sizeof($post_data['poll_options']) &&
  573. ((!$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)))
  574. {
  575. if ($submit && check_form_key('posting'))
  576. {
  577. $sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . "
  578. WHERE topic_id = $topic_id";
  579. $db->sql_query($sql);
  580. $sql = 'DELETE FROM ' . POLL_VOTES_TABLE . "
  581. WHERE topic_id = $topic_id";
  582. $db->sql_query($sql);
  583. $topic_sql = array(
  584. 'poll_title' => '',
  585. 'poll_start' => 0,
  586. 'poll_length' => 0,
  587. 'poll_last_vote' => 0,
  588. 'poll_max_options' => 0,
  589. 'poll_vote_change' => 0,
  590. 'poll_show_voters' => 0
  591. );
  592. $sql = 'UPDATE ' . TOPICS_TABLE . '
  593. SET ' . $db->sql_build_array('UPDATE', $topic_sql) . "
  594. WHERE topic_id = $topic_id";
  595. $db->sql_query($sql);
  596. }
  597. $post_data['poll_title'] = $post_data['poll_option_text'] = '';
  598. $post_data['poll_vote_change'] = $post_data['poll_max_options'] = $post_data['poll_length'] = 0;
  599. $post_data['poll_show_voters'] = 0;
  600. }
  601. else
  602. {
  603. $post_data['poll_title'] = utf8_normalize_nfc(request_var('poll_title', '', true));
  604. $post_data['poll_length'] = request_var('poll_length', 0);
  605. $post_data['poll_option_text'] = utf8_normalize_nfc(request_var('poll_option_text', '', true));
  606. $post_data['poll_max_options'] = request_var('poll_max_options', 1);
  607. $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;
  608. $post_data['poll_show_voters'] = isset($_POST['poll_show_voters']) ? 1 : 0;
  609. }
  610. // If replying/quoting and last post id has changed
  611. // give user option to continue submit or return to post
  612. // notify and show user the post made between his request and the final submit
  613. if (($mode == 'reply' || $mode == 'quote') && $post_data['topic_cur_post_id'] && $post_data['topic_cur_post_id'] != $post_data['topic_last_post_id'])
  614. {
  615. // Only do so if it is allowed forum-wide
  616. if ($post_data['forum_flags'] & FORUM_FLAG_POST_REVIEW)
  617. {
  618. if (topic_review($topic_id, $forum_id, 'post_review', $post_data['topic_cur_post_id']))
  619. {
  620. $template->assign_var('S_POST_REVIEW', true);
  621. }
  622. $submit = false;
  623. $refresh = true;
  624. }
  625. }
  626. // Parse Attachments - before checksum is calculated
  627. $message_parser->parse_attachments('fileupload', $mode, $forum_id, $submit, $preview, $refresh);
  628. // Grab md5 'checksum' of new message
  629. $message_md5 = md5($message_parser->message);
  630. // Save message for posts merging
  631. $addon_for_merge = $message_parser->message;
  632. // If editing and checksum has changed we know the post was edited while we're editing
  633. // Notify and show user the changed post
  634. if ($mode == 'edit' && $post_data['forum_flags'] & FORUM_FLAG_POST_REVIEW)
  635. {
  636. $edit_post_message_checksum = request_var('edit_post_message_checksum', '');
  637. $edit_post_subject_checksum = request_var('edit_post_subject_checksum', '');
  638. // $post_data['post_checksum'] is the checksum of the post submitted in the meantime
  639. // $message_md5 is the checksum of the post we're about to submit
  640. // $edit_post_message_checksum is the checksum of the post we're editing
  641. // ...
  642. // We make sure nobody else made exactly the same change
  643. // we're about to submit by also checking $message_md5 != $post_data['post_checksum']
  644. if (($edit_post_message_checksum !== '' && $edit_post_message_checksum != $post_data['post_checksum'] && $message_md5 != $post_data['post_checksum'])
  645. || ($edit_post_subject_checksum !== '' && $edit_post_subject_checksum != $post_data['post_subject_md5'] && md5($post_data['post_subject']) != $post_data['post_subject_md5']))
  646. {
  647. if (topic_review($topic_id, $forum_id, 'post_review_edit', $post_id))
  648. {
  649. $template->assign_vars(array(
  650. 'S_POST_REVIEW' => true,
  651. 'L_POST_REVIEW' => $user->lang['POST_REVIEW_EDIT'],
  652. 'L_POST_REVIEW_EXPLAIN' => $user->lang['POST_REVIEW_EDIT_EXPLAIN'],
  653. ));
  654. }
  655. $submit = false;
  656. $refresh = true;
  657. }
  658. }
  659. // Check checksum ... don't re-parse message if the same
  660. $update_message = ($mode != 'edit' || $message_md5 != $post_data['post_checksum'] || $status_switch || strlen($post_data['bbcode_uid']) < BBCODE_UID_LEN) ? true : false;
  661. // Also check if subject got updated...
  662. $update_subject = $mode != 'edit' || ($post_data['post_subject_md5'] && $post_data['post_subject_md5'] != md5($post_data['post_subject']));
  663. // Parse message
  664. if ($update_message)
  665. {
  666. if (sizeof($message_parser->warn_msg))
  667. {
  668. $error[] = implode('<br />', $message_parser->warn_msg);
  669. $message_parser->warn_msg = array();
  670. }
  671. $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']);
  672. // On a refresh we do not care about message parsing errors
  673. if (sizeof($message_parser->warn_msg) && $refresh)
  674. {
  675. $message_parser->warn_msg = array();
  676. }
  677. }
  678. else
  679. {
  680. $message_parser->bbcode_bitfield = $post_data['bbcode_bitfield'];
  681. }
  682. if ($mode != 'edit' && !$preview && !$refresh && $config['flood_interval'] && !$auth->acl_get('f_ignoreflood', $forum_id))
  683. {
  684. // Flood check
  685. $last_post_time = 0;
  686. if ($user->data['is_registered'])
  687. {
  688. $last_post_time = $user->data['user_lastpost_time'];
  689. }
  690. else
  691. {
  692. $sql = 'SELECT post_time AS last_post_time
  693. FROM ' . POSTS_TABLE . "
  694. WHERE poster_ip = '" . $user->ip . "'
  695. AND post_time > " . ($current_time - $config['flood_interval']);
  696. $result = $db->sql_query_limit($sql, 1);
  697. if ($row = $db->sql_fetchrow($result))
  698. {
  699. $last_post_time = $row['last_post_time'];
  700. }
  701. $db->sql_freeresult($result);
  702. }
  703. if ($last_post_time && ($current_time - $last_post_time) < intval($config['flood_interval']))
  704. {
  705. $error[] = $user->lang['FLOOD_ERROR'];
  706. }
  707. }
  708. // Validate username
  709. 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']))
  710. {
  711. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  712. $user->add_lang('ucp');
  713. if (($result = validate_username($post_data['username'], (!empty($post_data['post_username'])) ? $post_data['post_username'] : '')) !== false)
  714. {
  715. $error[] = $user->lang[$result . '_USERNAME'];
  716. }
  717. if (($result = validate_string($post_data['username'], false, $config['min_name_chars'], $config['max_name_chars'])) !== false)
  718. {
  719. $min_max_amount = ($result == 'TOO_SHORT') ? $config['min_name_chars'] : $config['max_name_chars'];
  720. $error[] = sprintf($user->lang['FIELD_' . $result], $user->lang['USERNAME'], $min_max_amount);
  721. }
  722. }
  723. if ($config['enable_post_confirm'] && !$user->data['is_registered'] && in_array($mode, array('quote', 'post', 'reply')))
  724. {
  725. $captcha_data = array(
  726. 'message' => utf8_normalize_nfc(request_var('message', '', true)),
  727. 'subject' => utf8_normalize_nfc(request_var('subject', '', true)),
  728. 'username' => utf8_normalize_nfc(request_var('username', '', true)),
  729. );
  730. $vc_response = $captcha->validate($captcha_data);
  731. if ($vc_response)
  732. {
  733. $error[] = $vc_response;
  734. }
  735. }
  736. // check form
  737. if (($submit || $preview) && !check_form_key('posting'))
  738. {
  739. $error[] = $user->lang['FORM_INVALID'];
  740. }
  741. // Parse subject
  742. if (!$preview && !$refresh && utf8_clean_string($post_data['post_subject']) === '' && ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_id)))
  743. {
  744. $error[] = $user->lang['EMPTY_SUBJECT'];
  745. }
  746. $post_data['poll_last_vote'] = (isset($post_data['poll_last_vote'])) ? $post_data['poll_last_vote'] : 0;
  747. if ($post_data['poll_option_text'] &&
  748. ($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id']/* && (!$post_data['poll_last_vote'] || $auth->acl_get('m_edit', $forum_id))*/))
  749. && $auth->acl_get('f_poll', $forum_id))
  750. {
  751. $poll = array(
  752. 'poll_title' => $post_data['poll_title'],
  753. 'poll_length' => $post_data['poll_length'],
  754. 'poll_max_options' => $post_data['poll_max_options'],
  755. 'poll_option_text' => $post_data['poll_option_text'],
  756. 'poll_start' => $post_data['poll_start'],
  757. 'poll_last_vote' => $post_data['poll_last_vote'],
  758. 'poll_vote_change' => $post_data['poll_vote_change'],
  759. 'poll_show_voters' => $post_data['poll_show_voters'],
  760. 'enable_bbcode' => $post_data['enable_bbcode'],
  761. 'enable_urls' => $post_data['enable_urls'],
  762. 'enable_smilies' => $post_data['enable_smilies'],
  763. 'img_status' => $img_status
  764. );
  765. $message_parser->parse_poll($poll);
  766. $post_data['poll_options'] = (isset($poll['poll_options'])) ? $poll['poll_options'] : array();
  767. $post_data['poll_title'] = (isset($poll['poll_title'])) ? $poll['poll_title'] : '';
  768. /* We reset votes, therefore also allow removing options
  769. if ($post_data['poll_last_vote'] && ($poll['poll_options_size'] < $orig_poll_options_size))
  770. {
  771. $message_parser->warn_msg[] = $user->lang['NO_DELETE_POLL_OPTIONS'];
  772. }*/
  773. }
  774. else if ($mode == 'edit' && $post_id == $post_data['topic_first_post_id'] && $auth->acl_get('f_poll', $forum_id))
  775. {
  776. // The user removed all poll options, this is equal to deleting the poll.
  777. $poll = array(
  778. 'poll_title' => '',
  779. 'poll_length' => 0,
  780. 'poll_max_options' => 0,
  781. 'poll_option_text' => '',
  782. 'poll_start' => 0,
  783. 'poll_last_vote' => 0,
  784. 'poll_vote_change' => 0,
  785. 'poll_options' => array(),
  786. );
  787. $post_data['poll_options'] = array();
  788. $post_data['poll_title'] = '';
  789. $post_data['poll_start'] = $post_data['poll_length'] = $post_data['poll_max_options'] = $post_data['poll_last_vote'] = $post_data['poll_vote_change'] = 0;
  790. }
  791. else if (!$auth->acl_get('f_poll', $forum_id) && ($mode == 'edit') && ($post_id == $post_data['topic_first_post_id']) && ($original_poll_data['poll_title'] != ''))
  792. {
  793. // We have a poll but the editing user is not permitted to create/edit it.
  794. // So we just keep the original poll-data.
  795. $poll = array_merge($original_poll_data, array(
  796. 'enable_bbcode' => $post_data['enable_bbcode'],
  797. 'enable_urls' => $post_data['enable_urls'],
  798. 'enable_smilies' => $post_data['enable_smilies'],
  799. 'img_status' => $img_status,
  800. ));
  801. $message_parser->parse_poll($poll);
  802. $post_data['poll_options'] = (isset($poll['poll_options'])) ? $poll['poll_options'] : array();
  803. $post_data['poll_title'] = (isset($poll['poll_title'])) ? $poll['poll_title'] : '';
  804. }
  805. else
  806. {
  807. $poll = array();
  808. }
  809. // Check topic type
  810. if ($post_data['topic_type'] != POST_NORMAL && ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_id)))
  811. {
  812. switch ($post_data['topic_type'])
  813. {
  814. case POST_GLOBAL:
  815. case POST_ANNOUNCE:
  816. $auth_option = 'f_announce';
  817. break;
  818. case POST_STICKY:
  819. $auth_option = 'f_sticky';
  820. break;
  821. default:
  822. $auth_option = '';
  823. break;
  824. }
  825. if (!$auth->acl_get($auth_option, $forum_id))
  826. {
  827. // There is a special case where a user edits his post whereby the topic type got changed by an admin/mod.
  828. // Another case would be a mod not having sticky permissions for example but edit permissions.
  829. if ($mode == 'edit')
  830. {
  831. // To prevent non-authed users messing around with the topic type we reset it to the original one.
  832. $post_data['topic_type'] = $post_data['orig_topic_type'];
  833. }
  834. else
  835. {
  836. $error[] = $user->lang['CANNOT_POST_' . str_replace('F_', '', strtoupper($auth_option))];
  837. }
  838. }
  839. }
  840. if (sizeof($message_parser->warn_msg))
  841. {
  842. $error[] = implode('<br />', $message_parser->warn_msg);
  843. }
  844. // DNSBL check
  845. if ($config['check_dnsbl'] && !$refresh)
  846. {
  847. if (($dnsbl = $user->check_dnsbl('post')) !== false)
  848. {
  849. $error[] = sprintf($user->lang['IP_BLACKLISTED'], $user->ip, $dnsbl[1]);
  850. }
  851. }
  852. // Store message, sync counters
  853. if (!sizeof($error) && $submit)
  854. {
  855. // Check if we want to de-globalize the topic... and ask for new forum
  856. if ($post_data['topic_type'] != POST_GLOBAL)
  857. {
  858. $sql = 'SELECT topic_type, forum_id
  859. FROM ' . TOPICS_TABLE . "
  860. WHERE topic_id = $topic_id";
  861. $result = $db->sql_query($sql);
  862. $row = $db->sql_fetchrow($result);
  863. $db->sql_freeresult($result);
  864. if ($row && !$row['forum_id'] && $row['topic_type'] == POST_GLOBAL)
  865. {
  866. $to_forum_id = request_var('to_forum_id', 0);
  867. if ($to_forum_id)
  868. {
  869. $sql = 'SELECT forum_type
  870. FROM ' . FORUMS_TABLE . '
  871. WHERE forum_id = ' . $to_forum_id;
  872. $result = $db->sql_query($sql);
  873. $forum_type = (int) $db->sql_fetchfield('forum_type');
  874. $db->sql_freeresult($result);
  875. 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)))
  876. {
  877. $to_forum_id = 0;
  878. }
  879. }
  880. if (!$to_forum_id)
  881. {
  882. include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
  883. $template->assign_vars(array(
  884. 'S_FORUM_SELECT' => make_forum_select(false, false, false, true, true, true),
  885. 'S_UNGLOBALISE' => true)
  886. );
  887. $submit = false;
  888. $refresh = true;
  889. }
  890. else
  891. {
  892. if (!$auth->acl_get('f_post', $to_forum_id))
  893. {
  894. // This will only be triggered if the user tried to trick the forum.
  895. trigger_error('NOT_AUTHORISED');
  896. }
  897. $forum_id = $to_forum_id;
  898. }
  899. }
  900. }
  901. if ($submit)
  902. {
  903. // Lock/Unlock Topic
  904. $change_topic_status = $post_data['topic_status'];
  905. $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;
  906. if ($post_data['topic_status'] == ITEM_LOCKED && !$topic_lock && $perm_lock_unlock)
  907. {
  908. $change_topic_status = ITEM_UNLOCKED;
  909. }
  910. else if ($post_data['topic_status'] == ITEM_UNLOCKED && $topic_lock && $perm_lock_unlock)
  911. {
  912. $change_topic_status = ITEM_LOCKED;
  913. }
  914. if ($change_topic_status != $post_data['topic_status'])
  915. {
  916. $sql = 'UPDATE ' . TOPICS_TABLE . "
  917. SET topic_status = $change_topic_status
  918. WHERE topic_id = $topic_id
  919. AND topic_moved_id = 0";
  920. $db->sql_query($sql);
  921. $user_lock = ($auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && $user->data['user_id'] == $post_data['topic_poster']) ? 'USER_' : '';
  922. add_log('mod', $forum_id, $topic_id, 'LOG_' . $user_lock . (($change_topic_status == ITEM_LOCKED) ? 'LOCK' : 'UNLOCK'), $post_data['topic_title']);
  923. }
  924. // Lock/Unlock Post Edit
  925. if ($mode == 'edit' && $post_data['post_edit_locked'] == ITEM_LOCKED && !$post_lock && $auth->acl_get('m_edit', $forum_id))
  926. {
  927. $post_data['post_edit_locked'] = ITEM_UNLOCKED;
  928. }
  929. else if ($mode == 'edit' && $post_data['post_edit_locked'] == ITEM_UNLOCKED && $post_lock && $auth->acl_get('m_edit', $forum_id))
  930. {
  931. $post_data['post_edit_locked'] = ITEM_LOCKED;
  932. }
  933. $data = array(
  934. 'topic_title' => (empty($post_data['topic_title'])) ? $post_data['post_subject'] : $post_data['topic_title'],
  935. 'topic_first_post_id' => (isset($post_data['topic_first_post_id'])) ? (int) $post_data['topic_first_post_id'] : 0,
  936. 'topic_last_post_id' => (isset($post_data['topic_last_post_id'])) ? (int) $post_data['topic_last_post_id'] : 0,
  937. 'topic_time_limit' => (int) $post_data['topic_time_limit'],
  938. 'topic_attachment' => (isset($post_data['topic_attachment'])) ? (int) $post_data['topic_attachment'] : 0,
  939. 'post_id' => (int) $post_id,
  940. 'topic_id' => (int) $topic_id,
  941. 'forum_id' => (int) $forum_id,
  942. 'icon_id' => (int) $post_data['icon_id'],
  943. 'poster_id' => (int) $post_data['poster_id'],
  944. 'enable_sig' => (bool) $post_data['enable_sig'],
  945. 'enable_bbcode' => (bool) $post_data['enable_bbcode'],
  946. 'enable_smilies' => (bool) $post_data['enable_smilies'],
  947. 'enable_urls' => (bool) $post_data['enable_urls'],
  948. 'enable_indexing' => (bool) $post_data['enable_indexing'],
  949. 'message_md5' => (string) $message_md5,
  950. 'post_time' => (isset($post_data['post_time'])) ? (int) $post_data['post_time'] : $current_time,
  951. 'post_checksum' => (isset($post_data['post_checksum'])) ? (string) $post_data['post_checksum'] : '',
  952. 'post_edit_reason' => $post_data['post_edit_reason'],
  953. 'post_edit_user' => ($mode == 'edit') ? $user->data['user_id'] : ((isset($post_data['post_edit_user'])) ? (int) $post_data['post_edit_user'] : 0),
  954. 'forum_parents' => $post_data['forum_parents'],
  955. 'forum_name' => $post_data['forum_name'],
  956. 'notify' => $notify,
  957. 'notify_set' => $post_data['notify_set'],
  958. 'poster_ip' => (isset($post_data['poster_ip'])) ? $post_data['poster_ip'] : $user->ip,
  959. 'post_edit_locked' => (int) $post_data['post_edit_locked'],
  960. 'bbcode_bitfield' => $message_parser->bbcode_bitfield,
  961. 'bbcode_uid' => $message_parser->bbcode_uid,
  962. 'message' => $message_parser->message,
  963. 'attachment_data' => $message_parser->attachment_data,
  964. 'filename_data' => $message_parser->filename_data,
  965. 'topic_approved' => (isset($post_data['topic_approved'])) ? $post_data['topic_approved'] : false,
  966. 'post_approved' => (isset($post_data['post_approved'])) ? $post_data['post_approved'] : false,
  967. );
  968. if ($mode == 'edit')
  969. {
  970. $data['topic_replies_real'] = $post_data['topic_replies_real'];
  971. $data['topic_replies'] = $post_data['topic_replies'];
  972. }
  973. include($phpbb_root_path . 'includes/posts_merging.' . $phpEx);
  974. // The last parameter tells submit_post if search indexer has to be run
  975. $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);
  976. // Show/Unshow first post on every page
  977. if(($mode == 'edit' && $post_id == $post_data['topic_first_post_id']) || $mode == 'post')
  978. {
  979. if($mode == 'post')
  980. {
  981. $topic_id = $data['topic_id'];
  982. }
  983. $perm_show_unshow = ($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'])) ? true : false;
  984. if($post_data['topic_first_post_show'] != $topic_first_post_show && $perm_show_unshow)
  985. {
  986. $sql = 'UPDATE ' . TOPICS_TABLE . '
  987. SET topic_first_post_show = ' . (($topic_first_post_show) ? 1 : 0) . "
  988. WHERE topic_id = $topic_id";
  989. $db->sql_query($sql);
  990. }
  991. }
  992. if ($config['enable_post_confirm'] && !$user->data['is_registered'] && (isset($captcha) && $captcha->is_solved() === true) && ($mode == 'post' || $mode == 'reply' || $mode == 'quote'))
  993. {
  994. $captcha->reset();
  995. }
  996. // Check the permissions for post approval. Moderators are not affected.
  997. 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']))
  998. {
  999. meta_refresh(10, $redirect_url);
  1000. $message = ($mode == 'edit') ? $user->lang['POST_EDITED_MOD'] : $user->lang['POST_STORED_MOD'];
  1001. $message .= (($user->data['user_id'] == ANONYMOUS) ? '' : ' '. $user->lang['POST_APPROVAL_NOTIFY']);
  1002. }
  1003. else
  1004. {
  1005. meta_refresh(3, $redirect_url);
  1006. $message = ($mode == 'edit') ? 'POST_EDITED' : 'POST_STORED';
  1007. $message = $user->lang[$message] . '<br /><br />' . sprintf($user->lang['VIEW_MESSAGE'], '<a href="' . $redirect_url . '">', '</a>');
  1008. }
  1009. $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $data['forum_id']) . '">', '</a>');
  1010. trigger_error($message);
  1011. }
  1012. }
  1013. }
  1014. // Preview
  1015. if (!sizeof($error) && $preview)
  1016. {
  1017. $post_data['post_time'] = ($mode == 'edit') ? $post_data['post_time'] : $current_time;
  1018. $preview_message = $message_parser->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies'], false);
  1019. $preview_signature = ($mode == 'edit') ? $post_data['user_sig'] : $user->data['user_sig'];
  1020. $preview_signature_uid = ($mode == 'edit') ? $post_data['user_sig_bbcode_uid'] : $user->data['user_sig_bbcode_uid'];
  1021. $preview_signature_bitfield = ($mode == 'edit') ? $post_data['user_sig_bbcode_bitfield'] : $user->data['user_sig_bbcode_bitfield'];
  1022. // Signature
  1023. if ($post_data['enable_sig'] && $config['allow_sig'] && $preview_signature && $auth->acl_get('f_sigs', $forum_id))
  1024. {
  1025. $parse_sig = new parse_message($preview_signature);
  1026. $parse_sig->bbcode_uid = $preview_signature_uid;
  1027. $parse_sig->bbcode_bitfield = $preview_signature_bitfield;
  1028. // Not sure about parameters for bbcode/smilies/urls... in signatures
  1029. $parse_sig->format_display($config['allow_sig_bbcode'], $config['allow_sig_links'], $config['allow_sig_smilies']);
  1030. $preview_signature = $parse_sig->message;
  1031. unset($parse_sig);
  1032. }
  1033. else
  1034. {
  1035. $preview_signature = '';
  1036. }
  1037. $preview_subject = censor_text($post_data['post_subject']);
  1038. // Poll Preview
  1039. 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))*/))
  1040. && $auth->acl_get('f_poll', $forum_id))
  1041. {
  1042. $parse_poll = new parse_message($post_data['poll_title']);
  1043. $parse_poll->bbcode_uid = $message_parser->bbcode_uid;
  1044. $parse_poll->bbcode_bitfield = $message_parser->bbcode_bitfield;
  1045. $parse_poll->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies']);
  1046. if ($post_data['poll_length'])
  1047. {
  1048. $poll_end = ($post_data['poll_length'] * 86400) + (($post_data['poll_start']) ? $post_data['poll_start'] : time());
  1049. }
  1050. $template->assign_vars(array(
  1051. 'S_HAS_POLL_OPTIONS' => (sizeof($post_data['poll_options'])),
  1052. 'S_IS_MULTI_CHOICE' => ($post_data['poll_max_options'] > 1) ? true : false,
  1053. 'POLL_QUESTION' => $parse_poll->message,
  1054. 'L_POLL_LENGTH' => ($post_data['poll_length']) ? sprintf($user->lang['POLL_RUN_TILL'], $user->format_date($poll_end)) : '',
  1055. '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']))
  1056. );
  1057. $parse_poll->message = implode("\n", $post_data['poll_options']);
  1058. $parse_poll->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies']);
  1059. $preview_poll_options = explode('<br />', $parse_poll->message);
  1060. unset($parse_poll);
  1061. foreach ($preview_poll_options as $key => $option)
  1062. {
  1063. $template->assign_block_vars('poll_option', array(
  1064. 'POLL_OPTION_CAPTION' => $option,
  1065. 'POLL_OPTION_ID' => $key + 1)
  1066. );
  1067. }
  1068. unset($preview_poll_options);
  1069. }
  1070. // Attachment Preview
  1071. if (sizeof($message_parser->attachment_data))
  1072. {
  1073. $template->assign_var('S_HAS_ATTACHMENTS', true);
  1074. $update_count = array();
  1075. $attachment_data = $message_parser->attachment_data;
  1076. parse_attachments($forum_id, $preview_message, $attachment_data, $update_count, true);
  1077. foreach ($attachment_data as $i => $attachment)
  1078. {
  1079. $template->assign_block_vars('attachment', array(
  1080. 'DISPLAY_ATTACHMENT' => $attachment)
  1081. );
  1082. }
  1083. unset($attachment_data);
  1084. }
  1085. if (!sizeof($error))
  1086. {
  1087. $template->assign_vars(array(
  1088. 'PREVIEW_SUBJECT' => $preview_subject,
  1089. 'PREVIEW_MESSAGE' => $preview_message,
  1090. 'PREVIEW_SIGNATURE' => $preview_signature,
  1091. 'S_DISPLAY_PREVIEW' => true)
  1092. );
  1093. }
  1094. }
  1095. // Decode text for message display
  1096. $post_data['bbcode_uid'] = ($mode == 'quote' && !$preview && !$refresh && !sizeof($error)) ? $post_data['bbcode_uid'] : $message_parser->bbcode_uid;
  1097. $message_parser->decode_message($post_data['bbcode_uid']);
  1098. if ($mode == 'quote' && !$submit && !$preview && !$refresh)
  1099. {
  1100. if ($config['allow_bbcode'])
  1101. {
  1102. $message_parser->message = '[quote=&quot;' . $post_data['quote_username'] . '&quot;]' . censor_text(trim($message_parser->message)) . "[/quote]\n";
  1103. }
  1104. else
  1105. {
  1106. $offset = 0;
  1107. $quote_string = "&gt; ";
  1108. $message = censor_text(trim($message_parser->message));
  1109. // see if we are nesting. It's easily tricked but should work for one level of nesting
  1110. if (strpos($message, "&gt;") !== false)
  1111. {
  1112. $offset = 10;
  1113. }
  1114. $message = utf8_wordwrap($message, 75 + $offset, "\n");
  1115. $message = $quote_string . $message;
  1116. $message = str_replace("\n", "\n" . $quote_string, $message);
  1117. $message_parser->message = $post_data['quote_username'] . " " . $user->lang['WROTE'] . ":\n" . $message . "\n";
  1118. }
  1119. }
  1120. if (($mode == 'reply' || $mode == 'quote') && !$submit && !$preview && !$refresh)
  1121. {
  1122. $post_data['post_subject'] = ''; // ((strpos($post_data['post_subject'], 'Re: ') !== 0) ? 'Re: ' : '') . censor_text($post_data['post_subject']);
  1123. }
  1124. $attachment_data = $message_parser->attachment_data;
  1125. $filename_data = $message_parser->filename_data;
  1126. $post_data['post_text'] = $message_parser->message;
  1127. if (sizeof($post_data['poll_options']) || !empty($post_data['poll_title']))
  1128. {
  1129. $message_parser->message = $post_data['poll_title'];
  1130. $message_parser->bbcode_uid = $post_data['bbcode_uid'];
  1131. $message_parser->decode_message();
  1132. $post_data['poll_title'] = $message_parser->message;
  1133. $message_parser->message = implode("\n", $post_data['poll_options']);
  1134. $message_parser->decode_message();
  1135. $post_data['poll_options'] = explode("\n", $message_parser->message);
  1136. }
  1137. // MAIN POSTING PAGE BEGINS HERE
  1138. // Forum moderators?
  1139. $moderators = array();
  1140. if ($config['load_moderators'])
  1141. {
  1142. get_moderators($moderators, $forum_id);
  1143. }
  1144. // Generate smiley listing
  1145. generate_smilies('inline', $forum_id);
  1146. // Generate inline attachment select box
  1147. posting_gen_inline_attachments($attachment_data);
  1148. // Do show topic type selection only in first post.
  1149. $topic_type_toggle = false;
  1150. if ($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id']))
  1151. {
  1152. $topic_type_toggle = posting_gen_topic_types($forum_id, $post_data['topic_type']);
  1153. }
  1154. // Do show show first post on every page checkbox only in first post
  1155. $first_post_show_allowed = false;
  1156. if(($mode == 'edit' && $post_id == $post_data['topic_first_post_id']) || $mode == 'post')
  1157. {
  1158. $first_post_show_allowed = true;
  1159. }
  1160. $s_topic_icons = false;
  1161. if ($post_data['enable_icons'] && $auth->acl_get('f_icons', $forum_id))
  1162. {
  1163. $s_topic_icons = posting_gen_topic_icons($mode, $post_data['icon_id']);
  1164. }
  1165. $bbcode_checked = (isset($post_data['enable_bbcode'])) ? !$post_data['enable_bbcode'] : (($config['allow_bbcode']) ? !$user->optionget('bbcode') : 1);
  1166. $smilies_checked = (isset($post_data['enable_smilies'])) ? !$post_data['enable_smilies'] : (($config['allow_smilies']) ? !$user->optionget('smilies') : 1);
  1167. $urls_checked = (isset($post_data['enable_urls'])) ? !$post_data['enable_urls'] : 0;
  1168. $sig_checked = $post_data['enable_sig'];
  1169. $lock_topic_checked = (isset($topic_lock) && $topic_lock) ? $topic_lock : (($post_data['topic_status'] == ITEM_LOCKED) ? 1 : 0);
  1170. $lock_post_checked = (isset($post_lock)) ? $post_lock : $post_data['post_edit_locked'];
  1171. $first_post_show_checked = (isset($post_data['topic_first_post_show'])) ? $post_data['topic_first_post_show'] : 0;
  1172. // 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
  1173. $notify_set = ($mode != 'edit' && $config['allow_topic_notify'] && $user->data['is_registered'] && !$post_data['notify_set']) ? $user->data['user_notify'] : $post_data['notify_set'];
  1174. $notify_checked = (isset($notify)) ? $notify : (($mode == 'post') ? $user->data['user_notify'] : $notify_set);
  1175. // Page title & action URL
  1176. $s_action = append_sid("{$phpbb_root_path}posting.$phpEx", "mode=$mode&amp;f=$forum_id");
  1177. $s_action .= ($topic_id) ? "&amp;t=$topic_id" : '';
  1178. $s_action .= ($post_id) ? "&amp;p=$post_id" : '';
  1179. switch ($mode)
  1180. {
  1181. case 'post':
  1182. $page_title = $user->lang['POST_TOPIC'];
  1183. break;
  1184. case 'quote':
  1185. case 'reply':
  1186. $page_title = $user->lang['POST_REPLY'];
  1187. break;
  1188. case 'delete':
  1189. case 'edit':
  1190. $page_title = $user->lang['EDIT_POST'];
  1191. break;
  1192. }
  1193. // Build Navigation Links
  1194. generate_forum_nav($post_data);
  1195. // Build Forum Rules
  1196. generat

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