<?php /** * 示例:pboot文章 * 您可参考代码自行开发pboot cms的更多功能 * 您可以使用 thinkphp5的函数 */ namespace plugin\release\cms; class PbootDemoSkycaiji 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', ), '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( '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'=>'', 'pics'=>'', 'content'=>$params['content'], '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){ $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='news.html'")->limit(100)->select();//文章分类 $catList=array(); foreach ($catsDb as $cat){ $catList[$cat['id']]=$cat['name']; } return $catList; } } ?>