Verzeichnisstruktur phpBB-3.0.0
- Veröffentlicht
- 12.12.2007
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
posting.php
0001 <?php
0002 /**
0003 *
0004 * @package phpBB3
0005 * @version $Id$
0006 * @copyright (c) 2005 phpBB Group
0007 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
0008 *
0009 */
0010
0011 /**
0012 * @ignore
0013 */
0014 define('IN_PHPBB', true);
0015 $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
0016 $phpEx = substr(strrchr(__FILE__, '.'), 1);
0017 include($phpbb_root_path . 'common.' . $phpEx);
0018 include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
0019 include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
0020 include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
0021
0022
0023 // Start session management
0024 $user->session_begin();
0025 $auth->acl($user->data);
0026
0027
0028 // Grab only parameters needed here
0029 $post_id = request_var('p', 0);
0030 $topic_id = request_var('t', 0);
0031 $forum_id = request_var('f', 0);
0032 $draft_id = request_var('d', 0);
0033 $lastclick = request_var('lastclick', 0);
0034
0035 $submit = (isset($_POST['post'])) ? true : false;
0036 $preview = (isset($_POST['preview'])) ? true : false;
0037 $save = (isset($_POST['save'])) ? true : false;
0038 $load = (isset($_POST['load'])) ? true : false;
0039 $delete = (isset($_POST['delete'])) ? true : false;
0040 $cancel = (isset($_POST['cancel']) && !isset($_POST['save'])) ? true : false;
0041
0042 $refresh = (isset($_POST['add_file']) || isset($_POST['delete_file']) || isset($_POST['cancel_unglobalise']) || $save || $load) ? true : false;
0043 $mode = ($delete && !$preview && !$refresh && $submit) ? 'delete' : request_var('mode', '');
0044
0045 $error = $post_data = array();
0046 $current_time = time();
0047
0048
0049 // Was cancel pressed? If so then redirect to the appropriate page
0050 if ($cancel || ($current_time - $lastclick < 2 && $submit))
0051 {
0052 $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")));
0053 redirect($redirect);
0054 }
0055
0056 if (in_array($mode, array('post', 'reply', 'quote', 'edit', 'delete')) && !$forum_id)
0057 {
0058 trigger_error('NO_FORUM');
0059 }
0060
0061 // We need to know some basic information in all cases before we do anything.
0062 switch ($mode)
0063 {
0064 case 'post':
0065 $sql = 'SELECT *
0066 FROM ' . FORUMS_TABLE . "
0067 WHERE forum_id = $forum_id";
0068 break;
0069
0070 case 'bump':
0071 case 'reply':
0072 if (!$topic_id)
0073 {
0074 trigger_error('NO_TOPIC');
0075 }
0076
0077 $sql = 'SELECT f.*, t.*
0078 FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f
0079 WHERE t.topic_id = $topic_id
0080 AND (f.forum_id = t.forum_id
0081 OR f.forum_id = $forum_id)";
0082 break;
0083
0084 case 'quote':
0085 case 'edit':
0086 case 'delete':
0087 if (!$post_id)
0088 {
0089 $user->setup('posting');
0090 trigger_error('NO_POST');
0091 }
0092
0093 $sql = 'SELECT f.*, t.*, p.*, u.username, u.username_clean, u.user_sig, u.user_sig_bbcode_uid, u.user_sig_bbcode_bitfield
0094 FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . ' f, ' . USERS_TABLE . " u
0095 WHERE p.post_id = $post_id
0096 AND t.topic_id = p.topic_id
0097 AND u.user_id = p.poster_id
0098 AND (f.forum_id = t.forum_id
0099 OR f.forum_id = $forum_id)";
0100 break;
0101
0102 case 'smilies':
0103 $sql = '';
0104 generate_smilies('window', $forum_id);
0105 break;
0106
0107 case 'popup':
0108 if ($forum_id)
0109 {
0110 $sql = 'SELECT forum_style
0111 FROM ' . FORUMS_TABLE . '
0112 WHERE forum_id = ' . $forum_id;
0113 }
0114 else
0115 {
0116 upload_popup();
0117 garbage_collection();
0118 exit_handler();
0119 }
0120 break;
0121
0122 default:
0123 $sql = '';
0124 break;
0125 }
0126
0127 if (!$sql)
0128 {
0129 $user->setup('posting');
0130 trigger_error('NO_POST_MODE');
0131 }
0132
0133 $result = $db->sql_query($sql);
0134 $post_data = $db->sql_fetchrow($result);
0135 $db->sql_freeresult($result);
0136
0137 if (!$post_data)
0138 {
0139 if (!($mode == 'post' || $mode == 'bump' || $mode == 'reply'))
0140 {
0141 $user->setup('posting');
0142 }
0143 trigger_error(($mode == 'post' || $mode == 'bump' || $mode == 'reply') ? 'NO_TOPIC' : 'NO_POST');
0144 }
0145
0146 if ($mode == 'popup')
0147 {
0148 upload_popup($post_data['forum_style']);
0149 exit_handler();
0150 }
0151
0152 $user->setup(array('posting', 'mcp', 'viewtopic'), $post_data['forum_style']);
0153
0154 // Use post_row values in favor of submitted ones...
0155 $forum_id = (!empty($post_data['forum_id'])) ? (int) $post_data['forum_id'] : (int) $forum_id;
0156 $topic_id = (!empty($post_data['topic_id'])) ? (int) $post_data['topic_id'] : (int) $topic_id;
0157 $post_id = (!empty($post_data['post_id'])) ? (int) $post_data['post_id'] : (int) $post_id;
0158
0159 // Need to login to passworded forum first?
0160 if ($post_data['forum_password'])
0161 {
0162 login_forum_box(array(
0163 'forum_id' => $forum_id,
0164 'forum_password' => $post_data['forum_password'])
0165 );
0166 }
0167
0168 // Check permissions
0169 if ($user->data['is_bot'])
0170 {
0171 redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
0172 }
0173
0174 // Is the user able to read within this forum?
0175 if (!$auth->acl_get('f_read', $forum_id))
0176 {
0177 if ($user->data['user_id'] != ANONYMOUS)
0178 {
0179 trigger_error('USER_CANNOT_READ');
0180 }
0181
0182 login_box('', $user->lang['LOGIN_EXPLAIN_POST']);
0183 }
0184
0185 // Permission to do the action asked?
0186 $is_authed = false;
0187
0188 switch ($mode)
0189 {
0190 case 'post':
0191 if ($auth->acl_get('f_post', $forum_id))
0192 {
0193 $is_authed = true;
0194 }
0195 break;
0196
0197 case 'bump':
0198 if ($auth->acl_get('f_bump', $forum_id))
0199 {
0200 $is_authed = true;
0201 }
0202 break;
0203
0204 case 'quote':
0205
0206 $post_data['post_edit_locked'] = 0;
0207
0208 // no break;
0209
0210 case 'reply':
0211 if ($auth->acl_get('f_reply', $forum_id))
0212 {
0213 $is_authed = true;
0214 }
0215 break;
0216
0217 case 'edit':
0218 if ($user->data['is_registered'] && $auth->acl_gets('f_edit', 'm_edit', $forum_id))
0219 {
0220 $is_authed = true;
0221 }
0222 break;
0223
0224 case 'delete':
0225 if ($user->data['is_registered'] && $auth->acl_gets('f_delete', 'm_delete', $forum_id))
0226 {
0227 $is_authed = true;
0228 }
0229 break;
0230 }
0231
0232 if (!$is_authed)
0233 {
0234 $check_auth = ($mode == 'quote') ? 'reply' : $mode;
0235
0236 if ($user->data['is_registered'])
0237 {
0238 trigger_error('USER_CANNOT_' . strtoupper($check_auth));
0239 }
0240
0241 login_box('', $user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)]);
0242 }
0243
0244 // Is the user able to post within this forum?
0245 if ($post_data['forum_type'] != FORUM_POST && in_array($mode, array('post', 'bump', 'quote', 'reply')))
0246 {
0247 trigger_error('USER_CANNOT_FORUM_POST');
0248 }
0249
0250 // Forum/Topic locked?
0251 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))
0252 {
0253 trigger_error(($post_data['forum_status'] == ITEM_LOCKED) ? 'FORUM_LOCKED' : 'TOPIC_LOCKED');
0254 }
0255
0256 // Can we edit this post ... if we're a moderator with rights then always yes
0257 // else it depends on editing times, lock status and if we're the correct user
0258 if ($mode == 'edit' && !$auth->acl_get('m_edit', $forum_id))
0259 {
0260 if ($user->data['user_id'] != $post_data['poster_id'])
0261 {
0262 trigger_error('USER_CANNOT_EDIT');
0263 }
0264
0265 if (!($post_data['post_time'] > time() - ($config['edit_time'] * 60) || !$config['edit_time']))
0266 {
0267 trigger_error('CANNOT_EDIT_TIME');
0268 }
0269
0270 if ($post_data['post_edit_locked'])
0271 {
0272 trigger_error('CANNOT_EDIT_POST_LOCKED');
0273 }
0274 }
0275
0276 // Handle delete mode...
0277 if ($mode == 'delete')
0278 {
0279 handle_post_delete($forum_id, $topic_id, $post_id, $post_data);
0280 exit_handler();
0281 }
0282
0283 // Handle bump mode...
0284 if ($mode == 'bump')
0285 {
0286 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']))
0287 {
0288 $db->sql_transaction('begin');
0289
0290 $sql = 'UPDATE ' . POSTS_TABLE . "
0291 SET post_time = $current_time
0292 WHERE post_id = {$post_data['topic_last_post_id']}
0293 AND topic_id = $topic_id";
0294 $db->sql_query($sql);
0295
0296 $sql = 'UPDATE ' . TOPICS_TABLE . "
0297 SET topic_last_post_time = $current_time,
0298 topic_bumped = 1,
0299 topic_bumper = " . $user->data['user_id'] . "
0300 WHERE topic_id = $topic_id";
0301 $db->sql_query($sql);
0302
0303 update_post_information('forum', $forum_id);
0304
0305 $sql = 'UPDATE ' . USERS_TABLE . "
0306 SET user_lastpost_time = $current_time
0307 WHERE user_id = " . $user->data['user_id'];
0308 $db->sql_query($sql);
0309
0310 $db->sql_transaction('commit');
0311
0312 markread('post', $forum_id, $topic_id, $current_time);
0313
0314 add_log('mod', $forum_id, $topic_id, 'LOG_BUMP_TOPIC', $post_data['topic_title']);
0315
0316 $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']}";
0317 meta_refresh(3, $meta_url);
0318
0319 $message = $user->lang['TOPIC_BUMPED'] . '<br /><br />' . sprintf($user->lang['VIEW_MESSAGE'], '<a href="' . $meta_url . '">', '</a>');
0320 $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
0321
0322 trigger_error($message);
0323 }
0324
0325 trigger_error('BUMP_ERROR');
0326 }
0327
0328 // Subject length limiting to 60 characters if first post...
0329 if ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_data['post_id']))
0330 {
0331 $template->assign_var('S_NEW_MESSAGE', true);
0332 }
0333
0334 // Determine some vars
0335 if (isset($post_data['poster_id']) && $post_data['poster_id'] == ANONYMOUS)
0336 {
0337 $post_data['quote_username'] = (!empty($post_data['post_username'])) ? $post_data['post_username'] : $user->lang['GUEST'];
0338 }
0339 else
0340 {
0341 $post_data['quote_username'] = isset($post_data['username']) ? $post_data['username'] : '';
0342 }
0343
0344 $post_data['post_edit_locked'] = (isset($post_data['post_edit_locked'])) ? (int) $post_data['post_edit_locked'] : 0;
0345 $post_data['post_subject'] = (in_array($mode, array('quote', 'edit'))) ? $post_data['post_subject'] : ((isset($post_data['topic_title'])) ? $post_data['topic_title'] : '');
0346 $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;
0347 $post_data['poll_length'] = (!empty($post_data['poll_length'])) ? (int) $post_data['poll_length'] / 86400 : 0;
0348 $post_data['poll_start'] = (!empty($post_data['poll_start'])) ? (int) $post_data['poll_start'] : 0;
0349 $post_data['icon_id'] = (!isset($post_data['icon_id']) || in_array($mode, array('quote', 'reply'))) ? 0 : (int) $post_data['icon_id'];
0350 $post_data['poll_options'] = array();
0351
0352 // Get Poll Data
0353 if ($post_data['poll_start'])
0354 {
0355 $sql = 'SELECT poll_option_text
0356 FROM ' . POLL_OPTIONS_TABLE . "
0357 WHERE topic_id = $topic_id
0358 ORDER BY poll_option_id";
0359 $result = $db->sql_query($sql);
0360
0361 while ($row = $db->sql_fetchrow($result))
0362 {
0363 $post_data['poll_options'][] = trim($row['poll_option_text']);
0364 }
0365 $db->sql_freeresult($result);
0366 }
0367
0368 $orig_poll_options_size = sizeof($post_data['poll_options']);
0369
0370 $message_parser = new parse_message();
0371
0372 if (isset($post_data['post_text']))
0373 {
0374 $message_parser->message = &$post_data['post_text'];
0375 unset($post_data['post_text']);
0376 }
0377
0378 // Set some default variables
0379 $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);
0380
0381 foreach ($uninit as $var_name => $default_value)
0382 {
0383 if (!isset($post_data[$var_name]))
0384 {
0385 $post_data[$var_name] = $default_value;
0386 }
0387 }
0388 unset($uninit);
0389
0390 // Always check if the submitted attachment data is valid and belongs to the user.
0391 // Further down (especially in submit_post()) we do not check this again.
0392 $message_parser->get_submitted_attachment_data($post_data['poster_id']);
0393
0394 if ($post_data['post_attachment'] && !$submit && !$refresh && !$preview && $mode == 'edit')
0395 {
0396 // Do not change to SELECT *
0397 $sql = 'SELECT attach_id, is_orphan, attach_comment, real_filename
0398 FROM ' . ATTACHMENTS_TABLE . "
0399 WHERE post_msg_id = $post_id
0400 AND in_message = 0
0401 AND is_orphan = 0
0402 ORDER BY filetime DESC";
0403 $result = $db->sql_query($sql);
0404 $message_parser->attachment_data = array_merge($message_parser->attachment_data, $db->sql_fetchrowset($result));
0405 $db->sql_freeresult($result);
0406 }
0407
0408 if ($post_data['poster_id'] == ANONYMOUS)
0409 {
0410 $post_data['username'] = ($mode == 'quote' || $mode == 'edit') ? trim($post_data['post_username']) : '';
0411 }
0412 else
0413 {
0414 $post_data['username'] = ($mode == 'quote' || $mode == 'edit') ? trim($post_data['username']) : '';
0415 }
0416
0417 $post_data['enable_urls'] = $post_data['enable_magic_url'];
0418
0419 if ($mode != 'edit')
0420 {
0421 $post_data['enable_sig'] = ($config['allow_sig'] && $user->optionget('attachsig')) ? true: false;
0422 $post_data['enable_smilies'] = ($config['allow_smilies'] && $user->optionget('smilies')) ? true : false;
0423 $post_data['enable_bbcode'] = ($config['allow_bbcode'] && $user->optionget('bbcode')) ? true : false;
0424 $post_data['enable_urls'] = true;
0425 }
0426
0427 $post_data['enable_magic_url'] = $post_data['drafts'] = false;
0428
0429 // User own some drafts?
0430 if ($user->data['is_registered'] && $auth->acl_get('u_savedrafts') && ($mode == 'reply' || $mode == 'post' || $mode == 'quote'))
0431 {
0432 $sql = 'SELECT draft_id
0433 FROM ' . DRAFTS_TABLE . '
0434 WHERE user_id = ' . $user->data['user_id'] .
0435 (($forum_id) ? ' AND forum_id = ' . (int) $forum_id : '') .
0436 (($topic_id) ? ' AND topic_id = ' . (int) $topic_id : '') .
0437 (($draft_id) ? " AND draft_id <> $draft_id" : '');
0438 $result = $db->sql_query_limit($sql, 1);
0439
0440 if ($db->sql_fetchrow($result))
0441 {
0442 $post_data['drafts'] = true;
0443 }
0444 $db->sql_freeresult($result);
0445 }
0446
0447 $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);
0448
0449 // Check if user is watching this topic
0450 if ($mode != 'post' && $config['allow_topic_notify'] && $user->data['is_registered'])
0451 {
0452 $sql = 'SELECT topic_id
0453 FROM ' . TOPICS_WATCH_TABLE . '
0454 WHERE topic_id = ' . $topic_id . '
0455 AND user_id = ' . $user->data['user_id'];
0456 $result = $db->sql_query($sql);
0457 $post_data['notify_set'] = (int) $db->sql_fetchfield('topic_id');
0458 $db->sql_freeresult($result);
0459 }
0460
0461 // Do we want to edit our post ?
0462 if ($mode == 'edit' && $post_data['bbcode_uid'])
0463 {
0464 $message_parser->bbcode_uid = $post_data['bbcode_uid'];
0465 }
0466
0467 // HTML, BBCode, Smilies, Images and Flash status
0468 $bbcode_status = ($config['allow_bbcode'] && $auth->acl_get('f_bbcode', $forum_id)) ? true : false;
0469 $smilies_status = ($bbcode_status && $config['allow_smilies'] && $auth->acl_get('f_smilies', $forum_id)) ? true : false;
0470 $img_status = ($bbcode_status && $auth->acl_get('f_img', $forum_id)) ? true : false;
0471 $url_status = ($config['allow_post_links']) ? true : false;
0472 $flash_status = ($bbcode_status && $auth->acl_get('f_flash', $forum_id) && $config['allow_post_flash']) ? true : false;
0473 $quote_status = ($auth->acl_get('f_reply', $forum_id)) ? true : false;
0474
0475 // Save Draft
0476 if ($save && $user->data['is_registered'] && $auth->acl_get('u_savedrafts') && ($mode == 'reply' || $mode == 'post' || $mode == 'quote'))
0477 {
0478 $subject = utf8_normalize_nfc(request_var('subject', '', true));
0479 $subject = (!$subject && $mode != 'post') ? $post_data['topic_title'] : $subject;
0480 $message = utf8_normalize_nfc(request_var('message', '', true));
0481
0482 if ($subject && $message)
0483 {
0484 if (confirm_box(true))
0485 {
0486 $sql = 'INSERT INTO ' . DRAFTS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
0487 'user_id' => (int) $user->data['user_id'],
0488 'topic_id' => (int) $topic_id,
0489 'forum_id' => (int) $forum_id,
0490 'save_time' => (int) $current_time,
0491 'draft_subject' => (string) $subject,
0492 'draft_message' => (string) $message)
0493 );
0494 $db->sql_query($sql);
0495
0496 $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");
0497
0498 meta_refresh(3, $meta_info);
0499
0500 $message = $user->lang['DRAFT_SAVED'] . '<br /><br />';
0501 $message .= ($mode != 'post') ? sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $meta_info . '">', '</a>') . '<br /><br />' : '';
0502 $message .= sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
0503
0504 trigger_error($message);
0505 }
0506 else
0507 {
0508 $s_hidden_fields = build_hidden_fields(array(
0509 'mode' => $mode,
0510 'save' => true,
0511 'f' => $forum_id,
0512 't' => $topic_id,
0513 'subject' => $subject,
0514 'message' => $message,
0515 )
0516 );
0517
0518 confirm_box(false, 'SAVE_DRAFT', $s_hidden_fields);
0519 }
0520 }
0521 else
0522 {
0523 if (!$subject || !utf8_clean_string($subject))
0524 {
0525 $error[] = $user->lang['EMPTY_SUBJECT'];
0526 }
0527
0528 if (!$message)
0529 {
0530 $error[] = $user->lang['TOO_FEW_CHARS'];
0531 }
0532 }
0533 unset($subject, $message);
0534 }
0535
0536 // Load requested Draft
0537 if ($draft_id && ($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $user->data['is_registered'] && $auth->acl_get('u_savedrafts'))
0538 {
0539 $sql = 'SELECT draft_subject, draft_message
0540 FROM ' . DRAFTS_TABLE . "
0541 WHERE draft_id = $draft_id
0542 AND user_id = " . $user->data['user_id'];
0543 $result = $db->sql_query_limit($sql, 1);
0544 $row = $db->sql_fetchrow($result);
0545 $db->sql_freeresult($result);
0546
0547 if ($row)
0548 {
0549 $post_data['post_subject'] = $row['draft_subject'];
0550 $message_parser->message = $row['draft_message'];
0551
0552 $template->assign_var('S_DRAFT_LOADED', true);
0553 }
0554 else
0555 {
0556 $draft_id = 0;
0557 }
0558 }
0559
0560 // Load draft overview
0561 if ($load && ($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $post_data['drafts'])
0562 {
0563 load_drafts($topic_id, $forum_id);
0564 }
0565
0566 $solved_captcha = false;
0567
0568 if ($submit || $preview || $refresh)
0569 {
0570 $post_data['topic_cur_post_id'] = request_var('topic_cur_post_id', 0);
0571 $post_data['post_subject'] = utf8_normalize_nfc(request_var('subject', '', true));
0572 $message_parser->message = utf8_normalize_nfc(request_var('message', '', true));
0573
0574 $post_data['username'] = utf8_normalize_nfc(request_var('username', $post_data['username'], true));
0575 $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)) : '';
0576
0577 $post_data['orig_topic_type'] = $post_data['topic_type'];
0578 $post_data['topic_type'] = request_var('topic_type', (($mode != 'post') ? (int) $post_data['topic_type'] : POST_NORMAL));
0579 $post_data['topic_time_limit'] = request_var('topic_time_limit', (($mode != 'post') ? (int) $post_data['topic_time_limit'] : 0));
0580 $post_data['icon_id'] = request_var('icon', 0);
0581
0582 $post_data['enable_bbcode'] = (!$bbcode_status || isset($_POST['disable_bbcode'])) ? false : true;
0583 $post_data['enable_smilies'] = (!$smilies_status || isset($_POST['disable_smilies'])) ? false : true;
0584 $post_data['enable_urls'] = (isset($_POST['disable_magic_url'])) ? 0 : 1;
0585 $post_data['enable_sig'] = (!$config['allow_sig']) ? false : ((isset($_POST['attach_sig']) && $user->data['is_registered']) ? true : false);
0586
0587 if ($config['allow_topic_notify'] && $user->data['is_registered'])
0588 {
0589 $notify = (isset($_POST['notify'])) ? true : false;
0590 }
0591 else
0592 {
0593 $notify = false;
0594 }
0595
0596 $topic_lock = (isset($_POST['lock_topic'])) ? true : false;
0597 $post_lock = (isset($_POST['lock_post'])) ? true : false;
0598 $poll_delete = (isset($_POST['poll_delete'])) ? true : false;
0599
0600 if ($submit)
0601 {
0602 $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);
0603 $status_switch = ($status_switch != $check_value);
0604 }
0605 else
0606 {
0607 $status_switch = 1;
0608 }
0609
0610 // Delete Poll
0611 if ($poll_delete && $mode == 'edit' && sizeof($post_data['poll_options']) &&
0612 ((!$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)))
0613 {
0614 if ($submit && check_form_key('posting'))
0615 {
0616 $sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . "
0617 WHERE topic_id = $topic_id";
0618 $db->sql_query($sql);
0619
0620 $sql = 'DELETE FROM ' . POLL_VOTES_TABLE . "
0621 WHERE topic_id = $topic_id";
0622 $db->sql_query($sql);
0623
0624 $topic_sql = array(
0625 'poll_title' => '',
0626 'poll_start' => 0,
0627 'poll_length' => 0,
0628 'poll_last_vote' => 0,
0629 'poll_max_options' => 0,
0630 'poll_vote_change' => 0
0631 );
0632
0633 $sql = 'UPDATE ' . TOPICS_TABLE . '
0634 SET ' . $db->sql_build_array('UPDATE', $topic_sql) . "
0635 WHERE topic_id = $topic_id";
0636 $db->sql_query($sql);
0637 }
0638
0639 $post_data['poll_title'] = $post_data['poll_option_text'] = '';
0640 $post_data['poll_vote_change'] = $post_data['poll_max_options'] = $post_data['poll_length'] = 0;
0641 }
0642 else
0643 {
0644 $post_data['poll_title'] = utf8_normalize_nfc(request_var('poll_title', '', true));
0645 $post_data['poll_length'] = request_var('poll_length', 0);
0646 $post_data['poll_option_text'] = utf8_normalize_nfc(request_var('poll_option_text', '', true));
0647 $post_data['poll_max_options'] = request_var('poll_max_options', 1);
0648 $post_data['poll_vote_change'] = ($auth->acl_get('f_votechg', $forum_id) && isset($_POST['poll_vote_change'])) ? 1 : 0;
0649 }
0650
0651 // If replying/quoting and last post id has changed
0652 // give user option to continue submit or return to post
0653 // notify and show user the post made between his request and the final submit
0654 if (($mode == 'reply' || $mode == 'quote') && $post_data['topic_cur_post_id'] && $post_data['topic_cur_post_id'] != $post_data['topic_last_post_id'])
0655 {
0656 // Only do so if it is allowed forum-wide
0657 if ($post_data['forum_flags'] & FORUM_FLAG_POST_REVIEW)
0658 {
0659 if (topic_review($topic_id, $forum_id, 'post_review', $post_data['topic_cur_post_id']))
0660 {
0661 $template->assign_var('S_POST_REVIEW', true);
0662 }
0663
0664 $submit = false;
0665 $refresh = true;
0666 }
0667 }
0668
0669 // Parse Attachments - before checksum is calculated
0670 $message_parser->parse_attachments('fileupload', $mode, $forum_id, $submit, $preview, $refresh);
0671
0672 // Grab md5 'checksum' of new message
0673 $message_md5 = md5($message_parser->message);
0674
0675 // Check checksum ... don't re-parse message if the same
0676 $update_message = ($mode != 'edit' || $message_md5 != $post_data['post_checksum'] || $status_switch || strlen($post_data['bbcode_uid']) < BBCODE_UID_LEN) ? true : false;
0677
0678 // Parse message
0679 if ($update_message)
0680 {
0681 if (sizeof($message_parser->warn_msg))
0682 {
0683 $error[] = implode('<br />', $message_parser->warn_msg);
0684 $message_parser->warn_msg = array();
0685 }
0686
0687 $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']);
0688
0689 // On a refresh we do not care about message parsing errors
0690 if (sizeof($message_parser->warn_msg) && $refresh)
0691 {
0692 $message_parser->warn_msg = array();
0693 }
0694 }
0695 else
0696 {
0697 $message_parser->bbcode_bitfield = $post_data['bbcode_bitfield'];
0698 }
0699
0700 if ($mode != 'edit' && !$preview && !$refresh && $config['flood_interval'] && !$auth->acl_get('f_ignoreflood', $forum_id))
0701 {
0702 // Flood check
0703 $last_post_time = 0;
0704
0705 if ($user->data['is_registered'])
0706 {
0707 $last_post_time = $user->data['user_lastpost_time'];
0708 }
0709 else
0710 {
0711 $sql = 'SELECT post_time AS last_post_time
0712 FROM ' . POSTS_TABLE . "
0713 WHERE poster_ip = '" . $user->ip . "'
0714 AND post_time > " . ($current_time - $config['flood_interval']);
0715 $result = $db->sql_query_limit($sql, 1);
0716 if ($row = $db->sql_fetchrow($result))
0717 {
0718 $last_post_time = $row['last_post_time'];
0719 }
0720 $db->sql_freeresult($result);
0721 }
0722
0723 if ($last_post_time && ($current_time - $last_post_time) < intval($config['flood_interval']))
0724 {
0725 $error[] = $user->lang['FLOOD_ERROR'];
0726 }
0727 }
0728
0729 // Validate username
0730 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']))
0731 {
0732 include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
0733
0734 if (($result = validate_username($post_data['username'], (!empty($post_data['post_username'])) ? $post_data['post_username'] : '')) !== false)
0735 {
0736 $user->add_lang('ucp');
0737 $error[] = $user->lang[$result . '_USERNAME'];
0738 }
0739 }
0740
0741 if ($config['enable_post_confirm'] && !$user->data['is_registered'] && in_array($mode, array('quote', 'post', 'reply')))
0742 {
0743 $confirm_id = request_var('confirm_id', '');
0744 $confirm_code = request_var('confirm_code', '');
0745
0746 $sql = 'SELECT code
0747 FROM ' . CONFIRM_TABLE . "
0748 WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "'
0749 AND session_id = '" . $db->sql_escape($user->session_id) . "'
0750 AND confirm_type = " . CONFIRM_POST;
0751 $result = $db->sql_query($sql);
0752 $confirm_row = $db->sql_fetchrow($result);
0753 $db->sql_freeresult($result);
0754
0755 if (empty($confirm_row['code']) || strcasecmp($confirm_row['code'], $confirm_code) !== 0)
0756 {
0757 $error[] = $user->lang['CONFIRM_CODE_WRONG'];
0758 }
0759 else
0760 {
0761 $solved_captcha = true;
0762 }
0763 }
0764
0765 // check form
0766 if (($submit || $preview) && !check_form_key('posting'))
0767 {
0768 $error[] = $user->lang['FORM_INVALID'];
0769 }
0770
0771 // Parse subject
0772 if (!$preview && !$refresh && !utf8_clean_string($post_data['post_subject']) && ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_id)))
0773 {
0774 $error[] = $user->lang['EMPTY_SUBJECT'];
0775 }
0776
0777 $post_data['poll_last_vote'] = (isset($post_data['poll_last_vote'])) ? $post_data['poll_last_vote'] : 0;
0778
0779 if ($post_data['poll_option_text'] &&
0780 ($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id']/* && (!$post_data['poll_last_vote'] || $auth->acl_get('m_edit', $forum_id))*/))
0781 && $auth->acl_get('f_poll', $forum_id))
0782 {
0783 $poll = array(
0784 'poll_title' => $post_data['poll_title'],
0785 'poll_length' => $post_data['poll_length'],
0786 'poll_max_options' => $post_data['poll_max_options'],
0787 'poll_option_text' => $post_data['poll_option_text'],
0788 'poll_start' => $post_data['poll_start'],
0789 'poll_last_vote' => $post_data['poll_last_vote'],
0790 'poll_vote_change' => $post_data['poll_vote_change'],
0791 'enable_bbcode' => $post_data['enable_bbcode'],
0792 'enable_urls' => $post_data['enable_urls'],
0793 'enable_smilies' => $post_data['enable_smilies'],
0794 'img_status' => $img_status
0795 );
0796
0797 $message_parser->parse_poll($poll);
0798
0799 $post_data['poll_options'] = (isset($poll['poll_options'])) ? $poll['poll_options'] : '';
0800 $post_data['poll_title'] = (isset($poll['poll_title'])) ? $poll['poll_title'] : '';
0801
0802 /* We reset votes, therefore also allow removing options
0803 if ($post_data['poll_last_vote'] && ($poll['poll_options_size'] < $orig_poll_options_size))
0804 {
0805 $message_parser->warn_msg[] = $user->lang['NO_DELETE_POLL_OPTIONS'];
0806 }*/
0807 }
0808 else
0809 {
0810 $poll = array();
0811 }
0812
0813 // Check topic type
0814 if ($post_data['topic_type'] != POST_NORMAL && ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_id)))
0815 {
0816 switch ($post_data['topic_type'])
0817 {
0818 case POST_GLOBAL:
0819 case POST_ANNOUNCE:
0820 $auth_option = 'f_announce';
0821 break;
0822
0823 case POST_STICKY:
0824 $auth_option = 'f_sticky';
0825 break;
0826
0827 default:
0828 $auth_option = '';
0829 break;
0830 }
0831
0832 if (!$auth->acl_get($auth_option, $forum_id))
0833 {
0834 // There is a special case where a user edits his post whereby the topic type got changed by an admin/mod.
0835 // Another case would be a mod not having sticky permissions for example but edit permissions.
0836 if ($mode == 'edit')
0837 {
0838 // To prevent non-authed users messing around with the topic type we reset it to the original one.
0839 $post_data['topic_type'] = $post_data['orig_topic_type'];
0840 }
0841 else
0842 {
0843 $error[] = $user->lang['CANNOT_POST_' . str_replace('F_', '', strtoupper($auth_option))];
0844 }
0845 }
0846 }
0847
0848 if (sizeof($message_parser->warn_msg))
0849 {
0850 $error[] = implode('<br />', $message_parser->warn_msg);
0851 }
0852
0853 // DNSBL check
0854 if ($config['check_dnsbl'] && !$refresh)
0855 {
0856 if (($dnsbl = $user->check_dnsbl('post')) !== false)
0857 {
0858 $error[] = sprintf($user->lang['IP_BLACKLISTED'], $user->ip, $dnsbl[1]);
0859 }
0860 }
0861
0862 // Store message, sync counters
0863 if (!sizeof($error) && $submit)
0864 {
0865 // Check if we want to de-globalize the topic... and ask for new forum
0866 if ($post_data['topic_type'] != POST_GLOBAL)
0867 {
0868 $sql = 'SELECT topic_type, forum_id
0869 FROM ' . TOPICS_TABLE . "
0870 WHERE topic_id = $topic_id";
0871 $result = $db->sql_query($sql);
0872 $row = $db->sql_fetchrow($result);
0873 $db->sql_freeresult($result);
0874
0875 if ($row && !$row['forum_id'] && $row['topic_type'] == POST_GLOBAL)
0876 {
0877 $to_forum_id = request_var('to_forum_id', 0);
0878
0879 if ($to_forum_id)
0880 {
0881 $sql = 'SELECT forum_type
0882 FROM ' . FORUMS_TABLE . '
0883 WHERE forum_id = ' . $to_forum_id;
0884 $result = $db->sql_query($sql);
0885 $forum_type = (int) $db->sql_fetchfield('forum_type');
0886 $db->sql_freeresult($result);
0887
0888 if ($forum_type != FORUM_POST || !$auth->acl_get('f_post', $to_forum_id))
0889 {
0890 $to_forum_id = 0;
0891 }
0892 }
0893
0894 if (!$to_forum_id)
0895 {
0896 include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
0897
0898 $template->assign_vars(array(
0899 'S_FORUM_SELECT' => make_forum_select(false, false, false, true, true, true),
0900 'S_UNGLOBALISE' => true)
0901 );
0902
0903 $submit = false;
0904 $refresh = true;
0905 }
0906 else
0907 {
0908 if (!$auth->acl_get('f_post', $to_forum_id))
0909 {
0910 // This will only be triggered if the user tried to trick the forum.
0911 trigger_error('NOT_AUTHORISED');
0912 }
0913
0914 $forum_id = $to_forum_id;
0915 }
0916 }
0917 }
0918
0919 if ($submit)
0920 {
0921 // Lock/Unlock Topic
0922 $change_topic_status = $post_data['topic_status'];
0923 $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;
0924
0925 if ($post_data['topic_status'] == ITEM_LOCKED && !$topic_lock && $perm_lock_unlock)
0926 {
0927 $change_topic_status = ITEM_UNLOCKED;
0928 }
0929 else if ($post_data['topic_status'] == ITEM_UNLOCKED && $topic_lock && $perm_lock_unlock)
0930 {
0931 $change_topic_status = ITEM_LOCKED;
0932 }
0933
0934 if ($change_topic_status != $post_data['topic_status'])
0935 {
0936 $sql = 'UPDATE ' . TOPICS_TABLE . "
0937 SET topic_status = $change_topic_status
0938 WHERE topic_id = $topic_id
0939 AND topic_moved_id = 0";
0940 $db->sql_query($sql);
0941
0942 $user_lock = ($auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && $user->data['user_id'] == $post_data['topic_poster']) ? 'USER_' : '';
0943
0944 add_log('mod', $forum_id, $topic_id, 'LOG_' . $user_lock . (($change_topic_status == ITEM_LOCKED) ? 'LOCK' : 'UNLOCK'), $post_data['topic_title']);
0945 }
0946
0947 // Lock/Unlock Post Edit
0948 if ($mode == 'edit' && $post_data['post_edit_locked'] == ITEM_LOCKED && !$post_lock && $auth->acl_get('m_edit', $forum_id))
0949 {
0950 $post_data['post_edit_locked'] = ITEM_UNLOCKED;
0951 }
0952 else if ($mode == 'edit' && $post_data['post_edit_locked'] == ITEM_UNLOCKED && $post_lock && $auth->acl_get('m_edit', $forum_id))
0953 {
0954 $post_data['post_edit_locked'] = ITEM_LOCKED;
0955 }
0956
0957 $data = array(
0958 'topic_title' => (empty($post_data['topic_title'])) ? $post_data['post_subject'] : $post_data['topic_title'],
0959 'topic_first_post_id' => (isset($post_data['topic_first_post_id'])) ? (int) $post_data['topic_first_post_id'] : 0,
0960 'topic_last_post_id' => (isset($post_data['topic_last_post_id'])) ? (int) $post_data['topic_last_post_id'] : 0,
0961 'topic_time_limit' => (int) $post_data['topic_time_limit'],
0962 'topic_attachment' => (isset($post_data['topic_attachment'])) ? (int) $post_data['topic_attachment'] : 0,
0963 'post_id' => (int) $post_id,
0964 'topic_id' => (int) $topic_id,
0965 'forum_id' => (int) $forum_id,
0966 'icon_id' => (int) $post_data['icon_id'],
0967 'poster_id' => (int) $post_data['poster_id'],
0968 'enable_sig' => (bool) $post_data['enable_sig'],
0969 'enable_bbcode' => (bool) $post_data['enable_bbcode'],
0970 'enable_smilies' => (bool) $post_data['enable_smilies'],
0971 'enable_urls' => (bool) $post_data['enable_urls'],
0972 'enable_indexing' => (bool) $post_data['enable_indexing'],
0973 'message_md5' => (string) $message_md5,
0974 'post_time' => (isset($post_data['post_time'])) ? (int) $post_data['post_time'] : $current_time,
0975 'post_checksum' => (isset($post_data['post_checksum'])) ? (string) $post_data['post_checksum'] : '',
0976 'post_edit_reason' => $post_data['post_edit_reason'],
0977 'post_edit_user' => ($mode == 'edit') ? $user->data['user_id'] : ((isset($post_data['post_edit_user'])) ? (int) $post_data['post_edit_user'] : 0),
0978 'forum_parents' => $post_data['forum_parents'],
0979 'forum_name' => $post_data['forum_name'],
0980 'notify' => $notify,
0981 'notify_set' => $post_data['notify_set'],
0982 'poster_ip' => (isset($post_data['poster_ip'])) ? $post_data['poster_ip'] : $user->ip,
0983 'post_edit_locked' => (int) $post_data['post_edit_locked'],
0984 'bbcode_bitfield' => $message_parser->bbcode_bitfield,
0985 'bbcode_uid' => $message_parser->bbcode_uid,
0986 'message' => $message_parser->message,
0987 'attachment_data' => $message_parser->attachment_data,
0988 'filename_data' => $message_parser->filename_data,
0989
0990 'topic_approved' => (isset($post_data['topic_approved'])) ? $post_data['topic_approved'] : false,
0991 'post_approved' => (isset($post_data['post_approved'])) ? $post_data['post_approved'] : false,
0992 );
0993
0994 if ($mode == 'edit')
0995 {
0996 $data['topic_replies_real'] = $post_data['topic_replies_real'];
0997 $data['topic_replies'] = $post_data['topic_replies'];
0998 }
0999
1000 unset($message_parser);
1001
1002 $redirect_url = submit_post($mode, $post_data['post_subject'], $post_data['username'], $post_data['topic_type'], $poll, $data, $update_message);
1003 $post_need_approval = (!$auth->acl_get('f_noapprove', $data['forum_id']) && !$auth->acl_get('m_approve', $data['forum_id'])) ? true : false;
1004
1005 // If the post need approval we will wait a lot longer.
1006 if ($post_need_approval)
1007 {
1008 meta_refresh(10, $redirect_url);
1009 $message = ($mode == 'edit') ? $user->lang['POST_EDITED_MOD'] : $user->lang['POST_STORED_MOD'];
1010 $message .= (($user->data['user_id'] == ANONYMOUS) ? '' : ' '. $user->lang['POST_APPROVAL_NOTIFY']);
1011 }
1012 else
1013 {
1014 meta_refresh(3, $redirect_url);
1015
1016 $message = ($mode == 'edit') ? 'POST_EDITED' : 'POST_STORED';
1017 $message = $user->lang[$message] . '<br /><br />' . sprintf($user->lang['VIEW_MESSAGE'], '<a href="' . $redirect_url . '">', '</a>');
1018 }
1019
1020 $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $data['forum_id']) . '">', '</a>');
1021 trigger_error($message);
1022 }
1023 }
1024 }
1025
1026 // Preview
1027 if (!sizeof($error) && $preview)
1028 {
1029 $post_data['post_time'] = ($mode == 'edit') ? $post_data['post_time'] : $current_time;
1030
1031 $preview_message = $message_parser->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies'], false);
1032
1033 $preview_signature = ($mode == 'edit') ? $post_data['user_sig'] : $user->data['user_sig'];
1034 $preview_signature_uid = ($mode == 'edit') ? $post_data['user_sig_bbcode_uid'] : $user->data['user_sig_bbcode_uid'];
1035 $preview_signature_bitfield = ($mode == 'edit') ? $post_data['user_sig_bbcode_bitfield'] : $user->data['user_sig_bbcode_bitfield'];
1036
1037 // Signature
1038 if ($post_data['enable_sig'] && $config['allow_sig'] && $preview_signature && $auth->acl_get('f_sigs', $forum_id))
1039 {
1040 $parse_sig = new parse_message($preview_signature);
1041 $parse_sig->bbcode_uid = $preview_signature_uid;
1042 $parse_sig->bbcode_bitfield = $preview_signature_bitfield;
1043
1044 // Not sure about parameters for bbcode/smilies/urls... in signatures
1045 $parse_sig->format_display($config['allow_sig_bbcode'], true, $config['allow_sig_smilies']);
1046 $preview_signature = $parse_sig->message;
1047 unset($parse_sig);
1048 }
1049 else
1050 {
1051 $preview_signature = '';
1052 }
1053
1054 $preview_subject = censor_text($post_data['post_subject']);
1055
1056 // Poll Preview
1057 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))*/))
1058 && $auth->acl_get('f_poll', $forum_id))
1059 {
1060 $parse_poll = new parse_message($post_data['poll_title']);
1061 $parse_poll->bbcode_uid = $message_parser->bbcode_uid;
1062 $parse_poll->bbcode_bitfield = $message_parser->bbcode_bitfield;
1063
1064 $parse_poll->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies']);
1065
1066 if ($post_data['poll_length'])
1067 {
1068 $poll_end = ($post_data['poll_length'] * 86400) + (($post_data['poll_start']) ? $post_data['poll_start'] : time());
1069 }
1070
1071 $template->assign_vars(array(
1072 'S_HAS_POLL_OPTIONS' => (sizeof($post_data['poll_options'])),
1073 'S_IS_MULTI_CHOICE' => ($post_data['poll_max_options'] > 1) ? true : false,
1074
1075 'POLL_QUESTION' => $parse_poll->message,
1076
1077 'L_POLL_LENGTH' => ($post_data['poll_length']) ? sprintf($user->lang['POLL_RUN_TILL'], $user->format_date($poll_end)) : '',
1078 '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']))
1079 );
1080
1081 $parse_poll->message = implode("\n", $post_data['poll_options']);
1082 $parse_poll->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies']);
1083 $preview_poll_options = explode('<br />', $parse_poll->message);
1084 unset($parse_poll);
1085
1086 foreach ($preview_poll_options as $key => $option)
1087 {
1088 $template->assign_block_vars('poll_option', array(
1089 'POLL_OPTION_CAPTION' => $option,
1090 'POLL_OPTION_ID' => $key + 1)
1091 );
1092 }
1093 unset($preview_poll_options);
1094 }
1095
1096 // Attachment Preview
1097 if (sizeof($message_parser->attachment_data))
1098 {
1099 $template->assign_var('S_HAS_ATTACHMENTS', true);
1100
1101 $update_count = array();
1102 $attachment_data = $message_parser->attachment_data;
1103
1104 parse_attachments($forum_id, $preview_message, $attachment_data, $update_count, true);
1105
1106 foreach ($attachment_data as $i => $attachment)
1107 {
1108 $template->assign_block_vars('attachment', array(
1109 'DISPLAY_ATTACHMENT' => $attachment)
1110 );
1111 }
1112 unset($attachment_data);
1113 }
1114
1115 if (!sizeof($error))
1116 {
1117 $template->assign_vars(array(
1118 'PREVIEW_SUBJECT' => $preview_subject,
1119 'PREVIEW_MESSAGE' => $preview_message,
1120 'PREVIEW_SIGNATURE' => $preview_signature,
1121
1122 'S_DISPLAY_PREVIEW' => true)
1123 );
1124 }
1125 }
1126
1127 // Decode text for message display
1128 $post_data['bbcode_uid'] = ($mode == 'quote' && !$preview && !$refresh && !sizeof($error)) ? $post_data['bbcode_uid'] : $message_parser->bbcode_uid;
1129 $message_parser->decode_message($post_data['bbcode_uid']);
1130
1131 if ($mode == 'quote' && !$submit && !$preview && !$refresh)
1132 {
1133 $message_parser->message = '[quote="' . $post_data['quote_username'] . '"]' . censor_text(trim($message_parser->message)) . "[/quote]\n";
1134 }
1135
1136 if (($mode == 'reply' || $mode == 'quote') && !$submit && !$preview && !$refresh)
1137 {
1138 $post_data['post_subject'] = ((strpos($post_data['post_subject'], 'Re: ') !== 0) ? 'Re: ' : '') . censor_text($post_data['post_subject']);
1139 }
1140
1141 $attachment_data = $message_parser->attachment_data;
1142 $filename_data = $message_parser->filename_data;
1143 $post_data['post_text'] = $message_parser->message;
1144
1145 if (sizeof($post_data['poll_options']) && $post_data['poll_title'])
1146 {
1147 $message_parser->message = $post_data['poll_title'];
1148 $message_parser->bbcode_uid = $post_data['bbcode_uid'];
1149
1150 $message_parser->decode_message();
1151 $post_data['poll_title'] = $message_parser->message;
1152
1153 $message_parser->message = implode("\n", $post_data['poll_options']);
1154 $message_parser->decode_message();
1155 $post_data['poll_options'] = explode("\n", $message_parser->message);
1156 }
1157 unset($message_parser);
1158
1159 // MAIN POSTING PAGE BEGINS HERE
1160
1161 // Forum moderators?
1162 $moderators = array();
1163 get_moderators($moderators, $forum_id);
1164
1165 // Generate smiley listing
1166 generate_smilies('inline', $forum_id);
1167
1168 // Generate inline attachment select box
1169 posting_gen_inline_attachments($attachment_data);
1170
1171 // Do show topic type selection only in first post.
1172 $topic_type_toggle = false;
1173
1174 if ($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id']))
1175 {
1176 $topic_type_toggle = posting_gen_topic_types($forum_id, $post_data['topic_type']);
1177 }
1178
1179 $s_topic_icons = false;
1180 if ($post_data['enable_icons'] && $auth->acl_get('f_icons', $forum_id))
1181 {
1182 $s_topic_icons = posting_gen_topic_icons($mode, $post_data['icon_id']);
1183 }
1184
1185 $bbcode_checked = (isset($post_data['enable_bbcode'])) ? !$post_data['enable_bbcode'] : (($config['allow_bbcode']) ? !$user->optionget('bbcode') : 1);
1186 $smilies_checked = (isset($post_data['enable_smilies'])) ? !$post_data['enable_smilies'] : (($config['allow_smilies']) ? !$user->optionget('smilies') : 1);
1187 $urls_checked = (isset($post_data['enable_urls'])) ? !$post_data['enable_urls'] : 0;
1188 $sig_checked = $post_data['enable_sig'];
1189 $lock_topic_checked = (isset($topic_lock) && $topic_lock) ? $topic_lock : (($post_data['topic_status'] == ITEM_LOCKED) ? 1 : 0);
1190 $lock_post_checked = (isset($post_lock)) ? $post_lock : $post_data['post_edit_locked'];
1191
1192 // 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
1193 $notify_set = ($mode != 'edit' && $config['allow_topic_notify'] && $user->data['is_registered'] && !$post_data['notify_set']) ? $user->data['user_notify'] : $post_data['notify_set'];
1194 $notify_checked = (isset($notify)) ? $notify : (($mode == 'post') ? $user->data['user_notify'] : $notify_set);
1195
1196 // Page title & action URL, include session_id for security purpose
1197 $s_action = append_sid("{$phpbb_root_path}posting.$phpEx", "mode=$mode&f=$forum_id", true, $user->session_id);
1198 $s_action .= ($topic_id) ? "&t=$topic_id" : '';
1199 $s_action .= ($post_id) ? "&p=$post_id" : '';
1200
1201 switch ($mode)
1202 {
1203 case 'post':
1204 $page_title = $user->lang['POST_TOPIC'];
1205 break;
1206
1207 case 'quote':
1208 case 'reply':
1209 $page_title = $user->lang['POST_REPLY'];
1210 break;
1211
1212 case 'delete':
1213 case 'edit':
1214 $page_title = $user->lang['EDIT_POST'];
1215 break;
1216 }
1217
1218 // Build Navigation Links
1219 generate_forum_nav($post_data);
1220
1221 // Build Forum Rules
1222 generate_forum_rules($post_data);
1223
1224 if ($config['enable_post_confirm'] && !$user->data['is_registered'] && $solved_captcha === false && ($mode == 'post' || $mode == 'reply' || $mode == 'quote'))
1225 {
1226 // Show confirm image
1227 $sql = 'DELETE FROM ' . CONFIRM_TABLE . "
1228 WHERE session_id = '" . $db->sql_escape($user->session_id) . "'
1229 AND confirm_type = " . CONFIRM_POST;
1230 $db->sql_query($sql);
1231
1232 // Generate code
1233 $code = gen_rand_string(mt_rand(5, 8));
1234 $confirm_id = md5(unique_id($user->ip));
1235 $seed = hexdec(substr(unique_id(), 4, 10));
1236
1237 // compute $seed % 0x7fffffff
1238 $seed -= 0x7fffffff * floor($seed / 0x7fffffff);
1239
1240 $sql = 'INSERT INTO ' . CONFIRM_TABLE . ' ' . $db->sql_build_array('INSERT', array(
1241 'confirm_id' => (string) $confirm_id,
1242 'session_id' => (string) $user->session_id,
1243 'confirm_type' => (int) CONFIRM_POST,
1244 'code' => (string) $code,
1245 'seed' => (int) $seed)
1246 );
1247 $db->sql_query($sql);
1248
1249 $template->assign_vars(array(
1250 'S_CONFIRM_CODE' => true,
1251 'CONFIRM_ID' => $confirm_id,
1252 'CONFIRM_IMAGE' => '<img src="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=confirm&id=' . $confirm_id . '&type=' . CONFIRM_POST) . '" alt="" title="" />',
1253 'L_POST_CONFIRM_EXPLAIN' => sprintf($user->lang['POST_CONFIRM_EXPLAIN'], '<a href="mailto:' . htmlspecialchars($config['board_contact']) . '">', '</a>'),
1254 ));
1255 }
1256
1257 $s_hidden_fields = ($mode == 'reply' || $mode == 'quote') ? '<input type="hidden" name="topic_cur_post_id" value="' . $post_data['topic_last_post_id'] . '" />' : '';
1258 $s_hidden_fields .= '<input type="hidden" name="lastclick" value="' . $current_time . '" />';
1259 $s_hidden_fields .= ($draft_id || isset($_REQUEST['draft_loaded'])) ? '<input type="hidden" name="draft_loaded" value="' . request_var('draft_loaded', $draft_id) . '" />' : '';
1260
1261 // Add the confirm id/code pair to the hidden fields, else an error is displayed on next submit/preview
1262 if ($solved_captcha !== false)
1263 {
1264 $s_hidden_fields .= build_hidden_fields(array(
1265 'confirm_id' => request_var('confirm_id', ''),
1266 'confirm_code' => request_var('confirm_code', ''))
1267 );
1268 }
1269
1270 $form_enctype = (@ini_get('file_uploads') == '0' || strtolower(@ini_get('file_uploads')) == 'off' || @ini_get('file_uploads') == '0' || !$config['allow_attachments'] || !$auth->acl_get('u_attach') || !$auth->acl_get('f_attach', $forum_id)) ? '' : ' enctype="multipart/form-data"';
1271 add_form_key('posting');
1272
1273
1274 // Start assigning vars for main posting page ...
1275 $template->assign_vars(array(
1276 'L_POST_A' => $page_title,
1277 'L_ICON' => ($mode == 'reply' || $mode == 'quote' || ($mode == 'edit' && $post_id != $post_data['topic_first_post_id'])) ? $user->lang['POST_ICON'] : $user->lang['TOPIC_ICON'],
1278 'L_MESSAGE_BODY_EXPLAIN' => (intval($config['max_post_chars'])) ? sprintf($user->lang['MESSAGE_BODY_EXPLAIN'], intval($config['max_post_chars'])) : '',
1279
1280 'FORUM_NAME' => $post_data['forum_name'],
1281 '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']) : '',
1282 'TOPIC_TITLE' => censor_text($post_data['topic_title']),
1283 'MODERATORS' => (sizeof($moderators)) ? implode(', ', $moderators[$forum_id]) : '',
1284 'USERNAME' => ((!$preview && $mode != 'quote') || $preview) ? $post_data['username'] : '',
1285 'SUBJECT' => $post_data['post_subject'],
1286 'MESSAGE' => $post_data['post_text'],
1287 '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>'),
1288 'IMG_STATUS' => ($img_status) ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'],
1289 'FLASH_STATUS' => ($flash_status) ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'],
1290 'SMILIES_STATUS' => ($smilies_status) ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'],
1291 'URL_STATUS' => ($bbcode_status && $url_status) ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'],
1292 'MINI_POST_IMG' => $user->img('icon_post_target', $user->lang['POST']),
1293 'POST_DATE' => ($post_data['post_time']) ? $user->format_date($post_data['post_time']) : '',
1294 'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '',
1295 'TOPIC_TIME_LIMIT' => (int) $post_data['topic_time_limit'],
1296 'EDIT_REASON' => $post_data['post_edit_reason'],
1297 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id"),
1298 'U_VIEW_TOPIC' => ($mode != 'post') ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id") : '',
1299 'U_PROGRESS_BAR' => append_sid("{$phpbb_root_path}posting.$phpEx", "f=$forum_id&mode=popup"),
1300 'UA_PROGRESS_BAR' => addslashes(append_sid("{$phpbb_root_path}posting.$phpEx", "f=$forum_id&mode=popup")),
1301
1302 'S_PRIVMSGS' => false,
1303 'S_CLOSE_PROGRESS_WINDOW' => (isset($_POST['add_file'])) ? true : false,
1304 'S_EDIT_POST' => ($mode == 'edit') ? true : false,
1305 'S_EDIT_REASON' => ($mode == 'edit' && $auth->acl_get('m_edit', $forum_id)) ? true : false,
1306 'S_DISPLAY_USERNAME' => (!$user->data['is_registered'] || ($mode == 'edit' && $post_data['poster_id'] == ANONYMOUS)) ? true : false,
1307 'S_SHOW_TOPIC_ICONS' => $s_topic_icons,
1308 'S_DELETE_ALLOWED' => ($mode == 'edit' && (($post_id == $post_data['topic_last_post_id'] && $post_data['poster_id'] == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id)) || $auth->acl_get('m_delete', $forum_id))) ? true : false,
1309 'S_BBCODE_ALLOWED' => $bbcode_status,
1310 'S_BBCODE_CHECKED' => ($bbcode_checked) ? ' checked="checked"' : '',
1311 'S_SMILIES_ALLOWED' => $smilies_status,
1312 'S_SMILIES_CHECKED' => ($smilies_checked) ? ' checked="checked"' : '',
1313 'S_SIG_ALLOWED' => ($auth->acl_get('f_sigs', $forum_id) && $config['allow_sig'] && $user->data['is_registered']) ? true : false,
1314 'S_SIGNATURE_CHECKED' => ($sig_checked) ? ' checked="checked"' : '',
1315 '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,
1316 'S_NOTIFY_CHECKED' => ($notify_checked) ? ' checked="checked"' : '',
1317 '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,
1318 'S_LOCK_TOPIC_CHECKED' => ($lock_topic_checked) ? ' checked="checked"' : '',
1319 'S_LOCK_POST_ALLOWED' => ($mode == 'edit' && $auth->acl_get('m_edit', $forum_id)) ? true : false,
1320 'S_LOCK_POST_CHECKED' => ($lock_post_checked) ? ' checked="checked"' : '',
1321 'S_LINKS_ALLOWED' => $url_status,
1322 'S_MAGIC_URL_CHECKED' => ($urls_checked) ? ' checked="checked"' : '',
1323 'S_TYPE_TOGGLE' => $topic_type_toggle,
1324 'S_SAVE_ALLOWED' => ($auth->acl_get('u_savedrafts') && $user->data['is_registered'] && $mode != 'edit') ? true : false,
1325 'S_HAS_DRAFTS' => ($auth->acl_get('u_savedrafts') && $user->data['is_registered'] && $post_data['drafts']) ? true : false,
1326 'S_FORM_ENCTYPE' => $form_enctype,
1327
1328 'S_BBCODE_IMG' => $img_status,
1329 'S_BBCODE_URL' => $url_status,
1330 'S_BBCODE_FLASH' => $flash_status,
1331 'S_BBCODE_QUOTE' => $quote_status,
1332
1333 'S_POST_ACTION' => $s_action,
1334 'S_HIDDEN_FIELDS' => $s_hidden_fields)
1335 );
1336
1337 // Build custom bbcodes array
1338 display_custom_bbcodes();
1339
1340 // Poll entry
1341 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))*/))
1342 && $auth->acl_get('f_poll', $forum_id))
1343 {
1344 $template->assign_vars(array(
1345 'S_SHOW_POLL_BOX' => true,
1346 'S_POLL_VOTE_CHANGE' => ($auth->acl_get('f_votechg', $forum_id)),
1347 '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))),
1348 'S_POLL_DELETE_CHECKED' => (!empty($poll_delete)) ? true : false,
1349
1350 'L_POLL_OPTIONS_EXPLAIN' => sprintf($user->lang['POLL_OPTIONS_' . (($mode == 'edit') ? 'EDIT_' : '') . 'EXPLAIN'], $config['max_poll_options']),
1351
1352 'VOTE_CHANGE_CHECKED' => (!empty($post_data['poll_vote_change'])) ? ' checked="checked"' : '',
1353 'POLL_TITLE' => (isset($post_data['poll_title'])) ? $post_data['poll_title'] : '',
1354 'POLL_OPTIONS' => (!empty($post_data['poll_options'])) ? implode("\n", $post_data['poll_options']) : '',
1355 'POLL_MAX_OPTIONS' => (isset($post_data['poll_max_options'])) ? (int) $post_data['poll_max_options'] : 1,
1356 'POLL_LENGTH' => $post_data['poll_length'])
1357 );
1358 }
1359
1360 // Attachment entry
1361 // Not using acl_gets here, because it is using OR logic
1362 if ($auth->acl_get('f_attach', $forum_id) && $auth->acl_get('u_attach') && $config['allow_attachments'] && $form_enctype)
1363 {
1364 posting_gen_attachment_entry($attachment_data, $filename_data);
1365 }
1366
1367 // Output page ...
1368 page_header($page_title);
1369
1370 $template->set_filenames(array(
1371 'body' => 'posting_body.html')
1372 );
1373
1374 make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
1375
1376 // Topic review
1377 if ($mode == 'reply' || $mode == 'quote')
1378 {
1379 if (topic_review($topic_id, $forum_id))
1380 {
1381 $template->assign_var('S_DISPLAY_REVIEW', true);
1382 }
1383 }
1384
1385 page_footer();
1386
1387 /**
1388 * Show upload popup (progress bar)
1389 */
1390 function upload_popup($forum_style = 0)
1391 {
1392 global $template, $user;
1393
1394 ($forum_style) ? $user->setup('posting', $forum_style) : $user->setup('posting');
1395
1396 page_header($user->lang['PROGRESS_BAR']);
1397
1398 $template->set_filenames(array(
1399 'popup' => 'posting_progress_bar.html')
1400 );
1401
1402 $template->assign_vars(array(
1403 'PROGRESS_BAR' => $user->img('upload_bar', $user->lang['UPLOAD_IN_PROGRESS']))
1404 );
1405
1406 $template->display('popup');
1407 }
1408
1409 /**
1410 * Do the various checks required for removing posts as well as removing it
1411 */
1412 function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data)
1413 {
1414 global $user, $db, $auth;
1415 global $phpbb_root_path, $phpEx;
1416
1417 // If moderator removing post or user itself removing post, present a confirmation screen
1418 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']))
1419 {
1420 $s_hidden_fields = build_hidden_fields(array(
1421 'p' => $post_id,
1422 'f' => $forum_id,
1423 'mode' => 'delete')
1424 );
1425
1426 if (confirm_box(true))
1427 {
1428 $data = array(
1429 'topic_first_post_id' => $post_data['topic_first_post_id'],
1430 'topic_last_post_id' => $post_data['topic_last_post_id'],
1431 'topic_approved' => $post_data['topic_approved'],
1432 'topic_type' => $post_data['topic_type'],
1433 'post_approved' => $post_data['post_approved'],
1434 'post_reported' => $post_data['post_reported'],
1435 'post_time' => $post_data['post_time'],
1436 'poster_id' => $post_data['poster_id'],
1437 'post_postcount' => $post_data['post_postcount']
1438 );
1439
1440 $next_post_id = delete_post($forum_id, $topic_id, $post_id, $data);
1441
1442 if ($post_data['topic_first_post_id'] == $post_data['topic_last_post_id'])
1443 {
1444 add_log('mod', $forum_id, $topic_id, 'LOG_DELETE_TOPIC', $post_data['topic_title']);
1445
1446 $meta_info = append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id");
1447 $message = $user->lang['POST_DELETED'];
1448 }
1449 else
1450 {
1451 add_log('mod', $forum_id, $topic_id, 'LOG_DELETE_POST', $post_data['post_subject']);
1452
1453 $meta_info = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id&p=$next_post_id") . "#p$next_post_id";
1454 $message = $user->lang['POST_DELETED'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $meta_info . '">', '</a>');
1455 }
1456
1457 meta_refresh(3, $meta_info);
1458 $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
1459 trigger_error($message);
1460 }
1461 else
1462 {
1463 confirm_box(false, 'DELETE_MESSAGE', $s_hidden_fields);
1464 }
1465 }
1466
1467 // If we are here the user is not able to delete - present the correct error message
1468 if ($post_data['poster_id'] != $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id))
1469 {
1470 trigger_error('DELETE_OWN_POSTS');
1471 }
1472
1473 if ($post_data['poster_id'] == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id) && $post_id != $post_data['topic_last_post_id'])
1474 {
1475 trigger_error('CANNOT_DELETE_REPLIED');
1476 }
1477
1478 trigger_error('USER_CANNOT_DELETE');
1479 }
1480
1481 ?>