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

类型
发布插件 » cms程序
标识
mipcmsdemoskycaiji
下载
295次
更新
2019-02-22
实现mipcms文章入库功能,您可参考该代码开发更多mipcms应用
db()->table('__settings__')->where("`key`='articledomain'")->find();
		$this->siteurl=$siteurl['val'];
	}
	public function cms_db_mipcms($cmspath){
		$dbfile=realpath($cmspath.'/app/database.php');
		//转换成thinkphp数据库配置
		$config=include $dbfile;
		
		$cmsdb=array(
			'db_type'  => $config['type'],
			'db_user'  => $config['username'],
			'db_pwd'   => $config['password'],
			'db_host'  => $config['hostname'],
			'db_port'  => $config['hostport'],
			'db_name'  => $config['database'],
			'db_charset'  => $config['charset'],
			'db_prefix'  => $config['prefix']
		);
		
		return $cmsdb;
	}
	//参数
	public $_params = array (
		'author' => array (
			'name' => '作者账号',
			'require' => 1,
			'tag' => 'text',
		),
		'category' => array (
			'name' => '分类',
			'require' => 1,
			'tag' => 'select',
			'option' => 'function:param_option_category',
		),
		'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('__users__')->where(array('username'=>$params['author']))->find();
		if(!empty($uid)){
			$uid=$uid['uid'];
		}else{
			return array('id'=>0,'error'=>'用户不存在');
		}
		
		$uuid=$this->uuid();
		
		$newarticle=array(
	        'uuid'=>$uuid,
	        'cid'=>$params['category'],
	        'uid'=>$uid,
	        'title'=>$params['title'],
	        'views'=>0,
	        'create_time'=>0,
	        'edit_time'=>0,
	        'is_recommend'=>0,
	        'comments'=>0,
	        'version'=>0,
	        'publish_time'=>time(),
	        'collect'=>0,
	        'mip_post_num'=>0,
	        'content_id'=>$uuid,
	        'url_name'=>'',
	        'img_url'=>null,
	        'keywords'=>'',
	        'link_tags'=>'',
	        'description'=>'',
	        'site_id'=>null,
	        'mip_push_num'=>null,
	        'amp_push_num'=>null,
	        'xzh_push_num'=>null,
	        'link_push_num'=>null,
	        'yc_push_num'=>null,
	        'baidu_spider_num'=>null,
	        'google_spider_num'=>null,
	        'so_spider_num'=>null,
	        'sm_spider_num'=>null,
	        'sogou_spider_num'=>null,
	        'baidu_spider_time'=>null,
	        'google_spider_time'=>null,
	        'so_spider_time'=>null,
	        'sm_spider_time'=>null,
	        'sogou_spider_time'=>null,
		);
		
		$id=$this->db()->table('__articles__')->insert($newarticle,false,true);//添加并返回id
		if($id>0){
			//添加内容
			$this->db()->table('__articles_content__')->insert(array(
				'id'=>$uuid,
				'content'=>$params['content']
			));
			
			return array('id'=>$id,'target'=>$this->siteurl."index.php?s=/article/{$id}.html");
		}else{
			return array('id'=>0,'error'=>'添加文章失败');
		}
	}
	
	/*
	 * 参数选项:分类
	 * 必须返回键值对形式的数组
	 */
	public function param_option_category(){
		$catdb=$this->db()->table('__articles_category__')->select();
		$catlist=array();
		foreach ($catdb as $cat){
			$catlist[$cat['id']]=auto_convert2utf8($cat['name']);
		}
		return $catlist;
	}
	public function uuid(){
        $charid = strtolower(md5(uniqid(rand(), true)));
        return substr($charid,0,24);
    }
}
?>
非常抱歉!该插件已停止更新仅供示例参考,cms程序更新可能会导致插件功能失效,请自行修改代码以适应您的需求
网站地图