<?php

@$vercode=''; //此处取值请自行修改

if(isset($_POST['vercode'])){
if ($_POST['vercode']!=$vercode){
 echo("[err]invalid vercode[/err]");
 exit();
}
}

foreach($_POST as $key=>$value){
        $_GET[$key]=$value;
}

$_GET['mod']='post'; //zzcityadd
$_GET['action']='newthread'; //zzcityadd
if(isset($_GET['adddynamic'])){
	$_POST['adddynamic'] =$_GET['adddynamic'] = trim($_GET['adddynamic'])=='' ? '1' : $_GET['adddynamic']; //zzcity add 如果未设置则默认转播
}else{
	$_POST['adddynamic'] =$_GET['adddynamic']='1';
}
if(isset($_GET['cronpublish'])){
	$_POST['cronpublish'] =$_GET['cronpublish'] = trim($_GET['cronpublish'])=='' ? '0' : $_GET['cronpublish']; //zzcity add 如果未设置则默认不预发布
}else{
	$_POST['cronpublish'] =$_GET['cronpublish']='0';
}

if($_GET['cronpublish']='1'){
	if(isset($_GET['cronpublishhour'])){
		$_GET['cronpublishhour']=empty($_GET['cronpublishhour']) ? 0 :intval($_GET['cronpublishhour']);
	}else{
		$_GET['cronpublishhour']=0;
	}
	if ($_GET['cronpublishhour']>0){
		$zzcrontime=time()+3600*$_GET['cronpublishhour'];
		$zzcron=getdate($zzcrontime);
		if($zzcron['minutes']>=30){
			$_POST['cronpublishdate']=$_GET['cronpublishdate']=date("Y-m-d H:30");	
		}else{
			$_POST['cronpublishdate']=$_GET['cronpublishdate']=date("Y-m-d H:00");	
		}
	}else{
		if(isset($_GET['cronpublishdate'])){
			$_POST['cronpublishdate'] =$_GET['cronpublishdate'] = trim($_GET['cronpublishdate'])=='' ? '' : $_GET['cronpublishdate']; //zzcity add 如果未设置则默认不预发布
		}else{
			$_POST['cronpublishdate'] =$_GET['cronpublishdate']='';
		}
		if($_POST['cronpublishdate']<>''){

			if (trim($_POST['cronpublishdate'])<>''){
				$_POST['cronpublishdate']=str_replace(array('年', '月'), '-',$_POST['cronpublishdate']);
				$_POST['cronpublishdate']=str_replace(array('日'), '',$_POST['cronpublishdate']);
				if ($_POST['cronpublishdate'] && strlen(trim( $_POST['cronpublishdate'] )) <= 10) {
				 $_POST['cronpublishdate'] .= date('H:i');
				}
				if (strtotime($_POST['cronpublishdate'])==false||strtotime($_POST['cronpublishdate'])==-1){
				 echo("[err]定时时间格式错误[/err]");
				 exit();
				}
				$_GET['cronpublishdate'] =$_POST['cronpublishdate'];
			}

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


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

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

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

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


define('CURMODULE', $mod);
$cachelist = array();
if(isset($modcachelist[CURMODULE])) {
 $cachelist = $modcachelist[CURMODULE];
}
if(C::app()->var['mod'] == 'group') {
	$_G['basescript'] = 'group';
}

C::app()->cachelist = $cachelist;
C::app()->init();

//zzcity add
$member = array();
$member = c::t('common_member')->fetch_by_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;
	loadcache('usergroup_'.$_G['groupid']);
	C::app()->session->isnew = true;
	C::app()->session->updatesession();

	dsetcookie('auth', authcode("{$member['password']}\t{$member['uid']}", 'ENCODE'), $cookietime, 1, true);
	dsetcookie('loginuser');
	dsetcookie('activationauth');
	dsetcookie('pmnum');

	include_once libfile('function/stat');
	updatestat('login', 1);
	if(defined('IN_MOBILE')) {
		updatestat('mobilelogin', 1);
	}
	if($_G['setting']['connect']['allow'] && $_G['member']['conisbind']) {
		updatestat('connectlogin', 1);
	}
	$rule = updatecreditbyaction('daylogin', $_G['uid']);
	if(!$rule['updatecredit']) {
		checkusergroup($_G['uid']);
	}
	$_G['gp_htmlon']=$_GET['htmlon'] = trim($_GET['htmlon'])=='' ? '1' : $_GET['htmlon'];
//zzcity
loadforum();

//zzcityadd
$_G['group']['allowhtml']=$_G['gp_htmlon'];
$_G['forum']['allowhtml']=$_G['gp_htmlon'];

$zzhour = !isset($_G['gp_zzhour']) ? '1' : intval($_G['gp_zzhour']); //zzcity add
$zztimestamp =$_G['timestamp']=time()-$zzhour*60*60; //zzcity add

//zzcity


set_rssauth();
//runhooks();
$navtitle = str_replace('{bbname}', $_G['setting']['bbname'], $_G['setting']['seotitle']['forum']);

//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'));

$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('post/threadsorts', 'include');
}

if($_G['forum']['status'] == 3) {
	if(!helper_access::check_module('group')) {
		showmessage('group_status_off');
	}
	require_once libfile('function/group');
	$status = groupperm($_G['forum'], $_G['uid'], 'post');
	if($status == -1) {
		//showmessage('forum_not_group', 'index.php');
		exit('[err]该版块不是群组[/err]');
	} elseif($status == 1) {
		//showmessage('forum_group_status_off');
		exit('[err]该群组已经关闭[/err]');
	} elseif($status == 2) {
		//showmessage('forum_group_noallowed', "forum.php?mod=group&fid=$_G[fid]");
		exit('[err]您没有权限访问该群组[/err]');
	} elseif($status == 3) {
		//showmessage('forum_group_moderated', "forum.php?mod=group&fid=$_G[fid]");
		exit('[err]请等待群主审核[/err]');
	} elseif($status == 4) {
		if($_G['uid']) {
			//showmessage('forum_group_not_groupmember', "", array('fid' => $_G['fid']), array('showmsg' => 1));
			exit('[err]非本群组成员不能发帖[/err]');
		} else {
			//showmessage('forum_group_not_groupmember_guest', "", array('fid' => $_G['fid']), array('showmsg' => 1, 'login' => 1));
			exit('[err]非本群组成员不能发帖[/err]');
		}
	} elseif($status == 5) {
		//showmessage('forum_group_moderated', "", array('fid' => $_G['fid']), array('showmsg' => 1));
		exit('[err]请等待群主审核[/err]');
	}
}

/*
if(empty($_GET['action'])) {
	showmessage('undefined_action', NULL);
} elseif($_GET['action'] == 'albumphoto') {
	require libfile('post/albumphoto', 'include');
} elseif(($_G['forum']['simple'] & 1) || $_G['forum']['redirect']) {
	showmessage('forum_disablepost');
}
*/
require_once libfile('function/discuzcode');
$space = array();
space_merge($space, 'field_home');

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


$navigation = $navtitle = '';

if(!empty($_GET['cedit'])) {
	unset($_G['inajax'], $_GET['infloat'], $_GET['ajaxtarget'], $_GET['handlekey']);
}
/*
if($_GET['action'] == 'edit' || $_GET['action'] == 'reply') {

	$thread = C::t('forum_thread')->fetch($_G['tid']);
	if(!$_G['forum_auditstatuson'] && !($thread['displayorder']>=0 || (in_array($thread['displayorder'], array(-4, -2)) && $thread['authorid']==$_G['uid']))) {
		$thread = array();
	}
	if(!empty($thread)) {

		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($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($_GET['extra']) ? '&action=list&'.preg_replace("/^(&)*/", '', $_GET['extra']) : '').'#groupnav';
	$nav = get_groupnav($_G['forum']);
	$navigation = ' <em>&rsaquo;</em> <a href="group.php">'.$_G['setting']['navs'][3]['navname'].'</a> '.$nav['nav'];
} else {
	loadcache('forums');
	$returnurl = 'forum.php?mod=forumdisplay&fid='.$_G['fid'].(!empty($_GET['extra']) ? '&'.preg_replace("/^(&)*/", '', $_GET['extra']) : '');
	$navigation = ' <em>&rsaquo;</em> <a href="forum.php">'.$_G['setting']['navs'][2]['navname'].'</a>';

	if($_G['forum']['type'] == 'sub') {
		$fup = $_G['cache']['forums'][$_G['forum']['fup']]['fup'];
		$t_link = $_G['cache']['forums'][$fup]['type'] == 'group' ? 'forum.php?gid='.$fup : 'forum.php?mod=forumdisplay&fid='.$fup;
		$navigation .= ' <em>&rsaquo;</em> <a href="'.$t_link.'">'.($_G['cache']['forums'][$fup]['name']).'</a>';
	}

	if($_G['forum']['fup']) {
		$fup = $_G['forum']['fup'];
		$t_link = $_G['cache']['forums'][$fup]['type'] == 'group' ? 'forum.php?gid='.$fup : 'forum.php?mod=forumdisplay&fid='.$fup;
		$navigation .= ' <em>&rsaquo;</em> <a href="'.$t_link.'">'.($_G['cache']['forums'][$fup]['name']).'</a>';
	}

	$t_link = 'forum.php?mod=forumdisplay&fid='.$_G['fid'].($_GET['extra'] && !IS_ROBOT ? '&'.$_GET['extra'] : '');
	$navigation .= ' <em>&rsaquo;</em> <a href="'.$t_link.'">'.($_G['forum']['name']).'</a>';

	unset($t_link, $t_name);
}

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'] * 60) && TIMESTAMP - $_G['member']['regdate'] < $_G['setting']['newbiespan'] * 60) {
 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'];
require_once libfile('function/upload');
$swfconfig = getuploadconfig($_G['uid'], $_G['fid']);
$imgexts = str_replace(array(';', '*.'), array(', ', ''), $swfconfig['imageexts']['ext']);
$allowuploadnum = $allowuploadtoday = TRUE;
if($_G['group']['allowpostattach'] || $_G['group']['allowpostimage']) {
 if($_G['group']['maxattachnum']) {
  $allowuploadnum = $_G['group']['maxattachnum'] - getuserprofile('todayattachs');
  $allowuploadnum = $allowuploadnum < 0 ? 0 : $allowuploadnum;
  if(!$allowuploadnum) {
   $allowuploadtoday = false;
  }
 }
 if($_G['group']['maxsizeperday']) {
  $allowuploadsize = $_G['group']['maxsizeperday'] - getuserprofile('todayattachsize');
  $allowuploadsize = $allowuploadsize < 0 ? 0 : $allowuploadsize;
  if(!$allowuploadsize) {
   $allowuploadtoday = false;
  }
  $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';

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

$extra = !empty($_GET['extra']) ? rawurlencode($_GET['extra']) : '';
$notifycheck = empty($emailnotify) ? '' : 'checked="checked"';
$stickcheck = empty($sticktopic) ? '' : 'checked="checked"';
$digestcheck = empty($addtodigest) ? '' : 'checked="checked"';

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

	$message=addslashes($message);

$polloptions = isset($polloptions) ? censor(trim($polloptions)) : '';
$readperm = isset($_GET['readperm']) ? intval($_GET['readperm']) : 0;
$price = isset($_GET['price']) ? intval($_GET['price']) : 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');
}
*/
$modnewthreads = $modnewreplies = 0;
if(($subject || $message) && empty($_GET['save'])) {
	$extramessage = ($special == 5 ? "\t".$_GET['affirmpoint']."\t".$_GET['negapoint'] : '').
					($special == 4 ? "\t".$_GET['activityplace']."\t".$_GET['activitycity']."\t".$_GET['activityclass'] : '').
					($special == 2 ? "\t".$_GET['item_name']."\t".$_GET['item_locus'] : '').
					($_GET['typeoption'] ? "\t".implode("\t", $_GET['typeoption']) : '').
					($_GET['polloptions'] || $_GET['polloption'] ? ("\t".implode("\t", $_GET['tpolloption'] == 2 ? explode("\n", $_GET['polloptions']) : $_GET['polloption'])) : '');
	list($modnewthreads, $modnewreplies) = threadmodstatus($subject."\t".$message.$extramessage);
	unset($extramessage);
}

$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);
$_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($_GET['specialextra']) ? $_GET['specialextra'] : '';
$_G['forum']['threadplugin'] = dunserialize($_G['forum']['threadplugin']);

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'] : dunserialize($_G['forum']['threadplugin'])) ||
	!@in_array($specialextra, $_G['group']['allowthreadplugin']))) {
	$specialextra = '';
}
if($special == 3 && !isset($_G['setting']['extcredits'][$_G['setting']['creditstrans']])) {
	//showmessage('reward_credits_closed');
	exit('[err]交易积分被关闭，请联系管理员[/err]');
}

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

if($_GET['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']) {
		$threadpluginary = array_intersect($_G['forum']['threadplugin'], $_G['group']['allowthreadplugin']);
		$specialextra = in_array($specialextra, $threadpluginary) ? $specialextra : '';
	}

 if(!$special && !$specialextra) {
  //showmessage('group_nopermission', NULL, array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1));
    exit('[err]您所在的用户组无法进行此操作[/err]');
 }
}

if(!$sortid && !$specialextra) {
 $postspecialcheck[$special] = ' class="a"';
}


$editorid = 'e';
$_G['setting']['editoroptions'] = str_pad(decbin($_G['setting']['editoroptions']), 3, 0, STR_PAD_LEFT);
$editormode = $_G['setting']['editoroptions']{0};
$allowswitcheditor = $_G['setting']['editoroptions']{1};
$editor = array(
 'editormode' => $editormode,
 'allowswitcheditor' => $allowswitcheditor,
 'allowhtml' => $_G['forum']['allowhtml'],
 'allowsmilies' => $_G['forum']['allowsmilies'],
 'allowbbcode' => $_G['forum']['allowbbcode'],
 'allowimgcode' => $_G['forum']['allowimgcode'],
 'allowresize' => 1,
 'allowchecklength' => 1,
 'allowtopicreset' => 1,
 'textarea' => 'message',
 'simplemode' => !isset($_G['cookie']['editormode_'.$editorid]) ? !$_G['setting']['editoroptions']{2} : $_G['cookie']['editormode_'.$editorid],
);
if($specialextra) {
 $special = 127;
}

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

$albumlist = array();
if(helper_access::check_module('album') && $_G['group']['allowupload'] && $_G['uid']) {
	$query = C::t('home_album')->fetch_all_by_uid($_G['uid'], 'updatetime');
	foreach($query as $value) {
		if($value['picnum']) {
			$albumlist[] = $value;
		}
	}
}

$posturl = "action=$_GET[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($_GET['firstpid']) ? "&firstpid=$firstpid" : '').
	(!empty($_GET['addtrade']) ? "&addtrade=$addtrade" : '');

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

if($special == 4) {
	$_G['setting']['activityfield'] = $_G['setting']['activityfield'] ? dunserialize($_G['setting']['activityfield']) : array();
}
if(helper_access::check_module('album') && $_G['group']['allowupload'] && $_G['setting']['albumcategorystat'] && !empty($_G['cache']['albumcategory'])) {
	require_once libfile('function/portalcp');
}
$navtitle = lang('core', 'title_'.$_GET['action'].'_post');

/*
if($_GET['action'] == 'newthread') {
	loadcache('groupreadaccess');
	$navtitle .= ' - '.$_G['forum']['name'];
	require_once libfile('post/newthread', 'include');
} elseif($_GET['action'] == 'reply') {
	$navtitle .= ' - '.$thread['subject'].' - '.$_G['forum']['name'];
	require_once libfile('post/newreply', 'include');
} elseif($_GET['action'] == 'edit') {
	loadcache('groupreadaccess');
	$navtitle .= ' - '.$thread['subject'].' - '.$_G['forum']['name'];
	require_once libfile('post/editpost', 'include');
} elseif($_GET['action'] == 'newtrade') {
	$navtitle .= ' - '.$_G['forum']['name'];
	require_once libfile('post/newtrade', 'include');
}
*/

//require_once libfile('post/newthread', 'include');替换开始
//if(!defined('IN_DISCUZ')) {
// exit('Access Denied');
//}
//
if(empty($_G['forum']['fid']) || $_G['forum']['type'] == 'group') {
// showmessage('forum_nonexistence');
 exit('[err]'.lang('message', 'forum_nonexistence').'[/err]');
}

if(($special == 1 && !$_G['group']['allowpostpoll']) || ($special == 2 && !$_G['group']['allowposttrade']) || ($special == 3 && !$_G['group']['allowpostreward']) || ($special == 4 && !$_G['group']['allowpostactivity']) || ($special == 5 && !$_G['group']['allowpostdebate'])) {
// showmessage('group_nopermission', NULL, array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1));
 exit('[err]'.lang('message', 'group_nopermission',array('grouptitle' => $_G['group']['grouptitle'])).'[/err]');
}

/*if(!$_G['uid'] && !((!$_G['forum']['postperm'] && $_G['group']['allowpost']) || ($_G['forum']['postperm'] && forumperm($_G['forum']['postperm'])))) {
 if(!defined('IN_MOBILE')) {
  showmessage('postperm_login_nopermission', NULL, array(), array('login' => 1));
 } else {
  showmessage('postperm_login_nopermission_mobile', NULL, array('referer' => rawurlencode(dreferer())), array('login' => 1));
 }
} elseif(empty($_G['forum']['allowpost'])) {
 if(!$_G['forum']['postperm'] && !$_G['group']['allowpost']) {
  showmessage('postperm_none_nopermission', NULL, array(), array('login' => 1));
 } elseif($_G['forum']['postperm'] && !forumperm($_G['forum']['postperm'])) {
  showmessagenoperm('postperm', $_G['fid'], $_G['forum']['formulaperm']);
 }
} elseif($_G['forum']['allowpost'] == -1) {
 showmessage('post_forum_newthread_nopermission', NULL);
}

if(!$_G['uid'] && ($_G['setting']['need_avatar'] || $_G['setting']['need_email'] || $_G['setting']['need_friendnum'])) {
 showmessage('postperm_login_nopermission', NULL, array(), array('login' => 1));
}
*/
//checklowerlimit('post', 0, 1, $_G['forum']['fid']);

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

 $savethreads = array();
 $savethreadothers = array();
	foreach(C::t('forum_post')->fetch_all_by_authorid(0, $_G['uid'], false, '', 0, 20, 1, -3) as $savethread) {
  $savethread['dateline'] = dgmdate($savethread['dateline'], 'u');
  if($_G['fid'] == $savethread['fid']) {
   $savethreads[] = $savethread;
  } else {
   $savethreadothers[] = $savethread;
  }
 }
 $savethreadcount = count($savethreads);
 $savethreadothercount = count($savethreadothers);
 if($savethreadothercount) {
  loadcache('forums');
 }
 $savecount = $savethreadcount + $savethreadothercount;
 unset($savethread);

 $isfirstpost = 1;
 $allownoticeauthor = 1;
 $tagoffcheck = '';
 $showthreadsorts = !empty($sortid) || $_G['forum']['threadsorts']['required'] && empty($special);
 if(empty($sortid) && empty($special) && $_G['forum']['threadsorts']['required'] && $_G['forum']['threadsorts']['types']) {
  $tmp = array_keys($_G['forum']['threadsorts']['types']);
  $sortid = $tmp[0];

		require_once libfile('post/threadsorts', 'include');
	}

 if($special == 2 && $_G['group']['allowposttrade']) {

  $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));

 } elseif($specialextra) {

  $threadpluginclass = null;
  if(isset($_G['setting']['threadplugins'][$specialextra]['module'])) {
   $threadpluginfile = DISCUZ_ROOT.'./source/plugin/'.$_G['setting']['threadplugins'][$specialextra]['module'].'.class.php';
   if(file_exists($threadpluginfile)) {
    @include_once $threadpluginfile;
    $classname = 'threadplugin_'.$specialextra;
    if(class_exists($classname) && method_exists($threadpluginclass = new $classname, 'newthread')) {
     $threadplughtml = $threadpluginclass->newthread($_G['fid']);
     $buttontext = lang('plugin/'.$specialextra, $threadpluginclass->buttontext);
     $iconfile = $threadpluginclass->iconfile;
     $iconsflip = array_flip($_G['cache']['icons']);
     $thread['iconid'] = $iconsflip[$iconfile];
    }
   }
  }

  if(!is_object($threadpluginclass)) {
   $specialextra = '';
  }
 }

 if($special == 4) {
  $activity = array('starttimeto' => '', 'starttimefrom' => '', 'place' => '', 'class' => '', 'cost' => '', 'number' => '', 'gender' => '', 'expiration' => '');
  $activitytypelist = $_G['setting']['activitytype'] ? explode("\n", trim($_G['setting']['activitytype'])) : '';
 }

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

 !isset($attachs['unused']) && $attachs['unused'] = array();
 !isset($imgattachs['unused']) && $imgattachs['unused'] = array();

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

} else {
*/
 if(trim($subject) == '') {
		$subject = cutstr($message, 75, '');
 }

 if(!$sortid && !$special && trim($message) == '') {
//  showmessage('post_sm_isnull');
  exit('[err]'.lang('message', 'post_sm_isnull').'[/err]');
 }

 if($post_invalid = checkpost($subject, $message, ($special || $sortid))) {
//  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]');
 }

/* if(checkflood()) {
  showmessage('post_flood_ctrl', '', array('floodctrl' => $_G['setting']['floodctrl']));
	} elseif(checkmaxperhour('tid')) {
		showmessage('thread_flood_ctrl_threads_per_hour', '', array('threads_per_hour' => $_G['group']['maxthreadsperhour']));
 }
*/ 
	$_GET['save'] = $_G['uid'] ? $_GET['save'] : 0;

	if ($_G['group']['allowsetpublishdate'] && $_GET['cronpublish'] && $_GET['cronpublishdate']) {
		$publishdate = strtotime($_GET['cronpublishdate']);
		if ($publishdate > $_G['timestamp']) {
			$_GET['save'] = 1;
		} else {
			$publishdate = $_G['timestamp'];
		}
	} else {
		$publishdate = $_G['timestamp'];
	}

	$typeid = isset($typeid) && isset($_G['forum']['threadtypes']['types'][$typeid]) && (empty($_G['forum']['threadtypes']['moderators'][$typeid]) || $_G['forum']['ismoderator']) ? $typeid : 0;
	$displayorder = $modnewthreads ? -2 : (($_G['forum']['ismoderator'] && $_G['group']['allowstickthread'] && !empty($_GET['sticktopic'])) ? 1 : (empty($_GET['save']) ? 0 : -4));
	if($displayorder == -2) {
		C::t('forum_forum')->update($_G['fid'], array('modworks' => '1'));
	} elseif($displayorder == -4) {
		$_GET['addfeed'] = 0;
	}

	$digest = $_G['forum']['ismoderator'] && $_G['group']['allowdigestthread'] && !empty($_GET['addtodigest']) ? 1 : 0;
	$readperm = $_G['group']['allowsetreadperm'] ? $readperm : 0;
	$isanonymous = $_G['group']['allowanonymous'] && $_GET['isanonymous'] ? 1 : 0;
 $price = intval($price);
 //$price = $_G['group']['maxprice'] && !$special ? ($price <= $_G['group']['maxprice'] ? $price : $_G['group']['maxprice']) : 0;
 $maxclick =isset($_POST["maxclick"]) && !empty($_POST["maxclick"]) ? intval($_POST["maxclick"]):200;
/* if(!$typeid && $_G['forum']['threadtypes']['required'] && !$special) {
  showmessage('post_type_isnull');
 }
*/
/* if(!$sortid && $_G['forum']['threadsorts']['required'] && !$special) {
  showmessage('post_sort_isnull');
 }
*/
 if($price > 0 && floor($price * (1 - $_G['setting']['creditstax'])) == 0) {
//  showmessage('post_net_price_iszero');
  exit('[err]'.lang('message', 'post_net_price_iszero').'[/err]');
 }

/* if($special == 1) {

		$polloption = $_GET['tpolloption'] == 2 ? explode("\n", $_GET['polloptions']) : $_GET['polloption'];
  $pollarray = array();
  foreach($polloption as $key => $value) {
   $polloption[$key] = censor($polloption[$key]);
   if(trim($value) === '') {
    unset($polloption[$key]);
   }
  }

  if(count($polloption) > $_G['setting']['maxpolloptions']) {
   showmessage('post_poll_option_toomany', '', array('maxpolloptions' => $_G['setting']['maxpolloptions']));
  } elseif(count($polloption) < 2) {
   showmessage('post_poll_inputmore');
  }

  $curpolloption = count($polloption);
		$pollarray['maxchoices'] = empty($_GET['maxchoices']) ? 0 : ($_GET['maxchoices'] > $curpolloption ? $curpolloption : $_GET['maxchoices']);
		$pollarray['multiple'] = empty($_GET['maxchoices']) || $_GET['maxchoices'] == 1 ? 0 : 1;
		$pollarray['options'] = $polloption;
		$pollarray['visible'] = empty($_GET['visibilitypoll']);
		$pollarray['overt'] = !empty($_GET['overt']);

		if(preg_match("/^\d*$/", trim($_GET['expiration']))) {
			if(empty($_GET['expiration'])) {
				$pollarray['expiration'] = 0;
			} else {
				$pollarray['expiration'] = TIMESTAMP + 86400 * $_GET['expiration'];
   }
  } else {
   showmessage('poll_maxchoices_expiration_invalid');
  }

 } elseif($special == 3) {

		$rewardprice = intval($_GET['rewardprice']);
  if($rewardprice < 1) {
   showmessage('reward_credits_please');
  } elseif($rewardprice > 32767) {
   showmessage('reward_credits_overflow');
  } elseif($rewardprice < $_G['group']['minrewardprice'] || ($_G['group']['maxrewardprice'] > 0 && $rewardprice > $_G['group']['maxrewardprice'])) {
   if($_G['group']['maxrewardprice'] > 0) {
    showmessage('reward_credits_between', '', array('minrewardprice' => $_G['group']['minrewardprice'], 'maxrewardprice' => $_G['group']['maxrewardprice']));
   } else {
    showmessage('reward_credits_lower', '', array('minrewardprice' => $_G['group']['minrewardprice']));
   }
  } elseif(($realprice = $rewardprice + ceil($rewardprice * $_G['setting']['creditstax'])) > getuserprofile('extcredits'.$_G['setting']['creditstransextra'][2])) {
   showmessage('reward_credits_shortage');
  }
  $price = $rewardprice;

 } elseif($special == 4) {

		$activitytime = intval($_GET['activitytime']);
		if(empty($_GET['starttimefrom'][$activitytime])) {
			showmessage('activity_fromtime_please');
		} elseif(@strtotime($_GET['starttimefrom'][$activitytime]) === -1 || @strtotime($_GET['starttimefrom'][$activitytime]) === FALSE) {
			showmessage('activity_fromtime_error');
		} elseif($activitytime && ((@strtotime($_GET['starttimefrom']) > @strtotime($_GET['starttimeto']) || !$_GET['starttimeto']))) {
			showmessage('activity_fromtime_error');
		} elseif(!trim($_GET['activityclass'])) {
			showmessage('activity_sort_please');
		} elseif(!trim($_GET['activityplace'])) {
			showmessage('activity_address_please');
		} elseif(trim($_GET['activityexpiration']) && (@strtotime($_GET['activityexpiration']) === -1 || @strtotime($_GET['activityexpiration']) === FALSE)) {
			showmessage('activity_totime_error');
		}

		$activity = array();
		$activity['class'] = censor(dhtmlspecialchars(trim($_GET['activityclass'])));
		$activity['starttimefrom'] = @strtotime($_GET['starttimefrom'][$activitytime]);
		$activity['starttimeto'] = $activitytime ? @strtotime($_GET['starttimeto']) : 0;
		$activity['place'] = censor(dhtmlspecialchars(trim($_GET['activityplace'])));
		$activity['cost'] = intval($_GET['cost']);
		$activity['gender'] = intval($_GET['gender']);
		$activity['number'] = intval($_GET['activitynumber']);

		if($_GET['activityexpiration']) {
			$activity['expiration'] = @strtotime($_GET['activityexpiration']);
		} else {
			$activity['expiration'] = 0;
		}
		if(trim($_GET['activitycity'])) {
			$subject .= '['.dhtmlspecialchars(trim($_GET['activitycity'])).']';
		}
		$extfield = $_GET['extfield'];
		$extfield = explode("\n", $_GET['extfield']);
		foreach($extfield as $key => $value) {
			$extfield[$key] = censor(trim($value));
			if($extfield[$key] === '' || is_numeric($extfield[$key])) {
				unset($extfield[$key]);
			}
		}
		$extfield = array_unique($extfield);
		if(count($extfield) > $_G['setting']['activityextnum']) {
			showmessage('post_activity_extfield_toomany', '', array('maxextfield' => $_G['setting']['activityextnum']));
		}
		$activity['ufield'] = array('userfield' => $_GET['userfield'], 'extfield' => $extfield);
		$activity['ufield'] = serialize($activity['ufield']);
		if(intval($_GET['activitycredit']) > 0) {
			$activity['credit'] = intval($_GET['activitycredit']);
		}
	} elseif($special == 5) {

		if(empty($_GET['affirmpoint']) || empty($_GET['negapoint'])) {
			showmessage('debate_position_nofound');
		} elseif(!empty($_GET['endtime']) && (!($endtime = @strtotime($_GET['endtime'])) || $endtime < TIMESTAMP)) {
			showmessage('debate_endtime_invalid');
		} elseif(!empty($_GET['umpire'])) {
			if(!C::t('common_member')->fetch_uid_by_username($_GET['umpire'])) {
				$_GET['umpire'] = dhtmlspecialchars($_GET['umpire']);
				showmessage('debate_umpire_invalid', '', array('umpire' => $umpire));
			}
		}
		$affirmpoint = censor(dhtmlspecialchars($_GET['affirmpoint']));
		$negapoint = censor(dhtmlspecialchars($_GET['negapoint']));
		$stand = censor(intval($_GET['stand']));

 } else
*/ if($specialextra) {

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

 }

	$sortid = $special && $_G['forum']['threadsorts']['types'][$sortid] ? 0 : $sortid;
	$typeexpiration = intval($_GET['typeexpiration']);

/* if($_G['forum']['threadsorts']['expiration'][$typeid] && !$typeexpiration) {
  showmessage('threadtype_expiration_invalid');
 }
*/
 $_G['forum_optiondata'] = array();
 if($_G['forum']['threadsorts']['types'][$sortid] && !$_G['forum']['allowspecialonly']) {
		$_G['forum_optiondata'] = threadsort_validator($_GET['typeoption'], $pid);
 }

 $author = !$isanonymous ? $_G['username'] : '';

 $moderated = $digest || $displayorder > 0 ? 1 : 0;

 $thread['status'] = 0;

	$_GET['ordertype'] && $thread['status'] = setstatus(4, 1, $thread['status']);

	$_GET['hiddenreplies'] && $thread['status'] = setstatus(2, 1, $thread['status']);

	if($_G['group']['allowpostrushreply'] && $_GET['rushreply']) {
		$_GET['rushreplyfrom'] = strtotime($_GET['rushreplyfrom']);
		$_GET['rushreplyto'] = strtotime($_GET['rushreplyto']);
		$_GET['rewardfloor'] = trim($_GET['rewardfloor']);
		$_GET['stopfloor'] = intval($_GET['stopfloor']);
		$_GET['creditlimit'] = $_GET['creditlimit'] == '' ? '-996' : intval($_GET['creditlimit']);
		if($_GET['rushreplyfrom'] > $_GET['rushreplyto'] && !empty($_GET['rushreplyto'])) {
			showmessage('post_rushreply_timewrong');
		}
		if(($_GET['rushreplyfrom'] > $_G['timestamp']) || (!empty($_GET['rushreplyto']) && $_GET['rushreplyto'] < $_G['timestamp']) || ($_GET['stopfloor'] == 1) ) {
			$closed = true;
		}
		if(!empty($_GET['rewardfloor']) && !empty($_GET['stopfloor'])) {
			$floors = explode(',', $_GET['rewardfloor']);
			if(!empty($floors) && is_array($floors)) {
				foreach($floors AS $key => $floor) {
					if(strpos($floor, '*') === false) {
						if(intval($floor) == 0) {
							unset($floors[$key]);
						} elseif($floor > $_GET['stopfloor']) {
							unset($floors[$key]);
						}
					}
				}
				$_GET['rewardfloor'] = implode(',', $floors);
			}
		}
		$thread['status'] = setstatus(3, 1, $thread['status']);
		$thread['status'] = setstatus(1, 1, $thread['status']);
	}
	$_GET['allownoticeauthor'] && $thread['status'] = setstatus(6, 1, $thread['status']);
	$isgroup = $_G['forum']['status'] == 3 ? 1 : 0;

	if($_G['group']['allowreplycredit']) {
		$_GET['replycredit_extcredits'] = intval($_GET['replycredit_extcredits']);
		$_GET['replycredit_times'] = intval($_GET['replycredit_times']);
		$_GET['replycredit_membertimes'] = intval($_GET['replycredit_membertimes']);
		$_GET['replycredit_random'] = intval($_GET['replycredit_random']);

		$_GET['replycredit_random'] = $_GET['replycredit_random'] < 0 || $_GET['replycredit_random'] > 99 ? 0 : $_GET['replycredit_random'] ;
		$replycredit = $replycredit_real = 0;
		if($_GET['replycredit_extcredits'] > 0 && $_GET['replycredit_times'] > 0) {
			$replycredit_real = ceil(($_GET['replycredit_extcredits'] * $_GET['replycredit_times']) + ($_GET['replycredit_extcredits'] * $_GET['replycredit_times'] *  $_G['setting']['creditstax']));
			if($replycredit_real > getuserprofile('extcredits'.$_G['setting']['creditstransextra'][10])) {
				showmessage('replycredit_morethan_self');
			} else {
				$replycredit = ceil($_GET['replycredit_extcredits'] * $_GET['replycredit_times']);
			}
		}
	}

  $views=rand(30,$maxclick); //zzcityadd
	$newthread = array(
		'fid' => $_G['fid'],
		'posttableid' => 0,
		'readperm' => $readperm,
		'price' => $price,
		'typeid' => $typeid,
		'sortid' => $sortid,
		'author' => $author,
		'authorid' => $_G['uid'],
		'subject' => $subject,
		'dateline' => $publishdate,
		'lastpost' => $publishdate,
		'lastposter' => $author,
		'displayorder' => $displayorder,
		'digest' => $digest,
		'special' => $special,
		'attachment' => 0,
		'moderated' => $moderated,
		'status' => $thread['status'],
		'isgroup' => $isgroup,
		'replycredit' => $replycredit,
		'closed' => $closed ? 1 : 0,
		'views' => $views //zzcity add
	);
	$tid = C::t('forum_thread')->insert($newthread, true);
 useractionlog($_G['uid'], 'tid');
	if(!getuserprofile('threads') && $_G['setting']['newbie']) {
		C::t('forum_thread')->update($tid, array('icon' => $_G['setting']['newbie']));
	}
	if ($publishdate != $_G['timestamp']) {
		loadcache('cronpublish');
		$cron_publish_ids = dunserialize($_G['cache']['cronpublish']);
		$cron_publish_ids[$tid] = $tid;
		$cron_publish_ids = serialize($cron_publish_ids);
		savecache('cronpublish', $cron_publish_ids);
	}


	if(!$isanonymous) {
		C::t('common_member_field_home')->update($_G['uid'], array('recentnote'=>$subject));
	}

 if($special == 3 && $_G['group']['allowpostreward']) {
  updatemembercount($_G['uid'], array($_G['setting']['creditstransextra'][2] => -$realprice), 1, 'RTC', $tid);
 }

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

/* if($special == 1) {//note 投票入库
		foreach($pollarray['options'] as $polloptvalue) {
			$polloptvalue = dhtmlspecialchars(trim($polloptvalue));
			C::t('forum_polloption')->insert(array('tid' => $tid, 'polloption' => $polloptvalue));
		}
		$polloptionpreview = '';
		$query = C::t('forum_polloption')->fetch_all_by_tid($tid, 1, 2);
		foreach($query as $option) {
			$polloptvalue = preg_replace("/\[url=(https?){1}:\/\/([^\[\"']+?)\](.+?)\[\/url\]/i", "<a href=\"\\1://\\2\" target=\"_blank\">\\3</a>", $option['polloption']);
			$polloptionpreview .= $polloptvalue."\t";
		}

		$polloptionpreview = daddslashes($polloptionpreview);

		$data = array('tid' => $tid, 'multiple' => $pollarray['multiple'], 'visible' => $pollarray['visible'], 'maxchoices' => $pollarray['maxchoices'], 'expiration' => $pollarray['expiration'], 'overt' => $pollarray['overt'], 'pollpreview' => $polloptionpreview);
		C::t('forum_poll')->insert($data);
	} elseif($special == 4 && $_G['group']['allowpostactivity']) {
		$data = array('tid' => $tid, 'uid' => $_G['uid'], 'cost' => $activity['cost'], 'starttimefrom' => $activity['starttimefrom'], 'starttimeto' => $activity['starttimeto'], 'place' => $activity['place'], 'class' => $activity['class'], 'gender' => $activity['gender'], 'number' => $activity['number'], 'expiration' => $activity['expiration'], 'aid' => $_GET['activityaid'], 'ufield' => $activity['ufield'], 'credit' => $activity['credit']);
		C::t('forum_activity')->insert($data);

	} elseif($special == 5 && $_G['group']['allowpostdebate']) {

		C::t('forum_debate')->insert(array(
		    'tid' => $tid,
		    'uid' => $_G['uid'],
		    'starttime' => $publishdate,
		    'endtime' => $endtime,
		    'affirmdebaters' => 0,
		    'negadebaters' => 0,
		    'affirmvotes' => 0,
		    'negavotes' => 0,
		    'umpire' => $_GET['umpire'],
		    'winner' => '',
		    'bestdebater' => '',
		    'affirmpoint' => $affirmpoint,
		    'negapoint' => $negapoint,
		    'umpirepoint' => ''
		));

 } else
*/ if($special == 127) {

  $message .= chr(0).chr(0).chr(0).$specialextra;

 }

	if($_G['forum']['threadsorts']['types'][$sortid] && !empty($_G['forum_optiondata']) && is_array($_G['forum_optiondata'])) {
		$filedname = $valuelist = $separator = '';
		foreach($_G['forum_optiondata'] as $optionid => $value) {
			if($value) {
				$filedname .= $separator.$_G['forum_optionlist'][$optionid]['identifier'];
				$valuelist .= $separator."'".daddslashes($value)."'";
				$separator = ' ,';
			}

			if($_G['forum_optionlist'][$optionid]['type'] == 'image') {
				$identifier = $_G['forum_optionlist'][$optionid]['identifier'];
				$sortaids[] = intval($_GET['typeoption'][$identifier]['aid']);
			}

			C::t('forum_typeoptionvar')->insert(array(
				'sortid' => $sortid,
				'tid' => $tid,
				'fid' => $_G['fid'],
				'optionid' => $optionid,
				'value' => censor($value),
				'expiration' => ($typeexpiration ? $publishdate + $typeexpiration : 0),
			));
		}

		if($filedname && $valuelist) {
			C::t('forum_optionvalue')->insert($sortid, "($filedname, tid, fid) VALUES ($valuelist, '$tid', '$_G[fid]')");
		}
	}
	if($_G['group']['allowat']) {
		$atlist = $atlist_tmp = array();
		preg_match_all("/@([^\r\n]*?)\s/i", $message.' ', $atlist_tmp);
		$atlist_tmp = array_slice(array_unique($atlist_tmp[1]), 0, $_G['group']['allowat']);
		if(!empty($atlist_tmp)) {
			if(empty($_G['setting']['at_anyone'])) {
				foreach(C::t('home_follow')->fetch_all_by_uid_fusername($_G['uid'], $atlist_tmp) as $row) {
					$atlist[$row['followuid']] = $row['fusername'];
				}
				if(count($atlist) < $_G['group']['allowat']) {
					$query = C::t('home_friend')->fetch_all_by_uid_username($_G['uid'], $atlist_tmp);
					foreach($query as $row) {
						$atlist[$row['fuid']] = $row['fusername'];
					}
				}
			} else {
				foreach(C::t('common_member')->fetch_all_by_username($atlist_tmp) as $row) {
					$atlist[$row['uid']] = $row['username'];
				}
			}
		}
		if($atlist) {
			foreach($atlist as $atuid => $atusername) {
				$atsearch[] = "/@$atusername /i";
				$atreplace[] = "[url=home.php?mod=space&uid=$atuid]@{$atusername}[/url] ";
			}
			$message = preg_replace($atsearch, $atreplace, $message.' ', 1);
		}
	}

	$bbcodeoff = checkbbcodes($message, !empty($_GET['bbcodeoff']));
	$smileyoff = checksmilies($message, !empty($_GET['smileyoff']));
	$parseurloff = !empty($_GET['parseurloff']);
	$htmlon = $_G['group']['allowhtml'] && !empty($_GET['htmlon']) ? 1 : 0;
	$usesig = !empty($_GET['usesig']) && $_G['group']['maxsigsize'] ? 1 : 0;


 //自动标签
  if ($_GET['tagauto']==1){
		$subjectenc = rawurlencode(strip_tags($subject));
		$messageenc = rawurlencode(strip_tags(preg_replace("/\[.+?\]/U", '', $message)));
		$data = @implode('', file("http://keyword.discuz.com/related_kw.html?ics=".CHARSET."&ocs=".CHARSET."&title=$subjectenc&content=$messageenc"));
		
		if($data) {
		
			if(PHP_VERSION > '5' && CHARSET != 'utf-8') {
				require_once libfile('class/chinese');
				$chs = new Chinese('utf-8', CHARSET);
			}
		
			$parser = xml_parser_create();
			xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
			xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
			xml_parse_into_struct($parser, $data, $values, $index);
			xml_parser_free($parser);
		
			$kws = array();
		
			foreach($values as $valuearray) {
				if($valuearray['tag'] == 'kw' || $valuearray['tag'] == 'ekw') {
					$kws[] = !empty($chs) ? $chs->convert(trim($valuearray['value'])) : trim($valuearray['value']);
				}
			}
		
			$zztags = '';
			if($kws) {
				foreach($kws as $kw) {
					$kw = dhtmlspecialchars($kw);
					$zztags .= $kw.' ';
				}
				$_GET['tags']  = dhtmlspecialchars($zztags);
			}
			
  
  	}
 
 }
	$class_tag = new tag();
	$tagstr = $class_tag->add_tag($_GET['tags'], $tid, 'tid');

	if($_G['group']['allowreplycredit']) {
		if($replycredit > 0 && $replycredit_real > 0) {
			updatemembercount($_G['uid'], array('extcredits'.$_G['setting']['creditstransextra'][10] => -$replycredit_real), 1, 'RCT', $tid);
			$insertdata = array(
					'tid' => $tid,
					'extcredits' => $_GET['replycredit_extcredits'],
					'extcreditstype' => $_G['setting']['creditstransextra'][10],
					'times' => $_GET['replycredit_times'],
					'membertimes' => $_GET['replycredit_membertimes'],
					'random' => $_GET['replycredit_random']
				);
			C::t('forum_replycredit')->insert($insertdata);
		}
	}

	if($_G['group']['allowpostrushreply'] && $_GET['rushreply']) {
		$rushdata = array('tid' => $tid, 'stopfloor' => $_GET['stopfloor'], 'starttimefrom' => $_GET['rushreplyfrom'], 'starttimeto' => $_GET['rushreplyto'], 'rewardfloor' => $_GET['rewardfloor'], 'creditlimit' => $_GET['creditlimit']);
		C::t('forum_threadrush')->insert($rushdata);
	}

	$pinvisible = $modnewthreads ? -2 : (empty($_GET['save']) ? 0 : -3);


//zzcity add

   function zzfileext($filename) {
    return strtolower(substr(strrchr($filename, '.'), 1, 10));
   }

 $attachlist=explode(',',$_POST['etattachs']);

 $curattachs='';
 foreach ($attachlist as $key => $value) {
 $value=trim($value);
 if(empty($value))continue;
    if (preg_match("/".preg_quote($value,"/")."/i",$message)){
     $message=preg_replace("/<a([^>]*?)".preg_quote($value,"/")."([^<]*?)<img([^>]*?)".preg_quote($value,"/")."([^<]*?)<\/(.*?)>/i",'[attachimg]'.$value.'[/attachimg]',$message);
     $message=preg_replace("/<img([^>]*?)".preg_quote($value,"/")."([^>]*?)>/i",'[attachimg]'.$value.'[/attachimg]',$message);
     $message=preg_replace("/\[img([^\]]*?)\]".preg_quote($value,"/")."\[\/img\]/i",'[attachimg]'.$value.'[/attachimg]',$message);

     $message=preg_replace("/<a([^>]*?)".preg_quote($value,"/")."([^>]*?)>([^<]+?)<\/a(.*?)>/i",'[attach]'.$value.'[/attach]',$message);
     $message=preg_replace("/\[url=".preg_quote($value,"/")."(.*?)\[\/url\]/i",'[attach]'.$value.'[/attach]',$message);
     if (in_array(zzfileext('ext'),array("wma","mp3","ra","rm"))) {
      $message=preg_replace("/<object((?!object)(\s|\S))*".preg_quote($value,"/")."((?!object)(\s|\S))*</(.*?)>/i",'[audio=1]'.$value.'[/audio]',$message);
      $message=preg_replace("/<embed((?!embed)(\s|\S))*".preg_quote($value,"/")."((?!embed)(\s|\S))*</(.*?)>/i",'[audio=1]'.$value.'[/audio]',$message);
     }elseif  (in_array(zzfileext('ext'), array('wmv','rmvb','avi','mov'))){
      $message=preg_replace("/<object((?!object)(\s|\S))*".preg_quote($value,"/")."((?!object)(\s|\S))*</(.*?)>/i",'[media='.zzfileext('ext').',500,375,1]'.$value.'[/media]',$message);
      $message=preg_replace("/<embed((?!embed)(\s|\S))*".preg_quote($value,"/")."((?!embed)(\s|\S))*</(.*?)>/i",'[media='.zzfileext('ext').',500,375,1]'.$value.'[/media]',$message);
     }elseif  (in_array(zzfileext('ext'), array('swf','flv'))){
      $message=preg_replace("/<object((?!object)(\s|\S))*".preg_quote($value,"/")."((?!object)(\s|\S))*</(.*?)>/i",'[flash]'.$value.'[/flash]',$message);
      $message=preg_replace("/<embed((?!embed)(\s|\S))*".preg_quote($value,"/")."((?!embed)(\s|\S))*</(.*?)>/i",'[flash]'.$value.'[/flash]',$message);}
   $curattachs.= empty($curattachs) ? $value:','.$value;
   
  }
 }

 $message = preg_replace('/\[attachimg\](.+?)\[\/attachimg\]/is', '[attach]\1[/attach]', $message);


//zzcity close

 $pid = insertpost(array(
  'fid' => $_G['fid'],
  'tid' => $tid,
  'first' => '1',
  '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',
  'tags' => $tagstr,
  'replycredit' => 0,
  'status' => (defined('IN_MOBILE') ? 8 : 0)
 ));

	if($_G['group']['allowat'] && $atlist) {
		foreach($atlist as $atuid => $atusername) {
			notification_add($atuid, 'at', 'at_message', array('from_id' => $tid, 'from_idtype' => 'thread', 'buyerid' => $_G['uid'], 'buyer' => $_G['username'], 'tid' => $tid, 'subject' => $subject, 'pid' => $pid, 'message' => messagecutstr($message, 150)));
		}
		set_atlist_cookie(array_keys($atlist));
	}
//zzcity add attachment
 $ashowurl =  empty($_POST['ashowurl']) ? "/data/attachment/forum" : trim($_POST['ashowurl']);
 
 $ashowurl = substr($ashowurl,-1)=="/" ? $ashowurl: $ashowurl.'/';
 

 $curalist=explode(',',$curattachs);
 $attachnum =  empty($curattachs) ? 0 :count($curalist);
 if ($attachnum){

   $zzattachtype=1;
   //
   function zzis_image_ext($ext) {
    static $imgext  = array('jpg', 'jpeg', 'gif', 'png', 'bmp');
    return in_array($ext, $imgext) ? 1 : 0;
   }
   //
   function zzget_target_extension($ext) {
    static $safeext  = array('attach', 'jpg', 'jpeg', 'gif', 'png', 'swf', 'bmp', 'txt', 'zip', 'rar', 'mp3');
    return strtolower(!in_array(strtolower($ext), $safeext) ? 'attach' : $ext);
   }
   function zzforum_upload($filename) {
    global $_G,$zzattachtype;
 
    $zzuid = intval($_G['uid']);
//    $swfhash = md5(substr(md5($_G['config']['security']['authkey']), 8).$this->uid);
  
     $zzaid = 0;
//     $zzsimple = !empty($_G['gp_simple']) ? $_G['gp_simple'] : 0;
  
//     $_G['groupid'] = intval(DB::result_first("SELECT groupid FROM ".DB::table('common_member')." WHERE uid='".$this->uid."'"));
//     loadcache('usergroup_'.$_G['groupid']);
//     $_G['group'] = $_G['cache']['usergroup_'.$_G['groupid']];
  
  
//     $upload = new discuz_upload();
//     $upload->init($_FILES['Filedata'], 'forum');
//     $this->attach = &$upload->attach;
     $thistype='forum';
     $attach=array();
  
     $attach['name'] =  trim(substr(strrchr($filename,'/'),1));
     $attach['thumb'] = '';
     
     $attach['name'] =  dhtmlspecialchars($attach['name'], ENT_QUOTES);
     if(strlen($attach['name']) > 90) {
      $attach['name'] = cutstr($attach['name'], 90, '').'.'.$attach['ext'];
     }
     $attach['ext'] = zzfileext($attach['name']);
     $attach['isimage'] = zzis_image_ext($attach['ext']);
    
     $attach['extension'] = zzget_target_extension($attach['ext']);
     
//     $attach['attachdir'] = $this->get_target_dir($thistype, $extid);
//     $attach['attachment'] = $attach['attachdir'].$this->get_target_filename($this->type, $this->extid, $this->forcename).'.'.$attach['extension'];
     $attach['attachment'] = $filename;
     $attach['target'] = getglobal('setting/attachdir').'./'.$thistype.'/'.$attach['attachment'];
     $attach['size'] = intval(filesize($attach['target']));

  
//     if($upload->error()) {
//      $this->uploadmsg(2);
//     }
//  
//     $allowupload = !$_G['group']['maxattachnum'] || $_G['group']['maxattachnum'] && $_G['group']['maxattachnum'] > DB::result_first("SELECT count(*) FROM ".DB::table('forum_attachment')." WHERE uid='$_G[uid]' AND dateline>'$_G[timestamp]'-86400");
//     if(!$allowupload) {
//      $this->uploadmsg(9);
//     }
  
//     if($_G['group']['attachextensions'] && (!preg_match("/(^|\s|,)".preg_quote($upload->attach['ext'], '/')."($|\s|,)/i", $_G['group']['attachextensions']) || !$upload->attach['ext'])) {
//      $this->uploadmsg(1);
//     }
  
//     if(empty($upload->attach['size'])) {
//      $this->uploadmsg(2);
//     }
  
//     if($_G['group']['maxattachsize'] && $upload->attach['size'] > $_G['group']['maxattachsize']) {
//      $this->uploadmsg(3);
//     }
//  
//     if($type = DB::fetch_first("SELECT maxsize FROM ".DB::table('forum_attachtype')." WHERE extension='".addslashes($upload->attach['ext'])."'")) {
//      if($type['maxsize'] == 0) {
//       $this->uploadmsg(4);
//      } elseif($upload->attach['size'] > $type['maxsize']) {
//       $this->uploadmsg(5);
//      }
//     }
  
//     if($upload->attach['size'] && $_G['group']['maxsizeperday']) {
//      $todaysize = intval(DB::result_first("SELECT SUM(filesize) FROM ".DB::table('forum_attachment')." WHERE uid='$_G[uid]' AND dateline>'$_G[timestamp]'-86400"));
//      $todaysize += $upload->attach['size'];
//      if($todaysize >= $_G['group']['maxsizeperday']) {
//       $this->uploadmsg(6);
//      }
//     }
//     $upload->save();
//     if($upload->error() == -103) {
//      $this->uploadmsg(8);
//     } elseif($upload->error()) {
//      $this->uploadmsg(9);
//     }
  $thumb = $remote = $width = 0;
  if($attach['isimage']) {
   $zzattachtype=2;
   if($_G['setting']['thumbstatus']) {
    require_once libfile('class/image');
    $image = new image;
    //$thumb = $image->Thumb($upload->attach['target'], '', $_G['setting']['thumbwidth'], $_G['setting']['thumbheight'], $_G['setting']['thumbstatus'], $_G['setting']['thumbsource']) ? 1 : 0;
    $thumb = $image->Thumb($attach['target'], '', $_G['setting']['thumbwidth'], $_G['setting']['thumbheight'], $_G['setting']['thumbstatus'], $_G['setting']['thumbsource']) ? 1 : 0;
    $image->Watermark($attach['target']);
    $width = $image->imginfo['width'];
   }
   if($_G['setting']['thumbsource'] || !$_G['setting']['thumbstatus']) {
    list($width) = @getimagesize($attach['target']);
   }
   
  }
//     if(!$zzsimple) {
//      $attach['name'] = diconv($attach['name'], 'utf-8');
//     }
//     if($_G['gp_type'] != 'image' && $attach['isimage']) {
//      $attach['isimage'] = -1;
//     }
  $zzaid=getattachnewaid($zzuid);

  DB::query("INSERT INTO ".DB::table('forum_attachment_unused')." (aid, dateline, filename, filesize, attachment, isimage, uid, thumb, remote, width)
   VALUES ('$zzaid', '$_G[timestamp]', '".$attach['name']."', '".$attach['size']."', '".$attach['attachment']."', '".$attach['isimage']."', '".$zzuid."', '$thumb', '$remote', '$width')");
 
     return $zzaid;
//     $this->uploadmsg(0);
  
   }

 foreach ($curalist as $key => $value) {
  $oldvalue=$value;
  $value=str_replace($ashowurl,'',$value);
  $aid=zzforum_upload($value);
  
  $message=str_replace($oldvalue,$aid,$message);
  $aids[]=$aid;

 }
 
 DB::query('UPDATE '.DB::table('forum_thread').' SET attachment='.$zzattachtype.' WHERE tid = '.$tid);
 $posttable = getposttablebytid($tid);
 DB::query("UPDATE ".DB::table($posttable)." SET message='$message',attachment=$attachnum WHERE pid=$pid");
 foreach($aids as $key => $value){
  convertunusedattach($value,$tid,$pid); 
 }
 if(getglobal('setting/ftp/on')){
  ftpupload($aids,intval($_G['uid']));
 }
} 
//zzcity add attachment close


 $threadimageaid = 0;
 $threadimage = array();
/* 
	if($special == 4 && $_GET['activityaid']) {
		$threadimageaid = $_GET['activityaid'];
		convertunusedattach($_GET['activityaid'], $tid, $pid);
	}
*/
 if($_G['forum']['threadsorts']['types'][$sortid] && !empty($_G['forum_optiondata']) && is_array($_G['forum_optiondata']) && $sortaids) {
  foreach($sortaids as $sortaid) {
   convertunusedattach($sortaid, $tid, $pid);
  }
 }
// if(($_G['group']['allowpostattach'] || $_G['group']['allowpostimage']) && ($_GET['attachnew'] || $sortid || !empty($_GET['activityaid']))) {
	if($attachnum){
		updateattach($displayorder == -4 || $modnewthreads, $tid, $pid, $_GET['attachnew']);
		if(!$threadimageaid) {
			$threadimage = C::t('forum_attachment_n')->fetch_max_image('tid:'.$tid, 'tid', $tid);
			$threadimageaid = $threadimage['aid'];
		}
	}
	$values = array('fid' => $_G['fid'], 'tid' => $tid, 'pid' => $pid, 'coverimg' => '');
	$param = array();
	if($_G['forum']['picstyle']) {
		if(!setthreadcover($pid, 0, $threadimageaid)) {
			preg_match_all("/(\[img\]|\[img=\d{1,4}[x|\,]\d{1,4}\])\s*([^\[\<\r\n]+?)\s*\[\/img\]/is", $message, $imglist, PREG_SET_ORDER);
			$values['coverimg'] = "<p id=\"showsetcover\">".lang('message', 'post_newthread_set_cover')."<span id=\"setcoverwait\"></span></p><script>if($('forward_a')){\$('forward_a').style.display='none';setTimeout(\"$('forward_a').style.display=''\", 5000);};ajaxget('forum.php?mod=ajax&action=setthreadcover&tid=$tid&pid=$pid&fid=$_G[fid]&imgurl={$imglist[0][2]}&newthread=1', 'showsetcover', 'setcoverwait')</script>";
			$param['clean_msgforward'] = 1;
			$param['timeout'] = $param['refreshtime'] = 15;
		}
	}

	if($threadimageaid) {
		if(!$threadimage) {
			$threadimage = C::t('forum_attachment_n')->fetch('tid:'.$tid, $threadimageaid);
		}
		$threadimage = daddslashes($threadimage);
		C::t('forum_threadimage')->insert(array(
			'tid' => $tid,
			'attachment' => $threadimage['attachment'],
			'remote' => $threadimage['remote'],
		));
	}

 $statarr = array(0 => 'thread', 1 => 'poll', 2 => 'trade', 3 => 'reward', 4 => 'activity', 5 => 'debate', 127 => 'thread');
 include_once libfile('function/stat');
 updatestat($isgroup ? 'groupthread' : $statarr[$special]);

 dsetcookie('clearUserdata', 'forum');

 if($specialextra) {

  $classname = 'threadplugin_'.$specialextra;
  if(class_exists($classname) && method_exists($threadpluginclass = new $classname, 'newthread_submit_end')) {
   $threadpluginclass->newthread_submit_end($_G['fid'], $tid);
  }

 }
	if(!empty($_G['setting']['rewriterule']['forum_viewthread']) && in_array('forum_viewthread', $_G['setting']['rewritestatus'])) {
		$returnurl = rewriteoutput('forum_viewthread', 1, '', $tid, 1, '', $extra);
	} else {
		$returnurl = "forum.php?mod=viewthread&tid=$tid&extra=$extra";
	}
	if($modnewthreads) {
		updatemoderate('tid', $tid);
		C::t('forum_forum')->update_forum_counter($_G['fid'], 0, 0, 1);
		manage_addnotify('verifythread');
//  showmessage('post_newthread_mod_succeed', "forum.php?mod=viewthread&tid=$tid&extra=$extra", $param);
 } else {
		if($displayorder >= 0 && helper_access::check_module('follow') && !empty($_GET['adddynamic']) && !$isanonymous) {
			require_once libfile('function/discuzcode');
			require_once libfile('function/followcode');
			$feedcontent = array(
				'tid' => $tid,
				'content' => followcode($message, $tid, $pid, 1000),
			);
			C::t('forum_threadpreview')->insert($feedcontent);
			C::t('forum_thread')->update_status_by_tid($tid, '512');
			$followfeed = array(
				'uid' => $_G['uid'],
				'username' => $_G['username'],
				'tid' => $tid,
				'note' => '',
				'dateline' => $_G['timestamp']
			);
			$values['feedid'] = C::t('home_follow_feed')->insert($followfeed, true);
			C::t('common_member_count')->increase($_G['uid'], array('feeds'=>1));
		}
   $feed = array(
   'icon' => '',
   'title_template' => '',
   'title_data' => array(),
   'body_template' => '',
   'body_data' => array(),
   'title_data'=>array(),
   'images'=>array()
  );

		if(!empty($_GET['addfeed']) && $_G['forum']['allowfeed'] && !$isanonymous) {
			$message = !$price && !$readperm ? $message : '';
			if($special == 0) {
    $feed['icon'] = 'thread';
    $feed['title_template'] = 'feed_thread_title';
    $feed['body_template'] = 'feed_thread_message';
    $feed['body_data'] = array(
     'subject' => "<a href=\"forum.php?mod=viewthread&tid=$tid\">$subject</a>",
     'message' => messagecutstr($message, 150)
    );
    if(!empty($_G['forum_attachexist'])) {
			$imgattach = C::t('forum_attachment_n')->fetch_max_image('tid:'.$tid, 'pid', $pid);
			$firstaid = $imgattach['aid'];
			unset($imgattach);
     if($firstaid) {
      $feed['images'] = array(getforumimg($firstaid));
      $feed['image_links'] = array("forum.php?mod=viewthread&do=tradeinfo&tid=$tid&pid=$pid");
     }
    }
   } elseif($special > 0) {
    if($special == 1) {
     $pvs = explode("\t", messagecutstr($polloptionpreview, 150));
     $s = '';
     $i = 1;
     foreach($pvs as $pv) {
      $s .= $i.'. '.$pv.'<br />';
     }
					$s .= '&nbsp;&nbsp;&nbsp;...';
     $feed['icon'] = 'poll';
     $feed['title_template'] = 'feed_thread_poll_title';
     $feed['body_template'] = 'feed_thread_poll_message';
     $feed['body_data'] = array(
      'subject' => "<a href=\"forum.php?mod=viewthread&tid=$tid\">$subject</a>",
      'message' => $s
     );
    } elseif($special == 3) {
     $feed['icon'] = 'reward';
     $feed['title_template'] = 'feed_thread_reward_title';
     $feed['body_template'] = 'feed_thread_reward_message';
     $feed['body_data'] = array(
      'subject'=> "<a href=\"forum.php?mod=viewthread&tid=$tid\">$subject</a>",
      'rewardprice'=> $rewardprice,
      'extcredits' => $_G['setting']['extcredits'][$_G['setting']['creditstransextra'][2]]['title'],
     );
				} elseif($special == 4) {
					$feed['icon'] = 'activity';
					$feed['title_template'] = 'feed_thread_activity_title';
					$feed['body_template'] = 'feed_thread_activity_message';
					$feed['body_data'] = array(
						'subject' => "<a href=\"forum.php?mod=viewthread&tid=$tid\">$subject</a>",
						'starttimefrom' => $_GET['starttimefrom'][$activitytime],
						'activityplace'=> $activity['place'],
						'message' => messagecutstr($message, 150),
					);
					if($_GET['activityaid']) {
						$feed['images'] = array(getforumimg($_GET['activityaid']));
						$feed['image_links'] = array("forum.php?mod=viewthread&do=tradeinfo&tid=$tid&pid=$pid");
					}
				} elseif($special == 5) {
     $feed['icon'] = 'debate';
     $feed['title_template'] = 'feed_thread_debate_title';
     $feed['body_template'] = 'feed_thread_debate_message';
     $feed['body_data'] = array(
      'subject' => "<a href=\"forum.php?mod=viewthread&tid=$tid\">$subject</a>",
      'message' => messagecutstr($message, 150),
      'affirmpoint'=> messagecutstr($affirmpoint, 150),
      'negapoint'=> messagecutstr($negapoint, 150)
     );
    }
   }

   $feed['title_data']['hash_data'] = "tid{$tid}";
   $feed['id'] = $tid;
   $feed['idtype'] = 'tid';
   if($feed['icon']) {
    postfeed($feed);
   }
  }


		if($displayorder != -4) {
			if($digest) {
				updatepostcredits('+',  $_G['uid'], 'digest', $_G['fid']);
			}
			updatepostcredits('+',  $_G['uid'], 'post', $_G['fid']);
			if($isgroup) {
				C::t('forum_groupuser')->update_counter_for_user($_G['uid'], $_G['fid'], 1);
			}

			$subject = str_replace("\t", ' ', $subject);
			$lastpost = "$tid\t".$subject."\t$_G[timestamp]\t$author";
			C::t('forum_forum')->update($_G['fid'], array('lastpost' => $lastpost));
			C::t('forum_forum')->update_forum_counter($_G['fid'], 1, 1, 1);
			if($_G['forum']['type'] == 'sub') {
				C::t('forum_forum')->update($_G['forum']['fup'], array('lastpost' => $lastpost));
			}
		}

		if($_G['forum']['status'] == 3) {
			C::t('forum_forumfield')->update($_G['fid'], array('lastupdate' => $_G['timestamp']));
			require_once libfile('function/grouplog');
			updategroupcreditlog($_G['fid'], $_G['uid']);
		}

//		showmessage('post_newthread_succeed', $returnurl, $values, $param);
 }
 exit('[reply]tid='.$tid.';pid='.$pid.'[/reply]'); //zzcityadd

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




function check_allow_action($action = 'allowpost') {
 global $_G;
// if(isset($_G['forum'][$action]) && $_G['forum'][$action] == -1) {
//  showmessage('forum_access_disallow');
// }
}

function recent_use_tag() {
	$tagarray = $stringarray = array();
	$string = '';
	$i = 0;
	$query = C::t('common_tagitem')->select(0, 0, 'tid', 'itemid', 'DESC', 10);
	foreach($query as $result) {
		if($i > 4) {
			break;
		}
		if($tagarray[$result['tagid']] == '') {
			$i++;
		}
		$tagarray[$result['tagid']] = 1;
	}
	if($tagarray) {
		$query = C::t('common_tag')->fetch_all(array_keys($tagarray));
		foreach($query as $result) {
			$tagarray[$result[tagid]] = $result['tagname'];
		}
	}
	return $tagarray;
}



//require DISCUZ_ROOT.'./source/module/forum/forum_'.$mod.'.php';替换结束

?>
