if ($mybb->get_input('restore', MyBB::INPUT_INT) == 1) { $query = $db->simple_select("posts", "pid", "tid='{$tid}'", array("limit" => 1, "order_by" => "dateline", "order_dir" => "asc")); $firstcheck = $db->fetch_array($query); if ($firstcheck['pid'] == $pid) { $firstpost = 1; } else { $firstpost = 0; } $modlogdata['fid'] = $fid; $modlogdata['tid'] = $tid; $modlogdata['pid'] = $pid; if ($firstpost) { if (is_moderator($fid, "canrestorethreads")) { require_once MYBB_ROOT . "inc/class_moderation.php"; $moderation = new Moderation(); $moderation->restore_threads(array($tid)); log_moderator_action($modlogdata, $lang->thread_restored); if ($mybb->input['ajax'] == 1) { header("Content-type: application/json; charset={$lang->settings['charset']}"); echo json_encode(array("data" => '1')); } else { redirect(get_forum_link($fid), $lang->redirect_threadrestored); } } else { error_no_permission(); } } else { if (is_moderator($fid, "canrestoreposts")) { // Select the first post before this require_once MYBB_ROOT . "inc/class_moderation.php"; $moderation = new Moderation();
/** * MyBB 1.8 * Copyright 2014 MyBB Group, All Rights Reserved * * Website: http://www.mybb.com * License: http://www.mybb.com/about/license * */ function task_delayedmoderation($task) { global $db, $lang, $plugins; require_once MYBB_ROOT . "inc/class_moderation.php"; $moderation = new Moderation(); require_once MYBB_ROOT . "inc/class_custommoderation.php"; $custommod = new CustomModeration(); // Iterate through all our delayed moderation actions $query = $db->simple_select("delayedmoderation", "*", "delaydateline <= '" . TIME_NOW . "'"); while ($delayedmoderation = $db->fetch_array($query)) { if (is_object($plugins)) { $args = array('task' => &$task, 'delayedmoderation' => &$delayedmoderation); $plugins->run_hooks('task_delayedmoderation', $args); } $tids = explode(',', $delayedmoderation['tids']); $input = my_unserialize($delayedmoderation['inputs']); if (my_strpos($delayedmoderation['type'], "modtool") !== false) { list(, $custom_id) = explode('_', $delayedmoderation['type'], 2); $custommod->execute($custom_id, $tids); } else { switch ($delayedmoderation['type']) { case "openclosethread": $closed_tids = $open_tids = array(); $query2 = $db->simple_select("threads", "tid,closed", "tid IN({$delayedmoderation['tids']})"); while ($thread = $db->fetch_array($query2)) { if ($thread['closed'] == 1) { $closed_tids[] = $thread['tid']; } else { $open_tids[] = $thread['tid']; } } if (!empty($closed_tids)) { $moderation->open_threads($closed_tids); } if (!empty($open_tids)) { $moderation->close_threads($open_tids); } break; case "deletethread": foreach ($tids as $tid) { $moderation->delete_thread($tid); } break; case "move": foreach ($tids as $tid) { $moderation->move_thread($tid, $input['new_forum']); } break; case "stick": $unstuck_tids = $stuck_tids = array(); $query2 = $db->simple_select("threads", "tid,sticky", "tid IN({$delayedmoderation['tids']})"); while ($thread = $db->fetch_array($query2)) { if ($thread['sticky'] == 1) { $stuck_tids[] = $thread['tid']; } else { $unstuck_tids[] = $thread['tid']; } } if (!empty($stuck_tids)) { $moderation->unstick_threads($stuck_tids); } if (!empty($unstuck_tids)) { $moderation->stick_threads($unstuck_tids); } break; case "merge": // $delayedmoderation['tids'] should be a single tid if (count($tids) != 1) { continue; } // explode at # sign in a url (indicates a name reference) and reassign to the url $realurl = explode("#", $input['threadurl']); $input['threadurl'] = $realurl[0]; // Are we using an SEO URL? if (substr($input['threadurl'], -4) == "html") { // Get thread to merge's tid the SEO way preg_match("#thread-([0-9]+)?#i", $input['threadurl'], $threadmatch); preg_match("#post-([0-9]+)?#i", $input['threadurl'], $postmatch); if ($threadmatch[1]) { $parameters['tid'] = $threadmatch[1]; } if ($postmatch[1]) { $parameters['pid'] = $postmatch[1]; } } else { // Get thread to merge's tid the normal way $splitloc = explode(".php", $input['threadurl']); $temp = explode("&", my_substr($splitloc[1], 1)); if (!empty($temp)) { for ($i = 0; $i < count($temp); $i++) { $temp2 = explode("=", $temp[$i], 2); $parameters[$temp2[0]] = $temp2[1]; } } else { $temp2 = explode("=", $splitloc[1], 2); $parameters[$temp2[0]] = $temp2[1]; } } if ($parameters['pid'] && !$parameters['tid']) { $post = get_post($parameters['pid']); $mergetid = $post['tid']; } else { if ($parameters['tid']) { $mergetid = $parameters['tid']; } } $mergetid = (int) $mergetid; $mergethread = get_thread($mergetid); if (!$mergethread['tid']) { continue; } if ($mergetid == $delayedmoderation['tids']) { // sanity check continue; } if ($input['subject']) { $subject = $input['subject']; } else { $query = $db->simple_select("threads", "subject", "tid='{$delayedmoderation['tids']}'"); $subject = $db->fetch_field($query, "subject"); } $moderation->merge_threads($mergetid, $delayedmoderation['tids'], $subject); break; case "removeredirects": foreach ($tids as $tid) { $moderation->remove_redirects($tid); } break; case "removesubscriptions": $moderation->remove_thread_subscriptions($tids, true); break; case "approveunapprovethread": $approved_tids = $unapproved_tids = array(); $query2 = $db->simple_select("threads", "tid,visible", "tid IN({$delayedmoderation['tids']})"); while ($thread = $db->fetch_array($query2)) { if ($thread['visible'] == 1) { $approved_tids[] = $thread['tid']; } else { $unapproved_tids[] = $thread['tid']; } } if (!empty($approved_tids)) { $moderation->unapprove_threads($approved_tids); } if (!empty($unapproved_tids)) { $moderation->approve_threads($unapproved_tids); } break; case "softdeleterestorethread": $delete_tids = $restore_tids = array(); $query2 = $db->simple_select("threads", "tid,visible", "tid IN({$delayedmoderation['tids']})"); while ($thread = $db->fetch_array($query2)) { if ($thread['visible'] == -1) { $restore_tids[] = $thread['tid']; } else { $delete_tids[] = $thread['tid']; } } if (!empty($restore_tids)) { $moderation->restore_threads($restore_tids); } if (!empty($delete_tids)) { $moderation->soft_delete_threads($delete_tids); } break; } } $db->delete_query("delayedmoderation", "did='{$delayedmoderation['did']}'"); } add_task_log($task, $lang->task_delayedmoderation_ran); }
$moderation->unapprove_threads($tid); moderation_redirect(get_thread_link($thread['tid']), $lang->redirect_threadunapproved); break; // Restore a thread // Restore a thread case "restorethread": // Verify incoming POST request verify_post_check($mybb->get_input('my_post_key')); if (!is_moderator($fid, "canrestorethreads")) { error_no_permission(); } $thread = get_thread($tid); $plugins->run_hooks("moderation_restorethread"); $lang->thread_restored = $lang->sprintf($lang->thread_restored, $thread['subject']); log_moderator_action($modlogdata, $lang->thread_restored); $moderation->restore_threads($tid); moderation_redirect(get_thread_link($thread['tid']), $lang->redirect_threadrestored); break; // Soft delete a thread // Soft delete a thread case "softdeletethread": // Verify incoming POST request verify_post_check($mybb->get_input('my_post_key')); if (!is_moderator($fid, "cansoftdeletethreads")) { error_no_permission(); } $thread = get_thread($tid); $plugins->run_hooks("moderation_softdeletethread"); $lang->thread_soft_deleted = $lang->sprintf($lang->thread_soft_deleted, $thread['subject']); log_moderator_action($modlogdata, $lang->thread_soft_deleted); $moderation->soft_delete_threads($tid);