i think david just forgot these. ;)
[phpbb.git] / phpBB / posting.php
blob926b542699639cbcdd710ea97c96a84a8e3d5a3e
1 <?php
2 /**
4 * @package phpBB3
5 * @version $Id$
6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
9 */
11 /**
12 * @ignore
14 define('IN_PHPBB', true);
15 $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
16 $phpEx = substr(strrchr(__FILE__, '.'), 1);
17 include($phpbb_root_path . 'common.' . $phpEx);
18 include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
19 include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
20 include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
23 // Start session management
24 $user->session_begin();
25 $auth->acl($user->data);
28 // Grab only parameters needed here
29 $post_id = request_var('p', 0);
30 $topic_id = request_var('t', 0);
31 $forum_id = request_var('f', 0);
32 $draft_id = request_var('d', 0);
33 $lastclick = request_var('lastclick', 0);
35 $submit = (isset($_POST['post'])) ? true : false;
36 $preview = (isset($_POST['preview'])) ? true : false;
37 $save = (isset($_POST['save'])) ? true : false;
38 $load = (isset($_POST['load'])) ? true : false;
39 $delete = (isset($_POST['delete'])) ? true : false;
40 $cancel = (isset($_POST['cancel']) && !isset($_POST['save'])) ? true : false;
42 $refresh = (isset($_POST['add_file']) || isset($_POST['delete_file']) || isset($_POST['cancel_unglobalise']) || $save || $load) ? true : false;
43 $mode = ($delete && !$preview && !$refresh && $submit) ? 'delete' : request_var('mode', '');
45 $error = $post_data = array();
46 $current_time = time();
49 // Was cancel pressed? If so then redirect to the appropriate page
50 if ($cancel || ($current_time - $lastclick < 2 && $submit))
52 $redirect = ($post_id) ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'p=' . $post_id) . '#p' . $post_id : (($topic_id) ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $topic_id) : (($forum_id) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) : append_sid("{$phpbb_root_path}index.$phpEx")));
53 redirect($redirect);
56 if (in_array($mode, array('post', 'reply', 'quote', 'edit', 'delete')) && !$forum_id)
58 trigger_error('NO_FORUM');
61 // We need to know some basic information in all cases before we do anything.
62 switch ($mode)
64 case 'post':
65 $sql = 'SELECT *
66 FROM ' . FORUMS_TABLE . "
67 WHERE forum_id = $forum_id";
68 break;
70 case 'bump':
71 case 'reply':
72 if (!$topic_id)
74 trigger_error('NO_TOPIC');
77 $sql = 'SELECT f.*, t.*
78 FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f
79 WHERE t.topic_id = $topic_id
80 AND (f.forum_id = t.forum_id
81 OR f.forum_id = $forum_id)";
82 break;
84 case 'quote':
85 case 'edit':
86 case 'delete':
87 if (!$post_id)
89 $user->setup('posting');
90 trigger_error('NO_POST');
93 $sql = 'SELECT f.*, t.*, p.*, u.username, u.username_clean, u.user_sig, u.user_sig_bbcode_uid, u.user_sig_bbcode_bitfield
94 FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . ' f, ' . USERS_TABLE . " u
95 WHERE p.post_id = $post_id
96 AND t.topic_id = p.topic_id
97 AND u.user_id = p.poster_id
98 AND (f.forum_id = t.forum_id
99 OR f.forum_id = $forum_id)";
100 break;
102 case 'smilies':
103 $sql = '';
104 generate_smilies('window', $forum_id);
105 break;
107 case 'popup':
108 if ($forum_id)
110 $sql = 'SELECT forum_style
111 FROM ' . FORUMS_TABLE . '
112 WHERE forum_id = ' . $forum_id;
114 else
116 upload_popup();
117 garbage_collection();
118 exit_handler();
120 break;
122 default:
123 $sql = '';
124 break;
127 if (!$sql)
129 $user->setup('posting');
130 trigger_error('NO_POST_MODE');
133 $result = $db->sql_query($sql);
134 $post_data = $db->sql_fetchrow($result);
135 $db->sql_freeresult($result);
137 if (!$post_data)
139 if (!($mode == 'post' || $mode == 'bump' || $mode == 'reply'))
141 $user->setup('posting');
143 trigger_error(($mode == 'post' || $mode == 'bump' || $mode == 'reply') ? 'NO_TOPIC' : 'NO_POST');
146 if ($mode == 'popup')
148 upload_popup($post_data['forum_style']);
149 exit_handler();
152 $user->setup(array('posting', 'mcp', 'viewtopic'), $post_data['forum_style']);
154 // Use post_row values in favor of submitted ones...
155 $forum_id = (!empty($post_data['forum_id'])) ? (int) $post_data['forum_id'] : (int) $forum_id;
156 $topic_id = (!empty($post_data['topic_id'])) ? (int) $post_data['topic_id'] : (int) $topic_id;
157 $post_id = (!empty($post_data['post_id'])) ? (int) $post_data['post_id'] : (int) $post_id;
159 // Need to login to passworded forum first?
160 if ($post_data['forum_password'])
162 login_forum_box(array(
163 'forum_id' => $forum_id,
164 'forum_password' => $post_data['forum_password'])
168 // Check permissions
169 if ($user->data['is_bot'])
171 redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
174 // Is the user able to read within this forum?
175 if (!$auth->acl_get('f_read', $forum_id))
177 if ($user->data['user_id'] != ANONYMOUS)
179 trigger_error('USER_CANNOT_READ');
182 login_box('', $user->lang['LOGIN_EXPLAIN_POST']);
185 // Permission to do the action asked?
186 $is_authed = false;
188 switch ($mode)
190 case 'post':
191 if ($auth->acl_get('f_post', $forum_id))
193 $is_authed = true;
195 break;
197 case 'bump':
198 if ($auth->acl_get('f_bump', $forum_id))
200 $is_authed = true;
202 break;
204 case 'quote':
206 $post_data['post_edit_locked'] = 0;
208 // no break;
210 case 'reply':
211 if ($auth->acl_get('f_reply', $forum_id))
213 $is_authed = true;
215 break;
217 case 'edit':
218 if ($user->data['is_registered'] && $auth->acl_gets('f_edit', 'm_edit', $forum_id))
220 $is_authed = true;
222 break;
224 case 'delete':
225 if ($user->data['is_registered'] && $auth->acl_gets('f_delete', 'm_delete', $forum_id))
227 $is_authed = true;
229 break;
232 if (!$is_authed)
234 $check_auth = ($mode == 'quote') ? 'reply' : $mode;
236 if ($user->data['is_registered'])
238 trigger_error('USER_CANNOT_' . strtoupper($check_auth));
241 login_box('', $user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)]);
244 // Is the user able to post within this forum?
245 if ($post_data['forum_type'] != FORUM_POST && in_array($mode, array('post', 'bump', 'quote', 'reply')))
247 trigger_error('USER_CANNOT_FORUM_POST');
250 // Forum/Topic locked?
251 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))
253 trigger_error(($post_data['forum_status'] == ITEM_LOCKED) ? 'FORUM_LOCKED' : 'TOPIC_LOCKED');
256 // Can we edit this post ... if we're a moderator with rights then always yes
257 // else it depends on editing times, lock status and if we're the correct user
258 if ($mode == 'edit' && !$auth->acl_get('m_edit', $forum_id))
260 if ($user->data['user_id'] != $post_data['poster_id'])
262 trigger_error('USER_CANNOT_EDIT');
265 if (!($post_data['post_time'] > time() - ($config['edit_time'] * 60) || !$config['edit_time']))
267 trigger_error('CANNOT_EDIT_TIME');
270 if ($post_data['post_edit_locked'])
272 trigger_error('CANNOT_EDIT_POST_LOCKED');
276 // Handle delete mode...
277 if ($mode == 'delete')
279 handle_post_delete($forum_id, $topic_id, $post_id, $post_data);
280 exit_handler();
283 // Handle bump mode...
284 if ($mode == 'bump')
286 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']))
288 $db->sql_transaction('begin');
290 $sql = 'UPDATE ' . POSTS_TABLE . "
291 SET post_time = $current_time
292 WHERE post_id = {$post_data['topic_last_post_id']}
293 AND topic_id = $topic_id";
294 $db->sql_query($sql);
296 $sql = 'UPDATE ' . TOPICS_TABLE . "
297 SET topic_last_post_time = $current_time,
298 topic_bumped = 1,
299 topic_bumper = " . $user->data['user_id'] . "
300 WHERE topic_id = $topic_id";
301 $db->sql_query($sql);
303 update_post_information('forum', $forum_id);
305 $sql = 'UPDATE ' . USERS_TABLE . "
306 SET user_lastpost_time = $current_time
307 WHERE user_id = " . $user->data['user_id'];
308 $db->sql_query($sql);
310 $db->sql_transaction('commit');
312 markread('post', $forum_id, $topic_id, $current_time);
314 add_log('mod', $forum_id, $topic_id, 'LOG_BUMP_TOPIC', $post_data['topic_title']);
316 $meta_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;p={$post_data['topic_last_post_id']}") . "#p{$post_data['topic_last_post_id']}";
317 meta_refresh(3, $meta_url);
319 $message = $user->lang['TOPIC_BUMPED'] . '<br /><br />' . sprintf($user->lang['VIEW_MESSAGE'], '<a href="' . $meta_url . '">', '</a>');
320 $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
322 trigger_error($message);
325 trigger_error('BUMP_ERROR');
328 // Subject length limiting to 60 characters if first post...
329 if ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_data['post_id']))
331 $template->assign_var('S_NEW_MESSAGE', true);
334 // Determine some vars
335 if (isset($post_data['poster_id']) && $post_data['poster_id'] == ANONYMOUS)
337 $post_data['quote_username'] = (!empty($post_data['post_username'])) ? $post_data['post_username'] : $user->lang['GUEST'];
339 else
341 $post_data['quote_username'] = isset($post_data['username']) ? $post_data['username'] : '';
344 $post_data['post_edit_locked'] = (isset($post_data['post_edit_locked'])) ? (int) $post_data['post_edit_locked'] : 0;
345 $post_data['post_subject'] = (in_array($mode, array('quote', 'edit'))) ? $post_data['post_subject'] : ((isset($post_data['topic_title'])) ? $post_data['topic_title'] : '');
346 $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;
347 $post_data['poll_length'] = (!empty($post_data['poll_length'])) ? (int) $post_data['poll_length'] / 86400 : 0;
348 $post_data['poll_start'] = (!empty($post_data['poll_start'])) ? (int) $post_data['poll_start'] : 0;
349 $post_data['icon_id'] = (!isset($post_data['icon_id']) || in_array($mode, array('quote', 'reply'))) ? 0 : (int) $post_data['icon_id'];
350 $post_data['poll_options'] = array();
352 // Get Poll Data
353 if ($post_data['poll_start'])
355 $sql = 'SELECT poll_option_text
356 FROM ' . POLL_OPTIONS_TABLE . "
357 WHERE topic_id = $topic_id
358 ORDER BY poll_option_id";
359 $result = $db->sql_query($sql);
361 while ($row = $db->sql_fetchrow($result))
363 $post_data['poll_options'][] = trim($row['poll_option_text']);
365 $db->sql_freeresult($result);
368 $orig_poll_options_size = sizeof($post_data['poll_options']);
370 $message_parser = new parse_message();
372 if (isset($post_data['post_text']))
374 $message_parser->message = &$post_data['post_text'];
375 unset($post_data['post_text']);
378 // Set some default variables
379 $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);
381 foreach ($uninit as $var_name => $default_value)
383 if (!isset($post_data[$var_name]))
385 $post_data[$var_name] = $default_value;
388 unset($uninit);
390 // Always check if the submitted attachment data is valid and belongs to the user.
391 // Further down (especially in submit_post()) we do not check this again.
392 $message_parser->get_submitted_attachment_data($post_data['poster_id']);
394 if ($post_data['post_attachment'] && !$submit && !$refresh && !$preview && $mode == 'edit')
396 // Do not change to SELECT *
397 $sql = 'SELECT attach_id, is_orphan, attach_comment, real_filename
398 FROM ' . ATTACHMENTS_TABLE . "
399 WHERE post_msg_id = $post_id
400 AND in_message = 0
401 AND is_orphan = 0
402 ORDER BY filetime DESC";
403 $result = $db->sql_query($sql);
404 $message_parser->attachment_data = array_merge($message_parser->attachment_data, $db->sql_fetchrowset($result));
405 $db->sql_freeresult($result);
408 if ($post_data['poster_id'] == ANONYMOUS)
410 $post_data['username'] = ($mode == 'quote' || $mode == 'edit') ? trim($post_data['post_username']) : '';
412 else
414 $post_data['username'] = ($mode == 'quote' || $mode == 'edit') ? trim($post_data['username']) : '';
417 $post_data['enable_urls'] = $post_data['enable_magic_url'];
419 if ($mode != 'edit')
421 $post_data['enable_sig'] = ($config['allow_sig'] && $user->optionget('attachsig')) ? true: false;
422 $post_data['enable_smilies'] = ($config['allow_smilies'] && $user->optionget('smilies')) ? true : false;
423 $post_data['enable_bbcode'] = ($config['allow_bbcode'] && $user->optionget('bbcode')) ? true : false;
424 $post_data['enable_urls'] = true;
427 $post_data['enable_magic_url'] = $post_data['drafts'] = false;
429 // User own some drafts?
430 if ($user->data['is_registered'] && $auth->acl_get('u_savedrafts') && ($mode == 'reply' || $mode == 'post' || $mode == 'quote'))
432 $sql = 'SELECT draft_id
433 FROM ' . DRAFTS_TABLE . '
434 WHERE user_id = ' . $user->data['user_id'] .
435 (($forum_id) ? ' AND forum_id = ' . (int) $forum_id : '') .
436 (($topic_id) ? ' AND topic_id = ' . (int) $topic_id : '') .
437 (($draft_id) ? " AND draft_id <> $draft_id" : '');
438 $result = $db->sql_query_limit($sql, 1);
440 if ($db->sql_fetchrow($result))
442 $post_data['drafts'] = true;
444 $db->sql_freeresult($result);
447 $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);
449 // Check if user is watching this topic
450 if ($mode != 'post' && $config['allow_topic_notify'] && $user->data['is_registered'])
452 $sql = 'SELECT topic_id
453 FROM ' . TOPICS_WATCH_TABLE . '
454 WHERE topic_id = ' . $topic_id . '
455 AND user_id = ' . $user->data['user_id'];
456 $result = $db->sql_query($sql);
457 $post_data['notify_set'] = (int) $db->sql_fetchfield('topic_id');
458 $db->sql_freeresult($result);
461 // Do we want to edit our post ?
462 if ($mode == 'edit' && $post_data['bbcode_uid'])
464 $message_parser->bbcode_uid = $post_data['bbcode_uid'];
467 // HTML, BBCode, Smilies, Images and Flash status
468 $bbcode_status = ($config['allow_bbcode'] && $auth->acl_get('f_bbcode', $forum_id)) ? true : false;
469 $smilies_status = ($bbcode_status && $config['allow_smilies'] && $auth->acl_get('f_smilies', $forum_id)) ? true : false;
470 $img_status = ($bbcode_status && $auth->acl_get('f_img', $forum_id)) ? true : false;
471 $url_status = ($config['allow_post_links']) ? true : false;
472 $flash_status = ($bbcode_status && $auth->acl_get('f_flash', $forum_id) && $config['allow_post_flash']) ? true : false;
473 $quote_status = ($auth->acl_get('f_reply', $forum_id)) ? true : false;
475 // Save Draft
476 if ($save && $user->data['is_registered'] && $auth->acl_get('u_savedrafts') && ($mode == 'reply' || $mode == 'post' || $mode == 'quote'))
478 $subject = utf8_normalize_nfc(request_var('subject', '', true));
479 $subject = (!$subject && $mode != 'post') ? $post_data['topic_title'] : $subject;
480 $message = utf8_normalize_nfc(request_var('message', '', true));
482 if ($subject && $message)
484 if (confirm_box(true))
486 $sql = 'INSERT INTO ' . DRAFTS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
487 'user_id' => (int) $user->data['user_id'],
488 'topic_id' => (int) $topic_id,
489 'forum_id' => (int) $forum_id,
490 'save_time' => (int) $current_time,
491 'draft_subject' => (string) $subject,
492 'draft_message' => (string) $message)
494 $db->sql_query($sql);
496 $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");
498 meta_refresh(3, $meta_info);
500 $message = $user->lang['DRAFT_SAVED'] . '<br /><br />';
501 $message .= ($mode != 'post') ? sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $meta_info . '">', '</a>') . '<br /><br />' : '';
502 $message .= sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
504 trigger_error($message);
506 else
508 $s_hidden_fields = build_hidden_fields(array(
509 'mode' => $mode,
510 'save' => true,
511 'f' => $forum_id,
512 't' => $topic_id,
513 'subject' => $subject,
514 'message' => $message,
518 confirm_box(false, 'SAVE_DRAFT', $s_hidden_fields);
521 else
523 if (!$subject || !utf_clean_string($subject))
525 $error[] = $user->lang['EMPTY_SUBJECT'];
528 if (!$message)
530 $error[] = $user->lang['TOO_FEW_CHARS'];
534 unset($subject, $message);
537 // Load requested Draft
538 if ($draft_id && ($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $user->data['is_registered'] && $auth->acl_get('u_savedrafts'))
540 $sql = 'SELECT draft_subject, draft_message
541 FROM ' . DRAFTS_TABLE . "
542 WHERE draft_id = $draft_id
543 AND user_id = " . $user->data['user_id'];
544 $result = $db->sql_query_limit($sql, 1);
545 $row = $db->sql_fetchrow($result);
546 $db->sql_freeresult($result);
548 if ($row)
550 $post_data['post_subject'] = $row['draft_subject'];
551 $message_parser->message = $row['draft_message'];
553 $template->assign_var('S_DRAFT_LOADED', true);
555 else
557 $draft_id = 0;
561 // Load draft overview
562 if ($load && ($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $post_data['drafts'])
564 load_drafts($topic_id, $forum_id);
567 $solved_captcha = false;
569 if ($submit || $preview || $refresh)
571 $post_data['topic_cur_post_id'] = request_var('topic_cur_post_id', 0);
572 $post_data['post_subject'] = utf8_normalize_nfc(request_var('subject', '', true));
573 $message_parser->message = utf8_normalize_nfc(request_var('message', '', true));
575 $post_data['username'] = utf8_normalize_nfc(request_var('username', $post_data['username'], true));
576 $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)) : '';
578 $post_data['orig_topic_type'] = $post_data['topic_type'];
579 $post_data['topic_type'] = request_var('topic_type', (($mode != 'post') ? (int) $post_data['topic_type'] : POST_NORMAL));
580 $post_data['topic_time_limit'] = request_var('topic_time_limit', (($mode != 'post') ? (int) $post_data['topic_time_limit'] : 0));
581 $post_data['icon_id'] = request_var('icon', 0);
583 $post_data['enable_bbcode'] = (!$bbcode_status || isset($_POST['disable_bbcode'])) ? false : true;
584 $post_data['enable_smilies'] = (!$smilies_status || isset($_POST['disable_smilies'])) ? false : true;
585 $post_data['enable_urls'] = (isset($_POST['disable_magic_url'])) ? 0 : 1;
586 $post_data['enable_sig'] = (!$config['allow_sig']) ? false : ((isset($_POST['attach_sig']) && $user->data['is_registered']) ? true : false);
588 if ($config['allow_topic_notify'] && $user->data['is_registered'])
590 $notify = (isset($_POST['notify'])) ? true : false;
592 else
594 $notify = false;
597 $topic_lock = (isset($_POST['lock_topic'])) ? true : false;
598 $post_lock = (isset($_POST['lock_post'])) ? true : false;
599 $poll_delete = (isset($_POST['poll_delete'])) ? true : false;
601 if ($submit)
603 $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);
604 $status_switch = ($status_switch != $check_value);
606 else
608 $status_switch = 1;
611 // Delete Poll
612 if ($poll_delete && $mode == 'edit' && sizeof($post_data['poll_options']) &&
613 ((!$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)))
615 if ($submit && check_form_key('posting'))
617 $sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . "
618 WHERE topic_id = $topic_id";
619 $db->sql_query($sql);
621 $sql = 'DELETE FROM ' . POLL_VOTES_TABLE . "
622 WHERE topic_id = $topic_id";
623 $db->sql_query($sql);
625 $topic_sql = array(
626 'poll_title' => '',
627 'poll_start' => 0,
628 'poll_length' => 0,
629 'poll_last_vote' => 0,
630 'poll_max_options' => 0,
631 'poll_vote_change' => 0
634 $sql = 'UPDATE ' . TOPICS_TABLE . '
635 SET ' . $db->sql_build_array('UPDATE', $topic_sql) . "
636 WHERE topic_id = $topic_id";
637 $db->sql_query($sql);
640 $post_data['poll_title'] = $post_data['poll_option_text'] = '';
641 $post_data['poll_vote_change'] = $post_data['poll_max_options'] = $post_data['poll_length'] = 0;
643 else
645 $post_data['poll_title'] = utf8_normalize_nfc(request_var('poll_title', '', true));
646 $post_data['poll_length'] = request_var('poll_length', 0);
647 $post_data['poll_option_text'] = utf8_normalize_nfc(request_var('poll_option_text', '', true));
648 $post_data['poll_max_options'] = request_var('poll_max_options', 1);
649 $post_data['poll_vote_change'] = ($auth->acl_get('f_votechg', $forum_id) && isset($_POST['poll_vote_change'])) ? 1 : 0;
652 // If replying/quoting and last post id has changed
653 // give user option to continue submit or return to post
654 // notify and show user the post made between his request and the final submit
655 if (($mode == 'reply' || $mode == 'quote') && $post_data['topic_cur_post_id'] && $post_data['topic_cur_post_id'] != $post_data['topic_last_post_id'])
657 // Only do so if it is allowed forum-wide
658 if ($post_data['forum_flags'] & FORUM_FLAG_POST_REVIEW)
660 if (topic_review($topic_id, $forum_id, 'post_review', $post_data['topic_cur_post_id']))
662 $template->assign_var('S_POST_REVIEW', true);
665 $submit = false;
666 $refresh = true;
670 // Parse Attachments - before checksum is calculated
671 $message_parser->parse_attachments('fileupload', $mode, $forum_id, $submit, $preview, $refresh);
673 // Grab md5 'checksum' of new message
674 $message_md5 = md5($message_parser->message);
676 // Check checksum ... don't re-parse message if the same
677 $update_message = ($mode != 'edit' || $message_md5 != $post_data['post_checksum'] || $status_switch || strlen($post_data['bbcode_uid']) < BBCODE_UID_LEN) ? true : false;
679 // Parse message
680 if ($update_message)
682 if (sizeof($message_parser->warn_msg))
684 $error[] = implode('<br />', $message_parser->warn_msg);
685 $message_parser->warn_msg = array();
688 $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']);
690 // On a refresh we do not care about message parsing errors
691 if (sizeof($message_parser->warn_msg) && $refresh)
693 $message_parser->warn_msg = array();
696 else
698 $message_parser->bbcode_bitfield = $post_data['bbcode_bitfield'];
701 if ($mode != 'edit' && !$preview && !$refresh && $config['flood_interval'] && !$auth->acl_get('f_ignoreflood', $forum_id))
703 // Flood check
704 $last_post_time = 0;
706 if ($user->data['is_registered'])
708 $last_post_time = $user->data['user_lastpost_time'];
710 else
712 $sql = 'SELECT post_time AS last_post_time
713 FROM ' . POSTS_TABLE . "
714 WHERE poster_ip = '" . $user->ip . "'
715 AND post_time > " . ($current_time - $config['flood_interval']);
716 $result = $db->sql_query_limit($sql, 1);
717 if ($row = $db->sql_fetchrow($result))
719 $last_post_time = $row['last_post_time'];
721 $db->sql_freeresult($result);
724 if ($last_post_time && ($current_time - $last_post_time) < intval($config['flood_interval']))
726 $error[] = $user->lang['FLOOD_ERROR'];
730 // Validate username
731 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']))
733 include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
735 if (($result = validate_username($post_data['username'], (!empty($post_data['post_username'])) ? $post_data['post_username'] : '')) !== false)
737 $user->add_lang('ucp');
738 $error[] = $user->lang[$result . '_USERNAME'];
742 if ($config['enable_post_confirm'] && !$user->data['is_registered'] && in_array($mode, array('quote', 'post', 'reply')))
744 $confirm_id = request_var('confirm_id', '');
745 $confirm_code = request_var('confirm_code', '');
747 $sql = 'SELECT code
748 FROM ' . CONFIRM_TABLE . "
749 WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "'
750 AND session_id = '" . $db->sql_escape($user->session_id) . "'
751 AND confirm_type = " . CONFIRM_POST;
752 $result = $db->sql_query($sql);
753 $confirm_row = $db->sql_fetchrow($result);
754 $db->sql_freeresult($result);
756 if (empty($confirm_row['code']) || strcasecmp($confirm_row['code'], $confirm_code) !== 0)
758 $error[] = $user->lang['CONFIRM_CODE_WRONG'];
760 else
762 $solved_captcha = true;
766 // check form
767 if (!check_form_key('posting', false, '', false, 2))
769 $error[] = $user->lang['FORM_INVALID'];
772 // Parse subject
773 if (!$preview && !$refresh && !utf8_clean_string($post_data['post_subject']) && ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_id)))
775 $error[] = $user->lang['EMPTY_SUBJECT'];
778 $post_data['poll_last_vote'] = (isset($post_data['poll_last_vote'])) ? $post_data['poll_last_vote'] : 0;
780 if ($post_data['poll_option_text'] &&
781 ($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id']/* && (!$post_data['poll_last_vote'] || $auth->acl_get('m_edit', $forum_id))*/))
782 && $auth->acl_get('f_poll', $forum_id))
784 $poll = array(
785 'poll_title' => $post_data['poll_title'],
786 'poll_length' => $post_data['poll_length'],
787 'poll_max_options' => $post_data['poll_max_options'],
788 'poll_option_text' => $post_data['poll_option_text'],
789 'poll_start' => $post_data['poll_start'],
790 'poll_last_vote' => $post_data['poll_last_vote'],
791 'poll_vote_change' => $post_data['poll_vote_change'],
792 'enable_bbcode' => $post_data['enable_bbcode'],
793 'enable_urls' => $post_data['enable_urls'],
794 'enable_smilies' => $post_data['enable_smilies'],
795 'img_status' => $img_status
798 $message_parser->parse_poll($poll);
800 $post_data['poll_options'] = (isset($poll['poll_options'])) ? $poll['poll_options'] : '';
801 $post_data['poll_title'] = (isset($poll['poll_title'])) ? $poll['poll_title'] : '';
803 /* We reset votes, therefore also allow removing options
804 if ($post_data['poll_last_vote'] && ($poll['poll_options_size'] < $orig_poll_options_size))
806 $message_parser->warn_msg[] = $user->lang['NO_DELETE_POLL_OPTIONS'];
809 else
811 $poll = array();
814 // Check topic type
815 if ($post_data['topic_type'] != POST_NORMAL && ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_id)))
817 switch ($post_data['topic_type'])
819 case POST_GLOBAL:
820 case POST_ANNOUNCE:
821 $auth_option = 'f_announce';
822 break;
824 case POST_STICKY:
825 $auth_option = 'f_sticky';
826 break;
828 default:
829 $auth_option = '';
830 break;
833 if (!$auth->acl_get($auth_option, $forum_id))
835 // There is a special case where a user edits his post whereby the topic type got changed by an admin/mod.
836 // Another case would be a mod not having sticky permissions for example but edit permissions.
837 if ($mode == 'edit')
839 // To prevent non-authed users messing around with the topic type we reset it to the original one.
840 $post_data['topic_type'] = $post_data['orig_topic_type'];
842 else
844 $error[] = $user->lang['CANNOT_POST_' . str_replace('F_', '', strtoupper($auth_option))];
849 if (sizeof($message_parser->warn_msg))
851 $error[] = implode('<br />', $message_parser->warn_msg);
854 // DNSBL check
855 if ($config['check_dnsbl'] && !$refresh)
857 if (($dnsbl = $user->check_dnsbl('post')) !== false)
859 $error[] = sprintf($user->lang['IP_BLACKLISTED'], $user->ip, $dnsbl[1]);
863 // Store message, sync counters
864 if (!sizeof($error) && $submit)
866 // Check if we want to de-globalize the topic... and ask for new forum
867 if ($post_data['topic_type'] != POST_GLOBAL)
869 $sql = 'SELECT topic_type, forum_id
870 FROM ' . TOPICS_TABLE . "
871 WHERE topic_id = $topic_id";
872 $result = $db->sql_query($sql);
873 $row = $db->sql_fetchrow($result);
874 $db->sql_freeresult($result);
876 if ($row && !$row['forum_id'] && $row['topic_type'] == POST_GLOBAL)
878 $to_forum_id = request_var('to_forum_id', 0);
880 if ($to_forum_id)
882 $sql = 'SELECT forum_type
883 FROM ' . FORUMS_TABLE . '
884 WHERE forum_id = ' . $to_forum_id;
885 $result = $db->sql_query($sql);
886 $forum_type = (int) $db->sql_fetchfield('forum_type');
887 $db->sql_freeresult($result);
889 if ($forum_type != FORUM_POST || !$auth->acl_get('f_post', $to_forum_id))
891 $to_forum_id = 0;
895 if (!$to_forum_id)
897 include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
899 $template->assign_vars(array(
900 'S_FORUM_SELECT' => make_forum_select(false, false, false, true, true, true),
901 'S_UNGLOBALISE' => true)
904 $submit = false;
905 $refresh = true;
907 else
909 if (!$auth->acl_get('f_post', $to_forum_id))
911 // This will only be triggered if the user tried to trick the forum.
912 trigger_error('NOT_AUTHORISED');
915 $forum_id = $to_forum_id;
920 if ($submit)
922 // Lock/Unlock Topic
923 $change_topic_status = $post_data['topic_status'];
924 $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;
926 if ($post_data['topic_status'] == ITEM_LOCKED && !$topic_lock && $perm_lock_unlock)
928 $change_topic_status = ITEM_UNLOCKED;
930 else if ($post_data['topic_status'] == ITEM_UNLOCKED && $topic_lock && $perm_lock_unlock)
932 $change_topic_status = ITEM_LOCKED;
935 if ($change_topic_status != $post_data['topic_status'])
937 $sql = 'UPDATE ' . TOPICS_TABLE . "
938 SET topic_status = $change_topic_status
939 WHERE topic_id = $topic_id
940 AND topic_moved_id = 0";
941 $db->sql_query($sql);
943 $user_lock = ($auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && $user->data['user_id'] == $post_data['topic_poster']) ? 'USER_' : '';
945 add_log('mod', $forum_id, $topic_id, 'LOG_' . $user_lock . (($change_topic_status == ITEM_LOCKED) ? 'LOCK' : 'UNLOCK'), $post_data['topic_title']);
948 // Lock/Unlock Post Edit
949 if ($mode == 'edit' && $post_data['post_edit_locked'] == ITEM_LOCKED && !$post_lock && $auth->acl_get('m_edit', $forum_id))
951 $post_data['post_edit_locked'] = ITEM_UNLOCKED;
953 else if ($mode == 'edit' && $post_data['post_edit_locked'] == ITEM_UNLOCKED && $post_lock && $auth->acl_get('m_edit', $forum_id))
955 $post_data['post_edit_locked'] = ITEM_LOCKED;
958 $data = array(
959 'topic_title' => (empty($post_data['topic_title'])) ? $post_data['post_subject'] : $post_data['topic_title'],
960 'topic_first_post_id' => (isset($post_data['topic_first_post_id'])) ? (int) $post_data['topic_first_post_id'] : 0,
961 'topic_last_post_id' => (isset($post_data['topic_last_post_id'])) ? (int) $post_data['topic_last_post_id'] : 0,
962 'topic_time_limit' => (int) $post_data['topic_time_limit'],
963 'topic_attachment' => (isset($post_data['topic_attachment'])) ? (int) $post_data['topic_attachment'] : 0,
964 'post_id' => (int) $post_id,
965 'topic_id' => (int) $topic_id,
966 'forum_id' => (int) $forum_id,
967 'icon_id' => (int) $post_data['icon_id'],
968 'poster_id' => (int) $post_data['poster_id'],
969 'enable_sig' => (bool) $post_data['enable_sig'],
970 'enable_bbcode' => (bool) $post_data['enable_bbcode'],
971 'enable_smilies' => (bool) $post_data['enable_smilies'],
972 'enable_urls' => (bool) $post_data['enable_urls'],
973 'enable_indexing' => (bool) $post_data['enable_indexing'],
974 'message_md5' => (string) $message_md5,
975 'post_time' => (isset($post_data['post_time'])) ? (int) $post_data['post_time'] : $current_time,
976 'post_checksum' => (isset($post_data['post_checksum'])) ? (string) $post_data['post_checksum'] : '',
977 'post_edit_reason' => $post_data['post_edit_reason'],
978 'post_edit_user' => ($mode == 'edit') ? $user->data['user_id'] : ((isset($post_data['post_edit_user'])) ? (int) $post_data['post_edit_user'] : 0),
979 'forum_parents' => $post_data['forum_parents'],
980 'forum_name' => $post_data['forum_name'],
981 'notify' => $notify,
982 'notify_set' => $post_data['notify_set'],
983 'poster_ip' => (isset($post_data['poster_ip'])) ? $post_data['poster_ip'] : $user->ip,
984 'post_edit_locked' => (int) $post_data['post_edit_locked'],
985 'bbcode_bitfield' => $message_parser->bbcode_bitfield,
986 'bbcode_uid' => $message_parser->bbcode_uid,
987 'message' => $message_parser->message,
988 'attachment_data' => $message_parser->attachment_data,
989 'filename_data' => $message_parser->filename_data,
991 'topic_approved' => (isset($post_data['topic_approved'])) ? $post_data['topic_approved'] : false,
992 'post_approved' => (isset($post_data['post_approved'])) ? $post_data['post_approved'] : false,
995 if ($mode == 'edit')
997 $data['topic_replies_real'] = $post_data['topic_replies_real'];
998 $data['topic_replies'] = $post_data['topic_replies'];
1001 unset($message_parser);
1003 $redirect_url = submit_post($mode, $post_data['post_subject'], $post_data['username'], $post_data['topic_type'], $poll, $data, $update_message);
1004 $post_need_approval = (!$auth->acl_get('f_noapprove', $data['forum_id']) && !$auth->acl_get('m_approve', $data['forum_id'])) ? true : false;
1006 // If the post need approval we will wait a lot longer.
1007 if ($post_need_approval)
1009 meta_refresh(10, $redirect_url);
1010 $message = ($mode == 'edit') ? $user->lang['POST_EDITED_MOD'] : $user->lang['POST_STORED_MOD'];
1011 $message .= (($user->data['user_id'] == ANONYMOUS) ? '' : ' '. $user->lang['POST_APPROVAL_NOTIFY']);
1013 else
1015 meta_refresh(3, $redirect_url);
1017 $message = ($mode == 'edit') ? 'POST_EDITED' : 'POST_STORED';
1018 $message = $user->lang[$message] . '<br /><br />' . sprintf($user->lang['VIEW_MESSAGE'], '<a href="' . $redirect_url . '">', '</a>');
1021 $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $data['forum_id']) . '">', '</a>');
1022 trigger_error($message);
1027 // Preview
1028 if (!sizeof($error) && $preview)
1030 $post_data['post_time'] = ($mode == 'edit') ? $post_data['post_time'] : $current_time;
1032 $preview_message = $message_parser->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies'], false);
1034 $preview_signature = ($mode == 'edit') ? $post_data['user_sig'] : $user->data['user_sig'];
1035 $preview_signature_uid = ($mode == 'edit') ? $post_data['user_sig_bbcode_uid'] : $user->data['user_sig_bbcode_uid'];
1036 $preview_signature_bitfield = ($mode == 'edit') ? $post_data['user_sig_bbcode_bitfield'] : $user->data['user_sig_bbcode_bitfield'];
1038 // Signature
1039 if ($post_data['enable_sig'] && $config['allow_sig'] && $preview_signature && $auth->acl_get('f_sigs', $forum_id))
1041 $parse_sig = new parse_message($preview_signature);
1042 $parse_sig->bbcode_uid = $preview_signature_uid;
1043 $parse_sig->bbcode_bitfield = $preview_signature_bitfield;
1045 // Not sure about parameters for bbcode/smilies/urls... in signatures
1046 $parse_sig->format_display($config['allow_sig_bbcode'], true, $config['allow_sig_smilies']);
1047 $preview_signature = $parse_sig->message;
1048 unset($parse_sig);
1050 else
1052 $preview_signature = '';
1055 $preview_subject = censor_text($post_data['post_subject']);
1057 // Poll Preview
1058 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))*/))
1059 && $auth->acl_get('f_poll', $forum_id))
1061 $parse_poll = new parse_message($post_data['poll_title']);
1062 $parse_poll->bbcode_uid = $message_parser->bbcode_uid;
1063 $parse_poll->bbcode_bitfield = $message_parser->bbcode_bitfield;
1065 $parse_poll->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies']);
1067 if ($post_data['poll_length'])
1069 $poll_end = ($post_data['poll_length'] * 86400) + (($post_data['poll_start']) ? $post_data['poll_start'] : time());
1072 $template->assign_vars(array(
1073 'S_HAS_POLL_OPTIONS' => (sizeof($post_data['poll_options'])),
1074 'S_IS_MULTI_CHOICE' => ($post_data['poll_max_options'] > 1) ? true : false,
1076 'POLL_QUESTION' => $parse_poll->message,
1078 'L_POLL_LENGTH' => ($post_data['poll_length']) ? sprintf($user->lang['POLL_RUN_TILL'], $user->format_date($poll_end)) : '',
1079 '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']))
1082 $parse_poll->message = implode("\n", $post_data['poll_options']);
1083 $parse_poll->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies']);
1084 $preview_poll_options = explode('<br />', $parse_poll->message);
1085 unset($parse_poll);
1087 foreach ($preview_poll_options as $key => $option)
1089 $template->assign_block_vars('poll_option', array(
1090 'POLL_OPTION_CAPTION' => $option,
1091 'POLL_OPTION_ID' => $key + 1)
1094 unset($preview_poll_options);
1097 // Attachment Preview
1098 if (sizeof($message_parser->attachment_data))
1100 $template->assign_var('S_HAS_ATTACHMENTS', true);
1102 $update_count = array();
1103 $attachment_data = $message_parser->attachment_data;
1105 parse_attachments($forum_id, $preview_message, $attachment_data, $update_count, true);
1107 foreach ($attachment_data as $i => $attachment)
1109 $template->assign_block_vars('attachment', array(
1110 'DISPLAY_ATTACHMENT' => $attachment)
1113 unset($attachment_data);
1116 if (!sizeof($error))
1118 $template->assign_vars(array(
1119 'PREVIEW_SUBJECT' => $preview_subject,
1120 'PREVIEW_MESSAGE' => $preview_message,
1121 'PREVIEW_SIGNATURE' => $preview_signature,
1123 'S_DISPLAY_PREVIEW' => true)
1128 // Decode text for message display
1129 $post_data['bbcode_uid'] = ($mode == 'quote' && !$preview && !$refresh && !sizeof($error)) ? $post_data['bbcode_uid'] : $message_parser->bbcode_uid;
1130 $message_parser->decode_message($post_data['bbcode_uid']);
1132 if ($mode == 'quote' && !$submit && !$preview && !$refresh)
1134 $message_parser->message = '[quote="' . $post_data['quote_username'] . '"]' . censor_text(trim($message_parser->message)) . "[/quote]\n";
1137 if (($mode == 'reply' || $mode == 'quote') && !$submit && !$preview && !$refresh)
1139 $post_data['post_subject'] = ((strpos($post_data['post_subject'], 'Re: ') !== 0) ? 'Re: ' : '') . censor_text($post_data['post_subject']);
1142 $attachment_data = $message_parser->attachment_data;
1143 $filename_data = $message_parser->filename_data;
1144 $post_data['post_text'] = $message_parser->message;
1146 if (sizeof($post_data['poll_options']) && $post_data['poll_title'])
1148 $message_parser->message = $post_data['poll_title'];
1149 $message_parser->bbcode_uid = $post_data['bbcode_uid'];
1151 $message_parser->decode_message();
1152 $post_data['poll_title'] = $message_parser->message;
1154 $message_parser->message = implode("\n", $post_data['poll_options']);
1155 $message_parser->decode_message();
1156 $post_data['poll_options'] = explode("\n", $message_parser->message);
1158 unset($message_parser);
1160 // MAIN POSTING PAGE BEGINS HERE
1162 // Forum moderators?
1163 $moderators = array();
1164 get_moderators($moderators, $forum_id);
1166 // Generate smiley listing
1167 generate_smilies('inline', $forum_id);
1169 // Generate inline attachment select box
1170 posting_gen_inline_attachments($attachment_data);
1172 // Do show topic type selection only in first post.
1173 $topic_type_toggle = false;
1175 if ($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id']))
1177 $topic_type_toggle = posting_gen_topic_types($forum_id, $post_data['topic_type']);
1180 $s_topic_icons = false;
1181 if ($post_data['enable_icons'] && $auth->acl_get('f_icons', $forum_id))
1183 $s_topic_icons = posting_gen_topic_icons($mode, $post_data['icon_id']);
1186 $bbcode_checked = (isset($post_data['enable_bbcode'])) ? !$post_data['enable_bbcode'] : (($config['allow_bbcode']) ? !$user->optionget('bbcode') : 1);
1187 $smilies_checked = (isset($post_data['enable_smilies'])) ? !$post_data['enable_smilies'] : (($config['allow_smilies']) ? !$user->optionget('smilies') : 1);
1188 $urls_checked = (isset($post_data['enable_urls'])) ? !$post_data['enable_urls'] : 0;
1189 $sig_checked = $post_data['enable_sig'];
1190 $lock_topic_checked = (isset($topic_lock) && $topic_lock) ? $topic_lock : (($post_data['topic_status'] == ITEM_LOCKED) ? 1 : 0);
1191 $lock_post_checked = (isset($post_lock)) ? $post_lock : $post_data['post_edit_locked'];
1193 // 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
1194 $notify_set = ($mode != 'edit' && $config['allow_topic_notify'] && $user->data['is_registered'] && !$post_data['notify_set']) ? $user->data['user_notify'] : $post_data['notify_set'];
1195 $notify_checked = (isset($notify)) ? $notify : (($mode == 'post') ? $user->data['user_notify'] : $notify_set);
1197 // Page title & action URL, include session_id for security purpose
1198 $s_action = append_sid("{$phpbb_root_path}posting.$phpEx", "mode=$mode&amp;f=$forum_id", true, $user->session_id);
1199 $s_action .= ($topic_id) ? "&amp;t=$topic_id" : '';
1200 $s_action .= ($post_id) ? "&amp;p=$post_id" : '';
1202 switch ($mode)
1204 case 'post':
1205 $page_title = $user->lang['POST_TOPIC'];
1206 break;
1208 case 'quote':
1209 case 'reply':
1210 $page_title = $user->lang['POST_REPLY'];
1211 break;
1213 case 'delete':
1214 case 'edit':
1215 $page_title = $user->lang['EDIT_POST'];
1216 break;
1219 // Build Navigation Links
1220 generate_forum_nav($post_data);
1222 // Build Forum Rules
1223 generate_forum_rules($post_data);
1225 if ($config['enable_post_confirm'] && !$user->data['is_registered'] && $solved_captcha === false && ($mode == 'post' || $mode == 'reply' || $mode == 'quote'))
1227 // Show confirm image
1228 $sql = 'DELETE FROM ' . CONFIRM_TABLE . "
1229 WHERE session_id = '" . $db->sql_escape($user->session_id) . "'
1230 AND confirm_type = " . CONFIRM_POST;
1231 $db->sql_query($sql);
1233 // Generate code
1234 $code = gen_rand_string(mt_rand(5, 8));
1235 $confirm_id = md5(unique_id($user->ip));
1236 $seed = hexdec(substr(unique_id(), 4, 10));
1238 // compute $seed % 0x7fffffff
1239 $seed -= 0x7fffffff * floor($seed / 0x7fffffff);
1241 $sql = 'INSERT INTO ' . CONFIRM_TABLE . ' ' . $db->sql_build_array('INSERT', array(
1242 'confirm_id' => (string) $confirm_id,
1243 'session_id' => (string) $user->session_id,
1244 'confirm_type' => (int) CONFIRM_POST,
1245 'code' => (string) $code,
1246 'seed' => (int) $seed)
1248 $db->sql_query($sql);
1250 $template->assign_vars(array(
1251 'S_CONFIRM_CODE' => true,
1252 'CONFIRM_ID' => $confirm_id,
1253 'CONFIRM_IMAGE' => '<img src="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=confirm&amp;id=' . $confirm_id . '&amp;type=' . CONFIRM_POST) . '" alt="" title="" />',
1254 'L_POST_CONFIRM_EXPLAIN' => sprintf($user->lang['POST_CONFIRM_EXPLAIN'], '<a href="mailto:' . htmlspecialchars($config['board_contact']) . '">', '</a>'),
1258 $s_hidden_fields = ($mode == 'reply' || $mode == 'quote') ? '<input type="hidden" name="topic_cur_post_id" value="' . $post_data['topic_last_post_id'] . '" />' : '';
1259 $s_hidden_fields .= '<input type="hidden" name="lastclick" value="' . $current_time . '" />';
1260 $s_hidden_fields .= ($draft_id || isset($_REQUEST['draft_loaded'])) ? '<input type="hidden" name="draft_loaded" value="' . request_var('draft_loaded', $draft_id) . '" />' : '';
1262 // Add the confirm id/code pair to the hidden fields, else an error is displayed on next submit/preview
1263 if ($solved_captcha !== false)
1265 $s_hidden_fields .= build_hidden_fields(array(
1266 'confirm_id' => request_var('confirm_id', ''),
1267 'confirm_code' => request_var('confirm_code', ''))
1271 $form_enctype = (@ini_get('file_uploads') == '0' || strtolower(@ini_get('file_uploads')) == 'off' || @ini_get('file_uploads') == '0' || !$config['allow_attachments'] || !$auth->acl_get('u_attach') || !$auth->acl_get('f_attach', $forum_id)) ? '' : ' enctype="multipart/form-data"';
1272 add_form_key('posting');
1275 // Start assigning vars for main posting page ...
1276 $template->assign_vars(array(
1277 'L_POST_A' => $page_title,
1278 'L_ICON' => ($mode == 'reply' || $mode == 'quote' || ($mode == 'edit' && $post_id != $post_data['topic_first_post_id'])) ? $user->lang['POST_ICON'] : $user->lang['TOPIC_ICON'],
1279 'L_MESSAGE_BODY_EXPLAIN' => (intval($config['max_post_chars'])) ? sprintf($user->lang['MESSAGE_BODY_EXPLAIN'], intval($config['max_post_chars'])) : '',
1281 'FORUM_NAME' => $post_data['forum_name'],
1282 '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']) : '',
1283 'TOPIC_TITLE' => censor_text($post_data['topic_title']),
1284 'MODERATORS' => (sizeof($moderators)) ? implode(', ', $moderators[$forum_id]) : '',
1285 'USERNAME' => ((!$preview && $mode != 'quote') || $preview) ? $post_data['username'] : '',
1286 'SUBJECT' => $post_data['post_subject'],
1287 'MESSAGE' => $post_data['post_text'],
1288 'BBCODE_STATUS' => ($bbcode_status) ? sprintf($user->lang['BBCODE_IS_ON'], '<a href="' . append_sid("{$phpbb_root_path}faq.$phpEx", 'mode=bbcode') . '">', '</a>') : sprintf($user->lang['BBCODE_IS_OFF'], '<a href="' . append_sid("{$phpbb_root_path}faq.$phpEx", 'mode=bbcode') . '">', '</a>'),
1289 'IMG_STATUS' => ($img_status) ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'],
1290 'FLASH_STATUS' => ($flash_status) ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'],
1291 'SMILIES_STATUS' => ($smilies_status) ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'],
1292 'URL_STATUS' => ($bbcode_status && $url_status) ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'],
1293 'MINI_POST_IMG' => $user->img('icon_post_target', $user->lang['POST']),
1294 'POST_DATE' => ($post_data['post_time']) ? $user->format_date($post_data['post_time']) : '',
1295 'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '',
1296 'TOPIC_TIME_LIMIT' => (int) $post_data['topic_time_limit'],
1297 'EDIT_REASON' => $post_data['post_edit_reason'],
1298 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id"),
1299 'U_VIEW_TOPIC' => ($mode != 'post') ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id") : '',
1300 'U_PROGRESS_BAR' => append_sid("{$phpbb_root_path}posting.$phpEx", "f=$forum_id&amp;mode=popup"),
1301 'UA_PROGRESS_BAR' => addslashes(append_sid("{$phpbb_root_path}posting.$phpEx", "f=$forum_id&amp;mode=popup")),
1303 'S_PRIVMSGS' => false,
1304 'S_CLOSE_PROGRESS_WINDOW' => (isset($_POST['add_file'])) ? true : false,
1305 'S_EDIT_POST' => ($mode == 'edit') ? true : false,
1306 'S_EDIT_REASON' => ($mode == 'edit' && $auth->acl_get('m_edit', $forum_id)) ? true : false,
1307 'S_DISPLAY_USERNAME' => (!$user->data['is_registered'] || ($mode == 'edit' && $post_data['poster_id'] == ANONYMOUS)) ? true : false,
1308 'S_SHOW_TOPIC_ICONS' => $s_topic_icons,
1309 'S_DELETE_ALLOWED' => ($mode == 'edit' && (($post_id == $post_data['topic_last_post_id'] && $post_data['poster_id'] == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id)) || $auth->acl_get('m_delete', $forum_id))) ? true : false,
1310 'S_BBCODE_ALLOWED' => $bbcode_status,
1311 'S_BBCODE_CHECKED' => ($bbcode_checked) ? ' checked="checked"' : '',
1312 'S_SMILIES_ALLOWED' => $smilies_status,
1313 'S_SMILIES_CHECKED' => ($smilies_checked) ? ' checked="checked"' : '',
1314 'S_SIG_ALLOWED' => ($auth->acl_get('f_sigs', $forum_id) && $config['allow_sig'] && $user->data['is_registered']) ? true : false,
1315 'S_SIGNATURE_CHECKED' => ($sig_checked) ? ' checked="checked"' : '',
1316 'S_NOTIFY_ALLOWED' => (!$user->data['is_registered'] || ($mode == 'edit' && $user->data['user_id'] != $post_data['poster_id']) || !$config['allow_topic_notify'] || !$config['email_enable']) ? false : true,
1317 'S_NOTIFY_CHECKED' => ($notify_checked) ? ' checked="checked"' : '',
1318 'S_LOCK_TOPIC_ALLOWED' => (($mode == 'edit' || $mode == 'reply' || $mode == 'quote') && ($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,
1319 'S_LOCK_TOPIC_CHECKED' => ($lock_topic_checked) ? ' checked="checked"' : '',
1320 'S_LOCK_POST_ALLOWED' => ($mode == 'edit' && $auth->acl_get('m_edit', $forum_id)) ? true : false,
1321 'S_LOCK_POST_CHECKED' => ($lock_post_checked) ? ' checked="checked"' : '',
1322 'S_LINKS_ALLOWED' => $url_status,
1323 'S_MAGIC_URL_CHECKED' => ($urls_checked) ? ' checked="checked"' : '',
1324 'S_TYPE_TOGGLE' => $topic_type_toggle,
1325 'S_SAVE_ALLOWED' => ($auth->acl_get('u_savedrafts') && $user->data['is_registered'] && $mode != 'edit') ? true : false,
1326 'S_HAS_DRAFTS' => ($auth->acl_get('u_savedrafts') && $user->data['is_registered'] && $post_data['drafts']) ? true : false,
1327 'S_FORM_ENCTYPE' => $form_enctype,
1329 'S_BBCODE_IMG' => $img_status,
1330 'S_BBCODE_URL' => $url_status,
1331 'S_BBCODE_FLASH' => $flash_status,
1332 'S_BBCODE_QUOTE' => $quote_status,
1334 'S_POST_ACTION' => $s_action,
1335 'S_HIDDEN_FIELDS' => $s_hidden_fields)
1338 // Build custom bbcodes array
1339 display_custom_bbcodes();
1341 // Poll entry
1342 if (($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id']/* && (!$post_data['poll_last_vote'] || $auth->acl_get('m_edit', $forum_id))*/))
1343 && $auth->acl_get('f_poll', $forum_id))
1345 $template->assign_vars(array(
1346 'S_SHOW_POLL_BOX' => true,
1347 'S_POLL_VOTE_CHANGE' => ($auth->acl_get('f_votechg', $forum_id)),
1348 'S_POLL_DELETE' => ($mode == 'edit' && sizeof($post_data['poll_options']) && ((!$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))),
1349 'S_POLL_DELETE_CHECKED' => (!empty($poll_delete)) ? true : false,
1351 'L_POLL_OPTIONS_EXPLAIN' => sprintf($user->lang['POLL_OPTIONS_' . (($mode == 'edit') ? 'EDIT_' : '') . 'EXPLAIN'], $config['max_poll_options']),
1353 'VOTE_CHANGE_CHECKED' => (!empty($post_data['poll_vote_change'])) ? ' checked="checked"' : '',
1354 'POLL_TITLE' => (isset($post_data['poll_title'])) ? $post_data['poll_title'] : '',
1355 'POLL_OPTIONS' => (!empty($post_data['poll_options'])) ? implode("\n", $post_data['poll_options']) : '',
1356 'POLL_MAX_OPTIONS' => (isset($post_data['poll_max_options'])) ? (int) $post_data['poll_max_options'] : 1,
1357 'POLL_LENGTH' => $post_data['poll_length'])
1361 // Attachment entry
1362 // Not using acl_gets here, because it is using OR logic
1363 if ($auth->acl_get('f_attach', $forum_id) && $auth->acl_get('u_attach') && $config['allow_attachments'] && $form_enctype)
1365 posting_gen_attachment_entry($attachment_data, $filename_data);
1368 // Output page ...
1369 page_header($page_title);
1371 $template->set_filenames(array(
1372 'body' => 'posting_body.html')
1375 make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
1377 // Topic review
1378 if ($mode == 'reply' || $mode == 'quote')
1380 if (topic_review($topic_id, $forum_id))
1382 $template->assign_var('S_DISPLAY_REVIEW', true);
1386 page_footer();
1389 * Show upload popup (progress bar)
1391 function upload_popup($forum_style = 0)
1393 global $template, $user;
1395 ($forum_style) ? $user->setup('posting', $forum_style) : $user->setup('posting');
1397 page_header($user->lang['PROGRESS_BAR']);
1399 $template->set_filenames(array(
1400 'popup' => 'posting_progress_bar.html')
1403 $template->assign_vars(array(
1404 'PROGRESS_BAR' => $user->img('upload_bar', $user->lang['UPLOAD_IN_PROGRESS']))
1407 $template->display('popup');
1411 * Do the various checks required for removing posts as well as removing it
1413 function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data)
1415 global $user, $db, $auth;
1416 global $phpbb_root_path, $phpEx;
1418 // If moderator removing post or user itself removing post, present a confirmation screen
1419 if ($auth->acl_get('m_delete', $forum_id) || ($post_data['poster_id'] == $user->data['user_id'] && $user->data['is_registered'] && $auth->acl_get('f_delete', $forum_id) && $post_id == $post_data['topic_last_post_id']))
1421 $s_hidden_fields = build_hidden_fields(array(
1422 'p' => $post_id,
1423 'f' => $forum_id,
1424 'mode' => 'delete')
1427 if (confirm_box(true))
1429 $data = array(
1430 'topic_first_post_id' => $post_data['topic_first_post_id'],
1431 'topic_last_post_id' => $post_data['topic_last_post_id'],
1432 'topic_approved' => $post_data['topic_approved'],
1433 'topic_type' => $post_data['topic_type'],
1434 'post_approved' => $post_data['post_approved'],
1435 'post_reported' => $post_data['post_reported'],
1436 'post_time' => $post_data['post_time'],
1437 'poster_id' => $post_data['poster_id'],
1438 'post_postcount' => $post_data['post_postcount']
1441 $next_post_id = delete_post($forum_id, $topic_id, $post_id, $data);
1443 if ($post_data['topic_first_post_id'] == $post_data['topic_last_post_id'])
1445 add_log('mod', $forum_id, $topic_id, 'LOG_DELETE_TOPIC', $post_data['topic_title']);
1447 $meta_info = append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id");
1448 $message = $user->lang['POST_DELETED'];
1450 else
1452 add_log('mod', $forum_id, $topic_id, 'LOG_DELETE_POST', $post_data['post_subject']);
1454 $meta_info = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;p=$next_post_id") . "#p$next_post_id";
1455 $message = $user->lang['POST_DELETED'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $meta_info . '">', '</a>');
1458 meta_refresh(3, $meta_info);
1459 $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
1460 trigger_error($message);
1462 else
1464 confirm_box(false, 'DELETE_MESSAGE', $s_hidden_fields);
1468 // If we are here the user is not able to delete - present the correct error message
1469 if ($post_data['poster_id'] != $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id))
1471 trigger_error('DELETE_OWN_POSTS');
1474 if ($post_data['poster_id'] == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id) && $post_id != $post_data['topic_last_post_id'])
1476 trigger_error('CANNOT_DELETE_REPLIED');
1479 trigger_error('USER_CANNOT_DELETE');