当采集任务中,有扩展字段(自定义字段)时候需要对发布插件(\plugin\release\cms中那个)进行修改,参考代码片段如下
下面是完整代码
<?php
/**
* 示例:pboot文章
* 您可参考代码自行开发pboot cms的更多功能
* 您可以使用 thinkphp5的函数
*/
namespace plugin\release\cms;
class PbootQikanSkypecaiji extends BaseCms{
public function cms_db_pboot($cmsPath){
$dbFile=realpath($cmsPath.'/config/database.php');
$cmsDb=array();
if(file_exists($dbFile)){
$dbFile=include $dbFile;
$dbFile=$dbFile['database'];
if(is_array($dbFile)){
//使用sqlite必须开启pdo_sqlite
$cmsDb['db_type']=stripos($dbFile['type'], 'sqlite')!==false?'sqlite':'mysql';
$cmsDb['db_name']=$cmsDb['db_type']=='sqlite'?($cmsPath.$dbFile['dbname']):$dbFile['dbname'];
$cmsDb['db_host']=$dbFile['host'];
$cmsDb['db_user']=$dbFile['user'];
$cmsDb['db_pwd']=$dbFile['passwd'];
$cmsDb['db_charset']='utf8';
$cmsDb['db_port']=$dbFile['port'];
$cmsDb['db_prefix']='ay_';//固定的前缀
}
}
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',
),
'ico' => array (
'name' => '缩略图',
'require' => 0,
'tag' => 'select',
'option' => 'function:param_option_fields',
),
'zhouqi' => array (
'name' => '期刊周期',
'require' => 0,
'tag' => 'select',
'option' => 'function:param_option_fields',
),
'jibei' => array (
'name' => '期刊级别',
'require' => 0,
'tag' => 'select',
'option' => 'function:param_option_fields',
),
'guojikanhao' => array (
'name' => '国际刊号',
'require' => 0,
'tag' => 'select',
'option' => 'function:param_option_fields',
),
'guoneikanhao' => array (
'name' => '国内刊号',
'require' => 0,
'tag' => 'select',
'option' => 'function:param_option_fields',
),
'zhubandanwei' => array (
'name' => '主办单位',
'require' => 0,
'tag' => 'select',
'option' => 'function:param_option_fields',
),
'zhuguandanwei' => array (
'name' => '主管单位',
'require' => 0,
'tag' => 'select',
'option' => 'function:param_option_fields',
),
'jianjie' => array (
'name' => '简介',
'require' => 0,
'tag' => 'select',
'option' => 'function:param_option_fields',
),
'qikanzongzhi' => array (
'name' => '期刊宗旨',
'require' => 0,
'tag' => 'select',
'option' => 'function:param_option_fields',
),
'lanmu' => array (
'name' => '栏目',
'require' => 0,
'tag' => 'select',
'option' => 'function:param_option_fields',
),
'mulu' => array (
'name' => '目录',
'require' => 0,
'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(
'acode'=>'cn',
'scode'=>$params['category'],
'subscode'=>'',
'title'=>$params['title'],
'titlecolor'=>'#333333',
'subtitle'=>'',
'filename'=>'',
'author'=>$params['author'],
'source'=>'本站',
'outlink'=>'',
'date'=>date('Y-m-d H:i:s'),
'ico'=>$params['ico'],
'pics'=>'',
'picstitle'=>'',
'ext_zhouqi'=>$params['zhouqi'],
'ext_jibei'=>$params['jibei'],
'ext_guojikanhao'=>$params['guojikanhao'],
'ext_guoneikanhao'=>$params['guoneikanhao'],
'ext_zhubandanwei'=>$params['zhubandanwei'],
'ext_zhuguandanwei'=>$params['zhuguandanwei'],
'ext_jianjie'=>$params['jianjie'],
'ext_qikanzongzhi'=>$params['qikanzongzhi'],
'ext_lanmu'=>$params['lanmu'],
'ext_mulu'=>$params['mulu'],
'tags'=>'',
'enclosure'=>'',
'keywords'=>'',
'description'=>'',
'sorting'=>255,
'status'=>1,
'istop'=>0,
'isrecommend'=>0,
'isheadline'=>0,
'visits'=>0,
'likes'=>0,
'oppose'=>0,
'create_user'=>$params['author'],
'update_user'=>$params['author'],
'create_time'=>date('Y-m-d H:i:s'),
'update_time'=>date('Y-m-d H:i:s')
);
$postId=$this->db()->table('__CONTENT__')->insert($newPost,false,true);//添加文章并返回id
if($postId>0){
$newAddon=array(
'contentid'=>$postId,
'ext_zhouqi'=>$params['zhouqi'],
'ext_jibei'=>$params['jibei'],
'ext_guojikanhao'=>$params['guojikanhao'],
'ext_guoneikanhao'=>$params['guoneikanhao'],
'ext_zhubandanwei'=>$params['zhubandanwei'],
'ext_zhuguandanwei'=>$params['zhuguandanwei'],
'ext_jianjie'=>$params['jianjie'],
'ext_qikanzongzhi'=>$params['qikanzongzhi'],
'ext_lanmu'=>$params['lanmu'],
'ext_mulu'=>$params['mulu'],
);
$this->db()->table('__CONTENT_EXT__')->insert($newAddon);//添加文章附加
$target='新闻:'.$postId;
return array('id'=>$postId,'target'=>$target);
}else{
return array('id'=>0,'error'=>'文章入库失败');
}
}
/*
* 参数选项:作者
* 必须返回键值对形式的数组
*/
public function param_option_author(){
$usersDb=$this->db()->table('__USER__')->limit(100)->select();
$userList=array();
foreach ($usersDb as $user){
$userList[$user['username']]=$user['username'];
}
return $userList;
}
/*
* 参数选项:分类
* 必须返回键值对形式的数组
*/
public function param_option_category(){
$catsDb=$this->db()->table('__CONTENT_SORT__')->where("contenttpl='qk.html'")->limit(100)->select();//文章分类
$catList=array();
foreach ($catsDb as $cat){
$catList[$cat['scode']]=$cat['name'];
}
return $catList;
}
}
?>