/**
  * Post save function run on each record. Applies only if there was a post submitted.
  */
 function post_save_each_post($doquery = true)
 {
     $postid = intval($this->fetch_field($this->table == 'post' ? 'postid' : 'firstpostid'));
     if (!$this->info['user'] and $this->registry->userinfo['userid'] and $this->fetch_field('userid', 'post') == $this->registry->userinfo['userid']) {
         $this->set_info('user', $this->registry->userinfo);
     }
     if ($this->info['posthash'] and $this->fetch_field('attach') and $postid) {
         $this->dbobject->query_write("\n\t\t\t\tUPDATE " . TABLE_PREFIX . "attachment SET\n\t\t\t\t\tpostid = {$postid},\n\t\t\t\t\tposthash = ''\n\t\t\t\tWHERE posthash = '" . $this->dbobject->escape_string($this->info['posthash']) . "'\n\t\t\t\t\tAND userid = " . intval($this->fetch_field('userid', 'post')) . "\n\t\t\t");
     }
     if ($this->condition and $postid) {
         if ($this->post['pagetext']) {
             if ($this->fetch_field('userid', 'post') != $this->registry->userinfo['userid']) {
                 // if another user edits the post then the postlog information is no longer valid.
                 $this->dbobject->query_write("DELETE FROM " . TABLE_PREFIX . "postlog WHERE postid = " . intval($postid));
             }
             $this->dbobject->query_write("DELETE FROM " . TABLE_PREFIX . "postparsed WHERE postid = " . intval($postid));
             if ($this->info['forum']) {
                 require_once DIR . '/includes/functions_databuild.php';
                 delete_post_index($postid, $this->existing['title'], $this->existing['pagetext']);
             }
         }
         // Check to see if this was a spam post being approved
         if ($this->existing['visible'] == 0 and $this->fetch_field('visible') == 1) {
             $this->akismet_mark_as_ham($postid);
         }
     }
     if ($this->post['pagetext'] and $this->info['forum'] and $postid) {
         // ### UPDATE SEARCH INDEX ###
         require_once DIR . '/includes/functions_databuild.php';
         build_post_index($postid, $this->info['forum']);
     }
     if ($this->spamlog_insert and $postid) {
         $this->dbobject->query_write("INSERT INTO " . TABLE_PREFIX . "spamlog (postid) VALUES ({$postid})");
     }
     if (!$this->condition and $this->fetch_field('visible') == 1) {
         if ($this->info['forum'] and $this->fetch_field('dateline') == TIMENOW) {
             $forumdata =& datamanager_init('Forum', $this->registry, ERRTYPE_SILENT);
             $forumdata->set_existing($this->info['forum']);
             $forumdata->set_info('disable_cache_rebuild', true);
             if (in_coventry($this->fetch_field('userid', 'post'), true)) {
                 $forumdata->set_info('coventry', array('in_coventry' => 1, 'userid' => $this->fetch_field('userid', 'post')));
             }
             if ($this->table == 'thread') {
                 // we're inserting a new thread
                 $forumdata->set('threadcount', 'threadcount + 1', false);
             }
             $forumdata->set('replycount', 'replycount + 1', false);
             $forumdata->set('lastpost', $this->fetch_field('dateline'));
             $forumdata->set('lastpostid', $postid);
             $forumdata->set('lastposter', $this->fetch_field('username', 'post'));
             if ($this->table == 'thread') {
                 $forumdata->set('lastthread', $this->fetch_field('title'));
                 $forumdata->set('lastthreadid', $this->fetch_field('threadid'));
                 $forumdata->set('lasticonid', $this->fetch_field('pollid') ? -1 : $this->fetch_field('iconid'));
                 $forumdata->set('lastprefixid', $this->fetch_field('prefixid'));
             } else {
                 if ($this->info['thread']) {
                     $forumdata->set('lastthread', $this->info['thread']['title']);
                     $forumdata->set('lastthreadid', $this->info['thread']['threadid']);
                     $forumdata->set('lasticonid', $this->info['thread']['pollid'] ? -1 : $this->info['thread']['iconid']);
                     $forumdata->set('lastprefixid', $this->info['thread']['prefixid']);
                 }
             }
             $forumdata->save();
         }
         if ($this->info['user'] and (empty($this->info['is_automated']) or $this->info['is_automated'] == 'rss')) {
             $user =& datamanager_init('User', $this->registry, ERRTYPE_SILENT);
             $user->set_existing($this->info['user']);
             if ($this->info['forum']['countposts']) {
                 $user->set('posts', 'posts + 1', false);
                 $user->set_ladder_usertitle($this->info['user']['posts'] + 1);
             }
             $dateline = $this->fetch_field('dateline');
             if ($dateline == TIMENOW or isset($this->info['user']['lastpost']) and $dateline > $this->info['user']['lastpost']) {
                 $user->set('lastpost', $dateline);
             }
             $postid = intval($this->fetch_field('postid'));
             if ($dateline == TIMENOW or isset($this->info['user']['lastpostid']) and $postid > $this->info['user']['postid']) {
                 $user->set('lastpostid', $postid);
             }
             $user->save();
         }
     }
 }
Exemplo n.º 2
0
function delete_post($postid, $countposts = true, $threadid = 0, $physicaldel = true, $delinfo = NULL, $dolog = true)
{
	global $vbulletin, $vbphrase, $threadinfo;

	$postid = intval($postid);
	$threadid = intval($threadid);

	if (!is_array($delinfo))
	{
		$delinfo = array(
			'userid'          => $vbulletin->userinfo['userid'],
			'username'        => $vbulletin->userinfo['username'],
			'reason'          => '',
			'keepattachments' => false
		);
	}
	else
	{
		if (!$delinfo['userid'])
		{
			$delinfo['userid'] = $vbulletin->userinfo['userid'];
		}
		if (!$delinfo['username'])
		{
			$delinfo['username'] = $vbulletin->userinfo['username'];
		}
	}

	if ($postinfo = fetch_postinfo($postid))
	{
		$threadinfo = fetch_threadinfo($postinfo['threadid']);

		if (!$physicaldel AND $postinfo['visible'] == 2)
		{	// post is already soft deleted
			return;
		}

		if ($threadinfo['firstpostid'] == $postid)
		{
			if (!$physicaldel AND $threadinfo['visible'] == 2)
			{	// thread is already soft deleted
				return;
			}

			// delete thread
			$threadman =& datamanager_init('Thread', $vbulletin, ERRTYPE_SILENT, 'threadpost');
			$threadman->set_existing($threadinfo);
			$threadman->delete($countposts, $physicaldel, $delinfo);
			unset($threadman);
			return;
		}

		if (can_moderate() AND $dolog)
		{
			fetch_phrase_group('threadmanage');

			if (!$physicaldel)
			{
				$type = 'post_x_by_y_softdeleted';
			}
			else
			{
				$type = 'post_x_by_y_removed';
			}

			$postinfo['forumid'] = $threadinfo['forumid'];
			require_once(DIR . '/includes/functions_log_error.php');
			log_moderator_action($postinfo, $type, array($postinfo['title'], $postinfo['username']));
		}

		if ($countposts AND $postinfo['visible'] == 1 AND $threadinfo['visible'] == 1 AND $postinfo['userid'])
		{	// deleted posts have already been decremented and hidden posts were never incremented (as of 3.5 at least)
			// init user data manager
			$userdata =& datamanager_init('User', $vbulletin, ERRTYPE_SILENT);
			$userdata->set_existing($postinfo);
			$userdata->set('posts', 'IF(posts > 1, posts - 1, 0)', false);
			$userdata->set_ladder_usertitle_relative(-1);
			$userdata->save();
			unset($userdata);
		}

		if ($postinfo['attach'])
		{
			if ($physicaldel OR (!$delinfo['keepattachments'] AND can_moderate($threadinfo['forumid'], 'canremoveposts')))
			{
				require_once(DIR . '/includes/class_bootstrap_framework.php');
				require_once(DIR . '/vb/types.php');
				vB_Bootstrap_Framework::init();
				$types = vB_Types::instance();
				$contenttypeid = intval($types->getContentTypeID('vBForum_Post'));

				$attachdata =& datamanager_init('Attachment', $vbulletin, ERRTYPE_SILENT, 'attachment');
				$attachdata->condition = "a.contentid = " . intval($postinfo['postid']) . " AND a.contenttypeid = " . intval($contenttypeid);
				$attachdata->delete(true, false);
			}
		}

		if (!$physicaldel)
		{
			$deletionman =& datamanager_init('Deletionlog_ThreadPost', $vbulletin, ERRTYPE_SILENT, 'deletionlog');
			$deletionman->set('primaryid', $postinfo['postid']);
			$deletionman->set('type', 'post');
			$deletionman->set('userid', $delinfo['userid']);
			$deletionman->set('username', $delinfo['username']);
			$deletionman->set('reason', $delinfo['reason']);
			$deletionman->save();
			unset($deletionman);

			$postman =& datamanager_init('Post', $vbulletin, ERRTYPE_SILENT, 'threadpost');
			$postman->set_existing($postinfo);
			$postman->set('visible', 2);
			$postman->save();
			unset($postman);

			if (!$postinfo['visible'])
			{ // only posts that are already moderated need tidied up
				$vbulletin->db->query_write("DELETE FROM " . TABLE_PREFIX . "moderation WHERE primaryid = $postinfo[postid] AND type = 'reply'");
				$vbulletin->db->query_write("DELETE FROM " . TABLE_PREFIX . "spamlog WHERE postid = $postinfo[postid]");
			}

			return;
		}

		// Sending the cookie below in rapid fire fashion for 300 posts deleted via inline mod seems to blowup IE but we don't need to set this cookie when using inlinemod
		if (THIS_SCRIPT != 'inlinemod')
		{
			// Delete any postid entries from the inline moderation cookie
			$vbulletin->input->clean_array_gpc('c', array(
				'vbulletin_inlinepost' => TYPE_STR,
			));

			if (!empty($vbulletin->GPC['vbulletin_inlinepost']) AND !headers_sent())
			{
				$newcookie = array();
				$found = false;
				$temp = explode('-', $vbulletin->GPC['vbulletin_inlinepost']);
				foreach($temp AS $inlinepostid)
				{
					if ($inlinepostid == $postid)
					{
						$found = true;
					}
					else
					{
						$newcookie[] = $inlinepostid;
					}
				}

				// this post is in the inline post cookie so delete it by rewriting cookie without it
				if ($found)
				{
					setcookie('vbulletin_inlinepost', implode('-', $newcookie), TIMENOW + 3600, '/');
				}
			}
		}

		// delete post hash when physically deleting a post - last argument is type
		$dupehash = md5($threadinfo['forumid'] . $postinfo['title'] . $postinfo['pagetext'] . $postinfo['userid'] . 'reply');

		$vbulletin->db->query_write("
			DELETE FROM " . TABLE_PREFIX . "posthash
			WHERE userid = $postinfo[userid] AND
			dupehash = '" . $vbulletin->db->escape_string($dupehash) . "' AND
			dateline > " . (TIMENOW - 300)
		);

		// Hook this post's children up to it's parent so they aren't orphaned. Foster parents I guess.
		if ($postinfo['parentid'] == 0)
		{
			if ($firstchild = $vbulletin->db->query_first("
				SELECT *
				FROM " . TABLE_PREFIX . "post
				WHERE threadid = $postinfo[threadid] AND
				parentid = $postid
				ORDER BY dateline, postid
				LIMIT 1
			"))
			{
				$postman =& datamanager_init('Post', $vbulletin, ERRTYPE_SILENT, 'threadpost');
				$postman->set_existing($firstchild);
				$postman->set('parentid', 0);
				$postman->save();
				unset($postman);

				$postinfo['parentid'] = $firstchild['postid'];
			}
		}

		$vbulletin->db->query_write("
			UPDATE " . TABLE_PREFIX . "post SET
				parentid = " . intval($postinfo['parentid']) . "
			WHERE threadid = $postinfo[threadid]
				AND parentid = $postid
		");

		$deletiondata =& datamanager_init('Deletionlog_ThreadPost', $vbulletin, ERRTYPE_SILENT, 'deletionlog');
		$deletioninfo = array('type' => 'post', 'primaryid' => $postid);
		$deletiondata->set_existing($deletioninfo);
		$deletiondata->delete();
		unset($deletiondata, $deletioninfo);


		delete_post_index($postid);
		$vbulletin->db->query_write("DELETE FROM " . TABLE_PREFIX . "post WHERE postid = $postid");
		$vbulletin->db->query_write("DELETE FROM " . TABLE_PREFIX . "postparsed WHERE postid = $postid");
		$vbulletin->db->query_write("DELETE FROM " . TABLE_PREFIX . "editlog WHERE postid = $postid");
		$vbulletin->db->query_write("DELETE FROM " . TABLE_PREFIX . "postedithistory WHERE postid = $postid");
		//$vbulletin->db->query_write("DELETE FROM " . TABLE_PREFIX . "reputation WHERE postid = $postid");
		$vbulletin->db->query_write("DELETE FROM " . TABLE_PREFIX . "moderation WHERE primaryid = $postid AND type = 'reply'");
		$vbulletin->db->query_write("DELETE FROM " . TABLE_PREFIX . "spamlog WHERE postid = $postid");
	}
}
Exemplo n.º 3
0
			$threaddata->set('similar', implode(',', $similarthreads));
		}

		$getfirstpost = $db->query_first("
			SELECT post.*
			FROM " . TABLE_PREFIX . "post AS post
			WHERE threadid = $threadinfo[threadid]
			ORDER BY dateline
			LIMIT 1
		");

		if ($threaddata->save())
		{
			// Reindex first post to set up title properly.
			require_once(DIR . '/includes/functions_databuild.php');
			delete_post_index($getfirstpost['postid'], $getfirstpost['title'], $getfirstpost['pagetext']);
			$getfirstpost['threadtitle'] = $threaddata->fetch_field('title');
			$getfirstpost['title'] =& $getfirstpost['threadtitle'];
			build_post_index($getfirstpost['postid'] , $foruminfo, 1, $getfirstpost);

			cache_ordered_forums(1);

			if ($vbulletin->forumcache["$threadinfo[forumid]"]['lastthreadid'] == $threadinfo['threadid'])
			{
				require_once(DIR . '/includes/functions_databuild.php');
				build_forum_counters($threadinfo['forumid']);
			}

			// we do not appear to log thread title updates
			$xml = new vB_AJAX_XML_Builder($vbulletin, 'text/xml');
			$xml->add_group('foo');
Exemplo n.º 4
0
        $merge_thread->set('open', 10);
        $merge_thread->set('pollid', $threadinfo['threadid']);
        $merge_thread->set('visible', 1);
        $merge_thread->set('dateline', TIMENOW);
        $merge_thread->save();
        if ($vbulletin->GPC['redirect'] == 'expires') {
            $db->query_write("\n\t\t\t\tINSERT INTO " . TABLE_PREFIX . "threadredirect\n\t\t\t\t\t(threadid, expires)\n\t\t\t\tVALUES\n\t\t\t\t\t({$mergethreadinfo['threadid']}, {$expires})\n\t\t\t");
        }
    } else {
        // remove remnants of merge thread
        $merge_thread->delete(false, true, NULL, false);
    }
    unset($merge_thread);
    // update postindex for the 2 posts who's titles may have changed (first post of each thread)
    delete_post_index($thrd_firstpost['postid']);
    delete_post_index($mrgthrd_firstpost['postid']);
    build_post_index($thrd_firstpost['postid'], $foruminfo);
    build_post_index($mrgthrd_firstpost['postid'], $foruminfo);
    build_thread_counters($threadinfo['threadid']);
    build_forum_counters($threadinfo['forumid']);
    if ($mergethreadinfo['forumid'] != $threadinfo['forumid']) {
        build_forum_counters($mergethreadinfo['forumid']);
    }
    log_moderator_action($threadinfo, 'thread_merged_with_x', $mergethreadinfo['title']);
    ($hook = vBulletinHook::fetch_hook('threadmanage_merge_complete')) ? eval($hook) : false;
    $vbulletin->url = 'showthread.php?' . $vbulletin->session->vars['sessionurl'] . "t={$threadinfo['threadid']}";
    eval(print_standard_redirect('redirect_mergethread'));
}
// ############################### start stick / unstick thread ###############################
if ($_POST['do'] == 'stick') {
    if ($threadinfo['isdeleted'] and !can_moderate($threadinfo['forumid'], 'candeleteposts') or !$threadinfo['visible'] and !can_moderate($threadinfo['forumid'], 'canmoderateposts')) {