$cfg['database'],
'db_user' => $cfg['db_user'],
'db_pwd' => $cfg['db_pass'],
'db_host' => $cfg['db_host'],
'db_port' => 3306,
'db_name' => $cfg['db_name'],
'db_charset' => $cfg['db_charset'],
'db_prefix' => $cfg['tb_pre']
);
$this->siteurl=$cfg['url'];
return $cmsdb;
}
//参数
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){
$newarticle=array(
'catid'=>$params['category'],
'areaid'=>0,
'level'=>0,
'title'=>$params['title'],
'style'=>'',
'fee'=>0,
'subtitle'=>'',
'introduce'=>mb_substr(strip_tags($params['content']), 0,60,'utf-8'),
'tag'=>'',
'keyword'=>'',
'pptword'=>'',
'author'=>'',
'copyfrom'=>'',
'fromurl'=>'',
'voteid'=>'',
'hits'=>0,
'comments'=>0,
'thumb'=>'',
'username'=>$params['author'],
'addtime'=>time(),
'editor'=>$params['author'],
'edittime'=>time(),
'ip'=>'',
'template'=>'',
'status'=>3,
'islink'=>0,
'linkurl'=>'',
'filepath'=>'',
'note'=>''
);
$articleid=$this->db()->table('__article_21__')->insert($newarticle,false,true);//添加文章并返回id
if($articleid>0){
$target='show.php?itemid='.$articleid;
$this->db()->table('__article_21__')->where(array('itemid'=>$articleid))->update(array('linkurl'=>$target));
$this->db()->table('__article_data_21__')->insert(array('itemid'=>$articleid,'content'=>$params['content']));
$target=$this->siteurl.'news/'.$target;
return array('id'=>$articleid,'target'=>$target);
}else{
return array('id'=>0,'error'=>'文章入库失败');
}
}
/*
* 参数选项:作者
* 必须返回键值对形式的数组
*/
public function param_option_author(){
$usersdb=$this->db()->table('__member__')->where('admin=1')->select();
$userlist=array();
foreach ($usersdb as $user){
$uname=$user['username'];
$userlist[$uname]=$uname;
}
return $userlist;
}
/*
* 参数选项:分类
* 必须返回键值对形式的数组
*/
public function param_option_category(){
$catsdb=$this->db()->table('__category__')->where('moduleid=21')->select();//文章分类
$catlist=array();
foreach ($catsdb as $cat){
$catlist[$cat['catid']]=$cat['catname'];
}
return $catlist;
}
}
?>