topicadmin.php

来自「速度很快的PHP论坛源程序」· PHP 代码 · 共 528 行 · 第 1/2 页

PHP
528
字号
<?php

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

	Version: 4.0.0
	Web: http://www.comsenz.com
	Copyright: 2001-2005 Comsenz Technology Ltd.
	Last Modified: 2004/12/18 09:12
*/


require_once './include/common.inc.php';
require_once DISCUZ_ROOT.'./include/post.func.php';
require_once DISCUZ_ROOT.'./include/misc.func.php';

$discuz_action = 201;
$resultarray = array();

if(!$discuz_uid || !$forum['ismoderator']) {
	showmessage('admin_nopermission', NULL, 'HALTED');
}

if($forum['type'] == 'forum') {
	$navigation = "&raquo; <a href=\"forumdisplay.php?fid=$fid\">$forum[name]</a>";
	$navtitle = ' - '.strip_tags($forum['name']);
} else {
	$query = $db->query("SELECT fid, name FROM {$tablepre}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> ";
	$navtitle = ' - '.strip_tags($fup['name']).' - '.strip_tags($forum['name']);
}

if($tid) {
	$query = $db->query("SELECT * FROM {$tablepre}threads WHERE tid='$tid' AND fid='$fid' AND displayorder>='0'");
	if($thread = $db->fetch_array($query)) {
		$navigation .= " &raquo; <a href=\"viewthread.php?tid=$tid\">$thread[subject]</a> ";
		$navtitle .= ' - '.$thread['subject'];
	} else {
		showmessage('thread_nonexistence');
	}
} elseif(!in_array($action, array('moderate', 'delpost', 'getip'))) {
	showmessage('undefined_action', NULL, 'HALTED');
}

// Reason P.M. Preprocess Start
$reasonpmcheck = $reasonpm == 2 || $reasonpm == 3 ? 'checked disabled' : '';
if(($reasonpm == 2 || $reasonpm == 3) || $sendreasonpm) {
	$forumname = strip_tags($forum['name']);
	$sendreasonpm = 1;
} else {
	$sendreasonpm = 0;
}
// End

if(($action == 'moderate' && $fid) || in_array($action, array('delete', 'move', 'close', 'stick', 'digest'))) {

	if($action != 'moderate') {
		$operation = $action;
		$action = 'moderate';
		$moderate = array($tid);
		$single = 1;
		$referer = "forumdisplay.php?fid=$fid";
	} else {
		$single = 0;
		$referer = dreferer();
	}

	if(empty($moderate) || !is_array($moderate) || !in_array($operation, array('delete', 'move', 'close', 'stick', 'digest')) || (!$allowdelpost && $operation == 'delete')) {
		showmessage('admin_moderate_invalid');
	}

	$tids = is_array($moderate) ? '\''.implode('\',\'', $moderate).'\'' : '';

	if(!submitcheck('modsubmit')) {

		if($operation == 'move') {
			require_once DISCUZ_ROOT.'./include/forum.func.php';
			$forumselect = forumselect();
		}

		$threadlist = array();
		$query = $db->query("SELECT * FROM {$tablepre}threads WHERE tid IN ($tids) AND fid='$fid' AND displayorder>='0' LIMIT $tpp");
		while($thread = $db->fetch_array($query)) {
			$thread['lastposterenc'] = rawurlencode($thread['lastposter']);
			$thread['lastpost'] = gmdate("$dateformat $timeformat", $thread['lastpost'] + $timeoffset * 3600);
			$threadlist[] = $thread;
		}

		include template('topicadmin_moderate');

	} else {

		$moderatetids = '0';
		$threads = array();
		$query = $db->query("SELECT * FROM {$tablepre}threads WHERE tid IN ($tids) AND fid='$fid' AND displayorder>='0' LIMIT $tpp");
		while($thread = $db->fetch_array($query)) {
			//$thread['subject'] = addslashes($thread['subject']);
			//$thread['message'] = addslashes($thread['message']);
			$threads[] = $thread;
			$moderatetids .= ','.$thread['tid'];
		}

		checkreasonpm();

		if($operation == 'delete') {

			foreach($threads as $thread) {
				if($thread['digest']) {
					$db->query("UPDATE {$tablepre}members SET digestposts=digestposts-1, credits=credits-'$digestcredits' WHERE uid='$thread[authorid]'", 'UNBUFFERED');
				}
			}

			//Update members' credits and post number
			$uids = $comma = '';
			$query = $db->query("SELECT authorid FROM {$tablepre}posts WHERE tid IN ($moderatetids)");
			while($post = $db->fetch_array($query)) {
				$uids .= $comma.$post['authorid'];
				$comma = ',';
			}

			updatemember('-', $uids, $deletedcredits);
			$modaction = 'DEL';

			if($forum['recyclebin']) {

				$db->query("UPDATE {$tablepre}threads SET displayorder='-1', digest='0', moderated='1' WHERE tid IN ($moderatetids)");
				$db->query("UPDATE {$tablepre}posts SET invisible='-1' WHERE tid IN ($moderatetids)");

			} else {

				$query = $db->query("SELECT attachment FROM {$tablepre}attachments WHERE tid IN ($moderatetids)");
				while($attach = $db->fetch_array($query)) {
					@unlink($attachdir.'/'.$attach['attachment']);
				}

				$db->query("DELETE FROM {$tablepre}attachments WHERE tid IN ($moderatetids)", 'UNBUFFERED');
				$db->query("DELETE FROM {$tablepre}threadsmod WHERE tid IN ($moderatetids)", 'UNBUFFERED');
				$db->query("DELETE FROM {$tablepre}threads WHERE tid IN ($moderatetids)");
				$db->query("DELETE FROM {$tablepre}posts WHERE tid IN ($moderatetids)");
				$db->query("DELETE FROM {$tablepre}polls WHERE tid IN ($moderatetids)");

			}

			updateforumcount($fid);

		 } else {

		 	if($operation == 'stick' || $operation == 'digest') {

				if($level < 0 || $level > 3) {
					showmessage('undefined_action');
				}

				if($operation == 'stick') {
					$modaction = $level == 0 ? 'UST' : 'STK';
					$db->query("UPDATE {$tablepre}threads SET displayorder='$level', moderated='1' WHERE tid IN ($moderatetids)");
				} elseif($operation == 'digest') {
					$modaction = $level == 0 ? 'UDG' : 'DIG';
					$db->query("UPDATE {$tablepre}threads SET digest='$level', moderated='1' WHERE tid IN ($moderatetids)");
					foreach($threads as $thread) {
						if(($thread['digest'] > 0 && $level == 0) || ($thread['digest'] == 0 && $level > 0)) {
							$operator = $level == 0 ? '-' : '+';
							$db->query("UPDATE {$tablepre}members SET digestposts=digestposts$operator'1', credits=credits$operator'$digestcredits' WHERE uid='$thread[authorid]'", 'UNBUFFERED');
						}
					}
				}

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

				$close = intval($close);
				$modaction = $close ? 'CLS' : 'OPN';
				$db->query("UPDATE {$tablepre}threads SET closed='$close', moderated='1' WHERE tid IN ($moderatetids)");

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

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

				$displayorderadd = $adminid == 3 ? ', displayorder=\'0\'' : '';

				$db->query("UPDATE {$tablepre}threads SET fid='$moveto', moderated='1' $displayorderadd WHERE tid IN ($moderatetids)");
				$db->query("UPDATE {$tablepre}posts SET fid='$moveto' WHERE tid IN ($moderatetids)");

				if($type == 'redirect') {
					foreach($threads as $thread) {
						$db->query("INSERT INTO {$tablepre}threads (fid, creditsrequire, iconid, author, authorid, subject, dateline, lastpost, lastposter, views, replies, displayorder, digest, closed, poll, attachment)
							VALUES ('$thread[fid]', '$thread[creditsrequire]', '$thread[iconid]', '".addslashes($thread['author'])."', '$thread[authorid]', '".addslashes($thread['subject'])."', '$thread[dateline]', '$thread[lastpost]', '$thread[lastposter]', '0', '0', '0', '0', '$thread[tid]', '0', '0')");
					}
				}

				$modaction = 'MOV';

				updateforumcount($moveto);
				updateforumcount($fid);

			}

		}

		$resultarray = array(
			'redirect'	=> dreferer("forumdisplay.php?fid=$fid"),
			'reasonpm'	=> ($sendreasonpm ? array('data' => $threads, 'var' => 'thread', 'item' => 'reason_moderate') : array()),
			'modtids'	=> ($operation == 'delete' && !$forum['recyclebin']) ? 0 : $moderatetids,
			'modlog'	=> $threads
		);

	}

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

	if(!$allowdelpost || !$tid) {
		showmessage('admin_nopermission', NULL, 'HALTED');
	} elseif(!is_array($delete) && !count($delete)) {
		showmessage('admin_delpost_invalid');
	} else {
		$deletepids = '\''.implode('\',\'', $delete).'\'';
		$query = $db->query("SELECT pid FROM {$tablepre}posts WHERE pid IN ($deletepids) AND dateline='$thread[dateline]' AND authorid='$thread[authorid]'");
		if($db->num_rows($query)) {
			header("Location: {$boardurl}topicadmin.php?action=delete&tid=$thread[tid]");
			dexit();
		}
	}

	if(!submitcheck('delpostsubmit')) {

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

		include template('topicadmin_delpost');
			
	} else {

		checkreasonpm();

		$posts = array();
		$pids = 0;
		$uids = $comma = '';
		$query = $db->query("SELECT pid, authorid, dateline, message FROM {$tablepre}posts WHERE pid IN ($deletepids) AND tid='$tid'");
		while($post = $db->fetch_array($query)) {
			$posts[] = $post;
			$uids .= $comma.$post['authorid'];
			$pids .= ','.$post['pid'];
			$comma = ',';
		}

		updatemember('-', $uids, $deletedcredits);

		$query = $db->query("SELECT attachment FROM {$tablepre}attachments WHERE pid IN ($pids)");
		while($attach = $db->fetch_array($query)) {
			@unlink($attachdir.'/'.$attach['attachment']);
		}

		$db->query("DELETE FROM {$tablepre}attachments WHERE pid IN ($pids)");
		$db->query("DELETE FROM {$tablepre}posts WHERE pid IN ($pids)");

		updatethreadcount($tid, 1);
		updateforumcount($fid);

		$modaction = 'DLP';

⌨️ 快捷键说明

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