应用上传安装

This commit is contained in:
devil_gong 2019-02-14 11:33:41 +08:00
parent 31820544d9
commit 3f13cc19bd
17 changed files with 111 additions and 204 deletions

View File

@ -195,5 +195,24 @@ class Pluginsadmin extends Common
// 开始处理 // 开始处理
return PluginsAdminService::PluginsStatusUpdate(input('post.')); return PluginsAdminService::PluginsStatusUpdate(input('post.'));
} }
/**
* 上传安装
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-05-10T16:27:09+0800
*/
public function Upload()
{
// 是否ajax
if(!IS_AJAX)
{
return $this->error('非法访问');
}
// 开始处理
return PluginsAdminService::PluginsUpload(input());
}
} }
?> ?>

View File

@ -98,8 +98,7 @@ class Theme extends Common
} }
// 开始处理 // 开始处理
$params = input(); return ThemeService::ThemeDelete(input());
return ThemeService::ThemeDelete($params);
} }
/** /**
@ -118,8 +117,7 @@ class Theme extends Common
} }
// 开始处理 // 开始处理
$params = input(); return ThemeService::ThemeUpload(input());
return ThemeService::ThemeUpload($params);
} }
} }
?> ?>

View File

@ -25,8 +25,8 @@
<label class="block">LOGO<span class="fs-12 fw-100 cr-999">建议130像数X130像数</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"> <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> <li>
<input type="text" name="logo" value="{{if !empty($data['logo'])}}{{$data.logo}}{{/if}}" data-validation-message="请上传图片" required /> <input type="text" name="logo" value="{{if !empty($data['logo_old'])}}{{$data.logo_old}}{{/if}}" data-validation-message="请上传图片" required />
<img src="{{if !empty($data['logo_old'])}}{{$data.logo_old}}{{else /}}{{$attachment_host}}/static/admin/default/images/default-images.png{{/if}}" /> <img src="{{if !empty($data['logo'])}}{{$data.logo}}{{else /}}{{$attachment_host}}/static/admin/default/images/default-images.png{{/if}}" />
</li> </li>
</ul> </ul>
<div class="plug-file-upload-submit" data-view-tag="ul.plugins-logo-view">+上传图片</div> <div class="plug-file-upload-submit" data-view-tag="ul.plugins-logo-view">+上传图片</div>

View File

@ -8,12 +8,12 @@
<!-- nav end --> <!-- nav end -->
<!-- form start --> <!-- form start -->
<form class="am-form form-validation view-save m-t-10" action="{{:MyUrl('admin/plugins/upload')}}" method="POST" request-type="ajax-url" request-value="{{:MyUrl('admin/plugins/index')}}" enctype="multipart/form-data"> <form class="am-form form-validation view-save m-t-10" action="{{:MyUrl('admin/pluginsadmin/upload')}}" method="POST" request-type="ajax-url" request-value="{{:MyUrl('admin/pluginsadmin/index')}}" enctype="multipart/form-data">
<div class="am-form-group am-form-file"> <div class="am-form-group am-form-file">
<button type="button" class="am-btn am-btn-default am-btn-sm am-radius"> <button type="button" class="am-btn am-btn-default am-btn-sm am-radius">
<i class="am-icon-cloud-upload"></i> 选择文件</button> <i class="am-icon-cloud-upload"></i> 选择文件</button>
<input type="file" name="file" class="file-event" data-tips-tag="#form-file-tips" multiple data-validation-message="请选择需要上传的文件" required /> <input type="file" name="file" class="file-event" data-tips-tag="#form-file-tips" multiple data-validation-message="请选择需要上传的文件" required />
<span class="tips fs-12">上传一个zip压缩格式的主题安装包</span> <span class="tips fs-12">上传一个zip压缩格式的应用安装包</span>
<div id="form-file-tips"></div> <div id="form-file-tips"></div>
</div> </div>
<div class="am-form-group"> <div class="am-form-group">

View File

@ -1,6 +1,6 @@
{ {
"name":"默认模板", "name":"默认模板",
"ver":"1.2.0", "ver":"1.3.0",
"author":"魔鬼", "author":"Devil",
"home":"http://gong.gg/" "home":"http://shopxo.net/"
} }

View File

@ -1,24 +0,0 @@
<?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);
}
}
?>

View File

@ -1,27 +0,0 @@
<?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!';
}
}
}
?>

View File

@ -1,24 +0,0 @@
<?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);
}
}
?>

View File

@ -1,21 +0,0 @@
{
"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":[
]
}

View File

@ -1,15 +0,0 @@
{{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 -->

View File

@ -1,31 +0,0 @@
{{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 -->

View File

@ -298,16 +298,30 @@ class PluginsAdminService
return DataReturn('应用不存在', -10); return DataReturn('应用不存在', -10);
} }
// 开启事务
Db::startTrans();
// 删除操作 // 删除操作
if(Db::name('Plugins')->where($where)->delete()) if(Db::name('Plugins')->where($where)->delete())
{ {
// 删除应用文件 // 钩子部署
self::PluginsResourcesDelete($plugins); $ret = self::PluginsHookDeployment();
if($ret['code'] == 0)
{
// 删除应用文件
self::PluginsResourcesDelete($plugins);
return DataReturn('删除成功'); // 提交事务
Db::commit();
return DataReturn('删除成功');
}
} else {
$ret = DataReturn('删除失败或资源不存在', -100);
} }
return DataReturn('删除失败或资源不存在', -100); // 事务回退
Db::rollback();
return $ret;
} }
/** /**
@ -725,7 +739,7 @@ php;
], ],
// 钩子配置 // 钩子配置
'hook' => [], 'hook' => (object) [],
]; ];
// 创建配置文件 // 创建配置文件
@ -842,6 +856,21 @@ php;
return $ret; return $ret;
} }
// 资源目录
$dir_list = [
'_controller_' => APP_PATH.'plugins'.DS,
'_view_' => APP_PATH.'plugins'.DS.'view'.DS,
'_css_' => ROOT.'public'.DS.'static'.DS.'plugins'.DS.'css'.DS,
'_js_' => ROOT.'public'.DS.'static'.DS.'plugins'.DS.'js'.DS,
'_images_' => ROOT.'public'.DS.'static'.DS.'plugins'.DS.'images'.DS,
'_uploadfile_' => ROOT.'public'.DS.'static'.DS.'upload'.DS.'file'.DS,
'_uploadimages_' => ROOT.'public'.DS.'static'.DS.'upload'.DS.'images'.DS,
'_uploadvideo_' => ROOT.'public'.DS.'static'.DS.'upload'.DS.'video'.DS,
];
// 包名
$plugins_name = '';
// 开始解压文件 // 开始解压文件
$resource = zip_open($_FILES['file']['tmp_name']); $resource = zip_open($_FILES['file']['tmp_name']);
while(($temp_resource = zip_read($resource)) !== false) while(($temp_resource = zip_read($resource)) !== false)
@ -851,29 +880,40 @@ php;
// 当前压缩包中项目名称 // 当前压缩包中项目名称
$file = zip_entry_name($temp_resource); $file = zip_entry_name($temp_resource);
// 获取包名
if(empty($plugins_name))
{
// 应用不存在则添加
$plugins_name = substr($file, 0, strpos($file, '/'));
$ret = self::PluginsExistInsert([], $plugins_name);
if($ret['code'] != 0)
{
zip_entry_close($temp_resource);
return $ret;
}
}
// 去除包名
$file = substr($file, strpos($file, '/')+1);
// 排除临时文件和临时目录 // 排除临时文件和临时目录
if(strpos($file, '/.') === false && strpos($file, '__') === false) if(strpos($file, '/.') === false && strpos($file, '__') === false)
{ {
// 拼接路径 // 文件包对应系统所在目录
if(strpos($file, '_controller') !== false) foreach($dir_list as $dir_key=>$dir_value)
{ {
$file = ROOT.self::$html_path.$file; if(strpos($file, $dir_key) !== false)
} else if(strpos($file, '_static') !== false) {
{ $file = str_replace($dir_key.'/', '', $dir_value.$file);
$file = ROOT.self::$static_path.$file; break;
} else { }
continue;
} }
$file = str_replace(array('_static/', '_html/'), '', $file);
// 截取文件路径 // 截取文件路径
$file_path = substr($file, 0, strrpos($file, '/')); $file_path = substr($file, 0, strrpos($file, '/'));
// 路径不存在则创建 // 路径不存在则创建
if(!is_dir($file_path)) \base\FileUtil::CreateDir($file_path);
{
mkdir($file_path, 0777, true);
}
// 如果不是目录则写入文件 // 如果不是目录则写入文件
if(!is_dir($file)) if(!is_dir($file))
@ -881,14 +921,15 @@ php;
// 读取这个文件 // 读取这个文件
$file_size = zip_entry_filesize($temp_resource); $file_size = zip_entry_filesize($temp_resource);
$file_content = zip_entry_read($temp_resource, $file_size); $file_content = zip_entry_read($temp_resource, $file_size);
file_put_contents($file, $file_content); @file_put_contents($file, $file_content);
} }
// 关闭目录项 // 关闭目录项
zip_entry_close($temp_resource); zip_entry_close($temp_resource);
} }
} }
} }
return DataReturn('操作成功'); return DataReturn('安装成功');
} }
} }
?> ?>

View File

@ -116,6 +116,12 @@ class ThemeService
return DataReturn('资源目录没权限', -10); return DataReturn('资源目录没权限', -10);
} }
// 资源目录
$dir_list = [
'_html_' => ROOT.self::$html_path,
'_static_' => ROOT.self::$static_path,
];
// 开始解压文件 // 开始解压文件
$resource = zip_open($_FILES['theme']['tmp_name']); $resource = zip_open($_FILES['theme']['tmp_name']);
while(($temp_resource = zip_read($resource)) !== false) while(($temp_resource = zip_read($resource)) !== false)
@ -128,17 +134,15 @@ class ThemeService
// 排除临时文件和临时目录 // 排除临时文件和临时目录
if(strpos($file, '/.') === false && strpos($file, '__') === false) if(strpos($file, '/.') === false && strpos($file, '__') === false)
{ {
// 拼接路径 // 文件包对应系统所在目录
if(strpos($file, '_html') !== false) foreach($dir_list as $dir_key=>$dir_value)
{ {
$file = ROOT.self::$html_path.$file; if(strpos($file, $dir_key) !== false)
} else if(strpos($file, '_static') !== false) {
{ $file = str_replace($dir_key.'/', '', $dir_value.$file);
$file = ROOT.self::$static_path.$file; break;
} else { }
continue;
} }
$file = str_replace(array('_static/', '_html/'), '', $file);
// 截取文件路径 // 截取文件路径
$file_path = substr($file, 0, strrpos($file, '/')); $file_path = substr($file, 0, strrpos($file, '/'));
@ -157,12 +161,13 @@ class ThemeService
$file_content = zip_entry_read($temp_resource, $file_size); $file_content = zip_entry_read($temp_resource, $file_size);
file_put_contents($file, $file_content); file_put_contents($file, $file_content);
} }
// 关闭目录项 // 关闭目录项
zip_entry_close($temp_resource); zip_entry_close($temp_resource);
} }
} }
} }
return DataReturn('操作成功'); return DataReturn('安装成功');
} }
/** /**

File diff suppressed because one or more lines are too long

View File

@ -1,7 +0,0 @@
h1 {
font-size: 60px;
}
.msg {
font-size: 38px;
color: #F00;
}

View File

@ -1,7 +0,0 @@
h1 {
font-size: 60px;
}
.msg {
font-size: 68px;
color: #4CAF50;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.9 KiB