<?php /** * 示例:maccms文章 * 您可参考代码自行开发maccms的更多功能 * 您可以使用 thinkphp5的函数 */ namespace plugin\release\cms; class MaccmsDemoSkycaiji extends BaseCms{ //参数 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', ), ); public function cms_db_maccms($cmsPath){ $config=include $cmsPath.'/application/database.php'; $cmsDb=array( 'db_type' => $config['type'], 'db_user' => $config['username'], 'db_pwd' => $config['password'], 'db_host' => $config['hostname'], 'db_port' => $config['hostport'], 'db_name' => $config['database'], 'db_charset' => $config['charset'], 'db_prefix' => $config['prefix'] ); return $cmsDb; } /* * 导入数据 * 必须以数组形式返回: * id(必填)表示入库返回的自增id或状态 * target(可选)记录入库的数据位置(发布的网址等) * desc(可选)记录入库的数据位置附加信息 * error(可选)记录入库失败的错误信息 * 入库的信息可在“已采集数据”中查看 * return array('id'=>0,'target'=>'','desc'=>'','error'=>''); */ public function runImport($params){ $uid=$this->db()->table('__ADMIN__')->where(array('admin_name'=>$params['author']))->find(); if(!empty($uid)){ $uid=$uid['admin_id']; }else{ return array('id'=>0,'error'=>'用户不存在'); } $cat=$this->db()->table('__TYPE__')->where(array('type_id'=>$params['category']))->find(); $newArticle=array( 'type_id'=>$params['category'], 'type_id_1'=>$cat['type_pid'], 'group_id'=>0, 'art_name'=>$params['title'], 'art_sub'=>'', 'art_en'=>'', 'art_status'=>1, 'art_letter'=>'', 'art_color'=>'', 'art_from'=>'', 'art_author'=>'', 'art_tag'=>'', 'art_class'=>'', 'art_pic'=>'', 'art_pic_thumb'=>'', 'art_pic_slide'=>'', 'art_blurb'=>'', 'art_remarks'=>'', 'art_jumpurl'=>'', 'art_tpl'=>'', 'art_level'=>0, 'art_lock'=>0, 'art_up'=>0, 'art_down'=>0, 'art_hits'=>0, 'art_hits_day'=>0, 'art_hits_week'=>0, 'art_hits_month'=>0, 'art_time'=>time(), 'art_time_add'=>time(), 'art_time_hits'=>0, 'art_time_make'=>0, 'art_score'=>0, 'art_score_all'=>0, 'art_score_num'=>0, 'art_rel_art'=>'', 'art_rel_vod'=>'', 'art_title'=>'', 'art_note'=>'', 'art_content'=>$params['content'] ); $id=$this->db()->table('__ART__')->insert($newArticle,false,true); if($id>0){ return array('id'=>$id,'target'=>'文章:'.$id); }else{ return array('id'=>0,'error'=>'添加文章失败'); } } /* * 参数选项:作者 * 必须返回键值对形式的数组 */ public function param_option_author(){ $usersDb=$this->db()->table('__ADMIN__')->select(); $userList=array(); foreach ($usersDb as $user){ $uname=auto_convert2utf8($user['admin_name']); $userList[$uname]=$uname; } return $userList; } /* * 参数选项:分类 * 必须返回键值对形式的数组 */ public function param_option_category(){ $catsDb=$this->db()->table('__TYPE__')->where('type_mid=2')->select();//分类 $catList=array(); foreach ($catsDb as $cat){ $catList[$cat['type_id']]=auto_convert2utf8($cat['type_name']); } return $catList; } } ?>