非常抱歉!该插件已停止更新仅供示例参考,cms程序更新可能会导致插件功能失效,请自行修改代码以适应您的需求
<?php
/**
* 示例:chanzhi文章
* 您可参考代码自行开发chanzhi的更多功能
* 您可以使用 thinkphp5的函数
*/
namespace plugin\release\cms;
class ChanzhiDemoSkycaiji extends BaseCms{
public $siteurl;//cms站点网址
public function cms_db_chanzhi($cmsPath){
$dbFile=realpath($cmsPath.'/../system/config/my.php');
$cmsDb=array();
if(file_exists($dbFile)){
$dbFile=file_get_contents($dbFile);
$dbParams=array('db_host'=>'host','db_user'=>'user','db_pwd'=>'password','db_port'=>'port','db_name'=>'name','db_prefix'=>'prefix');
foreach ($dbParams as $k=>$v){
if(preg_match('/\$config->db->'.$v.'\s*=\s*[\'\"](?P<val>.*)[\'\"]/i',$dbFile,$dbMatch)){
$cmsDb[$k]=$dbMatch['val'];
}
}
$cmsDb['db_charset']='utf8';
}
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(
'title'=>$params['title'],
'titleColor'=>'',
'alias'=>'',
'keywords'=>'',
'summary'=>mb_substr(strip_tags($params['content']),0,100),
'content'=>$params['content'],
'source'=>'original',
'copySite'=>'',
'copyURL'=>'',
'author'=>$params['author'],
'addedBy'=>$params['author'],
'editor'=>'',
'addedDate'=>date('Y-m-d H:i:s'),
'editedDate'=>date('Y-m-d H:i:s'),
'status'=>'normal',
'type'=>'article',
'submission'=>0,
'views'=>0,
'sticky'=>0,
'stickTime'=>'0000-00-00 00:00:00',
'stickBold'=>0,
'order'=>0,
'link'=>'',
'css'=>'',
'js'=>'',
'onlyBody'=>0,
'lang'=>'zh-cn',
);
$postId=$this->db()->table('__ARTICLE__')->insert($newPost,false,true);//添加并返回id
if($postId>0){
$this->db()->table('__RELATION__')->insert(array('type'=>'article','id'=>$postId,'category'=>$params['category'],'lang'=>'zh-cn'));
$target='文章:'.$postId;
return array('id'=>$postId,'target'=>$target);
}else{
return array('id'=>0,'error'=>'文章入库失败');
}
}
/*
* 参数选项:作者
* 必须返回键值对形式的数组
*/
public function param_option_author(){
$usersDb=$this->db()->table('__USER__')->select();
$userList=array();
foreach ($usersDb as $user){
$userList[$user['account']]=$user['account'];
}
return $userList;
}
/*
* 参数选项:分类
* 必须返回键值对形式的数组
*/
public function param_option_category(){
$catsDb=$this->db()->table('__CATEGORY__')->where("`type`='article'")->select();//文章分类
$catList=array();
foreach ($catsDb as $cat){
$catList[$cat['id']]=$cat['name'];
}
return $catList;
}
}
?>