Passed
Push — master ( e36f7a...bc1029 )
by Warwick
04:46
created
classes/class-lsx-wetu-importer.php 1 patch
Indentation   +1288 added lines, -1288 removed lines patch added patch discarded remove patch
@@ -13,465 +13,465 @@  discard block
 block discarded – undo
13 13
  */
14 14
 class LSX_WETU_Importer {
15 15
 
16
-	/**
17
-	 * Holds class instance
18
-	 *
19
-	 * @since 1.0.0
20
-	 *
21
-	 * @var      object|Module_Template
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
63
-	 *
64
-	 * @since 0.0.1
65
-	 *
66
-	 * @var      boolean
67
-	 */
68
-	public $scale_images = false;
69
-
70
-	/**
71
-	 * The WETU API Key
72
-	 */
73
-	public $api_key = false;
74
-
75
-	/**
76
-	 * The post types this works with.
77
-	 */
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
117
-	 *
118
-	 * @var      int
119
-	 */
120
-	public $featured_image = false;
121
-
122
-	/**
123
-	 * the banner image
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.
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() {
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() ) {
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'] ) {
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 ) {
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
-	}
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
-	}
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;
255
-
256
-		$temp_options = get_option( '_lsx-to_settings', false );
257
-		if ( false !== $temp_options ) {
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' ) ) {
266
-			if ( isset( $options['api_key'] ) && '' !== $options['api_key'] ) {
267
-				$this->api_key = $options['api_key'];
268
-			}
269
-		} else {
270
-			$this->api_key = WETU_API_KEY;
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'] ) ) {
277
-				$this->tab_slug = sanitize_text_field( $_GET['tab'] );
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'] ) ) {
289
-			$this->scale_images = true;
290
-
291
-			$width = '1024';
292
-			if ( isset( $this->options['width'] ) && '' !== $this->options['width'] ) {
293
-				$width = $this->options['width'];
294
-			}
295
-
296
-			$height = '768';
297
-			if ( isset( $this->options['height'] ) && '' !== $this->options['height'] ) {
298
-				$height = $this->options['height'];
299
-			}
300
-
301
-			$cropping = 'w';
302
-			if ( isset( $this->options['cropping'] ) && '' !== $this->options['cropping'] ) {
303
-				$cropping = $this->options['cropping'];
304
-			}
305
-
306
-			$this->image_scaling_url = 'https://wetu.com/ImageHandler/' . $cropping . $width . 'x' . $height . '/';
307
-		}
308
-
309
-		if ( isset( $this->options ) && isset( $this->options['image_limit'] ) && '' !== $this->options['image_limit'] ) {
310
-			$this->image_limit = $this->options['image_limit'];
311
-		}
312
-	}
313
-
314
-	// COMPATABILITY FUNCTIONS.
315
-
316
-	/**
317
-	 * On plugin activation
318
-	 *
319
-	 * @since 1.0.0
320
-	 */
321
-	public static function register_activation_hook() {
322
-		self::compatible_version_check_on_activation();
323
-	}
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', '<' ) ) {
332
-			return false;
333
-		}
334
-
335
-		return true;
336
-	}
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() ) {
346
-			if ( is_plugin_active( plugin_basename( LSX_WETU_IMPORTER_CORE ) ) ) {
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'] ) ) {
351
-					unset( $_GET['activate'] );
352
-				}
353
-			}
354
-		}
355
-	}
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
-	}
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() ) {
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
-	}
380
-
381
-	// DISPLAY FUNCTIONS.
382
-
383
-	/**
384
-	 * Load the importer class you want to use
385
-	 */
386
-	public function load_class() {
387
-		switch ( $this->tab_slug ) {
388
-			case 'accommodation':
389
-				$this->current_importer = new LSX_WETU_Importer_Accommodation();
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
-	}
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
-	}
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 ) {
422
-			$min = '';
423
-		} else {
424
-			$min = '.min';
425
-		}
426
-
427
-		$min = '';
428
-
429
-		if ( is_admin() && isset( $_GET['page'] ) && $this->plugin_slug === $_GET['page'] ) {
430
-
431
-			//wp_enqueue_style( 'datatables', LSX_WETU_IMPORTER_URL . 'assets/css/datatables' . $min . '.css', LSX_WETU_IMPORTER_VER, true );
432
-			wp_enqueue_style( 'lsx-wetu-importer-style', LSX_WETU_IMPORTER_URL . 'assets/css/lsx-wetu-importer.css', LSX_WETU_IMPORTER_VER, true );
433
-
434
-			if ( isset( $_GET['tab'] ) ) {
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
-	}
449
-
450
-	/**
451
-	 * Display the importer administration screen
452
-	 */
453
-	public function display_page() {
454
-		?>
16
+     /**
17
+      * Holds class instance
18
+      *
19
+      * @since 1.0.0
20
+      *
21
+      * @var      object|Module_Template
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
63
+      *
64
+      * @since 0.0.1
65
+      *
66
+      * @var      boolean
67
+      */
68
+     public $scale_images = false;
69
+
70
+     /**
71
+      * The WETU API Key
72
+      */
73
+     public $api_key = false;
74
+
75
+     /**
76
+      * The post types this works with.
77
+      */
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
117
+      *
118
+      * @var      int
119
+      */
120
+     public $featured_image = false;
121
+
122
+     /**
123
+      * the banner image
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.
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() {
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() ) {
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'] ) {
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 ) {
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
+     }
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
+     }
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;
255
+
256
+          $temp_options = get_option( '_lsx-to_settings', false );
257
+          if ( false !== $temp_options ) {
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' ) ) {
266
+               if ( isset( $options['api_key'] ) && '' !== $options['api_key'] ) {
267
+                    $this->api_key = $options['api_key'];
268
+               }
269
+          } else {
270
+               $this->api_key = WETU_API_KEY;
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'] ) ) {
277
+                    $this->tab_slug = sanitize_text_field( $_GET['tab'] );
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'] ) ) {
289
+               $this->scale_images = true;
290
+
291
+               $width = '1024';
292
+               if ( isset( $this->options['width'] ) && '' !== $this->options['width'] ) {
293
+                    $width = $this->options['width'];
294
+               }
295
+
296
+               $height = '768';
297
+               if ( isset( $this->options['height'] ) && '' !== $this->options['height'] ) {
298
+                    $height = $this->options['height'];
299
+               }
300
+
301
+               $cropping = 'w';
302
+               if ( isset( $this->options['cropping'] ) && '' !== $this->options['cropping'] ) {
303
+                    $cropping = $this->options['cropping'];
304
+               }
305
+
306
+               $this->image_scaling_url = 'https://wetu.com/ImageHandler/' . $cropping . $width . 'x' . $height . '/';
307
+          }
308
+
309
+          if ( isset( $this->options ) && isset( $this->options['image_limit'] ) && '' !== $this->options['image_limit'] ) {
310
+               $this->image_limit = $this->options['image_limit'];
311
+          }
312
+     }
313
+
314
+     // COMPATABILITY FUNCTIONS.
315
+
316
+     /**
317
+      * On plugin activation
318
+      *
319
+      * @since 1.0.0
320
+      */
321
+     public static function register_activation_hook() {
322
+          self::compatible_version_check_on_activation();
323
+     }
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', '<' ) ) {
332
+               return false;
333
+          }
334
+
335
+          return true;
336
+     }
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() ) {
346
+               if ( is_plugin_active( plugin_basename( LSX_WETU_IMPORTER_CORE ) ) ) {
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'] ) ) {
351
+                         unset( $_GET['activate'] );
352
+                    }
353
+               }
354
+          }
355
+     }
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
+     }
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() ) {
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
+     }
380
+
381
+     // DISPLAY FUNCTIONS.
382
+
383
+     /**
384
+      * Load the importer class you want to use
385
+      */
386
+     public function load_class() {
387
+          switch ( $this->tab_slug ) {
388
+               case 'accommodation':
389
+                    $this->current_importer = new LSX_WETU_Importer_Accommodation();
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
+     }
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
+     }
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 ) {
422
+               $min = '';
423
+          } else {
424
+               $min = '.min';
425
+          }
426
+
427
+          $min = '';
428
+
429
+          if ( is_admin() && isset( $_GET['page'] ) && $this->plugin_slug === $_GET['page'] ) {
430
+
431
+               //wp_enqueue_style( 'datatables', LSX_WETU_IMPORTER_URL . 'assets/css/datatables' . $min . '.css', LSX_WETU_IMPORTER_VER, true );
432
+               wp_enqueue_style( 'lsx-wetu-importer-style', LSX_WETU_IMPORTER_URL . 'assets/css/lsx-wetu-importer.css', LSX_WETU_IMPORTER_VER, true );
433
+
434
+               if ( isset( $_GET['tab'] ) ) {
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
+     }
449
+
450
+     /**
451
+      * Display the importer administration screen
452
+      */
453
+     public function display_page() {
454
+          ?>
455 455
 		<div class="wrap">
456 456
 			<?php
457
-			$this->navigation( $this->tab_slug );
458
-			if ( 'default' !== $this->tab_slug && 'settings' !== $this->tab_slug ) {
459
-				$this->wetu_status();
460
-				$this->post_status_navigation();
461
-			}
462
-			$this->current_importer->display_page();
463
-			?>
457
+               $this->navigation( $this->tab_slug );
458
+               if ( 'default' !== $this->tab_slug && 'settings' !== $this->tab_slug ) {
459
+                    $this->wetu_status();
460
+                    $this->post_status_navigation();
461
+               }
462
+               $this->current_importer->display_page();
463
+               ?>
464 464
 		</div>
465 465
 		<?php
466
-	}
467
-
468
-	/**
469
-	 * Outputs the post status navigation
470
-	 *
471
-	 * @return void
472
-	 */
473
-	public function post_status_navigation() {
474
-		?>
466
+     }
467
+
468
+     /**
469
+      * Outputs the post status navigation
470
+      *
471
+      * @return void
472
+      */
473
+     public function post_status_navigation() {
474
+          ?>
475 475
 		<ul class="subsubsub">
476 476
 			<li class="searchform"><a class="current" href="#search"><?php esc_attr_e( 'Search', 'lsx-wetu-importer' ); ?></a> | </li>
477 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>
@@ -486,13 +486,13 @@  discard block
 block discarded – undo
486 486
 		</ul>
487 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 488
 		<?php
489
-	}
489
+     }
490 490
 
491
-	/**
492
-	 * Search Form
493
-	 */
494
-	public function search_form() {
495
-		?>
491
+     /**
492
+      * Search Form
493
+      */
494
+     public function search_form() {
495
+          ?>
496 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 497
 			<input type="hidden" name="page" value="<?php echo esc_attr( $this->tab_slug ); ?>" />
498 498
 
@@ -518,13 +518,13 @@  discard block
 block discarded – undo
518 518
 			<a class="button advanced-search-toggle" href="#"><?php esc_html_e( 'Bulk Search', 'lsx-wetu-importer' ); ?></a>
519 519
 		</form>
520 520
 		<?php
521
-	}
521
+     }
522 522
 
523
-	/**
524
-	 * The header of the item list
525
-	 */
526
-	public function table_header() {
527
-		?>
523
+     /**
524
+      * The header of the item list
525
+      */
526
+     public function table_header() {
527
+          ?>
528 528
 		<thead>
529 529
 		<tr>
530 530
 			<th style="" class="manage-column column-cb check-column no-sort" id="cb" scope="col">
@@ -538,13 +538,13 @@  discard block
 block discarded – undo
538 538
 		</tr>
539 539
 		</thead>
540 540
 		<?php
541
-	}
541
+     }
542 542
 
543
-	/**
544
-	 * The footer of the item list
545
-	 */
546
-	public function table_footer() {
547
-		?>
543
+     /**
544
+      * The footer of the item list
545
+      */
546
+     public function table_footer() {
547
+          ?>
548 548
 		<tfoot>
549 549
 		<tr>
550 550
 			<th style="" class="manage-column column-cb check-column" id="cb" scope="col">
@@ -558,710 +558,710 @@  discard block
 block discarded – undo
558 558
 		</tr>
559 559
 		</tfoot>
560 560
 		<?php
561
-	}
562
-
563
-	/**
564
-	 * Displays the importers navigation.
565
-	 *
566
-	 * @param $tab string
567
-	 */
568
-	public function navigation( $tab = '' ) {
569
-		$post_types = array(
570
-			'tour'          => esc_attr( 'Tours', 'lsx-wetu-importer' ),
571
-			'accommodation' => esc_attr( 'Accommodation', 'lsx-wetu-importer' ),
572
-			'destination'   => esc_attr( 'Destinations', 'lsx-wetu-importer' ),
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 ) {
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
-	}
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'] ) ) {
595
-			$result = $this->update_options();
596
-			if ( true === $result ) {
597
-				echo '<span style="color:green;">' . esc_attr( 'Connected', 'lsx-wetu-importer' ) . '</span>';
598
-				echo ' - <small><a href="#">' . esc_attr( 'Refresh', 'lsx-wetu-importer' ) . '</a></small>';
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>';
604
-		}
605
-		echo '</h3>';
606
-		echo '</div>';
607
-	}
608
-
609
-	/**
610
-	 * Set_taxonomy with some terms
611
-	 */
612
-	public function team_member_checkboxes( $selected = array() ) {
613
-		if ( post_type_exists( 'team' ) ) { 
614
-        ?>
561
+     }
562
+
563
+     /**
564
+      * Displays the importers navigation.
565
+      *
566
+      * @param $tab string
567
+      */
568
+     public function navigation( $tab = '' ) {
569
+          $post_types = array(
570
+               'tour'          => esc_attr( 'Tours', 'lsx-wetu-importer' ),
571
+               'accommodation' => esc_attr( 'Accommodation', 'lsx-wetu-importer' ),
572
+               'destination'   => esc_attr( 'Destinations', 'lsx-wetu-importer' ),
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 ) {
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
+     }
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'] ) ) {
595
+               $result = $this->update_options();
596
+               if ( true === $result ) {
597
+                    echo '<span style="color:green;">' . esc_attr( 'Connected', 'lsx-wetu-importer' ) . '</span>';
598
+                    echo ' - <small><a href="#">' . esc_attr( 'Refresh', 'lsx-wetu-importer' ) . '</a></small>';
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>';
604
+          }
605
+          echo '</h3>';
606
+          echo '</div>';
607
+     }
608
+
609
+     /**
610
+      * Set_taxonomy with some terms
611
+      */
612
+     public function team_member_checkboxes( $selected = array() ) {
613
+          if ( post_type_exists( 'team' ) ) { 
614
+          ?>
615 615
 			<ul>
616 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() ) {
627
-						foreach ( $team_members->posts as $member ) {
628
-							?>
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() ) {
627
+                              foreach ( $team_members->posts as $member ) {
628
+                                   ?>
629 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 630
 							<?php
631
-						}
632
-					} else { 
631
+                              }
632
+                         } else { 
633 633
                     ?>
634 634
 						<li><input class="team" type="checkbox" value="0" /> <?php esc_html_e( 'None', 'lsx-wetu-importer' ); ?></li>
635 635
 					<?php 
636 636
                     }
637
-				?>
637
+                    ?>
638 638
 			</ul>
639 639
 		<?php 
640
-        }
641
-	}
642
-
643
-
644
-	// GENERAL FUNCTIONS.
645
-
646
-	/**
647
-	 * Checks to see if an item is checked.
648
-	 *
649
-	 * @param $haystack array|string
650
-	 * @param $needle string
651
-	 * @param $echo bool
652
-	 */
653
-	public function checked( $haystack = false, $needle = '', $echo = true ) {
654
-		$return = $this->itemd( $haystack, $needle, 'checked', false );
655
-
656
-		if ( '' !== $return ) {
657
-			if ( true === $echo ) {
658
-				echo wp_kses_post( $return );
659
-			} else {
660
-				return $return;
661
-			}
662
-		}
663
-	}
664
-
665
-	/**
666
-	 * Checks to see if an item is checked.
667
-	 *
668
-	 * @param $haystack array|string
669
-	 * @param $needle string
670
-	 * @param $echo bool
671
-	 */
672
-	public function selected( $haystack = false, $needle = '', $echo = true ) {
673
-		$return = $this->itemd( $haystack, $needle, 'selected' );
674
-
675
-		if ( '' !== $return ) {
676
-			if ( true === $echo ) {
677
-				echo wp_kses_post( $return );
678
-			} else {
679
-				return $return;
680
-			}
681
-		}
682
-	}
683
-
684
-	/**
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
688
-	 * @param $needle string
689
-	 * @param $type string
690
-	 * @param $wrap bool
691
-	 * @return $html string
692
-	 */
693
-	public function itemd( $haystack = false, $needle = '', $type = '', $wrap = true ) {
694
-		$html = '';
695
-
696
-		if ( '' !== $type ) {
697
-			if ( ! is_array( $haystack ) ) {
698
-				$haystack = array( $haystack );
699
-			}
700
-			if ( in_array( $needle, $haystack ) ) {
701
-				if ( true === $wrap || 'true' === $wrap ) {
702
-					$html = $type . '="' . $type . '"';
703
-				} else {
704
-					$html = $type;
705
-				}
706
-			}
707
-		}
708
-
709
-		return $html;
710
-	}
711
-
712
-	/**
713
-	 * Grabs any attachments for the current item
714
-	 */
715
-	public function find_attachments( $id = false ) {
716
-		if ( false !== $id ) {
717
-			if ( empty( $this->found_attachments ) ) {
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() ) {
730
-					foreach ( $attachments->posts as $attachment ) {
731
-						$this->found_attachments[ $attachment->ID ] = str_replace( array( '.jpg', '.png', '.jpeg' ), '', $attachment->post_title );
732
-					}
733
-				}
734
-			}
735
-		}
736
-	}
737
-
738
-	// CUSTOM FIELD FUNCTIONS.
739
-
740
-	/**
741
-	 * Saves the room data
742
-	 */
743
-	public function save_custom_field( $value = false, $meta_key, $id, $decrease = false, $unique = true ) {
744
-		if ( false !== $value ) {
745
-			if ( false !== $decrease ) {
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 ) {
753
-				update_post_meta( $id, $meta_key, $value, $prev );
754
-			} else {
755
-				add_post_meta( $id, $meta_key, $value, $unique );
756
-			}
757
-		}
758
-	}
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 ) ) {
765
-
766
-			foreach ( $this->cleanup_posts as $id => $key ) {
767
-				$prev_items = get_post_meta( $id, $key, false );
768
-				$new_items = array_unique( $prev_items );
769
-				delete_post_meta( $id, $key );
770
-
771
-				foreach ( $new_items as $new_item ) {
772
-					add_post_meta( $id, $key, $new_item, false );
773
-				}
774
-			}
775
-		}
776
-	}
777
-
778
-	// TAXONOMY FUNCTIONS.
779
-
780
-	/**
781
-	 * Set_taxonomy with some terms
782
-	 */
783
-	public function set_taxonomy( $taxonomy, $terms, $id ) {
784
-		$result = array();
785
-
786
-		if ( ! empty( $data ) ) {
787
-			foreach ( $data as $k ) {
788
-				if ( $id ) {
789
-					$term = term_exists( trim( $k ), $tax );
790
-					if ( ! $term ) {
791
-						$term = wp_insert_term( trim( $k ), $tax );
792
-
793
-						if ( is_wp_error( $term ) ) {
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
-		}
806
-		return $result;
807
-	}
808
-
809
-	/**
810
-	 * Sets the terms of the current post
811
-	 *
812
-	 * @param boolean $id
813
-	 * @param boolean $name
814
-	 * @param boolean $taxonomy
815
-	 * @param boolean $parent
816
-	 * @return void
817
-	 */
818
-	public function set_term( $id = false, $name = false, $taxonomy = false, $parent = false ) {
819
-		$term = term_exists( $name, $taxonomy );
820
-		if ( ! $term ) {
821
-			if ( false !== $parent ) {
822
-				$parent = array(
823
-					'parent' => $parent,
824
-				);
825
-			}
826
-			$term = wp_insert_term( trim( $name ), $taxonomy, $parent );
827
-
828
-			if ( is_wp_error( $term ) ) {
829
-				echo wp_kses_post( $term->get_error_message() );
830
-			} else {
831
-				wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true );
832
-			}
833
-		} else {
834
-			wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true );
835
-		}
836
-
837
-		return $term['term_id'];
838
-	}
839
-
840
-	/**
841
-	 * set_taxonomy with some terms
842
-	 */
843
-	public function taxonomy_checkboxes( $taxonomy = false, $selected = array() ) {
844
-		$return = '';
845
-
846
-		if ( false !== $taxonomy ) {
847
-			$return .= '<ul>';
848
-			$terms = get_terms( array(
849
-				'taxonomy' => $taxonomy,
850
-				'hide_empty' => false,
851
-			) );
852
-
853
-			if ( ! is_wp_error( $terms ) ) {
854
-				foreach ( $terms as $term ) {
855
-					$return .= '<li><input class="' . $taxonomy . '" ' . $this->checked( $selected, $term->term_id, false ) . ' type="checkbox" value="' . $term->term_id . '" /> ' . $term->name . '</li>';
856
-				}
857
-			} else {
858
-				$return .= '<li><input type="checkbox" value="" /> ' . __( 'None', 'lsx-wetu-importer' ) . '</li>';
859
-			}
860
-
861
-			$return .= '</ul>';
862
-		}
863
-
864
-		return $return;
865
-	}
866
-
867
-	// MAP FUNCTIONS
868
-
869
-	/**
870
-	 * Saves the longitude and lattitude, as well as sets the map marker.
871
-	 */
872
-	public function set_map_data( $data, $id, $zoom = '10' ) {
873
-		$longitude = false;
874
-		$latitude = false;
875
-		$address = false;
876
-
877
-		if ( isset( $data[0]['position'] ) ) {
878
-			if ( isset( $data[0]['position']['driving_latitude'] ) ) {
879
-				$latitude = $data[0]['position']['driving_latitude'];
880
-			} elseif ( isset( $data[0]['position']['latitude'] ) ) {
881
-				$latitude = $data[0]['position']['latitude'];
882
-			}
883
-
884
-			if ( isset( $data[0]['position']['driving_longitude'] ) ) {
885
-				$longitude = $data[0]['position']['driving_longitude'];
886
-			} elseif ( isset( $data[0]['position']['longitude'] ) ) {
887
-				$longitude = $data[0]['position']['longitude'];
888
-			}
889
-		}
890
-
891
-		if ( isset( $data[0]['content'] ) && isset( $data[0]['content']['contact_information'] ) ) {
892
-			if ( isset( $data[0]['content']['contact_information']['address'] ) ) {
893
-				$address = strip_tags( $data[0]['content']['contact_information']['address'] );
894
-				$address = explode( "\n", $address );
895
-
896
-				foreach ( $address as $bitkey => $bit ) {
897
-					$bit = ltrim( rtrim( $bit ) );
898
-
899
-					if ( false === $bit || '' === $bit || null === $bit || empty( $bit ) ) {
900
-						unset( $address[ $bitkey ] );
901
-					}
902
-				}
903
-
904
-				$address = implode( ', ', $address );
905
-				$address = str_replace( ', , ', ', ', $address );
906
-			}
907
-		}
908
-
909
-		if ( false !== $longitude ) {
910
-			$location_data = array(
911
-				'address'   => (string) $address,
912
-				'lat'       => (string) $latitude,
913
-				'long'      => (string) $longitude,
914
-				'zoom'      => (string) $zoom,
915
-				'elevation' => '',
916
-			);
917
-
918
-			if ( false !== $id && '0' !== $id ) {
919
-				$prev = get_post_meta( $id, 'location', true );
920
-				update_post_meta( $id, 'location', $location_data, $prev );
921
-			} else {
922
-				add_post_meta( $id, 'location', $location_data, true );
923
-			}
924
-		}
925
-	}
926
-
927
-	// IMAGE FUNCTIONS
928
-
929
-	/**
930
-	 * Creates the main gallery data
931
-	 */
932
-	public function set_featured_image( $data, $id ) {
933
-		if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) {
934
-			$this->featured_image = $this->attach_image( $data[0]['content']['images'][0], $id,  array(
935
-				'width' => '800',
936
-				'height' => '600',
937
-				'cropping' => 'h',
938
-			) );
939
-
940
-			if ( false !== $this->featured_image ) {
941
-				delete_post_meta( $id, '_thumbnail_id' );
942
-				add_post_meta( $id, '_thumbnail_id', $this->featured_image, true );
943
-			}
944
-		}
945
-	}
946
-
947
-	/**
948
-	 * Sets a banner image
949
-	 */
950
-	public function set_banner_image( $data, $id, $content = array( 'none' ) ) {
951
-		if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) {
952
-			if ( in_array( 'unique_banner_image', $content ) && isset( $data[0]['destination_image'] ) && is_array( $data[0]['destination_image'] ) ) {
953
-				$temp_banner = $this->attach_image( $data[0]['destination_image'], $id, array(
954
-					'width' => '1920',
955
-					'height' => '600',
956
-					'cropping' => 'c',
957
-				));
958
-			} else {
959
-				$temp_banner = $this->attach_image( $data[0]['content']['images'][1], $id, array(
960
-					'width' => '1920',
961
-					'height' => '600',
962
-					'cropping' => 'c',
963
-				));
964
-			}
965
-
966
-			if ( false !== $temp_banner ) {
967
-				$this->banner_image = $temp_banner;
968
-
969
-				delete_post_meta( $id, 'image_group' );
970
-
971
-				$new_banner = array(
972
-					'banner_image' => array(
973
-						'cmb-field-0' => $this->banner_image,
974
-					),
975
-				);
976
-
977
-				add_post_meta( $id, 'image_group', $new_banner, true );
978
-			}
979
-		}
980
-	}
981
-
982
-	/**
983
-	 * Checks if the current image is being used as a thumbnail somewhere else.
984
-	 */
985
-	public function is_image_being_used( $image_id = '', $post_id = '' ) {
986
-		global $wpdb;
987
-		$being_used = false;
988
-		if ( '' !== $image_id ) {
989
-			$sql = "SELECT * FROM `{$wpdb->postmeta}` WHERE `post_id` != {$post_id} AND `meta_key` LIKE '_thumbnail_id' AND `meta_value` LIKE '{$image_id}'";
990
-			$results = $wpdb->query( $sql );
991
-			if ( false !== $results && ! empty( $results ) ) {
992
-				$being_used = true;
993
-			}
994
-		}
995
-		return $being_used;
996
-	}
997
-
998
-	/**
999
-	 * Creates the main gallery data
1000
-	 */
1001
-	public function create_main_gallery( $data, $id ) {
1002
-		if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) {
1003
-			if ( isset( $this->options['image_replacing'] ) && 'on' === $this->options['image_replacing'] ) {
1004
-				$current_gallery = get_post_meta( $id, 'gallery', false );
1005
-
1006
-				if ( false !== $current_gallery && ! empty( $current_gallery ) ) {
1007
-					foreach ( $current_gallery as $g ) {
1008
-						delete_post_meta( $id, 'gallery', $g );
1009
-
1010
-						if ( 'attachment' === get_post_type( $g ) && false === $this->is_image_being_used( $g, $id ) ) {
1011
-							wp_delete_attachment( $g, true );
1012
-						}
1013
-					}
1014
-				}
1015
-			}
1016
-
1017
-			$counter = 0;
1018
-
1019
-			foreach ( $data[0]['content']['images'] as $image_data ) {
1020
-				if ( ( 0 === $counter && false !== $this->featured_image ) || ( 1 === $counter && false !== $this->banner_image ) ) {
1021
-					$counter++;
1022
-
1023
-					if ( false !== $this->image_limit && false !== $this->image_limit ) {
1024
-						$this->image_limit++;
1025
-					}
1026
-
1027
-					continue;
1028
-				}
1029
-
1030
-				if ( false !== $this->image_limit && $counter >= $this->image_limit ) {
1031
-					continue;
1032
-				}
1033
-
1034
-				$this->gallery_meta[] = $this->attach_image( $image_data, $id );
1035
-				$counter++;
1036
-			}
1037
-
1038
-			if ( ! empty( $this->gallery_meta ) ) {
1039
-				delete_post_meta( $id, 'gallery' );
1040
-				$this->gallery_meta = array_unique( $this->gallery_meta );
1041
-
1042
-				foreach ( $this->gallery_meta as $gallery_id ) {
1043
-					if ( false !== $gallery_id && '' !== $gallery_id && ! is_array( $gallery_id ) ) {
1044
-						add_post_meta( $id, 'gallery', $gallery_id, false );
1045
-					}
1046
-				}
1047
-			}
1048
-		}
1049
-	}
1050
-
1051
-	/**
1052
-	 * search_form
1053
-	 */
1054
-	public function get_scaling_url( $args = array() ) {
1055
-		$defaults = array(
1056
-			'width' => '1024',
1057
-			'height' => '768',
1058
-			//'cropping' => 'w',
1059
-			'cropping' => 'h',
1060
-		);
1061
-
1062
-		if ( false !== $this->options ) {
1063
-			if ( isset( $this->options['width'] ) && '' !== $this->options['width'] ) {
1064
-				$defaults['width'] = $this->options['width'];
1065
-			}
1066
-
1067
-			if ( isset( $this->options['height'] ) && '' !== $this->options['height'] ) {
1068
-				$defaults['height'] = $this->options['height'];
1069
-			}
1070
-
1071
-			if ( isset( $this->options['cropping'] ) && '' !== $this->options['cropping'] ) {
1072
-				$defaults['cropping'] = $this->options['cropping'];
1073
-			}
1074
-		}
1075
-
1076
-		$args = wp_parse_args( $args, $defaults );
1077
-		$cropping = $args['cropping'];
1078
-		$width = $args['width'];
1079
-		$height = $args['height'];
1080
-
1081
-		return 'https://wetu.com/ImageHandler/' . $cropping . $width . 'x' . $height . '/';
1082
-	}
1083
-
1084
-	/**
1085
-	 * Attaches 1 image
1086
-	 */
1087
-	public function attach_image( $v = false, $parent_id, $image_sizes = false, $banner = false ) {
1088
-		if ( false !== $v ) {
1089
-			$temp_fragment = explode( '/', $v['url_fragment'] );
1090
-			$url_filename  = $temp_fragment[ count( $temp_fragment ) - 1 ];
1091
-			$url_filename  = str_replace( array( '.jpg', '.png', '.jpeg' ), '', $url_filename );
1092
-			$url_filename  = trim( $url_filename );
1093
-			$title         = $url_filename;
1094
-			$url_filename  = str_replace( ' ', '_', $url_filename );
1095
-
1096
-			if ( ! isset( $this->options['image_replacing'] ) && in_array( $url_filename, $this->found_attachments ) ) {
1097
-				return array_search( $url_filename, $this->found_attachments );
1098
-			}
1099
-
1100
-			$postdata = array();
1101
-
1102
-			if ( empty( $v['label'] ) ) {
1103
-				$v['label'] = '';
1104
-			}
1105
-
1106
-			if ( ! empty( $v['description'] ) ) {
1107
-				$desc = wp_strip_all_tags( $v['description'] );
1108
-				$posdata = array(
1109
-					'post_excerpt' => $desc,
1110
-				);
1111
-			}
1112
-
1113
-			if ( ! empty( $v['section'] ) ) {
1114
-				$desc = wp_strip_all_tags( $v['section'] );
1115
-				$posdata = array(
1116
-					'post_excerpt' => $desc,
1117
-				);
1118
-			}
1119
-
1120
-			$attach_id = null;
1121
-			// Resizor - add option to setting if required.
1122
-			$fragment  = str_replace( ' ', '%20', $v['url_fragment'] );
1123
-			$url       = $this->get_scaling_url( $image_sizes ) . $fragment;
1124
-			$attach_id = $this->attach_external_image2( $url, $parent_id, '', $v['label'], $postdata );
1125
-			if ( ! empty( $attach_id ) ) {
1126
-				$this->found_attachments[ $attach_id ] = $url_filename;
1127
-				add_post_meta( $attach_id, 'lsx_wetu_id', $v['url_fragment'], true );
1128
-				return $attach_id;
1129
-			}
1130
-		}
1131
-		return false;
1132
-	}
1133
-
1134
-	public function attach_external_image2( $url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array() ) {
1135
-		if ( ! $url || ! $post_id ) {
640
+          }
641
+     }
642
+
643
+
644
+     // GENERAL FUNCTIONS.
645
+
646
+     /**
647
+      * Checks to see if an item is checked.
648
+      *
649
+      * @param $haystack array|string
650
+      * @param $needle string
651
+      * @param $echo bool
652
+      */
653
+     public function checked( $haystack = false, $needle = '', $echo = true ) {
654
+          $return = $this->itemd( $haystack, $needle, 'checked', false );
655
+
656
+          if ( '' !== $return ) {
657
+               if ( true === $echo ) {
658
+                    echo wp_kses_post( $return );
659
+               } else {
660
+                    return $return;
661
+               }
662
+          }
663
+     }
664
+
665
+     /**
666
+      * Checks to see if an item is checked.
667
+      *
668
+      * @param $haystack array|string
669
+      * @param $needle string
670
+      * @param $echo bool
671
+      */
672
+     public function selected( $haystack = false, $needle = '', $echo = true ) {
673
+          $return = $this->itemd( $haystack, $needle, 'selected' );
674
+
675
+          if ( '' !== $return ) {
676
+               if ( true === $echo ) {
677
+                    echo wp_kses_post( $return );
678
+               } else {
679
+                    return $return;
680
+               }
681
+          }
682
+     }
683
+
684
+     /**
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
688
+      * @param $needle string
689
+      * @param $type string
690
+      * @param $wrap bool
691
+      * @return $html string
692
+      */
693
+     public function itemd( $haystack = false, $needle = '', $type = '', $wrap = true ) {
694
+          $html = '';
695
+
696
+          if ( '' !== $type ) {
697
+               if ( ! is_array( $haystack ) ) {
698
+                    $haystack = array( $haystack );
699
+               }
700
+               if ( in_array( $needle, $haystack ) ) {
701
+                    if ( true === $wrap || 'true' === $wrap ) {
702
+                         $html = $type . '="' . $type . '"';
703
+                    } else {
704
+                         $html = $type;
705
+                    }
706
+               }
707
+          }
708
+
709
+          return $html;
710
+     }
711
+
712
+     /**
713
+      * Grabs any attachments for the current item
714
+      */
715
+     public function find_attachments( $id = false ) {
716
+          if ( false !== $id ) {
717
+               if ( empty( $this->found_attachments ) ) {
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() ) {
730
+                         foreach ( $attachments->posts as $attachment ) {
731
+                              $this->found_attachments[ $attachment->ID ] = str_replace( array( '.jpg', '.png', '.jpeg' ), '', $attachment->post_title );
732
+                         }
733
+                    }
734
+               }
735
+          }
736
+     }
737
+
738
+     // CUSTOM FIELD FUNCTIONS.
739
+
740
+     /**
741
+      * Saves the room data
742
+      */
743
+     public function save_custom_field( $value = false, $meta_key, $id, $decrease = false, $unique = true ) {
744
+          if ( false !== $value ) {
745
+               if ( false !== $decrease ) {
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 ) {
753
+                    update_post_meta( $id, $meta_key, $value, $prev );
754
+               } else {
755
+                    add_post_meta( $id, $meta_key, $value, $unique );
756
+               }
757
+          }
758
+     }
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 ) ) {
765
+
766
+               foreach ( $this->cleanup_posts as $id => $key ) {
767
+                    $prev_items = get_post_meta( $id, $key, false );
768
+                    $new_items = array_unique( $prev_items );
769
+                    delete_post_meta( $id, $key );
770
+
771
+                    foreach ( $new_items as $new_item ) {
772
+                         add_post_meta( $id, $key, $new_item, false );
773
+                    }
774
+               }
775
+          }
776
+     }
777
+
778
+     // TAXONOMY FUNCTIONS.
779
+
780
+     /**
781
+      * Set_taxonomy with some terms
782
+      */
783
+     public function set_taxonomy( $taxonomy, $terms, $id ) {
784
+          $result = array();
785
+
786
+          if ( ! empty( $data ) ) {
787
+               foreach ( $data as $k ) {
788
+                    if ( $id ) {
789
+                         $term = term_exists( trim( $k ), $tax );
790
+                         if ( ! $term ) {
791
+                              $term = wp_insert_term( trim( $k ), $tax );
792
+
793
+                              if ( is_wp_error( $term ) ) {
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
+          }
806
+          return $result;
807
+     }
808
+
809
+     /**
810
+      * Sets the terms of the current post
811
+      *
812
+      * @param boolean $id
813
+      * @param boolean $name
814
+      * @param boolean $taxonomy
815
+      * @param boolean $parent
816
+      * @return void
817
+      */
818
+     public function set_term( $id = false, $name = false, $taxonomy = false, $parent = false ) {
819
+          $term = term_exists( $name, $taxonomy );
820
+          if ( ! $term ) {
821
+               if ( false !== $parent ) {
822
+                    $parent = array(
823
+                         'parent' => $parent,
824
+                    );
825
+               }
826
+               $term = wp_insert_term( trim( $name ), $taxonomy, $parent );
827
+
828
+               if ( is_wp_error( $term ) ) {
829
+                    echo wp_kses_post( $term->get_error_message() );
830
+               } else {
831
+                    wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true );
832
+               }
833
+          } else {
834
+               wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy, true );
835
+          }
836
+
837
+          return $term['term_id'];
838
+     }
839
+
840
+     /**
841
+      * set_taxonomy with some terms
842
+      */
843
+     public function taxonomy_checkboxes( $taxonomy = false, $selected = array() ) {
844
+          $return = '';
845
+
846
+          if ( false !== $taxonomy ) {
847
+               $return .= '<ul>';
848
+               $terms = get_terms( array(
849
+                    'taxonomy' => $taxonomy,
850
+                    'hide_empty' => false,
851
+               ) );
852
+
853
+               if ( ! is_wp_error( $terms ) ) {
854
+                    foreach ( $terms as $term ) {
855
+                         $return .= '<li><input class="' . $taxonomy . '" ' . $this->checked( $selected, $term->term_id, false ) . ' type="checkbox" value="' . $term->term_id . '" /> ' . $term->name . '</li>';
856
+                    }
857
+               } else {
858
+                    $return .= '<li><input type="checkbox" value="" /> ' . __( 'None', 'lsx-wetu-importer' ) . '</li>';
859
+               }
860
+
861
+               $return .= '</ul>';
862
+          }
863
+
864
+          return $return;
865
+     }
866
+
867
+     // MAP FUNCTIONS
868
+
869
+     /**
870
+      * Saves the longitude and lattitude, as well as sets the map marker.
871
+      */
872
+     public function set_map_data( $data, $id, $zoom = '10' ) {
873
+          $longitude = false;
874
+          $latitude = false;
875
+          $address = false;
876
+
877
+          if ( isset( $data[0]['position'] ) ) {
878
+               if ( isset( $data[0]['position']['driving_latitude'] ) ) {
879
+                    $latitude = $data[0]['position']['driving_latitude'];
880
+               } elseif ( isset( $data[0]['position']['latitude'] ) ) {
881
+                    $latitude = $data[0]['position']['latitude'];
882
+               }
883
+
884
+               if ( isset( $data[0]['position']['driving_longitude'] ) ) {
885
+                    $longitude = $data[0]['position']['driving_longitude'];
886
+               } elseif ( isset( $data[0]['position']['longitude'] ) ) {
887
+                    $longitude = $data[0]['position']['longitude'];
888
+               }
889
+          }
890
+
891
+          if ( isset( $data[0]['content'] ) && isset( $data[0]['content']['contact_information'] ) ) {
892
+               if ( isset( $data[0]['content']['contact_information']['address'] ) ) {
893
+                    $address = strip_tags( $data[0]['content']['contact_information']['address'] );
894
+                    $address = explode( "\n", $address );
895
+
896
+                    foreach ( $address as $bitkey => $bit ) {
897
+                         $bit = ltrim( rtrim( $bit ) );
898
+
899
+                         if ( false === $bit || '' === $bit || null === $bit || empty( $bit ) ) {
900
+                              unset( $address[ $bitkey ] );
901
+                         }
902
+                    }
903
+
904
+                    $address = implode( ', ', $address );
905
+                    $address = str_replace( ', , ', ', ', $address );
906
+               }
907
+          }
908
+
909
+          if ( false !== $longitude ) {
910
+               $location_data = array(
911
+                    'address'   => (string) $address,
912
+                    'lat'       => (string) $latitude,
913
+                    'long'      => (string) $longitude,
914
+                    'zoom'      => (string) $zoom,
915
+                    'elevation' => '',
916
+               );
917
+
918
+               if ( false !== $id && '0' !== $id ) {
919
+                    $prev = get_post_meta( $id, 'location', true );
920
+                    update_post_meta( $id, 'location', $location_data, $prev );
921
+               } else {
922
+                    add_post_meta( $id, 'location', $location_data, true );
923
+               }
924
+          }
925
+     }
926
+
927
+     // IMAGE FUNCTIONS
928
+
929
+     /**
930
+      * Creates the main gallery data
931
+      */
932
+     public function set_featured_image( $data, $id ) {
933
+          if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) {
934
+               $this->featured_image = $this->attach_image( $data[0]['content']['images'][0], $id,  array(
935
+                    'width' => '800',
936
+                    'height' => '600',
937
+                    'cropping' => 'h',
938
+               ) );
939
+
940
+               if ( false !== $this->featured_image ) {
941
+                    delete_post_meta( $id, '_thumbnail_id' );
942
+                    add_post_meta( $id, '_thumbnail_id', $this->featured_image, true );
943
+               }
944
+          }
945
+     }
946
+
947
+     /**
948
+      * Sets a banner image
949
+      */
950
+     public function set_banner_image( $data, $id, $content = array( 'none' ) ) {
951
+          if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) {
952
+               if ( in_array( 'unique_banner_image', $content ) && isset( $data[0]['destination_image'] ) && is_array( $data[0]['destination_image'] ) ) {
953
+                    $temp_banner = $this->attach_image( $data[0]['destination_image'], $id, array(
954
+                         'width' => '1920',
955
+                         'height' => '600',
956
+                         'cropping' => 'c',
957
+                    ));
958
+               } else {
959
+                    $temp_banner = $this->attach_image( $data[0]['content']['images'][1], $id, array(
960
+                         'width' => '1920',
961
+                         'height' => '600',
962
+                         'cropping' => 'c',
963
+                    ));
964
+               }
965
+
966
+               if ( false !== $temp_banner ) {
967
+                    $this->banner_image = $temp_banner;
968
+
969
+                    delete_post_meta( $id, 'image_group' );
970
+
971
+                    $new_banner = array(
972
+                         'banner_image' => array(
973
+                              'cmb-field-0' => $this->banner_image,
974
+                         ),
975
+                    );
976
+
977
+                    add_post_meta( $id, 'image_group', $new_banner, true );
978
+               }
979
+          }
980
+     }
981
+
982
+     /**
983
+      * Checks if the current image is being used as a thumbnail somewhere else.
984
+      */
985
+     public function is_image_being_used( $image_id = '', $post_id = '' ) {
986
+          global $wpdb;
987
+          $being_used = false;
988
+          if ( '' !== $image_id ) {
989
+               $sql = "SELECT * FROM `{$wpdb->postmeta}` WHERE `post_id` != {$post_id} AND `meta_key` LIKE '_thumbnail_id' AND `meta_value` LIKE '{$image_id}'";
990
+               $results = $wpdb->query( $sql );
991
+               if ( false !== $results && ! empty( $results ) ) {
992
+                    $being_used = true;
993
+               }
994
+          }
995
+          return $being_used;
996
+     }
997
+
998
+     /**
999
+      * Creates the main gallery data
1000
+      */
1001
+     public function create_main_gallery( $data, $id ) {
1002
+          if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) {
1003
+               if ( isset( $this->options['image_replacing'] ) && 'on' === $this->options['image_replacing'] ) {
1004
+                    $current_gallery = get_post_meta( $id, 'gallery', false );
1005
+
1006
+                    if ( false !== $current_gallery && ! empty( $current_gallery ) ) {
1007
+                         foreach ( $current_gallery as $g ) {
1008
+                              delete_post_meta( $id, 'gallery', $g );
1009
+
1010
+                              if ( 'attachment' === get_post_type( $g ) && false === $this->is_image_being_used( $g, $id ) ) {
1011
+                                   wp_delete_attachment( $g, true );
1012
+                              }
1013
+                         }
1014
+                    }
1015
+               }
1016
+
1017
+               $counter = 0;
1018
+
1019
+               foreach ( $data[0]['content']['images'] as $image_data ) {
1020
+                    if ( ( 0 === $counter && false !== $this->featured_image ) || ( 1 === $counter && false !== $this->banner_image ) ) {
1021
+                         $counter++;
1022
+
1023
+                         if ( false !== $this->image_limit && false !== $this->image_limit ) {
1024
+                              $this->image_limit++;
1025
+                         }
1026
+
1027
+                         continue;
1028
+                    }
1029
+
1030
+                    if ( false !== $this->image_limit && $counter >= $this->image_limit ) {
1031
+                         continue;
1032
+                    }
1033
+
1034
+                    $this->gallery_meta[] = $this->attach_image( $image_data, $id );
1035
+                    $counter++;
1036
+               }
1037
+
1038
+               if ( ! empty( $this->gallery_meta ) ) {
1039
+                    delete_post_meta( $id, 'gallery' );
1040
+                    $this->gallery_meta = array_unique( $this->gallery_meta );
1041
+
1042
+                    foreach ( $this->gallery_meta as $gallery_id ) {
1043
+                         if ( false !== $gallery_id && '' !== $gallery_id && ! is_array( $gallery_id ) ) {
1044
+                              add_post_meta( $id, 'gallery', $gallery_id, false );
1045
+                         }
1046
+                    }
1047
+               }
1048
+          }
1049
+     }
1050
+
1051
+     /**
1052
+      * search_form
1053
+      */
1054
+     public function get_scaling_url( $args = array() ) {
1055
+          $defaults = array(
1056
+               'width' => '1024',
1057
+               'height' => '768',
1058
+               //'cropping' => 'w',
1059
+               'cropping' => 'h',
1060
+          );
1061
+
1062
+          if ( false !== $this->options ) {
1063
+               if ( isset( $this->options['width'] ) && '' !== $this->options['width'] ) {
1064
+                    $defaults['width'] = $this->options['width'];
1065
+               }
1066
+
1067
+               if ( isset( $this->options['height'] ) && '' !== $this->options['height'] ) {
1068
+                    $defaults['height'] = $this->options['height'];
1069
+               }
1070
+
1071
+               if ( isset( $this->options['cropping'] ) && '' !== $this->options['cropping'] ) {
1072
+                    $defaults['cropping'] = $this->options['cropping'];
1073
+               }
1074
+          }
1075
+
1076
+          $args = wp_parse_args( $args, $defaults );
1077
+          $cropping = $args['cropping'];
1078
+          $width = $args['width'];
1079
+          $height = $args['height'];
1080
+
1081
+          return 'https://wetu.com/ImageHandler/' . $cropping . $width . 'x' . $height . '/';
1082
+     }
1083
+
1084
+     /**
1085
+      * Attaches 1 image
1086
+      */
1087
+     public function attach_image( $v = false, $parent_id, $image_sizes = false, $banner = false ) {
1088
+          if ( false !== $v ) {
1089
+               $temp_fragment = explode( '/', $v['url_fragment'] );
1090
+               $url_filename  = $temp_fragment[ count( $temp_fragment ) - 1 ];
1091
+               $url_filename  = str_replace( array( '.jpg', '.png', '.jpeg' ), '', $url_filename );
1092
+               $url_filename  = trim( $url_filename );
1093
+               $title         = $url_filename;
1094
+               $url_filename  = str_replace( ' ', '_', $url_filename );
1095
+
1096
+               if ( ! isset( $this->options['image_replacing'] ) && in_array( $url_filename, $this->found_attachments ) ) {
1097
+                    return array_search( $url_filename, $this->found_attachments );
1098
+               }
1099
+
1100
+               $postdata = array();
1101
+
1102
+               if ( empty( $v['label'] ) ) {
1103
+                    $v['label'] = '';
1104
+               }
1105
+
1106
+               if ( ! empty( $v['description'] ) ) {
1107
+                    $desc = wp_strip_all_tags( $v['description'] );
1108
+                    $posdata = array(
1109
+                         'post_excerpt' => $desc,
1110
+                    );
1111
+               }
1112
+
1113
+               if ( ! empty( $v['section'] ) ) {
1114
+                    $desc = wp_strip_all_tags( $v['section'] );
1115
+                    $posdata = array(
1116
+                         'post_excerpt' => $desc,
1117
+                    );
1118
+               }
1119
+
1120
+               $attach_id = null;
1121
+               // Resizor - add option to setting if required.
1122
+               $fragment  = str_replace( ' ', '%20', $v['url_fragment'] );
1123
+               $url       = $this->get_scaling_url( $image_sizes ) . $fragment;
1124
+               $attach_id = $this->attach_external_image2( $url, $parent_id, '', $v['label'], $postdata );
1125
+               if ( ! empty( $attach_id ) ) {
1126
+                    $this->found_attachments[ $attach_id ] = $url_filename;
1127
+                    add_post_meta( $attach_id, 'lsx_wetu_id', $v['url_fragment'], true );
1128
+                    return $attach_id;
1129
+               }
1130
+          }
1131
+          return false;
1132
+     }
1133
+
1134
+     public function attach_external_image2( $url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array() ) {
1135
+          if ( ! $url || ! $post_id ) {
1136 1136
 return new WP_Error( 'missing', 'Need a valid URL and post ID...' ); }
1137
-		$att_id = false;
1138
-
1139
-		require_once( ABSPATH . 'wp-admin/includes/file.php' );
1140
-		require_once( ABSPATH . 'wp-admin/includes/media.php' );
1141
-		require_once( ABSPATH . 'wp-admin/includes/image.php' );
1142
-		// Download file to temp location, returns full server path to temp file.
1143
-
1144
-		$tmp   = tempnam( '/tmp', 'FOO' );
1145
-		$image = wp_remote_get( $url );
1146
-		if ( ! is_wp_error( $image ) && ! empty( $image ) && isset( $image['response'] ) && isset( $image['response']['code'] ) && 200 === $image['response']['code'] ) {
1147
-			file_put_contents( $tmp, $image['body'] );
1148
-			chmod( $tmp, '777' );
1149
-
1150
-			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
1151
-			$url_filename = basename( $matches[0] );
1152
-			$url_filename = str_replace( '%20', '_', $url_filename );
1153
-			// extract filename from url for title
1154
-			$url_type = wp_check_filetype( $url_filename );                                           // determine file type (ext and mime/type)
1155
-
1156
-			// override filename if given, reconstruct server path.
1157
-			if ( ! empty( $filename ) && ' ' != $filename ) {
1158
-				$filename = sanitize_file_name( $filename );
1159
-				$tmppath = pathinfo( $tmp );
1160
-
1161
-				$extension = '';
1162
-				if ( isset( $tmppath['extension'] ) ) {
1163
-					$extension = $tmppath['extension'];
1164
-				}
1165
-
1166
-				$new = $tmppath['dirname'] . '/' . $filename . '.' . $extension;
1167
-				rename( $tmp, $new );                                                                 // renames temp file on server
1168
-				$tmp = $new;                                                                        // push new filename (in path) to be used in file array later
1169
-			}
1170
-
1171
-			// assemble file data (should be built like $_FILES since wp_handle_sideload() will be using).
1172
-			$file_array['tmp_name'] = $tmp;                                                         // full server path to temp file
1173
-
1174
-			if ( ! empty( $filename ) && ' ' != $filename ) {
1175
-				$file_array['name'] = $filename . '.' . $url_type['ext'];                           // user given filename for title, add original URL extension
1176
-			} else {
1177
-				$file_array['name'] = $url_filename;                                                // just use original URL filename
1178
-			}
1179
-
1180
-			// set additional wp_posts columns.
1181
-			if ( empty( $post_data['post_title'] ) ) {
1182
-
1183
-				$url_filename = str_replace( '%20', ' ', $url_filename );
1184
-
1185
-				$post_data['post_title'] = basename( $url_filename, '.' . $url_type['ext'] );         // just use the original filename (no extension)
1186
-			}
1187
-
1188
-			// make sure gets tied to parent.
1189
-			if ( empty( $post_data['post_parent'] ) ) {
1190
-				$post_data['post_parent'] = $post_id;
1191
-			}
1192
-
1193
-			// do the validation and storage stuff.
1194
-			$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
1195
-
1196
-			// If error storing permanently, unlink.
1197
-			if ( is_wp_error( $att_id ) ) {
1198
-				unlink( $file_array['tmp_name'] );
1199
-				return false;
1200
-			}
1201
-		}
1202
-		return $att_id;
1203
-	}
1204
-
1205
-	// AJAX FUNCTIONS
1206
-	/**
1207
-	 * Run through the accommodation grabbed from the DB.
1208
-	 */
1209
-	public function process_ajax_search() {
1210
-		$this->current_importer->process_ajax_search();
1211
-		die();
1212
-	}
1213
-
1214
-	/**
1215
-	 * Connect to wetu
1216
-	 */
1217
-	public function process_ajax_import() {
1218
-		$this->current_importer->process_ajax_import();
1219
-		die();
1220
-	}
1221
-
1222
-	/**
1223
-	 * Formats the row for the completed list.
1224
-	 */
1225
-	public function format_completed_row( $response ) {
1226
-		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>' );
1227
-	}
1228
-
1229
-	/**
1230
-	 * Formats the error.
1231
-	 */
1232
-	public function format_error( $response ) {
1233
-		echo wp_kses_post( '<li class="post-error"><span class="dashicons dashicons-no"></span>' . $response . '</li>' );
1234
-	}
1235
-
1236
-	/**
1237
-	 * Does a multine search
1238
-	 */
1239
-	public function multineedle_stripos( $haystack, $needles, $offset = 0 ) {
1240
-		$found = false;
1241
-		$needle_count = count( $needles );
1242
-
1243
-		foreach ( $needles as $needle ) {
1244
-			if ( false !== stripos( $haystack, $needle, $offset ) ) {
1245
-				$found[] = true;
1246
-			}
1247
-		}
1248
-
1249
-		if ( false !== $found && count( $found ) === $needle_count ) {
1250
-			return true;
1251
-		} else {
1252
-			return false;
1253
-		}
1254
-	}
1255
-
1256
-	/**
1257
-	 * Grab all the current accommodation posts via the lsx_wetu_id field.
1258
-	 */
1259
-	public function find_current_accommodation( $post_type = 'accommodation' ) {
1260
-		global $wpdb;
1261
-		$return = array();
1262
-
1263
-		// @codingStandardsIgnoreStart
1264
-		$current_accommodation = $wpdb->get_results("
1137
+          $att_id = false;
1138
+
1139
+          require_once( ABSPATH . 'wp-admin/includes/file.php' );
1140
+          require_once( ABSPATH . 'wp-admin/includes/media.php' );
1141
+          require_once( ABSPATH . 'wp-admin/includes/image.php' );
1142
+          // Download file to temp location, returns full server path to temp file.
1143
+
1144
+          $tmp   = tempnam( '/tmp', 'FOO' );
1145
+          $image = wp_remote_get( $url );
1146
+          if ( ! is_wp_error( $image ) && ! empty( $image ) && isset( $image['response'] ) && isset( $image['response']['code'] ) && 200 === $image['response']['code'] ) {
1147
+               file_put_contents( $tmp, $image['body'] );
1148
+               chmod( $tmp, '777' );
1149
+
1150
+               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
1151
+               $url_filename = basename( $matches[0] );
1152
+               $url_filename = str_replace( '%20', '_', $url_filename );
1153
+               // extract filename from url for title
1154
+               $url_type = wp_check_filetype( $url_filename );                                           // determine file type (ext and mime/type)
1155
+
1156
+               // override filename if given, reconstruct server path.
1157
+               if ( ! empty( $filename ) && ' ' != $filename ) {
1158
+                    $filename = sanitize_file_name( $filename );
1159
+                    $tmppath = pathinfo( $tmp );
1160
+
1161
+                    $extension = '';
1162
+                    if ( isset( $tmppath['extension'] ) ) {
1163
+                         $extension = $tmppath['extension'];
1164
+                    }
1165
+
1166
+                    $new = $tmppath['dirname'] . '/' . $filename . '.' . $extension;
1167
+                    rename( $tmp, $new );                                                                 // renames temp file on server
1168
+                    $tmp = $new;                                                                        // push new filename (in path) to be used in file array later
1169
+               }
1170
+
1171
+               // assemble file data (should be built like $_FILES since wp_handle_sideload() will be using).
1172
+               $file_array['tmp_name'] = $tmp;                                                         // full server path to temp file
1173
+
1174
+               if ( ! empty( $filename ) && ' ' != $filename ) {
1175
+                    $file_array['name'] = $filename . '.' . $url_type['ext'];                           // user given filename for title, add original URL extension
1176
+               } else {
1177
+                    $file_array['name'] = $url_filename;                                                // just use original URL filename
1178
+               }
1179
+
1180
+               // set additional wp_posts columns.
1181
+               if ( empty( $post_data['post_title'] ) ) {
1182
+
1183
+                    $url_filename = str_replace( '%20', ' ', $url_filename );
1184
+
1185
+                    $post_data['post_title'] = basename( $url_filename, '.' . $url_type['ext'] );         // just use the original filename (no extension)
1186
+               }
1187
+
1188
+               // make sure gets tied to parent.
1189
+               if ( empty( $post_data['post_parent'] ) ) {
1190
+                    $post_data['post_parent'] = $post_id;
1191
+               }
1192
+
1193
+               // do the validation and storage stuff.
1194
+               $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
1195
+
1196
+               // If error storing permanently, unlink.
1197
+               if ( is_wp_error( $att_id ) ) {
1198
+                    unlink( $file_array['tmp_name'] );
1199
+                    return false;
1200
+               }
1201
+          }
1202
+          return $att_id;
1203
+     }
1204
+
1205
+     // AJAX FUNCTIONS
1206
+     /**
1207
+      * Run through the accommodation grabbed from the DB.
1208
+      */
1209
+     public function process_ajax_search() {
1210
+          $this->current_importer->process_ajax_search();
1211
+          die();
1212
+     }
1213
+
1214
+     /**
1215
+      * Connect to wetu
1216
+      */
1217
+     public function process_ajax_import() {
1218
+          $this->current_importer->process_ajax_import();
1219
+          die();
1220
+     }
1221
+
1222
+     /**
1223
+      * Formats the row for the completed list.
1224
+      */
1225
+     public function format_completed_row( $response ) {
1226
+          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>' );
1227
+     }
1228
+
1229
+     /**
1230
+      * Formats the error.
1231
+      */
1232
+     public function format_error( $response ) {
1233
+          echo wp_kses_post( '<li class="post-error"><span class="dashicons dashicons-no"></span>' . $response . '</li>' );
1234
+     }
1235
+
1236
+     /**
1237
+      * Does a multine search
1238
+      */
1239
+     public function multineedle_stripos( $haystack, $needles, $offset = 0 ) {
1240
+          $found = false;
1241
+          $needle_count = count( $needles );
1242
+
1243
+          foreach ( $needles as $needle ) {
1244
+               if ( false !== stripos( $haystack, $needle, $offset ) ) {
1245
+                    $found[] = true;
1246
+               }
1247
+          }
1248
+
1249
+          if ( false !== $found && count( $found ) === $needle_count ) {
1250
+               return true;
1251
+          } else {
1252
+               return false;
1253
+          }
1254
+     }
1255
+
1256
+     /**
1257
+      * Grab all the current accommodation posts via the lsx_wetu_id field.
1258
+      */
1259
+     public function find_current_accommodation( $post_type = 'accommodation' ) {
1260
+          global $wpdb;
1261
+          $return = array();
1262
+
1263
+          // @codingStandardsIgnoreStart
1264
+          $current_accommodation = $wpdb->get_results("
1265 1265
 			SELECT key1.post_id,key1.meta_value
1266 1266
 			FROM {$wpdb->postmeta} key1
1267 1267
 
@@ -1273,128 +1273,128 @@  discard block
 block discarded – undo
1273 1273
 
1274 1274
 			LIMIT 0,5000
1275 1275
 		");
1276
-		// @codingStandardsIgnoreEnd
1277
-
1278
-		if ( null !== $current_accommodation && ! empty( $current_accommodation ) ) {
1279
-			foreach ( $current_accommodation as $accom ) {
1280
-				$return[ $accom->meta_value ] = $accom;
1281
-			}
1282
-		}
1283
-
1284
-		return $return;
1285
-	}
1286
-
1287
-	/**
1288
-	 * Set the Video date
1289
-	 */
1290
-	public function set_video_data( $data, $id ) {
1291
-		if ( ! empty( $data[0]['content']['youtube_videos'] ) && is_array( $data[0]['content']['youtube_videos'] ) ) {
1292
-			$videos = false;
1293
-
1294
-			foreach ( $data[0]['content']['youtube_videos'] as $video ) {
1295
-				$temp_video = array();
1296
-
1297
-				if ( isset( $video['label'] ) ) {
1298
-					$temp_video['title'] = $video['label'];
1299
-				}
1300
-				if ( isset( $video['description'] ) ) {
1301
-					$temp_video['description'] = strip_tags( $video['description'] );
1302
-				}
1303
-				if ( isset( $video['url'] ) ) {
1304
-					$temp_video['url'] = $video['url'];
1305
-				}
1306
-
1307
-				$temp_video['thumbnail'] = '';
1308
-				$videos[] = $temp_video;
1309
-			}
1310
-
1311
-			if ( false !== $id && '0' !== $id ) {
1312
-				delete_post_meta( $id, 'videos' );
1313
-			}
1314
-
1315
-			foreach ( $videos as $video ) {
1316
-				add_post_meta( $id, 'videos', $video, false );
1317
-			}
1318
-		}
1319
-	}
1320
-
1321
-	public function shuffle_assoc( &$array ) {
1322
-		$new = array();
1323
-		$keys = array_keys( $array );
1324
-
1325
-		shuffle( $keys );
1326
-
1327
-		foreach ( $keys as $key ) {
1328
-			$new[ $key ] = $array[ $key ];
1329
-		}
1330
-
1331
-		$array = $new;
1332
-
1333
-		return true;
1334
-	}
1335
-
1336
-	/**
1337
-	 * Save the list of Tours into an option
1338
-	 */
1339
-	public function update_options() {
1340
-		$own = '';
1341
-		$options = array();
1342
-		delete_option( 'lsx_ti_tours_api_options' );
1343
-
1344
-		if ( isset( $_GET['own'] ) ) {
1345
-			$this->current_importer->url_qs .= '&own=true';
1346
-			$options[] = 'own';
1347
-		}
1348
-
1349
-		if ( isset( $_GET['type'] ) && 'allitineraries' !== $_GET['type'] ) {
1350
-			$this->current_importer->url_qs .= '&type=' . $_GET['type'];
1351
-			$options[] = $_GET['type'];
1352
-		} else {
1353
-			$options[] = 'sample';
1354
-			$this->current_importer->url_qs .= '&type=sample';
1355
-		}
1356
-
1357
-		$url = str_replace( 'Pins', 'Itinerary', $this->current_importer->url . '/V8/List?' . $this->current_importer->url_qs );
1358
-		$url .= '&results=2000';
1359
-		add_option( 'lsx_ti_tours_api_options', $options );
1360
-		$data = wp_remote_get( $url );
1361
-		$tours = json_decode( wp_remote_retrieve_body( $data ), true );
1362
-
1363
-		if ( isset( $tours['error'] ) ) {
1364
-			return $tours['error'];
1365
-		} elseif ( isset( $tours['itineraries'] ) && ! empty( $tours['itineraries'] ) ) {
1366
-			set_transient( 'lsx_ti_tours', $tours['itineraries'], 60 * 60 * 4 );
1367
-			return true;
1368
-		}
1369
-	}
1370
-
1371
-	/**
1372
-	 * Gets the post_id from the key
1373
-	 *
1374
-	 * @param boolean $wetu_id
1375
-	 * @return string
1376
-	 */
1377
-	public function get_post_id_by_key_value( $wetu_id = false ) {
1378
-		global $wpdb;
1379
-		$id = false;
1380
-		if ( false !== $wetu_id && '' !== $wetu_id ) {
1381
-			$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 ) ) );
1382
-			if ( false !== $result && ! empty( $result ) ) {
1383
-				$id = $result;
1384
-			}
1385
-		}
1386
-		return $id;
1387
-	}
1388
-	/**
1389
-	 * Set the team memberon each item.
1390
-	 */
1391
-	public function set_team_member( $id, $team_members ) {
1392
-		delete_post_meta( $id, 'team_to_' . $this->tab_slug );
1393
-
1394
-		foreach ( $team_members as $team ) {
1395
-			add_post_meta( $id, 'team_to_' . $this->tab_slug, $team );
1396
-		}
1397
-	}
1276
+          // @codingStandardsIgnoreEnd
1277
+
1278
+          if ( null !== $current_accommodation && ! empty( $current_accommodation ) ) {
1279
+               foreach ( $current_accommodation as $accom ) {
1280
+                    $return[ $accom->meta_value ] = $accom;
1281
+               }
1282
+          }
1283
+
1284
+          return $return;
1285
+     }
1286
+
1287
+     /**
1288
+      * Set the Video date
1289
+      */
1290
+     public function set_video_data( $data, $id ) {
1291
+          if ( ! empty( $data[0]['content']['youtube_videos'] ) && is_array( $data[0]['content']['youtube_videos'] ) ) {
1292
+               $videos = false;
1293
+
1294
+               foreach ( $data[0]['content']['youtube_videos'] as $video ) {
1295
+                    $temp_video = array();
1296
+
1297
+                    if ( isset( $video['label'] ) ) {
1298
+                         $temp_video['title'] = $video['label'];
1299
+                    }
1300
+                    if ( isset( $video['description'] ) ) {
1301
+                         $temp_video['description'] = strip_tags( $video['description'] );
1302
+                    }
1303
+                    if ( isset( $video['url'] ) ) {
1304
+                         $temp_video['url'] = $video['url'];
1305
+                    }
1306
+
1307
+                    $temp_video['thumbnail'] = '';
1308
+                    $videos[] = $temp_video;
1309
+               }
1310
+
1311
+               if ( false !== $id && '0' !== $id ) {
1312
+                    delete_post_meta( $id, 'videos' );
1313
+               }
1314
+
1315
+               foreach ( $videos as $video ) {
1316
+                    add_post_meta( $id, 'videos', $video, false );
1317
+               }
1318
+          }
1319
+     }
1320
+
1321
+     public function shuffle_assoc( &$array ) {
1322
+          $new = array();
1323
+          $keys = array_keys( $array );
1324
+
1325
+          shuffle( $keys );
1326
+
1327
+          foreach ( $keys as $key ) {
1328
+               $new[ $key ] = $array[ $key ];
1329
+          }
1330
+
1331
+          $array = $new;
1332
+
1333
+          return true;
1334
+     }
1335
+
1336
+     /**
1337
+      * Save the list of Tours into an option
1338
+      */
1339
+     public function update_options() {
1340
+          $own = '';
1341
+          $options = array();
1342
+          delete_option( 'lsx_ti_tours_api_options' );
1343
+
1344
+          if ( isset( $_GET['own'] ) ) {
1345
+               $this->current_importer->url_qs .= '&own=true';
1346
+               $options[] = 'own';
1347
+          }
1348
+
1349
+          if ( isset( $_GET['type'] ) && 'allitineraries' !== $_GET['type'] ) {
1350
+               $this->current_importer->url_qs .= '&type=' . $_GET['type'];
1351
+               $options[] = $_GET['type'];
1352
+          } else {
1353
+               $options[] = 'sample';
1354
+               $this->current_importer->url_qs .= '&type=sample';
1355
+          }
1356
+
1357
+          $url = str_replace( 'Pins', 'Itinerary', $this->current_importer->url . '/V8/List?' . $this->current_importer->url_qs );
1358
+          $url .= '&results=2000';
1359
+          add_option( 'lsx_ti_tours_api_options', $options );
1360
+          $data = wp_remote_get( $url );
1361
+          $tours = json_decode( wp_remote_retrieve_body( $data ), true );
1362
+
1363
+          if ( isset( $tours['error'] ) ) {
1364
+               return $tours['error'];
1365
+          } elseif ( isset( $tours['itineraries'] ) && ! empty( $tours['itineraries'] ) ) {
1366
+               set_transient( 'lsx_ti_tours', $tours['itineraries'], 60 * 60 * 4 );
1367
+               return true;
1368
+          }
1369
+     }
1370
+
1371
+     /**
1372
+      * Gets the post_id from the key
1373
+      *
1374
+      * @param boolean $wetu_id
1375
+      * @return string
1376
+      */
1377
+     public function get_post_id_by_key_value( $wetu_id = false ) {
1378
+          global $wpdb;
1379
+          $id = false;
1380
+          if ( false !== $wetu_id && '' !== $wetu_id ) {
1381
+               $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 ) ) );
1382
+               if ( false !== $result && ! empty( $result ) ) {
1383
+                    $id = $result;
1384
+               }
1385
+          }
1386
+          return $id;
1387
+     }
1388
+     /**
1389
+      * Set the team memberon each item.
1390
+      */
1391
+     public function set_team_member( $id, $team_members ) {
1392
+          delete_post_meta( $id, 'team_to_' . $this->tab_slug );
1393
+
1394
+          foreach ( $team_members as $team ) {
1395
+               add_post_meta( $id, 'team_to_' . $this->tab_slug, $team );
1396
+          }
1397
+     }
1398 1398
 }
1399 1399
 
1400 1400
 $lsx_wetu_importer = new LSX_WETU_Importer();
Please login to merge, or discard this patch.