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.
Completed
Branch dev (953bb6)
by Liuta
01:57
created

Xcloner::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
1
<?php
2
/**
3
 * XCloner - Backup and Restore backup plugin for Wordpress
4
 *
5
 * class-xcloner.php
6
 * @author Liuta Ovidiu <[email protected]>
7
 *
8
 *        This program is free software; you can redistribute it and/or modify
9
 *        it under the terms of the GNU General Public License as published by
10
 *        the Free Software Foundation; either version 2 of the License, or
11
 *        (at your option) any later version.
12
 *
13
 *        This program is distributed in the hope that it will be useful,
14
 *        but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 *        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 *        GNU General Public License for more details.
17
 *
18
 *        You should have received a copy of the GNU General Public License
19
 *        along with this program; if not, write to the Free Software
20
 *        Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
 *        MA 02110-1301, USA.
22
 *
23
 * @link https://github.com/ovidiul/XCloner-Wordpress
24
 *
25
 * @modified 7/31/18 3:29 PM
26
 *
27
 */
28
29
/**
30
 * The core plugin class.
31
 *
32
 * This is used to define internationalization, admin-specific hooks, and
33
 * public-facing site hooks.
34
 *
35
 * Also maintains the unique identifier of this plugin as well as the current
36
 * version of the plugin.
37
 *
38
 * @since      1.0.0
39
 * @package    Xcloner
40
 * @subpackage Xcloner/includes
41
 * @author     Liuta Ovidiu <[email protected]>
42
 * @link       http://www.thinkovi.com
43
 */
44
class Xcloner {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type Xcloner has been defined more than once; this definition is ignored, only the first definition in includes/class-xcloner-encryption.php (L364-368) is considered.

This check looks for classes that have been defined more than once.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
45
46
	/**
47
	 * The loader that's responsible for maintaining and registering all hooks that power
48
	 * the plugin.
49
	 *
50
	 * @since    1.0.0
51
	 * @access   protected
52
	 * @var      Xcloner_Loader    $loader    Maintains and registers all hooks for the plugin.
53
	 */
54
	protected $loader;
55
56
	/**
57
	 * The unique identifier of this plugin.
58
	 *
59
	 * @since    1.0.0
60
	 * @access   protected
61
	 * @var      string    $plugin_name    The string used to uniquely identify this plugin.
62
	 */
63
	protected $plugin_name;
64
65
	protected $plugin_admin;
66
67
	/**
68
	 * The current version of the plugin.
69
	 *
70
	 * @since    1.0.0
71
	 * @access   protected
72
	 * @var      string    $version    The current version of the plugin.
73
	 */
74
	protected $version;
75
76
	private $xcloner_settings;
77
	private $xcloner_logger;
78
	private $xcloner_sanitization;
79
	private $xcloner_requirements;
80
	private $xcloner_filesystem;
81
	private $archive_system;
82
	private $xcloner_database;
83
	private $xcloner_scheduler;
84
	private $xcloner_remote_storage;
85
	private $xcloner_file_transfer;
86
	private $xcloner_encryption;
87
	/**
88
	 * Define the core functionality of the plugin.
89
	 *
90
	 * Set the plugin name and the plugin version that can be used throughout the plugin.
91
	 * Load the dependencies, define the locale, and set the hooks for the admin area and
92
	 * the public-facing side of the site.
93
	 *
94
	 * @since    1.0.0
95
	 */
96
	public function init()
97
	{
98
		register_shutdown_function(array($this, 'exception_handler'));
99
100
		$this->plugin_name = 'xcloner';
0 ignored issues
show
Bug introduced by
The property plugin_name does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
101
		$this->version = '4.0.4';
0 ignored issues
show
Bug introduced by
The property version does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
102
103
		$this->load_dependencies();
0 ignored issues
show
Bug introduced by
The method load_dependencies() does not seem to exist on object<Xcloner>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
104
		$this->set_locale();
0 ignored issues
show
Bug introduced by
The method set_locale() does not seem to exist on object<Xcloner>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
105
		$this->define_admin_hooks();
0 ignored issues
show
Bug introduced by
The method define_admin_hooks() does not seem to exist on object<Xcloner>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
106
		$this->define_public_hooks();
0 ignored issues
show
Bug introduced by
The method define_public_hooks() does not seem to exist on object<Xcloner>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
107
108
		$this->define_admin_menu();
0 ignored issues
show
Bug introduced by
The method define_admin_menu() does not seem to exist on object<Xcloner>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
109
		$this->define_plugin_settings();
0 ignored issues
show
Bug introduced by
The method define_plugin_settings() does not seem to exist on object<Xcloner>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
110
111
		$this->define_ajax_hooks();
0 ignored issues
show
Bug introduced by
The method define_ajax_hooks() does not seem to exist on object<Xcloner>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
112
		$this->define_cron_hooks();
0 ignored issues
show
Bug introduced by
The method define_cron_hooks() does not seem to exist on object<Xcloner>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
113
114
	}
115
116
	public function get_xcloner_settings()
117
	{
118
		return $this->xcloner_settings;
0 ignored issues
show
Bug introduced by
The property xcloner_settings does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
119
	}
120
121
	public function get_xcloner_filesystem()
122
	{
123
		return $this->xcloner_filesystem;
0 ignored issues
show
Bug introduced by
The property xcloner_filesystem does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
124
	}
125
126
	public function get_xcloner_logger()
127
	{
128
		return $this->xcloner_logger;
0 ignored issues
show
Bug introduced by
The property xcloner_logger does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
129
	}
130
131
	public function get_xcloner_sanitization()
132
	{
133
		return $this->xcloner_sanitization;
0 ignored issues
show
Bug introduced by
The property xcloner_sanitization does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
134
	}
135
136
	public function get_xcloner_requirements()
137
	{
138
		return $this->xcloner_requirements;
0 ignored issues
show
Bug introduced by
The property xcloner_requirements does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
139
	}
140
141
	public function get_archive_system()
142
	{
143
		return $this->archive_system;
0 ignored issues
show
Bug introduced by
The property archive_system does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
144
	}
145
146
	public function get_xcloner_database()
147
	{
148
		return $this->xcloner_database;
0 ignored issues
show
Bug introduced by
The property xcloner_database does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
149
	}
150
151
	public function get_xcloner_scheduler()
152
	{
153
		return $this->xcloner_scheduler;
0 ignored issues
show
Bug introduced by
The property xcloner_scheduler does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
154
	}
155
156
	public function get_xcloner_remote_storage()
157
	{
158
		return $this->xcloner_remote_storage;
0 ignored issues
show
Bug introduced by
The property xcloner_remote_storage does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
159
	}
160
161
	public function get_xcloner_file_transfer()
162
	{
163
		return $this->xcloner_file_transfer;
0 ignored issues
show
Bug introduced by
The property xcloner_file_transfer does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
164
	}
165
166
	public function get_xcloner_encryption()
167
	{
168
		return $this->xcloner_encryption;
0 ignored issues
show
Bug introduced by
The property xcloner_encryption does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
169
	}
170
171
	public function check_dependencies(){
172
173
		$backup_storage_path = realpath(__DIR__.DS."..".DS."..".DS."..").DS."backups".DS;
174
175
		define("XCLONER_STORAGE_PATH", realpath($backup_storage_path));
176
177 View Code Duplication
		if(!is_dir($backup_storage_path))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
178
		{
179
			if(!@mkdir($backup_storage_path))
180
			{
181
				$status = "error";
182
				$message = sprintf(__("Unable to create the Backup Storage Location Folder %s . Please fix this before starting the backup process."), $backup_storage_path);
183
				$this->trigger_message($message, $status, $backup_storage_path);
0 ignored issues
show
Bug introduced by
The method trigger_message() does not seem to exist on object<Xcloner>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
184
				return;
185
			}
186
		}
187 View Code Duplication
		if(!is_writable($backup_storage_path))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
188
		{
189
			$status = "error";
190
			$message = sprintf(__("Unable to write to the Backup Storage Location Folder %s . Please fix this before starting the backup process."), $backup_storage_path);
191
			$this->trigger_message($message, $status, $backup_storage_path);
0 ignored issues
show
Bug introduced by
The method trigger_message() does not seem to exist on object<Xcloner>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
192
193
			return;
194
		}
195
196
	}
197
198
	public function trigger_message($message, $status = "error", $message_param1 = "", $message_param2 = "", $message_param3 = "")
199
	{
200
			$message = sprintf(__($message), $message_param1, $message_param2, $message_param3);
201
			add_action( 'xcloner_admin_notices', array($this,"trigger_message_notice"), 10, 2);
202
			do_action( 'xcloner_admin_notices', $message, $status);
203
	}
204
205
	public function trigger_message_notice($message, $status = "success")
206
	{
207
		?>
208
		<div class="notice notice-<?php echo $status?> is-dismissible">
209
	        <p><?php _e( $message, 'xcloner-backup-and-restore' ); ?></p>
210
	    </div>
211
		<?php
212
	}
213
214
	/**
215
	 * Load the required dependencies for this plugin.
216
	 *
217
	 * Include the following files that make up the plugin:
218
	 *
219
	 * - Xcloner_Loader. Orchestrates the hooks of the plugin.
220
	 * - Xcloner_i18n. Defines internationalization functionality.
221
	 * - Xcloner_Admin. Defines all hooks for the admin area.
222
	 * - Xcloner_Public. Defines all hooks for the public side of the site.
223
	 *
224
	 * Create an instance of the loader which will be used to register the hooks
225
	 * with WordPress.
226
	 *
227
	 * @since    1.0.0
228
	 * @access   private
229
	 */
230
	private function load_dependencies() {
231
232
		/**
233
		 * The class responsible for orchestrating the actions and filters of the
234
		 * core plugin.
235
		 */
236
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-loader.php';
237
238
		/**
239
		 * The class responsible for defining internationalization functionality
240
		 * of the plugin.
241
		 */
242
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-i18n.php';
243
244
		/**
245
		 * The class responsible for defining all actions that occur in the admin area.
246
		 */
247
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-xcloner-admin.php';
248
249
		/**
250
		 * The class responsible for debugging XCloner.
251
		 */
252
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-logger.php';
253
254
		/**
255
		 * The class responsible for defining the admin settings area.
256
		 */
257
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-settings.php';
258
259
		/**
260
		 * The class responsible for defining the Remote Storage settings area.
261
		 */
262
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-remote-storage.php';
263
264
		/**
265
		 * The class responsible for implementing the database backup methods.
266
		 */
267
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-database.php';
268
269
		/**
270
		 * The class responsible for sanitization of users input.
271
		 */
272
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-sanitization.php';
273
274
		/**
275
		 * The class responsible for XCloner system requirements validation.
276
		 */
277
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-requirements.php';
278
279
		/**
280
		 * The class responsible for XCloner backup archive creation.
281
		 */
282
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-archive.php';
283
284
		/**
285
		 * The class responsible for XCloner API requests.
286
		 */
287
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-api.php';
288
289
		/**
290
		 * The class responsible for the XCloner File System methods.
291
		 */
292
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-file-system.php';
293
294
		/**
295
		 * The class responsible for the XCloner File Transfer methods.
296
		 */
297
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-file-transfer.php';
298
299
		/**
300
		 * The class responsible for the XCloner Scheduler methods.
301
		 */
302
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-scheduler.php';
303
304
        /**
305
         * The class responsible for the XCloner Encryption methods.
306
         */
307
        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-encryption.php';
308
309
		/**
310
		 * The class responsible for defining all actions that occur in the public-facing
311
		 * side of the site.
312
		 */
313
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-xcloner-public.php';
314
315
		$this->loader = new Xcloner_Loader($this);
0 ignored issues
show
Bug introduced by
The property loader does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
316
317
	}
318
319
	/**
320
	 * Define the locale for this plugin for internationalization.
321
	 *
322
	 * Uses the Xcloner_i18n class in order to set the domain and to register the hook
323
	 * with WordPress.
324
	 *
325
	 * @since    1.0.0
326
	 * @access   private
327
	 */
328
	private function set_locale() {
329
330
		$plugin_i18n = new Xcloner_i18n();
331
332
		$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
333
334
		//wp_localize_script( 'ajax-script', 'my_ajax_object',
335
        //   array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
336
337
	}
338
339
	/**
340
	 * Register all of the hooks related to the admin area functionality
341
	 * of the plugin.
342
	 *
343
	 * @since    1.0.0
344
	 * @access   private
345
	 */
346
	private function define_admin_hooks() {
347
348
		$plugin_admin = new Xcloner_Admin( $this );
349
		$this->plugin_admin = $plugin_admin;
0 ignored issues
show
Bug introduced by
The property plugin_admin does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
350
351
		$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
352
		$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
353
354
		add_action( 'backup_archive_finished', array($this, 'do_action_after_backup_finished'), 10, 2);
355
	}
356
357
	/**
358
	 * Register the Admin Sidebar menu
359
	 *
360
	 * @access    private
361
	 *
362
	 */
363
	private function define_admin_menu(){
364
365
		add_action('admin_menu', array($this->loader, 'xcloner_backup_add_admin_menu'));
366
367
	}
368
369
	private function define_plugin_settings(){
370
		/**
371
		* register wporg_settings_init to the admin_init action hook
372
		*/
373
374
		$this->xcloner_settings = new XCloner_Settings($this);
375
376
		if(defined('DOING_CRON') || isset($_POST['hash'])){
377
378
			if(defined('DOING_CRON') || $_POST['hash'] == "generate_hash"){
379
				$this->xcloner_settings->generate_new_hash();
380
			}else{
381
				$this->xcloner_settings->set_hash($_POST['hash']);
382
			}
383
		}
384
385
		if(defined('DOING_CRON') || !isset($_POST['hash']))
386
		{
387
			add_action( 'shutdown', function(){
388
				$this->xcloner_filesystem = new Xcloner_File_System($this);
389
				$this->xcloner_filesystem->remove_tmp_filesystem();
390
			});
391
		}
392
393
		$this->xcloner_sanitization 	= new Xcloner_Sanitization();
394
		$this->xcloner_requirements 	= new Xcloner_Requirements($this);
395
396
		add_action('admin_init', array($this->xcloner_settings, 'settings_init'));
397
398
		//adding links to the Manage Plugins Wordpress page for XCloner
399
		add_filter('plugin_action_links', array($this, 'add_plugin_action_links'), 10, 2);
400
401
402
403
	}
404
405
	/*
406
	 * type = core|plugin|theme|translation
407
	 */
408
	public function pre_auto_update($type, $item, $context)
409
	{
410
		if(!$type)
411
		{
412
			return false;
413
		}
414
415
		$this->get_xcloner_logger()->info(sprintf("Doing automatic backup before %s upgrade, pre_auto_update hook.", $type));
0 ignored issues
show
Bug introduced by
The method get_xcloner_logger() does not seem to exist on object<Xcloner>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
416
417
		$content_dir = str_replace(ABSPATH, "", WP_CONTENT_DIR);
418
		$plugins_dir 	= str_replace(ABSPATH, "", WP_PLUGIN_DIR);
419
		$langs_dir 		= $content_dir . DS . "languages";
420
		$themes_dir 		= $content_dir . DS . "themes";
421
422
		switch ( $type ) {
423
			case 'core':
424
				$exclude_files = array(
425
									"^(?!(wp-admin|wp-includes|(?!.*\/.*.php)))(.*)$",
426
								);
427
				break;
428 View Code Duplication
			case 'plugin':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
429
430
				$dir_array = explode(DS, $plugins_dir);
431
432
				foreach($dir_array as $dir)
433
				{
434
					$data .= "\/".$dir;
0 ignored issues
show
Bug introduced by
The variable $data does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
435
					$regex .= $data."$|";
0 ignored issues
show
Bug introduced by
The variable $regex does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
436
				}
437
438
				$regex .= "\/".implode("\/", $dir_array);
439
440
				$exclude_files = array(
441
									"^(?!(".$regex."))(.*)$",
442
								);
443
				break;
444 View Code Duplication
			case 'theme':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
445
446
				$dir_array = explode(DS, $themes_dir);
447
448
				foreach($dir_array as $dir)
449
				{
450
					$data .= "\/".$dir;
451
					$regex .= $data."$|";
452
				}
453
454
				$regex .= "\/".implode("\/", $dir_array);
455
456
				$exclude_files = array(
457
									"^(?!(".$regex."))(.*)$",
458
								);
459
				break;
460 View Code Duplication
			case 'translation':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
461
462
				$dir_array = explode(DS, $langs_dir);
463
464
				foreach($dir_array as $dir)
465
				{
466
					$data .= "\/".$dir;
467
					$regex .= $data."$|";
468
				}
469
470
				$regex .= "\/".implode("\/", $dir_array);
471
472
				$exclude_files = array(
473
									"^(?!(".$regex."))(.*)$",
474
								);
475
				break;
476
		}
477
478
		$schedule = array();
479
480
		$schedule['id'] = 0;
481
		$schedule['name'] = "pre_auto_update";
482
		$schedule['recurrence'] = "single";
483
		$schedule['excluded_files'] = json_encode($exclude_files);
0 ignored issues
show
Bug introduced by
The variable $exclude_files does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
484
		$schedule['table_params'] = json_encode(array("#" => array($this->get_xcloner_settings()->get_db_database())));
0 ignored issues
show
Bug introduced by
The method get_xcloner_settings() does not seem to exist on object<Xcloner>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
485
486
		$schedule['backup_params'] = new stdClass();
487
		$schedule['backup_params']->email_notification = get_option('admin_email');
488
		$schedule['backup_params']->backup_name = "backup_pre_auto_update_".$type."_[domain]-[time]-sql";
489
490
		try{
491
			$this->xcloner_scheduler->xcloner_scheduler_callback(0, $schedule);
492
		}catch(Exception $e){
493
			$this->get_xcloner_logger()->error($e->getMessage());
0 ignored issues
show
Bug introduced by
The method get_xcloner_logger() does not seem to exist on object<Xcloner>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
494
		}
495
496
	}
497
498
	/**
499
	 * Register all of the hooks related to the public-facing functionality
500
	 * of the plugin.
501
	 *
502
	 * @since    1.0.0
503
	 * @access   private
504
	 */
505
	private function define_public_hooks() {
506
507
		$plugin_public = new Xcloner_Public( $this );
508
509
		$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
510
		$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
511
512
	}
513
514
	public function exception_handler() {
515
516
		$logger = new XCloner_Logger($this, "php_system");
517
		$error = error_get_last();
518
519
		if($error['type'] and $logger)
520
		{
521
			$logger->info($this->friendly_error_type ($error['type']).": ".var_export($error, true));
0 ignored issues
show
Bug introduced by
The method friendly_error_type() does not seem to exist on object<Xcloner>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
522
		}
523
524
	}
525
526 View Code Duplication
	function friendly_error_type($type) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
527
	    static $levels=null;
528
	    if ($levels===null) {
529
	        $levels=[];
530
	        foreach (get_defined_constants() as $key=>$value) {
531
	            if (strpos($key,'E_')!==0) {continue;}
532
					$levels[$value]= $key; //substr($key,2);
533
	        }
534
	    }
535
	    return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}");
536
	}
537
538
	private function define_ajax_hooks()
539
	{
540
		//adding the pre-update hook
541
542
		if(is_admin() || defined('DOING_CRON'))
543
		{
544
			$this->xcloner_logger 			= new XCloner_Logger($this, "xcloner_api");
545
			$this->xcloner_filesystem 		= new Xcloner_File_System($this);
546
547
			//$this->xcloner_filesystem->set_diff_timestamp_start (strtotime("-15 days"));
548
549
			$this->archive_system 			= new Xcloner_Archive($this);
550
			$this->xcloner_database 		= new Xcloner_Database($this);
551
			$this->xcloner_scheduler 		= new Xcloner_Scheduler($this);
552
			$this->xcloner_remote_storage 	= new Xcloner_Remote_Storage($this);
553
			$this->xcloner_file_transfer 	= new Xcloner_File_Transfer($this);
554
			$this->xcloner_encryption    	= new Xcloner_Encryption($this);
555
556
			$xcloner_api 					= new Xcloner_Api($this);
557
558
			add_action( 'wp_ajax_get_database_tables_action', 	array($xcloner_api,'get_database_tables_action')  );
559
			add_action( 'wp_ajax_get_file_system_action', 		array($xcloner_api,'get_file_system_action')  );
560
			add_action( 'wp_ajax_scan_filesystem', 				array($xcloner_api,'scan_filesystem')  );
561
			add_action( 'wp_ajax_backup_database', 				array($xcloner_api,'backup_database')  );
562
			add_action( 'wp_ajax_backup_files'	, 				array($xcloner_api,'backup_files')  );
563
			add_action( 'wp_ajax_save_schedule'	, 				array($xcloner_api,'save_schedule')  );
564
			add_action( 'wp_ajax_get_schedule_by_id',	 		array($xcloner_api,'get_schedule_by_id')  );
565
			add_action( 'wp_ajax_get_scheduler_list',	 		array($xcloner_api,'get_scheduler_list')  );
566
			add_action( 'wp_ajax_delete_schedule_by_id'	, 		array($xcloner_api,'delete_schedule_by_id')  );
567
			add_action( 'wp_ajax_delete_backup_by_name'	, 		array($xcloner_api,'delete_backup_by_name')  );
568
			add_action( 'wp_ajax_download_backup_by_name', 		array($xcloner_api,'download_backup_by_name')  );
569
			add_action( 'wp_ajax_remote_storage_save_status', 	array($xcloner_api,'remote_storage_save_status')  );
570
			add_action( 'wp_ajax_upload_backup_to_remote', 		array($xcloner_api,'upload_backup_to_remote')  );
571
			add_action( 'wp_ajax_list_backup_files'	,			array($xcloner_api,'list_backup_files')  );
572
			add_action( 'wp_ajax_restore_upload_backup'	, 		array($xcloner_api,'restore_upload_backup')  );
573
			add_action( 'wp_ajax_download_restore_script', 		array($xcloner_api,'download_restore_script')  );
574
			add_action( 'wp_ajax_copy_backup_remote_to_local', 	array($xcloner_api,'copy_backup_remote_to_local')  );
575
			add_action( 'wp_ajax_restore_backup', 				array($xcloner_api,'restore_backup')  );
576
			add_action( 'wp_ajax_backup_encryption', 			array($xcloner_api,'backup_encryption')  );
577
			add_action( 'wp_ajax_backup_decryption', 			array($xcloner_api,'backup_decryption')  );
578
			add_action( 'wp_ajax_get_manage_backups_list', 		array($xcloner_api,'get_manage_backups_list')  );
579
			add_action( 'admin_notices', 						array($this, 'xcloner_error_admin_notices' ));
580
581
        }
582
583
        //Do a pre-update backup of targeted files
584
        if($this->get_xcloner_settings()->get_xcloner_option('xcloner_enable_pre_update_backup'))
0 ignored issues
show
Bug introduced by
The method get_xcloner_settings() does not seem to exist on object<Xcloner>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
585
        {
586
			add_action("pre_auto_update", array($this, "pre_auto_update"), 1, 3);
587
		}
588
	}
589
590
	function add_plugin_action_links($links, $file) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
591
        if ($file == plugin_basename(dirname(dirname(__FILE__)) . '/xcloner.php'))
592
		{
593
			$links[] = '<a href="admin.php?page=xcloner_settings_page">'.__('Settings', 'xcloner-backup-and-restore').'</a>';
594
			$links[] = '<a href="admin.php?page=xcloner_generate_backups_page">'.__('Generate Backup', 'xcloner-backup-and-restore').'</a>';
595
		}
596
597
        return $links;
598
    }
599
600
	public function xcloner_error_admin_notices() {
601
			settings_errors( 'xcloner_error_message' );
602
		}
603
604
	public function define_cron_hooks()
605
	{
606
		//registering new schedule intervals
607
		add_filter( 'cron_schedules', array($this, 'add_new_intervals'));
608
609
610
		$xcloner_scheduler = $this->get_xcloner_scheduler();
0 ignored issues
show
Bug introduced by
The method get_xcloner_scheduler() does not seem to exist on object<Xcloner>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
611
		$xcloner_scheduler->update_wp_cron_hooks();
612
613
	}
614
615
	function add_new_intervals($schedules)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
616
	{
617
		//weekly scheduler interval
618
		$schedules['weekly'] = array(
619
			'interval' => 604800,
620
			'display' => __('Once Weekly', 'xcloner-backup-and-restore')
621
		);
622
623
		//monthly scheduler interval
624
		$schedules['monthly'] = array(
625
			'interval' => 2635200,
626
			'display' => __('Once Monthly', 'xcloner-backup-and-restore')
627
		);
628
629
		//monthly scheduler interval
630
		$schedules['twicedaily'] = array(
631
			'interval' => 43200,
632
			'display' => __('Twice Daily', 'xcloner-backup-and-restore')
633
		);
634
635
		return $schedules;
636
	}
637
638
639
	/**
640
	 * Run the loader to execute all of the hooks with WordPress.
641
	 *
642
	 * @since    1.0.0
643
	 */
644
	public function run() {
645
		$this->loader->run();
646
	}
647
648
	/**
649
	 * The name of the plugin used to uniquely identify it within the context of
650
	 * WordPress and to define internationalization functionality.
651
	 *
652
	 * @since     1.0.0
653
	 * @return    string    The name of the plugin.
654
	 */
655
	public function get_plugin_name() {
656
		return $this->plugin_name;
657
	}
658
659
	/**
660
	 * The reference to the class that orchestrates the hooks with the plugin.
661
	 *
662
	 * @since     1.0.0
663
	 * @return    Xcloner_Loader    Orchestrates the hooks of the plugin.
664
	 */
665
	public function get_loader() {
666
		return $this->loader;
667
	}
668
669
	/**
670
	 * Retrieve the version number of the plugin.
671
	 *
672
	 * @since     1.0.0
673
	 * @return    string    The version number of the plugin.
674
	 */
675
	public function get_version() {
676
		return $this->version;
677
	}
678
679
	function xcloner_display()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
680
	{
681
		// check user capabilities
682
	    if (!current_user_can('manage_options')) {
683
	        return;
684
	    }
685
686
		$page = sanitize_key($_GET['page']);
687
688
		if($page)
689
		{
690
			$this->display($page);
0 ignored issues
show
Bug introduced by
The method display() does not seem to exist on object<Xcloner>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
691
		}
692
693
	}
694
695
	public function display($page)
696
	{
697
		$plugin_admin = new Xcloner_Admin($this);
698
		$this->plugin_admin = $plugin_admin;
699
700
		call_user_func_array(array($this->plugin_admin, $page), array());
701
	}
702
}
703