<?php /** * 示例:hybbs文章 * 您可参考代码自行开发hybbs的更多功能 * 您可以使用 thinkphp5的函数 */ namespace plugin\release\cms; class HybbsDemoSkycaiji extends BaseCms{ public $siteurl;//cms站点网址 public function cms_db_hybbs($cmsPath){ $dbFile=realpath($cmsPath.'/Conf/config.php'); $cmsDb=array(); if(file_exists($dbFile)){ $dbFile=include $dbFile; if(is_array($dbFile)){ $cmsDb['db_host']=$dbFile['SQL_IP']; $cmsDb['db_user']=$dbFile['SQL_USER']; $cmsDb['db_pwd']=$dbFile['SQL_PASS']; $cmsDb['db_charset']=$dbFile['SQL_CHARSET']; $cmsDb['db_port']=$dbFile['SQL_PORT']; $cmsDb['db_name']=$dbFile['SQL_NAME']; $cmsDb['db_prefix']=$dbFile['SQL_PREFIX']; $this->siteurl=rtrim($dbFile['DOMAIN_NAME'],'\/\\').'/'; } } 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){ $newThread=array( 'fid'=>$params['category'], 'uid'=>$params['author'], 'pid'=>0, 'title'=>$params['title'], 'summary'=>mb_substr(strip_tags($params['content']),0,100), 'atime'=>time(), 'etime'=>time(), 'euid'=>0, 'btime'=>time(), 'buid'=>0, 'views'=>0, 'posts'=>0, 'goods'=>0, 'nos'=>0, 'img'=>'', 'img_count'=>0, 'top'=>0, 'files'=>0, 'hide'=>0, 'gold'=>0, 'state'=>0 ); $threadId=$this->db()->table('__THREAD__')->insert($newThread,false,true);//添加并返回id if($threadId>0){ $newPost=array( 'tid'=>$threadId, 'fid'=>$params['category'], 'uid'=>$params['author'], 'rpid'=>0, 'isthread'=>1, 'content'=>$params['content'], 'atime'=>time(), 'etime'=>0, 'euid'=>0, 'goods'=>0, 'nos'=>0, 'posts'=>0, ); $postId=$this->db()->table('__POST__')->insert($newPost,false,true);//添加并返回id if($postId>0){ $this->db()->table('__THREAD__')->where('tid',$threadId)->update(array('pid'=>$postId)); } $target=$this->siteurl.'?t/'.$threadId.'.html'; return array('id'=>$postId,'target'=>$target); }else{ return array('id'=>0,'error'=>'文章入库失败'); } } /* * 参数选项:作者 * 必须返回键值对形式的数组 */ public function param_option_author(){ $usersDb=$this->db()->table('__USER__')->where('gid=1')->select(); $userList=array(); foreach ($usersDb as $user){ $userList[$user['uid']]=$user['user']; } return $userList; } /* * 参数选项:分类 * 必须返回键值对形式的数组 */ public function param_option_category(){ $catsDb=$this->db()->table('__FORUM__')->select();//文章分类 $catList=array(); foreach ($catsDb as $cat){ $catList[$cat['id']]=$cat['name']; } return $catList; } } ?>