推荐使用帝国cms远程发布接口插件
<?php /** * 示例:empirecms文章 * 您可参考代码自行开发empirecms的更多功能 * 您可以使用 thinkphp5的函数 */ namespace plugin\release\cms; class EmpirecmsDemoSkycaiji extends BaseCms{ public $newsurl;//根目录 //参数 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', ), ); public function init_extend(){ include $this->cmsPath.'/e/config/config.php'; $this->newsurl=$public_r['newsurl']; } /* * 导入数据 * 必须以数组形式返回: * id(必填)表示入库返回的自增id或状态 * target(可选)记录入库的数据位置(发布的网址等) * desc(可选)记录入库的数据位置附加信息 * error(可选)记录入库失败的错误信息 * 入库的信息可在“已采集数据”中查看 * return array('id'=>0,'target'=>'','desc'=>'','error'=>''); */ public function runImport($params){ $uid=$this->db()->table('__ENEWSUSER__')->where(array('username'=>$params['author']))->find(); if(!empty($uid)){ $uid=$uid['userid']; }else{ return array('id'=>0,'error'=>'用户不存在'); } $cat=$this->db()->table('__ENEWSCLASS__')->where(array('classid'=>$params['category']))->find();//分类 $cat=$this->auto_convert2utf8($cat); if($cat['tbname']=='article'){ //添加文章 $newArticle=array( 'classid'=>$params['category'], 'ttid'=>0, 'onclick'=>0, 'plnum'=>0, 'totaldown'=>0, 'newspath'=>date('Y-m-d',time()), 'filename'=>'', 'userid'=>$uid, 'username'=>$params['author'], 'firsttitle'=>0, 'isgood'=>0, 'ispic'=>0, 'istop'=>0, 'isqf'=>0, 'ismember'=>0, 'isurl'=>0, 'truetime'=>time(), 'lastdotime'=>time(), 'havehtml'=>1, 'groupid'=>0, 'userfen'=>0, 'titlefont'=>'', 'titleurl'=>'', 'stb'=>1, 'fstb'=>1, 'restb'=>1, 'keyboard'=>'', 'title'=>$params['title'], 'newstime'=>time(), 'titlepic'=>'', 'eckuid'=>0, 'ftitle'=>'', 'smalltext'=>'', 'writer'=>'', 'befrom'=>'', 'newstext'=>'', 'diggtop'=>0 ); $aid=$this->db()->table('__ECMS_ARTICLE__')->insert($newArticle,false,true); if($aid>0){ //存储到文件中 $newstext=date('Y',time()).'/'.date('md',time()).'/'.md5($aid); $this->write_file($this->cmsPath.'/d/txt/'.$newstext.'.php','<? exit();?>'.$params['content']); $this->db()->table('__ECMS_ARTICLE__')->where(array('id'=>$aid))->update(array( 'filename'=>$aid, 'titleurl'=>$this->newsurl.'e/action/ShowInfo.php?classid='.$params['category'].'&id='.$aid, 'newstext'=>$newstext )); //附加表 $this->db()->table('__ECMS_ARTICLE_DATA_1__')->insert(array( 'id'=>$aid, 'classid'=>$params['category'], 'keyid'=>'', 'dokey'=>1, 'newstempid'=>0, 'closepl'=>0, 'haveaddfen'=>0, 'infotags'=>'' )); $this->db()->table('__ECMS_ARTICLE_INDEX__')->insert(array( 'id'=>$aid, 'classid'=>$params['category'], 'checked'=>1, 'newstime'=>time(), 'truetime'=>time(), 'lastdotime'=>time(), 'havehtml'=>1 )); return array('id'=>$aid,'target'=>'文章:'.$aid); }else{ return array('id'=>0,'error'=>'添加文章失败'); } }else{ //添加新闻 $newNews=array( 'classid'=>$params['category'], 'ttid'=>0, 'onclick'=>0, 'plnum'=>0, 'totaldown'=>0, 'newspath'=>date('Y-m-d',time()), 'filename'=>'', 'userid'=>$uid, 'username'=>$params['author'], 'firsttitle'=>0, 'isgood'=>0, 'ispic'=>0, 'istop'=>0, 'isqf'=>0, 'ismember'=>0, 'isurl'=>0, 'truetime'=>time(), 'lastdotime'=>time(), 'havehtml'=>1, 'groupid'=>0, 'userfen'=>0, 'titlefont'=>'', 'titleurl'=>'', 'stb'=>1, 'fstb'=>1, 'restb'=>1, 'keyboard'=>'', 'title'=>$params['title'], 'newstime'=>time(), 'titlepic'=>'', 'eckuid'=>0, 'ftitle'=>'', 'smalltext'=>'', 'diggtop'=>0 ); $nid=$this->db()->table('__ECMS_NEWS__')->insert($newNews,false,true); if($nid>0){ $this->db()->table('__ECMS_NEWS__')->where(array('id'=>$nid))->update(array( 'filename'=>$nid, 'titleurl'=>$this->newsurl.'e/action/ShowInfo.php?classid='.$params['category'].'&id='.$nid )); //附加表 $this->db()->table('__ECMS_NEWS_DATA_1__')->insert(array( 'id'=>$nid, 'classid'=>$params['category'], 'keyid'=>'', 'dokey'=>1, 'newstempid'=>0, 'closepl'=>0, 'haveaddfen'=>0, 'infotags'=>'', 'writer'=>'', 'befrom'=>'', 'newstext'=>$params['content'] )); $this->db()->table('__ECMS_NEWS_INDEX__')->insert(array( 'id'=>$nid, 'classid'=>$params['category'], 'checked'=>1, 'newstime'=>time(), 'truetime'=>time(), 'lastdotime'=>time(), 'havehtml'=>1 )); return array('id'=>$nid,'target'=>'新闻:'.$nid); }else{ return array('id'=>0,'error'=>'添加文章失败'); } } } /* * 参数选项:作者 * 必须返回键值对形式的数组 */ public function param_option_author(){ $usersDb=$this->db()->table('__ENEWSUSER__')->where('groupid=1')->select(); $userList=array(); foreach ($usersDb as $user){ $uname=auto_convert2utf8($user['username']); $userList[$uname]=$uname; } return $userList; } /* * 参数选项:分类 * 必须返回键值对形式的数组 */ public function param_option_category(){ $catsDb=$this->db()->table('__ENEWSCLASS__')->where("islast=1 and tbname in ('news','article')")->select();//文章分类 $catList=array(); foreach ($catsDb as $cat){ $catList[$cat['classid']]=auto_convert2utf8($cat['classname']); } return $catList; } } ?>