推荐使用
[^\'\"] )[\'\"]/i',$configfile,$prefix)){ //匹配前缀 $cmsdb['db_prefix']=$prefix['pre']; } if(preg_match('/\$db->addserver\s*\((?p[\s\s] ?)\)\s*,/i',$configfile,$db)){ //匹配数组 $db=$db['db']; $dbkeys=array('db_host'=>'host','db_user'=>'user','db_pwd'=>'password','db_charset'=>'charset','db_port'=>'port','db_name'=>'database'); foreach($dbkeys as $k=>$v){ if(preg_match('/[\'\"]'.$v.'[\'\"]\s*=\s*>\s*[\'\"](?p [^\'\"] )[\'\"]/i',$db,$val)){ $cmsdb[$k]=$val['val']; } } } } } return $cmsdb; } /*初始化扩展*/ public function init_extend(){ $siteurl=$this->db()->table('__options__')->where("name='siteurl'")->find(); $this->siteurl=rtrim($siteurl['value'],'\/\\').'/'; } //参数 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){ $newpost=array( 'title'=>$params['title'], 'created'=>time(), 'modified'=>time(), 'text'=>$params['content'], 'order'=>0, 'authorid'=>$params['author'], 'type'=>'post', 'status'=>'publish', 'allowcomment'=>1, 'allowping'=>1, 'allowfeed'=>1, 'parent'=>0 ); $postid=$this->db()->table('__contents__')->insert($newpost,false,true);//添加文章并返回id if($postid>0){ $this->db()->table('__contents__')->where('cid',$postid)->update(array('slug'=>$postid)); $this->db()->table('__relationships__')->insert(array('cid'=>$postid,'mid'=>$params['category']),true); $target=$this->siteurl.'/index.php/archives/'.$postid.'/'; return array('id'=>$postid,'target'=>$target); }else{ return array('id'=>0,'error'=>'文章入库失败'); } } /* * 参数选项:作者 * 必须返回键值对形式的数组 */ public function param_option_author(){ $usersdb=$this->db()->table('__users__')->where('group','administrator')->select(); $userlist=array(); foreach ($usersdb as $user){ $userlist[$user['uid']]=$user['name']; } return $userlist; } /* * 参数选项:分类 * 必须返回键值对形式的数组 */ public function param_option_category(){ $catsdb=$this->db()->table('__metas__')->select();//文章分类 $catlist=array(); foreach ($catsdb as $cat){ $catlist[$cat['mid']]=$cat['name']; } return $catlist; } } ?>