PageRenderTime 77ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 1ms

/phpBB/posting.php

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

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