|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* WebHemi. |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 7.1 |
|
6
|
|
|
* |
|
7
|
|
|
* @copyright 2012 - 2017 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 RuntimeException; |
|
17
|
|
|
use WebHemi\Configuration\ServiceInterface as ConfigurationInterface; |
|
18
|
|
|
use WebHemi\Environment\ServiceInterface as EnvironmentInterface; |
|
19
|
|
|
use WebHemi\Middleware\Action\AbstractMiddlewareAction; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Class IndexAction |
|
23
|
|
|
*/ |
|
24
|
|
|
class IndexAction extends AbstractMiddlewareAction |
|
25
|
|
|
{ |
|
26
|
|
|
/** @var ConfigurationInterface */ |
|
27
|
|
|
private $configuration; |
|
28
|
|
|
/** @var EnvironmentInterface */ |
|
29
|
|
|
private $environment; |
|
30
|
|
|
/** @var array */ |
|
31
|
|
|
private $defaultData = [ |
|
32
|
|
|
'name' => null, |
|
33
|
|
|
'title' => null, |
|
34
|
|
|
'description' => '', |
|
35
|
|
|
'version' => '', |
|
36
|
|
|
'author' => 'Unknown', |
|
37
|
|
|
'homepage' => '', |
|
38
|
|
|
'license' => '', |
|
39
|
|
|
'read_only' => false, |
|
40
|
|
|
'feature_website' => false, |
|
41
|
|
|
'feature_login' => false, |
|
42
|
|
|
'feature_admin' => false, |
|
43
|
|
|
'logo' => '', |
|
44
|
|
|
'preview' => '', |
|
45
|
|
|
]; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* IndexAction constructor. |
|
49
|
|
|
* |
|
50
|
|
|
* @param ConfigurationInterface $configuration |
|
51
|
|
|
* @param EnvironmentInterface $environment |
|
52
|
|
|
*/ |
|
53
|
|
|
public function __construct(ConfigurationInterface $configuration, EnvironmentInterface $environment) |
|
54
|
|
|
{ |
|
55
|
|
|
$this->configuration = $configuration; |
|
56
|
|
|
$this->environment = $environment; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Gets template map name or template file path. |
|
61
|
|
|
* |
|
62
|
|
|
* @return string |
|
63
|
|
|
*/ |
|
64
|
|
|
public function getTemplateName() : string |
|
65
|
|
|
{ |
|
66
|
|
|
return 'admin-control-panel-themes-list'; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Gets template data. |
|
71
|
|
|
* |
|
72
|
|
|
* @return array |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getTemplateData() : array |
|
75
|
|
|
{ |
|
76
|
|
|
$themes = $usedThemes = []; |
|
77
|
|
|
|
|
78
|
|
|
foreach ($this->configuration->getData('applications') as $application) { |
|
79
|
|
|
$usedThemes[$application['theme']] = $application['theme']; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
// Make the default theme read-only. |
|
83
|
|
|
$usedThemes['default'] = 'default'; |
|
84
|
|
|
|
|
85
|
|
|
foreach ($this->configuration->getData('themes') as $themeName => $themeData) { |
|
86
|
|
|
$themeStaticPath = '/resources/'. |
|
87
|
|
|
($themeName == 'default' ? 'default_theme' : 'vendor_themes/'.$themeName) |
|
88
|
|
|
. '/static/'; |
|
89
|
|
|
|
|
90
|
|
|
$themes[$themeName] = $this->defaultData; |
|
91
|
|
|
$themes[$themeName]['name'] = $themes[$themeName]['title'] = $themeName; |
|
92
|
|
|
$themes[$themeName]['read_only'] = isset($usedThemes[$themeName]); |
|
93
|
|
|
$themes[$themeName]['feature_website'] = (bool) ($themeData['features']['website_support'] ?? false); |
|
94
|
|
|
$themes[$themeName]['feature_login'] = (bool) ($themeData['features']['admin__login_support'] ?? false); |
|
95
|
|
|
$themes[$themeName]['feature_admin'] = (bool) ($themeData['features']['admin_support'] ?? false); |
|
96
|
|
|
|
|
97
|
|
|
foreach ($themeData['legal'] as $name => $value) { |
|
98
|
|
|
if (in_array($name, ['logo', 'preview'])) { |
|
99
|
|
|
$value = $themeStaticPath.$value; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
$themes[$themeName][$name] = $value; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
ksort($themes); |
|
107
|
|
|
|
|
108
|
|
|
return [ |
|
109
|
|
|
'themes' => $themes, |
|
110
|
|
|
'progressId' => 'test' |
|
111
|
|
|
]; |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|