1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* WebHemi. |
4
|
|
|
* |
5
|
|
|
* PHP version 7.2 |
6
|
|
|
* |
7
|
|
|
* @copyright 2012 - 2019 Gixx-web (http://www.gixx-web.com) |
8
|
|
|
* @license https://opensource.org/licenses/MIT The MIT License (MIT) |
9
|
|
|
* |
10
|
|
|
* @link http://www.gixx-web.com |
11
|
|
|
*/ |
12
|
|
|
declare(strict_types = 1); |
13
|
|
|
|
14
|
|
|
namespace WebHemi\Middleware\Action\Admin\ControlPanel\Themes; |
15
|
|
|
|
16
|
|
|
use WebHemi\Configuration\ServiceInterface as ConfigurationInterface; |
17
|
|
|
use WebHemi\Environment\ServiceInterface as EnvironmentInterface; |
18
|
|
|
use WebHemi\Middleware\Action\AbstractMiddlewareAction; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class ListAction |
22
|
|
|
*/ |
23
|
|
|
class ListAction extends AbstractMiddlewareAction |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var ConfigurationInterface |
27
|
|
|
*/ |
28
|
|
|
private $configuration; |
29
|
|
|
/** |
30
|
|
|
* @var EnvironmentInterface |
31
|
|
|
*/ |
32
|
|
|
private $environment; |
33
|
|
|
/** |
34
|
|
|
* @var array |
35
|
|
|
*/ |
36
|
|
|
private $defaultData = [ |
37
|
|
|
'name' => null, |
38
|
|
|
'title' => null, |
39
|
|
|
'description' => '', |
40
|
|
|
'version' => '', |
41
|
|
|
'author' => 'Unknown', |
42
|
|
|
'homepage' => '', |
43
|
|
|
'license' => '', |
44
|
|
|
'read_only' => false, |
45
|
|
|
'feature_website' => false, |
46
|
|
|
'feature_login' => false, |
47
|
|
|
'feature_admin' => false, |
48
|
|
|
'logo' => '', |
49
|
|
|
'preview' => '', |
50
|
|
|
]; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* IndexAction constructor. |
54
|
|
|
* |
55
|
|
|
* @param ConfigurationInterface $configuration |
56
|
|
|
* @param EnvironmentInterface $environment |
57
|
|
|
*/ |
58
|
|
|
public function __construct(ConfigurationInterface $configuration, EnvironmentInterface $environment) |
59
|
|
|
{ |
60
|
|
|
$this->configuration = $configuration; |
61
|
|
|
$this->environment = $environment; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Gets template map name or template file path. |
66
|
|
|
* |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
public function getTemplateName() : string |
70
|
|
|
{ |
71
|
|
|
return 'admin-control-panel-themes-list'; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Gets template data. |
76
|
|
|
* |
77
|
|
|
* @return array |
78
|
|
|
*/ |
79
|
|
|
public function getTemplateData() : array |
80
|
|
|
{ |
81
|
|
|
// TODO create Data Storage and Entity for the Themes, maybe store in Database too |
82
|
|
|
$themes = $usedThemes = []; |
83
|
|
|
|
84
|
|
|
foreach ($this->configuration->getData('applications') as $application) { |
85
|
|
|
$usedThemes[$application['theme']] = $application['theme']; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
// Make the default theme read-only. |
89
|
|
|
$usedThemes['default'] = 'default'; |
90
|
|
|
|
91
|
|
|
foreach ($this->configuration->getData('themes') as $themeName => $themeData) { |
92
|
|
|
$themeStaticPath = '/resources/'. |
93
|
|
|
($themeName == 'default' ? 'default_theme' : 'vendor_themes/'.$themeName) |
94
|
|
|
. '/static/'; |
95
|
|
|
|
96
|
|
|
$themes[$themeName] = $this->defaultData; |
97
|
|
|
$themes[$themeName]['name'] = $themes[$themeName]['title'] = $themeName; |
98
|
|
|
$themes[$themeName]['read_only'] = isset($usedThemes[$themeName]); |
99
|
|
|
$themes[$themeName]['feature_website'] = (bool) ($themeData['features']['website_support'] ?? false); |
100
|
|
|
$themes[$themeName]['feature_login'] = (bool) ($themeData['features']['admin_login_support'] ?? false); |
101
|
|
|
$themes[$themeName]['feature_admin'] = (bool) ($themeData['features']['admin_support'] ?? false); |
102
|
|
|
|
103
|
|
|
foreach ($themeData['legal'] as $name => $value) { |
104
|
|
|
if (in_array($name, ['logo', 'preview'])) { |
105
|
|
|
$value = $themeStaticPath.$value; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
$themes[$themeName][$name] = $value; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
ksort($themes); |
113
|
|
|
|
114
|
|
|
return [ |
115
|
|
|
'data' => $themes, |
116
|
|
|
'progressId' => 'test' |
117
|
|
|
]; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|