Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wds12580
ShopXO
提交
4bb31814
ShopXO
项目概览
wds12580
/
ShopXO
与 Fork 源项目一致
Fork自
纵之格 / ShopXO
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
ShopXO
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4bb31814
编写于
12月 19, 2018
作者:
G
gongfuxiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
主题
上级
282549cf
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
220 addition
and
174 deletion
+220
-174
application/admin/controller/Theme.php
application/admin/controller/Theme.php
+26
-169
application/admin/view/default/theme/index.html
application/admin/view/default/theme/index.html
+3
-1
application/admin/view/default/theme/upload.html
application/admin/view/default/theme/upload.html
+3
-3
application/index/view/default/config.json
application/index/view/default/config.json
+1
-1
application/service/ThemeService.php
application/service/ThemeService.php
+187
-0
未找到文件。
application/admin/controller/Theme.php
浏览文件 @
4bb31814
<?php
namespace
app\admin\controller
;
use
app\service\ThemeService
;
use
app\service\ConfigService
;
/**
* 主题管理
* @author Devil
...
...
@@ -10,9 +13,6 @@ namespace app\admin\controller;
*/
class
Theme
extends
Common
{
private
$html_path
;
private
$static_path
;
/**
* 构造方法
* @author Devil
...
...
@@ -31,10 +31,6 @@ class Theme extends Common
// 权限校验
$this
->
Is_Power
();
// 静态目录和html目录
$this
->
html_path
=
'application'
.
DS
.
'index'
.
DS
.
'view'
.
DS
;
$this
->
static_path
=
'public'
.
DS
.
'static'
.
DS
.
'index'
.
DS
;
// 小导航
$this
->
view_type
=
input
(
'view_type'
,
'home'
);
}
...
...
@@ -48,95 +44,33 @@ class Theme extends Common
*/
public
function
Index
()
{
// 模板列表
$this
->
assign
(
'data_list'
,
$this
->
GetThemeList
());
// 默认主题
$theme
=
cache
(
'cache_common_default_theme_data'
);
$this
->
assign
(
'theme'
,
empty
(
$theme
)
?
'Default'
:
$theme
);
// 导航参数
$this
->
assign
(
'view_type'
,
$this
->
view_type
);
return
$this
->
fetch
();
}
/**
* 模板安装
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-06T21:31:53+0800
*/
public
function
UploadInfo
()
{
// 导航参数
$this
->
assign
(
'view_type'
,
$this
->
view_type
);
return
$this
->
fetch
();
}
/**
* [GetThemeList 获取模板列表]
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-05-10T10:24:40+0800
* @return [array] [模板列表]
*/
private
function
GetThemeList
()
{
$result
=
[];
$dir
=
ROOT
.
$this
->
html_path
;
if
(
is_dir
(
$dir
))
if
(
$this
->
view_type
==
'home'
)
{
if
(
$dh
=
opendir
(
$dir
))
{
$default_preview
=
__MY_URL__
.
'static'
.
DS
.
'common'
.
DS
.
'images'
.
DS
.
'default-preview.jpg'
;
while
((
$temp_file
=
readdir
(
$dh
))
!==
false
)
{
$config
=
$dir
.
$temp_file
.
DS
.
'config.json'
;
if
(
!
file_exists
(
$config
))
{
continue
;
}
// 模板列表
$this
->
assign
(
'data_list'
,
ThemeService
::
ThemeList
());
// 读取配置文件
$data
=
json_decode
(
file_get_contents
(
$config
),
true
);
if
(
!
empty
(
$data
)
&&
is_array
(
$data
))
{
if
(
empty
(
$data
[
'name'
])
||
empty
(
$data
[
'ver'
])
||
empty
(
$data
[
'author'
]))
{
continue
;
}
$preview
=
ROOT
.
$this
->
static_path
.
$temp_file
.
DS
.
'images'
.
DS
.
'preview.jpg'
;
$result
[]
=
array
(
'theme'
=>
$temp_file
,
'name'
=>
htmlentities
(
$data
[
'name'
]),
'ver'
=>
str_replace
(
array
(
','
,
','
),
', '
,
htmlentities
(
$data
[
'ver'
])),
'author'
=>
htmlentities
(
$data
[
'author'
]),
'home'
=>
isset
(
$data
[
'home'
])
?
$data
[
'home'
]
:
''
,
'preview'
=>
file_exists
(
$preview
)
?
__MY_URL__
.
'static'
.
DS
.
'index'
.
DS
.
$temp_file
.
DS
.
'images'
.
DS
.
'preview.jpg'
:
$default_preview
,
);
}
}
closedir
(
$dh
);
}
// 默认主题
$theme
=
cache
(
'cache_common_default_theme_data'
);
$this
->
assign
(
'theme'
,
empty
(
$theme
)
?
'default'
:
$theme
);
return
$this
->
fetch
(
'index'
);
}
else
{
return
$this
->
fetch
(
'upload'
);
}
return
$result
;
}
/**
*
[Save 数据保存]
*
模板切换保存
* @author Devil
* @blog http://gong.gg/
* @version
0.0.1
* @datetime 201
7-02-05T20:12:30
+0800
* @version
1.0.0
* @datetime 201
8-12-19T00:58:47
+0800
*/
public
function
Save
()
{
// 配置更新
$this
->
MyConfigSave
();
return
ConfigService
::
ConfigSave
(
input
());
}
/**
...
...
@@ -151,33 +85,13 @@ class Theme extends Common
// 是否ajax
if
(
!
IS_AJAX
)
{
$this
->
error
(
'非法访问'
);
}
// 主题
$id
=
str_replace
(
array
(
'.'
,
'/'
,
'\\'
),
''
,
strip_tags
(
I
(
'id'
)));
if
(
empty
(
$id
))
{
$this
->
error
(
'主题名称有误'
);
}
// 默认主题
$theme
=
cache
(
'cache_common_default_theme_data'
);
$theme
=
empty
(
$theme
)
?
'Default'
:
$theme
;
// 不能删除正在使用的主题
if
(
$theme
==
$id
)
{
$this
->
ajaxReturn
(
'不能删除正在使用的主题'
,
-
2
);
return
$this
->
error
(
'非法访问'
);
}
// 开始删除主题
if
(
\
base\FileUtil
::
UnlinkDir
(
$this
->
html_path
.
$id
)
&&
\
base\FileUtil
::
UnlinkDir
(
$this
->
static_path
.
$id
))
{
$this
->
ajaxReturn
(
'删除成功'
);
}
else
{
$this
->
ajaxReturn
(
'删除失败或资源不存在'
,
-
100
);
}
// 开始处理
$params
=
input
();
$ret
=
ThemeService
::
ThemeDelete
(
$params
);
return
json
(
$ret
);
}
/**
...
...
@@ -192,70 +106,13 @@ class Theme extends Common
// 是否ajax
if
(
!
IS_AJAX
)
{
$this
->
error
(
'非法访问'
);
return
$this
->
error
(
'非法访问'
);
}
// 文件上传校验
$error
=
FileUploadError
(
'theme'
);
if
(
$error
!==
true
)
{
$this
->
ajaxReturn
(
$error
,
-
1
);
}
// 文件格式化校验
$type
=
array
(
'application/zip'
,
'application/octet-stream'
);
if
(
!
in_array
(
$_FILES
[
'theme'
][
'type'
],
$type
))
{
$this
->
ajaxReturn
(
'文件格式有误,请上传zip压缩包'
,
-
2
);
}
// 开始解压文件
$resource
=
zip_open
(
$_FILES
[
'theme'
][
'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
,
'_html'
)
!==
false
)
{
$file
=
$this
->
html_path
.
$file
;
}
else
if
(
strpos
(
$file
,
'_static'
)
!==
false
)
{
$file
=
$this
->
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
);
}
}
}
$this
->
ajaxReturn
(
'操作成功'
);
// 开始处理
$params
=
input
();
$ret
=
ThemeService
::
ThemeUpload
(
$params
);
return
json
(
$ret
);
}
}
?>
\ No newline at end of file
application/admin/view/default/theme/index.html
浏览文件 @
4bb31814
...
...
@@ -19,7 +19,9 @@
<div
class=
"am-gallery-item-bottom"
>
<h3
class=
"am-gallery-title"
>
{{$v.name}}
<a
href=
"javascript:;"
class=
"am-icon-trash-o fr submit-delete"
data-url=
"{{:url('admin/theme/delete')}}"
data-id=
"{{$v.theme}}"
></a>
{{if $v.is_delete eq 1}}
<a
href=
"javascript:;"
class=
"am-icon-trash-o fr submit-delete"
data-url=
"{{:url('admin/theme/delete')}}"
data-id=
"{{$v.theme}}"
></a>
{{/if}}
</h3>
<div
class=
"am-gallery-desc"
>
作者:
{{if empty($v['home'])}}
...
...
application/admin/view/default/theme/upload.html
浏览文件 @
4bb31814
...
...
@@ -4,16 +4,16 @@
<div
class=
"content-right"
>
<div
class=
"content"
>
<!-- nav start -->
<include
file=
"Nav"
/>
{{include file="theme/nav" /}}
<!-- nav end -->
<!-- form start -->
<form
class=
"am-form form-validation view-save m-t-10"
action=
"{{:url('
Admin/Theme/Upload')}}"
method=
"POST"
request-type=
"ajax-url"
request-value=
"{{:url('Admin/Theme/I
ndex')}}"
enctype=
"multipart/form-data"
>
<form
class=
"am-form form-validation view-save m-t-10"
action=
"{{:url('
admin/theme/upload')}}"
method=
"POST"
request-type=
"ajax-url"
request-value=
"{{:url('admin/theme/i
ndex')}}"
enctype=
"multipart/form-data"
>
<input
type=
"hidden"
name=
"max_file_size"
value=
"{{:MyC('home_max_limit_file', 51200000, true)}}"
/>
<div
class=
"am-form-group am-form-file"
>
<button
type=
"button"
class=
"am-btn am-btn-default am-btn-sm am-radius"
>
<i
class=
"am-icon-cloud-upload"
></i>
选择文件
</button>
<input
type=
"file"
name=
"theme"
class=
"file-event"
data-tips-tag=
"#form-theme-tips"
multiple
data-validation-message=
"请选择需要上传的文件"
required
/>
<span
class=
"tips fs-12
)}}
上传一个zip压缩格式的主题安装包</span>
<span
class=
"tips fs-12
"
>
上传一个zip压缩格式的主题安装包
</span>
<div
id=
"form-theme-tips"
></div>
</div>
<div
class=
"am-form-group"
>
...
...
application/index/view/default/config.json
浏览文件 @
4bb31814
{
"name"
:
"默认模板"
,
"ver"
:
"
2.3.1
"
,
"ver"
:
"
1.2.0
"
,
"author"
:
"魔鬼"
,
"home"
:
"http://gong.gg/"
}
\ No newline at end of file
application/service/ThemeService.php
0 → 100644
浏览文件 @
4bb31814
<?php
namespace
app\service
;
/**
* 主题服务层
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-01T21:51:08+0800
*/
class
ThemeService
{
// 静态目录和html目录
private
static
$html_path
=
'application'
.
DS
.
'index'
.
DS
.
'view'
.
DS
;
private
static
$static_path
=
'public'
.
DS
.
'static'
.
DS
.
'index'
.
DS
;
/**
* 获取模板列表
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-05-10T10:24:40+0800
* @param [array] $params [输入参数]
* @return [array] [模板列表]
*/
public
static
function
ThemeList
(
$params
=
[])
{
$result
=
[];
$dir
=
ROOT
.
self
::
$html_path
;
if
(
is_dir
(
$dir
))
{
if
(
$dh
=
opendir
(
$dir
))
{
$default_preview
=
__MY_URL__
.
'static'
.
DS
.
'common'
.
DS
.
'images'
.
DS
.
'default-preview.jpg'
;
while
((
$temp_file
=
readdir
(
$dh
))
!==
false
)
{
$config
=
$dir
.
$temp_file
.
DS
.
'config.json'
;
if
(
!
file_exists
(
$config
))
{
continue
;
}
// 读取配置文件
$data
=
json_decode
(
file_get_contents
(
$config
),
true
);
if
(
!
empty
(
$data
)
&&
is_array
(
$data
))
{
if
(
empty
(
$data
[
'name'
])
||
empty
(
$data
[
'ver'
])
||
empty
(
$data
[
'author'
]))
{
continue
;
}
$preview
=
ROOT
.
self
::
$static_path
.
$temp_file
.
DS
.
'images'
.
DS
.
'preview.jpg'
;
$result
[]
=
array
(
'theme'
=>
$temp_file
,
'name'
=>
htmlentities
(
$data
[
'name'
]),
'ver'
=>
str_replace
(
array
(
','
,
','
),
', '
,
htmlentities
(
$data
[
'ver'
])),
'author'
=>
htmlentities
(
$data
[
'author'
]),
'home'
=>
isset
(
$data
[
'home'
])
?
$data
[
'home'
]
:
''
,
'preview'
=>
file_exists
(
$preview
)
?
__MY_URL__
.
'static'
.
DS
.
'index'
.
DS
.
$temp_file
.
DS
.
'images'
.
DS
.
'preview.jpg'
:
$default_preview
,
'is_delete'
=>
(
$temp_file
==
'default'
)
?
0
:
1
,
);
}
}
closedir
(
$dh
);
}
}
return
$result
;
}
/**
* 模板上传
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2018-12-19T00:53:45+0800
* @param [array] $params [输入参数]
*/
public
static
function
ThemeUpload
(
$params
=
[])
{
// 文件上传校验
$error
=
FileUploadError
(
'theme'
);
if
(
$error
!==
true
)
{
return
DataReturn
(
$error
,
-
1
);
}
// 文件格式化校验
$type
=
array
(
'application/zip'
,
'application/octet-stream'
);
if
(
!
in_array
(
$_FILES
[
'theme'
][
'type'
],
$type
))
{
return
DataReturn
(
'文件格式有误,请上传zip压缩包'
,
-
2
);
}
// 开始解压文件
$resource
=
zip_open
(
$_FILES
[
'theme'
][
'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
,
'_html'
)
!==
false
)
{
$file
=
self
::
$html_path
.
$file
;
}
else
if
(
strpos
(
$file
,
'_static'
)
!==
false
)
{
$file
=
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
(
'操作成功'
);
}
/**
* 模板删除
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2018-12-19T00:46:02+0800
* @param [array] $params [输入参数]
*/
public
static
function
ThemeDelete
(
$params
=
[])
{
if
(
empty
(
$params
[
'id'
]))
{
return
DataReturn
(
'模板id有误'
,
-
1
);
}
// 主题
$id
=
str_replace
(
array
(
'.'
,
'/'
,
'\\'
),
''
,
strip_tags
(
$params
[
'id'
]));
if
(
empty
(
$id
))
{
return
DataReturn
(
'主题名称有误'
,
-
1
);
}
// default不能删除
if
(
$id
==
'default'
)
{
return
DataReturn
(
'系统模板不能删除'
,
-
2
);
}
// 默认主题
$theme
=
cache
(
'cache_common_default_theme_data'
);
$theme
=
empty
(
$theme
)
?
'default'
:
$theme
;
// 不能删除正在使用的主题
if
(
$theme
==
$id
)
{
return
DataReturn
(
'不能删除正在使用的主题'
,
-
2
);
}
// 开始删除主题
if
(
\
base\FileUtil
::
UnlinkDir
(
self
::
$html_path
.
$id
)
&&
\
base\FileUtil
::
UnlinkDir
(
self
::
$static_path
.
$id
))
{
return
DataReturn
(
'删除成功'
);
}
return
DataReturn
(
'删除失败或资源不存在'
,
-
100
);
}
}
?>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录