2 /***************************************************************************
5 * begin : Saturday, Feb 13, 2001
6 * copyright : (C) 2001 The phpBB Group
7 * email : support@phpbb.com
9 * $Id: posting.php,v 1.159.2.30 2006/12/16 13:11:24 acydburn Exp $
12 ***************************************************************************/
14 /***************************************************************************
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 ***************************************************************************/
23 define('IN_PHPBB', true);
24 $phpbb_root_path = './';
25 include($phpbb_root_path . 'extension.inc');
26 include($phpbb_root_path . 'common.'.$phpEx);
27 include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
28 include($phpbb_root_path . 'includes/functions_post.'.$phpEx);
31 // Check and set various parameters
33 $params = array('submit' => 'post', 'preview' => 'preview', 'delete' => 'delete', 'poll_delete' => 'poll_delete', 'poll_add' => 'add_poll_option', 'poll_edit' => 'edit_poll_option', 'mode' => 'mode');
34 while( list($var, $param) = @each($params) )
36 if ( !empty($HTTP_POST_VARS[$param]) || !empty($HTTP_GET_VARS[$param]) )
38 $$var = ( !empty($HTTP_POST_VARS[$param]) ) ? htmlspecialchars($HTTP_POST_VARS[$param]) : htmlspecialchars($HTTP_GET_VARS[$param]);
46 $confirm = isset($HTTP_POST_VARS['confirm']) ? true : false;
47 $sid = (isset($HTTP_POST_VARS['sid'])) ? $HTTP_POST_VARS['sid'] : 0;
49 $params = array('forum_id' => POST_FORUM_URL, 'topic_id' => POST_TOPIC_URL, 'post_id' => POST_POST_URL);
50 while( list($var, $param) = @each($params) )
52 if ( !empty($HTTP_POST_VARS[$param]) || !empty($HTTP_GET_VARS[$param]) )
54 $$var = ( !empty($HTTP_POST_VARS[$param]) ) ? intval($HTTP_POST_VARS[$param]) : intval($HTTP_GET_VARS[$param]);
62 $refresh = $preview || $poll_add || $poll_edit || $poll_delete;
63 $orig_word = $replacement_word = array();
68 $topic_type = ( !empty($HTTP_POST_VARS['topictype']) ) ? intval($HTTP_POST_VARS['topictype']) : POST_NORMAL;
69 $topic_type = ( in_array($topic_type, array(POST_NORMAL, POST_STICKY, POST_ANNOUNCE)) ) ? $topic_type : POST_NORMAL;
72 // If the mode is set to topic review then output
75 if ( $mode == 'topicreview' )
77 require($phpbb_root_path . 'includes/topic_review.'.$phpEx);
79 topic_review($topic_id, false);
82 else if ( $mode == 'smilies' )
84 generate_smilies('window', PAGE_POSTING);
89 // Start session management
91 $userdata = session_pagestart($user_ip, PAGE_POSTING);
92 init_userprefs($userdata);
94 // End session management
98 // Was cancel pressed? If so then redirect to the appropriate
99 // page, no point in continuing with any further checks
101 if ( isset($HTTP_POST_VARS['cancel']) )
105 $redirect = "viewtopic.$phpEx?" . POST_POST_URL . "=$post_id";
106 $post_append = "#$post_id";
108 else if ( $topic_id )
110 $redirect = "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id";
113 else if ( $forum_id )
115 $redirect = "viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id";
120 $redirect = "index.$phpEx";
124 redirect(append_sid($redirect, true) . $post_append);
128 // What auth type do we need to check?
134 if ( $topic_type == POST_ANNOUNCE )
136 $is_auth_type = 'auth_announce';
138 else if ( $topic_type == POST_STICKY )
140 $is_auth_type = 'auth_sticky';
144 $is_auth_type = 'auth_post';
149 $is_auth_type = 'auth_reply';
152 $is_auth_type = 'auth_edit';
156 $is_auth_type = 'auth_delete';
159 $is_auth_type = 'auth_vote';
162 $is_auth_type = 'auth_read';
165 message_die(GENERAL_MESSAGE, $lang['No_post_mode']);
170 // Here we do various lookups to find topic_id, forum_id, post_id etc.
171 // Doing it here prevents spoofing (eg. faking forum_id, topic_id or post_id
174 $post_data = array();
178 if ( empty($forum_id) )
180 message_die(GENERAL_MESSAGE, $lang['Forum_not_exist']);
184 FROM " . FORUMS_TABLE . "
185 WHERE forum_id = $forum_id";
190 if ( empty( $topic_id) )
192 message_die(GENERAL_MESSAGE, $lang['No_topic_id']);
195 $sql = "SELECT f.*, t.topic_status, t.topic_title, t.topic_type
196 FROM " . FORUMS_TABLE . " f, " . TOPICS_TABLE . " t
197 WHERE t.topic_id = $topic_id
198 AND f.forum_id = t.forum_id";
205 if ( empty($post_id) )
207 message_die(GENERAL_MESSAGE, $lang['No_post_id']);
210 $select_sql = (!$submit) ? ', t.topic_title, p.enable_bbcode, p.enable_html, p.enable_smilies, p.enable_sig, p.post_username, pt.post_subject, pt.post_text, pt.bbcode_uid, u.username, u.user_id, u.user_sig, u.user_sig_bbcode_uid' : '';
211 $from_sql = ( !$submit ) ? ", " . POSTS_TEXT_TABLE . " pt, " . USERS_TABLE . " u" : '';
212 $where_sql = ( !$submit ) ? "AND pt.post_id = p.post_id AND u.user_id = p.poster_id" : '';
214 $sql = "SELECT f.*, t.topic_id, t.topic_status, t.topic_type, t.topic_first_post_id, t.topic_last_post_id, t.topic_vote, p.post_id, p.poster_id" . $select_sql . "
215 FROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f" . $from_sql . "
216 WHERE p.post_id = $post_id
217 AND t.topic_id = p.topic_id
218 AND f.forum_id = p.forum_id
223 message_die(GENERAL_MESSAGE, $lang['No_valid_mode']);
226 if ( ($result = $db->sql_query($sql)) && ($post_info = $db->sql_fetchrow($result)) )
228 $db->sql_freeresult($result);
230 $forum_id = $post_info['forum_id'];
231 $forum_name = $post_info['forum_name'];
233 $is_auth = auth(AUTH_ALL, $forum_id, $userdata, $post_info);
235 if ( $post_info['forum_status'] == FORUM_LOCKED && !$is_auth['auth_mod'])
237 message_die(GENERAL_MESSAGE, $lang['Forum_locked']);
239 else if ( $mode != 'newtopic' && $post_info['topic_status'] == TOPIC_LOCKED && !$is_auth['auth_mod'])
241 message_die(GENERAL_MESSAGE, $lang['Topic_locked']);
244 if ( $mode == 'editpost' || $mode == 'delete' || $mode == 'poll_delete' )
246 $topic_id = $post_info['topic_id'];
248 $post_data['poster_post'] = ( $post_info['poster_id'] == $userdata['user_id'] ) ? true : false;
249 $post_data['first_post'] = ( $post_info['topic_first_post_id'] == $post_id ) ? true : false;
250 $post_data['last_post'] = ( $post_info['topic_last_post_id'] == $post_id ) ? true : false;
251 $post_data['last_topic'] = ( $post_info['forum_last_post_id'] == $post_id ) ? true : false;
252 $post_data['has_poll'] = ( $post_info['topic_vote'] ) ? true : false;
253 $post_data['topic_type'] = $post_info['topic_type'];
254 $post_data['poster_id'] = $post_info['poster_id'];
256 if ( $post_data['first_post'] && $post_data['has_poll'] )
259 FROM " . VOTE_DESC_TABLE . " vd, " . VOTE_RESULTS_TABLE . " vr
260 WHERE vd.topic_id = $topic_id
261 AND vr.vote_id = vd.vote_id
262 ORDER BY vr.vote_option_id";
263 if ( !($result = $db->sql_query($sql)) )
265 message_die(GENERAL_ERROR, 'Could not obtain vote data for this topic', '', __LINE__, __FILE__, $sql);
268 $poll_options = array();
269 $poll_results_sum = 0;
270 if ( $row = $db->sql_fetchrow($result) )
272 $poll_title = $row['vote_text'];
273 $poll_id = $row['vote_id'];
274 $poll_length = $row['vote_length'] / 86400;
278 $poll_options[$row['vote_option_id']] = $row['vote_option_text'];
279 $poll_results_sum += $row['vote_result'];
281 while ( $row = $db->sql_fetchrow($result) );
283 $db->sql_freeresult($result);
285 $post_data['edit_poll'] = ( ( !$poll_results_sum || $is_auth['auth_mod'] ) && $post_data['first_post'] ) ? true : 0;
289 $post_data['edit_poll'] = ($post_data['first_post'] && $is_auth['auth_pollcreate']) ? true : false;
293 // Can this user edit/delete the post/poll?
295 if ( $post_info['poster_id'] != $userdata['user_id'] && !$is_auth['auth_mod'] )
297 $message = ( $delete || $mode == 'delete' ) ? $lang['Delete_own_posts'] : $lang['Edit_own_posts'];
298 $message .= '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id") . '">', '</a>');
300 message_die(GENERAL_MESSAGE, $message);
302 else if ( !$post_data['last_post'] && !$is_auth['auth_mod'] && ( $mode == 'delete' || $delete ) )
304 message_die(GENERAL_MESSAGE, $lang['Cannot_delete_replied']);
306 else if ( !$post_data['edit_poll'] && !$is_auth['auth_mod'] && ( $mode == 'poll_delete' || $poll_delete ) )
308 message_die(GENERAL_MESSAGE, $lang['Cannot_delete_poll']);
313 if ( $mode == 'quote' )
315 $topic_id = $post_info['topic_id'];
317 if ( $mode == 'newtopic' )
319 $post_data['topic_type'] = POST_NORMAL;
322 $post_data['first_post'] = ( $mode == 'newtopic' ) ? true : 0;
323 $post_data['last_post'] = false;
324 $post_data['has_poll'] = false;
325 $post_data['edit_poll'] = false;
327 if ( $mode == 'poll_delete' && !isset($poll_id) )
329 message_die(GENERAL_MESSAGE, $lang['No_such_post']);
334 message_die(GENERAL_MESSAGE, $lang['No_such_post']);
338 // The user is not authed, if they're not logged in then redirect
339 // them, else show them an error message
341 if ( !$is_auth[$is_auth_type] )
343 if ( $userdata['session_logged_in'] )
345 message_die(GENERAL_MESSAGE, sprintf($lang['Sorry_' . $is_auth_type], $is_auth[$is_auth_type . "_type"]));
351 $redirect = "mode=newtopic&" . POST_FORUM_URL . "=" . $forum_id;
355 $redirect = "mode=reply&" . POST_TOPIC_URL . "=" . $topic_id;
359 $redirect = "mode=quote&" . POST_POST_URL ."=" . $post_id;
363 redirect(append_sid("login.$phpEx?redirect=posting.$phpEx&" . $redirect, true));
367 // Set toggles for various options
369 if ( !$board_config['allow_html'] )
375 $html_on = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['disable_html']) ) ? 0 : TRUE ) : ( ( $userdata['user_id'] == ANONYMOUS ) ? $board_config['allow_html'] : $userdata['user_allowhtml'] );
378 if ( !$board_config['allow_bbcode'] )
384 $bbcode_on = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['disable_bbcode']) ) ? 0 : TRUE ) : ( ( $userdata['user_id'] == ANONYMOUS ) ? $board_config['allow_bbcode'] : $userdata['user_allowbbcode'] );
387 if ( !$board_config['allow_smilies'] )
393 $smilies_on = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['disable_smilies']) ) ? 0 : TRUE ) : ( ( $userdata['user_id'] == ANONYMOUS ) ? $board_config['allow_smilies'] : $userdata['user_allowsmile'] );
396 if ( ($submit || $refresh) && $is_auth['auth_read'])
398 $notify_user = ( !empty($HTTP_POST_VARS['notify']) ) ? TRUE : 0;
402 if ( $mode != 'newtopic' && $userdata['session_logged_in'] && $is_auth['auth_read'] )
404 $sql = "SELECT topic_id
405 FROM " . TOPICS_WATCH_TABLE . "
406 WHERE topic_id = $topic_id
407 AND user_id = " . $userdata['user_id'];
408 if ( !($result = $db->sql_query($sql)) )
410 message_die(GENERAL_ERROR, 'Could not obtain topic watch information', '', __LINE__, __FILE__, $sql);
413 $notify_user = ( $db->sql_fetchrow($result) ) ? TRUE : $userdata['user_notify'];
414 $db->sql_freeresult($result);
418 $notify_user = ( $userdata['session_logged_in'] && $is_auth['auth_read'] ) ? $userdata['user_notify'] : 0;
422 $attach_sig = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['attach_sig']) ) ? TRUE : 0 ) : ( ( $userdata['user_id'] == ANONYMOUS ) ? 0 : $userdata['user_attachsig'] );
424 // --------------------
427 if ( ( $delete || $poll_delete || $mode == 'delete' ) && !$confirm )
432 $s_hidden_fields = '<input type="hidden" name="' . POST_POST_URL . '" value="' . $post_id . '" />';
433 $s_hidden_fields .= ( $delete || $mode == "delete" ) ? '<input type="hidden" name="mode" value="delete" />' : '<input type="hidden" name="mode" value="poll_delete" />';
434 $s_hidden_fields .= '<input type="hidden" name="sid" value="' . $userdata['session_id'] . '" />';
436 $l_confirm = ( $delete || $mode == 'delete' ) ? $lang['Confirm_delete'] : $lang['Confirm_delete_poll'];
439 // Output confirmation page
441 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
443 $template->set_filenames(array(
444 'confirm_body' => 'confirm_body.tpl')
447 $template->assign_vars(array(
448 'MESSAGE_TITLE' => $lang['Information'],
449 'MESSAGE_TEXT' => $l_confirm,
451 'L_YES' => $lang['Yes'],
452 'L_NO' => $lang['No'],
454 'S_CONFIRM_ACTION' => append_sid("posting.$phpEx"),
455 'S_HIDDEN_FIELDS' => $s_hidden_fields)
458 $template->pparse('confirm_body');
460 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
462 else if ( $mode == 'vote' )
467 if ( !empty($HTTP_POST_VARS['vote_id']) )
469 $vote_option_id = intval($HTTP_POST_VARS['vote_id']);
471 $sql = "SELECT vd.vote_id
472 FROM " . VOTE_DESC_TABLE . " vd, " . VOTE_RESULTS_TABLE . " vr
473 WHERE vd.topic_id = $topic_id
474 AND vr.vote_id = vd.vote_id
475 AND vr.vote_option_id = $vote_option_id
476 GROUP BY vd.vote_id";
477 if ( !($result = $db->sql_query($sql)) )
479 message_die(GENERAL_ERROR, 'Could not obtain vote data for this topic', '', __LINE__, __FILE__, $sql);
482 if ( $vote_info = $db->sql_fetchrow($result) )
484 $vote_id = $vote_info['vote_id'];
487 FROM " . VOTE_USERS_TABLE . "
488 WHERE vote_id = $vote_id
489 AND vote_user_id = " . $userdata['user_id'];
490 if ( !($result2 = $db->sql_query($sql)) )
492 message_die(GENERAL_ERROR, 'Could not obtain user vote data for this topic', '', __LINE__, __FILE__, $sql);
495 if ( !($row = $db->sql_fetchrow($result2)) )
497 $sql = "UPDATE " . VOTE_RESULTS_TABLE . "
498 SET vote_result = vote_result + 1
499 WHERE vote_id = $vote_id
500 AND vote_option_id = $vote_option_id";
501 if ( !$db->sql_query($sql, BEGIN_TRANSACTION) )
503 message_die(GENERAL_ERROR, 'Could not update poll result', '', __LINE__, __FILE__, $sql);
506 $sql = "INSERT INTO " . VOTE_USERS_TABLE . " (vote_id, vote_user_id, vote_user_ip)
507 VALUES ($vote_id, " . $userdata['user_id'] . ", '$user_ip')";
508 if ( !$db->sql_query($sql, END_TRANSACTION) )
510 message_die(GENERAL_ERROR, "Could not insert user_id for poll", "", __LINE__, __FILE__, $sql);
513 $message = $lang['Vote_cast'];
517 $message = $lang['Already_voted'];
519 $db->sql_freeresult($result2);
523 $message = $lang['No_vote_option'];
525 $db->sql_freeresult($result);
527 $template->assign_vars(array(
528 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id") . '">')
530 $message .= '<br /><br />' . sprintf($lang['Click_view_message'], '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id") . '">', '</a>');
531 message_die(GENERAL_MESSAGE, $message);
535 redirect(append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id", true));
538 else if ( $submit || $confirm )
541 // Submit post/vote (newtopic, edit, reply, etc.)
543 $return_message = '';
547 if ($sid == '' || $sid != $userdata['session_id'])
549 $error_msg .= (!empty($error_msg)) ? '<br />' . $lang['Session_invalid'] : $lang['Session_invalid'];
557 $username = ( !empty($HTTP_POST_VARS['username']) ) ? $HTTP_POST_VARS['username'] : '';
558 $subject = ( !empty($HTTP_POST_VARS['subject']) ) ? trim($HTTP_POST_VARS['subject']) : '';
559 $message = ( !empty($HTTP_POST_VARS['message']) ) ? $HTTP_POST_VARS['message'] : '';
560 $poll_title = ( isset($HTTP_POST_VARS['poll_title']) && $is_auth['auth_pollcreate'] ) ? $HTTP_POST_VARS['poll_title'] : '';
561 $poll_options = ( isset($HTTP_POST_VARS['poll_option_text']) && $is_auth['auth_pollcreate'] ) ? $HTTP_POST_VARS['poll_option_text'] : '';
562 $poll_length = ( isset($HTTP_POST_VARS['poll_length']) && $is_auth['auth_pollcreate'] ) ? $HTTP_POST_VARS['poll_length'] : '';
565 prepare_post($mode, $post_data, $bbcode_on, $html_on, $smilies_on, $error_msg, $username, $bbcode_uid, $subject, $message, $poll_title, $poll_options, $poll_length);
567 if ( $error_msg == '' )
569 $topic_type = ( $topic_type != $post_data['topic_type'] && !$is_auth['auth_sticky'] && !$is_auth['auth_announce'] ) ? $post_data['topic_type'] : $topic_type;
571 submit_post($mode, $post_data, $return_message, $return_meta, $forum_id, $topic_id, $post_id, $poll_id, $topic_type, $bbcode_on, $html_on, $smilies_on, $attach_sig, $bbcode_uid, str_replace("\'", "''", $username), str_replace("\'", "''", $subject), str_replace("\'", "''", $message), str_replace("\'", "''", $poll_title), $poll_options, $poll_length);
577 if ($error_msg != '')
579 message_die(GENERAL_MESSAGE, $error_msg);
582 delete_post($mode, $post_data, $return_message, $return_meta, $forum_id, $topic_id, $post_id, $poll_id);
586 if ( $error_msg == '' )
588 if ( $mode != 'editpost' )
590 $user_id = ( $mode == 'reply' || $mode == 'newtopic' ) ? $userdata['user_id'] : $post_data['poster_id'];
591 update_post_stats($mode, $post_data, $forum_id, $topic_id, $post_id, $user_id);
594 if ($error_msg == '' && $mode != 'poll_delete')
596 user_notification($mode, $post_data, $post_info['topic_title'], $forum_id, $topic_id, $post_id, $notify_user);
599 if ( $mode == 'newtopic' || $mode == 'reply' )
601 $tracking_topics = ( !empty($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) : array();
602 $tracking_forums = ( !empty($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) : array();
604 if ( count($tracking_topics) + count($tracking_forums) == 100 && empty($tracking_topics[$topic_id]) )
606 asort($tracking_topics);
607 unset($tracking_topics[key($tracking_topics)]);
610 $tracking_topics[$topic_id] = time();
612 setcookie($board_config['cookie_name'] . '_t', serialize($tracking_topics), 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
615 $template->assign_vars(array(
616 'META' => $return_meta)
618 message_die(GENERAL_MESSAGE, $return_message);
622 if( $refresh || isset($HTTP_POST_VARS['del_poll_option']) || $error_msg != '' )
624 $username = ( !empty($HTTP_POST_VARS['username']) ) ? htmlspecialchars(trim(stripslashes($HTTP_POST_VARS['username']))) : '';
625 $subject = ( !empty($HTTP_POST_VARS['subject']) ) ? htmlspecialchars(trim(stripslashes($HTTP_POST_VARS['subject']))) : '';
626 $message = ( !empty($HTTP_POST_VARS['message']) ) ? htmlspecialchars(trim(stripslashes($HTTP_POST_VARS['message']))) : '';
628 $poll_title = ( !empty($HTTP_POST_VARS['poll_title']) ) ? htmlspecialchars(trim(stripslashes($HTTP_POST_VARS['poll_title']))) : '';
629 $poll_length = ( isset($HTTP_POST_VARS['poll_length']) ) ? max(0, intval($HTTP_POST_VARS['poll_length'])) : 0;
631 $poll_options = array();
632 if ( !empty($HTTP_POST_VARS['poll_option_text']) )
634 while( list($option_id, $option_text) = @each($HTTP_POST_VARS['poll_option_text']) )
636 if( isset($HTTP_POST_VARS['del_poll_option'][$option_id]) )
638 unset($poll_options[$option_id]);
640 else if ( !empty($option_text) )
642 $poll_options[intval($option_id)] = htmlspecialchars(trim(stripslashes($option_text)));
647 if ( isset($poll_add) && !empty($HTTP_POST_VARS['add_poll_option_text']) )
649 $poll_options[] = htmlspecialchars(trim(stripslashes($HTTP_POST_VARS['add_poll_option_text'])));
652 if ( $mode == 'newtopic' || $mode == 'reply')
654 $user_sig = ( $userdata['user_sig'] != '' && $board_config['allow_sig'] ) ? $userdata['user_sig'] : '';
656 else if ( $mode == 'editpost' )
658 $user_sig = ( $post_info['user_sig'] != '' && $board_config['allow_sig'] ) ? $post_info['user_sig'] : '';
659 $userdata['user_sig_bbcode_uid'] = $post_info['user_sig_bbcode_uid'];
664 $orig_word = array();
665 $replacement_word = array();
666 obtain_word_list($orig_word, $replacement_word);
668 $bbcode_uid = ( $bbcode_on ) ? make_bbcode_uid() : '';
669 $preview_message = stripslashes(prepare_message(addslashes(unprepare_message($message)), $html_on, $bbcode_on, $smilies_on, $bbcode_uid));
670 $preview_subject = $subject;
671 $preview_username = $username;
674 // Finalise processing as per viewtopic
678 if( $user_sig != '' || !$userdata['user_allowhtml'] )
680 $user_sig = preg_replace('#(<)([\/]?.*?)(>)#is', '<\2>', $user_sig);
684 if( $attach_sig && $user_sig != '' && $userdata['user_sig_bbcode_uid'] )
686 $user_sig = bbencode_second_pass($user_sig, $userdata['user_sig_bbcode_uid']);
691 $preview_message = bbencode_second_pass($preview_message, $bbcode_uid);
694 if( !empty($orig_word) )
696 $preview_username = ( !empty($username) ) ? preg_replace($orig_word, $replacement_word, $preview_username) : '';
697 $preview_subject = ( !empty($subject) ) ? preg_replace($orig_word, $replacement_word, $preview_subject) : '';
698 $preview_message = ( !empty($preview_message) ) ? preg_replace($orig_word, $replacement_word, $preview_message) : '';
701 if( $user_sig != '' )
703 $user_sig = make_clickable($user_sig);
705 $preview_message = make_clickable($preview_message);
709 if( $userdata['user_allowsmile'] && $user_sig != '' )
711 $user_sig = smilies_pass($user_sig);
714 $preview_message = smilies_pass($preview_message);
717 if( $attach_sig && $user_sig != '' )
719 $preview_message = $preview_message . '<br /><br />_________________<br />' . $user_sig;
722 $preview_message = str_replace("\n", '<br />', $preview_message);
724 $template->set_filenames(array(
725 'preview' => 'posting_preview.tpl')
728 $template->assign_vars(array(
729 'TOPIC_TITLE' => $preview_subject,
730 'POST_SUBJECT' => $preview_subject,
731 'POSTER_NAME' => $preview_username,
732 'POST_DATE' => create_date($board_config['default_dateformat'], time(), $board_config['board_timezone']),
733 'MESSAGE' => $preview_message,
735 'L_POST_SUBJECT' => $lang['Post_subject'],
736 'L_PREVIEW' => $lang['Preview'],
737 'L_POSTED' => $lang['Posted'],
738 'L_POST' => $lang['Post'])
740 $template->assign_var_from_handle('POST_PREVIEW_BOX', 'preview');
742 else if( $error_msg != '' )
744 $template->set_filenames(array(
745 'reg_header' => 'error_body.tpl')
747 $template->assign_vars(array(
748 'ERROR_MESSAGE' => $error_msg)
750 $template->assign_var_from_handle('ERROR_BOX', 'reg_header');
756 // User default entry point
758 if ( $mode == 'newtopic' )
760 $user_sig = ( $userdata['user_sig'] != '' ) ? $userdata['user_sig'] : '';
762 $username = ($userdata['session_logged_in']) ? $userdata['username'] : '';
768 else if ( $mode == 'reply' )
770 $user_sig = ( $userdata['user_sig'] != '' ) ? $userdata['user_sig'] : '';
772 $username = ( $userdata['session_logged_in'] ) ? $userdata['username'] : '';
777 else if ( $mode == 'quote' || $mode == 'editpost' )
779 $subject = ( $post_data['first_post'] ) ? $post_info['topic_title'] : $post_info['post_subject'];
780 $message = $post_info['post_text'];
782 if ( $mode == 'editpost' )
784 $attach_sig = ( $post_info['enable_sig'] && $post_info['user_sig'] != '' ) ? TRUE : 0;
785 $user_sig = $post_info['user_sig'];
787 $html_on = ( $post_info['enable_html'] ) ? true : false;
788 $bbcode_on = ( $post_info['enable_bbcode'] ) ? true : false;
789 $smilies_on = ( $post_info['enable_smilies'] ) ? true : false;
793 $attach_sig = ( $userdata['user_attachsig'] ) ? TRUE : 0;
794 $user_sig = $userdata['user_sig'];
797 if ( $post_info['bbcode_uid'] != '' )
799 $message = preg_replace('/\:(([a-z0-9]:)?)' . $post_info['bbcode_uid'] . '/s', '', $message);
802 $message = str_replace('<', '<', $message);
803 $message = str_replace('>', '>', $message);
804 $message = str_replace('<br />', "\n", $message);
806 if ( $mode == 'quote' )
808 $orig_word = array();
809 $replacement_word = array();
810 obtain_word_list($orig_word, $replace_word);
812 $msg_date = create_date($board_config['default_dateformat'], $postrow['post_time'], $board_config['board_timezone']);
814 // Use trim to get rid of spaces placed there by MS-SQL 2000
815 $quote_username = ( trim($post_info['post_username']) != '' ) ? $post_info['post_username'] : $post_info['username'];
816 $message = '[quote="' . $quote_username . '"]' . $message . '[/quote]';
818 if ( !empty($orig_word) )
820 $subject = ( !empty($subject) ) ? preg_replace($orig_word, $replace_word, $subject) : '';
821 $message = ( !empty($message) ) ? preg_replace($orig_word, $replace_word, $message) : '';
824 if ( !preg_match('/^Re:/', $subject) && strlen($subject) > 0 )
826 $subject = 'Re: ' . $subject;
833 $username = ( $post_info['user_id'] == ANONYMOUS && !empty($post_info['post_username']) ) ? $post_info['post_username'] : '';
839 // Signature toggle selection
841 if( $user_sig != '' )
843 $template->assign_block_vars('switch_signature_checkbox', array());
847 // HTML toggle selection
849 if ( $board_config['allow_html'] )
851 $html_status = $lang['HTML_is_ON'];
852 $template->assign_block_vars('switch_html_checkbox', array());
856 $html_status = $lang['HTML_is_OFF'];
860 // BBCode toggle selection
862 if ( $board_config['allow_bbcode'] )
864 $bbcode_status = $lang['BBCode_is_ON'];
865 $template->assign_block_vars('switch_bbcode_checkbox', array());
869 $bbcode_status = $lang['BBCode_is_OFF'];
873 // Smilies toggle selection
875 if ( $board_config['allow_smilies'] )
877 $smilies_status = $lang['Smilies_are_ON'];
878 $template->assign_block_vars('switch_smilies_checkbox', array());
882 $smilies_status = $lang['Smilies_are_OFF'];
885 if( !$userdata['session_logged_in'] || ( $mode == 'editpost' && $post_info['poster_id'] == ANONYMOUS ) )
887 $template->assign_block_vars('switch_username_select', array());
891 // Notify checkbox - only show if user is logged in
893 if ( $userdata['session_logged_in'] && $is_auth['auth_read'] )
895 if ( $mode != 'editpost' || ( $mode == 'editpost' && $post_info['poster_id'] != ANONYMOUS ) )
897 $template->assign_block_vars('switch_notify_checkbox', array());
904 if ( $mode == 'editpost' && ( ( $is_auth['auth_delete'] && $post_data['last_post'] && ( !$post_data['has_poll'] || $post_data['edit_poll'] ) ) || $is_auth['auth_mod'] ) )
906 $template->assign_block_vars('switch_delete_checkbox', array());
910 // Topic type selection
912 $topic_type_toggle = '';
913 if ( $mode == 'newtopic' || ( $mode == 'editpost' && $post_data['first_post'] ) )
915 $template->assign_block_vars('switch_type_toggle', array());
917 if( $is_auth['auth_sticky'] )
919 $topic_type_toggle .= '<input type="radio" name="topictype" value="' . POST_STICKY . '"';
920 if ( $post_data['topic_type'] == POST_STICKY || $topic_type == POST_STICKY )
922 $topic_type_toggle .= ' checked="checked"';
924 $topic_type_toggle .= ' /> ' . $lang['Post_Sticky'] . ' ';
927 if( $is_auth['auth_announce'] )
929 $topic_type_toggle .= '<input type="radio" name="topictype" value="' . POST_ANNOUNCE . '"';
930 if ( $post_data['topic_type'] == POST_ANNOUNCE || $topic_type == POST_ANNOUNCE )
932 $topic_type_toggle .= ' checked="checked"';
934 $topic_type_toggle .= ' /> ' . $lang['Post_Announcement'] . ' ';
937 if ( $topic_type_toggle != '' )
939 $topic_type_toggle = $lang['Post_topic_as'] . ': <input type="radio" name="topictype" value="' . POST_NORMAL .'"' . ( ( $post_data['topic_type'] == POST_NORMAL || $topic_type == POST_NORMAL ) ? ' checked="checked"' : '' ) . ' /> ' . $lang['Post_Normal'] . ' ' . $topic_type_toggle;
943 $hidden_form_fields = '<input type="hidden" name="mode" value="' . $mode . '" />';
944 $hidden_form_fields .= '<input type="hidden" name="sid" value="' . $userdata['session_id'] . '" />';
949 $page_title = $lang['Post_a_new_topic'];
950 $hidden_form_fields .= '<input type="hidden" name="' . POST_FORUM_URL . '" value="' . $forum_id . '" />';
954 $page_title = $lang['Post_a_reply'];
955 $hidden_form_fields .= '<input type="hidden" name="' . POST_TOPIC_URL . '" value="' . $topic_id . '" />';
959 $page_title = $lang['Edit_Post'];
960 $hidden_form_fields .= '<input type="hidden" name="' . POST_POST_URL . '" value="' . $post_id . '" />';
964 // Generate smilies listing for page output
965 generate_smilies('inline', PAGE_POSTING);
968 // Include page header
970 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
972 $template->set_filenames(array(
973 'body' => 'posting_body.tpl',
974 'pollbody' => 'posting_poll_body.tpl',
975 'reviewbody' => 'posting_topic_review.tpl')
977 make_jumpbox('viewforum.'.$phpEx);
979 $template->assign_vars(array(
980 'FORUM_NAME' => $forum_name,
981 'L_POST_A' => $page_title,
982 'L_POST_SUBJECT' => $lang['Post_subject'],
984 'U_VIEW_FORUM' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id"))
988 // This enables the forum/topic title to be output for posting
989 // but not for privmsg (where it makes no sense)
991 $template->assign_block_vars('switch_not_privmsg', array());
994 // Output the data to the template
996 $template->assign_vars(array(
997 'USERNAME' => $username,
998 'SUBJECT' => $subject,
999 'MESSAGE' => $message,
1000 'HTML_STATUS' => $html_status,
1001 'BBCODE_STATUS' => sprintf($bbcode_status, '<a href="' . append_sid("faq.$phpEx?mode=bbcode") . '" target="_phpbbcode">', '</a>'),
1002 'SMILIES_STATUS' => $smilies_status,
1004 'L_SUBJECT' => $lang['Subject'],
1005 'L_MESSAGE_BODY' => $lang['Message_body'],
1006 'L_OPTIONS' => $lang['Options'],
1007 'L_PREVIEW' => $lang['Preview'],
1008 'L_SPELLCHECK' => $lang['Spellcheck'],
1009 'L_SUBMIT' => $lang['Submit'],
1010 'L_CANCEL' => $lang['Cancel'],
1011 'L_CONFIRM_DELETE' => $lang['Confirm_delete'],
1012 'L_DISABLE_HTML' => $lang['Disable_HTML_post'],
1013 'L_DISABLE_BBCODE' => $lang['Disable_BBCode_post'],
1014 'L_DISABLE_SMILIES' => $lang['Disable_Smilies_post'],
1015 'L_ATTACH_SIGNATURE' => $lang['Attach_signature'],
1016 'L_NOTIFY_ON_REPLY' => $lang['Notify'],
1017 'L_DELETE_POST' => $lang['Delete_post'],
1019 'L_BBCODE_B_HELP' => $lang['bbcode_b_help'],
1020 'L_BBCODE_I_HELP' => $lang['bbcode_i_help'],
1021 'L_BBCODE_U_HELP' => $lang['bbcode_u_help'],
1022 'L_BBCODE_Q_HELP' => $lang['bbcode_q_help'],
1023 'L_BBCODE_C_HELP' => $lang['bbcode_c_help'],
1024 'L_BBCODE_L_HELP' => $lang['bbcode_l_help'],
1025 'L_BBCODE_O_HELP' => $lang['bbcode_o_help'],
1026 'L_BBCODE_P_HELP' => $lang['bbcode_p_help'],
1027 'L_BBCODE_W_HELP' => $lang['bbcode_w_help'],
1028 'L_BBCODE_A_HELP' => $lang['bbcode_a_help'],
1029 'L_BBCODE_S_HELP' => $lang['bbcode_s_help'],
1030 'L_BBCODE_F_HELP' => $lang['bbcode_f_help'],
1031 'L_EMPTY_MESSAGE' => $lang['Empty_message'],
1033 'L_FONT_COLOR' => $lang['Font_color'],
1034 'L_COLOR_DEFAULT' => $lang['color_default'],
1035 'L_COLOR_DARK_RED' => $lang['color_dark_red'],
1036 'L_COLOR_RED' => $lang['color_red'],
1037 'L_COLOR_ORANGE' => $lang['color_orange'],
1038 'L_COLOR_BROWN' => $lang['color_brown'],
1039 'L_COLOR_YELLOW' => $lang['color_yellow'],
1040 'L_COLOR_GREEN' => $lang['color_green'],
1041 'L_COLOR_OLIVE' => $lang['color_olive'],
1042 'L_COLOR_CYAN' => $lang['color_cyan'],
1043 'L_COLOR_BLUE' => $lang['color_blue'],
1044 'L_COLOR_DARK_BLUE' => $lang['color_dark_blue'],
1045 'L_COLOR_INDIGO' => $lang['color_indigo'],
1046 'L_COLOR_VIOLET' => $lang['color_violet'],
1047 'L_COLOR_WHITE' => $lang['color_white'],
1048 'L_COLOR_BLACK' => $lang['color_black'],
1050 'L_FONT_SIZE' => $lang['Font_size'],
1051 'L_FONT_TINY' => $lang['font_tiny'],
1052 'L_FONT_SMALL' => $lang['font_small'],
1053 'L_FONT_NORMAL' => $lang['font_normal'],
1054 'L_FONT_LARGE' => $lang['font_large'],
1055 'L_FONT_HUGE' => $lang['font_huge'],
1057 'L_BBCODE_CLOSE_TAGS' => $lang['Close_Tags'],
1058 'L_STYLES_TIP' => $lang['Styles_tip'],
1060 'U_VIEWTOPIC' => ( $mode == 'reply' ) ? append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&postorder=desc") : '',
1061 'U_REVIEW_TOPIC' => ( $mode == 'reply' ) ? append_sid("posting.$phpEx?mode=topicreview&" . POST_TOPIC_URL . "=$topic_id") : '',
1063 'S_HTML_CHECKED' => ( !$html_on ) ? 'checked="checked"' : '',
1064 'S_BBCODE_CHECKED' => ( !$bbcode_on ) ? 'checked="checked"' : '',
1065 'S_SMILIES_CHECKED' => ( !$smilies_on ) ? 'checked="checked"' : '',
1066 'S_SIGNATURE_CHECKED' => ( $attach_sig ) ? 'checked="checked"' : '',
1067 'S_NOTIFY_CHECKED' => ( $notify_user ) ? 'checked="checked"' : '',
1068 'S_TYPE_TOGGLE' => $topic_type_toggle,
1069 'S_TOPIC_ID' => $topic_id,
1070 'S_POST_ACTION' => append_sid("posting.$phpEx"),
1071 'S_HIDDEN_FORM_FIELDS' => $hidden_form_fields)
1075 // Poll entry switch/output
1077 if( ( $mode == 'newtopic' || ( $mode == 'editpost' && $post_data['edit_poll']) ) && $is_auth['auth_pollcreate'] )
1079 $template->assign_vars(array(
1080 'L_ADD_A_POLL' => $lang['Add_poll'],
1081 'L_ADD_POLL_EXPLAIN' => $lang['Add_poll_explain'],
1082 'L_POLL_QUESTION' => $lang['Poll_question'],
1083 'L_POLL_OPTION' => $lang['Poll_option'],
1084 'L_ADD_OPTION' => $lang['Add_option'],
1085 'L_UPDATE_OPTION' => $lang['Update'],
1086 'L_DELETE_OPTION' => $lang['Delete'],
1087 'L_POLL_LENGTH' => $lang['Poll_for'],
1088 'L_DAYS' => $lang['Days'],
1089 'L_POLL_LENGTH_EXPLAIN' => $lang['Poll_for_explain'],
1090 'L_POLL_DELETE' => $lang['Delete_poll'],
1092 'POLL_TITLE' => $poll_title,
1093 'POLL_LENGTH' => $poll_length)
1096 if( $mode == 'editpost' && $post_data['edit_poll'] && $post_data['has_poll'])
1098 $template->assign_block_vars('switch_poll_delete_toggle', array());
1101 if( !empty($poll_options) )
1103 while( list($option_id, $option_text) = each($poll_options) )
1105 $template->assign_block_vars('poll_option_rows', array(
1106 'POLL_OPTION' => str_replace('"', '"', $option_text),
1108 'S_POLL_OPTION_NUM' => $option_id)
1113 $template->assign_var_from_handle('POLLBOX', 'pollbody');
1119 if( $mode == 'reply' && $is_auth['auth_read'] )
1121 require($phpbb_root_path . 'includes/topic_review.'.$phpEx);
1122 topic_review($topic_id, true);
1124 $template->assign_block_vars('switch_inline_mode', array());
1125 $template->assign_var_from_handle('TOPIC_REVIEW_BOX', 'reviewbody');
1128 $template->pparse('body');
1130 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);