LSX_WETU_Importer::set_variables()   F
last analyzed

Complexity

Conditions 20
Paths 324

Size

Total Lines 62
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 20
eloc 34
nc 324
nop 0
dl 0
loc 62
rs 1.7833
c 4
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * The main plugin class.
4
 *
5
 * @package   LSX_WETU_Importer
6
 * @author    LightSpeed
7
 * @license   GPL-2.0+
8
 * @link
9
 * @copyright 2016 LightSpeed
10
 */
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line after the file comment
Loading history...
11
/**
12
 * The Main plugin class.
13
 */
14
class LSX_WETU_Importer {
15
16
	/**
17
	 * Holds class instance
18
	 *
19
	 * @since 1.0.0
20
	 *
21
	 * @var      object|Module_Template
0 ignored issues
show
Bug introduced by
The type Module_Template was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
	 */
23
	protected static $instance = null;
24
25
	/**
26
	 * The slug for this plugin
27
	 *
28
	 * @since 0.0.1
29
	 *
30
	 * @var      string
31
	 */
32
	public $plugin_slug = 'lsx-wetu-importer';
33
34
	/**
35
	 * The url to list items from WETU
36
	 *
37
	 * @since 0.0.1
38
	 *
39
	 * @var      string
40
	 */
41
	public $tab_slug = 'default';
42
43
	/**
44
	 * The options for the plugin
45
	 *
46
	 * @since 0.0.1
47
	 *
48
	 * @var      string
49
	 */
50
	public $options = false;
51
52
	/**
53
	 * The url to import images from WETU
54
	 *
55
	 * @since 0.0.1
56
	 *
57
	 * @var      string
58
	 */
59
	public $import_scaling_url = false;
60
61
	/**
62
	 * scale the images on import or not
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
63
	 *
64
	 * @since 0.0.1
65
	 *
66
	 * @var      boolean
67
	 */
68
	public $scale_images = false;
69
70
	/**
71
	 * The WETU API Key
72
	 */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @var tag in member variable comment
Loading history...
73
	public $api_key = false;
74
75
	/**
76
	 * The post types this works with.
77
	 */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @var tag in member variable comment
Loading history...
78
	public $post_types = array();
79
80
	/**
81
	 * The previously attached images
82
	 *
83
	 * @var      array()
84
	 */
85
	public $found_attachments = array();
86
87
	/**
88
	 * The gallery ids for the found attachements
89
	 *
90
	 * @var      array()
91
	 */
92
	public $gallery_meta = array();
93
94
	/**
95
	 * The post ids to clean up (make sure the connected items are only singular)
96
	 *
97
	 * @var      array()
98
	 */
99
	public $cleanup_posts = array();
100
101
	/**
102
	 * A post => parent relationship array.
103
	 *
104
	 * @var      array()
105
	 */
106
	public $relation_meta = array();
107
108
	/**
109
	 * Image Limit
110
	 *
111
	 * @var      int
112
	 */
113
	public $image_limit = false;
114
115
	/**
116
	 * the featured image id
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
117
	 *
118
	 * @var      int
119
	 */
120
	public $featured_image = false;
121
122
	/**
123
	 * the banner image
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
124
	 *
125
	 * @var      int
126
	 */
127
	public $banner_image = false;
128
129
	/**
130
	 * Holds the current import to display
131
	 *
132
	 * @var      int
133
	 */
134
	public $current_importer = false;
135
136
	/**
137
	 * if you ran a tour import then you will have accommodation and destination queued to sync as well.
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
138
	 *
139
	 * @var      int
140
	 */
141
	public $queued_imports = array();
142
143
	/**
144
	 * An Array to hold the items to queue
145
	 *
146
	 * @var      int
147
	 */
148
	public $import_queue = array();
149
150
	/**
151
	 * Holds the current post that is being imported. Use to check the content and excerpt.
152
	 *
153
	 * @var      int
154
	 */
155
	public $current_post = false;
156
157
	/**
158
	 * Holds the accommodation settings
159
	 *
160
	 * @var      int
161
	 */
162
	public $accommodation_settings = false;
163
164
	/**
165
	 * Holds the tour settings
166
	 *
167
	 * @var      int
168
	 */
169
	public $tour_settings = false;
170
171
	/**
172
	 * Holds the destination settings
173
	 *
174
	 * @var      int
175
	 */
176
	public $destination_settings = false;
177
178
	/**
179
	 * Hold the flag to let you know if the debug is enabled or not.
180
	 *
181
	 * @var      int
182
	 */
183
	public $debug_enabled = false;
184
185
	/**
186
	 * Hold the post columns object
187
	 *
188
	 * @var object LSX_WETU_Importer_Post_Columns()
189
	 */
190
	public $post_columns = false;
191
192
	/**
193
	 * Initialize the plugin by setting localization, filters, and administration functions.
194
	 *
195
	 * @since 1.0.0
196
	 *
197
	 * @access private
198
	 */
199
	public function __construct() {
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
200
		add_action( 'admin_init', array( $this, 'compatible_version_check' ) );
201
		require_once LSX_WETU_IMPORTER_PATH . 'includes/helpers.php';
202
203
		// Don't run anything else in the plugin, if we're on an incompatible PHP version.
204
		if ( ! self::compatible_version() ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
205
			return;
206
		}
207
208
		$this->set_variables();
209
210
		add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
211
		add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ), 11 );
212
		add_action( 'admin_menu', array( $this, 'register_importer_page' ), 20 );
213
214
		require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-welcome.php';
215
		require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-accommodation.php';
216
		require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-destination.php';
217
		require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-tours.php';
218
		require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-settings.php';
219
		require_once LSX_WETU_IMPORTER_PATH . 'classes/class-cron.php';
220
221
		if ( isset( $this->options ) && isset( $this->options['enable_tour_ref_column'] ) && '' !== $this->options['enable_tour_ref_column'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
222
			require_once LSX_WETU_IMPORTER_PATH . 'classes/class-lsx-wetu-importer-post-columns.php';
223
			$this->post_columns = LSX_WETU_Importer_Post_Columns::get_instance();
224
		}
225
226
		add_action( 'init', array( $this, 'load_class' ) );
227
228
		if ( 'default' !== $this->tab_slug ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
229
			add_action( 'wp_ajax_lsx_tour_importer', array( $this, 'process_ajax_search' ) );
230
			add_action( 'wp_ajax_nopriv_lsx_tour_importer', array( $this, 'process_ajax_search' ) );
231
232
			add_action( 'wp_ajax_lsx_import_items', array( $this, 'process_ajax_import' ) );
233
			add_action( 'wp_ajax_nopriv_lsx_import_items', array( $this, 'process_ajax_import' ) );
234
		}
235
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
236
237
	/**
238
	 * Load the plugin text domain for translation.
239
	 *
240
	 * @since 1.0.0
241
	 */
242
	public function load_plugin_textdomain() {
243
		load_plugin_textdomain( 'lsx-wetu-importer', false, basename( LSX_WETU_IMPORTER_PATH ) . '/languages' );
244
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
245
246
	/**
247
	 * Sets the variables used throughout the plugin.
248
	 */
249
	public function set_variables() {
250
		$this->post_types = array( 'accommodation', 'destination', 'tour' );
251
		$options          = lsx_wetu_get_options();
252
253
		// Set the options.
254
		$this->options = $options;
0 ignored issues
show
Documentation Bug introduced by
It seems like $options of type array is incompatible with the declared type string of property $options.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
255
256
		$temp_options = get_option( '_lsx-to_settings', false );
257
		if ( false !== $temp_options ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
258
			$this->accommodation_settings = $temp_options['accommodation'];
259
			$this->tour_settings          = $temp_options['tour'];
260
			$this->destination_settings   = $temp_options['destination'];
261
		}
262
263
		$this->api_key = false;
264
265
		if ( ! defined( 'WETU_API_KEY' ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
266
			if ( isset( $options['api_key'] ) && '' !== $options['api_key'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
267
				$this->api_key = $options['api_key'];
268
			}
269
		} else {
270
			$this->api_key = WETU_API_KEY;
0 ignored issues
show
Bug introduced by
The constant WETU_API_KEY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
271
		}
272
273
		// Set the tab slug.
274
		// @codingStandardsIgnoreLine
275
		if ( isset( $_GET['tab'] ) || ( defined( 'DOING_AJAX' ) && isset( $_POST['type'] ) ) ) {
276
			if ( isset( $_GET['tab'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
introduced by
Processing form data without nonce verification.
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
277
				$this->tab_slug = sanitize_text_field( $_GET['tab'] );
0 ignored issues
show
introduced by
Processing form data without nonce verification.
Loading history...
introduced by
$_GET data not unslashed before sanitization. Use wp_unslash() or similar
Loading history...
278
			} else {
279
				// @codingStandardsIgnoreLine
280
				$this->tab_slug = sanitize_text_field( $_POST['type'] );
281
			}
282
		}
283
284
		// If any tours were queued.
285
		$this->queued_imports = get_option( 'lsx_wetu_importer_que', array() );
286
287
		// Set the scaling options.
288
		if ( isset( $this->options ) && isset( $this->options['image_scaling'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
289
			$this->scale_images = true;
290
291
			$width = '1024';
292
			if ( isset( $this->options['width'] ) && '' !== $this->options['width'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
293
				$width = $this->options['width'];
294
			}
295
296
			$height = '768';
297
			if ( isset( $this->options['height'] ) && '' !== $this->options['height'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
298
				$height = $this->options['height'];
299
			}
300
301
			$cropping = 'w';
302
			if ( isset( $this->options['cropping'] ) && '' !== $this->options['cropping'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
303
				$cropping = $this->options['cropping'];
304
			}
305
306
			$this->image_scaling_url = 'https://wetu.com/ImageHandler/' . $cropping . $width . 'x' . $height . '/';
0 ignored issues
show
Bug Best Practice introduced by
The property image_scaling_url does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
307
		}
308
309
		if ( isset( $this->options ) && isset( $this->options['image_limit'] ) && '' !== $this->options['image_limit'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
310
			$this->image_limit = $this->options['image_limit'];
311
		}
312
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
313
314
	// COMPATABILITY FUNCTIONS.
315
316
	/**
317
	 * On plugin activation
318
	 *
319
	 * @since 1.0.0
320
	 */
321
	public static function register_activation_hook() {
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
322
		self::compatible_version_check_on_activation();
323
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
324
325
	/**
326
	 * Check if the PHP version is compatible.
327
	 *
328
	 * @since 1.0.0
329
	 */
330
	public static function compatible_version() {
331
		if ( version_compare( PHP_VERSION, '5.6', '<' ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
332
			return false;
333
		}
334
335
		return true;
336
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
337
338
	/**
339
	 * The backup sanity check, in case the plugin is activated in a weird way,
340
	 * or the versions change after activation.
341
	 *
342
	 * @since 1.0.0
343
	 */
344
	public function compatible_version_check() {
345
		if ( ! self::compatible_version() ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
346
			if ( is_plugin_active( plugin_basename( LSX_WETU_IMPORTER_CORE ) ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
347
				deactivate_plugins( plugin_basename( LSX_WETU_IMPORTER_CORE ) );
348
				add_action( 'admin_notices', array( $this, 'compatible_version_notice' ) );
349
350
				if ( isset( $_GET['activate'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
introduced by
Processing form data without nonce verification.
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
351
					unset( $_GET['activate'] );
0 ignored issues
show
introduced by
Processing form data without nonce verification.
Loading history...
352
				}
353
			}
354
		}
355
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
356
357
	/**
358
	 * Display the notice related with the older version from PHP.
359
	 *
360
	 * @since 1.0.0
361
	 */
362
	public function compatible_version_notice() {
363
		$class   = 'notice notice-error';
364
		$message = esc_html__( 'LSX Importer for Wetu Plugin requires PHP 5.6 or higher.', 'lsx-wetu-importer' );
365
		printf( '<div class="%1$s"><p>%2$s</p></div>', esc_html( $class ), esc_html( $message ) );
366
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
367
368
	/**
369
	 * The primary sanity check, automatically disable the plugin on activation if it doesn't
370
	 * meet minimum requirements.
371
	 *
372
	 * @since 1.0.0
373
	 */
374
	public static function compatible_version_check_on_activation() {
375
		if ( ! self::compatible_version() ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
376
			deactivate_plugins( plugin_basename( LSX_WETU_IMPORTER_CORE ) );
377
			wp_die( esc_html__( 'LSX Importer for Wetu Plugin requires PHP 5.6 or higher.', 'lsx-wetu-importer' ) );
378
		}
379
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
380
381
	// DISPLAY FUNCTIONS.
382
383
	/**
384
	 * Load the importer class you want to use
385
	 */
386
	public function load_class() {
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
387
		switch ( $this->tab_slug ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
388
			case 'accommodation':
389
				$this->current_importer = new LSX_WETU_Importer_Accommodation();
0 ignored issues
show
Documentation Bug introduced by
It seems like new LSX_WETU_Importer_Accommodation() of type LSX_WETU_Importer_Accommodation is incompatible with the declared type integer of property $current_importer.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
390
				break;
391
392
			case 'destination':
393
				$this->current_importer = new LSX_WETU_Importer_Destination();
394
				break;
395
396
			case 'tour':
397
				$this->current_importer = new LSX_WETU_Importer_Tours();
398
				break;
399
400
			case 'settings':
401
				$this->current_importer = LSX_WETU_Importer_Settings::get_instance();
402
				break;
403
404
			default:
405
				$this->current_importer = LSX_WETU_Importer_Welcome::get_instance();
406
				break;
407
		}
408
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
409
410
	/**
411
	 * Registers the admin page which will house the importer form.
412
	 */
413
	public function register_importer_page() {
414
		add_submenu_page( 'tour-operator', esc_html__( 'Importer', 'tour-operator' ), esc_html__( 'Importer', 'tour-operator' ), 'manage_options', 'lsx-wetu-importer', array( $this, 'display_page' ) );
415
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
416
417
	/**
418
	 * Enqueue the JS needed to contact wetu and return your result.
419
	 */
420
	public function admin_scripts() {
421
		if ( defined( 'WP_DEBUG' ) && true === WP_DEBUG ) {
0 ignored issues
show
introduced by
The condition true === WP_DEBUG is always false.
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
422
			$min = '';
423
		} else {
424
			$min = '.min';
425
		}
426
427
		$min = '';
428
429
		if ( is_admin() && isset( $_GET['page'] ) && $this->plugin_slug === $_GET['page'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
introduced by
Processing form data without nonce verification.
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Blank line found at start of control structure
Loading history...
430
431
			// wp_enqueue_style( 'datatables', LSX_WETU_IMPORTER_URL . 'assets/css/datatables' . $min . '.css', LSX_WETU_IMPORTER_VER, true );
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
432
			wp_enqueue_style( 'lsx-wetu-importer-style', LSX_WETU_IMPORTER_URL . 'assets/css/lsx-wetu-importer.css', LSX_WETU_IMPORTER_VER, true );
0 ignored issues
show
Bug introduced by
LSX_WETU_IMPORTER_VER of type string is incompatible with the type string[] expected by parameter $deps of wp_enqueue_style(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

432
			wp_enqueue_style( 'lsx-wetu-importer-style', LSX_WETU_IMPORTER_URL . 'assets/css/lsx-wetu-importer.css', /** @scrutinizer ignore-type */ LSX_WETU_IMPORTER_VER, true );
Loading history...
433
434
			if ( isset( $_GET['tab'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
introduced by
Processing form data without nonce verification.
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
435
				wp_enqueue_script( 'datatables', LSX_WETU_IMPORTER_URL . 'assets/js/datatables' . $min . '.js', array( 'jquery' ), LSX_WETU_IMPORTER_VER, true );
436
				wp_enqueue_script( 'lsx-wetu-importers-script', LSX_WETU_IMPORTER_URL . 'assets/js/lsx-wetu-importer' . $min . '.js', array( 'jquery', 'datatables' ), LSX_WETU_IMPORTER_VER, true );
437
438
				wp_localize_script(
439
					'lsx-wetu-importers-script',
440
					'lsx_tour_importer_params',
441
					array(
442
						'ajax_url'   => admin_url( 'admin-ajax.php' ),
443
						'ajax_nonce' => wp_create_nonce( 'lsx_wetu_ajax_action' ),
444
					)
445
				);
446
			}
447
		}
448
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
449
450
	/**
451
	 * Display the importer administration screen
452
	 */
453
	public function display_page() {
454
		?>
455
		<div class="wrap">
456
			<?php
457
			$this->navigation( $this->tab_slug );
458
			if ( 'default' !== $this->tab_slug && 'settings' !== $this->tab_slug ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
459
				$this->wetu_status();
460
				$this->post_status_navigation();
461
			}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
462
			$this->current_importer->display_page();
0 ignored issues
show
Bug introduced by
The method display_page() does not exist on integer. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

462
			$this->current_importer->/** @scrutinizer ignore-call */ 
463
                            display_page();

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...
463
			?>
464
		</div>
465
		<?php
466
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
467
468
	/**
469
	 * Outputs the post status navigation
470
	 *
471
	 * @return void
472
	 */
473
	public function post_status_navigation() {
474
		?>
475
		<ul class="subsubsub">
476
			<li class="searchform"><a class="current" href="#search"><?php esc_attr_e( 'Search', 'lsx-wetu-importer' ); ?></a> | </li>
477
			<li class="publish"><a href="#publish"><?php esc_attr_e( 'Published', 'lsx-wetu-importer' ); ?> <span class="count"> (<?php echo esc_attr( lsx_wetu_get_post_count( $this->tab_slug, 'publish ' ) ); ?>)</span></a> | </li>
0 ignored issues
show
Bug introduced by
lsx_wetu_get_post_count(...->tab_slug, 'publish ') of type void is incompatible with the type string expected by parameter $text of esc_attr(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

477
			<li class="publish"><a href="#publish"><?php esc_attr_e( 'Published', 'lsx-wetu-importer' ); ?> <span class="count"> (<?php echo esc_attr( /** @scrutinizer ignore-type */ lsx_wetu_get_post_count( $this->tab_slug, 'publish ' ) ); ?>)</span></a> | </li>
Loading history...
478
			<li class="pending"><a href="#pending"><?php esc_attr_e( 'Pending', 'lsx-wetu-importer' ); ?> <span class="count"> (<?php echo esc_attr( lsx_wetu_get_post_count( $this->tab_slug, 'pending ' ) ); ?>)</span></a>| </li>
479
			<li class="draft"><a href="#draft"><?php esc_attr_e( 'Draft', 'lsx-wetu-importer' ); ?></a> <span class="count"> (<?php echo esc_attr( lsx_wetu_get_post_count( $this->tab_slug, 'draft ' ) ); ?>)</span></li>
480
481
			<?php if ( 'tour' === $this->tab_slug ) { ?>
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
482
				<li class="import"> | <a class="import search-toggle"  href="#import"><?php esc_attr_e( 'WETU', 'lsx-wetu-importer' ); ?> <span class="count"> (<?php echo esc_attr( lsx_wetu_get_tour_count() ); ?>)</span></a></li>
483
			<?php } elseif ( ! empty( $this->queued_imports ) ) { ?>
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
484
				<li class="import"> | <a class="import search-toggle"  href="#import"><?php esc_attr_e( 'WETU Queue', 'lsx-wetu-importer' ); ?> <span class="count"> (<?php echo esc_attr( lsx_wetu_get_queue_count( $this->tab_slug ) ); ?>)</span></a></li>
485
			<?php } ?>
486
		</ul>
487
		<a class="documentation" target="_blank"href="https://tour-operator.lsdev.biz/documentation/extension/wetu-importer/"><?php esc_attr_e( 'Documentation', 'lsx-wetu-importer' ); ?></a>
488
		<?php
489
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
490
491
	/**
492
	 * Search Form
493
	 */
494
	public function search_form() {
495
		?>
496
		<form class="ajax-form" id="<?php echo esc_attr( $this->plugin_slug ); ?>-search-form" method="get" action="tools.php" data-type="<?php echo esc_attr( $this->tab_slug ); ?>">
497
			<input type="hidden" name="page" value="<?php echo esc_attr( $this->tab_slug ); ?>" />
498
499
			<?php do_action( 'lsx_wetu_importer_search_form', $this ); ?>
500
501
			<div class="normal-search">
502
				<input pattern=".{3,}" placeholder="3 characters minimum" class="keyword" name="keyword" value=""> <input class="button button-primary submit" type="submit" value="<?php esc_html_e( 'Search', 'lsx-wetu-importer' ); ?>" />
503
			</div>
504
505
			<div class="advanced-search hidden" style="display:none;">
506
				<textarea rows="10" cols="40" name="bulk-keywords"></textarea>
507
				<input class="button button-primary submit" type="submit" value="<?php esc_attr_e( 'Search', 'lsx-wetu-importer' ); ?>" />
508
			</div>
509
510
			<div class="ajax-loader" style="display:none;width:100%;text-align:center;">
511
				<img style="width:64px;" src="<?php echo esc_url( LSX_WETU_IMPORTER_URL . 'assets/images/ajaxloader.gif' ); ?>" />
512
			</div>
513
514
			<div class="ajax-loader-small" style="display:none;width:100%;text-align:center;">
515
				<img style="width:32px;" src="<?php echo esc_url( LSX_WETU_IMPORTER_URL . 'assets/images/ajaxloader.gif' ); ?>" />
516
			</div>
517
518
			<a class="button advanced-search-toggle" href="#"><?php esc_html_e( 'Bulk Search', 'lsx-wetu-importer' ); ?></a>
519
		</form>
520
		<?php
521
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
522
523
	/**
524
	 * The header of the item list
525
	 */
526
	public function table_header() {
527
		?>
528
		<thead>
529
		<tr>
530
			<th style="" class="manage-column column-cb check-column no-sort" id="cb" scope="col">
531
				<label for="cb-select-all-1" class="screen-reader-text"><?php esc_attr_e( 'Select All', 'lsx-wetu-importer' ); ?></label>
532
				<input type="checkbox" id="cb-select-all-1">
533
			</th>
534
			<th style="" class="manage-column column-order " id="order"><?php esc_attr_e( 'Order', 'lsx-wetu-importer' ); ?></th>
535
			<th style="" class="manage-column column-title " id="title" style="width:50%;" scope="col"><?php esc_attr_e( 'Title', 'lsx-wetu-importer' ); ?></th>
536
			<th style="" class="manage-column column-date" id="date" scope="col"><?php esc_attr_e( 'Date', 'lsx-wetu-importer' ); ?></th>
537
			<th style="" class="manage-column column-ssid" id="ssid" scope="col"><?php esc_attr_e( 'WETU ID', 'lsx-wetu-importer' ); ?></th>
538
		</tr>
539
		</thead>
540
		<?php
541
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
542
543
	/**
544
	 * The footer of the item list
545
	 */
546
	public function table_footer() {
547
		?>
548
		<tfoot>
549
		<tr>
550
			<th style="" class="manage-column column-cb check-column" id="cb" scope="col">
551
				<label for="cb-select-all-1" class="screen-reader-text"><?php esc_attr_e( 'Select All', 'lsx-wetu-importer' ); ?></label>
552
				<input type="checkbox" id="cb-select-all-1">
553
			</th>
554
			<th style="" class="manage-column column-order "><?php esc_attr_e( 'Order', 'lsx-wetu-importer' ); ?></th>
555
			<th style="" class="manage-column column-title" scope="col"><?php esc_attr_e( 'Title', 'lsx-wetu-importer' ); ?></th>
556
			<th style="" class="manage-column column-date" scope="col"><?php esc_attr_e( 'Date', 'lsx-wetu-importer' ); ?></th>
557
			<th style="" class="manage-column column-ssid" scope="col"><?php esc_attr_e( 'WETU ID', 'lsx-wetu-importer' ); ?></th>
558
		</tr>
559
		</tfoot>
560
		<?php
561
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
562
563
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$tab" missing
Loading history...
564
	 * Displays the importers navigation.
565
	 *
566
	 * @param $tab string
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
567
	 */
568
	public function navigation( $tab = '' ) {
569
		$post_types = array(
570
			'tour'          => esc_attr( 'Tours', 'lsx-wetu-importer' ),
0 ignored issues
show
Unused Code introduced by
The call to esc_attr() has too many arguments starting with 'lsx-wetu-importer'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

570
			'tour'          => /** @scrutinizer ignore-call */ esc_attr( 'Tours', 'lsx-wetu-importer' ),

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
introduced by
esc_attr() expects only one parameter. Did you mean to use esc_attr__() ? Found: esc_attr( 'Tours', 'lsx-wetu-importer' )
Loading history...
571
			'accommodation' => esc_attr( 'Accommodation', 'lsx-wetu-importer' ),
0 ignored issues
show
introduced by
esc_attr() expects only one parameter. Did you mean to use esc_attr__() ? Found: esc_attr( 'Accommodation', 'lsx-wetu-importer' )
Loading history...
572
			'destination'   => esc_attr( 'Destinations', 'lsx-wetu-importer' ),
0 ignored issues
show
introduced by
esc_attr() expects only one parameter. Did you mean to use esc_attr__() ? Found: esc_attr( 'Destinations', 'lsx-wetu-importer' )
Loading history...
573
		);
574
575
		echo wp_kses_post( '<div class="wp-filter">' );
576
		echo wp_kses_post( '<ul class="filter-links">' );
577
		echo wp_kses_post( '<li><a class="' . $this->itemd( $tab, 'default', 'current', false ) . '" href="' . admin_url( 'admin.php' ) . '?page=' . $this->plugin_slug . '">' . esc_attr__( 'Home', 'lsx-wetu-importer' ) . '</a></li>' );
578
579
		foreach ( $post_types as $post_type => $label ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
580
			echo wp_kses_post( ' | <li><a class="' . $this->itemd( $tab, $post_type, 'current', false ) . '" href="' . admin_url( 'admin.php' ) . '?page=' . $this->plugin_slug . '&tab=' . $post_type . '">' . $label . '</a></li>' );
581
		}
582
583
		echo wp_kses_post( ' | <li><a class="' . $this->itemd( $tab, 'settings', 'current', false ) . '" href="' . admin_url( 'admin.php' ) . '?page=' . $this->plugin_slug . '&tab=settings">' . esc_attr__( 'Settings', 'lsx-wetu-importer' ) . '</a></li>' );
584
		echo wp_kses_post( '</ul> </div>' );
585
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
586
587
	/**
588
	 * Wetu Status Bar.
589
	 */
590
	public function wetu_status() {
591
		$tours = get_transient( 'lsx_ti_tours' );
592
		echo '<div class="wetu-status tour-wetu-status"><h3>' . esc_html__( 'Wetu Status', 'lsx-wetu-importer' ) . ' - ';
593
594
		if ( '' === $tours || false === $tours || isset( $_GET['refresh_tours'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
introduced by
Processing form data without nonce verification.
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
595
			$result = $this->update_options();
596
			if ( true === $result ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
597
				echo '<span style="color:green;">' . esc_attr( 'Connected', 'lsx-wetu-importer' ) . '</span>';
0 ignored issues
show
Unused Code introduced by
The call to esc_attr() has too many arguments starting with 'lsx-wetu-importer'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

597
				echo '<span style="color:green;">' . /** @scrutinizer ignore-call */ esc_attr( 'Connected', 'lsx-wetu-importer' ) . '</span>';

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
introduced by
esc_attr() expects only one parameter. Did you mean to use esc_attr__() ? Found: esc_attr( 'Connected', 'lsx-wetu-importer' )
Loading history...
598
				echo ' - <small><a href="#">' . esc_attr( 'Refresh', 'lsx-wetu-importer' ) . '</a></small>';
0 ignored issues
show
introduced by
esc_attr() expects only one parameter. Did you mean to use esc_attr__() ? Found: esc_attr( 'Refresh', 'lsx-wetu-importer' )
Loading history...
599
			} else {
600
				echo '<span style="color:red;">' . wp_kses_post( $result ) . '</span>';
601
			}
602
		} else {
603
			echo '<span style="color:green;">' . esc_attr( 'Connected', 'lsx-wetu-importer' ) . '</span> - <small><a href="#">' . esc_attr( 'Refresh', 'lsx-wetu-importer' ) . '</a></small>';
0 ignored issues
show
introduced by
esc_attr() expects only one parameter. Did you mean to use esc_attr__() ? Found: esc_attr( 'Connected', 'lsx-wetu-importer' )
Loading history...
introduced by
esc_attr() expects only one parameter. Did you mean to use esc_attr__() ? Found: esc_attr( 'Refresh', 'lsx-wetu-importer' )
Loading history...
604
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
605
		echo '</h3>';
606
		echo '</div>';
607
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
608
609
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$selected" missing
Loading history...
610
	 * Set_taxonomy with some terms
611
	 */
612
	public function team_member_checkboxes( $selected = array() ) {
613
		if ( post_type_exists( 'team' ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
614
			?>
615
			<ul>
616
				<?php
617
					$team_args = array(
618
						'post_type'   => 'team',
619
						'post_status' => 'publish',
620
						'nopagin'     => true,
621
						'fields'      => 'ids',
622
					);
623
624
					$team_members = new WP_Query( $team_args );
625
626
					if ( $team_members->have_posts() ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
627
						foreach ( $team_members->posts as $member ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
628
							?>
629
							<li><input class="team" <?php $this->checked( $selected, $member ); ?> type="checkbox" value="<?php echo esc_attr( $member ); ?>" /> <?php echo wp_kses_post( get_the_title( $member ) ); ?></li>
630
							<?php
631
						}
632
					} else {
633
						?>
634
						<li><input class="team" type="checkbox" value="0" /> <?php esc_html_e( 'None', 'lsx-wetu-importer' ); ?></li>
635
						<?php
636
					}
637
					?>
638
			</ul>
639
			<?php
640
		}
641
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
642
643
644
	// GENERAL FUNCTIONS.
645
646
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$haystack" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$needle" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$echo" missing
Loading history...
647
	 * Checks to see if an item is checked.
648
	 *
649
	 * @param $haystack array|string
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
650
	 * @param $needle string
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
651
	 * @param $echo bool
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
652
	 */
653
	public function checked( $haystack = false, $needle = '', $echo = true ) {
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
654
		$return = $this->itemd( $haystack, $needle, 'checked', false );
655
656
		if ( '' !== $return ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
657
			if ( true === $echo ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
658
				echo wp_kses_post( $return );
659
			} else {
660
				return $return;
661
			}
662
		}
663
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
664
665
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$haystack" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$needle" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$echo" missing
Loading history...
666
	 * Checks to see if an item is checked.
667
	 *
668
	 * @param $haystack array|string
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
669
	 * @param $needle string
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
670
	 * @param $echo bool
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
671
	 */
672
	public function selected( $haystack = false, $needle = '', $echo = true ) {
673
		$return = $this->itemd( $haystack, $needle, 'selected' );
674
675
		if ( '' !== $return ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
676
			if ( true === $echo ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
677
				echo wp_kses_post( $return );
678
			} else {
679
				return $return;
680
			}
681
		}
682
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
683
684
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$haystack" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$needle" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$type" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$wrap" missing
Loading history...
685
	 * Checks to see if an item is selected. If $echo is false,  it will return the $type if conditions are true.
686
	 *
687
	 * @param $haystack array|string
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
688
	 * @param $needle string
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
689
	 * @param $type string
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
690
	 * @param $wrap bool
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
691
	 * @return $html string
0 ignored issues
show
Documentation Bug introduced by
The doc comment $html at position 0 could not be parsed: Unknown type name '$html' at position 0 in $html.
Loading history...
692
	 */
693
	public function itemd( $haystack = false, $needle = '', $type = '', $wrap = true ) {
694
		$html = '';
695
696
		if ( '' !== $type ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
697
			if ( ! is_array( $haystack ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
698
				$haystack = array( $haystack );
699
			}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
700
			if ( in_array( $needle, $haystack ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
701
				if ( true === $wrap || 'true' === $wrap ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
702
					$html = $type . '="' . $type . '"';
703
				} else {
704
					$html = $type;
705
				}
706
			}
707
		}
708
709
		return $html;
710
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
711
712
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$id" missing
Loading history...
713
	 * Grabs any attachments for the current item
714
	 */
715
	public function find_attachments( $id = false ) {
716
		if ( false !== $id ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
717
			if ( empty( $this->found_attachments ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
718
				$attachments_args = array(
719
					'post_parent'    => $id,
720
					'post_status'    => 'inherit',
721
					'post_type'      => 'attachment',
722
					'order'          => 'ASC',
723
					'nopagin'        => 'true',
724
					'posts_per_page' => '-1',
725
				);
726
727
				$attachments = new WP_Query( $attachments_args );
728
729
				if ( $attachments->have_posts() ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
730
					foreach ( $attachments->posts as $attachment ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
731
						$this->found_attachments[ $attachment->ID ] = str_replace( array( '.jpg', '.png', '.jpeg' ), '', $attachment->post_title );
732
					}
733
				}
734
			}
735
		}
736
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
737
738
	// CUSTOM FIELD FUNCTIONS.
739
740
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$value" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$meta_key" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$id" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$decrease" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$unique" missing
Loading history...
741
	 * Saves the room data
742
	 */
743
	public function save_custom_field( $value = false, $meta_key, $id, $decrease = false, $unique = true ) {
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
744
		if ( false !== $value ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
745
			if ( false !== $decrease ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
746
				$value = intval( $value );
747
				$value--;
748
			}
749
750
			$prev = get_post_meta( $id, $meta_key, true );
751
752
			if ( false !== $id && '0' !== $id && false !== $prev && true === $unique ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
753
				update_post_meta( $id, $meta_key, $value, $prev );
754
			} else {
755
				add_post_meta( $id, $meta_key, $value, $unique );
756
			}
757
		}
758
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
759
760
	/**
761
	 * Grabs the custom fields,  and resaves an array of unique items.
762
	 */
763
	public function cleanup_posts() {
764
		if ( ! empty( $this->cleanup_posts ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Blank line found at start of control structure
Loading history...
765
766
			foreach ( $this->cleanup_posts as $id => $key ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
767
				$prev_items = get_post_meta( $id, $key, false );
768
				$new_items  = array_unique( $prev_items );
0 ignored issues
show
Bug introduced by
It seems like $prev_items can also be of type false and null; however, parameter $array of array_unique() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

768
				$new_items  = array_unique( /** @scrutinizer ignore-type */ $prev_items );
Loading history...
769
				delete_post_meta( $id, $key );
770
771
				foreach ( $new_items as $new_item ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
772
					add_post_meta( $id, $key, $new_item, false );
773
				}
774
			}
775
		}
776
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
777
778
	// TAXONOMY FUNCTIONS.
779
780
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$taxonomy" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$terms" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$id" missing
Loading history...
781
	 * Set_taxonomy with some terms
782
	 */
783
	public function set_taxonomy( $taxonomy, $terms, $id ) {
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
784
		$result = array();
785
786
		if ( ! empty( $data ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
787
			foreach ( $data as $k ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
788
				if ( $id ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
789
					$term = term_exists( trim( $k ), $tax );
790
					if ( ! $term ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
791
						$term = wp_insert_term( trim( $k ), $tax );
792
793
						if ( is_wp_error( $term ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
794
							echo wp_kses_post( $term->get_error_message() );
795
						} else {
796
							wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true );
797
						}
798
					} else {
799
						wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true );
800
					}
801
				} else {
802
					$result[] = trim( $k );
803
				}
804
			}
805
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
806
		return $result;
807
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
808
809
	/**
810
	 * Sets the terms of the current post
811
	 *
812
	 * @param boolean $id
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
813
	 * @param boolean $name
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
814
	 * @param boolean $taxonomy
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
815
	 * @param boolean $parent
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
816
	 * @return void
0 ignored issues
show
Coding Style introduced by
Function return type is void, but function contains return statement
Loading history...
817
	 */
818
	public function set_term( $id = false, $name = false, $taxonomy = false, $parent = false ) {
819
		$term = term_exists( $name, $taxonomy );
820
		if ( ! $term ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
821
			if ( false !== $parent ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
822
				$parent = array(
823
					'parent' => $parent,
824
				);
825
			}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
826
			$term = wp_insert_term( trim( $name ), $taxonomy, $parent );
0 ignored issues
show
Bug introduced by
It seems like $parent can also be of type false; however, parameter $args of wp_insert_term() does only seem to accept array|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

826
			$term = wp_insert_term( trim( $name ), $taxonomy, /** @scrutinizer ignore-type */ $parent );
Loading history...
Bug introduced by
$name of type boolean is incompatible with the type string expected by parameter $string of trim(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

826
			$term = wp_insert_term( trim( /** @scrutinizer ignore-type */ $name ), $taxonomy, $parent );
Loading history...
827
828
			if ( is_wp_error( $term ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
829
				echo wp_kses_post( $term->get_error_message() );
830
			} else {
831
				wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true );
0 ignored issues
show
Bug introduced by
$id of type boolean is incompatible with the type integer expected by parameter $object_id of wp_set_object_terms(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

831
				wp_set_object_terms( /** @scrutinizer ignore-type */ $id, intval( $term['term_id'] ), $taxonomy, true );
Loading history...
832
			}
833
		} else {
834
			wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true );
835
		}
836
837
		return $term['term_id'];
838
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
839
840
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$taxonomy" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$selected" missing
Loading history...
841
	 * set_taxonomy with some terms
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
842
	 */
843
	public function taxonomy_checkboxes( $taxonomy = false, $selected = array() ) {
844
		$return = '';
845
846
		if ( false !== $taxonomy ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
847
			$return .= '<ul>';
848
			$terms   = get_terms(
849
				array(
850
					'taxonomy'   => $taxonomy,
851
					'hide_empty' => false,
852
				)
853
			);
854
855
			if ( ! is_wp_error( $terms ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
856
				foreach ( $terms as $term ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
857
					$return .= '<li><input class="' . $taxonomy . '" ' . $this->checked( $selected, $term->term_id, false ) . ' type="checkbox" value="' . $term->term_id . '" /> ' . $term->name . '</li>';
858
				}
859
			} else {
860
				$return .= '<li><input type="checkbox" value="" /> ' . __( 'None', 'lsx-wetu-importer' ) . '</li>';
861
			}
862
863
			$return .= '</ul>';
864
		}
865
866
		return $return;
867
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
868
869
	// MAP FUNCTIONS
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
870
871
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$data" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$id" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$zoom" missing
Loading history...
872
	 * Saves the longitude and lattitude, as well as sets the map marker.
873
	 */
874
	public function set_map_data( $data, $id, $zoom = '10' ) {
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
875
		$longitude = false;
876
		$latitude  = false;
877
		$address   = false;
878
879
		if ( isset( $data[0]['position'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
880
			if ( isset( $data[0]['position']['driving_latitude'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
881
				$latitude = $data[0]['position']['driving_latitude'];
882
			} elseif ( isset( $data[0]['position']['latitude'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
883
				$latitude = $data[0]['position']['latitude'];
884
			}
885
886
			if ( isset( $data[0]['position']['driving_longitude'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
887
				$longitude = $data[0]['position']['driving_longitude'];
888
			} elseif ( isset( $data[0]['position']['longitude'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
889
				$longitude = $data[0]['position']['longitude'];
890
			}
891
		}
892
893
		if ( isset( $data[0]['content'] ) && isset( $data[0]['content']['contact_information'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
894
			if ( isset( $data[0]['content']['contact_information']['address'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
895
				$address = strip_tags( $data[0]['content']['contact_information']['address'] );
0 ignored issues
show
introduced by
strip_tags() is discouraged. Use the more comprehensive wp_strip_all_tags() instead.
Loading history...
896
				$address = explode( "\n", $address );
897
898
				foreach ( $address as $bitkey => $bit ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
899
					$bit = ltrim( rtrim( $bit ) );
900
901
					if ( false === $bit || '' === $bit || null === $bit || empty( $bit ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
902
						unset( $address[ $bitkey ] );
903
					}
904
				}
905
906
				$address = implode( ', ', $address );
907
				$address = str_replace( ', , ', ', ', $address );
908
			}
909
		}
910
911
		if ( false !== $longitude ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
912
			$location_data = array(
913
				'address'   => (string) $address,
914
				'lat'       => (string) $latitude,
915
				'long'      => (string) $longitude,
916
				'zoom'      => (string) $zoom,
917
				'elevation' => '',
918
			);
919
920
			if ( false !== $id && '0' !== $id ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
921
				$prev = get_post_meta( $id, 'location', true );
922
				update_post_meta( $id, 'location', $location_data, $prev );
923
			} else {
924
				add_post_meta( $id, 'location', $location_data, true );
925
			}
926
		}
927
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
928
929
	// IMAGE FUNCTIONS
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
930
931
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$data" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$id" missing
Loading history...
932
	 * Creates the main gallery data
933
	 */
934
	public function set_featured_image( $data, $id ) {
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
935
		if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
936
			$this->featured_image = $this->attach_image(
937
				$data[0]['content']['images'][0],
938
				$id,
939
				array(
940
					'width'    => '800',
941
					'height'   => '600',
942
					'cropping' => 'h',
943
				)
944
			);
945
946
			if ( false !== $this->featured_image ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
947
				delete_post_meta( $id, '_thumbnail_id' );
948
				add_post_meta( $id, '_thumbnail_id', $this->featured_image, true );
949
			}
950
		}
951
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
952
953
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$content" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$id" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$data" missing
Loading history...
954
	 * Sets a banner image
955
	 */
956
	public function set_banner_image( $data, $id, $content = array( 'none' ) ) {
957
		if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
958
			if ( in_array( 'unique_banner_image', $content ) && isset( $data[0]['destination_image'] ) && is_array( $data[0]['destination_image'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
959
				$temp_banner = $this->attach_image(
960
					$data[0]['destination_image'],
961
					$id,
962
					array(
963
						'width'    => '1920',
964
						'height'   => '600',
965
						'cropping' => 'c',
966
					)
967
				);
968
			} else {
969
				$temp_banner = $this->attach_image(
970
					$data[0]['content']['images'][1],
971
					$id,
972
					array(
973
						'width'    => '1920',
974
						'height'   => '600',
975
						'cropping' => 'c',
976
					)
977
				);
978
			}
979
980
			if ( false !== $temp_banner ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
981
				$this->banner_image = $temp_banner;
982
983
				delete_post_meta( $id, 'image_group' );
984
985
				$new_banner = array(
986
					'banner_image' => array(
987
						'cmb-field-0' => $this->banner_image,
988
					),
989
				);
990
991
				add_post_meta( $id, 'image_group', $new_banner, true );
992
			}
993
		}
994
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
995
996
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$image_id" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$post_id" missing
Loading history...
997
	 * Checks if the current image is being used as a thumbnail somewhere else.
998
	 */
999
	public function is_image_being_used( $image_id = '', $post_id = '' ) {
1000
		global $wpdb;
1001
		$being_used = false;
1002
		if ( '' !== $image_id ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1003
			$sql     = "SELECT * FROM `{$wpdb->postmeta}` WHERE `post_id` != {$post_id} AND `meta_key` LIKE '_thumbnail_id' AND `meta_value` LIKE '{$image_id}'";
1004
			$results = $wpdb->query( $sql );
0 ignored issues
show
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Use placeholders and $wpdb->prepare(); found $sql
Loading history...
introduced by
Direct database call without caching detected. Consider using wp_cache_get() / wp_cache_set() or wp_cache_delete().
Loading history...
1005
			if ( false !== $results && ! empty( $results ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1006
				$being_used = true;
1007
			}
1008
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
1009
		return $being_used;
1010
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
1011
1012
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$id" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$data" missing
Loading history...
1013
	 * Creates the main gallery data
1014
	 */
1015
	public function create_main_gallery( $data, $id ) {
1016
		if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
1017
			if ( isset( $this->options['image_replacing'] ) && 'on' === $this->options['image_replacing'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
1018
				$current_gallery = get_post_meta( $id, 'gallery', false );
1019
1020
				if ( false !== $current_gallery && ! empty( $current_gallery ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1021
					foreach ( $current_gallery as $g ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
1022
						delete_post_meta( $id, 'gallery', $g );
1023
1024
						if ( 'attachment' === get_post_type( $g ) && false === $this->is_image_being_used( $g, $id ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1025
							wp_delete_attachment( $g, true );
1026
						}
1027
					}
1028
				}
1029
			}
1030
1031
			$counter = 0;
1032
1033
			foreach ( $data[0]['content']['images'] as $image_data ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1034
				if ( ( 0 === $counter && false !== $this->featured_image ) || ( 1 === $counter && false !== $this->banner_image ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1035
					$counter++;
1036
1037
					if ( false !== $this->image_limit && false !== $this->image_limit ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1038
						$this->image_limit++;
1039
					}
1040
1041
					continue;
1042
				}
1043
1044
				if ( false !== $this->image_limit && $counter >= $this->image_limit ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1045
					continue;
1046
				}
1047
1048
				$this->gallery_meta[] = $this->attach_image( $image_data, $id );
1049
				$counter++;
1050
			}
1051
1052
			if ( ! empty( $this->gallery_meta ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1053
				delete_post_meta( $id, 'gallery' );
1054
				$this->gallery_meta = array_unique( $this->gallery_meta );
1055
1056
				foreach ( $this->gallery_meta as $gallery_id ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
1057
					if ( false !== $gallery_id && '' !== $gallery_id && ! is_array( $gallery_id ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1058
						add_post_meta( $id, 'gallery', $gallery_id, false );
1059
					}
1060
				}
1061
			}
1062
		}
1063
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
1064
1065
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$args" missing
Loading history...
1066
	 * search_form
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
1067
	 */
1068
	public function get_scaling_url( $args = array() ) {
1069
		$defaults = array(
1070
			'width'    => '1024',
1071
			'height'   => '768',
1072
			// 'cropping' => 'w',
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1073
			'cropping' => 'h',
1074
		);
1075
1076
		if ( false !== $this->options ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
introduced by
The condition false !== $this->options is always true.
Loading history...
1077
			if ( isset( $this->options['width'] ) && '' !== $this->options['width'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1078
				$defaults['width'] = $this->options['width'];
1079
			}
1080
1081
			if ( isset( $this->options['height'] ) && '' !== $this->options['height'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1082
				$defaults['height'] = $this->options['height'];
1083
			}
1084
1085
			if ( isset( $this->options['cropping'] ) && '' !== $this->options['cropping'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1086
				$defaults['cropping'] = $this->options['cropping'];
1087
			}
1088
		}
1089
1090
		$args     = wp_parse_args( $args, $defaults );
1091
		$cropping = $args['cropping'];
1092
		$width    = $args['width'];
1093
		$height   = $args['height'];
1094
1095
		return 'https://wetu.com/ImageHandler/' . $cropping . $width . 'x' . $height . '/';
1096
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
1097
1098
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$image_sizes" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$v" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$banner" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$parent_id" missing
Loading history...
1099
	 * Attaches 1 image
1100
	 */
1101
	public function attach_image( $v = false, $parent_id, $image_sizes = false, $banner = false ) {
1102
		if ( false !== $v ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1103
			$temp_fragment = explode( '/', $v['url_fragment'] );
1104
			$url_filename  = $temp_fragment[ count( $temp_fragment ) - 1 ];
1105
			$url_filename  = str_replace( array( '.jpg', '.png', '.jpeg' ), '', $url_filename );
1106
			$url_filename  = trim( $url_filename );
1107
			$title         = $url_filename;
1108
			$url_filename  = str_replace( ' ', '_', $url_filename );
1109
1110
			if ( ! isset( $this->options['image_replacing'] ) && in_array( $url_filename, $this->found_attachments ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
introduced by
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1111
				return array_search( $url_filename, $this->found_attachments );
0 ignored issues
show
introduced by
Not using strict comparison for array_search; supply true for third argument.
Loading history...
1112
			}
1113
1114
			$postdata = array();
1115
1116
			if ( empty( $v['label'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1117
				$v['label'] = '';
1118
			}
1119
1120
			if ( ! empty( $v['description'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1121
				$desc    = wp_strip_all_tags( $v['description'] );
1122
				$posdata = array(
1123
					'post_excerpt' => $desc,
1124
				);
1125
			}
1126
1127
			if ( ! empty( $v['section'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
1128
				$desc    = wp_strip_all_tags( $v['section'] );
1129
				$posdata = array(
1130
					'post_excerpt' => $desc,
1131
				);
1132
			}
1133
1134
			$attach_id = null;
1135
			// Resizor - add option to setting if required.
1136
			$fragment  = str_replace( ' ', '%20', $v['url_fragment'] );
1137
			$url       = $this->get_scaling_url( $image_sizes ) . $fragment;
1138
			$attach_id = $this->attach_external_image2( $url, $parent_id, '', $v['label'], $postdata );
1139
			if ( ! empty( $attach_id ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
1140
				$this->found_attachments[ $attach_id ] = $url_filename;
1141
				add_post_meta( $attach_id, 'lsx_wetu_id', $v['url_fragment'], true );
0 ignored issues
show
Bug introduced by
It seems like $attach_id can also be of type WP_Error; however, parameter $post_id of add_post_meta() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1141
				add_post_meta( /** @scrutinizer ignore-type */ $attach_id, 'lsx_wetu_id', $v['url_fragment'], true );
Loading history...
1142
				return $attach_id;
1143
			}
1144
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
1145
		return false;
1146
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
1147
1148
	public function attach_external_image2( $url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array() ) {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function attach_external_image2()
Loading history...
1149
		if ( ! $url || ! $post_id ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
1150
			return new WP_Error( 'missing', 'Need a valid URL and post ID...' ); }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
1151
		$att_id = false;
1152
1153
		require_once ABSPATH . 'wp-admin/includes/file.php';
1154
		require_once ABSPATH . 'wp-admin/includes/media.php';
1155
		require_once ABSPATH . 'wp-admin/includes/image.php';
1156
		// Download file to temp location, returns full server path to temp file.
1157
1158
		$tmp   = tempnam( '/tmp', 'FOO' );
1159
		$image = wp_remote_get( $url );
1160
		if ( ! is_wp_error( $image ) && ! empty( $image ) && isset( $image['response'] ) && isset( $image['response']['code'] ) && 200 === $image['response']['code'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1161
			file_put_contents( $tmp, $image['body'] );
0 ignored issues
show
introduced by
File operations should use WP_Filesystem methods instead of direct PHP filesystem calls. Found: file_put_contents()
Loading history...
1162
			chmod( $tmp, '777' );
1163
1164
			preg_match( '/[^\?]+\.(tif|TIFF|jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG|pdf|PDF|bmp|BMP)/', $url, $matches );    // fix file filename for query strings
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
1165
			$url_filename = basename( $matches[0] );
1166
			$url_filename = str_replace( '%20', '_', $url_filename );
1167
			// extract filename from url for title
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
1168
			$url_type = wp_check_filetype( $url_filename );                                           // determine file type (ext and mime/type)
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
1169
1170
			// override filename if given, reconstruct server path.
1171
			if ( ! empty( $filename ) && ' ' != $filename ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
introduced by
Found: !=. Use strict comparisons (=== or !==).
Loading history...
1172
				$filename = sanitize_file_name( $filename );
1173
				$tmppath  = pathinfo( $tmp );
1174
1175
				$extension = '';
1176
				if ( isset( $tmppath['extension'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
1177
					$extension = $tmppath['extension'];
1178
				}
1179
1180
				$new = $tmppath['dirname'] . '/' . $filename . '.' . $extension;
1181
				rename( $tmp, $new );                                                                 // renames temp file on server
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
1182
				$tmp = $new;                                                                        // push new filename (in path) to be used in file array later
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
1183
			}
1184
1185
			// assemble file data (should be built like $_FILES since wp_handle_sideload() will be using).
1186
			$file_array['tmp_name'] = $tmp;                                                         // full server path to temp file
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
1187
1188
			if ( ! empty( $filename ) && ' ' != $filename ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
introduced by
Found: !=. Use strict comparisons (=== or !==).
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1189
				$file_array['name'] = $filename . '.' . $url_type['ext'];                           // user given filename for title, add original URL extension
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
1190
			} else {
1191
				$file_array['name'] = $url_filename;                                                // just use original URL filename
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
1192
			}
1193
1194
			// set additional wp_posts columns.
1195
			if ( empty( $post_data['post_title'] ) ) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
1196
1197
				$url_filename = str_replace( '%20', ' ', $url_filename );
1198
1199
				$post_data['post_title'] = basename( $url_filename, '.' . $url_type['ext'] );         // just use the original filename (no extension)
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
1200
			}
1201
1202
			// make sure gets tied to parent.
1203
			if ( empty( $post_data['post_parent'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
1204
				$post_data['post_parent'] = $post_id;
1205
			}
1206
1207
			// do the validation and storage stuff.
1208
			$att_id = media_handle_sideload( $file_array, $post_id, null, $post_data );             // $post_data can override the items saved to wp_posts table, like post_mime_type, guid, post_parent, post_title, post_content, post_status
1209
1210
			// If error storing permanently, unlink.
1211
			if ( is_wp_error( $att_id ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1212
				unlink( $file_array['tmp_name'] );
1213
				return false;
1214
			}
1215
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
1216
		return $att_id;
1217
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
1218
1219
	// AJAX FUNCTIONS
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
1220
	/**
1221
	 * Run through the accommodation grabbed from the DB.
1222
	 */
1223
	public function process_ajax_search() {
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
1224
		$this->current_importer->process_ajax_search();
1225
		die();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
1226
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
1227
1228
	/**
1229
	 * Connect to wetu
1230
	 */
1231
	public function process_ajax_import() {
1232
		$this->current_importer->process_ajax_import();
1233
		die();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
1234
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
1235
1236
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$response" missing
Loading history...
1237
	 * Formats the row for the completed list.
1238
	 */
1239
	public function format_completed_row( $response ) {
1240
		echo wp_kses_post( '<li class="post-' . $response . '"><span class="dashicons dashicons-yes"></span> <a target="_blank" href="' . get_permalink( $response ) . '">' . get_the_title( $response ) . '</a></li>' );
0 ignored issues
show
Bug introduced by
Are you sure get_permalink($response) of type false|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1240
		echo wp_kses_post( '<li class="post-' . $response . '"><span class="dashicons dashicons-yes"></span> <a target="_blank" href="' . /** @scrutinizer ignore-type */ get_permalink( $response ) . '">' . get_the_title( $response ) . '</a></li>' );
Loading history...
1241
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
1242
1243
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$response" missing
Loading history...
1244
	 * Formats the error.
1245
	 */
1246
	public function format_error( $response ) {
1247
		echo wp_kses_post( '<li class="post-error"><span class="dashicons dashicons-no"></span>' . $response . '</li>' );
1248
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
1249
1250
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$offset" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$needles" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$haystack" missing
Loading history...
1251
	 * Does a multine search
1252
	 */
1253
	public function multineedle_stripos( $haystack, $needles, $offset = 0 ) {
1254
		$found        = false;
1255
		$needle_count = count( $needles );
1256
1257
		foreach ( $needles as $needle ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
1258
			if ( false !== stripos( $haystack, $needle, $offset ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
1259
				$found[] = true;
1260
			}
1261
		}
1262
1263
		if ( false !== $found && count( $found ) === $needle_count ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
introduced by
The condition false !== $found is always false.
Loading history...
1264
			return true;
1265
		} else {
1266
			return false;
1267
		}
1268
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
1269
1270
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$post_type" missing
Loading history...
1271
	 * Grab all the current accommodation posts via the lsx_wetu_id field.
1272
	 */
1273
	public function find_current_accommodation( $post_type = 'accommodation' ) {
1274
		global $wpdb;
1275
		$return = array();
1276
1277
		// @codingStandardsIgnoreStart
1278
		$current_accommodation = $wpdb->get_results("
1279
			SELECT key1.post_id,key1.meta_value
1280
			FROM {$wpdb->postmeta} key1
1281
1282
			INNER JOIN  {$wpdb->posts} key2
1283
			ON key1.post_id = key2.ID
1284
1285
			WHERE key1.meta_key = 'lsx_wetu_id'
1286
			AND key2.post_type = '{$post_type}'
1287
1288
			LIMIT 0,5000
1289
		");
1290
		// @codingStandardsIgnoreEnd
1291
1292
		if ( null !== $current_accommodation && ! empty( $current_accommodation ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
1293
			foreach ( $current_accommodation as $accom ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
1294
				$return[ $accom->meta_value ] = $accom;
0 ignored issues
show
introduced by
Detected usage of meta_value, possible slow query.
Loading history...
1295
			}
1296
		}
1297
1298
		return $return;
1299
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
1300
1301
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$data" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$id" missing
Loading history...
1302
	 * Set the Video date
1303
	 */
1304
	public function set_video_data( $data, $id ) {
1305
		if ( ! empty( $data[0]['content']['youtube_videos'] ) && is_array( $data[0]['content']['youtube_videos'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1306
			$videos = false;
1307
1308
			foreach ( $data[0]['content']['youtube_videos'] as $video ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
1309
				$temp_video = array();
1310
1311
				if ( isset( $video['label'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1312
					$temp_video['title'] = $video['label'];
1313
				}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
1314
				if ( isset( $video['description'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
1315
					$temp_video['description'] = strip_tags( $video['description'] );
0 ignored issues
show
introduced by
strip_tags() is discouraged. Use the more comprehensive wp_strip_all_tags() instead.
Loading history...
1316
				}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
1317
				if ( isset( $video['url'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1318
					$temp_video['url'] = $video['url'];
1319
				}
1320
1321
				$temp_video['thumbnail'] = '';
1322
				$videos[]                = $temp_video;
1323
			}
1324
1325
			if ( false !== $id && '0' !== $id ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1326
				delete_post_meta( $id, 'videos' );
1327
			}
1328
1329
			foreach ( $videos as $video ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1330
				add_post_meta( $id, 'videos', $video, false );
1331
			}
1332
		}
1333
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
1334
1335
	public function shuffle_assoc( &$array ) {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function shuffle_assoc()
Loading history...
1336
		$new  = array();
1337
		$keys = array_keys( $array );
1338
1339
		shuffle( $keys );
1340
1341
		foreach ( $keys as $key ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
1342
			$new[ $key ] = $array[ $key ];
1343
		}
1344
1345
		$array = $new;
1346
1347
		return true;
1348
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
1349
1350
	/**
1351
	 * Save the list of Tours into an option
1352
	 */
1353
	public function update_options() {
1354
		$own     = '';
1355
		$options = array();
1356
		delete_option( 'lsx_ti_tours_api_options' );
1357
1358
		if ( isset( $_GET['own'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
introduced by
Processing form data without nonce verification.
Loading history...
1359
			$this->current_importer->url_qs .= '&own=true';
0 ignored issues
show
Bug introduced by
The property url_qs does not exist on integer.
Loading history...
1360
			$options[]                       = 'own';
1361
		}
1362
1363
		if ( isset( $_GET['type'] ) && 'allitineraries' !== $_GET['type'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
introduced by
Processing form data without nonce verification.
Loading history...
1364
			$this->current_importer->url_qs .= '&type=' . $_GET['type'];
0 ignored issues
show
introduced by
Processing form data without nonce verification.
Loading history...
introduced by
$_GET data not unslashed before sanitization. Use wp_unslash() or similar
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_GET['type']
Loading history...
1365
			$options[]                       = $_GET['type'];
0 ignored issues
show
introduced by
Detected usage of a non-sanitized input variable: $_GET['type']
Loading history...
introduced by
Processing form data without nonce verification.
Loading history...
introduced by
$_GET data not unslashed before sanitization. Use wp_unslash() or similar
Loading history...
1366
		} else {
1367
			$options[]                       = 'sample';
1368
			$this->current_importer->url_qs .= '&type=sample';
1369
		}
1370
1371
		$url  = str_replace( 'Pins', 'Itinerary', $this->current_importer->url . '/V8/List?' . $this->current_importer->url_qs );
0 ignored issues
show
Bug introduced by
The property url does not exist on integer.
Loading history...
1372
		$url .= '&results=2000';
1373
		add_option( 'lsx_ti_tours_api_options', $options );
1374
		$data  = wp_remote_get( $url );
1375
		$tours = json_decode( wp_remote_retrieve_body( $data ), true );
1376
1377
		if ( isset( $tours['error'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1378
			return $tours['error'];
1379
		} elseif ( isset( $tours['itineraries'] ) && ! empty( $tours['itineraries'] ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1380
			set_transient( 'lsx_ti_tours', $tours['itineraries'], 60 * 60 * 4 );
1381
			return true;
1382
		}
1383
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
1384
1385
	/**
1386
	 * Gets the post_id from the key
1387
	 *
1388
	 * @param boolean $wetu_id
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
1389
	 * @return string
1390
	 */
1391
	public function get_post_id_by_key_value( $wetu_id = false ) {
1392
		global $wpdb;
1393
		$id = false;
1394
		if ( false !== $wetu_id && '' !== $wetu_id ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1395
			$result = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM `$wpdb->postmeta` WHERE `meta_key` = 'lsx_wetu_id' AND `meta_value` = '%s'", array( $wetu_id ) ) );
0 ignored issues
show
introduced by
Simple placeholders should not be quoted in the query string in $wpdb->prepare(). Found: '%s'.
Loading history...
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Direct database call without caching detected. Consider using wp_cache_get() / wp_cache_set() or wp_cache_delete().
Loading history...
1396
			if ( false !== $result && ! empty( $result ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
1397
				$id = $result;
1398
			}
1399
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
1400
		return $id;
1401
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
1402
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$id" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$team_members" missing
Loading history...
1403
	 * Set the team memberon each item.
1404
	 */
1405
	public function set_team_member( $id, $team_members ) {
1406
		delete_post_meta( $id, 'team_to_' . $this->tab_slug );
1407
1408
		foreach ( $team_members as $team ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
1409
			add_post_meta( $id, 'team_to_' . $this->tab_slug, $team );
1410
		}
1411
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
1412
}
1413
1414
$lsx_wetu_importer = new LSX_WETU_Importer();
1415