1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/posting.php Wed Mar 07 16:41:10 2012 +0400
1.3 @@ -0,0 +1,1625 @@
1.4 +<?php
1.5 +/**
1.6 +*
1.7 +* @package phpBB3
1.8 +* @version $Id$
1.9 +* @copyright (c) 2005 phpBB Group
1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
1.11 +*
1.12 +*/
1.13 +
1.14 +/**
1.15 +* @ignore
1.16 +*/
1.17 +define('IN_PHPBB', true);
1.18 +$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
1.19 +$phpEx = substr(strrchr(__FILE__, '.'), 1);
1.20 +include($phpbb_root_path . 'common.' . $phpEx);
1.21 +include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
1.22 +include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
1.23 +include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
1.24 +
1.25 +
1.26 +// Start session management
1.27 +$user->session_begin();
1.28 +$auth->acl($user->data);
1.29 +
1.30 +
1.31 +// Grab only parameters needed here
1.32 +$post_id = request_var('p', 0);
1.33 +$topic_id = request_var('t', 0);
1.34 +$forum_id = request_var('f', 0);
1.35 +$draft_id = request_var('d', 0);
1.36 +$lastclick = request_var('lastclick', 0);
1.37 +
1.38 +$submit = (isset($_POST['post'])) ? true : false;
1.39 +$preview = (isset($_POST['preview'])) ? true : false;
1.40 +$save = (isset($_POST['save'])) ? true : false;
1.41 +$load = (isset($_POST['load'])) ? true : false;
1.42 +$delete = (isset($_POST['delete'])) ? true : false;
1.43 +$cancel = (isset($_POST['cancel']) && !isset($_POST['save'])) ? true : false;
1.44 +
1.45 +$refresh = (isset($_POST['add_file']) || isset($_POST['delete_file']) || isset($_POST['full_editor']) || isset($_POST['cancel_unglobalise']) || $save || $load) ? true : false;
1.46 +$mode = ($delete && !$preview && !$refresh && $submit) ? 'delete' : request_var('mode', '');
1.47 +
1.48 +$error = $post_data = array();
1.49 +$current_time = time();
1.50 +
1.51 +// Was cancel pressed? If so then redirect to the appropriate page
1.52 +if ($cancel || ($current_time - $lastclick < 2 && $submit))
1.53 +{
1.54 + $f = ($forum_id) ? 'f=' . $forum_id . '&' : '';
1.55 + $redirect = ($post_id) ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", $f . 'p=' . $post_id) . '#p' . $post_id : (($topic_id) ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", $f . 't=' . $topic_id) : (($forum_id) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) : append_sid("{$phpbb_root_path}index.$phpEx")));
1.56 + redirect($redirect);
1.57 +}
1.58 +
1.59 +if (in_array($mode, array('post', 'reply', 'quote', 'edit', 'delete')) && !$forum_id)
1.60 +{
1.61 + trigger_error('NO_FORUM');
1.62 +}
1.63 +
1.64 +// We need to know some basic information in all cases before we do anything.
1.65 +switch ($mode)
1.66 +{
1.67 + case 'post':
1.68 + $sql = 'SELECT *
1.69 + FROM ' . FORUMS_TABLE . "
1.70 + WHERE forum_id = $forum_id";
1.71 + break;
1.72 +
1.73 + case 'bump':
1.74 + case 'reply':
1.75 + if (!$topic_id)
1.76 + {
1.77 + trigger_error('NO_TOPIC');
1.78 + }
1.79 +
1.80 + // Force forum id
1.81 + $sql = 'SELECT forum_id
1.82 + FROM ' . TOPICS_TABLE . '
1.83 + WHERE topic_id = ' . $topic_id;
1.84 + $result = $db->sql_query($sql);
1.85 + $f_id = (int) $db->sql_fetchfield('forum_id');
1.86 + $db->sql_freeresult($result);
1.87 +
1.88 + $forum_id = (!$f_id) ? $forum_id : $f_id;
1.89 +
1.90 + $sql = 'SELECT f.*, t.*
1.91 + FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f
1.92 + WHERE t.topic_id = $topic_id
1.93 + AND (f.forum_id = t.forum_id
1.94 + OR f.forum_id = $forum_id)" .
1.95 + (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1');
1.96 + break;
1.97 +
1.98 + case 'quote':
1.99 + case 'edit':
1.100 + case 'delete':
1.101 + if (!$post_id)
1.102 + {
1.103 + $user->setup('posting');
1.104 + trigger_error('NO_POST');
1.105 + }
1.106 +
1.107 + // Force forum id
1.108 + $sql = 'SELECT forum_id
1.109 + FROM ' . POSTS_TABLE . '
1.110 + WHERE post_id = ' . $post_id;
1.111 + $result = $db->sql_query($sql);
1.112 + $f_id = (int) $db->sql_fetchfield('forum_id');
1.113 + $db->sql_freeresult($result);
1.114 +
1.115 + $forum_id = (!$f_id) ? $forum_id : $f_id;
1.116 +
1.117 + $sql = 'SELECT f.*, t.*, p.*, u.username, u.username_clean, u.user_sig, u.user_sig_bbcode_uid, u.user_sig_bbcode_bitfield
1.118 + FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . ' f, ' . USERS_TABLE . " u
1.119 + WHERE p.post_id = $post_id
1.120 + AND t.topic_id = p.topic_id
1.121 + AND u.user_id = p.poster_id
1.122 + AND (f.forum_id = t.forum_id
1.123 + OR f.forum_id = $forum_id)" .
1.124 + (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND p.post_approved = 1');
1.125 + break;
1.126 +
1.127 + case 'smilies':
1.128 + $sql = '';
1.129 + generate_smilies('window', $forum_id);
1.130 + break;
1.131 +
1.132 + case 'popup':
1.133 + if ($forum_id)
1.134 + {
1.135 + $sql = 'SELECT forum_style
1.136 + FROM ' . FORUMS_TABLE . '
1.137 + WHERE forum_id = ' . $forum_id;
1.138 + }
1.139 + else
1.140 + {
1.141 + upload_popup();
1.142 + return;
1.143 + }
1.144 + break;
1.145 +
1.146 + default:
1.147 + $sql = '';
1.148 + break;
1.149 +}
1.150 +
1.151 +if (!$sql)
1.152 +{
1.153 + $user->setup('posting');
1.154 + trigger_error('NO_POST_MODE');
1.155 +}
1.156 +
1.157 +$result = $db->sql_query($sql);
1.158 +$post_data = $db->sql_fetchrow($result);
1.159 +$db->sql_freeresult($result);
1.160 +
1.161 +if (!$post_data)
1.162 +{
1.163 + if (!($mode == 'post' || $mode == 'bump' || $mode == 'reply'))
1.164 + {
1.165 + $user->setup('posting');
1.166 + }
1.167 + trigger_error(($mode == 'post' || $mode == 'bump' || $mode == 'reply') ? 'NO_TOPIC' : 'NO_POST');
1.168 +}
1.169 +
1.170 +// Not able to reply to unapproved posts/topics
1.171 +// TODO: add more descriptive language key
1.172 +if ($auth->acl_get('m_approve', $forum_id) && ((($mode == 'reply' || $mode == 'bump') && !$post_data['topic_approved']) || ($mode == 'quote' && !$post_data['post_approved'])))
1.173 +{
1.174 + trigger_error(($mode == 'reply' || $mode == 'bump') ? 'TOPIC_UNAPPROVED' : 'POST_UNAPPROVED');
1.175 +}
1.176 +
1.177 +if ($mode == 'popup')
1.178 +{
1.179 + upload_popup($post_data['forum_style']);
1.180 + return;
1.181 +}
1.182 +
1.183 +$user->setup(array('posting', 'mcp', 'viewtopic'), $post_data['forum_style']);
1.184 +
1.185 +if ($config['enable_post_confirm'] && !$user->data['is_registered'])
1.186 +{
1.187 + include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
1.188 + $captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']);
1.189 + $captcha->init(CONFIRM_POST);
1.190 +}
1.191 +
1.192 +// Use post_row values in favor of submitted ones...
1.193 +$forum_id = (!empty($post_data['forum_id'])) ? (int) $post_data['forum_id'] : (int) $forum_id;
1.194 +$topic_id = (!empty($post_data['topic_id'])) ? (int) $post_data['topic_id'] : (int) $topic_id;
1.195 +$post_id = (!empty($post_data['post_id'])) ? (int) $post_data['post_id'] : (int) $post_id;
1.196 +
1.197 +// Need to login to passworded forum first?
1.198 +if ($post_data['forum_password'])
1.199 +{
1.200 + login_forum_box(array(
1.201 + 'forum_id' => $forum_id,
1.202 + 'forum_password' => $post_data['forum_password'])
1.203 + );
1.204 +}
1.205 +
1.206 +// Check permissions
1.207 +if ($user->data['is_bot'])
1.208 +{
1.209 + redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
1.210 +}
1.211 +
1.212 +// Is the user able to read within this forum?
1.213 +if (!$auth->acl_get('f_read', $forum_id))
1.214 +{
1.215 + if ($user->data['user_id'] != ANONYMOUS)
1.216 + {
1.217 + trigger_error('USER_CANNOT_READ');
1.218 + }
1.219 +
1.220 + login_box('', $user->lang['LOGIN_EXPLAIN_POST']);
1.221 +}
1.222 +
1.223 +// Permission to do the action asked?
1.224 +$is_authed = false;
1.225 +
1.226 +switch ($mode)
1.227 +{
1.228 + case 'post':
1.229 + if ($auth->acl_get('f_post', $forum_id))
1.230 + {
1.231 + $is_authed = true;
1.232 + }
1.233 + break;
1.234 +
1.235 + case 'bump':
1.236 + if ($auth->acl_get('f_bump', $forum_id))
1.237 + {
1.238 + $is_authed = true;
1.239 + }
1.240 + break;
1.241 +
1.242 + case 'quote':
1.243 +
1.244 + $post_data['post_edit_locked'] = 0;
1.245 +
1.246 + // no break;
1.247 +
1.248 + case 'reply':
1.249 + if ($auth->acl_get('f_reply', $forum_id))
1.250 + {
1.251 + $is_authed = true;
1.252 + }
1.253 + break;
1.254 +
1.255 + case 'edit':
1.256 + if ($user->data['is_registered'] && $auth->acl_gets('f_edit', 'm_edit', $forum_id))
1.257 + {
1.258 + $is_authed = true;
1.259 + }
1.260 + break;
1.261 +
1.262 + case 'delete':
1.263 + if ($user->data['is_registered'] && $auth->acl_gets('f_delete', 'm_delete', $forum_id))
1.264 + {
1.265 + $is_authed = true;
1.266 + }
1.267 + break;
1.268 +}
1.269 +
1.270 +if (!$is_authed)
1.271 +{
1.272 + $check_auth = ($mode == 'quote') ? 'reply' : $mode;
1.273 +
1.274 + if ($user->data['is_registered'])
1.275 + {
1.276 + trigger_error('USER_CANNOT_' . strtoupper($check_auth));
1.277 + }
1.278 +
1.279 + login_box('', $user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)]);
1.280 +}
1.281 +
1.282 +// Is the user able to post within this forum?
1.283 +if ($post_data['forum_type'] != FORUM_POST && in_array($mode, array('post', 'bump', 'quote', 'reply')))
1.284 +{
1.285 + trigger_error('USER_CANNOT_FORUM_POST');
1.286 +}
1.287 +
1.288 +// Forum/Topic locked?
1.289 +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))
1.290 +{
1.291 + trigger_error(($post_data['forum_status'] == ITEM_LOCKED) ? 'FORUM_LOCKED' : 'TOPIC_LOCKED');
1.292 +}
1.293 +
1.294 +// Can we edit this post ... if we're a moderator with rights then always yes
1.295 +// else it depends on editing times, lock status and if we're the correct user
1.296 +if ($mode == 'edit' && !$auth->acl_get('m_edit', $forum_id))
1.297 +{
1.298 + if ($user->data['user_id'] != $post_data['poster_id'])
1.299 + {
1.300 + trigger_error('USER_CANNOT_EDIT');
1.301 + }
1.302 +
1.303 + if (!($post_data['post_time'] > time() - ($config['edit_time'] * 60) || !$config['edit_time']))
1.304 + {
1.305 + trigger_error('CANNOT_EDIT_TIME');
1.306 + }
1.307 +
1.308 + if ($post_data['post_edit_locked'])
1.309 + {
1.310 + trigger_error('CANNOT_EDIT_POST_LOCKED');
1.311 + }
1.312 +}
1.313 +
1.314 +// Handle delete mode...
1.315 +if ($mode == 'delete')
1.316 +{
1.317 + handle_post_delete($forum_id, $topic_id, $post_id, $post_data);
1.318 + return;
1.319 +}
1.320 +
1.321 +// Handle bump mode...
1.322 +if ($mode == 'bump')
1.323 +{
1.324 + 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'])
1.325 + && check_link_hash(request_var('hash', ''), "topic_{$post_data['topic_id']}"))
1.326 + {
1.327 + $meta_url = phpbb_bump_topic($forum_id, $topic_id, $post_data, $current_time);
1.328 + meta_refresh(3, $meta_url);
1.329 +
1.330 + $message = $user->lang['TOPIC_BUMPED'] . '<br /><br />' . sprintf($user->lang['VIEW_MESSAGE'], '<a href="' . $meta_url . '">', '</a>');
1.331 + $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
1.332 +
1.333 + trigger_error($message);
1.334 + }
1.335 +
1.336 + trigger_error('BUMP_ERROR');
1.337 +}
1.338 +
1.339 +// Subject length limiting to 60 characters if first post...
1.340 +if ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_data['post_id']))
1.341 +{
1.342 + $template->assign_var('S_NEW_MESSAGE', true);
1.343 +}
1.344 +
1.345 +// Determine some vars
1.346 +if (isset($post_data['poster_id']) && $post_data['poster_id'] == ANONYMOUS)
1.347 +{
1.348 + $post_data['quote_username'] = (!empty($post_data['post_username'])) ? $post_data['post_username'] : $user->lang['GUEST'];
1.349 +}
1.350 +else
1.351 +{
1.352 + $post_data['quote_username'] = isset($post_data['username']) ? $post_data['username'] : '';
1.353 +}
1.354 +
1.355 +$post_data['post_edit_locked'] = (isset($post_data['post_edit_locked'])) ? (int) $post_data['post_edit_locked'] : 0;
1.356 +$post_data['post_subject_md5'] = (isset($post_data['post_subject']) && $mode == 'edit') ? md5($post_data['post_subject']) : '';
1.357 +$post_data['post_subject'] = (in_array($mode, array('quote', 'edit'))) ? $post_data['post_subject'] : ((isset($post_data['topic_title'])) ? $post_data['topic_title'] : '');
1.358 +$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;
1.359 +$post_data['poll_length'] = (!empty($post_data['poll_length'])) ? (int) $post_data['poll_length'] / 86400 : 0;
1.360 +$post_data['poll_start'] = (!empty($post_data['poll_start'])) ? (int) $post_data['poll_start'] : 0;
1.361 +$post_data['icon_id'] = (!isset($post_data['icon_id']) || in_array($mode, array('quote', 'reply'))) ? 0 : (int) $post_data['icon_id'];
1.362 +$post_data['poll_options'] = array();
1.363 +
1.364 +// Get Poll Data
1.365 +if ($post_data['poll_start'])
1.366 +{
1.367 + $sql = 'SELECT poll_option_text
1.368 + FROM ' . POLL_OPTIONS_TABLE . "
1.369 + WHERE topic_id = $topic_id
1.370 + ORDER BY poll_option_id";
1.371 + $result = $db->sql_query($sql);
1.372 +
1.373 + while ($row = $db->sql_fetchrow($result))
1.374 + {
1.375 + $post_data['poll_options'][] = trim($row['poll_option_text']);
1.376 + }
1.377 + $db->sql_freeresult($result);
1.378 +}
1.379 +
1.380 +if ($mode == 'edit')
1.381 +{
1.382 + $original_poll_data = array(
1.383 + 'poll_title' => $post_data['poll_title'],
1.384 + 'poll_length' => $post_data['poll_length'],
1.385 + 'poll_max_options' => $post_data['poll_max_options'],
1.386 + 'poll_option_text' => implode("\n", $post_data['poll_options']),
1.387 + 'poll_start' => $post_data['poll_start'],
1.388 + 'poll_last_vote' => $post_data['poll_last_vote'],
1.389 + 'poll_vote_change' => $post_data['poll_vote_change'],
1.390 + );
1.391 +}
1.392 +
1.393 +$orig_poll_options_size = sizeof($post_data['poll_options']);
1.394 +
1.395 +$message_parser = new parse_message();
1.396 +
1.397 +if (isset($post_data['post_text']))
1.398 +{
1.399 + $message_parser->message = &$post_data['post_text'];
1.400 + unset($post_data['post_text']);
1.401 +}
1.402 +
1.403 +// Set some default variables
1.404 +$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);
1.405 +
1.406 +foreach ($uninit as $var_name => $default_value)
1.407 +{
1.408 + if (!isset($post_data[$var_name]))
1.409 + {
1.410 + $post_data[$var_name] = $default_value;
1.411 + }
1.412 +}
1.413 +unset($uninit);
1.414 +
1.415 +// Always check if the submitted attachment data is valid and belongs to the user.
1.416 +// Further down (especially in submit_post()) we do not check this again.
1.417 +$message_parser->get_submitted_attachment_data($post_data['poster_id']);
1.418 +
1.419 +if ($post_data['post_attachment'] && !$submit && !$refresh && !$preview && $mode == 'edit')
1.420 +{
1.421 + // Do not change to SELECT *
1.422 + $sql = 'SELECT attach_id, is_orphan, attach_comment, real_filename
1.423 + FROM ' . ATTACHMENTS_TABLE . "
1.424 + WHERE post_msg_id = $post_id
1.425 + AND in_message = 0
1.426 + AND is_orphan = 0
1.427 + ORDER BY filetime DESC";
1.428 + $result = $db->sql_query($sql);
1.429 + $message_parser->attachment_data = array_merge($message_parser->attachment_data, $db->sql_fetchrowset($result));
1.430 + $db->sql_freeresult($result);
1.431 +}
1.432 +
1.433 +if ($post_data['poster_id'] == ANONYMOUS)
1.434 +{
1.435 + $post_data['username'] = ($mode == 'quote' || $mode == 'edit') ? trim($post_data['post_username']) : '';
1.436 +}
1.437 +else
1.438 +{
1.439 + $post_data['username'] = ($mode == 'quote' || $mode == 'edit') ? trim($post_data['username']) : '';
1.440 +}
1.441 +
1.442 +$post_data['enable_urls'] = $post_data['enable_magic_url'];
1.443 +
1.444 +if ($mode != 'edit')
1.445 +{
1.446 + $post_data['enable_sig'] = ($config['allow_sig'] && $user->optionget('attachsig')) ? true: false;
1.447 + $post_data['enable_smilies'] = ($config['allow_smilies'] && $user->optionget('smilies')) ? true : false;
1.448 + $post_data['enable_bbcode'] = ($config['allow_bbcode'] && $user->optionget('bbcode')) ? true : false;
1.449 + $post_data['enable_urls'] = true;
1.450 +}
1.451 +
1.452 +$post_data['enable_magic_url'] = $post_data['drafts'] = false;
1.453 +
1.454 +// User own some drafts?
1.455 +if ($user->data['is_registered'] && $auth->acl_get('u_savedrafts') && ($mode == 'reply' || $mode == 'post' || $mode == 'quote'))
1.456 +{
1.457 + $sql = 'SELECT draft_id
1.458 + FROM ' . DRAFTS_TABLE . '
1.459 + WHERE user_id = ' . $user->data['user_id'] .
1.460 + (($forum_id) ? ' AND forum_id = ' . (int) $forum_id : '') .
1.461 + (($topic_id) ? ' AND topic_id = ' . (int) $topic_id : '') .
1.462 + (($draft_id) ? " AND draft_id <> $draft_id" : '');
1.463 + $result = $db->sql_query_limit($sql, 1);
1.464 +
1.465 + if ($db->sql_fetchrow($result))
1.466 + {
1.467 + $post_data['drafts'] = true;
1.468 + }
1.469 + $db->sql_freeresult($result);
1.470 +}
1.471 +
1.472 +$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);
1.473 +
1.474 +// Check if user is watching this topic
1.475 +if ($mode != 'post' && $config['allow_topic_notify'] && $user->data['is_registered'])
1.476 +{
1.477 + $sql = 'SELECT topic_id
1.478 + FROM ' . TOPICS_WATCH_TABLE . '
1.479 + WHERE topic_id = ' . $topic_id . '
1.480 + AND user_id = ' . $user->data['user_id'];
1.481 + $result = $db->sql_query($sql);
1.482 + $post_data['notify_set'] = (int) $db->sql_fetchfield('topic_id');
1.483 + $db->sql_freeresult($result);
1.484 +}
1.485 +
1.486 +// Do we want to edit our post ?
1.487 +if ($mode == 'edit' && $post_data['bbcode_uid'])
1.488 +{
1.489 + $message_parser->bbcode_uid = $post_data['bbcode_uid'];
1.490 +}
1.491 +
1.492 +// HTML, BBCode, Smilies, Images and Flash status
1.493 +$bbcode_status = ($config['allow_bbcode'] && $auth->acl_get('f_bbcode', $forum_id)) ? true : false;
1.494 +$smilies_status = ($config['allow_smilies'] && $auth->acl_get('f_smilies', $forum_id)) ? true : false;
1.495 +$img_status = ($bbcode_status && $auth->acl_get('f_img', $forum_id)) ? true : false;
1.496 +$url_status = ($config['allow_post_links']) ? true : false;
1.497 +$flash_status = ($bbcode_status && $auth->acl_get('f_flash', $forum_id) && $config['allow_post_flash']) ? true : false;
1.498 +$quote_status = true;
1.499 +
1.500 +// Save Draft
1.501 +if ($save && $user->data['is_registered'] && $auth->acl_get('u_savedrafts') && ($mode == 'reply' || $mode == 'post' || $mode == 'quote'))
1.502 +{
1.503 + $subject = utf8_normalize_nfc(request_var('subject', '', true));
1.504 + $subject = (!$subject && $mode != 'post') ? $post_data['topic_title'] : $subject;
1.505 + $message = utf8_normalize_nfc(request_var('message', '', true));
1.506 +
1.507 + if ($subject && $message)
1.508 + {
1.509 + if (confirm_box(true))
1.510 + {
1.511 + $sql = 'INSERT INTO ' . DRAFTS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
1.512 + 'user_id' => (int) $user->data['user_id'],
1.513 + 'topic_id' => (int) $topic_id,
1.514 + 'forum_id' => (int) $forum_id,
1.515 + 'save_time' => (int) $current_time,
1.516 + 'draft_subject' => (string) $subject,
1.517 + 'draft_message' => (string) $message)
1.518 + );
1.519 + $db->sql_query($sql);
1.520 +
1.521 + $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");
1.522 +
1.523 + meta_refresh(3, $meta_info);
1.524 +
1.525 + $message = $user->lang['DRAFT_SAVED'] . '<br /><br />';
1.526 + $message .= ($mode != 'post') ? sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $meta_info . '">', '</a>') . '<br /><br />' : '';
1.527 + $message .= sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
1.528 +
1.529 + trigger_error($message);
1.530 + }
1.531 + else
1.532 + {
1.533 + $s_hidden_fields = build_hidden_fields(array(
1.534 + 'mode' => $mode,
1.535 + 'save' => true,
1.536 + 'f' => $forum_id,
1.537 + 't' => $topic_id,
1.538 + 'subject' => $subject,
1.539 + 'message' => $message,
1.540 + 'attachment_data' => $message_parser->attachment_data,
1.541 + )
1.542 + );
1.543 +
1.544 + $hidden_fields = array(
1.545 + 'icon_id' => 0,
1.546 +
1.547 + 'disable_bbcode' => false,
1.548 + 'disable_smilies' => false,
1.549 + 'disable_magic_url' => false,
1.550 + 'attach_sig' => true,
1.551 + 'lock_topic' => false,
1.552 +
1.553 + 'topic_type' => POST_NORMAL,
1.554 + 'topic_time_limit' => 0,
1.555 +
1.556 + 'poll_title' => '',
1.557 + 'poll_option_text' => '',
1.558 + 'poll_max_options' => 1,
1.559 + 'poll_length' => 0,
1.560 + 'poll_vote_change' => false,
1.561 + );
1.562 +
1.563 + foreach ($hidden_fields as $name => $default)
1.564 + {
1.565 + if (!isset($_POST[$name]))
1.566 + {
1.567 + // Don't include it, if its not available
1.568 + unset($hidden_fields[$name]);
1.569 + continue;
1.570 + }
1.571 +
1.572 + if (is_bool($default))
1.573 + {
1.574 + // Use the string representation
1.575 + $hidden_fields[$name] = request_var($name, '');
1.576 + }
1.577 + else
1.578 + {
1.579 + $hidden_fields[$name] = request_var($name, $default);
1.580 + }
1.581 + }
1.582 +
1.583 + $s_hidden_fields .= build_hidden_fields($hidden_fields);
1.584 +
1.585 + confirm_box(false, 'SAVE_DRAFT', $s_hidden_fields);
1.586 + }
1.587 + }
1.588 + else
1.589 + {
1.590 + if (utf8_clean_string($subject) === '')
1.591 + {
1.592 + $error[] = $user->lang['EMPTY_SUBJECT'];
1.593 + }
1.594 +
1.595 + if (utf8_clean_string($message) === '')
1.596 + {
1.597 + $error[] = $user->lang['TOO_FEW_CHARS'];
1.598 + }
1.599 + }
1.600 + unset($subject, $message);
1.601 +}
1.602 +
1.603 +// Load requested Draft
1.604 +if ($draft_id && ($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $user->data['is_registered'] && $auth->acl_get('u_savedrafts'))
1.605 +{
1.606 + $sql = 'SELECT draft_subject, draft_message
1.607 + FROM ' . DRAFTS_TABLE . "
1.608 + WHERE draft_id = $draft_id
1.609 + AND user_id = " . $user->data['user_id'];
1.610 + $result = $db->sql_query_limit($sql, 1);
1.611 + $row = $db->sql_fetchrow($result);
1.612 + $db->sql_freeresult($result);
1.613 +
1.614 + if ($row)
1.615 + {
1.616 + $post_data['post_subject'] = $row['draft_subject'];
1.617 + $message_parser->message = $row['draft_message'];
1.618 +
1.619 + $template->assign_var('S_DRAFT_LOADED', true);
1.620 + }
1.621 + else
1.622 + {
1.623 + $draft_id = 0;
1.624 + }
1.625 +}
1.626 +
1.627 +// Load draft overview
1.628 +if ($load && ($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $post_data['drafts'])
1.629 +{
1.630 + load_drafts($topic_id, $forum_id);
1.631 +}
1.632 +
1.633 +
1.634 +if ($submit || $preview || $refresh)
1.635 +{
1.636 + $post_data['topic_cur_post_id'] = request_var('topic_cur_post_id', 0);
1.637 + $post_data['post_subject'] = utf8_normalize_nfc(request_var('subject', '', true));
1.638 + $message_parser->message = utf8_normalize_nfc(request_var('message', '', true));
1.639 +
1.640 + $post_data['username'] = utf8_normalize_nfc(request_var('username', $post_data['username'], true));
1.641 + $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)) : '';
1.642 +
1.643 + $post_data['orig_topic_type'] = $post_data['topic_type'];
1.644 + $post_data['topic_type'] = request_var('topic_type', (($mode != 'post') ? (int) $post_data['topic_type'] : POST_NORMAL));
1.645 + $post_data['topic_time_limit'] = request_var('topic_time_limit', (($mode != 'post') ? (int) $post_data['topic_time_limit'] : 0));
1.646 +
1.647 + if ($post_data['enable_icons'] && $auth->acl_get('f_icons', $forum_id))
1.648 + {
1.649 + $post_data['icon_id'] = request_var('icon', (int) $post_data['icon_id']);
1.650 + }
1.651 +
1.652 + $post_data['enable_bbcode'] = (!$bbcode_status || isset($_POST['disable_bbcode'])) ? false : true;
1.653 + $post_data['enable_smilies'] = (!$smilies_status || isset($_POST['disable_smilies'])) ? false : true;
1.654 + $post_data['enable_urls'] = (isset($_POST['disable_magic_url'])) ? 0 : 1;
1.655 + $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);
1.656 +
1.657 + if ($config['allow_topic_notify'] && $user->data['is_registered'])
1.658 + {
1.659 + $notify = (isset($_POST['notify'])) ? true : false;
1.660 + }
1.661 + else
1.662 + {
1.663 + $notify = false;
1.664 + }
1.665 +
1.666 + $topic_lock = (isset($_POST['lock_topic'])) ? true : false;
1.667 + $post_lock = (isset($_POST['lock_post'])) ? true : false;
1.668 + $poll_delete = (isset($_POST['poll_delete'])) ? true : false;
1.669 +
1.670 + if ($submit)
1.671 + {
1.672 + $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);
1.673 + $status_switch = ($status_switch != $check_value);
1.674 + }
1.675 + else
1.676 + {
1.677 + $status_switch = 1;
1.678 + }
1.679 +
1.680 + // Delete Poll
1.681 + if ($poll_delete && $mode == 'edit' && sizeof($post_data['poll_options']) &&
1.682 + ((!$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)))
1.683 + {
1.684 + if ($submit && check_form_key('posting'))
1.685 + {
1.686 + $sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . "
1.687 + WHERE topic_id = $topic_id";
1.688 + $db->sql_query($sql);
1.689 +
1.690 + $sql = 'DELETE FROM ' . POLL_VOTES_TABLE . "
1.691 + WHERE topic_id = $topic_id";
1.692 + $db->sql_query($sql);
1.693 +
1.694 + $topic_sql = array(
1.695 + 'poll_title' => '',
1.696 + 'poll_start' => 0,
1.697 + 'poll_length' => 0,
1.698 + 'poll_last_vote' => 0,
1.699 + 'poll_max_options' => 0,
1.700 + 'poll_vote_change' => 0
1.701 + );
1.702 +
1.703 + $sql = 'UPDATE ' . TOPICS_TABLE . '
1.704 + SET ' . $db->sql_build_array('UPDATE', $topic_sql) . "
1.705 + WHERE topic_id = $topic_id";
1.706 + $db->sql_query($sql);
1.707 + }
1.708 +
1.709 + $post_data['poll_title'] = $post_data['poll_option_text'] = '';
1.710 + $post_data['poll_vote_change'] = $post_data['poll_max_options'] = $post_data['poll_length'] = 0;
1.711 + }
1.712 + else
1.713 + {
1.714 + $post_data['poll_title'] = utf8_normalize_nfc(request_var('poll_title', '', true));
1.715 + $post_data['poll_length'] = request_var('poll_length', 0);
1.716 + $post_data['poll_option_text'] = utf8_normalize_nfc(request_var('poll_option_text', '', true));
1.717 + $post_data['poll_max_options'] = request_var('poll_max_options', 1);
1.718 + $post_data['poll_vote_change'] = ($auth->acl_get('f_votechg', $forum_id) && $auth->acl_get('f_vote', $forum_id) && isset($_POST['poll_vote_change'])) ? 1 : 0;
1.719 + }
1.720 +
1.721 + // If replying/quoting and last post id has changed
1.722 + // give user option to continue submit or return to post
1.723 + // notify and show user the post made between his request and the final submit
1.724 + if (($mode == 'reply' || $mode == 'quote') && $post_data['topic_cur_post_id'] && $post_data['topic_cur_post_id'] != $post_data['topic_last_post_id'])
1.725 + {
1.726 + // Only do so if it is allowed forum-wide
1.727 + if ($post_data['forum_flags'] & FORUM_FLAG_POST_REVIEW)
1.728 + {
1.729 + if (topic_review($topic_id, $forum_id, 'post_review', $post_data['topic_cur_post_id']))
1.730 + {
1.731 + $template->assign_var('S_POST_REVIEW', true);
1.732 + }
1.733 +
1.734 + $submit = false;
1.735 + $refresh = true;
1.736 + }
1.737 + }
1.738 +
1.739 + // Parse Attachments - before checksum is calculated
1.740 + $message_parser->parse_attachments('fileupload', $mode, $forum_id, $submit, $preview, $refresh);
1.741 +
1.742 + // Grab md5 'checksum' of new message
1.743 + $message_md5 = md5($message_parser->message);
1.744 +
1.745 + // If editing and checksum has changed we know the post was edited while we're editing
1.746 + // Notify and show user the changed post
1.747 + if ($mode == 'edit' && $post_data['forum_flags'] & FORUM_FLAG_POST_REVIEW)
1.748 + {
1.749 + $edit_post_message_checksum = request_var('edit_post_message_checksum', '');
1.750 + $edit_post_subject_checksum = request_var('edit_post_subject_checksum', '');
1.751 +
1.752 + // $post_data['post_checksum'] is the checksum of the post submitted in the meantime
1.753 + // $message_md5 is the checksum of the post we're about to submit
1.754 + // $edit_post_message_checksum is the checksum of the post we're editing
1.755 + // ...
1.756 +
1.757 + // We make sure nobody else made exactly the same change
1.758 + // we're about to submit by also checking $message_md5 != $post_data['post_checksum']
1.759 + if (($edit_post_message_checksum !== '' && $edit_post_message_checksum != $post_data['post_checksum'] && $message_md5 != $post_data['post_checksum'])
1.760 + || ($edit_post_subject_checksum !== '' && $edit_post_subject_checksum != $post_data['post_subject_md5'] && md5($post_data['post_subject']) != $post_data['post_subject_md5']))
1.761 + {
1.762 + if (topic_review($topic_id, $forum_id, 'post_review_edit', $post_id))
1.763 + {
1.764 + $template->assign_vars(array(
1.765 + 'S_POST_REVIEW' => true,
1.766 +
1.767 + 'L_POST_REVIEW' => $user->lang['POST_REVIEW_EDIT'],
1.768 + 'L_POST_REVIEW_EXPLAIN' => $user->lang['POST_REVIEW_EDIT_EXPLAIN'],
1.769 + ));
1.770 + }
1.771 +
1.772 + $submit = false;
1.773 + $refresh = true;
1.774 + }
1.775 + }
1.776 +
1.777 + // Check checksum ... don't re-parse message if the same
1.778 + $update_message = ($mode != 'edit' || $message_md5 != $post_data['post_checksum'] || $status_switch || strlen($post_data['bbcode_uid']) < BBCODE_UID_LEN) ? true : false;
1.779 +
1.780 + // Also check if subject got updated...
1.781 + $update_subject = $mode != 'edit' || ($post_data['post_subject_md5'] && $post_data['post_subject_md5'] != md5($post_data['post_subject']));
1.782 +
1.783 + // Parse message
1.784 + if ($update_message)
1.785 + {
1.786 + if (sizeof($message_parser->warn_msg))
1.787 + {
1.788 + $error[] = implode('<br />', $message_parser->warn_msg);
1.789 + $message_parser->warn_msg = array();
1.790 + }
1.791 +
1.792 + $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']);
1.793 +
1.794 + // On a refresh we do not care about message parsing errors
1.795 + if (sizeof($message_parser->warn_msg) && $refresh)
1.796 + {
1.797 + $message_parser->warn_msg = array();
1.798 + }
1.799 + }
1.800 + else
1.801 + {
1.802 + $message_parser->bbcode_bitfield = $post_data['bbcode_bitfield'];
1.803 + }
1.804 +
1.805 + if ($mode != 'edit' && !$preview && !$refresh && $config['flood_interval'] && !$auth->acl_get('f_ignoreflood', $forum_id))
1.806 + {
1.807 + // Flood check
1.808 + $last_post_time = 0;
1.809 +
1.810 + if ($user->data['is_registered'])
1.811 + {
1.812 + $last_post_time = $user->data['user_lastpost_time'];
1.813 + }
1.814 + else
1.815 + {
1.816 + $sql = 'SELECT post_time AS last_post_time
1.817 + FROM ' . POSTS_TABLE . "
1.818 + WHERE poster_ip = '" . $user->ip . "'
1.819 + AND post_time > " . ($current_time - $config['flood_interval']);
1.820 + $result = $db->sql_query_limit($sql, 1);
1.821 + if ($row = $db->sql_fetchrow($result))
1.822 + {
1.823 + $last_post_time = $row['last_post_time'];
1.824 + }
1.825 + $db->sql_freeresult($result);
1.826 + }
1.827 +
1.828 + if ($last_post_time && ($current_time - $last_post_time) < intval($config['flood_interval']))
1.829 + {
1.830 + $error[] = $user->lang['FLOOD_ERROR'];
1.831 + }
1.832 + }
1.833 +
1.834 + // Validate username
1.835 + 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']))
1.836 + {
1.837 + include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
1.838 +
1.839 + $user->add_lang('ucp');
1.840 +
1.841 + if (($result = validate_username($post_data['username'], (!empty($post_data['post_username'])) ? $post_data['post_username'] : '')) !== false)
1.842 + {
1.843 + $error[] = $user->lang[$result . '_USERNAME'];
1.844 + }
1.845 +
1.846 + if (($result = validate_string($post_data['username'], false, $config['min_name_chars'], $config['max_name_chars'])) !== false)
1.847 + {
1.848 + $min_max_amount = ($result == 'TOO_SHORT') ? $config['min_name_chars'] : $config['max_name_chars'];
1.849 + $error[] = sprintf($user->lang['FIELD_' . $result], $user->lang['USERNAME'], $min_max_amount);
1.850 + }
1.851 + }
1.852 +
1.853 + if ($config['enable_post_confirm'] && !$user->data['is_registered'] && in_array($mode, array('quote', 'post', 'reply')))
1.854 + {
1.855 + $captcha_data = array(
1.856 + 'message' => utf8_normalize_nfc(request_var('message', '', true)),
1.857 + 'subject' => utf8_normalize_nfc(request_var('subject', '', true)),
1.858 + 'username' => utf8_normalize_nfc(request_var('username', '', true)),
1.859 + );
1.860 + $vc_response = $captcha->validate($captcha_data);
1.861 + if ($vc_response)
1.862 + {
1.863 + $error[] = $vc_response;
1.864 + }
1.865 + }
1.866 +
1.867 + // check form
1.868 + if (($submit || $preview) && !check_form_key('posting'))
1.869 + {
1.870 + $error[] = $user->lang['FORM_INVALID'];
1.871 + }
1.872 +
1.873 + // Parse subject
1.874 + if (!$preview && !$refresh && utf8_clean_string($post_data['post_subject']) === '' && ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_id)))
1.875 + {
1.876 + $error[] = $user->lang['EMPTY_SUBJECT'];
1.877 + }
1.878 +
1.879 + $post_data['poll_last_vote'] = (isset($post_data['poll_last_vote'])) ? $post_data['poll_last_vote'] : 0;
1.880 +
1.881 + if ($post_data['poll_option_text'] &&
1.882 + ($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id']/* && (!$post_data['poll_last_vote'] || $auth->acl_get('m_edit', $forum_id))*/))
1.883 + && $auth->acl_get('f_poll', $forum_id))
1.884 + {
1.885 + $poll = array(
1.886 + 'poll_title' => $post_data['poll_title'],
1.887 + 'poll_length' => $post_data['poll_length'],
1.888 + 'poll_max_options' => $post_data['poll_max_options'],
1.889 + 'poll_option_text' => $post_data['poll_option_text'],
1.890 + 'poll_start' => $post_data['poll_start'],
1.891 + 'poll_last_vote' => $post_data['poll_last_vote'],
1.892 + 'poll_vote_change' => $post_data['poll_vote_change'],
1.893 + 'enable_bbcode' => $post_data['enable_bbcode'],
1.894 + 'enable_urls' => $post_data['enable_urls'],
1.895 + 'enable_smilies' => $post_data['enable_smilies'],
1.896 + 'img_status' => $img_status
1.897 + );
1.898 +
1.899 + $message_parser->parse_poll($poll);
1.900 +
1.901 + $post_data['poll_options'] = (isset($poll['poll_options'])) ? $poll['poll_options'] : array();
1.902 + $post_data['poll_title'] = (isset($poll['poll_title'])) ? $poll['poll_title'] : '';
1.903 +
1.904 + /* We reset votes, therefore also allow removing options
1.905 + if ($post_data['poll_last_vote'] && ($poll['poll_options_size'] < $orig_poll_options_size))
1.906 + {
1.907 + $message_parser->warn_msg[] = $user->lang['NO_DELETE_POLL_OPTIONS'];
1.908 + }*/
1.909 + }
1.910 + else if ($mode == 'edit' && $post_id == $post_data['topic_first_post_id'] && $auth->acl_get('f_poll', $forum_id))
1.911 + {
1.912 + // The user removed all poll options, this is equal to deleting the poll.
1.913 + $poll = array(
1.914 + 'poll_title' => '',
1.915 + 'poll_length' => 0,
1.916 + 'poll_max_options' => 0,
1.917 + 'poll_option_text' => '',
1.918 + 'poll_start' => 0,
1.919 + 'poll_last_vote' => 0,
1.920 + 'poll_vote_change' => 0,
1.921 + 'poll_options' => array(),
1.922 + );
1.923 +
1.924 + $post_data['poll_options'] = array();
1.925 + $post_data['poll_title'] = '';
1.926 + $post_data['poll_start'] = $post_data['poll_length'] = $post_data['poll_max_options'] = $post_data['poll_last_vote'] = $post_data['poll_vote_change'] = 0;
1.927 + }
1.928 + else if (!$auth->acl_get('f_poll', $forum_id) && ($mode == 'edit') && ($post_id == $post_data['topic_first_post_id']) && ($original_poll_data['poll_title'] != ''))
1.929 + {
1.930 + // We have a poll but the editing user is not permitted to create/edit it.
1.931 + // So we just keep the original poll-data.
1.932 + $poll = array_merge($original_poll_data, array(
1.933 + 'enable_bbcode' => $post_data['enable_bbcode'],
1.934 + 'enable_urls' => $post_data['enable_urls'],
1.935 + 'enable_smilies' => $post_data['enable_smilies'],
1.936 + 'img_status' => $img_status,
1.937 + ));
1.938 +
1.939 + $message_parser->parse_poll($poll);
1.940 +
1.941 + $post_data['poll_options'] = (isset($poll['poll_options'])) ? $poll['poll_options'] : array();
1.942 + $post_data['poll_title'] = (isset($poll['poll_title'])) ? $poll['poll_title'] : '';
1.943 + }
1.944 + else
1.945 + {
1.946 + $poll = array();
1.947 + }
1.948 +
1.949 + // Check topic type
1.950 + if ($post_data['topic_type'] != POST_NORMAL && ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_id)))
1.951 + {
1.952 + switch ($post_data['topic_type'])
1.953 + {
1.954 + case POST_GLOBAL:
1.955 + case POST_ANNOUNCE:
1.956 + $auth_option = 'f_announce';
1.957 + break;
1.958 +
1.959 + case POST_STICKY:
1.960 + $auth_option = 'f_sticky';
1.961 + break;
1.962 +
1.963 + default:
1.964 + $auth_option = '';
1.965 + break;
1.966 + }
1.967 +
1.968 + if (!$auth->acl_get($auth_option, $forum_id))
1.969 + {
1.970 + // There is a special case where a user edits his post whereby the topic type got changed by an admin/mod.
1.971 + // Another case would be a mod not having sticky permissions for example but edit permissions.
1.972 + if ($mode == 'edit')
1.973 + {
1.974 + // To prevent non-authed users messing around with the topic type we reset it to the original one.
1.975 + $post_data['topic_type'] = $post_data['orig_topic_type'];
1.976 + }
1.977 + else
1.978 + {
1.979 + $error[] = $user->lang['CANNOT_POST_' . str_replace('F_', '', strtoupper($auth_option))];
1.980 + }
1.981 + }
1.982 + }
1.983 +
1.984 + if (sizeof($message_parser->warn_msg))
1.985 + {
1.986 + $error[] = implode('<br />', $message_parser->warn_msg);
1.987 + }
1.988 +
1.989 + // DNSBL check
1.990 + if ($config['check_dnsbl'] && !$refresh)
1.991 + {
1.992 + if (($dnsbl = $user->check_dnsbl('post')) !== false)
1.993 + {
1.994 + $error[] = sprintf($user->lang['IP_BLACKLISTED'], $user->ip, $dnsbl[1]);
1.995 + }
1.996 + }
1.997 +
1.998 + // Store message, sync counters
1.999 + if (!sizeof($error) && $submit)
1.1000 + {
1.1001 + // Check if we want to de-globalize the topic... and ask for new forum
1.1002 + if ($post_data['topic_type'] != POST_GLOBAL)
1.1003 + {
1.1004 + $sql = 'SELECT topic_type, forum_id
1.1005 + FROM ' . TOPICS_TABLE . "
1.1006 + WHERE topic_id = $topic_id";
1.1007 + $result = $db->sql_query($sql);
1.1008 + $row = $db->sql_fetchrow($result);
1.1009 + $db->sql_freeresult($result);
1.1010 +
1.1011 + if ($row && !$row['forum_id'] && $row['topic_type'] == POST_GLOBAL)
1.1012 + {
1.1013 + $to_forum_id = request_var('to_forum_id', 0);
1.1014 +
1.1015 + if ($to_forum_id)
1.1016 + {
1.1017 + $sql = 'SELECT forum_type
1.1018 + FROM ' . FORUMS_TABLE . '
1.1019 + WHERE forum_id = ' . $to_forum_id;
1.1020 + $result = $db->sql_query($sql);
1.1021 + $forum_type = (int) $db->sql_fetchfield('forum_type');
1.1022 + $db->sql_freeresult($result);
1.1023 +
1.1024 + if ($forum_type != FORUM_POST || !$auth->acl_get('f_post', $to_forum_id) || (!$auth->acl_get('m_approve', $to_forum_id) && !$auth->acl_get('f_noapprove', $to_forum_id)))
1.1025 + {
1.1026 + $to_forum_id = 0;
1.1027 + }
1.1028 + }
1.1029 +
1.1030 + if (!$to_forum_id)
1.1031 + {
1.1032 + include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
1.1033 +
1.1034 + $template->assign_vars(array(
1.1035 + 'S_FORUM_SELECT' => make_forum_select(false, false, false, true, true, true),
1.1036 + 'S_UNGLOBALISE' => true)
1.1037 + );
1.1038 +
1.1039 + $submit = false;
1.1040 + $refresh = true;
1.1041 + }
1.1042 + else
1.1043 + {
1.1044 + if (!$auth->acl_get('f_post', $to_forum_id))
1.1045 + {
1.1046 + // This will only be triggered if the user tried to trick the forum.
1.1047 + trigger_error('NOT_AUTHORISED');
1.1048 + }
1.1049 +
1.1050 + $forum_id = $to_forum_id;
1.1051 + }
1.1052 + }
1.1053 + }
1.1054 +
1.1055 + if ($submit)
1.1056 + {
1.1057 + // Lock/Unlock Topic
1.1058 + $change_topic_status = $post_data['topic_status'];
1.1059 + $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;
1.1060 +
1.1061 + if ($post_data['topic_status'] == ITEM_LOCKED && !$topic_lock && $perm_lock_unlock)
1.1062 + {
1.1063 + $change_topic_status = ITEM_UNLOCKED;
1.1064 + }
1.1065 + else if ($post_data['topic_status'] == ITEM_UNLOCKED && $topic_lock && $perm_lock_unlock)
1.1066 + {
1.1067 + $change_topic_status = ITEM_LOCKED;
1.1068 + }
1.1069 +
1.1070 + if ($change_topic_status != $post_data['topic_status'])
1.1071 + {
1.1072 + $sql = 'UPDATE ' . TOPICS_TABLE . "
1.1073 + SET topic_status = $change_topic_status
1.1074 + WHERE topic_id = $topic_id
1.1075 + AND topic_moved_id = 0";
1.1076 + $db->sql_query($sql);
1.1077 +
1.1078 + $user_lock = ($auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && $user->data['user_id'] == $post_data['topic_poster']) ? 'USER_' : '';
1.1079 +
1.1080 + add_log('mod', $forum_id, $topic_id, 'LOG_' . $user_lock . (($change_topic_status == ITEM_LOCKED) ? 'LOCK' : 'UNLOCK'), $post_data['topic_title']);
1.1081 + }
1.1082 +
1.1083 + // Lock/Unlock Post Edit
1.1084 + if ($mode == 'edit' && $post_data['post_edit_locked'] == ITEM_LOCKED && !$post_lock && $auth->acl_get('m_edit', $forum_id))
1.1085 + {
1.1086 + $post_data['post_edit_locked'] = ITEM_UNLOCKED;
1.1087 + }
1.1088 + else if ($mode == 'edit' && $post_data['post_edit_locked'] == ITEM_UNLOCKED && $post_lock && $auth->acl_get('m_edit', $forum_id))
1.1089 + {
1.1090 + $post_data['post_edit_locked'] = ITEM_LOCKED;
1.1091 + }
1.1092 +
1.1093 + $data = array(
1.1094 + 'topic_title' => (empty($post_data['topic_title'])) ? $post_data['post_subject'] : $post_data['topic_title'],
1.1095 + 'topic_first_post_id' => (isset($post_data['topic_first_post_id'])) ? (int) $post_data['topic_first_post_id'] : 0,
1.1096 + 'topic_last_post_id' => (isset($post_data['topic_last_post_id'])) ? (int) $post_data['topic_last_post_id'] : 0,
1.1097 + 'topic_time_limit' => (int) $post_data['topic_time_limit'],
1.1098 + 'topic_attachment' => (isset($post_data['topic_attachment'])) ? (int) $post_data['topic_attachment'] : 0,
1.1099 + 'post_id' => (int) $post_id,
1.1100 + 'topic_id' => (int) $topic_id,
1.1101 + 'forum_id' => (int) $forum_id,
1.1102 + 'icon_id' => (int) $post_data['icon_id'],
1.1103 + 'poster_id' => (int) $post_data['poster_id'],
1.1104 + 'enable_sig' => (bool) $post_data['enable_sig'],
1.1105 + 'enable_bbcode' => (bool) $post_data['enable_bbcode'],
1.1106 + 'enable_smilies' => (bool) $post_data['enable_smilies'],
1.1107 + 'enable_urls' => (bool) $post_data['enable_urls'],
1.1108 + 'enable_indexing' => (bool) $post_data['enable_indexing'],
1.1109 + 'message_md5' => (string) $message_md5,
1.1110 + 'post_time' => (isset($post_data['post_time'])) ? (int) $post_data['post_time'] : $current_time,
1.1111 + 'post_checksum' => (isset($post_data['post_checksum'])) ? (string) $post_data['post_checksum'] : '',
1.1112 + 'post_edit_reason' => $post_data['post_edit_reason'],
1.1113 + 'post_edit_user' => ($mode == 'edit') ? $user->data['user_id'] : ((isset($post_data['post_edit_user'])) ? (int) $post_data['post_edit_user'] : 0),
1.1114 + 'forum_parents' => $post_data['forum_parents'],
1.1115 + 'forum_name' => $post_data['forum_name'],
1.1116 + 'notify' => $notify,
1.1117 + 'notify_set' => $post_data['notify_set'],
1.1118 + 'poster_ip' => (isset($post_data['poster_ip'])) ? $post_data['poster_ip'] : $user->ip,
1.1119 + 'post_edit_locked' => (int) $post_data['post_edit_locked'],
1.1120 + 'bbcode_bitfield' => $message_parser->bbcode_bitfield,
1.1121 + 'bbcode_uid' => $message_parser->bbcode_uid,
1.1122 + 'message' => $message_parser->message,
1.1123 + 'attachment_data' => $message_parser->attachment_data,
1.1124 + 'filename_data' => $message_parser->filename_data,
1.1125 +
1.1126 + 'topic_approved' => (isset($post_data['topic_approved'])) ? $post_data['topic_approved'] : false,
1.1127 + 'post_approved' => (isset($post_data['post_approved'])) ? $post_data['post_approved'] : false,
1.1128 + );
1.1129 +
1.1130 + if ($mode == 'edit')
1.1131 + {
1.1132 + $data['topic_replies_real'] = $post_data['topic_replies_real'];
1.1133 + $data['topic_replies'] = $post_data['topic_replies'];
1.1134 + }
1.1135 +
1.1136 + // The last parameter tells submit_post if search indexer has to be run
1.1137 + $redirect_url = submit_post($mode, $post_data['post_subject'], $post_data['username'], $post_data['topic_type'], $poll, $data, $update_message, ($update_message || $update_subject) ? true : false);
1.1138 +
1.1139 + if ($config['enable_post_confirm'] && !$user->data['is_registered'] && (isset($captcha) && $captcha->is_solved() === true) && ($mode == 'post' || $mode == 'reply' || $mode == 'quote'))
1.1140 + {
1.1141 + $captcha->reset();
1.1142 + }
1.1143 +
1.1144 + // Check the permissions for post approval. Moderators are not affected.
1.1145 + if ((!$auth->acl_get('f_noapprove', $data['forum_id']) && !$auth->acl_get('m_approve', $data['forum_id']) && empty($data['force_approved_state'])) || (isset($data['force_approved_state']) && !$data['force_approved_state']))
1.1146 + {
1.1147 + meta_refresh(10, $redirect_url);
1.1148 + $message = ($mode == 'edit') ? $user->lang['POST_EDITED_MOD'] : $user->lang['POST_STORED_MOD'];
1.1149 + $message .= (($user->data['user_id'] == ANONYMOUS) ? '' : ' '. $user->lang['POST_APPROVAL_NOTIFY']);
1.1150 + }
1.1151 + else
1.1152 + {
1.1153 + meta_refresh(3, $redirect_url);
1.1154 +
1.1155 + $message = ($mode == 'edit') ? 'POST_EDITED' : 'POST_STORED';
1.1156 + $message = $user->lang[$message] . '<br /><br />' . sprintf($user->lang['VIEW_MESSAGE'], '<a href="' . $redirect_url . '">', '</a>');
1.1157 + }
1.1158 +
1.1159 + $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $data['forum_id']) . '">', '</a>');
1.1160 + trigger_error($message);
1.1161 + }
1.1162 + }
1.1163 +}
1.1164 +
1.1165 +// Preview
1.1166 +if (!sizeof($error) && $preview)
1.1167 +{
1.1168 + $post_data['post_time'] = ($mode == 'edit') ? $post_data['post_time'] : $current_time;
1.1169 +
1.1170 + $preview_message = $message_parser->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies'], false);
1.1171 +
1.1172 + $preview_signature = ($mode == 'edit') ? $post_data['user_sig'] : $user->data['user_sig'];
1.1173 + $preview_signature_uid = ($mode == 'edit') ? $post_data['user_sig_bbcode_uid'] : $user->data['user_sig_bbcode_uid'];
1.1174 + $preview_signature_bitfield = ($mode == 'edit') ? $post_data['user_sig_bbcode_bitfield'] : $user->data['user_sig_bbcode_bitfield'];
1.1175 +
1.1176 + // Signature
1.1177 + if ($post_data['enable_sig'] && $config['allow_sig'] && $preview_signature && $auth->acl_get('f_sigs', $forum_id))
1.1178 + {
1.1179 + $parse_sig = new parse_message($preview_signature);
1.1180 + $parse_sig->bbcode_uid = $preview_signature_uid;
1.1181 + $parse_sig->bbcode_bitfield = $preview_signature_bitfield;
1.1182 +
1.1183 + // Not sure about parameters for bbcode/smilies/urls... in signatures
1.1184 + $parse_sig->format_display($config['allow_sig_bbcode'], $config['allow_sig_links'], $config['allow_sig_smilies']);
1.1185 + $preview_signature = $parse_sig->message;
1.1186 + unset($parse_sig);
1.1187 + }
1.1188 + else
1.1189 + {
1.1190 + $preview_signature = '';
1.1191 + }
1.1192 +
1.1193 + $preview_subject = censor_text($post_data['post_subject']);
1.1194 +
1.1195 + // Poll Preview
1.1196 + 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))*/))
1.1197 + && $auth->acl_get('f_poll', $forum_id))
1.1198 + {
1.1199 + $parse_poll = new parse_message($post_data['poll_title']);
1.1200 + $parse_poll->bbcode_uid = $message_parser->bbcode_uid;
1.1201 + $parse_poll->bbcode_bitfield = $message_parser->bbcode_bitfield;
1.1202 +
1.1203 + $parse_poll->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies']);
1.1204 +
1.1205 + if ($post_data['poll_length'])
1.1206 + {
1.1207 + $poll_end = ($post_data['poll_length'] * 86400) + (($post_data['poll_start']) ? $post_data['poll_start'] : time());
1.1208 + }
1.1209 +
1.1210 + $template->assign_vars(array(
1.1211 + 'S_HAS_POLL_OPTIONS' => (sizeof($post_data['poll_options'])),
1.1212 + 'S_IS_MULTI_CHOICE' => ($post_data['poll_max_options'] > 1) ? true : false,
1.1213 +
1.1214 + 'POLL_QUESTION' => $parse_poll->message,
1.1215 +
1.1216 + 'L_POLL_LENGTH' => ($post_data['poll_length']) ? sprintf($user->lang['POLL_RUN_TILL'], $user->format_date($poll_end)) : '',
1.1217 + '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']))
1.1218 + );
1.1219 +
1.1220 + $parse_poll->message = implode("\n", $post_data['poll_options']);
1.1221 + $parse_poll->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies']);
1.1222 + $preview_poll_options = explode('<br />', $parse_poll->message);
1.1223 + unset($parse_poll);
1.1224 +
1.1225 + foreach ($preview_poll_options as $key => $option)
1.1226 + {
1.1227 + $template->assign_block_vars('poll_option', array(
1.1228 + 'POLL_OPTION_CAPTION' => $option,
1.1229 + 'POLL_OPTION_ID' => $key + 1)
1.1230 + );
1.1231 + }
1.1232 + unset($preview_poll_options);
1.1233 + }
1.1234 +
1.1235 + // Attachment Preview
1.1236 + if (sizeof($message_parser->attachment_data))
1.1237 + {
1.1238 + $template->assign_var('S_HAS_ATTACHMENTS', true);
1.1239 +
1.1240 + $update_count = array();
1.1241 + $attachment_data = $message_parser->attachment_data;
1.1242 +
1.1243 + parse_attachments($forum_id, $preview_message, $attachment_data, $update_count, true);
1.1244 +
1.1245 + foreach ($attachment_data as $i => $attachment)
1.1246 + {
1.1247 + $template->assign_block_vars('attachment', array(
1.1248 + 'DISPLAY_ATTACHMENT' => $attachment)
1.1249 + );
1.1250 + }
1.1251 + unset($attachment_data);
1.1252 + }
1.1253 +
1.1254 + if (!sizeof($error))
1.1255 + {
1.1256 + $template->assign_vars(array(
1.1257 + 'PREVIEW_SUBJECT' => $preview_subject,
1.1258 + 'PREVIEW_MESSAGE' => $preview_message,
1.1259 + 'PREVIEW_SIGNATURE' => $preview_signature,
1.1260 +
1.1261 + 'S_DISPLAY_PREVIEW' => true)
1.1262 + );
1.1263 + }
1.1264 +}
1.1265 +
1.1266 +// Decode text for message display
1.1267 +$post_data['bbcode_uid'] = ($mode == 'quote' && !$preview && !$refresh && !sizeof($error)) ? $post_data['bbcode_uid'] : $message_parser->bbcode_uid;
1.1268 +$message_parser->decode_message($post_data['bbcode_uid']);
1.1269 +
1.1270 +if ($mode == 'quote' && !$submit && !$preview && !$refresh)
1.1271 +{
1.1272 + if ($config['allow_bbcode'])
1.1273 + {
1.1274 + $message_parser->message = '[quote="' . $post_data['quote_username'] . '"]' . censor_text(trim($message_parser->message)) . "[/quote]\n";
1.1275 + }
1.1276 + else
1.1277 + {
1.1278 + $offset = 0;
1.1279 + $quote_string = "> ";
1.1280 + $message = censor_text(trim($message_parser->message));
1.1281 + // see if we are nesting. It's easily tricked but should work for one level of nesting
1.1282 + if (strpos($message, ">") !== false)
1.1283 + {
1.1284 + $offset = 10;
1.1285 + }
1.1286 + $message = utf8_wordwrap($message, 75 + $offset, "\n");
1.1287 +
1.1288 + $message = $quote_string . $message;
1.1289 + $message = str_replace("\n", "\n" . $quote_string, $message);
1.1290 + $message_parser->message = $post_data['quote_username'] . " " . $user->lang['WROTE'] . ":\n" . $message . "\n";
1.1291 + }
1.1292 +}
1.1293 +
1.1294 +if (($mode == 'reply' || $mode == 'quote') && !$submit && !$preview && !$refresh)
1.1295 +{
1.1296 + $post_data['post_subject'] = ((strpos($post_data['post_subject'], 'Re: ') !== 0) ? 'Re: ' : '') . censor_text($post_data['post_subject']);
1.1297 +}
1.1298 +
1.1299 +$attachment_data = $message_parser->attachment_data;
1.1300 +$filename_data = $message_parser->filename_data;
1.1301 +$post_data['post_text'] = $message_parser->message;
1.1302 +
1.1303 +if (sizeof($post_data['poll_options']) || !empty($post_data['poll_title']))
1.1304 +{
1.1305 + $message_parser->message = $post_data['poll_title'];
1.1306 + $message_parser->bbcode_uid = $post_data['bbcode_uid'];
1.1307 +
1.1308 + $message_parser->decode_message();
1.1309 + $post_data['poll_title'] = $message_parser->message;
1.1310 +
1.1311 + $message_parser->message = implode("\n", $post_data['poll_options']);
1.1312 + $message_parser->decode_message();
1.1313 + $post_data['poll_options'] = explode("\n", $message_parser->message);
1.1314 +}
1.1315 +
1.1316 +// MAIN POSTING PAGE BEGINS HERE
1.1317 +
1.1318 +// Forum moderators?
1.1319 +$moderators = array();
1.1320 +if ($config['load_moderators'])
1.1321 +{
1.1322 + get_moderators($moderators, $forum_id);
1.1323 +}
1.1324 +
1.1325 +// Generate smiley listing
1.1326 +generate_smilies('inline', $forum_id);
1.1327 +
1.1328 +// Generate inline attachment select box
1.1329 +posting_gen_inline_attachments($attachment_data);
1.1330 +
1.1331 +// Do show topic type selection only in first post.
1.1332 +$topic_type_toggle = false;
1.1333 +
1.1334 +if ($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id']))
1.1335 +{
1.1336 + $topic_type_toggle = posting_gen_topic_types($forum_id, $post_data['topic_type']);
1.1337 +}
1.1338 +
1.1339 +$s_topic_icons = false;
1.1340 +if ($post_data['enable_icons'] && $auth->acl_get('f_icons', $forum_id))
1.1341 +{
1.1342 + $s_topic_icons = posting_gen_topic_icons($mode, $post_data['icon_id']);
1.1343 +}
1.1344 +
1.1345 +$bbcode_checked = (isset($post_data['enable_bbcode'])) ? !$post_data['enable_bbcode'] : (($config['allow_bbcode']) ? !$user->optionget('bbcode') : 1);
1.1346 +$smilies_checked = (isset($post_data['enable_smilies'])) ? !$post_data['enable_smilies'] : (($config['allow_smilies']) ? !$user->optionget('smilies') : 1);
1.1347 +$urls_checked = (isset($post_data['enable_urls'])) ? !$post_data['enable_urls'] : 0;
1.1348 +$sig_checked = $post_data['enable_sig'];
1.1349 +$lock_topic_checked = (isset($topic_lock) && $topic_lock) ? $topic_lock : (($post_data['topic_status'] == ITEM_LOCKED) ? 1 : 0);
1.1350 +$lock_post_checked = (isset($post_lock)) ? $post_lock : $post_data['post_edit_locked'];
1.1351 +
1.1352 +// 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
1.1353 +$notify_set = ($mode != 'edit' && $config['allow_topic_notify'] && $user->data['is_registered'] && !$post_data['notify_set']) ? $user->data['user_notify'] : $post_data['notify_set'];
1.1354 +$notify_checked = (isset($notify)) ? $notify : (($mode == 'post') ? $user->data['user_notify'] : $notify_set);
1.1355 +
1.1356 +// Page title & action URL
1.1357 +$s_action = append_sid("{$phpbb_root_path}posting.$phpEx", "mode=$mode&f=$forum_id");
1.1358 +$s_action .= ($topic_id) ? "&t=$topic_id" : '';
1.1359 +$s_action .= ($post_id) ? "&p=$post_id" : '';
1.1360 +
1.1361 +switch ($mode)
1.1362 +{
1.1363 + case 'post':
1.1364 + $page_title = $user->lang['POST_TOPIC'];
1.1365 + break;
1.1366 +
1.1367 + case 'quote':
1.1368 + case 'reply':
1.1369 + $page_title = $user->lang['POST_REPLY'];
1.1370 + break;
1.1371 +
1.1372 + case 'delete':
1.1373 + case 'edit':
1.1374 + $page_title = $user->lang['EDIT_POST'];
1.1375 + break;
1.1376 +}
1.1377 +
1.1378 +// Build Navigation Links
1.1379 +generate_forum_nav($post_data);
1.1380 +
1.1381 +// Build Forum Rules
1.1382 +generate_forum_rules($post_data);
1.1383 +
1.1384 +// Posting uses is_solved for legacy reasons. Plugins have to use is_solved to force themselves to be displayed.
1.1385 +if ($config['enable_post_confirm'] && !$user->data['is_registered'] && (isset($captcha) && $captcha->is_solved() === false) && ($mode == 'post' || $mode == 'reply' || $mode == 'quote'))
1.1386 +{
1.1387 +
1.1388 + $template->assign_vars(array(
1.1389 + 'S_CONFIRM_CODE' => true,
1.1390 + 'CAPTCHA_TEMPLATE' => $captcha->get_template(),
1.1391 + ));
1.1392 +}
1.1393 +
1.1394 +$s_hidden_fields = ($mode == 'reply' || $mode == 'quote') ? '<input type="hidden" name="topic_cur_post_id" value="' . $post_data['topic_last_post_id'] . '" />' : '';
1.1395 +$s_hidden_fields .= '<input type="hidden" name="lastclick" value="' . $current_time . '" />';
1.1396 +$s_hidden_fields .= ($draft_id || isset($_REQUEST['draft_loaded'])) ? '<input type="hidden" name="draft_loaded" value="' . request_var('draft_loaded', $draft_id) . '" />' : '';
1.1397 +
1.1398 +if ($mode == 'edit')
1.1399 +{
1.1400 + $s_hidden_fields .= build_hidden_fields(array(
1.1401 + 'edit_post_message_checksum' => $post_data['post_checksum'],
1.1402 + 'edit_post_subject_checksum' => $post_data['post_subject_md5'],
1.1403 + ));
1.1404 +}
1.1405 +
1.1406 +// Add the confirm id/code pair to the hidden fields, else an error is displayed on next submit/preview
1.1407 +if (isset($captcha) && $captcha->is_solved() !== false)
1.1408 +{
1.1409 + $s_hidden_fields .= build_hidden_fields($captcha->get_hidden_fields());
1.1410 +}
1.1411 +
1.1412 +$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"';
1.1413 +add_form_key('posting');
1.1414 +
1.1415 +
1.1416 +// Start assigning vars for main posting page ...
1.1417 +$template->assign_vars(array(
1.1418 + 'L_POST_A' => $page_title,
1.1419 + 'L_ICON' => ($mode == 'reply' || $mode == 'quote' || ($mode == 'edit' && $post_id != $post_data['topic_first_post_id'])) ? $user->lang['POST_ICON'] : $user->lang['TOPIC_ICON'],
1.1420 + 'L_MESSAGE_BODY_EXPLAIN' => (intval($config['max_post_chars'])) ? sprintf($user->lang['MESSAGE_BODY_EXPLAIN'], intval($config['max_post_chars'])) : '',
1.1421 +
1.1422 + 'FORUM_NAME' => $post_data['forum_name'],
1.1423 + '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']) : '',
1.1424 + 'TOPIC_TITLE' => censor_text($post_data['topic_title']),
1.1425 + 'MODERATORS' => (sizeof($moderators)) ? implode(', ', $moderators[$forum_id]) : '',
1.1426 + 'USERNAME' => ((!$preview && $mode != 'quote') || $preview) ? $post_data['username'] : '',
1.1427 + 'SUBJECT' => $post_data['post_subject'],
1.1428 + 'MESSAGE' => $post_data['post_text'],
1.1429 + 'BBCODE_STATUS' => ($bbcode_status) ? sprintf($user->lang['BBCODE_IS_ON'], '<a href="' . append_sid("{$phpbb_root_path}faq.$phpEx", 'mode=bbcode') . '">', '</a>') : sprintf($user->lang['BBCODE_IS_OFF'], '<a href="' . append_sid("{$phpbb_root_path}faq.$phpEx", 'mode=bbcode') . '">', '</a>'),
1.1430 + 'IMG_STATUS' => ($img_status) ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'],
1.1431 + 'FLASH_STATUS' => ($flash_status) ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'],
1.1432 + 'SMILIES_STATUS' => ($smilies_status) ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'],
1.1433 + 'URL_STATUS' => ($bbcode_status && $url_status) ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'],
1.1434 + 'MAX_FONT_SIZE' => (int) $config['max_post_font_size'],
1.1435 + 'MINI_POST_IMG' => $user->img('icon_post_target', $user->lang['POST']),
1.1436 + 'POST_DATE' => ($post_data['post_time']) ? $user->format_date($post_data['post_time']) : '',
1.1437 + 'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '',
1.1438 + 'TOPIC_TIME_LIMIT' => (int) $post_data['topic_time_limit'],
1.1439 + 'EDIT_REASON' => $post_data['post_edit_reason'],
1.1440 + 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id"),
1.1441 + 'U_VIEW_TOPIC' => ($mode != 'post') ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id") : '',
1.1442 + 'U_PROGRESS_BAR' => append_sid("{$phpbb_root_path}posting.$phpEx", "f=$forum_id&mode=popup"),
1.1443 + 'UA_PROGRESS_BAR' => addslashes(append_sid("{$phpbb_root_path}posting.$phpEx", "f=$forum_id&mode=popup")),
1.1444 +
1.1445 + 'S_PRIVMSGS' => false,
1.1446 + 'S_CLOSE_PROGRESS_WINDOW' => (isset($_POST['add_file'])) ? true : false,
1.1447 + 'S_EDIT_POST' => ($mode == 'edit') ? true : false,
1.1448 + 'S_EDIT_REASON' => ($mode == 'edit' && $auth->acl_get('m_edit', $forum_id)) ? true : false,
1.1449 + 'S_DISPLAY_USERNAME' => (!$user->data['is_registered'] || ($mode == 'edit' && $post_data['poster_id'] == ANONYMOUS)) ? true : false,
1.1450 + 'S_SHOW_TOPIC_ICONS' => $s_topic_icons,
1.1451 + '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['delete_time'] * 60) || !$config['delete_time'])) || $auth->acl_get('m_delete', $forum_id))) ? true : false,
1.1452 + 'S_BBCODE_ALLOWED' => ($bbcode_status) ? 1 : 0,
1.1453 + 'S_BBCODE_CHECKED' => ($bbcode_checked) ? ' checked="checked"' : '',
1.1454 + 'S_SMILIES_ALLOWED' => $smilies_status,
1.1455 + 'S_SMILIES_CHECKED' => ($smilies_checked) ? ' checked="checked"' : '',
1.1456 + 'S_SIG_ALLOWED' => ($auth->acl_get('f_sigs', $forum_id) && $config['allow_sig'] && $user->data['is_registered']) ? true : false,
1.1457 + 'S_SIGNATURE_CHECKED' => ($sig_checked) ? ' checked="checked"' : '',
1.1458 + '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,
1.1459 + 'S_NOTIFY_CHECKED' => ($notify_checked) ? ' checked="checked"' : '',
1.1460 + '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,
1.1461 + 'S_LOCK_TOPIC_CHECKED' => ($lock_topic_checked) ? ' checked="checked"' : '',
1.1462 + 'S_LOCK_POST_ALLOWED' => ($mode == 'edit' && $auth->acl_get('m_edit', $forum_id)) ? true : false,
1.1463 + 'S_LOCK_POST_CHECKED' => ($lock_post_checked) ? ' checked="checked"' : '',
1.1464 + 'S_LINKS_ALLOWED' => $url_status,
1.1465 + 'S_MAGIC_URL_CHECKED' => ($urls_checked) ? ' checked="checked"' : '',
1.1466 + 'S_TYPE_TOGGLE' => $topic_type_toggle,
1.1467 + 'S_SAVE_ALLOWED' => ($auth->acl_get('u_savedrafts') && $user->data['is_registered'] && $mode != 'edit') ? true : false,
1.1468 + 'S_HAS_DRAFTS' => ($auth->acl_get('u_savedrafts') && $user->data['is_registered'] && $post_data['drafts']) ? true : false,
1.1469 + 'S_FORM_ENCTYPE' => $form_enctype,
1.1470 +
1.1471 + 'S_BBCODE_IMG' => $img_status,
1.1472 + 'S_BBCODE_URL' => $url_status,
1.1473 + 'S_BBCODE_FLASH' => $flash_status,
1.1474 + 'S_BBCODE_QUOTE' => $quote_status,
1.1475 +
1.1476 + 'S_POST_ACTION' => $s_action,
1.1477 + 'S_HIDDEN_FIELDS' => $s_hidden_fields)
1.1478 +);
1.1479 +
1.1480 +// Build custom bbcodes array
1.1481 +display_custom_bbcodes();
1.1482 +
1.1483 +// Poll entry
1.1484 +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))*/))
1.1485 + && $auth->acl_get('f_poll', $forum_id))
1.1486 +{
1.1487 + $template->assign_vars(array(
1.1488 + 'S_SHOW_POLL_BOX' => true,
1.1489 + 'S_POLL_VOTE_CHANGE' => ($auth->acl_get('f_votechg', $forum_id) && $auth->acl_get('f_vote', $forum_id)),
1.1490 + '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))),
1.1491 + 'S_POLL_DELETE_CHECKED' => (!empty($poll_delete)) ? true : false,
1.1492 +
1.1493 + 'L_POLL_OPTIONS_EXPLAIN' => sprintf($user->lang['POLL_OPTIONS_' . (($mode == 'edit') ? 'EDIT_' : '') . 'EXPLAIN'], $config['max_poll_options']),
1.1494 +
1.1495 + 'VOTE_CHANGE_CHECKED' => (!empty($post_data['poll_vote_change'])) ? ' checked="checked"' : '',
1.1496 + 'POLL_TITLE' => (isset($post_data['poll_title'])) ? $post_data['poll_title'] : '',
1.1497 + 'POLL_OPTIONS' => (!empty($post_data['poll_options'])) ? implode("\n", $post_data['poll_options']) : '',
1.1498 + 'POLL_MAX_OPTIONS' => (isset($post_data['poll_max_options'])) ? (int) $post_data['poll_max_options'] : 1,
1.1499 + 'POLL_LENGTH' => $post_data['poll_length'])
1.1500 + );
1.1501 +}
1.1502 +
1.1503 +// Show attachment box for adding attachments if true
1.1504 +$allowed = ($auth->acl_get('f_attach', $forum_id) && $auth->acl_get('u_attach') && $config['allow_attachments'] && $form_enctype);
1.1505 +
1.1506 +// Attachment entry
1.1507 +posting_gen_attachment_entry($attachment_data, $filename_data, $allowed);
1.1508 +
1.1509 +// Output page ...
1.1510 +page_header($page_title, false);
1.1511 +
1.1512 +$template->set_filenames(array(
1.1513 + 'body' => 'posting_body.html')
1.1514 +);
1.1515 +
1.1516 +make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
1.1517 +
1.1518 +// Topic review
1.1519 +if ($mode == 'reply' || $mode == 'quote')
1.1520 +{
1.1521 + if (topic_review($topic_id, $forum_id))
1.1522 + {
1.1523 + $template->assign_var('S_DISPLAY_REVIEW', true);
1.1524 + }
1.1525 +}
1.1526 +
1.1527 +page_footer();
1.1528 +
1.1529 +/**
1.1530 +* Show upload popup (progress bar)
1.1531 +*/
1.1532 +function upload_popup($forum_style = 0)
1.1533 +{
1.1534 + global $template, $user;
1.1535 +
1.1536 + ($forum_style) ? $user->setup('posting', $forum_style) : $user->setup('posting');
1.1537 +
1.1538 + page_header($user->lang['PROGRESS_BAR'], false);
1.1539 +
1.1540 + $template->set_filenames(array(
1.1541 + 'popup' => 'posting_progress_bar.html')
1.1542 + );
1.1543 +
1.1544 + $template->assign_vars(array(
1.1545 + 'PROGRESS_BAR' => $user->img('upload_bar', $user->lang['UPLOAD_IN_PROGRESS']))
1.1546 + );
1.1547 +
1.1548 + $template->display('popup');
1.1549 +
1.1550 + garbage_collection();
1.1551 + exit_handler();
1.1552 +}
1.1553 +
1.1554 +/**
1.1555 +* Do the various checks required for removing posts as well as removing it
1.1556 +*/
1.1557 +function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data)
1.1558 +{
1.1559 + global $user, $db, $auth, $config;
1.1560 + global $phpbb_root_path, $phpEx;
1.1561 +
1.1562 + // If moderator removing post or user itself removing post, present a confirmation screen
1.1563 + 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['delete_time'] * 60) || !$config['delete_time'])))
1.1564 + {
1.1565 + $s_hidden_fields = build_hidden_fields(array(
1.1566 + 'p' => $post_id,
1.1567 + 'f' => $forum_id,
1.1568 + 'mode' => 'delete')
1.1569 + );
1.1570 +
1.1571 + if (confirm_box(true))
1.1572 + {
1.1573 + $data = array(
1.1574 + 'topic_first_post_id' => $post_data['topic_first_post_id'],
1.1575 + 'topic_last_post_id' => $post_data['topic_last_post_id'],
1.1576 + 'topic_replies_real' => $post_data['topic_replies_real'],
1.1577 + 'topic_approved' => $post_data['topic_approved'],
1.1578 + 'topic_type' => $post_data['topic_type'],
1.1579 + 'post_approved' => $post_data['post_approved'],
1.1580 + 'post_reported' => $post_data['post_reported'],
1.1581 + 'post_time' => $post_data['post_time'],
1.1582 + 'poster_id' => $post_data['poster_id'],
1.1583 + 'post_postcount' => $post_data['post_postcount']
1.1584 + );
1.1585 +
1.1586 + $next_post_id = delete_post($forum_id, $topic_id, $post_id, $data);
1.1587 + $post_username = ($post_data['poster_id'] == ANONYMOUS && !empty($post_data['post_username'])) ? $post_data['post_username'] : $post_data['username'];
1.1588 +
1.1589 + if ($next_post_id === false)
1.1590 + {
1.1591 + add_log('mod', $forum_id, $topic_id, 'LOG_DELETE_TOPIC', $post_data['topic_title'], $post_username);
1.1592 +
1.1593 + $meta_info = append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id");
1.1594 + $message = $user->lang['POST_DELETED'];
1.1595 + }
1.1596 + else
1.1597 + {
1.1598 + add_log('mod', $forum_id, $topic_id, 'LOG_DELETE_POST', $post_data['post_subject'], $post_username);
1.1599 +
1.1600 + $meta_info = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id&p=$next_post_id") . "#p$next_post_id";
1.1601 + $message = $user->lang['POST_DELETED'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $meta_info . '">', '</a>');
1.1602 + }
1.1603 +
1.1604 + meta_refresh(3, $meta_info);
1.1605 + $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
1.1606 + trigger_error($message);
1.1607 + }
1.1608 + else
1.1609 + {
1.1610 + confirm_box(false, 'DELETE_POST', $s_hidden_fields);
1.1611 + }
1.1612 + }
1.1613 +
1.1614 + // If we are here the user is not able to delete - present the correct error message
1.1615 + if ($post_data['poster_id'] != $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id))
1.1616 + {
1.1617 + trigger_error('DELETE_OWN_POSTS');
1.1618 + }
1.1619 +
1.1620 + if ($post_data['poster_id'] == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id) && $post_id != $post_data['topic_last_post_id'])
1.1621 + {
1.1622 + trigger_error('CANNOT_DELETE_REPLIED');
1.1623 + }
1.1624 +
1.1625 + trigger_error('USER_CANNOT_DELETE');
1.1626 +}
1.1627 +
1.1628 +?>
1.1629 \ No newline at end of file