1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* mutate_settings.ajax.php |
4
|
|
|
*/ |
5
|
|
|
if (!defined('IN_MANAGER_MODE') || IN_MANAGER_MODE !== true) { |
6
|
|
|
die("<b>INCLUDE_ORDERING_ERROR</b><br /><br />Please use the EVO Content Manager instead of accessing this file directly."); |
7
|
|
|
} |
8
|
|
|
|
9
|
|
|
$action = preg_replace('/[^A-Za-z0-9_\-\.\/]/', '', $_POST['action']); |
10
|
|
|
$lang = preg_replace('/[^A-Za-z0-9_\s\+\-\.\/]/', '', $_POST['lang']); |
11
|
|
|
$key = preg_replace('/[^A-Za-z0-9_\-\.\/]/', '', $_POST['key']); |
12
|
|
|
$value = preg_replace('/[^A-Za-z0-9_\-\.\/]/', '', $_POST['value']); |
13
|
|
|
|
14
|
|
|
$action = $modx->getDatabase()->escape($action); |
15
|
|
|
$lang = $modx->getDatabase()->escape($lang); |
16
|
|
|
$key = $modx->getDatabase()->escape($key); |
17
|
|
|
$value = $modx->getDatabase()->escape($value); |
18
|
|
|
|
19
|
|
|
$str = ''; |
20
|
|
|
$emptyCache = false; |
21
|
|
|
|
22
|
|
|
switch (true) { |
23
|
|
|
case ($action == 'get' && preg_match('/^[A-z0-9_-]+$/', |
|
|
|
|
24
|
|
|
$lang) && file_exists(MODX_MANAGER_PATH . 'includes/lang/' . $lang . '.inc.php')): { |
25
|
|
|
include MODX_MANAGER_PATH . 'includes/lang/' . $lang . '.inc.php'; |
26
|
|
|
$str = isset($key, $_lang, $_lang[$key]) ? $_lang[$key] : ""; |
27
|
|
|
break; |
28
|
|
|
} |
29
|
|
|
case ($action == 'setsetting' && !empty($key) && !empty($value)): { |
|
|
|
|
30
|
|
|
$sql = "REPLACE INTO " . $modx->getDatabase()->getFullTableName("system_settings") . " (setting_name, setting_value) VALUES('{$key}', '{$value}');"; |
31
|
|
|
$str = "true"; |
32
|
|
|
$modx->getDatabase()->query($sql); |
33
|
|
|
$emptyCache = true; |
34
|
|
|
break; |
35
|
|
|
} |
36
|
|
|
case ($action == 'updateplugin' && ($key == '_delete_' && !empty($lang))): { |
|
|
|
|
37
|
|
|
$modx->getDatabase()->delete($modx->getDatabase()->getFullTableName("site_plugins"), "name='{$lang}'"); |
38
|
|
|
$str = "true"; |
39
|
|
|
$emptyCache = true; |
40
|
|
|
break; |
41
|
|
|
} |
42
|
|
|
case ($action == 'updateplugin' && (!empty($key) && !empty($lang) && !empty($value))): { |
|
|
|
|
43
|
|
|
$modx->getDatabase()->update(array($key => $value), $modx->getDatabase()->getFullTableName("site_plugins"), "name = '{$lang}'"); |
44
|
|
|
$str = "true"; |
45
|
|
|
$emptyCache = true; |
46
|
|
|
break; |
47
|
|
|
} |
48
|
|
|
default: { |
|
|
|
|
49
|
|
|
break; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if ($emptyCache) { |
54
|
|
|
$modx->clearCache('full'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
echo $str; |
58
|
|
|
|
As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next
break
.There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.