<?php /** * 示例:Drupal文章 * 您可参考代码自行开发Drupal的更多功能 * 您可以使用 thinkphp5的函数 */ namespace plugin\release\cms; class DrupalDemoSkycaiji extends BaseCms{ public $siteurl;//cms站点网址 public function cms_db_drupal($cmsPath){ $dbFile=realpath($cmsPath.'/sites/default/settings.php'); $cmsDb=array(); if(file_exists($dbFile)){ $dbFile=file_get_contents($dbFile); if(preg_match('/\$databases\s*\=\s*array[\s\S]+?\)\s*\;/i',$dbFile,$dbFile)){ $dbFile=$dbFile[0]; $dbParams=array('db_host'=>'host','db_user'=>'username','db_pwd'=>'password','db_port'=>'port','db_name'=>'database','db_prefix'=>'prefix'); foreach ($dbParams as $k=>$v){ if(preg_match('/\''.$v.'\'\s*\=\s*\>\s*[\'\"](?P<val>.*)[\'\"]/i',$dbFile,$dbMatch)){ $cmsDb[$k]=$dbMatch['val']; } } $cmsDb['db_charset']='utf8'; } } 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){ $language='und'; $postId=$this->db()->table('__NODE_REVISION__')->insert(array( 'nid'=>0, 'uid'=>$params['author'], 'title'=>$params['title'], 'log'=>'', 'timestamp'=>time(), 'status'=>1, 'comment'=>2, 'promote'=>1, 'sticky'=>0, ),false,true); if($postId>0){ $this->db()->table('__NODE_REVISION__')->where('vid',$postId)->update(array('nid'=>$postId)); $this->db()->table('__NODE__')->insert(array( 'nid'=>$postId, 'vid'=>$postId, 'type'=>$params['category'], 'language'=>$language, 'title'=>$params['title'], 'uid'=>$params['author'], 'status'=>1, 'created'=>time(), 'changed'=>time(), 'comment'=>2, 'promote'=>1, 'sticky'=>0, 'tnid'=>0, 'translate'=>0, )); $this->db()->table('__FIELD_DATA_BODY__')->insert(array( 'entity_type'=>'node', 'bundle'=>$params['category'], 'deleted'=>0, 'entity_id'=>$postId, 'revision_id'=>$postId, 'language'=>$language, 'delta'=>0, 'body_value'=>$params['content'], 'body_summary'=>mb_substr(strip_tags($params['content']),0,100), 'body_format'=>'full_html', )); $this->db()->table('__NODE_COMMENT_STATISTICS__')->insert(array( 'nid'=>$postId, 'cid'=>0, 'last_comment_timestamp'=>time(), 'last_comment_name'=>null, 'last_comment_uid'=>$params['author'], 'comment_count'=>0, )); return array('id'=>$postId,'target'=>'文章:'.$postId); }else{ return array('id'=>0,'error'=>'文章入库失败'); } } /* * 参数选项:作者 * 必须返回键值对形式的数组 */ public function param_option_author(){ $usersDb=$this->db()->table('__USERS__')->select(); $userList=array(); foreach ($usersDb as $user){ $userList[$user['uid']]=$user['name']; } return $userList; } /* * 参数选项:分类 * 必须返回键值对形式的数组 */ public function param_option_category(){ $catsDb=$this->db()->table('__NODE_TYPE__')->where("`module`='node'")->select();//文章分类 $catList=array(); foreach ($catsDb as $cat){ $catList[$cat['type']]=$cat['name']; } return $catList; } } ?>