ThemeController.php
4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace api\home\controller;
use api\home\model\ThemeFileModel;
use cmf\controller\RestBaseController;
class ThemeController extends RestBaseController
{
/**
* 获取模板扩展属性
*/
public function more()
{
$theme = $this->request->param('theme');
$themeFileModel = new ThemeFileModel();
$file = $this->request->param('file');
$file = $themeFileModel->where('theme', $theme)->where('file', $file)->find();
$vars = [];
$widgets = [];
$oldMore = $file['more'];
if (!empty($oldMore['vars'])) {
foreach ($oldMore['vars'] as $varName => $var) {
switch ($var['type']) {
case 'image':
$vars[$varName] = cmf_get_image_url($var['value']);
break;
case 'file':
$vars[$varName] = cmf_get_file_download_url($var['value']);
break;
case 'array':
foreach ($var['value'] as $varKey => $varValue) {
foreach ($varValue as $varValueKey => $varValueValue) {
switch ($var['item'][$varValueKey]['type']) {
case 'image':
$var['value'][$varKey][$varValueKey] = cmf_get_image_url($varValueValue);
break;
case 'file':
$var['value'][$varKey][$varValueKey] = cmf_get_file_download_url($varValueValue);
break;
default:
$var['value'][$varKey][$varValueKey] = $varValueValue;
}
}
}
$vars[$varName] = $var['value'];
break;
default:
$vars[$varName] = $var['value'];
}
}
}
if (!empty($oldMore['widgets'])) {
foreach ($oldMore['widgets'] as $widgetName => $widget) {
$widgetVars = [];
if (!empty($widget['vars'])) {
foreach ($widget['vars'] as $varName => $var) {
switch ($var['type']) {
case 'image':
$widgetVars[$varName] = cmf_get_image_url($var['value']);
break;
case 'file':
$widgetVars[$varName] = cmf_get_file_download_url($var['value']);
break;
case 'array':
foreach ($var['value'] as $varKey => $varValue) {
foreach ($varValue as $varValueKey => $varValueValue) {
switch ($var['item'][$varValueKey]['type']) {
case 'image':
$var['value'][$varKey][$varValueKey] = cmf_get_image_url($varValueValue);
break;
case 'file':
$var['value'][$varKey][$varValueKey] = cmf_get_file_download_url($varValueValue);
break;
default:
$var['value'][$varKey][$varValueKey] = $varValueValue;
}
}
}
$widgetVars[$varName]=$var['value'];
break;
default:
$widgetVars[$varName] = $var['value'];
}
}
}
$widget['vars'] = $widgetVars;
$widgets[$widgetName] = $widget;
}
}
$this->success('success', [
'vars' => $vars,
'widgets' => $widgets
]);
}
}