推荐使用
$config['zc_database_type'],
'db_user' => $config['zc_mysql_username'],
'db_pwd' => $config['zc_mysql_password'],
'db_host' => $config['zc_mysql_server'],
'db_port' => $config['zc_mysql_port'],
'db_name' => $config['zc_mysql_name'],
'db_charset' => $config['zc_mysql_charset'],
'db_prefix' => $config['zc_mysql_pre']
);
return $cmsdb;
}
/*初始化扩展*/
public function init_extend(){
$system=$this->db()->table('__config__')->where("conf_name='system'")->find();
$system=unserialize($system['conf_value']);
$this->siteurl=str_replace('|', '', $system['zc_blog_host']);
}
//参数
public $_params = array (
'author' => 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',
),
'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){
$newpost=array(
'log_cateid'=>$params['category'],
'log_authorid'=>$params['author'],
'log_tag'=>'',
'log_status'=>0,
'log_type'=>0,
'log_alias'=>'',
'log_istop'=>0,
'log_islock'=>0,
'log_title'=>$params['title'],
'log_intro'=>mb_substr(strip_tags($params['content']), 0,100,'utf-8'),
'log_content'=>$params['content'],
'log_posttime'=>time(),
'log_commnums'=>0,
'log_viewnums'=>0,
'log_template'=>'',
'log_meta'=>''
);
$postid=$this->db()->table('__post__')->insert($newpost,false,true);//添加文章并返回id
if($postid>0){
$target=$this->siteurl.'?id='.$postid;
return array('id'=>$postid,'target'=>$target);
}else{
return array('id'=>0,'error'=>'文章入库失败');
}
}
/*
* 参数选项:作者
* 必须返回键值对形式的数组
*/
public function param_option_author(){
$usersdb=$this->db()->table('__member__')->select();
$userlist=array();
foreach ($usersdb as $user){
$userlist[$user['mem_id']]=$user['mem_name'];
}
return $userlist;
}
/*
* 参数选项:分类
* 必须返回键值对形式的数组
*/
public function param_option_category(){
$catsdb=$this->db()->table('__category__')->select();//文章分类
$catlist=array();
foreach ($catsdb as $cat){
$catlist[$cat['cate_id']]=$cat['cate_name'];
}
return $catlist;
}
}
?>