break; default: $query = $db->simple_select("threads", "COUNT(tid) as threads", "fid = '{$fid}' AND (lastpost >= '" . intval($thread['lastpost']) . "'{$stickybit}) {$visibleonly} {$uid_only}", array('order_by' => 'lastpost', 'order_dir' => 'desc')); } $thread_position = $db->fetch_field($query, "threads"); $thread_page = ceil($thread_position / $mybb->settings['threadsperpage']); $breadcrumb_multipage = array("num_threads" => $threadcount, "current_page" => $thread_page); } // Build the navigation. build_forum_breadcrumb($fid, $breadcrumb_multipage); add_breadcrumb($thread['displayprefix'] . $thread['subject'], get_thread_link($thread['tid'])); $plugins->run_hooks("showthread_start"); // Show the entire thread (taking into account pagination). if ($mybb->input['action'] == "thread") { if ($thread['firstpost'] == 0) { update_first_post($tid); } // Does this thread have a poll? if ($thread['poll']) { $options = array("limit" => 1); $query = $db->simple_select("polls", "*", "pid='" . $thread['poll'] . "'", $options); $poll = $db->fetch_array($query); $poll['timeout'] = $poll['timeout'] * 60 * 60 * 24; $expiretime = $poll['dateline'] + $poll['timeout']; $now = TIME_NOW; // If the poll or the thread is closed or if the poll is expired, show the results. if ($poll['closed'] == 1 || $thread['closed'] == 1 || $expiretime < $now && $poll['timeout'] > 0) { $showresults = 1; } // If the user is not a guest, check if he already voted. if ($mybb->user['uid'] != 0) {
function upgrade5_lastposts() { global $db, $output; $output->print_header("Przebudowywanie informacji o ostatnich postach"); if (!$_POST['tpp']) { echo "<p>Nastęnym krokiem w aktualizacji jest przebudowanie informacji o ostatnim poście w każdym wątku na Twoim forum. Wpisz w poniższe pole ilość wpisów, które mają zostać przetworzone na stronę.</p>"; echo "<p><strong>Wpisów na stronę:</strong> <input type=\"text\" size=\"3\" value=\"200\" name=\"tpp\" /></p>"; echo "<p>Jeżeli wszystko gotowe, naciśnij przycisk Dalej, aby rozpocząć proces przebudowy.</p>"; $output->print_footer("5_lastposts"); } else { require_once MYBB_ROOT . "inc/functions_rebuild.php"; $query = $db->simple_select("threads", "COUNT(*) as num_threads", "closed NOT LIKE 'moved|%'"); $num_threads = $db->fetch_field($query, 'num_threads'); $tpp = intval($_POST['tpp']); $start = intval($_POST['start']); $end = $start + $tpp; if ($end > $num_threads) { $end = $num_threads; } echo "<p>Aktualizacja {$start} do {$end} z {$num_threads}...</p>"; $query = $db->simple_select("threads", "tid, firstpost", "closed NOT LIKE 'moved|%'", array("order_by" => "tid", "order_dir" => "asc", "limit" => $tpp, "limit_start" => $start)); while ($thread = $db->fetch_array($query)) { rebuild_thread_counters($thread['tid']); if ($thread['firstpost'] == 0) { update_first_post($thread['tid']); } } echo "<p>Zakończono</p>"; if ($end >= $num_threads) { echo "<p>Proces przebudowy został pomyślnie zakończony. Naciśnij przycisk Dalej, aby kontynuować proces aktualizacji."; $output->print_footer("5_forumlastposts"); } else { echo "<p>Naciśnij przycisk Dalej, aby kontynuować proces przebudowy.</p>"; echo "<input type=\"hidden\" name=\"tpp\" value=\"{$tpp}\" />"; echo "<input type=\"hidden\" name=\"start\" value=\"{$end}\" />"; $output->print_footer("5_lastposts"); } } }
function upgrade5_lastposts() { global $db, $output; $output->print_header("Rebuilding Last Post Columns"); if (!$_POST['tpp']) { echo "<p>The next step in the upgrade process involves rebuilding the last post information for every thread in your forum. Below, please enter the number of threads to process per page.</p>"; echo "<p><strong>Threads Per Page:</strong> <input type=\"text\" size=\"3\" value=\"200\" name=\"tpp\" /></p>"; echo "<p>Once you're ready, press next to begin the rebuild process.</p>"; $output->print_footer("5_lastposts"); } else { require_once MYBB_ROOT . "inc/functions_rebuild.php"; $query = $db->simple_select("threads", "COUNT(*) as num_threads", "closed NOT LIKE 'moved|%'"); $num_threads = $db->fetch_field($query, 'num_threads'); $tpp = intval($_POST['tpp']); $start = intval($_POST['start']); $end = $start + $tpp; if ($end > $num_threads) { $end = $num_threads; } echo "<p>Updating {$start} to {$end} of {$num_threads}...</p>"; $query = $db->simple_select("threads", "tid, firstpost", "closed NOT LIKE 'moved|%'", array("order_by" => "tid", "order_dir" => "asc", "limit" => $tpp, "limit_start" => $start)); while ($thread = $db->fetch_array($query)) { rebuild_thread_counters($thread['tid']); if ($thread['firstpost'] == 0) { update_first_post($thread['tid']); } } echo "<p>Done</p>"; if ($end >= $num_threads) { echo "<p>The rebuild process has completed successfully. Click next to continue with the upgrade."; $output->print_footer("5_forumlastposts"); } else { echo "<p>Click Next to continue with the build process.</p>"; echo "<input type=\"hidden\" name=\"tpp\" value=\"{$tpp}\" />"; echo "<input type=\"hidden\" name=\"start\" value=\"{$end}\" />"; $output->print_footer("5_lastposts"); } } }
function get_thread_func($xmlrpc_params) { global $db, $lang, $mybb, $position, $plugins, $pids; global $pforumcache, $currentitem, $forum_cache, $navbits, $base_url, $archiveurl; $input = Tapatalk_Input::filterXmlInput(array('topic_id' => Tapatalk_Input::STRING, 'start_num' => Tapatalk_Input::INT, 'last_num' => Tapatalk_Input::INT, 'return_html' => Tapatalk_Input::INT), $xmlrpc_params); if (preg_match('/^ann_/', $input['topic_id'])) { $_GET["aid"] = intval(str_replace('ann_', '', $input['topic_id'])); return get_announcement_func($xmlrpc_params); } $lang->load("showthread"); global $parser; $parser = new Tapatalk_Parser(); // Get the thread details from the database. $thread = get_thread($input['topic_id']); if (!empty($thread['closed'])) { $moved = explode("|", $thread['closed']); if ($moved[0] == "moved") { $thread = get_thread($moved[1]); } } // Get thread prefix if there is one. $thread['threadprefix'] = ''; $thread['displayprefix'] = ''; if ($thread['prefix'] != 0) { $threadprefix = build_prefixes($thread['prefix']); if ($threadprefix['prefix']) { $thread['threadprefix'] = $threadprefix['prefix'] . ' '; $thread['displayprefix'] = $threadprefix['displaystyle'] . ' '; } } $thread['subject'] = $parser->parse_badwords($thread['subject']); $tid = $thread['tid']; $fid = $thread['fid']; if (!$thread['username']) { $thread['username'] = $lang->guest; } $visibleonly = "AND visible='1'"; // Is the currently logged in user a moderator of this forum? if (is_moderator($fid)) { $visibleonly = " AND (visible='1' OR visible='0')"; $ismod = true; } else { $ismod = false; } $forumpermissions = forum_permissions($thread['fid']); // Does the user have permission to view this thread? if ($forumpermissions['canview'] != 1 || $forumpermissions['canviewthreads'] != 1) { error_no_permission(); } if ($forumpermissions['canonlyviewownthreads'] == 1 && $thread['uid'] != $mybb->user['uid']) { error_no_permission(); } // Make sure we are looking at a real thread here. if (!$thread['tid'] || $thread['visible'] == 0 && $ismod == false || $thread['visible'] > 1 && $ismod == true) { return xmlrespfalse($lang->error_invalidthread); } // Does the thread belong to a valid forum? $forum = get_forum($fid); if (!$forum || $forum['type'] != "f") { return xmlrespfalse($lang->error_invalidforum); } tt_check_forum_password($forum['fid']); if ($thread['firstpost'] == 0) { update_first_post($tid); } // Mark this thread as read mark_thread_read($tid, $fid); // Increment the thread view. if ($mybb->settings['delayedthreadviews'] == 1) { $db->shutdown_query("INSERT INTO " . TABLE_PREFIX . "threadviews (tid) VALUES('{$tid}')"); } else { $db->shutdown_query("UPDATE " . TABLE_PREFIX . "threads SET views=views+1 WHERE tid='{$tid}'"); } ++$thread['views']; // Work out if we are showing unapproved posts as well (if the user is a moderator etc.) if ($ismod) { $visible = "AND (p.visible='0' OR p.visible='1')"; } else { $visible = "AND p.visible='1'"; } // Fetch the ignore list for the current user if they have one $ignored_users = array(); if ($mybb->user['uid'] > 0 && $mybb->user['ignorelist'] != "") { $ignore_list = explode(',', $mybb->user['ignorelist']); foreach ($ignore_list as $uid) { $ignored_users[$uid] = 1; } } list($start, $limit) = process_page($input['start_num'], $input['last_num']); // Recount replies if user is a moderator to take into account unapproved posts. if ($ismod) { $query = $db->simple_select("posts p", "COUNT(*) AS replies", "p.tid='{$tid}' {$visible}"); $thread['replies'] = $db->fetch_field($query, 'replies') - 1; } $postcount = intval($thread['replies']) + 1; $pids = ""; $comma = ''; $query = $db->simple_select("posts p", "p.pid", "p.tid='{$tid}' {$visible}", array('order_by' => 'p.dateline', 'limit_start' => $start, 'limit' => $limit)); while ($getid = $db->fetch_array($query)) { // Set the ID of the first post on page to $pid if it doesn't hold any value // to allow this value to be used for Thread Mode/Linear Mode links // and ensure the user lands on the correct page after changing view mode if (!$pid) { $pid = $getid['pid']; } // Gather a comma separated list of post IDs $pids .= "{$comma}'{$getid['pid']}'"; $comma = ","; } if ($pids) { $pids = "pid IN({$pids})"; global $attachcache; $attachcache = array(); if ($thread['attachmentcount'] > 0) { // Now lets fetch all of the attachments for these posts. $query = $db->simple_select("attachments", "*", $pids); while ($attachment = $db->fetch_array($query)) { $attachcache[$attachment['pid']][$attachment['aid']] = $attachment; } } } else { // If there are no pid's the thread is probably awaiting approval. return xmlrespfalse($lang->error_invalidthread); } $post_list = array(); // Get the actual posts from the database here. $posts = ''; $query = $db->query("\n SELECT u.*, u.username AS userusername, p.*, f.*, eu.username AS editusername, IF(b.lifted > UNIX_TIMESTAMP() OR b.lifted = 0, 1, 0) as isbanned\n FROM " . TABLE_PREFIX . "posts p\n LEFT JOIN " . TABLE_PREFIX . "users u ON (u.uid=p.uid)\n LEFT JOIN " . TABLE_PREFIX . "userfields f ON (f.ufid=u.uid)\n LEFT JOIN " . TABLE_PREFIX . "users eu ON (eu.uid=p.edituid)\n LEFT JOIN " . TABLE_PREFIX . "banned b ON (b.uid = p.uid)\n WHERE {$pids}\n ORDER BY p.dateline\n "); //can_rename topic $can_rename = (is_moderator($fid, "caneditposts") || $forumpermissions['caneditposts'] == 1 && $mybb->user['uid'] == $thread['uid']) && $mybb->user['uid'] != 0; while ($post = $db->fetch_array($query)) { if ($thread['firstpost'] == $post['pid'] && $thread['visible'] == 0) { $post['visible'] = 0; } //$posts .= build_postbit($post); $parser_options = array(); $parser_options['allow_html'] = false; $parser_options['allow_mycode'] = true; $parser_options['allow_smilies'] = false; $parser_options['allow_imgcode'] = true; $parser_options['allow_videocode'] = true; $parser_options['nl2br'] = (bool) $input['return_html']; $parser_options['filter_badwords'] = 1; if (!$post['username']) { $post['username'] = $lang->guest; } if ($post['userusername']) { $parser_options['me_username'] = $post['userusername']; } else { $parser_options['me_username'] = $post['username']; } $post['subject'] = $parser->parse_badwords($post['subject']); $post['author'] = $post['uid']; if ($post['userusername']) { // This post was made by a registered user $post['username'] = $post['userusername']; } // Eidt Option $can_edit = (is_moderator($fid, "caneditposts") || $forumpermissions['caneditposts'] == 1 && $mybb->user['uid'] == $post['uid']) && $mybb->user['uid'] != 0; // Quick Delete Option $can_delete = 0; if ($mybb->user['uid'] == $post['uid']) { if ($forumpermissions['candeletethreads'] == 1 && $postcounter == 1) { $can_delete = 1; } else { if ($forumpermissions['candeleteposts'] == 1 && $postcounter != 1) { $can_delete = 1; } } } $can_delete = (is_moderator($fid, "candeleteposts") || $can_delete == 1) && $mybb->user['uid'] != 0; // User Online status $is_online = false; $timecut = TIME_NOW - $mybb->settings['wolcutoff']; if ($post['lastactive'] > $timecut && ($post['invisible'] != 1 || $mybb->usergroup['canviewwolinvis'] == 1) && $post['lastvisit'] != $post['lastactive']) { $is_online = true; } $post['message'] = post_bbcode_clean($post['message']); $plugins->remove_hook('parse_message', 'mybbirckeditor_parser'); // Post content and attachments $post['message'] = $parser->parse_message($post['message'], $parser_options); $attachment_list = process_post_attachments($post['pid'], $post); // add for thank/like support $post = $plugins->run_hooks("postbit", $post); if (is_array($ignored_users) && $post['uid'] != 0 && $ignored_users[$post['uid']] == 1) { $show_spoiler = "[spoiler]" . $post['message'] . "[/spoiler]"; $post['message'] = $lang->sprintf($lang->postbit_currently_ignoring_user, $post['username']) . $show_spoiler; } $post_xmlrpc = array('post_id' => new xmlrpcval($post['pid'], 'string'), 'post_title' => new xmlrpcval(basic_clean($post['subject']), 'base64'), 'post_content' => new xmlrpcval(process_post($post['message'], $input['return_html']), 'base64'), 'post_author_id' => new xmlrpcval($post['uid'], 'string'), 'post_author_name' => new xmlrpcval(basic_clean($post['username']), 'base64'), 'icon_url' => new xmlrpcval(absolute_url($post['avatar']), 'string'), 'post_time' => new xmlrpcval(mobiquo_iso8601_encode($post['dateline']), 'dateTime.iso8601'), 'timestamp' => new xmlrpcval($post['dateline'], 'string'), 'attachments' => new xmlrpcval($attachment_list, 'array')); if (!$post['visible']) { $post_xmlrpc['is_approved'] = new xmlrpcval(false, 'boolean'); } // default as true if ($post['smilieoff']) { $post_xmlrpc['allow_smilies'] = new xmlrpcval(false, 'boolean'); } // default as true if ($post['isbanned']) { $post_xmlrpc['is_ban'] = new xmlrpcval(true, 'boolean'); } if ($is_online) { $post_xmlrpc['is_online'] = new xmlrpcval(true, 'boolean'); } if ($can_edit) { $post_xmlrpc['can_edit'] = new xmlrpcval(true, 'boolean'); } if ($can_delete) { $post_xmlrpc['can_delete'] = new xmlrpcval(true, 'boolean'); } if (is_moderator($fid, 'canmanagethreads')) { $post_xmlrpc['can_approve'] = new xmlrpcval(true, 'boolean'); } if (is_moderator($fid, 'canmanagethreads')) { $post_xmlrpc['can_move'] = new xmlrpcval(true, 'boolean'); } if ($mybb->usergroup['canmodcp'] == 1) { $post_xmlrpc['can_ban'] = new xmlrpcval(true, 'boolean'); } if ($post['edituid']) { //add edit info $edit_info = array('editor_id' => new xmlrpcval($post['edituid'], 'string'), 'editor_name' => new xmlrpcval($post['editusername'], 'base64'), 'edit_time' => new xmlrpcval($post['edittime'], 'string')); if (!empty($post['editreason'])) { $edit_info['edit_reason'] = new xmlrpcval($post['editreason'], 'base64'); } $post_xmlrpc = array_merge($post_xmlrpc, $edit_info); } // add for thank/like support if (isset($post['button_tyl']) && $mybb->user['uid']) { global $mobiquo_config, $g33k_pcache; $thlprefix = $mobiquo_config['thlprefix']; $tyled = false; $tyl_list = array(); if ($mybb->settings[$thlprefix . 'enabled'] == "1") { if ($post['thankyoulike'] && isset($g33k_pcache[$post['pid']])) { foreach ($g33k_pcache[$post['pid']] as $tyl) { if ($tyl['uid'] == $mybb->user['uid']) { $tyled = true; } $tyl_list[] = new xmlrpcval(array('userid' => new xmlrpcval($tyl['uid'], 'string'), 'username' => new xmlrpcval(basic_clean($tyl['username']), 'base64')), 'struct'); } } if ($mybb->settings[$thlprefix . 'thankslike'] == "like") { if ($post['button_tyl']) { $post_xmlrpc['can_like'] = new xmlrpcval(true, 'boolean'); } if ($tyled) { $post_xmlrpc['is_liked'] = new xmlrpcval(true, 'boolean'); } if ($tyl_list) { $post_xmlrpc['likes_info'] = new xmlrpcval($tyl_list, 'array'); } } else { if ($mybb->settings[$thlprefix . 'thankslike'] == "thanks") { if ($post['button_tyl']) { $post_xmlrpc['can_thank'] = new xmlrpcval(true, 'boolean'); } if ($mybb->settings[$thlprefix . 'removing'] == 1) { $post_xmlrpc['can_remove_thank'] = new xmlrpcval(true, 'boolean'); } if ($tyled) { $post_xmlrpc['is_thanked'] = new xmlrpcval(true, 'boolean'); } if ($tyl_list) { $post_xmlrpc['thanks_info'] = new xmlrpcval($tyl_list, 'array'); } } } } } $post_list[] = new xmlrpcval($post_xmlrpc, 'struct'); } $query = $db->simple_select("threadsubscriptions", "tid", "tid='" . intval($tid) . "' AND uid='" . intval($mybb->user['uid']) . "'", array('limit' => 1)); $subscribed = (bool) $db->fetch_field($query, 'tid'); $query = $db->simple_select("banned", "uid", "uid='{$thread['uid']}'"); $isbanned = !!$db->fetch_field($query, "uid"); $can_reply = $forumpermissions['canpostreplys'] != 0 && $mybb->user['suspendposting'] != 1 && ($thread['closed'] != 1 || is_moderator($fid)) && $forum['open'] != 0; build_tt_breadcrumb($fid); $navgation_arr = $navbits; if (is_array($navgation_arr) && count($navgation_arr) > 1) { unset($navgation_arr[0]); foreach ($navgation_arr as $navigation) { $forum_id = $navigation['fid']; $sub_only = false; if ($navigation['type'] != 'f') { $sub_only = true; } $breadcrumb[] = new xmlrpcval(array('forum_id' => new xmlrpcval($forum_id, 'string'), 'forum_name' => new xmlrpcval($navigation['name'], 'base64'), 'sub_only' => new xmlrpcval($sub_only, 'boolean')), 'struct'); } } $is_poll = !empty($thread['poll']) ? true : false; $result = array('total_post_num' => new xmlrpcval($postcount, 'int'), 'forum_id' => new xmlrpcval($thread['fid'], 'string'), 'forum_name' => new xmlrpcval(basic_clean($forum['name']), 'base64'), 'topic_id' => new xmlrpcval($thread['tid'], 'string'), 'topic_title' => new xmlrpcval(basic_clean($thread['subject']), 'base64'), 'can_upload' => new xmlrpcval($forumpermissions['canpostattachments'] != 0, 'boolean'), 'can_report' => new xmlrpcval(true, 'boolean'), 'can_reply' => new xmlrpcval($can_reply, 'boolean'), 'is_poll' => new xmlrpcval($is_poll, 'boolean'), 'view_number' => new xmlrpcval(intval($thread['views']), 'int')); if ($forumpermissions['canview'] == 0 || $forumpermissions['canviewthreads'] == 0) { $new_topic['can_subscribe'] = new xmlrpcval(false, 'boolean'); } else { $new_topic['can_subscribe'] = new xmlrpcval(true, 'boolean'); } if ($thread['prefix']) { $result['prefix'] = new xmlrpcval(basic_clean($thread['displayprefix']), 'base64'); } if (!$thread['visible']) { $result['is_approved'] = new xmlrpcval(false, 'boolean'); } // default as true if ($thread['closed']) { $result['is_closed'] = new xmlrpcval(true, 'boolean'); } if ($thread['sticky']) { $result['is_sticky'] = new xmlrpcval(true, 'boolean'); } if ($subscribed) { $result['is_subscribed'] = new xmlrpcval(true, 'boolean'); } else { $result['is_subscribed'] = new xmlrpcval(false, 'boolean'); } if ($isbanned) { $result['is_ban'] = new xmlrpcval(true, 'boolean'); } if ($position) { $result['position'] = new xmlrpcval(intval($position), 'int'); } if (is_moderator($fid, "canopenclosethreads")) { $result['can_close'] = new xmlrpcval(true, 'boolean'); } if (is_moderator($fid, "candeleteposts")) { $result['can_delete'] = new xmlrpcval(true, 'boolean'); } if (is_moderator($fid, "canmanagethreads")) { $result['can_stick'] = new xmlrpcval(true, 'boolean'); } if (is_moderator($fid, "canmanagethreads")) { $result['can_move'] = new xmlrpcval(true, 'boolean'); $result['can_merge'] = new xmlrpcval(true, 'boolean'); $result['can_merge_post'] = new xmlrpcval(true, 'boolean'); } if (is_moderator($fid, "canopenclosethreads")) { $result['can_approve'] = new xmlrpcval(true, 'boolean'); } if ($can_rename) { $result['can_rename'] = new xmlrpcval(true, 'boolean'); } if ($mybb->usergroup['canmodcp'] == 1) { $result['can_ban'] = new xmlrpcval(true, 'boolean'); } if (!empty($breadcrumb)) { $result['breadcrumb'] = new xmlrpcval($breadcrumb, 'array'); } $result['posts'] = new xmlrpcval($post_list, 'array'); return new xmlrpcresp(new xmlrpcval($result, 'struct')); }
/** * Split posts into a new/existing thread * * @param array $pids PIDs of posts to split * @param int $tid Original thread ID (this is only used as a base for the new * thread; it can be set to 0 when the posts specified are coming from more * than 1 thread) * @param int $moveto Destination forum * @param string $newsubject New thread subject * @param int $destination_tid TID if moving into existing thread * @return int|bool New thread ID or false on failure */ function split_posts($pids, $tid, $moveto, $newsubject, $destination_tid = 0) { global $db, $thread, $plugins, $cache; $tid = (int) $tid; $moveto = (int) $moveto; $newtid = (int) $destination_tid; // Make sure we only have valid values $pids = array_map('intval', $pids); $pids_list = implode(',', $pids); // Get forum infos $forum_cache = $cache->read('forums'); if (empty($pids) || !$forum_cache[$moveto]) { return false; } // Get the first split post $query = $db->simple_select('posts', 'pid,uid,visible,icon,username,dateline', 'pid IN (' . $pids_list . ')', array('order_by' => 'dateline', 'order_dir' => 'asc', 'limit' => 1)); $post_info = $db->fetch_array($query); $visible = $post_info['visible']; $forum_counters[$moveto] = array('threads' => 0, 'deletedthreads' => 0, 'unapprovedthreads' => 0, 'posts' => 0, 'unapprovedposts' => 0, 'deletedposts' => 0); if ($destination_tid == 0) { // Splitting into a new thread // Create the new thread $newsubject = $db->escape_string($newsubject); $newthread = array("fid" => $moveto, "subject" => $newsubject, "icon" => (int) $post_info['icon'], "uid" => (int) $post_info['uid'], "username" => $db->escape_string($post_info['username']), "dateline" => (int) $post_info['dateline'], "firstpost" => $post_info['pid'], "lastpost" => 0, "lastposter" => '', "visible" => (int) $visible, "notes" => ''); $newtid = $db->insert_query("threads", $newthread); if ($visible == 1) { ++$forum_counters[$moveto]['threads']; if (!isset($user_counters[$newthread['uid']])) { $user_counters[$newthread['uid']] = array('postnum' => 0, 'threadnum' => 0); } // Subtract thread from old thread opener --$user_counters[$newthread['uid']]['threadnum']; } elseif ($visible == -1) { ++$forum_counters[$moveto]['deletedthreads']; } else { // Unapproved thread? ++$forum_counters[$moveto]['unapprovedthreads']; } } else { $newthread = get_thread($newtid); if (!$newthread) { return false; } $moveto = $newthread['fid']; } // Get selected posts before moving forums to keep old fid $original_posts_query = $db->query("\n\t\t\tSELECT p.pid, p.tid, p.fid, p.visible, p.uid, p.dateline, t.visible as threadvisible, t.firstpost, COUNT(a.aid) as postattachmentcount\n\t\t\tFROM " . TABLE_PREFIX . "posts p\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "threads t ON (p.tid=t.tid)\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "attachments a ON (a.pid=p.pid AND a.visible=1)\n\t\t\tWHERE p.pid IN ({$pids_list})\n\t\t\tGROUP BY p.pid\n\t\t"); // Move the selected posts over $sqlarray = array("tid" => $newtid, "fid" => $moveto, "replyto" => 0); $db->update_query("posts", $sqlarray, "pid IN ({$pids_list})"); $thread_counters[$newtid] = array('replies' => 0, 'unapprovedposts' => 0, 'deletedposts' => 0, 'attachmentcount' => 0); // Get posts being merged while ($post = $db->fetch_array($original_posts_query)) { if (!isset($thread_counters[$post['tid']])) { $thread_counters[$post['tid']] = array('replies' => 0, 'unapprovedposts' => 0, 'deletedposts' => 0, 'attachmentcount' => 0); } if (!isset($forum_counters[$post['fid']])) { $forum_counters[$post['fid']] = array('posts' => 0, 'unapprovedposts' => 0, 'deletedposts' => 0); } if (!isset($user_counters[$post['uid']])) { $user_counters[$post['uid']] = array('postnum' => 0, 'threadnum' => 0); } if ($post['visible'] == 1) { // Modify users' post counts if ($post['threadvisible'] == 1 && $forum_cache[$post['fid']]['usepostcounts'] == 1 && ($forum_cache[$moveto]['usepostcounts'] == 0 || $newthread['visible'] != 1)) { // Moving into a forum that doesn't count post counts --$user_counters[$post['uid']]['postnum']; } // Subtract 1 from the old thread's replies --$thread_counters[$post['tid']]['replies']; } elseif ($post['visible'] == 0) { // Unapproved post // Subtract 1 from the old thread's unapproved posts --$thread_counters[$post['tid']]['unapprovedposts']; } elseif ($post['visible'] == -1) { // Soft deleted post // Subtract 1 from the old thread's deleted posts --$thread_counters[$post['tid']]['deletedposts']; } // Subtract 1 from the old forum's posts if ($post['threadvisible'] == 1 && $post['visible'] == 1) { --$forum_counters[$post['fid']]['posts']; } elseif ($post['threadvisible'] == 0 || $post['visible'] == 0 && $post['threadvisible'] == 1) { --$forum_counters[$post['fid']]['unapprovedposts']; } else { --$forum_counters[$post['fid']]['deletedposts']; } // Subtract attachment counts from old thread and add to new thread (which are counted regardless of post or attachment unapproval at time of coding) $thread_counters[$post['tid']]['attachmentcount'] -= $post['postattachmentcount']; $thread_counters[$newtid]['attachmentcount'] += $post['postattachmentcount']; if ($post['firstpost'] == $post['pid']) { // In some cases the first post of a thread changes // Therefore resync the visible field to make sure they're the same if they're not $query = $db->simple_select("posts", "pid, visible, uid", "tid='{$post['tid']}'", array('order_by' => 'dateline', 'order_dir' => 'asc', 'limit' => 1)); $new_firstpost = $db->fetch_array($query); if (!isset($user_counters[$new_firstpost['uid']])) { $user_counters[$new_firstpost['uid']] = array('postnum' => 0, 'threadnum' => 0); } // Update post counters if visibility changes if ($post['threadvisible'] != $new_firstpost['visible']) { $db->update_query("posts", array('visible' => $post['threadvisible']), "pid='{$new_firstpost['pid']}'"); // Subtract new first post if ($new_firstpost['visible'] == 1) { --$thread_counters[$post['tid']]['replies']; if ($post['threadvisible'] == 1 && $forum_cache[$post['fid']]['usepostcounts'] == 1) { --$user_counters[$new_firstpost['uid']]['postnum']; } } elseif ($new_firstpost['visible'] == -1) { --$thread_counters[$post['tid']]['deletedposts']; } else { --$thread_counters[$post['tid']]['unapprovedposts']; } if ($post['threadvisible'] == 0 || $new_firstpost['visible'] == 0 && $post['threadvisible'] == 1) { --$forum_counters[$post['fid']]['unapprovedposts']; } else { --$forum_counters[$post['fid']]['deletedposts']; } // Add old first post if ($post['threadvisible'] == 1) { ++$thread_counters[$post['tid']]['replies']; ++$forum_counters[$post['fid']]['posts']; if ($forum_cache[$post['fid']]['usepostcounts'] == 1) { ++$user_counters[$new_firstpost['uid']]['postnum']; } } elseif ($post['threadvisible'] == -1) { ++$thread_counters[$post['tid']]['deletedposts']; ++$forum_counters[$post['fid']]['deletedposts']; } else { ++$thread_counters[$post['tid']]['unapprovedposts']; ++$forum_counters[$post['fid']]['unapprovedposts']; } } // Update user thread counter if thread opener changes if ($post['threadvisible'] == 1 && $forum_cache[$post['fid']]['usethreadcounts'] == 1 && $post['uid'] != $new_firstpost['uid']) { // Subtract thread from old thread opener --$user_counters[$post['uid']]['threadnum']; // Add thread to new thread opener ++$user_counters[$new_firstpost['uid']]['threadnum']; } update_first_post($post['tid']); } // This is the new first post of an existing thread? if ($post['pid'] == $post_info['pid'] && $post['dateline'] < $newthread['dateline']) { // Update post counters if visibility changes if ($post['visible'] != $newthread['visible']) { $db->update_query("posts", array('visible' => $newthread['visible']), "pid='{$post['pid']}'"); // This is needed to update the forum counters correctly $post['visible'] = $newthread['visible']; } // Update user thread counter if thread opener changes if ($newthread['visible'] == 1 && $forum_cache[$newthread['fid']]['usethreadcounts'] == 1 && $post['uid'] != $newthread['uid']) { // Add thread to new thread opener ++$user_counters[$post['uid']]['threadnum']; if (!isset($user_counters[$newthread['uid']])) { $user_counters[$newthread['uid']] = array('postnum' => 0, 'threadnum' => 0); } // Subtract thread from old thread opener --$user_counters[$newthread['uid']]['threadnum']; } update_first_post($newtid); } if ($post['visible'] == 1) { // Modify users' post counts if ($newthread['visible'] == 1 && ($forum_cache[$post['fid']]['usepostcounts'] == 0 || $post['threadvisible'] != 1) && $forum_cache[$moveto]['usepostcounts'] == 1) { // Moving into a forum that does count post counts ++$user_counters[$post['uid']]['postnum']; } // Add 1 to the new thread's replies ++$thread_counters[$newtid]['replies']; } elseif ($post['visible'] == 0) { // Unapproved post // Add 1 to the new thread's unapproved posts ++$thread_counters[$newtid]['unapprovedposts']; } elseif ($post['visible'] == -1) { // Soft deleted post // Add 1 to the new thread's deleted posts ++$thread_counters[$newtid]['deletedposts']; } // Add 1 to the new forum's posts if ($newthread['visible'] == 1 && $post['visible'] == 1) { ++$forum_counters[$moveto]['posts']; } elseif ($newthread['visible'] == 0 || $post['visible'] == 0 && $newthread['visible'] == 1) { ++$forum_counters[$moveto]['unapprovedposts']; } else { ++$forum_counters[$moveto]['deletedposts']; } } if ($destination_tid == 0 && $newthread['visible'] == 1) { // If splitting into a new thread, subtract one from the thread's reply count to compensate for the original post --$thread_counters[$newtid]['replies']; } elseif ($destination_tid == 0 && $newthread['visible'] == 0) { // If splitting into a new thread, subtract one from the thread's reply count to compensate for the original post --$thread_counters[$newtid]['unapprovedposts']; } elseif ($destination_tid == 0 && $newthread['visible'] == -1) { // If splitting into a new thread, subtract one from the thread's reply count to compensate for the original post --$thread_counters[$newtid]['deletedposts']; } $arguments = array("pids" => $pids, "tid" => $tid, "moveto" => $moveto, "newsubject" => $newsubject, "destination_tid" => $destination_tid); $plugins->run_hooks("class_moderation_split_posts", $arguments); // Update user post counts if (!empty($user_counters)) { foreach ($user_counters as $uid => $counters) { foreach ($counters as $key => $counter) { if ($counter >= 0) { $counters[$key] = "+{$counter}"; // add the addition operator for query } } update_user_counters($uid, $counters); } } // Update thread counters if (is_array($thread_counters)) { foreach ($thread_counters as $tid => $counters) { if ($tid == $newtid) { // Update the subject of the first post in the new thread $query = $db->simple_select("posts", "pid", "tid='{$newtid}'", array('order_by' => 'dateline', 'limit' => 1)); $newthread = $db->fetch_array($query); $sqlarray = array("subject" => $newsubject, "replyto" => 0); $db->update_query("posts", $sqlarray, "pid='{$newthread['pid']}'"); } else { // Update the subject of the first post in the old thread $query = $db->query("\n\t\t\t\t\t\tSELECT p.pid, t.subject\n\t\t\t\t\t\tFROM " . TABLE_PREFIX . "posts p\n\t\t\t\t\t\tLEFT JOIN " . TABLE_PREFIX . "threads t ON (p.tid=t.tid)\n\t\t\t\t\t\tWHERE p.tid='{$tid}'\n\t\t\t\t\t\tORDER BY p.dateline ASC\n\t\t\t\t\t\tLIMIT 1\n\t\t\t\t\t"); $oldthread = $db->fetch_array($query); $sqlarray = array("subject" => $db->escape_string($oldthread['subject']), "replyto" => 0); $db->update_query("posts", $sqlarray, "pid='{$oldthread['pid']}'"); } foreach ($counters as $key => $counter) { if ($counter >= 0) { $counters[$key] = "+{$counter}"; } } update_thread_counters($tid, $counters); update_last_post($tid); } } // Update forum counters if (!empty($forum_counters)) { foreach ($forum_counters as $fid => $counters) { foreach ($counters as $key => $counter) { if ($counter >= 0) { $counters[$key] = "+{$counter}"; } } update_forum_counters($fid, $counters); update_forum_lastpost($fid); } } return $newtid; }
/** * Split posts into a new/existing thread * * @param array PIDs of posts to split * @param int Original thread ID (this is only used as a base for the new * thread; it can be set to 0 when the posts specified are coming from more * than 1 thread) * @param int Destination forum * @param string New thread subject * @param int TID if moving into existing thread * @return int New thread ID */ function split_posts($pids, $tid, $moveto, $newsubject, $destination_tid = 0) { global $db, $thread, $plugins; $tid = intval($tid); $moveto = intval($moveto); $newtid = intval($destination_tid); // Get forum infos $query = $db->simple_select("forums", "fid, usepostcounts, posts, threads, unapprovedposts, unapprovedthreads"); while ($forum = $db->fetch_array($query)) { $forum_cache[$forum['fid']] = $forum; } // Make sure we only have valid values $pids = array_map('intval', $pids); $pids_list = implode(',', $pids); // Get the icon for the first split post $query = $db->simple_select("posts", "icon, visible", "pid=" . intval($pids[0])); $post_info = $db->fetch_array($query); $icon = $post_info['icon']; $visible = $post_info['visible']; if ($destination_tid == 0) { // Splitting into a new thread $thread = get_thread($tid); // Create the new thread $newsubject = $db->escape_string($newsubject); $query = array("fid" => $moveto, "subject" => $newsubject, "icon" => intval($icon), "uid" => intval($thread['uid']), "username" => $db->escape_string($thread['username']), "dateline" => intval($thread['dateline']), "lastpost" => intval($thread['lastpost']), "lastposter" => $db->escape_string($thread['lastposter']), "replies" => count($pids) - 1, "visible" => intval($visible), "notes" => ''); $newtid = $db->insert_query("threads", $query); $forum_counters[$moveto]['threads'] = $forum_cache[$moveto]['threads']; $forum_counters[$moveto]['unapprovedthreads'] = $forum_cache[$moveto]['unapprovedthreads']; if ($visible) { ++$forum_counters[$moveto]['threads']; } else { // Unapproved thread? ++$forum_counters[$moveto]['unapprovedthreads']; } } // Get attachment counts for each post /*$query = $db->simple_select("attachments", "COUNT(aid) as count, pid", "pid IN ($pids_list)"); $query = $db->query(" SELECT COUNT(aid) as count, p.pid, "); $attachment_sum = 0; while($attachment = $db->fetch_array($query)) { $attachments[$attachment['pid']] = $attachment['count']; $attachment_sum += $attachment['count']; } $thread_counters[$newtid]['attachmentcount'] = '+'.$attachment_sum;*/ // Get selected posts before moving forums to keep old fid //$original_posts_query = $db->simple_select("posts", "fid, visible, pid", "pid IN ($pids_list)"); $original_posts_query = $db->query("\n\t\t\tSELECT p.pid, p.tid, p.fid, p.visible, p.uid, t.visible as threadvisible, t.replies as threadreplies, t.unapprovedposts as threadunapprovedposts, t.attachmentcount as threadattachmentcount, COUNT(a.aid) as postattachmentcount\n\t\t\tFROM " . TABLE_PREFIX . "posts p\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "threads t ON (p.tid=t.tid)\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "attachments a ON (a.pid=p.pid)\n\t\t\tWHERE p.pid IN ({$pids_list})\n\t\t\tGROUP BY p.pid, p.tid, p.fid, p.visible, p.uid, t.visible, t.replies, t.unapprovedposts,t.attachmentcount\n\t\t"); // Move the selected posts over $sqlarray = array("tid" => $newtid, "fid" => $moveto, "replyto" => 0); $db->update_query("posts", $sqlarray, "pid IN ({$pids_list})"); $db->update_query("reportedposts", array('tid' => $newtid), "pid IN ({$pids_list})"); // Get posts being merged while ($post = $db->fetch_array($original_posts_query)) { if ($post['visible'] == 1) { // Modify users' post counts if ($forum_cache[$post['fid']]['usepostcounts'] == 1 && $forum_cache[$moveto]['usepostcounts'] == 0) { // Moving into a forum that doesn't count post counts if (!isset($user_counters[$post['uid']])) { $user_counters[$post['uid']] = 0; } --$user_counters[$post['uid']]; } elseif ($forum_cache[$post['fid']]['usepostcounts'] == 0 && $forum_cache[$moveto]['usepostcounts'] == 1) { // Moving into a forum that does count post counts if (!isset($user_counters[$post['uid']])) { $user_counters[$post['uid']] = 0; } ++$user_counters[$post['uid']]; } // Subtract 1 from the old thread's replies if (!isset($thread_counters[$post['tid']]['replies'])) { $thread_counters[$post['tid']]['replies'] = $post['threadreplies']; } --$thread_counters[$post['tid']]['replies']; // Add 1 to the new thread's replies ++$thread_counters[$newtid]['replies']; if ($moveto != $post['fid']) { // Only need to change forum info if the old forum is different from new forum // Subtract 1 from the old forum's posts if (!isset($forum_counters[$post['fid']]['posts'])) { $forum_counters[$post['fid']]['posts'] = $forum_cache[$post['fid']]['posts']; } --$forum_counters[$post['fid']]['posts']; // Add 1 to the new forum's posts if (!isset($forum_counters[$moveto]['posts'])) { $forum_counters[$moveto]['posts'] = $forum_cache[$moveto]['posts']; } ++$forum_counters[$moveto]['posts']; } } elseif ($post['visible'] == 0) { // Unapproved post // Subtract 1 from the old thread's unapproved posts if (!isset($thread_counters[$post['tid']]['unapprovedposts'])) { $thread_counters[$post['tid']]['unapprovedposts'] = $post['threadunapprovedposts']; } --$thread_counters[$post['tid']]['unapprovedposts']; // Add 1 to the new thread's unapproved posts ++$thread_counters[$newtid]['unapprovedposts']; if ($moveto != $post['fid']) { // Only need to change forum info if the old forum is different from new forum // Subtract 1 from the old forum's unapproved posts if (!isset($forum_counters[$post['fid']]['unapprovedposts'])) { $forum_counters[$post['fid']]['unapprovedposts'] = $forum_cache[$post['fid']]['unapprovedposts']; } --$forum_counters[$post['fid']]['unapprovedposts']; // Add 1 to the new forum's unapproved posts if (!isset($forum_counters[$moveto]['unapprovedposts'])) { $forum_counters[$moveto]['unapprovedposts'] = $forum_cache[$moveto]['unapprovedposts']; } ++$forum_counters[$moveto]['unapprovedposts']; } } // Subtract attachment counts from old thread and add to new thread (which are counted regardless of post or attachment unapproval at time of coding) if (!isset($thread_counters[$post['tid']]['attachmentcount'])) { $thread_counters[$post['tid']]['attachmentcount'] = $post['threadattachmentcount']; } $thread_counters[$post['tid']]['attachmentcount'] -= $post['postattachmentcount']; $thread_counters[$newtid]['attachmentcount'] += $post['postattachmentcount']; } if ($destination_tid == 0 && $thread_counters[$newtid]['replies'] > 0) { // If splitting into a new thread, subtract one from the thread's reply count to compensate for the original post --$thread_counters[$newtid]['replies']; } $arguments = array("pids" => $pids, "tid" => $tid, "moveto" => $moveto, "newsubject" => $newsubject, "destination_tid" => $destination_tid); $plugins->run_hooks("class_moderation_split_posts", $arguments); // Update user post counts if (is_array($user_counters)) { foreach ($user_counters as $uid => $change) { if ($change >= 0) { $change = '+' . $change; // add the addition operator for query } $db->update_query("users", array("postnum" => "postnum{$change}"), "uid='{$uid}'", 1, true); } } // Update thread counters if (is_array($thread_counters)) { foreach ($thread_counters as $tid => $counters) { if ($tid == $newtid) { // Update the subject of the first post in the new thread $query = $db->simple_select("posts", "pid", "tid='{$newtid}'", array('order_by' => 'dateline', 'limit' => 1)); $newthread = $db->fetch_array($query); $sqlarray = array("subject" => $newsubject, "replyto" => 0); $db->update_query("posts", $sqlarray, "pid='{$newthread['pid']}'"); } else { // Update the subject of the first post in the old thread $query = $db->query("\n\t\t\t\t\t\tSELECT p.pid, t.subject\n\t\t\t\t\t\tFROM " . TABLE_PREFIX . "posts p\n\t\t\t\t\t\tLEFT JOIN " . TABLE_PREFIX . "threads t ON (p.tid=t.tid)\n\t\t\t\t\t\tWHERE p.tid='{$tid}'\n\t\t\t\t\t\tORDER BY p.dateline ASC\n\t\t\t\t\t\tLIMIT 1\n\t\t\t\t\t"); $oldthread = $db->fetch_array($query); $sqlarray = array("subject" => $db->escape_string($oldthread['subject']), "replyto" => 0); $db->update_query("posts", $sqlarray, "pid='{$oldthread['pid']}'"); } $db->update_query("threads", $counters, "tid='{$tid}'"); update_thread_data($tid); // Update first post columns update_first_post($tid); } } update_thread_data($newtid); update_first_post($newtid); // Update forum counters if (is_array($forum_counters)) { foreach ($forum_counters as $fid => $counters) { update_forum_counters($fid, $counters); } } return $newtid; }