PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 2.0.3
JetBackup – Backup, Restore & Migrate v2.0.3
3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / public / include / functions.php
backup / public / include Last commit date
footer-new.php 3 years ago footer.php 3 years ago functions.php 3 years ago header-new.php 3 years ago header.php 3 years ago modal.php 3 years ago sidebar.php 3 years ago
functions.php
325 lines
1 <?php
2
3 function _backupGuardT($key, $return = false)
4 {
5 if (SG_ENV_ADAPTER == SG_ENV_WORDPRESS) {
6 if ($return) {
7 return __($key, "backup-guard-pro");
8 } else {
9 _e($key, "backup-guard-pro");
10 }
11 } else {
12 if ($return) {
13 return $key;
14 } else {
15 echo $key;
16 }
17 }
18 }
19
20 function backupGuardIsAjax()
21 {
22 return (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
23 }
24
25 function selectElement($data, $attributes = array(), $firstOption = '', $selectedKey = '')
26 {
27 $attrString = '';
28 foreach ($attributes as $attributeKey => $attributeValue) {
29 $attrString .= " " . $attributeKey . '="' . $attributeValue . '"';
30 }
31 $select = '<select' . $attrString . '>';
32 if ($firstOption) {
33 $select .= '<option value="0">' . $firstOption . '</option>';
34 }
35 foreach ($data as $key => $val) {
36 $selected = $selectedKey == $key ? ' selected="selected"' : '';
37 $select .= '<option value="' . $key . '"' . $selected . '>' . $val . '</option>';
38 }
39 $select .= '</select>';
40
41 return $select;
42 }
43
44 function backupGuardParseBackupOptions($options)
45 {
46
47 $scheduleOptions = array(
48 'interval' => '',
49 'monthOfInterval' => '',
50 'dayOfInterval' => '',
51 'intervalHour' => '',
52 'isBackgroundMode' => false,
53 'isDatabaseSelected' => false,
54 'isFilesSelected' => false,
55 'isCustomBackup' => false,
56 'selectedDirectories' => array(),
57 'excludeDirectories' => array(),
58 'selectedClouds' => array(),
59 'label' => ''
60 );
61
62 if (isset($options['schedule_options'])) {
63 $scheduleExecutionOptions = json_decode($options['schedule_options'], true);
64
65 $scheduleOptions['interval'] = $scheduleExecutionOptions['interval'];
66 $scheduleOptions['monthOfInterval'] = $scheduleExecutionOptions['monthOfInterval'];
67 $scheduleOptions['dayOfInterval'] = $scheduleExecutionOptions['dayOfInterval'];
68 $scheduleOptions['intervalHour'] = $scheduleExecutionOptions['intervalHour'];
69 }
70
71 if (isset($options['backup_options'])) {
72 $backupOptions = json_decode($options['backup_options'], true);
73
74 $scheduleOptions['isBackgroundMode'] = $backupOptions['SG_BACKUP_IN_BACKGROUND_MODE'] ? true : false;
75 $scheduleOptions['isDatabaseSelected'] = $backupOptions['SG_ACTION_BACKUP_DATABASE_AVAILABLE'] ? true : false;
76 $scheduleOptions['isFilesSelected'] = $backupOptions['SG_ACTION_BACKUP_FILES_AVAILABLE'] ? true : false;
77 $backupType = $backupOptions['SG_BACKUP_TYPE'];
78
79 $scheduleOptions['isCustomBackup'] = $backupType == SG_BACKUP_TYPE_FULL ? false : true;
80
81 if ($scheduleOptions['isCustomBackup']) {
82 $scheduleOptions['selectedDirectories'] = explode(',', $backupOptions['SG_BACKUP_FILE_PATHS']);
83 if ($scheduleOptions['isFilesSelected']) {
84 $scheduleOptions['excludeDirectories'] = explode(',', $backupOptions['SG_BACKUP_FILE_PATHS_EXCLUDE']);
85 }
86 }
87
88 if (strlen($backupOptions['SG_BACKUP_UPLOAD_TO_STORAGES'])) {
89 $scheduleOptions['selectedClouds'] = explode(',', $backupOptions['SG_BACKUP_UPLOAD_TO_STORAGES']);
90 }
91 }
92
93 if (isset($options['label'])) {
94 $scheduleOptions['label'] = $options['label'];
95 }
96
97 return $scheduleOptions;
98 }
99
100 function backupGuardFilterStatusesByActionType($currentBackup, $currentOptions)
101 {
102 $filteredStatuses = array();
103 if ($currentBackup['type'] == SG_ACTION_TYPE_RESTORE) {
104 $filteredStatuses[] = SG_ACTION_TYPE_RESTORE . SG_ACTION_STATUS_IN_PROGRESS_FILES;
105 $filteredStatuses[] = SG_ACTION_TYPE_RESTORE . SG_ACTION_STATUS_IN_PROGRESS_DB;
106 } else {
107 $currentOptions = backupGuardActiveOptionToType($currentOptions);
108 if ($currentOptions['backupDatabase']) {
109 $filteredStatuses[] = $currentOptions['backupDatabase'];
110 }
111 if ($currentOptions['backupFiles']) {
112 $filteredStatuses[] = $currentOptions['backupFiles'];
113 }
114 if ($currentOptions['ftp']) {
115 $filteredStatuses[] = $currentOptions['ftp'];
116 }
117 if ($currentOptions['dropbox']) {
118 $filteredStatuses[] = $currentOptions['dropbox'];
119 }
120 if ($currentOptions['gdrive']) {
121 $filteredStatuses[] = $currentOptions['gdrive'];
122 }
123 if ($currentOptions['amazon']) {
124 $filteredStatuses[] = $currentOptions['amazon'];
125 }
126 if ($currentOptions['oneDrive']) {
127 $filteredStatuses[] = $currentOptions['oneDrive'];
128 }
129 if ($currentOptions['pCloud']) {
130 $filteredStatuses[] = $currentOptions['pCloud'];
131 }
132 if ($currentOptions['box']) {
133 $filteredStatuses[] = $currentOptions['box'];
134 }
135 if ($currentOptions['backupGuard']) {
136 $filteredStatuses[] = $currentOptions['backupGuard'];
137 }
138 }
139
140 return $filteredStatuses;
141 }
142
143 function backupGuardActiveOptionToType($activeOption)
144 {
145 $activeOptions = array();
146 $activeOption = json_decode($activeOption, true);
147 $activeOptions['backupDatabase'] = !empty($activeOption['SG_ACTION_BACKUP_DATABASE_AVAILABLE']) ? SG_ACTION_STATUS_IN_PROGRESS_DB : 0;
148 $activeOptions['backupFiles'] = !empty($activeOption['SG_ACTION_BACKUP_FILES_AVAILABLE']) ? SG_ACTION_STATUS_IN_PROGRESS_FILES : 0;
149
150 $storages = explode(',', @$activeOption['SG_BACKUP_UPLOAD_TO_STORAGES']);
151 $activeOptions['ftp'] = 0;
152 $activeOptions['dropbox'] = 0;
153 $activeOptions['gdrive'] = 0;
154 $activeOptions['amazon'] = 0;
155 $activeOptions['oneDrive'] = 0;
156 $activeOptions['pCloud'] = 0;
157 $activeOptions['box'] = 0;
158 $activeOptions['backupGuard'] = 0;
159 foreach ($storages as $storage) {
160 switch ($storage) {
161 case SG_STORAGE_FTP:
162 $activeOptions['ftp'] = SG_ACTION_TYPE_UPLOAD . SG_STORAGE_FTP;
163 break;
164 case SG_STORAGE_DROPBOX:
165 $activeOptions['dropbox'] = SG_ACTION_TYPE_UPLOAD . SG_STORAGE_DROPBOX;
166 break;
167 case SG_STORAGE_GOOGLE_DRIVE:
168 $activeOptions['gdrive'] = SG_ACTION_TYPE_UPLOAD . SG_STORAGE_GOOGLE_DRIVE;
169 break;
170 case SG_STORAGE_AMAZON:
171 $activeOptions['amazon'] = SG_ACTION_TYPE_UPLOAD . SG_STORAGE_AMAZON;
172 break;
173 case SG_STORAGE_ONE_DRIVE:
174 $activeOptions['oneDrive'] = SG_ACTION_TYPE_UPLOAD . SG_STORAGE_ONE_DRIVE;
175 break;
176 case SG_STORAGE_P_CLOUD:
177 $activeOptions['pCloud'] = SG_ACTION_TYPE_UPLOAD . SG_STORAGE_P_CLOUD;
178 break;
179 case SG_STORAGE_BOX:
180 $activeOptions['box'] = SG_ACTION_TYPE_UPLOAD . SG_STORAGE_BOX;
181 break;
182 }
183 }
184
185 return $activeOptions;
186 }
187
188 function backupGuardConvertToBytes($from)
189 {
190 $number = substr($from, 0, -2);
191 switch (strtoupper(substr($from, -2))) {
192 case "KB":
193 return $number * 1024;
194 case "MB":
195 return $number * pow(1024, 2);
196 case "GB":
197 return $number * pow(1024, 3);
198 case "TB":
199 return $number * pow(1024, 4);
200 case "PB":
201 return $number * pow(1024, 5);
202 default:
203 return $from;
204 }
205 }
206
207 function backupGuardGetRunningActions()
208 {
209 $runningActions = SGBackup::getRunningActions();
210 $isAnyActiveActions = count($runningActions);
211 if ($isAnyActiveActions) {
212 return $runningActions;
213 }
214
215 return false;
216 }
217
218 function backupGuardShouldUpdate()
219 {
220 $currentVersion = SG_BACKUP_GUARD_VERSION;
221 $oldVersion = SGConfig::get('SG_BACKUP_GUARD_VERSION', true);
222
223 if (!$oldVersion) {
224 return true;
225 }
226
227 if ($currentVersion !== $oldVersion) {
228 SGConfig::set('SG_BACKUP_GUARD_VERSION', $currentVersion, true);
229 SGBoot::didUpdatePluginVersion();
230
231 return SG_FORCE_DB_TABLES_RESET;
232 }
233
234 if (!checkAllMissedTables()) {
235 return true;
236 }
237
238 return false;
239 }
240
241 function backupGuardGetDatabaseEngine()
242 {
243 global $wpdb;
244 $dbName = $wpdb->dbname;
245 $engine = 'InnoDB';
246 $engineCheckSql = "SELECT ENGINE FROM information_schema.TABLES WHERE TABLE_SCHEMA = '$dbName'";
247 $result = $wpdb->get_results($engineCheckSql, ARRAY_A);
248 if (!empty($result)) {
249 $engineCheckSql = "SHOW TABLE STATUS WHERE Name = '" . $wpdb->prefix . "users' AND Engine = 'MyISAM'";
250 $result = $wpdb->get_results($engineCheckSql, ARRAY_A);
251 if (isset($result[0]['Engine']) && $result[0]['Engine'] == 'MyISAM') {
252 $engine = 'MyISAM';
253 }
254 }
255
256 return $engine;
257 }
258
259 function backupGuardShouldActivateExtension($extension)
260 {
261 $extensionAdapter = SGExtension::getInstance();
262
263 if (!$extensionAdapter->isExtensionAvailable($extension) || SGConfig::get($extension) || !$extensionAdapter->isExtensionAlreadyInPluginsFolder($extension) || $extensionAdapter->isExtensionActive($extension)) {
264 return false;
265 }
266
267 return true;
268 }
269
270 function backupGuardShouldInstallExtension($extension)
271 {
272 $extensionAdapter = SGExtension::getInstance();
273
274 if (!$extensionAdapter->isExtensionAvailable($extension) || SGConfig::get($extension) || $extensionAdapter->isExtensionAlreadyInPluginsFolder($extension) || $extensionAdapter->isExtensionActive($extension)) {
275 return false;
276 }
277
278 return true;
279 }
280
281 function backupGuardLoggedMessage()
282 {
283 $html = '<span class="bg-logged-msg-container">';
284 $html .= 'Package: ' . backupGuardGetProductName() . ' | Version: ' . SG_BACKUP_GUARD_VERSION;
285 $html .= '</span>';
286
287 return $html;
288 }
289
290 function modifyCronJobsByTimezone()
291 {
292 $allSchedules = SGBackupSchedule::getAllSchedules(false);
293
294 foreach ($allSchedules as $schedule) {
295 $id = $schedule['id'];
296 $cronTab = json_decode($schedule['schedule_options'], true);
297 $cronOptions = json_decode($schedule['backup_options'], true);
298 $cronLabel = $schedule['label'];
299
300 SGBackupSchedule::create($cronTab, $cronOptions, $cronLabel);
301 SGBackupSchedule::remove($id);
302 }
303 }
304
305 if (!function_exists('dd')) {
306 function dd()
307 {
308 $args = func_get_args();
309
310 foreach ($args as $arg) {
311 ob_start();
312 print_r($arg);
313 $output = ob_get_clean();
314
315 // Add formatting
316 $output = preg_replace("/\]\=\>\n(\s+)/m", "] => ", $output);
317 $output = '<pre style="background: #FFFEEF; color: #000; border: 1px dashed #888; padding: 10px; margin: 10px 0; text-align: left;">' . $output . '</pre>';
318
319 echo $output;
320 }
321
322 exit;
323 }
324 }
325