示例:xiunobbs发帖 -pg电子试玩免费

类型
发布插件 » cms程序
标识
xiunobbsdemoskycaiji
下载
585次
更新
2019-02-22
实现xiunobbs修罗论坛发帖功能,您可参考该代码开发更多xiunobbs应用
 'mysql',
			'db_user'  => $config['user'],
			'db_pwd'   => $config['password'],
			'db_host'  => $config['host'],
			'db_port'  => 3306,
			'db_name'  => $config['name'],
			'db_charset'  => $config['charset'],
			'db_prefix'  => $config['tablepre']
		);
		
		return $cmsdb;
	}
	//参数
	public $_params = array (
		'author' => array (
			'name' => '作者账号',
			'require' => 1,
			'tag' => 'text',
		),
		'forum' => array (
			'name' => '版块id',
			'require' => 1,
			'tag' => 'select',
			'option' => 'function:param_option_forum',
		),
		'title' => array (
			'name' => '帖子标题',
			'require' => 1,
			'tag' => 'select',
			'option' => 'function:param_option_fields',
		),
		'content' => array (
			'name' => '帖子内容',
			'require' => 1,
			'tag' => 'select',
			'option' => 'function:param_option_fields',
		),
	);
	/*
	 * 导入数据
	* 必须以数组形式返回:
	* id(必填)表示入库返回的自增id或状态
	* target(可选)记录入库的数据位置(发布的网址等)
	* desc(可选)记录入库的数据位置附加信息
	* error(可选)记录入库失败的错误信息
	* 入库的信息可在“已采集数据”中查看
	* return array('id'=>0,'target'=>'','desc'=>'','error'=>'');
	*/
	public function runimport($params){
		$uid=$this->db()->table('__user__')->where(array('username'=>$params['author']))->find();
		if(!empty($uid)){
			$uid=$uid['uid'];
		}else{
			return array('id'=>0,'error'=>'用户不存在');
		}
		
		$newthread=array(
	        'fid'=>$params['forum'],
			'top'=>0,
	        'uid'=>$uid,
			'userip'=>'',
	        'subject'=>$params['title'],
			'create_date'=>time(),
			'last_date'=>time(),
			'views'=>0,
			'posts'=>0,
			'images'=>0,
			'files'=>0,
			'mods'=>0,
			'closed'=>0,
			'firstpid'=>0,
			'lastuid'=>0,
			'lastpid'=>0,
		);
		
		$tid=$this->db()->table('__thread__')->insert($newthread,false,true);//添加主题并返回id
		if($tid>0){
			$this->db()->table('__mythread__')->insert(array('uid'=>$uid,'tid'=>$tid));//我的主题
			
			$newpost=array(
				'tid'=>$tid,
				'uid'=>$uid,
				'isfirst'=>1,
				'create_date'=>time(),
				'userip'=>0,
				'images'=>0,
				'files'=>0,
				'doctype'=>1,
				'quotepid'=>0,
				'message'=>strip_tags($params['content']),
				'message_fmt'=>$params['content'],
			);
			$pid=$this->db()->table('__post__')->insert($newpost,false,true);//添加帖子并返回id
			$this->db()->table('__thread__')->where(array('tid'=>$tid))->update(array('firstpid'=>$pid,'lastpid'=>$pid));
			$this->db()->table('__forum__')->where('fid',$params['forum'])->setinc('threads',1);
			return array('id'=>$tid,'target'=>'主题:'.$tid);
		}else{
			return array('id'=>0,'error'=>'添加主题失败');
		}
	}
	
	/*
	 * 参数选项:版块
	 * 必须返回键值对形式的数组
	 */
	public function param_option_forum(){
		$forumsdb=$this->db()->table('__forum__')->select();
		$forumlist=array();
		foreach ($forumsdb as $forum){
			$forumlist[$forum['fid']]=auto_convert2utf8($forum['name']);
		}
		return $forumlist;
	}
}
?>
非常抱歉!该插件已停止更新仅供示例参考,cms程序更新可能会导致插件功能失效,请自行修改代码以适应您的需求
网站地图