<?php /** * 示例:destoon文章 * 您可参考代码自行开发destoon的更多功能 * 您可以使用 thinkphp5的函数 */ namespace plugin\release\cms; class DestoonDemoSkycaiji extends BaseCms{ public $siteurl;//cms站点网址 public function cms_db_destoon($cmsPath){ define('IN_DESTOON',true); $dbFile=realpath($cmsPath.'/config.inc.php'); //转换成thinkphp数据库配置 include $dbFile;//导入本地cms配置文件 $cmsDb=array( 'db_type' => $CFG['database'], 'db_user' => $CFG['db_user'], 'db_pwd' => $CFG['db_pass'], 'db_host' => $CFG['db_host'], 'db_port' => 3306, 'db_name' => $CFG['db_name'], 'db_charset' => $CFG['db_charset'], 'db_prefix' => $CFG['tb_pre'] ); $this->siteurl=$CFG['url']; 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){ $newArticle=array( 'catid'=>$params['category'], 'areaid'=>0, 'level'=>0, 'title'=>$params['title'], 'style'=>'', 'fee'=>0, 'subtitle'=>'', 'introduce'=>mb_substr(strip_tags($params['content']), 0,60,'utf-8'), 'tag'=>'', 'keyword'=>'', 'pptword'=>'', 'author'=>'', 'copyfrom'=>'', 'fromurl'=>'', 'voteid'=>'', 'hits'=>0, 'comments'=>0, 'thumb'=>'', 'username'=>$params['author'], 'addtime'=>time(), 'editor'=>$params['author'], 'edittime'=>time(), 'ip'=>'', 'template'=>'', 'status'=>3, 'islink'=>0, 'linkurl'=>'', 'filepath'=>'', 'note'=>'' ); $articleId=$this->db()->table('__ARTICLE_21__')->insert($newArticle,false,true);//添加文章并返回id if($articleId>0){ $target='show.php?itemid='.$articleId; $this->db()->table('__ARTICLE_21__')->where(array('itemid'=>$articleId))->update(array('linkurl'=>$target)); $this->db()->table('__ARTICLE_DATA_21__')->insert(array('itemid'=>$articleId,'content'=>$params['content'])); $target=$this->siteurl.'news/'.$target; return array('id'=>$articleId,'target'=>$target); }else{ return array('id'=>0,'error'=>'文章入库失败'); } } /* * 参数选项:作者 * 必须返回键值对形式的数组 */ public function param_option_author(){ $usersDb=$this->db()->table('__MEMBER__')->where('admin=1')->select(); $userList=array(); foreach ($usersDb as $user){ $uname=$user['username']; $userList[$uname]=$uname; } return $userList; } /* * 参数选项:分类 * 必须返回键值对形式的数组 */ public function param_option_category(){ $catsDb=$this->db()->table('__CATEGORY__')->where('moduleid=21')->select();//文章分类 $catList=array(); foreach ($catsDb as $cat){ $catList[$cat['catid']]=$cat['catname']; } return $catList; } } ?>