非常抱歉!该插件已停止更新仅供示例参考,cms程序更新可能会导致插件功能失效,请自行修改代码以适应您的需求
<?php
/**
* 示例:catfish文章
* 您可参考代码自行开发catfish的更多功能
* 您可以使用 thinkphp5的函数
*/
namespace plugin\release\cms;
class CatfishDemoSkycaiji extends BaseCms{
public $siteurl;//cms站点网址
public function cms_db_catfish($cmsPath){
$dbFile=realpath($cmsPath.'/application/database.php');
$cmsDb=array();
if(file_exists($dbFile)){
$dbFile=include $dbFile;
if(is_array($dbFile)){
$cmsDb['db_host']=$dbFile['hostname'];
$cmsDb['db_user']=$dbFile['username'];
$cmsDb['db_pwd']=$dbFile['password'];
$cmsDb['db_charset']=$dbFile['charset'];
$cmsDb['db_port']=$dbFile['hostport'];
$cmsDb['db_name']=$dbFile['database'];
$cmsDb['db_prefix']=$dbFile['prefix'];
}
}
return $cmsDb;
}
/*初始化扩展*/
public function init_extend(){
$siteUrl=$this->db()->table('__OPTIONS__')->where("option_name='domain'")->find();
$this->siteurl=rtrim($siteUrl['option_value'],'\/\\').'/';
}
//参数
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(
'post_author'=>$params['author'],
'post_keywords'=>'',
'post_source'=>'',
'post_date'=>date("Y-m-d H:i:s",time()),
'post_content'=>$params['content'],
'post_title'=>$params['title'],
'post_excerpt'=>mb_substr(strip_tags($params['content']),0,100),
'post_status'=>1,
'comment_status'=>1,
'post_modified'=>date("Y-m-d H:i:s",time()),
'post_comment'=>'',
'parent_id'=>0,
'post_type'=>0,
'comment_count'=>0,
'thumbnail'=>'',
'post_hits'=>0,
'post_like'=>0,
'istop'=>0,
'recommended'=>0,
'status'=>1
);
$postId=$this->db()->table('__POSTS__')->insert($newPost,false,true);//添加文章并返回id
if($postId>0){
$this->db()->table('__TERM_RELATIONSHIPS__')->insert(array('object_id'=>$postId,'term_id'=>$params['category']),true);
$target=$this->siteurl.'article/'.$postId.'.html';
return array('id'=>$postId,'target'=>$target);
}else{
return array('id'=>0,'error'=>'文章入库失败');
}
}
/*
* 参数选项:作者
* 必须返回键值对形式的数组
*/
public function param_option_author(){
$usersDb=$this->db()->table('__USERS__')->where('user_type','in',array(1,3))->select();
$userList=array();
foreach ($usersDb as $user){
$userList[$user['id']]=$user['user_login'];
}
return $userList;
}
/*
* 参数选项:分类
* 必须返回键值对形式的数组
*/
public function param_option_category(){
$catsDb=$this->db()->table('__TERMS__')->select();//文章分类
$catList=array();
foreach ($catsDb as $cat){
$catList[$cat['id']]=$cat['term_name'];
}
return $catList;
}
}
?>