zoukankan      html  css  js  c++  java
  • discuz数据批量入库接口

       近期在做社区,首选discuz,数据需要用scrapy爬虫批量入库,就写了一个php入库接口。

       

    <?php
    define('PW', 'abc123456');//一定要修改
    if($_REQUEST['pw'] !== PW){
    	exit('密码错误');
    }
    error_reporting(E_ERROR | E_WARNING | E_PARSE);
    define('APPTYPEID', 2);
    define('CURSCRIPT', 'forum');
    define('JK_CHARSET','gbk');
    require './source/class/class_core.php';
    require './source/function/function_forum.php';
    C::app()->init();
    @set_time_limit(0);
    /****************配置信息华丽的分割线***************/
    $config = array
    (
    	'使用签名'			=>			0,							//使用签名(1或0)
    	'注册会员邮件后缀'	=>			'126.com|||163.com',		//多个用|||分割
    	'数据库用户'			=>			0,							//是否从数据随机取出用户,如果为1从数据库随机取出数据。
    	'回复用户名'			=>			'回复用户1|||回复用户2|||回复用户3|||回复用户4|||回复用户5|||回复用户6',	
    	//回复用户名,把想充当回复的用户名放到这里,用|||分割,用户名不需要在论坛已经存在,如果没有会自动注册
    	'用户密码'			=>			'',								//新注册用户的密码			
    	'用户密码参数'		=>			'jksdjfs',						//用户密码参数,建议随意修改
    	'回复间隔'			=>			array( 30 , 60 ),				//回复间隔,单位是秒。会随机在2个数字的中间取值
    	'回复用户签名'		=>			'',//回复用户签名,为空新注册的用户没有签名,否则设置签名,随机签名
    	'分隔符'				=>			'|||',							//采集器标签循环的分隔符
    	'附件权限组'			=>			'',							//权限多个用|分割
    	'附件价格'			=>			'0',				//价格多个用|分割
    	'附件隐藏'			=>			0,
    	'fname'				=>			array(						//用来映射fid的值的
    									'板块1'=>'1',
    									'板块2'=>'2',
    								),
    	'typename'			=>			array(						//用来映射typeid的值的
    									'站长杂谈'=>'1',
    									'分类2'=>'2',
    								),
    	'标题允许重复'		=>			'1',						//为0的话不允许标题重复
    	'新注册用户群组'		=>			array(),					//用户组的id写里面,新注册的用户就是这个用户组了。可以写多个。如:array(16,17,18);		
    );
    /****************配置信息华丽的分割线***************/
    $j = new jiekou();
    if(empty($_POST)){
    	$j->makeCat(getgpc('type'));
    	//memory('rm', '2', 'forumdisplay_');
    }else{
    	define('NOROBOT', TRUE);
    	$j->checkAndInitData();
    	runhooks();
    	set_rssauth();
    	loadforum();
    	require_once libfile('function/misc');
    	require_once libfile('function/member');
    	loaducenter();
    	$j->logonUser();
    	$j->newthread();
    	$j->reply();
    	exit('发布成功');
    }
    class jiekou
    {
    	public $replys 	= array();
    	public $file	= array();
    	/**
    	 * 生成栏目列表
    	 */
    	public function makeCat($type = 'forum')
    	{
    		function maketree($ar,$id,$pre)
    		{
    			$ids='';
    			foreach($ar as $k=>$v){
    				$pid=$v['fud'];
    				$cname=$v['name'];
    				$cid=$v['fid'];
    				if($pid==$id)
    				{
    					$ids.="<option value='$cid'>{$pre}{$cname}</option>";
    					foreach($ar as $kk=>$vv)
    					{
    						$pp=$vv['pid'];
    						if($pp==$cid)
    						{
    							$ids.=maketree($ar,$cid,$pre."  ");
    							break;
    						}
    					}
    				}
    			}
    			return $ids;
    		}
    		if($type == 'group'){
    			$cates = DB::fetch_all("SELECT * FROM ".DB::table('forum_forum')." WHERE status='3' AND type = 'sub'");
    		}else{
    			$cates = C::t('forum_forum')->fetch_all_valid_forum();
    		}
    		echo "<select name='list'>";
    		echo maketree($cates,0,'');
    		echo '</select>';
    		exit;
    	}
    	
    	/**
    	 * 检测以及初始化数据
    	 */
    	public function checkAndInitData()
    	{
    		global $_G , $config;
    		$fid = intval(getgpc('fid'));
    		$sortid = intval(getgpc('sortid'));
    		$typeid = intval(getgpc('typeid'));
    		$special = intval(getgpc('special'));
    		if(empty($sortid) && !empty($_POST['sortname'])){
    			$_POST['sortid'] = intval($config['sortname'][trim($_POST['sortname'])]);
    		}
    		if(empty($typeid) && !empty($_POST['typename'])){
    			$_POST['typeid'] = intval($config['typename'][trim($_POST['typename'])]);
    		}
    		if(empty($fid) && !empty($_GET['fname'])){
    			$_GET['fid'] = intval($config['fname'][trim($_GET['fname'])]);
    		}
    		if(empty($_GET['fid']) || empty($_GET['subject']) || empty($_GET['message']) || empty($_GET['username'])){
    			echo '错误缺少参数:';
    			empty($_GET['fid']) && print('fid ');
    			empty($_GET['subject']) && print('标题 ');
    			empty($_GET['message']) && print('内容 ');
    			empty($_GET['username']) && print('作者 ');
    			exit();
    		}else{
    			$this->subject = trim($_POST['subject']);
    			$messageArr = explode($config['分隔符'] , trim($_POST['message']));
    			$usernameArr = explode($config['分隔符'] , trim($_POST['username']));
    			foreach($usernameArr as $k =>$v){
    				$usernameArr[$k] = trim($v); 
    				if(!$this->check_username($v)){
    					unset($usernameArr[$k]);
    				}
    			}
    			
    			$this->message = array_shift($messageArr);
    			$this->username = array_shift($usernameArr);
    			
    			isset($_POST['price']) && $this->price = intval(trim($_POST['price']));
    			isset($_POST['readperm']) && $this->readperm = intval($_POST['readperm']);
    		}
    		if(!empty($_POST['publishdate'])){
    			$publish_date_arr = explode($config['分隔符'] , trim($_POST['publishdate']));
    			$publish_date_tmp = array_shift($publish_date_arr);
    			$publish_date = strtotime(trim($publish_date_tmp)); 
    			if($publish_date > 0){
    				$this->publish_date = $publish_date;
    			}else{
    				$this->publish_date = $_G['timestamp'];
    			}
    		}else{
    			$this->publish_date = $_G['timestamp'];
    		}
    		
    		if(!empty($_POST['avatar'])){
    			$avatar_tmp_arr = array_unique(explode($config['分隔符'] , trim($_POST['avatar'])));
    			foreach($avatar_tmp_arr as $k => $v){
    				foreach ($_FILES as $k2 => $v2){
    					if(strpos($k2 , 'avatar') === 0){
    						if(strpos($v , $v2['name']) !== false){
    							$this->avatar[] = array('username' => $v , 'file'=>$v2);
    							break;
    						}
    					}
    				}
    			}
    		}
    		/**if(!empty($_FILES)){
    			$i = 0;
    			while (isset($_FILES['attach'.$i])){
    				$this->attach[] = $_FILES['attach'.$i++];
    		  }
    			//unset($_FILES);
    			//$_FILES=null;
    		}**/
    		
    		$this->save_date = $this->publish_date;
    		if(!empty($messageArr)){
    			if(!empty($usernameArr)){
    				$reply_user = $usernameArr;
    				$is_username_random = false;
    			}elseif(!empty($config['回复用户名'])){
    				$is_username_random = true;
    				$reply_user = explode('|||', $config['回复用户名']);
    			}else{
    				$reply_user = $this->username;
    			}
    			if(!empty($publish_date_arr)){
    				$reply_times = $publish_date_arr;
    			}
    			//签名
    			if(!empty($_POST['signature'])){
    				$reply_sig = explode($config['分隔符'], trim($_POST['signature']));
    				$this->sightml = array_shift($reply_sig);
    				$is_signature_random = false;
    			//随机用户签名
    			}elseif(!empty($config['回复用户签名'])){
    				$is_signature_random = true;
    				$reply_sig = explode('|||', $config['回复用户签名']);
    				$this->sightml = array_shift($reply_sig);
    			}
    			foreach($messageArr as $k => $v)
    			{
    				$reply_tmp 	= (!$is_username_random && isset($reply_user[$k])) ? $reply_user[$k] : $reply_user[rand(0,count($reply_user)-1)];
    				$sig_tmp 	= (!$is_signature_random && isset($reply_sig[$k])) ? $reply_sig[$k] : (empty($reply_sig) ? '' : $reply_sig[rand(0,count($reply_sig)-1)]);
    				if(isset($reply_times[$k])){
    					$reply_time_tmp = strtotime($reply_times[$k]);
    					if($reply_time_tmp > 0){
    						 $this->save_date = $reply_time_tmp;
    					}else{
    						$this->save_date = $reply_time_tmp = $this->save_date + rand($config['回复间隔'][0] , $config['回复间隔'][1]);
    					}
    				}else{
    					$this->save_date = $reply_time_tmp = $this->save_date + rand($config['回复间隔'][0] , $config['回复间隔'][1]);
    				}
    				$this->replys[$k] = array(
    						'message' 		=>	$v , 
    						'username'		=>	$reply_tmp ,
    						'publishdate' 	=>	$reply_time_tmp ,
    						'signature'		=>	$sig_tmp
    					);
    			}
    		}
    	}
    	
    	/**
    	 * 得到随机ip
    	 */ 
    	private function randomip()
    	{
    		return rand(0,255).'.'.rand(0,255).'.'.rand(0,255).'.'.rand(0,255);
    	}
    	
    	public function logonUser($username = '')
    	{
    		empty($username) && $username = $this->username;
    		global $_G , $config;
    		$user = uc_get_user($username);
    		$uid = $user[0];
    		$ip = $this->randomip();
    		$groupinfo = array();
    		$groupinfo['groupid'] = empty($config['新注册用户群组']) ? $_G['setting']['newusergroupid'] : (is_array($config['新注册用户群组']) ? $config['新注册用户群组'][rand(0,count($config['新注册用户群组'])-1)] : $config['新注册用户群组']);
    		$init_arr = array('credits' => explode(',', $_G['setting']['initcredits']), 'profile'=>array());
    		if($user){
    			if(!C::t('common_member')->fetch_uid_by_username($username)){
    				C::t('common_member')->insert($uid, $username, md5(1), $user[2], $ip, $groupinfo['groupid'], $init_arr);
    			}
    			$member = getuserbyuid($user[0]);
    			$this->setloginstatus($member , 0);
    		}else{
    			if(!empty($config['用户密码'])){
    				$password = $config['用户密码'];
    			}else{
    				$md5 = md5($username.$config['用户密码参数']);
    				$password = substr($md5, 20);
    			}
    			if(empty($config['注册会员邮件后缀'])){
    				$mail_ext = '@126.com';
    			}else{
    				$mail_arr = explode('|||', $config['注册会员邮件后缀']);
    				$mail_ext = '@'.$mail_arr[rand(0 , count($mail_arr)-1)];
    			}
    			$email = substr($md5, 0 , 6).$mail_ext ;
    			
    			$uid = uc_user_register(addslashes($username), $password , $email , '', '', $ip);
    			if($uid == -1) {
    				exit('错误|用户名包含敏感字符->'.addslashes($username));
    			} elseif($uid == -2) {
    				exit('错误|用户名包含被系统屏蔽的字符');
    			} elseif($uid == -3) {
    				exit('错误|该用户名已被注册');
    			} elseif($uid == -4) {
    				exit('错误|Email 地址无效');
    			} elseif($uid == -5) {
    				exit('错误|抱歉,Email 包含不可使用的邮箱域名');
    			} elseif($uid == -6) {
    				exit('错误|该 Email 地址已被注册');
    			} elseif($uid <= 0) {
    				exit('错误|未定义操作');
    			}
    			if(getuserbyuid($uid, 1)) {
    				uc_user_delete($uid);
    				exit("错误抱歉,用户 ID {$uid} 已被占用");
    			}
    			
    			$setregip = null;
    			if($_G['setting']['regfloodctrl']) {
    				$regip = C::t('common_regip')->fetch_by_ip_dateline($ip, $_G['timestamp']-86400);
    				if($regip) {
    					if($$regip['count'] >= $_G['setting']['regfloodctrl']) {
    						exit('错误ip注册数超过'.$_G['setting']['regfloodctrl']);
    					} else {
    						$setregip = 1;
    					}
    				} else {
    					$setregip = 2;
    				}
    			}
    			if($setregip !== null) {
    				if($setregip == 1) {
    					C::t('common_regip')->update_count_by_ip($ip);
    				} else {
    					C::t('common_regip')->insert(array('ip' => $ip, 'count' => 1, 'dateline' => $_G['timestamp']));
    				}
    			}
    			
    			C::t('common_member')->insert($uid, $username, md5($password), $email, $ip, $groupinfo['groupid'], $init_arr);
    			if(!empty($this->sightml)){
    				C::t('common_member_field_forum')->update($uid, array('sightml' => $this->sightml));
    			}
    			
    			//上传头像
    			$this->postAvatar($uid , $username);
    			require_once libfile('cache/userstats', 'function');
    			build_cache_userstats();
    			//unset($_COOKIE);$_COOKIE = array();
    			$this->setloginstatus(array(
    				'uid' => $uid,
    				'username' => $username,
    				'password' => $password,
    				'groupid' => $groupinfo['groupid'],
    			), 0);
    			include_once libfile('function/stat');
    			updatestat('register');
    		}
    		$_G['group']['allowsigbbcode'] = $_G['group']['allowhtml'] = $_G['group']['allowposttag'] = $_G['group']['allowsetattachperm'] = '1';
    		
    	}
    	private function postAvatar($uid,$username)
    	{
    		global $config;
    	
    		if(empty($this->avatar) || !function_exists('fsockopen')){
    			return false;
    		}
    		//匹配用户名和头像
    		foreach($this->avatar as $k => $v){
    			if(strpos($v['username'] , $username) !== false && is_uploaded_file($v['file']['tmp_name'])){
    				$img_file = $v['file'];
    				$nowkey = $k;
    			}
    		}
    		if(!empty($img_file)){
    			require_once './uc_server/lib/upload.class.php';
    			$uc_datadir = './uc_server/data/';
    			$dir=upload::mkdir_by_uid($uid , $uc_datadir.'avatar/');
    			$ext='jpg';//upload::fileext($img_file['name']);
    			$u = str_pad(substr($uid,-2,2), 2, "0", STR_PAD_LEFT);
    			$bImg=$uc_datadir.'avatar/'.$dir.'/'.$u.'_avatar_big.'.$ext;
    			$mImg=$uc_datadir.'avatar/'.$dir.'/'.$u.'_avatar_middle.'.$ext;
    			$sImg=$uc_datadir.'avatar/'.$dir.'/'.$u.'_avatar_small.'.$ext;
    			upload::thumb(200,200,$img_file['tmp_name'],$bImg,$ext);
    			upload::thumb(120,120,$bImg,$mImg,$ext);
    			upload::thumb(48,48,$bImg,$sImg,$ext);
    		}
    	}
    	
    	private function setloginstatus($member, $cookietime)
    	{
    		global $_G;
    		$_G['uid'] = intval($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']}	{$member['uid']}", 'ENCODE'), $cookietime, 1, true);
    		dsetcookie('loginuser');
    		dsetcookie('activationauth');
    		dsetcookie('pmnum');
    		*/
    		include_once libfile('function/stat');
    		updatestat('login', 1);
    		$rule = updatecreditbyaction('daylogin', $_G['uid']);
    		if(!$rule['updatecredit']) {
    			checkusergroup($_G['uid']);
    		}
    	}
    	
    	private function checkGroup()
    	{
    		global $_G;
    		if($_G['forum']['status'] == 3) {
    			if(!helper_access::check_module('group')) {
    				exit('错误group_status_off');
    			}
    			require_once libfile('function/group');
    			$status = groupperm($_G['forum'], $_G['uid'], 'post');
    			if($status == -1) {
    				exit("错误|该版块不是{$_G['setting']['navs']['3']['navname']}");
    			} elseif($status == 1) {
    				exit("错误|该{$_G['setting']['navs']['3']['navname']}已关闭");
    			} elseif($status == 2) {
    				exit("错误|抱歉,您没有权限访问该{$_G['setting']['navs']['3']['navname']}");
    			} elseif($status == 3) {
    				exit('错误|请等待群主审核');
    			} elseif($status == 4) {
    				exit("错误|抱歉,您还不是本{$_G['setting']['navs']['3']['navname']}成员不能发帖");
    			} elseif($status == 5) {
    				exit('错误|请等待群主审核');
    			}
    		}
    		if(($_G['forum']['simple'] & 1) || $_G['forum']['redirect']) {
    			exit('错误|本版块禁止发帖');
    		}
    	}
    	
    	private function upload($publishdate)
    	{
    		global $_G;
    		empty($publishdate) && $publishdate = $_G['timestamp'];
    		$upload = new discuz_upload();
    		$upload->init($_FILES['Filedata'], 'forum');
    		//$this->attach = &$upload->attach;
    
    		if($upload->error()) {
    			exit('错误上传错误');
    		}
    		/*
    		if($_G['group']['attachextensions'] && (!preg_match("/(^|s|,)".preg_quote($upload->attach['ext'], '/')."($|s|,)/i", $_G['group']['attachextensions']) || !$upload->attach['ext'])) {
    			exit('错误不支持的附近格式'.$upload->attach['ext']);
    		}
    
    		if(empty($upload->attach['size']) || $_G['group']['maxattachsize'] && $upload->attach['size'] > $_G['group']['maxattachsize']) {
    			exit('错误附近大小不对'.$upload->attach['size'].'最大'.$_G['group']['maxattachsize']);
    		}
    
    		loadcache('attachtype');
    		if($_G['fid'] && isset($_G['cache']['attachtype'][$_G['fid']][$upload->attach['ext']])) {
    			$maxsize = $_G['cache']['attachtype'][$_G['fid']][$upload->attach['ext']];
    		} elseif(isset($_G['cache']['attachtype'][0][$upload->attach['ext']])) {
    			$maxsize = $_G['cache']['attachtype'][0][$upload->attach['ext']];
    		}
    		if(isset($maxsize)) {
    			if(!$maxsize) {
    				exit(4);
    			} elseif($upload->attach['size'] > $maxsize) {
    				exit(5);
    			}
    		}
    		*/
    		updatemembercount($_G['uid'], array('todayattachs' => 1, 'todayattachsize' => $upload->attach['size']));
    		$upload->save();
    		if($upload->error() == -103) {
    			exit(8);
    		} elseif($upload->error()) {
    			exit(9);
    		}
    		$thumb = $remote = $width = 0;
    		if($upload->attach['isimage']) {
    			if($_G['setting']['showexif']) {
    				require_once libfile('function/attachment');
    				$exif = getattachexif(0, $upload->attach['target']);
    			}
    			if($_G['setting']['thumbsource'] || $_G['setting']['thumbstatus']) {
    				require_once libfile('class/image');
    				$image = new image;
    			}
    			if($_G['setting']['thumbsource'] && $_G['setting']['sourcewidth'] && $_G['setting']['sourceheight']) {
    				$thumb = $image->Thumb($upload->attach['target'], '', $_G['setting']['sourcewidth'], $_G['setting']['sourceheight'], 1, 1) ? 1 : 0;
    				$width = $image->imginfo['width'];
    				$upload->attach['size'] = $image->imginfo['size'];
    			}
    			if($_G['setting']['thumbstatus']) {
    				$thumb = $image->Thumb($upload->attach['target'], '', $_G['setting']['thumbwidth'], $_G['setting']['thumbheight'], $_G['setting']['thumbstatus'], 0) ? 1 : 0;
    				$width = $image->imginfo['width'];
    			}
    			if($_G['setting']['thumbsource'] || !$_G['setting']['thumbstatus']) {
    				list($width) = @getimagesize($upload->attach['target']);
    			}
    		}
    		$aid = getattachnewaid($_G['uid']);
    		$insert = array(
    			'aid' => $aid,
    			'dateline' => $publishdate,
    			'filename' => censor($upload->attach['name']),
    			'filesize' => $upload->attach['size'],
    			'attachment' => $upload->attach['attachment'],
    			'isimage' => $upload->attach['isimage'],
    			'uid' => $_G['uid'],
    			'thumb' => $thumb,
    			'remote' => $remote,
    			'width' => $width,
    		);
    		C::t('forum_attachment_unused')->insert($insert);
    		if($upload->attach['isimage'] && $_G['setting']['showexif']) {
    			C::t('forum_attachment_exif')->insert($aid, $exif);
    		}
    		return array('aid'=>$aid , 'name' => $upload->attach['name'] , 'isimage' => $upload->attach['isimage']);
    	}
    	
    	private function setUpdate(&$attach , $message)
    	{
    		global $config;
    		if(empty($attach)){
    			return $message;
    		}
    		$uploadFile = array();
    		foreach($attach as $k => $v){
    			if(!empty($v) && $v['error'] == 0 && strpos($message , $v['name']) !== false){
    				$_FILES['Filedata'] = $v;
    				//$_FILES['Filedata']['name'] = addslashes(diconv(urldecode($_FILES['Filedata']['name']), 'UTF-8'));
    				$_FILES['Filedata']['name'] = addslashes(urldecode($_FILES['Filedata']['name']));
    				$_FILES['Filedata']['type'] = strrchr($_FILES['Filedata']['name'], '.');
    				$uploadFile[] = $this->upload($this->publishdate);
    				unset($attach[$k]);
    			}
    		}
    		if(!empty($uploadFile)){
    			foreach($uploadFile as $k => $v){
    				$have = false;
    				$preg_name = preg_quote($v['name']);
    				if($v['isimage'] == '1'){
    					//正则替换,
    					if(preg_match("/<img[^<>]+".$preg_name."[^<>]+>/iUs", $message , $match)){
    						$have = true;
    						if($config['附件隐藏']){
    							$message = str_replace($match[0], '[hide][attach]'.$v['aid'].'[/attach][/hide]', $message);
    						}else{
    							$message = str_replace($match[0], '[attach]'.$v['aid'].'[/attach]', $message);
    						}
    						//[img]19352073h2uh607pzo6oh6.jpg[/img]
    					}elseif(preg_match("/[img][^[]]*".$preg_name."[/img]/iUs", $message , $match)){
    						$have = true;
    						if($config['附件隐藏']){
    							$message = str_replace($match[0], '[hide][attach]'.$v['aid'].'[/attach][/hide]', $message);
    						}else{
    							$message = str_replace($match[0], '[attach]'.$v['aid'].'[/attach]', $message);
    						}
    					}
    				}else{
    					if(preg_match("/<a[^<>]*>[^<>]*".$preg_name."[^<>]*</a>/iUs", $message , $match)){
    						$have = true;
    						if($config['附件隐藏']){
    							$message = str_replace($match[0], '[hide][attach]'.$v['aid'].'[/attach][/hide]', $message);
    						}else{
    							$message = str_replace($match[0], '[attach]'.$v['aid'].'[/attach]', $message);
    						}
    					}elseif(preg_match("/[url=[^[]]+][^[]]*".$preg_name."[/url]/iUs", $message , $match)){
    						$have = true;
    						if($config['附件隐藏']){
    							$message = str_replace($match[0], '[hide][attach]'.$v['aid'].'[/attach][/hide]', $message);
    						}else{
    							$message = str_replace($match[0], '[attach]'.$v['aid'].'[/attach]', $message);
    						}
    					}
    				}
    				
    				if(!empty($config['附件权限组'])){
    					$readpermArr = explode('|', $config['附件权限组']);
    					$readperm = $readpermArr[rand(0 , count($readpermArr)-1)];
    				}else{
    					$readperm = 0;
    				}
    				if(!empty($config['附件价格'])){
    					$priceArr = explode('|', $config['附件价格']);
    					$price = $priceArr[rand(0 , count($priceArr)-1)];
    				}else{
    					$price = 0;
    				}
    				$_GET['attachnew'][$v['aid']]['description'] = $v['name'];
    				$_GET['attachnew'][$v['aid']]['readperm'] = $readperm;
    				$_GET['attachnew'][$v['aid']]['price'] = $price;//$config['附件价格'];
    			}
    		}
    		return $message;
    	}
    	
    	public function newthread()
    	{
    		global $_G,$config;
    		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');
    		}
    		$this->checkGroup();
    		//require_once libfile('function/discuzcode');
    		
    		$space = array();
    		space_merge($space, 'field_home');
    		
    		formulaperm($_G['forum']['formulaperm']);
    		
    		$_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 =  '';
    		
    		$subject = dhtmlspecialchars(censor(trim($this->subject)));
    		$subject = !empty($subject) ? str_replace("	", ' ', $subject) : $subject;
    		if(empty($config['标题允许重复'])){
    			C::t('forum_thread')->count_by_tid_fid('','','','',$subject)> 0 &&  exit('错误,标题重复');
    		}
    		$message = $this->setUpdate($this->attach , censor($this->message));
    		$polloptions = isset($polloptions) ? censor(trim($polloptions)) : '';
    		$readperm = isset($this->readperm) ? $this->readperm : 0;
    		$price = isset($this->price) ? $this->price : 0;
    		/*
    		if(empty($bbcodeoff) && !$_G['group']['allowhidecode'] && !empty($message) && preg_match("/[hide=?d*].*?[/hide]/is", preg_replace("/([code](.+?)[/code])/is", ' ', $message))) {
    			exit('错误post_hide_nopermission');
    		}
    		*/
    		$modnewthreads = $modnewreplies = 0;
    		$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);
    		$_G['forum']['threadplugin'] = dunserialize($_G['forum']['threadplugin']);
    		
    
    		$_G['group']['allowanonymous'] = $_G['forum']['allowanonymous'] || $_G['group']['allowanonymous'] ? 1 : 0;
    		
    		$policykey = 'post';
    		$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;
    				}
    			}
    		}
    		check_allow_action('allowpost');
    		
    		if(helper_access::check_module('album') && $_G['group']['allowupload'] && $_G['setting']['albumcategorystat'] && !empty($_G['cache']['albumcategory'])) {
    			require_once libfile('function/portalcp');
    		}
    		loadcache('groupreadaccess');
    		/*
    		if(empty($_G['forum']['fid']) || $_G['forum']['type'] == 'group') {
    			exit('错误板块id不正确');
    		}
    		if(!$_G['uid'] && !((!$_G['forum']['postperm'] && $_G['group']['allowpost']) || ($_G['forum']['postperm'] && forumperm($_G['forum']['postperm'])))) {
    			exit('错误postperm_login_nopermission');
    		} elseif(empty($_G['forum']['allowpost'])) {
    			if(!$_G['forum']['postperm'] && !$_G['group']['allowpost']) {
    				exit('错误|抱歉,您没有权限在该版块发帖|postperm_none_nopermission');
    			} elseif($_G['forum']['postperm'] && !forumperm($_G['forum']['postperm'])) {
    				exit('错误|抱歉,您没有权限在该版块发帖');
    				//showmessagenoperm('postperm', $_G['fid'], $_G['forum']['formulaperm']);
    			}
    		} elseif($_G['forum']['allowpost'] == -1) {
    			exit('错误|抱歉,本版块只有特定用户组可以发新主题|post_forum_newthread_nopermission');
    		}
    		if(!$_G['uid'] && ($_G['setting']['need_avatar'] || $_G['setting']['need_email'] || $_G['setting']['need_friendnum'])) {
    			exit('错误|抱歉,您尚未登录,没有权限在该版块发帖|postperm_login_nopermission');
    		}
    		
    		checklowerlimit('post', 0, 1, $_G['forum']['fid']);
    		
    		检测长度
    		if($post_invalid = checkpost($subject, $message, ($special || $sortid))) {
    			exit('错误'.$post_invalid);
    		}
    		*/
    		
    		$_GET['save'] = $_G['uid'] ? $_GET['save'] : 0;
    		if ($this->publish_date  > $_G['timestamp']) {
    			$_GET['save'] = 1;
    		}
    		$publishdate = $this->publish_date;
    		
    		$typeid = isset($typeid) && isset($_G['forum']['threadtypes']['types'][$typeid]) && (empty($_G['forum']['threadtypes']['moderators'][$typeid]) || $_G['forum']['ismoderator']) ? $typeid : 0;
    		$displayorder = ($_G['forum']['ismoderator'] && $_G['group']['allowstickthread'] && !empty($_GET['sticktopic'])) ? 1 : (empty($_GET['save']) ? 0 : -4);
    		if($displayorder == -4) {
    			$_GET['addfeed'] = 0;
    		}
    		$digest = $_G['forum']['ismoderator'] && $_G['group']['allowdigestthread'] && !empty($_GET['addtodigest']) ? 1 : 0;
    		$readperm = $_G['group']['allowsetreadperm'] ? $readperm : 0;
    		$isanonymous = 0;
    		//$price = $_G['group']['maxprice'] && !$special ? ($price <= $_G['group']['maxprice'] ? $price : $_G['group']['maxprice']) : 0;
    	
    		if(!$typeid && $_G['forum']['threadtypes']['required'] && !$special) {
    			exit('错误该板块必须要主题分类typeid');
    		}
    	
    		if(!$sortid && $_G['forum']['threadsorts']['required'] && !$special) {
    			exit('错误该板块必须要分类信息sortid');
    		}
    	
    		if($price > 0 && floor($price * (1 - $_G['setting']['creditstax'])) == 0) {
    			exit('错误|抱歉,您的主题售价扣除积分交易税后为 0|post_net_price_iszero');
    		}
    	
    		$typeexpiration = intval($_GET['typeexpiration']);
    	
    		if($_G['forum']['threadsorts']['expiration'][$typeid] && !$typeexpiration) {
    			exit('错误|抱歉,此主题必须指定有效期|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 =  $_G['username'] ;
    	
    		$moderated = $digest || $displayorder > 0 ? 1 : 0;
    	
    		$thread['status'] = 0;
    		$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])) {
    					exit('错误|抱歉,回帖送积分额度大于您的积分|replycredit_morethan_self');
    				} else {
    					$replycredit = ceil($_GET['replycredit_extcredits'] * $_GET['replycredit_times']);
    				}
    			}
    		}
    		
    		$newthread = array(
    			'fid' => $_G['fid'],
    			'posttableid' => 0,
    			'readperm' => $readperm,
    			'price' => $price,
    			'typeid' => $typeid,
    			'sortid' => $sortid,
    			'author' => $author,
    			'authorid' => $_G['uid'],
    			'subject' => $subject,
    			'views'	 =>	(rand(5,10)*count($this->replys))+rand(1,10),
    			'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
    		);
    		$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);
    		}
    	
    		
    		C::t('common_member_field_home')->update($_G['uid'], array('recentnote'=>$subject));
    		
    		if($moderated) {
    			updatemodlog($tid, ($displayorder > 0 ? 'STK' : 'DIG'));
    			updatemodworks(($displayorder > 0 ? 'STK' : 'DIG'), 1);
    		}
    	
    		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("/@([^
    ]*?)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, 0);
    		$smileyoff = checksmilies($message, 0);
    		$parseurloff = !empty($_GET['parseurloff']);
    		$htmlon = strpos($message , '<') !==false ? 1 : 0;
    		$usesig = $config['使用签名'];
    		$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);
    			}
    		}
    		$pinvisible = $modnewthreads ? -2 : (empty($_GET['save']) ? 0 : -3);
    
    		$pid = insertpost(array(
    			'fid' => $_G['fid'],
    			'tid' => $tid,
    			'first' => '1',
    			'author' => $_G['username'],
    			'authorid' => $_G['uid'],
    			'subject' => $subject,
    			'dateline' => $publishdate,
    			'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' => 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));
    		}
    		$threadimageaid = 0;
    		$threadimage = array();
    
    		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']))) {
    			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*([^[<
    ]+?)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' : 'thread');
    	
    		//dsetcookie('clearUserdata', 'forum');
    	
    		if($modnewthreads) {
    			updatemoderate('tid', $tid);
    			C::t('forum_forum')->update_forum_counter($_G['fid'], 0, 0, 1);
    			manage_addnotify('verifythread');
    			exit('陈功|新主题需要审核,您的帖子通过审核后才能显示|post_newthread_mod_succeed');
    		} else {
    			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);
    				}
    	
    				C::t('forum_forum')->update_forum_counter($_G['fid'], 1, 1, 1);
    				if($publishdate >= $_G['timestamp']){
    					$subject = str_replace("	", ' ', $subject);
    					$lastpost = "$tid	".$subject."	$publishdate	$author";
    					C::t('forum_forum')->update($_G['fid'], array('lastpost' => $lastpost));
    					if($_G['forum']['type'] == 'sub') {
    						C::t('forum_forum')->update($_G['forum']['fup'], array('lastpost' => $lastpost));
    					}
    				}
    			}
    
    			if($_G['forum']['status'] == 3) {
    				if($publishdate >= $_G['timestamp']){
    					C::t('forum_forumfield')->update($_G['fid'], array('lastupdate' => $publishdate));
    				}
    				require_once libfile('function/grouplog');
    				updategroupcreditlog($_G['fid'], $_G['uid']);
    			}
    		}
    		$_G['tid'] = $_GET['tid'] = $tid;
    		$_GET['attachnew'] = null;
    		loadforum();
    	}
    	
    	public function doreply($username , $message , $publishdate)
    	{
    		global $_G,$config;
    		//cknewuser();
    		$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');
    		}
    		$this->checkGroup();
    		require_once libfile('function/discuzcode');
    		
    		$space = array();
    		space_merge($space, 'field_home');
    		
    		if(!empty($_GET['cedit'])) {
    			unset($_G['inajax'], $_GET['infloat'], $_GET['ajaxtarget'], $_GET['handlekey']);
    		}
    		
    		$thread = C::t('forum_thread')->fetch($_G['tid']);
    		formulaperm($_G['forum']['formulaperm']);
    		
    		$_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 = '';
    		
    		$subject = isset($subject) ? dhtmlspecialchars(censor(trim($subject))) : '';
    		$subject = !empty($subject) ? str_replace("	", ' ', $subject) : $subject;
    		$message = isset($message) ? censor($message) : '';
    		/*
    		if(empty($bbcodeoff) && !$_G['group']['allowhidecode'] && !empty($message) && preg_match("/[hide=?d*].*?[/hide]/is", preg_replace("/([code](.+?)[/code])/is", ' ', $message))) {
    			exit('错误post_hide_nopermission');//);
    		}
    		*/
    		$modnewthreads = $modnewreplies = 0;
    		
    		$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);
    		$_G['forum']['threadplugin'] = dunserialize($_G['forum']['threadplugin']);
    
    		$_G['group']['allowanonymous'] = $_G['forum']['allowanonymous'] || $_G['group']['allowanonymous'] ? 1 : 0;
    		$policykey = 'reply';
    		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;
    				}
    			}
    		}
    		
    		check_allow_action('allowreply');
    		
    		if(helper_access::check_module('album') && $_G['group']['allowupload'] && $_G['setting']['albumcategorystat'] && !empty($_G['cache']['albumcategory'])) {
    			require_once libfile('function/portalcp');
    		}
    				
    		require_once libfile('function/forumlist');
    		
    		$isfirstpost = 0;
    		$showthreadsorts = 0;
    		$quotemessage = '';
    		if(trim($subject) == '' && trim($message) == '') {
    			return false;
    		}
    		$attentionon = empty($_GET['attention_add']) ? 0 : 1;
    		$attentionoff = empty($attention_remove) ? 0 : 1;
    		$heatthreadset = update_threadpartake($_G['tid'], true);
    		$message = $this->setUpdate($this->attach , $message);
    		$bbcodeoff = checkbbcodes($message, 0);
    		$smileyoff = checksmilies($message, 0);
    		$parseurloff = !empty($_GET['parseurloff']);
    		$htmlon = strpos($message , '<') !== false ? 1 : 0 ;//$_G['group']['allowhtml'] && !empty($_GET['htmlon']) ? 1 : 0;
    		$usesig = $config['使用签名'];
    	
    		$isanonymous = 0;
    		$author = $_G['username'] ;
    	
    		if($thread['displayorder'] == -4) {
    			$modnewreplies = 0;
    		}
    		$pinvisible = $modnewreplies ? -2 : ($thread['displayorder'] == -4 ? -3 : 0);
    		$postcomment = in_array(2, $_G['setting']['allowpostcomment']) && $_G['group']['allowcommentreply'] && !$pinvisible && !empty($_GET['reppid']) && ($nauthorid != $_G['uid'] || $_G['setting']['commentpostself']) ? messagecutstr($message, 200, ' ') : '';
    		$position= C::t('forum_post')->count_visiblepost_by_tid($_G['tid']) + 1;
    		$pid = insertpost(array(
    			'fid' => $_G['fid'],
    			'tid' => $_G['tid'],
    			'first' => '0',
    			'author' => $_G['username'],
    			'authorid' => $_G['uid'],
    			'subject' => $subject,
    			'dateline' => $publishdate,
    			'message' => $message,
    			'useip' => $this->randomip(),
    			'invisible' => $pinvisible,
    			'anonymous' => $isanonymous,
    			'usesig' => $usesig,
    			'htmlon' => $htmlon,
    			'bbcodeoff' => $bbcodeoff,
    			'smileyoff' => $smileyoff,
    			'parseurloff' => $parseurloff,
    			'attachment' => '0',
    			'status' => 0,
    			'position' => $position
    		));
    		if($_G['group']['allowat'] && $atlist) {
    			foreach($atlist as $atuid => $atusername) {
    				notification_add($atuid, 'at', 'at_message', array('from_id' => $_G['tid'], 'from_idtype' => 'thread', 'buyerid' => $_G['uid'], 'buyer' => $_G['username'], 'tid' => $_G['tid'], 'subject' => $thread['subject'], 'pid' => $pid, 'message' => messagecutstr($message, 150)));
    			}
    			set_atlist_cookie(array_keys($atlist));
    		}
    		$updatethreaddata = $heatthreadset ? $heatthreadset : array();
    		$postionid = C::t('forum_post')->fetch_maxposition_by_tid($thread['posttableid'], $_G['tid']);
    		$updatethreaddata[] = DB::field('maxposition', $postionid);
    		if(getstatus($thread['status'], 3) && $postionid) {
    			$rushstopfloor = $rushinfo['stopfloor'];
    			if($rushstopfloor > 0 && $thread['closed'] == 0 && $postionid >= $rushstopfloor) {
    				$updatethreaddata[] = 'closed=1';
    			}
    		}
    		useractionlog($_G['uid'], 'pid');
    	
    		$nauthorid = 0;
    	
    		if($thread['authorid'] != $_G['uid'] && getstatus($thread['status'], 6) && empty($_GET['noticeauthor']) && !$isanonymous && !$modnewreplies) {
    			$thapost = C::t('forum_post')->fetch_threadpost_by_tid_invisible($_G['tid'], 0);
    			notification_add($thapost['authorid'], 'post', 'reppost_noticeauthor', array(
    				'tid' => $thread['tid'],
    				'subject' => $thread['subject'],
    				'fid' => $_G['fid'],
    				'pid' => $pid,
    				'from_id' => $thread['tid'],
    				'from_idtype' => 'post',
    			));
    		}
    	
    		if($thread['replycredit'] > 0 && !$modnewreplies && $thread['authorid'] != $_G['uid'] && $_G['uid']) {
    	
    			$replycredit_rule = C::t('forum_replycredit')->fetch($_G['tid']);
    			if(!empty($replycredit_rule['times'])) {
    				$have_replycredit = C::t('common_credit_log')->count_by_uid_operation_relatedid($_G['uid'], 'RCA', $_G['tid']);
    				if($replycredit_rule['membertimes'] - $have_replycredit > 0 && $thread['replycredit'] - $replycredit_rule['extcredits'] >= 0) {
    					$replycredit_rule['extcreditstype'] = $replycredit_rule['extcreditstype'] ? $replycredit_rule['extcreditstype'] : $_G['setting']['creditstransextra'][10];
    					if($replycredit_rule['random'] > 0) {
    						$rand = rand(1, 100);
    						$rand_replycredit = $rand <= $replycredit_rule['random'] ? true : false ;
    					} else {
    						$rand_replycredit = true;
    					}
    					if($rand_replycredit) {
    						updatemembercount($_G['uid'], array($replycredit_rule['extcreditstype'] => $replycredit_rule['extcredits']), 1, 'RCA', $_G[tid]);
    						C::t('forum_post')->update('tid:'.$_G['tid'], $pid, array('replycredit' => $replycredit_rule['extcredits']));
    						$updatethreaddata[] = DB::field('replycredit', $thread['replycredit'] - $replycredit_rule['extcredits']);
    					}
    				}
    			}
    		}
    		($_G['group']['allowpostattach'] || $_G['group']['allowpostimage']) && ($_GET['attachnew'] || $special == 2 && $_GET['tradeaid']) && updateattach($thread['displayorder'] == -4 || $modnewreplies, $_G['tid'], $pid, $_GET['attachnew']);
    		$_GET['attachnew'] = null;
    		$_G['forum']['threadcaches'] && deletethreadcaches($_G['tid']);
    	
    		include_once libfile('function/stat');
    		updatestat($thread['isgroup'] ? 'grouppost' : 'post');
    	
    		$param = array('fid' => $_G['fid'], 'tid' => $_G['tid'], 'pid' => $pid, 'from' => $_GET['from'], 'sechash' => !empty($_GET['sechash']) ? $_GET['sechash'] : '');
    		if($feedid) {
    			$param['feedid'] = $feedid;
    		}
    		//dsetcookie('clearUserdata', 'forum');
    	
    		if($modnewreplies) {
    			updatemoderate('pid', $pid);
    			unset($param['pid']);
    			if($updatethreaddata) {
    				C::t('forum_thread')->update($_G['tid'], $updatethreaddata, false, false, 0, true);
    			}
    			C::t('forum_forum')->update_forum_counter($_G['fid'], 0, 0, 1, 1);
    			manage_addnotify('verifypost');
    		} else {
    			$fieldarr = array(
    				'lastposter' => array($author),
    				'replies' => 1
    			);
    			if($thread['lastpost'] < $publishdate) {
    				$fieldarr['lastpost'] = array($publishdate);
    			}
    			$row = C::t('forum_threadaddviews')->fetch($_G['tid']);
    			if(!empty($row)) {
    				C::t('forum_threadaddviews')->update($_G['tid'], array('addviews' => 0));
    				$fieldarr['views'] = $row['addviews'];
    			}
    			$updatethreaddata = array_merge($updatethreaddata, C::t('forum_thread')->increase($_G['tid'], $fieldarr, false, 0, true));
    			if($thread['displayorder'] != -4) {
    				updatepostcredits('+', $_G['uid'], 'reply', $_G['fid']);
    				if($_G['forum']['status'] == 3) {
    					if($_G['forum']['closed'] > 1) {
    						C::t('forum_thread')->increase($_G['forum']['closed'], $fieldarr, true);
    					}
    					C::t('forum_groupuser')->update_counter_for_user($_G['uid'], $_G['fid'], 0, 1);
    					C::t('forum_forumfield')->update($_G['fid'], array('lastupdate' => $publishdate));
    					require_once libfile('function/grouplog');
    					updategroupcreditlog($_G['fid'], $_G['uid']);
    				}
    				
    				C::t('forum_forum')->update_forum_counter($_G['fid'], 0, 1, 1);
    				if($publishdate >= $_G['timestamp']){
    					$lastpost = "$thread[tid]	$thread[subject]	$publishdate	$author";
    					C::t('forum_forum')->update($_G['fid'], array('lastpost' => $lastpost));
    					if($_G['forum']['type'] == 'sub') {
    						C::t('forum_forum')->update($_G['forum']['fup'], array('lastpost' => $lastpost));
    					}
    				}
    			}
    			if($updatethreaddata) {
    				C::t('forum_thread')->update($_G['tid'], $updatethreaddata, false, false, 0, true);
    			}
    		}
    	}
    	
    	public function reply()
    	{
    		global $_G,$config;
    		if(empty($this->replys)){
    			return false;
    		}else{
    			require_once libfile('class/credit');
    			require_once libfile('function/post');
    			foreach($this->replys as $k => $v){
    				if(!empty($config['数据库用户'])){
    					$max = C::t('common_member')->max_uid();
    					$randuid = rand(1, $max);
    					$username_info = DB::fetch_first("SELECT uid,username FROM `".DB::table('common_member')."` where uid >= {$randuid} order by uid ASC LIMIT 1" );
    					$username = $username_info['username'];
    				}else{
    					$username = $v['username'];
    				}
    				$this->logonUser($username);
    				empty($v['signature']) ||	C::t('common_member_field_forum')->update($_G['uid'], array('sightml' => $v['signature']));
    				$this->doreply($username , $v['message'] , $v['publishdate']);
    				//$_COOKIE = null;
    			}
    		}
    	}
    	
    	function check_username($username) {
    		$guestexp = 'xA1xA1|xACxA3|^Guest|^xD3xCExBFxCD|xB9x43xABxC8';
    		$len = $this->dstrlen($username);
    		if($len > 15 || $len < 3 || preg_match("/s+|^c:\con\con|[%,*"s<>&]|$guestexp/is", $username)) {
    			return FALSE;
    		} else {
    			return TRUE;
    		}
    	}
    	function dstrlen($str) {
    		if(strtolower(JK_CHARSET) != 'utf-8') {
    			return strlen($str);
    		}
    		$count = 0;
    		for($i = 0; $i < strlen($str); $i++){
    			$value = ord($str[$i]);
    			if($value > 127) {
    				$count++;
    				if($value >= 192 && $value <= 223) $i++;
    				elseif($value >= 224 && $value <= 239) $i = $i + 2;
    				elseif($value >= 240 && $value <= 247) $i = $i + 3;
    		    	}
    	    		$count++;
    		}
    		return $count;
    	}
    }
    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;
    }
    

      

  • 相关阅读:
    java概述------
    java中有几种方法实现一个线程?用什么关键字修饰同步方法?stop()和suspend()方法为何不推荐使用?
    java的5个框架,哪个框架更适合你的项目?
    java的热门应用有哪些?
    vue-router 切换页面时怎么设置过渡动画
    Referrer Policy 介绍
    await进行同步操作
    vue中axios拦截器同一项目多域名如何配置
    正规方程求解特征参数的推导过程
    一种网页中显示代码所涉及的字符转义问题的解决方案
  • 原文地址:https://www.cnblogs.com/68xi/p/11355901.html
Copyright © 2011-2022 走看看