- do not allow setting the parent to currently assigned childs [Bug #6708]
[phpbb.git] / phpBB / posting.php
blob1afd964b3882eed12b1dbe3f43fd3374df27a124
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 = './';
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['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 // Was cancel pressed? If so then redirect to the appropriate page
49 if ($cancel || ($current_time - $lastclick < 2 && $submit))
51 $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")));
52 redirect($redirect);
55 if (in_array($mode, array('post', 'reply', 'quote', 'edit', 'delete')) && !$forum_id)
57 trigger_error('NO_FORUM');
60 // We need to know some basic information in all cases before we do anything.
61 switch ($mode)
63 case 'post':
64 $sql = 'SELECT *
65 FROM ' . FORUMS_TABLE . "
66 WHERE forum_id = $forum_id";
67 break;
69 case 'bump':
70 case 'reply':
71 if (!$topic_id)
73 trigger_error('NO_TOPIC');
76 $sql = 'SELECT f.*, t.*
77 FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f
78 WHERE t.topic_id = $topic_id
79 AND (f.forum_id = t.forum_id
80 OR f.forum_id = $forum_id)";
81 break;
83 case 'quote':
84 case 'edit':
85 case 'delete':
86 if (!$post_id)
88 trigger_error('NO_POST');
91 $sql = 'SELECT f.*, t.*, p.*, u.username, u.username_clean, u.user_sig, u.user_sig_bbcode_uid, u.user_sig_bbcode_bitfield
92 FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . ' f, ' . USERS_TABLE . " u
93 WHERE p.post_id = $post_id
94 AND t.topic_id = p.topic_id
95 AND u.user_id = p.poster_id
96 AND (f.forum_id = t.forum_id
97 OR f.forum_id = $forum_id)";
98 break;
100 case 'smilies':
101 $sql = '';
102 generate_smilies('window', $forum_id);
103 break;
105 case 'popup':
106 if ($forum_id)
108 $sql = 'SELECT forum_style
109 FROM ' . FORUMS_TABLE . '
110 WHERE forum_id = ' . $forum_id;
112 else
114 upload_popup();
115 exit;
117 break;
119 default:
120 $sql = '';
121 break;
124 if (!$sql)
126 $user->setup(array('posting', 'mcp', 'viewtopic'));
127 trigger_error('NO_POST_MODE');
130 $result = $db->sql_query($sql);
131 $post_data = $db->sql_fetchrow($result);
132 $db->sql_freeresult($result);
134 if (!$post_data)
136 trigger_error(($mode == 'post' || $mode == 'bump' || $mode == 'reply') ? 'NO_TOPIC' : 'NO_POST');
139 if ($mode == 'popup')
141 upload_popup($post_data['forum_style']);
142 exit;
145 $user->setup(array('posting', 'mcp', 'viewtopic'), $post_data['forum_style']);
147 // Use post_row values in favor of submitted ones...
148 $forum_id = (!empty($post_data['forum_id'])) ? (int) $post_data['forum_id'] : (int) $forum_id;
149 $topic_id = (!empty($post_data['topic_id'])) ? (int) $post_data['topic_id'] : (int) $topic_id;
150 $post_id = (!empty($post_data['post_id'])) ? (int) $post_data['post_id'] : (int) $post_id;
152 // Need to login to passworded forum first?
153 if ($post_data['forum_password'])
155 login_forum_box(array(
156 'forum_id' => $forum_id,
157 'forum_password' => $post_data['forum_password'])
161 // Check permissions
163 // Is the user able to read within this forum?
164 if (!$auth->acl_get('f_read', $forum_id))
166 if ($user->data['user_id'] != ANONYMOUS)
168 trigger_error('USER_CANNOT_READ');
171 login_box('', $user->lang['LOGIN_EXPLAIN_POST']);
174 // Permission to do the action asked?
175 $is_authed = false;
177 switch ($mode)
179 case 'post':
180 if ($auth->acl_get('f_post', $forum_id))
182 $is_authed = true;
184 break;
186 case 'bump':
187 if ($auth->acl_get('f_bump', $forum_id))
189 $is_authed = true;
191 break;
193 case 'quote':
194 case 'reply':
195 if ($auth->acl_get('f_reply', $forum_id))
197 $is_authed = true;
199 break;
201 case 'edit':
202 if ($user->data['is_registered'] && $auth->acl_gets('f_edit', 'm_edit', $forum_id))
204 $is_authed = true;
206 break;
208 case 'delete':
209 if ($user->data['is_registered'] && $auth->acl_gets('f_delete', 'm_delete', $forum_id))
211 $is_authed = true;
213 break;
216 if (!$is_authed)
218 $check_auth = ($mode == 'quote') ? 'reply' : $mode;
220 if ($user->data['is_registered'])
222 trigger_error('USER_CANNOT_' . strtoupper($check_auth));
225 login_box('', $user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)]);
228 // Is the user able to post within this forum?
229 if ($post_data['forum_type'] != FORUM_POST && in_array($mode, array('post', 'bump', 'quote', 'reply')))
231 trigger_error('USER_CANNOT_FORUM_POST');
234 // Forum/Topic locked?
235 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))
237 trigger_error(($post_data['forum_status'] == ITEM_LOCKED) ? 'FORUM_LOCKED' : 'TOPIC_LOCKED');
240 // Can we edit this post ... if we're a moderator with rights then always yes
241 // else it depends on editing times, lock status and if we're the correct user
242 if ($mode == 'edit' && !$auth->acl_get('m_edit', $forum_id))
244 if ($user->data['user_id'] != $post_data['poster_id'])
246 trigger_error('USER_CANNOT_EDIT');
249 if (!($post_data['post_time'] > time() - ($config['edit_time'] * 60) || !$config['edit_time']))
251 trigger_error('CANNOT_EDIT_TIME');
254 if ($post_data['post_edit_locked'])
256 trigger_error('CANNOT_EDIT_POST_LOCKED');
260 // Handle delete mode...
261 if ($mode == 'delete')
263 handle_post_delete($forum_id, $topic_id, $post_id, $post_data);
264 exit;
267 // Handle bump mode...
268 if ($mode == 'bump')
270 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']))
272 $db->sql_transaction('begin');
274 $sql = 'UPDATE ' . POSTS_TABLE . "
275 SET post_time = $current_time
276 WHERE post_id = {$post_data['topic_last_post_id']}
277 AND topic_id = $topic_id";
278 $db->sql_query($sql);
280 $sql = 'UPDATE ' . TOPICS_TABLE . "
281 SET topic_last_post_time = $current_time,
282 topic_bumped = 1,
283 topic_bumper = " . $user->data['user_id'] . "
284 WHERE topic_id = $topic_id";
285 $db->sql_query($sql);
287 update_post_information('forum', $forum_id);
289 $sql = 'UPDATE ' . USERS_TABLE . "
290 SET user_lastpost_time = $current_time
291 WHERE user_id = " . $user->data['user_id'];
292 $db->sql_query($sql);
294 $db->sql_transaction('commit');
296 markread('post', $forum_id, $topic_id, $current_time);
298 add_log('mod', $forum_id, $topic_id, 'LOG_BUMP_TOPIC', $post_data['topic_title']);
300 $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']}";
301 meta_refresh(3, $meta_url);
303 $message = $user->lang['TOPIC_BUMPED'] . '<br /><br />' . sprintf($user->lang['VIEW_MESSAGE'], '<a href="' . $meta_url . '">', '</a>');
304 $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
306 trigger_error($message);
309 trigger_error('BUMP_ERROR');
313 // Determine some vars
314 $post_data['quote_username'] = (!empty($post_data['username'])) ? $post_data['username'] : ((!empty($post_data['post_username'])) ? $post_data['post_username'] : '');
315 $post_data['post_edit_locked'] = (isset($post_data['post_edit_locked'])) ? (int) $post_data['post_edit_locked'] : 0;
316 $post_data['post_subject'] = (in_array($mode, array('quote', 'edit'))) ? $post_data['post_subject'] : ((isset($post_data['topic_title'])) ? $post_data['topic_title'] : '');
317 $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;
318 $post_data['poll_length'] = (!empty($post_data['poll_length'])) ? (int) $post_data['poll_length'] / 86400 : 0;
319 $post_data['poll_start'] = (!empty($post_data['poll_start'])) ? (int) $post_data['poll_start'] : 0;
320 $post_data['icon_id'] = (!isset($post_data['icon_id']) || in_array($mode, array('quote', 'reply'))) ? 0 : (int) $post_data['icon_id'];
321 $post_data['poll_options'] = array();
323 // Get Poll Data
324 if ($post_data['poll_start'])
326 $sql = 'SELECT poll_option_text
327 FROM ' . POLL_OPTIONS_TABLE . "
328 WHERE topic_id = $topic_id
329 ORDER BY poll_option_id";
330 $result = $db->sql_query($sql);
332 while ($row = $db->sql_fetchrow($result))
334 $post_data['poll_options'][] = trim($row['poll_option_text']);
336 $db->sql_freeresult($result);
339 $orig_poll_options_size = sizeof($post_data['poll_options']);
341 $message_parser = new parse_message();
343 if (isset($post_data['post_text']))
345 $message_parser->message = &$post_data['post_text'];
346 unset($post_data['post_text']);
349 // Set some default variables
350 $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);
352 foreach ($uninit as $var_name => $default_value)
354 if (!isset($post_data[$var_name]))
356 $post_data[$var_name] = $default_value;
359 unset($uninit);
361 // Always check if the submitted attachment data is valid and belongs to the user.
362 // Further down (especially in submit_post()) we do not check this again.
363 $message_parser->get_submitted_attachment_data($post_data['poster_id']);
365 if ($post_data['post_attachment'] && !$submit && !$refresh && !$preview && $mode == 'edit')
367 // Do not change to SELECT *
368 $sql = 'SELECT attach_id, is_orphan, attach_comment, real_filename
369 FROM ' . ATTACHMENTS_TABLE . "
370 WHERE post_msg_id = $post_id
371 AND in_message = 0
372 AND is_orphan = 0
373 ORDER BY filetime DESC";
374 $result = $db->sql_query($sql);
375 $message_parser->attachment_data = array_merge($message_parser->attachment_data, $db->sql_fetchrowset($result));
376 $db->sql_freeresult($result);
379 if ($post_data['poster_id'] == ANONYMOUS)
381 $post_data['username'] = ($mode == 'quote' || $mode == 'edit') ? trim($post_data['post_username']) : '';
383 else
385 $post_data['username'] = ($mode == 'quote' || $mode == 'edit') ? trim($post_data['username']) : '';
388 $post_data['enable_urls'] = $post_data['enable_magic_url'];
390 if ($mode != 'edit')
392 $post_data['enable_sig'] = ($config['allow_sig'] && $user->optionget('attachsig')) ? true: false;
393 $post_data['enable_smilies'] = ($config['allow_smilies'] && $user->optionget('smilies')) ? true : false;
394 $post_data['enable_bbcode'] = ($config['allow_bbcode'] && $user->optionget('bbcode')) ? true : false;
395 $post_data['enable_urls'] = true;
398 $post_data['enable_magic_url'] = $post_data['drafts'] = false;
400 // User own some drafts?
401 if ($user->data['is_registered'] && $auth->acl_get('u_savedrafts'))
403 $sql = 'SELECT draft_id
404 FROM ' . DRAFTS_TABLE . '
405 WHERE (forum_id IN (' . $forum_id . ', 0)' . (($topic_id) ? " OR topic_id = $topic_id" : '') . ')
406 AND user_id = ' . $user->data['user_id'] .
407 (($draft_id) ? " AND draft_id <> $draft_id" : '');
408 $result = $db->sql_query_limit($sql, 1);
410 if ($db->sql_fetchrow($result))
412 $post_data['drafts'] = true;
414 $db->sql_freeresult($result);
417 $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);
419 // Check if user is watching this topic
420 if ($mode != 'post' && $config['allow_topic_notify'] && $user->data['is_registered'])
422 $sql = 'SELECT topic_id
423 FROM ' . TOPICS_WATCH_TABLE . '
424 WHERE topic_id = ' . $topic_id . '
425 AND user_id = ' . $user->data['user_id'];
426 $result = $db->sql_query($sql);
427 $post_data['notify_set'] = (int) $db->sql_fetchfield('topic_id');
428 $db->sql_freeresult($result);
431 // Do we want to edit our post ?
432 if ($mode == 'edit' && $post_data['bbcode_uid'])
434 $message_parser->bbcode_uid = $post_data['bbcode_uid'];
437 // HTML, BBCode, Smilies, Images and Flash status
438 $bbcode_status = ($config['allow_bbcode'] && $auth->acl_get('f_bbcode', $forum_id)) ? true : false;
439 $smilies_status = ($config['allow_smilies'] && $auth->acl_get('f_smilies', $forum_id)) ? true : false;
440 $img_status = ($auth->acl_get('f_img', $forum_id)) ? true : false;
441 $url_status = ($config['allow_post_links']) ? true : false;
442 $flash_status = ($auth->acl_get('f_flash', $forum_id)) ? true : false;
443 $quote_status = ($auth->acl_get('f_reply', $forum_id)) ? true : false;
445 // Save Draft
446 if ($save && $user->data['is_registered'] && $auth->acl_get('u_savedrafts'))
448 $subject = utf8_normalize_nfc(request_var('subject', '', true));
449 $subject = (!$subject && $mode != 'post') ? $post_data['topic_title'] : $subject;
450 $message = utf8_normalize_nfc(request_var('message', '', true));
452 if ($subject && $message)
454 if (confirm_box(true))
456 $sql = 'INSERT INTO ' . DRAFTS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
457 'user_id' => $user->data['user_id'],
458 'topic_id' => $topic_id,
459 'forum_id' => $forum_id,
460 'save_time' => $current_time,
461 'draft_subject' => $subject,
462 'draft_message' => $message)
464 $db->sql_query($sql);
466 $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");
468 meta_refresh(3, $meta_info);
470 $message = $user->lang['DRAFT_SAVED'] . '<br /><br />';
471 $message .= ($mode != 'post') ? sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $meta_info . '">', '</a>') . '<br /><br />' : '';
472 $message .= sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
474 trigger_error($message);
476 else
478 $s_hidden_fields = build_hidden_fields(array(
479 'mode' => $mode,
480 'save' => true,
481 'f' => $forum_id,
482 't' => $topic_id,
483 'subject' => $subject,
484 'message' => $message,
488 confirm_box(false, 'SAVE_DRAFT', $s_hidden_fields);
491 else
493 if (!$subject)
495 $error[] = $user->lang['EMPTY_SUBJECT'];
498 if (!$message)
500 $error[] = $user->lang['TOO_FEW_CHARS'];
504 unset($subject, $message);
507 // Load requested Draft
508 if ($draft_id && $user->data['is_registered'] && $auth->acl_get('u_savedrafts'))
510 $sql = 'SELECT draft_subject, draft_message
511 FROM ' . DRAFTS_TABLE . "
512 WHERE draft_id = $draft_id
513 AND user_id = " . $user->data['user_id'];
514 $result = $db->sql_query_limit($sql, 1);
515 $row = $db->sql_fetchrow($result);
516 $db->sql_freeresult($result);
518 if ($row)
520 $post_data['post_subject'] = $row['draft_subject'];
521 $message_parser->message = $row['draft_message'];
523 $template->assign_var('S_DRAFT_LOADED', true);
525 else
527 $draft_id = 0;
531 // Load draft overview
532 if ($load && $post_data['drafts'])
534 load_drafts($topic_id, $forum_id);
537 $solved_captcha = false;
539 if ($submit || $preview || $refresh)
541 $post_data['topic_cur_post_id'] = request_var('topic_cur_post_id', 0);
542 $post_data['post_subject'] = utf8_normalize_nfc(request_var('subject', '', true));
543 $message_parser->message = utf8_normalize_nfc(request_var('message', '', true));
545 $post_data['username'] = utf8_normalize_nfc(request_var('username', $post_data['username'], true));
546 $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)) : '';
548 $post_data['topic_type'] = request_var('topic_type', (($mode != 'post') ? (int) $post_data['topic_type'] : POST_NORMAL));
549 $post_data['topic_time_limit'] = request_var('topic_time_limit', (($mode != 'post') ? (int) $post_data['topic_time_limit'] : 0));
550 $post_data['icon_id'] = request_var('icon', 0);
552 $post_data['enable_bbcode'] = (!$bbcode_status || isset($_POST['disable_bbcode'])) ? false : true;
553 $post_data['enable_smilies'] = (!$smilies_status || isset($_POST['disable_smilies'])) ? false : true;
554 $post_data['enable_urls'] = (isset($_POST['disable_magic_url'])) ? 0 : 1;
555 $post_data['enable_sig'] = (!$config['allow_sig']) ? false : ((isset($_POST['attach_sig']) && $user->data['is_registered']) ? true : false);
557 if ($config['allow_topic_notify'] && $user->data['is_registered'])
559 $notify = (isset($_POST['notify'])) ? true : false;
561 else
563 $notify = false;
566 $topic_lock = (isset($_POST['lock_topic'])) ? true : false;
567 $post_lock = (isset($_POST['lock_post'])) ? true : false;
568 $poll_delete = (isset($_POST['poll_delete'])) ? true : false;
570 if ($submit)
572 $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);
573 $status_switch = ($status_switch != $check_value);
575 else
577 $status_switch = 1;
580 // Delete Poll
581 if ($poll_delete && $mode == 'edit' && sizeof($post_data['poll_options']) &&
582 ((!$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)))
584 if ($submit)
586 $sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . "
587 WHERE topic_id = $topic_id";
588 $db->sql_query($sql);
590 $sql = 'DELETE FROM ' . POLL_VOTES_TABLE . "
591 WHERE topic_id = $topic_id";
592 $db->sql_query($sql);
594 $topic_sql = array(
595 'poll_title' => '',
596 'poll_start' => 0,
597 'poll_length' => 0,
598 'poll_last_vote' => 0,
599 'poll_max_options' => 0,
600 'poll_vote_change' => 0
603 $sql = 'UPDATE ' . TOPICS_TABLE . '
604 SET ' . $db->sql_build_array('UPDATE', $topic_sql) . "
605 WHERE topic_id = $topic_id";
606 $db->sql_query($sql);
609 $post_data['poll_title'] = $post_data['poll_option_text'] = '';
610 $post_data['poll_vote_change'] = $post_data['poll_max_options'] = $post_data['poll_length'] = 0;
612 else
614 $post_data['poll_title'] = utf8_normalize_nfc(request_var('poll_title', '', true));
615 $post_data['poll_length'] = request_var('poll_length', 0);
616 $post_data['poll_option_text'] = utf8_normalize_nfc(request_var('poll_option_text', '', true));
617 $post_data['poll_max_options'] = request_var('poll_max_options', 1);
618 $post_data['poll_vote_change'] = ($auth->acl_get('f_votechg', $forum_id) && isset($_POST['poll_vote_change'])) ? 1 : 0;
621 // If replying/quoting and last post id has changed
622 // give user option to continue submit or return to post
623 // notify and show user the post made between his request and the final submit
624 if (($mode == 'reply' || $mode == 'quote') && $post_data['topic_cur_post_id'] && $post_data['topic_cur_post_id'] != $post_data['topic_last_post_id'])
626 // Only do so if it is allowed forum-wide
627 if ($post_data['forum_flags'] & FORUM_FLAG_POST_REVIEW)
629 if (topic_review($topic_id, $forum_id, 'post_review', $post_data['topic_cur_post_id']))
631 $template->assign_var('S_POST_REVIEW', true);
634 $submit = false;
635 $refresh = true;
639 // Parse Attachments - before checksum is calculated
640 $message_parser->parse_attachments('fileupload', $mode, $forum_id, $submit, $preview, $refresh);
642 // Grab md5 'checksum' of new message
643 $message_md5 = md5($message_parser->message);
645 // Check checksum ... don't re-parse message if the same
646 $update_message = ($mode != 'edit' || $message_md5 != $post_data['post_checksum'] || $status_switch) ? true : false;
648 // Parse message
649 if ($update_message)
651 if (sizeof($message_parser->warn_msg))
653 $error[] = implode('<br />', $message_parser->warn_msg);
654 $message_parser->warn_msg = array();
657 $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']);
659 // On a refresh we do not care about message parsing errors
660 if (sizeof($message_parser->warn_msg) && $refresh)
662 $message_parser->warn_msg = array();
665 else
667 $message_parser->bbcode_bitfield = $post_data['bbcode_bitfield'];
670 if ($mode != 'edit' && !$preview && !$refresh && $config['flood_interval'] && !$auth->acl_get('f_ignoreflood', $forum_id))
672 // Flood check
673 $last_post_time = 0;
675 if ($user->data['is_registered'])
677 $last_post_time = $user->data['user_lastpost_time'];
679 else
681 $sql = 'SELECT post_time AS last_post_time
682 FROM ' . POSTS_TABLE . "
683 WHERE poster_ip = '" . $user->ip . "'
684 AND post_time > " . ($current_time - $config['flood_interval']);
685 $result = $db->sql_query_limit($sql, 1);
686 if ($row = $db->sql_fetchrow($result))
688 $last_post_time = $row['last_post_time'];
690 $db->sql_freeresult($result);
693 if ($last_post_time && ($current_time - $last_post_time) < intval($config['flood_interval']))
695 $error[] = $user->lang['FLOOD_ERROR'];
699 // Validate username
700 if (($post_data['username'] && !$user->data['is_registered']) || ($mode == 'edit' && $post_data['username'] && $post_data['post_username'] && $post_data['post_username'] != $post_data['username']))
702 include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
704 if (($result = validate_username($post_data['username'])) !== false)
706 $user->add_lang('ucp');
707 $error[] = $user->lang[$result . '_USERNAME'];
711 if ($config['enable_post_confirm'] && !$user->data['is_registered'] && in_array($mode, array('quote', 'post', 'reply')))
713 $confirm_id = request_var('confirm_id', '');
714 $confirm_code = request_var('confirm_code', '');
716 $sql = 'SELECT code
717 FROM ' . CONFIRM_TABLE . "
718 WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "'
719 AND session_id = '" . $db->sql_escape($user->session_id) . "'
720 AND confirm_type = " . CONFIRM_POST;
721 $result = $db->sql_query($sql);
722 $confirm_row = $db->sql_fetchrow($result);
723 $db->sql_freeresult($result);
725 if (empty($confirm_row['code']) || strcasecmp($confirm_row['code'], $confirm_code) !== 0)
727 $error[] = $user->lang['CONFIRM_CODE_WRONG'];
729 else
731 $solved_captcha = true;
735 // Parse subject
736 if (!$preview && !$refresh && !$post_data['post_subject'] && ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_id)))
738 $error[] = $user->lang['EMPTY_SUBJECT'];
741 $post_data['poll_last_vote'] = (isset($post_data['poll_last_vote'])) ? $post_data['poll_last_vote'] : 0;
743 if ($post_data['poll_option_text'] &&
744 ($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id'] && (!$post_data['poll_last_vote'] || $auth->acl_get('m_edit', $forum_id))))
745 && $auth->acl_get('f_poll', $forum_id))
747 $poll = array(
748 'poll_title' => $post_data['poll_title'],
749 'poll_length' => $post_data['poll_length'],
750 'poll_max_options' => $post_data['poll_max_options'],
751 'poll_option_text' => $post_data['poll_option_text'],
752 'poll_start' => $post_data['poll_start'],
753 'poll_last_vote' => $post_data['poll_last_vote'],
754 'poll_vote_change' => $post_data['poll_vote_change'],
755 'enable_bbcode' => $post_data['enable_bbcode'],
756 'enable_urls' => $post_data['enable_urls'],
757 'enable_smilies' => $post_data['enable_smilies'],
758 'img_status' => $img_status
761 $message_parser->parse_poll($poll);
763 $post_data['poll_options'] = (isset($poll['poll_options'])) ? $poll['poll_options'] : '';
764 $post_data['poll_title'] = (isset($poll['poll_title'])) ? $poll['poll_title'] : '';
766 if ($post_data['poll_last_vote'] && ($poll['poll_options_size'] < $orig_poll_options_size))
768 $message_parser->warn_msg[] = $user->lang['NO_DELETE_POLL_OPTIONS'];
771 else
773 $poll = array();
776 // Check topic type
777 if ($post_data['topic_type'] != POST_NORMAL && ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_id)))
779 switch ($post_data['topic_type'])
781 case POST_GLOBAL:
782 case POST_ANNOUNCE:
783 $auth_option = 'f_announce';
784 break;
786 case POST_STICKY:
787 $auth_option = 'f_sticky';
788 break;
790 default:
791 $auth_option = '';
792 break;
795 if (!$auth->acl_get($auth_option, $forum_id))
797 $error[] = $user->lang['CANNOT_POST_' . str_replace('F_', '', strtoupper($auth_option))];
801 if (sizeof($message_parser->warn_msg))
803 $error[] = implode('<br />', $message_parser->warn_msg);
806 // DNSBL check
807 if ($config['check_dnsbl'] && !$refresh)
809 if (($dnsbl = $user->check_dnsbl('post')) !== false)
811 $error[] = sprintf($user->lang['IP_BLACKLISTED'], $user->ip, $dnsbl[1]);
815 // Store message, sync counters
816 if (!sizeof($error) && $submit)
818 // Check if we want to de-globalize the topic... and ask for new forum
819 if ($post_data['topic_type'] != POST_GLOBAL)
821 $sql = 'SELECT topic_type, forum_id
822 FROM ' . TOPICS_TABLE . "
823 WHERE topic_id = $topic_id";
824 $result = $db->sql_query_limit($sql, 1);
825 $row = $db->sql_fetchrow($result);
826 $db->sql_freeresult($result);
828 if ($row && !$row['forum_id'] && $row['topic_type'] == POST_GLOBAL)
830 $to_forum_id = request_var('to_forum_id', 0);
832 if (!$to_forum_id)
834 include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
836 $template->assign_vars(array(
837 'S_FORUM_SELECT' => make_forum_select(false, false, false, true, true),
838 'S_UNGLOBALISE' => true)
841 $submit = false;
842 $refresh = true;
844 else
846 $forum_id = $to_forum_id;
851 if ($submit)
853 // Lock/Unlock Topic
854 $change_topic_status = $post_data['topic_status'];
855 $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;
857 if ($post_data['topic_status'] == ITEM_LOCKED && !$topic_lock && $perm_lock_unlock)
859 $change_topic_status = ITEM_UNLOCKED;
861 else if ($post_data['topic_status'] == ITEM_UNLOCKED && $topic_lock && $perm_lock_unlock)
863 $change_topic_status = ITEM_LOCKED;
866 if ($change_topic_status != $post_data['topic_status'])
868 $sql = 'UPDATE ' . TOPICS_TABLE . "
869 SET topic_status = $change_topic_status
870 WHERE topic_id = $topic_id
871 AND topic_moved_id = 0";
872 $db->sql_query($sql);
874 $user_lock = ($auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && $user->data['user_id'] == $post_data['topic_poster']) ? 'USER_' : '';
876 add_log('mod', $forum_id, $topic_id, 'LOG_' . $user_lock . (($change_topic_status == ITEM_LOCKED) ? 'LOCK' : 'UNLOCK'), $post_data['topic_title']);
879 // Lock/Unlock Post Edit
880 if ($mode == 'edit' && $post_data['post_edit_locked'] == ITEM_LOCKED && !$post_lock && $auth->acl_get('m_edit', $forum_id))
882 $post_data['post_edit_locked'] = ITEM_UNLOCKED;
884 else if ($mode == 'edit' && $post_data['post_edit_locked'] == ITEM_UNLOCKED && $post_lock && $auth->acl_get('m_edit', $forum_id))
886 $post_data['post_edit_locked'] = ITEM_LOCKED;
889 $data = array(
890 'topic_title' => (empty($post_data['topic_title'])) ? $post_data['post_subject'] : $post_data['topic_title'],
891 'topic_first_post_id' => (isset($post_data['topic_first_post_id'])) ? (int) $post_data['topic_first_post_id'] : 0,
892 'topic_last_post_id' => (isset($post_data['topic_last_post_id'])) ? (int) $post_data['topic_last_post_id'] : 0,
893 'topic_time_limit' => (int) $post_data['topic_time_limit'],
894 'post_id' => (int) $post_id,
895 'topic_id' => (int) $topic_id,
896 'forum_id' => (int) $forum_id,
897 'icon_id' => (int) $post_data['icon_id'],
898 'poster_id' => (int) $post_data['poster_id'],
899 'enable_sig' => (bool) $post_data['enable_sig'],
900 'enable_bbcode' => (bool) $post_data['enable_bbcode'],
901 'enable_smilies' => (bool) $post_data['enable_smilies'],
902 'enable_urls' => (bool) $post_data['enable_urls'],
903 'enable_indexing' => (bool) $post_data['enable_indexing'],
904 'message_md5' => (string) $message_md5,
905 'post_time' => (isset($post_data['post_time'])) ? (int) $post_data['post_time'] : $current_time,
906 'post_checksum' => (isset($post_data['post_checksum'])) ? (string) $post_data['post_checksum'] : '',
907 'post_edit_reason' => $post_data['post_edit_reason'],
908 'post_edit_user' => ($mode == 'edit') ? $user->data['user_id'] : ((isset($post_data['post_edit_user'])) ? (int) $post_data['post_edit_user'] : 0),
909 'forum_parents' => $post_data['forum_parents'],
910 'forum_name' => $post_data['forum_name'],
911 'notify' => $notify,
912 'notify_set' => $post_data['notify_set'],
913 'poster_ip' => (isset($post_data['poster_ip'])) ? $post_data['poster_ip'] : $user->ip,
914 'post_edit_locked' => (int) $post_data['post_edit_locked'],
915 'bbcode_bitfield' => $message_parser->bbcode_bitfield,
916 'bbcode_uid' => $message_parser->bbcode_uid,
917 'message' => $message_parser->message,
918 'attachment_data' => $message_parser->attachment_data,
919 'filename_data' => $message_parser->filename_data
921 unset($message_parser);
923 $redirect_url = submit_post($mode, $post_data['post_subject'], $post_data['username'], $post_data['topic_type'], $poll, $data, $update_message);
925 meta_refresh(3, $redirect_url);
927 $message = (!$auth->acl_get('f_noapprove', $data['forum_id']) && !$auth->acl_get('m_approve', $data['forum_id'])) ? (($mode == 'edit') ? 'POST_EDITED_MOD' : 'POST_STORED_MOD') : (($mode == 'edit') ? 'POST_EDITED' : 'POST_STORED');
928 $message = $user->lang[$message] . (($auth->acl_get('f_noapprove', $data['forum_id']) || $auth->acl_get('m_approve', $data['forum_id'])) ? '<br /><br />' . sprintf($user->lang['VIEW_MESSAGE'], '<a href="' . $redirect_url . '">', '</a>') : '');
929 $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $data['forum_id']) . '">', '</a>');
930 trigger_error($message);
935 // Preview
936 if (!sizeof($error) && $preview)
938 $post_data['post_time'] = ($mode == 'edit') ? $post_data['post_time'] : $current_time;
940 $preview_message = $message_parser->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies'], false);
942 $preview_signature = ($mode == 'edit') ? $post_data['user_sig'] : $user->data['user_sig'];
943 $preview_signature_uid = ($mode == 'edit') ? $post_data['user_sig_bbcode_uid'] : $user->data['user_sig_bbcode_uid'];
944 $preview_signature_bitfield = ($mode == 'edit') ? $post_data['user_sig_bbcode_bitfield'] : $user->data['user_sig_bbcode_bitfield'];
946 // Signature
947 if ($post_data['enable_sig'] && $config['allow_sig'] && $preview_signature && $auth->acl_get('f_sigs', $forum_id))
949 $parse_sig = new parse_message($preview_signature);
950 $parse_sig->bbcode_uid = $preview_signature_uid;
951 $parse_sig->bbcode_bitfield = $preview_signature_bitfield;
953 // Not sure about parameters for bbcode/smilies/urls... in signatures
954 $parse_sig->format_display($config['allow_sig_bbcode'], true, $config['allow_sig_smilies']);
955 $preview_signature = $parse_sig->message;
956 unset($parse_sig);
958 else
960 $preview_signature = '';
963 $preview_subject = censor_text($post_data['post_subject']);
965 // Poll Preview
966 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))))
967 && $auth->acl_get('f_poll', $forum_id))
969 $parse_poll = new parse_message($post_data['poll_title']);
970 $parse_poll->bbcode_uid = $message_parser->bbcode_uid;
971 $parse_poll->bbcode_bitfield = $message_parser->bbcode_bitfield;
973 $parse_poll->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies']);
975 $template->assign_vars(array(
976 'S_HAS_POLL_OPTIONS' => (sizeof($post_data['poll_options'])),
977 'S_IS_MULTI_CHOICE' => ($post_data['poll_max_options'] > 1) ? true : false,
979 'POLL_QUESTION' => $parse_poll->message,
981 'L_POLL_LENGTH' => ($post_data['poll_length']) ? sprintf($user->lang['POLL_RUN_TILL'], $user->format_date($post_data['poll_length'] + $post_data['poll_start'])) : '',
982 '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']))
985 $parse_poll->message = implode("\n", $post_data['poll_options']);
986 $parse_poll->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies']);
987 $preview_poll_options = explode('<br />', $parse_poll->message);
988 unset($parse_poll);
990 foreach ($preview_poll_options as $option)
992 $template->assign_block_vars('poll_option', array(
993 'POLL_OPTION_CAPTION' => $option)
996 unset($preview_poll_options);
999 // Attachment Preview
1000 if (sizeof($message_parser->attachment_data))
1002 $template->assign_var('S_HAS_ATTACHMENTS', true);
1004 $update_count = array();
1005 $attachment_data = $message_parser->attachment_data;
1007 parse_attachments($forum_id, $preview_message, $attachment_data, $update_count, true);
1009 foreach ($attachment_data as $i => $attachment)
1011 $template->assign_block_vars('attachment', array(
1012 'DISPLAY_ATTACHMENT' => $attachment)
1015 unset($attachment_data);
1018 if (!sizeof($error))
1020 $template->assign_vars(array(
1021 'PREVIEW_SUBJECT' => $preview_subject,
1022 'PREVIEW_MESSAGE' => $preview_message,
1023 'PREVIEW_SIGNATURE' => $preview_signature,
1025 'S_DISPLAY_PREVIEW' => true)
1030 // Decode text for message display
1031 $post_data['bbcode_uid'] = ($mode == 'quote' && !$preview && !$refresh && !sizeof($error)) ? $post_data['bbcode_uid'] : $message_parser->bbcode_uid;
1032 $message_parser->decode_message($post_data['bbcode_uid']);
1034 if ($mode == 'quote' && !$submit && !$preview && !$refresh)
1036 $message_parser->message = '[quote="' . $post_data['quote_username'] . '"]' . censor_text(trim($message_parser->message)) . "[/quote]\n";
1039 if (($mode == 'reply' || $mode == 'quote') && !$submit && !$preview && !$refresh)
1041 $post_data['post_subject'] = ((strpos($post_data['post_subject'], 'Re: ') !== 0) ? 'Re: ' : '') . censor_text($post_data['post_subject']);
1044 $attachment_data = $message_parser->attachment_data;
1045 $filename_data = $message_parser->filename_data;
1046 $post_data['post_text'] = $message_parser->message;
1048 if (sizeof($post_data['poll_options']) && $post_data['poll_title'])
1050 $message_parser->message = $post_data['poll_title'];
1051 $message_parser->bbcode_uid = $post_data['bbcode_uid'];
1053 $message_parser->decode_message();
1054 $post_data['poll_title'] = $message_parser->message;
1056 $message_parser->message = implode("\n", $post_data['poll_options']);
1057 $message_parser->decode_message();
1058 $post_data['poll_options'] = explode("\n", $message_parser->message);
1060 unset($message_parser);
1062 // MAIN POSTING PAGE BEGINS HERE
1064 // Forum moderators?
1065 $moderators = array();
1066 get_moderators($moderators, $forum_id);
1068 // Generate smiley listing
1069 generate_smilies('inline', $forum_id);
1071 // Generate inline attachment select box
1072 posting_gen_inline_attachments($attachment_data);
1074 // Do show topic type selection only in first post.
1075 $topic_type_toggle = false;
1077 if ($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id']))
1079 $topic_type_toggle = posting_gen_topic_types($forum_id, $post_data['topic_type']);
1082 $s_topic_icons = false;
1083 if ($post_data['enable_icons'])
1085 $s_topic_icons = posting_gen_topic_icons($mode, $post_data['icon_id']);
1088 $bbcode_checked = (isset($post_data['enable_bbcode'])) ? !$post_data['enable_bbcode'] : (($config['allow_bbcode']) ? !$user->optionget('bbcode') : 1);
1089 $smilies_checked = (isset($post_data['enable_smilies'])) ? !$post_data['enable_smilies'] : (($config['allow_smilies']) ? !$user->optionget('smilies') : 1);
1090 $urls_checked = (isset($post_data['enable_urls'])) ? !$post_data['enable_urls'] : 0;
1091 $sig_checked = $post_data['enable_sig'];
1092 $lock_topic_checked = (isset($topic_lock)) ? $topic_lock : (($post_data['topic_status'] == ITEM_LOCKED) ? 1 : 0);
1093 $lock_post_checked = (isset($post_lock)) ? $post_lock : $post_data['post_edit_locked'];
1095 // 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
1096 $notify_set = ($mode != 'edit' && $config['allow_topic_notify'] && $user->data['is_registered'] && !$post_data['notify_set']) ? $user->data['user_notify'] : $post_data['notify_set'];
1097 $notify_checked = (isset($notify)) ? $notify : (($mode == 'post') ? $user->data['user_notify'] : $notify_set);
1099 // Page title & action URL, include session_id for security purpose
1100 $s_action = append_sid("{$phpbb_root_path}posting.$phpEx", "mode=$mode&amp;f=$forum_id", true, $user->session_id);
1101 $s_action .= ($topic_id) ? "&amp;t=$topic_id" : '';
1102 $s_action .= ($post_id) ? "&amp;p=$post_id" : '';
1104 switch ($mode)
1106 case 'post':
1107 $page_title = $user->lang['POST_TOPIC'];
1108 break;
1110 case 'quote':
1111 case 'reply':
1112 $page_title = $user->lang['POST_REPLY'];
1113 break;
1115 case 'delete':
1116 case 'edit':
1117 $page_title = $user->lang['EDIT_POST'];
1118 break;
1121 // Build Navigation Links
1122 generate_forum_nav($post_data);
1124 // Build Forum Rules
1125 generate_forum_rules($post_data);
1127 if ($config['enable_post_confirm'] && !$user->data['is_registered'] && $solved_captcha === false && ($mode == 'post' || $mode == 'reply' || $mode == 'quote'))
1129 // Show confirm image
1130 $sql = 'DELETE FROM ' . CONFIRM_TABLE . "
1131 WHERE session_id = '" . $db->sql_escape($user->session_id) . "'
1132 AND confirm_type = " . CONFIRM_POST;
1133 $db->sql_query($sql);
1135 // Generate code
1136 $code = gen_rand_string(mt_rand(5, 8));
1137 $confirm_id = md5(unique_id($user->ip));
1138 $seed = hexdec(substr(unique_id(), 4, 10));
1140 // compute $seed % 0x7fffffff
1141 $seed -= 0x7fffffff * floor($seed / 0x7fffffff);
1143 $sql = 'INSERT INTO ' . CONFIRM_TABLE . ' ' . $db->sql_build_array('INSERT', array(
1144 'confirm_id' => (string) $confirm_id,
1145 'session_id' => (string) $user->session_id,
1146 'confirm_type' => (int) CONFIRM_POST,
1147 'code' => (string) $code,
1148 'seed' => (int) $seed)
1150 $db->sql_query($sql);
1152 $template->assign_vars(array(
1153 'S_CONFIRM_CODE' => true,
1154 'CONFIRM_ID' => $confirm_id,
1155 'CONFIRM_IMAGE' => '<img src="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=confirm&amp;id=' . $confirm_id . '&amp;type=' . CONFIRM_POST) . '" alt="" title="" />',
1156 'L_POST_CONFIRM_EXPLAIN' => sprintf($user->lang['POST_CONFIRM_EXPLAIN'], '<a href="mailto:' . htmlspecialchars($config['board_contact']) . '">', '</a>'),
1160 $s_hidden_fields = ($mode == 'reply' || $mode == 'quote') ? '<input type="hidden" name="topic_cur_post_id" value="' . $post_data['topic_last_post_id'] . '" />' : '';
1161 $s_hidden_fields .= '<input type="hidden" name="lastclick" value="' . $current_time . '" />';
1162 $s_hidden_fields .= ($draft_id || isset($_REQUEST['draft_loaded'])) ? '<input type="hidden" name="draft_loaded" value="' . request_var('draft_loaded', $draft_id) . '" />' : '';
1164 // Add the confirm id/code pair to the hidden fields, else an error is displayed on next submit/preview
1165 if ($solved_captcha !== false)
1167 $s_hidden_fields .= build_hidden_fields(array(
1168 'confirm_id' => request_var('confirm_id', ''),
1169 'confirm_code' => request_var('confirm_code', ''))
1173 $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"';
1175 // Start assigning vars for main posting page ...
1176 $template->assign_vars(array(
1177 'L_POST_A' => $page_title,
1178 'L_ICON' => ($mode == 'reply' || $mode == 'quote' || ($mode == 'edit' && $post_id != $post_data['topic_first_post_id'])) ? $user->lang['POST_ICON'] : $user->lang['TOPIC_ICON'],
1179 'L_MESSAGE_BODY_EXPLAIN' => (intval($config['max_post_chars'])) ? sprintf($user->lang['MESSAGE_BODY_EXPLAIN'], intval($config['max_post_chars'])) : '',
1181 'FORUM_NAME' => $post_data['forum_name'],
1182 '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']) : '',
1183 'TOPIC_TITLE' => censor_text($post_data['topic_title']),
1184 'MODERATORS' => (sizeof($moderators)) ? implode(', ', $moderators[$forum_id]) : '',
1185 'USERNAME' => ((!$preview && $mode != 'quote') || $preview) ? $post_data['username'] : '',
1186 'SUBJECT' => $post_data['post_subject'],
1187 'MESSAGE' => $post_data['post_text'],
1188 '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>'),
1189 'IMG_STATUS' => ($img_status) ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'],
1190 'FLASH_STATUS' => ($flash_status) ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'],
1191 'SMILIES_STATUS' => ($smilies_status) ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'],
1192 'URL_STATUS' => ($url_status) ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'],
1193 'MINI_POST_IMG' => $user->img('icon_post_target', $user->lang['POST']),
1194 'POST_DATE' => ($post_data['post_time']) ? $user->format_date($post_data['post_time']) : '',
1195 'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '',
1196 'TOPIC_TIME_LIMIT' => (int) $post_data['topic_time_limit'],
1197 'EDIT_REASON' => $post_data['post_edit_reason'],
1198 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id"),
1199 'U_VIEW_TOPIC' => ($mode != 'post') ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id") : '',
1200 'U_PROGRESS_BAR' => append_sid("{$phpbb_root_path}posting.$phpEx", "f=$forum_id&amp;mode=popup"),
1201 'UA_PROGRESS_BAR' => append_sid("{$phpbb_root_path}posting.$phpEx", "f=$forum_id&mode=popup", false),
1203 'S_PRIVMSGS' => false,
1204 'S_CLOSE_PROGRESS_WINDOW' => (isset($_POST['add_file'])) ? true : false,
1205 'S_EDIT_POST' => ($mode == 'edit') ? true : false,
1206 'S_EDIT_REASON' => ($mode == 'edit' && $auth->acl_get('m_edit', $forum_id)) ? true : false,
1207 'S_DISPLAY_USERNAME' => (!$user->data['is_registered'] || ($mode == 'edit' && $post_data['post_username'])) ? true : false,
1208 'S_SHOW_TOPIC_ICONS' => $s_topic_icons,
1209 '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,
1210 'S_BBCODE_ALLOWED' => $bbcode_status,
1211 'S_BBCODE_CHECKED' => ($bbcode_checked) ? ' checked="checked"' : '',
1212 'S_SMILIES_ALLOWED' => $smilies_status,
1213 'S_SMILIES_CHECKED' => ($smilies_checked) ? ' checked="checked"' : '',
1214 'S_SIG_ALLOWED' => ($auth->acl_get('f_sigs', $forum_id) && $config['allow_sig'] && $user->data['is_registered']) ? true : false,
1215 'S_SIGNATURE_CHECKED' => ($sig_checked) ? ' checked="checked"' : '',
1216 'S_NOTIFY_ALLOWED' => (!$user->data['is_registered'] || ($mode == 'edit' && $user->data['user_id'] != $post_data['poster_id']) || !$config['allow_topic_notify']) ? false : true,
1217 'S_NOTIFY_CHECKED' => ($notify_checked) ? ' checked="checked"' : '',
1218 '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,
1219 'S_LOCK_TOPIC_CHECKED' => ($lock_topic_checked) ? ' checked="checked"' : '',
1220 'S_LOCK_POST_ALLOWED' => ($mode == 'edit' && $auth->acl_get('m_edit', $forum_id)) ? true : false,
1221 'S_LOCK_POST_CHECKED' => ($lock_post_checked) ? ' checked="checked"' : '',
1222 'S_LINKS_ALLOWED' => $url_status,
1223 'S_MAGIC_URL_CHECKED' => ($urls_checked) ? ' checked="checked"' : '',
1224 'S_TYPE_TOGGLE' => $topic_type_toggle,
1225 'S_SAVE_ALLOWED' => ($auth->acl_get('u_savedrafts') && $user->data['is_registered']) ? true : false,
1226 'S_HAS_DRAFTS' => ($auth->acl_get('u_savedrafts') && $user->data['is_registered'] && $post_data['drafts']) ? true : false,
1227 'S_FORM_ENCTYPE' => $form_enctype,
1229 'S_BBCODE_IMG' => $img_status,
1230 'S_BBCODE_URL' => $url_status,
1231 'S_BBCODE_FLASH' => $flash_status,
1232 'S_BBCODE_QUOTE' => $quote_status,
1234 'S_POST_ACTION' => $s_action,
1235 'S_HIDDEN_FIELDS' => $s_hidden_fields)
1238 // Build custom bbcodes array
1239 display_custom_bbcodes();
1241 // Poll entry
1242 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))))
1243 && $auth->acl_get('f_poll', $forum_id))
1245 $template->assign_vars(array(
1246 'S_SHOW_POLL_BOX' => true,
1247 'S_POLL_VOTE_CHANGE' => ($auth->acl_get('f_votechg', $forum_id)),
1248 '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))),
1249 'S_POLL_DELETE_CHECKED' => (!empty($poll_delete)) ? true : false,
1251 'L_POLL_OPTIONS_EXPLAIN' => sprintf($user->lang['POLL_OPTIONS_EXPLAIN'], $config['max_poll_options']),
1253 'VOTE_CHANGE_CHECKED' => (!empty($post_data['poll_vote_change'])) ? ' checked="checked"' : '',
1254 'POLL_TITLE' => (isset($post_data['poll_title'])) ? $post_data['poll_title'] : '',
1255 'POLL_OPTIONS' => (!empty($post_data['poll_options'])) ? implode("\n", $post_data['poll_options']) : '',
1256 'POLL_MAX_OPTIONS' => (isset($post_data['poll_max_options'])) ? (int) $post_data['poll_max_options'] : 1,
1257 'POLL_LENGTH' => $post_data['poll_length'])
1261 // Attachment entry
1262 // Not using acl_gets here, because it is using OR logic
1263 if ($auth->acl_get('f_attach', $forum_id) && $auth->acl_get('u_attach') && $config['allow_attachments'] && $form_enctype)
1265 posting_gen_attachment_entry($attachment_data, $filename_data);
1268 // Output page ...
1269 page_header($page_title);
1271 $template->set_filenames(array(
1272 'body' => 'posting_body.html')
1275 make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
1277 // Topic review
1278 if ($mode == 'reply' || $mode == 'quote')
1280 if (topic_review($topic_id, $forum_id))
1282 $template->assign_var('S_DISPLAY_REVIEW', true);
1286 page_footer();
1289 * Show upload popup (progress bar)
1291 function upload_popup($forum_style = 0)
1293 global $template, $user;
1295 ($forum_style) ? $user->setup('posting', $forum_style) : $user->setup('posting');
1297 page_header($user->lang['PROGRESS_BAR']);
1299 $template->set_filenames(array(
1300 'popup' => 'posting_progress_bar.html')
1303 $template->assign_vars(array(
1304 'PROGRESS_BAR' => $user->img('upload_bar', $user->lang['UPLOAD_IN_PROGRESS']))
1307 $template->display('popup');
1311 * Do the various checks required for removing posts as well as removing it
1313 function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data)
1315 global $user, $db, $auth;
1316 global $phpbb_root_path, $phpEx;
1318 // If moderator removing post or user itself removing post, present a confirmation screen
1319 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']))
1321 $s_hidden_fields = build_hidden_fields(array(
1322 'p' => $post_id,
1323 'f' => $forum_id,
1324 'mode' => 'delete')
1327 if (confirm_box(true))
1329 $data = array(
1330 'topic_first_post_id' => $post_data['topic_first_post_id'],
1331 'topic_last_post_id' => $post_data['topic_last_post_id'],
1332 'topic_approved' => $post_data['topic_approved'],
1333 'topic_type' => $post_data['topic_type'],
1334 'post_approved' => $post_data['post_approved'],
1335 'post_reported' => $post_data['post_reported'],
1336 'post_time' => $post_data['post_time'],
1337 'poster_id' => $post_data['poster_id'],
1338 'post_postcount' => $post_data['post_postcount']
1341 $next_post_id = delete_post($forum_id, $topic_id, $post_id, $data);
1343 if ($post_data['topic_first_post_id'] == $post_data['topic_last_post_id'])
1345 add_log('mod', $forum_id, $topic_id, 'LOG_DELETE_TOPIC', $post_data['topic_title']);
1347 $meta_info = append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id");
1348 $message = $user->lang['POST_DELETED'];
1350 else
1352 add_log('mod', $forum_id, $topic_id, 'LOG_DELETE_POST', $post_data['post_subject']);
1354 $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";
1355 $message = $user->lang['POST_DELETED'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $meta_info . '">', '</a>');
1358 meta_refresh(3, $meta_info);
1359 $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
1360 trigger_error($message);
1362 else
1364 confirm_box(false, 'DELETE_MESSAGE', $s_hidden_fields);
1368 // If we are here the user is not able to delete - present the correct error message
1369 if ($post_data['poster_id'] != $user->data['user_id'] && !$auth->acl_get('f_delete', $forum_id))
1371 trigger_error('DELETE_OWN_POSTS');
1374 if ($post_data['poster_id'] == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id) && $post_id != $post_data['topic_last_post_id'])
1376 trigger_error('CANNOT_DELETE_REPLIED');
1379 trigger_error('USER_CANNOT_DELETE');