<?php /** * 示例:yzmcms文章 * 您可参考代码自行开发yzmcms的更多功能 * 您可以使用 thinkphp5的函数 */ namespace plugin\release\cms; class YzmcmsDemoSkycaiji extends BaseCms{ public $siteurl;//cms站点网址 //参数 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', ), 'seotitle' => array ( 'name' => 'SEO标题', 'require' => 1, 'tag' => 'select', 'option' => 'function:param_option_fields', ), 'content' => array ( 'name' => '文章内容', 'require' => 1, 'tag' => 'select', 'option' => 'function:param_option_fields', ), 'cover' => array ( 'name' => '封面图', 'require' => 0, 'tag' => 'select', 'option' => 'function:param_option_fields', ), ); public function cms_db_yzmcms($cmsPath){ $config=include $cmsPath.'/common/config/config.php'; $cmsDb=array( 'db_type' => 'mysql', 'db_user' => $config['db_user'], 'db_pwd' => $config['db_pwd'], 'db_host' => $config['db_host'], 'db_port' => $config['db_port'], 'db_name' => $config['db_name'], 'db_charset' => 'utf8', 'db_prefix' => $config['db_prefix'] ); return $cmsDb; } public function init_extend(){ $siteurl=$this->db()->table('__CONFIG__')->where("`name`='site_url'")->find(); $this->siteurl=$siteurl['value']; } /* * 导入数据 * 必须以数组形式返回: * id(必填)表示入库返回的自增id或状态 * target(可选)记录入库的数据位置(发布的网址等) * desc(可选)记录入库的数据位置附加信息 * error(可选)记录入库失败的错误信息 * 入库的信息可在“已采集数据”中查看 * return array('id'=>0,'target'=>'','desc'=>'','error'=>''); */ public function runImport($params){ $user=$this->db()->table('__ADMIN__')->where(array('adminname'=>$params['author']))->find(); if(empty($user)){ return array('id'=>0,'error'=>'用户不存在'); } $cat=$this->db()->table('__CATEGORY__')->where(array('catid'=>$params['category']))->find(); $newArticle=array( 'catid'=>$params['category'], 'userid'=>$user['adminid'], 'username'=>$user['adminname'], 'nickname'=>$user['nickname'], 'title'=>$params['title'], 'seo_title'=>$params['seotitle'], 'inputtime'=>time(), 'updatetime'=>time(), 'keywords'=>'', 'description'=>mb_substr(trim(strip_tags($params['content'])), 0,100,'utf-8'), 'click'=>'', 'content'=>$params['content'], 'copyfrom'=>'', 'thumb'=>$params['cover'], 'url'=>'', 'flag'=>'', 'status'=>1, 'system'=>1, 'listorder'=>10, 'groupids_view'=>0, 'readpoint'=>0 ); $id=$this->db()->table('__ARTICLE__')->insert($newArticle,false,true); if($id>0){ $url=$this->siteurl.$cat['catdir'].'/'.$id.'.html';//文章url $this->db()->table('__ARTICLE__')->where(array('id'=>$id))->update(array('url'=>$url)); return array('id'=>$id,'target'=>$url); }else{ return array('id'=>0,'error'=>'添加文章失败'); } } /* * 参数选项:作者 * 必须返回键值对形式的数组 */ public function param_option_author(){ $usersDb=$this->db()->table('__ADMIN__')->select(); $userList=array(); foreach ($usersDb as $user){ $uname=auto_convert2utf8($user['adminname']); $userList[$uname]=$uname; } return $userList; } /* * 参数选项:分类 * 必须返回键值对形式的数组 */ public function param_option_category(){ $catsDb=$this->db()->table('__CATEGORY__')->where('modelid=1')->select();//分类 $catList=array(); foreach ($catsDb as $cat){ $catList[$cat['catid']]=auto_convert2utf8($cat['catname']); } return $catList; } } ?>