推荐使用
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',''.$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; } } ?>