public function build() { $data = $_POST; $data['info']['name'] = trim($data['info']['name']); $addonFile = $this->preview(false); $addons_dir = ONETHINK_ADDON_PATH; //创建目录结构 $files = array(); $addon_dir = "{$addons_dir}{$data['info']['name']}/"; $files[] = $addon_dir; $addon_name = "{$data['info']['name']}Addon.class.php"; $files[] = "{$addon_dir}{$addon_name}"; if ($data['has_config'] == 1) { } //如果有配置文件 $files[] = $addon_dir . 'config.php'; if ($data['has_outurl']) { $files[] = "{$addon_dir}Controller/"; $files[] = "{$addon_dir}Controller/{$data['info']['name']}Controller.class.php"; $files[] = "{$addon_dir}Model/"; $files[] = "{$addon_dir}Model/{$data['info']['name']}Model.class.php"; } $custom_config = trim($data['custom_config']); if ($custom_config) { $data[] = "{$addon_dir}{$custom_config}"; } $custom_adminlist = trim($data['custom_adminlist']); if ($custom_adminlist) { $data[] = "{$addon_dir}{$custom_adminlist}"; } create_dir_or_files($files); //写文件 file_put_contents("{$addon_dir}{$addon_name}", $addonFile); if ($data['has_outurl']) { $addonController = <<<str <?php namespace Addons\\{$data['info']['name']}\\Controller; use Home\\Controller\\AddonsController; class {$data['info']['name']}Controller extends AddonsController{ } str; file_put_contents("{$addon_dir}Controller/{$data['info']['name']}Controller.class.php", $addonController); $addonModel = <<<str <?php namespace Addons\\{$data['info']['name']}\\Model; use Think\\Model; /** * {$data['info']['name']}模型 */ class {$data['info']['name']}Model extends Model{ } str; file_put_contents("{$addon_dir}Model/{$data['info']['name']}Model.class.php", $addonModel); } if ($data['has_config'] == 1) { file_put_contents("{$addon_dir}config.php", $data['config']); } $this->success('创建成功', U('index')); }
public function build() { $data = $_POST; $data['info']['name'] = trim($data['info']['name']); $addonFile = $this->preview(false); $addons_dir = ONETHINK_ADDON_PATH; //创建目录结构 $files = array(); $addon_dir = "{$addons_dir}{$data['info']['name']}/"; $files[] = $addon_dir; $addon_name = "{$data['info']['name']}Addon.class.php"; $files[] = "{$addon_dir}{$addon_name}"; if ($data['has_config'] == 1) { } //如果有配置文件 $files[] = $addon_dir . 'config.php'; if ($data['has_outurl']) { $files[] = "{$addon_dir}Controller/"; $files[] = "{$addon_dir}Controller/{$data['info']['name']}Controller.class.php"; $files[] = "{$addon_dir}Model/"; $files[] = "{$addon_dir}Model/{$data['info']['name']}Model.class.php"; } $custom_config = trim($data['custom_config']); if ($custom_config) { $data[] = "{$addon_dir}{$custom_config}"; } $custom_adminlist = trim($data['custom_adminlist']); if ($custom_adminlist) { $data[] = "{$addon_dir}{$custom_adminlist}"; } create_dir_or_files($files); //写文件 file_put_contents("{$addon_dir}{$addon_name}", $addonFile); if ($data['has_outurl']) { $addonController = <<<str <?php namespace Addons\\{$data['info']['name']}\\Controller; use Home\\Controller\\AddonsController; class {$data['info']['name']}Controller extends AddonsController{ } str; file_put_contents("{$addon_dir}Controller/{$data['info']['name']}Controller.class.php", $addonController); $addonModel = <<<str <?php namespace Addons\\{$data['info']['name']}\\Model; use Think\\Model; /** * {$data['info']['name']}模型 */ class {$data['info']['name']}Model extends Model{ public \$model = array( 'title'=>'',//新增[title]、编辑[title]、删除[title]的提示 'template_add'=>'',//自定义新增模板自定义html edit.html 会读取插件根目录的模板 'template_edit'=>'',//自定义编辑模板html 'search_key'=>'',// 搜索的字段名,默认是title 'extend'=>1, ); public \$_fields = array( 'id'=>array( 'name'=>'id',//字段名 'title'=>'ID',//显示标题 'type'=>'num',//字段类型 'remark'=>'',// 备注,相当于配置里的tip 'is_show'=>3,// 1-始终显示 2-新增显示 3-编辑显示 0-不显示 'value'=>0,//默认值 ), 'title'=>array( 'name'=>'title', 'title'=>'书名', 'type'=>'string', 'remark'=>'', 'is_show'=>1, 'value'=>0, 'is_must'=>1, ), ); } str; file_put_contents("{$addon_dir}Model/{$data['info']['name']}Model.class.php", $addonModel); } if ($data['has_config'] == 1) { file_put_contents("{$addon_dir}config.php", $data['config']); } $this->success('创建成功', U('index')); }
public function tpllists() { if (IS_POST) { $info = I('post.'); if ($info['createtype'] == 'dir') { $file_ext = explode('.', $info['createname']); if (!empty($file_ext[1]) || preg_match('/[^\\x00-\\x80]/', $info['createname'])) { $this->error('文件夹名称应为英文字符和数字'); } $filepath = $this->setFullpath($info['createpath'], $info['createname'], ''); if (is_dir($filepath)) { $this->error('该文件(文件夹)已经存在,请换个标识'); } else { create_dir_or_files(array(0 => $filepath)); $this->success($info['createname'] . '文件夹创建成功!路径为:' . $filepath, U('edit')); } } else { import('Common.ORG.Input'); $content = \Input::getVar($info['content']); $file_ext = explode('.', $info['createname']); if (count($file_ext) > 0) { $ext = end($file_ext); $filename = str_replace('.' . $ext, '', $info['createname']); //创建路径 file_put_contents("{$addon_dir}Model/{$data['info']['name']}Model.class.php", $addonModel); $filepath = $this->setFullpath($info['createpath'], $filename, $ext); //判断文件是否存在 否则创建 if (!file_exists($filepath)) { create_dir_or_files(array(0 => $filepath)); //是否存在 if (!file_exists($filepath)) { $this->error('模板文件新建失败,后缀标识为.,请确保文件名请使用非中文和标点,当前路径为合法路径'); } } if (!is_writable($filepath)) { $this->error("文件 {$info['createname']} 不可写!"); } file_put_contents($filepath, $content); $this->success('创建【' . $info['createname'] . '】文件成功!', U('edit')); } else { $this->error('请输入有效的文件后缀名!'); } } } else { $this->assign('meta_title', '模板编辑'); $info = I('get.'); if (empty($info['type'])) { $filename = $info['filename']; $showpath = str_replace('-', '/', $info['dir']) . '/' . $info['filename']; $this->assign('editpath', $showpath); $this->assign('title', '新增'); $this->assign('nowpath', $showpath); } else { $filename = $info['filename'] . '.' . $info['type']; $showpath = str_replace('-', '/', $info['dir']); $filepath = $this->setFullpath($info['dir'], $info['filename'], $info['type']); //标签合法 $content = file_get_contents($filepath); import('Common.ORG.Input'); $content = \Input::forTarea($content); $this->assign('content', $content); $this->assign('title', '编辑'); $this->assign('editpath', $showpath); $this->assign('nowpath', $showpath . '/' . $filename); $this->assign('fileinfo', $filename); $this->assign('filetype', 'file'); } $this->display(); } }
public function build() { $data = $_POST; $data['info']['name'] = trim($data['info']['name']); $addonFile = $this->preview(false); $addons_dir = ONETHINK_ADDON_PATH; //创建目录结构 $files = array(); $addon_dir = "{$addons_dir}{$data['info']['name']}/"; $files[] = $addon_dir; $addon_name = "{$data['info']['name']}Addon.class.php"; $files[] = "{$addon_dir}{$addon_name}"; if ($data['has_config'] == 1) { $files[] = $addon_dir . 'config.php'; } if ($data['has_outurl'] || $data['type'] == 1) { $files[] = "{$addon_dir}Controller/"; $files[] = "{$addon_dir}Controller/{$data['info']['name']}Controller.class.php"; $files[] = "{$addon_dir}Model/"; $files[] = "{$addon_dir}Model/{$data['info']['name']}Model.class.php"; $files[] = "{$addon_dir}View/"; $files[] = "{$addon_dir}View/default/"; $files[] = "{$addon_dir}View/default/{$data['info']['name']}/"; } $custom_config = trim($data['custom_config']); if ($custom_config) { $data[] = "{$addon_dir}{$custom_config}"; } $custom_adminlist = trim($data['custom_adminlist']); if ($custom_adminlist) { $data[] = "{$addon_dir}{$custom_adminlist}"; } create_dir_or_files($files); //写文件 file_put_contents("{$addon_dir}{$addon_name}", $addonFile); if ($data['has_outurl']) { $addonController = <<<str <?php namespace Addons\\{$data['info']['name']}\\Controller; use Home\\Controller\\AddonsController; class {$data['info']['name']}Controller extends AddonsController{ } str; file_put_contents("{$addon_dir}Controller/{$data['info']['name']}Controller.class.php", $addonController); $addonModel = <<<str <?php namespace Addons\\{$data['info']['name']}\\Model; use Think\\Model; /** * {$data['info']['name']}模型 */ class {$data['info']['name']}Model extends Model{ } str; file_put_contents("{$addon_dir}Model/{$data['info']['name']}Model.class.php", $addonModel); } if ($data['type'] == 1) { $addonModel = <<<str <?php \t namespace Addons\\{$data['info']['name']}\\Model; use Home\\Model\\WeixinModel; \t /** * {$data['info']['name']}的微信模型 */ class WeixinAddonModel extends WeixinModel{ \tfunction reply(\$dataArr, \$keywordArr = array()) { \t\t\$config = getAddonConfig ( '{$data['info']['name']}' ); // 获取后台插件的配置参数\t \t\t//dump(\$config); \t} \t// 关注公众号事件 \tpublic function subscribe() { \t\treturn true; \t} \t \t// 取消关注公众号事件 \tpublic function unsubscribe() { \t\treturn true; \t} \t \t// 扫描带参数二维码事件 \tpublic function scan() { \t\treturn true; \t} \t \t// 上报地理位置事件 \tpublic function location() { \t\treturn true; \t} \t \t// 自定义菜单事件 \tpublic function click() { \t\treturn true; \t}\t } \t str; file_put_contents("{$addon_dir}Model/WeixinAddonModel.class.php", $addonModel); } if ($data['has_config'] == 1) { file_put_contents("{$addon_dir}config.php", $data['config']); } if ($data['type'] == 1) { $this->success('创建成功', U('weixin')); } else { $this->success('创建成功', U('index')); } }
/** * 写入配置文件 * @param array $config 配置信息 */ function write_config($config, $auth) { if (is_array($config)) { //读取配置内容 $conf = file_get_contents(MODULE_PATH . 'Data/conf.tpl'); $user = file_get_contents(MODULE_PATH . 'Data/user.tpl'); //替换配置项 foreach ($config as $name => $value) { $conf = str_replace("[{$name}]", $value, $conf); $user = str_replace("[{$name}]", $value, $user); } $conf = str_replace('[AUTH_KEY]', $auth, $conf); $user = str_replace('[AUTH_KEY]', $auth, $user); //写入应用配置文件 if (!IS_WRITE) { return '由于您的环境不可写,请复制下面的配置文件内容覆盖到相关的配置文件,然后再登录后台。<p>' . realpath(APP_PATH) . '/Common/Conf/config.php</p> <textarea name="" style="width:650px;height:185px">' . $conf . '</textarea> <p>' . realpath(APP_PATH) . '/User/Conf/config.php</p> <textarea name="" style="width:650px;height:125px">' . $user . '</textarea>'; } else { //判断文件是否存在 不存在就自动创建 兼容 $commonconfig = APP_PATH . 'Common/Conf/config.php'; $userconfig = APP_PATH . 'User/Conf/config.php'; if (!file_exists($commonconfig)) { $files[] = $commonconfig; } if (!file_exists($userconfig)) { $files[] = $userconfig; } if (!empty($files)) { create_dir_or_files($files); } if (file_put_contents($commonconfig, $conf) && file_put_contents($userconfig, $user)) { show_msg('配置文件写入成功'); } else { //写入失败则删除 if (!empty($files)) { foreach ($files as $key => $value) { unlink($value); } } show_msg('配置文件写入失败!', 'error'); session('error', true); } return ''; } } }
public function build() { $data = $_POST; //根据标签生成微信方法 $tagslist = parse_config($data['tagslists']); //去掉空标签配置 foreach ($tagslist as $key => $value) { if (empty($key)) { unset($tagslist[$key]); } } $autotagaction = ''; foreach ($tagslist as $key => $value) { if (substr_count($value, '/') == 0) { $autotagaction .= <<<str //实现的{$value}微信TAG方法 public function {$value}(\$param){ return '实现的{$value}微信TAG方法'; } str; } } $data['info']['name'] = trim($data['info']['name']); $addonFile = $this->preview(false); $addons_dir = ONETHINK_ADDON_PATH; //创建目录结构 $files = array(); $addon_dir = "{$addons_dir}{$data['info']['name']}/"; $files[] = $addon_dir; $addon_name = "{$data['info']['name']}Addon.class.php"; $files[] = "{$addon_dir}{$addon_name}"; if ($data['has_config'] == 1) { } //如果有配置文件 $files[] = $addon_dir . 'config.php'; if ($data['has_org'] == 1) { } //如果有自定义类 $files[] = "{$addon_dir}ORG/"; if ($data['has_outurl']) { //生成插件控制器 $files[] = "{$addon_dir}Controller/"; $files[] = "{$addon_dir}Controller/{$data['info']['name']}Controller.class.php"; $files[] = "{$addon_dir}Controller/HomeController.class.php"; $files[] = "{$addon_dir}Controller/WeixinController.class.php"; $files[] = "{$addon_dir}Model/"; $files[] = "{$addon_dir}Model/{$data['info']['name']}Model.class.php"; //生成资源文件 $files[] = "{$addon_dir}Public/"; //生成模板文件 $files[] = "{$addon_dir}View/"; $files[] = "{$addon_dir}View/default/"; $files[] = "{$addon_dir}View/default/Home/"; $files[] = "{$addon_dir}View/default/Home/index.html"; $files[] = "{$addon_dir}View/default/Home/profile.html"; } $custom_config = trim($data['custom_config']); if ($custom_config) { $data[] = "{$addon_dir}{$custom_config}"; } $custom_adminlist = trim($data['custom_adminlist']); if ($custom_adminlist) { $data[] = "{$addon_dir}{$custom_adminlist}"; } create_dir_or_files($files); //写文件 file_put_contents("{$addon_dir}{$addon_name}", $addonFile); if ($data['has_outurl']) { //创建 插件名Controller $addonController = <<<str <?php namespace Addons\\{$data['info']['name']}\\Controller; use Home\\Controller\\AddonsController; class {$data['info']['name']}Controller extends AddonsController{ } str; file_put_contents("{$addon_dir}Controller/{$data['info']['name']}Controller.class.php", $addonController); //创建 HomeController $homeController = <<<str <?php namespace Addons\\{$data['info']['name']}\\Controller; use Home\\Controller\\AddonsController; class HomeController extends AddonsController{ /** * 开发说明:三大全局变量 global \$_W,\$_K; W[网站信息] K[默认微信公众号信息] * session('P'); 前台用户信息 * 获取插件配置 get_addon_config(\$name); */ //插件前台展示页面 public function index(){ \$this->display(); } //插件Tips返回处理 return 数字 public function run(){ return ''; } //插件首页用户后台 public function profile(){ \$this->display(); } } str; file_put_contents("{$addon_dir}Controller/HomeController.class.php", $homeController); //创建 Home模板文件 $indexhtml = <<<str <!-- 统一风格 采用模板渲染 插件通用模板addons 默认已加载 请参考 Amaze UI的css框架 --> <extend name="Base/addon"/> <block name="header"></block> <block name="body"></block> <block name="foot"></block> str; file_put_contents("{$addon_dir}View/default/Home/index.html", $indexhtml); //创建 Home模板文件 $profilehtml = <<<str <!-- 统一风格 采用模板渲染 用户中心通用模板addons 默认已加载 请参考 Amaze UI的css框架 --> <extend name="Base/addons"/> <block name="title">网页标题</block> <block name="main">内容主体</block> <block name="foot"></block> str; file_put_contents("{$addon_dir}View/default/Home/profile.html", $profilehtml); $addonModel = <<<str <?php namespace Addons\\{$data['info']['name']}\\Model; use Think\\Model; /** * {$data['info']['name']}模型 * model 作用: 列表页显示参数设置 * _fields 作用: 编辑时候显示字段 */ class {$data['info']['name']}Model extends Model{ public \$model = array( 'title'=>'',//新增[title]、编辑[title]、删除[title]的提示 'template_add'=>'',//自定义新增模板自定义html edit.html 会读取插件根目录的模板 'template_edit'=>'',//自定义编辑模板html 'search_key'=>'',// 搜索的字段名,默认是title 'extend'=>1, ); public \$_fields = array( 'id'=>array( 'name'=>'id',//字段名 'title'=>'ID',//显示标题 'type'=>'num',//字段类型 'remark'=>'',// 备注,相当于配置里的tip 'is_show'=>3,// 1-始终显示 2-新增显示 3-编辑显示 0-不显示 'value'=>0,//默认值 ), 'title'=>array( 'name'=>'title', 'title'=>'书名', 'type'=>'string', 'remark'=>'', 'is_show'=>1, 'value'=>0, 'is_must'=>1, ), ); } str; file_put_contents("{$addon_dir}Model/{$data['info']['name']}Model.class.php", $addonModel); } //生成微信处理 if ($data['weixin']) { $weixinController = <<<str <?php namespace Addons\\{$data['info']['name']}\\Controller; use Common\\Controller\\Bundle; /** * {$data['info']['name']}微信处理Bundle */ class WeixinController extends Bundle{ /** * 自动匹配定位:可以通过配置_rules属性 * 开发说明:三大全局变量 global \$_W,\$_P,\$_K; W[微信请求参数] P[用户信息] K[匹配到关键词信息] * 获取插件配置 \$config = Amango_Addons_Config(); * 微信回复 \$this->assign(类型,\$article); 类型[Text Dantw Duotw] * \$this->display(); */ //插件微信处理默认入口 \tpublic function index(){ wx_success('Hello World!这是{$data['info']['title']}的微信Bundle!'); \t} {$autotagaction} public function run(){ return true; } //插件展示微信TAG方法 public function showTips(){ return ''; } } str; file_put_contents("{$addon_dir}Controller/WeixinController.class.php", $weixinController); } if ($data['has_config'] == 1) { file_put_contents("{$addon_dir}config.php", $data['config']); } $this->success('创建成功', U('index')); }