推荐使用
siteurl=$this->db()->table('__options__')->where(array('option_name'=>'blogurl'))->value('option_value');
}
public function cms_db_emlog($cmspath){
$configfile=realpath($cmspath.'/config.php');
$cmsdb=array('db_type'=>'mysql','db_charset'=>'utf8');
if(file_exists($configfile)){
$configfile=file_get_contents($configfile);
if($configfile){
$dbkeys=array('db_host'=>'db_host','db_user'=>'db_user','db_pwd'=>'db_passwd','db_prefix'=>'db_prefix','db_name'=>'db_name');
foreach($dbkeys as $k=>$v){
if(preg_match('/define\s*\(\s*[\'\"]'.$v.'[\'\"]\s*,\s*[\'\"](?p[^\'\"] )[\'\"]\s*\)/i',$configfile,$val)){
$cmsdb[$k]=$val['val'];
}
}
}
}
return $cmsdb;
}
//参数
public $_params = array (
'author' => array (
'name' => '作者账号',
'require' => 1,
'tag' => 'select',
'option' => 'function:param_option_author',
),
'category' => array (
'name' => '分类',
'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){
$uid=$this->db()->table('__user__')->where(array('username'=>$params['author']))->find();
if(!empty($uid)){
$uid=$uid['uid'];
}else{
return array('id'=>0,'error'=>'用户不存在');
}
$newpost=array(
'title'=>$params['title'],
'date'=>time(),
'content'=>$params['content'],
'excerpt'=>'',
'alias'=>'',
'author'=>$uid,
'sortid'=>1,
'type'=>'blog',
'views'=>0,
'comnum'=>0,
'attnum'=>0,
'top'=>'n',
'sortop'=>'n',
'hide'=>'n',
'checked'=>'y',
'allow_remark'=>'y',
'password'=>'',
'template'=>'',
'tags'=>'',
);
$postid=$this->db()->table('__blog__')->insert($newpost,false,true);//添加文章并返回id
if($postid>0){
//返回成功内容网址
$target=$this->siteurl.'?post='.$postid;
return array('id'=>$postid,'target'=>$target);
}else{
return array('id'=>0,'error'=>'文章入库失败');
}
}
/*
* 参数选项:作者
* 必须返回键值对形式的数组
*/
public function param_option_author(){
$usersdb=$this->db()->table('__user__')->limit(100)->select();
$userlist=array();
foreach ($usersdb as $user){
$userlist[$user['username']]=$user['username'];
}
return $userlist;
}
/*
* 参数选项:分类
* 必须返回键值对形式的数组
*/
public function param_option_category(){
$catsdb=$this->db()->table('__sort__')->select();
$catlist=array();
foreach ($catsdb as $cat){
$catlist[$cat['sid']]=$cat['sortname'];
}
return $catlist;
}
}
?>