adjusted the faq a bit according to bug #11120. Thanks to dark/rain and marosell...
[phpbb.git] / phpBB / posting.php
blob77f8aa720d0bc9599d11c631f048a6d56c5e9b38
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 = './';
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();
48 // Was cancel pressed? If so then redirect to the appropriate page
49 if ($cancel || ($current_time - $lastclick < 2 && $submit))
51 $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")));
52 redirect($redirect);
55 if (in_array($mode, array('post', 'reply', 'quote', 'edit', 'delete')) && !$forum_id)
57 trigger_error('NO_FORUM');
60 // We need to know some basic information in all cases before we do anything.
61 switch ($mode)
63 case 'post':
64 $sql = 'SELECT *
65 FROM ' . FORUMS_TABLE . "
66 WHERE forum_id = $forum_id";
67 break;
69 case 'bump':
70 case 'reply':
71 if (!$topic_id)
73 trigger_error('NO_TOPIC');
76 $sql = 'SELECT f.*, t.*
77 FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f
78 WHERE t.topic_id = $topic_id
79 AND (f.forum_id = t.forum_id
80 OR f.forum_id = $forum_id)";
81 break;
83 case 'quote':
84 case 'edit':
85 case 'delete':
86 if (!$post_id)
88 $user->setup('posting');
89 trigger_error('NO_POST');
92 $sql = 'SELECT f.*, t.*, p.*, u.username, u.username_clean, u.user_sig, u.user_sig_bbcode_uid, u.user_sig_bbcode_bitfield
93 FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . ' f, ' . USERS_TABLE . " u
94 WHERE p.post_id = $post_id
95 AND t.topic_id = p.topic_id
96 AND u.user_id = p.poster_id
97 AND (f.forum_id = t.forum_id
98 OR f.forum_id = $forum_id)";
99 break;
101 case 'smilies':
102 $sql = '';
103 generate_smilies('window', $forum_id);
104 break;
106 case 'popup':
107 if ($forum_id)
109 $sql = 'SELECT forum_style
110 FROM ' . FORUMS_TABLE . '
111 WHERE forum_id = ' . $forum_id;
113 else
115 upload_popup();
116 exit;
118 break;
120 default:
121 $sql = '';
122 break;
125 if (!$sql)
127 $user->setup('posting');
128 trigger_error('NO_POST_MODE');
131 $result = $db->sql_query($sql);
132 $post_data = $db->sql_fetchrow($result);
133 $db->sql_freeresult($result);
135 if (!$post_data)
137 if (!($mode == 'post' || $mode == 'bump' || $mode == 'reply'))
139 $user->setup('posting');
141 trigger_error(($mode == 'post' || $mode == 'bump' || $mode == 'reply') ? 'NO_TOPIC' : 'NO_POST');
144 if ($mode == 'popup')
146 upload_popup($post_data['forum_style']);
147 exit;
150 $user->setup(array('posting', 'mcp', 'viewtopic'), $post_data['forum_style']);
152 // Use post_row values in favor of submitted ones...
153 $forum_id = (!empty($post_data['forum_id'])) ? (int) $post_data['forum_id'] : (int) $forum_id;
154 $topic_id = (!empty($post_data['topic_id'])) ? (int) $post_data['topic_id'] : (int) $topic_id;
155 $post_id = (!empty($post_data['post_id'])) ? (int) $post_data['post_id'] : (int) $post_id;
157 // Need to login to passworded forum first?
158 if ($post_data['forum_password'])
160 login_forum_box(array(
161 'forum_id' => $forum_id,
162 'forum_password' => $post_data['forum_password'])
166 // Check permissions
168 // Is the user able to read within this forum?
169 if (!$auth->acl_get('f_read', $forum_id))
171 if ($user->data['user_id'] != ANONYMOUS)
173 trigger_error('USER_CANNOT_READ');
176 login_box('', $user->lang['LOGIN_EXPLAIN_POST']);
179 // Permission to do the action asked?
180 $is_authed = false;
182 switch ($mode)
184 case 'post':
185 if ($auth->acl_get('f_post', $forum_id))
187 $is_authed = true;
189 break;
191 case 'bump':
192 if ($auth->acl_get('f_bump', $forum_id))
194 $is_authed = true;
196 break;
198 case 'quote':
200 $post_data['post_edit_locked'] = 0;
202 // no break;
204 case 'reply':
205 if ($auth->acl_get('f_reply', $forum_id))
207 $is_authed = true;
209 break;
211 case 'edit':
212 if ($user->data['is_registered'] && $auth->acl_gets('f_edit', 'm_edit', $forum_id))
214 $is_authed = true;
216 break;
218 case 'delete':
219 if ($user->data['is_registered'] && $auth->acl_gets('f_delete', 'm_delete', $forum_id))
221 $is_authed = true;
223 break;
226 if (!$is_authed)
228 $check_auth = ($mode == 'quote') ? 'reply' : $mode;
230 if ($user->data['is_registered'])
232 trigger_error('USER_CANNOT_' . strtoupper($check_auth));
235 login_box('', $user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)]);
238 // Is the user able to post within this forum?
239 if ($post_data['forum_type'] != FORUM_POST && in_array($mode, array('post', 'bump', 'quote', 'reply')))
241 trigger_error('USER_CANNOT_FORUM_POST');
244 // Forum/Topic locked?
245 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))
247 trigger_error(($post_data['forum_status'] == ITEM_LOCKED) ? 'FORUM_LOCKED' : 'TOPIC_LOCKED');
250 // Can we edit this post ... if we're a moderator with rights then always yes
251 // else it depends on editing times, lock status and if we're the correct user
252 if ($mode == 'edit' && !$auth->acl_get('m_edit', $forum_id))
254 if ($user->data['user_id'] != $post_data['poster_id'])
256 trigger_error('USER_CANNOT_EDIT');
259 if (!($post_data['post_time'] > time() - ($config['edit_time'] * 60) || !$config['edit_time']))
261 trigger_error('CANNOT_EDIT_TIME');
264 if ($post_data['post_edit_locked'])
266 trigger_error('CANNOT_EDIT_POST_LOCKED');
270 // Handle delete mode...
271 if ($mode == 'delete')
273 handle_post_delete($forum_id, $topic_id, $post_id, $post_data);
274 exit;
277 // Handle bump mode...
278 if ($mode == 'bump')
280 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']))
282 $db->sql_transaction('begin');
284 $sql = 'UPDATE ' . POSTS_TABLE . "
285 SET post_time = $current_time
286 WHERE post_id = {$post_data['topic_last_post_id']}
287 AND topic_id = $topic_id";
288 $db->sql_query($sql);
290 $sql = 'UPDATE ' . TOPICS_TABLE . "
291 SET topic_last_post_time = $current_time,
292 topic_bumped = 1,
293 topic_bumper = " . $user->data['user_id'] . "
294 WHERE topic_id = $topic_id";
295 $db->sql_query($sql);
297 update_post_information('forum', $forum_id);
299 $sql = 'UPDATE ' . USERS_TABLE . "
300 SET user_lastpost_time = $current_time
301 WHERE user_id = " . $user->data['user_id'];
302 $db->sql_query($sql);
304 $db->sql_transaction('commit');
306 markread('post', $forum_id, $topic_id, $current_time);
308 add_log('mod', $forum_id, $topic_id, 'LOG_BUMP_TOPIC', $post_data['topic_title']);
310 $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']}";
311 meta_refresh(3, $meta_url);
313 $message = $user->lang['TOPIC_BUMPED'] . '<br /><br />' . sprintf($user->lang['VIEW_MESSAGE'], '<a href="' . $meta_url . '">', '</a>');
314 $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
316 trigger_error($message);
319 trigger_error('BUMP_ERROR');
323 // Determine some vars
324 $post_data['quote_username'] = (!empty($post_data['username'])) ? $post_data['username'] : ((!empty($post_data['post_username'])) ? $post_data['post_username'] : '');
325 $post_data['post_edit_locked'] = (isset($post_data['post_edit_locked'])) ? (int) $post_data['post_edit_locked'] : 0;
326 $post_data['post_subject'] = (in_array($mode, array('quote', 'edit'))) ? $post_data['post_subject'] : ((isset($post_data['topic_title'])) ? $post_data['topic_title'] : '');
327 $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;
328 $post_data['poll_length'] = (!empty($post_data['poll_length'])) ? (int) $post_data['poll_length'] / 86400 : 0;
329 $post_data['poll_start'] = (!empty($post_data['poll_start'])) ? (int) $post_data['poll_start'] : 0;
330 $post_data['icon_id'] = (!isset($post_data['icon_id']) || in_array($mode, array('quote', 'reply'))) ? 0 : (int) $post_data['icon_id'];
331 $post_data['poll_options'] = array();
333 // Get Poll Data
334 if ($post_data['poll_start'])
336 $sql = 'SELECT poll_option_text
337 FROM ' . POLL_OPTIONS_TABLE . "
338 WHERE topic_id = $topic_id
339 ORDER BY poll_option_id";
340 $result = $db->sql_query($sql);
342 while ($row = $db->sql_fetchrow($result))
344 $post_data['poll_options'][] = trim($row['poll_option_text']);
346 $db->sql_freeresult($result);
349 $orig_poll_options_size = sizeof($post_data['poll_options']);
351 $message_parser = new parse_message();
353 if (isset($post_data['post_text']))
355 $message_parser->message = &$post_data['post_text'];
356 unset($post_data['post_text']);
359 // Set some default variables
360 $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);
362 foreach ($uninit as $var_name => $default_value)
364 if (!isset($post_data[$var_name]))
366 $post_data[$var_name] = $default_value;
369 unset($uninit);
371 // Always check if the submitted attachment data is valid and belongs to the user.
372 // Further down (especially in submit_post()) we do not check this again.
373 $message_parser->get_submitted_attachment_data($post_data['poster_id']);
375 if ($post_data['post_attachment'] && !$submit && !$refresh && !$preview && $mode == 'edit')
377 // Do not change to SELECT *
378 $sql = 'SELECT attach_id, is_orphan, attach_comment, real_filename
379 FROM ' . ATTACHMENTS_TABLE . "
380 WHERE post_msg_id = $post_id
381 AND in_message = 0
382 AND is_orphan = 0
383 ORDER BY filetime DESC";
384 $result = $db->sql_query($sql);
385 $message_parser->attachment_data = array_merge($message_parser->attachment_data, $db->sql_fetchrowset($result));
386 $db->sql_freeresult($result);
389 if ($post_data['poster_id'] == ANONYMOUS)
391 $post_data['username'] = ($mode == 'quote' || $mode == 'edit') ? trim($post_data['post_username']) : '';
393 else
395 $post_data['username'] = ($mode == 'quote' || $mode == 'edit') ? trim($post_data['username']) : '';
398 $post_data['enable_urls'] = $post_data['enable_magic_url'];
400 if ($mode != 'edit')
402 $post_data['enable_sig'] = ($config['allow_sig'] && $user->optionget('attachsig')) ? true: false;
403 $post_data['enable_smilies'] = ($config['allow_smilies'] && $user->optionget('smilies')) ? true : false;
404 $post_data['enable_bbcode'] = ($config['allow_bbcode'] && $user->optionget('bbcode')) ? true : false;
405 $post_data['enable_urls'] = true;
408 $post_data['enable_magic_url'] = $post_data['drafts'] = false;
410 // User own some drafts?
411 if ($user->data['is_registered'] && $auth->acl_get('u_savedrafts') && ($mode == 'reply' || $mode == 'post' || $mode == 'quote'))
413 $sql = 'SELECT draft_id
414 FROM ' . DRAFTS_TABLE . '
415 WHERE user_id = ' . $user->data['user_id'] .
416 (($forum_id) ? ' AND forum_id = ' . (int) $forum_id : '') .
417 (($topic_id) ? ' AND topic_id = ' . (int) $topic_id : '') .
418 (($draft_id) ? " AND draft_id <> $draft_id" : '');
419 $result = $db->sql_query_limit($sql, 1);
421 if ($db->sql_fetchrow($result))
423 $post_data['drafts'] = true;
425 $db->sql_freeresult($result);
428 $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);
430 // Check if user is watching this topic
431 if ($mode != 'post' && $config['allow_topic_notify'] && $user->data['is_registered'])
433 $sql = 'SELECT topic_id
434 FROM ' . TOPICS_WATCH_TABLE . '
435 WHERE topic_id = ' . $topic_id . '
436 AND user_id = ' . $user->data['user_id'];
437 $result = $db->sql_query($sql);
438 $post_data['notify_set'] = (int) $db->sql_fetchfield('topic_id');
439 $db->sql_freeresult($result);
442 // Do we want to edit our post ?
443 if ($mode == 'edit' && $post_data['bbcode_uid'])
445 $message_parser->bbcode_uid = $post_data['bbcode_uid'];
448 // HTML, BBCode, Smilies, Images and Flash status
449 $bbcode_status = ($config['allow_bbcode'] && $auth->acl_get('f_bbcode', $forum_id)) ? true : false;
450 $smilies_status = ($bbcode_status && $config['allow_smilies'] && $auth->acl_get('f_smilies', $forum_id)) ? true : false;
451 $img_status = ($bbcode_status && $auth->acl_get('f_img', $forum_id)) ? true : false;
452 $url_status = ($config['allow_post_links']) ? true : false;
453 $flash_status = ($bbcode_status && $auth->acl_get('f_flash', $forum_id)) ? true : false;
454 $quote_status = ($auth->acl_get('f_reply', $forum_id)) ? true : false;
456 // Save Draft
457 if ($save && $user->data['is_registered'] && $auth->acl_get('u_savedrafts') && ($mode == 'reply' || $mode == 'post' || $mode == 'quote'))
459 $subject = utf8_normalize_nfc(request_var('subject', '', true));
460 $subject = (!$subject && $mode != 'post') ? $post_data['topic_title'] : $subject;
461 $message = utf8_normalize_nfc(request_var('message', '', true));
463 if ($subject && $message)
465 if (confirm_box(true))
467 $sql = 'INSERT INTO ' . DRAFTS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
468 'user_id' => $user->data['user_id'],
469 'topic_id' => $topic_id,
470 'forum_id' => $forum_id,
471 'save_time' => $current_time,
472 'draft_subject' => $subject,
473 'draft_message' => $message)
475 $db->sql_query($sql);
477 $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");
479 meta_refresh(3, $meta_info);
481 $message = $user->lang['DRAFT_SAVED'] . '<br /><br />';
482 $message .= ($mode != 'post') ? sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $meta_info . '">', '</a>') . '<br /><br />' : '';
483 $message .= sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
485 trigger_error($message);
487 else
489 $s_hidden_fields = build_hidden_fields(array(
490 'mode' => $mode,
491 'save' => true,
492 'f' => $forum_id,
493 't' => $topic_id,
494 'subject' => $subject,
495 'message' => $message,
499 confirm_box(false, 'SAVE_DRAFT', $s_hidden_fields);
502 else
504 if (!$subject)
506 $error[] = $user->lang['EMPTY_SUBJECT'];
509 if (!$message)
511 $error[] = $user->lang['TOO_FEW_CHARS'];
515 unset($subject, $message);
518 // Load requested Draft
519 if ($draft_id && ($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $user->data['is_registered'] && $auth->acl_get('u_savedrafts'))
521 $sql = 'SELECT draft_subject, draft_message
522 FROM ' . DRAFTS_TABLE . "
523 WHERE draft_id = $draft_id
524 AND user_id = " . $user->data['user_id'];
525 $result = $db->sql_query_limit($sql, 1);
526 $row = $db->sql_fetchrow($result);
527 $db->sql_freeresult($result);
529 if ($row)
531 $post_data['post_subject'] = $row['draft_subject'];
532 $message_parser->message = $row['draft_message'];
534 $template->assign_var('S_DRAFT_LOADED', true);
536 else
538 $draft_id = 0;
542 // Load draft overview
543 if ($load && ($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $post_data['drafts'])
545 load_drafts($topic_id, $forum_id);
548 $solved_captcha = false;
550 if ($submit || $preview || $refresh)
552 $post_data['topic_cur_post_id'] = request_var('topic_cur_post_id', 0);
553 $post_data['post_subject'] = trim(utf8_normalize_nfc(request_var('subject', '', true)));
554 $message_parser->message = utf8_normalize_nfc(request_var('message', '', true));
556 $post_data['username'] = utf8_normalize_nfc(request_var('username', $post_data['username'], true));
557 $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)) : '';
559 $post_data['orig_topic_type'] = $post_data['topic_type'];
560 $post_data['topic_type'] = request_var('topic_type', (($mode != 'post') ? (int) $post_data['topic_type'] : POST_NORMAL));
561 $post_data['topic_time_limit'] = request_var('topic_time_limit', (($mode != 'post') ? (int) $post_data['topic_time_limit'] : 0));
562 $post_data['icon_id'] = request_var('icon', 0);
564 $post_data['enable_bbcode'] = (!$bbcode_status || isset($_POST['disable_bbcode'])) ? false : true;
565 $post_data['enable_smilies'] = (!$smilies_status || isset($_POST['disable_smilies'])) ? false : true;
566 $post_data['enable_urls'] = (isset($_POST['disable_magic_url'])) ? 0 : 1;
567 $post_data['enable_sig'] = (!$config['allow_sig']) ? false : ((isset($_POST['attach_sig']) && $user->data['is_registered']) ? true : false);
569 if ($config['allow_topic_notify'] && $user->data['is_registered'])
571 $notify = (isset($_POST['notify'])) ? true : false;
573 else
575 $notify = false;
578 $topic_lock = (isset($_POST['lock_topic'])) ? true : false;
579 $post_lock = (isset($_POST['lock_post'])) ? true : false;
580 $poll_delete = (isset($_POST['poll_delete'])) ? true : false;
582 if ($submit)
584 $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);
585 $status_switch = ($status_switch != $check_value);
587 else
589 $status_switch = 1;
592 // Delete Poll
593 if ($poll_delete && $mode == 'edit' && sizeof($post_data['poll_options']) &&
594 ((!$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)))
596 if ($submit)
598 $sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . "
599 WHERE topic_id = $topic_id";
600 $db->sql_query($sql);
602 $sql = 'DELETE FROM ' . POLL_VOTES_TABLE . "
603 WHERE topic_id = $topic_id";
604 $db->sql_query($sql);
606 $topic_sql = array(
607 'poll_title' => '',
608 'poll_start' => 0,
609 'poll_length' => 0,
610 'poll_last_vote' => 0,
611 'poll_max_options' => 0,
612 'poll_vote_change' => 0
615 $sql = 'UPDATE ' . TOPICS_TABLE . '
616 SET ' . $db->sql_build_array('UPDATE', $topic_sql) . "
617 WHERE topic_id = $topic_id";
618 $db->sql_query($sql);
621 $post_data['poll_title'] = $post_data['poll_option_text'] = '';
622 $post_data['poll_vote_change'] = $post_data['poll_max_options'] = $post_data['poll_length'] = 0;
624 else
626 $post_data['poll_title'] = utf8_normalize_nfc(request_var('poll_title', '', true));
627 $post_data['poll_length'] = request_var('poll_length', 0);
628 $post_data['poll_option_text'] = utf8_normalize_nfc(request_var('poll_option_text', '', true));
629 $post_data['poll_max_options'] = request_var('poll_max_options', 1);
630 $post_data['poll_vote_change'] = ($auth->acl_get('f_votechg', $forum_id) && isset($_POST['poll_vote_change'])) ? 1 : 0;
633 // If replying/quoting and last post id has changed
634 // give user option to continue submit or return to post
635 // notify and show user the post made between his request and the final submit
636 if (($mode == 'reply' || $mode == 'quote') && $post_data['topic_cur_post_id'] && $post_data['topic_cur_post_id'] != $post_data['topic_last_post_id'])
638 // Only do so if it is allowed forum-wide
639 if ($post_data['forum_flags'] & FORUM_FLAG_POST_REVIEW)
641 if (topic_review($topic_id, $forum_id, 'post_review', $post_data['topic_cur_post_id']))
643 $template->assign_var('S_POST_REVIEW', true);
646 $submit = false;
647 $refresh = true;
651 // Parse Attachments - before checksum is calculated
652 $message_parser->parse_attachments('fileupload', $mode, $forum_id, $submit, $preview, $refresh);
654 // Grab md5 'checksum' of new message
655 $message_md5 = md5($message_parser->message);
657 // Check checksum ... don't re-parse message if the same
658 $update_message = ($mode != 'edit' || $message_md5 != $post_data['post_checksum'] || $status_switch) ? true : false;
660 // Parse message
661 if ($update_message)
663 if (sizeof($message_parser->warn_msg))
665 $error[] = implode('<br />', $message_parser->warn_msg);
666 $message_parser->warn_msg = array();
669 $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']);
671 // On a refresh we do not care about message parsing errors
672 if (sizeof($message_parser->warn_msg) && $refresh)
674 $message_parser->warn_msg = array();
677 else
679 $message_parser->bbcode_bitfield = $post_data['bbcode_bitfield'];
682 if ($mode != 'edit' && !$preview && !$refresh && $config['flood_interval'] && !$auth->acl_get('f_ignoreflood', $forum_id))
684 // Flood check
685 $last_post_time = 0;
687 if ($user->data['is_registered'])
689 $last_post_time = $user->data['user_lastpost_time'];
691 else
693 $sql = 'SELECT post_time AS last_post_time
694 FROM ' . POSTS_TABLE . "
695 WHERE poster_ip = '" . $user->ip . "'
696 AND post_time > " . ($current_time - $config['flood_interval']);
697 $result = $db->sql_query_limit($sql, 1);
698 if ($row = $db->sql_fetchrow($result))
700 $last_post_time = $row['last_post_time'];
702 $db->sql_freeresult($result);
705 if ($last_post_time && ($current_time - $last_post_time) < intval($config['flood_interval']))
707 $error[] = $user->lang['FLOOD_ERROR'];
711 // Validate username
712 if (($post_data['username'] && !$user->data['is_registered']) || ($mode == 'edit' && $post_data['username'] && $post_data['post_username'] && $post_data['post_username'] != $post_data['username']))
714 include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
716 if (($result = validate_username($post_data['username'], (!empty($post_data['post_username'])) ? $post_data['post_username'] : '')) !== false)
718 $user->add_lang('ucp');
719 $error[] = $user->lang[$result . '_USERNAME'];
723 if ($config['enable_post_confirm'] && !$user->data['is_registered'] && in_array($mode, array('quote', 'post', 'reply')))
725 $confirm_id = request_var('confirm_id', '');
726 $confirm_code = request_var('confirm_code', '');
728 $sql = 'SELECT code
729 FROM ' . CONFIRM_TABLE . "
730 WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "'
731 AND session_id = '" . $db->sql_escape($user->session_id) . "'
732 AND confirm_type = " . CONFIRM_POST;
733 $result = $db->sql_query($sql);
734 $confirm_row = $db->sql_fetchrow($result);
735 $db->sql_freeresult($result);
737 if (empty($confirm_row['code']) || strcasecmp($confirm_row['code'], $confirm_code) !== 0)
739 $error[] = $user->lang['CONFIRM_CODE_WRONG'];
741 else
743 $solved_captcha = true;
747 // Parse subject
748 if (!$preview && !$refresh && !$post_data['post_subject'] && ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_id)))
750 $error[] = $user->lang['EMPTY_SUBJECT'];
753 $post_data['poll_last_vote'] = (isset($post_data['poll_last_vote'])) ? $post_data['poll_last_vote'] : 0;
755 if ($post_data['poll_option_text'] &&
756 ($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id'] && (!$post_data['poll_last_vote'] || $auth->acl_get('m_edit', $forum_id))))
757 && $auth->acl_get('f_poll', $forum_id))
759 $poll = array(
760 'poll_title' => $post_data['poll_title'],
761 'poll_length' => $post_data['poll_length'],
762 'poll_max_options' => $post_data['poll_max_options'],
763 'poll_option_text' => $post_data['poll_option_text'],
764 'poll_start' => $post_data['poll_start'],
765 'poll_last_vote' => $post_data['poll_last_vote'],
766 'poll_vote_change' => $post_data['poll_vote_change'],
767 'enable_bbcode' => $post_data['enable_bbcode'],
768 'enable_urls' => $post_data['enable_urls'],
769 'enable_smilies' => $post_data['enable_smilies'],
770 'img_status' => $img_status
773 $message_parser->parse_poll($poll);
775 $post_data['poll_options'] = (isset($poll['poll_options'])) ? $poll['poll_options'] : '';
776 $post_data['poll_title'] = (isset($poll['poll_title'])) ? $poll['poll_title'] : '';
778 /* We reset votes, therefore also allow removing options
779 if ($post_data['poll_last_vote'] && ($poll['poll_options_size'] < $orig_poll_options_size))
781 $message_parser->warn_msg[] = $user->lang['NO_DELETE_POLL_OPTIONS'];
784 else
786 $poll = array();
789 // Check topic type
790 if ($post_data['topic_type'] != POST_NORMAL && ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_id)))
792 switch ($post_data['topic_type'])
794 case POST_GLOBAL:
795 case POST_ANNOUNCE:
796 $auth_option = 'f_announce';
797 break;
799 case POST_STICKY:
800 $auth_option = 'f_sticky';
801 break;
803 default:
804 $auth_option = '';
805 break;
808 if (!$auth->acl_get($auth_option, $forum_id))
810 // There is a special case where a user edits his post whereby the topic type got changed by an admin/mod.
811 // Another case would be a mod not having sticky permissions for example but edit permissions.
812 if ($mode == 'edit')
814 // To prevent non-authed users messing around with the topic type we reset it to the original one.
815 $post_data['topic_type'] = $post_data['orig_topic_type'];
817 else
819 $error[] = $user->lang['CANNOT_POST_' . str_replace('F_', '', strtoupper($auth_option))];
824 if (sizeof($message_parser->warn_msg))
826 $error[] = implode('<br />', $message_parser->warn_msg);
829 // DNSBL check
830 if ($config['check_dnsbl'] && !$refresh)
832 if (($dnsbl = $user->check_dnsbl('post')) !== false)
834 $error[] = sprintf($user->lang['IP_BLACKLISTED'], $user->ip, $dnsbl[1]);
838 // Store message, sync counters
839 if (!sizeof($error) && $submit)
841 // Check if we want to de-globalize the topic... and ask for new forum
842 if ($post_data['topic_type'] != POST_GLOBAL)
844 $sql = 'SELECT topic_type, forum_id
845 FROM ' . TOPICS_TABLE . "
846 WHERE topic_id = $topic_id";
847 $result = $db->sql_query_limit($sql, 1);
848 $row = $db->sql_fetchrow($result);
849 $db->sql_freeresult($result);
851 if ($row && !$row['forum_id'] && $row['topic_type'] == POST_GLOBAL)
853 $to_forum_id = request_var('to_forum_id', 0);
855 if (!$to_forum_id)
857 include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
859 $template->assign_vars(array(
860 'S_FORUM_SELECT' => make_forum_select(false, false, false, true, true, true),
861 'S_UNGLOBALISE' => true)
864 $submit = false;
865 $refresh = true;
867 else
869 if (!$auth->acl_get('f_post', $to_forum_id))
871 // This will only be triggered if the user tried to trick the forum.
872 trigger_error('NOT_AUTHORISED');
875 $forum_id = $to_forum_id;
880 if ($submit)
882 // Lock/Unlock Topic
883 $change_topic_status = $post_data['topic_status'];
884 $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;
886 if ($post_data['topic_status'] == ITEM_LOCKED && !$topic_lock && $perm_lock_unlock)
888 $change_topic_status = ITEM_UNLOCKED;
890 else if ($post_data['topic_status'] == ITEM_UNLOCKED && $topic_lock && $perm_lock_unlock)
892 $change_topic_status = ITEM_LOCKED;
895 if ($change_topic_status != $post_data['topic_status'])
897 $sql = 'UPDATE ' . TOPICS_TABLE . "
898 SET topic_status = $change_topic_status
899 WHERE topic_id = $topic_id
900 AND topic_moved_id = 0";
901 $db->sql_query($sql);
903 $user_lock = ($auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && $user->data['user_id'] == $post_data['topic_poster']) ? 'USER_' : '';
905 add_log('mod', $forum_id, $topic_id, 'LOG_' . $user_lock . (($change_topic_status == ITEM_LOCKED) ? 'LOCK' : 'UNLOCK'), $post_data['topic_title']);
908 // Lock/Unlock Post Edit
909 if ($mode == 'edit' && $post_data['post_edit_locked'] == ITEM_LOCKED && !$post_lock && $auth->acl_get('m_edit', $forum_id))
911 $post_data['post_edit_locked'] = ITEM_UNLOCKED;
913 else if ($mode == 'edit' && $post_data['post_edit_locked'] == ITEM_UNLOCKED && $post_lock && $auth->acl_get('m_edit', $forum_id))
915 $post_data['post_edit_locked'] = ITEM_LOCKED;
918 $data = array(
919 'topic_title' => (empty($post_data['topic_title'])) ? $post_data['post_subject'] : $post_data['topic_title'],
920 'topic_first_post_id' => (isset($post_data['topic_first_post_id'])) ? (int) $post_data['topic_first_post_id'] : 0,
921 'topic_last_post_id' => (isset($post_data['topic_last_post_id'])) ? (int) $post_data['topic_last_post_id'] : 0,
922 'topic_time_limit' => (int) $post_data['topic_time_limit'],
923 'topic_attachment' => (isset($post_data['topic_attachment'])) ? (int) $post_data['topic_attachment'] : 0,
924 'post_id' => (int) $post_id,
925 'topic_id' => (int) $topic_id,
926 'forum_id' => (int) $forum_id,
927 'icon_id' => (int) $post_data['icon_id'],
928 'poster_id' => (int) $post_data['poster_id'],
929 'enable_sig' => (bool) $post_data['enable_sig'],
930 'enable_bbcode' => (bool) $post_data['enable_bbcode'],
931 'enable_smilies' => (bool) $post_data['enable_smilies'],
932 'enable_urls' => (bool) $post_data['enable_urls'],
933 'enable_indexing' => (bool) $post_data['enable_indexing'],
934 'message_md5' => (string) $message_md5,
935 'post_time' => (isset($post_data['post_time'])) ? (int) $post_data['post_time'] : $current_time,
936 'post_checksum' => (isset($post_data['post_checksum'])) ? (string) $post_data['post_checksum'] : '',
937 'post_edit_reason' => $post_data['post_edit_reason'],
938 'post_edit_user' => ($mode == 'edit') ? $user->data['user_id'] : ((isset($post_data['post_edit_user'])) ? (int) $post_data['post_edit_user'] : 0),
939 'forum_parents' => $post_data['forum_parents'],
940 'forum_name' => $post_data['forum_name'],
941 'notify' => $notify,
942 'notify_set' => $post_data['notify_set'],
943 'poster_ip' => (isset($post_data['poster_ip'])) ? $post_data['poster_ip'] : $user->ip,
944 'post_edit_locked' => (int) $post_data['post_edit_locked'],
945 'bbcode_bitfield' => $message_parser->bbcode_bitfield,
946 'bbcode_uid' => $message_parser->bbcode_uid,
947 'message' => $message_parser->message,
948 'attachment_data' => $message_parser->attachment_data,
949 'filename_data' => $message_parser->filename_data,
951 'topic_approved' => (isset($post_data['topic_approved'])) ? $post_data['topic_approved'] : false,
952 'post_approved' => (isset($post_data['post_approved'])) ? $post_data['post_approved'] : false,
955 if ($mode == 'edit')
957 $data['topic_replies_real'] = $post_data['topic_replies_real'];
960 unset($message_parser);
962 $redirect_url = submit_post($mode, $post_data['post_subject'], $post_data['username'], $post_data['topic_type'], $poll, $data, $update_message);
964 meta_refresh(3, $redirect_url);
966 $message = (!$auth->acl_get('f_noapprove', $data['forum_id']) && !$auth->acl_get('m_approve', $data['forum_id'])) ? (($mode == 'edit') ? 'POST_EDITED_MOD' : 'POST_STORED_MOD') : (($mode == 'edit') ? 'POST_EDITED' : 'POST_STORED');
967 $message = $user->lang[$message] . (($auth->acl_get('f_noapprove', $data['forum_id']) || $auth->acl_get('m_approve', $data['forum_id'])) ? '<br /><br />' . sprintf($user->lang['VIEW_MESSAGE'], '<a href="' . $redirect_url . '">', '</a>') : '');
968 $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $data['forum_id']) . '">', '</a>');
969 trigger_error($message);
974 // Preview
975 if (!sizeof($error) && $preview)
977 $post_data['post_time'] = ($mode == 'edit') ? $post_data['post_time'] : $current_time;
979 $preview_message = $message_parser->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies'], false);
981 $preview_signature = ($mode == 'edit') ? $post_data['user_sig'] : $user->data['user_sig'];
982 $preview_signature_uid = ($mode == 'edit') ? $post_data['user_sig_bbcode_uid'] : $user->data['user_sig_bbcode_uid'];
983 $preview_signature_bitfield = ($mode == 'edit') ? $post_data['user_sig_bbcode_bitfield'] : $user->data['user_sig_bbcode_bitfield'];
985 // Signature
986 if ($post_data['enable_sig'] && $config['allow_sig'] && $preview_signature && $auth->acl_get('f_sigs', $forum_id))
988 $parse_sig = new parse_message($preview_signature);
989 $parse_sig->bbcode_uid = $preview_signature_uid;
990 $parse_sig->bbcode_bitfield = $preview_signature_bitfield;
992 // Not sure about parameters for bbcode/smilies/urls... in signatures
993 $parse_sig->format_display($config['allow_sig_bbcode'], true, $config['allow_sig_smilies']);
994 $preview_signature = $parse_sig->message;
995 unset($parse_sig);
997 else
999 $preview_signature = '';
1002 $preview_subject = censor_text($post_data['post_subject']);
1004 // Poll Preview
1005 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))))
1006 && $auth->acl_get('f_poll', $forum_id))
1008 $parse_poll = new parse_message($post_data['poll_title']);
1009 $parse_poll->bbcode_uid = $message_parser->bbcode_uid;
1010 $parse_poll->bbcode_bitfield = $message_parser->bbcode_bitfield;
1012 $parse_poll->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies']);
1014 $template->assign_vars(array(
1015 'S_HAS_POLL_OPTIONS' => (sizeof($post_data['poll_options'])),
1016 'S_IS_MULTI_CHOICE' => ($post_data['poll_max_options'] > 1) ? true : false,
1018 'POLL_QUESTION' => $parse_poll->message,
1020 'L_POLL_LENGTH' => ($post_data['poll_length']) ? sprintf($user->lang['POLL_RUN_TILL'], $user->format_date($post_data['poll_length'] + $post_data['poll_start'])) : '',
1021 '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']))
1024 $parse_poll->message = implode("\n", $post_data['poll_options']);
1025 $parse_poll->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies']);
1026 $preview_poll_options = explode('<br />', $parse_poll->message);
1027 unset($parse_poll);
1029 foreach ($preview_poll_options as $option)
1031 $template->assign_block_vars('poll_option', array(
1032 'POLL_OPTION_CAPTION' => $option)
1035 unset($preview_poll_options);
1038 // Attachment Preview
1039 if (sizeof($message_parser->attachment_data))
1041 $template->assign_var('S_HAS_ATTACHMENTS', true);
1043 $update_count = array();
1044 $attachment_data = $message_parser->attachment_data;
1046 parse_attachments($forum_id, $preview_message, $attachment_data, $update_count, true);
1048 foreach ($attachment_data as $i => $attachment)
1050 $template->assign_block_vars('attachment', array(
1051 'DISPLAY_ATTACHMENT' => $attachment)
1054 unset($attachment_data);
1057 if (!sizeof($error))
1059 $template->assign_vars(array(
1060 'PREVIEW_SUBJECT' => $preview_subject,
1061 'PREVIEW_MESSAGE' => $preview_message,
1062 'PREVIEW_SIGNATURE' => $preview_signature,
1064 'S_DISPLAY_PREVIEW' => true)
1069 // Decode text for message display
1070 $post_data['bbcode_uid'] = ($mode == 'quote' && !$preview && !$refresh && !sizeof($error)) ? $post_data['bbcode_uid'] : $message_parser->bbcode_uid;
1071 $message_parser->decode_message($post_data['bbcode_uid']);
1073 if ($mode == 'quote' && !$submit && !$preview && !$refresh)
1075 $message_parser->message = '[quote="' . $post_data['quote_username'] . '"]' . censor_text(trim($message_parser->message)) . "[/quote]\n";
1078 if (($mode == 'reply' || $mode == 'quote') && !$submit && !$preview && !$refresh)
1080 $post_data['post_subject'] = ((strpos($post_data['post_subject'], 'Re: ') !== 0) ? 'Re: ' : '') . censor_text($post_data['post_subject']);
1083 $attachment_data = $message_parser->attachment_data;
1084 $filename_data = $message_parser->filename_data;
1085 $post_data['post_text'] = $message_parser->message;
1087 if (sizeof($post_data['poll_options']) && $post_data['poll_title'])
1089 $message_parser->message = $post_data['poll_title'];
1090 $message_parser->bbcode_uid = $post_data['bbcode_uid'];
1092 $message_parser->decode_message();
1093 $post_data['poll_title'] = $message_parser->message;
1095 $message_parser->message = implode("\n", $post_data['poll_options']);
1096 $message_parser->decode_message();
1097 $post_data['poll_options'] = explode("\n", $message_parser->message);
1099 unset($message_parser);
1101 // MAIN POSTING PAGE BEGINS HERE
1103 // Forum moderators?
1104 $moderators = array();
1105 get_moderators($moderators, $forum_id);
1107 // Generate smiley listing
1108 generate_smilies('inline', $forum_id);
1110 // Generate inline attachment select box
1111 posting_gen_inline_attachments($attachment_data);
1113 // Do show topic type selection only in first post.
1114 $topic_type_toggle = false;
1116 if ($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id']))
1118 $topic_type_toggle = posting_gen_topic_types($forum_id, $post_data['topic_type']);
1121 $s_topic_icons = false;
1122 if ($post_data['enable_icons'] && $auth->acl_get('f_icons', $forum_id))
1124 $s_topic_icons = posting_gen_topic_icons($mode, $post_data['icon_id']);
1127 $bbcode_checked = (isset($post_data['enable_bbcode'])) ? !$post_data['enable_bbcode'] : (($config['allow_bbcode']) ? !$user->optionget('bbcode') : 1);
1128 $smilies_checked = (isset($post_data['enable_smilies'])) ? !$post_data['enable_smilies'] : (($config['allow_smilies']) ? !$user->optionget('smilies') : 1);
1129 $urls_checked = (isset($post_data['enable_urls'])) ? !$post_data['enable_urls'] : 0;
1130 $sig_checked = $post_data['enable_sig'];
1131 $lock_topic_checked = (isset($topic_lock)) ? $topic_lock : (($post_data['topic_status'] == ITEM_LOCKED) ? 1 : 0);
1132 $lock_post_checked = (isset($post_lock)) ? $post_lock : $post_data['post_edit_locked'];
1134 // 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
1135 $notify_set = ($mode != 'edit' && $config['allow_topic_notify'] && $user->data['is_registered'] && !$post_data['notify_set']) ? $user->data['user_notify'] : $post_data['notify_set'];
1136 $notify_checked = (isset($notify)) ? $notify : (($mode == 'post') ? $user->data['user_notify'] : $notify_set);
1138 // Page title & action URL, include session_id for security purpose
1139 $s_action = append_sid("{$phpbb_root_path}posting.$phpEx", "mode=$mode&amp;f=$forum_id", true, $user->session_id);
1140 $s_action .= ($topic_id) ? "&amp;t=$topic_id" : '';
1141 $s_action .= ($post_id) ? "&amp;p=$post_id" : '';
1143 switch ($mode)
1145 case 'post':
1146 $page_title = $user->lang['POST_TOPIC'];
1147 break;
1149 case 'quote':
1150 case 'reply':
1151 $page_title = $user->lang['POST_REPLY'];
1152 break;
1154 case 'delete':
1155 case 'edit':
1156 $page_title = $user->lang['EDIT_POST'];
1157 break;
1160 // Build Navigation Links
1161 generate_forum_nav($post_data);
1163 // Build Forum Rules
1164 generate_forum_rules($post_data);
1166 if ($config['enable_post_confirm'] && !$user->data['is_registered'] && $solved_captcha === false && ($mode == 'post' || $mode == 'reply' || $mode == 'quote'))
1168 // Show confirm image
1169 $sql = 'DELETE FROM ' . CONFIRM_TABLE . "
1170 WHERE session_id = '" . $db->sql_escape($user->session_id) . "'
1171 AND confirm_type = " . CONFIRM_POST;
1172 $db->sql_query($sql);
1174 // Generate code
1175 $code = gen_rand_string(mt_rand(5, 8));
1176 $confirm_id = md5(unique_id($user->ip));
1177 $seed = hexdec(substr(unique_id(), 4, 10));
1179 // compute $seed % 0x7fffffff
1180 $seed -= 0x7fffffff * floor($seed / 0x7fffffff);
1182 $sql = 'INSERT INTO ' . CONFIRM_TABLE . ' ' . $db->sql_build_array('INSERT', array(
1183 'confirm_id' => (string) $confirm_id,
1184 'session_id' => (string) $user->session_id,
1185 'confirm_type' => (int) CONFIRM_POST,
1186 'code' => (string) $code,
1187 'seed' => (int) $seed)
1189 $db->sql_query($sql);
1191 $template->assign_vars(array(
1192 'S_CONFIRM_CODE' => true,
1193 'CONFIRM_ID' => $confirm_id,
1194 'CONFIRM_IMAGE' => '<img src="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=confirm&amp;id=' . $confirm_id . '&amp;type=' . CONFIRM_POST) . '" alt="" title="" />',
1195 'L_POST_CONFIRM_EXPLAIN' => sprintf($user->lang['POST_CONFIRM_EXPLAIN'], '<a href="mailto:' . htmlspecialchars($config['board_contact']) . '">', '</a>'),
1199 $s_hidden_fields = ($mode == 'reply' || $mode == 'quote') ? '<input type="hidden" name="topic_cur_post_id" value="' . $post_data['topic_last_post_id'] . '" />' : '';
1200 $s_hidden_fields .= '<input type="hidden" name="lastclick" value="' . $current_time . '" />';
1201 $s_hidden_fields .= ($draft_id || isset($_REQUEST['draft_loaded'])) ? '<input type="hidden" name="draft_loaded" value="' . request_var('draft_loaded', $draft_id) . '" />' : '';
1203 // Add the confirm id/code pair to the hidden fields, else an error is displayed on next submit/preview
1204 if ($solved_captcha !== false)
1206 $s_hidden_fields .= build_hidden_fields(array(
1207 'confirm_id' => request_var('confirm_id', ''),
1208 'confirm_code' => request_var('confirm_code', ''))
1212 $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"';
1214 // Start assigning vars for main posting page ...
1215 $template->assign_vars(array(
1216 'L_POST_A' => $page_title,
1217 'L_ICON' => ($mode == 'reply' || $mode == 'quote' || ($mode == 'edit' && $post_id != $post_data['topic_first_post_id'])) ? $user->lang['POST_ICON'] : $user->lang['TOPIC_ICON'],
1218 'L_MESSAGE_BODY_EXPLAIN' => (intval($config['max_post_chars'])) ? sprintf($user->lang['MESSAGE_BODY_EXPLAIN'], intval($config['max_post_chars'])) : '',
1220 'FORUM_NAME' => $post_data['forum_name'],
1221 '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']) : '',
1222 'TOPIC_TITLE' => censor_text($post_data['topic_title']),
1223 'MODERATORS' => (sizeof($moderators)) ? implode(', ', $moderators[$forum_id]) : '',
1224 'USERNAME' => ((!$preview && $mode != 'quote') || $preview) ? $post_data['username'] : '',
1225 'SUBJECT' => $post_data['post_subject'],
1226 'MESSAGE' => $post_data['post_text'],
1227 '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>'),
1228 'IMG_STATUS' => ($img_status) ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'],
1229 'FLASH_STATUS' => ($flash_status) ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'],
1230 'SMILIES_STATUS' => ($smilies_status) ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'],
1231 'URL_STATUS' => ($bbcode_status && $url_status) ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'],
1232 'MINI_POST_IMG' => $user->img('icon_post_target', $user->lang['POST']),
1233 'POST_DATE' => ($post_data['post_time']) ? $user->format_date($post_data['post_time']) : '',
1234 'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '',
1235 'TOPIC_TIME_LIMIT' => (int) $post_data['topic_time_limit'],
1236 'EDIT_REASON' => $post_data['post_edit_reason'],
1237 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id"),
1238 'U_VIEW_TOPIC' => ($mode != 'post') ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id") : '',
1239 'U_PROGRESS_BAR' => append_sid("{$phpbb_root_path}posting.$phpEx", "f=$forum_id&amp;mode=popup"),
1240 'UA_PROGRESS_BAR' => append_sid("{$phpbb_root_path}posting.$phpEx", "f=$forum_id&mode=popup", false),
1242 'S_PRIVMSGS' => false,
1243 'S_CLOSE_PROGRESS_WINDOW' => (isset($_POST['add_file'])) ? true : false,
1244 'S_EDIT_POST' => ($mode == 'edit') ? true : false,
1245 'S_EDIT_REASON' => ($mode == 'edit' && $auth->acl_get('m_edit', $forum_id)) ? true : false,
1246 'S_DISPLAY_USERNAME' => (!$user->data['is_registered'] || ($mode == 'edit' && $post_data['poster_id'] == ANONYMOUS)) ? true : false,
1247 'S_SHOW_TOPIC_ICONS' => $s_topic_icons,
1248 '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,
1249 'S_BBCODE_ALLOWED' => $bbcode_status,
1250 'S_BBCODE_CHECKED' => ($bbcode_checked) ? ' checked="checked"' : '',
1251 'S_SMILIES_ALLOWED' => $smilies_status,
1252 'S_SMILIES_CHECKED' => ($smilies_checked) ? ' checked="checked"' : '',
1253 'S_SIG_ALLOWED' => ($auth->acl_get('f_sigs', $forum_id) && $config['allow_sig'] && $user->data['is_registered']) ? true : false,
1254 'S_SIGNATURE_CHECKED' => ($sig_checked) ? ' checked="checked"' : '',
1255 'S_NOTIFY_ALLOWED' => (!$user->data['is_registered'] || ($mode == 'edit' && $user->data['user_id'] != $post_data['poster_id']) || !$config['allow_topic_notify']) ? false : true,
1256 'S_NOTIFY_CHECKED' => ($notify_checked) ? ' checked="checked"' : '',
1257 '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,
1258 'S_LOCK_TOPIC_CHECKED' => ($lock_topic_checked) ? ' checked="checked"' : '',
1259 'S_LOCK_POST_ALLOWED' => ($mode == 'edit' && $auth->acl_get('m_edit', $forum_id)) ? true : false,
1260 'S_LOCK_POST_CHECKED' => ($lock_post_checked) ? ' checked="checked"' : '',
1261 'S_LINKS_ALLOWED' => $url_status,
1262 'S_MAGIC_URL_CHECKED' => ($urls_checked) ? ' checked="checked"' : '',
1263 'S_TYPE_TOGGLE' => $topic_type_toggle,
1264 'S_SAVE_ALLOWED' => ($auth->acl_get('u_savedrafts') && $user->data['is_registered'] && $mode != 'edit') ? true : false,
1265 'S_HAS_DRAFTS' => ($auth->acl_get('u_savedrafts') && $user->data['is_registered'] && $post_data['drafts']) ? true : false,
1266 'S_FORM_ENCTYPE' => $form_enctype,
1268 'S_BBCODE_IMG' => $img_status,
1269 'S_BBCODE_URL' => $url_status,
1270 'S_BBCODE_FLASH' => $flash_status,
1271 'S_BBCODE_QUOTE' => $quote_status,
1273 'S_POST_ACTION' => $s_action,
1274 'S_HIDDEN_FIELDS' => $s_hidden_fields)
1277 // Build custom bbcodes array
1278 display_custom_bbcodes();
1280 // Poll entry
1281 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))))
1282 && $auth->acl_get('f_poll', $forum_id))
1284 $template->assign_vars(array(
1285 'S_SHOW_POLL_BOX' => true,
1286 'S_POLL_VOTE_CHANGE' => ($auth->acl_get('f_votechg', $forum_id)),
1287 '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))),
1288 'S_POLL_DELETE_CHECKED' => (!empty($poll_delete)) ? true : false,
1290 'L_POLL_OPTIONS_EXPLAIN' => sprintf($user->lang['POLL_OPTIONS_EXPLAIN'], $config['max_poll_options']),
1292 'VOTE_CHANGE_CHECKED' => (!empty($post_data['poll_vote_change'])) ? ' checked="checked"' : '',
1293 'POLL_TITLE' => (isset($post_data['poll_title'])) ? $post_data['poll_title'] : '',
1294 'POLL_OPTIONS' => (!empty($post_data['poll_options'])) ? implode("\n", $post_data['poll_options']) : '',
1295 'POLL_MAX_OPTIONS' => (isset($post_data['poll_max_options'])) ? (int) $post_data['poll_max_options'] : 1,
1296 'POLL_LENGTH' => $post_data['poll_length'])
1300 // Attachment entry
1301 // Not using acl_gets here, because it is using OR logic
1302 if ($auth->acl_get('f_attach', $forum_id) && $auth->acl_get('u_attach') && $config['allow_attachments'] && $form_enctype)
1304 posting_gen_attachment_entry($attachment_data, $filename_data);
1307 // Output page ...
1308 page_header($page_title);
1310 $template->set_filenames(array(
1311 'body' => 'posting_body.html')
1314 make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
1316 // Topic review
1317 if ($mode == 'reply' || $mode == 'quote')
1319 if (topic_review($topic_id, $forum_id))
1321 $template->assign_var('S_DISPLAY_REVIEW', true);
1325 page_footer();
1328 * Show upload popup (progress bar)
1330 function upload_popup($forum_style = 0)
1332 global $template, $user;
1334 ($forum_style) ? $user->setup('posting', $forum_style) : $user->setup('posting');
1336 page_header($user->lang['PROGRESS_BAR']);
1338 $template->set_filenames(array(
1339 'popup' => 'posting_progress_bar.html')
1342 $template->assign_vars(array(
1343 'PROGRESS_BAR' => $user->img('upload_bar', $user->lang['UPLOAD_IN_PROGRESS']))
1346 $template->display('popup');
1350 * Do the various checks required for removing posts as well as removing it
1352 function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data)
1354 global $user, $db, $auth;
1355 global $phpbb_root_path, $phpEx;
1357 // If moderator removing post or user itself removing post, present a confirmation screen
1358 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']))
1360 $s_hidden_fields = build_hidden_fields(array(
1361 'p' => $post_id,
1362 'f' => $forum_id,
1363 'mode' => 'delete')
1366 if (confirm_box(true))
1368 $data = array(
1369 'topic_first_post_id' => $post_data['topic_first_post_id'],
1370 'topic_last_post_id' => $post_data['topic_last_post_id'],
1371 'topic_approved' => $post_data['topic_approved'],
1372 'topic_type' => $post_data['topic_type'],
1373 'post_approved' => $post_data['post_approved'],
1374 'post_reported' => $post_data['post_reported'],
1375 'post_time' => $post_data['post_time'],
1376 'poster_id' => $post_data['poster_id'],
1377 'post_postcount' => $post_data['post_postcount']
1380 $next_post_id = delete_post($forum_id, $topic_id, $post_id, $data);
1382 if ($post_data['topic_first_post_id'] == $post_data['topic_last_post_id'])
1384 add_log('mod', $forum_id, $topic_id, 'LOG_DELETE_TOPIC', $post_data['topic_title']);
1386 $meta_info = append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id");
1387 $message = $user->lang['POST_DELETED'];
1389 else
1391 add_log('mod', $forum_id, $topic_id, 'LOG_DELETE_POST', $post_data['post_subject']);
1393 $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";
1394 $message = $user->lang['POST_DELETED'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $meta_info . '">', '</a>');
1397 meta_refresh(3, $meta_info);
1398 $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
1399 trigger_error($message);
1401 else
1403 confirm_box(false, 'DELETE_MESSAGE', $s_hidden_fields);
1407 // If we are here the user is not able to delete - present the correct error message
1408 if ($post_data['poster_id'] != $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id))
1410 trigger_error('DELETE_OWN_POSTS');
1413 if ($post_data['poster_id'] == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id) && $post_id != $post_data['topic_last_post_id'])
1415 trigger_error('CANNOT_DELETE_REPLIED');
1418 trigger_error('USER_CANNOT_DELETE');