1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Apps\Model\Admin\Main; |
4
|
|
|
|
5
|
|
|
use Ffcms\Core\App; |
6
|
|
|
use Ffcms\Core\Arch\Model; |
7
|
|
|
use Ffcms\Core\Helper\FileSystem\Directory; |
8
|
|
|
use Ffcms\Core\Helper\FileSystem\File; |
9
|
|
|
use Ffcms\Core\Helper\Type\Arr; |
10
|
|
|
use Ffcms\Core\Helper\Type\Obj; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class FormSettings. Admin settings business logic |
14
|
|
|
* @package Apps\Model\Admin\Main |
15
|
|
|
*/ |
16
|
|
|
class FormSettings extends Model |
17
|
|
|
{ |
18
|
|
|
// base cfg |
19
|
|
|
public $baseProto; |
20
|
|
|
public $baseDomain; |
21
|
|
|
public $basePath; |
22
|
|
|
public $passwordSalt; |
23
|
|
|
public $timezone; |
24
|
|
|
public $adminEmail; |
25
|
|
|
public $debug; |
26
|
|
|
public $userCron; |
27
|
|
|
|
28
|
|
|
// theme & database configs |
29
|
|
|
public $theme; |
30
|
|
|
public $database; |
31
|
|
|
|
32
|
|
|
// lang cfgs |
33
|
|
|
public $baseLanguage = 'en'; |
34
|
|
|
public $multiLanguage; |
35
|
|
|
public $singleLanguage; |
36
|
|
|
public $languages; |
37
|
|
|
|
38
|
|
|
public $languageDomainAlias; |
39
|
|
|
|
40
|
|
|
// google analytics settings |
41
|
|
|
public $gaClientId; |
42
|
|
|
public $gaTrackId; |
43
|
|
|
|
44
|
|
|
// other |
45
|
|
|
public $trustedProxy; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Set property values from configurations |
49
|
|
|
*/ |
50
|
|
|
public function before() |
51
|
|
|
{ |
52
|
|
|
$properties = App::$Properties->getAll(); |
53
|
|
|
if ($properties === false || !Obj::isArray($properties)) { |
54
|
|
|
return; |
55
|
|
|
} |
56
|
|
|
// set default values |
57
|
|
|
foreach (App::$Properties->getAll() as $key => $value) { |
|
|
|
|
58
|
|
|
if (property_exists($this, $key)) { |
59
|
|
|
$this->{$key} = $value; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Set form display labels |
66
|
|
|
* @return array |
67
|
|
|
*/ |
68
|
|
|
public function labels() |
69
|
|
|
{ |
70
|
|
|
return [ |
71
|
|
|
'baseDomain' => __('Base domain'), |
72
|
|
|
'baseProto' => __('Base protocol'), |
73
|
|
|
'basePath' => __('Base path'), |
74
|
|
|
'adminEmail' => __('Admin email'), |
75
|
|
|
'timezone' => __('Timezone'), |
76
|
|
|
'userCron' => __('User run cron'), |
77
|
|
|
'debug.all' => __('Debug for all'), |
78
|
|
|
'singleLanguage' => __('Default language'), |
79
|
|
|
'languages' => __('Available languages'), |
80
|
|
|
'multiLanguage' => __('Multi-languages'), |
81
|
|
|
'theme.Front' => __('User theme'), |
82
|
|
|
'theme.Admin' => __('Admin theme'), |
83
|
|
|
'database.driver' => __('Database driver'), |
84
|
|
|
'database.host' => __('Database host'), |
85
|
|
|
'database.database' => __('Database name'), |
86
|
|
|
'database.username' => __('Database user'), |
87
|
|
|
'database.password' => __('Database user pass'), |
88
|
|
|
'database.charset' => __('Charset'), |
89
|
|
|
'database.collation' => __('Collation'), |
90
|
|
|
'database.prefix' => __('Tables prefix'), |
91
|
|
|
'debug.cookie.key' => __('Debug cookie key'), |
92
|
|
|
'debug.cookie.value' => __('Debug cookie value'), |
93
|
|
|
'gaClientId' => __('GA Client ID'), |
94
|
|
|
'gaTrackId' => __('GA Track ID'), |
95
|
|
|
'trustedProxy' => __('Proxy list'), |
96
|
|
|
]; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Config validation rules |
101
|
|
|
* @return array |
102
|
|
|
*/ |
103
|
|
|
public function rules() |
104
|
|
|
{ |
105
|
|
|
return [ |
106
|
|
|
[['debug.all', 'multiLanguage', 'gaClientId', 'gaTrackId', 'trustedProxy', 'languages', 'userCron'], 'used'], |
107
|
|
|
[['baseProto', 'baseDomain', 'basePath', 'singleLanguage', 'adminEmail', 'timezone'], 'required'], |
108
|
|
|
[['debug.cookie.key', 'debug.cookie.value'], 'required'], |
109
|
|
|
[['theme.Front', 'theme.Admin'], 'required'], |
110
|
|
|
[['database.driver', 'database.database'], 'required'], |
111
|
|
|
['adminEmail', 'email'], |
112
|
|
|
['timezone', 'string'], |
113
|
|
|
['baseProto', 'in', ['http', 'https']], |
114
|
|
|
['userCron', 'in', ['0', '1']] |
115
|
|
|
]; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Get available themes for environment |
120
|
|
|
* @param $env_name |
121
|
|
|
* @return array |
122
|
|
|
*/ |
123
|
|
|
public function getAvailableThemes($env_name) |
124
|
|
|
{ |
125
|
|
|
$path = root . '/Apps/View/' . $env_name . '/'; |
126
|
|
|
if (!Directory::exist($path)) { |
127
|
|
|
return []; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
$scan = Directory::scan($path); |
131
|
|
|
$response = []; |
132
|
|
|
|
133
|
|
|
foreach ($scan as $object) { |
|
|
|
|
134
|
|
|
$response[] = substr(strrchr($object, '/'), 1); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
return $response; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Save model properties as configurations |
142
|
|
|
*/ |
143
|
|
|
public function makeSave() |
144
|
|
|
{ |
145
|
|
|
$toSave = App::$Security->strip_php_tags($this->getAllProperties()); |
|
|
|
|
146
|
|
|
$stringSave = '<?php return ' . Arr::exportVar($toSave, null, true) . ';'; |
147
|
|
|
|
148
|
|
|
$cfgPath = '/Private/Config/Default.php'; |
149
|
|
|
if (File::exist($cfgPath) && File::writable($cfgPath)) { |
150
|
|
|
File::write($cfgPath, $stringSave); |
151
|
|
|
return true; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
return false; |
155
|
|
|
} |
156
|
|
|
} |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.