Blame Extras/phpBB/3.0.4/posting.php

4c79b5
4c79b5
/**
4c79b5
*
4c79b5
* @package phpBB3
4c79b5
* @version $Id: posting.php 9048 2008-11-04 15:54:43Z toonarmy $
4c79b5
* @copyright (c) 2005 phpBB Group
4c79b5
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
4c79b5
*
4c79b5
*/
4c79b5
4c79b5
/**
4c79b5
* @ignore
4c79b5
*/
4c79b5
define('IN_PHPBB', true);
4c79b5
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
4c79b5
$phpEx = substr(strrchr(__FILE__, '.'), 1);
4c79b5
include($phpbb_root_path . 'common.' . $phpEx);
4c79b5
include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
4c79b5
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
4c79b5
include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
4c79b5
4c79b5
4c79b5
// Start session management
4c79b5
$user->session_begin();
4c79b5
$auth->acl($user->data);
4c79b5
4c79b5
4c79b5
// Grab only parameters needed here
4c79b5
$post_id	= request_var('p', 0);
4c79b5
$topic_id	= request_var('t', 0);
4c79b5
$forum_id	= request_var('f', 0);
4c79b5
$draft_id	= request_var('d', 0);
4c79b5
$lastclick	= request_var('lastclick', 0);
4c79b5
4c79b5
$submit		= (isset($_POST['post'])) ? true : false;
4c79b5
$preview	= (isset($_POST['preview'])) ? true : false;
4c79b5
$save		= (isset($_POST['save'])) ? true : false;
4c79b5
$load		= (isset($_POST['load'])) ? true : false;
4c79b5
$delete		= (isset($_POST['delete'])) ? true : false;
4c79b5
$cancel		= (isset($_POST['cancel']) && !isset($_POST['save'])) ? true : false;
4c79b5
4c79b5
$refresh	= (isset($_POST['add_file']) || isset($_POST['delete_file']) || isset($_POST['cancel_unglobalise']) || $save || $load) ? true : false;
4c79b5
$mode		= ($delete && !$preview && !$refresh && $submit) ? 'delete' : request_var('mode', '');
4c79b5
4c79b5
$error = $post_data = array();
4c79b5
$current_time = time();
4c79b5
4c79b5
4c79b5
// Was cancel pressed? If so then redirect to the appropriate page
4c79b5
if ($cancel || ($current_time - $lastclick < 2 && $submit))
4c79b5
{
4c79b5
	$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")));
4c79b5
	redirect($redirect);
4c79b5
}
4c79b5
4c79b5
if (in_array($mode, array('post', 'reply', 'quote', 'edit', 'delete')) && !$forum_id)
4c79b5
{
4c79b5
	trigger_error('NO_FORUM');
4c79b5
}
4c79b5
4c79b5
// We need to know some basic information in all cases before we do anything.
4c79b5
switch ($mode)
4c79b5
{
4c79b5
	case 'post':
4c79b5
		$sql = 'SELECT *
4c79b5
			FROM ' . FORUMS_TABLE . "
4c79b5
			WHERE forum_id = $forum_id";
4c79b5
	break;
4c79b5
4c79b5
	case 'bump':
4c79b5
	case 'reply':
4c79b5
		if (!$topic_id)
4c79b5
		{
4c79b5
			trigger_error('NO_TOPIC');
4c79b5
		}
4c79b5
4c79b5
		$sql = 'SELECT f.*, t.*
4c79b5
			FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f
4c79b5
			WHERE t.topic_id = $topic_id
4c79b5
				AND (f.forum_id = t.forum_id
4c79b5
					OR f.forum_id = $forum_id)";
4c79b5
	break;
4c79b5
4c79b5
	case 'quote':
4c79b5
	case 'edit':
4c79b5
	case 'delete':
4c79b5
		if (!$post_id)
4c79b5
		{
4c79b5
			$user->setup('posting');
4c79b5
			trigger_error('NO_POST');
4c79b5
		}
4c79b5
4c79b5
		$sql = 'SELECT f.*, t.*, p.*, u.username, u.username_clean, u.user_sig, u.user_sig_bbcode_uid, u.user_sig_bbcode_bitfield
4c79b5
			FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . ' f, ' . USERS_TABLE . " u
4c79b5
			WHERE p.post_id = $post_id
4c79b5
				AND t.topic_id = p.topic_id
4c79b5
				AND u.user_id = p.poster_id
4c79b5
				AND (f.forum_id = t.forum_id
4c79b5
					OR f.forum_id = $forum_id)";
4c79b5
	break;
4c79b5
4c79b5
	case 'smilies':
4c79b5
		$sql = '';
4c79b5
		generate_smilies('window', $forum_id);
4c79b5
	break;
4c79b5
4c79b5
	case 'popup':
4c79b5
		if ($forum_id)
4c79b5
		{
4c79b5
			$sql = 'SELECT forum_style
4c79b5
				FROM ' . FORUMS_TABLE . '
4c79b5
				WHERE forum_id = ' . $forum_id;
4c79b5
		}
4c79b5
		else
4c79b5
		{
4c79b5
			upload_popup();
4c79b5
			return;
4c79b5
		}
4c79b5
	break;
4c79b5
4c79b5
	default:
4c79b5
		$sql = '';
4c79b5
	break;
4c79b5
}
4c79b5
4c79b5
if (!$sql)
4c79b5
{
4c79b5
	$user->setup('posting');
4c79b5
	trigger_error('NO_POST_MODE');
4c79b5
}
4c79b5
4c79b5
$result = $db->sql_query($sql);
4c79b5
$post_data = $db->sql_fetchrow($result);
4c79b5
$db->sql_freeresult($result);
4c79b5
4c79b5
if (!$post_data)
4c79b5
{
4c79b5
	if (!($mode == 'post' || $mode == 'bump' || $mode == 'reply'))
4c79b5
	{
4c79b5
		$user->setup('posting');
4c79b5
	}
4c79b5
	trigger_error(($mode == 'post' || $mode == 'bump' || $mode == 'reply') ? 'NO_TOPIC' : 'NO_POST');
4c79b5
}
4c79b5
4c79b5
if ($mode == 'popup')
4c79b5
{
4c79b5
	upload_popup($post_data['forum_style']);
4c79b5
	return;
4c79b5
}
4c79b5
4c79b5
$user->setup(array('posting', 'mcp', 'viewtopic'), $post_data['forum_style']);
4c79b5
4c79b5
// Use post_row values in favor of submitted ones...
4c79b5
$forum_id	= (!empty($post_data['forum_id'])) ? (int) $post_data['forum_id'] : (int) $forum_id;
4c79b5
$topic_id	= (!empty($post_data['topic_id'])) ? (int) $post_data['topic_id'] : (int) $topic_id;
4c79b5
$post_id	= (!empty($post_data['post_id'])) ? (int) $post_data['post_id'] : (int) $post_id;
4c79b5
4c79b5
// Need to login to passworded forum first?
4c79b5
if ($post_data['forum_password'])
4c79b5
{
4c79b5
	login_forum_box(array(
4c79b5
		'forum_id'			=> $forum_id,
4c79b5
		'forum_password'	=> $post_data['forum_password'])
4c79b5
	);
4c79b5
}
4c79b5
4c79b5
// Check permissions
4c79b5
if ($user->data['is_bot'])
4c79b5
{
4c79b5
	redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
4c79b5
}
4c79b5
4c79b5
// Is the user able to read within this forum?
4c79b5
if (!$auth->acl_get('f_read', $forum_id))
4c79b5
{
4c79b5
	if ($user->data['user_id'] != ANONYMOUS)
4c79b5
	{
4c79b5
		trigger_error('USER_CANNOT_READ');
4c79b5
	}
4c79b5
4c79b5
	login_box('', $user->lang['LOGIN_EXPLAIN_POST']);
4c79b5
}
4c79b5
4c79b5
// Permission to do the action asked?
4c79b5
$is_authed = false;
4c79b5
4c79b5
switch ($mode)
4c79b5
{
4c79b5
	case 'post':
4c79b5
		if ($auth->acl_get('f_post', $forum_id))
4c79b5
		{
4c79b5
			$is_authed = true;
4c79b5
		}
4c79b5
	break;
4c79b5
4c79b5
	case 'bump':
4c79b5
		if ($auth->acl_get('f_bump', $forum_id))
4c79b5
		{
4c79b5
			$is_authed = true;
4c79b5
		}
4c79b5
	break;
4c79b5
4c79b5
	case 'quote':
4c79b5
4c79b5
		$post_data['post_edit_locked'] = 0;
4c79b5
4c79b5
	// no break;
4c79b5
4c79b5
	case 'reply':
4c79b5
		if ($auth->acl_get('f_reply', $forum_id))
4c79b5
		{
4c79b5
			$is_authed = true;
4c79b5
		}
4c79b5
	break;
4c79b5
4c79b5
	case 'edit':
4c79b5
		if ($user->data['is_registered'] && $auth->acl_gets('f_edit', 'm_edit', $forum_id))
4c79b5
		{
4c79b5
			$is_authed = true;
4c79b5
		}
4c79b5
	break;
4c79b5
4c79b5
	case 'delete':
4c79b5
		if ($user->data['is_registered'] && $auth->acl_gets('f_delete', 'm_delete', $forum_id))
4c79b5
		{
4c79b5
			$is_authed = true;
4c79b5
		}
4c79b5
	break;
4c79b5
}
4c79b5
4c79b5
if (!$is_authed)
4c79b5
{
4c79b5
	$check_auth = ($mode == 'quote') ? 'reply' : $mode;
4c79b5
4c79b5
	if ($user->data['is_registered'])
4c79b5
	{
4c79b5
		trigger_error('USER_CANNOT_' . strtoupper($check_auth));
4c79b5
	}
4c79b5
4c79b5
	login_box('', $user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)]);
4c79b5
}
4c79b5
4c79b5
// Is the user able to post within this forum?
4c79b5
if ($post_data['forum_type'] != FORUM_POST && in_array($mode, array('post', 'bump', 'quote', 'reply')))
4c79b5
{
4c79b5
	trigger_error('USER_CANNOT_FORUM_POST');
4c79b5
}
4c79b5
4c79b5
// Forum/Topic locked?
4c79b5
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))
4c79b5
{
4c79b5
	trigger_error(($post_data['forum_status'] == ITEM_LOCKED) ? 'FORUM_LOCKED' : 'TOPIC_LOCKED');
4c79b5
}
4c79b5
4c79b5
// Can we edit this post ... if we're a moderator with rights then always yes
4c79b5
// else it depends on editing times, lock status and if we're the correct user
4c79b5
if ($mode == 'edit' && !$auth->acl_get('m_edit', $forum_id))
4c79b5
{
4c79b5
	if ($user->data['user_id'] != $post_data['poster_id'])
4c79b5
	{
4c79b5
		trigger_error('USER_CANNOT_EDIT');
4c79b5
	}
4c79b5
4c79b5
	if (!($post_data['post_time'] > time() - ($config['edit_time'] * 60) || !$config['edit_time']))
4c79b5
	{
4c79b5
		trigger_error('CANNOT_EDIT_TIME');
4c79b5
	}
4c79b5
4c79b5
	if ($post_data['post_edit_locked'])
4c79b5
	{
4c79b5
		trigger_error('CANNOT_EDIT_POST_LOCKED');
4c79b5
	}
4c79b5
}
4c79b5
4c79b5
// Handle delete mode...
4c79b5
if ($mode == 'delete')
4c79b5
{
4c79b5
	handle_post_delete($forum_id, $topic_id, $post_id, $post_data);
4c79b5
	return;
4c79b5
}
4c79b5
4c79b5
// Handle bump mode...
4c79b5
if ($mode == 'bump')
4c79b5
{
4c79b5
	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'])
4c79b5
	   && check_link_hash(request_var('hash', ''), "topic_{$post_data['topic_id']}"))
4c79b5
	{
4c79b5
		$db->sql_transaction('begin');
4c79b5
4c79b5
		$sql = 'UPDATE ' . POSTS_TABLE . "
4c79b5
			SET post_time = $current_time
4c79b5
			WHERE post_id = {$post_data['topic_last_post_id']}
4c79b5
				AND topic_id = $topic_id";
4c79b5
		$db->sql_query($sql);
4c79b5
4c79b5
		$sql = 'UPDATE ' . TOPICS_TABLE . "
4c79b5
			SET topic_last_post_time = $current_time,
4c79b5
				topic_bumped = 1,
4c79b5
				topic_bumper = " . $user->data['user_id'] . "
4c79b5
			WHERE topic_id = $topic_id";
4c79b5
		$db->sql_query($sql);
4c79b5
4c79b5
		update_post_information('forum', $forum_id);
4c79b5
4c79b5
		$sql = 'UPDATE ' . USERS_TABLE . "
4c79b5
			SET user_lastpost_time = $current_time
4c79b5
			WHERE user_id = " . $user->data['user_id'];
4c79b5
		$db->sql_query($sql);
4c79b5
4c79b5
		$db->sql_transaction('commit');
4c79b5
4c79b5
		markread('post', $forum_id, $topic_id, $current_time);
4c79b5
4c79b5
		add_log('mod', $forum_id, $topic_id, 'LOG_BUMP_TOPIC', $post_data['topic_title']);
4c79b5
4c79b5
		$meta_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id&p={$post_data['topic_last_post_id']}") . "#p{$post_data['topic_last_post_id']}";
4c79b5
		meta_refresh(3, $meta_url);
4c79b5
4c79b5
		$message = $user->lang['TOPIC_BUMPED'] . '

' . sprintf($user->lang['VIEW_MESSAGE'], '', '');
4c79b5
		$message .= '

' . sprintf($user->lang['RETURN_FORUM'], '', '');
4c79b5
4c79b5
		trigger_error($message);
4c79b5
	}
4c79b5
4c79b5
	trigger_error('BUMP_ERROR');
4c79b5
}
4c79b5
4c79b5
// Subject length limiting to 60 characters if first post...
4c79b5
if ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_data['post_id']))
4c79b5
{
4c79b5
	$template->assign_var('S_NEW_MESSAGE', true);
4c79b5
}
4c79b5
4c79b5
// Determine some vars
4c79b5
if (isset($post_data['poster_id']) && $post_data['poster_id'] == ANONYMOUS)
4c79b5
{
4c79b5
	$post_data['quote_username'] = (!empty($post_data['post_username'])) ? $post_data['post_username'] : $user->lang['GUEST'];
4c79b5
}
4c79b5
else
4c79b5
{
4c79b5
	$post_data['quote_username'] = isset($post_data['username']) ? $post_data['username'] : '';
4c79b5
}
4c79b5
4c79b5
$post_data['post_edit_locked']	= (isset($post_data['post_edit_locked'])) ? (int) $post_data['post_edit_locked'] : 0;
4c79b5
$post_data['post_subject']		= (in_array($mode, array('quote', 'edit'))) ? $post_data['post_subject'] : ((isset($post_data['topic_title'])) ? $post_data['topic_title'] : '');
4c79b5
$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;
4c79b5
$post_data['poll_length']		= (!empty($post_data['poll_length'])) ? (int) $post_data['poll_length'] / 86400 : 0;
4c79b5
$post_data['poll_start']		= (!empty($post_data['poll_start'])) ? (int) $post_data['poll_start'] : 0;
4c79b5
$post_data['icon_id']			= (!isset($post_data['icon_id']) || in_array($mode, array('quote', 'reply'))) ? 0 : (int) $post_data['icon_id'];
4c79b5
$post_data['poll_options']		= array();
4c79b5
4c79b5
// Get Poll Data
4c79b5
if ($post_data['poll_start'])
4c79b5
{
4c79b5
	$sql = 'SELECT poll_option_text
4c79b5
		FROM ' . POLL_OPTIONS_TABLE . "
4c79b5
		WHERE topic_id = $topic_id
4c79b5
		ORDER BY poll_option_id";
4c79b5
	$result = $db->sql_query($sql);
4c79b5
4c79b5
	while ($row = $db->sql_fetchrow($result))
4c79b5
	{
4c79b5
		$post_data['poll_options'][] = trim($row['poll_option_text']);
4c79b5
	}
4c79b5
	$db->sql_freeresult($result);
4c79b5
}
4c79b5
4c79b5
$orig_poll_options_size = sizeof($post_data['poll_options']);
4c79b5
4c79b5
$message_parser = new parse_message();
4c79b5
4c79b5
if (isset($post_data['post_text']))
4c79b5
{
4c79b5
	$message_parser->message = &$post_data['post_text'];
4c79b5
	unset($post_data['post_text']);
4c79b5
}
4c79b5
4c79b5
// Set some default variables
4c79b5
$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);
4c79b5
4c79b5
foreach ($uninit as $var_name => $default_value)
4c79b5
{
4c79b5
	if (!isset($post_data[$var_name]))
4c79b5
	{
4c79b5
		$post_data[$var_name] = $default_value;
4c79b5
	}
4c79b5
}
4c79b5
unset($uninit);
4c79b5
4c79b5
// Always check if the submitted attachment data is valid and belongs to the user.
4c79b5
// Further down (especially in submit_post()) we do not check this again.
4c79b5
$message_parser->get_submitted_attachment_data($post_data['poster_id']);
4c79b5
4c79b5
if ($post_data['post_attachment'] && !$submit && !$refresh && !$preview && $mode == 'edit')
4c79b5
{
4c79b5
	// Do not change to SELECT *
4c79b5
	$sql = 'SELECT attach_id, is_orphan, attach_comment, real_filename
4c79b5
		FROM ' . ATTACHMENTS_TABLE . "
4c79b5
		WHERE post_msg_id = $post_id
4c79b5
			AND in_message = 0
4c79b5
			AND is_orphan = 0
4c79b5
		ORDER BY filetime DESC";
4c79b5
	$result = $db->sql_query($sql);
4c79b5
	$message_parser->attachment_data = array_merge($message_parser->attachment_data, $db->sql_fetchrowset($result));
4c79b5
	$db->sql_freeresult($result);
4c79b5
}
4c79b5
4c79b5
if ($post_data['poster_id'] == ANONYMOUS)
4c79b5
{
4c79b5
	$post_data['username'] = ($mode == 'quote' || $mode == 'edit') ? trim($post_data['post_username']) : '';
4c79b5
}
4c79b5
else
4c79b5
{
4c79b5
	$post_data['username'] = ($mode == 'quote' || $mode == 'edit') ? trim($post_data['username']) : '';
4c79b5
}
4c79b5
4c79b5
$post_data['enable_urls'] = $post_data['enable_magic_url'];
4c79b5
4c79b5
if ($mode != 'edit')
4c79b5
{
4c79b5
	$post_data['enable_sig']		= ($config['allow_sig'] && $user->optionget('attachsig')) ? true: false;
4c79b5
	$post_data['enable_smilies']	= ($config['allow_smilies'] && $user->optionget('smilies')) ? true : false;
4c79b5
	$post_data['enable_bbcode']		= ($config['allow_bbcode'] && $user->optionget('bbcode')) ? true : false;
4c79b5
	$post_data['enable_urls']		= true;
4c79b5
}
4c79b5
4c79b5
$post_data['enable_magic_url'] = $post_data['drafts'] = false;
4c79b5
4c79b5
// User own some drafts?
4c79b5
if ($user->data['is_registered'] && $auth->acl_get('u_savedrafts') && ($mode == 'reply' || $mode == 'post' || $mode == 'quote'))
4c79b5
{
4c79b5
	$sql = 'SELECT draft_id
4c79b5
		FROM ' . DRAFTS_TABLE . '
4c79b5
		WHERE user_id = ' . $user->data['user_id'] .
4c79b5
			(($forum_id) ? ' AND forum_id = ' . (int) $forum_id : '') .
4c79b5
			(($topic_id) ? ' AND topic_id = ' . (int) $topic_id : '') .
4c79b5
			(($draft_id) ? " AND draft_id <> $draft_id" : '');
4c79b5
	$result = $db->sql_query_limit($sql, 1);
4c79b5
4c79b5
	if ($db->sql_fetchrow($result))
4c79b5
	{
4c79b5
		$post_data['drafts'] = true;
4c79b5
	}
4c79b5
	$db->sql_freeresult($result);
4c79b5
}
4c79b5
4c79b5
$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);
4c79b5
4c79b5
// Check if user is watching this topic
4c79b5
if ($mode != 'post' && $config['allow_topic_notify'] && $user->data['is_registered'])
4c79b5
{
4c79b5
	$sql = 'SELECT topic_id
4c79b5
		FROM ' . TOPICS_WATCH_TABLE . '
4c79b5
		WHERE topic_id = ' . $topic_id . '
4c79b5
			AND user_id = ' . $user->data['user_id'];
4c79b5
	$result = $db->sql_query($sql);
4c79b5
	$post_data['notify_set'] = (int) $db->sql_fetchfield('topic_id');
4c79b5
	$db->sql_freeresult($result);
4c79b5
}
4c79b5
4c79b5
// Do we want to edit our post ?
4c79b5
if ($mode == 'edit' && $post_data['bbcode_uid'])
4c79b5
{
4c79b5
	$message_parser->bbcode_uid = $post_data['bbcode_uid'];
4c79b5
}
4c79b5
4c79b5
// HTML, BBCode, Smilies, Images and Flash status
4c79b5
$bbcode_status	= ($config['allow_bbcode'] && $auth->acl_get('f_bbcode', $forum_id)) ? true : false;
4c79b5
$smilies_status	= ($bbcode_status && $config['allow_smilies'] && $auth->acl_get('f_smilies', $forum_id)) ? true : false;
4c79b5
$img_status		= ($bbcode_status && $auth->acl_get('f_img', $forum_id)) ? true : false;
4c79b5
$url_status		= ($config['allow_post_links']) ? true : false;
4c79b5
$flash_status	= ($bbcode_status && $auth->acl_get('f_flash', $forum_id) && $config['allow_post_flash']) ? true : false;
4c79b5
$quote_status	= ($auth->acl_get('f_reply', $forum_id)) ? true : false;
4c79b5
4c79b5
// Save Draft
4c79b5
if ($save && $user->data['is_registered'] && $auth->acl_get('u_savedrafts') && ($mode == 'reply' || $mode == 'post' || $mode == 'quote'))
4c79b5
{
4c79b5
	$subject = utf8_normalize_nfc(request_var('subject', '', true));
4c79b5
	$subject = (!$subject && $mode != 'post') ? $post_data['topic_title'] : $subject;
4c79b5
	$message = utf8_normalize_nfc(request_var('message', '', true));
4c79b5
4c79b5
	if ($subject && $message)
4c79b5
	{
4c79b5
		if (confirm_box(true))
4c79b5
		{
4c79b5
			$sql = 'INSERT INTO ' . DRAFTS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
4c79b5
				'user_id'		=> (int) $user->data['user_id'],
4c79b5
				'topic_id'		=> (int) $topic_id,
4c79b5
				'forum_id'		=> (int) $forum_id,
4c79b5
				'save_time'		=> (int) $current_time,
4c79b5
				'draft_subject'	=> (string) $subject,
4c79b5
				'draft_message'	=> (string) $message)
4c79b5
			);
4c79b5
			$db->sql_query($sql);
4c79b5
4c79b5
			$meta_info = ($mode == 'post') ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) : append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id");
4c79b5
4c79b5
			meta_refresh(3, $meta_info);
4c79b5
4c79b5
			$message = $user->lang['DRAFT_SAVED'] . '

';
4c79b5
			$message .= ($mode != 'post') ? sprintf($user->lang['RETURN_TOPIC'], '', '') . '

' : '';
4c79b5
			$message .= sprintf($user->lang['RETURN_FORUM'], '', '');
4c79b5
4c79b5
			trigger_error($message);
4c79b5
		}
4c79b5
		else
4c79b5
		{
4c79b5
			$s_hidden_fields = build_hidden_fields(array(
4c79b5
				'mode'		=> $mode,
4c79b5
				'save'		=> true,
4c79b5
				'f'			=> $forum_id,
4c79b5
				't'			=> $topic_id,
4c79b5
				'subject'	=> $subject,
4c79b5
				'message'	=> $message,
4c79b5
				'attachment_data' => $message_parser->attachment_data,
4c79b5
				)
4c79b5
			);
4c79b5
4c79b5
			confirm_box(false, 'SAVE_DRAFT', $s_hidden_fields);
4c79b5
		}
4c79b5
	}
4c79b5
	else
4c79b5
	{
4c79b5
		if (utf8_clean_string($subject) === '')
4c79b5
		{
4c79b5
			$error[] = $user->lang['EMPTY_SUBJECT'];
4c79b5
		}
4c79b5
4c79b5
		if (utf8_clean_string($message) === '')
4c79b5
		{
4c79b5
			$error[] = $user->lang['TOO_FEW_CHARS'];
4c79b5
		}
4c79b5
	}
4c79b5
	unset($subject, $message);
4c79b5
}
4c79b5
4c79b5
// Load requested Draft
4c79b5
if ($draft_id && ($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $user->data['is_registered'] && $auth->acl_get('u_savedrafts'))
4c79b5
{
4c79b5
	$sql = 'SELECT draft_subject, draft_message
4c79b5
		FROM ' . DRAFTS_TABLE . "
4c79b5
		WHERE draft_id = $draft_id
4c79b5
			AND user_id = " . $user->data['user_id'];
4c79b5
	$result = $db->sql_query_limit($sql, 1);
4c79b5
	$row = $db->sql_fetchrow($result);
4c79b5
	$db->sql_freeresult($result);
4c79b5
4c79b5
	if ($row)
4c79b5
	{
4c79b5
		$post_data['post_subject'] = $row['draft_subject'];
4c79b5
		$message_parser->message = $row['draft_message'];
4c79b5
4c79b5
		$template->assign_var('S_DRAFT_LOADED', true);
4c79b5
	}
4c79b5
	else
4c79b5
	{
4c79b5
		$draft_id = 0;
4c79b5
	}
4c79b5
}
4c79b5
4c79b5
// Load draft overview
4c79b5
if ($load && ($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $post_data['drafts'])
4c79b5
{
4c79b5
	load_drafts($topic_id, $forum_id);
4c79b5
}
4c79b5
4c79b5
$solved_captcha = false;
4c79b5
4c79b5
if ($submit || $preview || $refresh)
4c79b5
{
4c79b5
	$post_data['topic_cur_post_id']	= request_var('topic_cur_post_id', 0);
4c79b5
	$post_data['post_subject']		= utf8_normalize_nfc(request_var('subject', '', true));
4c79b5
	$message_parser->message		= utf8_normalize_nfc(request_var('message', '', true));
4c79b5
4c79b5
	$post_data['username']			= utf8_normalize_nfc(request_var('username', $post_data['username'], true));
4c79b5
	$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)) : '';
4c79b5
4c79b5
	$post_data['orig_topic_type']	= $post_data['topic_type'];
4c79b5
	$post_data['topic_type']		= request_var('topic_type', (($mode != 'post') ? (int) $post_data['topic_type'] : POST_NORMAL));
4c79b5
	$post_data['topic_time_limit']	= request_var('topic_time_limit', (($mode != 'post') ? (int) $post_data['topic_time_limit'] : 0));
4c79b5
	$post_data['icon_id']			= request_var('icon', 0);
4c79b5
4c79b5
	$post_data['enable_bbcode']		= (!$bbcode_status || isset($_POST['disable_bbcode'])) ? false : true;
4c79b5
	$post_data['enable_smilies']	= (!$smilies_status || isset($_POST['disable_smilies'])) ? false : true;
4c79b5
	$post_data['enable_urls']		= (isset($_POST['disable_magic_url'])) ? 0 : 1;
4c79b5
	$post_data['enable_sig']		= (!$config['allow_sig'] || !$auth->acl_get('f_sigs', $forum_id) || !$auth->acl_get('u_sig')) ? false : ((isset($_POST['attach_sig']) && $user->data['is_registered']) ? true : false);
4c79b5
4c79b5
	if ($config['allow_topic_notify'] && $user->data['is_registered'])
4c79b5
	{
4c79b5
		$notify = (isset($_POST['notify'])) ? true : false;
4c79b5
	}
4c79b5
	else
4c79b5
	{
4c79b5
		$notify = false;
4c79b5
	}
4c79b5
4c79b5
	$topic_lock			= (isset($_POST['lock_topic'])) ? true : false;
4c79b5
	$post_lock			= (isset($_POST['lock_post'])) ? true : false;
4c79b5
	$poll_delete		= (isset($_POST['poll_delete'])) ? true : false;
4c79b5
4c79b5
	if ($submit)
4c79b5
	{
4c79b5
		$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);
4c79b5
		$status_switch = ($status_switch != $check_value);
4c79b5
	}
4c79b5
	else
4c79b5
	{
4c79b5
		$status_switch = 1;
4c79b5
	}
4c79b5
4c79b5
	// Delete Poll
4c79b5
	if ($poll_delete && $mode == 'edit' && sizeof($post_data['poll_options']) &&
4c79b5
		((!$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)))
4c79b5
	{
4c79b5
		if ($submit && check_form_key('posting'))
4c79b5
		{
4c79b5
			$sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . "
4c79b5
				WHERE topic_id = $topic_id";
4c79b5
			$db->sql_query($sql);
4c79b5
4c79b5
			$sql = 'DELETE FROM ' . POLL_VOTES_TABLE . "
4c79b5
				WHERE topic_id = $topic_id";
4c79b5
			$db->sql_query($sql);
4c79b5
4c79b5
			$topic_sql = array(
4c79b5
				'poll_title'		=> '',
4c79b5
				'poll_start' 		=> 0,
4c79b5
				'poll_length'		=> 0,
4c79b5
				'poll_last_vote'	=> 0,
4c79b5
				'poll_max_options'	=> 0,
4c79b5
				'poll_vote_change'	=> 0
4c79b5
			);
4c79b5
4c79b5
			$sql = 'UPDATE ' . TOPICS_TABLE . '
4c79b5
				SET ' . $db->sql_build_array('UPDATE', $topic_sql) . "
4c79b5
				WHERE topic_id = $topic_id";
4c79b5
			$db->sql_query($sql);
4c79b5
		}
4c79b5
4c79b5
		$post_data['poll_title'] = $post_data['poll_option_text'] = '';
4c79b5
		$post_data['poll_vote_change'] = $post_data['poll_max_options'] = $post_data['poll_length'] = 0;
4c79b5
	}
4c79b5
	else
4c79b5
	{
4c79b5
		$post_data['poll_title']		= utf8_normalize_nfc(request_var('poll_title', '', true));
4c79b5
		$post_data['poll_length']		= request_var('poll_length', 0);
4c79b5
		$post_data['poll_option_text']	= utf8_normalize_nfc(request_var('poll_option_text', '', true));
4c79b5
		$post_data['poll_max_options']	= request_var('poll_max_options', 1);
4c79b5
		$post_data['poll_vote_change']	= ($auth->acl_get('f_votechg', $forum_id) && isset($_POST['poll_vote_change'])) ? 1 : 0;
4c79b5
	}
4c79b5
4c79b5
	// If replying/quoting and last post id has changed
4c79b5
	// give user option to continue submit or return to post
4c79b5
	// notify and show user the post made between his request and the final submit
4c79b5
	if (($mode == 'reply' || $mode == 'quote') && $post_data['topic_cur_post_id'] && $post_data['topic_cur_post_id'] != $post_data['topic_last_post_id'])
4c79b5
	{
4c79b5
		// Only do so if it is allowed forum-wide
4c79b5
		if ($post_data['forum_flags'] & FORUM_FLAG_POST_REVIEW)
4c79b5
		{
4c79b5
			if (topic_review($topic_id, $forum_id, 'post_review', $post_data['topic_cur_post_id']))
4c79b5
			{
4c79b5
				$template->assign_var('S_POST_REVIEW', true);
4c79b5
			}
4c79b5
4c79b5
			$submit = false;
4c79b5
			$refresh = true;
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	// Parse Attachments - before checksum is calculated
4c79b5
	$message_parser->parse_attachments('fileupload', $mode, $forum_id, $submit, $preview, $refresh);
4c79b5
4c79b5
	// Grab md5 'checksum' of new message
4c79b5
	$message_md5 = md5($message_parser->message);
4c79b5
4c79b5
	// Check checksum ... don't re-parse message if the same
4c79b5
	$update_message = ($mode != 'edit' || $message_md5 != $post_data['post_checksum'] || $status_switch || strlen($post_data['bbcode_uid']) < BBCODE_UID_LEN) ? true : false;
4c79b5
4c79b5
	// Parse message
4c79b5
	if ($update_message)
4c79b5
	{
4c79b5
		if (sizeof($message_parser->warn_msg))
4c79b5
		{
4c79b5
			$error[] = implode('
', $message_parser->warn_msg);
4c79b5
			$message_parser->warn_msg = array();
4c79b5
		}
4c79b5
4c79b5
		$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']);
4c79b5
4c79b5
		// On a refresh we do not care about message parsing errors
4c79b5
		if (sizeof($message_parser->warn_msg) && $refresh)
4c79b5
		{
4c79b5
			$message_parser->warn_msg = array();
4c79b5
		}
4c79b5
	}
4c79b5
	else
4c79b5
	{
4c79b5
		$message_parser->bbcode_bitfield = $post_data['bbcode_bitfield'];
4c79b5
	}
4c79b5
4c79b5
	if ($mode != 'edit' && !$preview && !$refresh && $config['flood_interval'] && !$auth->acl_get('f_ignoreflood', $forum_id))
4c79b5
	{
4c79b5
		// Flood check
4c79b5
		$last_post_time = 0;
4c79b5
4c79b5
		if ($user->data['is_registered'])
4c79b5
		{
4c79b5
			$last_post_time = $user->data['user_lastpost_time'];
4c79b5
		}
4c79b5
		else
4c79b5
		{
4c79b5
			$sql = 'SELECT post_time AS last_post_time
4c79b5
				FROM ' . POSTS_TABLE . "
4c79b5
				WHERE poster_ip = '" . $user->ip . "'
4c79b5
					AND post_time > " . ($current_time - $config['flood_interval']);
4c79b5
			$result = $db->sql_query_limit($sql, 1);
4c79b5
			if ($row = $db->sql_fetchrow($result))
4c79b5
			{
4c79b5
				$last_post_time = $row['last_post_time'];
4c79b5
			}
4c79b5
			$db->sql_freeresult($result);
4c79b5
		}
4c79b5
4c79b5
		if ($last_post_time && ($current_time - $last_post_time) < intval($config['flood_interval']))
4c79b5
		{
4c79b5
			$error[] = $user->lang['FLOOD_ERROR'];
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	// Validate username
4c79b5
	if (($post_data['username'] && !$user->data['is_registered']) || ($mode == 'edit' && $post_data['poster_id'] == ANONYMOUS && $post_data['username'] && $post_data['post_username'] && $post_data['post_username'] != $post_data['username']))
4c79b5
	{
4c79b5
		include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
4c79b5
4c79b5
		if (($result = validate_username($post_data['username'], (!empty($post_data['post_username'])) ? $post_data['post_username'] : '')) !== false)
4c79b5
		{
4c79b5
			$user->add_lang('ucp');
4c79b5
			$error[] = $user->lang[$result . '_USERNAME'];
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	if ($config['enable_post_confirm'] && !$user->data['is_registered'] && in_array($mode, array('quote', 'post', 'reply')))
4c79b5
	{
4c79b5
		$confirm_id = request_var('confirm_id', '');
4c79b5
		$confirm_code = request_var('confirm_code', '');
4c79b5
4c79b5
		$sql = 'SELECT code
4c79b5
			FROM ' . CONFIRM_TABLE . "
4c79b5
			WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "'
4c79b5
				AND session_id = '" . $db->sql_escape($user->session_id) . "'
4c79b5
				AND confirm_type = " . CONFIRM_POST;
4c79b5
		$result = $db->sql_query($sql);
4c79b5
		$confirm_row = $db->sql_fetchrow($result);
4c79b5
		$db->sql_freeresult($result);
4c79b5
4c79b5
		if (empty($confirm_row['code']) || strcasecmp($confirm_row['code'], $confirm_code) !== 0)
4c79b5
		{
4c79b5
			$error[] = $user->lang['CONFIRM_CODE_WRONG'];
4c79b5
		}
4c79b5
		else
4c79b5
		{
4c79b5
			$solved_captcha = true;
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	// check form
4c79b5
	if (($submit || $preview) && !check_form_key('posting'))
4c79b5
	{
4c79b5
		$error[] = $user->lang['FORM_INVALID'];
4c79b5
	}
4c79b5
4c79b5
	// Parse subject
4c79b5
	if (!$preview && !$refresh && utf8_clean_string($post_data['post_subject']) === '' && ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_id)))
4c79b5
	{
4c79b5
		$error[] = $user->lang['EMPTY_SUBJECT'];
4c79b5
	}
4c79b5
4c79b5
	$post_data['poll_last_vote'] = (isset($post_data['poll_last_vote'])) ? $post_data['poll_last_vote'] : 0;
4c79b5
4c79b5
	if ($post_data['poll_option_text'] &&
4c79b5
		($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id']/* && (!$post_data['poll_last_vote'] || $auth->acl_get('m_edit', $forum_id))*/))
4c79b5
		&& $auth->acl_get('f_poll', $forum_id))
4c79b5
	{
4c79b5
		$poll = array(
4c79b5
			'poll_title'		=> $post_data['poll_title'],
4c79b5
			'poll_length'		=> $post_data['poll_length'],
4c79b5
			'poll_max_options'	=> $post_data['poll_max_options'],
4c79b5
			'poll_option_text'	=> $post_data['poll_option_text'],
4c79b5
			'poll_start'		=> $post_data['poll_start'],
4c79b5
			'poll_last_vote'	=> $post_data['poll_last_vote'],
4c79b5
			'poll_vote_change'	=> $post_data['poll_vote_change'],
4c79b5
			'enable_bbcode'		=> $post_data['enable_bbcode'],
4c79b5
			'enable_urls'		=> $post_data['enable_urls'],
4c79b5
			'enable_smilies'	=> $post_data['enable_smilies'],
4c79b5
			'img_status'		=> $img_status
4c79b5
		);
4c79b5
4c79b5
		$message_parser->parse_poll($poll);
4c79b5
4c79b5
		$post_data['poll_options'] = (isset($poll['poll_options'])) ? $poll['poll_options'] : '';
4c79b5
		$post_data['poll_title'] = (isset($poll['poll_title'])) ? $poll['poll_title'] : '';
4c79b5
4c79b5
		/* We reset votes, therefore also allow removing options
4c79b5
		if ($post_data['poll_last_vote'] && ($poll['poll_options_size'] < $orig_poll_options_size))
4c79b5
		{
4c79b5
			$message_parser->warn_msg[] = $user->lang['NO_DELETE_POLL_OPTIONS'];
4c79b5
		}*/
4c79b5
	}
4c79b5
	else
4c79b5
	{
4c79b5
		$poll = array();
4c79b5
	}
4c79b5
4c79b5
	// Check topic type
4c79b5
	if ($post_data['topic_type'] != POST_NORMAL && ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_id)))
4c79b5
	{
4c79b5
		switch ($post_data['topic_type'])
4c79b5
		{
4c79b5
			case POST_GLOBAL:
4c79b5
			case POST_ANNOUNCE:
4c79b5
				$auth_option = 'f_announce';
4c79b5
			break;
4c79b5
4c79b5
			case POST_STICKY:
4c79b5
				$auth_option = 'f_sticky';
4c79b5
			break;
4c79b5
4c79b5
			default:
4c79b5
				$auth_option = '';
4c79b5
			break;
4c79b5
		}
4c79b5
4c79b5
		if (!$auth->acl_get($auth_option, $forum_id))
4c79b5
		{
4c79b5
			// There is a special case where a user edits his post whereby the topic type got changed by an admin/mod.
4c79b5
			// Another case would be a mod not having sticky permissions for example but edit permissions.
4c79b5
			if ($mode == 'edit')
4c79b5
			{
4c79b5
				// To prevent non-authed users messing around with the topic type we reset it to the original one.
4c79b5
				$post_data['topic_type'] = $post_data['orig_topic_type'];
4c79b5
			}
4c79b5
			else
4c79b5
			{
4c79b5
				$error[] = $user->lang['CANNOT_POST_' . str_replace('F_', '', strtoupper($auth_option))];
4c79b5
			}
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	if (sizeof($message_parser->warn_msg))
4c79b5
	{
4c79b5
		$error[] = implode('
', $message_parser->warn_msg);
4c79b5
	}
4c79b5
4c79b5
	// DNSBL check
4c79b5
	if ($config['check_dnsbl'] && !$refresh)
4c79b5
	{
4c79b5
		if (($dnsbl = $user->check_dnsbl('post')) !== false)
4c79b5
		{
4c79b5
			$error[] = sprintf($user->lang['IP_BLACKLISTED'], $user->ip, $dnsbl[1]);
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	// Store message, sync counters
4c79b5
	if (!sizeof($error) && $submit)
4c79b5
	{
4c79b5
		// Check if we want to de-globalize the topic... and ask for new forum
4c79b5
		if ($post_data['topic_type'] != POST_GLOBAL)
4c79b5
		{
4c79b5
			$sql = 'SELECT topic_type, forum_id
4c79b5
				FROM ' . TOPICS_TABLE . "
4c79b5
				WHERE topic_id = $topic_id";
4c79b5
			$result = $db->sql_query($sql);
4c79b5
			$row = $db->sql_fetchrow($result);
4c79b5
			$db->sql_freeresult($result);
4c79b5
4c79b5
			if ($row && !$row['forum_id'] && $row['topic_type'] == POST_GLOBAL)
4c79b5
			{
4c79b5
				$to_forum_id = request_var('to_forum_id', 0);
4c79b5
4c79b5
				if ($to_forum_id)
4c79b5
				{
4c79b5
					$sql = 'SELECT forum_type
4c79b5
						FROM ' . FORUMS_TABLE . '
4c79b5
						WHERE forum_id = ' . $to_forum_id;
4c79b5
					$result = $db->sql_query($sql);
4c79b5
					$forum_type = (int) $db->sql_fetchfield('forum_type');
4c79b5
					$db->sql_freeresult($result);
4c79b5
4c79b5
					if ($forum_type != FORUM_POST || !$auth->acl_get('f_post', $to_forum_id))
4c79b5
					{
4c79b5
						$to_forum_id = 0;
4c79b5
					}
4c79b5
				}
4c79b5
4c79b5
				if (!$to_forum_id)
4c79b5
				{
4c79b5
					include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
4c79b5
4c79b5
					$template->assign_vars(array(
4c79b5
						'S_FORUM_SELECT'	=> make_forum_select(false, false, false, true, true, true),
4c79b5
						'S_UNGLOBALISE'		=> true)
4c79b5
					);
4c79b5
4c79b5
					$submit = false;
4c79b5
					$refresh = true;
4c79b5
				}
4c79b5
				else
4c79b5
				{
4c79b5
					if (!$auth->acl_get('f_post', $to_forum_id))
4c79b5
					{
4c79b5
						// This will only be triggered if the user tried to trick the forum.
4c79b5
						trigger_error('NOT_AUTHORISED');
4c79b5
					}
4c79b5
4c79b5
					$forum_id = $to_forum_id;
4c79b5
				}
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		if ($submit)
4c79b5
		{
4c79b5
			// Lock/Unlock Topic
4c79b5
			$change_topic_status = $post_data['topic_status'];
4c79b5
			$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;
4c79b5
4c79b5
			if ($post_data['topic_status'] == ITEM_LOCKED && !$topic_lock && $perm_lock_unlock)
4c79b5
			{
4c79b5
				$change_topic_status = ITEM_UNLOCKED;
4c79b5
			}
4c79b5
			else if ($post_data['topic_status'] == ITEM_UNLOCKED && $topic_lock && $perm_lock_unlock)
4c79b5
			{
4c79b5
				$change_topic_status = ITEM_LOCKED;
4c79b5
			}
4c79b5
4c79b5
			if ($change_topic_status != $post_data['topic_status'])
4c79b5
			{
4c79b5
				$sql = 'UPDATE ' . TOPICS_TABLE . "
4c79b5
					SET topic_status = $change_topic_status
4c79b5
					WHERE topic_id = $topic_id
4c79b5
						AND topic_moved_id = 0";
4c79b5
				$db->sql_query($sql);
4c79b5
4c79b5
				$user_lock = ($auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && $user->data['user_id'] == $post_data['topic_poster']) ? 'USER_' : '';
4c79b5
4c79b5
				add_log('mod', $forum_id, $topic_id, 'LOG_' . $user_lock . (($change_topic_status == ITEM_LOCKED) ? 'LOCK' : 'UNLOCK'), $post_data['topic_title']);
4c79b5
			}
4c79b5
4c79b5
			// Lock/Unlock Post Edit
4c79b5
			if ($mode == 'edit' && $post_data['post_edit_locked'] == ITEM_LOCKED && !$post_lock && $auth->acl_get('m_edit', $forum_id))
4c79b5
			{
4c79b5
				$post_data['post_edit_locked'] = ITEM_UNLOCKED;
4c79b5
			}
4c79b5
			else if ($mode == 'edit' && $post_data['post_edit_locked'] == ITEM_UNLOCKED && $post_lock && $auth->acl_get('m_edit', $forum_id))
4c79b5
			{
4c79b5
				$post_data['post_edit_locked'] = ITEM_LOCKED;
4c79b5
			}
4c79b5
4c79b5
			$data = array(
4c79b5
				'topic_title'			=> (empty($post_data['topic_title'])) ? $post_data['post_subject'] : $post_data['topic_title'],
4c79b5
				'topic_first_post_id'	=> (isset($post_data['topic_first_post_id'])) ? (int) $post_data['topic_first_post_id'] : 0,
4c79b5
				'topic_last_post_id'	=> (isset($post_data['topic_last_post_id'])) ? (int) $post_data['topic_last_post_id'] : 0,
4c79b5
				'topic_time_limit'		=> (int) $post_data['topic_time_limit'],
4c79b5
				'topic_attachment'		=> (isset($post_data['topic_attachment'])) ? (int) $post_data['topic_attachment'] : 0,
4c79b5
				'post_id'				=> (int) $post_id,
4c79b5
				'topic_id'				=> (int) $topic_id,
4c79b5
				'forum_id'				=> (int) $forum_id,
4c79b5
				'icon_id'				=> (int) $post_data['icon_id'],
4c79b5
				'poster_id'				=> (int) $post_data['poster_id'],
4c79b5
				'enable_sig'			=> (bool) $post_data['enable_sig'],
4c79b5
				'enable_bbcode'			=> (bool) $post_data['enable_bbcode'],
4c79b5
				'enable_smilies'		=> (bool) $post_data['enable_smilies'],
4c79b5
				'enable_urls'			=> (bool) $post_data['enable_urls'],
4c79b5
				'enable_indexing'		=> (bool) $post_data['enable_indexing'],
4c79b5
				'message_md5'			=> (string) $message_md5,
4c79b5
				'post_time'				=> (isset($post_data['post_time'])) ? (int) $post_data['post_time'] : $current_time,
4c79b5
				'post_checksum'			=> (isset($post_data['post_checksum'])) ? (string) $post_data['post_checksum'] : '',
4c79b5
				'post_edit_reason'		=> $post_data['post_edit_reason'],
4c79b5
				'post_edit_user'		=> ($mode == 'edit') ? $user->data['user_id'] : ((isset($post_data['post_edit_user'])) ? (int) $post_data['post_edit_user'] : 0),
4c79b5
				'forum_parents'			=> $post_data['forum_parents'],
4c79b5
				'forum_name'			=> $post_data['forum_name'],
4c79b5
				'notify'				=> $notify,
4c79b5
				'notify_set'			=> $post_data['notify_set'],
4c79b5
				'poster_ip'				=> (isset($post_data['poster_ip'])) ? $post_data['poster_ip'] : $user->ip,
4c79b5
				'post_edit_locked'		=> (int) $post_data['post_edit_locked'],
4c79b5
				'bbcode_bitfield'		=> $message_parser->bbcode_bitfield,
4c79b5
				'bbcode_uid'			=> $message_parser->bbcode_uid,
4c79b5
				'message'				=> $message_parser->message,
4c79b5
				'attachment_data'		=> $message_parser->attachment_data,
4c79b5
				'filename_data'			=> $message_parser->filename_data,
4c79b5
4c79b5
				'topic_approved'		=> (isset($post_data['topic_approved'])) ? $post_data['topic_approved'] : false,
4c79b5
				'post_approved'			=> (isset($post_data['post_approved'])) ? $post_data['post_approved'] : false,
4c79b5
			);
4c79b5
4c79b5
			if ($mode == 'edit')
4c79b5
			{
4c79b5
				$data['topic_replies_real'] = $post_data['topic_replies_real'];
4c79b5
				$data['topic_replies'] = $post_data['topic_replies'];
4c79b5
			}
4c79b5
4c79b5
			$redirect_url = submit_post($mode, $post_data['post_subject'], $post_data['username'], $post_data['topic_type'], $poll, $data, $update_message);
4c79b5
4c79b5
			// Check the permissions for post approval, as well as the queue trigger where users are put on approval with a post count lower than specified. Moderators are not affected.
4c79b5
			if ((($config['enable_queue_trigger'] && $user->data['user_posts'] < $config['queue_trigger_posts']) || !$auth->acl_get('f_noapprove', $data['forum_id'])) && !$auth->acl_get('m_approve', $data['forum_id']))
4c79b5
			{
4c79b5
				meta_refresh(10, $redirect_url);
4c79b5
				$message = ($mode == 'edit') ? $user->lang['POST_EDITED_MOD'] : $user->lang['POST_STORED_MOD'];
4c79b5
				$message .= (($user->data['user_id'] == ANONYMOUS) ? '' : ' '. $user->lang['POST_APPROVAL_NOTIFY']);
4c79b5
			}
4c79b5
			else
4c79b5
			{
4c79b5
				meta_refresh(3, $redirect_url);
4c79b5
4c79b5
				$message = ($mode == 'edit') ? 'POST_EDITED' : 'POST_STORED';
4c79b5
				$message = $user->lang[$message] . '

' . sprintf($user->lang['VIEW_MESSAGE'], '', '');
4c79b5
			}
4c79b5
4c79b5
			$message .= '

' . sprintf($user->lang['RETURN_FORUM'], '', '');
4c79b5
			trigger_error($message);
4c79b5
		}
4c79b5
	}
4c79b5
}
4c79b5
4c79b5
// Preview
4c79b5
if (!sizeof($error) && $preview)
4c79b5
{
4c79b5
	$post_data['post_time'] = ($mode == 'edit') ? $post_data['post_time'] : $current_time;
4c79b5
4c79b5
	$preview_message = $message_parser->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies'], false);
4c79b5
4c79b5
	$preview_signature = ($mode == 'edit') ? $post_data['user_sig'] : $user->data['user_sig'];
4c79b5
	$preview_signature_uid = ($mode == 'edit') ? $post_data['user_sig_bbcode_uid'] : $user->data['user_sig_bbcode_uid'];
4c79b5
	$preview_signature_bitfield = ($mode == 'edit') ? $post_data['user_sig_bbcode_bitfield'] : $user->data['user_sig_bbcode_bitfield'];
4c79b5
4c79b5
	// Signature
4c79b5
	if ($post_data['enable_sig'] && $config['allow_sig'] && $preview_signature && $auth->acl_get('f_sigs', $forum_id))
4c79b5
	{
4c79b5
		$parse_sig = new parse_message($preview_signature);
4c79b5
		$parse_sig->bbcode_uid = $preview_signature_uid;
4c79b5
		$parse_sig->bbcode_bitfield = $preview_signature_bitfield;
4c79b5
4c79b5
		// Not sure about parameters for bbcode/smilies/urls... in signatures
4c79b5
		$parse_sig->format_display($config['allow_sig_bbcode'], true, $config['allow_sig_smilies']);
4c79b5
		$preview_signature = $parse_sig->message;
4c79b5
		unset($parse_sig);
4c79b5
	}
4c79b5
	else
4c79b5
	{
4c79b5
		$preview_signature = '';
4c79b5
	}
4c79b5
4c79b5
	$preview_subject = censor_text($post_data['post_subject']);
4c79b5
4c79b5
	// Poll Preview
4c79b5
	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))*/))
4c79b5
	&& $auth->acl_get('f_poll', $forum_id))
4c79b5
	{
4c79b5
		$parse_poll = new parse_message($post_data['poll_title']);
4c79b5
		$parse_poll->bbcode_uid = $message_parser->bbcode_uid;
4c79b5
		$parse_poll->bbcode_bitfield = $message_parser->bbcode_bitfield;
4c79b5
4c79b5
		$parse_poll->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies']);
4c79b5
4c79b5
		if ($post_data['poll_length'])
4c79b5
		{
4c79b5
			$poll_end = ($post_data['poll_length'] * 86400) + (($post_data['poll_start']) ? $post_data['poll_start'] : time());
4c79b5
		}
4c79b5
4c79b5
		$template->assign_vars(array(
4c79b5
			'S_HAS_POLL_OPTIONS'	=> (sizeof($post_data['poll_options'])),
4c79b5
			'S_IS_MULTI_CHOICE'		=> ($post_data['poll_max_options'] > 1) ? true : false,
4c79b5
4c79b5
			'POLL_QUESTION'		=> $parse_poll->message,
4c79b5
4c79b5
			'L_POLL_LENGTH'		=> ($post_data['poll_length']) ? sprintf($user->lang['POLL_RUN_TILL'], $user->format_date($poll_end)) : '',
4c79b5
			'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']))
4c79b5
		);
4c79b5
4c79b5
		$parse_poll->message = implode("\n", $post_data['poll_options']);
4c79b5
		$parse_poll->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies']);
4c79b5
		$preview_poll_options = explode('
', $parse_poll->message);
4c79b5
		unset($parse_poll);
4c79b5
4c79b5
		foreach ($preview_poll_options as $key => $option)
4c79b5
		{
4c79b5
			$template->assign_block_vars('poll_option', array(
4c79b5
				'POLL_OPTION_CAPTION'	=> $option,
4c79b5
				'POLL_OPTION_ID'		=> $key + 1)
4c79b5
			);
4c79b5
		}
4c79b5
		unset($preview_poll_options);
4c79b5
	}
4c79b5
4c79b5
	// Attachment Preview
4c79b5
	if (sizeof($message_parser->attachment_data))
4c79b5
	{
4c79b5
		$template->assign_var('S_HAS_ATTACHMENTS', true);
4c79b5
4c79b5
		$update_count = array();
4c79b5
		$attachment_data = $message_parser->attachment_data;
4c79b5
4c79b5
		parse_attachments($forum_id, $preview_message, $attachment_data, $update_count, true);
4c79b5
4c79b5
		foreach ($attachment_data as $i => $attachment)
4c79b5
		{
4c79b5
			$template->assign_block_vars('attachment', array(
4c79b5
				'DISPLAY_ATTACHMENT'	=> $attachment)
4c79b5
			);
4c79b5
		}
4c79b5
		unset($attachment_data);
4c79b5
	}
4c79b5
4c79b5
	if (!sizeof($error))
4c79b5
	{
4c79b5
		$template->assign_vars(array(
4c79b5
			'PREVIEW_SUBJECT'		=> $preview_subject,
4c79b5
			'PREVIEW_MESSAGE'		=> $preview_message,
4c79b5
			'PREVIEW_SIGNATURE'		=> $preview_signature,
4c79b5
4c79b5
			'S_DISPLAY_PREVIEW'		=> true)
4c79b5
		);
4c79b5
	}
4c79b5
}
4c79b5
4c79b5
// Decode text for message display
4c79b5
$post_data['bbcode_uid'] = ($mode == 'quote' && !$preview && !$refresh && !sizeof($error)) ? $post_data['bbcode_uid'] : $message_parser->bbcode_uid;
4c79b5
$message_parser->decode_message($post_data['bbcode_uid']);
4c79b5
4c79b5
if ($mode == 'quote' && !$submit && !$preview && !$refresh)
4c79b5
{
4c79b5
	$message_parser->message = '[quote="' . $post_data['quote_username'] . '"]' . censor_text(trim($message_parser->message)) . "[/quote]\n";
4c79b5
}
4c79b5
4c79b5
if (($mode == 'reply' || $mode == 'quote') && !$submit && !$preview && !$refresh)
4c79b5
{
4c79b5
	$post_data['post_subject'] = ((strpos($post_data['post_subject'], 'Re: ') !== 0) ? 'Re: ' : '') . censor_text($post_data['post_subject']);
4c79b5
}
4c79b5
4c79b5
$attachment_data = $message_parser->attachment_data;
4c79b5
$filename_data = $message_parser->filename_data;
4c79b5
$post_data['post_text'] = $message_parser->message;
4c79b5
4c79b5
if (sizeof($post_data['poll_options']) && $post_data['poll_title'])
4c79b5
{
4c79b5
	$message_parser->message = $post_data['poll_title'];
4c79b5
	$message_parser->bbcode_uid = $post_data['bbcode_uid'];
4c79b5
4c79b5
	$message_parser->decode_message();
4c79b5
	$post_data['poll_title'] = $message_parser->message;
4c79b5
4c79b5
	$message_parser->message = implode("\n", $post_data['poll_options']);
4c79b5
	$message_parser->decode_message();
4c79b5
	$post_data['poll_options'] = explode("\n", $message_parser->message);
4c79b5
}
4c79b5
4c79b5
// MAIN POSTING PAGE BEGINS HERE
4c79b5
4c79b5
// Forum moderators?
4c79b5
$moderators = array();
4c79b5
get_moderators($moderators, $forum_id);
4c79b5
4c79b5
// Generate smiley listing
4c79b5
generate_smilies('inline', $forum_id);
4c79b5
4c79b5
// Generate inline attachment select box
4c79b5
posting_gen_inline_attachments($attachment_data);
4c79b5
4c79b5
// Do show topic type selection only in first post.
4c79b5
$topic_type_toggle = false;
4c79b5
4c79b5
if ($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id']))
4c79b5
{
4c79b5
	$topic_type_toggle = posting_gen_topic_types($forum_id, $post_data['topic_type']);
4c79b5
}
4c79b5
4c79b5
$s_topic_icons = false;
4c79b5
if ($post_data['enable_icons'] && $auth->acl_get('f_icons', $forum_id))
4c79b5
{
4c79b5
	$s_topic_icons = posting_gen_topic_icons($mode, $post_data['icon_id']);
4c79b5
}
4c79b5
4c79b5
$bbcode_checked		= (isset($post_data['enable_bbcode'])) ? !$post_data['enable_bbcode'] : (($config['allow_bbcode']) ? !$user->optionget('bbcode') : 1);
4c79b5
$smilies_checked	= (isset($post_data['enable_smilies'])) ? !$post_data['enable_smilies'] : (($config['allow_smilies']) ? !$user->optionget('smilies') : 1);
4c79b5
$urls_checked		= (isset($post_data['enable_urls'])) ? !$post_data['enable_urls'] : 0;
4c79b5
$sig_checked		= $post_data['enable_sig'];
4c79b5
$lock_topic_checked	= (isset($topic_lock) && $topic_lock) ? $topic_lock : (($post_data['topic_status'] == ITEM_LOCKED) ? 1 : 0);
4c79b5
$lock_post_checked	= (isset($post_lock)) ? $post_lock : $post_data['post_edit_locked'];
4c79b5
4c79b5
// 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
4c79b5
$notify_set			= ($mode != 'edit' && $config['allow_topic_notify'] && $user->data['is_registered'] && !$post_data['notify_set']) ? $user->data['user_notify'] : $post_data['notify_set'];
4c79b5
$notify_checked		= (isset($notify)) ? $notify : (($mode == 'post') ? $user->data['user_notify'] : $notify_set);
4c79b5
4c79b5
// Page title & action URL, include session_id for security purpose
4c79b5
$s_action = append_sid("{$phpbb_root_path}posting.$phpEx", "mode=$mode&f=$forum_id", true, $user->session_id);
4c79b5
$s_action .= ($topic_id) ? "&t=$topic_id" : '';
4c79b5
$s_action .= ($post_id) ? "&p=$post_id" : '';
4c79b5
4c79b5
switch ($mode)
4c79b5
{
4c79b5
	case 'post':
4c79b5
		$page_title = $user->lang['POST_TOPIC'];
4c79b5
	break;
4c79b5
4c79b5
	case 'quote':
4c79b5
	case 'reply':
4c79b5
		$page_title = $user->lang['POST_REPLY'];
4c79b5
	break;
4c79b5
4c79b5
	case 'delete':
4c79b5
	case 'edit':
4c79b5
		$page_title = $user->lang['EDIT_POST'];
4c79b5
	break;
4c79b5
}
4c79b5
4c79b5
// Build Navigation Links
4c79b5
generate_forum_nav($post_data);
4c79b5
4c79b5
// Build Forum Rules
4c79b5
generate_forum_rules($post_data);
4c79b5
4c79b5
if ($config['enable_post_confirm'] && !$user->data['is_registered'] && $solved_captcha === false && ($mode == 'post' || $mode == 'reply' || $mode == 'quote'))
4c79b5
{
4c79b5
	// Show confirm image
4c79b5
	$sql = 'DELETE FROM ' . CONFIRM_TABLE . "
4c79b5
		WHERE session_id = '" . $db->sql_escape($user->session_id) . "'
4c79b5
			AND confirm_type = " . CONFIRM_POST;
4c79b5
	$db->sql_query($sql);
4c79b5
4c79b5
	// Generate code
4c79b5
	$code = gen_rand_string(mt_rand(5, 8));
4c79b5
	$confirm_id = md5(unique_id($user->ip));
4c79b5
	$seed = hexdec(substr(unique_id(), 4, 10));
4c79b5
4c79b5
	// compute $seed % 0x7fffffff
4c79b5
	$seed -= 0x7fffffff * floor($seed / 0x7fffffff);
4c79b5
4c79b5
	$sql = 'INSERT INTO ' . CONFIRM_TABLE . ' ' . $db->sql_build_array('INSERT', array(
4c79b5
		'confirm_id'	=> (string) $confirm_id,
4c79b5
		'session_id'	=> (string) $user->session_id,
4c79b5
		'confirm_type'	=> (int) CONFIRM_POST,
4c79b5
		'code'			=> (string) $code,
4c79b5
		'seed'			=> (int) $seed)
4c79b5
	);
4c79b5
	$db->sql_query($sql);
4c79b5
4c79b5
	$template->assign_vars(array(
4c79b5
		'S_CONFIRM_CODE'			=> true,
4c79b5
		'CONFIRM_ID'				=> $confirm_id,
4c79b5
		'CONFIRM_IMAGE'				=> '',
4c79b5
		'L_POST_CONFIRM_EXPLAIN'	=> sprintf($user->lang['POST_CONFIRM_EXPLAIN'], '', ''),
4c79b5
	));
4c79b5
}
4c79b5
4c79b5
$s_hidden_fields = ($mode == 'reply' || $mode == 'quote') ? '<input type="hidden" name="topic_cur_post_id" value="' . $post_data['topic_last_post_id'] . '" />' : '';
4c79b5
$s_hidden_fields .= '<input type="hidden" name="lastclick" value="' . $current_time . '" />';
4c79b5
$s_hidden_fields .= ($draft_id || isset($_REQUEST['draft_loaded'])) ? '<input type="hidden" name="draft_loaded" value="' . request_var('draft_loaded', $draft_id) . '" />' : '';
4c79b5
4c79b5
// Add the confirm id/code pair to the hidden fields, else an error is displayed on next submit/preview
4c79b5
if ($solved_captcha !== false)
4c79b5
{
4c79b5
	$s_hidden_fields .= build_hidden_fields(array(
4c79b5
		'confirm_id'		=> request_var('confirm_id', ''),
4c79b5
		'confirm_code'		=> request_var('confirm_code', ''))
4c79b5
	);
4c79b5
}
4c79b5
4c79b5
$form_enctype = (@ini_get('file_uploads') == '0' || strtolower(@ini_get('file_uploads')) == 'off' || !$config['allow_attachments'] || !$auth->acl_get('u_attach') || !$auth->acl_get('f_attach', $forum_id)) ? '' : ' enctype="multipart/form-data"';
4c79b5
add_form_key('posting');
4c79b5
4c79b5
4c79b5
// Start assigning vars for main posting page ...
4c79b5
$template->assign_vars(array(
4c79b5
	'L_POST_A'					=> $page_title,
4c79b5
	'L_ICON'					=> ($mode == 'reply' || $mode == 'quote' || ($mode == 'edit' && $post_id != $post_data['topic_first_post_id'])) ? $user->lang['POST_ICON'] : $user->lang['TOPIC_ICON'],
4c79b5
	'L_MESSAGE_BODY_EXPLAIN'	=> (intval($config['max_post_chars'])) ? sprintf($user->lang['MESSAGE_BODY_EXPLAIN'], intval($config['max_post_chars'])) : '',
4c79b5
4c79b5
	'FORUM_NAME'			=> $post_data['forum_name'],
4c79b5
	'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']) : '',
4c79b5
	'TOPIC_TITLE'			=> censor_text($post_data['topic_title']),
4c79b5
	'MODERATORS'			=> (sizeof($moderators)) ? implode(', ', $moderators[$forum_id]) : '',
4c79b5
	'USERNAME'				=> ((!$preview && $mode != 'quote') || $preview) ? $post_data['username'] : '',
4c79b5
	'SUBJECT'				=> $post_data['post_subject'],
4c79b5
	'MESSAGE'				=> $post_data['post_text'],
4c79b5
	'BBCODE_STATUS'			=> ($bbcode_status) ? sprintf($user->lang['BBCODE_IS_ON'], '', '') : sprintf($user->lang['BBCODE_IS_OFF'], '', ''),
4c79b5
	'IMG_STATUS'			=> ($img_status) ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'],
4c79b5
	'FLASH_STATUS'			=> ($flash_status) ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'],
4c79b5
	'SMILIES_STATUS'		=> ($smilies_status) ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'],
4c79b5
	'URL_STATUS'			=> ($bbcode_status && $url_status) ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'],
4c79b5
	'MINI_POST_IMG'			=> $user->img('icon_post_target', $user->lang['POST']),
4c79b5
	'POST_DATE'				=> ($post_data['post_time']) ? $user->format_date($post_data['post_time']) : '',
4c79b5
	'ERROR'					=> (sizeof($error)) ? implode('
', $error) : '',
4c79b5
	'TOPIC_TIME_LIMIT'		=> (int) $post_data['topic_time_limit'],
4c79b5
	'EDIT_REASON'			=> $post_data['post_edit_reason'],
4c79b5
	'U_VIEW_FORUM'			=> append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id"),
4c79b5
	'U_VIEW_TOPIC'			=> ($mode != 'post') ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id") : '',
4c79b5
	'U_PROGRESS_BAR'		=> append_sid("{$phpbb_root_path}posting.$phpEx", "f=$forum_id&mode=popup"),
4c79b5
	'UA_PROGRESS_BAR'		=> addslashes(append_sid("{$phpbb_root_path}posting.$phpEx", "f=$forum_id&mode=popup")),
4c79b5
4c79b5
	'S_PRIVMSGS'				=> false,
4c79b5
	'S_CLOSE_PROGRESS_WINDOW'	=> (isset($_POST['add_file'])) ? true : false,
4c79b5
	'S_EDIT_POST'				=> ($mode == 'edit') ? true : false,
4c79b5
	'S_EDIT_REASON'				=> ($mode == 'edit' && $auth->acl_get('m_edit', $forum_id)) ? true : false,
4c79b5
	'S_DISPLAY_USERNAME'		=> (!$user->data['is_registered'] || ($mode == 'edit' && $post_data['poster_id'] == ANONYMOUS)) ? true : false,
4c79b5
	'S_SHOW_TOPIC_ICONS'		=> $s_topic_icons,
4c79b5
	'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) && !$post_data['post_edit_locked'] && ($post_data['post_time'] > time() - ($config['edit_time'] * 60) || !$config['edit_time'])) || $auth->acl_get('m_delete', $forum_id))) ? true : false,
4c79b5
	'S_BBCODE_ALLOWED'			=> $bbcode_status,
4c79b5
	'S_BBCODE_CHECKED'			=> ($bbcode_checked) ? ' checked="checked"' : '',
4c79b5
	'S_SMILIES_ALLOWED'			=> $smilies_status,
4c79b5
	'S_SMILIES_CHECKED'			=> ($smilies_checked) ? ' checked="checked"' : '',
4c79b5
	'S_SIG_ALLOWED'				=> ($auth->acl_get('f_sigs', $forum_id) && $config['allow_sig'] && $user->data['is_registered']) ? true : false,
4c79b5
	'S_SIGNATURE_CHECKED'		=> ($sig_checked) ? ' checked="checked"' : '',
4c79b5
	'S_NOTIFY_ALLOWED'			=> (!$user->data['is_registered'] || ($mode == 'edit' && $user->data['user_id'] != $post_data['poster_id']) || !$config['allow_topic_notify'] || !$config['email_enable']) ? false : true,
4c79b5
	'S_NOTIFY_CHECKED'			=> ($notify_checked) ? ' checked="checked"' : '',
4c79b5
	'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,
4c79b5
	'S_LOCK_TOPIC_CHECKED'		=> ($lock_topic_checked) ? ' checked="checked"' : '',
4c79b5
	'S_LOCK_POST_ALLOWED'		=> ($mode == 'edit' && $auth->acl_get('m_edit', $forum_id)) ? true : false,
4c79b5
	'S_LOCK_POST_CHECKED'		=> ($lock_post_checked) ? ' checked="checked"' : '',
4c79b5
	'S_LINKS_ALLOWED'			=> $url_status,
4c79b5
	'S_MAGIC_URL_CHECKED'		=> ($urls_checked) ? ' checked="checked"' : '',
4c79b5
	'S_TYPE_TOGGLE'				=> $topic_type_toggle,
4c79b5
	'S_SAVE_ALLOWED'			=> ($auth->acl_get('u_savedrafts') && $user->data['is_registered'] && $mode != 'edit') ? true : false,
4c79b5
	'S_HAS_DRAFTS'				=> ($auth->acl_get('u_savedrafts') && $user->data['is_registered'] && $post_data['drafts']) ? true : false,
4c79b5
	'S_FORM_ENCTYPE'			=> $form_enctype,
4c79b5
4c79b5
	'S_BBCODE_IMG'			=> $img_status,
4c79b5
	'S_BBCODE_URL'			=> $url_status,
4c79b5
	'S_BBCODE_FLASH'		=> $flash_status,
4c79b5
	'S_BBCODE_QUOTE'		=> $quote_status,
4c79b5
4c79b5
	'S_POST_ACTION'			=> $s_action,
4c79b5
	'S_HIDDEN_FIELDS'		=> $s_hidden_fields)
4c79b5
);
4c79b5
4c79b5
// Build custom bbcodes array
4c79b5
display_custom_bbcodes();
4c79b5
4c79b5
// Poll entry
4c79b5
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))*/))
4c79b5
	&& $auth->acl_get('f_poll', $forum_id))
4c79b5
{
4c79b5
	$template->assign_vars(array(
4c79b5
		'S_SHOW_POLL_BOX'		=> true,
4c79b5
		'S_POLL_VOTE_CHANGE'	=> ($auth->acl_get('f_votechg', $forum_id)),
4c79b5
		'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))),
4c79b5
		'S_POLL_DELETE_CHECKED'	=> (!empty($poll_delete)) ? true : false,
4c79b5
4c79b5
		'L_POLL_OPTIONS_EXPLAIN'	=> sprintf($user->lang['POLL_OPTIONS_' . (($mode == 'edit') ? 'EDIT_' : '') . 'EXPLAIN'], $config['max_poll_options']),
4c79b5
4c79b5
		'VOTE_CHANGE_CHECKED'	=> (!empty($post_data['poll_vote_change'])) ? ' checked="checked"' : '',
4c79b5
		'POLL_TITLE'			=> (isset($post_data['poll_title'])) ? $post_data['poll_title'] : '',
4c79b5
		'POLL_OPTIONS'			=> (!empty($post_data['poll_options'])) ? implode("\n", $post_data['poll_options']) : '',
4c79b5
		'POLL_MAX_OPTIONS'		=> (isset($post_data['poll_max_options'])) ? (int) $post_data['poll_max_options'] : 1,
4c79b5
		'POLL_LENGTH'			=> $post_data['poll_length'])
4c79b5
	);
4c79b5
}
4c79b5
4c79b5
// Show attachment box for adding attachments if true
4c79b5
$allowed = ($auth->acl_get('f_attach', $forum_id) && $auth->acl_get('u_attach') && $config['allow_attachments'] && $form_enctype);
4c79b5
4c79b5
// Attachment entry
4c79b5
posting_gen_attachment_entry($attachment_data, $filename_data, $allowed);
4c79b5
4c79b5
// Output page ...
4c79b5
page_header($page_title);
4c79b5
4c79b5
$template->set_filenames(array(
4c79b5
	'body' => 'posting_body.html')
4c79b5
);
4c79b5
4c79b5
make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
4c79b5
4c79b5
// Topic review
4c79b5
if ($mode == 'reply' || $mode == 'quote')
4c79b5
{
4c79b5
	if (topic_review($topic_id, $forum_id))
4c79b5
	{
4c79b5
		$template->assign_var('S_DISPLAY_REVIEW', true);
4c79b5
	}
4c79b5
}
4c79b5
4c79b5
page_footer();
4c79b5
4c79b5
/**
4c79b5
* Show upload popup (progress bar)
4c79b5
*/
4c79b5
function upload_popup($forum_style = 0)
4c79b5
{
4c79b5
	global $template, $user;
4c79b5
4c79b5
	($forum_style) ? $user->setup('posting', $forum_style) : $user->setup('posting');
4c79b5
4c79b5
	page_header($user->lang['PROGRESS_BAR']);
4c79b5
4c79b5
	$template->set_filenames(array(
4c79b5
		'popup'	=> 'posting_progress_bar.html')
4c79b5
	);
4c79b5
4c79b5
	$template->assign_vars(array(
4c79b5
		'PROGRESS_BAR'	=> $user->img('upload_bar', $user->lang['UPLOAD_IN_PROGRESS']))
4c79b5
	);
4c79b5
4c79b5
	$template->display('popup');
4c79b5
4c79b5
	garbage_collection();
4c79b5
	exit_handler();
4c79b5
}
4c79b5
4c79b5
/**
4c79b5
* Do the various checks required for removing posts as well as removing it
4c79b5
*/
4c79b5
function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data)
4c79b5
{
4c79b5
	global $user, $db, $auth, $config;
4c79b5
	global $phpbb_root_path, $phpEx;
4c79b5
4c79b5
	// If moderator removing post or user itself removing post, present a confirmation screen
4c79b5
	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'] && !$post_data['post_edit_locked'] && ($post_data['post_time'] > time() - ($config['edit_time'] * 60) || !$config['edit_time'])))
4c79b5
	{
4c79b5
		$s_hidden_fields = build_hidden_fields(array(
4c79b5
			'p'		=> $post_id,
4c79b5
			'f'		=> $forum_id,
4c79b5
			'mode'	=> 'delete')
4c79b5
		);
4c79b5
4c79b5
		if (confirm_box(true))
4c79b5
		{
4c79b5
			$data = array(
4c79b5
				'topic_first_post_id'	=> $post_data['topic_first_post_id'],
4c79b5
				'topic_last_post_id'	=> $post_data['topic_last_post_id'],
4c79b5
				'topic_replies_real'	=> $post_data['topic_replies_real'],
4c79b5
				'topic_approved'		=> $post_data['topic_approved'],
4c79b5
				'topic_type'			=> $post_data['topic_type'],
4c79b5
				'post_approved'			=> $post_data['post_approved'],
4c79b5
				'post_reported'			=> $post_data['post_reported'],
4c79b5
				'post_time'				=> $post_data['post_time'],
4c79b5
				'poster_id'				=> $post_data['poster_id'],
4c79b5
				'post_postcount'		=> $post_data['post_postcount']
4c79b5
			);
4c79b5
4c79b5
			$next_post_id = delete_post($forum_id, $topic_id, $post_id, $data);
4c79b5
4c79b5
			if ($next_post_id === false)
4c79b5
			{
4c79b5
				add_log('mod', $forum_id, $topic_id, 'LOG_DELETE_TOPIC', $post_data['topic_title']);
4c79b5
4c79b5
				$meta_info = append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id");
4c79b5
				$message = $user->lang['POST_DELETED'];
4c79b5
			}
4c79b5
			else
4c79b5
			{
4c79b5
				add_log('mod', $forum_id, $topic_id, 'LOG_DELETE_POST', $post_data['post_subject']);
4c79b5
4c79b5
				$meta_info = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id&p=$next_post_id") . "#p$next_post_id";
4c79b5
				$message = $user->lang['POST_DELETED'] . '

' . sprintf($user->lang['RETURN_TOPIC'], '', '');
4c79b5
			}
4c79b5
4c79b5
			meta_refresh(3, $meta_info);
4c79b5
			$message .= '

' . sprintf($user->lang['RETURN_FORUM'], '', '');
4c79b5
			trigger_error($message);
4c79b5
		}
4c79b5
		else
4c79b5
		{
4c79b5
			confirm_box(false, 'DELETE_POST', $s_hidden_fields);
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	// If we are here the user is not able to delete - present the correct error message
4c79b5
	if ($post_data['poster_id'] != $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id))
4c79b5
	{
4c79b5
		trigger_error('DELETE_OWN_POSTS');
4c79b5
	}
4c79b5
4c79b5
	if ($post_data['poster_id'] == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id) && $post_id != $post_data['topic_last_post_id'])
4c79b5
	{
4c79b5
		trigger_error('CANNOT_DELETE_REPLIED');
4c79b5
	}
4c79b5
4c79b5
	trigger_error('USER_CANNOT_DELETE');
4c79b5
}
4c79b5
4c79b5
?>