提交 6cf07c22 编写于 作者: D devil_gong

应用管理

上级 de3c208c
......@@ -95,7 +95,7 @@ class Plugins extends Common
$plugins = '\app\plugins\\'.$pluginsname.'\\'.ucfirst($pluginscontrol);
if(!class_exists($plugins))
{
$this->assign('msg', ucfirst($pluginscontrol).' 控制器未定义');
$this->assign('msg', ucfirst($pluginscontrol).' 应用控制器未定义');
return $this->fetch('public/error');
}
......@@ -103,7 +103,7 @@ class Plugins extends Common
$obj = new $plugins();
if(!method_exists($obj, $pluginsaction))
{
$this->assign('msg', ucfirst($pluginsaction).' 方法未定义');
$this->assign('msg', ucfirst($pluginsaction).' 应用方法未定义');
return $this->fetch('public/error');
}
$ret = $obj->$pluginsaction($params);
......
......@@ -22,7 +22,7 @@
</div>
<div class="am-form-group am-form-file">
<label class="block">LOGO<span class="fs-12 fw-100 cr-999">(建议100像数X100像数)</span></label>
<label class="block">LOGO<span class="fs-12 fw-100 cr-999">(建议130像数X130像数)</span></label>
<ul class="plug-file-upload-view plugins-logo-view" data-form-name="logo" data-max-number="1" data-delete="0" data-dialog-type="images">
<li>
<input type="text" name="logo" value="{{if !empty($data['logo'])}}{{$data.logo}}{{/if}}" data-validation-message="请上传图片" required />
......
......@@ -89,7 +89,7 @@ class Plugins extends Common
$plugins = '\app\plugins\\'.$pluginsname.'\\'.ucfirst($pluginscontrol);
if(!class_exists($plugins))
{
$this->assign('msg', ucfirst($pluginscontrol).' 控制器未定义');
$this->assign('msg', ucfirst($pluginscontrol).' 应用控制器未定义');
return $this->fetch('public/error');
}
......@@ -97,7 +97,7 @@ class Plugins extends Common
$obj = new $plugins();
if(!method_exists($obj, $pluginsaction))
{
$this->assign('msg', ucfirst($pluginsaction).' 方法未定义');
$this->assign('msg', ucfirst($pluginsaction).' 应用方法未定义');
return $this->fetch('public/error');
}
$ret = $obj->$pluginsaction($params);
......
<?php
namespace app\plugins\ttttttsssstest88;
/**
* 测试应用 - 后台管理
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-01T21:51:08+0800
*/
class Admin
{
// 后台管理入口
public function index($params = [])
{
// 数组组装
$data = [
'data' => ['hello', 'world!'],
'msg' => 'hello world! admin',
];
return DataReturn('处理成功', 0, $data);
}
}
?>
\ No newline at end of file
<?php
namespace app\plugins\ttttttsssstest88;
/**
* 测试应用 - 钩子入口
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-01T21:51:08+0800
*/
class Hook
{
// 应用响应入口
public function run($params = [])
{
// 是否控制器钩子
if(isset($params['is_control']) && $params['is_control'] === true)
{
return [];
// 默认返回视图
} else {
return 'hello world!';
}
}
}
?>
\ No newline at end of file
<?php
namespace app\plugins\ttttttsssstest88;
/**
* 测试应用 - 前端独立页面入口
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-01T21:51:08+0800
*/
class Index
{
// 前端页面入口
public function index($params = [])
{
// 数组组装
$data = [
'data' => ['hello', 'world!'],
'msg' => 'hello world! index',
];
return DataReturn('处理成功', 0, $data);
}
}
?>
\ No newline at end of file
{
"base":{
"plugins":"ttttttsssstest88",
"name":"测试应用",
"logo":"\/static\/upload\/images\/plugins_ttttttsssstest88\/2019\/02\/13\/1550050651917730.png",
"author":"Devil",
"author_url":"https:\/\/shopxo.net\/",
"version":"1.0.0",
"desc":"测试应用描述",
"apply_terminal":[
"pc"
],
"apply_version":[
"1.3.0"
],
"is_home":true
},
"hook":[
]
}
\ No newline at end of file
......@@ -11,6 +11,6 @@
"is_home": false
},
"hook": {
"plugins_common_top": ["app\\plugins\\usercentertopnotice\\Hook"]
"plugins_user_center_top": ["app\\plugins\\usercentertopnotice\\Hook"]
}
}
\ No newline at end of file
{{include file="public/header" /}}
<!-- right content start -->
<div class="content-right">
<div class="content">
<h1>后台管理页面</h1>
{{:print_r($data)}}
<p class="msg">{{$msg}}</p>
</div>
</div>
<!-- right content end -->
<!-- footer start -->
{{include file="public/footer" /}}
<!-- footer end -->
\ No newline at end of file
{{include file="public/header" /}}
<!-- nav start -->
{{include file="public/nav" /}}
<!-- nav end -->
<!-- header top nav -->
{{include file="public/header_top_nav" /}}
<!-- search -->
{{include file="public/nav_search" /}}
<!-- header nav -->
{{include file="public/header_nav" /}}
<!-- goods category -->
{{include file="public/goods_category" /}}
<!-- content start -->
<div class="am-g my-content">
<div class="am-u-md-6 am-u-sm-centered">
<h1>前端页面</h1>
{{:print_r($data)}}
<p class="msg">{{$msg}}</p>
</div>
</div>
<!-- content end -->
<!-- footer start -->
{{include file="public/footer" /}}
<!-- footer end -->
\ No newline at end of file
......@@ -150,11 +150,113 @@ class PluginsAdminService
// 数据更新
if(Db::name('Plugins')->where(['id'=>$params['id']])->update(['is_enable'=>intval($params['state']), 'upd_time'=>time()]))
{
// 钩子部署
$ret = self::PluginsHookDeployment();
if($ret['code'] != 0)
{
return $ret;
}
return DataReturn('操作成功');
}
return DataReturn('操作失败', -100);
}
/**
* 应用钩子部署
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2019-02-13
* @desc description
*/
private static function PluginsHookDeployment()
{
// 钩子配置文件
$tags_file = APP_PATH.'tags.php';
if(!is_writable($tags_file))
{
return DataReturn('钩子配置文件没有操作权限'.'['.$tags_file.']', -3);
}
// 钩子容器
$result = [];
// 系统自带钩子处理
if(file_exists($tags_file))
{
$tags = require $tags_file;
if(!empty($tags) && is_array($tags))
{
$system_hook_list = [
'app_init',
'app_dispatch',
'app_begin',
'module_init',
'action_begin',
'view_filter',
'app_end',
'log_write',
'log_level',
'response_send',
'response_end'
];
foreach($system_hook_list as $system_hook)
{
if(isset($tags[$system_hook]))
{
$result[$system_hook] = $tags[$system_hook];
}
}
}
}
// 处理应用钩子
$data = Db::name('Plugins')->where(['is_enable'=>1])->column('plugins');
if(!empty($data))
{
foreach($data as $plugins)
{
if(file_exists(APP_PATH.'plugins'.DS.$plugins.DS.'config.json'))
{
$config = json_decode(file_get_contents(APP_PATH.'plugins'.DS.$plugins.DS.'config.json'), true);
if(!empty($config['hook']) && is_array($config['hook']))
{
foreach($config['hook'] as $hook_key=>$hook_value)
{
if(isset($result[$hook_key]))
{
$result[$hook_key] = array_merge($result[$hook_key], $hook_value);
} else {
$result[$hook_key] = $hook_value;
}
}
}
}
}
}
// 部署钩子到文件
$ret = @file_put_contents($tags_file, "<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
// | Copyright (c) 2011~2018 http://shopxo.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
// 应用行为扩展定义文件\nreturn ".var_export($result, true).";\n?>");
if($ret === false)
{
return DataReturn('应用钩子部署失败', -10);
}
return DataReturn('处理成功', 0);
}
/**
* 删除
* @author Devil
......@@ -305,16 +407,16 @@ class PluginsAdminService
return DataReturn($ret, -1);
}
// 应用唯一标记
$plugins = trim($params['plugins']);
// 权限校验
$ret = self::PowerCheck($plugins);
$ret = self::PowerCheck();
if($ret['code'] != 0)
{
return $ret;
}
// 应用唯一标记
$plugins = trim($params['plugins']);
// 应用不存在则添加
$ret = self::PluginsExistInsert($params, $plugins);
if($ret['code'] != 0)
......@@ -642,7 +744,7 @@ php;
$temp_plugins = Db::name('Plugins')->where(['plugins'=>$plugins])->value('plugins');
if(empty($temp_plugins))
{
if(Db::name('Plugins')->insertGetId(['plugins'=>$plugins, 'add_time'=>time()]) <= 0)
if(Db::name('Plugins')->insertGetId(['plugins'=>$plugins, 'is_enable'=>0, 'add_time'=>time()]) <= 0)
{
return DataReturn('应用添加失败', -1);
}
......@@ -661,9 +763,8 @@ php;
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2018-09-29T00:01:49+0800
* @param [string] $plugins [应用唯一标记]
*/
private static function PowerCheck($plugins)
private static function PowerCheck()
{
// 应用目录
$app_dir = APP_PATH.'plugins';
......@@ -701,5 +802,85 @@ php;
}
return DataReturn('权限正常', 0);
}
/**
* 应用上传
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2018-12-19T00:53:45+0800
* @param [array] $params [输入参数]
*/
public static function PluginsUpload($params = [])
{
// 文件上传校验
$error = FileUploadError('file');
if($error !== true)
{
return DataReturn($error, -1);
}
// 文件格式化校验
$type = array('application/zip', 'application/octet-stream');
if(!in_array($_FILES['file']['type'], $type))
{
return DataReturn('文件格式有误,请上传zip压缩包', -2);
}
// 权限校验
$ret = self::PowerCheck();
if($ret['code'] != 0)
{
return $ret;
}
// 开始解压文件
$resource = zip_open($_FILES['file']['tmp_name']);
while(($temp_resource = zip_read($resource)) !== false)
{
if(zip_entry_open($resource, $temp_resource))
{
// 当前压缩包中项目名称
$file = zip_entry_name($temp_resource);
// 排除临时文件和临时目录
if(strpos($file, '/.') === false && strpos($file, '__') === false)
{
// 拼接路径
if(strpos($file, '_controller') !== false)
{
$file = ROOT.self::$html_path.$file;
} else if(strpos($file, '_static') !== false)
{
$file = ROOT.self::$static_path.$file;
} else {
continue;
}
$file = str_replace(array('_static/', '_html/'), '', $file);
// 截取文件路径
$file_path = substr($file, 0, strrpos($file, '/'));
// 路径不存在则创建
if(!is_dir($file_path))
{
mkdir($file_path, 0777, true);
}
// 如果不是目录则写入文件
if(!is_dir($file))
{
// 读取这个文件
$file_size = zip_entry_filesize($temp_resource);
$file_content = zip_entry_read($temp_resource, $file_size);
file_put_contents($file, $file_content);
}
// 关闭目录项
zip_entry_close($temp_resource);
}
}
}
return DataReturn('操作成功');
}
}
?>
\ No newline at end of file
......@@ -10,26 +10,36 @@
// +----------------------------------------------------------------------
// 应用行为扩展定义文件
return [
// 应用初始化
'app_init' => [],
// 应用开始
'app_begin' => [],
// 模块初始化
'module_init' => [],
// 操作开始执行
'action_begin' => [],
// 视图内容过滤
'view_filter' => [],
// 日志写入
'log_write' => [],
// 应用结束
'app_end' => [],
// 钩子测试
'plugins_common_top' => ['app\\plugins\\commontopmaxpicture\\Hook', 'app\\plugins\\commontopnotice\\Hook'],
// 用户中心
'plugins_user_center_top' => ['app\\plugins\\usercentertopnotice\\Hook'],
];
return array (
'app_init' =>
array (
),
'app_begin' =>
array (
),
'module_init' =>
array (
),
'action_begin' =>
array (
),
'view_filter' =>
array (
),
'app_end' =>
array (
),
'log_write' =>
array (
),
'plugins_common_top' =>
array (
0 => 'app\\plugins\\commontopmaxpicture\\Hook',
1 => 'app\\plugins\\commontopnotice\\Hook',
),
'plugins_user_center_top' =>
array (
0 => 'app\\plugins\\usercentertopnotice\\Hook',
),
);
?>
\ No newline at end of file
此差异已折叠。
h1 {
font-size: 60px;
}
.msg {
font-size: 38px;
color: #F00;
}
\ No newline at end of file
h1 {
font-size: 60px;
}
.msg {
font-size: 68px;
color: #4CAF50;
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册