• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

蓝天采集器和amp;pbootcms 自定义扩展字段 录入问题

武飞扬头像
hyt48079287
帮助2

当采集任务中,有扩展字段(自定义字段)时候需要对发布插件(\plugin\release\cms中那个)进行修改,参考代码片段如下

学新通

学新通 

下面是完整代码

  1.  
    <?php
  2.  
    /**
  3.  
    * 示例:pboot文章
  4.  
    * 您可参考代码自行开发pboot cms的更多功能
  5.  
    * 您可以使用 thinkphp5的函数
  6.  
    */
  7.  
    namespace plugin\release\cms;
  8.  
    class PbootQikanSkypecaiji extends BaseCms{
  9.  
    public function cms_db_pboot($cmsPath){
  10.  
    $dbFile=realpath($cmsPath.'/config/database.php');
  11.  
    $cmsDb=array();
  12.  
    if(file_exists($dbFile)){
  13.  
    $dbFile=include $dbFile;
  14.  
    $dbFile=$dbFile['database'];
  15.  
    if(is_array($dbFile)){
  16.  
    //使用sqlite必须开启pdo_sqlite
  17.  
    $cmsDb['db_type']=stripos($dbFile['type'], 'sqlite')!==false?'sqlite':'mysql';
  18.  
    $cmsDb['db_name']=$cmsDb['db_type']=='sqlite'?($cmsPath.$dbFile['dbname']):$dbFile['dbname'];
  19.  
    $cmsDb['db_host']=$dbFile['host'];
  20.  
    $cmsDb['db_user']=$dbFile['user'];
  21.  
    $cmsDb['db_pwd']=$dbFile['passwd'];
  22.  
    $cmsDb['db_charset']='utf8';
  23.  
    $cmsDb['db_port']=$dbFile['port'];
  24.  
    $cmsDb['db_prefix']='ay_';//固定的前缀
  25.  
    }
  26.  
    }
  27.  
    return $cmsDb;
  28.  
    }
  29.  
    //参数
  30.  
    public $_params = array (
  31.  
    'author' => array (
  32.  
    'name' => '作者账号',
  33.  
    'require' => 1,
  34.  
    'tag' => 'select',
  35.  
    'option' => 'function:param_option_author',
  36.  
    ),
  37.  
    'category' => array (
  38.  
    'name' => '分类',
  39.  
    'require' => 1,
  40.  
    'tag' => 'select',
  41.  
    'option' => 'function:param_option_category',
  42.  
    ),
  43.  
    'title' => array (
  44.  
    'name' => '标题',
  45.  
    'require' => 1,
  46.  
    'tag' => 'select',
  47.  
    'option' => 'function:param_option_fields',
  48.  
    ),
  49.  
    'ico' => array (
  50.  
    'name' => '缩略图',
  51.  
    'require' => 0,
  52.  
    'tag' => 'select',
  53.  
    'option' => 'function:param_option_fields',
  54.  
    ),
  55.  
    'zhouqi' => array (
  56.  
    'name' => '期刊周期',
  57.  
    'require' => 0,
  58.  
    'tag' => 'select',
  59.  
    'option' => 'function:param_option_fields',
  60.  
    ),
  61.  
    'jibei' => array (
  62.  
    'name' => '期刊级别',
  63.  
    'require' => 0,
  64.  
    'tag' => 'select',
  65.  
    'option' => 'function:param_option_fields',
  66.  
    ),
  67.  
    'guojikanhao' => array (
  68.  
    'name' => '国际刊号',
  69.  
    'require' => 0,
  70.  
    'tag' => 'select',
  71.  
    'option' => 'function:param_option_fields',
  72.  
    ),
  73.  
    'guoneikanhao' => array (
  74.  
    'name' => '国内刊号',
  75.  
    'require' => 0,
  76.  
    'tag' => 'select',
  77.  
    'option' => 'function:param_option_fields',
  78.  
    ),
  79.  
    'zhubandanwei' => array (
  80.  
    'name' => '主办单位',
  81.  
    'require' => 0,
  82.  
    'tag' => 'select',
  83.  
    'option' => 'function:param_option_fields',
  84.  
    ),
  85.  
    'zhuguandanwei' => array (
  86.  
    'name' => '主管单位',
  87.  
    'require' => 0,
  88.  
    'tag' => 'select',
  89.  
    'option' => 'function:param_option_fields',
  90.  
    ),
  91.  
    'jianjie' => array (
  92.  
    'name' => '简介',
  93.  
    'require' => 0,
  94.  
    'tag' => 'select',
  95.  
    'option' => 'function:param_option_fields',
  96.  
    ),
  97.  
    'qikanzongzhi' => array (
  98.  
    'name' => '期刊宗旨',
  99.  
    'require' => 0,
  100.  
    'tag' => 'select',
  101.  
    'option' => 'function:param_option_fields',
  102.  
    ),
  103.  
    'lanmu' => array (
  104.  
    'name' => '栏目',
  105.  
    'require' => 0,
  106.  
    'tag' => 'select',
  107.  
    'option' => 'function:param_option_fields',
  108.  
    ),
  109.  
    'mulu' => array (
  110.  
    'name' => '目录',
  111.  
    'require' => 0,
  112.  
    'tag' => 'select',
  113.  
    'option' => 'function:param_option_fields',
  114.  
    ),
  115.  
    );
  116.  
     
  117.  
    /*
  118.  
    * 导入数据
  119.  
    * 必须以数组形式返回:
  120.  
    * id(必填)表示入库返回的自增id或状态
  121.  
    * target(可选)记录入库的数据位置(发布的网址等)
  122.  
    * desc(可选)记录入库的数据位置附加信息
  123.  
    * error(可选)记录入库失败的错误信息
  124.  
    * 入库的信息可在“已采集数据”中查看
  125.  
    * return array('id'=>0,'target'=>'','desc'=>'','error'=>'');
  126.  
    */
  127.  
    public function runImport($params){
  128.  
    $newPost=array(
  129.  
    'acode'=>'cn',
  130.  
    'scode'=>$params['category'],
  131.  
    'subscode'=>'',
  132.  
    'title'=>$params['title'],
  133.  
    'titlecolor'=>'#333333',
  134.  
    'subtitle'=>'',
  135.  
    'filename'=>'',
  136.  
    'author'=>$params['author'],
  137.  
    'source'=>'本站',
  138.  
    'outlink'=>'',
  139.  
    'date'=>date('Y-m-d H:i:s'),
  140.  
    'ico'=>$params['ico'],
  141.  
    'pics'=>'',
  142.  
    'picstitle'=>'',
  143.  
    'ext_zhouqi'=>$params['zhouqi'],
  144.  
    'ext_jibei'=>$params['jibei'],
  145.  
    'ext_guojikanhao'=>$params['guojikanhao'],
  146.  
    'ext_guoneikanhao'=>$params['guoneikanhao'],
  147.  
    'ext_zhubandanwei'=>$params['zhubandanwei'],
  148.  
    'ext_zhuguandanwei'=>$params['zhuguandanwei'],
  149.  
    'ext_jianjie'=>$params['jianjie'],
  150.  
    'ext_qikanzongzhi'=>$params['qikanzongzhi'],
  151.  
    'ext_lanmu'=>$params['lanmu'],
  152.  
    'ext_mulu'=>$params['mulu'],
  153.  
    'tags'=>'',
  154.  
    'enclosure'=>'',
  155.  
    'keywords'=>'',
  156.  
    'description'=>'',
  157.  
    'sorting'=>255,
  158.  
    'status'=>1,
  159.  
    'istop'=>0,
  160.  
    'isrecommend'=>0,
  161.  
    'isheadline'=>0,
  162.  
    'visits'=>0,
  163.  
    'likes'=>0,
  164.  
    'oppose'=>0,
  165.  
    'create_user'=>$params['author'],
  166.  
    'update_user'=>$params['author'],
  167.  
    'create_time'=>date('Y-m-d H:i:s'),
  168.  
    'update_time'=>date('Y-m-d H:i:s')
  169.  
    );
  170.  
     
  171.  
    $postId=$this->db()->table('__CONTENT__')->insert($newPost,false,true);//添加文章并返回id
  172.  
    if($postId>0){
  173.  
     
  174.  
    $newAddon=array(
  175.  
    'contentid'=>$postId,
  176.  
    'ext_zhouqi'=>$params['zhouqi'],
  177.  
    'ext_jibei'=>$params['jibei'],
  178.  
    'ext_guojikanhao'=>$params['guojikanhao'],
  179.  
    'ext_guoneikanhao'=>$params['guoneikanhao'],
  180.  
    'ext_zhubandanwei'=>$params['zhubandanwei'],
  181.  
    'ext_zhuguandanwei'=>$params['zhuguandanwei'],
  182.  
    'ext_jianjie'=>$params['jianjie'],
  183.  
    'ext_qikanzongzhi'=>$params['qikanzongzhi'],
  184.  
    'ext_lanmu'=>$params['lanmu'],
  185.  
    'ext_mulu'=>$params['mulu'],
  186.  
    );
  187.  
     
  188.  
     
  189.  
    $this->db()->table('__CONTENT_EXT__')->insert($newAddon);//添加文章附加
  190.  
     
  191.  
    $target='新闻:'.$postId;
  192.  
    return array('id'=>$postId,'target'=>$target);
  193.  
    }else{
  194.  
    return array('id'=>0,'error'=>'文章入库失败');
  195.  
    }
  196.  
    }
  197.  
    /*
  198.  
    * 参数选项:作者
  199.  
    * 必须返回键值对形式的数组
  200.  
    */
  201.  
    public function param_option_author(){
  202.  
    $usersDb=$this->db()->table('__USER__')->limit(100)->select();
  203.  
    $userList=array();
  204.  
    foreach ($usersDb as $user){
  205.  
    $userList[$user['username']]=$user['username'];
  206.  
    }
  207.  
    return $userList;
  208.  
    }
  209.  
     
  210.  
    /*
  211.  
    * 参数选项:分类
  212.  
    * 必须返回键值对形式的数组
  213.  
    */
  214.  
    public function param_option_category(){
  215.  
    $catsDb=$this->db()->table('__CONTENT_SORT__')->where("contenttpl='qk.html'")->limit(100)->select();//文章分类
  216.  
    $catList=array();
  217.  
    foreach ($catsDb as $cat){
  218.  
    $catList[$cat['scode']]=$cat['name'];
  219.  
    }
  220.  
    return $catList;
  221.  
    }
  222.  
    }
  223.  
    ?>
学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgakehc
系列文章
更多 icon
同类精品
更多 icon
继续加载