PluginProbe ʕ •ᴥ•ʔ
Backup Migration / 1.3.0
Backup Migration v1.3.0
2.1.6 2.1.5.2 trunk 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.6.1 1.4.7 1.4.8 1.4.9 1.4.9.1 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.5.1
backup-backup / includes / config.php
backup-backup / includes Last commit date
banner 2 years ago check 2 years ago cli 2 years ago cron 2 years ago dashboard 2 years ago database 2 years ago extracter 2 years ago htaccess 2 years ago progress 2 years ago scanner 2 years ago staging 2 years ago uploader 2 years ago zipper 2 years ago activation.php 2 years ago ajax.php 2 years ago analyst.php 2 years ago backup-cli.php 2 years ago backup-heart.php 2 years ago bypasser.php 2 years ago cli-handler.php 2 years ago compatibility.php 2 years ago config.php 2 years ago constants.php 2 years ago initializer.php 2 years ago logger.php 2 years ago restore-batching.php 2 years ago
config.php
216 lines
1 <?php
2
3 // Namespace
4 namespace BMI\Plugin\Dashboard;
5
6 // Exit on direct access
7 if (!defined('ABSPATH')) exit;
8
9 if (!function_exists('bmi_get_config')) {
10 function bmi_get_config($setting, $configpath = false) {
11
12 if ($configpath == false && defined('BMI_CONFIG_PATH')) {
13 $configpath = BMI_CONFIG_PATH;
14 }
15
16 // Load default and additional
17 $defaults = json_decode(file_get_contents(BMI_CONFIG_DEFAULT));
18
19 // Result default
20 if (isset($defaults->{$setting}))
21 $result = $defaults->{$setting};
22 else $result = array();
23
24 // Load user config
25 if (file_exists($configpath) && BMI_CONFIG_STATUS) {
26
27 // Get file contents
28 $bmi_config_contents = file_get_contents($configpath);
29 $bmi_config_json = json_decode($bmi_config_contents);
30
31 // If config is correct set it
32 if (json_last_error() == JSON_ERROR_NONE) {
33
34 // Setting exist?
35 if (isset($bmi_config_json->{$setting})) {
36
37 // Get result
38 $result = $bmi_config_json->{$setting};
39
40 }
41
42 }
43
44 }
45
46 // Replace exceptions
47 if ($setting == 'STORAGE::LOCAL::PATH' && $result == 'default') {
48 $result = BMI_BACKUPS_DEFAULT;
49 }
50
51 // Replace backshashes
52 if ($setting == 'STORAGE::LOCAL::PATH') {
53 $result = str_replace('\\\\', DIRECTORY_SEPARATOR, $result);
54 $result = str_replace('\\', DIRECTORY_SEPARATOR, $result);
55 $result = str_replace('/', DIRECTORY_SEPARATOR, $result);
56 }
57
58 // Return setting
59 return $result;
60
61 }
62 }
63
64 if (!function_exists('bmi_set_config')) {
65 function bmi_set_config($setting, $value) {
66
67 // Load default and additional
68 if (file_exists(BMI_CONFIG_PATH)) {
69
70 // Get file contents
71 $bmi_config_contents = file_get_contents(BMI_CONFIG_PATH);
72 $bmi_config_json = json_decode($bmi_config_contents);
73
74 // Result default
75 $default = bmi_get_config($setting);
76
77 // If config is correct set it
78 if (!(json_last_error() == JSON_ERROR_NONE)) {
79
80 // Setting refill base
81 $bmi_config_json = json_decode(json_encode(array()));;
82
83 }
84
85 // Allow empty
86 $allow_empty = ['OTHER:CLI:PATH'];
87
88 // Check if setting is not empty
89 if (isset($value) && (!is_string($value) || (in_array($setting, $allow_empty) || strlen(trim($value)) > 0))) {
90
91 // Set new setting
92 @$bmi_config_json->{$setting} = $value;
93
94 } else return false;
95
96 // Write edited settings
97 file_put_contents(BMI_CONFIG_PATH, json_encode($bmi_config_json));
98 return true;
99
100 }
101
102 return false;
103
104 }
105 }
106
107 if (!function_exists('bmi_try_checked')) {
108 function bmi_try_checked($setting, $reversed = false) {
109
110 if (!$reversed) {
111
112 if (bmi_get_config($setting) == 'true' || bmi_get_config($setting) === true) {
113 echo ' checked';
114 } else return false;
115
116 } else {
117
118 if (bmi_get_config($setting) == 'true' || bmi_get_config($setting) === true) {
119 return false;
120 } else {
121 echo ' checked';
122 }
123
124 }
125
126 }
127 }
128
129 if (!function_exists('bmi_try_value')) {
130 function bmi_try_value($setting) {
131
132 $res = bmi_get_config($setting);
133 if ($res !== false) {
134 echo ' value="' . sanitize_text_field($res) . '"';
135 } else echo '';
136
137 }
138 }
139
140 $bmi_initial_config_filepath = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'backup-migration' . DIRECTORY_SEPARATOR . 'config.json';
141 $bmi_initial_config_dirpath = dirname($bmi_initial_config_filepath);
142 $bmi_database_config_dirpath = get_option('BMI::STORAGE::LOCAL::PATH', false);
143
144 if ($bmi_database_config_dirpath != false && dirname($bmi_database_config_dirpath) != $bmi_initial_config_dirpath) {
145 $bmi_initial_config_filepath = $bmi_database_config_dirpath . DIRECTORY_SEPARATOR . 'config.json';
146 $bmi_initial_config_dirpath = dirname($bmi_initial_config_filepath);
147 }
148
149 // Get config and parse it
150 if (file_exists($bmi_initial_config_filepath)) {
151
152 // Get file contents
153 $bmi_config_contents = file_get_contents($bmi_initial_config_filepath);
154 $bmi_config_json = json_decode($bmi_config_contents);
155
156 // If config is correct set it
157 if (json_last_error() == JSON_ERROR_NONE) {
158
159 if (!defined('BMI_CONFIG_STATUS')) define('BMI_CONFIG_STATUS', true);
160 $localStoragePath = bmi_get_config('STORAGE::LOCAL::PATH', $bmi_initial_config_filepath);
161 if (!defined('BMI_BACKUPS_ROOT')) define('BMI_BACKUPS_ROOT', $localStoragePath);
162 if (!defined('BMI_BACKUPS')) define('BMI_BACKUPS', $localStoragePath . DIRECTORY_SEPARATOR . 'backups');
163 if (!defined('BMI_STAGING')) define('BMI_STAGING', $localStoragePath . DIRECTORY_SEPARATOR . 'staging');
164
165 if ($bmi_database_config_dirpath == false || $bmi_database_config_dirpath != $localStoragePath) {
166 @copy($bmi_initial_config_filepath, $localStoragePath . DIRECTORY_SEPARATOR . 'config.json');
167 @unlink($bmi_initial_config_filepath);
168
169 $prev_path = dirname($bmi_initial_config_filepath);
170 $prev_path_backups = dirname($bmi_initial_config_filepath) . DIRECTORY_SEPARATOR . 'backups';
171
172 if (file_exists($prev_path_backups) && is_dir($prev_path_backups)) {
173 $scanned_directory_backups = array_diff(scandir($prev_path_backups), ['..', '.']);
174 foreach ($scanned_directory_backups as $i => $file) {
175 if (file_exists($prev_path . DIRECTORY_SEPARATOR . $file) && !is_dir($prev_path . DIRECTORY_SEPARATOR . $file)) {
176 rename($prev_path . DIRECTORY_SEPARATOR . $file, $localStoragePath . DIRECTORY_SEPARATOR . $file);
177 }
178 }
179 @rmdir($prev_path_backups);
180 }
181
182 if (file_exists($prev_path) && is_dir($prev_path)) {
183 $scanned_directory = array_diff(scandir($prev_path), ['..', '.']);
184 foreach ($scanned_directory as $i => $file) {
185 if (file_exists($prev_path . DIRECTORY_SEPARATOR . $file) && !is_dir($prev_path . DIRECTORY_SEPARATOR . $file)) {
186 rename($prev_path . DIRECTORY_SEPARATOR . $file, $localStoragePath . DIRECTORY_SEPARATOR . $file);
187 }
188 }
189 @rmdir($prev_path);
190 }
191
192 update_option('BMI::STORAGE::LOCAL::PATH', $localStoragePath);
193 }
194
195 if (!defined('BMI_CONFIG_PATH')) define('BMI_CONFIG_PATH', $localStoragePath . DIRECTORY_SEPARATOR . 'config.json');
196 if (!defined('BMI_CONFIG_DIR')) define('BMI_CONFIG_DIR', $localStoragePath);
197
198 } else {
199
200 if (!defined('BMI_CONFIG_STATUS')) define('BMI_CONFIG_STATUS', false);
201
202 }
203
204 } else {
205
206 if (!file_exists(dirname($bmi_initial_config_filepath)) && !is_dir(dirname($bmi_initial_config_filepath))) {
207 @mkdir(dirname($bmi_initial_config_filepath), 0755, true);
208 }
209
210 @copy(BMI_CONFIG_DEFAULT, $bmi_initial_config_filepath);
211 if (!defined('BMI_CONFIG_STATUS')) define('BMI_CONFIG_STATUS', true);
212 if (!defined('BMI_CONFIG_PATH')) define('BMI_CONFIG_PATH', $bmi_initial_config_filepath);
213 if (!defined('BMI_CONFIG_DIR')) define('BMI_CONFIG_DIR', dirname($bmi_initial_config_filepath));
214
215 }
216