<?php

$vercode=''; //此处取值请自行修改
if(isset($_REQUEST['vercode'])){
if ($_REQUEST['vercode']!=$vercode){
 echo("[err]invalid vercode[/err]");
 exit();
}
}

define('CURSCRIPT', 'post');
define('NOROBOT', TRUE);

//require_once './include/common.inc.php';//zzcity modi
//common.inc.php代码开始 zzcity add
error_reporting(0);
set_magic_quotes_runtime(0);
$mtime = explode(' ', microtime());
$discuz_starttime = $mtime[1] + $mtime[0];

define('SYS_DEBUG', FALSE);
define('IN_DISCUZ', TRUE);
//define('DISCUZ_ROOT', substr(dirname(__FILE__), 0, -7));
//zzcity add
$DISCUZROOT=ereg_replace("[/\\]{1,}",'/',dirname(__FILE__) ) ;
if (substr($DISCUZROOT,-1,1)!='/')$DISCUZROOT.='/';
define('DISCUZ_ROOT', $DISCUZROOT);

define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
//!defined('CURSCRIPT') && define('CURSCRIPT', '');

if(PHP_VERSION < '4.1.0') {
 $_GET = &$HTTP_GET_VARS;
 $_POST = &$HTTP_POST_VARS;
 $_COOKIE = &$HTTP_COOKIE_VARS;
 $_SERVER = &$HTTP_SERVER_VARS;
 $_ENV = &$HTTP_ENV_VARS;
 $_FILES = &$HTTP_POST_FILES;
}

if (isset($_REQUEST['GLOBALS']) OR isset($_FILES['GLOBALS'])) {
 exit('Request tainting attempted.');
}

require_once DISCUZ_ROOT.'./include/global.func.php';
/*
getrobot();
if(defined('NOROBOT') && IS_ROBOT) {
 exit(header("HTTP/1.1 403 Forbidden"));
}
*/
foreach(array('_COOKIE', '_POST', '_GET') as $_request) {
 foreach($$_request as $_key => $_value) {
  $_key{0} != '_' && $$_key = daddslashes($_value);
 }
}

if (!MAGIC_QUOTES_GPC && $_FILES) {
 $_FILES = daddslashes($_FILES);
}

$charset = $dbs = $dbcharset = $forumfounders = $metakeywords = $extrahead = $seodescription = $mnid = '';
$plugins = $pluginclasses = $hooks = $admincp = $jsmenu = $forum = $thread = $language = $actioncode = $modactioncode = $lang = array();
$_DCOOKIE = $_DSESSION = $_DCACHE = $_DPLUGIN = $advlist = array();

require_once DISCUZ_ROOT.'./config.inc.php';
//zzcity add
include language('messages');

if($urlxssdefend && !empty($_SERVER['REQUEST_URI'])) {
 $temp = urldecode($_SERVER['REQUEST_URI']);
 if(strpos($temp, '<') !== false || strpos($temp, '"') !== false)
  exit('Request Bad url');
}

$prelength = strlen($cookiepre);
foreach($_COOKIE as $key => $val) {
 if(substr($key, 0, $prelength) == $cookiepre) {
  $_DCOOKIE[(substr($key, $prelength))] = MAGIC_QUOTES_GPC ? $val : daddslashes($val);
 }
}
unset($prelength, $_request, $_key, $_value);

$inajax = !empty($inajax);
$handlekey = !empty($handlekey) ? htmlspecialchars($handlekey) : '';
$timestamp = time();

if($attackevasive && (!define('CURSCRIPT') || CURSCRIPT != 'seccode')) {
 require_once DISCUZ_ROOT.'./include/security.inc.php';
}

require_once DISCUZ_ROOT.'./include/db_'.$database.'.class.php';


$PHP_SELF = dhtmlspecialchars($_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME']);
$BASESCRIPT = basename($PHP_SELF);
list($BASEFILENAME) = explode('.', $BASESCRIPT);
$boardurl = htmlspecialchars('http://'.$_SERVER['HTTP_HOST'].preg_replace("/\/+(api|archiver|wap)?\/*$/i", '', substr($PHP_SELF, 0, strrpos($PHP_SELF, '/'))).'/');

if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
 $onlineip = getenv('HTTP_CLIENT_IP');
} elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
 $onlineip = getenv('HTTP_X_FORWARDED_FOR');
} elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
 $onlineip = getenv('REMOTE_ADDR');
} elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
 $onlineip = $_SERVER['REMOTE_ADDR'];
}

preg_match("/[\d\.]{7,15}/", $onlineip, $onlineipmatches);
$onlineip = $onlineipmatches[0] ? $onlineipmatches[0] : 'unknown';
unset($onlineipmatches);

$cachelost = (@include DISCUZ_ROOT.'./forumdata/cache/cache_settings.php') ? '' : 'settings';
@extract($_DCACHE['settings']);

if(defined('BINDDOMAIN') && BINDDOMAIN && !$cachelost && $binddomains && $forumdomains) {
 $loadforum = isset($binddomains[$_SERVER['HTTP_HOST']]) ? max(0, intval($binddomains[$_SERVER['HTTP_HOST']])) : 0;
 if($loadforum) {
  if(BINDDOMAIN == 'forumdisplay' && $loadforum == $fid) {
   header("HTTP/1.1 301 Moved Permanently");
   $query_string = preg_replace('/\??fid='.$fid.'&?/is', '', $_SERVER['QUERY_STRING']);
   dheader("Location: http://$_SERVER[HTTP_HOST]/{$indexname}".($query_string ? "?{$query_string}" : ''));
  }
  if(BINDDOMAIN == 'index') {
   $fid = $_GET['fid'] = $_REQUEST['fid'] = $loadforum;
   define('CURSCRIPT', 'forumdisplay');
  }
 } else {
  if(BINDDOMAIN == 'forumdisplay' && isset($forumdomains[$fid])) {
   $host = $forumdomains[$fid];
   header("HTTP/1.1 301 Moved Permanently");
   dheader("Location: http://{$host}/{$indexname}");
  }
  define('CURSCRIPT', BINDDOMAIN);
 }
}
if(!defined('CURSCRIPT')) {
 define('CURSCRIPT', defined('BINDDOMAIN') ? BINDDOMAIN : '');
}


if(!defined('STAT_ID') && isset($statdisable) && empty($statdisable)) {
 define('STAT_ID', $_DCACHE['settings']['statid']);
 define('STAT_KEY', $_DCACHE['settings']['statkey']);
}
if($gzipcompress && function_exists('ob_gzhandler') && !in_array(CURSCRIPT, array('attachment', 'wap')) && !$inajax) {
 ob_start('ob_gzhandler');
} else {
 $gzipcompress = 0;
 ob_start();
}

if(!empty($loadctrl) && substr(PHP_OS, 0, 3) != 'WIN') {
 if($fp = @fopen('/proc/loadavg', 'r')) {
  list($loadaverage) = explode(' ', fread($fp, 6));
  fclose($fp);
  if($loadaverage > $loadctrl) {
   header("HTTP/1.0 503 Service Unavailable");
   include DISCUZ_ROOT.'./include/serverbusy.htm';
   exit();
  }
 }
}

if(in_array(CURSCRIPT, array('index', 'forumdisplay', 'viewthread', 'post', 'topicadmin', 'register', 'archiver'))) {
 $cachelost .= (@include DISCUZ_ROOT.'./forumdata/cache/cache_'.CURSCRIPT.'.php') ? '' : ' '.CURSCRIPT;
}

$db = new dbstuff;
$db->connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect, true, $dbcharset);
$dbuser = $dbpw = $pconnect = $sdb = NULL;

$sid = daddslashes(($transsidstatus || CURSCRIPT == 'wap') && (isset($_GET['sid']) || isset($_POST['sid'])) ?
 (isset($_GET['sid']) ? $_GET['sid'] : $_POST['sid']) :
 (isset($_DCOOKIE['sid']) ? $_DCOOKIE['sid'] : ''));

CURSCRIPT == 'attachment' && isset($_GET['sid']) && $sid = addslashes(authcode($_GET['sid'], 'DECODE', $_DCACHE['settings']['authkey']));

$discuz_auth_key = md5($_DCACHE['settings']['authkey'].$_SERVER['HTTP_USER_AGENT']);
list($discuz_pw, $discuz_secques, $discuz_uid) = empty($_DCOOKIE['auth']) ? array('', '', 0) : daddslashes(explode("\t", authcode($_DCOOKIE['auth'], 'DECODE')), 1);

$prompt = $sessionexists = $seccode = 0;
$membertablefields = 'm.uid AS discuz_uid, m.username AS discuz_user, m.password AS discuz_pw, m.secques AS discuz_secques,
 m.adminid, m.groupid, m.groupexpiry, m.extgroupids, m.email, m.timeoffset, m.tpp, m.ppp, m.posts, m.threads, m.digestposts,
 m.oltime, m.pageviews, m.credits, m.extcredits1, m.extcredits2, m.extcredits3, m.extcredits4, m.extcredits5,
 m.extcredits6, m.extcredits7, m.extcredits8, m.timeformat, m.dateformat, m.pmsound, m.sigstatus, m.invisible,
 m.lastvisit, m.lastactivity, m.lastpost, m.prompt, m.accessmasks, m.editormode, m.customshow, m.customaddfeed, m.newbietaskid';
/*if($sid) {
 if($discuz_uid) {
  $query = $db->query("SELECT s.sid, s.styleid, s.groupid='6' AS ipbanned, s.pageviews AS spageviews, s.lastolupdate, s.seccode, $membertablefields
   FROM {$tablepre}sessions s, {$tablepre}members m
   WHERE m.uid=s.uid AND s.sid='$sid' AND CONCAT_WS('.',s.ip1,s.ip2,s.ip3,s.ip4)='$onlineip' AND m.uid='$discuz_uid'
   AND m.password='$discuz_pw' AND m.secques='$discuz_secques'");
 } else {
  $query = $db->query("SELECT sid, uid AS sessionuid, groupid, groupid='6' AS ipbanned, pageviews AS spageviews, styleid, lastolupdate, seccode
   FROM {$tablepre}sessions WHERE sid='$sid' AND CONCAT_WS('.',ip1,ip2,ip3,ip4)='$onlineip'");
 }
 if($_DSESSION = $db->fetch_array($query)) {
  $sessionexists = 1;
  if(!empty($_DSESSION['sessionuid'])) {
   $_DSESSION = array_merge($_DSESSION, $db->fetch_first("SELECT $membertablefields
    FROM {$tablepre}members m WHERE uid='$_DSESSION[sessionuid]'"));
  }
 } else {
  if($_DSESSION = $db->fetch_first("SELECT sid, groupid, groupid='6' AS ipbanned, pageviews AS spageviews, styleid, lastolupdate, seccode
   FROM {$tablepre}sessions WHERE sid='$sid' AND CONCAT_WS('.',ip1,ip2,ip3,ip4)='$onlineip'")) {
   clearcookies();
   $sessionexists = 1;
  }
 }
}
*/
if(!$sessionexists) {
 //zzcity add
 if (empty($username) || empty($password)) {
  echo('[err]username or password is empty[/err]');
  exit(); 
  }
 else{

  if(!($_DSESSION = $db->fetch_first("SELECT $membertablefields, m.styleid
  FROM {$tablepre}members m WHERE m.username='".addslashes($username)."'"))) {
  clearcookies();
  }
 }
 $discuz_uid=$_DSESSION['discuz_uid'];
 $discuz_pw=$_DSESSION['discuz_pw'];
 $discuz_user=$_DSESSION['discuz_user'];

/* if($discuz_uid) {
  if(!($_DSESSION = $db->fetch_first("SELECT $membertablefields, m.styleid
   FROM {$tablepre}members m WHERE m.uid='$discuz_uid' AND m.password='$discuz_pw' AND m.secques='$discuz_secques'"))) {
   clearcookies();
  }
 }
*/
 if(ipbanned($onlineip)) $_DSESSION['ipbanned'] = 1;

 $_DSESSION['sid'] = random(6);
 $_DSESSION['seccode'] = random(6, 1);
}

$_DSESSION['dateformat'] = empty($_DSESSION['dateformat']) || empty($_DCACHE['settings']['userdateformat'][$_DSESSION['dateformat'] -1])? $_DCACHE['settings']['dateformat'] : $_DCACHE['settings']['userdateformat'][$_DSESSION['dateformat'] -1];
$_DSESSION['timeformat'] = empty($_DSESSION['timeformat']) ? $_DCACHE['settings']['timeformat'] : ($_DSESSION['timeformat'] == 1 ? 'h:i A' : 'H:i');
$_DSESSION['timeoffset'] = isset($_DSESSION['timeoffset']) && $_DSESSION['timeoffset'] != 9999 ? $_DSESSION['timeoffset'] : $_DCACHE['settings']['timeoffset'];

$membertablefields = '';
@extract($_DSESSION);

$disableprompt = !empty($_DCOOKIE['disableprompt']) ? explode('|', $_DCOOKIE['disableprompt']) : array();

if($prompt) {
 if($taskon && ($prompt & 8)) {
  $prompts['newbietask'] = 1;
  $disallowfloat = str_replace('task', '', $disallowfloat);
  $disallowfloat .= '|newthread|reply';
  $editormode = 0;
 }
 $prompt = 0;
 $query = $db->query("SELECT typeid, number FROM {$tablepre}prompt WHERE uid='$discuz_uid'");
 while($promptrow = $db->fetch_array($query)) {
  if($disableprompt && in_array($promptkeys[$promptrow['typeid']], $disableprompt)) {
   continue;
  }
  $prompt = $promptrow['number'] ? 1 : $prompt;
  $prompts[$promptkeys[$promptrow['typeid']]]['new'] = $promptrow['number'];
 }
}

if($announcepm && !in_array('announcepm', $disableprompt)) {
 $prompts['announcepm']['new'] = $announcepm;
}

$lastvisit = empty($lastvisit) ? $timestamp - 86400 : $lastvisit;
$timenow = array('time' => gmdate("$dateformat $timeformat", $timestamp + 3600 * $timeoffset),
 'offset' => ($timeoffset >= 0 ? ($timeoffset == 0 ? '' : '+'.$timeoffset) : $timeoffset));

if(PHP_VERSION > '5.1') {
 @date_default_timezone_set('Etc/GMT'.($timeoffset > 0 ? '-' : '+').(abs($timeoffset)));
}

$accessadd1 = $accessadd2 = $modadd1 = $modadd2 = $metadescription = $hookscriptmessage = '';
if(empty($discuz_uid) || empty($discuz_user)) {
 $discuz_user = $extgroupids = '';
 $discuz_uid = $adminid = $posts = $digestposts = $pageviews = $oltime = $invisible
  = $credits = $extcredits1 = $extcredits2 = $extcredits3 = $extcredits4
  = $extcredits5 = $extcredits6 = $extcredits7 = $extcredits8 = 0;
 $groupid = empty($groupid) || $groupid != 6 ? 7 : 6;

} else {
 $discuz_userss = $discuz_user;
 $discuz_user = addslashes($discuz_user);

 if($accessmasks) {
  $accessadd1 = ', a.allowview, a.allowpost, a.allowreply, a.allowgetattach, a.allowpostattach';
  $accessadd2 = "LEFT JOIN {$tablepre}access a ON a.uid='$discuz_uid' AND a.fid=f.fid";
 }

 if($adminid == 3) {
  $modadd1 = ', m.uid AS ismoderator';
  $modadd2 = "LEFT JOIN {$tablepre}moderators m ON m.uid='$discuz_uid' AND m.fid=f.fid";
 }
}
/*
if($errorreport == 2 || ($errorreport == 1 && $adminid > 0)) {
 error_reporting(E_ERROR | E_WARNING | E_PARSE);
}
*/
define('FORMHASH', formhash());

$statstatus && !$inajax && require_once DISCUZ_ROOT.'./include/counter.inc.php';

$extra = isset($extra) && @preg_match("/^[&=;a-z0-9]+$/i", $extra) ? $extra : '';

$rsshead = $navtitle = $navigation = '';

$_DSESSION['groupid'] = $groupid = empty($ipbanned) ? (empty($groupid) ? 7 : intval($groupid)) : 6;
if(!@include DISCUZ_ROOT.'./forumdata/cache/usergroup_'.$groupid.'.php') {
 $grouptype = $db->result_first("SELECT type FROM {$tablepre}usergroups WHERE groupid='$groupid'");
 if(!empty($grouptype)) {
  $cachelost .= ' usergroup_'.$groupid;
 } else {
  $grouptype = 'member';
 }
}

/*
$link_login = 'logging.php?action=login';
$link_logout = 'logging.php?action=logout&amp;formhash='.FORMHASH;
$link_register = $regname;
*/

if($discuz_uid && $_DSESSION) {
 if(!empty($groupexpiry) && $groupexpiry < $timestamp && !in_array(CURSCRIPT, array('wap', 'member'))) {
  dheader("Location: {$boardurl}member.php?action=groupexpiry");
 } elseif($grouptype && $groupid != getgroupid($discuz_uid, array
  (
  'type' => $grouptype,
  'creditshigher' => $groupcreditshigher,
  'creditslower' => $groupcreditslower
  ), $_DSESSION)) {
  @extract($_DSESSION);
  $cachelost .= (@include DISCUZ_ROOT.'./forumdata/cache/usergroup_'.intval($groupid).'.php') ? '' : ' usergroup_'.$groupid;
 }
}

$tpp = intval(empty($_DSESSION['tpp']) ? $topicperpage : $_DSESSION['tpp']);
$ppp = intval(empty($_DSESSION['ppp']) ? $postperpage : $_DSESSION['ppp']);

if(!in_array($adminid, array(1, 2, 3))) {
 $alloweditpost = $alloweditpoll = $allowstickthread = $allowmodpost = $allowdelpost = $allowmassprune
  = $allowrefund = $allowcensorword = $allowviewip = $allowbanip = $allowedituser = $allowmoduser
  = $allowbanuser = $allowpostannounce = $allowviewlog = $disablepostctrl = 0;
} elseif(isset($radminid) && $adminid != $radminid && $adminid != $groupid) {
 $cachelost .= (@include DISCUZ_ROOT.'./forumdata/cache/admingroup_'.intval($adminid).'.php') ? '' : ' admingroup_'.$groupid;
}


$page = isset($page) ? max(1, intval($page)) : 1;
$tid = isset($tid) && is_numeric($tid) ? $tid : 0;
$fid = isset($fid) && is_numeric($fid) ? $fid : 0;
$typeid = isset($typeid) ? intval($typeid) : 0;

$modthreadkey = isset($modthreadkey) && $modthreadkey == modthreadkey($tid) ? $modthreadkey : '';
$auditstatuson = $modthreadkey ? true : false;

if(!empty($tid) || !empty($fid)) {
 if(empty($tid)) {
  $forum = $db->fetch_first("SELECT f.fid, f.*, ff.* $accessadd1 $modadd1, f.fid AS fid
   FROM {$tablepre}forums f
   LEFT JOIN {$tablepre}forumfields ff ON ff.fid=f.fid $accessadd2 $modadd2
   WHERE f.fid='$fid'");
 } else {
  $forum = $db->fetch_first("SELECT t.tid, t.closed,".(defined('SQL_ADD_THREAD') ? SQL_ADD_THREAD : '')." f.*, ff.* $accessadd1 $modadd1, f.fid AS fid
   FROM {$tablepre}threads t
   INNER JOIN {$tablepre}forums f ON f.fid=t.fid
   LEFT JOIN {$tablepre}forumfields ff ON ff.fid=f.fid $accessadd2 $modadd2
   WHERE t.tid='$tid'".($auditstatuson ? '' : " AND t.displayorder>='0'")." LIMIT 1");
  $tid = $forum['tid'];
 }

 if($forum) {
  $fid = $forum['fid'];
  $forum['ismoderator'] = !empty($forum['ismoderator']) || $adminid == 1 || $adminid == 2 ? 1 : 0;
  foreach(array('postcredits', 'replycredits', 'threadtypes', 'threadsorts', 'digestcredits', 'postattachcredits', 'getattachcredits', 'modrecommend') as $key) {
   $forum[$key] = !empty($forum[$key]) ? unserialize($forum[$key]) : array();
  }
 } else {
  $fid = 0;
 }
}

$styleid = intval(!empty($_GET['styleid']) ? $_GET['styleid'] :
  (!empty($_POST['styleid']) ? $_POST['styleid'] :
  (!empty($_DSESSION['styleid']) ? $_DSESSION['styleid'] :
  $_DCACHE['settings']['styleid'])));

$styleid = intval(isset($styles[$styleid]) ? $styleid : $_DCACHE['settings']['styleid']);

if(@!include DISCUZ_ROOT.'./forumdata/cache/style_'.intval(!empty($forum['styleid']) ? $forum['styleid'] : $styleid).'.php') {
 $cachelost .= (@include DISCUZ_ROOT.'./forumdata/cache/style_'.($styleid = $_DCACHE['settings']['styleid']).'.php') ? '' : ' style_'.$styleid;
}

if($cachelost) {
 require_once DISCUZ_ROOT.'./include/cache.func.php';
 updatecache();
 exit('Cache List: '.$cachelost.'<br />Caches successfully created, please refresh.');
}

if(CURSCRIPT != 'wap') {
 if($nocacheheaders) {
  @dheader("Expires: 0");
  @dheader("Cache-Control: private, post-check=0, pre-check=0, max-age=0", FALSE);
  @dheader("Pragma: no-cache");
 }
 if($headercharset) {
  @dheader('Content-Type: text/html; charset='.$charset);
 }
 if(empty($_DCOOKIE['sid']) || $sid != $_DCOOKIE['sid']) {
  dsetcookie('sid', $sid, 604800, 1, true);
 }
}

$_DCOOKIE['loginuser'] = !empty($_DCOOKIE['loginuser']) ? substr(htmlspecialchars($_DCOOKIE['loginuser']), 0, 15) : '';

if($cronnextrun && $cronnextrun <= $timestamp) {
 require_once DISCUZ_ROOT.'./include/cron.func.php';
 runcron();
}

if(isset($plugins['include']) && is_array($plugins['include'])) {
 foreach($plugins['include'] as $pluginid => $include) {
  if(!$include['adminid'] || ($include['adminid'] && $adminid > 0 && $include['adminid'] >= $adminid)) {
   if(@in_array($pluginid, $pluginlangs)) {
    @include_once DISCUZ_ROOT.'./forumdata/cache/cache_scriptlang.php';
   }
   @include_once DISCUZ_ROOT.'./plugins/'.$include['script'].'.inc.php';
  }
 }
}

if((!empty($_DCACHE['advs']) || $globaladvs) && !defined('IN_ADMINCP')) {
 require_once DISCUZ_ROOT.'./include/advertisements.inc.php';
}

if(isset($allowvisit) && $allowvisit == 0 && !(CURSCRIPT == 'member' && ($action == 'groupexpiry' || $action == 'activate'))) {
 showmessage('user_banned', NULL, 'HALTED');
} elseif(!(in_array(CURSCRIPT, array('logging', 'wap', 'seccode', 'ajax')) || $adminid == 1)) {
 if($bbclosed) {
  clearcookies();
  $closedreason = $db->result_first("SELECT value FROM {$tablepre}settings WHERE variable='closedreason'");
  showmessage($closedreason ? $closedreason : 'board_closed', NULL, 'NOPERM');
 }
 periodscheck('visitbanperiods');
}

if((!empty($fromuid) || !empty($fromuser)) && ($creditspolicy['promotion_visit'] || $creditspolicy['promotion_register'])) {
 require_once DISCUZ_ROOT.'/include/promotion.inc.php';
}

if($uchome['addfeed']) {
 $customaddfeed = $customaddfeed == '-1' ? 0 : ($customaddfeed == 0 ? $uchome['addfeed'] : intval($customaddfeed));
} else {
 $customaddfeed = 0;
}

$rssauth = $rssstatus && $discuz_uid ? rawurlencode(authcode("$discuz_uid\t".($fid ? $fid : '')."\t".substr(md5($discuz_pw.$discuz_secques), 0, 8), 'ENCODE', md5($_DCACHE['settings']['authkey']))) : '0';
$transferstatus = $transferstatus && $allowtransfer;
$feedpostnum = $feedpostnum && $uchomeurl ? intval($feedpostnum) : 0;

$pluginhooks = array();
if(isset($hookscript[CURSCRIPT]['module'])) {
 hookscript(CURSCRIPT);
}

if($discuz_uid && $newbietaskupdate && $lastactivity < $newbietaskupdate) {
 require_once DISCUZ_ROOT.'./include/task.func.php';
 task_newfunction_autoapply();
}
//common.inc.php代码结束

require_once DISCUZ_ROOT.'./include/post.func.php';

$_DTYPE = $checkoption = $optionlist = array();
if($sortid) {
 threadsort_checkoption();
}

$action = 'reply'; //zzcity add
$replyno = empty($replyno) ? '0' : $_REQUEST['replyno']; //zzcity add
$timestamp = time()+$replyno*5*60;  //zzcity add

/*
if(empty($action)) {

 showmessage('undefined_action', NULL, 'HALTED');

}elseif($action == 'threadsorts') {
 threadsort_optiondata();
 $template = intval($operate) ? 'search_sortoption' : 'post_sortoption';
 include template($template);
 exit;

} elseif(($forum['simple'] & 1) || $forum['redirect']) {
 showmessage('forum_disablepost');
}
*/

require_once DISCUZ_ROOT.'./include/discuzcode.func.php';

if($action == 'reply') {
 $addfeedcheck = $customaddfeed & 4 ? 'checked="checked"': '';
} elseif(!empty($special) && $action != 'reply') {
 $addfeedcheck = $customaddfeed & 2 ? 'checked="checked"': '';
} else {
 $addfeedcheck = $customaddfeed & 1 ? 'checked="checked"': '';
}


$navigation = $navtitle = $thread = '';
if(!empty($cedit)) {
 unset($inajax, $infloat, $ajaxtarget, $handlekey);
}

if($action == 'edit' || $action == 'reply') {

 if($thread = $db->fetch_first("SELECT * FROM {$tablepre}threads WHERE tid='$tid'".($auditstatuson ? '' : " AND displayorder>='0'"))) {

  $navigation = "&raquo; <a href=\"viewthread.php?tid=$tid\">$thread[subject]</a>";
  $navtitle = $thread['subject'].' - ';
  /*if($thread['readperm'] && $thread['readperm'] > $readaccess && !$forum['ismoderator'] && $thread['authorid'] != $discuz_uid) {
   showmessage('thread_nopermission', NULL, 'NOPERM');
  }
*/
  $fid = $thread['fid'];
  $special = $thread['special'];

 } else {
  //showmessage('thread_nonexistence');
  echo('[err]'.$language['thread_nonexistence'].'[/err]');
  exit;  
 }
/*
 if($action == 'reply' && ($thread['closed'] == 1) && !$forum['ismoderator']) {
  showmessage('post_thread_closed');
 }
*/
}

$navigation = "&raquo; <a href=\"forumdisplay.php?fid=$fid".($extra ? '&'.preg_replace("/^(&)*/", '', $extra) : '')."\">$forum[name]</a> $navigation";
$navtitle = $navtitle.strip_tags($forum['name']).' - ';

if($forum['type'] == 'sub') {
 $fup = $db->fetch_first("SELECT name, fid FROM {$tablepre}forums WHERE fid='$forum[fup]'");
 $navigation = "&raquo; <a href=\"forumdisplay.php?fid=$fup[fid]\">$fup[name]</a> $navigation";
 $navtitle = $navtitle.strip_tags($fup['name']).' - ';
}

periodscheck('postbanperiods');
/*
if($forum['password'] && $forum['password'] != $_DCOOKIE['fidpw'.$fid]) {
 showmessage('forum_passwd', "forumdisplay.php?fid=$fid");
}

if(empty($forum['allowview'])) {
 if(!$forum['viewperm'] && !$readaccess) {
  showmessage('group_nopermission', NULL, 'NOPERM');
 } elseif($forum['viewperm'] && !forumperm($forum['viewperm'])) {
  showmessagenoperm('viewperm', $fid);
 }
} elseif($forum['allowview'] == -1) {
 showmessage('forum_access_view_disallow');
}
*/
formulaperm($forum['formulaperm']);
/*
if(!$adminid && $newbiespan && (!$lastpost || $timestamp - $lastpost < $newbiespan * 3600)) {
 if($timestamp - ($db->result_first("SELECT regdate FROM {$tablepre}members WHERE uid='$discuz_uid'")) < $newbiespan * 3600) {
  showmessage('post_newbie_span');
 }
}
*/
$special = $special > 0 && $special < 7 || $special == 127 ? intval($special) : 0;

$allowpostattach = $forum['allowpostattach'] != -1 && ($forum['allowpostattach'] == 1 || (!$forum['postattachperm'] && $allowpostattach) || ($forum['postattachperm'] && forumperm($forum['postattachperm'])));
$attachextensions = $forum['attachextensions'] ? $forum['attachextensions'] : $attachextensions;
if($attachextensions) {
 $imgexts = explode(',', str_replace(' ', '', $attachextensions));
 $imgexts = array_intersect(array('jpg','jpeg','gif','png','bmp'), $imgexts);
 $imgexts = implode(', ', $imgexts);
} else {
 $imgexts = 'jpg, jpeg, gif, png, bmp';
}
$allowuploadnum = TRUE;
if($allowpostattach) {
 if($maxattachnum) {
  $allowuploadnum = $maxattachnum - $db->result_first("SELECT count(*) FROM {$tablepre}attachments WHERE uid='$discuz_uid' AND dateline>'$timestamp'-86400");
  $allowuploadnum = $allowuploadnum < 0 ? 0 : $allowuploadnum;
 }
 if($maxsizeperday) {
  $allowuploadsize = $maxsizeperday - intval($db->result_first("SELECT SUM(filesize) FROM {$tablepre}attachments WHERE uid='$discuz_uid' AND dateline>'$timestamp'-86400"));
  $allowuploadsize = $allowuploadsize < 0 ? 0 : $allowuploadsize;
  $allowuploadsize = $allowuploadsize / 1048576 >= 1 ? round(($allowuploadsize / 1048576), 1).'MB' : round(($allowuploadsize / 1024)).'KB';
 }
}

$allowpostimg = $allowpostattach && $imgexts;
$enctype = $allowpostattach ? 'enctype="multipart/form-data"' : '';
$maxattachsize_mb = $maxattachsize / 1048576 >= 1 ? round(($maxattachsize / 1048576), 1).'MB' : round(($maxattachsize / 1024)).'KB';

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

$maxprice = isset($extcredits[$creditstrans]) ? $maxprice : 0;

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

$subject = isset($subject) ? dhtmlspecialchars(censor(trim($subject))) : '';
$subject = !empty($subject) ? str_replace("\t", ' ', $subject) : $subject;
$message = isset($message) ? censor(trim($message)) : '';
$polloptions = isset($polloptions) ? censor(trim($polloptions)) : '';
$readperm = isset($readperm) ? intval($readperm) : 0;
$price = isset($price) ? intval($price) : 0;
$tagstatus = $tagstatus && $forum['allowtag'] ? ($tagstatus == 2 ? 2 : $forum['allowtag']) : 0;

if(empty($bbcodeoff) && !$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;
 $modnewthreads = $modnewreplies = 0;
//} else {
 $censormod = censormod($subject."\t".$message);
// $modnewthreads = (!$allowdirectpost || $allowdirectpost == 1) && $forum['modnewposts'] || $censormod ? 1 : 0;
// $modnewreplies = (!$allowdirectpost || $allowdirectpost == 2) && $forum['modnewposts'] == 2 || $censormod ? 1 : 0;
//}

if($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($allowposturl == 0) {
    showmessage('post_url_nopermission');
   } elseif($allowposturl == 1) {
    $modnewthreads = $modnewreplies = 1;
    break;
   } elseif($allowposturl == 2) {
    $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 = '';
if($discuz_uid) {
 if($db->result_first("SELECT COUNT(*) FROM {$tablepre}favoritethreads WHERE tid='$tid' AND uid='$discuz_uid'")) {
  $has_attention = true;
 }
}

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

$allowpostpoll = $allowpost && $allowpostpoll && ($forum['allowpostspecial'] & 1);
$allowposttrade = $allowpost && $allowposttrade && ($forum['allowpostspecial'] & 2);
$allowpostreward = $allowpost && $allowpostreward && ($forum['allowpostspecial'] & 4) && isset($extcredits[$creditstrans]);
$allowpostactivity = $allowpost && $allowpostactivity && ($forum['allowpostspecial'] & 8);
$allowpostdebate = $allowpost && $allowpostdebate && ($forum['allowpostspecial'] & 16);
$usesigcheck = $discuz_uid && $sigstatus ? 'checked="checked"' : '';
$ordertypecheck = getstatus($thread['status'], 4) ? 'checked="checked"' : '';

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

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

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

 if(!$special && !$specialextra) {
  showmessage('undefined_action', NULL, 'HALTED');
 }
}

$editorid = 'e';
$editoroptions = str_pad(decbin($editoroptions), 2, 0, STR_PAD_LEFT);
$editormode = $editormode == 2 ? $editoroptions{0} : $editormode;
$allowswitcheditor = $editoroptions{1};
if($specialextra) {
 $special = 127;
 if(@in_array($specialextra, $pluginlangs)) {
  @include_once DISCUZ_ROOT.'./forumdata/cache/cache_scriptlang.php';
 }
}

if($action == 'newthread') {
 $policykey = 'post';
} elseif($action == 'reply') {
 $policykey = 'reply';
} else {
 $policykey = '';
}
if($policykey) {
 $postcredits = $forum[$policykey.'credits'] ? $forum[$policykey.'credits'] : $creditspolicy[$policykey];
}
/*
$posturl = "action=$action&fid=$fid".
 (!empty($tid) ? "&tid=$tid" : '').
 (!empty($pid) ? "&pid=$pid" : '').
 (!empty($special) ? "&special=$special" : '').
 (!empty($sortid) ? "&sortid=$sortid" : '').
 (!empty($typeid) ? "&sortid=$typeid" : '').
 (!empty($firstpid) ? "&firstpid=$firstpid" : '').
 (!empty($addtrade) ? "&addtrade=$addtrade" : '');

if($action == 'newthread') {
 ($forum['allowpost'] == -1) && showmessage('forum_access_disallow');
 require_once DISCUZ_ROOT.'./include/newthread.inc.php';
} elseif($action == 'reply') {
 ($forum['allowreply'] == -1) && showmessage('forum_access_disallow');
 require_once DISCUZ_ROOT.'./include/newreply.inc.php';
} elseif($action == 'edit') {
 ($forum['allowpost'] == -1) && showmessage('forum_access_disallow');
 require_once DISCUZ_ROOT.'./include/editpost.inc.php';
} elseif($action == 'newtrade') {
 ($forum['allowpost'] == -1) && showmessage('forum_access_disallow');
 require_once DISCUZ_ROOT.'./include/newtrade.inc.php';
}
*/
//newreply.inc.php代码开始
if(!defined('IN_DISCUZ')) {
 exit('Access Denied');
}
$discuz_action = 12;
/*
if($special == 5) {
 $debate = array_merge($thread, $db->fetch_first("SELECT * FROM {$tablepre}debates WHERE tid='$tid'"));
 $standquery = $db->query("SELECT stand FROM {$tablepre}debateposts WHERE tid='$tid' AND uid='$discuz_uid' AND stand<>'0' ORDER BY dateline LIMIT 1");
 $firststand = $db->result_first("SELECT stand FROM {$tablepre}debateposts WHERE tid='$tid' AND uid='$discuz_uid' AND stand<>'0' ORDER BY dateline LIMIT 1");

 if($debate['endtime'] && $debate['endtime'] < $timestamp) {
  showmessage('debate_end');
 }
}

if(!$discuz_uid && !((!$forum['replyperm'] && $allowreply) || ($forum['replyperm'] && forumperm($forum['replyperm'])))) {
 showmessage('replyperm_login_nopermission', NULL, 'NOPERM');
} elseif(empty($forum['allowreply'])) {
 if(!$forum['replyperm'] && !$allowreply) {
  showmessage('replyperm_none_nopermission', NULL, 'NOPERM');
 } elseif($forum['replyperm'] && !forumperm($forum['replyperm'])) {
  showmessagenoperm('replyperm', $forum['fid']);
 }
} elseif($forum['allowreply'] == -1) {
 showmessage('post_forum_newreply_nopermission', NULL, 'HALTED');
}

if(empty($thread)) {
 showmessage('thread_nonexistence');
} elseif($thread['price'] > 0 && $thread['special'] == 0 && !$discuz_uid) {
 showmessage('group_nopermission', NULL, 'NOPERM');
}

checklowerlimit($replycredits);
*/
if($special == 127) {
 $postinfo = $db->fetch_first("SELECT message FROM {$tablepre}posts WHERE tid='$tid' AND first='1'");
 $sppos = strrpos($postinfo['message'], chr(0).chr(0).chr(0));
 $specialextra = substr($postinfo['message'], $sppos + 3);
 if(!array_key_exists($specialextra, $threadplugins) || !in_array($specialextra, unserialize($forum['threadplugin'])) || !in_array($specialextra, $allowthreadplugin)) {
  $special = 0;
  $specialextra = '';
 }
}
/*
if(!submitcheck('replysubmit', 0, $seccodecheck, $secqaacheck)) {

 if($thread['special'] == 2 && ((!isset($addtrade) || $thread['authorid'] != $discuz_uid) && !$tradenum = $db->result_first("SELECT count(*) FROM {$tablepre}trades WHERE tid='$tid'"))) {
  showmessage('trade_newreply_nopermission', NULL, 'HALTED');
 }

 include_once language('misc');
 $noticeauthor = $noticetrimstr = '';
 if(isset($repquote)) {

  $thaquote = $db->fetch_first("SELECT tid, fid, author, authorid, first, message, useip, dateline, anonymous, status FROM {$tablepre}posts WHERE pid='$repquote' AND invisible='0'");
  if($thaquote['tid'] != $tid) {
   showmessage('undefined_action', NULL, 'HALTED');
  }

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

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

   if($bannedmessages && $thaquote['authorid']) {
    $author = $db->fetch_first("SELECT groupid FROM {$tablepre}members 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 = gmdate("$dateformat $timeformat", $thaquote['dateline'] + ($timeoffset * 3600));
   $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'];
   }

   eval("\$language['post_reply_quote'] = \"$language[post_reply_quote]\";");
   $noticeauthormsg = htmlspecialchars($message);
   $message = "[quote]$message\n[size=2][color=#999999]$language[post_reply_quote][/color] [url={$boardurl}redirect.php?goto=findpost&pid=$repquote&ptid=$tid][img]{$boardurl}images/common/back.gif[/img][/url][/size][/quote]\n\n\n    ";
   $noticeauthor = htmlspecialchars('q|'.$thaquote['authorid'].'|'.$thaquote['author']);
   $noticetrimstr = htmlspecialchars($message);
  }

 } elseif(isset($reppost)) {

  $thapost = $db->fetch_first("SELECT tid, author, authorid, useip, dateline, anonymous, status, message FROM {$tablepre}posts WHERE pid='$reppost' AND invisible='0'");
  if($thapost['tid'] != $tid) {
   showmessage('undefined_action', NULL, 'HALTED');
  }

  $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]';
  }

  $thapost['number'] = $db->result_first("SELECT count(*) FROM {$tablepre}posts WHERE tid='$thapost[tid]' AND dateline<='$thapost[dateline]'");
  $message = "[b]$language[post_reply] [url={$boardurl}redirect.php?goto=findpost&pid=$reppost&ptid=$thapost[tid]]$thapost[number]#[/url] $thapost[author] $lang[post_thread][/b]\n\n\n    ";
  $noticeauthormsg = htmlspecialchars(messagecutstr($thapost['message'], 100));
  $noticeauthor = htmlspecialchars('r|'.$thapost['authorid'].'|'.$thapost['author']);
  $noticetrimstr = htmlspecialchars($message);

 }

 if(isset($addtrade) && $thread['special'] == 2 && $allowposttrade && $thread['authorid'] == $discuz_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'] <= $ppp) {
  $postlist = array();
  $query = $db->query("SELECT p.* ".($bannedmessages ? ', m.groupid ' : '').
   "FROM {$tablepre}posts p ".($bannedmessages ? "LEFT JOIN {$tablepre}members m ON p.authorid=m.uid " : '').
   "WHERE p.tid='$tid' AND p.invisible='0' ".($thread['price'] > 0 && $thread['special'] == 0 ? 'AND p.first = 0' : '')." ORDER BY p.dateline DESC");
  while($post = $db->fetch_array($query)) {

   $post['dateline'] = dgmdate("$dateformat $timeformat", $post['dateline'] + $timeoffset * 3600);

   if($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, $forum['allowsmilies'], $forum['allowbbcode'], $forum['allowimgcode'], $forum['allowhtml'], $forum['jammer']);
   }

   $postlist[] = $post;
  }
 }

 if($special == 2 && isset($addtrade) && $thread['authorid'] == $discuz_uid) {
  $tradetypeselect = '';
  $forum['tradetypes'] = $forum['tradetypes'] == '' ? -1 : unserialize($forum['tradetypes']);
  if($tradetypes && !empty($forum['tradetypes'])) {
   $tradetypeselect = '<select name="tradetypeid" onchange="ajaxget(\'post.php?action=threadsorts&tradetype=yes&sortid=\'+this.options[this.selectedIndex].value+\'&sid='.$sid.'\', \'threadtypes\', \'threadtypeswait\')"><option value="0">&nbsp;</option>';
   foreach($tradetypes as $typeid => $name) {
    if($forum['tradetypes'] == -1 || @in_array($typeid, $forum['tradetypes'])) {
     $tradetypeselect .= '<option value="'.$typeid.'">'.strip_tags($name).'</option>';
    }
   }
   $tradetypeselect .= '</select><span id="threadtypeswait"></span>';
  }
 }

 if($allowpostattach) {
  $attachlist = getattach();
  $attachs = $attachlist['attachs'];
  $imgattachs = $attachlist['imgattachs'];
  unset($attachlist);
 }

 $infloat ? include template('post_infloat') : include template('post');

} else {
*/
 require_once DISCUZ_ROOT.'./include/forum.func.php';
 //zzcity add
 $subject='';
 if ($message == ''){
  echo('[err]message is null[/err]');
  exit();

 }
/*
 if($subject == '' && $message == '' && $thread['special'] != 2) {
  showmessage('post_sm_isnull');
 } elseif($thread['closed'] && !$forum['ismoderator']) {
  showmessage('post_thread_closed');
 } elseif($post_autoclose = checkautoclose()) {
  showmessage($post_autoclose);
 } elseif($post_invalid = checkpost($special == 2 && $allowposttrade)) {
  showmessage($post_invalid);
 } elseif(checkflood()) {
  showmessage('post_flood_ctrl');
 }
 if(!empty($trade) && $thread['special'] == 2 && $allowposttrade) {

  $item_price = floatval($item_price);
  $item_credit = intval($item_credit);
  if(!trim($item_name)) {
   showmessage('trade_please_name');
  } elseif($maxtradeprice && $item_price > 0 && ($mintradeprice > $item_price || $maxtradeprice < $item_price)) {
   showmessage('trade_price_between');
  } elseif($maxtradeprice && $item_credit > 0 && ($mintradeprice > $item_credit || $maxtradeprice < $item_credit)) {
   showmessage('trade_credit_between');
  } elseif(!$maxtradeprice && $item_price > 0 && $mintradeprice > $item_price) {
   showmessage('trade_price_more_than');
  } elseif(!$maxtradeprice && $item_credit > 0 && $mintradeprice > $item_credit) {
   showmessage('trade_credit_more_than');
  } elseif($item_price <= 0 && $item_credit <= 0) {
   showmessage('trade_pricecredit_need');
  } elseif($item_number < 1) {
   showmessage('tread_please_number');
  }

  threadsort_checkoption(1, 1);

  $optiondata = array();
  if($tradetypes && $typeoption && $checkoption) {
   $optiondata = threadsort_validator($typeoption);
  }

 }
*/
 $attentionon = empty($attention_add) ? 0 : 1;
 $attentionoff = empty($attention_remove) ? 0 : 1;

 if($thread['lastposter'] != $discuz_userss) {
  $userreplies = $db->result_first("SELECT COUNT(*) FROM {$tablepre}posts WHERE tid='$tid' AND first='0' AND authorid='$discuz_uid'");
  $thread['heats'] += round($heatthread['reply'] * pow(0.8, $userreplies));
  $heatbefore = $thread['heats'];
  $db->query("UPDATE {$tablepre}threads SET heats='$thread[heats]' WHERE tid='$tid'", 'UNBUFFERED');
 }

 $bbcodeoff = checkbbcodes($message, !empty($bbcodeoff));
 $smileyoff = checksmilies($message, !empty($smileyoff));
 $parseurloff = !empty($parseurloff);
 //$htmlon = $allowhtml && !empty($htmlon) ? 1 : 0;
 $htmlon = ($htmlon==1 || !isset($htmlon)) ? 1 : 0; //zzcity add

 $usesig = !empty($usesig) ? 1 : 0;

 $isanonymous = $allowanonymous && !empty($isanonymous)? 1 : 0;
 $author = empty($isanonymous) ? $discuz_user : '';

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

 $db->query("INSERT INTO {$tablepre}posts (fid, tid, first, author, authorid, subject, dateline, message, useip, invisible, anonymous, usesig, htmlon, bbcodeoff, smileyoff, parseurloff, attachment)
   VALUES ('$fid', '$tid', '0', '$discuz_user', '$discuz_uid', '$subject', '$timestamp', '$message', '$onlineip', '$pinvisible', '$isanonymous', '$usesig', '$htmlon', '$bbcodeoff', '$smileyoff', '$parseurloff', '0')");
 $pid = $db->insert_id();
 $cacheposition = getstatus($thread['status'], 1);
 if($pid && $cacheposition) {
  savepostposition($tid, $pid);
 }

 $nauthorid = 0;
 if(!empty($noticeauthor) && !$isanonymous) {
  list($ac, $nauthorid, $nauthor) = explode('|', $noticeauthor);
  if($nauthorid != $discuz_uid) {
   $postmsg = messagecutstr(str_replace($noticetrimstr, '', $message), 100);
   if($ac == 'q') {
    sendnotice($nauthorid, 'repquote_noticeauthor', 'threads');
   } elseif($ac == 'r') {
    sendnotice($nauthorid, 'reppost_noticeauthor', 'threads');
   }
  }
 }

 $uidarray = array();
 $query = $db->query("SELECT uid FROM {$tablepre}favoritethreads WHERE tid='$tid'");
 while($favthread = $db->fetch_array($query)) {
  if($favthread['uid'] !== $discuz_uid && (!$nauthorid || $nauthorid != $favthread['uid'])) {
   $uidarray[] = $favthread['uid'];
  }
 }
 if($discuz_uid && !empty($uidarray)) {
  sendnotice(implode(',', $uidarray), 'favoritethreads_notice', 'threads', $tid, array('user' => (!$isanonymous ? $discuz_userss : '<i>Anonymous</i>'), 'maxusers' => 5));
  $db->query("UPDATE {$tablepre}favoritethreads SET newreplies=newreplies+1, dateline='$timestamp' WHERE uid IN (".implodeids($uidarray).") AND tid='$tid'", 'UNBUFFERED');
 }
 if($discuz_uid) {
  $stataction = '';
  if($attentionon) {
   $stataction = 'attentionon';
   $db->query("REPLACE INTO {$tablepre}favoritethreads (tid, uid, dateline) VALUES ('$tid', '$discuz_uid', '$timestamp')", 'UNBUFFERED');
  }
  if($attentionoff) {
   $stataction = 'attentionoff';
   $db->query("DELETE FROM {$tablepre}favoritethreads WHERE tid='$tid' AND uid='$discuz_uid'", 'UNBUFFERED');
  }
  if($stataction) {
   write_statlog('', 'item=attention&action=newreply_'.$stataction, '', '', 'my.php');
  }
 }
/*
 if($special == 3 && $thread['authorid'] != $discuz_uid && $thread['price'] > 0) {

  $rewardlog = $db->fetch_first("SELECT * FROM {$tablepre}rewardlog WHERE tid='$tid' AND answererid='$discuz_uid'");
  if(!$rewardlog) {
   $db->query("INSERT INTO {$tablepre}rewardlog (tid, answererid, dateline) VALUES ('$tid', '$discuz_uid', '$timestamp')");
  }

 } elseif($special == 5) {

  $stand = $firststand ? $firststand : intval($stand);

  if(!$db->num_rows($standquery)) {
   if($stand == 1) {
    $db->query("UPDATE {$tablepre}debates SET affirmdebaters=affirmdebaters+1 WHERE tid='$tid'");
   } elseif($stand == 2) {
    $db->query("UPDATE {$tablepre}debates SET negadebaters=negadebaters+1 WHERE tid='$tid'");
   }
  } else {
   $stand = $firststand;
  }
  if($stand == 1) {
   $db->query("UPDATE {$tablepre}debates SET affirmreplies=affirmreplies+1 WHERE tid='$tid'");
  } elseif($stand == 2) {
   $db->query("UPDATE {$tablepre}debates SET negareplies=negareplies+1 WHERE tid='$tid'");
  }
  $db->query("INSERT INTO {$tablepre}debateposts (tid, pid, uid, dateline, stand, voters, voterids) VALUES ('$tid', '$pid', '$discuz_uid', '$timestamp', '$stand', '0', '')");
 }
*/
 $allowpostattach && ($attachnew || $attachdel || $special == 2 && $tradeaid) && updateattach();

 $replymessage = 'post_reply_succeed';
/*
 if($special == 2 && $allowposttrade && $thread['authorid'] == $discuz_uid && !empty($trade) && !empty($item_name)) {

  if($tradetypes && $optiondata) {
   foreach($optiondata as $optionid => $value) {
    $db->query("INSERT INTO {$tablepre}tradeoptionvars (sortid, pid, optionid, value)
     VALUES ('$tradetypeid', '$pid', '$optionid', '$value')");
   }
  }

  require_once DISCUZ_ROOT.'./include/trade.func.php';
  trade_create(array(
   'tid' => $tid,
   'pid' => $pid,
   'aid' => $tradeaid,
   'typeid' => $tradetypeid,
   'item_expiration' => $item_expiration,
   'thread' => $thread,
   'discuz_uid' => $discuz_uid,
   'author' => $author,
   'seller' => $seller,
   'item_name' => $item_name,
   'item_price' => $item_price,
   'item_number' => $item_number,
   'item_quality' => $item_quality,
   'item_locus' => $item_locus,
   'transport' => $transport,
   'postage_mail' => $postage_mail,
   'postage_express' => $postage_express,
   'postage_ems' => $postage_ems,
   'item_type' => $item_type,
   'item_costprice' => $item_costprice,
   'item_credit' => $item_credit,
   'item_costcredit' => $item_costcredit
  ));

  $replymessage = 'trade_add_succeed';

 }
*/
 if($specialextra) {

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

 }

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

 if($modnewreplies) {
  $db->query("UPDATE {$tablepre}forums SET todayposts=todayposts+1 WHERE fid='$fid'", 'UNBUFFERED');
  showmessage('post_reply_mod_succeed', "forumdisplay.php?fid=$fid");
 } else {

  $db->query("UPDATE {$tablepre}threads SET lastposter='$author', lastpost='$timestamp', replies=replies+1 WHERE tid='$tid'", 'UNBUFFERED');

  updatepostcredits('+', $discuz_uid, $replycredits);

  $lastpost = "$thread[tid]\t".addslashes($thread['subject'])."\t$timestamp\t$author";
  $db->query("UPDATE {$tablepre}forums SET lastpost='$lastpost', posts=posts+1, todayposts=todayposts+1 WHERE fid='$fid'", 'UNBUFFERED');
  if($forum['type'] == 'sub') {
   $db->query("UPDATE {$tablepre}forums SET lastpost='$lastpost' WHERE fid='$forum[fup]'", 'UNBUFFERED');
  }
/*
  $feed = array();
  if($addfeed && $forum['allowfeed'] && $thread['authorid'] != $discuz_uid && !$isanonymous) {
   if($special == 2 && !empty($trade) && !empty($item_name) && !empty($item_price)) {
    $feed['icon'] = 'goods';
    $feed['title_template'] = 'feed_thread_goods_title';
    $feed['body_template'] = 'feed_thread_goods_message';
    $feed['body_data'] = array(
     'itemname'=> "<a href=\"{$boardurl}viewthread.php?do=tradeinfo&tid=$tid&pid=$pid\">$item_name</a>",
     'itemprice'=> $item_price
    );
   } elseif($special == 3) {
    $feed['icon'] = 'reward';
    $feed['title_template'] = 'feed_reply_reward_title';
    $feed['title_data'] = array(
     'subject' => "<a href=\"{$boardurl}viewthread.php?tid=$tid\">$thread[subject]</a>",
     'author' => "<a href=\"space.php?uid=$thread[authorid]\">$thread[author]</a>"
    );
   } elseif($special == 5) {
    $feed['icon'] = 'debate';
    $feed['title_template'] = 'feed_thread_debatevote_title';
    $feed['title_data'] = array(
     'subject' => "<a href=\"{$boardurl}viewthread.php?tid=$tid\">$thread[subject]</a>",
     'author' => "<a href=\"space.php?uid=$thread[authorid]\">$thread[author]</a>"
    );
   } else {
    $feed['icon'] = 'post';
    $feed['title_template'] = 'feed_reply_title';
    $feed['title_data'] = array(
     'subject' => "<a href=\"{$boardurl}viewthread.php?tid=$tid\">$thread[subject]</a>",
     'author' => "<a href=\"space.php?uid=$thread[authorid]\">$thread[author]</a>"
    );
   }
   postfeed($feed);
  }

  if(is_array($dzfeed_limit['thread_replies']) && in_array(($thread['replies'] + 1), $dzfeed_limit['thread_replies'])) {
   $arg = $data = array();
   $arg['type'] = 'thread_replies';
   $arg['fid'] = $thread['fid'];
   $arg['typeid'] = $thread['typeid'];
   $arg['sortid'] = $thread['sortid'];
   $arg['uid'] = $thread['authorid'];
   $arg['username'] = addslashes($thread['author']);
   $data['title']['actor'] = $thread['authorid'] ? "<a href=\"space.php?uid={$thread[authorid]}\" target=\"_blank\">{$thread[author]}</a>" : $thread['author'];
   $data['title']['forum'] = "<a href=\"forumdisplay.php?fid={$thread[fid]}\" target=\"_blank\">".$forum['name'].'</a>';
   $data['title']['count'] = $thread['replies'] + 1;
   $data['title']['subject'] = "<a href=\"viewthread.php?tid={$thread[tid]}\" target=\"_blank\">{$thread[subject]}</a>";
   add_feed($arg, $data);
  }

  if(is_array($dzfeed_limit['user_posts']) && in_array(($posts + 1), $dzfeed_limit['user_posts'])) {
   $arg = $data = array();
   $arg['type'] = 'user_posts';
   $arg['uid'] = $discuz_uid;
   $arg['username'] = $discuz_userss;
   $data['title']['actor'] = "<a href=\"space.php?uid={$discuz_uid}\" target=\"_blank\">{$discuz_user}</a>";
   $data['title']['count'] = $posts + 1;
   add_feed($arg, $data);
  }
  
  $page = getstatus($thread['status'], 4) ? 1 : @ceil(($thread['special'] ? $thread['replies'] + 1 : $thread['replies'] + 2) / $ppp);
  showmessage($replymessage, "viewthread.php?tid=$tid&pid=$pid&page=$page&extra=$extra#pid$pid");
*/
  echo("[ok]pid=$pid");
  exit();   

 }

//}
//newreply.inc.php代码结束?>