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.22 2004/07/11 16:46:16 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;
48 $params = array('forum_id' => POST_FORUM_URL, 'topic_id' => POST_TOPIC_URL, 'post_id' => POST_POST_URL);
49 while( list($var, $param) = @each($params) )
51 if ( !empty($HTTP_POST_VARS[$param]) || !empty($HTTP_GET_VARS[$param]) )
53 $$var = ( !empty($HTTP_POST_VARS[$param]) ) ? intval($HTTP_POST_VARS[$param]) : intval($HTTP_GET_VARS[$param]);
61 $refresh = $preview || $poll_add || $poll_edit || $poll_delete;
66 $topic_type = ( !empty($HTTP_POST_VARS['topictype']) ) ? intval($HTTP_POST_VARS['topictype']) : POST_NORMAL;
69 // If the mode is set to topic review then output
72 if ( $mode == 'topicreview' )
74 require($phpbb_root_path . 'includes/topic_review.'.$phpEx);
76 topic_review($topic_id, false);
79 else if ( $mode == 'smilies' )
81 generate_smilies('window', PAGE_POSTING);
86 // Start session management
88 $userdata = session_pagestart($user_ip, PAGE_POSTING);
89 init_userprefs($userdata);
91 // End session management
95 // Was cancel pressed? If so then redirect to the appropriate
96 // page, no point in continuing with any further checks
98 if ( isset($HTTP_POST_VARS['cancel']) )
102 $redirect = "viewtopic.$phpEx?" . POST_POST_URL . "=$post_id";
103 $post_append = "#$post_id";
105 else if ( $topic_id )
107 $redirect = "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id";
110 else if ( $forum_id )
112 $redirect = "viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id";
117 $redirect = "index.$phpEx";
121 redirect(append_sid($redirect, true) . $post_append);
125 // What auth type do we need to check?
131 if ( $topic_type == POST_ANNOUNCE )
133 $is_auth_type = 'auth_announce';
135 else if ( $topic_type == POST_STICKY )
137 $is_auth_type = 'auth_sticky';
141 $is_auth_type = 'auth_post';
146 $is_auth_type = 'auth_reply';
149 $is_auth_type = 'auth_edit';
153 $is_auth_type = 'auth_delete';
156 $is_auth_type = 'auth_vote';
159 $is_auth_type = 'auth_read';
162 message_die(GENERAL_MESSAGE, $lang['No_post_mode']);
167 // Here we do various lookups to find topic_id, forum_id, post_id etc.
168 // Doing it here prevents spoofing (eg. faking forum_id, topic_id or post_id
171 $post_data = array();
175 if ( empty($forum_id) )
177 message_die(GENERAL_MESSAGE, $lang['Forum_not_exist']);
181 FROM " . FORUMS_TABLE . "
182 WHERE forum_id = $forum_id";
187 if ( empty( $topic_id) )
189 message_die(GENERAL_MESSAGE, $lang['No_topic_id']);
192 $sql = "SELECT f.*, t.topic_status, t.topic_title
193 FROM " . FORUMS_TABLE . " f, " . TOPICS_TABLE . " t
194 WHERE t.topic_id = $topic_id
195 AND f.forum_id = t.forum_id";
202 if ( empty($post_id) )
204 message_die(GENERAL_MESSAGE, $lang['No_post_id']);
207 $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" : '';
208 $from_sql = ( !$submit ) ? ", " . POSTS_TEXT_TABLE . " pt, " . USERS_TABLE . " u" : '';
209 $where_sql = ( !$submit ) ? "AND pt.post_id = p.post_id AND u.user_id = p.poster_id" : '';
211 $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 . "
212 FROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f" . $from_sql . "
213 WHERE p.post_id = $post_id
214 AND t.topic_id = p.topic_id
215 AND f.forum_id = p.forum_id
220 message_die(GENERAL_MESSAGE, $lang['No_valid_mode']);
223 if ( $result = $db->sql_query($sql) )
225 $post_info = $db->sql_fetchrow($result);
226 $db->sql_freeresult($result);
228 $forum_id = $post_info['forum_id'];
229 $forum_name = $post_info['forum_name'];
231 $is_auth = auth(AUTH_ALL, $forum_id, $userdata, $post_info);
233 if ( $post_info['forum_status'] == FORUM_LOCKED && !$is_auth['auth_mod'])
235 message_die(GENERAL_MESSAGE, $lang['Forum_locked']);
237 else if ( $mode != 'newtopic' && $post_info['topic_status'] == TOPIC_LOCKED && !$is_auth['auth_mod'])
239 message_die(GENERAL_MESSAGE, $lang['Topic_locked']);
242 if ( $mode == 'editpost' || $mode == 'delete' || $mode == 'poll_delete' )
244 $topic_id = $post_info['topic_id'];
246 $post_data['poster_post'] = ( $post_info['poster_id'] == $userdata['user_id'] ) ? true : false;
247 $post_data['first_post'] = ( $post_info['topic_first_post_id'] == $post_id ) ? true : false;
248 $post_data['last_post'] = ( $post_info['topic_last_post_id'] == $post_id ) ? true : false;
249 $post_data['last_topic'] = ( $post_info['forum_last_post_id'] == $post_id ) ? true : false;
250 $post_data['has_poll'] = ( $post_info['topic_vote'] ) ? true : false;
251 $post_data['topic_type'] = $post_info['topic_type'];
252 $post_data['poster_id'] = $post_info['poster_id'];
254 if ( $post_data['first_post'] && $post_data['has_poll'] )
257 FROM " . VOTE_DESC_TABLE . " vd, " . VOTE_RESULTS_TABLE . " vr
258 WHERE vd.topic_id = $topic_id
259 AND vr.vote_id = vd.vote_id
260 ORDER BY vr.vote_option_id";
261 if ( !($result = $db->sql_query($sql)) )
263 message_die(GENERAL_ERROR, 'Could not obtain vote data for this topic', '', __LINE__, __FILE__, $sql);
266 $poll_options = array();
267 $poll_results_sum = 0;
268 if ( $row = $db->sql_fetchrow($result) )
270 $poll_title = $row['vote_text'];
271 $poll_id = $row['vote_id'];
272 $poll_length = $row['vote_length'] / 86400;
276 $poll_options[$row['vote_option_id']] = $row['vote_option_text'];
277 $poll_results_sum += $row['vote_result'];
279 while ( $row = $db->sql_fetchrow($result) );
281 $db->sql_freeresult($result);
283 $post_data['edit_poll'] = ( ( !$poll_results_sum || $is_auth['auth_mod'] ) && $post_data['first_post'] ) ? true : 0;
287 $post_data['edit_poll'] = ($post_data['first_post'] && $is_auth['auth_pollcreate']) ? true : false;
291 // Can this user edit/delete the post/poll?
293 if ( $post_info['poster_id'] != $userdata['user_id'] && !$is_auth['auth_mod'] )
295 $message = ( $delete || $mode == 'delete' ) ? $lang['Delete_own_posts'] : $lang['Edit_own_posts'];
296 $message .= '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id") . '">', '</a>');
298 message_die(GENERAL_MESSAGE, $message);
300 else if ( !$post_data['last_post'] && !$is_auth['auth_mod'] && ( $mode == 'delete' || $delete ) )
302 message_die(GENERAL_MESSAGE, $lang['Cannot_delete_replied']);
304 else if ( !$post_data['edit_poll'] && !$is_auth['auth_mod'] && ( $mode == 'poll_delete' || $poll_delete ) )
306 message_die(GENERAL_MESSAGE, $lang['Cannot_delete_poll']);
311 if ( $mode == 'quote' )
313 $topic_id = $post_info['topic_id'];
316 $post_data['first_post'] = ( $mode == 'newtopic' ) ? true : 0;
317 $post_data['last_post'] = false;
318 $post_data['has_poll'] = false;
319 $post_data['edit_poll'] = false;
324 message_die(GENERAL_MESSAGE, $lang['No_such_post']);
328 // The user is not authed, if they're not logged in then redirect
329 // them, else show them an error message
331 if ( !$is_auth[$is_auth_type] )
333 if ( $userdata['session_logged_in'] )
335 message_die(GENERAL_MESSAGE, sprintf($lang['Sorry_' . $is_auth_type], $is_auth[$is_auth_type . "_type"]));
341 $redirect = "mode=newtopic&" . POST_FORUM_URL . "=" . $forum_id;
345 $redirect = "mode=reply&" . POST_TOPIC_URL . "=" . $topic_id;
349 $redirect = "mode=quote&" . POST_POST_URL ."=" . $post_id;
353 redirect(append_sid("login.$phpEx?redirect=posting.$phpEx&" . $redirect, true));
357 // Set toggles for various options
359 if ( !$board_config['allow_html'] )
365 $html_on = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['disable_html']) ) ? 0 : TRUE ) : ( ( $userdata['user_id'] == ANONYMOUS ) ? $board_config['allow_html'] : $userdata['user_allowhtml'] );
368 if ( !$board_config['allow_bbcode'] )
374 $bbcode_on = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['disable_bbcode']) ) ? 0 : TRUE ) : ( ( $userdata['user_id'] == ANONYMOUS ) ? $board_config['allow_bbcode'] : $userdata['user_allowbbcode'] );
377 if ( !$board_config['allow_smilies'] )
383 $smilies_on = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['disable_smilies']) ) ? 0 : TRUE ) : ( ( $userdata['user_id'] == ANONYMOUS ) ? $board_config['allow_smilies'] : $userdata['user_allowsmile'] );
386 if ( ($submit || $refresh) && $is_auth['auth_read'])
388 $notify_user = ( !empty($HTTP_POST_VARS['notify']) ) ? TRUE : 0;
392 if ( $mode != 'newtopic' && $userdata['session_logged_in'] && $is_auth['auth_read'] )
394 $sql = "SELECT topic_id
395 FROM " . TOPICS_WATCH_TABLE . "
396 WHERE topic_id = $topic_id
397 AND user_id = " . $userdata['user_id'];
398 if ( !($result = $db->sql_query($sql)) )
400 message_die(GENERAL_ERROR, 'Could not obtain topic watch information', '', __LINE__, __FILE__, $sql);
403 $notify_user = ( $db->sql_fetchrow($result) ) ? TRUE : $userdata['user_notify'];
404 $db->sql_freeresult($result);
408 $notify_user = ( $userdata['session_logged_in'] && $is_auth['auth_read'] ) ? $userdata['user_notify'] : 0;
412 $attach_sig = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['attach_sig']) ) ? TRUE : 0 ) : ( ( $userdata['user_id'] == ANONYMOUS ) ? 0 : $userdata['user_attachsig'] );
414 // --------------------
417 if ( ( $delete || $poll_delete || $mode == 'delete' ) && !$confirm )
422 $s_hidden_fields = '<input type="hidden" name="' . POST_POST_URL . '" value="' . $post_id . '" />';
423 $s_hidden_fields .= ( $delete || $mode == "delete" ) ? '<input type="hidden" name="mode" value="delete" />' : '<input type="hidden" name="mode" value="poll_delete" />';
425 $l_confirm = ( $delete || $mode == 'delete' ) ? $lang['Confirm_delete'] : $lang['Confirm_delete_poll'];
428 // Output confirmation page
430 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
432 $template->set_filenames(array(
433 'confirm_body' => 'confirm_body.tpl')
436 $template->assign_vars(array(
437 'MESSAGE_TITLE' => $lang['Information'],
438 'MESSAGE_TEXT' => $l_confirm,
440 'L_YES' => $lang['Yes'],
441 'L_NO' => $lang['No'],
443 'S_CONFIRM_ACTION' => append_sid("posting.$phpEx"),
444 'S_HIDDEN_FIELDS' => $s_hidden_fields)
447 $template->pparse('confirm_body');
449 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
451 else if ( $mode == 'vote' )
456 if ( !empty($HTTP_POST_VARS['vote_id']) )
458 $vote_option_id = intval($HTTP_POST_VARS['vote_id']);
460 $sql = "SELECT vd.vote_id
461 FROM " . VOTE_DESC_TABLE . " vd, " . VOTE_RESULTS_TABLE . " vr
462 WHERE vd.topic_id = $topic_id
463 AND vr.vote_id = vd.vote_id
464 AND vr.vote_option_id = $vote_option_id
465 GROUP BY vd.vote_id";
466 if ( !($result = $db->sql_query($sql)) )
468 message_die(GENERAL_ERROR, 'Could not obtain vote data for this topic', '', __LINE__, __FILE__, $sql);
471 if ( $vote_info = $db->sql_fetchrow($result) )
473 $vote_id = $vote_info['vote_id'];
476 FROM " . VOTE_USERS_TABLE . "
477 WHERE vote_id = $vote_id
478 AND vote_user_id = " . $userdata['user_id'];
479 if ( !($result2 = $db->sql_query($sql)) )
481 message_die(GENERAL_ERROR, 'Could not obtain user vote data for this topic', '', __LINE__, __FILE__, $sql);
484 if ( !($row = $db->sql_fetchrow($result2)) )
486 $sql = "UPDATE " . VOTE_RESULTS_TABLE . "
487 SET vote_result = vote_result + 1
488 WHERE vote_id = $vote_id
489 AND vote_option_id = $vote_option_id";
490 if ( !$db->sql_query($sql, BEGIN_TRANSACTION) )
492 message_die(GENERAL_ERROR, 'Could not update poll result', '', __LINE__, __FILE__, $sql);
495 $sql = "INSERT INTO " . VOTE_USERS_TABLE . " (vote_id, vote_user_id, vote_user_ip)
496 VALUES ($vote_id, " . $userdata['user_id'] . ", '$user_ip')";
497 if ( !$db->sql_query($sql, END_TRANSACTION) )
499 message_die(GENERAL_ERROR, "Could not insert user_id for poll", "", __LINE__, __FILE__, $sql);
502 $message = $lang['Vote_cast'];
506 $message = $lang['Already_voted'];
508 $db->sql_freeresult($result2);
512 $message = $lang['No_vote_option'];
514 $db->sql_freeresult($result);
516 $template->assign_vars(array(
517 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id") . '">')
519 $message .= '<br /><br />' . sprintf($lang['Click_view_message'], '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id") . '">', '</a>');
520 message_die(GENERAL_MESSAGE, $message);
524 redirect(append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id", true));
527 else if ( $submit || $confirm )
530 // Submit post/vote (newtopic, edit, reply, etc.)
532 $return_message = '';
540 $username = ( !empty($HTTP_POST_VARS['username']) ) ? $HTTP_POST_VARS['username'] : '';
541 $subject = ( !empty($HTTP_POST_VARS['subject']) ) ? trim($HTTP_POST_VARS['subject']) : '';
542 $message = ( !empty($HTTP_POST_VARS['message']) ) ? $HTTP_POST_VARS['message'] : '';
543 $poll_title = ( isset($HTTP_POST_VARS['poll_title']) && $is_auth['auth_pollcreate'] ) ? $HTTP_POST_VARS['poll_title'] : '';
544 $poll_options = ( isset($HTTP_POST_VARS['poll_option_text']) && $is_auth['auth_pollcreate'] ) ? $HTTP_POST_VARS['poll_option_text'] : '';
545 $poll_length = ( isset($HTTP_POST_VARS['poll_length']) && $is_auth['auth_pollcreate'] ) ? $HTTP_POST_VARS['poll_length'] : '';
548 prepare_post($mode, $post_data, $bbcode_on, $html_on, $smilies_on, $error_msg, $username, $bbcode_uid, $subject, $message, $poll_title, $poll_options, $poll_length);
550 if ( $error_msg == '' )
552 $topic_type = ( $topic_type != $post_data['topic_type'] && !$is_auth['auth_sticky'] && !$is_auth['auth_announce'] ) ? $post_data['topic_type'] : $topic_type;
554 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);
560 delete_post($mode, $post_data, $return_message, $return_meta, $forum_id, $topic_id, $post_id, $poll_id);
564 if ( $error_msg == '' )
566 if ( $mode != 'editpost' )
568 $user_id = ( $mode == 'reply' || $mode == 'newtopic' ) ? $userdata['user_id'] : $post_data['poster_id'];
569 update_post_stats($mode, $post_data, $forum_id, $topic_id, $post_id, $user_id);
572 if ($error_msg == '' && $mode != 'poll_delete')
574 user_notification($mode, $post_data, $post_info['topic_title'], $forum_id, $topic_id, $post_id, $notify_user);
577 if ( $mode == 'newtopic' || $mode == 'reply' )
579 $tracking_topics = ( !empty($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) : array();
580 $tracking_forums = ( !empty($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) : array();
582 if ( count($tracking_topics) + count($tracking_forums) == 100 && empty($tracking_topics[$topic_id]) )
584 asort($tracking_topics);
585 unset($tracking_topics[key($tracking_topics)]);
588 $tracking_topics[$topic_id] = time();
590 setcookie($board_config['cookie_name'] . '_t', serialize($tracking_topics), 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
593 $template->assign_vars(array(
594 'META' => $return_meta)
596 message_die(GENERAL_MESSAGE, $return_message);
600 if( $refresh || isset($HTTP_POST_VARS['del_poll_option']) || $error_msg != '' )
602 $username = ( !empty($HTTP_POST_VARS['username']) ) ? htmlspecialchars(trim(stripslashes($HTTP_POST_VARS['username']))) : '';
603 $subject = ( !empty($HTTP_POST_VARS['subject']) ) ? htmlspecialchars(trim(stripslashes($HTTP_POST_VARS['subject']))) : '';
604 $message = ( !empty($HTTP_POST_VARS['message']) ) ? htmlspecialchars(trim(stripslashes($HTTP_POST_VARS['message']))) : '';
606 $poll_title = ( !empty($HTTP_POST_VARS['poll_title']) ) ? htmlspecialchars(trim(stripslashes($HTTP_POST_VARS['poll_title']))) : '';
607 $poll_length = ( isset($HTTP_POST_VARS['poll_length']) ) ? max(0, intval($HTTP_POST_VARS['poll_length'])) : 0;
609 $poll_options = array();
610 if ( !empty($HTTP_POST_VARS['poll_option_text']) )
612 while( list($option_id, $option_text) = @each($HTTP_POST_VARS['poll_option_text']) )
614 if( isset($HTTP_POST_VARS['del_poll_option'][$option_id]) )
616 unset($poll_options[$option_id]);
618 else if ( !empty($option_text) )
620 $poll_options[$option_id] = htmlspecialchars(trim(stripslashes($option_text)));
625 if ( isset($poll_add) && !empty($HTTP_POST_VARS['add_poll_option_text']) )
627 $poll_options[] = htmlspecialchars(trim(stripslashes($HTTP_POST_VARS['add_poll_option_text'])));
630 if ( $mode == 'newtopic' || $mode == 'reply')
632 $user_sig = ( $userdata['user_sig'] != '' && $board_config['allow_sig'] ) ? $userdata['user_sig'] : '';
634 else if ( $mode == 'editpost' )
636 $user_sig = ( $post_info['user_sig'] != '' && $board_config['allow_sig'] ) ? $post_info['user_sig'] : '';
641 $orig_word = array();
642 $replacement_word = array();
643 obtain_word_list($orig_word, $replacement_word);
645 $bbcode_uid = ( $bbcode_on ) ? make_bbcode_uid() : '';
646 $preview_message = stripslashes(prepare_message(addslashes(unprepare_message($message)), $html_on, $bbcode_on, $smilies_on, $bbcode_uid));
647 $preview_subject = $subject;
648 $preview_username = $username;
651 // Finalise processing as per viewtopic
655 if( $user_sig != '' || !$userdata['user_allowhtml'] )
657 $user_sig = preg_replace('#(<)([\/]?.*?)(>)#is', '<\2>', $user_sig);
661 if( $attach_sig && $user_sig != '' && $userdata['user_sig_bbcode_uid'] )
663 $user_sig = bbencode_second_pass($user_sig, $userdata['user_sig_bbcode_uid']);
668 $preview_message = bbencode_second_pass($preview_message, $bbcode_uid);
671 if( !empty($orig_word) )
673 $preview_username = ( !empty($username) ) ? preg_replace($orig_word, $replacement_word, $preview_username) : '';
674 $preview_subject = ( !empty($subject) ) ? preg_replace($orig_word, $replacement_word, $preview_subject) : '';
675 $preview_message = ( !empty($preview_message) ) ? preg_replace($orig_word, $replacement_word, $preview_message) : '';
678 if( $user_sig != '' )
680 $user_sig = make_clickable($user_sig);
682 $preview_message = make_clickable($preview_message);
686 if( $userdata['user_allowsmile'] && $user_sig != '' )
688 $user_sig = smilies_pass($user_sig);
691 $preview_message = smilies_pass($preview_message);
694 if( $attach_sig && $user_sig != '' )
696 $preview_message = $preview_message . '<br /><br />_________________<br />' . $user_sig;
699 $preview_message = str_replace("\n", '<br />', $preview_message);
701 $template->set_filenames(array(
702 'preview' => 'posting_preview.tpl')
705 $template->assign_vars(array(
706 'TOPIC_TITLE' => $preview_subject,
707 'POST_SUBJECT' => $preview_subject,
708 'POSTER_NAME' => $preview_username,
709 'POST_DATE' => create_date($board_config['default_dateformat'], time(), $board_config['board_timezone']),
710 'MESSAGE' => $preview_message,
712 'L_POST_SUBJECT' => $lang['Post_subject'],
713 'L_PREVIEW' => $lang['Preview'],
714 'L_POSTED' => $lang['Posted'],
715 'L_POST' => $lang['Post'])
717 $template->assign_var_from_handle('POST_PREVIEW_BOX', 'preview');
719 else if( $error_msg != '' )
721 $template->set_filenames(array(
722 'reg_header' => 'error_body.tpl')
724 $template->assign_vars(array(
725 'ERROR_MESSAGE' => $error_msg)
727 $template->assign_var_from_handle('ERROR_BOX', 'reg_header');
733 // User default entry point
735 if ( $mode == 'newtopic' )
737 $user_sig = ( $userdata['user_sig'] != '' ) ? $userdata['user_sig'] : '';
739 $username = ($userdata['session_logged_in']) ? $userdata['username'] : '';
745 else if ( $mode == 'reply' )
747 $user_sig = ( $userdata['user_sig'] != '' ) ? $userdata['user_sig'] : '';
749 $username = ( $userdata['session_logged_in'] ) ? $userdata['username'] : '';
754 else if ( $mode == 'quote' || $mode == 'editpost' )
756 $subject = ( $post_data['first_post'] ) ? $post_info['topic_title'] : $post_info['post_subject'];
757 $message = $post_info['post_text'];
759 if ( $mode == 'editpost' )
761 $attach_sig = ( $post_info['enable_sig'] && $post_info['user_sig'] != '' ) ? TRUE : 0;
762 $user_sig = $post_info['user_sig'];
764 $html_on = ( $post_info['enable_html'] ) ? true : false;
765 $bbcode_on = ( $post_info['enable_bbcode'] ) ? true : false;
766 $smilies_on = ( $post_info['enable_smilies'] ) ? true : false;
770 $attach_sig = ( $userdata['user_attachsig'] ) ? TRUE : 0;
771 $user_sig = $userdata['user_sig'];
774 if ( $post_info['bbcode_uid'] != '' )
776 $message = preg_replace('/\:(([a-z0-9]:)?)' . $post_info['bbcode_uid'] . '/s', '', $message);
779 $message = str_replace('<', '<', $message);
780 $message = str_replace('>', '>', $message);
781 $message = str_replace('<br />', "\n", $message);
783 if ( $mode == 'quote' )
785 $orig_word = array();
786 $replacement_word = array();
787 obtain_word_list($orig_word, $replace_word);
789 $msg_date = create_date($board_config['default_dateformat'], $postrow['post_time'], $board_config['board_timezone']);
791 // Use trim to get rid of spaces placed there by MS-SQL 2000
792 $quote_username = ( trim($post_info['post_username']) != '' ) ? $post_info['post_username'] : $post_info['username'];
793 $message = '[quote="' . $quote_username . '"]' . $message . '[/quote]';
795 if ( !empty($orig_word) )
797 $subject = ( !empty($subject) ) ? preg_replace($orig_word, $replace_word, $subject) : '';
798 $message = ( !empty($message) ) ? preg_replace($orig_word, $replace_word, $message) : '';
801 if ( !preg_match('/^Re:/', $subject) && strlen($subject) > 0 )
803 $subject = 'Re: ' . $subject;
810 $username = ( $post_info['user_id'] == ANONYMOUS && !empty($post_info['post_username']) ) ? $post_info['post_username'] : '';
816 // Signature toggle selection
818 if( $user_sig != '' )
820 $template->assign_block_vars('switch_signature_checkbox', array());
824 // HTML toggle selection
826 if ( $board_config['allow_html'] )
828 $html_status = $lang['HTML_is_ON'];
829 $template->assign_block_vars('switch_html_checkbox', array());
833 $html_status = $lang['HTML_is_OFF'];
837 // BBCode toggle selection
839 if ( $board_config['allow_bbcode'] )
841 $bbcode_status = $lang['BBCode_is_ON'];
842 $template->assign_block_vars('switch_bbcode_checkbox', array());
846 $bbcode_status = $lang['BBCode_is_OFF'];
850 // Smilies toggle selection
852 if ( $board_config['allow_smilies'] )
854 $smilies_status = $lang['Smilies_are_ON'];
855 $template->assign_block_vars('switch_smilies_checkbox', array());
859 $smilies_status = $lang['Smilies_are_OFF'];
862 if( !$userdata['session_logged_in'] || ( $mode == 'editpost' && $post_info['poster_id'] == ANONYMOUS ) )
864 $template->assign_block_vars('switch_username_select', array());
868 // Notify checkbox - only show if user is logged in
870 if ( $userdata['session_logged_in'] && $is_auth['auth_read'] )
872 if ( $mode != 'editpost' || ( $mode == 'editpost' && $post_info['poster_id'] != ANONYMOUS ) )
874 $template->assign_block_vars('switch_notify_checkbox', array());
881 if ( $mode == 'editpost' && ( ( $is_auth['auth_delete'] && $post_data['last_post'] && ( !$post_data['has_poll'] || $post_data['edit_poll'] ) ) || $is_auth['auth_mod'] ) )
883 $template->assign_block_vars('switch_delete_checkbox', array());
887 // Topic type selection
889 $topic_type_toggle = '';
890 if ( $mode == 'newtopic' || ( $mode == 'editpost' && $post_data['first_post'] ) )
892 $template->assign_block_vars('switch_type_toggle', array());
894 if( $is_auth['auth_sticky'] )
896 $topic_type_toggle .= '<input type="radio" name="topictype" value="' . POST_STICKY . '"';
897 if ( $post_data['topic_type'] == POST_STICKY || $topic_type == POST_STICKY )
899 $topic_type_toggle .= ' checked="checked"';
901 $topic_type_toggle .= ' /> ' . $lang['Post_Sticky'] . ' ';
904 if( $is_auth['auth_announce'] )
906 $topic_type_toggle .= '<input type="radio" name="topictype" value="' . POST_ANNOUNCE . '"';
907 if ( $post_data['topic_type'] == POST_ANNOUNCE || $topic_type == POST_ANNOUNCE )
909 $topic_type_toggle .= ' checked="checked"';
911 $topic_type_toggle .= ' /> ' . $lang['Post_Announcement'] . ' ';
914 if ( $topic_type_toggle != '' )
916 $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;
920 $hidden_form_fields = '<input type="hidden" name="mode" value="' . $mode . '" />';
925 $page_title = $lang['Post_a_new_topic'];
926 $hidden_form_fields .= '<input type="hidden" name="' . POST_FORUM_URL . '" value="' . $forum_id . '" />';
930 $page_title = $lang['Post_a_reply'];
931 $hidden_form_fields .= '<input type="hidden" name="' . POST_TOPIC_URL . '" value="' . $topic_id . '" />';
935 $page_title = $lang['Edit_Post'];
936 $hidden_form_fields .= '<input type="hidden" name="' . POST_POST_URL . '" value="' . $post_id . '" />';
940 // Generate smilies listing for page output
941 generate_smilies('inline', PAGE_POSTING);
944 // Include page header
946 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
948 $template->set_filenames(array(
949 'body' => 'posting_body.tpl',
950 'pollbody' => 'posting_poll_body.tpl',
951 'reviewbody' => 'posting_topic_review.tpl')
953 make_jumpbox('viewforum.'.$phpEx);
955 $template->assign_vars(array(
956 'FORUM_NAME' => $forum_name,
957 'L_POST_A' => $page_title,
958 'L_POST_SUBJECT' => $lang['Post_subject'],
960 'U_VIEW_FORUM' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id"))
964 // This enables the forum/topic title to be output for posting
965 // but not for privmsg (where it makes no sense)
967 $template->assign_block_vars('switch_not_privmsg', array());
970 // Output the data to the template
972 $template->assign_vars(array(
973 'USERNAME' => $username,
974 'SUBJECT' => $subject,
975 'MESSAGE' => $message,
976 'HTML_STATUS' => $html_status,
977 'BBCODE_STATUS' => sprintf($bbcode_status, '<a href="' . append_sid("faq.$phpEx?mode=bbcode") . '" target="_phpbbcode">', '</a>'),
978 'SMILIES_STATUS' => $smilies_status,
980 'L_SUBJECT' => $lang['Subject'],
981 'L_MESSAGE_BODY' => $lang['Message_body'],
982 'L_OPTIONS' => $lang['Options'],
983 'L_PREVIEW' => $lang['Preview'],
984 'L_SPELLCHECK' => $lang['Spellcheck'],
985 'L_SUBMIT' => $lang['Submit'],
986 'L_CANCEL' => $lang['Cancel'],
987 'L_CONFIRM_DELETE' => $lang['Confirm_delete'],
988 'L_DISABLE_HTML' => $lang['Disable_HTML_post'],
989 'L_DISABLE_BBCODE' => $lang['Disable_BBCode_post'],
990 'L_DISABLE_SMILIES' => $lang['Disable_Smilies_post'],
991 'L_ATTACH_SIGNATURE' => $lang['Attach_signature'],
992 'L_NOTIFY_ON_REPLY' => $lang['Notify'],
993 'L_DELETE_POST' => $lang['Delete_post'],
995 'L_BBCODE_B_HELP' => $lang['bbcode_b_help'],
996 'L_BBCODE_I_HELP' => $lang['bbcode_i_help'],
997 'L_BBCODE_U_HELP' => $lang['bbcode_u_help'],
998 'L_BBCODE_Q_HELP' => $lang['bbcode_q_help'],
999 'L_BBCODE_C_HELP' => $lang['bbcode_c_help'],
1000 'L_BBCODE_L_HELP' => $lang['bbcode_l_help'],
1001 'L_BBCODE_O_HELP' => $lang['bbcode_o_help'],
1002 'L_BBCODE_P_HELP' => $lang['bbcode_p_help'],
1003 'L_BBCODE_W_HELP' => $lang['bbcode_w_help'],
1004 'L_BBCODE_A_HELP' => $lang['bbcode_a_help'],
1005 'L_BBCODE_S_HELP' => $lang['bbcode_s_help'],
1006 'L_BBCODE_F_HELP' => $lang['bbcode_f_help'],
1007 'L_EMPTY_MESSAGE' => $lang['Empty_message'],
1009 'L_FONT_COLOR' => $lang['Font_color'],
1010 'L_COLOR_DEFAULT' => $lang['color_default'],
1011 'L_COLOR_DARK_RED' => $lang['color_dark_red'],
1012 'L_COLOR_RED' => $lang['color_red'],
1013 'L_COLOR_ORANGE' => $lang['color_orange'],
1014 'L_COLOR_BROWN' => $lang['color_brown'],
1015 'L_COLOR_YELLOW' => $lang['color_yellow'],
1016 'L_COLOR_GREEN' => $lang['color_green'],
1017 'L_COLOR_OLIVE' => $lang['color_olive'],
1018 'L_COLOR_CYAN' => $lang['color_cyan'],
1019 'L_COLOR_BLUE' => $lang['color_blue'],
1020 'L_COLOR_DARK_BLUE' => $lang['color_dark_blue'],
1021 'L_COLOR_INDIGO' => $lang['color_indigo'],
1022 'L_COLOR_VIOLET' => $lang['color_violet'],
1023 'L_COLOR_WHITE' => $lang['color_white'],
1024 'L_COLOR_BLACK' => $lang['color_black'],
1026 'L_FONT_SIZE' => $lang['Font_size'],
1027 'L_FONT_TINY' => $lang['font_tiny'],
1028 'L_FONT_SMALL' => $lang['font_small'],
1029 'L_FONT_NORMAL' => $lang['font_normal'],
1030 'L_FONT_LARGE' => $lang['font_large'],
1031 'L_FONT_HUGE' => $lang['font_huge'],
1033 'L_BBCODE_CLOSE_TAGS' => $lang['Close_Tags'],
1034 'L_STYLES_TIP' => $lang['Styles_tip'],
1036 'U_VIEWTOPIC' => ( $mode == 'reply' ) ? append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&postorder=desc") : '',
1037 'U_REVIEW_TOPIC' => ( $mode == 'reply' ) ? append_sid("posting.$phpEx?mode=topicreview&" . POST_TOPIC_URL . "=$topic_id") : '',
1039 'S_HTML_CHECKED' => ( !$html_on ) ? 'checked="checked"' : '',
1040 'S_BBCODE_CHECKED' => ( !$bbcode_on ) ? 'checked="checked"' : '',
1041 'S_SMILIES_CHECKED' => ( !$smilies_on ) ? 'checked="checked"' : '',
1042 'S_SIGNATURE_CHECKED' => ( $attach_sig ) ? 'checked="checked"' : '',
1043 'S_NOTIFY_CHECKED' => ( $notify_user ) ? 'checked="checked"' : '',
1044 'S_TYPE_TOGGLE' => $topic_type_toggle,
1045 'S_TOPIC_ID' => $topic_id,
1046 'S_POST_ACTION' => append_sid("posting.$phpEx"),
1047 'S_HIDDEN_FORM_FIELDS' => $hidden_form_fields)
1051 // Poll entry switch/output
1053 if( ( $mode == 'newtopic' || ( $mode == 'editpost' && $post_data['edit_poll']) ) && $is_auth['auth_pollcreate'] )
1055 $template->assign_vars(array(
1056 'L_ADD_A_POLL' => $lang['Add_poll'],
1057 'L_ADD_POLL_EXPLAIN' => $lang['Add_poll_explain'],
1058 'L_POLL_QUESTION' => $lang['Poll_question'],
1059 'L_POLL_OPTION' => $lang['Poll_option'],
1060 'L_ADD_OPTION' => $lang['Add_option'],
1061 'L_UPDATE_OPTION' => $lang['Update'],
1062 'L_DELETE_OPTION' => $lang['Delete'],
1063 'L_POLL_LENGTH' => $lang['Poll_for'],
1064 'L_DAYS' => $lang['Days'],
1065 'L_POLL_LENGTH_EXPLAIN' => $lang['Poll_for_explain'],
1066 'L_POLL_DELETE' => $lang['Delete_poll'],
1068 'POLL_TITLE' => $poll_title,
1069 'POLL_LENGTH' => $poll_length)
1072 if( $mode == 'editpost' && $post_data['edit_poll'] && $post_data['has_poll'])
1074 $template->assign_block_vars('switch_poll_delete_toggle', array());
1077 if( !empty($poll_options) )
1079 while( list($option_id, $option_text) = each($poll_options) )
1081 $template->assign_block_vars('poll_option_rows', array(
1082 'POLL_OPTION' => str_replace('"', '"', $option_text),
1084 'S_POLL_OPTION_NUM' => $option_id)
1089 $template->assign_var_from_handle('POLLBOX', 'pollbody');
1095 if( $mode == 'reply' && $is_auth['auth_read'] )
1097 require($phpbb_root_path . 'includes/topic_review.'.$phpEx);
1098 topic_review($topic_id, true);
1100 $template->assign_block_vars('switch_inline_mode', array());
1101 $template->assign_var_from_handle('TOPIC_REVIEW_BOX', 'reviewbody');
1104 $template->pparse('body');
1106 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);