function submit_merged_post($post_id, $forum_id, $subject, $message, &$return_message, &$return_meta) { global $board_config, $db, $lang, $phpEx, $phpbb_root_path; include $phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_merge.' . $phpEx; include $phpbb_root_path . 'includes/functions_search.' . $phpEx; $current_time = time(); // Check message if (empty($message)) { message_die(GENERAL_MESSAGE, $lang['Empty_message']); } $sql = "SELECT p.post_created, p.post_time, p.enable_html, p.enable_bbcode, p.enable_smilies, pt.* \r\n\t\tFROM " . POSTS_TABLE . " p, " . POSTS_TEXT_TABLE . " pt\r\n\t\tWHERE p.post_id = {$post_id}\r\n\t\t\tAND pt.post_id = p.post_id"; $result = $db->sql_query($sql) or message_die(GENERAL_ERROR, 'Could not obtain last post information', '', __LINE__, __FILE__, $sql); $last_post_data = $db->sql_fetchrow($result); // Flood control if ($current_time - intval($last_post_data['post_time']) < intval($board_config['merge_flood_interval'])) { message_die(GENERAL_MESSAGE, $lang['Flood_Error']); } $last_post_created = $last_post_data['post_created']; $last_post_time = $last_post_data['post_time']; $last_html = $last_post_data['enable_html']; $last_bbcode = $last_post_data['enable_bbcode']; $last_smilies = $last_post_data['enable_smilies']; $last_bbcode_uid = $last_post_data['bbcode_uid']; $last_subject = $last_post_data['post_subject']; $last_message = $last_post_data['post_text']; $db->sql_freeresult($result); if ($last_bbcode_uid != '') { $last_message = preg_replace('/\\:(([a-z0-9]:)?)' . $last_bbcode_uid . '/s', '', $last_message); } $last_message = unprepare_message($last_message); // Adding slashes, we need this step for comparison $last_subject = addslashes($last_subject); $last_message = addslashes($last_message); // Preparing separator $merged_after = $current_time - $last_post_time; $merged_sec = $merged_after % 60; $merged_min = $merged_after / 60 % 60; $merged_hours = $merged_after / 3600 % 24; $merged_days = $merged_after / 86400 % 31; $s_st = $merged_sec ? seconds_st($merged_sec) : ''; $m_st = $merged_min ? minutes_st($merged_min) : ''; $h_st = $merged_hours ? hours_st($merged_hours) : ''; $d_st = $merged_days ? days_st($merged_days) : ''; $separator = sprintf($lang['Merge_separator'], $d_st, $h_st, $m_st, $s_st); $separator .= !empty($subject) && $subject != $last_subject ? sprintf($lang['Merge_post_subject'], $subject) : ''; $separator = str_replace("'", "''", $separator); $message = $message != $last_message ? $last_message . $separator . trim($message) : trim($message); $message = prepare_message($message, $last_html, $last_bbcode, $last_smilies, $last_bbcode_uid); // This replacement was borrowed from posting.php $last_subject = str_replace("\\'", "''", $last_subject); $last_message = str_replace("\\'", "''", $last_message); $sql = "UPDATE " . POSTS_TEXT_TABLE . " SET post_text = '{$message}' WHERE post_id = {$post_id}"; $result = $db->sql_query($sql) or message_die(GENERAL_ERROR, 'Could not update post text information', '', __LINE__, __FILE__, $sql); $sql = "UPDATE " . POSTS_TABLE . " SET post_time = {$current_time} WHERE post_id = {$post_id}"; $result = $db->sql_query($sql) or message_die(GENERAL_ERROR, 'Could not update last post time', '', __LINE__, __FILE__, $sql); $sql = "UPDATE " . FORUMS_TABLE . " SET forum_last_post_id = {$post_id} WHERE forum_id = {$forum_id}"; $result = $db->sql_query($sql) or message_die(GENERAL_ERROR, 'Could not update forum last post id', '', __LINE__, __FILE__, $sql); $db->clear_cache('topics_recent_'); $db->clear_cache('posts_'); // Search routines remove_search_post($post_id); add_search_words('single', $post_id, stripslashes($message), stripslashes($subject)); // Meta & return message $return_meta = '<meta http-equiv="refresh" content="3;url=' . append_sid("viewtopic.{$phpEx}?" . POST_POST_URL . "=" . $post_id) . '#' . $post_id . '">'; $return_message = $lang['Stored'] . '<br /><br />' . sprintf($lang['Click_view_message'], '<a href="' . append_sid("viewtopic.{$phpEx}?" . POST_POST_URL . "=" . $post_id) . '#' . $post_id . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_forum'], '<a href="' . append_sid("viewforum.{$phpEx}?" . POST_FORUM_URL . "={$forum_id}") . '">', '</a>'); }
if (!$errors && !isset($_POST['preview'])) { // MERGE POSTS BEGIN $merged = false; if (isset($_POST['merge'])) { $_POST['merge'] = 1; } else { $_POST['merge'] = 0; } if (!$pun_user['is_guest'] && !$fid && (($is_admmod && $_POST['merge']) == 1 || !$is_admmod) && $cur_posting['poster_id'] && $cur_posting['message'] && $_SERVER['REQUEST_TIME'] - $cur_posting['posted'] < $pun_config['o_timeout_merge']) { // Preparing separator $merged_after = $_SERVER['REQUEST_TIME'] - $cur_posting['posted']; $merged_sec = $merged_after % 60; $merged_min = $merged_after / 60 % 60; $merged_hours = $merged_after / 3600 % 24; $merged_days = $merged_after / 86400 % 31; $s_st = $merged_sec ? seconds_st($merged_sec) : ''; $m_st = $merged_min ? minutes_st($merged_min) : ''; $h_st = $merged_hours ? hours_st($merged_hours) : ''; $d_st = $merged_days ? days_st($merged_days) : ''; $message = pun_linebreaks(pun_trim('[color=#bbb][i]' . $lang_post['Added'] . $d_st . ' ' . $h_st . ' ' . $m_st . ' ' . $s_st . ': [/i][/color]')) . "\n" . $message; $merged = true; } // MERGE POSTS END // If it's a reply if ($tid) { if (!$pun_user['is_guest']) { // Insert the new post if ($merged) { $message = $cur_posting['message'] . "\n" . $message; $db->query('UPDATE ' . $db->prefix . 'posts SET message=\'' . $db->escape($message) . '\' WHERE id=' . $cur_posting['post_id']) or error('Unable to merge post', __FILE__, __LINE__, $db->error()); $new_pid = $cur_posting['post_id'];