推荐使用
db()->table('__site__')->order('siteid asc')->find(); $this->siteurl=$site['domain']; } //参数 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){ //新文章 $newnews=array( 'catid'=>$params['category'], 'typeid'=>0, 'title'=>$params['title'], 'style'=>'', 'thumb'=>'', 'keywords'=>'', 'description'=>'', 'posids'=>0, 'url'=>'', 'listorder'=>'', 'status'=>99, 'sysadd'=>1, 'islink'=>0, 'username'=>$params['author'], 'inputtime'=>time(), 'updatetime'=>time() ); $newsid=$this->db()->table('__news__')->insert($newnews,false,true);//添加到文章主表 if($newsid>0){ //入库成功 $url=$this->siteurl.'index.php?m=content&c=index&a=show&catid='.$params['category'].'&id='.$newsid; $this->db()->table('__news__')->where(array('id'=>$newsid))->update(array('url'=>$url));//修改url //文章从表 $newdata=array( 'id'=>$newsid, 'content'=>$params['content'], 'readpoint'=>0, 'groupids_view'=>'', 'paginationtype'=>0, 'maxcharperpage'=>10000, 'template'=>'', 'paytype'=>0, 'relation'=>'', 'voteid'=>0, 'allow_comment'=>1, 'copyfrom'=>'' ); $this->db()->table('__news_data__')->insert($newdata);//添加到文章从表 return array('id'=>$newsid,'target'=>$url); }else{ return array('id'=>0,'error'=>'文章入库失败'); } } /* * 参数选项:文章栏目 * 必须返回键值对形式的数组 */ public function param_option_category(){ $catsdb=$this->db()->table('__category__')->where("`module`='content' and `modelid`=1")->select(); $catlist=array(); foreach ($catsdb as $cat){ $catlist[$cat['catid']]=auto_convert2utf8($cat['catname']); } return $catlist; } /* * 参数选项:作者 * 必须返回键值对形式的数组 */ public function param_option_author(){ $usersdb=$this->db()->table('__admin__')->select(); $userlist=array(); foreach ($usersdb as $user){ $user['username']=auto_convert2utf8($user['username']); $userlist[$user['username']]=$user['username']; } return $userlist; } } ?>