forked from thelia/thelia
/
ConfigQuery.php
298 lines (240 loc) · 6.99 KB
/
ConfigQuery.php
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<?php
namespace Thelia\Model;
use Thelia\Model\Base\ConfigQuery as BaseConfigQuery;
/**
* Skeleton subclass for performing query and update operations on the 'config' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class ConfigQuery extends BaseConfigQuery
{
protected static $cache = array();
/**
*
* Find a config variable and return the value or default value if not founded.
*
* Use this method for better performance, a cache is created for each variable already searched
*
* @param $search
* @param null $default
* @return mixed
*/
public static function read($search, $default = null)
{
if (array_key_exists($search, self::$cache)) {
return self::$cache[$search];
}
$value = self::create()->findOneByName($search);
self::$cache[$search] = $value ? $value->getValue() : $default;
return self::$cache[$search];
}
public static function write($configName, $value, $secured = null, $hidden = null)
{
$config = self::create()->findOneByName($configName);
if (null == $config) {
$config = new Config();
$config->setName($configName);
}
if ($secured !== null) {
$config->setSecured($secured ? 1 : 0);
}
if ($hidden !== null) {
$config->setHidden($hidden ? 1 : 0);
}
$config->setValue($value);
$config->save();
self::$cache[$configName] = $value;
}
public static function resetCache($key = null)
{
if ($key) {
if (array_key_exists($key, self::$cache)) {
unset(self::$cache[$key]);
return true;
}
}
self::$cache = array();
return true;
}
public static function getConfiguredShopUrl()
{
return ConfigQuery::read("url_site", '');
}
public static function getDefaultLangWhenNoTranslationAvailable()
{
return ConfigQuery::read("default_lang_without_translation", 1);
}
public static function isRewritingEnable()
{
return self::read("rewriting_enable") == 1;
}
public static function getPageNotFoundView()
{
return self::read("page_not_found_view", '404.html');
}
public static function getObsoleteRewrittenUrlView()
{
return self::read('obsolete_rewriten_url_view', 'obsolete-rewritten-url');
}
public static function useTaxFreeAmounts()
{
return self::read('use_tax_free_amounts', 'default') == 1;
}
public static function checkAvailableStock()
{
return self::read('check-available-stock', 1) != 0;
}
public static function getUnknownFlagPath()
{
return self::read('unknown-flag-path', '/assets/img/flags/unknown.png');
}
public static function getStoreEmail()
{
return self::read('store_email', null);
}
public static function getStoreName()
{
return self::read('store_name', '');
}
public static function getStoreDescription()
{
return self::read('store_description', '');
}
/**
* @return array a list of email addresses to send the shop's notifications
*/
public static function getNotificationEmailsList()
{
$contactEmail = self::getStoreEmail();
$list = preg_split("/[,;]/", self::read('store_notification_emails', $contactEmail));
$arr = [];
foreach ($list as $item) {
$arr[] = trim($item);
}
return $arr;
}
/* smtp config */
public static function isSmtpEnable()
{
return self::read('smtp.enabled') == 1;
}
public static function getSmtpHost()
{
return self::read('smtp.host', 'localhost');
}
public static function getSmtpPort()
{
return self::read('smtp.port');
}
public static function getSmtpEncryption()
{
return self::read('smtp.encryption');
}
public static function getSmtpUsername()
{
return self::read('smtp.username');
}
public static function getSmtpPassword()
{
return self::read('smtp.password');
}
public static function getSmtpAuthMode()
{
return self::read('smtp.authmode');
}
public static function getSmtpTimeout()
{
return self::read('smtp.timeout', 30);
}
public static function getSmtpSourceIp()
{
return self::read('smtp.sourceip');
}
public static function enableSmtp()
{
self::write('smtp.enabled', 1, 1, 1);
}
public static function disableSmtp()
{
self::write('smtp.enabled', 0, 1, 1);
}
public static function setSmtpHost($value)
{
self::write('smtp.host', $value, 1, 1);
}
public static function setSmtpPort($value)
{
self::write('smtp.port', $value, 1, 1);
}
public static function setSmtpEncryption($value)
{
self::write('smtp.encryption', $value, 1, 1);
}
public static function setSmtpUsername($value)
{
self::write('smtp.username', $value, 1, 1);
}
public static function setSmtpPassword($value)
{
self::write('smtp.password', $value, 1, 1);
}
public static function setSmtpAuthMode($value)
{
self::write('smtp.authmode', $value, 1, 1);
}
public static function setSmtpTimeout($value)
{
self::write('smtp.timeout', $value, 1, 1);
}
public static function setSmtpSourceIp($value)
{
self::write('smtp.sourceip', $value, 1, 1);
}
/* end smtp config */
/* Thelia version */
public static function getTheliaSimpleVersion()
{
$majorVersion = self::read('thelia_major_version');
$minorVersion = self::read('thelia_minus_version');
$releaseVersion = self::read('thelia_release_version');
return $majorVersion.'.'.$minorVersion.'.'.$releaseVersion;
}
public static function isShowingErrorMessage()
{
return (bool) static::read("error_message.show", false);
}
/**
* @param bool $v
*/
public static function setShowingErrorMessage($v)
{
static::write("error_message.show", (int) (@(bool) $v));
}
public static function getErrorMessagePageName()
{
return static::read("error_message.page_name");
}
public static function setErrorMessagePageName($v)
{
static::write("error_message.page_name", $v);
}
public static function getAdminCacheHomeStatsTTL()
{
return intval(static::read("admin_cache_home_stats_ttl", 600));
}
/**
* check if Thelia multi domain is activated. (Means one domain for each language)
*
* @return bool
*/
public static function isMultiDomainActivated()
{
return (bool) self::read("one_domain_foreach_lang", false);
}
}
// ConfigQuery