topicadmin.php

来自「xm2sv1.0寻梦二手网 v1.0,一个经过我调试的PHP原代码,有机会大家多」· PHP 代码 · 共 387 行

PHP
387
字号
<?php

/*
	[DISCUZ!] topicadmin - moderator's administration
	This is NOT a freeware, use is subject to license terms

	Version: 2.0.0
	Author: Crossday (info@discuz.net)
	Copyright: Crossday Studio (www.crossday.com)
	Last Modified: 2002/12/6 17:00
*/

require './include/common.php';
require $discuz_root.'./include/post.php';
require $discuz_root.'./include/misc.php';

$discuz_action = 151;
$ismoderator = modcheck($discuz_user);

$tid = $tid ? $tid : $delete[0];
if($tid) {
	$query = $db->query("SELECT * FROM $table_threads WHERE tid='$tid'");
	$thread = $db->fetch_array($query);
	$thread['subject'] .= $action == 'delthread' ? ", etc." : NULL;
}

if($forum['type'] == 'forum') {
	$navigation = "&raquo; <a href=\"forumdisplay.php?fid=$fid\">$forum[name]</a> &raquo; <a href=\"viewthread.php?tid=$tid\">$thread[subject]</a> ";
	$navtitle = " - $forum[name] - $thread[subject]";
} else {
	$query = $db->query("SELECT name, fid FROM $table_forums WHERE fid='$forum[fup]'");
	$fup = $db->fetch_array($query);
	$navigation = "&raquo; <a href=\"forumdisplay.php?fid=$fup[fid]\">$fup[name]</a> &raquo; <a href=\"forumdisplay.php?fid=$fid\">$forum[name]</a> &raquo; <a href=\"viewthread.php?tid=$tid\">$thread[subject]</a> ";
	$navtitle = " - $fup[name] - $forum[name] - $thread[subject]";
}

if(!$discuz_user || !$discuz_pw || !$ismoderator) {
	showmessage('admin_nopermission');
}

$fupadd = $fup ? "OR (fid='$fup[fid]' && type<>'group')" : NULL;

if($action == 'delthread') {

	if(!is_array($delete) && !count($delete)) {
		showmessage('admin_delthread_invalid');
	} else {
		if(!$delthreadsubmit) {

			$deleteid = '';
			foreach($delete as $id) {
				$deleteid .= "<input type=\"hidden\" name=\"delete[]\" value=\"$id\">\n";
			}

			include template('topicadmin_delthread');
				
		} else {

			$tids = $comma = '';
			foreach($delete as $id) {
				$tids .= "$comma'$id'";
				$comma = ", ";
			}

			$usernames = $comma = '';
			$query = $db->query("SELECT author FROM $table_posts WHERE tid IN ($tids)");
			while($result = $db->fetch_array($query)) {
				$author = addslashes($result[author]);
				$usernames .= "$comma$author";
				$comma = ",";
			}
			updatemember('-', $usernames);

			$query = $db->query("SELECT attachment FROM $table_attachments WHERE tid IN ($tids)");
			while($attach = $db->fetch_array($query)) {
				@unlink("$attachdir/$attach[attachment]");
			}

			$db->query("DELETE FROM $table_threads WHERE tid IN ($tids) OR closed='moved|$tid'");
			$db->query("DELETE FROM $table_posts WHERE tid IN ($tids)");
			$db->query("DELETE FROM $table_attachments WHERE tid IN ($tids)");
			updateforumcount($fid);

			showmessage('admin_succeed', "forumdisplay.php?fid=$fid&page=$page");

		}
	}		

} elseif($action == 'delpost') {

	if(!is_array($delete) && !count($delete)) {
		showmessage('admin_delpost_invalid');
	} else {
		if(!$delpostsubmit) {

			$query = $db->query("SELECT COUNT(*) FROM $table_posts WHERE tid='$tid'");
			if(count($delete) < $db->result($query, 0)) {

				$deleteid = '';
				foreach($delete as $id) {
					$deleteid .= "<input type=\"hidden\" name=\"delete[]\" value=\"$id\">\n";
				}

				include template('topicadmin_delpost');
				
			} else {
				header("Location: {$boardurl}topicadmin.php?action=delete&fid=$fid&tid=$tid");
			}

		} else {

			$pids = $comma = '';
			foreach($delete as $id) {
				$pids .= "$comma'$id'";
				$comma = ", ";
			}

			$usernames = $comma = '';
			$query = $db->query("SELECT author FROM $table_posts WHERE pid IN ($pids)");
			while($result = $db->fetch_array($query)) {
				$author = addslashes($result[author]);
				$usernames .= "$comma$author";
				$comma = ",";
			}
			updatemember('-', $usernames);

			$attach_type = '';
			$query = $db->query("SELECT pid, attachment, filetype FROM $table_attachments WHERE tid='$tid'");
			while($attach = $db->fetch_array($query)) {
				if(in_array($attach[pid], $delete)) {
					@unlink("$attachdir/$attach[attachment]");
				} else {
					$attach_type = substr(strrchr($attach[attachment], "."), 1)."\t".$attach[filetype];
				}
			}

			if($attach_type) {
				$db->query("UPDATE $table_threads SET attachment='$attach_type' WHERE tid='$tid'");
			}

			$db->query("DELETE FROM $table_posts WHERE pid IN ($pids)");
			$db->query("DELETE FROM $table_attachments WHERE pid IN ($pids)");
			updatethreadcount($tid);
			updateforumcount($fid);

			showmessage('admin_succeed', "forumdisplay.php?fid=$fid&page=$page");

		}
	}

} elseif($action == 'digest') {

	if(!$digestsubmit) {

		include template('topicadmin_digest');

	} else {

		$db->query("UPDATE $table_threads SET digest='$level' WHERE tid='$tid'");
		if($digestcredits) {
			$db->query("UPDATE $table_members SET credit=credit".($level == 0 ? "-" : "+")."($digestcredits) WHERE username='$thread[author]'");
		}
		showmessage('admin_succeed', "forumdisplay.php?fid=$fid");

	}

} elseif($action == 'delete') {

	if(!$deletesubmit) {

		include template('topicadmin_delete');

	} else {

		$usernames = $comma = '';
		$query = $db->query("SELECT author FROM $table_posts WHERE tid='$tid'");
		while($result = $db->fetch_array($query)) {
			$author = addslashes($result[author]);
			$usernames .= "$comma$author";
			$comma = ",";
		}
		updatemember('-', $usernames);

		$db->query("DELETE FROM $table_threads WHERE tid='$tid' OR closed='moved|$tid'");
		$db->query("DELETE FROM $table_posts WHERE tid='$tid'");
		$query = $db->query("SELECT attachment FROM $table_attachments WHERE tid='$tid'");
		while($thread_attachment = $db->fetch_array($query)) {
			@unlink("$attachdir/$thread_attachment[attachment]");
		}
		$db->query("DELETE FROM $table_attachments WHERE tid='$tid'");
		updateforumcount($fid);
		if ($forum[type] == "sub") {
			updateforumcount($fup[fid]);
		}

		showmessage('admin_succeed', "forumdisplay.php?fid=$fid");

	}

} elseif($action == 'close') {

	if(!$closesubmit) {

		include template('topicadmin_openclose');

	} else {
		$openclose = $thread[closed] ? 0 : 1;
		$db->query("UPDATE $table_threads SET closed='$openclose' WHERE tid='$tid' AND fid='$fid'");
		showmessage('admin_succeed', "forumdisplay.php?fid=$fid");
	}

} elseif($action == 'move') {

	if(!$movesubmit) {

		require $discuz_root.'./include/forum.php';

		$forumselect = forumselect();
		include template('topicadmin_move');

	} else {

		if(!$moveto) {
			showmessage('admin_move_invalid');
		}

		if($type == 'normal') {
			$db->query("UPDATE $table_threads SET fid='$moveto' WHERE tid='$tid' AND fid='$fid'");
			$db->query("UPDATE $table_posts SET fid='$moveto' WHERE tid='$tid' AND fid='$fid'");
		} else {
			$db->query("INSERT INTO $table_threads (tid, fid, creditsrequire, icon, author, subject, dateline, lastpost, lastposter, views, replies, topped, digest, closed, pollopts, attachment)
				VALUES ('', '$thread[fid]', '$thread[creditsrequire]', '$thread[icon]', '$thread[author]', '$thread[subject]', '$thread[dateline]', '$thread[lastpost]', '$thread[lastposter]', '-', '-', '$thread[topped]', '$thread[digest]', 'moved|$thread[tid]', '', '')");

			$db->query("UPDATE $table_threads SET fid='$moveto' WHERE tid='$tid' AND fid='$fid'");
			$db->query("UPDATE $table_posts SET fid='$moveto' WHERE tid='$tid' AND fid='$fid'");
		}

		if ($forum['type'] == 'sub') {
			$query= $db->query("SELECT fup FROM $table_forums WHERE fid='$fid' LIMIT 1");
			$fup = $db->result($query, 0);
			updateforumcount($fup);
		}

		updateforumcount($moveto);
		updateforumcount($fid);
		showmessage('admin_succeed', "forumdisplay.php?fid=$fid");
	}

} elseif($action == 'top') {

	if(!$topsubmit) {

		include template('topicadmin_topuntop');

	} else {

		if(!$issupermod && $level >= 3) {
			showmessage('undefined_action');
		}
		$db->query("UPDATE $table_threads SET topped='$level' WHERE tid='$tid' AND fid='$fid'");
		showmessage('admin_succeed', "forumdisplay.php?fid=$fid");

	}

} elseif($action == 'getip') {

	$query = $db->query("SELECT useip FROM $table_posts WHERE pid='$pid' AND tid='$tid'");
	$useip = $db->result($query, 0);
	$iplocation = convertip($useip);

	include template('topicadmin_getip');

} elseif($action == 'bump') {

	if(!$bumpsubmit) {

		include template('topicadmin_bump');

	} else {

		$query = $db->query("SELECT subject, lastposter, lastpost FROM $table_threads WHERE tid='$tid' LIMIT 0, 1");
		$thread = $db->fetch_array($query);
		$thread[lastposter] = addslashes($thread[lastposter]);
		$db->query("UPDATE $table_threads SET lastpost='$timestamp' WHERE tid='$tid' AND fid='$fid'");
		$db->query("UPDATE $table_forums SET lastpost='$thread[subject]\t$timestamp\t$thread[lastposter]' WHERE fid='$fid' $fupadd");

		showmessage('admin_succeed', "forumdisplay.php?fid=$fid");

	}

} elseif($action == 'split') {

	if(!$splitsubmit) {

		require $discuz_root.'./include/discuzcode.php';

		$replies = $thread['replies'];
		if($replies <= 0) {
			showmessage('admin_split_invalid');
		}

		$postlist = array();
		$query = $db->query("SELECT * FROM $table_posts WHERE tid='$tid' ORDER BY dateline");
		while($post = $db->fetch_array($query)) {
			$post['message'] = postify($post['message'], $post['smileyoff'], $post['bbcodeoff']);
			$postlist[] = $post;
		}

		include template('topicadmin_split');

	} else {

		if(!trim($subject)) {
			showmessage('admin_split_subject_invalid');
		}

		$query = $db->query("SELECT author, dateline FROM $table_posts WHERE tid='$tid' ORDER BY dateline LIMIT 0,1");
		$fpost = $db->fetch_array($query);
		$query = $db->query("SELECT author, dateline FROM $table_posts WHERE tid='$tid' ORDER BY dateline DESC LIMIT 0, 1");
		$lpost = $db->fetch_array($query);
		$db->query("INSERT INTO $table_threads (fid, subject, author, dateline, lastpost, lastposter)
			VALUES ('$fid', '$subject', '".addslashes($fpost['author'])."', '$fpost[dateline]', '$lpost[dateline]', '".addslashes($lpost['author'])."')");
		$newtid = $db->insert_id();

		$pids = $or = '';
		$query = $db->query("SELECT pid FROM $table_posts WHERE tid='$tid'");
		while($post = $db->fetch_array($query)) {
			$split = "split$post[pid]";
			$split = "${$split}";
			if($split) {
				$pids .= " $or pid='$split'";
				$or = "OR";
			}
		}
		if($pids) {
			$db->query("UPDATE $table_posts SET tid='$newtid' WHERE $pids");
			$db->query("UPDATE $table_attachments SET tid='$newtid' WHERE $pids");
			updatethreadcount($tid);
			updatethreadcount($newtid);
			updateforumcount($fid);
			showmessage('admin_succeed', "forumdisplay.php?fid=$fid");
		} else {
			showmessage('admin_split_new_invalid');
		}
	}

} elseif($action == 'merge') {

	if(!$mergesubmit) {

		include template('topicadmin_merge');

	} else {
		$query = $db->query("SELECT fid, views, replies FROM $table_threads WHERE tid='$othertid'");
		$other = $db->fetch_array($query);
		$other['views'] = intval($other['views']);
		$other['replies']++;

		$db->query("UPDATE $table_posts SET tid='$tid' WHERE tid='$othertid'");
		$postsmerged = $db->affected_rows();

		$db->query("UPDATE $table_attachments SET tid='$tid' WHERE tid='$othertid'");
		$db->query("DELETE FROM $table_threads WHERE tid='$othertid' OR closed='moved|$othertid'");
		$db->query("UPDATE $table_threads SET views=views+$other[views], replies=replies+$other[replies] WHERE tid='$tid'");
		
		if($fid == $other['fid']) {
			$db->query("UPDATE $table_forums SET threads=threads-1 WHERE fid='$fid' $fupadd");
		} else {
			$db->query("UPDATE $table_forums SET threads=threads-1, posts=posts-$postsmerged WHERE fid='$other[fid]'");
			$db->query("UPDATE $table_forums SET posts=$posts+$postsmerged WHERE fid='$fid' $fupadd");
		}

		showmessage('admin_succeed', "forumdisplay.php?fid=$fid");
	}

} else {

	showmessage('undefined_action');

}

@$fp = fopen($discuz_root.'./forumdata/modslog.php', 'a');
@flock($fp, 3);
@fwrite($fp, "$discuz_user\t$status\t$onlineip\t$timestamp\t$fid\t$forum[name]\t$tid\t$thread[subject]\t$action\n");
@fclose($fp);

?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?