<?php


$_GET['mod']='post';	//zzcityadd
$_GET['action']='reply';	//zzcityadd


define('APPTYPEID', 2);
define('CURSCRIPT', 'forum');


require './source/class/class_core.php';
require './source/function/function_forum.php';

$discuz = & discuz_core::instance();

$modarray = array('ajax','announcement','attachment','forumdisplay',
'group','image','index','medal','misc','modcp','notice','post','redirect',
'relatekw','relatethread','rss','search','topicadmin','trade','viewthread'
);

$modcachelist = array(
'index'		=> array('announcements', 'onlinelist', 'forumlinks', 'advs_index',
'heats', 'historyposts', 'onlinerecord', 'blockclass', 'userstats'),
'forumdisplay'	=> array('smilies', 'announcements_forum', 'globalstick', 'forums',
'icons', 'onlinelist', 'forumstick', 'blockclass',
'threadtable_info', 'threadtableids'),
'viewthread'	=> array('smilies', 'smileytypes', 'forums', 'usergroups', 'ranks',
'stamps', 'bbcodes', 'smilies',
'custominfo', 'groupicon', 'stamps', 'threadtableids', 'threadtable_info'),
'post'		=> array('bbcodes_display', 'bbcodes', 'smileycodes', 'smilies', 'smileytypes',
'icons', 'domainwhitelist'),
'space'		=> array('fields_required', 'fields_optional', 'custominfo'),
'group'		=> array('grouptype'),
);

//$mod = !in_array($discuz->var['mod'], $modarray) ? 'index' : $discuz->var['mod'];


define('CURMODULE', $mod != 'redirect' ? $mod : 'viewthread');
$cachelist = array();
if(isset($modcachelist[CURMODULE])) {
	$cachelist = $modcachelist[CURMODULE];
}

$discuz->cachelist = $cachelist;
$discuz->init();
//zzcity add
$member = array();
$member = DB::fetch_first("SELECT * FROM ".DB::table('common_member')." WHERE username='".$_POST['username']."'");
$cookietime=$_G['gp_cookietime'] ? 2592000 : 0;
	$_G['uid'] = $member['uid'];
	$_G['username'] = $member['username'];
	$_G['adminid'] = $member['adminid'];
	$_G['groupid'] = $member['groupid'];
	$_G['formhash'] = formhash();
	$_G['session']['invisible'] = getuserprofile('invisible');
	$_G['member'] = $member;
	$_G['core']->session->isnew = 1;

	dsetcookie('auth', authcode("{$member['password']}\t{$member['uid']}", 'ENCODE'), $cookietime, 1, true);
	dsetcookie('loginuser');
	dsetcookie('activationauth');
	dsetcookie('pmnum');
$discuz->_init_user();
$_G['gp_htmlon'] = trim($_G['gp_htmlon'])=='' ? '1' : $_G['gp_htmlon'];

//zzcity
loadforum();

//zzcityadd
$_G['group']['allowhtml']=$_G['gp_htmlon'];
$_G['forum']['allowhtml']=$_G['gp_htmlon'];
$zzhour = empty($_G['gp_zzhour']) ? '1' : intval($_G['gp_zzhour']); //zzcity add

$replyno = empty($_G['gp_replyno']) ? '1' : intval($_G['gp_replyno']); //zzcity add

$zztimestamp =time()-$zzhour*60*60; //zzcity add

$zztimestamp =$_G['timestamp']= $zztimestamp+$replyno*5*60+rand(0,4)*60;	 //zzcity add

//zzcity


set_rssauth();
//runhooks();
//require DISCUZ_ROOT.'./source/module/forum/forum_'.$mod.'.php';替换开始
if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}
define('NOROBOT', TRUE);

cknewuser();

require_once libfile('class/credit');
require_once libfile('function/post');


$pid = intval(getgpc('pid'));
$sortid = intval(getgpc('sortid'));
$typeid = intval(getgpc('typeid'));
$special = intval(getgpc('special'));
$_G['gp_from'] = !empty($_G['gp_from']) && in_array($_G['gp_from'], array('home', 'portal')) ? $_G['gp_from'] : '';

$postinfo = array('subject' => '');
$thread = array('readperm' => '', 'pricedisplay' => '', 'hiddenreplies' => '');

$_G['forum_dtype'] = $_G['forum_checkoption'] = $_G['forum_optionlist'] = $tagarray = $_G['forum_typetemplate'] = array();
if($sortid) {
	require_once libfile('function/threadsort');
	threadsort_checkoption($sortid);
}

if($_G['forum']['status'] == 3) {
	require_once libfile('function/group');
	$status = groupperm($_G['forum'], $_G['uid'], 'post');
	if($status == -1) {
//		showmessage('该版块不是群组', 'index.php');
		exit('[err]该版块不是群组[/err]');
	} elseif($status == 1) {
//		showmessage('该群组已经关闭');
		exit('[err]该群组已经关闭[/err]');
	} elseif($status == 2) {
//		showmessage('您没有权限访问该群组', "forum.php?mod=group&fid=$_G[fid]");
		exit('[err]您没有权限访问该群组[/err]');
	} elseif($status == 3) {
//		showmessage('请等待群主审核。', "forum.php?mod=group&fid=$_G[fid]");
		exit('[err]请等待群主审核[/err]');
	} elseif($status == 4) {
//		showmessage('您还不是本群组成员，不能发帖．', "forum.php?mod=forumdisplay&fid=$_G[fid]");
		exit('[err]您还不是本群组成员，不能发帖[/err]');
	}
}
/*
if(empty($_G['gp_action'])) {
	showmessage('undefined_action', NULL);
} elseif($_G['gp_action'] == 'threadsorts') {
	require_once libfile('function/threadsort');
	loadcache(array('threadsort_option_'.$_G['gp_sortid'], 'threadsort_template_'.$_G['gp_sortid']));
	threadsort_optiondata($_G['gp_pid'], $_G['gp_sortid'], $_G['cache']['threadsort_option_'.$_G['gp_sortid']], $_G['cache']['threadsort_template_'.$_G['gp_sortid']]);
	$template = intval($_G['gp_operate']) ? 'forum/search_sortoption' : 'forum/post_sortoption';
	include template($template);
	exit;
} elseif($_G['gp_action'] == 'albumphoto') {
	include_once libfile('function/home');
	$perpage = 8;
	$page = max(1, $_G['gp_page']);
	$start_limit = ($page - 1) * $perpage;
	$aid = intval($_G['gp_aid']);
	$photolist = array();
	$count= DB::result_first("SELECT picnum FROM ".DB::table('home_album')." WHERE albumid='$aid' AND uid='$_G[uid]'");
	$query = DB::query("SELECT * FROM ".DB::table('home_pic')." WHERE albumid='$aid' AND uid='$_G[uid]' ORDER BY dateline DESC LIMIT $start_limit,$perpage");
	while($value = DB::fetch($query)) {
		$value['bigpic'] = pic_get($value['filepath'], 'album', $value['thumb'], $value['remote'], 0);
		$value['pic'] = pic_get($value['filepath'], 'album', $value['thumb'], $value['remote']);
		$value['count'] = $count;
		$value['url'] = (substr(strtolower($value['bigpic']), 0, 7) == 'http://' ? '' : $_G['siteurl']).$value['bigpic'];
		$value['thumburl'] = (substr(strtolower($value['pic']), 0, 7) == 'http://' ? '' : $_G['siteurl']).$value['pic'];
		$photolist[] = $value;
	}
	$_G['gp_ajaxtarget'] = 'albumphoto';
	$multi = multi($count, $perpage, $page, "forum.php?mod=post&action=albumphoto&aid=$aid");
	include template('forum/ajax_albumlist');
	exit;

} elseif(($_G['forum']['simple'] & 1) || $_G['forum']['redirect']) {
	showmessage('forum_disablepost');
}
*/
require_once libfile('function/discuzcode');
$space = array();
space_merge($space, 'field_home');

if($_G['gp_action'] == 'reply') {
	$addfeedcheck = !empty($space['privacy']['feed']['newreply']) ? 'checked="checked"': '';
} else {
	$addfeedcheck = !empty($space['privacy']['feed']['newthread']) ? 'checked="checked"': '';
}


$navigation = $navtitle = $homedo = '';

if(!empty($_G['gp_cedit'])) {
	unset($_G['inajax'], $_G['gp_infloat'], $_G['gp_ajaxtarget'], $_G['gp_handlekey']);
}

if($_G['gp_action'] == 'edit' || $_G['gp_action'] == 'reply') {
	if($thread = DB::fetch_first("SELECT * FROM ".DB::table('forum_thread')." WHERE tid='$_G[tid]'".($_G['forum_auditstatuson'] ? '' : " AND displayorder>='0'"))) {
		
		$navtitle = $thread['subject'].' - ';
		if($thread['readperm'] && $thread['readperm'] > $_G['group']['readaccess'] && !$_G['forum']['ismoderator'] && $thread['authorid'] != $_G['uid']) {
//			showmessage('thread_nopermission', NULL, array('readperm' => $thread['readperm']), array('login' => 1));
			exit('[err]'.lang('message', 'thread_nopermission',array('readperm' => $thread['readperm']), array('login' => 1)).'[/err]');
		}

		$_G['fid'] = $thread['fid'];
		$special = $thread['special'];

	} else {
//		showmessage('thread_nonexistence');
		exit('[err]'.lang('message', 'thread_nonexistence').'[/err]');
	}

	if($_G['gp_action'] == 'reply' && ($thread['closed'] == 1) && !$_G['forum']['ismoderator']) {
//		showmessage('post_thread_closed');
		exit('[err]'.lang('message', 'post_thread_closed').'[/err]');
	}

}

if($_G['forum']['status'] == 3) {
	$returnurl = 'forum.php?mod=forumdisplay&fid='.$_G['fid'].(!empty($_G['gp_extra']) ? '&action=list&'.preg_replace("/^(&)*/", '', $_G['gp_extra']) : '').'#groupnav';
	$navigation = ' &rsaquo; <a href="group.php">'.$_G['setting']['navs'][3]['navname'].'</a> '.get_groupnav($_G['forum']);
} else {
	if($_G['gp_from'] != 'portal') {
		$returnurl = 'forum.php?mod=forumdisplay&fid='.$_G['fid'].(!empty($_G['gp_extra']) ? '&'.preg_replace("/^(&)*/", '', $_G['gp_extra']) : '');
		$navigation = '&rsaquo; <a href="'.$returnurl.'">'.$_G['forum']['name'].'</a> '.$navigation;
	}
	$navtitle = $navtitle.strip_tags($_G['forum']['name']).' - ';

	if($_G['forum']['type'] == 'sub') {
		$fup = DB::fetch_first("SELECT name, fid FROM ".DB::table('forum_forum')." WHERE fid='".$_G['forum']['fup']."'");
		$navigation = '&rsaquo; <a href="forum.php?mod=forumdisplay&fid='.$fup['fid'].'">'.$fup['name'].'</a> '.$navigation;
		$navtitle = $navtitle.strip_tags($fup['name']).' - ';
	}
	$navigation = ' &rsaquo; <a href="forum.php">'.$_G['setting']['navs'][2]['navname'].'</a> '.$navigation;
}

periodscheck('postbanperiods');

//if($_G['forum']['password'] && $_G['forum']['password'] != $_G['cookie']['fidpw'.$_G['fid']]) {
//	showmessage('forum_passwd', "forum.php?mod=forumdisplay&fid=$_G[fid]");
//}

/*if(empty($_G['forum']['allowview'])) {
	if(!$_G['forum']['viewperm'] && !$_G['group']['readaccess']) {
		showmessage('group_nopermission', NULL, array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1));
	} elseif($_G['forum']['viewperm'] && !forumperm($_G['forum']['viewperm'])) {
		showmessagenoperm('viewperm', $_G['fid']);
	}
} elseif($_G['forum']['allowview'] == -1) {
	showmessage('forum_access_view_disallow');
}
*/
formulaperm($_G['forum']['formulaperm']);

/*if(!$_G['adminid'] && $_G['setting']['newbiespan'] && (!getuserprofile('lastpost') || TIMESTAMP - getuserprofile('lastpost') < $_G['setting']['newbiespan'] * 3600)) {
	if(TIMESTAMP - (DB::result_first("SELECT regdate FROM ".DB::table('common_member')." WHERE uid='$_G[uid]'")) < $_G['setting']['newbiespan'] * 3600) {
		showmessage('post_newbie_span', '', array('newbiespan' => $_G['setting']['newbiespan']));
	}
}
*/
$special = $special > 0 && $special < 7 || $special == 127 ? intval($special) : 0;

$_G['forum']['allowpostattach'] = isset($_G['forum']['allowpostattach']) ? $_G['forum']['allowpostattach'] : '';
$_G['group']['allowpostattach'] = $_G['forum']['allowpostattach'] != -1 && ($_G['forum']['allowpostattach'] == 1 || (!$_G['forum']['postattachperm'] && $_G['group']['allowpostattach']) || ($_G['forum']['postattachperm'] && forumperm($_G['forum']['postattachperm'])));
$_G['forum']['allowpostimage'] = isset($_G['forum']['allowpostimage']) ? $_G['forum']['allowpostimage'] : '';
$_G['group']['allowpostimage'] = $_G['forum']['allowpostimage'] != -1 && ($_G['forum']['allowpostimage'] == 1 || (!$_G['forum']['postimageperm'] && $_G['group']['allowpostimage']) || ($_G['forum']['postimageperm'] && forumperm($_G['forum']['postimageperm'])));
$_G['group']['attachextensions'] = $_G['forum']['attachextensions'] ? $_G['forum']['attachextensions'] : $_G['group']['attachextensions'];
if($_G['group']['attachextensions']) {
	$imgexts = explode(',', str_replace(' ', '', $_G['group']['attachextensions']));
	$imgexts = array_intersect(array('jpg','jpeg','gif','png','bmp'), $imgexts);
	$imgexts = implode(', ', $imgexts);
} else {
	$imgexts = 'jpg, jpeg, gif, png, bmp';
}

$allowuploadnum = TRUE;
if($_G['group']['allowpostattach'] || $_G['group']['allowpostimage']) {
	if($_G['group']['maxattachnum']) {
		$allowuploadnum = $_G['group']['maxattachnum'] - DB::result_first("SELECT count(*) FROM ".DB::table('forum_attachment')." WHERE uid='$_G[uid]' AND dateline>'$_G[timestamp]'-86400");
		$allowuploadnum = $allowuploadnum < 0 ? 0 : $allowuploadnum;
		$_G['group']['allowpostimage'] = $_G['group']['allowpostattach'] = $allowuploadnum ? $allowuploadnum : 0;
	}
	if($_G['group']['maxsizeperday']) {
		$allowuploadsize = $_G['group']['maxsizeperday'] - intval(DB::result_first("SELECT SUM(filesize) FROM ".DB::table('forum_attachment')." WHERE uid='$_G[uid]' AND dateline>'$_G[timestamp]'-86400"));
		$allowuploadsize = $allowuploadsize < 0 ? 0 : $allowuploadsize;
		$allowuploadsize = $allowuploadsize / 1048576 >= 1 ? round(($allowuploadsize / 1048576), 1).'MB' : round(($allowuploadsize / 1024)).'KB';
	}
}
$allowpostimg = $_G['group']['allowpostimage'] && $imgexts;
$enctype = ($_G['group']['allowpostattach'] || $_G['group']['allowpostimage']) ? 'enctype="multipart/form-data"' : '';
$maxattachsize_mb = $_G['group']['maxattachsize'] / 1048576 >= 1 ? round(($_G['group']['maxattachsize'] / 1048576), 1).'MB' : round(($_G['group']['maxattachsize'] / 1024)).'KB';

$postcredits = $_G['forum']['postcredits'] ? $_G['forum']['postcredits'] : $_G['setting']['creditspolicy']['post'];
$replycredits = $_G['forum']['replycredits'] ? $_G['forum']['replycredits'] : $_G['setting']['creditspolicy']['reply'];
$digestcredits = $_G['forum']['digestcredits'] ? $_G['forum']['digestcredits'] : $_G['setting']['creditspolicy']['digest'];
$postattachcredits = $_G['forum']['postattachcredits'] ? $_G['forum']['postattachcredits'] : $_G['setting']['creditspolicy']['postattach'];

$_G['group']['maxprice'] = isset($_G['setting']['extcredits'][$_G['setting']['creditstrans']]) ? $_G['group']['maxprice'] : 0;

$extra = (!empty($_G['gp_extra']) ? rawurlencode($_G['gp_extra']) : '').(!empty($_G['gp_from']) ? '&from='.rawurlencode($_G['gp_from']) : '');
$notifycheck = empty($emailnotify) ? '' : 'checked="checked"';
$stickcheck = empty($sticktopic) ? '' : 'checked="checked"';
$digestcheck = empty($addtodigest) ? '' : 'checked="checked"';

$subject = isset($_G['gp_subject']) ? dhtmlspecialchars(censor(trim($_G['gp_subject']))) : '';
$subject = !empty($subject) ? str_replace("\t", ' ', $subject) : $subject;
$message = isset($_G['gp_message']) ? censor($_G['gp_message']) : '';

$polloptions = isset($polloptions) ? censor(trim($polloptions)) : '';
$readperm = isset($_G['gp_readperm']) ? intval($_G['gp_readperm']) : 0;
$price = isset($_G['gp_price']) ? intval($_G['gp_price']) : 0;
$_G['setting']['tagstatus'] = $_G['setting']['tagstatus'] && $_G['forum']['allowtag'] ? ($_G['setting']['tagstatus'] == 2 ? 2 : $_G['forum']['allowtag']) : 0;

/*if(empty($bbcodeoff) && !$_G['group']['allowhidecode'] && !empty($message) && preg_match("/\[hide=?\d*\].+?\[\/hide\]/is", preg_replace("/(\[code\](.+?)\[\/code\])/is", ' ', $message))) {
	showmessage('post_hide_nopermission');
}
*/
if(periodscheck('postmodperiods', 0)) {
	$modnewthreads = $modnewreplies = 1;
} else {
	$censormod = censormod($subject."\t".$message);
	$modnewthreads = (!$_G['group']['allowdirectpost'] || $_G['group']['allowdirectpost'] == 1) && $_G['forum']['modnewposts'] || $censormod ? 1 : 0;
	$modnewreplies = (!$_G['group']['allowdirectpost'] || $_G['group']['allowdirectpost'] == 2) && $_G['forum']['modnewposts'] == 2 || $censormod ? 1 : 0;
}

/*if($_G['group']['allowposturl'] < 3 && $message) {
	$urllist = get_url_list($message);
	if(is_array($urllist[1])) foreach($urllist[1] as $key => $val) {
		if(!$val = trim($val)) continue;
		if(!iswhitelist($val)) {
			if($_G['group']['allowposturl'] == 0) {//note 禁止发送站外连接
				showmessage('post_url_nopermission');
			} elseif($_G['group']['allowposturl'] == 1) {//note 允许发表站外连接，但是会进入审核状态
				$modnewthreads = $modnewreplies = 1;
				break;
			} elseif($_G['group']['allowposturl'] == 2) {//note 允许发表站外连接，但是不解析
				$message = str_replace('[url]'.$urllist[0][$key].'[/url]', $urllist[0][$key], $message);
				$message = preg_replace("@\[url={$urllist[0][$key]}\](.*?)\[/url\]@i", '\\1', $message);
			}
		}
	}
}
*/
$urloffcheck = $usesigcheck = $smileyoffcheck = $codeoffcheck = $htmloncheck = $emailcheck = '';

$seccodecheck = ($_G['setting']['seccodestatus'] & 4) && (!$_G['setting']['seccodedata']['minposts'] || getuserprofile('posts') < $_G['setting']['seccodedata']['minposts']);
$secqaacheck = $_G['setting']['secqaa']['status'] & 2 && (!$_G['setting']['secqaa']['minposts'] || getuserprofile('posts') < $_G['setting']['secqaa']['minposts']);

$_G['group']['allowpostpoll'] = $_G['group']['allowpost'] && $_G['group']['allowpostpoll'] && ($_G['forum']['allowpostspecial'] & 1);
$_G['group']['allowposttrade'] = $_G['group']['allowpost'] && $_G['group']['allowposttrade'] && ($_G['forum']['allowpostspecial'] & 2);
$_G['group']['allowpostreward'] = $_G['group']['allowpost'] && $_G['group']['allowpostreward'] && ($_G['forum']['allowpostspecial'] & 4) && isset($_G['setting']['extcredits'][$_G['setting']['creditstrans']]);
$_G['group']['allowpostactivity'] = $_G['group']['allowpost'] && $_G['group']['allowpostactivity'] && ($_G['forum']['allowpostspecial'] & 8);
$_G['group']['allowpostdebate'] = $_G['group']['allowpost'] && $_G['group']['allowpostdebate'] && ($_G['forum']['allowpostspecial'] & 16);
$usesigcheck = $_G['uid'] && $_G['group']['maxsigsize'] ? 'checked="checked"' : '';
$ordertypecheck = !empty($thread['tid']) && getstatus($thread['status'], 4) ? 'checked="checked"' : '';
$specialextra = !empty($_G['gp_specialextra']) ? $_G['gp_specialextra'] : '';

if($specialextra && $_G['group']['allowpost'] && $_G['setting']['threadplugins'] &&
	(!array_key_exists($specialextra, $_G['setting']['threadplugins']) ||
	!@in_array($specialextra, is_array($_G['forum']['threadplugin']) ? $_G['forum']['threadplugin'] : unserialize($_G['forum']['threadplugin'])) ||
	!@in_array($specialextra, $_G['group']['allowthreadplugin']))) {
	$specialextra = '';
}

$_G['group']['allowanonymous'] = $_G['forum']['allowanonymous'] || $_G['group']['allowanonymous'] ? 1 : 0;

if($_G['gp_action'] == 'newthread' && $_G['forum']['allowspecialonly'] && !$special) {
	if($_G['group']['allowpostpoll']) {
		$special = 1;
	} elseif($_G['group']['allowposttrade']) {
		$special = 2;
	} elseif($_G['group']['allowpostreward']) {
		$special = 3;
	} elseif($_G['group']['allowpostactivity']) {
		$special = 4;
	} elseif($_G['group']['allowpostdebate']) {
		$special = 5;
	} elseif($_G['group']['allowpost'] && $_G['setting']['threadplugins'] && $_G['group']['allowthreadplugin'] && ($_G['forum']['threadplugin'] = unserialize($_G['forum']['threadplugin']))) {
		$threadpluginary = array_intersect($_G['group']['allowthreadplugin'], $_G['forum']['threadplugin']);
		$specialextra = $threadpluginary[0] ? $threadpluginary[0] : '';
	}

	if(!$special && !$specialextra) {
		showmessage('group_nopermission', NULL, array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1));
	}
}

if(!empty($_G['gp_from']) && $_G['gp_from'] == 'home') {
	switch($special) {
		case 0:$homedo = 'thread';break;
		case 1:$homedo = 'poll';break;
		case 2:$homedo = 'trade';break;
		case 3:$homedo = 'reward';break;
		case 4:$homedo = 'activity';break;
		case 5:$homedo = 'debate';break;
	}
	if($homedo) {
		$navigation = '';
	}
}


$editorid = 'e';
$_G['setting']['editoroptions'] = str_pad(decbin($_G['setting']['editoroptions']), 2, 0, STR_PAD_LEFT);
$editormode = $_G['setting']['editoroptions']{0};
$allowswitcheditor = $_G['setting']['editoroptions']{1};
$editor = array(
	'editormode' => $editormode,
	'allowswitcheditor' => $allowswitcheditor,
	'allowhtml' => $_G['group']['allowhtml'],
	'allowhtml' => $_G['forum']['allowhtml'],
	'allowsmilies' => $_G['forum']['allowsmilies'],
	'allowbbcode' => $_G['forum']['allowbbcode'],
	'allowimgcode' => $_G['forum']['allowimgcode'],
	'allowcustombbcode' => $_G['forum']['allowbbcode'] && $_G['group']['allowcusbbcode'],
	'allowresize' => 1,
	'textarea' => 'message',
);
if($specialextra) {
	$special = 127;
}

if($_G['gp_action'] == 'newthread') {
	$policykey = 'post';
} elseif($_G['gp_action'] == 'reply') {
	$policykey = 'reply';
} else {
	$policykey = '';
}
if($policykey) {
	$postcredits = $_G['forum'][$policykey.'credits'] ? $_G['forum'][$policykey.'credits'] : $_G['setting']['creditspolicy'][$policykey];
}

$albumlist = array();
if($_G['uid']) {
	$query = DB::query("SELECT albumid, albumname, picnum FROM ".DB::table('home_album')." WHERE uid='$_G[uid]' ORDER BY updatetime DESC");
	while($value = DB::fetch($query)) {
		if($value['picnum']) {
			$albumlist[] = $value;
		}
	}
}

$posturl = "action=$_G[gp_action]&fid=$_G[fid]".
	(!empty($_G['tid']) ? "&tid=$_G[tid]" : '').
	(!empty($pid) ? "&pid=$pid" : '').
	(!empty($special) ? "&special=$special" : '').
	(!empty($sortid) ? "&sortid=$sortid" : '').
	(!empty($typeid) ? "&typeid=$typeid" : '').
	(!empty($_G['gp_firstpid']) ? "&firstpid=$firstpid" : '').
	(!empty($_G['gp_addtrade']) ? "&addtrade=$addtrade" : '');

if($_G['gp_action'] == 'reply') {
	check_allow_action('allowreply');
} else {
	check_allow_action('allowpost');
}

/*if($_G['gp_action'] == 'newthread') {
	require_once libfile('post/newthread', 'include');
} elseif($_G['gp_action'] == 'reply') {
	require_once libfile('post/newreply', 'include');
} elseif($_G['gp_action'] == 'edit') {
	require_once libfile('post/editpost', 'include');
} elseif($_G['gp_action'] == 'newtrade') {
	require_once libfile('post/newtrade', 'include');
}
*/

//require_once libfile('post/newreply', 'include');替换开始
//if(!defined('IN_DISCUZ')) {
//	exit('Access Denied');
//}

require_once libfile('function/forumlist');

$isfirstpost = 0;
$showthreadsorts = 0;

/*if($special == 5) {
	$debate = array_merge($thread, DB::fetch_first("SELECT * FROM ".DB::table('forum_debate')." WHERE tid='$_G[tid]'"));
	$standquery = DB::query("SELECT stand FROM ".DB::table('forum_debatepost')." WHERE tid='$_G[tid]' AND uid='$_G[uid]' AND stand<>'0' ORDER BY dateline LIMIT 1");
	$firststand = DB::result_first("SELECT stand FROM ".DB::table('forum_debatepost')." WHERE tid='$_G[tid]' AND uid='$_G[uid]' AND stand<>'0' ORDER BY dateline LIMIT 1");
	$stand = $firststand ? $firststand : intval($_G['gp_stand']);

	if($debate['endtime'] && $debate['endtime'] < TIMESTAMP) {
		showmessage('debate_end');
	}
}
*/
/*if(!$_G['uid'] && !((!$_G['forum']['replyperm'] && $_G['group']['allowreply']) || ($_G['forum']['replyperm'] && forumperm($_G['forum']['replyperm'])))) {
	showmessage('replyperm_login_nopermission', NULL, array(), array('login' => 1));
} elseif(empty($_G['forum']['allowreply'])) {
	if(!$_G['forum']['replyperm'] && !$_G['group']['allowreply']) {
		showmessage('replyperm_none_nopermission', NULL, array(), array('login' => 1));
	} elseif($_G['forum']['replyperm'] && !forumperm($_G['forum']['replyperm'])) {
		showmessagenoperm('replyperm', $_G['forum']['fid']);
	}
} elseif($_G['forum']['allowreply'] == -1) {
	showmessage('post_forum_newreply_nopermission', NULL);
}
*/
if(empty($thread)) {
//	showmessage('thread_nonexistence');
	exit('[err]'.lang('message', 'thread_nonexistence').'[/err]');
} elseif($thread['price'] > 0 && $thread['special'] == 0 && !$_G['uid']) {
//	showmessage('group_nopermission', NULL, array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1));
	exit('[err]'.lang('message', 'group_nopermission',array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1)).'[/err]');
}

//checklowerlimit('reply');

if($_G['setting']['commentnumber'] && !empty($_G['gp_comment'])) {
	$posttable = getposttablebytid($_G['tid']);
	if(!submitcheck('commentsubmit', 0, $seccodecheck)) {
//		showmessage('undefined_action', NULL);
		exit('[err]'.lang('message', 'undefined_action').'[/err]');
	}
	$post = DB::fetch_first('SELECT * FROM '.DB::table($posttable)." WHERE pid='$_G[gp_pid]'");
	if(!$post) {
//		showmessage('undefined_action', NULL);
		exit('[err]'.lang('message', 'undefined_action').'[/err]');
	}
/*	if($thread['closed'] && !$_G['forum']['ismoderator']) {
		showmessage('post_thread_closed');
	} elseif($post_autoclose = checkautoclose($thread)) {
		showmessage($post_autoclose, '', array('autoclose' => $_G['forum']['autoclose']));
	} elseif(checkflood()) {
		showmessage('post_flood_ctrl', '', array('floodctrl' => $_G['setting']['floodctrl']));
	}
*/	$commentscore = '';
	if(!empty($_G['gp_commentitem']) && $post['authorid'] != $_G['uid']) {
		foreach($_G['gp_commentitem'] as $itemk => $itemv) {
			if($itemv !== '') {
				$commentscore .= strip_tags(trim($itemk)).': <i>'.intval($itemv).'</i> ';
			}
		}
	}
	$comment = cutstr(($commentscore ? $commentscore.'<br />' : '').censor(trim(strip_tags($_G['gp_message'])), '***'), 200, ' ');
	if(!$comment) {
//		showmessage('post_sm_isnull');
		exit('[err]'.lang('message', 'post_sm_isnull').'[/err]');
	}
	DB::insert('forum_postcomment', array(
		'tid' => $post['tid'],
		'pid' => $post['pid'],
		'author' => $_G['username'],
		'authorid' => $_G['uid'],
		'dateline' => $zztimestamp,
		'comment' => $comment,
		'score' => $commentscore ? 1 : 0,
	));
	DB::update('forum_post', array('comment' => 1), "pid='$_G[gp_pid]'");
	updatepostcredits('+', $_G['uid'], 'reply', $_G['fid']);
	if($_G['uid'] != $post['authorid']) {
		notification_add($post['authorid'], 'pcomment', 'comment_add', array(
			'tid' => $_G['tid'],
			'pid' => $_G['gp_pid'],
			'subject' => $thread['subject'],
			'commentmsg' => messagecutstr(stripslashes($comment), 200)
		));
	}
	$pcid = DB::result_first("SELECT id FROM ".DB::table('forum_postcomment')." WHERE pid='$_G[gp_pid]' AND authorid='0'");
	if($_G['gp_commentitem']) {
		$query = DB::query('SELECT comment FROM '.DB::table('forum_postcomment')." WHERE pid='$_G[gp_pid]' AND score='1'");
		$totalcomment = array();
		while($comment = DB::fetch($query)) {
			$comment['comment'] = addslashes($comment['comment']);
			if(strexists($comment['comment'], '<br />')) {
				if(preg_match_all("/([^:]+?):\s<i>(\d+)<\/i>/", $comment['comment'], $a)) {
					foreach($a[1] as $k => $itemk) {
						$totalcomment[trim($itemk)][] = $a[2][$k];
					}
				}
			}
		}
		$totalv = '';
		foreach($totalcomment as $itemk => $itemv) {
			$totalv .= strip_tags(trim($itemk)).': <i>'.(floatval(sprintf('%1.1f', array_sum($itemv) / count($itemv)))).'</i> ';
		}

		if($pcid) {
			DB::update('forum_postcomment', array('comment' => $totalv, 'dateline' => $zztimestamp + 1), "id='$pcid'");
		} else {
			DB::insert('forum_postcomment', array(
				'tid' => $post['tid'],
				'pid' => $post['pid'],
				'author' => '',
				'authorid' => '0',
				'dateline' => $zztimestamp + 1,
				'comment' => $totalv
			));
		}
	}
	DB::update('forum_postcomment', array('dateline' => $zztimestamp + 1), "id='$pcid'");
	showmessage('comment_add_succeed', "forum.php?mod=viewthread&tid=$post[tid]&pid=$post[pid]&page=$_G[gp_page]&extra=$extra#pid$post[pid]");
}

if($special == 127) {
	$posttable = getposttablebytid($_G['tid']);
	$postinfo = DB::fetch_first("SELECT message FROM ".DB::table($posttable)." WHERE tid='$_G[tid]' AND first='1'");
	$sppos = strrpos($postinfo['message'], chr(0).chr(0).chr(0));
	$specialextra = substr($postinfo['message'], $sppos + 3);
}

/*if(!submitcheck('replysubmit', 0, $seccodecheck, $secqaacheck)) {

	if($thread['special'] == 2 && ((!isset($_G['gp_addtrade']) || $thread['authorid'] != $_G['uid']) && !$tradenum = DB::result_first("SELECT count(*) FROM ".DB::table('forum_trade')." WHERE tid='$_G[tid]'"))) {
		showmessage('trade_newreply_nopermission', NULL);
	}

	$language = lang('forum/misc');
	$noticeauthor = $noticetrimstr = '';
	if(isset($_G['gp_repquote'])) {
		$posttable = getposttablebytid($_G['tid']);
		$thaquote = DB::fetch_first("SELECT tid, fid, author, authorid, first, message, useip, dateline, anonymous, status FROM ".DB::table($posttable)." WHERE pid='$_G[gp_repquote]' AND invisible='0'");
		if($thaquote['tid'] != $_G['tid']) {
			showmessage('undefined_action', NULL);
		}

		if(getstatus($thread['status'], 2) && $thaquote['authorid'] != $_G['uid'] && $_G['uid'] != $thread['authorid'] && $thaquote['first'] != 1 && !$_G['forum']['ismoderator']) {
			showmessage('undefined_action', NULL);
		}

		if(!($thread['price'] && !$thread['special'] && $thaquote['first'])) {
			$quotefid = $thaquote['fid'];
			$message = $thaquote['message'];

			if($_G['setting']['bannedmessages'] && $thaquote['authorid']) {
				$author = DB::fetch_first("SELECT groupid FROM ".DB::table('common_member')." WHERE uid='$thaquote[authorid]'");
				if(!$author['groupid'] || $author['groupid'] == 4 || $author['groupid'] == 5) {
					$message = $language['post_banned'];
				} elseif($thaquote['status'] & 1) {
					$message = $language['post_single_banned'];
				}
			}

			$time = dgmdate($thaquote['dateline']);
			$message = messagecutstr($message, 100);

			$thaquote['useip'] = substr($thaquote['useip'], 0, strrpos($thaquote['useip'], '.')).'.x';
			if($thaquote['author'] && $thaquote['anonymous']) {
				$thaquote['author'] = 'Anonymous';
			} elseif(!$thaquote['author']) {
				$thaquote['author'] = 'Guest from '.$thaquote['useip'];
			} else {
				$thaquote['author'] = $thaquote['author'];
			}

			$post_reply_quote = lang('forum/misc', 'post_reply_quote', array('author' => $thaquote['author'], 'time' => $time));
			$noticeauthormsg = htmlspecialchars($message);
			$message = "[quote]$message\n[size=2][color=#999999]{$post_reply_quote}[/color] [url=$_G[siteurl]forum.php?mod=redirect&goto=findpost&pid=$_G[gp_repquote]&ptid={$_G['tid']}][img]{$_G['siteurl']}static/image/common/back.gif[/img][/url][/size][/quote]\n\n\n";
			$noticeauthor = htmlspecialchars('q|'.$thaquote['authorid'].'|'.$thaquote['author']);
			$noticetrimstr = htmlspecialchars($message);
		}

	} elseif(isset($_G['gp_reppost'])) {
		$posttable = getposttablebytid($_G['tid']);
		$thapost = DB::fetch_first("SELECT tid, author, authorid, useip, dateline, anonymous, status, message FROM ".DB::table($posttable)." WHERE pid='$_G[gp_reppost]' AND invisible='0'");
		if($thapost['tid'] != $_G['tid']) {
			showmessage('undefined_action', NULL);
		}

		$thapost['useip'] = substr($thapost['useip'], 0, strrpos($thapost['useip'], '.')).'.x';
		if($thapost['author'] && $thapost['anonymous']) {
			$thapost['author'] = '[i]Anonymous[/i]';
		} elseif(!$thapost['author']) {
			$thapost['author'] = '[i]Guest[/i] from '.$thapost['useip'];
		} else {
			$thapost['author'] = '[i]'.$thapost['author'].'[/i]';
		}
		$posttable = getposttablebytid($thapost['tid']);
		$thapost['number'] = DB::result_first("SELECT count(*) FROM ".DB::table($posttable)." WHERE tid='$thapost[tid]' AND dateline<='$thapost[dateline]'");
		$message = "[b]$language[post_reply] [url=$_G[siteurl]forum.php?mod=redirect&goto=findpost&pid=$_G[gp_reppost]&ptid=$thapost[tid]]$thapost[number]#[/url] $thapost[author] $language[post_thread][/b]\n\n\n    ";
		$noticeauthormsg = htmlspecialchars(messagecutstr($thapost['message'], 100));
		$noticeauthor = htmlspecialchars('r|'.$thapost['authorid'].'|'.$thapost['author']);
		$noticetrimstr = htmlspecialchars($message);

	}

	if(isset($_G['gp_addtrade']) && $thread['special'] == 2 && $_G['group']['allowposttrade'] && $thread['authorid'] == $_G['uid']) {
		$expiration_7days = date('Y-m-d', TIMESTAMP + 86400 * 7);
		$expiration_14days = date('Y-m-d', TIMESTAMP + 86400 * 14);
		$trade['expiration'] = $expiration_month = date('Y-m-d', mktime(0, 0, 0, date('m')+1, date('d'), date('Y')));
		$expiration_3months = date('Y-m-d', mktime(0, 0, 0, date('m')+3, date('d'), date('Y')));
		$expiration_halfyear = date('Y-m-d', mktime(0, 0, 0, date('m')+6, date('d'), date('Y')));
		$expiration_year = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y')+1));
	}

	if($thread['replies'] <= $_G['ppp']) {
		$postlist = array();
		$posttable = getposttablebytid($_G['tid']);
		$query = DB::query("SELECT p.* ".($_G['setting']['bannedmessages'] ? ', m.groupid ' : '').
			"FROM ".DB::table($posttable)." p ".($_G['setting']['bannedmessages'] ? "LEFT JOIN ".DB::table('common_member')." m ON p.authorid=m.uid " : '').
			"WHERE p.tid='$_G[tid]' AND p.invisible='0' ".($thread['price'] > 0 && $thread['special'] == 0 ? 'AND p.first = 0' : '')." ORDER BY p.dateline DESC");
		while($post = DB::fetch($query)) {

			$post['dateline'] = dgmdate($post['dateline'], 'u');

			if($_G['setting']['bannedmessages'] && ($post['authorid'] && (!$post['groupid'] || $post['groupid'] == 4 || $post['groupid'] == 5))) {
				$post['message'] = $language['post_banned'];
			} elseif($post['status'] & 1) {
				$post['message'] = $language['post_single_banned'];
			} else {
				$post['message'] = preg_replace("/\[hide=?\d*\](.+?)\[\/hide\]/is", "[b]$language[post_hidden][/b]", $post['message']);
				$post['message'] = discuzcode($post['message'], $post['smileyoff'], $post['bbcodeoff'], $post['htmlon'] & 1, $_G['forum']['allowsmilies'], $_G['forum']['allowbbcode'], $_G['forum']['allowimgcode'], $_G['forum']['allowhtml'], $_G['forum']['jammer']);
			}

			$postlist[] = $post;
		}
	}

	if($_G['group']['allowpostattach'] || $_G['group']['allowpostimage']) {
		$attachlist = getattach($pid);
		$attachs = $attachlist['attachs'];
		$imgattachs = $attachlist['imgattachs'];
		unset($attachlist);
	}

	getgpc('infloat') ? include template('forum/post_infloat') : include template('forum/post');

} else {
*/
	if($subject == '' && $message == '' && $thread['special'] != 2) {
//		showmessage('post_sm_isnull');
		exit('[err]'.lang('message', 'post_sm_isnull').'[/err]');
//	} elseif($thread['closed'] && !$_G['forum']['ismoderator']) {
//		showmessage('post_thread_closed');
//	} elseif($post_autoclose = checkautoclose($thread)) {
//		showmessage($post_autoclose, '', array('autoclose' => $_G['forum']['autoclose']));
	} elseif($post_invalid = checkpost($subject, $message, $special == 2 && $_G['group']['allowposttrade'])) {
//		showmessage($post_invalid, '', array('minpostsize' => $_G['setting']['minpostsize'], 'maxpostsize' => $_G['setting']['maxpostsize']));
		exit('[err]'.lang('message', $post_invalid,array('minpostsize' => $_G['setting']['minpostsize'], 'maxpostsize' => $_G['setting']['maxpostsize'])).'[/err]');
//	} elseif(checkflood()) {
//		showmessage('post_flood_ctrl', '', array('floodctrl' => $_G['setting']['floodctrl']));
	}
/*	if(!empty($_G['gp_trade']) && $thread['special'] == 2 && $_G['group']['allowposttrade']) {

		$item_price = floatval($_G['gp_item_price']);
		$item_credit = intval($_G['gp_item_credit']);
		if(!trim($_G['gp_item_name'])) {
			showmessage('trade_please_name');
		} elseif($_G['group']['maxtradeprice'] && $item_price > 0 && ($_G['group']['mintradeprice'] > $item_price || $_G['group']['maxtradeprice'] < $item_price)) {
			showmessage('trade_price_between', '', array('mintradeprice' => $_G['group']['mintradeprice'], 'maxtradeprice' => $_G['group']['maxtradeprice']));
		} elseif($_G['group']['maxtradeprice'] && $item_credit > 0 && ($_G['group']['mintradeprice'] > $item_credit || $_G['group']['maxtradeprice'] < $item_credit)) {
			showmessage('trade_credit_between', '', array('mintradeprice' => $_G['group']['mintradeprice'], 'maxtradeprice' => $_G['group']['maxtradeprice']));
		} elseif(!$_G['group']['maxtradeprice'] && $item_price > 0 && $_G['group']['mintradeprice'] > $item_price) {
			showmessage('trade_price_more_than', '', array('mintradeprice' => $_G['group']['mintradeprice']));
		} elseif(!$_G['group']['maxtradeprice'] && $item_credit > 0 && $_G['group']['mintradeprice'] > $item_credit) {
			showmessage('trade_credit_more_than', '', array('mintradeprice' => $_G['group']['mintradeprice']));
		} elseif($item_price <= 0 && $item_credit <= 0) {
			showmessage('trade_pricecredit_need');
		} elseif($_G['gp_item_number'] < 1) {
			showmessage('tread_please_number');
		}

	}
*/
	$attentionon = empty($_G['gp_attention_add']) ? 0 : 1;
	$attentionoff = empty($attention_remove) ? 0 : 1;

	if($thread['lastposter'] != $_G['member']['username']) {
		$posttable = getposttablebytid($_G['tid']);
		$userreplies = DB::result_first("SELECT COUNT(*) FROM ".DB::table($posttable)." WHERE tid='$_G[tid]' AND first='0' AND authorid='$_G[uid]'");
		$thread['heats'] += round($_G['setting']['heatthread']['reply'] * pow(0.8, $userreplies));
		$heatbefore = $thread['heats'];
		DB::query("UPDATE ".DB::table('forum_thread')." SET heats='$thread[heats]' WHERE tid='$_G[tid]'", 'UNBUFFERED');
	}

	$bbcodeoff = checkbbcodes($message, !empty($_G['gp_bbcodeoff']));
	$smileyoff = checksmilies($message, !empty($_G['gp_smileyoff']));
	$parseurloff = !empty($_G['gp_parseurloff']);
//	$htmlon = $_G['group']['allowhtml'] && !empty($_G['gp_htmlon']) ? 1 : 0;
	$htmlon = $_G['gp_htmlon']; //zzcityadd
	$usesig = !empty($_G['gp_usesig']) ? 1 : 0;

	$isanonymous = $_G['group']['allowanonymous'] && !empty($_G['gp_isanonymous'])? 1 : 0;
	$author = empty($isanonymous) ? $_G['username'] : '';

	$pinvisible = $modnewreplies ? -2 : 0;
	$message = preg_replace('/\[attachimg\](\d+)\[\/attachimg\]/is', '[attach]\1[/attach]', $message);
	$subject='';
	

	$pid = insertpost(array(
		'fid' => $_G['fid'],
		'tid' => $_G['tid'],
		'first' => '0',
		'author' => $_G['username'],
		'authorid' => $_G['uid'],
		'subject' => $subject,
		'dateline' => $zztimestamp,
		'message' => $message,
		'useip' => $_G['clientip'],
		'invisible' => $pinvisible,
		'anonymous' => $isanonymous,
		'usesig' => $usesig,
		'htmlon' => $htmlon,
		'bbcodeoff' => $bbcodeoff,
		'smileyoff' => $smileyoff,
		'parseurloff' => $parseurloff,
		'attachment' => '0',
	));
	$cacheposition = getstatus($thread['status'], 1);
	if($pid && $cacheposition) {
		savepostposition($_G['tid'], $pid);
	}

	$nauthorid = 0;
	if(!empty($_G['gp_noticeauthor']) && !$isanonymous && !$modnewreplies) {
		list($ac, $nauthorid, $nauthor) = explode('|', $_G['gp_noticeauthor']);
		if($nauthorid != $_G['uid']) {
			$noticeauthormsg = strip_tags($_G['gp_noticeauthormsg']);
			$postmsg = messagecutstr(stripslashes(str_replace($_G['gp_noticetrimstr'], '', $message)), 100);
			if($ac == 'q') {
				notification_add($nauthorid, 'post', 'repquote_noticeauthor', array(
					'tid' => $thread['tid'],
					'subject' => $thread['subject'],
					'noticeauthormsg' => $noticeauthormsg,
					'postmsg' => $postmsg,
					'fid' => $_G['fid'],
					'pid' => $pid,
				));
			} elseif($ac == 'r') {
				notification_add($nauthorid, 'post', 'reppost_noticeauthor', array(
					'tid' => $thread['tid'],
					'subject' => $thread['subject'],
					'noticeauthormsg' => $noticeauthormsg,
					'postmsg' => $postmsg,
					'fid' => $_G['fid'],
					'pid' => $pid,
				));
			}
		}
	}

/*	if($special == 5) {

		if(!DB::num_rows($standquery)) {
			if($stand == 1) {
				DB::query("UPDATE ".DB::table('forum_debate')." SET affirmdebaters=affirmdebaters+1 WHERE tid='$_G[tid]'");
			} elseif($stand == 2) {
				DB::query("UPDATE ".DB::table('forum_debate')." SET negadebaters=negadebaters+1 WHERE tid='$_G[tid]'");
			}
		} else {
			$stand = $firststand;
		}
		if($stand == 1) {
			DB::query("UPDATE ".DB::table('forum_debate')." SET affirmreplies=affirmreplies+1 WHERE tid='$_G[tid]'");
		} elseif($stand == 2) {
			DB::query("UPDATE ".DB::table('forum_debate')." SET negareplies=negareplies+1 WHERE tid='$_G[tid]'");
		}
		DB::query("INSERT INTO ".DB::table('forum_debatepost')." (tid, pid, uid, dateline, stand, voters, voterids) VALUES ('$_G[tid]', '$pid', '$_G[uid]', '$_G[timestamp]', '$stand', '0', '')");
	}
*/
	($_G['group']['allowpostattach'] || $_G['group']['allowpostimage']) && ($_G['gp_attachnew'] || $_G['gp_attachdel'] || $special == 2 && $_G['gp_tradeaid']) && updateattach($postattachcredits, $_G['tid'], $pid, $_G['gp_attachnew'], $_G['gp_attachdel']);

	$replymessage = 'post_reply_succeed';

/*	if($special == 2 && $_G['group']['allowposttrade'] && $thread['authorid'] == $_G['uid'] && !empty($_G['gp_trade']) && !empty($_G['gp_item_name'])) {

		require_once libfile('function/trade');
		trade_create(array(
			'tid' => $_G['tid'],
			'pid' => $pid,
			'aid' => $_G['gp_tradeaid'],
			'item_expiration' => $_G['gp_item_expiration'],
			'thread' => $thread,
			'discuz_uid' => $_G['uid'],
			'author' => $author,
			'seller' => empty($_G['gp_paymethod']) && $_G['gp_seller'] ? dhtmlspecialchars(trim($_G['gp_seller'])) : '',
			'item_name' => $_G['gp_item_name'],
			'item_price' => $_G['gp_item_price'],
			'item_number' => $_G['gp_item_number'],
			'item_quality' => $_G['gp_item_quality'],
			'item_locus' => $_G['gp_item_locus'],
			'transport' => $_G['gp_transport'],
			'postage_mail' => $_G['gp_postage_mail'],
			'postage_express' => $_G['gp_postage_express'],
			'postage_ems' => $_G['gp_postage_ems'],
			'item_type' => $_G['gp_item_type'],
			'item_costprice' => $_G['gp_item_costprice'],
			'item_credit' => $_G['gp_item_credit'],
			'item_costcredit' => $_G['gp_item_costcredit']
		));

		$replymessage = 'trade_add_succeed';

		if(!empty($_G['gp_tradeaid'])) {
			DB::query("UPDATE ".DB::table('forum_attachment')." SET tid='$_G[tid]', pid='$pid' WHERE aid='$_G[gp_tradeaid]' AND uid='$_G[uid]'");
		}

	}
*/
	if($specialextra) {

		@include_once DISCUZ_ROOT.'./source/plugin/'.$_G['setting']['threadplugins'][$specialextra]['module'].'.class.php';
		$classname = 'threadplugin_'.$specialextra;
		if(method_exists($classname, 'newreply_submit_end')) {
			$threadpluginclass = new $classname;
			$threadpluginclass->newreply_submit_end($_G['fid'], $_G['tid']);
		}

	}

	$_G['forum']['threadcaches'] && deletethreadcaches($_G['tid']);

	$param = array('fid' => $_G['fid'], 'tid' => $_G['tid'], 'pid' => $pid, 'from' => $_G['gp_from']);
//	if($modnewreplies) {
//		unset($param['pid']);
//		DB::query("UPDATE ".DB::table('forum_forum')." SET todayposts=todayposts+1 WHERE fid='$_G[fid]'", 'UNBUFFERED');
//		showmessage('post_reply_mod_succeed', "forum.php?mod=forumdisplay&fid=$_G[fid]", $param);
//	} else {

		DB::query("UPDATE ".DB::table('forum_thread')." SET lastposter='$author', lastpost='$zztimestamp', replies=replies+1 WHERE tid='$_G[tid]'", 'UNBUFFERED');

		updatepostcredits('+', $_G['uid'], 'reply', $_G['fid']);

		if($_G['forum']['status'] == 3) { //note 给群组用户累记发帖数 群组积分日志
			if($_G['forum']['closed'] > 1) {
				DB::query("UPDATE ".DB::table('forum_thread')." SET lastposter='$author', lastpost='$zztimestamp', replies=replies+1 WHERE tid='".$_G['forum']['closed']."'", 'UNBUFFERED');
			}
			DB::query("UPDATE ".DB::table('forum_groupuser')." SET replies=replies+1, lastupdate='".$zztimestamp."' WHERE uid='$_G[uid]' AND fid='$_G[fid]'");
			updateactivity($_G['fid'], 0);
			updategroupcreditlog($_G['fid'], $_G['uid']);
		}
		$lastpost = "$thread[tid]\t".addslashes($thread['subject'])."\t$zztimestamp\t$author";
		DB::query("UPDATE ".DB::table('forum_forum')." SET lastpost='$lastpost', posts=posts+1, todayposts=todayposts+1 WHERE fid='$_G[fid]'", 'UNBUFFERED');
		if($_G['forum']['type'] == 'sub') {
			DB::query("UPDATE ".DB::table('forum_forum')." SET lastpost='$lastpost' WHERE fid='".$_G['forum']['fup']."'", 'UNBUFFERED');
		}

		$feed = array();
		if(!empty($_G['gp_addfeed']) && $_G['forum']['allowfeed'] && !$isanonymous) {
			if($special == 2 && !empty($_G['gp_trade'])) {
				$feed['icon'] = 'goods';
				$feed['title_template'] = 'feed_thread_goods_title';
				if($_G['gp_item_price'] > 0) {
					if($_G['setting']['creditstransextra'][5] != -1 && $_G['gp_item_credit']) {
						$feed['body_template'] = 'feed_thread_goods_message_1';
					} else {
						$feed['body_template'] = 'feed_thread_goods_message_2';
					}
				} else {
					$feed['body_template'] = 'feed_thread_goods_message_3';
				}
				$feed['body_data'] = array(
					'itemname'=> "<a href=\"$_G[siteurl]forum.php?mod=viewthread&do=tradeinfo&tid=$_G[tid]&pid=$pid\">$_G[gp_item_name]</a>",
					'itemprice'=> $_G['gp_item_price'],
					'itemcredit'=> $_G['gp_item_credit'],
					'creditunit'=> $_G['setting']['extcredits'][$_G['setting']['creditstransextra'][5]]['unit'].$_G['setting']['extcredits'][$_G['setting']['creditstransextra'][5]]['title'],
				);
				if($_G['gp_tradeaid']) {
					$feed['images'] = array(getforumimg($_G['gp_tradeaid']));
					$feed['image_links'] = array("$_G[siteurl]forum.php?mod=viewthread&do=tradeinfo&tid=$_G[tid]&pid=$pid");
				}
			} elseif($special == 3 && $thread['authorid'] != $_G['uid']) {
				$feed['icon'] = 'reward';
				$feed['title_template'] = 'feed_reply_reward_title';
				$feed['title_data'] = array(
					'subject' => "<a href=\"$_G[siteurl]forum.php?mod=viewthread&tid=$_G[tid]\">$thread[subject]</a>",
					'author' => "<a href=\"home.php?mod=space&uid=$thread[authorid]\">$thread[author]</a>"
				);
			} elseif($special == 5 && $thread['authorid'] != $_G['uid']) {
				$feed['icon'] = 'debate';
				if($stand == 1) {
					$feed['title_template'] = 'feed_thread_debatevote_title_1';
				} elseif($stand == 2) {
					$feed['title_template'] = 'feed_thread_debatevote_title_2';
				} else {
					$feed['title_template'] = 'feed_thread_debatevote_title_3';
				}
				$feed['title_data'] = array(
					'subject' => "<a href=\"$_G[siteurl]forum.php?mod=viewthread&tid=$_G[tid]\">$thread[subject]</a>",
					'author' => "<a href=\"home.php?mod=space&uid=$thread[authorid]\">$thread[author]</a>"
				);
			} elseif($thread['authorid'] != $_G['uid']) {
				$post_url = "forum.php?mod=redirect&goto=findpost&pid=$pid&ptid=$_G[tid]";

				$feed['icon'] = 'post';	//note feed 类型
				$feed['title_template'] = !empty($thread['author']) ? 'feed_reply_title' : 'feed_reply_title_anonymous';	//note 标题模板
				$feed['title_data'] = array(
					'subject' => "<a href=\"$post_url\">$thread[subject]</a>",
					'author' => "<a href=\"home.php?mod=space&uid=$thread[authorid]\">$thread[author]</a>"
				);
				if(!empty($_G['forum_attachexist'])) {
					$firstaid = DB::result_first("SELECT aid FROM ".DB::table('forum_attachment')." WHERE pid='$pid' AND dateline>'0' AND isimage='1' ORDER BY dateline LIMIT 1");
					if($firstaid) {
						$feed['images'] = array(getforumimg($firstaid));
						$feed['image_links'] = array($post_url);
					}
				}
			}
			$feed['title_data']['hash_data'] = "tid{$_G[tid]}";
			postfeed($feed);
		}
		include_once libfile('function/stat');
		updatestat($thread['isgroup'] ? 'grouppost' : 'post');

//		$page = getstatus($thread['status'], 4) ? 1 : @ceil(($thread['special'] ? $thread['replies'] + 1 : $thread['replies'] + 2) / $_G['ppp']);

//		$url = empty($_POST['portal_referer'])?"forum.php?mod=viewthread&tid={$thread[tid]}&pid=$pid&page=$page&extra=$extra#pid$pid":$_POST['portal_referer'];
//		showmessage($replymessage, $url, $param);
		exit('[ok]replyno='.$_G['gp_replyno']); //zzcityadd

//	}

//}
//require_once libfile('post/newreply', 'include');替换结束



function check_allow_action($action = 'allowpost') {
	global $_G;
//	if(isset($_G['forum'][$action]) && $_G['forum'][$action] == -1) {
//		showmessage('forum_access_disallow');
//	}
}
//require DISCUZ_ROOT.'./source/module/forum/forum_'.$mod.'.php';替换结束

?>