db()->table('__runtime__')->where("`k`='cfg'")->find(); $config=json_decode($config['v'],true); $this->siteurl=trim($config['weburl'],'\/\\');//cms网址 } /** * 自定义数据库配置 * 绑定数据时需输入cms路径并在路径结尾加上@cms程序名 */ public function cms_db_twcms($cmspath){ $dbfile=realpath($cmspath.'/twcms/config/config.inc.php'); //转换成thinkphp数据库配置 include_once $dbfile;//导入本地cms配置文件 $config=$_env['_config'][db]; $cmsdb=array( 'db_type' => $config['type'], 'db_user' => $config['master']['user'], 'db_pwd' => $config['master']['password'], 'db_host' => $config['master']['host'], 'db_port' => 3306, 'db_name' => $config['master']['name'], 'db_charset' => $config['master']['charset'], 'db_prefix' => $config['master']['tablepre'] ); 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){ $userid=$this->db()->table('__user__')->where(array('username'=>$params['author']))->value('uid'); if($userid<=0){ return array('id'=>0,'error'=>'作者账号:'.$params['author'].' 不存在'); } $newarticle=array( 'cid'=>$params['category'], 'title'=>$params['title'], 'color'=>'', 'alias'=>'', 'tags'=>'', 'intro'=>'', 'pic'=>'', 'uid'=>$userid, 'author'=>$params['author'], 'source'=>'', 'dateline'=>time(), 'lasttime'=>time(), 'ip'=>'0', 'iscomment'=>'0', 'comments'=>'0', 'imagenum'=>'0', 'filenum'=>'0', 'flags'=>'', 'seo_title'=>'', 'seo_keywords'=>'', 'seo_description'=>'' ); $articleid=$this->db()->table('__cms_article__')->insert($newarticle,false,true);//添加文章并返回id if($articleid>0){ //返回成功内容网址 $this->db()->table('__cms_article_data__')->insert(array('id'=>$articleid,'content'=>$params['content']));//添加到内容表 $this->db()->table('__cms_article_views__')->insert(array('id'=>$articleid,'cid'=>$params['category'],'views'=>0));//添加到分类关系 $target=$this->siteurl."/index.php?show--cid-{$params['category']}-id-{$articleid}.html"; return array('id'=>$articleid,'target'=>$target); }else{ return array('id'=>0,'error'=>'文章入库失败'); } return array('id'=>0,'target'=>'','desc'=>'','error'=>''); } /* * 参数选项:作者 * 必须返回键值对形式的数组 */ public function param_option_author(){ $usersdb=$this->db()->table('__user__')->select(); $userlist=array(); foreach ($usersdb as $user){ $username=auto_convert2utf8($user['username']); $userlist[$username]=$username; } return $userlist; } /* * 参数选项:分类 * 必须返回键值对形式的数组 */ public function param_option_category(){ $catsdb=$this->db()->table('__category__')->where('mid=2')->select(); $catlist=array(); foreach ($catsdb as $cat){ $catlist[$cat['cid']]=$cat['name']; } return $catlist; } } ?>