GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 4a99fb...868d9e )
by Liuta
04:24
created
restore/xcloner_restore.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -906,11 +906,11 @@  discard block
 block discarded – undo
906 906
 		}
907 907
 
908 908
 		if( $this->is_encrypted_file($backup_file) ) {
909
-		    $message = sprintf('Backup file %s seems encrypted, please Decrypt it first from your Manage Backups panel.', $backup_file);
910
-            $this->logger->error($message);
911
-            $this->send_response(500, $message);
912
-            return;
913
-        }
909
+			$message = sprintf('Backup file %s seems encrypted, please Decrypt it first from your Manage Backups panel.', $backup_file);
910
+			$this->logger->error($message);
911
+			$this->send_response(500, $message);
912
+			return;
913
+		}
914 914
 		
915 915
 		$this->logger->info(sprintf('Opening backup archive %s at position %s', $backup_file, $start));
916 916
 		$backup_archive->open($this->backup_storage_dir.DS.$backup_file, $start);
@@ -955,25 +955,25 @@  discard block
 block discarded – undo
955 955
 		$this->send_response(200, $return);
956 956
 	}
957 957
 
958
-    /**
959
-     * Check if provided filename has encrypted suffix
960
-     *
961
-     * @param $filename
962
-     * @return bool
963
-     */
964
-    public function is_encrypted_file($filename) {
965
-        $fp = $this->filesystem->readStream( $filename );
966
-        if (is_resource($fp)) {
967
-            $encryption_length = fread($fp, 16);
968
-            fclose($fp);
969
-            if (is_numeric($encryption_length)) {
970
-                return true;
971
-            }
972
-        }
973
-
974
-        return false;
975
-
976
-    }
958
+	/**
959
+	 * Check if provided filename has encrypted suffix
960
+	 *
961
+	 * @param $filename
962
+	 * @return bool
963
+	 */
964
+	public function is_encrypted_file($filename) {
965
+		$fp = $this->filesystem->readStream( $filename );
966
+		if (is_resource($fp)) {
967
+			$encryption_length = fread($fp, 16);
968
+			fclose($fp);
969
+			if (is_numeric($encryption_length)) {
970
+				return true;
971
+			}
972
+		}
973
+
974
+		return false;
975
+
976
+	}
977 977
 
978 978
 	/**
979 979
 	 * Get current directory method
Please login to merge, or discard this patch.
includes/class-xcloner-archive.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -63,10 +63,10 @@  discard block
 block discarded – undo
63 63
 	 */
64 64
 	private $processed_size_bytes = 0;
65 65
 
66
-    /**
67
-     * The backup name encryption suffix
68
-     * @var string
69
-     */
66
+	/**
67
+	 * The backup name encryption suffix
68
+	 * @var string
69
+	 */
70 70
 	private $encrypt_suffix = "-enc";
71 71
 
72 72
 	/**
@@ -150,8 +150,8 @@  discard block
 block discarded – undo
150 150
 		$this->archive_name = $this->filesystem->process_backup_name($name);
151 151
 
152 152
 		if($encrypt_prefix) {
153
-		    $this->archive_name .= $this->encrypt_suffix;
154
-        }
153
+			$this->archive_name .= $this->encrypt_suffix;
154
+		}
155 155
 
156 156
 		if ($diff_timestamp_start = $this->filesystem->get_diff_timestamp_start()) {
157 157
 			//$this->archive_name = $this->archive_name."-diff-".date("Y-m-d_H-i",$diff_timestamp_start);
@@ -366,10 +366,10 @@  discard block
 block discarded – undo
366 366
 		if (isset($extra_params['backup_archive_name'])) {
367 367
 			$this->set_archive_name($extra_params['backup_archive_name'], $return['extra']['backup_part']);
368 368
 		} else {
369
-		    $encrypt = false;
370
-            if(isset($backup_params['backup_encrypt']) && $backup_params['backup_encrypt']) {
371
-                $encrypt = true;
372
-            }
369
+			$encrypt = false;
370
+			if(isset($backup_params['backup_encrypt']) && $backup_params['backup_encrypt']) {
371
+				$encrypt = true;
372
+			}
373 373
 			$this->set_archive_name($backup_params['backup_name'], 0, $encrypt);
374 374
 		}
375 375
 
Please login to merge, or discard this patch.
includes/class-xcloner-remote-storage.php 1 patch
Indentation   +648 added lines, -648 removed lines patch added patch discarded remove patch
@@ -54,775 +54,775 @@
 block discarded – undo
54 54
 class Xcloner_Remote_Storage
55 55
 {
56 56
 
57
-    private $gdrive_app_name = "XCloner Backup and Restore";
58
-
59
-    private $storage_fields = array(
60
-        "option_prefix" => "xcloner_",
61
-        "ftp" => array(
62
-            "text" => "FTP",
63
-            "ftp_enable" => "int",
64
-            "ftp_hostname" => "string",
65
-            "ftp_port" => "int",
66
-            "ftp_username" => "string",
67
-            "ftp_password" => "raw",
68
-            "ftp_path" => "path",
69
-            "ftp_transfer_mode" => "int",
70
-            "ftp_ssl_mode" => "int",
71
-            "ftp_timeout" => "int",
72
-            "ftp_cleanup_days" => "float",
73
-        ),
74
-        "sftp" => array(
75
-            "text" => "SFTP",
76
-            "sftp_enable" => "int",
77
-            "sftp_hostname" => "string",
78
-            "sftp_port" => "int",
79
-            "sftp_username" => "string",
80
-            "sftp_password" => "raw",
81
-            "sftp_path" => "path",
82
-            "sftp_private_key" => "raw",
83
-            "sftp_timeout" => "int",
84
-            "sftp_cleanup_days" => "float",
85
-        ),
86
-        "aws" => array(
87
-            "text" => "S3",
88
-            "aws_enable" => "int",
89
-            "aws_key" => "string",
90
-            "aws_secret" => "raw",
91
-            "aws_endpoint" => "string",
92
-            "aws_region" => "string",
93
-            "aws_bucket_name" => "string",
94
-            "aws_prefix" => "string",
95
-            "aws_cleanup_days" => "float",
96
-        ),
97
-        "dropbox" => array(
98
-            "text" => "Dropbox",
99
-            "dropbox_enable" => "int",
100
-            "dropbox_access_token" => "string",
101
-            "dropbox_app_secret" => "raw",
102
-            "dropbox_prefix" => "string",
103
-            "dropbox_cleanup_days" => "float",
104
-        ),
105
-        "azure" => array(
106
-            "text" => "Azure BLOB",
107
-            "azure_enable" => "int",
108
-            "azure_account_name" => "string",
109
-            "azure_api_key" => "string",
110
-            "azure_container" => "string",
111
-            "azure_cleanup_days" => "float",
112
-        ),
113
-        "backblaze" => array(
114
-            "text" => "Backblaze",
115
-            "backblaze_enable" => "int",
116
-            "backblaze_account_id" => "string",
117
-            "backblaze_application_key" => "string",
118
-            "backblaze_bucket_name" => "string",
119
-            "backblaze_cleanup_days" => "float",
120
-        ),
121
-
122
-        "webdav" => array(
123
-            "text" => "WebDAV",
124
-            "webdav_enable" => "int",
125
-            "webdav_url" => "string",
126
-            "webdav_username" => "string",
127
-            "webdav_password" => "raw",
128
-            "webdav_target_folder" => "string",
129
-            "webdav_cleanup_days" => "float",
130
-        ),
131
-
132
-        "gdrive" => array(
133
-            "text" => "Google Drive",
134
-            "gdrive_enable" => "int",
135
-            "gdrive_access_code" => "string",
136
-            "gdrive_client_id" => "string",
137
-            "gdrive_client_secret" => "raw",
138
-            "gdrive_target_folder" => "string",
139
-            "gdrive_cleanup_days" => "float",
140
-            "gdrive_empty_trash" => "int",
141
-        ),
142
-    );
143
-
144
-    private $aws_regions = array(
145
-        'us-east-1' => 'US East (N. Virginia)',
146
-        'us-east-2' => 'US East (Ohio)',
147
-        'us-west-1' => 'US West (N. California)',
148
-        'us-west-2' => 'US West (Oregon)',
149
-        'ca-central-1' => 'Canada (Central)',
150
-        'eu-west-1' => 'EU (Ireland)',
151
-        'eu-central-1' => 'EU (Frankfurt)',
152
-        'eu-west-2' => 'EU (London)',
153
-        'ap-northeast-1' => 'Asia Pacific (Tokyo)',
154
-        'ap-northeast-2' => 'Asia Pacific (Seoul)',
155
-        'ap-southeast-1' => 'Asia Pacific (Singapore)',
156
-        'ap-southeast-2' => 'Asia Pacific (Sydney)',
157
-        'ap-south-1' => 'Asia Pacific (Mumbai)',
158
-        'sa-east-1' => 'South America (São Paulo)'
159
-    );
160
-
161
-    private $xcloner_sanitization;
162
-    private $xcloner_file_system;
163
-    private $logger;
164
-    private $xcloner;
165
-
166
-    /**
167
-     * Xcloner_Remote_Storage constructor.
168
-     * @param Xcloner $xcloner_container
169
-     */
170
-    public function __construct(Xcloner $xcloner_container)
171
-    {
172
-        $this->xcloner_sanitization = $xcloner_container->get_xcloner_sanitization();
173
-        $this->xcloner_file_system = $xcloner_container->get_xcloner_filesystem();
174
-        $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_remote_storage");
175
-        $this->xcloner = $xcloner_container;
176
-
177
-        foreach ($this->storage_fields as $main_key => $array) {
178
-
179
-            if (is_array($array)) {
180
-                foreach ($array as $key => $type) {
181
-
182
-                    if ($type == "raw") {
183
-                        add_filter("pre_update_option_" . $this->storage_fields['option_prefix'] . $key,
184
-                            function ($value) {
185
-
186
-                                return $this->simple_crypt($value, 'e');
187
-
188
-                            }, 10, 1);
189
-
190
-                        add_filter("option_" . $this->storage_fields['option_prefix'] . $key, function ($value) {
191
-
192
-                            return $this->simple_crypt($value, 'd');
193
-
194
-                        }, 10, 1);
195
-                    }
196
-
197
-                }
198
-            }
199
-        }
200
-
201
-    }
202
-
203
-    /**
204
-     * Encrypts and Decrypt a string based on openssl lib
205
-     *
206
-     * @param $string
207
-     * @param string $action
208
-     * @return string
209
-     */
210
-    private function simple_crypt($string, $action = 'e')
211
-    {
212
-        // you may change these values to your own
213
-        $secret_key = NONCE_KEY;
214
-        $secret_iv = NONCE_SALT;
215
-
216
-        if (!$string) {
217
-            //we do no encryption for empty data
218
-            return $string;
219
-        }
220
-
221
-        $output = $string;
222
-        $encrypt_method = "AES-256-CBC";
223
-        $key = hash('sha256', $secret_key);
224
-        $iv = substr(hash('sha256', $secret_iv), 0, 16);
225
-
226
-        if ($action == 'e' && function_exists('openssl_encrypt')) {
227
-            $output = base64_encode(openssl_encrypt($string, $encrypt_method, $key, 0, $iv));
228
-        } else {
229
-            if ($action == 'd' && function_exists('openssl_decrypt') && base64_decode($string)) {
230
-                $decrypt = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
231
-                if ($decrypt) {
232
-                    //we check if decrypt was succesful
233
-                    $output = $decrypt;
234
-                }
235
-            }
236
-        }
237
-
238
-        return $output;
239
-    }
240
-
241
-    private function get_xcloner_container()
242
-    {
243
-        return $this->xcloner;
244
-    }
245
-
246
-    public function get_available_storages()
247
-    {
248
-        $return = array();
249
-        foreach ($this->storage_fields as $storage => $data) {
250
-            $check_field = $this->storage_fields["option_prefix"] . $storage . "_enable";
251
-            if (get_option($check_field)) {
252
-                $return[$storage] = $data['text'];
253
-            }
254
-        }
255
-
256
-        return $return;
257
-    }
258
-
259
-    public function save($action = "ftp")
260
-    {
261
-        if (!$action) {
262
-            return false;
263
-        }
264
-
265
-        $storage = $this->xcloner_sanitization->sanitize_input_as_string($action);
266
-        $this->logger->debug(sprintf("Saving the remote storage %s options", strtoupper($action)));
267
-
268
-        if (is_array($this->storage_fields[$storage])) {
269
-            foreach ($this->storage_fields[$storage] as $field => $validation) {
270
-                $check_field = $this->storage_fields["option_prefix"] . $field;
271
-                $sanitize_method = "sanitize_input_as_" . $validation;
272
-
273
-                if (!isset($_POST[$check_field])) {
274
-                    $_POST[$check_field] = 0;
275
-                }
276
-
277
-                if (!method_exists($this->xcloner_sanitization, $sanitize_method)) {
278
-                    $sanitize_method = "sanitize_input_as_string";
279
-                }
280
-
281
-                $sanitized_value = $this->xcloner_sanitization->$sanitize_method(stripslashes($_POST[$check_field]));
282
-                update_option($check_field, $sanitized_value);
283
-            }
284
-
285
-            $this->xcloner->trigger_message(__("%s storage settings saved.", 'xcloner-backup-and-restore'), "success",
286
-                $this->storage_fields[$action]['text']);
287
-        }
288
-
289
-    }
290
-
291
-    public function check($action = "ftp")
292
-    {
293
-        try {
294
-            $this->verify_filesystem($action);
295
-            $this->xcloner->trigger_message(__("%s connection is valid.", 'xcloner-backup-and-restore'), "success",
296
-                $this->storage_fields[$action]['text']);
297
-            $this->logger->debug(sprintf("Connection to remote storage %s is valid", strtoupper($action)));
298
-        } catch (Exception $e) {
299
-            $this->xcloner->trigger_message("%s connection error: " . $e->getMessage(), "error",
300
-                $this->storage_fields[$action]['text']);
301
-        }
302
-    }
303
-
304
-    /**
305
-     * @param string $storage_type
306
-     */
307
-    public function verify_filesystem($storage_type)
308
-    {
309
-        $method = "get_" . $storage_type . "_filesystem";
310
-
311
-        $this->logger->info(sprintf("Checking validity of the remote storage %s filesystem",
312
-            strtoupper($storage_type)));
313
-
314
-        if (!method_exists($this, $method)) {
315
-            return false;
316
-        }
317
-
318
-        list($adapter, $filesystem) = $this->$method();
319
-
320
-        $test_file = substr(".xcloner_" . md5(time()), 0, 15);
321
-
322
-        if ($storage_type == "gdrive") {
323
-            if (!is_array($filesystem->listContents())) {
324
-                throw new Exception(__("Could not read data", 'xcloner-backup-and-restore'));
325
-            }
326
-            $this->logger->debug(sprintf("I can list data from remote storage %s", strtoupper($storage_type)));
327
-
328
-            return true;
329
-        }
330
-
331
-        //testing write access
332
-        if (!$filesystem->write($test_file, "data")) {
333
-            throw new Exception(__("Could not write data", 'xcloner-backup-and-restore'));
334
-        }
335
-        $this->logger->debug(sprintf("I can write data to remote storage %s", strtoupper($storage_type)));
336
-
337
-        //testing read access
338
-        if (!$filesystem->has($test_file)) {
339
-            throw new Exception(__("Could not read data", 'xcloner-backup-and-restore'));
340
-        }
341
-        $this->logger->debug(sprintf("I can read data to remote storage %s", strtoupper($storage_type)));
342
-
343
-        //delete test file
344
-        if (!$filesystem->delete($test_file)) {
345
-            throw new Exception(__("Could not delete data", 'xcloner-backup-and-restore'));
346
-        }
347
-        $this->logger->debug(sprintf("I can delete data to remote storage %s", strtoupper($storage_type)));
348
-
349
-        return true;
350
-    }
351
-
352
-    public function upload_backup_to_storage($file, $storage)
353
-    {
354
-        if (!$this->xcloner_file_system->get_storage_filesystem()->has($file)) {
57
+	private $gdrive_app_name = "XCloner Backup and Restore";
58
+
59
+	private $storage_fields = array(
60
+		"option_prefix" => "xcloner_",
61
+		"ftp" => array(
62
+			"text" => "FTP",
63
+			"ftp_enable" => "int",
64
+			"ftp_hostname" => "string",
65
+			"ftp_port" => "int",
66
+			"ftp_username" => "string",
67
+			"ftp_password" => "raw",
68
+			"ftp_path" => "path",
69
+			"ftp_transfer_mode" => "int",
70
+			"ftp_ssl_mode" => "int",
71
+			"ftp_timeout" => "int",
72
+			"ftp_cleanup_days" => "float",
73
+		),
74
+		"sftp" => array(
75
+			"text" => "SFTP",
76
+			"sftp_enable" => "int",
77
+			"sftp_hostname" => "string",
78
+			"sftp_port" => "int",
79
+			"sftp_username" => "string",
80
+			"sftp_password" => "raw",
81
+			"sftp_path" => "path",
82
+			"sftp_private_key" => "raw",
83
+			"sftp_timeout" => "int",
84
+			"sftp_cleanup_days" => "float",
85
+		),
86
+		"aws" => array(
87
+			"text" => "S3",
88
+			"aws_enable" => "int",
89
+			"aws_key" => "string",
90
+			"aws_secret" => "raw",
91
+			"aws_endpoint" => "string",
92
+			"aws_region" => "string",
93
+			"aws_bucket_name" => "string",
94
+			"aws_prefix" => "string",
95
+			"aws_cleanup_days" => "float",
96
+		),
97
+		"dropbox" => array(
98
+			"text" => "Dropbox",
99
+			"dropbox_enable" => "int",
100
+			"dropbox_access_token" => "string",
101
+			"dropbox_app_secret" => "raw",
102
+			"dropbox_prefix" => "string",
103
+			"dropbox_cleanup_days" => "float",
104
+		),
105
+		"azure" => array(
106
+			"text" => "Azure BLOB",
107
+			"azure_enable" => "int",
108
+			"azure_account_name" => "string",
109
+			"azure_api_key" => "string",
110
+			"azure_container" => "string",
111
+			"azure_cleanup_days" => "float",
112
+		),
113
+		"backblaze" => array(
114
+			"text" => "Backblaze",
115
+			"backblaze_enable" => "int",
116
+			"backblaze_account_id" => "string",
117
+			"backblaze_application_key" => "string",
118
+			"backblaze_bucket_name" => "string",
119
+			"backblaze_cleanup_days" => "float",
120
+		),
121
+
122
+		"webdav" => array(
123
+			"text" => "WebDAV",
124
+			"webdav_enable" => "int",
125
+			"webdav_url" => "string",
126
+			"webdav_username" => "string",
127
+			"webdav_password" => "raw",
128
+			"webdav_target_folder" => "string",
129
+			"webdav_cleanup_days" => "float",
130
+		),
131
+
132
+		"gdrive" => array(
133
+			"text" => "Google Drive",
134
+			"gdrive_enable" => "int",
135
+			"gdrive_access_code" => "string",
136
+			"gdrive_client_id" => "string",
137
+			"gdrive_client_secret" => "raw",
138
+			"gdrive_target_folder" => "string",
139
+			"gdrive_cleanup_days" => "float",
140
+			"gdrive_empty_trash" => "int",
141
+		),
142
+	);
143
+
144
+	private $aws_regions = array(
145
+		'us-east-1' => 'US East (N. Virginia)',
146
+		'us-east-2' => 'US East (Ohio)',
147
+		'us-west-1' => 'US West (N. California)',
148
+		'us-west-2' => 'US West (Oregon)',
149
+		'ca-central-1' => 'Canada (Central)',
150
+		'eu-west-1' => 'EU (Ireland)',
151
+		'eu-central-1' => 'EU (Frankfurt)',
152
+		'eu-west-2' => 'EU (London)',
153
+		'ap-northeast-1' => 'Asia Pacific (Tokyo)',
154
+		'ap-northeast-2' => 'Asia Pacific (Seoul)',
155
+		'ap-southeast-1' => 'Asia Pacific (Singapore)',
156
+		'ap-southeast-2' => 'Asia Pacific (Sydney)',
157
+		'ap-south-1' => 'Asia Pacific (Mumbai)',
158
+		'sa-east-1' => 'South America (São Paulo)'
159
+	);
160
+
161
+	private $xcloner_sanitization;
162
+	private $xcloner_file_system;
163
+	private $logger;
164
+	private $xcloner;
165
+
166
+	/**
167
+	 * Xcloner_Remote_Storage constructor.
168
+	 * @param Xcloner $xcloner_container
169
+	 */
170
+	public function __construct(Xcloner $xcloner_container)
171
+	{
172
+		$this->xcloner_sanitization = $xcloner_container->get_xcloner_sanitization();
173
+		$this->xcloner_file_system = $xcloner_container->get_xcloner_filesystem();
174
+		$this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_remote_storage");
175
+		$this->xcloner = $xcloner_container;
176
+
177
+		foreach ($this->storage_fields as $main_key => $array) {
178
+
179
+			if (is_array($array)) {
180
+				foreach ($array as $key => $type) {
181
+
182
+					if ($type == "raw") {
183
+						add_filter("pre_update_option_" . $this->storage_fields['option_prefix'] . $key,
184
+							function ($value) {
185
+
186
+								return $this->simple_crypt($value, 'e');
187
+
188
+							}, 10, 1);
189
+
190
+						add_filter("option_" . $this->storage_fields['option_prefix'] . $key, function ($value) {
191
+
192
+							return $this->simple_crypt($value, 'd');
193
+
194
+						}, 10, 1);
195
+					}
196
+
197
+				}
198
+			}
199
+		}
200
+
201
+	}
202
+
203
+	/**
204
+	 * Encrypts and Decrypt a string based on openssl lib
205
+	 *
206
+	 * @param $string
207
+	 * @param string $action
208
+	 * @return string
209
+	 */
210
+	private function simple_crypt($string, $action = 'e')
211
+	{
212
+		// you may change these values to your own
213
+		$secret_key = NONCE_KEY;
214
+		$secret_iv = NONCE_SALT;
215
+
216
+		if (!$string) {
217
+			//we do no encryption for empty data
218
+			return $string;
219
+		}
220
+
221
+		$output = $string;
222
+		$encrypt_method = "AES-256-CBC";
223
+		$key = hash('sha256', $secret_key);
224
+		$iv = substr(hash('sha256', $secret_iv), 0, 16);
225
+
226
+		if ($action == 'e' && function_exists('openssl_encrypt')) {
227
+			$output = base64_encode(openssl_encrypt($string, $encrypt_method, $key, 0, $iv));
228
+		} else {
229
+			if ($action == 'd' && function_exists('openssl_decrypt') && base64_decode($string)) {
230
+				$decrypt = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
231
+				if ($decrypt) {
232
+					//we check if decrypt was succesful
233
+					$output = $decrypt;
234
+				}
235
+			}
236
+		}
237
+
238
+		return $output;
239
+	}
240
+
241
+	private function get_xcloner_container()
242
+	{
243
+		return $this->xcloner;
244
+	}
245
+
246
+	public function get_available_storages()
247
+	{
248
+		$return = array();
249
+		foreach ($this->storage_fields as $storage => $data) {
250
+			$check_field = $this->storage_fields["option_prefix"] . $storage . "_enable";
251
+			if (get_option($check_field)) {
252
+				$return[$storage] = $data['text'];
253
+			}
254
+		}
255
+
256
+		return $return;
257
+	}
258
+
259
+	public function save($action = "ftp")
260
+	{
261
+		if (!$action) {
262
+			return false;
263
+		}
264
+
265
+		$storage = $this->xcloner_sanitization->sanitize_input_as_string($action);
266
+		$this->logger->debug(sprintf("Saving the remote storage %s options", strtoupper($action)));
267
+
268
+		if (is_array($this->storage_fields[$storage])) {
269
+			foreach ($this->storage_fields[$storage] as $field => $validation) {
270
+				$check_field = $this->storage_fields["option_prefix"] . $field;
271
+				$sanitize_method = "sanitize_input_as_" . $validation;
272
+
273
+				if (!isset($_POST[$check_field])) {
274
+					$_POST[$check_field] = 0;
275
+				}
276
+
277
+				if (!method_exists($this->xcloner_sanitization, $sanitize_method)) {
278
+					$sanitize_method = "sanitize_input_as_string";
279
+				}
280
+
281
+				$sanitized_value = $this->xcloner_sanitization->$sanitize_method(stripslashes($_POST[$check_field]));
282
+				update_option($check_field, $sanitized_value);
283
+			}
284
+
285
+			$this->xcloner->trigger_message(__("%s storage settings saved.", 'xcloner-backup-and-restore'), "success",
286
+				$this->storage_fields[$action]['text']);
287
+		}
288
+
289
+	}
290
+
291
+	public function check($action = "ftp")
292
+	{
293
+		try {
294
+			$this->verify_filesystem($action);
295
+			$this->xcloner->trigger_message(__("%s connection is valid.", 'xcloner-backup-and-restore'), "success",
296
+				$this->storage_fields[$action]['text']);
297
+			$this->logger->debug(sprintf("Connection to remote storage %s is valid", strtoupper($action)));
298
+		} catch (Exception $e) {
299
+			$this->xcloner->trigger_message("%s connection error: " . $e->getMessage(), "error",
300
+				$this->storage_fields[$action]['text']);
301
+		}
302
+	}
303
+
304
+	/**
305
+	 * @param string $storage_type
306
+	 */
307
+	public function verify_filesystem($storage_type)
308
+	{
309
+		$method = "get_" . $storage_type . "_filesystem";
310
+
311
+		$this->logger->info(sprintf("Checking validity of the remote storage %s filesystem",
312
+			strtoupper($storage_type)));
313
+
314
+		if (!method_exists($this, $method)) {
315
+			return false;
316
+		}
317
+
318
+		list($adapter, $filesystem) = $this->$method();
319
+
320
+		$test_file = substr(".xcloner_" . md5(time()), 0, 15);
321
+
322
+		if ($storage_type == "gdrive") {
323
+			if (!is_array($filesystem->listContents())) {
324
+				throw new Exception(__("Could not read data", 'xcloner-backup-and-restore'));
325
+			}
326
+			$this->logger->debug(sprintf("I can list data from remote storage %s", strtoupper($storage_type)));
327
+
328
+			return true;
329
+		}
330
+
331
+		//testing write access
332
+		if (!$filesystem->write($test_file, "data")) {
333
+			throw new Exception(__("Could not write data", 'xcloner-backup-and-restore'));
334
+		}
335
+		$this->logger->debug(sprintf("I can write data to remote storage %s", strtoupper($storage_type)));
336
+
337
+		//testing read access
338
+		if (!$filesystem->has($test_file)) {
339
+			throw new Exception(__("Could not read data", 'xcloner-backup-and-restore'));
340
+		}
341
+		$this->logger->debug(sprintf("I can read data to remote storage %s", strtoupper($storage_type)));
342
+
343
+		//delete test file
344
+		if (!$filesystem->delete($test_file)) {
345
+			throw new Exception(__("Could not delete data", 'xcloner-backup-and-restore'));
346
+		}
347
+		$this->logger->debug(sprintf("I can delete data to remote storage %s", strtoupper($storage_type)));
348
+
349
+		return true;
350
+	}
351
+
352
+	public function upload_backup_to_storage($file, $storage)
353
+	{
354
+		if (!$this->xcloner_file_system->get_storage_filesystem()->has($file)) {
355
+			$this->logger->info(sprintf("File not found %s in local storage", $file));
356
+
357
+			return false;
358
+		}
359
+
360
+		$method = "get_" . $storage . "_filesystem";
361
+
362
+		if (!method_exists($this, $method)) {
363
+			return false;
364
+		}
365
+
366
+		list($remote_storage_adapter, $remote_storage_filesystem) = $this->$method();
367
+
368
+		//doing remote storage cleaning here
369
+		$this->clean_remote_storage($storage, $remote_storage_filesystem);
370
+
371
+		$this->logger->info(sprintf("Transferring backup %s to remote storage %s", $file, strtoupper($storage)),
372
+			array(""));
373
+
374
+		/*if(!$this->xcloner_file_system->get_storage_filesystem()->has($file))
375
+        {
355 376
             $this->logger->info(sprintf("File not found %s in local storage", $file));
356
-
357 377
             return false;
358
-        }
359
-
360
-        $method = "get_" . $storage . "_filesystem";
361
-
362
-        if (!method_exists($this, $method)) {
363
-            return false;
364
-        }
378
+        }*/
365 379
 
366
-        list($remote_storage_adapter, $remote_storage_filesystem) = $this->$method();
380
+		$backup_file_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($file);
367 381
 
368
-        //doing remote storage cleaning here
369
-        $this->clean_remote_storage($storage, $remote_storage_filesystem);
382
+		if (!$remote_storage_filesystem->writeStream($file, $backup_file_stream)) {
383
+			$this->logger->info(sprintf("Could not transfer file %s", $file));
370 384
 
371
-        $this->logger->info(sprintf("Transferring backup %s to remote storage %s", $file, strtoupper($storage)),
372
-            array(""));
385
+			return false;
386
+		}
373 387
 
374
-        /*if(!$this->xcloner_file_system->get_storage_filesystem()->has($file))
375
-        {
376
-            $this->logger->info(sprintf("File not found %s in local storage", $file));
377
-            return false;
378
-        }*/
388
+		if ($this->xcloner_file_system->is_multipart($file)) {
389
+			$parts = $this->xcloner_file_system->get_multipart_files($file);
390
+			if (is_array($parts)) {
391
+				foreach ($parts as $part_file) {
392
+					$this->logger->info(sprintf("Transferring backup %s to remote storage %s", $part_file,
393
+						strtoupper($storage)), array(""));
379 394
 
380
-        $backup_file_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($file);
395
+					$backup_file_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($part_file);
396
+					if (!$remote_storage_filesystem->writeStream($part_file, $backup_file_stream)) {
397
+						return false;
398
+					}
399
+				}
400
+			}
401
+		}
381 402
 
382
-        if (!$remote_storage_filesystem->writeStream($file, $backup_file_stream)) {
383
-            $this->logger->info(sprintf("Could not transfer file %s", $file));
403
+		$this->logger->info(sprintf("Upload done, disconnecting from remote storage %s", strtoupper($storage)));
384 404
 
385
-            return false;
386
-        }
405
+		return true;
387 406
 
388
-        if ($this->xcloner_file_system->is_multipart($file)) {
389
-            $parts = $this->xcloner_file_system->get_multipart_files($file);
390
-            if (is_array($parts)) {
391
-                foreach ($parts as $part_file) {
392
-                    $this->logger->info(sprintf("Transferring backup %s to remote storage %s", $part_file,
393
-                        strtoupper($storage)), array(""));
407
+	}
394 408
 
395
-                    $backup_file_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($part_file);
396
-                    if (!$remote_storage_filesystem->writeStream($part_file, $backup_file_stream)) {
397
-                        return false;
398
-                    }
399
-                }
400
-            }
401
-        }
409
+	public function copy_backup_remote_to_local($file, $storage)
410
+	{
411
+		$method = "get_" . $storage . "_filesystem";
402 412
 
403
-        $this->logger->info(sprintf("Upload done, disconnecting from remote storage %s", strtoupper($storage)));
413
+		$target_filename = $file;
404 414
 
405
-        return true;
415
+		if (!method_exists($this, $method)) {
416
+			return false;
417
+		}
406 418
 
407
-    }
419
+		list($remote_storage_adapter, $remote_storage_filesystem) = $this->$method();
408 420
 
409
-    public function copy_backup_remote_to_local($file, $storage)
410
-    {
411
-        $method = "get_" . $storage . "_filesystem";
421
+		if (!$remote_storage_filesystem->has($file)) {
422
+			$this->logger->info(sprintf("File not found %s in remote storage %s", $file, strtoupper($storage)));
412 423
 
413
-        $target_filename = $file;
424
+			return false;
425
+		}
414 426
 
415
-        if (!method_exists($this, $method)) {
416
-            return false;
417
-        }
427
+		if ($storage == "gdrive") {
428
+			$metadata = $remote_storage_filesystem->getMetadata($file);
429
+			$target_filename = $metadata['filename'] . "." . $metadata['extension'];
430
+		}
418 431
 
419
-        list($remote_storage_adapter, $remote_storage_filesystem) = $this->$method();
432
+		$this->logger->info(sprintf("Transferring backup %s to local storage from %s storage", $file,
433
+			strtoupper($storage)), array(""));
420 434
 
421
-        if (!$remote_storage_filesystem->has($file)) {
422
-            $this->logger->info(sprintf("File not found %s in remote storage %s", $file, strtoupper($storage)));
435
+		$backup_file_stream = $remote_storage_filesystem->readStream($file);
423 436
 
424
-            return false;
425
-        }
437
+		if (!$this->xcloner_file_system->get_storage_filesystem()->writeStream($target_filename, $backup_file_stream)) {
438
+			$this->logger->info(sprintf("Could not transfer file %s", $file));
426 439
 
427
-        if ($storage == "gdrive") {
428
-            $metadata = $remote_storage_filesystem->getMetadata($file);
429
-            $target_filename = $metadata['filename'] . "." . $metadata['extension'];
430
-        }
440
+			return false;
441
+		}
431 442
 
432
-        $this->logger->info(sprintf("Transferring backup %s to local storage from %s storage", $file,
433
-            strtoupper($storage)), array(""));
443
+		if ($this->xcloner_file_system->is_multipart($target_filename)) {
444
+			$parts = $this->xcloner_file_system->get_multipart_files($file, $storage);
445
+			if (is_array($parts)) {
446
+				foreach ($parts as $part_file) {
447
+					$this->logger->info(sprintf("Transferring backup %s to local storage from %s storage", $part_file,
448
+						strtoupper($storage)), array(""));
434 449
 
435
-        $backup_file_stream = $remote_storage_filesystem->readStream($file);
450
+					$backup_file_stream = $remote_storage_filesystem->readStream($part_file);
451
+					if (!$this->xcloner_file_system->get_storage_filesystem()->writeStream($part_file,
452
+						$backup_file_stream)) {
453
+						return false;
454
+					}
455
+				}
456
+			}
457
+		}
436 458
 
437
-        if (!$this->xcloner_file_system->get_storage_filesystem()->writeStream($target_filename, $backup_file_stream)) {
438
-            $this->logger->info(sprintf("Could not transfer file %s", $file));
459
+		$this->logger->info(sprintf("Upload done, disconnecting from remote storage %s", strtoupper($storage)));
439 460
 
440
-            return false;
441
-        }
461
+		return true;
442 462
 
443
-        if ($this->xcloner_file_system->is_multipart($target_filename)) {
444
-            $parts = $this->xcloner_file_system->get_multipart_files($file, $storage);
445
-            if (is_array($parts)) {
446
-                foreach ($parts as $part_file) {
447
-                    $this->logger->info(sprintf("Transferring backup %s to local storage from %s storage", $part_file,
448
-                        strtoupper($storage)), array(""));
449
-
450
-                    $backup_file_stream = $remote_storage_filesystem->readStream($part_file);
451
-                    if (!$this->xcloner_file_system->get_storage_filesystem()->writeStream($part_file,
452
-                        $backup_file_stream)) {
453
-                        return false;
454
-                    }
455
-                }
456
-            }
457
-        }
458
-
459
-        $this->logger->info(sprintf("Upload done, disconnecting from remote storage %s", strtoupper($storage)));
460
-
461
-        return true;
463
+	}
462 464
 
463
-    }
464
-
465
-    public function clean_remote_storage($storage, $remote_storage_filesystem)
466
-    {
467
-        $check_field = $this->storage_fields["option_prefix"] . $storage . "_cleanup_days";
468
-        if ($expire_days = get_option($check_field)) {
469
-            $this->logger->info(sprintf("Doing %s remote storage cleanup for %s days limit", strtoupper($storage),
470
-                $expire_days));
471
-            $files = $remote_storage_filesystem->listContents();
465
+	public function clean_remote_storage($storage, $remote_storage_filesystem)
466
+	{
467
+		$check_field = $this->storage_fields["option_prefix"] . $storage . "_cleanup_days";
468
+		if ($expire_days = get_option($check_field)) {
469
+			$this->logger->info(sprintf("Doing %s remote storage cleanup for %s days limit", strtoupper($storage),
470
+				$expire_days));
471
+			$files = $remote_storage_filesystem->listContents();
472 472
 
473
-            $current_timestamp = strtotime("-" . $expire_days . " days");
473
+			$current_timestamp = strtotime("-" . $expire_days . " days");
474 474
 
475
-            if (is_array($files)) {
476
-                foreach ($files as $file) {
477
-                    $file['timestamp'] = $remote_storage_filesystem->getTimestamp($file['path']);
475
+			if (is_array($files)) {
476
+				foreach ($files as $file) {
477
+					$file['timestamp'] = $remote_storage_filesystem->getTimestamp($file['path']);
478 478
 
479
-                    if ($current_timestamp >= $file['timestamp']) {
480
-                        $remote_storage_filesystem->delete($file['path']);
481
-                        $this->logger->info("Deleting remote file " . $file['path'] . " matching rule", array(
482
-                            "RETENTION LIMIT TIMESTAMP",
483
-                            $file['timestamp'] . " =< " . $expire_days
484
-                        ));
485
-                    }
479
+					if ($current_timestamp >= $file['timestamp']) {
480
+						$remote_storage_filesystem->delete($file['path']);
481
+						$this->logger->info("Deleting remote file " . $file['path'] . " matching rule", array(
482
+							"RETENTION LIMIT TIMESTAMP",
483
+							$file['timestamp'] . " =< " . $expire_days
484
+						));
485
+					}
486 486
 
487
-                }
488
-            }
489
-        }
490
-    }
487
+				}
488
+			}
489
+		}
490
+	}
491 491
 
492
-    public function get_azure_filesystem()
493
-    {
494
-        $this->logger->info(sprintf("Creating the AZURE BLOB remote storage connection"), array(""));
492
+	public function get_azure_filesystem()
493
+	{
494
+		$this->logger->info(sprintf("Creating the AZURE BLOB remote storage connection"), array(""));
495 495
 
496
-        if (version_compare(phpversion(), '5.6.0', '<')) {
497
-            throw new Exception("AZURE BLOB requires PHP 5.6 to be installed!");
498
-        }
496
+		if (version_compare(phpversion(), '5.6.0', '<')) {
497
+			throw new Exception("AZURE BLOB requires PHP 5.6 to be installed!");
498
+		}
499 499
 
500
-        if (!class_exists('XmlWriter')) {
501
-            throw new Exception("AZURE BLOB requires libxml PHP module to be installed with XmlWriter class enabled!");
502
-        }
500
+		if (!class_exists('XmlWriter')) {
501
+			throw new Exception("AZURE BLOB requires libxml PHP module to be installed with XmlWriter class enabled!");
502
+		}
503 503
 
504
-        $endpoint = sprintf(
505
-            'DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s',
506
-            get_option("xcloner_azure_account_name"),
507
-            get_option("xcloner_azure_api_key")
508
-        );
504
+		$endpoint = sprintf(
505
+			'DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s',
506
+			get_option("xcloner_azure_account_name"),
507
+			get_option("xcloner_azure_api_key")
508
+		);
509 509
 
510
-        $blobRestProxy = ServicesBuilder::getInstance()->createBlobService($endpoint);
510
+		$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($endpoint);
511 511
 
512
-        $adapter = new AzureAdapter($blobRestProxy, get_option("xcloner_azure_container"));
512
+		$adapter = new AzureAdapter($blobRestProxy, get_option("xcloner_azure_container"));
513 513
 
514
-        $filesystem = new Filesystem($adapter, new Config([
515
-            'disable_asserts' => true,
516
-        ]));
514
+		$filesystem = new Filesystem($adapter, new Config([
515
+			'disable_asserts' => true,
516
+		]));
517 517
 
518
-        return array($adapter, $filesystem);
519
-    }
518
+		return array($adapter, $filesystem);
519
+	}
520 520
 
521
-    public function get_dropbox_filesystem()
522
-    {
523
-        $this->logger->info(sprintf("Creating the DROPBOX remote storage connection"), array(""));
521
+	public function get_dropbox_filesystem()
522
+	{
523
+		$this->logger->info(sprintf("Creating the DROPBOX remote storage connection"), array(""));
524 524
 
525
-        if (version_compare(phpversion(), '5.6.0', '<')) {
526
-            throw new Exception("DROPBOX requires PHP 5.6 to be installed!");
527
-        }
525
+		if (version_compare(phpversion(), '5.6.0', '<')) {
526
+			throw new Exception("DROPBOX requires PHP 5.6 to be installed!");
527
+		}
528 528
 
529
-        $client = new DropboxClient(get_option("xcloner_dropbox_access_token"));
530
-        $adapter = new DropboxAdapter($client, get_option("xcloner_dropbox_prefix"));
529
+		$client = new DropboxClient(get_option("xcloner_dropbox_access_token"));
530
+		$adapter = new DropboxAdapter($client, get_option("xcloner_dropbox_prefix"));
531 531
 
532
-        $filesystem = new Filesystem($adapter, new Config([
533
-            'disable_asserts' => true,
534
-        ]));
532
+		$filesystem = new Filesystem($adapter, new Config([
533
+			'disable_asserts' => true,
534
+		]));
535 535
 
536
-        return array($adapter, $filesystem);
537
-    }
536
+		return array($adapter, $filesystem);
537
+	}
538 538
 
539
-    public function get_aws_filesystem()
540
-    {
541
-        $this->logger->info(sprintf("Creating the S3 remote storage connection"), array(""));
539
+	public function get_aws_filesystem()
540
+	{
541
+		$this->logger->info(sprintf("Creating the S3 remote storage connection"), array(""));
542 542
 
543
-        if (version_compare(phpversion(), '5.6.0', '<')) {
544
-            throw new Exception("S3 class requires PHP 5.6 to be installed!");
545
-        }
543
+		if (version_compare(phpversion(), '5.6.0', '<')) {
544
+			throw new Exception("S3 class requires PHP 5.6 to be installed!");
545
+		}
546 546
 
547
-        if (!class_exists('XmlWriter')) {
548
-            throw new Exception("AZURE BLOB requires libxml PHP module to be installed with XmlWriter class enabled!");
549
-        }
547
+		if (!class_exists('XmlWriter')) {
548
+			throw new Exception("AZURE BLOB requires libxml PHP module to be installed with XmlWriter class enabled!");
549
+		}
550 550
 
551 551
 
552
-        $credentials = array(
553
-            'credentials' => array(
554
-                'key' => get_option("xcloner_aws_key"),
555
-                'secret' => get_option("xcloner_aws_secret")
556
-            ),
557
-            'region' => get_option("xcloner_aws_region"),
558
-            'version' => 'latest',
559
-        );
552
+		$credentials = array(
553
+			'credentials' => array(
554
+				'key' => get_option("xcloner_aws_key"),
555
+				'secret' => get_option("xcloner_aws_secret")
556
+			),
557
+			'region' => get_option("xcloner_aws_region"),
558
+			'version' => 'latest',
559
+		);
560 560
 
561
-        if (get_option('xcloner_aws_endpoint') != "" && !get_option("xcloner_aws_region")) {
561
+		if (get_option('xcloner_aws_endpoint') != "" && !get_option("xcloner_aws_region")) {
562 562
 
563
-            $credentials['endpoint'] = get_option('xcloner_aws_endpoint');
564
-            #$credentials['use_path_style_endpoint'] = true;
565
-            #$credentials['bucket_endpoint'] = false;
563
+			$credentials['endpoint'] = get_option('xcloner_aws_endpoint');
564
+			#$credentials['use_path_style_endpoint'] = true;
565
+			#$credentials['bucket_endpoint'] = false;
566 566
 
567 567
 
568
-        }
568
+		}
569 569
 
570
-        $client = new S3Client($credentials);
570
+		$client = new S3Client($credentials);
571 571
 
572
-        $adapter = new AwsS3Adapter($client, get_option("xcloner_aws_bucket_name"), get_option("xcloner_aws_prefix"));
573
-        $filesystem = new Filesystem($adapter, new Config([
574
-            'disable_asserts' => true,
575
-        ]));
572
+		$adapter = new AwsS3Adapter($client, get_option("xcloner_aws_bucket_name"), get_option("xcloner_aws_prefix"));
573
+		$filesystem = new Filesystem($adapter, new Config([
574
+			'disable_asserts' => true,
575
+		]));
576 576
 
577
-        return array($adapter, $filesystem);
578
-    }
577
+		return array($adapter, $filesystem);
578
+	}
579 579
 
580
-    public function get_backblaze_filesystem()
581
-    {
582
-        $this->logger->info(sprintf("Creating the BACKBLAZE remote storage connection"), array(""));
580
+	public function get_backblaze_filesystem()
581
+	{
582
+		$this->logger->info(sprintf("Creating the BACKBLAZE remote storage connection"), array(""));
583 583
 
584
-        if (version_compare(phpversion(), '5.6.0', '<')) {
585
-            throw new Exception("BACKBLAZE API requires PHP 5.6 to be installed!");
586
-        }
584
+		if (version_compare(phpversion(), '5.6.0', '<')) {
585
+			throw new Exception("BACKBLAZE API requires PHP 5.6 to be installed!");
586
+		}
587 587
 
588 588
 
589
-        $client = new B2Client(get_option("xcloner_backblaze_account_id"),
590
-            get_option("xcloner_backblaze_application_key"));
591
-        $adapter = new BackblazeAdapter($client, get_option("xcloner_backblaze_bucket_name"));
589
+		$client = new B2Client(get_option("xcloner_backblaze_account_id"),
590
+			get_option("xcloner_backblaze_application_key"));
591
+		$adapter = new BackblazeAdapter($client, get_option("xcloner_backblaze_bucket_name"));
592 592
 
593
-        $filesystem = new Filesystem($adapter, new Config([
594
-            'disable_asserts' => true,
595
-        ]));
593
+		$filesystem = new Filesystem($adapter, new Config([
594
+			'disable_asserts' => true,
595
+		]));
596 596
 
597
-        return array($adapter, $filesystem);
598
-    }
597
+		return array($adapter, $filesystem);
598
+	}
599 599
 
600
-    public function get_webdav_filesystem()
601
-    {
602
-        $this->logger->info(sprintf("Creating the WEBDAV remote storage connection"), array(""));
600
+	public function get_webdav_filesystem()
601
+	{
602
+		$this->logger->info(sprintf("Creating the WEBDAV remote storage connection"), array(""));
603 603
 
604
-        if (version_compare(phpversion(), '5.6.0', '<')) {
605
-            throw new Exception("WEBDAV API requires PHP 5.6 to be installed!");
606
-        }
604
+		if (version_compare(phpversion(), '5.6.0', '<')) {
605
+			throw new Exception("WEBDAV API requires PHP 5.6 to be installed!");
606
+		}
607 607
 
608
-        $settings = array(
609
-            'baseUri' => get_option("xcloner_webdav_url"),
610
-            'userName' => get_option("xcloner_webdav_username"),
611
-            'password' => get_option("xcloner_webdav_password"),
612
-            //'proxy' => 'locahost:8888',
613
-        );
608
+		$settings = array(
609
+			'baseUri' => get_option("xcloner_webdav_url"),
610
+			'userName' => get_option("xcloner_webdav_username"),
611
+			'password' => get_option("xcloner_webdav_password"),
612
+			//'proxy' => 'locahost:8888',
613
+		);
614 614
 
615 615
 
616
-        $client = new SabreClient($settings);
617
-        $adapter = new WebDAVAdapter($client, get_option("xcloner_webdav_target_folder"));
618
-        $filesystem = new Filesystem($adapter, new Config([
619
-            'disable_asserts' => true,
620
-        ]));
616
+		$client = new SabreClient($settings);
617
+		$adapter = new WebDAVAdapter($client, get_option("xcloner_webdav_target_folder"));
618
+		$filesystem = new Filesystem($adapter, new Config([
619
+			'disable_asserts' => true,
620
+		]));
621 621
 
622
-        return array($adapter, $filesystem);
623
-    }
622
+		return array($adapter, $filesystem);
623
+	}
624 624
 
625 625
 
626
-    public function gdrive_construct()
627
-    {
626
+	public function gdrive_construct()
627
+	{
628 628
 
629
-        //if((function_exists("is_plugin_active") && !is_plugin_active("xcloner-google-drive/xcloner-google-drive.php")) || !file_exists(__DIR__ . "/../../xcloner-google-drive/vendor/autoload.php"))
630
-        if (!class_exists('Google_Client')) {
631
-            return false;
632
-        }
629
+		//if((function_exists("is_plugin_active") && !is_plugin_active("xcloner-google-drive/xcloner-google-drive.php")) || !file_exists(__DIR__ . "/../../xcloner-google-drive/vendor/autoload.php"))
630
+		if (!class_exists('Google_Client')) {
631
+			return false;
632
+		}
633 633
 
634
-        //require_once(__DIR__ . "/../../xcloner-google-drive/vendor/autoload.php");
634
+		//require_once(__DIR__ . "/../../xcloner-google-drive/vendor/autoload.php");
635 635
 
636
-        $client = new \Google_Client();
637
-        $client->setApplicationName($this->gdrive_app_name);
638
-        $client->setClientId(get_option("xcloner_gdrive_client_id"));
639
-        $client->setClientSecret(get_option("xcloner_gdrive_client_secret"));
636
+		$client = new \Google_Client();
637
+		$client->setApplicationName($this->gdrive_app_name);
638
+		$client->setClientId(get_option("xcloner_gdrive_client_id"));
639
+		$client->setClientSecret(get_option("xcloner_gdrive_client_secret"));
640 640
 
641
-        //$redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']."?page=xcloner_remote_storage_page&action=set_gdrive_code";
642
-        $redirect_uri = "urn:ietf:wg:oauth:2.0:oob";
641
+		//$redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']."?page=xcloner_remote_storage_page&action=set_gdrive_code";
642
+		$redirect_uri = "urn:ietf:wg:oauth:2.0:oob";
643 643
 
644
-        $client->setRedirectUri($redirect_uri); //urn:ietf:wg:oauth:2.0:oob
645
-        $client->addScope("https://www.googleapis.com/auth/drive");
646
-        $client->setAccessType('offline');
644
+		$client->setRedirectUri($redirect_uri); //urn:ietf:wg:oauth:2.0:oob
645
+		$client->addScope("https://www.googleapis.com/auth/drive");
646
+		$client->setAccessType('offline');
647 647
 
648
-        return $client;
649
-    }
648
+		return $client;
649
+	}
650 650
 
651
-    public function get_gdrive_auth_url()
652
-    {
653
-        $client = $this->gdrive_construct();
651
+	public function get_gdrive_auth_url()
652
+	{
653
+		$client = $this->gdrive_construct();
654 654
 
655
-        if (!$client) {
656
-            return false;
657
-        }
655
+		if (!$client) {
656
+			return false;
657
+		}
658 658
 
659
-        return $authUrl = $client->createAuthUrl();
660
-    }
659
+		return $authUrl = $client->createAuthUrl();
660
+	}
661 661
 
662
-    public function set_access_token($code)
663
-    {
664
-        $client = $this->gdrive_construct();
662
+	public function set_access_token($code)
663
+	{
664
+		$client = $this->gdrive_construct();
665 665
 
666
-        if (!$client) {
667
-            $error_msg = "Could not initialize the Google Drive Class, please check that the xcloner-google-drive plugin is enabled...";
668
-            $this->logger->error($error_msg);
666
+		if (!$client) {
667
+			$error_msg = "Could not initialize the Google Drive Class, please check that the xcloner-google-drive plugin is enabled...";
668
+			$this->logger->error($error_msg);
669 669
 
670
-            return false;
671
-        }
670
+			return false;
671
+		}
672 672
 
673
-        $token = $client->fetchAccessTokenWithAuthCode($code);
674
-        $client->setAccessToken($token);
673
+		$token = $client->fetchAccessTokenWithAuthCode($code);
674
+		$client->setAccessToken($token);
675 675
 
676
-        update_option("xcloner_gdrive_access_token", $token['access_token']);
677
-        update_option("xcloner_gdrive_refresh_token", $token['refresh_token']);
676
+		update_option("xcloner_gdrive_access_token", $token['access_token']);
677
+		update_option("xcloner_gdrive_refresh_token", $token['refresh_token']);
678 678
 
679
-        $redirect_url = ('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . "?page=xcloner_remote_storage_page#gdrive");
679
+		$redirect_url = ('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . "?page=xcloner_remote_storage_page#gdrive");
680 680
 
681
-        ?>
681
+		?>
682 682
         <script>
683 683
             window.location = '<?php echo $redirect_url?>';
684 684
         </script>
685 685
         <?php
686 686
 
687
-    }
687
+	}
688 688
 
689
-    /*
689
+	/*
690 690
      * php composer.phar remove nao-pon/flysystem-google-drive
691 691
      *
692 692
      */
693
-    public function get_gdrive_filesystem()
694
-    {
693
+	public function get_gdrive_filesystem()
694
+	{
695 695
 
696
-        if (version_compare(phpversion(), '5.6.0', '<')) {
697
-            throw new Exception("Google Drive API requires PHP 5.6 to be installed!");
698
-        }
696
+		if (version_compare(phpversion(), '5.6.0', '<')) {
697
+			throw new Exception("Google Drive API requires PHP 5.6 to be installed!");
698
+		}
699 699
 
700
-        $this->logger->info(sprintf("Creating the Google Drive remote storage connection"), array(""));
700
+		$this->logger->info(sprintf("Creating the Google Drive remote storage connection"), array(""));
701 701
 
702
-        $client = $this->gdrive_construct();
702
+		$client = $this->gdrive_construct();
703 703
 
704
-        if (!$client) {
705
-            $error_msg = "Could not initialize the Google Drive Class, please check that the xcloner-google-drive plugin is enabled...";
706
-            $this->logger->error($error_msg);
707
-            throw new Exception($error_msg);
708
-        }
704
+		if (!$client) {
705
+			$error_msg = "Could not initialize the Google Drive Class, please check that the xcloner-google-drive plugin is enabled...";
706
+			$this->logger->error($error_msg);
707
+			throw new Exception($error_msg);
708
+		}
709 709
 
710
-        $client->refreshToken(get_option("xcloner_gdrive_refresh_token"));
710
+		$client->refreshToken(get_option("xcloner_gdrive_refresh_token"));
711 711
 
712
-        $service = new \Google_Service_Drive($client);
712
+		$service = new \Google_Service_Drive($client);
713 713
 
714
-        if (get_option("xcloner_gdrive_empty_trash", 0)) {
715
-            $this->logger->info(sprintf("Doing a Google Drive emptyTrash call"), array(""));
716
-            $service->files->emptyTrash();
717
-        }
714
+		if (get_option("xcloner_gdrive_empty_trash", 0)) {
715
+			$this->logger->info(sprintf("Doing a Google Drive emptyTrash call"), array(""));
716
+			$service->files->emptyTrash();
717
+		}
718 718
 
719
-        $parent = 'root';
720
-        $dir = basename(get_option("xcloner_gdrive_target_folder"));
719
+		$parent = 'root';
720
+		$dir = basename(get_option("xcloner_gdrive_target_folder"));
721 721
 
722
-        $folderID = get_option("xcloner_gdrive_target_folder");
722
+		$folderID = get_option("xcloner_gdrive_target_folder");
723 723
 
724
-        $tmp = parse_url($folderID);
724
+		$tmp = parse_url($folderID);
725 725
 
726
-        if (isset($tmp['query'])) {
727
-            $folderID = str_replace("id=", "", $tmp['query']);
728
-        }
726
+		if (isset($tmp['query'])) {
727
+			$folderID = str_replace("id=", "", $tmp['query']);
728
+		}
729 729
 
730
-        if (stristr($folderID, "/")) {
731
-            $query = sprintf('mimeType = \'application/vnd.google-apps.folder\' and \'%s\' in parents and name contains \'%s\'',
732
-                $parent, $dir);
733
-            $response = $service->files->listFiles([
734
-                'pageSize' => 1,
735
-                'q' => $query
736
-            ]);
730
+		if (stristr($folderID, "/")) {
731
+			$query = sprintf('mimeType = \'application/vnd.google-apps.folder\' and \'%s\' in parents and name contains \'%s\'',
732
+				$parent, $dir);
733
+			$response = $service->files->listFiles([
734
+				'pageSize' => 1,
735
+				'q' => $query
736
+			]);
737 737
 
738
-            if (sizeof($response)) {
739
-                foreach ($response as $obj) {
740
-                    $folderID = $obj->getId();
741
-                }
742
-            } else {
743
-                $this->xcloner->trigger_message(sprintf(__("Could not find folder ID by name %s",
744
-                    'xcloner-backup-and-restore'), $folderID), "error");
745
-            }
746
-        }
738
+			if (sizeof($response)) {
739
+				foreach ($response as $obj) {
740
+					$folderID = $obj->getId();
741
+				}
742
+			} else {
743
+				$this->xcloner->trigger_message(sprintf(__("Could not find folder ID by name %s",
744
+					'xcloner-backup-and-restore'), $folderID), "error");
745
+			}
746
+		}
747 747
 
748
-        $this->logger->info(sprintf("Using target folder with ID %s on the remote storage", $folderID));
748
+		$this->logger->info(sprintf("Using target folder with ID %s on the remote storage", $folderID));
749 749
 
750
-        if (class_exists('XCloner_Google_Drive_Adapter')) {
751
-            $adapter = new XCloner_Google_Drive_Adapter($service, $folderID);
752
-        } else {
753
-            $adapter = new \Hypweb\Flysystem\GoogleDrive\GoogleDriveAdapter($service, $folderID);
754
-        }
750
+		if (class_exists('XCloner_Google_Drive_Adapter')) {
751
+			$adapter = new XCloner_Google_Drive_Adapter($service, $folderID);
752
+		} else {
753
+			$adapter = new \Hypweb\Flysystem\GoogleDrive\GoogleDriveAdapter($service, $folderID);
754
+		}
755 755
 
756
-        $filesystem = new \League\Flysystem\Filesystem($adapter, new Config([
757
-            'disable_asserts' => true,
758
-        ]));
756
+		$filesystem = new \League\Flysystem\Filesystem($adapter, new Config([
757
+			'disable_asserts' => true,
758
+		]));
759 759
 
760 760
 
761
-        return array($adapter, $filesystem);
762
-    }
761
+		return array($adapter, $filesystem);
762
+	}
763 763
 
764
-    public function get_ftp_filesystem()
765
-    {
766
-        $this->logger->info(sprintf("Creating the FTP remote storage connection"), array(""));
764
+	public function get_ftp_filesystem()
765
+	{
766
+		$this->logger->info(sprintf("Creating the FTP remote storage connection"), array(""));
767 767
 
768
-        $adapter = new Adapter([
769
-            'host' => get_option("xcloner_ftp_hostname"),
770
-            'username' => get_option("xcloner_ftp_username"),
771
-            'password' => get_option("xcloner_ftp_password"),
768
+		$adapter = new Adapter([
769
+			'host' => get_option("xcloner_ftp_hostname"),
770
+			'username' => get_option("xcloner_ftp_username"),
771
+			'password' => get_option("xcloner_ftp_password"),
772 772
 
773
-            /** optional config settings */
774
-            'port' => get_option("xcloner_ftp_port", 21),
775
-            'root' => get_option("xcloner_ftp_path"),
776
-            'passive' => get_option("xcloner_ftp_transfer_mode"),
777
-            'ssl' => get_option("xcloner_ftp_ssl_mode"),
778
-            'timeout' => get_option("xcloner_ftp_timeout", 30),
779
-        ]);
773
+			/** optional config settings */
774
+			'port' => get_option("xcloner_ftp_port", 21),
775
+			'root' => get_option("xcloner_ftp_path"),
776
+			'passive' => get_option("xcloner_ftp_transfer_mode"),
777
+			'ssl' => get_option("xcloner_ftp_ssl_mode"),
778
+			'timeout' => get_option("xcloner_ftp_timeout", 30),
779
+		]);
780 780
 
781
-        $adapter->connect();
781
+		$adapter->connect();
782 782
 
783
-        $filesystem = new Filesystem($adapter, new Config([
784
-            'disable_asserts' => true,
785
-        ]));
783
+		$filesystem = new Filesystem($adapter, new Config([
784
+			'disable_asserts' => true,
785
+		]));
786 786
 
787
-        return array($adapter, $filesystem);
788
-    }
787
+		return array($adapter, $filesystem);
788
+	}
789 789
 
790
-    public function get_sftp_filesystem()
791
-    {
792
-        $this->logger->info(sprintf("Creating the SFTP remote storage connection"), array(""));
790
+	public function get_sftp_filesystem()
791
+	{
792
+		$this->logger->info(sprintf("Creating the SFTP remote storage connection"), array(""));
793 793
 
794
-        $adapter = new SftpAdapter([
795
-            'host' => get_option("xcloner_sftp_hostname"),
796
-            'username' => get_option("xcloner_sftp_username"),
797
-            'password' => get_option("xcloner_sftp_password"),
794
+		$adapter = new SftpAdapter([
795
+			'host' => get_option("xcloner_sftp_hostname"),
796
+			'username' => get_option("xcloner_sftp_username"),
797
+			'password' => get_option("xcloner_sftp_password"),
798 798
 
799
-            /** optional config settings */
800
-            'port' => get_option("xcloner_sftp_port", 22),
801
-            'root' => (get_option("xcloner_sftp_path")?get_option("xcloner_sftp_path"):'./'),
802
-            'privateKey' => get_option("xcloner_sftp_private_key"),
803
-            'timeout' => get_option("xcloner_ftp_timeout", 30),
804
-        ]);
805
-
806
-        $adapter->connect();
807
-
808
-        $filesystem = new Filesystem($adapter, new Config([
809
-            'disable_asserts' => true,
810
-        ]));
811
-
812
-        return array($adapter, $filesystem);
813
-    }
814
-
815
-    public function change_storage_status($field, $value)
816
-    {
817
-        $field = $this->xcloner_sanitization->sanitize_input_as_string($field);
818
-        $value = $this->xcloner_sanitization->sanitize_input_as_int($value);
819
-
820
-        return update_option($field, $value);
821
-    }
822
-
823
-    public function get_aws_regions()
824
-    {
825
-        return $this->aws_regions;
826
-    }
799
+			/** optional config settings */
800
+			'port' => get_option("xcloner_sftp_port", 22),
801
+			'root' => (get_option("xcloner_sftp_path")?get_option("xcloner_sftp_path"):'./'),
802
+			'privateKey' => get_option("xcloner_sftp_private_key"),
803
+			'timeout' => get_option("xcloner_ftp_timeout", 30),
804
+		]);
805
+
806
+		$adapter->connect();
807
+
808
+		$filesystem = new Filesystem($adapter, new Config([
809
+			'disable_asserts' => true,
810
+		]));
811
+
812
+		return array($adapter, $filesystem);
813
+	}
814
+
815
+	public function change_storage_status($field, $value)
816
+	{
817
+		$field = $this->xcloner_sanitization->sanitize_input_as_string($field);
818
+		$value = $this->xcloner_sanitization->sanitize_input_as_int($value);
819
+
820
+		return update_option($field, $value);
821
+	}
822
+
823
+	public function get_aws_regions()
824
+	{
825
+		return $this->aws_regions;
826
+	}
827 827
 
828 828
 }
Please login to merge, or discard this patch.
includes/class-xcloner-encryption.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 	 * @param string $iv   The IV key to use.
107 107
 	 * @param bool $verification   Weather we should we try to verify the decryption.
108 108
 	 * @return array|false  Returns array or FALSE if an error occured
109
-     * @throws Exception
109
+	 * @throws Exception
110 110
 	 */
111 111
 	public function encrypt_file($source, $dest = "", $key = "", $start = 0, $iv = 0, $verification = true, $recursive = false)
112 112
 	{
@@ -164,8 +164,8 @@  discard block
 block discarded – undo
164 164
 
165 165
 					fclose($fpOut);
166 166
 
167
-                    unset($ciphertext);
168
-                    unset($plaintext);
167
+					unset($ciphertext);
168
+					unset($plaintext);
169 169
 
170 170
 					if (!feof($fpIn)) {
171 171
 						fclose($fpIn);
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 	 * @param int $start   Start position for reading when doing incremental mode.
241 241
 	 * @param string $iv   The IV key to use.
242 242
 	 * @return array|false  Returns array or FALSE if an error occured
243
-     * @throws Exception
243
+	 * @throws Exception
244 244
 	 */
245 245
 	public function decrypt_file($source, $dest = "", $key = "", $start = 0, $iv = 0, $recursive = false)
246 246
 	{
Please login to merge, or discard this patch.
includes/class-xcloner-file-system.php 1 patch
Indentation   +823 added lines, -823 removed lines patch added patch discarded remove patch
@@ -37,863 +37,863 @@
 block discarded – undo
37 37
 class Xcloner_File_System
38 38
 {
39 39
 
40
-    private $excluded_files = "";
41
-    private $additional_regex_patterns = array();
42
-    private $excluded_files_by_default = array("administrator/backups", "wp-content/backups");
43
-    private $included_files_handler = "backup_files.csv";
44
-    private $temp_dir_handler = ".dir";
45
-    public $filesystem;
46
-    public $tmp_filesystem;
47
-    public $storage_filesystem;
48
-    private $xcloner_container;
49
-    private $diff_timestamp_start = "";
50
-
51
-    private $logger;
52
-    private $start_adapter;
53
-    private $tmp_adapter;
54
-    private $storage_adapter;
55
-    private $xcloner_settings;
56
-    private $start_filesystem;
57
-    private $tmp_filesystem_append;
58
-    private $storage_filesystem_append;
59
-
60
-    private $files_counter;
61
-    private $files_size;
62
-    private $last_logged_file;
63
-    private $folders_to_process_per_session = 25;
64
-    private $backup_archive_extensions = array("tar", "tgz", "tar.gz", "gz", "csv", "encrypted", "decrypted");
65
-    private $backup_name_tags = array('[time]', '[hostname]', '[domain]');
66
-
67
-    /**
68
-     * Xcloner_File_System constructor.
69
-     * @param Xcloner $xcloner_container
70
-     * @param string $hash
71
-     */
72
-    public function __construct(Xcloner $xcloner_container, $hash = "")
73
-    {
74
-        $this->xcloner_container = $xcloner_container;
75
-
76
-        $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_file_system");
77
-        $this->xcloner_settings = $xcloner_container->get_xcloner_settings();
78
-
79
-        try {
80
-
81
-            $this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(), LOCK_EX, '0001');
82
-            $this->start_filesystem = new Filesystem($this->start_adapter, new Config([
83
-                'disable_asserts' => true,
84
-            ]));
85
-
86
-            $this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX, '0001');
87
-            $this->tmp_filesystem = new Filesystem($this->tmp_adapter, new Config([
88
-                'disable_asserts' => true,
89
-            ]));
90
-            $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX | FILE_APPEND, '0001');
91
-            $this->tmp_filesystem_append = new Filesystem($adapter, new Config([
92
-                'disable_asserts' => true,
93
-            ]));
94
-
95
-            $adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), LOCK_EX, '0001');
96
-            $this->storage_filesystem = new Filesystem($adapter, new Config([
97
-                'disable_asserts' => true,
98
-            ]));
99
-
100
-            $this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), FILE_APPEND,
101
-                '0001');
102
-            $this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([
103
-                'disable_asserts' => true,
104
-            ]));
105
-        }catch (Exception $e) {
106
-            $this->logger->error("Filesystem Initialization Error: ".$e->getMessage());
107
-        }
108
-
109
-
110
-        if ($value = get_option('xcloner_directories_to_scan_per_request')) {
111
-            $this->folders_to_process_per_session = $value;
112
-        }
113
-
114
-    }
115
-
116
-    /**
117
-     * Set differential timestamp date
118
-     * @param string $timestamp
119
-     */
120
-    public function set_diff_timestamp_start($timestamp = "")
121
-    {
122
-        if ($timestamp) {
123
-            $this->logger->info(sprintf("Setting Differential Timestamp To %s", date("Y-m-d", $timestamp)), array(
124
-                "FILESYSTEM",
125
-                "DIFF"
126
-            ));
127
-            $this->diff_timestamp_start = $timestamp;
128
-        }
129
-    }
130
-
131
-    /**
132
-     * Gets the differential timestamp date
133
-     * @return string
134
-     */
135
-    public function get_diff_timestamp_start()
136
-    {
137
-        return $this->diff_timestamp_start;
138
-    }
139
-
140
-    private function get_xcloner_container()
141
-    {
142
-        return $this->xcloner_container;
143
-    }
144
-
145
-    public function set_hash($hash)
146
-    {
147
-        $this->xcloner_settings->set_hash($hash);
148
-    }
149
-
150
-    public function get_hash($hash)
151
-    {
152
-        $this->xcloner_settings->get_hash();
153
-    }
154
-
155
-    public function get_tmp_filesystem()
156
-    {
157
-        return $this->tmp_filesystem;
158
-    }
159
-
160
-    public function get_storage_filesystem($remote_storage_selection = "")
161
-    {
162
-        if ($remote_storage_selection != "") {
163
-            $remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
164
-            $method = "get_".$remote_storage_selection."_filesystem";
165
-
166
-            if (!method_exists($remote_storage, $method)) {
167
-                return false;
168
-            }
169
-
170
-            list($adapter, $filesystem) = $remote_storage->$method();
171
-
172
-            return $filesystem;
173
-        }
174
-
175
-        return $this->storage_filesystem;
176
-    }
177
-
178
-    public function get_tmp_filesystem_adapter()
179
-    {
180
-        return $this->tmp_adapter;
181
-    }
182
-
183
-    public function get_tmp_filesystem_append()
184
-    {
185
-        return $this->tmp_filesystem_append;
186
-    }
187
-
188
-    public function get_start_adapter()
189
-    {
190
-        return $this->start_adapter;
191
-    }
192
-
193
-    public function get_start_filesystem()
194
-    {
195
-        return $this->start_filesystem;
196
-    }
197
-
198
-    public function get_logger()
199
-    {
200
-        return $this->logger;
201
-    }
202
-
203
-    public function get_start_path_file_info($file)
204
-    {
205
-        $info = $this->getMetadataFull('start_adapter', $file);
206
-
207
-        return $this->start_filesystem->normalizeFileInfo($info);
208
-    }
209
-
210
-    /**
211
-     * @param string $file
212
-     */
213
-    public function get_storage_path_file_info($file)
214
-    {
215
-        return $this->getMetadataFull('storage_adapter', $file);
216
-    }
217
-
218
-    public function get_included_files_handler($metadata = 0)
219
-    {
220
-        $path = $this->included_files_handler;
221
-        if (!$metadata) {
222
-            return $path;
223
-        }
224
-
225
-        $spl_info = $this->getMetadataFull('tmp_adapter', $path);
226
-
227
-        return $spl_info;
228
-
229
-    }
230
-
231
-    public function get_temp_dir_handler()
232
-    {
233
-        return $this->temp_dir_handler;
234
-    }
235
-
236
-    public function get_latest_backup()
237
-    {
238
-        $files = $this->get_backup_archives_list();
239
-
240
-        if (is_array($files)) {
241
-            $this->sort_by($files, "timestamp", "desc");
242
-        }
243
-
244
-        $new_list = array();
245
-
246
-        foreach ($files as $key => $file) {
247
-            if (!isset($file['parent'])) {
248
-                $new_list[] = ($files[$key]);
249
-            }
250
-        }
251
-
252
-        if (isset($new_list[0])) {
253
-            return $new_list[0];
254
-        }
255
-    }
256
-
257
-    public function get_latest_backups()
258
-    {
259
-        $files = $this->get_backup_archives_list();
260
-
261
-        if (is_array($files)) {
262
-            $this->sort_by($files, "timestamp", "desc");
263
-        }
264
-
265
-        $new_list = array();
266
-
267
-        foreach ($files as $key => $file) {
268
-            if (!isset($file['parent'])) {
269
-                $new_list[] = ($files[$key]);
270
-            }
271
-        }
272
-
273
-        return $new_list;
274
-    }
275
-
276
-    public function get_storage_usage()
277
-    {
278
-        $files = $this->get_backup_archives_list();
279
-        $total = 0;
280
-
281
-        if (is_array($files)) {
282
-            foreach ($files as $file) {
283
-                $total += $file['size'];
284
-            }
285
-        }
286
-
287
-        return $total;
288
-    }
289
-
290
-    public function is_part($backup_name)
291
-    {
292
-        if (stristr($backup_name, "-part")) {
293
-            return true;
294
-        }
295
-
296
-        return false;
297
-    }
298
-
299
-    public function is_multipart($backup_name)
300
-    {
301
-        if (stristr($backup_name, "-multipart")) {
302
-            return true;
303
-        }
304
-
305
-        return false;
306
-    }
307
-
308
-    public function get_backup_size($backup_name)
309
-    {
310
-        $backup_size = $this->get_storage_filesystem()->getSize($backup_name);
311
-        if ($this->is_multipart($backup_name)) {
312
-            $backup_parts = $this->get_multipart_files($backup_name);
313
-            foreach ($backup_parts as $part_file) {
314
-                $backup_size += $this->get_storage_filesystem()->getSize($part_file);
315
-            }
316
-        }
317
-
318
-        return $backup_size;
319
-    }
320
-
321
-    public function get_multipart_files($backup_name, $storage_selection = "")
322
-    {
323
-        $files = array();
324
-
325
-        if ($this->is_multipart($backup_name)) {
326
-            $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name));
327
-            foreach ($lines as $line) {
328
-                if ($line) {
329
-                    $data = str_getcsv($line);
330
-                    $files[] = $data[0];
331
-                }
332
-            }
333
-        }
334
-
335
-        return $files;
336
-    }
337
-
338
-    public function delete_backup_by_name($backup_name, $storage_selection = "")
339
-    {
340
-        if ($this->is_multipart($backup_name)) {
341
-            $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name));
342
-            foreach ($lines as $line) {
343
-                if ($line) {
344
-                    $data = str_getcsv($line);
345
-                    $this->get_storage_filesystem($storage_selection)->delete($data[0]);
346
-                }
347
-            }
348
-        }
349
-
350
-        if ($this->get_storage_filesystem($storage_selection)->delete($backup_name)) {
351
-            $return = true;
352
-        } else {
353
-            $return = false;
354
-        }
355
-
356
-        return $return;
357
-    }
358
-
359
-    public function getMetadataFull($adapter = "storage_adapter", $path)
360
-    {
361
-        $location = $this->$adapter->applyPathPrefix($path);
362
-        $spl_info = new SplFileInfo($location);
363
-
364
-        return ($spl_info);
365
-    }
366
-
367
-
368
-    public function get_backup_archives_list($storage_selection = "")
369
-    {
370
-        $list = array();
371
-
372
-
373
-        if (method_exists($this->get_storage_filesystem($storage_selection), "listContents")) {
374
-            $list = $this->get_storage_filesystem($storage_selection)->listContents();
375
-        }
376
-
377
-        $backup_files = array();
378
-        $parents = array();
379
-
380
-        foreach ($list as $file_info) {
381
-            if (isset($file_info['extension']) and $file_info['extension'] == "csv") {
382
-                $data = array();
383
-
384
-                $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($file_info['path']));
385
-                foreach ($lines as $line) {
386
-                    if ($line) {
387
-                        $data = str_getcsv($line);
388
-                        if (is_array($data)) {
389
-                            $parents[$data[0]] = $file_info['basename'];
390
-                            $file_info['childs'][] = $data;
391
-                            $file_info['size'] += $data[2];
392
-                        }
393
-                    }
394
-                }
395
-
396
-            }
397
-
398
-            if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'],
399
-                    $this->backup_archive_extensions)) {
400
-                $backup_files[$file_info['path']] = $file_info;
401
-            }
402
-        }
403
-
404
-        foreach ($backup_files as $key => $file_info) {
405
-            if (!isset($backup_files[$key]['timestamp'])) {
406
-                //$backup_files[$key]['timestamp'] = $this->get_storage_filesystem($storage_selection)->getTimestamp($file_info['path']);
407
-            }
408
-
409
-            if (isset($parents[$file_info['basename']])) {
410
-                $backup_files[$key]['parent'] = $parents[$file_info['basename']];
411
-            }
412
-        }
413
-
414
-        return $backup_files;
415
-    }
416
-
417
-    public function start_file_recursion($init = 0)
418
-    {
419
-        if ($init) {
420
-            $this->logger->info(sprintf(__("Starting the filesystem scanner on root folder %s"),
421
-                $this->xcloner_settings->get_xcloner_start_path()));
422
-            $this->do_system_init();
423
-        }
424
-
425
-        if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
426
-            //.dir exists, we presume we have files to iterate
427
-            $content = $this->tmp_filesystem->read($this->get_temp_dir_handler());
428
-            $files = array_filter(explode("\n", $content));
429
-            $this->tmp_filesystem->delete($this->get_temp_dir_handler());
430
-
431
-            $counter = 0;
432
-            foreach ($files as $file) {
433
-                if ($counter < $this->folders_to_process_per_session) {
434
-                    $this->build_files_list($file);
435
-                    $counter++;
436
-                } else {
437
-                    $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n");
438
-                }
439
-            }
440
-        } else {
441
-            $this->build_files_list();
442
-        }
443
-
444
-        if ($this->scan_finished()) {
445
-            $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata("index.html");
446
-            $this->store_file($metadata_dumpfile, 'tmp_filesystem');
447
-            $this->files_counter++;
448
-
449
-            //adding included dump file to the included files list
450
-            if ($this->get_tmp_filesystem()->has($this->get_included_files_handler())) {
451
-                $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->get_included_files_handler());
452
-                $this->store_file($metadata_dumpfile, 'tmp_filesystem');
453
-                $this->files_counter++;
454
-            }
455
-
456
-            //adding a default index.html to the temp xcloner folder
457
-            if (!$this->get_tmp_filesystem()->has("index.html")) {
458
-                $this->get_tmp_filesystem()->write("index.html", "");
459
-            }
460
-
461
-            //adding the default log file
462
-            if ($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) {
463
-                $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->xcloner_settings->get_logger_filename(1));
464
-                $this->store_file($metadata_dumpfile, 'tmp_filesystem');
465
-                $this->files_counter++;
466
-            }
467
-
468
-            return false;
469
-        }
470
-
471
-        return true;
472
-    }
473
-
474
-    public function get_backup_attachments()
475
-    {
476
-        $return = array();
477
-
478
-        $files_list_file = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler();
479
-        if (file_exists($files_list_file)) {
480
-            $return[] = $files_list_file;
481
-        }
482
-
483
-        if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) {
484
-            $log_file = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1);
485
-            if (!file_exists($log_file)) {
486
-                $log_file = $this->xcloner_settings->get_xcloner_store_path().DS.$this->xcloner_settings->get_logger_filename();
487
-            }
488
-
489
-            if (file_exists($log_file)) {
490
-                $return[] = $log_file;
491
-            }
492
-        }
493
-
494
-        return $return;
495
-    }
496
-
497
-    public function remove_tmp_filesystem()
498
-    {
499
-        //delete the temporary folder
500
-        $this->logger->debug(sprintf("Deleting the temporary storage folder %s",
501
-            $this->xcloner_settings->get_xcloner_tmp_path()));
502
-
503
-        $contents = $this->get_tmp_filesystem()->listContents();
504
-
505
-        if (is_array($contents)) {
506
-            foreach ($contents as $file_info) {
507
-                $this->get_tmp_filesystem()->delete($file_info['path']);
508
-            }
509
-        }
510
-
511
-        try {
512
-            rmdir($this->xcloner_settings->get_xcloner_tmp_path());
513
-        }catch (Exception $e) {
514
-            //silent continue
515
-        }
516
-
517
-        return;
518
-    }
519
-
520
-    public function cleanup_tmp_directories()
521
-    {
522
-        $this->logger->info(sprintf(("Cleaning up the temporary directories")));
523
-
524
-        $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(false), LOCK_EX, '0001');
525
-        $tmp_filesystem = new Filesystem($adapter, new Config([
526
-            'disable_asserts' => true,
527
-        ]));
528
-
529
-        $contents = $tmp_filesystem->listContents();
530
-
531
-        foreach ($contents as $file) {
532
-
533
-            if (preg_match("/.xcloner-(.*)/", $file['path'])) {
534
-                if ($file['timestamp'] < strtotime("-1days")) {
535
-                    $tmp_filesystem->deleteDir($file['path']);
536
-                    $this->logger->debug(sprintf("Delete temporary directory %s", $file['path']));
537
-                }
538
-            }
539
-        }
540
-
541
-        return true;
542
-    }
543
-
544
-    private function do_system_init()
545
-    {
546
-        $this->files_counter = 0;
547
-
548
-        if (!$this->storage_filesystem->has("index.html")) {
549
-            $this->storage_filesystem->write("index.html", "");
550
-        }
551
-
552
-        if (!$this->tmp_filesystem->has("index.html")) {
553
-            $this->tmp_filesystem->write("index.html", "");
554
-        }
555
-
556
-        if ($this->tmp_filesystem->has($this->get_included_files_handler())) {
557
-            $this->tmp_filesystem->delete($this->get_included_files_handler());
558
-        }
559
-
560
-        if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
561
-            $this->tmp_filesystem->delete($this->get_temp_dir_handler());
562
-        }
563
-    }
564
-
565
-    public function get_scanned_files_num()
566
-    {
567
-        return $this->files_counter;
568
-    }
569
-
570
-    public function get_scanned_files_total_size()
571
-    {
572
-        return $this->files_size;
573
-    }
574
-
575
-    public function last_logged_file()
576
-    {
577
-        return $this->last_logged_file;
578
-    }
579
-
580
-    public static function is_regex($regex)
581
-    {
582
-        return preg_match("/^\^(.*)\$$/i", $regex);
583
-    }
40
+	private $excluded_files = "";
41
+	private $additional_regex_patterns = array();
42
+	private $excluded_files_by_default = array("administrator/backups", "wp-content/backups");
43
+	private $included_files_handler = "backup_files.csv";
44
+	private $temp_dir_handler = ".dir";
45
+	public $filesystem;
46
+	public $tmp_filesystem;
47
+	public $storage_filesystem;
48
+	private $xcloner_container;
49
+	private $diff_timestamp_start = "";
50
+
51
+	private $logger;
52
+	private $start_adapter;
53
+	private $tmp_adapter;
54
+	private $storage_adapter;
55
+	private $xcloner_settings;
56
+	private $start_filesystem;
57
+	private $tmp_filesystem_append;
58
+	private $storage_filesystem_append;
59
+
60
+	private $files_counter;
61
+	private $files_size;
62
+	private $last_logged_file;
63
+	private $folders_to_process_per_session = 25;
64
+	private $backup_archive_extensions = array("tar", "tgz", "tar.gz", "gz", "csv", "encrypted", "decrypted");
65
+	private $backup_name_tags = array('[time]', '[hostname]', '[domain]');
584 66
 
585
-    public function set_excluded_files($excluded_files = array())
586
-    {
587
-        if (!is_array($excluded_files)) {
588
-            $excluded_files = array();
589
-        }
67
+	/**
68
+	 * Xcloner_File_System constructor.
69
+	 * @param Xcloner $xcloner_container
70
+	 * @param string $hash
71
+	 */
72
+	public function __construct(Xcloner $xcloner_container, $hash = "")
73
+	{
74
+		$this->xcloner_container = $xcloner_container;
75
+
76
+		$this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_file_system");
77
+		$this->xcloner_settings = $xcloner_container->get_xcloner_settings();
78
+
79
+		try {
80
+
81
+			$this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(), LOCK_EX, '0001');
82
+			$this->start_filesystem = new Filesystem($this->start_adapter, new Config([
83
+				'disable_asserts' => true,
84
+			]));
85
+
86
+			$this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX, '0001');
87
+			$this->tmp_filesystem = new Filesystem($this->tmp_adapter, new Config([
88
+				'disable_asserts' => true,
89
+			]));
90
+			$adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX | FILE_APPEND, '0001');
91
+			$this->tmp_filesystem_append = new Filesystem($adapter, new Config([
92
+				'disable_asserts' => true,
93
+			]));
94
+
95
+			$adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), LOCK_EX, '0001');
96
+			$this->storage_filesystem = new Filesystem($adapter, new Config([
97
+				'disable_asserts' => true,
98
+			]));
99
+
100
+			$this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), FILE_APPEND,
101
+				'0001');
102
+			$this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([
103
+				'disable_asserts' => true,
104
+			]));
105
+		}catch (Exception $e) {
106
+			$this->logger->error("Filesystem Initialization Error: ".$e->getMessage());
107
+		}
108
+
109
+
110
+		if ($value = get_option('xcloner_directories_to_scan_per_request')) {
111
+			$this->folders_to_process_per_session = $value;
112
+		}
113
+
114
+	}
115
+
116
+	/**
117
+	 * Set differential timestamp date
118
+	 * @param string $timestamp
119
+	 */
120
+	public function set_diff_timestamp_start($timestamp = "")
121
+	{
122
+		if ($timestamp) {
123
+			$this->logger->info(sprintf("Setting Differential Timestamp To %s", date("Y-m-d", $timestamp)), array(
124
+				"FILESYSTEM",
125
+				"DIFF"
126
+			));
127
+			$this->diff_timestamp_start = $timestamp;
128
+		}
129
+	}
130
+
131
+	/**
132
+	 * Gets the differential timestamp date
133
+	 * @return string
134
+	 */
135
+	public function get_diff_timestamp_start()
136
+	{
137
+		return $this->diff_timestamp_start;
138
+	}
139
+
140
+	private function get_xcloner_container()
141
+	{
142
+		return $this->xcloner_container;
143
+	}
144
+
145
+	public function set_hash($hash)
146
+	{
147
+		$this->xcloner_settings->set_hash($hash);
148
+	}
149
+
150
+	public function get_hash($hash)
151
+	{
152
+		$this->xcloner_settings->get_hash();
153
+	}
154
+
155
+	public function get_tmp_filesystem()
156
+	{
157
+		return $this->tmp_filesystem;
158
+	}
159
+
160
+	public function get_storage_filesystem($remote_storage_selection = "")
161
+	{
162
+		if ($remote_storage_selection != "") {
163
+			$remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
164
+			$method = "get_".$remote_storage_selection."_filesystem";
165
+
166
+			if (!method_exists($remote_storage, $method)) {
167
+				return false;
168
+			}
169
+
170
+			list($adapter, $filesystem) = $remote_storage->$method();
171
+
172
+			return $filesystem;
173
+		}
174
+
175
+		return $this->storage_filesystem;
176
+	}
177
+
178
+	public function get_tmp_filesystem_adapter()
179
+	{
180
+		return $this->tmp_adapter;
181
+	}
182
+
183
+	public function get_tmp_filesystem_append()
184
+	{
185
+		return $this->tmp_filesystem_append;
186
+	}
187
+
188
+	public function get_start_adapter()
189
+	{
190
+		return $this->start_adapter;
191
+	}
192
+
193
+	public function get_start_filesystem()
194
+	{
195
+		return $this->start_filesystem;
196
+	}
197
+
198
+	public function get_logger()
199
+	{
200
+		return $this->logger;
201
+	}
202
+
203
+	public function get_start_path_file_info($file)
204
+	{
205
+		$info = $this->getMetadataFull('start_adapter', $file);
206
+
207
+		return $this->start_filesystem->normalizeFileInfo($info);
208
+	}
209
+
210
+	/**
211
+	 * @param string $file
212
+	 */
213
+	public function get_storage_path_file_info($file)
214
+	{
215
+		return $this->getMetadataFull('storage_adapter', $file);
216
+	}
217
+
218
+	public function get_included_files_handler($metadata = 0)
219
+	{
220
+		$path = $this->included_files_handler;
221
+		if (!$metadata) {
222
+			return $path;
223
+		}
224
+
225
+		$spl_info = $this->getMetadataFull('tmp_adapter', $path);
226
+
227
+		return $spl_info;
228
+
229
+	}
230
+
231
+	public function get_temp_dir_handler()
232
+	{
233
+		return $this->temp_dir_handler;
234
+	}
235
+
236
+	public function get_latest_backup()
237
+	{
238
+		$files = $this->get_backup_archives_list();
239
+
240
+		if (is_array($files)) {
241
+			$this->sort_by($files, "timestamp", "desc");
242
+		}
243
+
244
+		$new_list = array();
245
+
246
+		foreach ($files as $key => $file) {
247
+			if (!isset($file['parent'])) {
248
+				$new_list[] = ($files[$key]);
249
+			}
250
+		}
251
+
252
+		if (isset($new_list[0])) {
253
+			return $new_list[0];
254
+		}
255
+	}
256
+
257
+	public function get_latest_backups()
258
+	{
259
+		$files = $this->get_backup_archives_list();
260
+
261
+		if (is_array($files)) {
262
+			$this->sort_by($files, "timestamp", "desc");
263
+		}
264
+
265
+		$new_list = array();
266
+
267
+		foreach ($files as $key => $file) {
268
+			if (!isset($file['parent'])) {
269
+				$new_list[] = ($files[$key]);
270
+			}
271
+		}
272
+
273
+		return $new_list;
274
+	}
275
+
276
+	public function get_storage_usage()
277
+	{
278
+		$files = $this->get_backup_archives_list();
279
+		$total = 0;
280
+
281
+		if (is_array($files)) {
282
+			foreach ($files as $file) {
283
+				$total += $file['size'];
284
+			}
285
+		}
286
+
287
+		return $total;
288
+	}
289
+
290
+	public function is_part($backup_name)
291
+	{
292
+		if (stristr($backup_name, "-part")) {
293
+			return true;
294
+		}
295
+
296
+		return false;
297
+	}
298
+
299
+	public function is_multipart($backup_name)
300
+	{
301
+		if (stristr($backup_name, "-multipart")) {
302
+			return true;
303
+		}
304
+
305
+		return false;
306
+	}
307
+
308
+	public function get_backup_size($backup_name)
309
+	{
310
+		$backup_size = $this->get_storage_filesystem()->getSize($backup_name);
311
+		if ($this->is_multipart($backup_name)) {
312
+			$backup_parts = $this->get_multipart_files($backup_name);
313
+			foreach ($backup_parts as $part_file) {
314
+				$backup_size += $this->get_storage_filesystem()->getSize($part_file);
315
+			}
316
+		}
317
+
318
+		return $backup_size;
319
+	}
320
+
321
+	public function get_multipart_files($backup_name, $storage_selection = "")
322
+	{
323
+		$files = array();
324
+
325
+		if ($this->is_multipart($backup_name)) {
326
+			$lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name));
327
+			foreach ($lines as $line) {
328
+				if ($line) {
329
+					$data = str_getcsv($line);
330
+					$files[] = $data[0];
331
+				}
332
+			}
333
+		}
334
+
335
+		return $files;
336
+	}
337
+
338
+	public function delete_backup_by_name($backup_name, $storage_selection = "")
339
+	{
340
+		if ($this->is_multipart($backup_name)) {
341
+			$lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name));
342
+			foreach ($lines as $line) {
343
+				if ($line) {
344
+					$data = str_getcsv($line);
345
+					$this->get_storage_filesystem($storage_selection)->delete($data[0]);
346
+				}
347
+			}
348
+		}
349
+
350
+		if ($this->get_storage_filesystem($storage_selection)->delete($backup_name)) {
351
+			$return = true;
352
+		} else {
353
+			$return = false;
354
+		}
355
+
356
+		return $return;
357
+	}
358
+
359
+	public function getMetadataFull($adapter = "storage_adapter", $path)
360
+	{
361
+		$location = $this->$adapter->applyPathPrefix($path);
362
+		$spl_info = new SplFileInfo($location);
363
+
364
+		return ($spl_info);
365
+	}
366
+
367
+
368
+	public function get_backup_archives_list($storage_selection = "")
369
+	{
370
+		$list = array();
371
+
372
+
373
+		if (method_exists($this->get_storage_filesystem($storage_selection), "listContents")) {
374
+			$list = $this->get_storage_filesystem($storage_selection)->listContents();
375
+		}
376
+
377
+		$backup_files = array();
378
+		$parents = array();
379
+
380
+		foreach ($list as $file_info) {
381
+			if (isset($file_info['extension']) and $file_info['extension'] == "csv") {
382
+				$data = array();
383
+
384
+				$lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($file_info['path']));
385
+				foreach ($lines as $line) {
386
+					if ($line) {
387
+						$data = str_getcsv($line);
388
+						if (is_array($data)) {
389
+							$parents[$data[0]] = $file_info['basename'];
390
+							$file_info['childs'][] = $data;
391
+							$file_info['size'] += $data[2];
392
+						}
393
+					}
394
+				}
395
+
396
+			}
397
+
398
+			if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'],
399
+					$this->backup_archive_extensions)) {
400
+				$backup_files[$file_info['path']] = $file_info;
401
+			}
402
+		}
403
+
404
+		foreach ($backup_files as $key => $file_info) {
405
+			if (!isset($backup_files[$key]['timestamp'])) {
406
+				//$backup_files[$key]['timestamp'] = $this->get_storage_filesystem($storage_selection)->getTimestamp($file_info['path']);
407
+			}
408
+
409
+			if (isset($parents[$file_info['basename']])) {
410
+				$backup_files[$key]['parent'] = $parents[$file_info['basename']];
411
+			}
412
+		}
413
+
414
+		return $backup_files;
415
+	}
416
+
417
+	public function start_file_recursion($init = 0)
418
+	{
419
+		if ($init) {
420
+			$this->logger->info(sprintf(__("Starting the filesystem scanner on root folder %s"),
421
+				$this->xcloner_settings->get_xcloner_start_path()));
422
+			$this->do_system_init();
423
+		}
424
+
425
+		if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
426
+			//.dir exists, we presume we have files to iterate
427
+			$content = $this->tmp_filesystem->read($this->get_temp_dir_handler());
428
+			$files = array_filter(explode("\n", $content));
429
+			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
430
+
431
+			$counter = 0;
432
+			foreach ($files as $file) {
433
+				if ($counter < $this->folders_to_process_per_session) {
434
+					$this->build_files_list($file);
435
+					$counter++;
436
+				} else {
437
+					$this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n");
438
+				}
439
+			}
440
+		} else {
441
+			$this->build_files_list();
442
+		}
443
+
444
+		if ($this->scan_finished()) {
445
+			$metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata("index.html");
446
+			$this->store_file($metadata_dumpfile, 'tmp_filesystem');
447
+			$this->files_counter++;
448
+
449
+			//adding included dump file to the included files list
450
+			if ($this->get_tmp_filesystem()->has($this->get_included_files_handler())) {
451
+				$metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->get_included_files_handler());
452
+				$this->store_file($metadata_dumpfile, 'tmp_filesystem');
453
+				$this->files_counter++;
454
+			}
455
+
456
+			//adding a default index.html to the temp xcloner folder
457
+			if (!$this->get_tmp_filesystem()->has("index.html")) {
458
+				$this->get_tmp_filesystem()->write("index.html", "");
459
+			}
460
+
461
+			//adding the default log file
462
+			if ($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) {
463
+				$metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->xcloner_settings->get_logger_filename(1));
464
+				$this->store_file($metadata_dumpfile, 'tmp_filesystem');
465
+				$this->files_counter++;
466
+			}
467
+
468
+			return false;
469
+		}
470
+
471
+		return true;
472
+	}
473
+
474
+	public function get_backup_attachments()
475
+	{
476
+		$return = array();
477
+
478
+		$files_list_file = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler();
479
+		if (file_exists($files_list_file)) {
480
+			$return[] = $files_list_file;
481
+		}
482
+
483
+		if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) {
484
+			$log_file = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1);
485
+			if (!file_exists($log_file)) {
486
+				$log_file = $this->xcloner_settings->get_xcloner_store_path().DS.$this->xcloner_settings->get_logger_filename();
487
+			}
488
+
489
+			if (file_exists($log_file)) {
490
+				$return[] = $log_file;
491
+			}
492
+		}
493
+
494
+		return $return;
495
+	}
496
+
497
+	public function remove_tmp_filesystem()
498
+	{
499
+		//delete the temporary folder
500
+		$this->logger->debug(sprintf("Deleting the temporary storage folder %s",
501
+			$this->xcloner_settings->get_xcloner_tmp_path()));
502
+
503
+		$contents = $this->get_tmp_filesystem()->listContents();
504
+
505
+		if (is_array($contents)) {
506
+			foreach ($contents as $file_info) {
507
+				$this->get_tmp_filesystem()->delete($file_info['path']);
508
+			}
509
+		}
510
+
511
+		try {
512
+			rmdir($this->xcloner_settings->get_xcloner_tmp_path());
513
+		}catch (Exception $e) {
514
+			//silent continue
515
+		}
516
+
517
+		return;
518
+	}
519
+
520
+	public function cleanup_tmp_directories()
521
+	{
522
+		$this->logger->info(sprintf(("Cleaning up the temporary directories")));
523
+
524
+		$adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(false), LOCK_EX, '0001');
525
+		$tmp_filesystem = new Filesystem($adapter, new Config([
526
+			'disable_asserts' => true,
527
+		]));
528
+
529
+		$contents = $tmp_filesystem->listContents();
530
+
531
+		foreach ($contents as $file) {
532
+
533
+			if (preg_match("/.xcloner-(.*)/", $file['path'])) {
534
+				if ($file['timestamp'] < strtotime("-1days")) {
535
+					$tmp_filesystem->deleteDir($file['path']);
536
+					$this->logger->debug(sprintf("Delete temporary directory %s", $file['path']));
537
+				}
538
+			}
539
+		}
540
+
541
+		return true;
542
+	}
543
+
544
+	private function do_system_init()
545
+	{
546
+		$this->files_counter = 0;
547
+
548
+		if (!$this->storage_filesystem->has("index.html")) {
549
+			$this->storage_filesystem->write("index.html", "");
550
+		}
551
+
552
+		if (!$this->tmp_filesystem->has("index.html")) {
553
+			$this->tmp_filesystem->write("index.html", "");
554
+		}
555
+
556
+		if ($this->tmp_filesystem->has($this->get_included_files_handler())) {
557
+			$this->tmp_filesystem->delete($this->get_included_files_handler());
558
+		}
559
+
560
+		if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
561
+			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
562
+		}
563
+	}
564
+
565
+	public function get_scanned_files_num()
566
+	{
567
+		return $this->files_counter;
568
+	}
569
+
570
+	public function get_scanned_files_total_size()
571
+	{
572
+		return $this->files_size;
573
+	}
574
+
575
+	public function last_logged_file()
576
+	{
577
+		return $this->last_logged_file;
578
+	}
579
+
580
+	public static function is_regex($regex)
581
+	{
582
+		return preg_match("/^\^(.*)\$$/i", $regex);
583
+	}
584
+
585
+	public function set_excluded_files($excluded_files = array())
586
+	{
587
+		if (!is_array($excluded_files)) {
588
+			$excluded_files = array();
589
+		}
590
+
591
+		foreach ($excluded_files as $excl) {
592
+
593
+			if ($this->is_regex($excl)) {
594
+				$this->additional_regex_patterns[] = $excl;
595
+			}
596
+		}
597
+
598
+		$this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default);
599
+
600
+		return $this->excluded_files;
601
+	}
602
+
603
+	public function get_excluded_files()
604
+	{
605
+		return $this->excluded_files_by_default;
606
+	}
607
+
608
+	public function list_directory($path)
609
+	{
610
+		return $this->start_filesystem->listContents($path);
611
+	}
612
+
613
+	public function build_files_list($folder = "")
614
+	{
615
+		$this->logger->debug(sprintf(("Building the files system list")));
616
+
617
+		//if we start with the root folder(empty value), we initializa the file system
618
+		if (!$folder) {
619
+
620
+		}
621
+
622
+		try {
623
+
624
+			$files = $this->start_filesystem->listContents($folder);
625
+			foreach ($files as $file) {
626
+				if (!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) {
627
+					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"),
628
+						$file['path']), array(
629
+						"FILESYSTEM SCAN",
630
+						"NOT READABLE"
631
+					));
632
+				} elseif (!$matching_pattern = $this->is_excluded($file)) {
633
+					$this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array(
634
+						"FILESYSTEM SCAN",
635
+						"INCLUDE"
636
+					));
637
+					$file['visibility'] = $this->start_filesystem->getVisibility($file['path']);
638
+					if ($this->store_file($file)) {
639
+						$this->files_counter++;
640
+					}
641
+					if (isset($file['size'])) {
642
+						$this->files_size += $file['size'];
643
+					}
644
+
645
+				} else {
646
+					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"),
647
+						$file['path'], $matching_pattern), array(
648
+						"FILESYSTEM SCAN",
649
+						"EXCLUDE"
650
+					));
651
+				}
652
+			}
590 653
 
591
-        foreach ($excluded_files as $excl) {
654
+		}catch (Exception $e) {
592 655
 
593
-            if ($this->is_regex($excl)) {
594
-                $this->additional_regex_patterns[] = $excl;
595
-            }
596
-        }
656
+			$this->logger->error($e->getMessage());
597 657
 
598
-        $this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default);
658
+		}
599 659
 
600
-        return $this->excluded_files;
601
-    }
660
+	}
602 661
 
603
-    public function get_excluded_files()
604
-    {
605
-        return $this->excluded_files_by_default;
606
-    }
662
+	public function estimate_read_write_time()
663
+	{
664
+		$tmp_file = ".xcloner".substr(md5(time()), 0, 5);
607 665
 
608
-    public function list_directory($path)
609
-    {
610
-        return $this->start_filesystem->listContents($path);
611
-    }
666
+		$start_time = microtime(true);
612 667
 
613
-    public function build_files_list($folder = "")
614
-    {
615
-        $this->logger->debug(sprintf(("Building the files system list")));
668
+		$data = str_repeat(rand(0, 9), 1024 * 1024); //write 1MB data
616 669
 
617
-        //if we start with the root folder(empty value), we initializa the file system
618
-        if (!$folder) {
670
+		try {
671
+			$this->tmp_filesystem->write($tmp_file, $data);
619 672
 
620
-        }
673
+			$end_time = microtime(true) - $start_time;
621 674
 
622
-        try {
675
+			$return['writing_time'] = $end_time;
623 676
 
624
-            $files = $this->start_filesystem->listContents($folder);
625
-            foreach ($files as $file) {
626
-                if (!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) {
627
-                    $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"),
628
-                        $file['path']), array(
629
-                        "FILESYSTEM SCAN",
630
-                        "NOT READABLE"
631
-                    ));
632
-                } elseif (!$matching_pattern = $this->is_excluded($file)) {
633
-                    $this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array(
634
-                        "FILESYSTEM SCAN",
635
-                        "INCLUDE"
636
-                    ));
637
-                    $file['visibility'] = $this->start_filesystem->getVisibility($file['path']);
638
-                    if ($this->store_file($file)) {
639
-                        $this->files_counter++;
640
-                    }
641
-                    if (isset($file['size'])) {
642
-                        $this->files_size += $file['size'];
643
-                    }
644
-
645
-                } else {
646
-                    $this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"),
647
-                        $file['path'], $matching_pattern), array(
648
-                        "FILESYSTEM SCAN",
649
-                        "EXCLUDE"
650
-                    ));
651
-                }
652
-            }
677
+			$return['reading_time'] = $this->estimate_reading_time($tmp_file);
653 678
 
654
-        }catch (Exception $e) {
679
+			$this->tmp_filesystem->delete($tmp_file);
655 680
 
656
-            $this->logger->error($e->getMessage());
657
-
658
-        }
681
+		}catch (Exception $e) {
659 682
 
660
-    }
683
+			$this->logger->error($e->getMessage());
661 684
 
662
-    public function estimate_read_write_time()
663
-    {
664
-        $tmp_file = ".xcloner".substr(md5(time()), 0, 5);
685
+		}
665 686
 
666
-        $start_time = microtime(true);
687
+		return $return;
688
+	}
667 689
 
668
-        $data = str_repeat(rand(0, 9), 1024 * 1024); //write 1MB data
690
+	public function backup_storage_cleanup()
691
+	{
692
+		$this->logger->info(sprintf(("Cleaning the backup storage on matching rules")));
669 693
 
670
-        try {
671
-            $this->tmp_filesystem->write($tmp_file, $data);
694
+		$_storage_size = 0;
695
+		$_backup_files_list = array();
672 696
 
673
-            $end_time = microtime(true) - $start_time;
697
+		//rule date limit
698
+		$current_timestamp = strtotime("-".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days')." days");
674 699
 
675
-            $return['writing_time'] = $end_time;
700
+		$files = $this->storage_filesystem->listContents();
676 701
 
677
-            $return['reading_time'] = $this->estimate_reading_time($tmp_file);
702
+		if (is_array($files)) {
703
+			foreach ($files as $file) {
704
+				if (isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) {
705
+					$_storage_size += $file['size']; //bytes
706
+					$_backup_files_list[] = $file;
707
+				}
708
+			}
709
+		}
678 710
 
679
-            $this->tmp_filesystem->delete($tmp_file);
680 711
 
681
-        }catch (Exception $e) {
712
+		$this->sort_by($_backup_files_list, "timestamp", "asc");
682 713
 
683
-            $this->logger->error($e->getMessage());
714
+		$_backups_counter = sizeof($_backup_files_list);
684 715
 
685
-        }
716
+		foreach ($_backup_files_list as $file) {
717
+			//processing rule folder capacity
718
+			if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') &&
719
+				$_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit')))    //bytes
720
+			{
721
+				$this->storage_filesystem->delete($file['path']);
722
+				$_storage_size -= $file['size'];
723
+				$this->logger->info("Deleting backup ".$file['path']." matching rule", array(
724
+					"STORAGE SIZE LIMIT",
725
+					$_storage_size." >= ".$set_storage_limit
726
+				));
727
+			}
686 728
 
687
-        return $return;
688
-    }
729
+			//processing rule days limit
730
+			if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) {
731
+				$this->storage_filesystem->delete($file['path']);
732
+				$this->logger->info("Deleting backup ".$file['path']." matching rule", array(
733
+					"RETENTION LIMIT TIMESTAMP",
734
+					$file['timestamp']." =< ".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days')
735
+				));
736
+			}
689 737
 
690
-    public function backup_storage_cleanup()
691
-    {
692
-        $this->logger->info(sprintf(("Cleaning the backup storage on matching rules")));
738
+			//processing backup countert limit
739
+			if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives') && $_backups_counter >= $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')) {
740
+				$this->storage_filesystem->delete($file['path']);
741
+				$_backups_counter--;
742
+				$this->logger->info("Deleting backup ".$file['path']." matching rule", array(
743
+					"BACKUP QUANTITY LIMIT",
744
+					$_backups_counter." >= ".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')
745
+				));
746
+			}
693 747
 
694
-        $_storage_size = 0;
695
-        $_backup_files_list = array();
696 748
 
697
-        //rule date limit
698
-        $current_timestamp = strtotime("-".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days')." days");
699
-
700
-        $files = $this->storage_filesystem->listContents();
701
-
702
-        if (is_array($files)) {
703
-            foreach ($files as $file) {
704
-                if (isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) {
705
-                    $_storage_size += $file['size']; //bytes
706
-                    $_backup_files_list[] = $file;
707
-                }
708
-            }
709
-        }
749
+		}
710 750
 
751
+	}
711 752
 
712
-        $this->sort_by($_backup_files_list, "timestamp", "asc");
713
-
714
-        $_backups_counter = sizeof($_backup_files_list);
715
-
716
-        foreach ($_backup_files_list as $file) {
717
-            //processing rule folder capacity
718
-            if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') &&
719
-                $_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit')))    //bytes
720
-            {
721
-                $this->storage_filesystem->delete($file['path']);
722
-                $_storage_size -= $file['size'];
723
-                $this->logger->info("Deleting backup ".$file['path']." matching rule", array(
724
-                    "STORAGE SIZE LIMIT",
725
-                    $_storage_size." >= ".$set_storage_limit
726
-                ));
727
-            }
728
-
729
-            //processing rule days limit
730
-            if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) {
731
-                $this->storage_filesystem->delete($file['path']);
732
-                $this->logger->info("Deleting backup ".$file['path']." matching rule", array(
733
-                    "RETENTION LIMIT TIMESTAMP",
734
-                    $file['timestamp']." =< ".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days')
735
-                ));
736
-            }
737
-
738
-            //processing backup countert limit
739
-            if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives') && $_backups_counter >= $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')) {
740
-                $this->storage_filesystem->delete($file['path']);
741
-                $_backups_counter--;
742
-                $this->logger->info("Deleting backup ".$file['path']." matching rule", array(
743
-                    "BACKUP QUANTITY LIMIT",
744
-                    $_backups_counter." >= ".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')
745
-                ));
746
-            }
747
-
748
-
749
-        }
753
+	/**
754
+	 * @param string $tmp_file
755
+	 */
756
+	public function estimate_reading_time($tmp_file)
757
+	{
758
+		$this->logger->debug(sprintf(("Estimating file system reading time")));
759
+
760
+		$start_time = microtime(true);
761
+
762
+		if ($this->tmp_filesystem->has($tmp_file)) {
763
+			$this->tmp_filesystem->read($tmp_file);
764
+		}
750 765
 
751
-    }
766
+		$end_time = microtime(true) - $start_time;
767
+
768
+		return $end_time;
769
+
770
+	}
771
+
772
+	public function process_backup_name($name = "", $max_length = 100)
773
+	{
774
+		if (!$name) {
775
+			$name = $this->xcloner_settings->get_default_backup_name();
776
+		}
777
+
778
+		foreach ($this->backup_name_tags as $tag) {
779
+			if ($tag == '[time]') {
780
+				$name = str_replace($tag, date("Y-m-d_H-i"), $name);
781
+			} elseif ($tag == '[hostname]') {
782
+				$name = str_replace($tag, gethostname(), $name);
783
+			} elseif ($tag == '[domain]') {
784
+				$domain = parse_url(admin_url(), PHP_URL_HOST);
785
+				$name = str_replace($tag, $domain, $name);
786
+			}
787
+		}
788
+
789
+		if ($max_length) {
790
+			$name = substr($name, 0, $max_length);
791
+		}
792
+
793
+		return $name;
794
+	}
795
+
796
+	/**
797
+	 * @param string $field
798
+	 */
799
+	public function sort_by(&$array, $field, $direction = 'asc')
800
+	{
801
+		if (strtolower($direction) == "desc" || $direction == SORT_DESC) {
802
+			$direction = SORT_DESC;
803
+		} else {
804
+			$direction = SORT_ASC;
805
+		}
806
+
807
+		$array = $this->array_orderby($array, $field, $direction);
808
+
809
+		return true;
810
+	}
811
+
812
+	private function array_orderby()
813
+	{
814
+		$args = func_get_args();
815
+		$data = array_shift($args);
816
+
817
+		foreach ($args as $n => $field) {
818
+			if (is_string($field)) {
819
+				$tmp = array();
820
+				foreach ($data as $key => $row) {
821
+					if (is_array($row)) {
822
+						$tmp[$key] = $row[$field];
823
+					} else {
824
+						$tmp[$key] = $row->$field;
825
+					}
826
+				}
827
+				$args[$n] = $tmp;
828
+			}
829
+		}
830
+		$args[] = &$data;
831
+
832
+		call_user_func_array('array_multisort', $args);
833
+
834
+		return array_pop($args);
835
+	}
836
+
837
+	private function check_file_diff_time($file)
838
+	{
839
+		if ($this->get_diff_timestamp_start() != "") {
840
+			$fileMeta = $this->getMetadataFull("start_adapter", $file['path']);
841
+			$timestamp = $fileMeta->getMTime();
842
+			if ($timestamp < $fileMeta->getCTime()) {
843
+				$timestamp = $fileMeta->getCTime();
844
+			}
845
+
846
+			if ($timestamp <= $this->get_diff_timestamp_start()) {
847
+				return " file DIFF timestamp ".$timestamp." < ".$this->diff_timestamp_start;
848
+			}
849
+		}
850
+
851
+		return false;
852
+	}
853
+
854
+	public function is_excluded($file)
855
+	{
856
+		$this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path']));
857
+
858
+		if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) {
859
+			if (isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) {
860
+				return "> ".$xcloner_exclude_files_larger_than_mb."MB";
861
+			}
862
+		}
863
+
864
+		if (!is_array($this->excluded_files) || !sizeof($this->excluded_files)) {
865
+			$this->set_excluded_files();
866
+		}
867
+
868
+		if (is_array($this->excluded_files)) {
869
+			foreach ($this->excluded_files as $excluded_file_pattern) {
870
+				if ($excluded_file_pattern == "/") {
871
+					$needle = "$";
872
+				} else {
873
+					$needle = "$".$excluded_file_pattern;
874
+				}
875
+
876
+				if (strstr("$".$file['path'], $needle)) {
877
+					return $excluded_file_pattern;
878
+				}
879
+			}
880
+		}
881
+
882
+		if ($regex = $this->is_excluded_regex($file)) {
883
+			return $regex;
884
+		}
885
+
886
+		if ($file['type'] == "file") {
887
+			$check_file_diff_timestamp = $this->check_file_diff_time($file);
888
+			if ($check_file_diff_timestamp) {
889
+				return $check_file_diff_timestamp;
890
+			}
891
+		}
892
+
893
+		return false;
894
+	}
752 895
 
753
-    /**
754
-     * @param string $tmp_file
755
-     */
756
-    public function estimate_reading_time($tmp_file)
757
-    {
758
-        $this->logger->debug(sprintf(("Estimating file system reading time")));
759
-
760
-        $start_time = microtime(true);
761
-
762
-        if ($this->tmp_filesystem->has($tmp_file)) {
763
-            $this->tmp_filesystem->read($tmp_file);
764
-        }
765
-
766
-        $end_time = microtime(true) - $start_time;
767
-
768
-        return $end_time;
769
-
770
-    }
771
-
772
-    public function process_backup_name($name = "", $max_length = 100)
773
-    {
774
-        if (!$name) {
775
-            $name = $this->xcloner_settings->get_default_backup_name();
776
-        }
777
-
778
-        foreach ($this->backup_name_tags as $tag) {
779
-            if ($tag == '[time]') {
780
-                $name = str_replace($tag, date("Y-m-d_H-i"), $name);
781
-            } elseif ($tag == '[hostname]') {
782
-                $name = str_replace($tag, gethostname(), $name);
783
-            } elseif ($tag == '[domain]') {
784
-                $domain = parse_url(admin_url(), PHP_URL_HOST);
785
-                $name = str_replace($tag, $domain, $name);
786
-            }
787
-        }
788
-
789
-        if ($max_length) {
790
-            $name = substr($name, 0, $max_length);
791
-        }
792
-
793
-        return $name;
794
-    }
795
-
796
-    /**
797
-     * @param string $field
798
-     */
799
-    public function sort_by(&$array, $field, $direction = 'asc')
800
-    {
801
-        if (strtolower($direction) == "desc" || $direction == SORT_DESC) {
802
-            $direction = SORT_DESC;
803
-        } else {
804
-            $direction = SORT_ASC;
805
-        }
806
-
807
-        $array = $this->array_orderby($array, $field, $direction);
808
-
809
-        return true;
810
-    }
811
-
812
-    private function array_orderby()
813
-    {
814
-        $args = func_get_args();
815
-        $data = array_shift($args);
816
-
817
-        foreach ($args as $n => $field) {
818
-            if (is_string($field)) {
819
-                $tmp = array();
820
-                foreach ($data as $key => $row) {
821
-                    if (is_array($row)) {
822
-                        $tmp[$key] = $row[$field];
823
-                    } else {
824
-                        $tmp[$key] = $row->$field;
825
-                    }
826
-                }
827
-                $args[$n] = $tmp;
828
-            }
829
-        }
830
-        $args[] = &$data;
831
-
832
-        call_user_func_array('array_multisort', $args);
833
-
834
-        return array_pop($args);
835
-    }
836
-
837
-    private function check_file_diff_time($file)
838
-    {
839
-        if ($this->get_diff_timestamp_start() != "") {
840
-            $fileMeta = $this->getMetadataFull("start_adapter", $file['path']);
841
-            $timestamp = $fileMeta->getMTime();
842
-            if ($timestamp < $fileMeta->getCTime()) {
843
-                $timestamp = $fileMeta->getCTime();
844
-            }
845
-
846
-            if ($timestamp <= $this->get_diff_timestamp_start()) {
847
-                return " file DIFF timestamp ".$timestamp." < ".$this->diff_timestamp_start;
848
-            }
849
-        }
850
-
851
-        return false;
852
-    }
853
-
854
-    public function is_excluded($file)
855
-    {
856
-        $this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path']));
857
-
858
-        if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) {
859
-            if (isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) {
860
-                return "> ".$xcloner_exclude_files_larger_than_mb."MB";
861
-            }
862
-        }
863
-
864
-        if (!is_array($this->excluded_files) || !sizeof($this->excluded_files)) {
865
-            $this->set_excluded_files();
866
-        }
867
-
868
-        if (is_array($this->excluded_files)) {
869
-            foreach ($this->excluded_files as $excluded_file_pattern) {
870
-                if ($excluded_file_pattern == "/") {
871
-                    $needle = "$";
872
-                } else {
873
-                    $needle = "$".$excluded_file_pattern;
874
-                }
875
-
876
-                if (strstr("$".$file['path'], $needle)) {
877
-                    return $excluded_file_pattern;
878
-                }
879
-            }
880
-        }
881
-
882
-        if ($regex = $this->is_excluded_regex($file)) {
883
-            return $regex;
884
-        }
885
-
886
-        if ($file['type'] == "file") {
887
-            $check_file_diff_timestamp = $this->check_file_diff_time($file);
888
-            if ($check_file_diff_timestamp) {
889
-                return $check_file_diff_timestamp;
890
-            }
891
-        }
892
-
893
-        return false;
894
-    }
895
-
896
-    /*REGEX examples
896
+	/*REGEX examples
897 897
      *
898 898
     * exclude all except .php file
899 899
     * PATTERN: ^(.*)\.(.+)$(?<!(php))
Please login to merge, or discard this patch.
includes/class-xcloner.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -114,13 +114,13 @@  discard block
 block discarded – undo
114 114
 
115 115
 	}
116 116
 
117
-    /**
118
-     * Retrieve the version number of the plugin.
119
-     *
120
-     * @since     1.0.0
121
-     * @return    string    The version number of the plugin.
122
-     */
123
-    /*public function get_version() {
117
+	/**
118
+	 * Retrieve the version number of the plugin.
119
+	 *
120
+	 * @since     1.0.0
121
+	 * @return    string    The version number of the plugin.
122
+	 */
123
+	/*public function get_version() {
124 124
         return $this->version;
125 125
     }
126 126
 
@@ -179,14 +179,14 @@  discard block
 block discarded – undo
179 179
 		return $this->xcloner_encryption;
180 180
 	}*/
181 181
 
182
-    public function __call($property, $args) {
182
+	public function __call($property, $args) {
183 183
 
184
-        $property = str_replace("get_", "", $property);
184
+		$property = str_replace("get_", "", $property);
185 185
 
186
-        if(property_exists($this, $property)){
187
-            return $this->$property;
188
-        }
189
-    }
186
+		if(property_exists($this, $property)){
187
+			return $this->$property;
188
+		}
189
+	}
190 190
 
191 191
 	public function check_dependencies() {
192 192
 
@@ -546,9 +546,9 @@  discard block
 block discarded – undo
546 546
 		{
547 547
 			$logger->error($this->friendly_error_type($error['type']).": ".var_export($error, true));
548 548
 		}elseif ($error['type'] and $logger)
549
-        {
550
-            $logger->debug($this->friendly_error_type($error['type']).": ".var_export($error, true));
551
-        }
549
+		{
550
+			$logger->debug($this->friendly_error_type($error['type']).": ".var_export($error, true));
551
+		}
552 552
 
553 553
 	}
554 554
 
@@ -564,10 +564,10 @@  discard block
 block discarded – undo
564 564
 		return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}");
565 565
 	}
566 566
 
567
-    /**
568
-     * @method get_xcloner_settings()
569
-     * @throws Exception
570
-     */
567
+	/**
568
+	 * @method get_xcloner_settings()
569
+	 * @throws Exception
570
+	 */
571 571
 	private function define_ajax_hooks()
572 572
 	{
573 573
 		//adding the pre-update hook
@@ -634,9 +634,9 @@  discard block
 block discarded – undo
634 634
 			settings_errors('xcloner_error_message');
635 635
 		}
636 636
 
637
-    /**
638
-     * @method get_xcloner_scheduler()
639
-     */
637
+	/**
638
+	 * @method get_xcloner_scheduler()
639
+	 */
640 640
 	public function define_cron_hooks()
641 641
 	{
642 642
 		//registering new schedule intervals
Please login to merge, or discard this patch.