newthread.inc.php

来自「速度很快的PHP论坛源程序」· PHP 代码 · 共 142 行

PHP
142
字号
<?php

/*
	[DISCUZ!] include/newthread.inc.php - starting new thread for post module
	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/10/11 10:48
*/

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

$discuz_action = 11;

if(empty($forum['fid']) || $forum['type'] == 'group') {
	showmessage('forum_nonexistence');
}

if(!$discuz_uid && !((!$forum['postperm'] && $allowpost) || ($forum['postperm'] && strstr($forum['postperm'], "\t$groupid\t")))) {
	header('Location: logging.php?action=login&referer='.rawurlencode("$PHP_SELF?action=$action&fid=$fid&poll=$poll"));
	exit();
} elseif(!$forum['allowpost']) {
	if(!$forum['postperm'] && !$allowpost) {
		showmessage('group_nopermission', NULL, 'NOPERM');
	} elseif($forum['postperm'] && !strstr($forum['postperm'], "\t$groupid\t")) {
		showmessage('post_forum_newthread_nopermission', NULL, 'HALTED');
	}
}

if(!submitcheck('topicsubmit')) {

	if(is_array($_DCACHE['icons'])) {
		$key = 1;
		foreach($_DCACHE['icons'] as $id => $icon) {
			$icons .= ' <input type="radio" name="iconid" value="'.$id.'"><img src="'.SMDIR.'/'.$icon.'">';
			$icons .= !(++$key % 10) ? '<br>' : '';
		}
	}

	include template('post_newthread');

} else {

	if($subject == '' || $message == '') {
		showmessage('post_sm_isnull');
	}

	if($post_invalid = checkpost()) {
		showmessage($post_invalid);
	}

	if(checkflood()) {
		showmessage('post_flood_ctrl');
	}

	$displayorder = $modnewthreads ? -2 : (($forum['ismoderator'] && $sticktopic) ? 1 : 0);
	$digest = ($forum['ismoderator'] && $addtodigest) ? 1 : 0;
	$blog = $allowuseblog && $addtoblog ? 1 : 0;
	$viewperm = $allowsetviewperm ? $viewperm : 0;

	if($poll == 'yes' && $allowpostpoll && trim($polloptions)) {
		$poll = 1;
		$pollarray = array();
		$polloptions = explode("\n", $polloptions);
		if(count($polloptions) > $maxpolloptions) {
			showmessage('post_poll_option_toomany');
		}

		foreach($polloptions as $polloption) {
			$polloption = trim($polloption);
			if($polloption) {
				$pollarray['options'][] = array($polloption, 0);
			}
		}
		$pollarray['multiple'] = $multiplepoll;
		$pollarray['voters'] = array();
		$pollopts = addslashes(serialize($pollarray));
	} else {
		$poll = 0;
		$pollopts = '';
	}

	$moderated = $digest || $displayorder > 0 ? 1 : 0;
	$attachment = ($allowpostattach && $attachments = attach_upload()) ? 1 : 0;

	$db->query("INSERT INTO {$tablepre}threads (fid, creditsrequire, iconid, author, authorid, subject, dateline, lastpost, lastposter, displayorder, digest, blog, poll, attachment, moderated)
		VALUES ('$fid', '$viewperm', '$iconid', '$discuz_user', '$discuz_uid', '$subject', '$timestamp', '$timestamp', '$discuz_user', '$displayorder', '$digest', '$blog', '$poll', '$attachment', '$moderated')");
	$tid = $db->insert_id();

	if($moderated) {
		updatemodlog($tid, ($displayorder > 0 ? 'STK' : 'DIG'));
	}

	if($poll) {
		$db->query("INSERT INTO {$tablepre}polls (tid, pollopts)
			VALUES ('$tid', '$pollopts')");
	}

	$bbcodeoff = checkbbcodes($message, $bbcodeoff);
	$smileyoff = checksmilies($message, $smileyoff);
	$htmlon = $allowhtml && $htmlon ? 1 : 0;

	$invisible = $modnewthreads ? -2 : 0;
	$db->query("INSERT INTO {$tablepre}posts (fid, tid, author, authorid, subject, dateline, message, useip, invisible, usesig, htmlon, bbcodeoff, smileyoff, parseurloff, attachment)
		VALUES ('$fid', '$tid', '$discuz_user', '$discuz_uid', '$subject', '$timestamp', '$message', '$onlineip', '$invisible', '$usesig', '$htmlon', '$bbcodeoff', '$smileyoff', '$parseurloff', '$attachment')");
	$pid = $db->insert_id();

	if($attachment) {
		foreach($attachments as $attach) {
			$db->query("INSERT INTO {$tablepre}attachments (tid, pid, creditsrequire, filename, filetype, filesize, attachment, downloads)
				VALUES ('$tid', '$pid', '$attach[perm]', '$attach[name]', '$attach[type]', '$attach[size]', '$attach[attachment]', '0')");
		}
	}

	if($modnewthreads) {
		showmessage('post_newthread_mod_succeed', "forumdisplay.php?fid=$fid");
	} else {
		updatemember('+', $discuz_uid, $postcredits);

		$lastpost = "$tid\t$subject\t$timestamp\t$discuz_user";
		$db->query("UPDATE {$tablepre}forums SET lastpost='$lastpost', threads=threads+1, posts=posts+1 WHERE fid='$fid'", 'UNBUFFERED');
		if($forum['type'] == 'sub') {
			$db->query("UPDATE {$tablepre}forums SET lastpost='$lastpost' WHERE fid='$forum[fup]'", 'UNBUFFERED');
		}

		if($emailnotify && $discuz_uid) {
			$query = $db->query("SELECT tid FROM {$tablepre}subscriptions WHERE uid='$discuz_uid' AND tid='$tid'");
			if(!$db->result($query, 0)) {
				$db->query("INSERT INTO {$tablepre}subscriptions (uid, email, tid)
					VALUES ('$discuz_uid', '$email', '$tid')", 'UNBUFFERED');
			}
		}
		showmessage('post_newthread_succeed', "viewthread.php?tid=$tid");
	}

}

?>

⌨️ 快捷键说明

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