root / tags / milestone_3 / phpBB / posting.php
History | View | Annotate | Download (63.9 kB)
| 1 | <?php
|
|---|---|
| 2 | /**
|
| 3 | * |
| 4 | * @package phpBB3 |
| 5 | * @version $Id: posting.php 5249 2005-10-03 15:21:00Z acydburn $ |
| 6 | * @copyright (c) 2005 phpBB Group |
| 7 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
| 8 | * |
| 9 | */ |
| 10 | |
| 11 | /**
|
| 12 | */ |
| 13 | define('IN_PHPBB', true); |
| 14 | $phpbb_root_path = './'; |
| 15 | $phpEx = substr(strrchr(__FILE__, '.'), 1); |
| 16 | include($phpbb_root_path . 'common.'.$phpEx); |
| 17 | include($phpbb_root_path . 'includes/functions_admin.'.$phpEx); |
| 18 | include($phpbb_root_path . 'includes/functions_posting.'.$phpEx); |
| 19 | include($phpbb_root_path . 'includes/functions_display.' . $phpEx); |
| 20 | include($phpbb_root_path . 'includes/message_parser.'.$phpEx); |
| 21 | |
| 22 | |
| 23 | // Start session management
|
| 24 | $user->session_begin();
|
| 25 | $auth->acl($user->data); |
| 26 | |
| 27 | |
| 28 | // Grab only parameters needed here
|
| 29 | $post_id = request_var('p', 0); |
| 30 | $topic_id = request_var('t', 0); |
| 31 | $forum_id = request_var('f', 0); |
| 32 | $draft_id = request_var('d', 0); |
| 33 | $lastclick = request_var('lastclick', 0); |
| 34 | |
| 35 | $submit = (isset($_POST['post'])); |
| 36 | $preview = (isset($_POST['preview'])); |
| 37 | $save = (isset($_POST['save'])); |
| 38 | $load = (isset($_POST['load'])); |
| 39 | $cancel = (isset($_POST['cancel'])); |
| 40 | $confirm = (isset($_POST['confirm'])); |
| 41 | $delete = (isset($_POST['delete'])); |
| 42 | |
| 43 | $refresh = isset($_POST['add_file']) || isset($_POST['delete_file']) || isset($_POST['edit_comment']) || isset($_POST['cancel_unglobalise']) || $save || $load; |
| 44 | |
| 45 | $mode = ($delete && !$preview && !$refresh && $submit) ? 'delete' : request_var('mode', ''); |
| 46 | |
| 47 | $error = array(); |
| 48 | $current_time = time(); |
| 49 | |
| 50 | |
| 51 | // Was cancel pressed? If so then redirect to the appropriate page
|
| 52 | if ($cancel || ($current_time - $lastclick < 2 && $submit)) |
| 53 | {
|
| 54 | $redirect = ($post_id) ? "viewtopic.$phpEx$SID&p=$post_id#$post_id" : (($topic_id) ? "viewtopic.$phpEx$SID&t=$topic_id" : (($forum_id) ? "viewforum.$phpEx$SID&f=$forum_id" : "index.$phpEx$SID")); |
| 55 | redirect($redirect);
|
| 56 | } |
| 57 | |
| 58 | if (in_array($mode, array('post', 'reply', 'quote', 'edit', 'delete', 'popup')) && !$forum_id) |
| 59 | {
|
| 60 | trigger_error('NO_FORUM'); |
| 61 | } |
| 62 | |
| 63 | // What is all this following SQL for? Well, we need to know
|
| 64 | // some basic information in all cases before we do anything.
|
| 65 | switch ($mode) |
| 66 | {
|
| 67 | case 'post': |
| 68 | $sql = 'SELECT * |
| 69 | FROM ' . FORUMS_TABLE . " |
| 70 | WHERE forum_id = $forum_id"; |
| 71 | break;
|
| 72 | |
| 73 | case 'bump': |
| 74 | case 'reply': |
| 75 | if (!$topic_id) |
| 76 | {
|
| 77 | trigger_error('NO_TOPIC'); |
| 78 | } |
| 79 | |
| 80 | $sql = 'SELECT f.*, t.* |
| 81 | FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f |
| 82 | WHERE t.topic_id = $topic_id |
| 83 | AND (f.forum_id = t.forum_id |
| 84 | OR f.forum_id = $forum_id)"; |
| 85 | break;
|
| 86 | |
| 87 | case 'quote': |
| 88 | case 'edit': |
| 89 | case 'delete': |
| 90 | if (!$post_id) |
| 91 | {
|
| 92 | trigger_error('NO_POST'); |
| 93 | } |
| 94 | |
| 95 | $sql = 'SELECT f.*, t.*, p.*, u.username, u.user_sig, u.user_sig_bbcode_uid, u.user_sig_bbcode_bitfield |
| 96 | FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . ' f, ' . USERS_TABLE . " u |
| 97 | WHERE p.post_id = $post_id |
| 98 | AND t.topic_id = p.topic_id |
| 99 | AND u.user_id = p.poster_id |
| 100 | AND (f.forum_id = t.forum_id |
| 101 | OR f.forum_id = $forum_id)"; |
| 102 | break;
|
| 103 | |
| 104 | case 'smilies': |
| 105 | $sql = ''; |
| 106 | generate_smilies('window', $forum_id); |
| 107 | break;
|
| 108 | |
| 109 | case 'popup': |
| 110 | $sql = 'SELECT forum_style |
| 111 | FROM ' . FORUMS_TABLE . ' |
| 112 | WHERE forum_id = ' . $forum_id; |
| 113 | break;
|
| 114 | |
| 115 | default:
|
| 116 | $sql = ''; |
| 117 | trigger_error('NO_POST_MODE'); |
| 118 | } |
| 119 | |
| 120 | if ($sql) |
| 121 | {
|
| 122 | $result = $db->sql_query($sql); |
| 123 | |
| 124 | extract($db->sql_fetchrow($result)); |
| 125 | $db->sql_freeresult($result); |
| 126 | |
| 127 | if ($mode == 'popup') |
| 128 | {
|
| 129 | upload_popup($forum_style);
|
| 130 | exit;
|
| 131 | } |
| 132 | |
| 133 | $quote_username = (isset($username)) ? $username : ((isset($post_username)) ? $post_username : ''); |
| 134 | |
| 135 | $forum_id = (int) $forum_id; |
| 136 | $topic_id = (int) $topic_id; |
| 137 | $post_id = (int) $post_id; |
| 138 | |
| 139 | // Global Topic? - Adjust forum id
|
| 140 | if (!$forum_id && $topic_type == POST_GLOBAL) |
| 141 | {
|
| 142 | $forum_id = request_var('f', 0); |
| 143 | } |
| 144 | |
| 145 | $post_edit_locked = (isset($post_edit_locked)) ? (int) $post_edit_locked : 0; |
| 146 | |
| 147 | $user->setup(array('posting', 'mcp', 'viewtopic'), $forum_style); |
| 148 | |
| 149 | if ($forum_password) |
| 150 | {
|
| 151 | $forum_info = array( |
| 152 | 'forum_id' => $forum_id, |
| 153 | 'forum_password'=> $forum_password |
| 154 | ); |
| 155 | |
| 156 | login_forum_box($forum_info);
|
| 157 | unset($forum_info); |
| 158 | } |
| 159 | |
| 160 | $post_subject = (in_array($mode, array('quote', 'edit', 'delete'))) ? $post_subject : ((isset($topic_title)) ? $topic_title : ''); |
| 161 | |
| 162 | $topic_time_limit = (isset($topic_time_limit)) ? (($topic_time_limit) ? (int) $topic_time_limit / 86400 : (int) $topic_time_limit) : 0; |
| 163 | |
| 164 | $poll_length = (isset($poll_length)) ? (($poll_length) ? (int) $poll_length / 86400 : (int) $poll_length) : 0; |
| 165 | $poll_start = (isset($poll_start)) ? (int) $poll_start : 0; |
| 166 | $poll_options = array(); |
| 167 | |
| 168 | if (!isset($icon_id) || in_array($mode, array('quote', 'reply'))) |
| 169 | {
|
| 170 | $icon_id = 0; |
| 171 | } |
| 172 | |
| 173 | // Get Poll Data
|
| 174 | if ($poll_start) |
| 175 | {
|
| 176 | $sql = 'SELECT poll_option_text |
| 177 | FROM ' . POLL_OPTIONS_TABLE . " |
| 178 | WHERE topic_id = $topic_id |
| 179 | ORDER BY poll_option_id";
|
| 180 | $result = $db->sql_query($sql); |
| 181 | |
| 182 | while ($row = $db->sql_fetchrow($result)) |
| 183 | {
|
| 184 | $poll_options[] = trim($row['poll_option_text']); |
| 185 | } |
| 186 | $db->sql_freeresult($result); |
| 187 | } |
| 188 | |
| 189 | $orig_poll_options_size = sizeof($poll_options); |
| 190 | $message_parser = new parse_message(); |
| 191 | |
| 192 | if (isset($post_text)) |
| 193 | {
|
| 194 | $message_parser->message = $post_text; |
| 195 | unset($post_text); |
| 196 | } |
| 197 | |
| 198 | $message_parser->get_submitted_attachment_data();
|
| 199 | |
| 200 | // Set uninitialized variables
|
| 201 | $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' => ''); |
| 202 | foreach ($uninit as $var_name => $default_value) |
| 203 | {
|
| 204 | if (!isset($$var_name)) |
| 205 | {
|
| 206 | $$var_name = $default_value; |
| 207 | } |
| 208 | } |
| 209 | unset($uninit, $var_name, $default_value); |
| 210 | |
| 211 | if ($post_attachment && !$submit && !$refresh && !$preview && $mode == 'edit') |
| 212 | {
|
| 213 | $sql = 'SELECT attach_id, physical_filename, comment, real_filename, extension, mimetype, filesize, filetime, thumbnail |
| 214 | FROM ' . ATTACHMENTS_TABLE . " |
| 215 | WHERE post_msg_id = $post_id |
| 216 | AND in_message = 0 |
| 217 | ORDER BY filetime " . ((!$config['display_order']) ? 'DESC' : 'ASC'); |
| 218 | $result = $db->sql_query($sql); |
| 219 | |
| 220 | $message_parser->attachment_data = array_merge($message_parser->attachment_data, $db->sql_fetchrowset($result)); |
| 221 | |
| 222 | $db->sql_freeresult($result); |
| 223 | } |
| 224 | |
| 225 | if ($poster_id == ANONYMOUS || !$poster_id) |
| 226 | {
|
| 227 | $username = (in_array($mode, array('quote', 'edit', 'delete'))) ? trim($post_username) : ''; |
| 228 | } |
| 229 | else
|
| 230 | {
|
| 231 | $username = (in_array($mode, array('quote', 'edit', 'delete'))) ? trim($username) : ''; |
| 232 | } |
| 233 | |
| 234 | $enable_urls = $enable_magic_url; |
| 235 | |
| 236 | $enable_html = (isset($enable_html)) ? $enable_html : $config['allow_html']; |
| 237 | |
| 238 | if (!in_array($mode, array('quote', 'edit', 'delete'))) |
| 239 | {
|
| 240 | $enable_sig = ($config['allow_sig'] && $user->optionget('attachsig')); |
| 241 | $enable_smilies = ($config['allow_smilies'] && $user->optionget('smilies')); |
| 242 | $enable_bbcode = ($config['allow_bbcode'] && $user->optionget('bbcode')); |
| 243 | $enable_urls = true; |
| 244 | } |
| 245 | |
| 246 | $enable_magic_url = $drafts = false; |
| 247 | |
| 248 | // User own some drafts?
|
| 249 | if ($user->data['is_registered'] && $auth->acl_get('u_savedrafts') && $mode != 'delete') |
| 250 | {
|
| 251 | $sql = 'SELECT draft_id |
| 252 | FROM ' . DRAFTS_TABLE . ' |
| 253 | WHERE (forum_id = ' . $forum_id . (($topic_id) ? " OR topic_id = $topic_id" : '') . ') |
| 254 | AND user_id = ' . $user->data['user_id'] . |
| 255 | (($draft_id) ? " AND draft_id <> $draft_id" : ''); |
| 256 | $result = $db->sql_query_limit($sql, 1); |
| 257 | |
| 258 | if ($db->sql_fetchrow($result)) |
| 259 | {
|
| 260 | $drafts = true; |
| 261 | } |
| 262 | $db->sql_freeresult($result); |
| 263 | } |
| 264 | |
| 265 | $check_value = (($enable_html+1) << 16) + (($enable_bbcode+1) << 8) + (($enable_smilies+1) << 4) + (($enable_urls+1) << 2) + (($enable_sig+1) << 1); |
| 266 | } |
| 267 | |
| 268 | // Notify user checkbox
|
| 269 | if ($mode != 'post' && $user->data['is_registered']) |
| 270 | {
|
| 271 | $sql = 'SELECT topic_id |
| 272 | FROM ' . TOPICS_WATCH_TABLE . ' |
| 273 | WHERE topic_id = ' . $topic_id . ' |
| 274 | AND user_id = ' . $user->data['user_id']; |
| 275 | $result = $db->sql_query_limit($sql, 1); |
| 276 | $notify_set = ($db->sql_fetchrow($result)) ? 1 : 0; |
| 277 | $db->sql_freeresult($result); |
| 278 | } |
| 279 | else
|
| 280 | {
|
| 281 | $notify_set = 0; |
| 282 | } |
| 283 | |
| 284 | if (!$auth->acl_get('f_' . $mode, $forum_id) && $forum_type == FORUM_POST) |
| 285 | {
|
| 286 | if ($user->data['is_registered']) |
| 287 | {
|
| 288 | trigger_error('USER_CANNOT_' . strtoupper($mode)); |
| 289 | } |
| 290 | |
| 291 | login_box('', $user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)]); |
| 292 | } |
| 293 | |
| 294 | |
| 295 | // Forum/Topic locked?
|
| 296 | if (($forum_status == ITEM_LOCKED || $topic_status == ITEM_LOCKED) && !$auth->acl_get('m_edit', $forum_id)) |
| 297 | {
|
| 298 | $message = ($forum_status == ITEM_LOCKED) ? 'FORUM_LOCKED' : 'TOPIC_LOCKED'; |
| 299 | trigger_error($message); |
| 300 | } |
| 301 | |
| 302 | // Can we edit this post ... if we're a moderator with rights then always yes
|
| 303 | // else it depends on editing times, lock status and if we're the correct user
|
| 304 | // !$preview && !$refresh && !$submit &&
|
| 305 | if ($mode == 'edit' && !$preview && !$refresh && !$submit && !$auth->acl_get('m_edit', $forum_id)) |
| 306 | {
|
| 307 | if ($user->data['user_id'] != $poster_id) |
| 308 | {
|
| 309 | trigger_error('USER_CANNOT_EDIT'); |
| 310 | } |
| 311 | |
| 312 | if (!($post_time > time() - $config['edit_time'] || !$config['edit_time'])) |
| 313 | {
|
| 314 | trigger_error('CANNOT_EDIT_TIME'); |
| 315 | } |
| 316 | |
| 317 | if ($post_edit_locked) |
| 318 | {
|
| 319 | trigger_error('CANNOT_EDIT_POST_LOCKED'); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | // Do we want to edit our post ?
|
| 324 | |
| 325 | if ($mode == 'edit') |
| 326 | {
|
| 327 | $message_parser->bbcode_uid = $bbcode_uid; |
| 328 | } |
| 329 | |
| 330 | |
| 331 | // Delete triggered ?
|
| 332 | 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))) |
| 333 | {
|
| 334 | $s_hidden_fields = build_hidden_fields(array( |
| 335 | 'p' => $post_id, |
| 336 | 'f' => $forum_id, |
| 337 | 'mode' => 'delete') |
| 338 | ); |
| 339 | |
| 340 | if (confirm_box(true)) |
| 341 | {
|
| 342 | $data = array( |
| 343 | 'topic_first_post_id' => $topic_first_post_id, |
| 344 | 'topic_last_post_id' => $topic_last_post_id, |
| 345 | 'topic_approved' => $topic_approved, |
| 346 | 'topic_type' => $topic_type, |
| 347 | 'post_approved' => $post_approved, |
| 348 | 'post_time' => $post_time, |
| 349 | 'poster_id' => $poster_id |
| 350 | ); |
| 351 | |
| 352 | $next_post_id = delete_post($mode, $post_id, $topic_id, $forum_id, $data); |
| 353 | |
| 354 | if ($topic_first_post_id == $topic_last_post_id) |
| 355 | {
|
| 356 | add_log('mod', $forum_id, $topic_id, 'LOG_DELETE_TOPIC', $topic_title); |
| 357 | |
| 358 | $meta_info = "{$phpbb_root_path}viewforum.$phpEx$SID&f=$forum_id"; |
| 359 | $message = $user->lang['POST_DELETED']; |
| 360 | } |
| 361 | else
|
| 362 | {
|
| 363 | add_log('mod', $forum_id, $topic_id, 'LOG_DELETE_POST', $post_subject); |
| 364 | |
| 365 | $meta_info = "{$phpbb_root_path}viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&p=$next_post_id#$next_post_id"; |
| 366 | $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#$next_post_id\">", '</a>'); |
| 367 | } |
| 368 | |
| 369 | meta_refresh(3, $meta_info); |
| 370 | $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], "<a href=\"{$phpbb_root_path}viewforum.$phpEx$SID&f=$forum_id\">", '</a>'); |
| 371 | trigger_error($message); |
| 372 | } |
| 373 | else
|
| 374 | {
|
| 375 | confirm_box(false, 'DELETE_MESSAGE', $s_hidden_fields); |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | |
| 380 | if ($mode == 'delete' && $poster_id != $user->data['user_id'] && !$auth->acl_get('f_delete', $forum_id)) |
| 381 | {
|
| 382 | trigger_error('DELETE_OWN_POSTS'); |
| 383 | } |
| 384 | |
| 385 | if ($mode == 'delete' && $poster_id == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id) && $post_id != $topic_last_post_id) |
| 386 | {
|
| 387 | trigger_error('CANNOT_DELETE_REPLIED'); |
| 388 | } |
| 389 | |
| 390 | if ($mode == 'delete') |
| 391 | {
|
| 392 | trigger_error('USER_CANNOT_DELETE'); |
| 393 | } |
| 394 | |
| 395 | |
| 396 | // HTML, BBCode, Smilies, Images and Flash status
|
| 397 | $html_status = ($config['allow_html'] && $auth->acl_get('f_html', $forum_id)); |
| 398 | $bbcode_status = ($config['allow_bbcode'] && $auth->acl_get('f_bbcode', $forum_id)); |
| 399 | $smilies_status = ($config['allow_smilies'] && $auth->acl_get('f_smilies', $forum_id)); |
| 400 | $img_status = ($auth->acl_get('f_img', $forum_id)); |
| 401 | $flash_status = ($auth->acl_get('f_flash', $forum_id)); |
| 402 | $quote_status = ($auth->acl_get('f_quote', $forum_id)); |
| 403 | |
| 404 | // Bump Topic
|
| 405 | if ($mode == 'bump' && ($bump_time = bump_topic_allowed($forum_id, $topic_bumped, $topic_last_post_time, $topic_poster, $topic_last_poster_id))) |
| 406 | {
|
| 407 | $db->sql_transaction();
|
| 408 | |
| 409 | $db->sql_query('UPDATE ' . POSTS_TABLE . " |
| 410 | SET post_time = $current_time |
| 411 | WHERE post_id = $topic_last_post_id |
| 412 | AND topic_id = $topic_id"); |
| 413 | |
| 414 | $db->sql_query('UPDATE ' . TOPICS_TABLE . " |
| 415 | SET topic_last_post_time = $current_time, |
| 416 | topic_bumped = 1, |
| 417 | topic_bumper = " . $user->data['user_id'] . " |
| 418 | WHERE topic_id = $topic_id"); |
| 419 | |
| 420 | $db->sql_query('UPDATE ' . FORUMS_TABLE . ' |
| 421 | SET ' . implode(', ', update_last_post_information('forum', $forum_id)) . " |
| 422 | WHERE forum_id = $forum_id"); |
| 423 | |
| 424 | $db->sql_query('UPDATE ' . USERS_TABLE . " |
| 425 | SET user_lastpost_time = $current_time |
| 426 | WHERE user_id = " . $user->data['user_id']); |
| 427 | |
| 428 | $db->sql_transaction('commit'); |
| 429 | |
| 430 | markread('post', $forum_id, $topic_id, $current_time); |
| 431 | |
| 432 | add_log('mod', $forum_id, $topic_id, sprintf($user->lang['LOGM_BUMP'], $topic_title)); |
| 433 | |
| 434 | meta_refresh(3, "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&p=$topic_last_post_id#$topic_last_post_id"); |
| 435 | |
| 436 | $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#$topic_last_post_id\">", '</a>') . '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="viewforum.' . $phpEx . $SID .'&f=' . $forum_id . '">', '</a>'); |
| 437 | |
| 438 | trigger_error($message); |
| 439 | } |
| 440 | else if ($mode == 'bump') |
| 441 | {
|
| 442 | trigger_error('BUMP_ERROR'); |
| 443 | } |
| 444 | |
| 445 | // Save Draft
|
| 446 | if ($save && $user->data['is_registered'] && $auth->acl_get('u_savedrafts')) |
| 447 | {
|
| 448 | $subject = request_var('subject', '', true); |
| 449 | $subject = (!$subject && $mode != 'post') ? $topic_title : $subject; |
| 450 | $message = request_var('message', '', true); |
| 451 | |
| 452 | if ($subject && $message) |
| 453 | {
|
| 454 | $sql = 'INSERT INTO ' . DRAFTS_TABLE . ' ' . $db->sql_build_array('INSERT', array( |
| 455 | 'user_id' => $user->data['user_id'], |
| 456 | 'topic_id' => $topic_id, |
| 457 | 'forum_id' => $forum_id, |
| 458 | 'save_time' => $current_time, |
| 459 | 'draft_subject' => $subject, |
| 460 | 'draft_message' => $message)); |
| 461 | $db->sql_query($sql); |
| 462 | |
| 463 | $meta_info = ($mode == 'post') ? "viewforum.$phpEx$SID&f=$forum_id" : "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id"; |
| 464 | |
| 465 | meta_refresh(3, $meta_info); |
| 466 | |
| 467 | $message = $user->lang['DRAFT_SAVED'] . '<br /><br />'; |
| 468 | $message .= ($mode != 'post') ? sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $meta_info . '">', '</a>') . '<br /><br />' : ''; |
| 469 | $message .= sprintf($user->lang['RETURN_FORUM'], '<a href="viewforum.' . $phpEx . $SID . '&f=' . $forum_id . '">', '</a>'); |
| 470 | |
| 471 | trigger_error($message); |
| 472 | } |
| 473 | |
| 474 | unset($subject); |
| 475 | unset($message); |
| 476 | } |
| 477 | |
| 478 | // Load Draft
|
| 479 | if ($draft_id && $user->data['is_registered'] && $auth->acl_get('u_savedrafts')) |
| 480 | {
|
| 481 | $sql = 'SELECT draft_subject, draft_message |
| 482 | FROM ' . DRAFTS_TABLE . " |
| 483 | WHERE draft_id = $draft_id |
| 484 | AND user_id = " . $user->data['user_id']; |
| 485 | $result = $db->sql_query_limit($sql, 1); |
| 486 | |
| 487 | if ($row = $db->sql_fetchrow($result)) |
| 488 | {
|
| 489 | $_REQUEST['subject'] = strtr($row['draft_subject'], array_flip(get_html_translation_table(HTML_ENTITIES))); |
| 490 | $_POST['message'] = strtr($row['draft_message'], array_flip(get_html_translation_table(HTML_ENTITIES))); |
| 491 | $refresh = true; |
| 492 | $template->assign_var('S_DRAFT_LOADED', true); |
| 493 | } |
| 494 | else
|
| 495 | {
|
| 496 | $draft_id = 0; |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | // Load Drafts
|
| 501 | if ($load && $drafts) |
| 502 | {
|
| 503 | load_drafts($topic_id, $forum_id); |
| 504 | } |
| 505 | |
| 506 | if ($submit || $preview || $refresh) |
| 507 | {
|
| 508 | $topic_cur_post_id = request_var('topic_cur_post_id', 0); |
| 509 | $subject = request_var('subject', '', true); |
| 510 | |
| 511 | if (strcmp($subject, strtoupper($subject)) == 0 && $subject) |
| 512 | {
|
| 513 | $subject = strtolower($subject); |
| 514 | } |
| 515 | |
| 516 | $message_parser->message = request_var('message', '', true); |
| 517 | |
| 518 | $username = (isset($_POST['username'])) ? request_var('username', '') : $username; |
| 519 | $post_edit_reason = (isset($_POST['edit_reason']) && !empty($_POST['edit_reason']) && $mode == 'edit' && $user->data['user_id'] != $poster_id) ? request_var('edit_reason', '') : ''; |
| 520 | |
| 521 | $topic_type = (isset($_POST['topic_type'])) ? (int) $_POST['topic_type'] : (($mode != 'post') ? $topic_type : POST_NORMAL); |
| 522 | $topic_time_limit = (isset($_POST['topic_time_limit'])) ? (int) $_POST['topic_time_limit'] : (($mode != 'post') ? $topic_time_limit : 0); |
| 523 | $icon_id = request_var('icon', 0); |
| 524 | |
| 525 | $enable_html = (!$html_status || isset($_POST['disable_html'])) ? false : true; |
| 526 | $enable_bbcode = (!$bbcode_status || isset($_POST['disable_bbcode'])) ? false : true; |
| 527 | $enable_smilies = (!$smilies_status || isset($_POST['disable_smilies'])) ? false : true; |
| 528 | $enable_urls = (isset($_POST['disable_magic_url'])) ? 0 : 1; |
| 529 | $enable_sig = (!$config['allow_sig']) ? false : ((isset($_POST['attach_sig']) && $user->data['is_registered']) ? true : false); |
| 530 | |
| 531 | $notify = (isset($_POST['notify'])); |
| 532 | $topic_lock = (isset($_POST['lock_topic'])); |
| 533 | $post_lock = (isset($_POST['lock_post'])); |
| 534 | |
| 535 | $poll_delete = (isset($_POST['poll_delete'])); |
| 536 | |
| 537 | if ($submit) |
| 538 | {
|
| 539 | $status_switch = (($enable_html+1) << 16) + (($enable_bbcode+1) << 8) + (($enable_smilies+1) << 4) + (($enable_urls+1) << 2) + (($enable_sig+1) << 1); |
| 540 | $status_switch = ($status_switch != $check_value); |
| 541 | } |
| 542 | else
|
| 543 | {
|
| 544 | $status_switch = 1; |
| 545 | } |
| 546 | |
| 547 | // Delete Poll
|
| 548 | if ($poll_delete && $mode == 'edit' && $poll_options && |
| 549 | ((!$poll_last_vote && $poster_id == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id)) || $auth->acl_get('m_delete', $forum_id))) |
| 550 | {
|
| 551 | switch (SQL_LAYER) |
| 552 | {
|
| 553 | case 'mysql4': |
| 554 | case 'mysqli': |
| 555 | $sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . ', ' . POLL_VOTES_TABLE . " |
| 556 | WHERE topic_id = $topic_id"; |
| 557 | $db->sql_query($sql); |
| 558 | break;
|
| 559 | |
| 560 | default:
|
| 561 | $sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . " |
| 562 | WHERE topic_id = $topic_id"; |
| 563 | $db->sql_query($sql); |
| 564 | |
| 565 | $sql = 'DELETE FROM ' . POLL_VOTES_TABLE . " |
| 566 | WHERE topic_id = $topic_id"; |
| 567 | $db->sql_query($sql); |
| 568 | } |
| 569 | |
| 570 | $topic_sql = array( |
| 571 | 'poll_title' => '', |
| 572 | 'poll_start' => 0, |
| 573 | 'poll_length' => 0, |
| 574 | 'poll_last_vote' => 0, |
| 575 | 'poll_max_options' => 0, |
| 576 | 'poll_vote_change' => 0 |
| 577 | ); |
| 578 | |
| 579 | $sql = 'UPDATE ' . TOPICS_TABLE . ' |
| 580 | SET ' . $db->sql_build_array('UPDATE', $topic_sql) . " |
| 581 | WHERE topic_id = $topic_id"; |
| 582 | $db->sql_query($sql); |
| 583 | |
| 584 | $poll_title = $poll_option_text = ''; |
| 585 | $poll_vote_change = $poll_max_options = $poll_length = 0; |
| 586 | } |
| 587 | else
|
| 588 | {
|
| 589 | $poll_title = request_var('poll_title', ''); |
| 590 | $poll_length = request_var('poll_length', 0); |
| 591 | $poll_option_text = request_var('poll_option_text', ''); |
| 592 | $poll_max_options = request_var('poll_max_options', 1); |
| 593 | $poll_vote_change = ($auth->acl_get('f_votechg', $forum_id) && isset($_POST['poll_vote_change'])) ? 1 : 0; |
| 594 | } |
| 595 | |
| 596 | // If replying/quoting and last post id has changed
|
| 597 | // give user option to continue submit or return to post
|
| 598 | // notify and show user the post made between his request and the final submit
|
| 599 | if (($mode == 'reply' || $mode == 'quote') && $topic_cur_post_id && $topic_cur_post_id != $topic_last_post_id) |
| 600 | {
|
| 601 | if (topic_review($topic_id, $forum_id, 'post_review', $topic_cur_post_id)) |
| 602 | {
|
| 603 | $template->assign_var('S_POST_REVIEW', true); |
| 604 | } |
| 605 | $submit = false; |
| 606 | $refresh = true; |
| 607 | } |
| 608 | |
| 609 | // Parse Attachments - before checksum is calculated
|
| 610 | $message_parser->parse_attachments('fileupload', $mode, $forum_id, $submit, $preview, $refresh); |
| 611 | |
| 612 | // Grab md5 'checksum' of new message
|
| 613 | $message_md5 = md5($message_parser->message); |
| 614 | |
| 615 | // Check checksum ... don't re-parse message if the same
|
| 616 | $update_message = ($mode != 'edit' || $message_md5 != $post_checksum || $status_switch) ? true : false; |
| 617 | |
| 618 | // Parse message
|
| 619 | if ($update_message) |
| 620 | {
|
| 621 | $message_parser->parse($enable_html, $enable_bbcode, $enable_urls, $enable_smilies, $img_status, $flash_status, $quote_status); |
| 622 | } |
| 623 | else
|
| 624 | {
|
| 625 | $message_parser->bbcode_bitfield = $bbcode_bitfield; |
| 626 | } |
| 627 | |
| 628 | if ($mode != 'edit' && !$preview && !$refresh && $config['flood_interval'] && !$auth->acl_get('f_ignoreflood', $forum_id)) |
| 629 | {
|
| 630 | // Flood check
|
| 631 | $last_post_time = 0; |
| 632 | |
| 633 | if ($user->data['is_registered']) |
| 634 | {
|
| 635 | $last_post_time = $user->data['user_lastpost_time']; |
| 636 | } |
| 637 | else
|
| 638 | {
|
| 639 | $sql = 'SELECT post_time AS last_post_time |
| 640 | FROM ' . POSTS_TABLE . " |
| 641 | WHERE poster_ip = '" . $user->ip . "' |
| 642 | AND post_time > " . ($current_time - $config['flood_interval']); |
| 643 | $result = $db->sql_query_limit($sql, 1); |
| 644 | if ($row = $db->sql_fetchrow($result)) |
| 645 | {
|
| 646 | $last_post_time = $row['last_post_time']; |
| 647 | } |
| 648 | $db->sql_freeresult($result); |
| 649 | } |
| 650 | |
| 651 | if ($last_post_time) |
| 652 | {
|
| 653 | if ($last_post_time && ($current_time - $last_post_time) < intval($config['flood_interval'])) |
| 654 | {
|
| 655 | $error[] = $user->lang['FLOOD_ERROR']; |
| 656 | } |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | // Validate username
|
| 661 | if (($username && !$user->data['is_registered']) || ($mode == 'edit' && $post_username)) |
| 662 | {
|
| 663 | include($phpbb_root_path . 'includes/functions_user.' . $phpEx); |
| 664 | |
| 665 | if (($result = validate_username(($mode == 'edit' && $post_username) ? $post_username : $username)) != false) |
| 666 | {
|
| 667 | $error[] = $result; |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | // Parse subject
|
| 672 | if (!$subject && ($mode == 'post' || ($mode == 'edit' && $topic_first_post_id == $post_id))) |
| 673 | {
|
| 674 | $error[] = $user->lang['EMPTY_SUBJECT']; |
| 675 | } |
| 676 | |
| 677 | $poll_last_vote = (isset($poll_last_vote)) ? $poll_last_vote : 0; |
| 678 | |
| 679 | if ($poll_option_text && |
| 680 | ($mode == 'post' || ($mode == 'edit' && $post_id == $topic_first_post_id && (!$poll_last_vote || $auth->acl_get('m_edit', $forum_id)))) |
| 681 | && $auth->acl_get('f_poll', $forum_id)) |
| 682 | {
|
| 683 | $poll = array( |
| 684 | 'poll_title' => $poll_title, |
| 685 | 'poll_length' => $poll_length, |
| 686 | 'poll_max_options' => $poll_max_options, |
| 687 | 'poll_option_text' => $poll_option_text, |
| 688 | 'poll_start' => $poll_start, |
| 689 | 'poll_last_vote' => $poll_last_vote, |
| 690 | 'poll_vote_change' => $poll_vote_change, |
| 691 | 'enable_html' => $enable_html, |
| 692 | 'enable_bbcode' => $enable_bbcode, |
| 693 | 'enable_urls' => $enable_urls, |
| 694 | 'enable_smilies' => $enable_smilies, |
| 695 | 'img_status' => $img_status |
| 696 | ); |
| 697 | |
| 698 | $message_parser->parse_poll($poll); |
| 699 | |
| 700 | $poll_options = isset($poll['poll_options']) ? $poll['poll_options'] : ''; |
| 701 | $poll_title = isset($poll['poll_title']) ? $poll['poll_title'] : ''; |
| 702 | |
| 703 | if ($poll_last_vote && ($poll['poll_options_size'] < $orig_poll_options_size)) |
| 704 | {
|
| 705 | $message_parser->warn_msg[] = $user->lang['NO_DELETE_POLL_OPTIONS']; |
| 706 | } |
| 707 | } |
| 708 | else
|
| 709 | {
|
| 710 | $poll = array(); |
| 711 | } |
| 712 | |
| 713 | // Check topic type
|
| 714 | if ($topic_type != POST_NORMAL && ($mode == 'post' || ($mode == 'edit' && $topic_first_post_id == $post_id))) |
| 715 | {
|
| 716 | switch ($topic_type) |
| 717 | {
|
| 718 | case POST_GLOBAL: |
| 719 | case POST_ANNOUNCE: |
| 720 | $auth_option = 'f_announce'; |
| 721 | break;
|
| 722 | case POST_STICKY: |
| 723 | $auth_option = 'f_sticky'; |
| 724 | break;
|
| 725 | default:
|
| 726 | $auth_option = ''; |
| 727 | } |
| 728 | |
| 729 | if (!$auth->acl_get($auth_option, $forum_id)) |
| 730 | {
|
| 731 | $error[] = $user->lang['CANNOT_POST_' . str_replace('F_', '', strtoupper($auth_option))]; |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | if (sizeof($message_parser->warn_msg)) |
| 736 | {
|
| 737 | $error[] = implode('<br />', $message_parser->warn_msg); |
| 738 | } |
| 739 | |
| 740 | // Store message, sync counters
|
| 741 | if (!sizeof($error) && $submit) |
| 742 | {
|
| 743 | // Check if we want to de-globalize the topic... and ask for new forum
|
| 744 | if ($topic_type != POST_GLOBAL) |
| 745 | {
|
| 746 | $sql = 'SELECT topic_type, forum_id |
| 747 | FROM ' . TOPICS_TABLE . " |
| 748 | WHERE topic_id = $topic_id"; |
| 749 | $result = $db->sql_query_limit($sql, 1); |
| 750 | |
| 751 | $row = $db->sql_fetchrow($result); |
| 752 | |
| 753 | if ($row && !$row['forum_id'] && $row['topic_type'] == POST_GLOBAL) |
| 754 | {
|
| 755 | $to_forum_id = request_var('to_forum_id', 0); |
| 756 | |
| 757 | if (!$to_forum_id) |
| 758 | {
|
| 759 | $template->assign_vars(array( |
| 760 | 'S_FORUM_SELECT' => make_forum_select(false, false, false, true, true), |
| 761 | 'S_UNGLOBALISE' => true) |
| 762 | ); |
| 763 | |
| 764 | $submit = false; |
| 765 | $refresh = true; |
| 766 | } |
| 767 | else
|
| 768 | {
|
| 769 | $forum_id = $to_forum_id; |
| 770 | } |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | if ($submit) |
| 775 | {
|
| 776 | // Lock/Unlock Topic
|
| 777 | $change_topic_status = $topic_status; |
| 778 | $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)); |
| 779 | |
| 780 | if ($topic_status == ITEM_LOCKED && !$topic_lock && $perm_lock_unlock) |
| 781 | {
|
| 782 | $change_topic_status = ITEM_UNLOCKED; |
| 783 | } |
| 784 | else if ($topic_status == ITEM_UNLOCKED && $topic_lock && $perm_lock_unlock) |
| 785 | {
|
| 786 | $change_topic_status = ITEM_LOCKED; |
| 787 | } |
| 788 | |
| 789 | if ($change_topic_status != $topic_status) |
| 790 | {
|
| 791 | $sql = 'UPDATE ' . TOPICS_TABLE . " |
| 792 | SET topic_status = $change_topic_status |
| 793 | WHERE topic_id = $topic_id |
| 794 | AND topic_moved_id = 0";
|
| 795 | $db->sql_query($sql); |
| 796 | |
| 797 | $user_lock = ($auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && $user->data['user_id'] == $topic_poster) ? 'USER_' : ''; |
| 798 | |
| 799 | add_log('mod', $forum_id, $topic_id, 'LOG_' . $user_lock . (($change_topic_status == ITEM_LOCKED) ? 'LOCK' : 'UNLOCK'), $topic_title); |
| 800 | } |
| 801 | |
| 802 | // Lock/Unlock Post Edit
|
| 803 | if ($mode == 'edit' && $post_edit_locked == ITEM_LOCKED && !$post_lock && $auth->acl_get('m_edit', $forum_id)) |
| 804 | {
|
| 805 | $post_edit_locked = ITEM_UNLOCKED; |
| 806 | } |
| 807 | else if ($mode == 'edit' && $post_edit_locked == ITEM_UNLOCKED && $post_lock && $auth->acl_get('m_edit', $forum_id)) |
| 808 | {
|
| 809 | $post_edit_locked = ITEM_LOCKED; |
| 810 | } |
| 811 | |
| 812 | $post_data = array( |
| 813 | 'topic_title' => (!$topic_title) ? $subject : $topic_title, |
| 814 | 'topic_first_post_id' => (isset($topic_first_post_id)) ? (int) $topic_first_post_id : 0, |
| 815 | 'topic_last_post_id' => (isset($topic_last_post_id)) ? (int) $topic_last_post_id : 0, |
| 816 | 'topic_time_limit' => (int) $topic_time_limit, |
| 817 | 'post_id' => (int) $post_id, |
| 818 | 'topic_id' => (int) $topic_id, |
| 819 | 'forum_id' => (int) $forum_id, |
| 820 | 'icon_id' => (int) $icon_id, |
| 821 | 'poster_id' => (int) $poster_id, |
| 822 | 'enable_sig' => (bool) $enable_sig, |
| 823 | 'enable_bbcode' => (bool) $enable_bbcode, |
| 824 | 'enable_html' => (bool) $enable_html, |
| 825 | 'enable_smilies' => (bool) $enable_smilies, |
| 826 | 'enable_urls' => (bool) $enable_urls, |
| 827 | 'enable_indexing' => (bool) $enable_indexing, |
| 828 | 'message_md5' => (string) $message_md5, |
| 829 | 'post_time' => (isset($post_time)) ? (int) $post_time : $current_time, |
| 830 | 'post_checksum' => (isset($post_checksum)) ? (string) $post_checksum : '', |
| 831 | 'post_edit_reason' => $post_edit_reason, |
| 832 | 'post_edit_user' => ($mode == 'edit') ? $user->data['user_id'] : ((isset($post_edit_user)) ? (int) $post_edit_user : 0), |
| 833 | 'forum_parents' => $forum_parents, |
| 834 | 'forum_name' => $forum_name, |
| 835 | 'notify' => $notify, |
| 836 | 'notify_set' => $notify_set, |
| 837 | 'poster_ip' => (isset($poster_ip)) ? (int) $poster_ip : $user->ip, |
| 838 | 'post_edit_locked' => (int) $post_edit_locked, |
| 839 | 'bbcode_bitfield' => (int) $message_parser->bbcode_bitfield, |
| 840 | 'bbcode_uid' => $message_parser->bbcode_uid, |
| 841 | 'message' => $message_parser->message, |
| 842 | 'attachment_data' => $message_parser->attachment_data, |
| 843 | 'filename_data' => $message_parser->filename_data |
| 844 | ); |
| 845 | unset($message_parser); |
| 846 | |
| 847 | submit_post($mode, $subject, $username, $topic_type, $poll, $post_data, $update_message); |
| 848 | } |
| 849 | } |
| 850 | |
| 851 | $post_subject = stripslashes($subject); |
| 852 | } |
| 853 | |
| 854 | // Preview
|
| 855 | if (!sizeof($error) && $preview) |
| 856 | {
|
| 857 | $post_time = ($mode == 'edit') ? $post_time : $current_time; |
| 858 | |
| 859 | $preview_message = $message_parser->format_display($enable_html, $enable_bbcode, $enable_urls, $enable_smilies, false); |
| 860 | |
| 861 | $preview_signature = ($mode == 'edit') ? $user_sig : $user->data['user_sig']; |
| 862 | $preview_signature_uid = ($mode == 'edit') ? $user_sig_bbcode_uid : $user->data['user_sig_bbcode_uid']; |
| 863 | $preview_signature_bitfield = ($mode == 'edit') ? $user_sig_bbcode_bitfield : $user->data['user_sig_bbcode_bitfield']; |
| 864 | |
| 865 | // Signature
|
| 866 | if ($enable_sig && $config['allow_sig'] && $preview_signature && $auth->acl_get('f_sigs', $forum_id)) |
| 867 | {
|
| 868 | $parse_sig = new parse_message($preview_signature); |
| 869 | $parse_sig->bbcode_uid = $preview_signature_uid; |
| 870 | $parse_sig->bbcode_bitfield = $preview_signature_bitfield; |
| 871 | |
| 872 | // Not sure about parameters for bbcode/smilies/urls... in signatures
|
| 873 | $parse_sig->format_display($config['allow_html'], $config['allow_bbcode'], true, $config['allow_smilies']); |
| 874 | $preview_signature = $parse_sig->message; |
| 875 | unset($parse_sig); |
| 876 | } |
| 877 | else
|
| 878 | {
|
| 879 | $preview_signature = ''; |
| 880 | } |
| 881 | |
| 882 | $preview_subject = censor_text($subject); |
| 883 | |
| 884 | // Poll Preview
|
| 885 | if (($mode == 'post' || ($mode == 'edit' && $post_id == $topic_first_post_id && (!$poll_last_vote || $auth->acl_get('m_edit', $forum_id)))) |
| 886 | && $auth->acl_get('f_poll', $forum_id)) |
| 887 | {
|
| 888 | $parse_poll = new parse_message($poll_title); |
| 889 | $parse_poll->bbcode_uid = $message_parser->bbcode_uid; |
| 890 | $parse_poll->bbcode_bitfield = $message_parser->bbcode_bitfield; |
| 891 | |
| 892 | $parse_poll->format_display($enable_html, $enable_bbcode, $enable_urls, $enable_smilies); |
| 893 | |
| 894 | $template->assign_vars(array( |
| 895 | 'S_HAS_POLL_OPTIONS'=> (sizeof($poll_options)), |
| 896 | 'S_IS_MULTI_CHOICE' => ($poll_max_options > 1) ? true : false, |
| 897 | |
| 898 | 'POLL_QUESTION' => $parse_poll->message, |
| 899 | |
| 900 | 'L_POLL_LENGTH' => ($poll_length) ? sprintf($user->lang['POLL_RUN_TILL'], $user->format_date($poll_length + $poll_start)) : '', |
| 901 | 'L_MAX_VOTES' => ($poll_max_options == 1) ? $user->lang['MAX_OPTION_SELECT'] : sprintf($user->lang['MAX_OPTIONS_SELECT'], $poll_max_options)) |
| 902 | ); |
| 903 | |
| 904 | $parse_poll->message = implode("\n", $poll_options); |
| 905 | $parse_poll->format_display($enable_html, $enable_bbcode, $enable_urls, $enable_smilies); |
| 906 | $preview_poll_options = explode('<br />', $parse_poll->message); |
| 907 | unset($parse_poll); |
| 908 | |
| 909 | foreach ($preview_poll_options as $option) |
| 910 | {
|
| 911 | $template->assign_block_vars('poll_option', array('POLL_OPTION_CAPTION' => $option)); |
| 912 | } |
| 913 | unset($preview_poll_options); |
| 914 | } |
| 915 | |
| 916 | // Attachment Preview
|
| 917 | if (sizeof($message_parser->attachment_data)) |
| 918 | {
|
| 919 | $extensions = $update_count = array(); |
| 920 | |
| 921 | $template->assign_var('S_HAS_ATTACHMENTS', true); |
| 922 | |
| 923 | $attachment_data = $message_parser->attachment_data; |
| 924 | $unset_attachments = parse_inline_attachments($preview_message, $attachment_data, $update_count, $forum_id, true); |
| 925 | |
| 926 | foreach ($unset_attachments as $index) |
| 927 | {
|
| 928 | unset($attachment_data[$index]); |
| 929 | } |
| 930 | |
| 931 | foreach ($attachment_data as $i => $attachment) |
| 932 | {
|
| 933 | $template->assign_block_vars('attachment', array( |
| 934 | 'DISPLAY_ATTACHMENT' => $attachment) |
| 935 | ); |
| 936 | } |
| 937 | unset($attachment_data, $attachment); |
| 938 | } |
| 939 | |
| 940 | if (!sizeof($error)) |
| 941 | {
|
| 942 | $template->assign_vars(array( |
| 943 | 'PREVIEW_SUBJECT' => $preview_subject, |
| 944 | 'PREVIEW_MESSAGE' => $preview_message, |
| 945 | 'PREVIEW_SIGNATURE' => $preview_signature, |
| 946 | |
| 947 | 'S_DISPLAY_PREVIEW' => true) |
| 948 | ); |
| 949 | } |
| 950 | |
| 951 | unset($post_text); |
| 952 | } |
| 953 | |
| 954 | // Decode text for message display
|
| 955 | $bbcode_uid = ($mode == 'quote' && !$preview && !$refresh && !sizeof($error)) ? $bbcode_uid : $message_parser->bbcode_uid; |
| 956 | $message_parser->decode_message($bbcode_uid); |
| 957 | |
| 958 | if ($mode == 'quote' && !$preview && !$refresh) |
| 959 | {
|
| 960 | $message_parser->message = '[quote="' . $quote_username . '"]' . censor_text(trim($message_parser->message)) . "[/quote]\n"; |
| 961 | } |
| 962 | |
| 963 | if (($mode == 'reply' || $mode == 'quote') && !$preview && !$refresh) |
| 964 | {
|
| 965 | $post_subject = ((!preg_match('/^Re:/', $post_subject)) ? 'Re: ' : '') . censor_text($post_subject); |
| 966 | } |
| 967 | |
| 968 | $attachment_data = $message_parser->attachment_data; |
| 969 | $filename_data = $message_parser->filename_data; |
| 970 | $post_text = $message_parser->message; |
| 971 | |
| 972 | if (sizeof($poll_options) && $poll_title) |
| 973 | {
|
| 974 | $message_parser->message = $poll_title; |
| 975 | $message_parser->bbcode_uid = $bbcode_uid; |
| 976 | |
| 977 | $message_parser->decode_message();
|
| 978 | $poll_title = $message_parser->message; |
| 979 | |
| 980 | $message_parser->message = implode("\n", $poll_options); |
| 981 | $message_parser->decode_message();
|
| 982 | $poll_options = explode("\n", $message_parser->message); |
| 983 | } |
| 984 | unset($message_parser); |
| 985 | |
| 986 | // MAIN POSTING PAGE BEGINS HERE
|
| 987 | |
| 988 | // Forum moderators?
|
| 989 | get_moderators($moderators, $forum_id); |
| 990 | |
| 991 | // Generate smiley listing
|
| 992 | generate_smilies('inline', $forum_id); |
| 993 | |
| 994 | // Generate inline attachment select box
|
| 995 | posting_gen_inline_attachments($attachment_data);
|
| 996 | |
| 997 | |
| 998 | // Do show topic type selection only in first post.
|
| 999 | $topic_type_toggle = false; |
| 1000 | |
| 1001 | if ($mode == 'post' || ($mode == 'edit' && $post_id == $topic_first_post_id)) |
| 1002 | {
|
| 1003 | $topic_type_toggle = posting_gen_topic_types($forum_id, $topic_type); |
| 1004 | } |
| 1005 | |
| 1006 | $s_topic_icons = false; |
| 1007 | if ($enable_icons) |
| 1008 | {
|
| 1009 | $s_topic_icons = posting_gen_topic_icons($mode, $icon_id); |
| 1010 | } |
| 1011 | |
| 1012 | $html_checked = (isset($enable_html)) ? !$enable_html : (($config['allow_html']) ? !$user->optionget('html') : 1); |
| 1013 | $bbcode_checked = (isset($enable_bbcode)) ? !$enable_bbcode : (($config['allow_bbcode']) ? !$user->optionget('bbcode') : 1); |
| 1014 | $smilies_checked = (isset($enable_smilies)) ? !$enable_smilies : (($config['allow_smilies']) ? !$user->optionget('smilies') : 1); |
| 1015 | $urls_checked = (isset($enable_urls)) ? !$enable_urls : 0; |
| 1016 | $sig_checked = $enable_sig; |
| 1017 | $notify_checked = (isset($notify)) ? $notify : ((!$notify_set) ? (($user->data['is_registered']) ? $user->data['user_notify'] : 0) : 1); |
| 1018 | $lock_topic_checked = (isset($topic_lock)) ? $topic_lock : (($topic_status == ITEM_LOCKED) ? 1 : 0); |
| 1019 | $lock_post_checked = (isset($post_lock)) ? $post_lock : $post_edit_locked; |
| 1020 | |
| 1021 | // Page title & action URL, include session_id for security purpose
|
| 1022 | $s_action = "posting.$phpEx?sid=" . $user->session_id . "&mode=$mode&f=$forum_id"; |
| 1023 | $s_action .= ($topic_id) ? "&t=$topic_id" : ''; |
| 1024 | $s_action .= ($post_id) ? "&p=$post_id" : ''; |
| 1025 | |
| 1026 | switch ($mode) |
| 1027 | {
|
| 1028 | case 'post': |
| 1029 | $page_title = $user->lang['POST_TOPIC']; |
| 1030 | break;
|
| 1031 | |
| 1032 | case 'quote': |
| 1033 | case 'reply': |
| 1034 | $page_title = $user->lang['POST_REPLY']; |
| 1035 | break;
|
| 1036 | |
| 1037 | case 'delete': |
| 1038 | case 'edit': |
| 1039 | $page_title = $user->lang['EDIT_POST']; |
| 1040 | } |
| 1041 | |
| 1042 | $forum_data = array( |
| 1043 | 'parent_id' => $parent_id, |
| 1044 | 'left_id' => $left_id, |
| 1045 | 'right_id' => $right_id, |
| 1046 | 'forum_parents' => $forum_parents, |
| 1047 | 'forum_name' => $forum_name, |
| 1048 | 'forum_id' => $forum_id, |
| 1049 | 'forum_type' => $forum_type, |
| 1050 | 'forum_desc' => $forum_desc, |
| 1051 | 'forum_rules' => $forum_rules, |
| 1052 | 'forum_rules_flags' => $forum_rules_flags, |
| 1053 | 'forum_rules_bbcode_uid' => $forum_rules_bbcode_uid, |
| 1054 | 'forum_rules_bbcode_bitfield' => $forum_rules_bbcode_bitfield, |
| 1055 | 'forum_rules_link' => $forum_rules_link |
| 1056 | ); |
| 1057 | |
| 1058 | // Build Navigation Links
|
| 1059 | generate_forum_nav($forum_data);
|
| 1060 | |
| 1061 | // Build Forum Rules
|
| 1062 | generate_forum_rules($forum_data);
|
| 1063 | |
| 1064 | $s_hidden_fields = ($mode == 'reply' || $mode == 'quote') ? '<input type="hidden" name="topic_cur_post_id" value="' . $topic_last_post_id . '" />' : ''; |
| 1065 | $s_hidden_fields .= '<input type="hidden" name="lastclick" value="' . $current_time . '" />'; |
| 1066 | $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) . '" />' : ''; |
| 1067 | |
| 1068 | $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"'; |
| 1069 | |
| 1070 | // Start assigning vars for main posting page ...
|
| 1071 | $template->assign_vars(array( |
| 1072 | 'L_POST_A' => $page_title, |
| 1073 | 'L_ICON' => ($mode == 'reply' || $mode == 'quote') ? $user->lang['POST_ICON'] : $user->lang['TOPIC_ICON'], |
| 1074 | 'L_MESSAGE_BODY_EXPLAIN'=> (intval($config['max_post_chars'])) ? sprintf($user->lang['MESSAGE_BODY_EXPLAIN'], intval($config['max_post_chars'])) : '', |
| 1075 | |
| 1076 | 'FORUM_NAME' => $forum_name, |
| 1077 | 'FORUM_DESC' => ($forum_desc) ? strip_tags($forum_desc) : '', |
| 1078 | 'TOPIC_TITLE' => $topic_title, |
| 1079 | 'MODERATORS' => (sizeof($moderators)) ? implode(', ', $moderators[$forum_id]) : '', |
| 1080 | 'USERNAME' => ((!$preview && $mode != 'quote') || $preview) ? stripslashes($username) : '', |
| 1081 | 'SUBJECT' => $post_subject, |
| 1082 | 'MESSAGE' => $post_text, |
| 1083 | 'HTML_STATUS' => ($html_status) ? $user->lang['HTML_IS_ON'] : $user->lang['HTML_IS_OFF'], |
| 1084 | 'BBCODE_STATUS' => ($bbcode_status) ? sprintf($user->lang['BBCODE_IS_ON'], '<a href="' . "faq.$phpEx$SID&mode=bbcode" . '" target="_phpbbcode">', '</a>') : sprintf($user->lang['BBCODE_IS_OFF'], '<a href="' . "faq.$phpEx$SID&mode=bbcode" . '" target="_phpbbcode">', '</a>'), |
| 1085 | 'IMG_STATUS' => ($img_status) ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'], |
| 1086 | 'FLASH_STATUS' => ($flash_status) ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'], |
| 1087 | 'SMILIES_STATUS' => ($smilies_status) ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'], |
| 1088 | 'MINI_POST_IMG' => $user->img('icon_post', $user->lang['POST']), |
| 1089 | 'POST_DATE' => ($post_time) ? $user->format_date($post_time) : '', |
| 1090 | 'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '', |
| 1091 | 'TOPIC_TIME_LIMIT' => (int) $topic_time_limit, |
| 1092 | 'EDIT_REASON' => $post_edit_reason, |
| 1093 | |
| 1094 | 'U_VIEW_FORUM' => "viewforum.$phpEx$SID&f=" . $forum_id, |
| 1095 | 'U_VIEWTOPIC' => ($mode != 'post') ? "viewtopic.$phpEx$SID&$forum_id&t=$topic_id" : '', |
| 1096 | 'U_PROGRESS_BAR' => "posting.$phpEx$SID&f=$forum_id&mode=popup", // do NOT replace & with & here |
| 1097 | |
| 1098 | 'S_PRIVMSGS' => false, |
| 1099 | 'S_CLOSE_PROGRESS_WINDOW' => isset($_POST['add_file']), |
| 1100 | 'S_EDIT_POST' => ($mode == 'edit'), |
| 1101 | 'S_EDIT_REASON' => ($mode == 'edit' && $user->data['user_id'] != $poster_id), |
| 1102 | 'S_DISPLAY_USERNAME' => (!$user->data['is_registered'] || ($mode == 'edit' && $post_username)), |
| 1103 | 'S_SHOW_TOPIC_ICONS' => $s_topic_icons, |
| 1104 | '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))), |
| 1105 | 'S_HTML_ALLOWED' => $html_status, |
| 1106 | 'S_HTML_CHECKED' => ($html_checked) ? ' checked="checked"' : '', |
| 1107 | 'S_BBCODE_ALLOWED' => $bbcode_status, |
| 1108 | 'S_BBCODE_CHECKED' => ($bbcode_checked) ? ' checked="checked"' : '', |
| 1109 | 'S_SMILIES_ALLOWED' => $smilies_status, |
| 1110 | 'S_SMILIES_CHECKED' => ($smilies_checked) ? ' checked="checked"' : '', |
| 1111 | 'S_SIG_ALLOWED' => ($auth->acl_get('f_sigs', $forum_id) && $config['allow_sig'] && $user->data['is_registered']), |
| 1112 | 'S_SIGNATURE_CHECKED' => ($sig_checked) ? ' checked="checked"' : '', |
| 1113 | 'S_NOTIFY_ALLOWED' => ($user->data['is_registered']), |
| 1114 | 'S_NOTIFY_CHECKED' => ($notify_checked) ? ' checked="checked"' : '', |
| 1115 | '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))), |
| 1116 | 'S_LOCK_TOPIC_CHECKED' => ($lock_topic_checked) ? ' checked="checked"' : '', |
| 1117 | 'S_LOCK_POST_ALLOWED' => ($mode == 'edit' && $auth->acl_get('m_edit', $forum_id)), |
| 1118 | 'S_LOCK_POST_CHECKED' => ($lock_post_checked) ? ' checked="checked"' : '', |
| 1119 | 'S_MAGIC_URL_CHECKED' => ($urls_checked) ? ' checked="checked"' : '', |
| 1120 | 'S_TYPE_TOGGLE' => $topic_type_toggle, |
| 1121 | 'S_SAVE_ALLOWED' => ($auth->acl_get('u_savedrafts') && $user->data['is_registered']), |
| 1122 | 'S_HAS_DRAFTS' => ($auth->acl_get('u_savedrafts') && $user->data['is_registered'] && $drafts), |
| 1123 | 'S_FORM_ENCTYPE' => $form_enctype, |
| 1124 | |
| 1125 | 'S_POST_ACTION' => $s_action, |
| 1126 | 'S_HIDDEN_FIELDS' => $s_hidden_fields) |
| 1127 | ); |
| 1128 | |
| 1129 | // Poll entry
|
| 1130 | if (($mode == 'post' || ($mode == 'edit' && $post_id == $topic_first_post_id && (!$poll_last_vote || $auth->acl_get('m_edit', $forum_id)))) |
| 1131 | && $auth->acl_get('f_poll', $forum_id)) |
| 1132 | {
|
| 1133 | $template->assign_vars(array( |
| 1134 | 'S_SHOW_POLL_BOX' => true, |
| 1135 | 'S_POLL_VOTE_CHANGE' => ($auth->acl_get('f_votechg', $forum_id)), |
| 1136 | '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))), |
| 1137 | |
| 1138 | 'L_POLL_OPTIONS_EXPLAIN'=> sprintf($user->lang['POLL_OPTIONS_EXPLAIN'], $config['max_poll_options']), |
| 1139 | |
| 1140 | 'VOTE_CHANGE_CHECKED' => (isset($poll_vote_change) && $poll_vote_change) ? ' checked="checked"' : '', |
| 1141 | 'POLL_TITLE' => (isset($poll_title)) ? $poll_title : '', |
| 1142 | 'POLL_OPTIONS' => (isset($poll_options) && $poll_options) ? implode("\n", $poll_options) : '', |
| 1143 | 'POLL_MAX_OPTIONS' => (isset($poll_max_options)) ? (int) $poll_max_options : 1, |
| 1144 | 'POLL_LENGTH' => $poll_length) |
| 1145 | ); |
| 1146 | } |
| 1147 | |
| 1148 | // Attachment entry
|
| 1149 | // Not using acl_gets here, because it is using OR logic
|
| 1150 | if ($auth->acl_get('f_attach', $forum_id) && $auth->acl_get('u_attach') && $config['allow_attachments'] && $form_enctype) |
| 1151 | {
|
| 1152 | posting_gen_attachment_entry($attachment_data, $filename_data); |
| 1153 | } |
| 1154 | |
| 1155 | // Output page ...
|
| 1156 | page_header($page_title);
|
| 1157 | |
| 1158 | $template->set_filenames(array( |
| 1159 | 'body' => 'posting_body.html') |
| 1160 | ); |
| 1161 | |
| 1162 | make_jumpbox('viewforum.'.$phpEx); |
| 1163 | |
| 1164 | // Topic review
|
| 1165 | if ($mode == 'reply' || $mode == 'quote') |
| 1166 | {
|
| 1167 | if (topic_review($topic_id, $forum_id)) |
| 1168 | {
|
| 1169 | $template->assign_var('S_DISPLAY_REVIEW', true); |
| 1170 | } |
| 1171 | } |
| 1172 | |
| 1173 | page_footer(); |
| 1174 | |
| 1175 | |
| 1176 | /**
|
| 1177 | * Delete Post |
| 1178 | */ |
| 1179 | function delete_post($mode, $post_id, $topic_id, $forum_id, &$data) |
| 1180 | {
|
| 1181 | global $db, $user, $config, $auth, $phpEx, $SID; |
| 1182 | |
| 1183 | // Specify our post mode
|
| 1184 | $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')); |
| 1185 | $sql_data = array(); |
| 1186 | $next_post_id = 0; |
| 1187 | |
| 1188 | $db->sql_transaction();
|
| 1189 | |
| 1190 | if (!delete_posts('post_id', array($post_id), false)) |
| 1191 | {
|
| 1192 | // Try to delete topic, we may had an previous error causing inconsistency
|
| 1193 | if ($post_mode = 'delete_topic') |
| 1194 | {
|
| 1195 | delete_topics('topic_id', array($topic_id), false); |
| 1196 | } |
| 1197 | trigger_error('ALREADY_DELETED'); |
| 1198 | } |
| 1199 | |
| 1200 | $db->sql_transaction('commit'); |
| 1201 | |
| 1202 | // Collect the necessary informations for updating the tables
|
| 1203 | $sql_data[FORUMS_TABLE] = ''; |
| 1204 | switch ($post_mode) |
| 1205 | {
|
| 1206 | case 'delete_topic': |
| 1207 | delete_topics('topic_id', array($topic_id), false); |
| 1208 | set_config('num_topics', $config['num_topics'] - 1, true); |
| 1209 | |
| 1210 | if ($data['topic_type'] != POST_GLOBAL) |
| 1211 | {
|
| 1212 | $sql_data[FORUMS_TABLE] .= 'forum_posts = forum_posts - 1, forum_topics_real = forum_topics_real - 1'; |
| 1213 | $sql_data[FORUMS_TABLE] .= ($data['topic_approved']) ? ', forum_topics = forum_topics - 1' : ''; |
| 1214 | } |
| 1215 | |
| 1216 | $sql_data[FORUMS_TABLE] .= ($sql_data[FORUMS_TABLE]) ? ', ' : ''; |
| 1217 | $sql_data[FORUMS_TABLE] .= implode(', ', update_last_post_information('forum', $forum_id)); |
| 1218 | $sql_data[TOPICS_TABLE] = 'topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : ''); |
| 1219 | break;
|
| 1220 | |
| 1221 | case 'delete_first_post': |
| 1222 | $sql = 'SELECT p.post_id, p.poster_id, p.post_username, u.username |
| 1223 | FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u |
| 1224 | WHERE p.topic_id = $topic_id |
| 1225 | AND p.poster_id = u.user_id |
| 1226 | ORDER BY p.post_time ASC";
|
| 1227 | $result = $db->sql_query_limit($sql, 1); |
| 1228 | |
| 1229 | $row = $db->sql_fetchrow($result); |
| 1230 | $db->sql_freeresult($result); |
| 1231 | |
| 1232 | if ($data['topic_type'] != POST_GLOBAL) |
| 1233 | {
|
| 1234 | $sql_data[FORUMS_TABLE] = 'forum_posts = forum_posts - 1'; |
| 1235 | } |
| 1236 | |
| 1237 | $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'])) . "'"; |
| 1238 | $sql_data[TOPICS_TABLE] .= ', topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : ''); |
| 1239 | |
| 1240 | $next_post_id = (int) $row['post_id']; |
| 1241 | break;
|
| 1242 | |
| 1243 | case 'delete_last_post': |
| 1244 | if ($data['topic_type'] != POST_GLOBAL) |
| 1245 | {
|
| 1246 | $sql_data[FORUMS_TABLE] = 'forum_posts = forum_posts - 1'; |
| 1247 | } |
| 1248 | |
| 1249 | $sql_data[FORUMS_TABLE] .= ($sql_data[FORUMS_TABLE]) ? ', ' : ''; |
| 1250 | $sql_data[FORUMS_TABLE] .= implode(', ', update_last_post_information('forum', $forum_id)); |
| 1251 | $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' : ''); |
| 1252 | |
| 1253 | $update = update_last_post_information('topic', $topic_id); |
| 1254 | if (sizeof($update)) |
| 1255 | {
|
| 1256 | $sql_data[TOPICS_TABLE] .= ', ' . implode(', ', $update); |
| 1257 | $next_post_id = (int) str_replace('topic_last_post_id = ', '', $update[0]); |
| 1258 | } |
| 1259 | else
|
| 1260 | {
|
| 1261 | $sql = 'SELECT MAX(post_id) as last_post_id |
| 1262 | FROM ' . POSTS_TABLE . " |
| 1263 | WHERE topic_id = $topic_id " . |
| 1264 | ((!$auth->acl_get('m_approve')) ? 'AND post_approved = 1' : ''); |
| 1265 | $result = $db->sql_query($sql); |
| 1266 | $row = $db->sql_fetchrow($result); |
| 1267 | $db->sql_freeresult($result); |
| 1268 | |
| 1269 | $next_post_id = (int) $row['last_post_id']; |
| 1270 | } |
| 1271 | break;
|
| 1272 | |
| 1273 | case 'delete': |
| 1274 | $sql = 'SELECT post_id |
| 1275 | FROM ' . POSTS_TABLE . " |
| 1276 | WHERE topic_id = $topic_id " . |
| 1277 | ((!$auth->acl_get('m_approve')) ? 'AND post_approved = 1' : '') . ' |
| 1278 | AND post_time > ' . $data['post_time'] . ' |
| 1279 | ORDER BY post_time ASC';
|
| 1280 | $result = $db->sql_query_limit($sql, 1); |
| 1281 | |
| 1282 | $row = $db->sql_fetchrow($result); |
| 1283 | $db->sql_freeresult($result); |
| 1284 | |
| 1285 | if ($data['topic_type'] != POST_GLOBAL) |
| 1286 | {
|
| 1287 | $sql_data[FORUMS_TABLE] = 'forum_posts = forum_posts - 1'; |
| 1288 | } |
| 1289 | |
| 1290 | $sql_data[TOPICS_TABLE] = 'topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : ''); |
| 1291 | $next_post_id = (int) $row['post_id']; |
| 1292 | } |
| 1293 | |
| 1294 | $sql_data[USERS_TABLE] = ($auth->acl_get('f_postcount', $forum_id)) ? 'user_posts = user_posts - 1' : ''; |
| 1295 | set_config('num_posts', $config['num_posts'] - 1, true); |
| 1296 | |
| 1297 | $db->sql_transaction();
|
| 1298 | |
| 1299 | $where_sql = array(FORUMS_TABLE => "forum_id = $forum_id", TOPICS_TABLE => "topic_id = $topic_id", USERS_TABLE => 'user_id = ' . $data['poster_id']); |
| 1300 | |
| 1301 | foreach ($sql_data as $table => $update_sql) |
| 1302 | {
|
| 1303 | if ($update_sql) |
| 1304 | {
|
| 1305 | $db->sql_query("UPDATE $table SET $update_sql WHERE " . $where_sql[$table]); |
| 1306 | } |
| 1307 | } |
| 1308 | |
| 1309 | $db->sql_transaction('commit'); |
| 1310 | |
| 1311 | return $next_post_id; |
| 1312 | } |
| 1313 | |
| 1314 | |
| 1315 | /**
|
| 1316 | * Submit Post |
| 1317 | */ |
| 1318 | function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $update_message = true) |
| 1319 | {
|
| 1320 | global $db, $auth, $user, $config, $phpEx, $SID, $template, $phpbb_root_path; |
| 1321 | |
| 1322 | // We do not handle erasing posts here
|
| 1323 | if ($mode == 'delete') |
| 1324 | {
|
| 1325 | return;
|
| 1326 | } |
| 1327 | |
| 1328 | $current_time = time(); |
| 1329 | |
| 1330 | if ($mode == 'post') |
| 1331 | {
|
| 1332 | $post_mode = 'post'; |
| 1333 | $update_message = true; |
| 1334 | } |
| 1335 | else if ($mode != 'edit') |
| 1336 | {
|
| 1337 | $post_mode = 'reply'; |
| 1338 | $update_message = true; |
| 1339 | } |
| 1340 | else if ($mode == 'edit') |
| 1341 | {
|
| 1342 | $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')); |
| 1343 | } |
| 1344 | |
| 1345 | |
| 1346 | // Collect some basic informations about which tables and which rows to update/insert
|
| 1347 | $sql_data = array(); |
| 1348 | $poster_id = ($mode == 'edit') ? $data['poster_id'] : (int) $user->data['user_id']; |
| 1349 | |
| 1350 | // Collect Informations
|
| 1351 | switch ($post_mode) |
| 1352 | {
|
| 1353 | case 'post': |
| 1354 | case 'reply': |
| 1355 | $sql_data[POSTS_TABLE]['sql'] = array( |
| 1356 | 'forum_id' => ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'], |
| 1357 | 'poster_id' => (int) $user->data['user_id'], |
| 1358 | 'icon_id' => $data['icon_id'], |
| 1359 | 'poster_ip' => $user->ip, |
| 1360 | 'post_time' => $current_time, |
| 1361 | 'post_approved' => ($auth->acl_get('f_moderate', $data['forum_id']) && !$auth->acl_get('m_approve')) ? 0 : 1, |
| 1362 | 'enable_bbcode' => $data['enable_bbcode'], |
| 1363 | 'enable_html' => $data['enable_html'], |
| 1364 | 'enable_smilies' => $data['enable_smilies'], |
| 1365 | 'enable_magic_url' => $data['enable_urls'], |
| 1366 | 'enable_sig' => $data['enable_sig'], |
| 1367 | 'post_username' => (!$user->data['is_registered']) ? stripslashes($username) : '', |
| 1368 | 'post_subject' => $subject, |
| 1369 | 'post_text' => $data['message'], |
| 1370 | 'post_checksum' => $data['message_md5'], |
| 1371 | 'post_encoding' => $user->lang['ENCODING'], |
| 1372 | 'post_attachment' => (isset($data['filename_data']['physical_filename']) && sizeof($data['filename_data'])) ? 1 : 0, |
| 1373 | 'bbcode_bitfield' => $data['bbcode_bitfield'], |
| 1374 | 'bbcode_uid' => $data['bbcode_uid'], |
| 1375 | 'post_edit_locked' => $data['post_edit_locked'] |
| 1376 | ); |
| 1377 | break;
|
| 1378 | |
| 1379 | case 'edit_first_post': |
| 1380 | case 'edit': |
| 1381 | |
| 1382 | if (!$auth->acl_gets('m_', 'a_') || $data['post_edit_reason']) |
| 1383 | {
|
| 1384 | $sql_data[POSTS_TABLE]['sql'] = array( |
| 1385 | 'post_edit_time' => $current_time |
| 1386 | ); |
| 1387 | |
| 1388 | $sql_data[POSTS_TABLE]['stat'][] = 'post_edit_count = post_edit_count + 1'; |
| 1389 | } |
| 1390 | |
| 1391 | case 'edit_last_post': |
| 1392 | case 'edit_topic': |
| 1393 | |
| 1394 | if (($post_mode == 'edit_last_post' || $post_mode == 'edit_topic') && $data['post_edit_reason']) |
| 1395 | {
|
| 1396 | $sql_data[POSTS_TABLE]['sql'] = array( |
| 1397 | 'post_edit_time' => $current_time |
| 1398 | ); |
| 1399 | |
| 1400 | $sql_data[POSTS_TABLE]['stat'][] = 'post_edit_count = post_edit_count + 1'; |
| 1401 | } |
| 1402 | |
| 1403 | if (!isset($sql_data[POSTS_TABLE]['sql'])) |
| 1404 | {
|
| 1405 | $sql_data[POSTS_TABLE]['sql'] = array(); |
| 1406 | } |
| 1407 | |
| 1408 | $sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array( |
| 1409 | 'forum_id' => ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'], |
| 1410 | 'poster_id' => $data['poster_id'], |
| 1411 | 'icon_id' => $data['icon_id'], |
| 1412 | 'post_approved' => ($auth->acl_get('f_moderate', $data['forum_id']) && !$auth->acl_get('m_approve')) ? 0 : 1, |
| 1413 | 'enable_bbcode' => $data['enable_bbcode'], |
| 1414 | 'enable_html' => $data['enable_html'], |
| 1415 | 'enable_smilies' => $data['enable_smilies'], |
| 1416 | 'enable_magic_url' => $data['enable_urls'], |
| 1417 | 'enable_sig' => $data['enable_sig'], |
| 1418 | 'post_username' => ($username && $data['poster_id'] == ANONYMOUS) ? stripslashes($username) : '', |
| 1419 | 'post_subject' => $subject, |
| 1420 | 'post_edit_reason' => $data['post_edit_reason'], |
| 1421 | 'post_edit_user' => (int) $data['post_edit_user'], |
| 1422 | 'post_checksum' => $data['message_md5'], |
| 1423 | 'post_encoding' => $user->lang['ENCODING'], |
| 1424 | 'post_attachment' => (isset($data['filename_data']['physical_filename']) && sizeof($data['filename_data'])) ? 1 : 0, |
| 1425 | 'bbcode_bitfield' => $data['bbcode_bitfield'], |
| 1426 | 'bbcode_uid' => $data['bbcode_uid'], |
| 1427 | 'post_edit_locked' => $data['post_edit_locked']) |
| 1428 | ); |
| 1429 | |
| 1430 | if ($update_message) |
| 1431 | {
|
| 1432 | $sql_data[POSTS_TABLE]['sql']['post_text'] = $data['message']; |
| 1433 | } |
| 1434 | |
| 1435 | break;
|
| 1436 | } |
| 1437 | |
| 1438 | // And the topic ladies and gentlemen
|
| 1439 | switch ($post_mode) |
| 1440 | {
|
| 1441 | case 'post': |
| 1442 | $sql_data[TOPICS_TABLE]['sql'] = array( |
| 1443 | 'topic_poster' => (int) $user->data['user_id'], |
| 1444 | 'topic_time' => $current_time, |
| 1445 | 'forum_id' => ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'], |
| 1446 | 'icon_id' => $data['icon_id'], |
| 1447 | 'topic_approved' => ($auth->acl_get('f_moderate', $data['forum_id']) && !$auth->acl_get('m_approve')) ? 0 : 1, |
| 1448 | 'topic_title' => $subject, |
| 1449 | 'topic_first_poster_name' => (!$user->data['is_registered'] && $username) ? stripslashes($username) : $user->data['username'], |
| 1450 | 'topic_type' => $topic_type, |
| 1451 | 'topic_time_limit' => ($topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE) ? ($data['topic_time_limit'] * 86400) : 0, |
| 1452 | 'topic_attachment' => (isset($data['filename_data']['physical_filename']) && sizeof($data['filename_data'])) ? 1 : 0 |
| 1453 | ); |
| 1454 | |
| 1455 | if (isset($poll['poll_options']) && !empty($poll['poll_options'])) |
| 1456 | {
|
| 1457 | $sql_data[TOPICS_TABLE]['sql'] = array_merge($sql_data[TOPICS_TABLE]['sql'], array( |
| 1458 | 'poll_title' => $poll['poll_title'], |
| 1459 | 'poll_start' => ($poll['poll_start']) ? $poll['poll_start'] : $current_time, |
| 1460 | 'poll_max_options' => $poll['poll_max_options'], |
| 1461 | 'poll_length' => ($poll['poll_length'] * 86400), |
| 1462 | 'poll_vote_change' => $poll['poll_vote_change']) |
| 1463 | ); |
| 1464 | } |
| 1465 | |
| 1466 | $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id'])) ? ', user_posts = user_posts + 1' : ''); |
| 1467 | |
| 1468 | if ($topic_type != POST_GLOBAL) |
| 1469 | {
|
| 1470 | if (!$auth->acl_get('f_moderate', $data['forum_id']) || $auth->acl_get('m_approve')) |
| 1471 | {
|
| 1472 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1'; |
| 1473 | } |
| 1474 | $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')) ? ', forum_topics = forum_topics + 1' : ''); |
| 1475 | } |
| 1476 | break;
|
| 1477 | |
| 1478 | case 'reply': |
| 1479 | $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')) ? ', topic_replies = topic_replies + 1' : ''); |
| 1480 | $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id'])) ? ', user_posts = user_posts + 1' : ''); |
| 1481 | |
| 1482 | if ((!$auth->acl_get('f_moderate', $data['forum_id']) || $auth->acl_get('m_approve')) && $topic_type != POST_GLOBAL) |
| 1483 | {
|
| 1484 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1'; |
| 1485 | } |
| 1486 | break;
|
| 1487 | |
| 1488 | case 'edit_topic': |
| 1489 | case 'edit_first_post': |
| 1490 | |
| 1491 | $sql_data[TOPICS_TABLE]['sql'] = array( |
| 1492 | 'forum_id' => ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'], |
| 1493 | 'icon_id' => $data['icon_id'], |
| 1494 | 'topic_approved' => ($auth->acl_get('f_moderate', $data['forum_id']) && !$auth->acl_get('m_approve')) ? 0 : 1, |
| 1495 | 'topic_title' => $subject, |
| 1496 | 'topic_first_poster_name' => stripslashes($username), |
| 1497 | 'topic_type' => $topic_type, |
| 1498 | 'topic_time_limit' => ($topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE) ? ($data['topic_time_limit'] * 86400) : 0, |
| 1499 | 'poll_title' => ($poll['poll_options']) ? $poll['poll_title'] : '', |
| 1500 | 'poll_start' => ($poll['poll_options']) ? (($poll['poll_start']) ? $poll['poll_start'] : $current_time) : 0, |
| 1501 | 'poll_max_options' => ($poll['poll_options']) ? $poll['poll_max_options'] : 1, |
| 1502 | 'poll_length' => ($poll['poll_options']) ? ($poll['poll_length'] * 86400) : 0, |
| 1503 | 'poll_vote_change' => $poll['poll_vote_change'], |
| 1504 | |
| 1505 | 'topic_attachment' => ($post_mode == 'edit_topic') ? ((isset($data['filename_data']['physical_filename']) && sizeof($data['filename_data'])) ? 1 : 0) : $data['topic_attachment'] |
| 1506 | ); |
| 1507 | break;
|
| 1508 | } |
| 1509 | |
| 1510 | $db->sql_transaction();
|
| 1511 | |
| 1512 | // Submit new topic
|
| 1513 | if ($post_mode == 'post') |
| 1514 | {
|
| 1515 | $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . |
| 1516 | $db->sql_build_array('INSERT', $sql_data[TOPICS_TABLE]['sql']); |
| 1517 | $db->sql_query($sql); |
| 1518 | |
| 1519 | $data['topic_id'] = $db->sql_nextid(); |
| 1520 | |
| 1521 | $sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array( |
| 1522 | 'topic_id' => $data['topic_id']) |
| 1523 | ); |
| 1524 | unset($sql_data[TOPICS_TABLE]['sql']); |
| 1525 | } |
| 1526 | |
| 1527 | // Submit new post
|
| 1528 | if ($post_mode == 'post' || $post_mode == 'reply') |
| 1529 | {
|
| 1530 | if ($post_mode == 'reply') |
| 1531 | {
|
| 1532 | $sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array( |
| 1533 | 'topic_id' => $data['topic_id']) |
| 1534 | ); |
| 1535 | } |
| 1536 | |
| 1537 | $sql = 'INSERT INTO ' . POSTS_TABLE . ' ' . |
| 1538 | $db->sql_build_array('INSERT', $sql_data[POSTS_TABLE]['sql']); |
| 1539 | $db->sql_query($sql); |
| 1540 | $data['post_id'] = $db->sql_nextid(); |
| 1541 | |
| 1542 | if ($post_mode == 'post') |
| 1543 | {
|
| 1544 | $sql_data[TOPICS_TABLE]['sql'] = array( |
| 1545 | 'topic_first_post_id' => $data['post_id'], |
| 1546 | 'topic_last_post_id' => $data['post_id'], |
| 1547 | 'topic_last_post_time' => $current_time, |
| 1548 | 'topic_last_poster_id' => (int) $user->data['user_id'], |
| 1549 | 'topic_last_poster_name'=> (!$user->data['is_registered'] && $username) ? stripslashes($username) : $user->data['username'] |
| 1550 | ); |
| 1551 | } |
| 1552 | |
| 1553 | unset($sql_data[POSTS_TABLE]['sql']); |
| 1554 | } |
| 1555 | |
| 1556 | $make_global = false; |
| 1557 | |
| 1558 | // Are we globalising or unglobalising?
|
| 1559 | if ($post_mode == 'edit_first_post' || $post_mode == 'edit_topic') |
| 1560 | {
|
| 1561 | $sql = 'SELECT topic_type, topic_replies_real, topic_approved |
| 1562 | FROM ' . TOPICS_TABLE . ' |
| 1563 | WHERE topic_id = ' . $data['topic_id']; |
| 1564 | $result = $db->sql_query($sql); |
| 1565 | $row = $db->sql_fetchrow($result); |
| 1566 | $db->sql_freeresult($result); |
| 1567 | |
| 1568 | // globalise
|
| 1569 | if ($row['topic_type'] != POST_GLOBAL && $topic_type == POST_GLOBAL) |
| 1570 | {
|
| 1571 | // Decrement topic/post count
|
| 1572 | $make_global = true; |
| 1573 | $sql_data[FORUMS_TABLE]['stat'] = array(); |
| 1574 | |
| 1575 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - ' . ($row['topic_replies_real'] + 1); |
| 1576 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real - 1' . (($row['topic_approved']) ? ', forum_topics = forum_topics - 1' : ''); |
| 1577 | |
| 1578 | // Update forum_ids for all posts
|
| 1579 | $sql = 'UPDATE ' . POSTS_TABLE . ' |
| 1580 | SET forum_id = 0 |
| 1581 | WHERE topic_id = ' . $data['topic_id']; |
| 1582 | $db->sql_query($sql); |
| 1583 | } |
| 1584 | // unglobalise
|
| 1585 | else if ($row['topic_type'] == POST_GLOBAL && $topic_type != POST_GLOBAL) |
| 1586 | {
|
| 1587 | // Increment topic/post count
|
| 1588 | $make_global = true; |
| 1589 | $sql_data[FORUMS_TABLE]['stat'] = array(); |
| 1590 | |
| 1591 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + ' . ($row['topic_replies_real'] + 1); |
| 1592 | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real + 1' . (($row['topic_approved']) ? ', forum_topics = forum_topics + 1' : ''); |
| 1593 | |
| 1594 | // Update forum_ids for all posts
|
| 1595 | $sql = 'UPDATE ' . POSTS_TABLE . ' |
| 1596 | SET forum_id = ' . $data['forum_id'] . ' |
| 1597 | WHERE topic_id = ' . $data['topic_id']; |
| 1598 | $db->sql_query($sql); |
| 1599 | } |
| 1600 | } |
| 1601 | |
| 1602 | // Update the topics table
|
| 1603 | if (isset($sql_data[TOPICS_TABLE]['sql'])) |
| 1604 | {
|
| 1605 | $db->sql_query('UPDATE ' . TOPICS_TABLE . ' |
| 1606 | SET ' . $db->sql_build_array('UPDATE', $sql_data[TOPICS_TABLE]['sql']) . ' |
| 1607 | WHERE topic_id = ' . $data['topic_id']); |
| 1608 | } |
| 1609 | |
| 1610 | // Update the posts table
|
| 1611 | if (isset($sql_data[POSTS_TABLE]['sql'])) |
| 1612 | {
|
| 1613 | $db->sql_query('UPDATE ' . POSTS_TABLE . ' |
| 1614 | SET ' . $db->sql_build_array('UPDATE', $sql_data[POSTS_TABLE]['sql']) . ' |
| 1615 | WHERE post_id = ' . $data['post_id']); |
| 1616 | } |
| 1617 | |
| 1618 | // Update Poll Tables
|
| 1619 | if (isset($poll['poll_options']) && !empty($poll['poll_options'])) |
| 1620 | {
|
| 1621 | $cur_poll_options = array(); |
| 1622 | |
| 1623 | if ($poll['poll_start'] && $mode == 'edit') |
| 1624 | {
|
| 1625 | $sql = 'SELECT * FROM ' . POLL_OPTIONS_TABLE . ' |
| 1626 | WHERE topic_id = ' . $data['topic_id'] . ' |
| 1627 | ORDER BY poll_option_id';
|
| 1628 | $result = $db->sql_query($sql); |
| 1629 | |
| 1630 | while ($cur_poll_options[] = $db->sql_fetchrow($result)); |
| 1631 | $db->sql_freeresult($result); |
| 1632 | } |
| 1633 | |
| 1634 | $sql_insert_ary = array(); |
| 1635 | for ($i = 0, $size = sizeof($poll['poll_options']); $i < $size; $i++) |
| 1636 | {
|
| 1637 | if (trim($poll['poll_options'][$i])) |
| 1638 | {
|
| 1639 | if (!$cur_poll_options[$i]) |
| 1640 | {
|
| 1641 | $sql_insert_ary[] = array( |
| 1642 | 'poll_option_id' => (int) $i, |
| 1643 | 'topic_id' => (int) $data['topic_id'], |
| 1644 | 'poll_option_text' => (string) $poll['poll_options'][$i] |
| 1645 | ); |
| 1646 | } |
| 1647 | else if ($poll['poll_options'][$i] != $cur_poll_options[$i]) |
| 1648 | {
|
| 1649 | $sql = "UPDATE " . POLL_OPTIONS_TABLE . " |
| 1650 | SET poll_option_text = '" . $db->sql_escape($poll['poll_options'][$i]) . "' |
| 1651 | WHERE poll_option_id = " . $cur_poll_options[$i]['poll_option_id'] . " |
| 1652 | AND topic_id = " . $data['topic_id']; |
| 1653 | $db->sql_query($sql); |
| 1654 | } |
| 1655 | } |
| 1656 | } |
| 1657 | |
| 1658 | if (sizeof($sql_insert_ary)) |
| 1659 | {
|
| 1660 | switch (SQL_LAYER) |
| 1661 | {
|
| 1662 | case 'mysql': |
| 1663 | case 'mysql4': |
| 1664 | case 'mysqli': |
| 1665 | $db->sql_query('INSERT INTO ' . POLL_OPTIONS_TABLE . ' ' . $db->sql_build_array('MULTI_INSERT', $sql_insert_ary); |
| 1666 | break;
|
| 1667 | |
| 1668 | default:
|
| 1669 | foreach ($sql_insert_ary as $ary) |
| 1670 | {
|
| 1671 | $db->sql_query('INSERT INTO ' . PRIVMSGS_TO_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_insert_ary)); |
| 1672 | } |
| 1673 | break;
|
| 1674 | } |
| 1675 | } |
| 1676 | |
| 1677 | if (sizeof($poll['poll_options']) < sizeof($cur_poll_options)) |
| 1678 | {
|
| 1679 | $sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . ' |
| 1680 | WHERE poll_option_id >= ' . sizeof($poll['poll_options']) . ' |
| 1681 | AND topic_id = ' . $data['topic_id']; |
| 1682 | $db->sql_query($sql); |
| 1683 | } |
| 1684 | } |
| 1685 | |
| 1686 | // Submit Attachments
|
| 1687 | if (sizeof($data['attachment_data']) && $data['post_id'] && in_array($mode, array('post', 'reply', 'quote', 'edit'))) |
| 1688 | {
|
| 1689 | $space_taken = $files_added = 0; |
| 1690 | |
| 1691 | foreach ($data['attachment_data'] as $pos => $attach_row) |
| 1692 | {
|
| 1693 | if ($attach_row['attach_id']) |
| 1694 | {
|
| 1695 | // update entry in db if attachment already stored in db and filespace
|
| 1696 | $sql = 'UPDATE ' . ATTACHMENTS_TABLE . " |
| 1697 | SET comment = '" . $db->sql_escape($attach_row['comment']) . "' |
| 1698 | WHERE attach_id = " . (int) $attach_row['attach_id']; |
| 1699 | $db->sql_query($sql); |
| 1700 | } |
| 1701 | else
|
| 1702 | {
|
| 1703 | // insert attachment into db
|
| 1704 | if (!@file_exists($phpbb_root_path . $config['upload_path'] . '/' . basename($attach_row['physical_filename']))) |
| 1705 | {
|
| 1706 | continue;
|
| 1707 | } |
| 1708 | |
| 1709 | $attach_sql = array( |
| 1710 | 'post_msg_id' => $data['post_id'], |
| 1711 | 'topic_id' => $data['topic_id'], |
| 1712 | 'in_message' => 0, |
| 1713 | 'poster_id' => $poster_id, |
| 1714 | 'physical_filename' => basename($attach_row['physical_filename']), |
| 1715 | 'real_filename' => basename($attach_row['real_filename']), |
| 1716 | 'comment' => $attach_row['comment'], |
| 1717 | 'extension' => $attach_row['extension'], |
| 1718 | 'mimetype' => $attach_row['mimetype'], |
| 1719 | 'filesize' => $attach_row['filesize'], |
| 1720 | 'filetime' => $attach_row['filetime'], |
| 1721 | 'thumbnail' => $attach_row['thumbnail'] |
| 1722 | ); |
| 1723 | |
| 1724 | $sql = 'INSERT INTO ' . ATTACHMENTS_TABLE . ' ' . |
| 1725 | $db->sql_build_array('INSERT', $attach_sql); |
| 1726 | $db->sql_query($sql); |
| 1727 | |
| 1728 | $space_taken += $attach_row['filesize']; |
| 1729 | $files_added++;
|
| 1730 | } |
| 1731 | } |
| 1732 | |
| 1733 | if (sizeof($data['attachment_data'])) |
| 1734 | {
|
| 1735 | $sql = 'UPDATE ' . POSTS_TABLE . ' |
| 1736 | SET post_attachment = 1 |
| 1737 | WHERE post_id = ' . $data['post_id']; |
| 1738 | $db->sql_query($sql); |
| 1739 | |
| 1740 | $sql = 'UPDATE ' . TOPICS_TABLE . ' |
| 1741 | SET topic_attachment = 1 |
| 1742 | WHERE topic_id = ' . $data['topic_id']; |
| 1743 | $db->sql_query($sql); |
| 1744 | } |
| 1745 | |
| 1746 | set_config('upload_dir_size', $config['upload_dir_size'] + $space_taken, true); |
| 1747 | set_config('num_files', $config['num_files'] + $files_added, true); |
| 1748 | } |
| 1749 | |
| 1750 | $db->sql_transaction('commit'); |
| 1751 | |
| 1752 | if ($post_mode == 'post' || $post_mode == 'reply' || $post_mode == 'edit_last_post') |
| 1753 | {
|
| 1754 | if ($topic_type != POST_GLOBAL) |
| 1755 | {
|
| 1756 | $sql_data[FORUMS_TABLE]['stat'][] = implode(', ', update_last_post_information('forum', $data['forum_id'])); |
| 1757 | } |
| 1758 | |
| 1759 | $update = update_last_post_information('topic', $data['topic_id']); |
| 1760 | if (sizeof($update)) |
| 1761 | {
|
| 1762 | $sql_data[TOPICS_TABLE]['stat'][] = implode(', ', $update); |
| 1763 | } |
| 1764 | } |
| 1765 | |
| 1766 | if ($make_global) |
| 1767 | {
|
| 1768 | $sql_data[FORUMS_TABLE]['stat'][] = implode(', ', update_last_post_information('forum', $data['forum_id'])); |
| 1769 | } |
| 1770 | |
| 1771 | if ($post_mode == 'edit_topic') |
| 1772 | {
|
| 1773 | $update = update_last_post_information('topic', $data['topic_id']); |
| 1774 | if (sizeof($update)) |
| 1775 | {
|
| 1776 | $sql_data[TOPICS_TABLE]['stat'][] = implode(', ', $update); |
| 1777 | } |
| 1778 | } |
| 1779 | |
| 1780 | // Update total post count, do not consider moderated posts/topics
|
| 1781 | if (!$auth->acl_get('f_moderate', $data['forum_id']) || $auth->acl_get('m_approve')) |
| 1782 | {
|
| 1783 | if ($post_mode == 'post') |
| 1784 | {
|
| 1785 | set_config('num_topics', $config['num_topics'] + 1, true); |
| 1786 | set_config('num_posts', $config['num_posts'] + 1, true); |
| 1787 | } |
| 1788 | |
| 1789 | if ($post_mode == 'reply') |
| 1790 | {
|
| 1791 | set_config('num_posts', $config['num_posts'] + 1, true); |
| 1792 | } |
| 1793 | } |
| 1794 | |
| 1795 | // Update forum stats
|
| 1796 | $db->sql_transaction();
|
| 1797 | |
| 1798 | $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']); |
| 1799 | |
| 1800 | foreach ($sql_data as $table => $update_ary) |
| 1801 | {
|
| 1802 | if (isset($update_ary['stat']) && implode('', $update_ary['stat'])) |
| 1803 | {
|
| 1804 | $db->sql_query("UPDATE $table SET " . implode(', ', $update_ary['stat']) . ' WHERE ' . $where_sql[$table]); |
| 1805 | } |
| 1806 | } |
| 1807 | |
| 1808 | // Delete topic shadows (if any exist). We do not need a shadow topic for an global announcement
|
| 1809 | if ($make_global) |
| 1810 | {
|
| 1811 | $db->sql_query('DELETE FROM ' . TOPICS_TABLE . ' |
| 1812 | WHERE topic_moved_id = ' . $data['topic_id']); |
| 1813 | } |
| 1814 | |
| 1815 | // Fulltext parse
|
| 1816 | if ($update_message && $data['enable_indexing']) |
| 1817 | {
|
| 1818 | $search = new fulltext_search(); |
| 1819 | $result = $search->add($mode, $data['post_id'], $data['message'], $subject); |
| 1820 | } |
| 1821 | |
| 1822 | $db->sql_transaction('commit'); |
| 1823 | |
| 1824 | // Delete draft if post was loaded...
|
| 1825 | $draft_id = request_var('draft_loaded', 0); |
| 1826 | if ($draft_id) |
| 1827 | {
|
| 1828 | $db->sql_query('DELETE FROM ' . DRAFTS_TABLE . " WHERE draft_id = $draft_id AND user_id = " . $user->data['user_id']); |
| 1829 | } |
| 1830 | |
| 1831 | // Topic Notification
|
| 1832 | if (!$data['notify_set'] && $data['notify']) |
| 1833 | {
|
| 1834 | $sql = 'INSERT INTO ' . TOPICS_WATCH_TABLE . ' (user_id, topic_id) |
| 1835 | VALUES (' . $user->data['user_id'] . ', ' . $data['topic_id'] . ')'; |
| 1836 | $db->sql_query($sql); |
| 1837 | } |
| 1838 | else if ($data['notify_set'] && !$data['notify']) |
| 1839 | {
|
| 1840 | $sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . ' |
| 1841 | WHERE user_id = ' . $user->data['user_id'] . ' |
| 1842 | AND topic_id = ' . $data['topic_id']; |
| 1843 | $db->sql_query($sql); |
| 1844 | } |
| 1845 | |
| 1846 | // Mark this topic as read and posted to.
|
| 1847 | $mark_mode = ($mode == 'post' || $mode == 'reply' || $mode == 'quote') ? 'post' : 'topic'; |
| 1848 | markread($mark_mode, $data['forum_id'], $data['topic_id'], $data['post_time']); |
| 1849 | |
| 1850 | // Send Notifications
|
| 1851 | if ($mode != 'edit' && $mode != 'delete' && (!$auth->acl_get('f_moderate', $data['forum_id']) || $auth->acl_get('m_approve'))) |
| 1852 | {
|
| 1853 | user_notification($mode, stripslashes($subject), stripslashes($data['topic_title']), stripslashes($data['forum_name']), $data['forum_id'], $data['topic_id'], $data['post_id']); |
| 1854 | } |
| 1855 | |
| 1856 | if ($mode == 'post') |
| 1857 | {
|
| 1858 | $url = (!$auth->acl_get('f_moderate', $data['forum_id']) || $auth->acl_get('m_approve')) ? "{$phpbb_root_path}viewtopic.$phpEx$SID&f=" . $data['forum_id'] . '&t=' . $data['topic_id'] : "{$phpbb_root_path}viewforum.$phpEx$SID&f=" . $data['forum_id']; |
| 1859 | } |
| 1860 | else
|
| 1861 | {
|
| 1862 | $url = (!$auth->acl_get('f_moderate', $data['forum_id']) || $auth->acl_get('m_approve')) ? "{$phpbb_root_path}viewtopic.$phpEx$SID&f={$data['forum_id']}&t={$data['topic_id']}&p={$data['post_id']}#{$data['post_id']}" : "{$phpbb_root_path}viewtopic.$phpEx$SID&f={$data['forum_id']}&t={$data['topic_id']}"; |
| 1863 | } |
| 1864 | |
| 1865 | meta_refresh(3, $url); |
| 1866 | |
| 1867 | $message = ($auth->acl_get('f_moderate', $data['forum_id']) && !$auth->acl_get('m_approve')) ? (($mode == 'edit') ? 'POST_EDITED_MOD' : 'POST_STORED_MOD') : (($mode == 'edit') ? 'POST_EDITED' : 'POST_STORED'); |
| 1868 | $message = $user->lang[$message] . ((!$auth->acl_get('f_moderate', $data['forum_id']) || $auth->acl_get('m_approve')) ? '<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>'); |
| 1869 | trigger_error($message); |
| 1870 | } |
| 1871 | |
| 1872 | function upload_popup($forum_style) |
| 1873 | {
|
| 1874 | global $template, $user; |
| 1875 | |
| 1876 | $user->setup('posting', $forum_style); |
| 1877 | |
| 1878 | page_header('PROGRESS_BAR');
|
| 1879 | |
| 1880 | $template->set_filenames(array( |
| 1881 | 'popup' => 'posting_progress_bar.html') |
| 1882 | ); |
| 1883 | |
| 1884 | $template->assign_vars(array( |
| 1885 | 'PROGRESS_BAR' => $user->img('attach_progress_bar', $user->lang['UPLOAD_IN_PROGRESS'])) |
| 1886 | ); |
| 1887 | |
| 1888 | $template->display('popup'); |
| 1889 | } |
| 1890 | |
| 1891 | ?> |

