function undelete_post($postid, $countposts, $postinfo = NULL, $threadinfo = NULL, $counterupdate = true) { global $vbulletin, $vbphrase; // Valid postinfo array will contain: postid, threadid, visible, userid, username, title // Invalid post or post is not deleted if (!$postinfo AND !$postinfo = fetch_postinfo($postid)) { return; } // Valid threadinfo array will contain: threadid, forumid, visible, firstpostid if (!$threadinfo AND !$threadinfo = fetch_threadinfo($postinfo['threadid'])) { return; } if ($threadinfo['firstpostid'] == $postid) { // undelete thread undelete_thread($threadinfo['threadid'], $countposts, $threadinfo); return; } // Post is not deleted if ($postinfo['visible'] != 2) { return; } // Only increment post for a visible thread in a counting forum if ($countposts AND $postinfo['userid'] AND $threadinfo['visible'] == 1) { $userdata =& datamanager_init('User', $vbulletin, ERRTYPE_SILENT); $userdata->set_existing($postinfo); $userdata->set('posts', 'posts + 1', false); $userdata->set_ladder_usertitle_relative(1); $userdata->save(); unset($userdata); } $deletiondata =& datamanager_init('Deletionlog_ThreadPost', $vbulletin, ERRTYPE_SILENT, 'deletionlog'); $deletioninfo = array('type' => 'post', 'primaryid' => $postid); $deletiondata->set_existing($deletioninfo); $deletiondata->delete(); unset($deletiondata, $deletioninfo); $postman =& datamanager_init('Post', $vbulletin, ERRTYPE_SILENT, 'threadpost'); $postman->set_existing($postinfo); $postman->set('visible', 1); $postman->save(); if ($counterupdate) { build_thread_counters($postinfo['threadid']); build_forum_counters($threadinfo['forumid']); } fetch_phrase_group('threadmanage'); $postinfo['forumid'] = $threadinfo['forumid']; require_once(DIR . '/includes/functions_log_error.php'); log_moderator_action($postinfo, 'post_y_by_x_undeleted', array($postinfo['title'], $postinfo['username'])); }
/** * Gets the associated thread for commenting on this content. * * @return vB_Legacy_Thread */ protected function getAssociatedThread() { // Get the thread // Resolve the thread id if (intval(vB::$vbulletin->options['vbcmsforumid']) AND intval($this->content->getSetPublish()) AND intval($this->content->getComments_Enabled())) { $threadid = $this->content->getAssociatedThreadId(); if (!$threadid) { $threadid = $this->associateThread(); //If we failed here, there's something wrong. Probably the forum id is invalid. if (!$threadid) { return false; } } //Verify that the thread is active. $thread = vB_Legacy_Thread::create_from_id($threadid); if (!$thread) { //Try again $threadid = $this->associateThread(); //If we failed here, there's something wrong. Probably the forum id is invalid. if (!$threadid) { return false; } $thread = vB_Legacy_Thread::create_from_id($threadid); if (!$thread) { return false; } } //If we got here, we have a valid thread. if (! $thread->get_field('visible')) { require_once DIR . '/includes/functions_databuild.php'; undelete_thread($threadid); } } return $thread; }
if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canview']) or !($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewthreads']) or !($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewothers']) and $thread['postuserid'] != $vbulletin->userinfo['userid']) { print_no_permission(); } $thread['prefix_plain_html'] = $thread['prefixid'] ? htmlspecialchars_uni($vbphrase["prefix_{$thread['prefixid']}_title_plain"]) . ' ' : ''; if (!can_moderate($thread['forumid'], 'candeleteposts')) { eval(standard_error(fetch_error('you_do_not_have_permission_to_manage_deleted_threads_and_posts', $vbphrase['n_a'], $thread['prefix_plain_html'] . $thread['title'], $vbulletin->forumcache["{$thread['forumid']}"]['title']))); } $threadarray["{$thread['threadid']}"] = $thread; $forumlist["{$thread['forumid']}"] = true; } if (empty($threadarray)) { eval(standard_error(fetch_error('you_did_not_select_any_valid_threads'))); } foreach ($threadarray as $threadid => $thread) { $countposts = $vbulletin->forumcache["{$thread['forumid']}"]['options'] & $vbulletin->bf_misc_forumoptions['countposts']; undelete_thread($thread['threadid'], $countposts, $thread); } foreach (array_keys($forumlist) as $forumid) { build_forum_counters($forumid); } // empty cookie setcookie('vbulletin_inlinethread', '', TIMENOW - 3600, '/'); ($hook = vBulletinHook::fetch_hook('inlinemod_undeletethread')) ? eval($hook) : false; eval(print_standard_redirect('redirect_inline_undeleted', true, $forceredirect)); } // ############################### start do approve thread ############################### if ($_POST['do'] == 'approvethread') { $countingthreads = array(); $firstposts = array(); // Validate threads $threads = $db->query_read_slave("\n\t\tSELECT threadid, visible, forumid, postuserid, firstpostid\n\t\tFROM " . TABLE_PREFIX . "thread\n\t\tWHERE threadid IN({$threadids})\n\t\t\tAND visible = 0\n\t\t\tAND open <> 10\n\t");
/** * Performs additional queries or tasks after saving. * * @param mixed - The save result * @param bool $deferred - Save was deferred * @param bool $replace - Save used REPLACE * @param bool $ignore - Save used IGNORE if inserting * @return bool - Whether the save can be considered a success */ protected function postSave($result, $deferred, $replace, $ignore) { //First let's handle the configuration. if (isset($this->set_fields['config'])) { if ($this->isUpdating()) { $this->assertItem(); $id = $this->item->getNodeId(); } else { if (!$this->primary_id) { throw (new vB_Exception_DM('No primary id available for setting the node config in DM \'' . get_class($this) . '\'')); } $id = $this->primary_id; } // delete the old config vB::$db->query_write( 'DELETE FROM ' . TABLE_PREFIX . 'cms_nodeconfig WHERE nodeid = ' . $id); // build the sql $sql = 'INSERT INTO ' . TABLE_PREFIX . 'cms_nodeconfig (nodeid, name, value, serialized) VALUES '; $values = array(); // write the new config foreach ($this->set_fields['config'] AS $cvar => $value) { if (is_resource($value)) { throw (new vB_Exception_DM('Trying to set a resource as a node config value')); } if (is_object($value) OR is_array($value)) { $serialized = true; $value = serialize($value); } else { $serialized = false; } $values[] = '(' . $id . ', \'' . vB::$db->escape_string($cvar) . '\',\'' . vB::$db->escape_string($value) . '\',\'' . intval($serialized) . '\')'; } // insert config vB::$db->insert_multiple($sql, $values, true); } //and set permissionsfrom the parent. Let's do this so we fix any close records. $nodeid = (isset($this->set_fields['nodeid']) ? $this->set_fields['nodeid'] : $this->primary_id); $parents = array(); if (intval($this->set_fields['permissionsfrom'])) { $permissionsfrom = $this->set_fields['permissionsfrom']; } else { //we'll pull from our parent. $rst = vB::$vbulletin->db->query_read("SELECT parent.nodeid, parent.parentnode, parent.permissionsfrom, parent.nodeleft, parent.noderight FROM " . TABLE_PREFIX . "cms_node AS node INNER JOIN " . TABLE_PREFIX . "cms_node AS parent ON (node.nodeleft >= parent.nodeleft AND node.nodeleft <=parent.noderight) WHERE node.nodeid = $nodeid ORDER BY parent.nodeleft DESC"); while($record = vB::$vbulletin->db->fetch_array($rst)) { $parents[] = $record; if (intval($record['permissionsfrom'])) { $permissionsfrom = $record['permissionsfrom']; if (intval($record['permissionsfrom']) != intval($nodeid)) { break; } } } //either we found a parent with a permissionsfrom, or we hit the top- which is // just as good. vB::$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "cms_node SET permissionsfrom = " . $permissionsfrom . " WHERE nodeid = $nodeid" ) ; } foreach ($parents as $parent) { vB::$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "cms_node SET permissionsfrom = " . $permissionsfrom . " WHERE parentnode = " . $parent['nodeid'] . " AND IFNULL(permissionsfrom, 0) = 0") ; } if (isset($this->set_fields['navigation'])) { $nodeid = intval((isset($this->set_fields['nodeid']) ? $this->set_fields['nodeid'] : $this->item->getNodeId())); // if there is array for navigation menu, it means we are not inheriting from parent // so we must add/modify the record in the navigation table for this node if (is_array($this->set_fields['navigation'])) { vB::$vbulletin->db->query_write(" REPLACE INTO " . TABLE_PREFIX . "cms_navigation SET nodeid = $nodeid, nodelist = '" . implode(',', $this->set_fields['navigation']) . "' "); } // if this is not an array, it means the drop-down was selected to inherit from parent // so delete any record in the navigation table for this node else { vB::$vbulletin->db->query_write(" DELETE FROM " . TABLE_PREFIX . "cms_navigation WHERE nodeid = $nodeid "); } } if (isset($this->set_fields['setpublish']) OR isset($this->set_fields['navigation'])) { // clear the navbar cache vB_Cache::instance()->event(array(vBCms_NavBar::GLOBAL_CACHE_EVENT, vBCms_NavBar::getCacheEventId($this->item->getNodeId()), $this->item->getCacheEvents(), $this->item->getContentCacheEvent())); vB_Cache::instance()->cleanNow(); $nav_node = new vBCms_Item_Content($this->item->getNodeId(), vBCms_Item_Content::INFO_NAVIGATION); // reload the navbar for the page vBCms_NavBar::prepareNavBar($nav_node, true); unset($nav_node); } else if ($this->item) { vB_Cache::instance()->event(array($this->item->getCacheEvents(), $this->item->getContentCacheEvent())); } //Let's set the thread status, if there is one. //If we get called from dm/rate.php or somewhere like that, we skip this section if ($this->isUpdating() AND in_array('comments_enabled', $this->set_fields) AND isset($this->set_fields['comments_enabled'])) { $record = vB::$vbulletin->db->query_first("SELECT info.associatedthreadid, thread.forumid FROM " . TABLE_PREFIX . "cms_nodeinfo AS info INNER JOIN " . TABLE_PREFIX . "thread AS thread ON thread.threadid = info.associatedthreadid WHERE info.nodeid = ". $this->item->getNodeId() ); if ($record['associatedthreadid']) { require_once DIR . '/includes/functions_databuild.php'; $thread = vB_Legacy_Thread::create_from_id($record['associatedthreadid']); if ($thread) { if (intval($this->set_fields['comments_enabled'])) { //We need to ensure comments are enabled. $visible = $thread->get_field('visible'); if ( intval($visible) != 1) { undelete_thread($record['associatedthreadid']); } //If the title has been updated in the article, update the thread title. if (($thread->getField('title') != '') AND isset($this->set_fields['title']) AND ($thread->getField('title') != $this->set_fields['title'])) { $sql = "UPDATE " . TABLE_PREFIX . "thread SET title = '" . vB::$db->escape_string($this->set_fields['title']) . "' WHERE threadid = " . $record['associatedthreadid']; vB::$db->query_write($sql); } } else { //We need to hide the thread. $thread->soft_delete(new vB_Legacy_CurrentUser(), '', true); } } build_thread_counters($record['associatedthreadid']); build_forum_counters($record['forumid']); } } parent::postSave($result, $deferred, $replace, $ignore); //we should never return false if we got here. $result = (intval($result) ? $result : true); return $result; }
// check if there is a forum password and if so, ensure the user has it set verify_forum_password($foruminfo['forumid'], $foruminfo['password']); if ($vbulletin->GPC['title'] == '') { eval(standard_error(fetch_error('notitle'))); } if (!can_moderate($threadinfo['forumid'], 'canopenclose') and !$forumperms['canopenclose']) { $vbulletin->GPC['open'] = $threadinfo['open']; } if (!can_moderate($threadinfo['forumid'], 'canmanagethreads')) { $vbulletin->GPC['sticky'] = $threadinfo['sticky']; } if ($threadinfo['visible'] == 2) { // Editing a deleted thread if ($vbulletin->GPC['threadstatus'] == 1 and can_moderate($threadinfo['forumid'], 'candeleteposts')) { // undelete undelete_thread($threadinfo['threadid'], $foruminfo['countposts']); $threaddeleted = -1; } else { if ($vbulletin->GPC['threadstatus'] == 2 and can_moderate($threadinfo['forumid'], 'canremoveposts')) { // remove $threadman =& datamanager_init('Thread', $vbulletin, ERRTYPE_STANDARD, 'threadpost'); $threadman->set_existing($threadinfo); $threadman->delete($foruminfo['countposts'], true); unset($threadman); $threaddeleted = 1; } else { if ($vbulletin->GPC['reason'] != '') { $deletionman =& datamanager_init('Deletionlog_Threadpost', $vbulletin, ERRTYPE_STANDARD, 'deletionlog'); $deletioninfo = array('type' => 'thread', 'primaryid' => $threadinfo['threadid']); $deletionman->set_existing($deletioninfo); $deletionman->set('reason', $vbulletin->GPC['reason']);