(a little test for later merges)
[phpbb.git] / phpBB / posting.php
blob1c7cd95b81738a98ca2b1d032fc2265581aaee64
1 <?php
2 /**
4 * @package phpBB3
5 * @version $Id$
6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
9 */
11 /**
12 * @ignore
14 define('IN_PHPBB', true);
15 $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
16 $phpEx = substr(strrchr(__FILE__, '.'), 1);
17 include($phpbb_root_path . 'common.' . $phpEx);
18 include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
19 include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
20 include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
23 // Start session management
24 $user->session_begin();
25 $auth->acl($user->data);
28 // Grab only parameters needed here
29 $post_id = request_var('p', 0);
30 $topic_id = request_var('t', 0);
31 $forum_id = request_var('f', 0);
32 $draft_id = request_var('d', 0);
33 $lastclick = request_var('lastclick', 0);
35 $submit = (isset($_POST['post'])) ? true : false;
36 $preview = (isset($_POST['preview'])) ? true : false;
37 $save = (isset($_POST['save'])) ? true : false;
38 $load = (isset($_POST['load'])) ? true : false;
39 $delete = (isset($_POST['delete'])) ? true : false;
40 $cancel = (isset($_POST['cancel']) && !isset($_POST['save'])) ? true : false;
42 $refresh = (isset($_POST['add_file']) || isset($_POST['delete_file']) || isset($_POST['full_editor']) || isset($_POST['cancel_unglobalise']) || $save || $load) ? true : false;
43 $mode = ($delete && !$preview && !$refresh && $submit) ? 'delete' : request_var('mode', '');
45 $error = $post_data = array();
46 $current_time = time();
48 if ($config['enable_post_confirm'] && !$user->data['is_registered'])
50 include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
51 $captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']);
52 $captcha->init(CONFIRM_POST);
55 // Was cancel pressed? If so then redirect to the appropriate page
56 if ($cancel || ($current_time - $lastclick < 2 && $submit))
58 $f = ($forum_id) ? 'f=' . $forum_id . '&amp;' : '';
59 $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")));
60 redirect($redirect);
63 if (in_array($mode, array('post', 'reply', 'quote', 'edit', 'delete')) && !$forum_id)
65 trigger_error('NO_FORUM');
68 // We need to know some basic information in all cases before we do anything.
69 switch ($mode)
71 case 'post':
72 $sql = 'SELECT *
73 FROM ' . FORUMS_TABLE . "
74 WHERE forum_id = $forum_id";
75 break;
77 case 'bump':
78 case 'reply':
79 if (!$topic_id)
81 trigger_error('NO_TOPIC');
84 // Force forum id
85 $sql = 'SELECT forum_id
86 FROM ' . TOPICS_TABLE . '
87 WHERE topic_id = ' . $topic_id;
88 $result = $db->sql_query($sql);
89 $f_id = (int) $db->sql_fetchfield('forum_id');
90 $db->sql_freeresult($result);
92 $forum_id = (!$f_id) ? $forum_id : $f_id;
94 $sql = 'SELECT f.*, t.*
95 FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f
96 WHERE t.topic_id = $topic_id
97 AND (f.forum_id = t.forum_id
98 OR f.forum_id = $forum_id)
99 AND t.topic_approved = 1";
100 break;
102 case 'quote':
103 case 'edit':
104 case 'delete':
105 if (!$post_id)
107 $user->setup('posting');
108 trigger_error('NO_POST');
111 // Force forum id
112 $sql = 'SELECT forum_id
113 FROM ' . POSTS_TABLE . '
114 WHERE post_id = ' . $post_id;
115 $result = $db->sql_query($sql);
116 $f_id = (int) $db->sql_fetchfield('forum_id');
117 $db->sql_freeresult($result);
119 $forum_id = (!$f_id) ? $forum_id : $f_id;
121 $sql = 'SELECT f.*, t.*, p.*, u.username, u.username_clean, u.user_sig, u.user_sig_bbcode_uid, u.user_sig_bbcode_bitfield
122 FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . ' f, ' . USERS_TABLE . " u
123 WHERE p.post_id = $post_id
124 AND t.topic_id = p.topic_id
125 AND u.user_id = p.poster_id
126 AND (f.forum_id = t.forum_id
127 OR f.forum_id = $forum_id)" .
128 (($auth->acl_get('m_approve', $forum_id) && $mode != 'quote') ? '' : 'AND p.post_approved = 1');
129 break;
131 case 'smilies':
132 $sql = '';
133 generate_smilies('window', $forum_id);
134 break;
136 case 'popup':
137 if ($forum_id)
139 $sql = 'SELECT forum_style
140 FROM ' . FORUMS_TABLE . '
141 WHERE forum_id = ' . $forum_id;
143 else
145 upload_popup();
146 return;
148 break;
150 default:
151 $sql = '';
152 break;
155 if (!$sql)
157 $user->setup('posting');
158 trigger_error('NO_POST_MODE');
161 $result = $db->sql_query($sql);
162 $post_data = $db->sql_fetchrow($result);
163 $db->sql_freeresult($result);
165 if (!$post_data)
167 if (!($mode == 'post' || $mode == 'bump' || $mode == 'reply'))
169 $user->setup('posting');
171 trigger_error(($mode == 'post' || $mode == 'bump' || $mode == 'reply') ? 'NO_TOPIC' : 'NO_POST');
174 if ($mode == 'popup')
176 upload_popup($post_data['forum_style']);
177 return;
180 $user->setup(array('posting', 'mcp', 'viewtopic'), $post_data['forum_style']);
182 // Use post_row values in favor of submitted ones...
183 $forum_id = (!empty($post_data['forum_id'])) ? (int) $post_data['forum_id'] : (int) $forum_id;
184 $topic_id = (!empty($post_data['topic_id'])) ? (int) $post_data['topic_id'] : (int) $topic_id;
185 $post_id = (!empty($post_data['post_id'])) ? (int) $post_data['post_id'] : (int) $post_id;
187 // Need to login to passworded forum first?
188 if ($post_data['forum_password'])
190 login_forum_box(array(
191 'forum_id' => $forum_id,
192 'forum_password' => $post_data['forum_password'])
196 // Check permissions
197 if ($user->data['is_bot'])
199 redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
202 // Is the user able to read within this forum?
203 if (!$auth->acl_get('f_read', $forum_id))
205 if ($user->data['user_id'] != ANONYMOUS)
207 trigger_error('USER_CANNOT_READ');
210 login_box('', $user->lang['LOGIN_EXPLAIN_POST']);
213 // Permission to do the action asked?
214 $is_authed = false;
216 switch ($mode)
218 case 'post':
219 if ($auth->acl_get('f_post', $forum_id))
221 $is_authed = true;
223 break;
225 case 'bump':
226 if ($auth->acl_get('f_bump', $forum_id))
228 $is_authed = true;
230 break;
232 case 'quote':
234 $post_data['post_edit_locked'] = 0;
236 // no break;
238 case 'reply':
239 if ($auth->acl_get('f_reply', $forum_id))
241 $is_authed = true;
243 break;
245 case 'edit':
246 if ($user->data['is_registered'] && $auth->acl_gets('f_edit', 'm_edit', $forum_id))
248 $is_authed = true;
250 break;
252 case 'delete':
253 if ($user->data['is_registered'] && $auth->acl_gets('f_delete', 'm_delete', $forum_id))
255 $is_authed = true;
257 break;
260 if (!$is_authed)
262 $check_auth = ($mode == 'quote') ? 'reply' : $mode;
264 if ($user->data['is_registered'])
266 trigger_error('USER_CANNOT_' . strtoupper($check_auth));
269 login_box('', $user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)]);
272 // Is the user able to post within this forum?
273 if ($post_data['forum_type'] != FORUM_POST && in_array($mode, array('post', 'bump', 'quote', 'reply')))
275 trigger_error('USER_CANNOT_FORUM_POST');
278 // Forum/Topic locked?
279 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))
281 trigger_error(($post_data['forum_status'] == ITEM_LOCKED) ? 'FORUM_LOCKED' : 'TOPIC_LOCKED');
284 // Can we edit this post ... if we're a moderator with rights then always yes
285 // else it depends on editing times, lock status and if we're the correct user
286 if ($mode == 'edit' && !$auth->acl_get('m_edit', $forum_id))
288 if ($user->data['user_id'] != $post_data['poster_id'])
290 trigger_error('USER_CANNOT_EDIT');
293 if (!($post_data['post_time'] > time() - ($config['edit_time'] * 60) || !$config['edit_time']))
295 trigger_error('CANNOT_EDIT_TIME');
298 if ($post_data['post_edit_locked'])
300 trigger_error('CANNOT_EDIT_POST_LOCKED');
304 // Handle delete mode...
305 if ($mode == 'delete')
307 handle_post_delete($forum_id, $topic_id, $post_id, $post_data);
308 return;
311 // Handle bump mode...
312 if ($mode == 'bump')
314 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'])
315 && check_link_hash(request_var('hash', ''), "topic_{$post_data['topic_id']}"))
317 $db->sql_transaction('begin');
319 $sql = 'UPDATE ' . POSTS_TABLE . "
320 SET post_time = $current_time
321 WHERE post_id = {$post_data['topic_last_post_id']}
322 AND topic_id = $topic_id";
323 $db->sql_query($sql);
325 $sql = 'UPDATE ' . TOPICS_TABLE . "
326 SET topic_last_post_time = $current_time,
327 topic_bumped = 1,
328 topic_bumper = " . $user->data['user_id'] . "
329 WHERE topic_id = $topic_id";
330 $db->sql_query($sql);
332 update_post_information('forum', $forum_id);
334 $sql = 'UPDATE ' . USERS_TABLE . "
335 SET user_lastpost_time = $current_time
336 WHERE user_id = " . $user->data['user_id'];
337 $db->sql_query($sql);
339 $db->sql_transaction('commit');
341 markread('post', $forum_id, $topic_id, $current_time);
343 add_log('mod', $forum_id, $topic_id, 'LOG_BUMP_TOPIC', $post_data['topic_title']);
345 $meta_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;p={$post_data['topic_last_post_id']}") . "#p{$post_data['topic_last_post_id']}";
346 meta_refresh(3, $meta_url);
348 $message = $user->lang['TOPIC_BUMPED'] . '<br /><br />' . sprintf($user->lang['VIEW_MESSAGE'], '<a href="' . $meta_url . '">', '</a>');
349 $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
351 trigger_error($message);
354 trigger_error('BUMP_ERROR');
357 // Subject length limiting to 60 characters if first post...
358 if ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_data['post_id']))
360 $template->assign_var('S_NEW_MESSAGE', true);
363 // Determine some vars
364 if (isset($post_data['poster_id']) && $post_data['poster_id'] == ANONYMOUS)
366 $post_data['quote_username'] = (!empty($post_data['post_username'])) ? $post_data['post_username'] : $user->lang['GUEST'];
368 else
370 $post_data['quote_username'] = isset($post_data['username']) ? $post_data['username'] : '';
373 $post_data['post_edit_locked'] = (isset($post_data['post_edit_locked'])) ? (int) $post_data['post_edit_locked'] : 0;
374 $post_data['post_subject_md5'] = (isset($post_data['post_subject']) && $mode == 'edit') ? md5($post_data['post_subject']) : '';
375 $post_data['post_subject'] = (in_array($mode, array('quote', 'edit'))) ? $post_data['post_subject'] : ((isset($post_data['topic_title'])) ? $post_data['topic_title'] : '');
376 $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;
377 $post_data['poll_length'] = (!empty($post_data['poll_length'])) ? (int) $post_data['poll_length'] / 86400 : 0;
378 $post_data['poll_start'] = (!empty($post_data['poll_start'])) ? (int) $post_data['poll_start'] : 0;
379 $post_data['icon_id'] = (!isset($post_data['icon_id']) || in_array($mode, array('quote', 'reply'))) ? 0 : (int) $post_data['icon_id'];
380 $post_data['poll_options'] = array();
382 // Get Poll Data
383 if ($post_data['poll_start'])
385 $sql = 'SELECT poll_option_text
386 FROM ' . POLL_OPTIONS_TABLE . "
387 WHERE topic_id = $topic_id
388 ORDER BY poll_option_id";
389 $result = $db->sql_query($sql);
391 while ($row = $db->sql_fetchrow($result))
393 $post_data['poll_options'][] = trim($row['poll_option_text']);
395 $db->sql_freeresult($result);
398 $orig_poll_options_size = sizeof($post_data['poll_options']);
400 $message_parser = new parse_message();
402 if (isset($post_data['post_text']))
404 $message_parser->message = &$post_data['post_text'];
405 unset($post_data['post_text']);
408 // Set some default variables
409 $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);
411 foreach ($uninit as $var_name => $default_value)
413 if (!isset($post_data[$var_name]))
415 $post_data[$var_name] = $default_value;
418 unset($uninit);
420 // Always check if the submitted attachment data is valid and belongs to the user.
421 // Further down (especially in submit_post()) we do not check this again.
422 $message_parser->get_submitted_attachment_data($post_data['poster_id']);
424 if ($post_data['post_attachment'] && !$submit && !$refresh && !$preview && $mode == 'edit')
426 // Do not change to SELECT *
427 $sql = 'SELECT attach_id, is_orphan, attach_comment, real_filename
428 FROM ' . ATTACHMENTS_TABLE . "
429 WHERE post_msg_id = $post_id
430 AND in_message = 0
431 AND is_orphan = 0
432 ORDER BY filetime DESC";
433 $result = $db->sql_query($sql);
434 $message_parser->attachment_data = array_merge($message_parser->attachment_data, $db->sql_fetchrowset($result));
435 $db->sql_freeresult($result);
438 if ($post_data['poster_id'] == ANONYMOUS)
440 $post_data['username'] = ($mode == 'quote' || $mode == 'edit') ? trim($post_data['post_username']) : '';
442 else
444 $post_data['username'] = ($mode == 'quote' || $mode == 'edit') ? trim($post_data['username']) : '';
447 $post_data['enable_urls'] = $post_data['enable_magic_url'];
449 if ($mode != 'edit')
451 $post_data['enable_sig'] = ($config['allow_sig'] && $user->optionget('attachsig')) ? true: false;
452 $post_data['enable_smilies'] = ($config['allow_smilies'] && $user->optionget('smilies')) ? true : false;
453 $post_data['enable_bbcode'] = ($config['allow_bbcode'] && $user->optionget('bbcode')) ? true : false;
454 $post_data['enable_urls'] = true;
457 $post_data['enable_magic_url'] = $post_data['drafts'] = false;
459 // User own some drafts?
460 if ($user->data['is_registered'] && $auth->acl_get('u_savedrafts') && ($mode == 'reply' || $mode == 'post' || $mode == 'quote'))
462 $sql = 'SELECT draft_id
463 FROM ' . DRAFTS_TABLE . '
464 WHERE user_id = ' . $user->data['user_id'] .
465 (($forum_id) ? ' AND forum_id = ' . (int) $forum_id : '') .
466 (($topic_id) ? ' AND topic_id = ' . (int) $topic_id : '') .
467 (($draft_id) ? " AND draft_id <> $draft_id" : '');
468 $result = $db->sql_query_limit($sql, 1);
470 if ($db->sql_fetchrow($result))
472 $post_data['drafts'] = true;
474 $db->sql_freeresult($result);
477 $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);
479 // Check if user is watching this topic
480 if ($mode != 'post' && $config['allow_topic_notify'] && $user->data['is_registered'])
482 $sql = 'SELECT topic_id
483 FROM ' . TOPICS_WATCH_TABLE . '
484 WHERE topic_id = ' . $topic_id . '
485 AND user_id = ' . $user->data['user_id'];
486 $result = $db->sql_query($sql);
487 $post_data['notify_set'] = (int) $db->sql_fetchfield('topic_id');
488 $db->sql_freeresult($result);
491 // Do we want to edit our post ?
492 if ($mode == 'edit' && $post_data['bbcode_uid'])
494 $message_parser->bbcode_uid = $post_data['bbcode_uid'];
497 // HTML, BBCode, Smilies, Images and Flash status
498 $bbcode_status = ($config['allow_bbcode'] && $auth->acl_get('f_bbcode', $forum_id)) ? true : false;
499 $smilies_status = ($config['allow_smilies'] && $auth->acl_get('f_smilies', $forum_id)) ? true : false;
500 $img_status = ($bbcode_status && $auth->acl_get('f_img', $forum_id)) ? true : false;
501 $url_status = ($config['allow_post_links']) ? true : false;
502 $flash_status = ($bbcode_status && $auth->acl_get('f_flash', $forum_id) && $config['allow_post_flash']) ? true : false;
503 $quote_status = true;
505 // Save Draft
506 if ($save && $user->data['is_registered'] && $auth->acl_get('u_savedrafts') && ($mode == 'reply' || $mode == 'post' || $mode == 'quote'))
508 $subject = utf8_normalize_nfc(request_var('subject', '', true));
509 $subject = (!$subject && $mode != 'post') ? $post_data['topic_title'] : $subject;
510 $message = utf8_normalize_nfc(request_var('message', '', true));
512 if ($subject && $message)
514 if (confirm_box(true))
516 $sql = 'INSERT INTO ' . DRAFTS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
517 'user_id' => (int) $user->data['user_id'],
518 'topic_id' => (int) $topic_id,
519 'forum_id' => (int) $forum_id,
520 'save_time' => (int) $current_time,
521 'draft_subject' => (string) $subject,
522 'draft_message' => (string) $message)
524 $db->sql_query($sql);
526 $meta_info = ($mode == 'post') ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) : append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id");
528 meta_refresh(3, $meta_info);
530 $message = $user->lang['DRAFT_SAVED'] . '<br /><br />';
531 $message .= ($mode != 'post') ? sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $meta_info . '">', '</a>') . '<br /><br />' : '';
532 $message .= sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
534 trigger_error($message);
536 else
538 $s_hidden_fields = build_hidden_fields(array(
539 'mode' => $mode,
540 'save' => true,
541 'f' => $forum_id,
542 't' => $topic_id,
543 'subject' => $subject,
544 'message' => $message,
545 'attachment_data' => $message_parser->attachment_data,
549 $hidden_fields = array(
550 'icon_id' => 0,
552 'disable_bbcode' => false,
553 'disable_smilies' => false,
554 'disable_magic_url' => false,
555 'attach_sig' => true,
556 'lock_topic' => false,
558 'topic_type' => POST_NORMAL,
559 'topic_time_limit' => 0,
561 'poll_title' => '',
562 'poll_option_text' => '',
563 'poll_max_options' => 1,
564 'poll_length' => 0,
565 'poll_vote_change' => false,
568 foreach ($hidden_fields as $name => $default)
570 if (!isset($_POST[$name]))
572 // Don't include it, if its not available
573 unset($hidden_fields[$name]);
574 continue;
577 if (is_bool($default))
579 // Use the string representation
580 $hidden_fields[$name] = request_var($name, '');
582 else
584 $hidden_fields[$name] = request_var($name, $default);
588 $s_hidden_fields .= build_hidden_fields($hidden_fields);
590 confirm_box(false, 'SAVE_DRAFT', $s_hidden_fields);
593 else
595 if (utf8_clean_string($subject) === '')
597 $error[] = $user->lang['EMPTY_SUBJECT'];
600 if (utf8_clean_string($message) === '')
602 $error[] = $user->lang['TOO_FEW_CHARS'];
605 unset($subject, $message);
608 // Load requested Draft
609 if ($draft_id && ($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $user->data['is_registered'] && $auth->acl_get('u_savedrafts'))
611 $sql = 'SELECT draft_subject, draft_message
612 FROM ' . DRAFTS_TABLE . "
613 WHERE draft_id = $draft_id
614 AND user_id = " . $user->data['user_id'];
615 $result = $db->sql_query_limit($sql, 1);
616 $row = $db->sql_fetchrow($result);
617 $db->sql_freeresult($result);
619 if ($row)
621 $post_data['post_subject'] = $row['draft_subject'];
622 $message_parser->message = $row['draft_message'];
624 $template->assign_var('S_DRAFT_LOADED', true);
626 else
628 $draft_id = 0;
632 // Load draft overview
633 if ($load && ($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $post_data['drafts'])
635 load_drafts($topic_id, $forum_id);
639 if ($submit || $preview || $refresh)
641 $post_data['topic_cur_post_id'] = request_var('topic_cur_post_id', 0);
642 $post_data['post_subject'] = utf8_normalize_nfc(request_var('subject', '', true));
643 $message_parser->message = utf8_normalize_nfc(request_var('message', '', true));
645 $post_data['username'] = utf8_normalize_nfc(request_var('username', $post_data['username'], true));
646 $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)) : '';
648 $post_data['orig_topic_type'] = $post_data['topic_type'];
649 $post_data['topic_type'] = request_var('topic_type', (($mode != 'post') ? (int) $post_data['topic_type'] : POST_NORMAL));
650 $post_data['topic_time_limit'] = request_var('topic_time_limit', (($mode != 'post') ? (int) $post_data['topic_time_limit'] : 0));
652 if ($post_data['enable_icons'] && $auth->acl_get('f_icons', $forum_id))
654 $post_data['icon_id'] = request_var('icon', (int) $post_data['icon_id']);
657 $post_data['enable_bbcode'] = (!$bbcode_status || isset($_POST['disable_bbcode'])) ? false : true;
658 $post_data['enable_smilies'] = (!$smilies_status || isset($_POST['disable_smilies'])) ? false : true;
659 $post_data['enable_urls'] = (isset($_POST['disable_magic_url'])) ? 0 : 1;
660 $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);
662 if ($config['allow_topic_notify'] && $user->data['is_registered'])
664 $notify = (isset($_POST['notify'])) ? true : false;
666 else
668 $notify = false;
671 $topic_lock = (isset($_POST['lock_topic'])) ? true : false;
672 $post_lock = (isset($_POST['lock_post'])) ? true : false;
673 $poll_delete = (isset($_POST['poll_delete'])) ? true : false;
675 if ($submit)
677 $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);
678 $status_switch = ($status_switch != $check_value);
680 else
682 $status_switch = 1;
685 // Delete Poll
686 if ($poll_delete && $mode == 'edit' && sizeof($post_data['poll_options']) &&
687 ((!$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)))
689 if ($submit && check_form_key('posting'))
691 $sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . "
692 WHERE topic_id = $topic_id";
693 $db->sql_query($sql);
695 $sql = 'DELETE FROM ' . POLL_VOTES_TABLE . "
696 WHERE topic_id = $topic_id";
697 $db->sql_query($sql);
699 $topic_sql = array(
700 'poll_title' => '',
701 'poll_start' => 0,
702 'poll_length' => 0,
703 'poll_last_vote' => 0,
704 'poll_max_options' => 0,
705 'poll_vote_change' => 0
708 $sql = 'UPDATE ' . TOPICS_TABLE . '
709 SET ' . $db->sql_build_array('UPDATE', $topic_sql) . "
710 WHERE topic_id = $topic_id";
711 $db->sql_query($sql);
714 $post_data['poll_title'] = $post_data['poll_option_text'] = '';
715 $post_data['poll_vote_change'] = $post_data['poll_max_options'] = $post_data['poll_length'] = 0;
717 else
719 $post_data['poll_title'] = utf8_normalize_nfc(request_var('poll_title', '', true));
720 $post_data['poll_length'] = request_var('poll_length', 0);
721 $post_data['poll_option_text'] = utf8_normalize_nfc(request_var('poll_option_text', '', true));
722 $post_data['poll_max_options'] = request_var('poll_max_options', 1);
723 $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;
726 // If replying/quoting and last post id has changed
727 // give user option to continue submit or return to post
728 // notify and show user the post made between his request and the final submit
729 if (($mode == 'reply' || $mode == 'quote') && $post_data['topic_cur_post_id'] && $post_data['topic_cur_post_id'] != $post_data['topic_last_post_id'])
731 // Only do so if it is allowed forum-wide
732 if ($post_data['forum_flags'] & FORUM_FLAG_POST_REVIEW)
734 if (topic_review($topic_id, $forum_id, 'post_review', $post_data['topic_cur_post_id']))
736 $template->assign_var('S_POST_REVIEW', true);
739 $submit = false;
740 $refresh = true;
744 // Parse Attachments - before checksum is calculated
745 $message_parser->parse_attachments('fileupload', $mode, $forum_id, $submit, $preview, $refresh);
747 // Grab md5 'checksum' of new message
748 $message_md5 = md5($message_parser->message);
750 // If editing and checksum has changed we know the post was edited while we're editing
751 // Notify and show user the changed post
752 if ($mode == 'edit' && $post_data['forum_flags'] & FORUM_FLAG_POST_REVIEW)
754 $edit_post_message_checksum = request_var('edit_post_message_checksum', '');
755 $edit_post_subject_checksum = request_var('edit_post_subject_checksum', '');
757 // $post_data['post_checksum'] is the checksum of the post submitted in the meantime
758 // $message_md5 is the checksum of the post we're about to submit
759 // $edit_post_message_checksum is the checksum of the post we're editing
760 // ...
762 // We make sure nobody else made exactly the same change
763 // we're about to submit by also checking $message_md5 != $post_data['post_checksum']
764 if (($edit_post_message_checksum !== '' && $edit_post_message_checksum != $post_data['post_checksum'] && $message_md5 != $post_data['post_checksum'])
765 || ($edit_post_subject_checksum !== '' && $edit_post_subject_checksum != $post_data['post_subject_md5'] && md5($post_data['post_subject']) != $post_data['post_subject_md5']))
767 if (topic_review($topic_id, $forum_id, 'post_review_edit', $post_id))
769 $template->assign_vars(array(
770 'S_POST_REVIEW' => true,
772 'L_POST_REVIEW' => $user->lang['POST_REVIEW_EDIT'],
773 'L_POST_REVIEW_EXPLAIN' => $user->lang['POST_REVIEW_EDIT_EXPLAIN'],
777 $submit = false;
778 $refresh = true;
782 // Check checksum ... don't re-parse message if the same
783 $update_message = ($mode != 'edit' || $message_md5 != $post_data['post_checksum'] || $status_switch || strlen($post_data['bbcode_uid']) < BBCODE_UID_LEN) ? true : false;
785 // Also check if subject got updated...
786 $update_subject = $mode != 'edit' || ($post_data['post_subject_md5'] && $post_data['post_subject_md5'] != md5($post_data['post_subject']));
788 // Parse message
789 if ($update_message)
791 if (sizeof($message_parser->warn_msg))
793 $error[] = implode('<br />', $message_parser->warn_msg);
794 $message_parser->warn_msg = array();
797 $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']);
799 // On a refresh we do not care about message parsing errors
800 if (sizeof($message_parser->warn_msg) && $refresh)
802 $message_parser->warn_msg = array();
805 else
807 $message_parser->bbcode_bitfield = $post_data['bbcode_bitfield'];
810 if ($mode != 'edit' && !$preview && !$refresh && $config['flood_interval'] && !$auth->acl_get('f_ignoreflood', $forum_id))
812 // Flood check
813 $last_post_time = 0;
815 if ($user->data['is_registered'])
817 $last_post_time = $user->data['user_lastpost_time'];
819 else
821 $sql = 'SELECT post_time AS last_post_time
822 FROM ' . POSTS_TABLE . "
823 WHERE poster_ip = '" . $user->ip . "'
824 AND post_time > " . ($current_time - $config['flood_interval']);
825 $result = $db->sql_query_limit($sql, 1);
826 if ($row = $db->sql_fetchrow($result))
828 $last_post_time = $row['last_post_time'];
830 $db->sql_freeresult($result);
833 if ($last_post_time && ($current_time - $last_post_time) < intval($config['flood_interval']))
835 $error[] = $user->lang['FLOOD_ERROR'];
839 // Validate username
840 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']))
842 include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
844 if (($result = validate_username($post_data['username'], (!empty($post_data['post_username'])) ? $post_data['post_username'] : '')) !== false)
846 $user->add_lang('ucp');
847 $error[] = $user->lang[$result . '_USERNAME'];
851 if ($config['enable_post_confirm'] && !$user->data['is_registered'] && in_array($mode, array('quote', 'post', 'reply')))
853 $captcha_data = array(
854 'message' => utf8_normalize_nfc(request_var('message', '', true)),
855 'subject' => utf8_normalize_nfc(request_var('subject', '', true)),
856 'username' => utf8_normalize_nfc(request_var('username', '', true)),
858 $vc_response = $captcha->validate($captcha_data);
859 if ($vc_response)
861 $error[] = $vc_response;
865 // check form
866 if (($submit || $preview) && !check_form_key('posting'))
868 $error[] = $user->lang['FORM_INVALID'];
871 // Parse subject
872 if (!$preview && !$refresh && utf8_clean_string($post_data['post_subject']) === '' && ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_id)))
874 $error[] = $user->lang['EMPTY_SUBJECT'];
877 $post_data['poll_last_vote'] = (isset($post_data['poll_last_vote'])) ? $post_data['poll_last_vote'] : 0;
879 if ($post_data['poll_option_text'] &&
880 ($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id']/* && (!$post_data['poll_last_vote'] || $auth->acl_get('m_edit', $forum_id))*/))
881 && $auth->acl_get('f_poll', $forum_id))
883 $poll = array(
884 'poll_title' => $post_data['poll_title'],
885 'poll_length' => $post_data['poll_length'],
886 'poll_max_options' => $post_data['poll_max_options'],
887 'poll_option_text' => $post_data['poll_option_text'],
888 'poll_start' => $post_data['poll_start'],
889 'poll_last_vote' => $post_data['poll_last_vote'],
890 'poll_vote_change' => $post_data['poll_vote_change'],
891 'enable_bbcode' => $post_data['enable_bbcode'],
892 'enable_urls' => $post_data['enable_urls'],
893 'enable_smilies' => $post_data['enable_smilies'],
894 'img_status' => $img_status
897 $message_parser->parse_poll($poll);
899 $post_data['poll_options'] = (isset($poll['poll_options'])) ? $poll['poll_options'] : '';
900 $post_data['poll_title'] = (isset($poll['poll_title'])) ? $poll['poll_title'] : '';
902 /* We reset votes, therefore also allow removing options
903 if ($post_data['poll_last_vote'] && ($poll['poll_options_size'] < $orig_poll_options_size))
905 $message_parser->warn_msg[] = $user->lang['NO_DELETE_POLL_OPTIONS'];
908 else
910 $poll = array();
913 // Check topic type
914 if ($post_data['topic_type'] != POST_NORMAL && ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_id)))
916 switch ($post_data['topic_type'])
918 case POST_GLOBAL:
919 case POST_ANNOUNCE:
920 $auth_option = 'f_announce';
921 break;
923 case POST_STICKY:
924 $auth_option = 'f_sticky';
925 break;
927 default:
928 $auth_option = '';
929 break;
932 if (!$auth->acl_get($auth_option, $forum_id))
934 // There is a special case where a user edits his post whereby the topic type got changed by an admin/mod.
935 // Another case would be a mod not having sticky permissions for example but edit permissions.
936 if ($mode == 'edit')
938 // To prevent non-authed users messing around with the topic type we reset it to the original one.
939 $post_data['topic_type'] = $post_data['orig_topic_type'];
941 else
943 $error[] = $user->lang['CANNOT_POST_' . str_replace('F_', '', strtoupper($auth_option))];
948 if (sizeof($message_parser->warn_msg))
950 $error[] = implode('<br />', $message_parser->warn_msg);
953 // DNSBL check
954 if ($config['check_dnsbl'] && !$refresh)
956 if (($dnsbl = $user->check_dnsbl('post')) !== false)
958 $error[] = sprintf($user->lang['IP_BLACKLISTED'], $user->ip, $dnsbl[1]);
962 // Store message, sync counters
963 if (!sizeof($error) && $submit)
965 // Check if we want to de-globalize the topic... and ask for new forum
966 if ($post_data['topic_type'] != POST_GLOBAL)
968 $sql = 'SELECT topic_type, forum_id
969 FROM ' . TOPICS_TABLE . "
970 WHERE topic_id = $topic_id";
971 $result = $db->sql_query($sql);
972 $row = $db->sql_fetchrow($result);
973 $db->sql_freeresult($result);
975 if ($row && !$row['forum_id'] && $row['topic_type'] == POST_GLOBAL)
977 $to_forum_id = request_var('to_forum_id', 0);
979 if ($to_forum_id)
981 $sql = 'SELECT forum_type
982 FROM ' . FORUMS_TABLE . '
983 WHERE forum_id = ' . $to_forum_id;
984 $result = $db->sql_query($sql);
985 $forum_type = (int) $db->sql_fetchfield('forum_type');
986 $db->sql_freeresult($result);
988 if ($forum_type != FORUM_POST || !$auth->acl_get('f_post', $to_forum_id))
990 $to_forum_id = 0;
994 if (!$to_forum_id)
996 include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
998 $template->assign_vars(array(
999 'S_FORUM_SELECT' => make_forum_select(false, false, false, true, true, true),
1000 'S_UNGLOBALISE' => true)
1003 $submit = false;
1004 $refresh = true;
1006 else
1008 if (!$auth->acl_get('f_post', $to_forum_id))
1010 // This will only be triggered if the user tried to trick the forum.
1011 trigger_error('NOT_AUTHORISED');
1014 $forum_id = $to_forum_id;
1019 if ($submit)
1021 // Lock/Unlock Topic
1022 $change_topic_status = $post_data['topic_status'];
1023 $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;
1025 if ($post_data['topic_status'] == ITEM_LOCKED && !$topic_lock && $perm_lock_unlock)
1027 $change_topic_status = ITEM_UNLOCKED;
1029 else if ($post_data['topic_status'] == ITEM_UNLOCKED && $topic_lock && $perm_lock_unlock)
1031 $change_topic_status = ITEM_LOCKED;
1034 if ($change_topic_status != $post_data['topic_status'])
1036 $sql = 'UPDATE ' . TOPICS_TABLE . "
1037 SET topic_status = $change_topic_status
1038 WHERE topic_id = $topic_id
1039 AND topic_moved_id = 0";
1040 $db->sql_query($sql);
1042 $user_lock = ($auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && $user->data['user_id'] == $post_data['topic_poster']) ? 'USER_' : '';
1044 add_log('mod', $forum_id, $topic_id, 'LOG_' . $user_lock . (($change_topic_status == ITEM_LOCKED) ? 'LOCK' : 'UNLOCK'), $post_data['topic_title']);
1047 // Lock/Unlock Post Edit
1048 if ($mode == 'edit' && $post_data['post_edit_locked'] == ITEM_LOCKED && !$post_lock && $auth->acl_get('m_edit', $forum_id))
1050 $post_data['post_edit_locked'] = ITEM_UNLOCKED;
1052 else if ($mode == 'edit' && $post_data['post_edit_locked'] == ITEM_UNLOCKED && $post_lock && $auth->acl_get('m_edit', $forum_id))
1054 $post_data['post_edit_locked'] = ITEM_LOCKED;
1057 $data = array(
1058 'topic_title' => (empty($post_data['topic_title'])) ? $post_data['post_subject'] : $post_data['topic_title'],
1059 'topic_first_post_id' => (isset($post_data['topic_first_post_id'])) ? (int) $post_data['topic_first_post_id'] : 0,
1060 'topic_last_post_id' => (isset($post_data['topic_last_post_id'])) ? (int) $post_data['topic_last_post_id'] : 0,
1061 'topic_time_limit' => (int) $post_data['topic_time_limit'],
1062 'topic_attachment' => (isset($post_data['topic_attachment'])) ? (int) $post_data['topic_attachment'] : 0,
1063 'post_id' => (int) $post_id,
1064 'topic_id' => (int) $topic_id,
1065 'forum_id' => (int) $forum_id,
1066 'icon_id' => (int) $post_data['icon_id'],
1067 'poster_id' => (int) $post_data['poster_id'],
1068 'enable_sig' => (bool) $post_data['enable_sig'],
1069 'enable_bbcode' => (bool) $post_data['enable_bbcode'],
1070 'enable_smilies' => (bool) $post_data['enable_smilies'],
1071 'enable_urls' => (bool) $post_data['enable_urls'],
1072 'enable_indexing' => (bool) $post_data['enable_indexing'],
1073 'message_md5' => (string) $message_md5,
1074 'post_time' => (isset($post_data['post_time'])) ? (int) $post_data['post_time'] : $current_time,
1075 'post_checksum' => (isset($post_data['post_checksum'])) ? (string) $post_data['post_checksum'] : '',
1076 'post_edit_reason' => $post_data['post_edit_reason'],
1077 'post_edit_user' => ($mode == 'edit') ? $user->data['user_id'] : ((isset($post_data['post_edit_user'])) ? (int) $post_data['post_edit_user'] : 0),
1078 'forum_parents' => $post_data['forum_parents'],
1079 'forum_name' => $post_data['forum_name'],
1080 'notify' => $notify,
1081 'notify_set' => $post_data['notify_set'],
1082 'poster_ip' => (isset($post_data['poster_ip'])) ? $post_data['poster_ip'] : $user->ip,
1083 'post_edit_locked' => (int) $post_data['post_edit_locked'],
1084 'bbcode_bitfield' => $message_parser->bbcode_bitfield,
1085 'bbcode_uid' => $message_parser->bbcode_uid,
1086 'message' => $message_parser->message,
1087 'attachment_data' => $message_parser->attachment_data,
1088 'filename_data' => $message_parser->filename_data,
1090 'topic_approved' => (isset($post_data['topic_approved'])) ? $post_data['topic_approved'] : false,
1091 'post_approved' => (isset($post_data['post_approved'])) ? $post_data['post_approved'] : false,
1094 if ($mode == 'edit')
1096 $data['topic_replies_real'] = $post_data['topic_replies_real'];
1097 $data['topic_replies'] = $post_data['topic_replies'];
1100 // The last parameter tells submit_post if search indexer has to be run
1101 $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);
1103 if ($config['enable_post_confirm'] && !$user->data['is_registered'] && (isset($captcha) && $captcha->is_solved() === true) && ($mode == 'post' || $mode == 'reply' || $mode == 'quote'))
1105 $captcha->reset();
1108 // Check the permissions for post approval. Moderators are not affected.
1109 if ((!$auth->acl_get('f_noapprove', $data['forum_id']) && !$auth->acl_get('m_approve', $data['forum_id'])) || !empty($post_data['force_approved_state']))
1111 meta_refresh(10, $redirect_url);
1112 $message = ($mode == 'edit') ? $user->lang['POST_EDITED_MOD'] : $user->lang['POST_STORED_MOD'];
1113 $message .= (($user->data['user_id'] == ANONYMOUS) ? '' : ' '. $user->lang['POST_APPROVAL_NOTIFY']);
1115 else
1117 meta_refresh(3, $redirect_url);
1119 $message = ($mode == 'edit') ? 'POST_EDITED' : 'POST_STORED';
1120 $message = $user->lang[$message] . '<br /><br />' . sprintf($user->lang['VIEW_MESSAGE'], '<a href="' . $redirect_url . '">', '</a>');
1123 $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $data['forum_id']) . '">', '</a>');
1124 trigger_error($message);
1129 // Preview
1130 if (!sizeof($error) && $preview)
1132 $post_data['post_time'] = ($mode == 'edit') ? $post_data['post_time'] : $current_time;
1134 $preview_message = $message_parser->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies'], false);
1136 $preview_signature = ($mode == 'edit') ? $post_data['user_sig'] : $user->data['user_sig'];
1137 $preview_signature_uid = ($mode == 'edit') ? $post_data['user_sig_bbcode_uid'] : $user->data['user_sig_bbcode_uid'];
1138 $preview_signature_bitfield = ($mode == 'edit') ? $post_data['user_sig_bbcode_bitfield'] : $user->data['user_sig_bbcode_bitfield'];
1140 // Signature
1141 if ($post_data['enable_sig'] && $config['allow_sig'] && $preview_signature && $auth->acl_get('f_sigs', $forum_id))
1143 $parse_sig = new parse_message($preview_signature);
1144 $parse_sig->bbcode_uid = $preview_signature_uid;
1145 $parse_sig->bbcode_bitfield = $preview_signature_bitfield;
1147 // Not sure about parameters for bbcode/smilies/urls... in signatures
1148 $parse_sig->format_display($config['allow_sig_bbcode'], true, $config['allow_sig_smilies']);
1149 $preview_signature = $parse_sig->message;
1150 unset($parse_sig);
1152 else
1154 $preview_signature = '';
1157 $preview_subject = censor_text($post_data['post_subject']);
1159 // Poll Preview
1160 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))*/))
1161 && $auth->acl_get('f_poll', $forum_id))
1163 $parse_poll = new parse_message($post_data['poll_title']);
1164 $parse_poll->bbcode_uid = $message_parser->bbcode_uid;
1165 $parse_poll->bbcode_bitfield = $message_parser->bbcode_bitfield;
1167 $parse_poll->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies']);
1169 if ($post_data['poll_length'])
1171 $poll_end = ($post_data['poll_length'] * 86400) + (($post_data['poll_start']) ? $post_data['poll_start'] : time());
1174 $template->assign_vars(array(
1175 'S_HAS_POLL_OPTIONS' => (sizeof($post_data['poll_options'])),
1176 'S_IS_MULTI_CHOICE' => ($post_data['poll_max_options'] > 1) ? true : false,
1178 'POLL_QUESTION' => $parse_poll->message,
1180 'L_POLL_LENGTH' => ($post_data['poll_length']) ? sprintf($user->lang['POLL_RUN_TILL'], $user->format_date($poll_end)) : '',
1181 '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']))
1184 $parse_poll->message = implode("\n", $post_data['poll_options']);
1185 $parse_poll->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies']);
1186 $preview_poll_options = explode('<br />', $parse_poll->message);
1187 unset($parse_poll);
1189 foreach ($preview_poll_options as $key => $option)
1191 $template->assign_block_vars('poll_option', array(
1192 'POLL_OPTION_CAPTION' => $option,
1193 'POLL_OPTION_ID' => $key + 1)
1196 unset($preview_poll_options);
1199 // Attachment Preview
1200 if (sizeof($message_parser->attachment_data))
1202 $template->assign_var('S_HAS_ATTACHMENTS', true);
1204 $update_count = array();
1205 $attachment_data = $message_parser->attachment_data;
1207 parse_attachments($forum_id, $preview_message, $attachment_data, $update_count, true);
1209 foreach ($attachment_data as $i => $attachment)
1211 $template->assign_block_vars('attachment', array(
1212 'DISPLAY_ATTACHMENT' => $attachment)
1215 unset($attachment_data);
1218 if (!sizeof($error))
1220 $template->assign_vars(array(
1221 'PREVIEW_SUBJECT' => $preview_subject,
1222 'PREVIEW_MESSAGE' => $preview_message,
1223 'PREVIEW_SIGNATURE' => $preview_signature,
1225 'S_DISPLAY_PREVIEW' => true)
1230 // Decode text for message display
1231 $post_data['bbcode_uid'] = ($mode == 'quote' && !$preview && !$refresh && !sizeof($error)) ? $post_data['bbcode_uid'] : $message_parser->bbcode_uid;
1232 $message_parser->decode_message($post_data['bbcode_uid']);
1234 if ($mode == 'quote' && !$submit && !$preview && !$refresh)
1236 if ($config['allow_bbcode'])
1238 $message_parser->message = '[quote=&quot;' . $post_data['quote_username'] . '&quot;]' . censor_text(trim($message_parser->message)) . "[/quote]\n";
1240 else
1242 $offset = 0;
1243 $quote_string = "&gt; ";
1244 $message = censor_text(trim($message_parser->message));
1245 // see if we are nesting. It's easily tricked but should work for one level of nesting
1246 if (strpos($message, "&gt;") !== false)
1248 $offset = 10;
1250 $message = utf8_wordwrap($message, 75 + $offset, "\n");
1252 $message = $quote_string . $message;
1253 $message = str_replace("\n", "\n" . $quote_string, $message);
1254 $message_parser->message = $post_data['quote_username'] . " " . $user->lang['WROTE'] . " :\n" . $message . "\n";
1258 if (($mode == 'reply' || $mode == 'quote') && !$submit && !$preview && !$refresh)
1260 $post_data['post_subject'] = ((strpos($post_data['post_subject'], 'Re: ') !== 0) ? 'Re: ' : '') . censor_text($post_data['post_subject']);
1263 $attachment_data = $message_parser->attachment_data;
1264 $filename_data = $message_parser->filename_data;
1265 $post_data['post_text'] = $message_parser->message;
1267 if (sizeof($post_data['poll_options']) && $post_data['poll_title'])
1269 $message_parser->message = $post_data['poll_title'];
1270 $message_parser->bbcode_uid = $post_data['bbcode_uid'];
1272 $message_parser->decode_message();
1273 $post_data['poll_title'] = $message_parser->message;
1275 $message_parser->message = implode("\n", $post_data['poll_options']);
1276 $message_parser->decode_message();
1277 $post_data['poll_options'] = explode("\n", $message_parser->message);
1280 // MAIN POSTING PAGE BEGINS HERE
1282 // Forum moderators?
1283 $moderators = array();
1284 if ($config['load_moderators'])
1286 get_moderators($moderators, $forum_id);
1289 // Generate smiley listing
1290 generate_smilies('inline', $forum_id);
1292 // Generate inline attachment select box
1293 posting_gen_inline_attachments($attachment_data);
1295 // Do show topic type selection only in first post.
1296 $topic_type_toggle = false;
1298 if ($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id']))
1300 $topic_type_toggle = posting_gen_topic_types($forum_id, $post_data['topic_type']);
1303 $s_topic_icons = false;
1304 if ($post_data['enable_icons'] && $auth->acl_get('f_icons', $forum_id))
1306 $s_topic_icons = posting_gen_topic_icons($mode, $post_data['icon_id']);
1309 $bbcode_checked = (isset($post_data['enable_bbcode'])) ? !$post_data['enable_bbcode'] : (($config['allow_bbcode']) ? !$user->optionget('bbcode') : 1);
1310 $smilies_checked = (isset($post_data['enable_smilies'])) ? !$post_data['enable_smilies'] : (($config['allow_smilies']) ? !$user->optionget('smilies') : 1);
1311 $urls_checked = (isset($post_data['enable_urls'])) ? !$post_data['enable_urls'] : 0;
1312 $sig_checked = $post_data['enable_sig'];
1313 $lock_topic_checked = (isset($topic_lock) && $topic_lock) ? $topic_lock : (($post_data['topic_status'] == ITEM_LOCKED) ? 1 : 0);
1314 $lock_post_checked = (isset($post_lock)) ? $post_lock : $post_data['post_edit_locked'];
1316 // 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
1317 $notify_set = ($mode != 'edit' && $config['allow_topic_notify'] && $user->data['is_registered'] && !$post_data['notify_set']) ? $user->data['user_notify'] : $post_data['notify_set'];
1318 $notify_checked = (isset($notify)) ? $notify : (($mode == 'post') ? $user->data['user_notify'] : $notify_set);
1320 // Page title & action URL, include session_id for security purpose
1321 $s_action = append_sid("{$phpbb_root_path}posting.$phpEx", "mode=$mode&amp;f=$forum_id", true, $user->session_id);
1322 $s_action .= ($topic_id) ? "&amp;t=$topic_id" : '';
1323 $s_action .= ($post_id) ? "&amp;p=$post_id" : '';
1325 switch ($mode)
1327 case 'post':
1328 $page_title = $user->lang['POST_TOPIC'];
1329 break;
1331 case 'quote':
1332 case 'reply':
1333 $page_title = $user->lang['POST_REPLY'];
1334 break;
1336 case 'delete':
1337 case 'edit':
1338 $page_title = $user->lang['EDIT_POST'];
1339 break;
1342 // Build Navigation Links
1343 generate_forum_nav($post_data);
1345 // Build Forum Rules
1346 generate_forum_rules($post_data);
1348 // Posting uses is_solved for legacy reasons. Plugins have to use is_solved to force themselves to be displayed.
1349 if ($config['enable_post_confirm'] && !$user->data['is_registered'] && (isset($captcha) && $captcha->is_solved() === false) && ($mode == 'post' || $mode == 'reply' || $mode == 'quote'))
1352 $template->assign_vars(array(
1353 'S_CONFIRM_CODE' => true,
1354 'CAPTCHA_TEMPLATE' => $captcha->get_template(),
1358 $s_hidden_fields = ($mode == 'reply' || $mode == 'quote') ? '<input type="hidden" name="topic_cur_post_id" value="' . $post_data['topic_last_post_id'] . '" />' : '';
1359 $s_hidden_fields .= '<input type="hidden" name="lastclick" value="' . $current_time . '" />';
1360 $s_hidden_fields .= ($draft_id || isset($_REQUEST['draft_loaded'])) ? '<input type="hidden" name="draft_loaded" value="' . request_var('draft_loaded', $draft_id) . '" />' : '';
1362 if ($mode == 'edit')
1364 $s_hidden_fields .= build_hidden_fields(array(
1365 'edit_post_message_checksum' => $post_data['post_checksum'],
1366 'edit_post_subject_checksum' => $post_data['post_subject_md5'],
1370 // Add the confirm id/code pair to the hidden fields, else an error is displayed on next submit/preview
1371 if (isset($captcha) && $captcha->is_solved() !== false)
1373 $s_hidden_fields .= build_hidden_fields($captcha->get_hidden_fields());
1376 $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"';
1377 add_form_key('posting');
1380 // Start assigning vars for main posting page ...
1381 $template->assign_vars(array(
1382 'L_POST_A' => $page_title,
1383 'L_ICON' => ($mode == 'reply' || $mode == 'quote' || ($mode == 'edit' && $post_id != $post_data['topic_first_post_id'])) ? $user->lang['POST_ICON'] : $user->lang['TOPIC_ICON'],
1384 'L_MESSAGE_BODY_EXPLAIN' => (intval($config['max_post_chars'])) ? sprintf($user->lang['MESSAGE_BODY_EXPLAIN'], intval($config['max_post_chars'])) : '',
1386 'FORUM_NAME' => $post_data['forum_name'],
1387 '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']) : '',
1388 'TOPIC_TITLE' => censor_text($post_data['topic_title']),
1389 'MODERATORS' => (sizeof($moderators)) ? implode(', ', $moderators[$forum_id]) : '',
1390 'USERNAME' => ((!$preview && $mode != 'quote') || $preview) ? $post_data['username'] : '',
1391 'SUBJECT' => $post_data['post_subject'],
1392 'MESSAGE' => $post_data['post_text'],
1393 '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>'),
1394 'IMG_STATUS' => ($img_status) ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'],
1395 'FLASH_STATUS' => ($flash_status) ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'],
1396 'SMILIES_STATUS' => ($smilies_status) ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'],
1397 'URL_STATUS' => ($bbcode_status && $url_status) ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'],
1398 'MAX_FONT_SIZE' => (int) $config['max_post_font_size'],
1399 'MINI_POST_IMG' => $user->img('icon_post_target', $user->lang['POST']),
1400 'POST_DATE' => ($post_data['post_time']) ? $user->format_date($post_data['post_time']) : '',
1401 'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '',
1402 'TOPIC_TIME_LIMIT' => (int) $post_data['topic_time_limit'],
1403 'EDIT_REASON' => $post_data['post_edit_reason'],
1404 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id"),
1405 'U_VIEW_TOPIC' => ($mode != 'post') ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id") : '',
1406 'U_PROGRESS_BAR' => append_sid("{$phpbb_root_path}posting.$phpEx", "f=$forum_id&amp;mode=popup"),
1407 'UA_PROGRESS_BAR' => addslashes(append_sid("{$phpbb_root_path}posting.$phpEx", "f=$forum_id&amp;mode=popup")),
1409 'S_PRIVMSGS' => false,
1410 'S_CLOSE_PROGRESS_WINDOW' => (isset($_POST['add_file'])) ? true : false,
1411 'S_EDIT_POST' => ($mode == 'edit') ? true : false,
1412 'S_EDIT_REASON' => ($mode == 'edit' && $auth->acl_get('m_edit', $forum_id)) ? true : false,
1413 'S_DISPLAY_USERNAME' => (!$user->data['is_registered'] || ($mode == 'edit' && $post_data['poster_id'] == ANONYMOUS)) ? true : false,
1414 'S_SHOW_TOPIC_ICONS' => $s_topic_icons,
1415 '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,
1416 'S_BBCODE_ALLOWED' => $bbcode_status,
1417 'S_BBCODE_CHECKED' => ($bbcode_checked) ? ' checked="checked"' : '',
1418 'S_SMILIES_ALLOWED' => $smilies_status,
1419 'S_SMILIES_CHECKED' => ($smilies_checked) ? ' checked="checked"' : '',
1420 'S_SIG_ALLOWED' => ($auth->acl_get('f_sigs', $forum_id) && $config['allow_sig'] && $user->data['is_registered']) ? true : false,
1421 'S_SIGNATURE_CHECKED' => ($sig_checked) ? ' checked="checked"' : '',
1422 '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,
1423 'S_NOTIFY_CHECKED' => ($notify_checked) ? ' checked="checked"' : '',
1424 '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,
1425 'S_LOCK_TOPIC_CHECKED' => ($lock_topic_checked) ? ' checked="checked"' : '',
1426 'S_LOCK_POST_ALLOWED' => ($mode == 'edit' && $auth->acl_get('m_edit', $forum_id)) ? true : false,
1427 'S_LOCK_POST_CHECKED' => ($lock_post_checked) ? ' checked="checked"' : '',
1428 'S_LINKS_ALLOWED' => $url_status,
1429 'S_MAGIC_URL_CHECKED' => ($urls_checked) ? ' checked="checked"' : '',
1430 'S_TYPE_TOGGLE' => $topic_type_toggle,
1431 'S_SAVE_ALLOWED' => ($auth->acl_get('u_savedrafts') && $user->data['is_registered'] && $mode != 'edit') ? true : false,
1432 'S_HAS_DRAFTS' => ($auth->acl_get('u_savedrafts') && $user->data['is_registered'] && $post_data['drafts']) ? true : false,
1433 'S_FORM_ENCTYPE' => $form_enctype,
1435 'S_BBCODE_IMG' => $img_status,
1436 'S_BBCODE_URL' => $url_status,
1437 'S_BBCODE_FLASH' => $flash_status,
1438 'S_BBCODE_QUOTE' => $quote_status,
1440 'S_POST_ACTION' => $s_action,
1441 'S_HIDDEN_FIELDS' => $s_hidden_fields)
1444 // Build custom bbcodes array
1445 display_custom_bbcodes();
1447 // Poll entry
1448 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))*/))
1449 && $auth->acl_get('f_poll', $forum_id))
1451 $template->assign_vars(array(
1452 'S_SHOW_POLL_BOX' => true,
1453 'S_POLL_VOTE_CHANGE' => ($auth->acl_get('f_votechg', $forum_id) && $auth->acl_get('f_vote', $forum_id)),
1454 '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))),
1455 'S_POLL_DELETE_CHECKED' => (!empty($poll_delete)) ? true : false,
1457 'L_POLL_OPTIONS_EXPLAIN' => sprintf($user->lang['POLL_OPTIONS_' . (($mode == 'edit') ? 'EDIT_' : '') . 'EXPLAIN'], $config['max_poll_options']),
1459 'VOTE_CHANGE_CHECKED' => (!empty($post_data['poll_vote_change'])) ? ' checked="checked"' : '',
1460 'POLL_TITLE' => (isset($post_data['poll_title'])) ? $post_data['poll_title'] : '',
1461 'POLL_OPTIONS' => (!empty($post_data['poll_options'])) ? implode("\n", $post_data['poll_options']) : '',
1462 'POLL_MAX_OPTIONS' => (isset($post_data['poll_max_options'])) ? (int) $post_data['poll_max_options'] : 1,
1463 'POLL_LENGTH' => $post_data['poll_length'])
1467 // Show attachment box for adding attachments if true
1468 $allowed = ($auth->acl_get('f_attach', $forum_id) && $auth->acl_get('u_attach') && $config['allow_attachments'] && $form_enctype);
1470 // Attachment entry
1471 posting_gen_attachment_entry($attachment_data, $filename_data, $allowed);
1473 // Output page ...
1474 page_header($page_title, false);
1476 $template->set_filenames(array(
1477 'body' => 'posting_body.html')
1480 make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
1482 // Topic review
1483 if ($mode == 'reply' || $mode == 'quote')
1485 if (topic_review($topic_id, $forum_id))
1487 $template->assign_var('S_DISPLAY_REVIEW', true);
1491 page_footer();
1494 * Show upload popup (progress bar)
1496 function upload_popup($forum_style = 0)
1498 global $template, $user;
1500 ($forum_style) ? $user->setup('posting', $forum_style) : $user->setup('posting');
1502 page_header($user->lang['PROGRESS_BAR'], false);
1504 $template->set_filenames(array(
1505 'popup' => 'posting_progress_bar.html')
1508 $template->assign_vars(array(
1509 'PROGRESS_BAR' => $user->img('upload_bar', $user->lang['UPLOAD_IN_PROGRESS']))
1512 $template->display('popup');
1514 garbage_collection();
1515 exit_handler();
1519 * Do the various checks required for removing posts as well as removing it
1521 function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data)
1523 global $user, $db, $auth, $config;
1524 global $phpbb_root_path, $phpEx;
1526 // If moderator removing post or user itself removing post, present a confirmation screen
1527 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'])))
1529 $s_hidden_fields = build_hidden_fields(array(
1530 'p' => $post_id,
1531 'f' => $forum_id,
1532 'mode' => 'delete')
1535 if (confirm_box(true))
1537 $data = array(
1538 'topic_first_post_id' => $post_data['topic_first_post_id'],
1539 'topic_last_post_id' => $post_data['topic_last_post_id'],
1540 'topic_replies_real' => $post_data['topic_replies_real'],
1541 'topic_approved' => $post_data['topic_approved'],
1542 'topic_type' => $post_data['topic_type'],
1543 'post_approved' => $post_data['post_approved'],
1544 'post_reported' => $post_data['post_reported'],
1545 'post_time' => $post_data['post_time'],
1546 'poster_id' => $post_data['poster_id'],
1547 'post_postcount' => $post_data['post_postcount']
1550 $next_post_id = delete_post($forum_id, $topic_id, $post_id, $data);
1551 $post_username = ($post_data['poster_id'] == ANONYMOUS && !empty($post_data['post_username'])) ? $post_data['post_username'] : $post_data['username'];
1553 if ($next_post_id === false)
1555 add_log('mod', $forum_id, $topic_id, 'LOG_DELETE_TOPIC', $post_data['topic_title'], $post_username);
1557 $meta_info = append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id");
1558 $message = $user->lang['POST_DELETED'];
1560 else
1562 add_log('mod', $forum_id, $topic_id, 'LOG_DELETE_POST', $post_data['post_subject'], $post_username);
1564 $meta_info = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;p=$next_post_id") . "#p$next_post_id";
1565 $message = $user->lang['POST_DELETED'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $meta_info . '">', '</a>');
1568 meta_refresh(3, $meta_info);
1569 $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
1570 trigger_error($message);
1572 else
1574 confirm_box(false, 'DELETE_POST', $s_hidden_fields);
1578 // If we are here the user is not able to delete - present the correct error message
1579 if ($post_data['poster_id'] != $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id))
1581 trigger_error('DELETE_OWN_POSTS');
1584 if ($post_data['poster_id'] == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id) && $post_id != $post_data['topic_last_post_id'])
1586 trigger_error('CANNOT_DELETE_REPLIED');
1589 trigger_error('USER_CANNOT_DELETE');