<?php /** * 示例:feifei文章 * 您可参考代码自行开发feifeicms的更多功能 * 您可以使用 thinkphp5的函数 */ namespace plugin\release\cms; class FeifeiDemoSkycaiji extends BaseCms{ public function cms_db_feifei($cmsPath){ $dbFile=realpath($cmsPath.'/Runtime/Conf/config.php'); $cmsDb=array(); if(file_exists($dbFile)){ $dbFile=include $dbFile; if(is_array($dbFile)){ $cmsDb['db_host']=$dbFile['db_host']; $cmsDb['db_user']=$dbFile['db_user']; $cmsDb['db_pwd']=$dbFile['db_pwd']; $cmsDb['db_charset']=$dbFile['db_charset']; $cmsDb['db_port']=$dbFile['db_port']; $cmsDb['db_name']=$dbFile['db_name']; $cmsDb['db_prefix']=$dbFile['db_prefix']; } } 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( 'news_cid'=>$params['category'], 'news_name'=>$params['title'], 'news_ename'=>'', 'news_keywords'=>'', 'news_type'=>'', 'news_color'=>'颜色', 'news_pic'=>'', 'news_pic_bg'=>'', 'news_pic_slide'=>'', 'news_inputer'=>$params['author'], 'news_reurl'=>'', 'news_remark'=>mb_substr(strip_tags($params['content']),0,100), 'news_content'=>$params['content'], 'news_hits'=>0, 'news_hits_day'=>0, 'news_hits_week'=>0, 'news_hits_month'=>0, 'news_hits_lasttime'=>0, 'news_stars'=>0, 'news_status'=>1, 'news_up'=>0, 'news_down'=>0, 'news_jumpurl'=>'', 'news_letter'=>'', 'news_addtime'=>time(), 'news_skin'=>'', 'news_gold'=>'0.0', 'news_golder'=>0, 'news_series'=>'', ); $postId=$this->db()->table('__NEWS__')->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('__ADMIN__')->select(); $userList=array(); foreach ($usersDb as $user){ $userList[$user['admin_name']]=$user['admin_name']; } return $userList; } /* * 参数选项:分类 * 必须返回键值对形式的数组 */ public function param_option_category(){ $catsDb=$this->db()->table('__LIST__')->where('list_sid=2')->select();//文章分类 $catList=array(); foreach ($catsDb as $cat){ $catList[$cat['list_id']]=$cat['list_name']; } return $catList; } } ?>