示例:yzmcms文章 -pg电子试玩免费

类型
发布插件 » cms程序
标识
yzmcmsdemoskycaiji
下载
324次
更新
2019-02-22
实现yzmcms文章入库功能,您可参考该代码开发更多yzmcms应用,使用时需在数据绑定»cms路径结尾加上@yzmcms
 array (
			'name' => '作者账号',
			'require' => 1,
			'tag' => 'select',
			'option' => 'function:param_option_author',
		),
		'category' => array (
			'name' => '栏目',
			'require' => 1,
			'tag' => 'select',
			'option' => 'function:param_option_category',
		),
		'title' => array (
			'name' => '文章标题',
			'require' => 1,
			'tag' => 'select',
			'option' => 'function:param_option_fields',
		),
		'seotitle' => array (
			'name' => 'seo标题',
			'require' => 1,
			'tag' => 'select',
			'option' => 'function:param_option_fields',
		),
		'content' => array (
			'name' => '文章内容',
			'require' => 1,
			'tag' => 'select',
			'option' => 'function:param_option_fields',
		),
		'cover' => array (
			'name' => '封面图',
			'require' => 0,
			'tag' => 'select',
			'option' => 'function:param_option_fields',
		),
	);
	public function cms_db_yzmcms($cmspath){
		$config=include $cmspath.'/common/config/config.php';
		$cmsdb=array(
			'db_type'  => 'mysql',
			'db_user'  => $config['db_user'],
			'db_pwd'   => $config['db_pwd'],
			'db_host'  => $config['db_host'],
			'db_port'  => $config['db_port'],
			'db_name'  => $config['db_name'],
			'db_charset'  => 'utf8',
			'db_prefix'  => $config['db_prefix']
		);
		return $cmsdb;
	}
	public function init_extend(){
		$siteurl=$this->db()->table('__config__')->where("`name`='site_url'")->find();
		$this->siteurl=$siteurl['value'];
	}
	/*
	 * 导入数据
	* 必须以数组形式返回:
	* id(必填)表示入库返回的自增id或状态
	* target(可选)记录入库的数据位置(发布的网址等)
	* desc(可选)记录入库的数据位置附加信息
	* error(可选)记录入库失败的错误信息
	* 入库的信息可在“已采集数据”中查看
	* return array('id'=>0,'target'=>'','desc'=>'','error'=>'');
	*/
	public function runimport($params){
		$user=$this->db()->table('__admin__')->where(array('adminname'=>$params['author']))->find();
		if(empty($user)){
			return array('id'=>0,'error'=>'用户不存在');
		}
		
		$cat=$this->db()->table('__category__')->where(array('catid'=>$params['category']))->find();
		
		$newarticle=array(
			'catid'=>$params['category'],
	        'userid'=>$user['adminid'],
	        'username'=>$user['adminname'],
	        'nickname'=>$user['nickname'],
	        'title'=>$params['title'],
	        'seo_title'=>$params['seotitle'],
	        'inputtime'=>time(),
	        'updatetime'=>time(),
	        'keywords'=>'',
	        'description'=>mb_substr(trim(strip_tags($params['content'])), 0,100,'utf-8'),
	        'click'=>'',
	        'content'=>$params['content'],
	        'copyfrom'=>'',
	        'thumb'=>$params['cover'],
	        'url'=>'',
	        'flag'=>'',
	        'status'=>1,
	        'system'=>1,
	        'listorder'=>10,
	        'groupids_view'=>0,
	        'readpoint'=>0
		);
		$id=$this->db()->table('__article__')->insert($newarticle,false,true);
		if($id>0){
			$url=$this->siteurl.$cat['catdir'].'/'.$id.'.html';//文章url
			$this->db()->table('__article__')->where(array('id'=>$id))->update(array('url'=>$url));
			
			return array('id'=>$id,'target'=>$url);
		}else{
			return array('id'=>0,'error'=>'添加文章失败');
		}
	}
	/*
	 * 参数选项:作者
	 * 必须返回键值对形式的数组
	 */
	public function param_option_author(){
		$usersdb=$this->db()->table('__admin__')->select();
		$userlist=array();
		foreach ($usersdb as $user){
			$uname=auto_convert2utf8($user['adminname']);
			$userlist[$uname]=$uname;
		}
		return $userlist;
	}
	
	/*
	 * 参数选项:分类
	 * 必须返回键值对形式的数组
	 */
	public function param_option_category(){
		$catsdb=$this->db()->table('__category__')->where('modelid=1')->select();//分类
		$catlist=array();
		foreach ($catsdb as $cat){
			$catlist[$cat['catid']]=auto_convert2utf8($cat['catname']);
		}
		return $catlist;
	}
}
?>
非常抱歉!该插件已停止更新仅供示例参考,cms程序更新可能会导致插件功能失效,请自行修改代码以适应您的需求
网站地图