diff options
author | Meik Sievertsen <acydburn@phpbb.com> | 2006-05-12 20:52:58 +0000 |
---|---|---|
committer | Meik Sievertsen <acydburn@phpbb.com> | 2006-05-12 20:52:58 +0000 |
commit | a8d99f2228cc042c8410553f5f3ec375148552f5 (patch) | |
tree | 11ccbd184cbc222775a08852d633d74ced7b2695 /phpBB/posting.php | |
parent | 7dd067bf5a532e4c30908cca24449274a4863326 (diff) | |
download | forums-a8d99f2228cc042c8410553f5f3ec375148552f5.tar forums-a8d99f2228cc042c8410553f5f3ec375148552f5.tar.gz forums-a8d99f2228cc042c8410553f5f3ec375148552f5.tar.bz2 forums-a8d99f2228cc042c8410553f5f3ec375148552f5.tar.xz forums-a8d99f2228cc042c8410553f5f3ec375148552f5.zip |
- introduce new function build_url to easily build a valid url from the user->page object as well as optionally removing certain keys
- changed attachment config to utilize the config build methods
- cleaned up posting.php
- the submit/delete_post functions are now usable (functions_posting.php)
- adjusted header icons (transparency)
- a bunch of fixes for mssql
- bug fixes
git-svn-id: file:///svn/phpbb/trunk@5902 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/posting.php')
-rw-r--r-- | phpBB/posting.php | 1641 |
1 files changed, 450 insertions, 1191 deletions
diff --git a/phpBB/posting.php b/phpBB/posting.php index 7d0b2892b4..a357e565c6 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -32,19 +32,18 @@ $forum_id = request_var('f', 0); $draft_id = request_var('d', 0); $lastclick = request_var('lastclick', 0); -$submit = (isset($_POST['post'])); -$preview = (isset($_POST['preview'])); -$save = (isset($_POST['save'])); -$load = (isset($_POST['load'])); -$cancel = (isset($_POST['cancel'])); -$confirm = (isset($_POST['confirm'])); -$delete = (isset($_POST['delete'])); - -$refresh = isset($_POST['add_file']) || isset($_POST['delete_file']) || isset($_POST['edit_comment']) || isset($_POST['cancel_unglobalise']) || $save || $load; - +$submit = (isset($_POST['post'])) ? true : false; +$preview = (isset($_POST['preview'])) ? true : false; +$save = (isset($_POST['save'])) ? true : false; +$load = (isset($_POST['load'])) ? true : false; +$delete = (isset($_POST['delete'])) ? true : false; +$cancel = (isset($_POST['cancel'])) ? true : false; +$confirm = (isset($_POST['confirm'])) ? true : false; + +$refresh = (isset($_POST['add_file']) || isset($_POST['delete_file']) || isset($_POST['edit_comment']) || isset($_POST['cancel_unglobalise']) || $save || $load) ? true : false; $mode = ($delete && !$preview && !$refresh && $submit) ? 'delete' : request_var('mode', ''); -$error = array(); +$error = $post_data = array(); $current_time = time(); // Was cancel pressed? If so then redirect to the appropriate page @@ -122,172 +121,44 @@ switch ($mode) default: $sql = ''; trigger_error('NO_POST_MODE'); + break; } -if ($sql) +if (!$sql) { - $result = $db->sql_query($sql); - - extract($db->sql_fetchrow($result)); - $db->sql_freeresult($result); - - if ($mode == 'popup') - { - upload_popup($forum_style); - exit; - } - - $quote_username = (isset($username)) ? $username : ((isset($post_username)) ? $post_username : ''); - - $forum_id = (int) $forum_id; - $topic_id = (int) $topic_id; - $post_id = (int) $post_id; - - // Global Topic? - Adjust forum id - if (!$forum_id && $topic_type == POST_GLOBAL) - { - $forum_id = request_var('f', 0); - } - - $post_edit_locked = (isset($post_edit_locked)) ? (int) $post_edit_locked : 0; - - $user->setup(array('posting', 'mcp', 'viewtopic'), $forum_style); - - if ($forum_password) - { - $forum_info = array( - 'forum_id' => $forum_id, - 'forum_password'=> $forum_password - ); - - login_forum_box($forum_info); - unset($forum_info); - } - - $post_subject = (in_array($mode, array('quote', 'edit', 'delete'))) ? $post_subject : ((isset($topic_title)) ? $topic_title : ''); - - $topic_time_limit = (isset($topic_time_limit)) ? (($topic_time_limit) ? (int) $topic_time_limit / 86400 : (int) $topic_time_limit) : 0; - - $poll_length = (isset($poll_length)) ? (($poll_length) ? (int) $poll_length / 86400 : (int) $poll_length) : 0; - $poll_start = (isset($poll_start)) ? (int) $poll_start : 0; - $poll_options = array(); - - if (!isset($icon_id) || in_array($mode, array('quote', 'reply'))) - { - $icon_id = 0; - } - - // Get Poll Data - if ($poll_start) - { - $sql = 'SELECT poll_option_text - FROM ' . POLL_OPTIONS_TABLE . " - WHERE topic_id = $topic_id - ORDER BY poll_option_id"; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - $poll_options[] = trim($row['poll_option_text']); - } - $db->sql_freeresult($result); - } - - $orig_poll_options_size = sizeof($poll_options); - $message_parser = new parse_message(); - - if (isset($post_text)) - { - $message_parser->message = $post_text; - unset($post_text); - } - - $message_parser->get_submitted_attachment_data(); - - // Set uninitialized variables - $uninit = array('post_attachment' => 0, 'poster_id' => 0, 'enable_magic_url' => 0, 'topic_status' => 0, 'topic_type' => POST_NORMAL, 'subject' => '', 'topic_title' => '', 'post_time' => 0, 'post_edit_reason' => ''); - foreach ($uninit as $var_name => $default_value) - { - if (!isset($$var_name)) - { - $$var_name = $default_value; - } - } - unset($uninit, $var_name, $default_value); - - if ($post_attachment && !$submit && !$refresh && !$preview && $mode == 'edit') - { - $sql = 'SELECT attach_id, physical_filename, comment, real_filename, extension, mimetype, filesize, filetime, thumbnail - FROM ' . ATTACHMENTS_TABLE . " - WHERE post_msg_id = $post_id - AND in_message = 0 - ORDER BY filetime " . ((!$config['display_order']) ? 'DESC' : 'ASC'); - $result = $db->sql_query($sql); - - $message_parser->attachment_data = array_merge($message_parser->attachment_data, $db->sql_fetchrowset($result)); - - $db->sql_freeresult($result); - } - - if ($poster_id == ANONYMOUS || !$poster_id) - { - $username = (in_array($mode, array('quote', 'edit', 'delete'))) ? trim($post_username) : ''; - } - else - { - $username = (in_array($mode, array('quote', 'edit', 'delete'))) ? trim($username) : ''; - } - - $enable_urls = $enable_magic_url; - - if (!in_array($mode, array('quote', 'edit', 'delete'))) - { - $enable_sig = ($config['allow_sig'] && $user->optionget('attachsig')); - $enable_smilies = ($config['allow_smilies'] && $user->optionget('smilies')); - $enable_bbcode = ($config['allow_bbcode'] && $user->optionget('bbcode')); - $enable_urls = true; - } + trigger_error('NO_POST_MODE'); +} - $enable_magic_url = $drafts = false; +$result = $db->sql_query($sql); +$post_data = $db->sql_fetchrow($result); +$db->sql_freeresult($result); - // User own some drafts? - if ($user->data['is_registered'] && $auth->acl_get('u_savedrafts') && $mode != 'delete') - { - $sql = 'SELECT draft_id - FROM ' . DRAFTS_TABLE . ' - WHERE (forum_id IN (' . $forum_id . ', 0)' . (($topic_id) ? " OR topic_id = $topic_id" : '') . ') - AND user_id = ' . $user->data['user_id'] . - (($draft_id) ? " AND draft_id <> $draft_id" : ''); - $result = $db->sql_query_limit($sql, 1); - - if ($db->sql_fetchrow($result)) - { - $drafts = true; - } - $db->sql_freeresult($result); - } +$user->setup(array('posting', 'mcp', 'viewtopic'), $post_data['forum_style']); - $check_value = (($enable_bbcode+1) << 8) + (($enable_smilies+1) << 4) + (($enable_urls+1) << 2) + (($enable_sig+1) << 1); -} - -// Notify user checkbox -if ($mode != 'post' && $user->data['is_registered']) +if ($mode == 'popup') { - $sql = 'SELECT topic_id - FROM ' . TOPICS_WATCH_TABLE . ' - WHERE topic_id = ' . $topic_id . ' - AND user_id = ' . $user->data['user_id']; - $result = $db->sql_query_limit($sql, 1); - $notify_set = ($db->sql_fetchrow($result)) ? 1 : 0; - $db->sql_freeresult($result); + upload_popup($post_data['forum_style']); + exit; } -else + +// Use post_row values in favor of submitted ones... +$forum_id = (!empty($post_data['forum_id'])) ? (int) $post_data['forum_id'] : (int) $forum_id; +$topic_id = (!empty($post_data['topic_id'])) ? (int) $post_data['topic_id'] : (int) $topic_id; +$post_id = (!empty($post_data['post_id'])) ? (int) $post_data['post_id'] : (int) $post_id; + +// Need to login to passworded forum first? +if ($post_data['forum_password']) { - $notify_set = 0; + login_forum_box(array( + 'forum_id' => $forum_id, + 'forum_password' => $post_data['forum_password']) + ); } // Check permissions -if ($forum_type != FORUM_POST && !$auth->acl_get('f_read', $forum_id)) + +// Is the user able to read within this forum? +if (!$auth->acl_get('f_read', $forum_id)) { if ($user->data['is_registered']) { @@ -297,9 +168,9 @@ if ($forum_type != FORUM_POST && !$auth->acl_get('f_read', $forum_id)) login_box('', $user->lang['LOGIN_EXPLAIN_POST']); } +// Permission to do the action asked? $check_auth = ($mode == 'quote') ? 'reply' : $mode; - -if (!$auth->acl_get('f_' . $check_auth, $forum_id) && $forum_type == FORUM_POST) +if (!$auth->acl_get('f_' . $check_auth, $forum_id)) { if ($user->data['is_registered']) { @@ -309,187 +180,248 @@ if (!$auth->acl_get('f_' . $check_auth, $forum_id) && $forum_type == FORUM_POST) login_box('', $user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)]); } +// Is the user able to post within this forum? +if ($post_data['forum_type'] != FORUM_POST && in_array($mode, array('post', 'bump', 'quote', 'reply'))) +{ + trigger_error('USER_CANNOT_FORUM_POST'); +} + // Forum/Topic locked? -if (($forum_status == ITEM_LOCKED || $topic_status == ITEM_LOCKED) && !$auth->acl_get('m_edit', $forum_id)) +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)) { - $message = ($forum_status == ITEM_LOCKED) ? 'FORUM_LOCKED' : 'TOPIC_LOCKED'; - trigger_error($message); + trigger_error(($post_data['forum_status'] == ITEM_LOCKED) ? 'FORUM_LOCKED' : 'TOPIC_LOCKED'); } // Can we edit this post ... if we're a moderator with rights then always yes // else it depends on editing times, lock status and if we're the correct user -// !$preview && !$refresh && !$submit && -if ($mode == 'edit' && !$preview && !$refresh && !$submit && !$auth->acl_get('m_edit', $forum_id)) +if ($mode == 'edit' && !$auth->acl_get('m_edit', $forum_id)) { - if ($user->data['user_id'] != $poster_id) + if ($user->data['user_id'] != $post_data['poster_id']) { trigger_error('USER_CANNOT_EDIT'); } - if (!($post_time > time() - $config['edit_time'] || !$config['edit_time'])) + if (!($post_data['post_time'] > time() - $config['edit_time'] || !$config['edit_time'])) { trigger_error('CANNOT_EDIT_TIME'); } - if ($post_edit_locked) + if ($post_data['post_edit_locked']) { trigger_error('CANNOT_EDIT_POST_LOCKED'); } } -// Do we want to edit our post ? - -if ($mode == 'edit') +// Handle delete mode... +if ($mode == 'delete') { - $message_parser->bbcode_uid = $bbcode_uid; + handle_post_delete($forum_id, $topic_id, $post_id, $post_data); + exit; } - -// Delete triggered ? -if ($mode == 'delete' && (($poster_id == $user->data['user_id'] && $user->data['is_registered'] && $auth->acl_get('f_delete', $forum_id) && $post_id == $topic_last_post_id) || $auth->acl_get('m_delete', $forum_id))) +// Handle bump mode... +if ($mode == 'bump') { - $s_hidden_fields = build_hidden_fields(array( - 'p' => $post_id, - 'f' => $forum_id, - 'mode' => 'delete') - ); - - if (confirm_box(true)) + 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'])) { - $data = array( - 'topic_first_post_id' => $topic_first_post_id, - 'topic_last_post_id' => $topic_last_post_id, - 'topic_approved' => $topic_approved, - 'topic_type' => $topic_type, - 'post_approved' => $post_approved, - 'post_time' => $post_time, - 'poster_id' => $poster_id - ); + $db->sql_transaction(); - $next_post_id = delete_post($mode, $post_id, $topic_id, $forum_id, $data); + $db->sql_query('UPDATE ' . POSTS_TABLE . " + SET post_time = $current_time + WHERE post_id = {$post_data['topic_last_post_id']} + AND topic_id = $topic_id"); - if ($topic_first_post_id == $topic_last_post_id) - { - add_log('mod', $forum_id, $topic_id, 'LOG_DELETE_TOPIC', $topic_title); + $db->sql_query('UPDATE ' . TOPICS_TABLE . " + SET topic_last_post_time = $current_time, + topic_bumped = 1, + topic_bumper = " . $user->data['user_id'] . " + WHERE topic_id = $topic_id"); - $meta_info = "{$phpbb_root_path}viewforum.$phpEx$SID&f=$forum_id"; - $message = $user->lang['POST_DELETED']; - } - else - { - add_log('mod', $forum_id, $topic_id, 'LOG_DELETE_POST', $post_subject); + update_post_information('forum', $forum_id); - $meta_info = "{$phpbb_root_path}viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&p=$next_post_id#p$next_post_id"; - $message = $user->lang['POST_DELETED'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], "<a href=\"{$phpbb_root_path}viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&p=$next_post_id#p$next_post_id\">", '</a>'); - } + $db->sql_query('UPDATE ' . USERS_TABLE . " + SET user_lastpost_time = $current_time + WHERE user_id = " . $user->data['user_id']); + + $db->sql_transaction('commit'); + + markread('post', $forum_id, $topic_id, $current_time); + + add_log('mod', $forum_id, $topic_id, sprintf($user->lang['LOGM_BUMP'], $post_data['topic_title'])); + + $meta_url = "{$phpbb_root_path}viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&p={$post_data['topic_last_post_id']}#p{$post_data['topic_last_post_id']}"; + meta_refresh(3, $meta_url); + + $message = $user->lang['TOPIC_BUMPED'] . '<br /><br />' . sprintf($user->lang['VIEW_MESSAGE'], '<a href="' . $meta_url . '">', '</a>'); + $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $phpbb_root_path . 'viewforum.' . $phpEx . $SID .'&f=' . $forum_id . '">', '</a>'); - meta_refresh(3, $meta_info); - $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], "<a href=\"{$phpbb_root_path}viewforum.$phpEx$SID&f=$forum_id\">", '</a>'); trigger_error($message); } - else + + trigger_error('BUMP_ERROR'); +} + + +// Determine some vars +$post_data['quote_username'] = (!empty($post_data['username'])) ? $post_data['username'] : ((!empty($post_data['post_username'])) ? $post_data['post_username'] : ''); +$post_data['post_edit_locked'] = (isset($post_data['post_edit_locked'])) ? (int) $post_data['post_edit_locked'] : 0; +$post_data['post_subject'] = (in_array($mode, array('quote', 'edit'))) ? $post_data['post_subject'] : ((isset($post_data['topic_title'])) ? $post_data['topic_title'] : ''); +$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; +$post_data['poll_length'] = (!empty($post_data['poll_length'])) ? (int) $post_data['poll_length'] / 86400 : 0; +$post_data['poll_start'] = (!empty($post_data['poll_start'])) ? (int) $post_data['poll_start'] : 0; +$post_data['icon_id'] = (!isset($post_data['icon_id']) || in_array($mode, array('quote', 'reply'))) ? 0 : (int) $post_data['icon_id']; +$post_data['poll_options'] = array(); + +// Get Poll Data +if ($post_data['poll_start']) +{ + $sql = 'SELECT poll_option_text + FROM ' . POLL_OPTIONS_TABLE . " + WHERE topic_id = $topic_id + ORDER BY poll_option_id"; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) { - confirm_box(false, 'DELETE_MESSAGE', $s_hidden_fields); + $post_data['poll_options'][] = trim($row['poll_option_text']); } + $db->sql_freeresult($result); } +$orig_poll_options_size = sizeof($post_data['poll_options']); -if ($mode == 'delete' && $poster_id != $user->data['user_id'] && !$auth->acl_get('f_delete', $forum_id)) +$message_parser = new parse_message(); + +if (isset($post_data['post_text'])) { - trigger_error('DELETE_OWN_POSTS'); + $message_parser->message = &$post_data['post_text']; + unset($post_data['post_text']); } -if ($mode == 'delete' && $poster_id == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id) && $post_id != $topic_last_post_id) +$message_parser->get_submitted_attachment_data(); + +// Set some default variables +$uninit = array('post_attachment' => 0, 'poster_id' => $user->data['user_id'], 'enable_magic_url' => 0, 'topic_status' => 0, 'topic_type' => POST_NORMAL, 'subject' => '', 'topic_title' => '', 'post_time' => 0, 'post_edit_reason' => '', 'notify_set' => 0); +foreach ($uninit as $var_name => $default_value) { - trigger_error('CANNOT_DELETE_REPLIED'); + if (!isset($post_data[$var_name])) + { + $post_data[$var_name] = $default_value; + } } +unset($uninit); -if ($mode == 'delete') +if ($post_data['post_attachment'] && !$submit && !$refresh && !$preview && $mode == 'edit') { - trigger_error('USER_CANNOT_DELETE'); + $sql = 'SELECT attach_id, physical_filename, comment, real_filename, extension, mimetype, filesize, filetime, thumbnail + FROM ' . ATTACHMENTS_TABLE . " + WHERE post_msg_id = $post_id + AND in_message = 0 + ORDER BY filetime " . ((!$config['display_order']) ? 'DESC' : 'ASC'); + $result = $db->sql_query($sql); + $message_parser->attachment_data = array_merge($message_parser->attachment_data, $db->sql_fetchrowset($result)); + $db->sql_freeresult($result); } - -// HTML, BBCode, Smilies, Images and Flash status -$bbcode_status = ($config['allow_bbcode'] && $auth->acl_get('f_bbcode', $forum_id)); -$smilies_status = ($config['allow_smilies'] && $auth->acl_get('f_smilies', $forum_id)); -$img_status = ($auth->acl_get('f_img', $forum_id)); -$flash_status = ($auth->acl_get('f_flash', $forum_id)); -$quote_status = ($auth->acl_get('f_reply', $forum_id)); - -// Bump Topic -if ($mode == 'bump' && ($bump_time = bump_topic_allowed($forum_id, $topic_bumped, $topic_last_post_time, $topic_poster, $topic_last_poster_id))) +if ($post_data['poster_id'] == ANONYMOUS) { - $db->sql_transaction(); - - $db->sql_query('UPDATE ' . POSTS_TABLE . " - SET post_time = $current_time - WHERE post_id = $topic_last_post_id - AND topic_id = $topic_id"); - - $db->sql_query('UPDATE ' . TOPICS_TABLE . " - SET topic_last_post_time = $current_time, - topic_bumped = 1, - topic_bumper = " . $user->data['user_id'] . " - WHERE topic_id = $topic_id"); - - update_post_information('forum', $forum_id); + $post_data['username'] = ($mode == 'quote' || $mode == 'edit') ? trim($post_data['post_username']) : ''; +} +else +{ + $post_data['username'] = ($mode == 'quote' || $mode == 'edit') ? trim($post_data['username']) : ''; +} - $db->sql_query('UPDATE ' . USERS_TABLE . " - SET user_lastpost_time = $current_time - WHERE user_id = " . $user->data['user_id']); +$post_data['enable_urls'] = $post_data['enable_magic_url']; - $db->sql_transaction('commit'); +if ($mode != 'edit') +{ + $post_data['enable_sig'] = ($config['allow_sig'] && $user->optionget('attachsig')) ? true: false; + $post_data['enable_smilies'] = ($config['allow_smilies'] && $user->optionget('smilies')) ? true : false; + $post_data['enable_bbcode'] = ($config['allow_bbcode'] && $user->optionget('bbcode')) ? true : false; + $post_data['enable_urls'] = true; +} - markread('post', $forum_id, $topic_id, $current_time); +$post_data['enable_magic_url'] = $post_data['drafts'] = false; - add_log('mod', $forum_id, $topic_id, sprintf($user->lang['LOGM_BUMP'], $topic_title)); +// User own some drafts? +if ($user->data['is_registered'] && $auth->acl_get('u_savedrafts')) +{ + $sql = 'SELECT draft_id + FROM ' . DRAFTS_TABLE . ' + WHERE (forum_id IN (' . $forum_id . ', 0)' . (($topic_id) ? " OR topic_id = $topic_id" : '') . ') + AND user_id = ' . $user->data['user_id'] . + (($draft_id) ? " AND draft_id <> $draft_id" : ''); + $result = $db->sql_query_limit($sql, 1); - meta_refresh(3, "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&p=$topic_last_post_id#p$topic_last_post_id"); + if ($db->sql_fetchrow($result)) + { + $post_data['drafts'] = true; + } + $db->sql_freeresult($result); +} - $message = $user->lang['TOPIC_BUMPED'] . '<br /><br />' . sprintf($user->lang['VIEW_MESSAGE'], '<a href="viewtopic.' . $phpEx . $SID . "&f=$forum_id&t=$topic_id&p=$topic_last_post_id#p$topic_last_post_id\">", '</a>') . '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="viewforum.' . $phpEx . $SID .'&f=' . $forum_id . '">', '</a>'); +$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); - trigger_error($message); +// Check if user is watching this topic +if ($mode != 'post') +{ + $sql = 'SELECT topic_id + FROM ' . TOPICS_WATCH_TABLE . ' + WHERE topic_id = ' . $topic_id . ' + AND user_id = ' . $user->data['user_id']; + $result = $db->sql_query($sql); + $post_data['notify_set'] = (int) $db->sql_fetchfield('topic_id'); + $db->sql_freeresult($result); } -else if ($mode == 'bump') + +// Do we want to edit our post ? +if ($mode == 'edit') { - trigger_error('BUMP_ERROR'); + $message_parser->bbcode_uid = $post_data['bbcode_uid']; } +// HTML, BBCode, Smilies, Images and Flash status +$bbcode_status = ($config['allow_bbcode'] && $auth->acl_get('f_bbcode', $forum_id)) ? true : false; +$smilies_status = ($config['allow_smilies'] && $auth->acl_get('f_smilies', $forum_id)) ? true : false; +$img_status = ($auth->acl_get('f_img', $forum_id)) ? true : false; +$flash_status = ($auth->acl_get('f_flash', $forum_id)) ? true : false; +$quote_status = ($auth->acl_get('f_reply', $forum_id)) ? true : false; + // Save Draft if ($save && $user->data['is_registered'] && $auth->acl_get('u_savedrafts')) { $subject = request_var('subject', '', true); - $subject = (!$subject && $mode != 'post') ? $topic_title : $subject; + $subject = (!$subject && $mode != 'post') ? $post_data['topic_title'] : $subject; $message = request_var('message', '', true); if ($subject && $message) { $sql = 'INSERT INTO ' . DRAFTS_TABLE . ' ' . $db->sql_build_array('INSERT', array( - 'user_id' => $user->data['user_id'], - 'topic_id' => $topic_id, - 'forum_id' => $forum_id, - 'save_time' => $current_time, - 'draft_subject' => $subject, - 'draft_message' => $message)); + 'user_id' => $user->data['user_id'], + 'topic_id' => $topic_id, + 'forum_id' => $forum_id, + 'save_time' => $current_time, + 'draft_subject' => $subject, + 'draft_message' => $message) + ); $db->sql_query($sql); - $meta_info = ($mode == 'post') ? "viewforum.$phpEx$SID&f=$forum_id" : "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id"; + $meta_info = ($mode == 'post') ? "{$phpbb_root_path}viewforum.$phpEx$SID&f=$forum_id" : "{$phpbb_root_path}viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id"; meta_refresh(3, $meta_info); $message = $user->lang['DRAFT_SAVED'] . '<br /><br />'; $message .= ($mode != 'post') ? sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $meta_info . '">', '</a>') . '<br /><br />' : ''; - $message .= sprintf($user->lang['RETURN_FORUM'], '<a href="viewforum.' . $phpEx . $SID . '&f=' . $forum_id . '">', '</a>'); + $message .= sprintf($user->lang['RETURN_FORUM'], '<a href="' . $phpbb_root_path . 'viewforum.' . $phpEx . $SID . '&f=' . $forum_id . '">', '</a>'); trigger_error($message); } - unset($subject); - unset($message); + unset($subject, $message); } -// Load Draft +// Load requested Draft if ($draft_id && $user->data['is_registered'] && $auth->acl_get('u_savedrafts')) { $sql = 'SELECT draft_subject, draft_message @@ -497,8 +429,10 @@ if ($draft_id && $user->data['is_registered'] && $auth->acl_get('u_savedrafts')) WHERE draft_id = $draft_id AND user_id = " . $user->data['user_id']; $result = $db->sql_query_limit($sql, 1); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); - if ($row = $db->sql_fetchrow($result)) + if ($row) { $_REQUEST['subject'] = html_entity_decode($row['draft_subject']); $_REQUEST['message'] = html_entity_decode($row['draft_message']); @@ -511,45 +445,45 @@ if ($draft_id && $user->data['is_registered'] && $auth->acl_get('u_savedrafts')) } } -// Load Drafts -if ($load && $drafts) +// Load draft overview +if ($load && $post_data['drafts']) { load_drafts($topic_id, $forum_id); } if ($submit || $preview || $refresh) { - $topic_cur_post_id = request_var('topic_cur_post_id', 0); - $subject = request_var('subject', '', true); + $post_data['topic_cur_post_id'] = request_var('topic_cur_post_id', 0); + $post_data['subject'] = request_var('subject', '', true); - if (strcmp($subject, strtoupper($subject)) == 0 && $subject) + // If subject is all-uppercase then we make all lowercase (we do not want to be yelled at too :P) + if ($post_data['subject'] && strcmp($post_data['subject'], strtoupper($post_data['subject'])) == 0) { - $subject = strtolower($subject); + $post_data['subject'] = strtolower($post_data['subject']); } $message_parser->message = request_var('message', '', true); - $username = (isset($_POST['username'])) ? request_var('username', '', true) : $username; - $post_edit_reason = (!empty($_POST['edit_reason']) && $mode == 'edit' && $auth->acl_get('m_edit', $forum_id)) ? request_var('edit_reason', '', true) : ''; - - $topic_type = (isset($_POST['topic_type'])) ? (int) $_POST['topic_type'] : (($mode != 'post') ? $topic_type : POST_NORMAL); - $topic_time_limit = (isset($_POST['topic_time_limit'])) ? (int) $_POST['topic_time_limit'] : (($mode != 'post') ? $topic_time_limit : 0); - $icon_id = request_var('icon', 0); + $post_data['username'] = request_var('username', $post_data['username'], true); + $post_data['post_edit_reason'] = (!empty($_POST['edit_reason']) && $mode == 'edit' && $auth->acl_get('m_edit', $forum_id)) ? request_var('edit_reason', '', true) : ''; - $enable_bbcode = (!$bbcode_status || isset($_POST['disable_bbcode'])) ? false : true; - $enable_smilies = (!$smilies_status || isset($_POST['disable_smilies'])) ? false : true; - $enable_urls = (isset($_POST['disable_magic_url'])) ? 0 : 1; - $enable_sig = (!$config['allow_sig']) ? false : ((isset($_POST['attach_sig']) && $user->data['is_registered']) ? true : false); + $post_data['topic_type'] = request_var('topic_type', (($mode != 'post') ? (int) $post_data['topic_type'] : POST_NORMAL)); + $post_data['topic_time_limit'] = request_var('topic_time_limit', (($mode != 'post') ? (int) $post_data['topic_time_limit'] : 0)); + $post_data['icon_id'] = request_var('icon', 0); - $notify = (isset($_POST['notify'])); - $topic_lock = (isset($_POST['lock_topic'])); - $post_lock = (isset($_POST['lock_post'])); + $post_data['enable_bbcode'] = (!$bbcode_status || isset($_POST['disable_bbcode'])) ? false : true; + $post_data['enable_smilies'] = (!$smilies_status || isset($_POST['disable_smilies'])) ? false : true; + $post_data['enable_urls'] = (isset($_POST['disable_magic_url'])) ? 0 : 1; + $post_data['enable_sig'] = (!$config['allow_sig']) ? false : ((isset($_POST['attach_sig']) && $user->data['is_registered']) ? true : false); - $poll_delete = (isset($_POST['poll_delete'])); + $notify = (isset($_POST['notify'])) ? true : false; + $topic_lock = (isset($_POST['lock_topic'])) ? true : false; + $post_lock = (isset($_POST['lock_post'])) ? true : false; + $poll_delete = (isset($_POST['poll_delete'])) ? true : false; if ($submit) { - $status_switch = (($enable_bbcode+1) << 8) + (($enable_smilies+1) << 4) + (($enable_urls+1) << 2) + (($enable_sig+1) << 1); + $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); $status_switch = ($status_switch != $check_value); } else @@ -558,8 +492,8 @@ if ($submit || $preview || $refresh) } // Delete Poll - if ($poll_delete && $mode == 'edit' && $poll_options && - ((!$poll_last_vote && $poster_id == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id)) || $auth->acl_get('m_delete', $forum_id))) + if ($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))) { switch (SQL_LAYER) { @@ -578,6 +512,7 @@ if ($submit || $preview || $refresh) $sql = 'DELETE FROM ' . POLL_VOTES_TABLE . " WHERE topic_id = $topic_id"; $db->sql_query($sql); + break; } $topic_sql = array( @@ -594,27 +529,28 @@ if ($submit || $preview || $refresh) WHERE topic_id = $topic_id"; $db->sql_query($sql); - $poll_title = $poll_option_text = ''; - $poll_vote_change = $poll_max_options = $poll_length = 0; + $post_data['poll_title'] = $post_data['poll_option_text'] = ''; + $post_data['poll_vote_change'] = $post_data['poll_max_options'] = $post_data['poll_length'] = 0; } else { - $poll_title = request_var('poll_title', '', true); - $poll_length = request_var('poll_length', 0); - $poll_option_text = request_var('poll_option_text', '', true); - $poll_max_options = request_var('poll_max_options', 1); - $poll_vote_change = ($auth->acl_get('f_votechg', $forum_id) && isset($_POST['poll_vote_change'])) ? 1 : 0; + $post_data['poll_title'] = request_var('poll_title', '', true); + $post_data['poll_length'] = request_var('poll_length', 0); + $post_data['poll_option_text'] = request_var('poll_option_text', '', true); + $post_data['poll_max_options'] = request_var('poll_max_options', 1); + $post_data['poll_vote_change'] = ($auth->acl_get('f_votechg', $forum_id) && isset($_POST['poll_vote_change'])) ? 1 : 0; } // If replying/quoting and last post id has changed // give user option to continue submit or return to post // notify and show user the post made between his request and the final submit - if (($mode == 'reply' || $mode == 'quote') && $topic_cur_post_id && $topic_cur_post_id != $topic_last_post_id) + if (($mode == 'reply' || $mode == 'quote') && $post_data['topic_cur_post_id'] && $post_data['topic_cur_post_id'] != $post_data['topic_last_post_id']) { - if (topic_review($topic_id, $forum_id, 'post_review', $topic_cur_post_id)) + if (topic_review($topic_id, $forum_id, 'post_review', $post_data['topic_cur_post_id'])) { $template->assign_var('S_POST_REVIEW', true); } + $submit = false; $refresh = true; } @@ -626,16 +562,16 @@ if ($submit || $preview || $refresh) $message_md5 = md5($message_parser->message); // Check checksum ... don't re-parse message if the same - $update_message = ($mode != 'edit' || $message_md5 != $post_checksum || $status_switch) ? true : false; + $update_message = ($mode != 'edit' || $message_md5 != $post_data['post_checksum'] || $status_switch) ? true : false; // Parse message if ($update_message) { - $message_parser->parse($enable_bbcode, $enable_urls, $enable_smilies, $img_status, $flash_status, $quote_status); + $message_parser->parse($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies'], $img_status, $flash_status, $quote_status); } else { - $message_parser->bbcode_bitfield = $bbcode_bitfield; + $message_parser->bbcode_bitfield = $post_data['bbcode_bitfield']; } if ($mode != 'edit' && !$preview && !$refresh && $config['flood_interval'] && !$auth->acl_get('f_ignoreflood', $forum_id)) @@ -661,27 +597,24 @@ if ($submit || $preview || $refresh) $db->sql_freeresult($result); } - if ($last_post_time) + if ($last_post_time && ($current_time - $last_post_time) < intval($config['flood_interval'])) { - if ($last_post_time && ($current_time - $last_post_time) < intval($config['flood_interval'])) - { - $error[] = $user->lang['FLOOD_ERROR']; - } + $error[] = $user->lang['FLOOD_ERROR']; } } // Validate username - if (($username && !$user->data['is_registered']) || ($mode == 'edit' && $post_username)) + if (($post_data['username'] && !$user->data['is_registered']) || ($mode == 'edit' && $post_data['post_username'])) { include($phpbb_root_path . 'includes/functions_user.' . $phpEx); - if (($result = validate_username(($mode == 'edit' && $post_username) ? $post_username : $username)) != false) + if (($result = validate_username(($mode == 'edit' && $post_data['post_username']) ? $post_data['post_username'] : $post_data['username'])) != false) { $error[] = $result; } } - if ($config['enable_post_confirm'] && !$user->data['is_registered'] && ($mode == 'post' || $mode == 'reply')) + if ($config['enable_post_confirm'] && !$user->data['is_registered'] && in_array($mode, array('quote', 'post', 'reply'))) { $confirm_id = request_var('confirm_id', ''); $confirm_code = request_var('confirm_code', ''); @@ -702,37 +635,37 @@ if ($submit || $preview || $refresh) } // Parse subject - if (!$subject && ($mode == 'post' || ($mode == 'edit' && $topic_first_post_id == $post_id))) + if (!$post_data['subject'] && ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_id))) { $error[] = $user->lang['EMPTY_SUBJECT']; } - $poll_last_vote = (isset($poll_last_vote)) ? $poll_last_vote : 0; + $post_data['poll_last_vote'] = (isset($post_data['poll_last_vote'])) ? $post_data['poll_last_vote'] : 0; - if ($poll_option_text && - ($mode == 'post' || ($mode == 'edit' && $post_id == $topic_first_post_id && (!$poll_last_vote || $auth->acl_get('m_edit', $forum_id)))) + if ($post_data['poll_option_text'] && + ($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id'] && (!$post_data['poll_last_vote'] || $auth->acl_get('m_edit', $forum_id)))) && $auth->acl_get('f_poll', $forum_id)) { $poll = array( - 'poll_title' => $poll_title, - 'poll_length' => $poll_length, - 'poll_max_options' => $poll_max_options, - 'poll_option_text' => $poll_option_text, - 'poll_start' => $poll_start, - 'poll_last_vote' => $poll_last_vote, - 'poll_vote_change' => $poll_vote_change, - 'enable_bbcode' => $enable_bbcode, - 'enable_urls' => $enable_urls, - 'enable_smilies' => $enable_smilies, + 'poll_title' => $post_data['poll_title'], + 'poll_length' => $post_data['poll_length'], + 'poll_max_options' => $post_data['poll_max_options'], + 'poll_option_text' => $post_data['poll_option_text'], + 'poll_start' => $post_data['poll_start'], + 'poll_last_vote' => $post_data['poll_last_vote'], + 'poll_vote_change' => $post_data['poll_vote_change'], + 'enable_bbcode' => $post_data['enable_bbcode'], + 'enable_urls' => $post_data['enable_urls'], + 'enable_smilies' => $post_data['enable_smilies'], 'img_status' => $img_status ); $message_parser->parse_poll($poll); - $poll_options = isset($poll['poll_options']) ? $poll['poll_options'] : ''; - $poll_title = isset($poll['poll_title']) ? $poll['poll_title'] : ''; + $post_data['poll_options'] = (isset($poll['poll_options'])) ? $poll['poll_options'] : ''; + $post_data['poll_title'] = (isset($poll['poll_title'])) ? $poll['poll_title'] : ''; - if ($poll_last_vote && ($poll['poll_options_size'] < $orig_poll_options_size)) + if ($post_data['poll_last_vote'] && ($poll['poll_options_size'] < $orig_poll_options_size)) { $message_parser->warn_msg[] = $user->lang['NO_DELETE_POLL_OPTIONS']; } @@ -743,9 +676,9 @@ if ($submit || $preview || $refresh) } // Check topic type - if ($topic_type != POST_NORMAL && ($mode == 'post' || ($mode == 'edit' && $topic_first_post_id == $post_id))) + if ($post_data['topic_type'] != POST_NORMAL && ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_id))) { - switch ($topic_type) + switch ($post_data['topic_type']) { case POST_GLOBAL: case POST_ANNOUNCE: @@ -758,6 +691,7 @@ if ($submit || $preview || $refresh) default: $auth_option = ''; + break; } if (!$auth->acl_get($auth_option, $forum_id)) @@ -775,14 +709,14 @@ if ($submit || $preview || $refresh) if (!sizeof($error) && $submit) { // Check if we want to de-globalize the topic... and ask for new forum - if ($topic_type != POST_GLOBAL) + if ($post_data['topic_type'] != POST_GLOBAL) { $sql = 'SELECT topic_type, forum_id FROM ' . TOPICS_TABLE . " WHERE topic_id = $topic_id"; $result = $db->sql_query_limit($sql, 1); - $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); if ($row && !$row['forum_id'] && $row['topic_type'] == POST_GLOBAL) { @@ -810,19 +744,19 @@ if ($submit || $preview || $refresh) if ($submit) { // Lock/Unlock Topic - $change_topic_status = $topic_status; - $perm_lock_unlock = ($auth->acl_get('m_lock', $forum_id) || ($auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && $user->data['user_id'] == $topic_poster)); + $change_topic_status = $post_data['topic_status']; + $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'])); - if ($topic_status == ITEM_LOCKED && !$topic_lock && $perm_lock_unlock) + if ($post_data['topic_status'] == ITEM_LOCKED && !$topic_lock && $perm_lock_unlock) { $change_topic_status = ITEM_UNLOCKED; } - else if ($topic_status == ITEM_UNLOCKED && $topic_lock && $perm_lock_unlock) + else if ($post_data['topic_status'] == ITEM_UNLOCKED && $topic_lock && $perm_lock_unlock) { $change_topic_status = ITEM_LOCKED; } - if ($change_topic_status != $topic_status) + if ($change_topic_status != $post_data['topic_status']) { $sql = 'UPDATE ' . TOPICS_TABLE . " SET topic_status = $change_topic_status @@ -830,47 +764,47 @@ if ($submit || $preview || $refresh) AND topic_moved_id = 0"; $db->sql_query($sql); - $user_lock = ($auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && $user->data['user_id'] == $topic_poster) ? 'USER_' : ''; + $user_lock = ($auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && $user->data['user_id'] == $post_data['topic_poster']) ? 'USER_' : ''; - add_log('mod', $forum_id, $topic_id, 'LOG_' . $user_lock . (($change_topic_status == ITEM_LOCKED) ? 'LOCK' : 'UNLOCK'), $topic_title); + add_log('mod', $forum_id, $topic_id, 'LOG_' . $user_lock . (($change_topic_status == ITEM_LOCKED) ? 'LOCK' : 'UNLOCK'), $post_data['topic_title']); } // Lock/Unlock Post Edit - if ($mode == 'edit' && $post_edit_locked == ITEM_LOCKED && !$post_lock && $auth->acl_get('m_edit', $forum_id)) + if ($mode == 'edit' && $post_data['post_edit_locked'] == ITEM_LOCKED && !$post_lock && $auth->acl_get('m_edit', $forum_id)) { - $post_edit_locked = ITEM_UNLOCKED; + $post_data['post_edit_locked'] = ITEM_UNLOCKED; } - else if ($mode == 'edit' && $post_edit_locked == ITEM_UNLOCKED && $post_lock && $auth->acl_get('m_edit', $forum_id)) + else if ($mode == 'edit' && $post_data['post_edit_locked'] == ITEM_UNLOCKED && $post_lock && $auth->acl_get('m_edit', $forum_id)) { - $post_edit_locked = ITEM_LOCKED; + $post_data['post_edit_locked'] = ITEM_LOCKED; } - $post_data = array( - 'topic_title' => (!$topic_title) ? $subject : $topic_title, - 'topic_first_post_id' => (isset($topic_first_post_id)) ? (int) $topic_first_post_id : 0, - 'topic_last_post_id' => (isset($topic_last_post_id)) ? (int) $topic_last_post_id : 0, - 'topic_time_limit' => (int) $topic_time_limit, + $data = array( + 'topic_title' => (empty($post_data['topic_title'])) ? $post_data['subject'] : $post_data['topic_title'], + 'topic_first_post_id' => (isset($post_data['topic_first_post_id'])) ? (int) $post_data['topic_first_post_id'] : 0, + 'topic_last_post_id' => (isset($post_data['topic_last_post_id'])) ? (int) $post_data['topic_last_post_id'] : 0, + 'topic_time_limit' => (int) $post_data['topic_time_limit'], 'post_id' => (int) $post_id, 'topic_id' => (int) $topic_id, 'forum_id' => (int) $forum_id, - 'icon_id' => (int) $icon_id, - 'poster_id' => (int) $poster_id, - 'enable_sig' => (bool) $enable_sig, - 'enable_bbcode' => (bool) $enable_bbcode, - 'enable_smilies' => (bool) $enable_smilies, - 'enable_urls' => (bool) $enable_urls, - 'enable_indexing' => (bool) $enable_indexing, + 'icon_id' => (int) $post_data['icon_id'], + 'poster_id' => (int) $post_data['poster_id'], + 'enable_sig' => (bool) $post_data['enable_sig'], + 'enable_bbcode' => (bool) $post_data['enable_bbcode'], + 'enable_smilies' => (bool) $post_data['enable_smilies'], + 'enable_urls' => (bool) $post_data['enable_urls'], + 'enable_indexing' => (bool) $post_data['enable_indexing'], 'message_md5' => (string) $message_md5, - 'post_time' => (isset($post_time)) ? (int) $post_time : $current_time, - 'post_checksum' => (isset($post_checksum)) ? (string) $post_checksum : '', - 'post_edit_reason' => $post_edit_reason, - 'post_edit_user' => ($mode == 'edit') ? $user->data['user_id'] : ((isset($post_edit_user)) ? (int) $post_edit_user : 0), - 'forum_parents' => $forum_parents, - 'forum_name' => $forum_name, + 'post_time' => (isset($post_data['post_time'])) ? (int) $post_data['post_time'] : $current_time, + 'post_checksum' => (isset($post_data['post_checksum'])) ? (string) $post_data['post_checksum'] : '', + 'post_edit_reason' => $post_data['post_edit_reason'], + 'post_edit_user' => ($mode == 'edit') ? $user->data['user_id'] : ((isset($post_data['post_edit_user'])) ? (int) $post_data['post_edit_user'] : 0), + 'forum_parents' => $post_data['forum_parents'], + 'forum_name' => $post_data['forum_name'], 'notify' => $notify, - 'notify_set' => $notify_set, - 'poster_ip' => (isset($poster_ip)) ? (int) $poster_ip : $user->ip, - 'post_edit_locked' => (int) $post_edit_locked, + 'notify_set' => $post_data['notify_set'], + 'poster_ip' => (isset($post_data['poster_ip'])) ? $post_data['poster_ip'] : $user->ip, + 'post_edit_locked' => (int) $post_data['post_edit_locked'], 'bbcode_bitfield' => (int) $message_parser->bbcode_bitfield, 'bbcode_uid' => $message_parser->bbcode_uid, 'message' => $message_parser->message, @@ -879,33 +813,40 @@ if ($submit || $preview || $refresh) ); unset($message_parser); - submit_post($mode, $subject, $username, $topic_type, $poll, $post_data, $update_message); + $redirect_url = submit_post($mode, $post_data['subject'], $post_data['username'], $post_data['topic_type'], $poll, $data, $update_message); + + meta_refresh(3, $redirect_url); + + $message = ($auth->acl_get('f_moderate', $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'); + $message = $user->lang[$message] . ((!$auth->acl_get('f_moderate', $data['forum_id']) || $auth->acl_get('m_approve', $data['forum_id'])) ? '<br /><br />' . sprintf($user->lang['VIEW_MESSAGE'], '<a href="' . $redirect_url . '">', '</a>') : ''); + $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $phpbb_root_path . 'viewforum.' . $phpEx . $SID .'&f=' . $data['forum_id'] . '">', '</a>'); + trigger_error($message); } } - $post_subject = stripslashes($subject); + $post_data['post_subject'] = $post_data['subject']; } // Preview if (!sizeof($error) && $preview) { - $post_time = ($mode == 'edit') ? $post_time : $current_time; + $post_data['post_time'] = ($mode == 'edit') ? $post_data['post_time'] : $current_time; - $preview_message = $message_parser->format_display($enable_bbcode, $enable_urls, $enable_smilies, false); + $preview_message = $message_parser->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies'], false); - $preview_signature = ($mode == 'edit') ? $user_sig : $user->data['user_sig']; - $preview_signature_uid = ($mode == 'edit') ? $user_sig_bbcode_uid : $user->data['user_sig_bbcode_uid']; - $preview_signature_bitfield = ($mode == 'edit') ? $user_sig_bbcode_bitfield : $user->data['user_sig_bbcode_bitfield']; + $preview_signature = ($mode == 'edit') ? $post_data['user_sig'] : $user->data['user_sig']; + $preview_signature_uid = ($mode == 'edit') ? $post_data['user_sig_bbcode_uid'] : $user->data['user_sig_bbcode_uid']; + $preview_signature_bitfield = ($mode == 'edit') ? $post_data['user_sig_bbcode_bitfield'] : $user->data['user_sig_bbcode_bitfield']; // Signature - if ($enable_sig && $config['allow_sig'] && $preview_signature && $auth->acl_get('f_sigs', $forum_id)) + if ($post_data['enable_sig'] && $config['allow_sig'] && $preview_signature && $auth->acl_get('f_sigs', $forum_id)) { $parse_sig = new parse_message($preview_signature); $parse_sig->bbcode_uid = $preview_signature_uid; $parse_sig->bbcode_bitfield = $preview_signature_bitfield; // Not sure about parameters for bbcode/smilies/urls... in signatures - $parse_sig->format_display($config['allow_bbcode'], true, $config['allow_smilies']); + $parse_sig->format_display($config['allow_sig_bbcode'], true, $config['allow_sig_smilies']); $preview_signature = $parse_sig->message; unset($parse_sig); } @@ -914,30 +855,30 @@ if (!sizeof($error) && $preview) $preview_signature = ''; } - $preview_subject = censor_text($subject); + $preview_subject = censor_text($post_data['subject']); // Poll Preview - if (($mode == 'post' || ($mode == 'edit' && $post_id == $topic_first_post_id && (!$poll_last_vote || $auth->acl_get('m_edit', $forum_id)))) + 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)))) && $auth->acl_get('f_poll', $forum_id)) { - $parse_poll = new parse_message($poll_title); + $parse_poll = new parse_message($post_data['poll_title']); $parse_poll->bbcode_uid = $message_parser->bbcode_uid; $parse_poll->bbcode_bitfield = $message_parser->bbcode_bitfield; - $parse_poll->format_display($enable_bbcode, $enable_urls, $enable_smilies); + $parse_poll->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies']); $template->assign_vars(array( - 'S_HAS_POLL_OPTIONS'=> (sizeof($poll_options)), - 'S_IS_MULTI_CHOICE' => ($poll_max_options > 1) ? true : false, + 'S_HAS_POLL_OPTIONS'=> (sizeof($post_data['poll_options'])), + 'S_IS_MULTI_CHOICE' => ($post_data['poll_max_options'] > 1) ? true : false, 'POLL_QUESTION' => $parse_poll->message, - 'L_POLL_LENGTH' => ($poll_length) ? sprintf($user->lang['POLL_RUN_TILL'], $user->format_date($poll_length + $poll_start)) : '', - 'L_MAX_VOTES' => ($poll_max_options == 1) ? $user->lang['MAX_OPTION_SELECT'] : sprintf($user->lang['MAX_OPTIONS_SELECT'], $poll_max_options)) + 'L_POLL_LENGTH' => ($post_data['poll_length']) ? sprintf($user->lang['POLL_RUN_TILL'], $user->format_date($post_data['poll_length'] + $post_data['poll_start'])) : '', + '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'])) ); - $parse_poll->message = implode("\n", $poll_options); - $parse_poll->format_display($enable_bbcode, $enable_urls, $enable_smilies); + $parse_poll->message = implode("\n", $post_data['poll_options']); + $parse_poll->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies']); $preview_poll_options = explode('<br />', $parse_poll->message); unset($parse_poll); @@ -982,45 +923,44 @@ if (!sizeof($error) && $preview) 'S_DISPLAY_PREVIEW' => true) ); } - - unset($post_text); } // Decode text for message display -$bbcode_uid = ($mode == 'quote' && !$preview && !$refresh && !sizeof($error)) ? $bbcode_uid : $message_parser->bbcode_uid; -$message_parser->decode_message($bbcode_uid); +$post_data['bbcode_uid'] = ($mode == 'quote' && !$preview && !$refresh && !sizeof($error)) ? $post_data['bbcode_uid'] : $message_parser->bbcode_uid; +$message_parser->decode_message($post_data['bbcode_uid']); if ($mode == 'quote' && !$preview && !$refresh) { - $message_parser->message = '[quote="' . $quote_username . '"]' . censor_text(trim($message_parser->message)) . "[/quote]\n"; + $message_parser->message = '[quote="' . $post_data['quote_username'] . '"]' . censor_text(trim($message_parser->message)) . "[/quote]\n"; } if (($mode == 'reply' || $mode == 'quote') && !$preview && !$refresh) { - $post_subject = ((!preg_match('/^Re:/', $post_subject)) ? 'Re: ' : '') . censor_text($post_subject); + $post_data['post_subject'] = ((!preg_match('/^Re:/', $post_data['post_subject'])) ? 'Re: ' : '') . censor_text($post_data['post_subject']); } $attachment_data = $message_parser->attachment_data; $filename_data = $message_parser->filename_data; -$post_text = $message_parser->message; +$post_data['post_text'] = $message_parser->message; -if (sizeof($poll_options) && $poll_title) +if (sizeof($post_data['poll_options']) && $post_data['poll_title']) { - $message_parser->message = $poll_title; - $message_parser->bbcode_uid = $bbcode_uid; + $message_parser->message = $post_data['poll_title']; + $message_parser->bbcode_uid = $post_data['bbcode_uid']; $message_parser->decode_message(); - $poll_title = $message_parser->message; + $post_data['poll_title'] = $message_parser->message; - $message_parser->message = implode("\n", $poll_options); + $message_parser->message = implode("\n", $post_data['poll_options']); $message_parser->decode_message(); - $poll_options = explode("\n", $message_parser->message); + $post_data['poll_options'] = explode("\n", $message_parser->message); } unset($message_parser); // MAIN POSTING PAGE BEGINS HERE // Forum moderators? +$moderators = array(); get_moderators($moderators, $forum_id); // Generate smiley listing @@ -1029,28 +969,29 @@ generate_smilies('inline', $forum_id); // Generate inline attachment select box posting_gen_inline_attachments($attachment_data); - // Do show topic type selection only in first post. $topic_type_toggle = false; -if ($mode == 'post' || ($mode == 'edit' && $post_id == $topic_first_post_id)) +if ($mode == 'post' || ($mode == 'edit' && $post_id == $post_data['topic_first_post_id'])) { - $topic_type_toggle = posting_gen_topic_types($forum_id, $topic_type); + $topic_type_toggle = posting_gen_topic_types($forum_id, $post_data['topic_type']); } $s_topic_icons = false; -if ($enable_icons) +if ($post_data['enable_icons']) { - $s_topic_icons = posting_gen_topic_icons($mode, $icon_id); + $s_topic_icons = posting_gen_topic_icons($mode, $post_data['icon_id']); } -$bbcode_checked = (isset($enable_bbcode)) ? !$enable_bbcode : (($config['allow_bbcode']) ? !$user->optionget('bbcode') : 1); -$smilies_checked = (isset($enable_smilies)) ? !$enable_smilies : (($config['allow_smilies']) ? !$user->optionget('smilies') : 1); -$urls_checked = (isset($enable_urls)) ? !$enable_urls : 0; -$sig_checked = $enable_sig; -$notify_checked = (isset($notify)) ? $notify : ((!$notify_set) ? (($user->data['is_registered']) ? $user->data['user_notify'] : 0) : 1); -$lock_topic_checked = (isset($topic_lock)) ? $topic_lock : (($topic_status == ITEM_LOCKED) ? 1 : 0); -$lock_post_checked = (isset($post_lock)) ? $post_lock : $post_edit_locked; +$bbcode_checked = (isset($post_data['enable_bbcode'])) ? !$post_data['enable_bbcode'] : (($config['allow_bbcode']) ? !$user->optionget('bbcode') : 1); +$smilies_checked = (isset($post_data['enable_smilies'])) ? !$post_data['enable_smilies'] : (($config['allow_smilies']) ? !$user->optionget('smilies') : 1); +$urls_checked = (isset($post_data['enable_urls'])) ? !$post_data['enable_urls'] : 0; +$sig_checked = $post_data['enable_sig']; +$lock_topic_checked = (isset($topic_lock)) ? $topic_lock : (($post_data['topic_status'] == ITEM_LOCKED) ? 1 : 0); +$lock_post_checked = (isset($post_lock)) ? $post_lock : $post_data['post_edit_locked']; + +// If in edit mode, and the user is not the poster, we do not take the notification into account +$notify_checked = (isset($notify)) ? $notify : (($mode != 'edit') ? $user->data['user_notify'] : $post_data['notify_set']); // Page title & action URL, include session_id for security purpose $s_action = "posting.$phpEx?sid=" . $user->session_id . "&mode=$mode&f=$forum_id"; @@ -1071,32 +1012,16 @@ switch ($mode) case 'delete': case 'edit': $page_title = $user->lang['EDIT_POST']; + break; } -$forum_data = array( - 'parent_id' => $parent_id, - 'left_id' => $left_id, - 'right_id' => $right_id, - 'forum_parents' => $forum_parents, - 'forum_name' => $forum_name, - 'forum_id' => $forum_id, - 'forum_type' => $forum_type, - 'forum_desc' => $forum_desc, - 'forum_desc_uid' => $forum_desc_uid, - 'forum_desc_bitfield' => $forum_desc_bitfield, - 'forum_rules' => $forum_rules, - 'forum_rules_uid' => $forum_rules_uid, - 'forum_rules_bitfield' => $forum_rules_bitfield, - 'forum_rules_link' => $forum_rules_link -); - // Build Navigation Links -generate_forum_nav($forum_data); +generate_forum_nav($post_data); // Build Forum Rules -generate_forum_rules($forum_data); +generate_forum_rules($post_data); -if ($config['enable_post_confirm'] && !$user->data['is_registered'] && ($mode == 'post' || $mode == 'reply')) +if ($config['enable_post_confirm'] && !$user->data['is_registered'] && ($mode == 'post' || $mode == 'reply' || $mode == 'quote')) { // Show confirm image $sql = 'DELETE FROM ' . CONFIRM_TABLE . " @@ -1120,68 +1045,67 @@ if ($config['enable_post_confirm'] && !$user->data['is_registered'] && ($mode == 'S_CONFIRM_CODE' => true, 'CONFIRM_ID' => $confirm_id, 'CONFIRM_IMAGE' => '<img src="' . $phpbb_root_path . 'ucp.' . $phpEx . $SID . '&mode=confirm&id=' . $confirm_id . '&type=' . CONFIRM_POST . '" alt="" title="" />', - 'L_POST_CONFIRM_EXPLAIN' => sprintf($user->lang['POST_CONFIRM_EXPLAIN'], '<a href="mailto:' . htmlentities($config['board_contact']) . '">', '</a>'), + 'L_POST_CONFIRM_EXPLAIN' => sprintf($user->lang['POST_CONFIRM_EXPLAIN'], '<a href="mailto:' . htmlentities($config['board_contact']) . '">', '</a>'), )); } -$s_hidden_fields = ($mode == 'reply' || $mode == 'quote') ? '<input type="hidden" name="topic_cur_post_id" value="' . $topic_last_post_id . '" />' : ''; +$s_hidden_fields = ($mode == 'reply' || $mode == 'quote') ? '<input type="hidden" name="topic_cur_post_id" value="' . $post_data['topic_last_post_id'] . '" />' : ''; $s_hidden_fields .= '<input type="hidden" name="lastclick" value="' . $current_time . '" />'; -$s_hidden_fields .= ($draft_id || isset($_REQUEST['draft_loaded'])) ? '<input type="hidden" name="draft_loaded" value="' . ((isset($_REQUEST['draft_loaded'])) ? intval($_REQUEST['draft_loaded']) : $draft_id) . '" />' : ''; +$s_hidden_fields .= ($draft_id || isset($_REQUEST['draft_loaded'])) ? '<input type="hidden" name="draft_loaded" value="' . request_var('draft_loaded', $draft_id) . '" />' : ''; $form_enctype = (@ini_get('file_uploads') == '0' || strtolower(@ini_get('file_uploads')) == 'off' || @ini_get('file_uploads') == '0' || !$config['allow_attachments'] || !$auth->acl_gets('f_attach', 'u_attach', $forum_id)) ? '' : ' enctype="multipart/form-data"'; // Start assigning vars for main posting page ... $template->assign_vars(array( 'L_POST_A' => $page_title, - 'L_ICON' => ($mode == 'reply' || $mode == 'quote' || ($mode == 'edit' && $post_id != $topic_first_post_id)) ? $user->lang['POST_ICON'] : $user->lang['TOPIC_ICON'], + 'L_ICON' => ($mode == 'reply' || $mode == 'quote' || ($mode == 'edit' && $post_id != $post_data['topic_first_post_id'])) ? $user->lang['POST_ICON'] : $user->lang['TOPIC_ICON'], 'L_MESSAGE_BODY_EXPLAIN'=> (intval($config['max_post_chars'])) ? sprintf($user->lang['MESSAGE_BODY_EXPLAIN'], intval($config['max_post_chars'])) : '', - 'FORUM_NAME' => $forum_name, - 'FORUM_DESC' => ($forum_desc) ? generate_text_for_display($forum_desc, $forum_desc_uid, $forum_desc_bitfield) : '', - 'TOPIC_TITLE' => $topic_title, + 'FORUM_NAME' => $post_data['forum_name'], + 'FORUM_DESC' => ($post_data['forum_desc']) ? generate_text_for_display($post_data['forum_desc'], $post_data['forum_desc_uid'], $post_data['forum_desc_bitfield']) : '', + 'TOPIC_TITLE' => $post_data['topic_title'], 'MODERATORS' => (sizeof($moderators)) ? implode(', ', $moderators[$forum_id]) : '', - 'USERNAME' => ((!$preview && $mode != 'quote') || $preview) ? stripslashes($username) : '', - 'SUBJECT' => $post_subject, - 'MESSAGE' => $post_text, - 'BBCODE_STATUS' => ($bbcode_status) ? sprintf($user->lang['BBCODE_IS_ON'], '<a href="' . "faq.$phpEx$SID&mode=bbcode" . '" onclick="target=\'_phpbbcode\';">', '</a>') : sprintf($user->lang['BBCODE_IS_OFF'], '<a href="' . "faq.$phpEx$SID&mode=bbcode" . '" onclick="target=\'_phpbbcode\';">', '</a>'), + 'USERNAME' => ((!$preview && $mode != 'quote') || $preview) ? $post_data['username'] : '', + 'SUBJECT' => $post_data['post_subject'], + 'MESSAGE' => $post_data['post_text'], + 'BBCODE_STATUS' => ($bbcode_status) ? sprintf($user->lang['BBCODE_IS_ON'], '<a href="' . "{$phpbb_root_path}faq.$phpEx$SID&mode=bbcode" . '" onclick="target=\'_phpbbcode\';">', '</a>') : sprintf($user->lang['BBCODE_IS_OFF'], '<a href="' . "{$phpbb_root_path}faq.$phpEx$SID&mode=bbcode" . '" onclick="target=\'_phpbbcode\';">', '</a>'), 'IMG_STATUS' => ($img_status) ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'], 'FLASH_STATUS' => ($flash_status) ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'], 'SMILIES_STATUS' => ($smilies_status) ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'], 'MINI_POST_IMG' => $user->img('icon_post', $user->lang['POST']), - 'POST_DATE' => ($post_time) ? $user->format_date($post_time) : '', + 'POST_DATE' => ($post_data['post_time']) ? $user->format_date($post_data['post_time']) : '', 'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '', - 'TOPIC_TIME_LIMIT' => (int) $topic_time_limit, - 'EDIT_REASON' => $post_edit_reason, - - 'U_VIEW_FORUM' => "viewforum.$phpEx$SID&f=" . $forum_id, - 'U_VIEWTOPIC' => ($mode != 'post') ? "viewtopic.$phpEx$SID&$forum_id&t=$topic_id" : '', - 'U_PROGRESS_BAR' => "posting.$phpEx$SID&f=$forum_id&mode=popup", - 'UA_PROGRESS_BAR' => "posting.$phpEx$SID&f=$forum_id&mode=popup", + 'TOPIC_TIME_LIMIT' => (int) $post_data['topic_time_limit'], + 'EDIT_REASON' => $post_data['post_edit_reason'], + 'U_VIEW_FORUM' => "{$phpbb_root_path}viewforum.$phpEx$SID&f=$forum_id", + 'U_VIEWTOPIC' => ($mode != 'post') ? "{$phpbb_root_path}viewtopic.$phpEx$SID&$forum_id&t=$topic_id" : '', + 'U_PROGRESS_BAR' => "{$phpbb_root_path}posting.$phpEx$SID&f=$forum_id&mode=popup", + 'UA_PROGRESS_BAR' => "{$phpbb_root_path}posting.$phpEx$SID&f=$forum_id&mode=popup", 'S_PRIVMSGS' => false, 'S_CLOSE_PROGRESS_WINDOW' => (isset($_POST['add_file'])) ? true : false, 'S_EDIT_POST' => ($mode == 'edit') ? true : false, 'S_EDIT_REASON' => ($mode == 'edit' && $auth->acl_get('m_edit', $forum_id)) ? true : false, - 'S_DISPLAY_USERNAME' => (!$user->data['is_registered'] || ($mode == 'edit' && $post_username)) ? true : false, - 'S_SHOW_TOPIC_ICONS' => $s_topic_icons, - 'S_DELETE_ALLOWED' => ($mode == 'edit' && (($post_id == $topic_last_post_id && $poster_id == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id)) || $auth->acl_get('m_delete', $forum_id))), - 'S_BBCODE_ALLOWED' => $bbcode_status, - 'S_BBCODE_CHECKED' => ($bbcode_checked) ? ' checked="checked"' : '', - 'S_SMILIES_ALLOWED' => $smilies_status, - 'S_SMILIES_CHECKED' => ($smilies_checked) ? ' checked="checked"' : '', - 'S_SIG_ALLOWED' => ($auth->acl_get('f_sigs', $forum_id) && $config['allow_sig'] && $user->data['is_registered']), - 'S_SIGNATURE_CHECKED' => ($sig_checked) ? ' checked="checked"' : '', - 'S_NOTIFY_ALLOWED' => ($user->data['is_registered']), - 'S_NOTIFY_CHECKED' => ($notify_checked) ? ' checked="checked"' : '', - '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'] && $user->data['user_id'] == $topic_poster))), - 'S_LOCK_TOPIC_CHECKED' => ($lock_topic_checked) ? ' checked="checked"' : '', - 'S_LOCK_POST_ALLOWED' => ($mode == 'edit' && $auth->acl_get('m_edit', $forum_id)), - 'S_LOCK_POST_CHECKED' => ($lock_post_checked) ? ' checked="checked"' : '', - 'S_MAGIC_URL_CHECKED' => ($urls_checked) ? ' checked="checked"' : '', - 'S_TYPE_TOGGLE' => $topic_type_toggle, - 'S_SAVE_ALLOWED' => ($auth->acl_get('u_savedrafts') && $user->data['is_registered']), - 'S_HAS_DRAFTS' => ($auth->acl_get('u_savedrafts') && $user->data['is_registered'] && $drafts), - 'S_FORM_ENCTYPE' => $form_enctype, + 'S_DISPLAY_USERNAME' => (!$user->data['is_registered'] || ($mode == 'edit' && $post_data['post_username'])) ? true : false, + 'S_SHOW_TOPIC_ICONS' => $s_topic_icons, + '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, + 'S_BBCODE_ALLOWED' => $bbcode_status, + 'S_BBCODE_CHECKED' => ($bbcode_checked) ? ' checked="checked"' : '', + 'S_SMILIES_ALLOWED' => $smilies_status, + 'S_SMILIES_CHECKED' => ($smilies_checked) ? ' checked="checked"' : '', + 'S_SIG_ALLOWED' => ($auth->acl_get('f_sigs', $forum_id) && $config['allow_sig'] && $user->data['is_registered']) ? true : false, + 'S_SIGNATURE_CHECKED' => ($sig_checked) ? ' checked="checked"' : '', + 'S_NOTIFY_ALLOWED' => (!$user->data['is_registered'] || ($mode == 'edit' && $user->data['user_id'] != $post_data['poster_id'])) ? false : true, + 'S_NOTIFY_CHECKED' => ($notify_checked) ? ' checked="checked"' : '', + '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']))) ? true : false, + 'S_LOCK_TOPIC_CHECKED' => ($lock_topic_checked) ? ' checked="checked"' : '', + 'S_LOCK_POST_ALLOWED' => ($mode == 'edit' && $auth->acl_get('m_edit', $forum_id)) ? true : false, + 'S_LOCK_POST_CHECKED' => ($lock_post_checked) ? ' checked="checked"' : '', + 'S_MAGIC_URL_CHECKED' => ($urls_checked) ? ' checked="checked"' : '', + 'S_TYPE_TOGGLE' => $topic_type_toggle, + 'S_SAVE_ALLOWED' => ($auth->acl_get('u_savedrafts') && $user->data['is_registered']) ? true : false, + 'S_HAS_DRAFTS' => ($auth->acl_get('u_savedrafts') && $user->data['is_registered'] && $post_data['drafts']) ? true : false, + 'S_FORM_ENCTYPE' => $form_enctype, 'S_BBCODE_IMG' => $img_status, 'S_BBCODE_FLASH' => $flash_status, @@ -1211,21 +1135,21 @@ while ($row = $db->sql_fetchrow($result)) $db->sql_freeresult($result); // Poll entry -if (($mode == 'post' || ($mode == 'edit' && $post_id == $topic_first_post_id && (!$poll_last_vote || $auth->acl_get('m_edit', $forum_id)))) +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)))) && $auth->acl_get('f_poll', $forum_id)) { $template->assign_vars(array( 'S_SHOW_POLL_BOX' => true, 'S_POLL_VOTE_CHANGE' => ($auth->acl_get('f_votechg', $forum_id)), - 'S_POLL_DELETE' => ($mode == 'edit' && $poll_options && ((!$poll_last_vote && $poster_id == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id)) || $auth->acl_get('m_delete', $forum_id))), + '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))), 'L_POLL_OPTIONS_EXPLAIN'=> sprintf($user->lang['POLL_OPTIONS_EXPLAIN'], $config['max_poll_options']), - 'VOTE_CHANGE_CHECKED' => (isset($poll_vote_change) && $poll_vote_change) ? ' checked="checked"' : '', - 'POLL_TITLE' => (isset($poll_title)) ? $poll_title : '', - 'POLL_OPTIONS' => (isset($poll_options) && $poll_options) ? implode("\n", $poll_options) : '', - 'POLL_MAX_OPTIONS' => (isset($poll_max_options)) ? (int) $poll_max_options : 1, - 'POLL_LENGTH' => $poll_length) + 'VOTE_CHANGE_CHECKED' => (!empty($post_data['poll_vote_change'])) ? ' checked="checked"' : '', + 'POLL_TITLE' => (isset($post_data['poll_title'])) ? $post_data['poll_title'] : '', + 'POLL_OPTIONS' => (!empty($post_data['poll_options'])) ? implode("\n", $post_data['poll_options']) : '', + 'POLL_MAX_OPTIONS' => (isset($post_data['poll_max_options'])) ? (int) $post_data['poll_max_options'] : 1, + 'POLL_LENGTH' => $post_data['poll_length']) ); } @@ -1243,7 +1167,7 @@ $template->set_filenames(array( 'body' => 'posting_body.html') ); -make_jumpbox('viewforum.'.$phpEx); +make_jumpbox('viewforum.' . $phpEx); // Topic review if ($mode == 'reply' || $mode == 'quote') @@ -1256,761 +1180,96 @@ if ($mode == 'reply' || $mode == 'quote') page_footer(); - /** -* Delete Post +* Show upload popup (progress bar) */ -function delete_post($mode, $post_id, $topic_id, $forum_id, &$data) +function upload_popup($forum_style = 0) { - global $db, $user, $config, $auth, $phpEx, $SID, $phpbb_root_path; - - // Specify our post mode - $post_mode = ($data['topic_first_post_id'] == $data['topic_last_post_id']) ? 'delete_topic' : (($data['topic_first_post_id'] == $post_id) ? 'delete_first_post' : (($data['topic_last_post_id'] == $post_id) ? 'delete_last_post' : 'delete')); - $sql_data = array(); - $next_post_id = 0; - - include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx); - - $db->sql_transaction(); - - if (!delete_posts('post_id', array($post_id), false)) - { - // Try to delete topic, we may had an previous error causing inconsistency - if ($post_mode = 'delete_topic') - { - delete_topics('topic_id', array($topic_id), false); - } - trigger_error('ALREADY_DELETED'); - } - - $db->sql_transaction('commit'); - - // Collect the necessary informations for updating the tables - $sql_data[FORUMS_TABLE] = ''; - switch ($post_mode) - { - case 'delete_topic': - delete_topics('topic_id', array($topic_id), false); - set_config('num_topics', $config['num_topics'] - 1, true); - - if ($data['topic_type'] != POST_GLOBAL) - { - $sql_data[FORUMS_TABLE] .= 'forum_posts = forum_posts - 1, forum_topics_real = forum_topics_real - 1'; - $sql_data[FORUMS_TABLE] .= ($data['topic_approved']) ? ', forum_topics = forum_topics - 1' : ''; - } - - $update_sql = update_post_information('forum', $forum_id, true); - if (sizeof($update_sql)) - { - $sql_data[FORUMS_TABLE] .= ($sql_data[FORUMS_TABLE]) ? ', ' : ''; - $sql_data[FORUMS_TABLE] .= implode(', ', $update_sql[$forum_id]); - } - - $sql_data[TOPICS_TABLE] = 'topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : ''); - break; - - case 'delete_first_post': - $sql = 'SELECT p.post_id, p.poster_id, p.post_username, u.username - FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u - WHERE p.topic_id = $topic_id - AND p.poster_id = u.user_id - ORDER BY p.post_time ASC"; - $result = $db->sql_query_limit($sql, 1); - - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if ($data['topic_type'] != POST_GLOBAL) - { - $sql_data[FORUMS_TABLE] = 'forum_posts = forum_posts - 1'; - } - - $sql_data[TOPICS_TABLE] = 'topic_first_post_id = ' . intval($row['post_id']) . ", topic_first_poster_name = '" . (($row['poster_id'] == ANONYMOUS) ? $db->sql_escape($row['post_username']) : $db->sql_escape($row['username'])) . "'"; - $sql_data[TOPICS_TABLE] .= ', topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : ''); - - $next_post_id = (int) $row['post_id']; - break; - - case 'delete_last_post': - if ($data['topic_type'] != POST_GLOBAL) - { - $sql_data[FORUMS_TABLE] = 'forum_posts = forum_posts - 1'; - } - - $update_sql = update_post_information('forum', $forum_id, true); - if (sizeof($update_sql)) - { - $sql_data[FORUMS_TABLE] .= ($sql_data[FORUMS_TABLE]) ? ', ' : ''; - $sql_data[FORUMS_TABLE] .= implode(', ', $update_sql[$forum_id]); - } - - $sql_data[TOPICS_TABLE] = 'topic_bumped = 0, topic_bumper = 0, topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : ''); - - $update_sql = update_post_information('topic', $topic_id, true); - if (sizeof($update_sql)) - { - $sql_data[TOPICS_TABLE] .= ', ' . implode(', ', $update_sql[$topic_id]); - $next_post_id = (int) str_replace('topic_last_post_id = ', '', $update_sql[$topic_id][0]); - } - else - { - $sql = 'SELECT MAX(post_id) as last_post_id - FROM ' . POSTS_TABLE . " - WHERE topic_id = $topic_id " . - ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND post_approved = 1' : ''); - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - $next_post_id = (int) $row['last_post_id']; - } - break; - - case 'delete': - $sql = 'SELECT post_id - FROM ' . POSTS_TABLE . " - WHERE topic_id = $topic_id " . - ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND post_approved = 1' : '') . ' - AND post_time > ' . $data['post_time'] . ' - ORDER BY post_time ASC'; - $result = $db->sql_query_limit($sql, 1); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if ($data['topic_type'] != POST_GLOBAL) - { - $sql_data[FORUMS_TABLE] = 'forum_posts = forum_posts - 1'; - } - - $sql_data[TOPICS_TABLE] = 'topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : ''); - $next_post_id = (int) $row['post_id']; - break; - } - - $sql_data[USERS_TABLE] = ($auth->acl_get('f_postcount', $forum_id)) ? 'user_posts = user_posts - 1' : ''; - set_config('num_posts', $config['num_posts'] - 1, true); + global $template, $user; - $db->sql_transaction(); + ($forum_style) ? $user->setup('posting', $forum_style) : $user->setup('posting'); - $where_sql = array(FORUMS_TABLE => "forum_id = $forum_id", TOPICS_TABLE => "topic_id = $topic_id", USERS_TABLE => 'user_id = ' . $data['poster_id']); + page_header('PROGRESS_BAR'); - foreach ($sql_data as $table => $update_sql) - { - if ($update_sql) - { - $db->sql_query("UPDATE $table SET $update_sql WHERE " . $where_sql[$table]); - } - } + $template->set_filenames(array( + 'popup' => 'posting_progress_bar.html') + ); - $db->sql_transaction('commit'); + $template->assign_vars(array( + 'PROGRESS_BAR' => $user->img('attach_progress_bar', $user->lang['UPLOAD_IN_PROGRESS'])) + ); - return $next_post_id; + $template->display('popup'); } - /** -* Submit Post +* Do the various checks required for removing posts as well as removing it */ -function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $update_message = true) +function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data) { - global $db, $auth, $user, $config, $phpEx, $SID, $template, $phpbb_root_path; - - // We do not handle erasing posts here - if ($mode == 'delete') - { - return; - } - - $current_time = time(); - - if ($mode == 'post') - { - $post_mode = 'post'; - $update_message = true; - } - else if ($mode != 'edit') - { - $post_mode = 'reply'; - $update_message = true; - } - else if ($mode == 'edit') - { - $post_mode = ($data['topic_first_post_id'] == $data['topic_last_post_id']) ? 'edit_topic' : (($data['topic_first_post_id'] == $data['post_id']) ? 'edit_first_post' : (($data['topic_last_post_id'] == $data['post_id']) ? 'edit_last_post' : 'edit')); - } - - - // Collect some basic informations about which tables and which rows to update/insert - $sql_data = array(); - $poster_id = ($mode == 'edit') ? $data['poster_id'] : (int) $user->data['user_id']; - - // Collect Informations - switch ($post_mode) - { - case 'post': - case 'reply': - $sql_data[POSTS_TABLE]['sql'] = array( - 'forum_id' => ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'], - 'poster_id' => (int) $user->data['user_id'], - 'icon_id' => $data['icon_id'], - 'poster_ip' => $user->ip, - 'post_time' => $current_time, - 'post_approved' => ($auth->acl_get('f_moderate', $data['forum_id']) && !$auth->acl_get('m_approve', $data['forum_id'])) ? 0 : 1, - 'enable_bbcode' => $data['enable_bbcode'], - 'enable_smilies' => $data['enable_smilies'], - 'enable_magic_url' => $data['enable_urls'], - 'enable_sig' => $data['enable_sig'], - 'post_username' => (!$user->data['is_registered']) ? stripslashes($username) : '', - 'post_subject' => $subject, - 'post_text' => $data['message'], - 'post_checksum' => $data['message_md5'], - 'post_encoding' => $user->lang['ENCODING'], - 'post_attachment' => (isset($data['filename_data']['physical_filename']) && sizeof($data['filename_data'])) ? 1 : 0, - 'bbcode_bitfield' => $data['bbcode_bitfield'], - 'bbcode_uid' => $data['bbcode_uid'], - 'post_edit_locked' => $data['post_edit_locked'] - ); - break; - - case 'edit_first_post': - case 'edit': - - if (!$auth->acl_gets('m_', 'a_') || $data['post_edit_reason']) - { - $sql_data[POSTS_TABLE]['sql'] = array( - 'post_edit_time' => $current_time - ); - - $sql_data[POSTS_TABLE]['stat'][] = 'post_edit_count = post_edit_count + 1'; - } - - case 'edit_last_post': - case 'edit_topic': - - if (($post_mode == 'edit_last_post' || $post_mode == 'edit_topic') && $data['post_edit_reason']) - { - $sql_data[POSTS_TABLE]['sql'] = array( - 'post_edit_time' => $current_time - ); - - $sql_data[POSTS_TABLE]['stat'][] = 'post_edit_count = post_edit_count + 1'; - } - - if (!isset($sql_data[POSTS_TABLE]['sql'])) - { - $sql_data[POSTS_TABLE]['sql'] = array(); - } - - $sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array( - 'forum_id' => ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'], - 'poster_id' => $data['poster_id'], - 'icon_id' => $data['icon_id'], - 'post_approved' => ($auth->acl_get('f_moderate', $data['forum_id']) && !$auth->acl_get('m_approve', $data['forum_id'])) ? 0 : 1, - 'enable_bbcode' => $data['enable_bbcode'], - 'enable_smilies' => $data['enable_smilies'], - 'enable_magic_url' => $data['enable_urls'], - 'enable_sig' => $data['enable_sig'], - 'post_username' => ($username && $data['poster_id'] == ANONYMOUS) ? stripslashes($username) : '', - 'post_subject' => $subject, - 'post_edit_reason' => $data['post_edit_reason'], - 'post_edit_user' => (int) $data['post_edit_user'], - 'post_checksum' => $data['message_md5'], - 'post_encoding' => $user->lang['ENCODING'], - 'post_attachment' => (isset($data['filename_data']['physical_filename']) && sizeof($data['filename_data'])) ? 1 : 0, - 'bbcode_bitfield' => $data['bbcode_bitfield'], - 'bbcode_uid' => $data['bbcode_uid'], - 'post_edit_locked' => $data['post_edit_locked']) - ); - - if ($update_message) - { - $sql_data[POSTS_TABLE]['sql']['post_text'] = $data['message']; - } - - break; - } - - // And the topic ladies and gentlemen - switch ($post_mode) - { - case 'post': - $sql_data[TOPICS_TABLE]['sql'] = array( - 'topic_poster' => (int) $user->data['user_id'], - 'topic_time' => $current_time, - 'forum_id' => ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'], - 'icon_id' => $data['icon_id'], - 'topic_approved' => ($auth->acl_get('f_moderate', $data['forum_id']) && !$auth->acl_get('m_approve', $data['forum_id'])) ? 0 : 1, - 'topic_title' => $subject, - 'topic_first_poster_name' => (!$user->data['is_registered'] && $username) ? stripslashes($username) : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : ''), - 'topic_type' => $topic_type, - 'topic_time_limit' => ($topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE) ? ($data['topic_time_limit'] * 86400) : 0, - 'topic_attachment' => (isset($data['filename_data']['physical_filename']) && sizeof($data['filename_data'])) ? 1 : 0 - ); - - if (isset($poll['poll_options']) && !empty($poll['poll_options'])) - { - $sql_data[TOPICS_TABLE]['sql'] = array_merge($sql_data[TOPICS_TABLE]['sql'], array( - 'poll_title' => $poll['poll_title'], - 'poll_start' => ($poll['poll_start']) ? $poll['poll_start'] : $current_time, - 'poll_max_options' => $poll['poll_max_options'], - 'poll_length' => ($poll['poll_length'] * 86400), - 'poll_vote_change' => $poll['poll_vote_change']) - ); - } - - $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id'])) ? ', user_posts = user_posts + 1' : ''); + global $user, $db, $auth; + global $phpbb_root_path, $phpEx, $SID; - if ($topic_type != POST_GLOBAL) - { - if (!$auth->acl_get('f_moderate', $data['forum_id']) || $auth->acl_get('m_approve', $data['forum_id'])) - { - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1'; - } - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real + 1' . ((!$auth->acl_get('f_moderate', $data['forum_id']) || $auth->acl_get('m_approve', $data['forum_id'])) ? ', forum_topics = forum_topics + 1' : ''); - } - break; - - case 'reply': - $sql_data[TOPICS_TABLE]['stat'][] = 'topic_replies_real = topic_replies_real + 1, topic_bumped = 0, topic_bumper = 0' . ((!$auth->acl_get('f_moderate', $data['forum_id']) || $auth->acl_get('m_approve', $data['forum_id'])) ? ', topic_replies = topic_replies + 1' : ''); - $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id'])) ? ', user_posts = user_posts + 1' : ''); - - if ((!$auth->acl_get('f_moderate', $data['forum_id']) || $auth->acl_get('m_approve', $data['forum_id'])) && $topic_type != POST_GLOBAL) - { - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1'; - } - break; - - case 'edit_topic': - case 'edit_first_post': - - $sql_data[TOPICS_TABLE]['sql'] = array( - 'forum_id' => ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'], - 'icon_id' => $data['icon_id'], - 'topic_approved' => ($auth->acl_get('f_moderate', $data['forum_id']) && !$auth->acl_get('m_approve', $data['forum_id'])) ? 0 : 1, - 'topic_title' => $subject, - 'topic_first_poster_name' => stripslashes($username), - 'topic_type' => $topic_type, - 'topic_time_limit' => ($topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE) ? ($data['topic_time_limit'] * 86400) : 0, - 'poll_title' => (isset($poll['poll_options'])) ? $poll['poll_title'] : '', - 'poll_start' => (isset($poll['poll_options'])) ? (($poll['poll_start']) ? $poll['poll_start'] : $current_time) : 0, - 'poll_max_options' => (isset($poll['poll_options'])) ? $poll['poll_max_options'] : 1, - 'poll_length' => (isset($poll['poll_options'])) ? ($poll['poll_length'] * 86400) : 0, - 'poll_vote_change' => (isset($poll['poll_vote_change'])) ? $poll['poll_vote_change'] : 0, - - 'topic_attachment' => ($post_mode == 'edit_topic') ? ((isset($data['filename_data']['physical_filename']) && sizeof($data['filename_data'])) ? 1 : 0) : (isset($data['topic_attachment']) ? $data['topic_attachment'] : 0) - ); - break; - } - - $db->sql_transaction(); - - // Submit new topic - if ($post_mode == 'post') + // If moderator removing post or user itself removing post, present a confirmation screen + 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'])) { - $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . - $db->sql_build_array('INSERT', $sql_data[TOPICS_TABLE]['sql']); - $db->sql_query($sql); - - $data['topic_id'] = $db->sql_nextid(); - - $sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array( - 'topic_id' => $data['topic_id']) + $s_hidden_fields = build_hidden_fields(array( + 'p' => $post_id, + 'f' => $forum_id, + 'mode' => 'delete') ); - unset($sql_data[TOPICS_TABLE]['sql']); - } - - // Submit new post - if ($post_mode == 'post' || $post_mode == 'reply') - { - if ($post_mode == 'reply') - { - $sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array( - 'topic_id' => $data['topic_id']) - ); - } - $sql = 'INSERT INTO ' . POSTS_TABLE . ' ' . - $db->sql_build_array('INSERT', $sql_data[POSTS_TABLE]['sql']); - $db->sql_query($sql); - $data['post_id'] = $db->sql_nextid(); - - if ($post_mode == 'post') + if (confirm_box(true)) { - $sql_data[TOPICS_TABLE]['sql'] = array( - 'topic_first_post_id' => $data['post_id'], - 'topic_last_post_id' => $data['post_id'], - 'topic_last_post_time' => $current_time, - 'topic_last_poster_id' => (int) $user->data['user_id'], - 'topic_last_poster_name'=> (!$user->data['is_registered'] && $username) ? stripslashes($username) : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : '') + $data = array( + 'topic_first_post_id' => $post_data['topic_first_post_id'], + 'topic_last_post_id' => $post_data['topic_last_post_id'], + 'topic_approved' => $post_data['topic_approved'], + 'topic_type' => $post_data['topic_type'], + 'post_approved' => $post_data['post_approved'], + 'post_time' => $post_data['post_time'], + 'poster_id' => $post_data['poster_id'] ); - } - unset($sql_data[POSTS_TABLE]['sql']); - } + $next_post_id = delete_post($forum_id, $topic_id, $post_id, $data); - $make_global = false; - - // Are we globalising or unglobalising? - if ($post_mode == 'edit_first_post' || $post_mode == 'edit_topic') - { - $sql = 'SELECT topic_type, topic_replies_real, topic_approved - FROM ' . TOPICS_TABLE . ' - WHERE topic_id = ' . $data['topic_id']; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - // globalise - if ($row['topic_type'] != POST_GLOBAL && $topic_type == POST_GLOBAL) - { - // Decrement topic/post count - $make_global = true; - $sql_data[FORUMS_TABLE]['stat'] = array(); - - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - ' . ($row['topic_replies_real'] + 1); - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real - 1' . (($row['topic_approved']) ? ', forum_topics = forum_topics - 1' : ''); - - // Update forum_ids for all posts - $sql = 'UPDATE ' . POSTS_TABLE . ' - SET forum_id = 0 - WHERE topic_id = ' . $data['topic_id']; - $db->sql_query($sql); - } - // unglobalise - else if ($row['topic_type'] == POST_GLOBAL && $topic_type != POST_GLOBAL) - { - // Increment topic/post count - $make_global = true; - $sql_data[FORUMS_TABLE]['stat'] = array(); - - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + ' . ($row['topic_replies_real'] + 1); - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real + 1' . (($row['topic_approved']) ? ', forum_topics = forum_topics + 1' : ''); - - // Update forum_ids for all posts - $sql = 'UPDATE ' . POSTS_TABLE . ' - SET forum_id = ' . $data['forum_id'] . ' - WHERE topic_id = ' . $data['topic_id']; - $db->sql_query($sql); - } - } - - // Update the topics table - if (isset($sql_data[TOPICS_TABLE]['sql'])) - { - $db->sql_query('UPDATE ' . TOPICS_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', $sql_data[TOPICS_TABLE]['sql']) . ' - WHERE topic_id = ' . $data['topic_id']); - } - - // Update the posts table - if (isset($sql_data[POSTS_TABLE]['sql'])) - { - $db->sql_query('UPDATE ' . POSTS_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', $sql_data[POSTS_TABLE]['sql']) . ' - WHERE post_id = ' . $data['post_id']); - } - - // Update Poll Tables - if (isset($poll['poll_options']) && !empty($poll['poll_options'])) - { - $cur_poll_options = array(); - - if ($poll['poll_start'] && $mode == 'edit') - { - $sql = 'SELECT * FROM ' . POLL_OPTIONS_TABLE . ' - WHERE topic_id = ' . $data['topic_id'] . ' - ORDER BY poll_option_id'; - $result = $db->sql_query($sql); - - while ($cur_poll_options[] = $db->sql_fetchrow($result)); - $db->sql_freeresult($result); - } - - $sql_insert_ary = array(); - for ($i = 0, $size = sizeof($poll['poll_options']); $i < $size; $i++) - { - if (trim($poll['poll_options'][$i])) + if ($post_data['topic_first_post_id'] == $post_data['topic_last_post_id']) { - if (!$cur_poll_options[$i]) - { - $sql_insert_ary[] = array( - 'poll_option_id' => (int) $i, - 'topic_id' => (int) $data['topic_id'], - 'poll_option_text' => (string) $poll['poll_options'][$i] - ); - } - else if ($poll['poll_options'][$i] != $cur_poll_options[$i]) - { - $sql = "UPDATE " . POLL_OPTIONS_TABLE . " - SET poll_option_text = '" . $db->sql_escape($poll['poll_options'][$i]) . "' - WHERE poll_option_id = " . $cur_poll_options[$i]['poll_option_id'] . " - AND topic_id = " . $data['topic_id']; - $db->sql_query($sql); - } - } - } + add_log('mod', $forum_id, $topic_id, 'LOG_DELETE_TOPIC', $post_data['topic_title']); - if (sizeof($sql_insert_ary)) - { - switch (SQL_LAYER) - { - case 'mysql': - case 'mysql4': - case 'mysqli': - $db->sql_query('INSERT INTO ' . POLL_OPTIONS_TABLE . ' ' . $db->sql_build_array('MULTI_INSERT', $sql_insert_ary)); - break; - - default: - foreach ($sql_insert_ary as $ary) - { - $db->sql_query('INSERT INTO ' . POLL_OPTIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $ary)); - } - break; - } - } - - if (sizeof($poll['poll_options']) < sizeof($cur_poll_options)) - { - $sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . ' - WHERE poll_option_id >= ' . sizeof($poll['poll_options']) . ' - AND topic_id = ' . $data['topic_id']; - $db->sql_query($sql); - } - } - - // Submit Attachments - if (sizeof($data['attachment_data']) && $data['post_id'] && in_array($mode, array('post', 'reply', 'quote', 'edit'))) - { - $space_taken = $files_added = 0; - - foreach ($data['attachment_data'] as $pos => $attach_row) - { - if ($attach_row['attach_id']) - { - // update entry in db if attachment already stored in db and filespace - $sql = 'UPDATE ' . ATTACHMENTS_TABLE . " - SET comment = '" . $db->sql_escape($attach_row['comment']) . "' - WHERE attach_id = " . (int) $attach_row['attach_id']; - $db->sql_query($sql); + $meta_info = "{$phpbb_root_path}viewforum.$phpEx$SID&f=$forum_id"; + $message = $user->lang['POST_DELETED']; } else { - // insert attachment into db - if (!@file_exists($phpbb_root_path . $config['upload_path'] . '/' . basename($attach_row['physical_filename']))) - { - continue; - } - - $attach_sql = array( - 'post_msg_id' => $data['post_id'], - 'topic_id' => $data['topic_id'], - 'in_message' => 0, - 'poster_id' => $poster_id, - 'physical_filename' => basename($attach_row['physical_filename']), - 'real_filename' => basename($attach_row['real_filename']), - 'comment' => $attach_row['comment'], - 'extension' => $attach_row['extension'], - 'mimetype' => $attach_row['mimetype'], - 'filesize' => $attach_row['filesize'], - 'filetime' => $attach_row['filetime'], - 'thumbnail' => $attach_row['thumbnail'] - ); - - $sql = 'INSERT INTO ' . ATTACHMENTS_TABLE . ' ' . - $db->sql_build_array('INSERT', $attach_sql); - $db->sql_query($sql); + add_log('mod', $forum_id, $topic_id, 'LOG_DELETE_POST', $post_data['post_subject']); - $space_taken += $attach_row['filesize']; - $files_added++; + $meta_info = "{$phpbb_root_path}viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&p=$next_post_id#p$next_post_id"; + $message = $user->lang['POST_DELETED'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $meta_info . '">', '</a>'); } - } - if (sizeof($data['attachment_data'])) - { - $sql = 'UPDATE ' . POSTS_TABLE . ' - SET post_attachment = 1 - WHERE post_id = ' . $data['post_id']; - $db->sql_query($sql); - - $sql = 'UPDATE ' . TOPICS_TABLE . ' - SET topic_attachment = 1 - WHERE topic_id = ' . $data['topic_id']; - $db->sql_query($sql); + meta_refresh(3, $meta_info); + $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $phpbb_root_path . 'viewforum.' . $phpEx . $SID . '&f=' . $forum_id . '">', '</a>'); + trigger_error($message); } - - set_config('upload_dir_size', $config['upload_dir_size'] + $space_taken, true); - set_config('num_files', $config['num_files'] + $files_added, true); - } - - $db->sql_transaction('commit'); - - if ($post_mode == 'post' || $post_mode == 'reply' || $post_mode == 'edit_last_post') - { - if ($topic_type != POST_GLOBAL) - { - $update_sql = update_post_information('forum', $data['forum_id'], true); - if (sizeof($update_sql)) - { - $sql_data[FORUMS_TABLE]['stat'][] = implode(', ', $update_sql[$data['forum_id']]); - } - } - - $update_sql = update_post_information('topic', $data['topic_id'], true); - if (sizeof($update_sql)) - { - $sql_data[TOPICS_TABLE]['stat'][] = implode(', ', $update_sql[$data['topic_id']]); - } - } - - if ($make_global) - { - $update_sql = update_post_information('forum', $data['forum_id'], true); - if (sizeof($update_sql)) - { - $sql_data[FORUMS_TABLE]['stat'][] = implode(', ', $update_sql[$data['forum_id']]); - } - } - - if ($post_mode == 'edit_topic') - { - $update_sql = update_post_information('topic', $data['topic_id'], true); - if (sizeof($update_sql)) - { - $sql_data[TOPICS_TABLE]['stat'][] = implode(', ', $update_sql[$data['topic_id']]); - } - } - - // Update total post count, do not consider moderated posts/topics - if (!$auth->acl_get('f_moderate', $data['forum_id']) || $auth->acl_get('m_approve', $data['forum_id'])) - { - if ($post_mode == 'post') - { - set_config('num_topics', $config['num_topics'] + 1, true); - set_config('num_posts', $config['num_posts'] + 1, true); - } - - if ($post_mode == 'reply') - { - set_config('num_posts', $config['num_posts'] + 1, true); - } - } - - // Update forum stats - $db->sql_transaction(); - - $where_sql = array(POSTS_TABLE => 'post_id = ' . $data['post_id'], TOPICS_TABLE => 'topic_id = ' . $data['topic_id'], FORUMS_TABLE => 'forum_id = ' . $data['forum_id'], USERS_TABLE => 'user_id = ' . $user->data['user_id']); - - foreach ($sql_data as $table => $update_ary) - { - if (isset($update_ary['stat']) && implode('', $update_ary['stat'])) - { - $db->sql_query("UPDATE $table SET " . implode(', ', $update_ary['stat']) . ' WHERE ' . $where_sql[$table]); - } - } - - // Delete topic shadows (if any exist). We do not need a shadow topic for an global announcement - if ($make_global) - { - $db->sql_query('DELETE FROM ' . TOPICS_TABLE . ' - WHERE topic_moved_id = ' . $data['topic_id']); - } - - // Index message contents - if ($update_message && $data['enable_indexing']) - { - // Select the search method and do some additional checks to ensure it can actually be utilised - $search_type = $config['search_type']; - - if (!file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx)) - { - trigger_error('NO_SUCH_SEARCH_MODULE'); - } - - require("{$phpbb_root_path}includes/search/$search_type.$phpEx"); - - $error = false; - $search = new $search_type($error); - - if ($error) + else { - trigger_error($error); + confirm_box(false, 'DELETE_MESSAGE', $s_hidden_fields); } - - $search->index($mode, $data['post_id'], $data['message'], $subject, $poster_id); - } - - $db->sql_transaction('commit'); - - // Delete draft if post was loaded... - $draft_id = request_var('draft_loaded', 0); - if ($draft_id) - { - $db->sql_query('DELETE FROM ' . DRAFTS_TABLE . " WHERE draft_id = $draft_id AND user_id = " . $user->data['user_id']); - } - - // Topic Notification - if (!$data['notify_set'] && $data['notify']) - { - $sql = 'INSERT INTO ' . TOPICS_WATCH_TABLE . ' (user_id, topic_id) - VALUES (' . $user->data['user_id'] . ', ' . $data['topic_id'] . ')'; - $db->sql_query($sql); - } - else if ($data['notify_set'] && !$data['notify']) - { - $sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . ' - WHERE user_id = ' . $user->data['user_id'] . ' - AND topic_id = ' . $data['topic_id']; - $db->sql_query($sql); } - if ($mode == 'post' || $mode == 'reply' || $mode == 'quote') + // If we are here the user is not able to delete - present the correct error message + if ($post_data['poster_id'] != $user->data['user_id'] && !$auth->acl_get('f_delete', $forum_id)) { - // Mark this topic as posted to - markread('post', $data['forum_id'], $data['topic_id'], $data['post_time']); + trigger_error('DELETE_OWN_POSTS'); } - // Mark this topic as read - // We do not use post_time here, this is intended (post_time can have a date in the past if editing a message) - markread('topic', $data['forum_id'], $data['topic_id'], time()); - - // Send Notifications - if ($mode != 'edit' && $mode != 'delete' && (!$auth->acl_get('f_moderate', $data['forum_id']) || $auth->acl_get('m_approve', $data['forum_id']))) - { - user_notification($mode, stripslashes($subject), stripslashes($data['topic_title']), stripslashes($data['forum_name']), $data['forum_id'], $data['topic_id'], $data['post_id']); - } - - if ($mode == 'post') - { - $url = (!$auth->acl_get('f_moderate', $data['forum_id']) || $auth->acl_get('m_approve', $data['forum_id'])) ? "{$phpbb_root_path}viewtopic.$phpEx$SID&f=" . $data['forum_id'] . '&t=' . $data['topic_id'] : "{$phpbb_root_path}viewforum.$phpEx$SID&f=" . $data['forum_id']; - } - else + if ($post_data['poster_id'] == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id) && $post_id != $post_data['topic_last_post_id']) { - $url = (!$auth->acl_get('f_moderate', $data['forum_id']) || $auth->acl_get('m_approve', $data['forum_id'])) ? "{$phpbb_root_path}viewtopic.$phpEx$SID&f={$data['forum_id']}&t={$data['topic_id']}&p={$data['post_id']}#p{$data['post_id']}" : "{$phpbb_root_path}viewtopic.$phpEx$SID&f={$data['forum_id']}&t={$data['topic_id']}"; + trigger_error('CANNOT_DELETE_REPLIED'); } - meta_refresh(3, $url); - - $message = ($auth->acl_get('f_moderate', $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'); - $message = $user->lang[$message] . ((!$auth->acl_get('f_moderate', $data['forum_id']) || $auth->acl_get('m_approve', $data['forum_id'])) ? '<br /><br />' . sprintf($user->lang['VIEW_MESSAGE'], '<a href="' . $url . '">', '</a>') : '') . '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="viewforum.' . $phpEx . $SID .'&f=' . $data['forum_id'] . '">', '</a>'); - trigger_error($message); -} - -function upload_popup($forum_style = 0) -{ - global $template, $user; - - ($forum_style) ? $user->setup('posting', $forum_style) : $user->setup('posting'); - - page_header('PROGRESS_BAR'); - - $template->set_filenames(array( - 'popup' => 'posting_progress_bar.html') - ); - - $template->assign_vars(array( - 'PROGRESS_BAR' => $user->img('attach_progress_bar', $user->lang['UPLOAD_IN_PROGRESS'])) - ); - - $template->display('popup'); + trigger_error('USER_CANNOT_DELETE'); } ?>
\ No newline at end of file |