|
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
|
|
|
|
|
10
|
|
|
class FormSettings extends Model |
|
11
|
|
|
{ |
|
12
|
|
|
|
|
13
|
|
|
public $basePath; |
|
14
|
|
|
public $passwordSalt; |
|
15
|
|
|
|
|
16
|
|
|
public $debug; |
|
17
|
|
|
public $theme; |
|
18
|
|
|
public $database; |
|
19
|
|
|
public $adminEmail; |
|
20
|
|
|
|
|
21
|
|
|
// lang cfgs |
|
22
|
|
|
public $baseLanguage = 'en'; |
|
23
|
|
|
public $multiLanguage; |
|
24
|
|
|
public $singleLanguage; |
|
25
|
|
|
public $languages; |
|
26
|
|
|
|
|
27
|
|
|
public $languageDomainAlias; |
|
28
|
|
|
|
|
29
|
|
|
// google analytics settings |
|
30
|
|
|
public $gaClientId; |
|
31
|
|
|
public $gaTrackId; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Set property values from configurations |
|
35
|
|
|
*/ |
|
36
|
|
|
public function before() |
|
37
|
|
|
{ |
|
38
|
|
|
// set default values |
|
39
|
|
|
foreach (App::$Properties->getAll() as $key => $value) { |
|
|
|
|
|
|
40
|
|
|
$this->{$key} = $value; |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Set translation helpers |
|
46
|
|
|
*/ |
|
47
|
|
|
public function labels() |
|
48
|
|
|
{ |
|
49
|
|
|
return [ |
|
50
|
|
|
'basePath' => __('Base path'), |
|
51
|
|
|
'debug.all' => __('Debug for all'), |
|
52
|
|
|
'singleLanguage' => __('Default language'), |
|
53
|
|
|
'languages' => __('Available languages'), |
|
54
|
|
|
'multiLanguage' => __('Multi-languages'), |
|
55
|
|
|
'theme.Front' => __('User theme'), |
|
56
|
|
|
'theme.Admin' => __('Admin theme'), |
|
57
|
|
|
'database.driver' => __('Database driver'), |
|
58
|
|
|
'database.host' => __('Database host'), |
|
59
|
|
|
'database.database' => __('Database name'), |
|
60
|
|
|
'database.username' => __('Database user'), |
|
61
|
|
|
'database.password' => __('Database user pass'), |
|
62
|
|
|
'database.charset' => __('Charset'), |
|
63
|
|
|
'database.collation' => __('Collation'), |
|
64
|
|
|
'database.prefix' => __('Tables prefix'), |
|
65
|
|
|
'debug.cookie.key' => __('Debug cookie key'), |
|
66
|
|
|
'debug.cookie.value' => __('Debug cookie value'), |
|
67
|
|
|
'gaClientId' => __('GA Client ID'), |
|
68
|
|
|
'gaTrackId' => __('GA Track ID') |
|
69
|
|
|
]; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Validation rules for configuration saving |
|
74
|
|
|
*/ |
|
75
|
|
|
public function rules() |
|
76
|
|
|
{ |
|
77
|
|
|
return [ |
|
78
|
|
|
[['debug.all', 'multiLanguage', 'gaClientId', 'gaTrackId'], 'used'], |
|
79
|
|
|
[['basePath', 'singleLanguage', 'adminEmail'], 'required'], |
|
80
|
|
|
[['debug.cookie.key', 'debug.cookie.value'], 'required'], |
|
81
|
|
|
[['theme.Front', 'theme.Admin'], 'required'], |
|
82
|
|
|
[['database.driver', 'database.database'], 'required'], |
|
83
|
|
|
['adminEmail', 'email'] |
|
84
|
|
|
]; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Get available themes for environment |
|
89
|
|
|
* @param $env_name |
|
90
|
|
|
* @return array |
|
91
|
|
|
*/ |
|
92
|
|
|
public function getAvailableThemes($env_name) |
|
93
|
|
|
{ |
|
94
|
|
|
$path = root . '/Apps/View/' . $env_name . '/'; |
|
95
|
|
|
if (!Directory::exist($path)) { |
|
96
|
|
|
return []; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
$scan = Directory::scan($path); |
|
100
|
|
|
$response = []; |
|
101
|
|
|
|
|
102
|
|
|
foreach ($scan as $object) { |
|
|
|
|
|
|
103
|
|
|
$response[] = substr(strrchr($object, '/'), 1); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
return $response; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Save model properties as configurations |
|
111
|
|
|
*/ |
|
112
|
|
|
public function makeSave() |
|
113
|
|
|
{ |
|
114
|
|
|
$toSave = App::$Security->strip_php_tags($this->getAllProperties()); |
|
|
|
|
|
|
115
|
|
|
$stringSave = '<?php return ' . App::$Security->var_export54($toSave, null, true) . ';'; |
|
|
|
|
|
|
116
|
|
|
|
|
117
|
|
|
$cfgPath = '/Private/Config/Default.php'; |
|
118
|
|
|
if (File::exist($cfgPath) && File::writable($cfgPath)) { |
|
119
|
|
|
File::write($cfgPath, $stringSave); |
|
120
|
|
|
return true; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
return false; |
|
124
|
|
|
} |
|
125
|
|
|
} |
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.