Completed
Push — master ( 484f95...246774 )
by Warwick
02:46
created
classes/class-importer.php 3 patches
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 			$this->api_username = false;
217 217
 			$this->api_password = false;
218 218
 
219
-            if(!defined('WETU_API_KEY')) {
219
+			if(!defined('WETU_API_KEY')) {
220 220
 
221 221
 				if (isset($temp_options['api']['wetu_api_key']) && '' !== $temp_options['api']['wetu_api_key']) {
222 222
 					$this->api_key = $temp_options['api']['wetu_api_key'];
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 				}
230 230
 			}else{
231 231
 				$this->api_key = WETU_API_KEY;
232
-            }
232
+			}
233 233
 
234 234
 			//Set the tab slug
235 235
 			if(isset($_GET['tab']) || isset($_POST['type'])) {
@@ -245,22 +245,22 @@  discard block
 block discarded – undo
245 245
 			}
246 246
 
247 247
 			//Set the scaling options
248
-            if (isset($temp_options[$this->plugin_slug]) && !empty($temp_options[$this->plugin_slug]) && isset($this->options['image_scaling'])) {
249
-                $this->scale_images = true;
250
-                $width = '1024';
251
-                if (isset($this->options['width']) && '' !== $this->options['width']) {
252
-                    $width = $this->options['width'];
253
-                }
254
-                $height = '768';
255
-                if (isset($this->options['height']) && '' !== $this->options['height']) {
256
-                    $height = $this->options['height'];
257
-                }
258
-                $cropping = 'w';
259
-                if (isset($this->options['cropping']) && '' !== $this->options['cropping']) {
260
-                    $cropping = $this->options['cropping'];
261
-                }
262
-                $this->image_scaling_url = 'https://wetu.com/ImageHandler/' . $cropping . $width . 'x' . $height . '/';
263
-            }
248
+			if (isset($temp_options[$this->plugin_slug]) && !empty($temp_options[$this->plugin_slug]) && isset($this->options['image_scaling'])) {
249
+				$this->scale_images = true;
250
+				$width = '1024';
251
+				if (isset($this->options['width']) && '' !== $this->options['width']) {
252
+					$width = $this->options['width'];
253
+				}
254
+				$height = '768';
255
+				if (isset($this->options['height']) && '' !== $this->options['height']) {
256
+					$height = $this->options['height'];
257
+				}
258
+				$cropping = 'w';
259
+				if (isset($this->options['cropping']) && '' !== $this->options['cropping']) {
260
+					$cropping = $this->options['cropping'];
261
+				}
262
+				$this->image_scaling_url = 'https://wetu.com/ImageHandler/' . $cropping . $width . 'x' . $height . '/';
263
+			}
264 264
 
265 265
 		}
266 266
 	}
@@ -334,10 +334,10 @@  discard block
 block discarded – undo
334 334
 
335 335
 	// DISPLAY FUNCTIONS
336 336
 
337
-    /*
337
+	/*
338 338
      * Load the importer class you want to use
339 339
      */
340
-    public function load_class(){
340
+	public function load_class(){
341 341
 
342 342
 		switch($this->tab_slug){
343 343
 			case 'accommodation':
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
 				break;
358 358
 		}
359 359
 
360
-    }
360
+	}
361 361
 
362 362
 	/**
363 363
 	 * Registers the admin page which will house the importer form.
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
 				<?php*/
414 414
 			}else{
415 415
 			   $this->current_importer->display_page();
416
-            }; ?>
416
+			}; ?>
417 417
         </div>
418 418
 		<?php
419 419
 	}
@@ -813,12 +813,12 @@  discard block
 block discarded – undo
813 813
 	 */
814 814
 	public function set_featured_image($data,$id) {
815 815
 		if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){
816
-		    if('tour' === $this->tab_slug){
817
-		        $key = array_rand($data[0]['content']['images']);
818
-                $this->featured_image = $this->attach_image($data[0]['content']['images'][$key],$id);
819
-            }else{
816
+			if('tour' === $this->tab_slug){
817
+				$key = array_rand($data[0]['content']['images']);
818
+				$this->featured_image = $this->attach_image($data[0]['content']['images'][$key],$id);
819
+			}else{
820 820
 				$this->featured_image = $this->attach_image($data[0]['content']['images'][0],$id);
821
-            }
821
+			}
822 822
 
823 823
 
824 824
 			if(false !== $this->featured_image){
@@ -838,7 +838,7 @@  discard block
 block discarded – undo
838 838
 	 */
839 839
 	public function set_banner_image($data,$id) {
840 840
 		if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){
841
-		    //if(isset($data[0]['destination_image']) && is_array($data[0]['destination_image'])) {
841
+			//if(isset($data[0]['destination_image']) && is_array($data[0]['destination_image'])) {
842 842
 				//$temp_banner = $this->attach_image($data[0]['destination_image'], $id, array('width' => '1920', 'height' => '600', 'cropping' => 'c'));
843 843
 			//}else{
844 844
 				//if ('tour' === $this->tab_slug) {
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
 				//} else {
848 848
 					$temp_banner = $this->attach_image($data[0]['content']['images'][1], $id, array('width' => '1920', 'height' => '600', 'cropping' => 'c'));
849 849
 				//}
850
-            //}
850
+			//}
851 851
 
852 852
 			if(false !== $temp_banner){
853 853
 				$this->banner_image = $temp_banner;
@@ -1058,7 +1058,7 @@  discard block
 block discarded – undo
1058 1058
 	 * Run through the accommodation grabbed from the DB.
1059 1059
 	 */
1060 1060
 	public function process_ajax_search() {
1061
-	    $this->current_importer->process_ajax_search();
1061
+		$this->current_importer->process_ajax_search();
1062 1062
 		die();
1063 1063
 	}
1064 1064
 
Please login to merge, or discard this patch.
Spacing   +255 added lines, -255 removed lines patch added patch discarded remove patch
@@ -162,31 +162,31 @@  discard block
 block discarded – undo
162 162
 	 */
163 163
 	public function __construct() {
164 164
 
165
-		add_action( 'admin_init', array( $this, 'compatible_version_check' ) );
165
+		add_action('admin_init', array($this, 'compatible_version_check'));
166 166
 
167 167
 		// Don't run anything else in the plugin, if we're on an incompatible PHP version
168
-		if ( ! self::compatible_version() ) {
168
+		if (!self::compatible_version()) {
169 169
 			return;
170 170
 		}
171 171
 
172 172
 		$this->set_variables();
173 173
 
174
-		add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
175
-		add_action( 'admin_enqueue_scripts', array($this,'admin_scripts') ,11 );
176
-		add_action( 'admin_menu', array( $this, 'register_importer_page' ),20 );
174
+		add_action('init', array($this, 'load_plugin_textdomain'));
175
+		add_action('admin_enqueue_scripts', array($this, 'admin_scripts'), 11);
176
+		add_action('admin_menu', array($this, 'register_importer_page'), 20);
177 177
 
178 178
 		require_once(WETU_IMPORTER_PATH.'classes/class-accommodation.php');
179 179
 		require_once(WETU_IMPORTER_PATH.'classes/class-destination.php');
180 180
 		require_once(WETU_IMPORTER_PATH.'classes/class-tours.php');
181 181
 
182
-		add_action( 'init', array( $this, 'load_class' ) );
182
+		add_action('init', array($this, 'load_class'));
183 183
 
184
-		if('default' !== $this->tab_slug){
185
-			add_action('wp_ajax_lsx_tour_importer',array($this,'process_ajax_search'));
186
-			add_action('wp_ajax_nopriv_lsx_tour_importer',array($this,'process_ajax_search'));
184
+		if ('default' !== $this->tab_slug) {
185
+			add_action('wp_ajax_lsx_tour_importer', array($this, 'process_ajax_search'));
186
+			add_action('wp_ajax_nopriv_lsx_tour_importer', array($this, 'process_ajax_search'));
187 187
 
188
-			add_action('wp_ajax_lsx_import_items',array($this,'process_ajax_import'));
189
-			add_action('wp_ajax_nopriv_lsx_import_items',array($this,'process_ajax_import'));
188
+			add_action('wp_ajax_lsx_import_items', array($this, 'process_ajax_import'));
189
+			add_action('wp_ajax_nopriv_lsx_import_items', array($this, 'process_ajax_import'));
190 190
 		}
191 191
 	}
192 192
 
@@ -198,25 +198,25 @@  discard block
 block discarded – undo
198 198
 	 * @since 1.0.0
199 199
 	 */
200 200
 	public function load_plugin_textdomain() {
201
-		load_plugin_textdomain( 'wetu-importer', FALSE, basename( WETU_IMPORTER_PATH ) . '/languages');
201
+		load_plugin_textdomain('wetu-importer', FALSE, basename(WETU_IMPORTER_PATH).'/languages');
202 202
 	}
203 203
 
204 204
 	/**
205 205
 	 * Sets the variables used throughout the plugin.
206 206
 	 */
207 207
 	public function set_variables() {
208
-		$this->post_types = array('accommodation','destination','tour');
209
-		$temp_options = get_option('_lsx-to_settings',false);
208
+		$this->post_types = array('accommodation', 'destination', 'tour');
209
+		$temp_options = get_option('_lsx-to_settings', false);
210 210
 
211 211
 		//Set the options.
212
-		if(false !== $temp_options && isset($temp_options[$this->plugin_slug])) {
212
+		if (false !== $temp_options && isset($temp_options[$this->plugin_slug])) {
213 213
 			$this->options = $temp_options[$this->plugin_slug];
214 214
 
215 215
 			$this->api_key = false;
216 216
 			$this->api_username = false;
217 217
 			$this->api_password = false;
218 218
 
219
-            if(!defined('WETU_API_KEY')) {
219
+            if (!defined('WETU_API_KEY')) {
220 220
 
221 221
 				if (isset($temp_options['api']['wetu_api_key']) && '' !== $temp_options['api']['wetu_api_key']) {
222 222
 					$this->api_key = $temp_options['api']['wetu_api_key'];
@@ -227,15 +227,15 @@  discard block
 block discarded – undo
227 227
 				if (isset($temp_options['api']['wetu_api_password']) && '' !== $temp_options['api']['wetu_api_password']) {
228 228
 					$this->api_password = $temp_options['api']['wetu_api_password'];
229 229
 				}
230
-			}else{
230
+			}else {
231 231
 				$this->api_key = WETU_API_KEY;
232 232
             }
233 233
 
234 234
 			//Set the tab slug
235
-			if(isset($_GET['tab']) || isset($_POST['type'])) {
235
+			if (isset($_GET['tab']) || isset($_POST['type'])) {
236 236
 				if (isset($_GET['tab'])) {
237 237
 					$this->tab_slug = $_GET['tab'];
238
-				} else {
238
+				}else {
239 239
 					$this->tab_slug = $_POST['type'];
240 240
 				}
241 241
 
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
                 if (isset($this->options['cropping']) && '' !== $this->options['cropping']) {
260 260
                     $cropping = $this->options['cropping'];
261 261
                 }
262
-                $this->image_scaling_url = 'https://wetu.com/ImageHandler/' . $cropping . $width . 'x' . $height . '/';
262
+                $this->image_scaling_url = 'https://wetu.com/ImageHandler/'.$cropping.$width.'x'.$height.'/';
263 263
             }
264 264
 
265 265
 		}
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 	 * @since 1.0.0
283 283
 	 */
284 284
 	public static function compatible_version() {
285
-		if ( version_compare( PHP_VERSION, '5.6', '<' ) ) {
285
+		if (version_compare(PHP_VERSION, '5.6', '<')) {
286 286
 			return false;
287 287
 		}
288 288
 
@@ -296,13 +296,13 @@  discard block
 block discarded – undo
296 296
 	 * @since 1.0.0
297 297
 	 */
298 298
 	public function compatible_version_check() {
299
-		if ( ! self::compatible_version() ) {
300
-			if ( is_plugin_active( plugin_basename( WETU_IMPORTER_CORE ) ) ) {
301
-				deactivate_plugins( plugin_basename( WETU_IMPORTER_CORE ) );
302
-				add_action( 'admin_notices', array( $this, 'compatible_version_notice' ) );
299
+		if (!self::compatible_version()) {
300
+			if (is_plugin_active(plugin_basename(WETU_IMPORTER_CORE))) {
301
+				deactivate_plugins(plugin_basename(WETU_IMPORTER_CORE));
302
+				add_action('admin_notices', array($this, 'compatible_version_notice'));
303 303
 				
304
-				if ( isset( $_GET['activate'] ) ) {
305
-					unset( $_GET['activate'] );
304
+				if (isset($_GET['activate'])) {
305
+					unset($_GET['activate']);
306 306
 				}
307 307
 			}
308 308
 		}
@@ -315,8 +315,8 @@  discard block
 block discarded – undo
315 315
 	 */
316 316
 	public function compatible_version_notice() {
317 317
 		$class = 'notice notice-error';
318
-		$message = esc_html__( 'Wetu Importer Plugin requires PHP 5.6 or higher.', 'wetu-importer' );
319
-		printf( '<div class="%1$s"><p>%2$s</p></div>', esc_html( $class ), esc_html( $message ) );
318
+		$message = esc_html__('Wetu Importer Plugin requires PHP 5.6 or higher.', 'wetu-importer');
319
+		printf('<div class="%1$s"><p>%2$s</p></div>', esc_html($class), esc_html($message));
320 320
 	}
321 321
 	
322 322
 	/**
@@ -326,9 +326,9 @@  discard block
 block discarded – undo
326 326
 	 * @since 1.0.0
327 327
 	 */
328 328
 	public static function compatible_version_check_on_activation() {
329
-		if ( ! self::compatible_version() ) {
330
-			deactivate_plugins( plugin_basename( WETU_IMPORTER_CORE ) );
331
-			wp_die( esc_html__( 'Wetu Importer Plugin requires PHP 5.6 or higher.', 'wetu-importer' ) );
329
+		if (!self::compatible_version()) {
330
+			deactivate_plugins(plugin_basename(WETU_IMPORTER_CORE));
331
+			wp_die(esc_html__('Wetu Importer Plugin requires PHP 5.6 or higher.', 'wetu-importer'));
332 332
 		}
333 333
 	}
334 334
 
@@ -337,9 +337,9 @@  discard block
 block discarded – undo
337 337
     /*
338 338
      * Load the importer class you want to use
339 339
      */
340
-    public function load_class(){
340
+    public function load_class() {
341 341
 
342
-		switch($this->tab_slug){
342
+		switch ($this->tab_slug) {
343 343
 			case 'accommodation':
344 344
 				$this->current_importer = new WETU_Importer_Accommodation();
345 345
 				break;
@@ -363,25 +363,25 @@  discard block
 block discarded – undo
363 363
 	 * Registers the admin page which will house the importer form.
364 364
 	 */
365 365
 	public function register_importer_page() {
366
-		add_submenu_page( 'tour-operator',esc_html__( 'Importer', 'tour-operator' ), esc_html__( 'Importer', 'tour-operator' ), 'manage_options', 'wetu-importer', array( $this, 'display_page' ) );
366
+		add_submenu_page('tour-operator', esc_html__('Importer', 'tour-operator'), esc_html__('Importer', 'tour-operator'), 'manage_options', 'wetu-importer', array($this, 'display_page'));
367 367
 	}
368 368
 
369 369
 	/**
370 370
 	 * Enqueue the JS needed to contact wetu and return your result.
371 371
 	 */
372 372
 	public function admin_scripts() {
373
-		if ( defined( 'WP_DEBUG' ) && true === WP_DEBUG ) {
373
+		if (defined('WP_DEBUG') && true === WP_DEBUG) {
374 374
 			$min = '';
375
-		} else {
375
+		}else {
376 376
 			$min = '.min';
377 377
 		}
378 378
 		$min = '';
379 379
 
380
-		if(is_admin() && isset($_GET['page']) && $this->plugin_slug === $_GET['page']){
381
-			wp_enqueue_script( 'wetu-importers-script', WETU_IMPORTER_URL . 'assets/js/wetu-importer' . $min . '.js', array( 'jquery' ), WETU_IMPORTER_VER, true );
382
-			wp_localize_script( 'wetu-importers-script', 'lsx_tour_importer_params', array(
380
+		if (is_admin() && isset($_GET['page']) && $this->plugin_slug === $_GET['page']) {
381
+			wp_enqueue_script('wetu-importers-script', WETU_IMPORTER_URL.'assets/js/wetu-importer'.$min.'.js', array('jquery'), WETU_IMPORTER_VER, true);
382
+			wp_localize_script('wetu-importers-script', 'lsx_tour_importer_params', array(
383 383
 				'ajax_url' => admin_url('admin-ajax.php'),
384
-			) );
384
+			));
385 385
 		}
386 386
 	}
387 387
 
@@ -393,14 +393,14 @@  discard block
 block discarded – undo
393 393
         <div class="wrap">
394 394
 			<?php screen_icon(); ?>
395 395
 
396
-			<?php if(!is_object($this->current_importer)){
396
+			<?php if (!is_object($this->current_importer)) {
397 397
 				?>
398
-                <h2><?php _e('Welcome to the LSX Wetu Importer','wetu-importer'); ?></h2>
398
+                <h2><?php _e('Welcome to the LSX Wetu Importer', 'wetu-importer'); ?></h2>
399 399
                 <p>If this is the first time you are running the import, then follow the steps below.</p>
400 400
                 <ul>
401
-                    <li>Step 1 - Import your <a href="<?php echo admin_url('admin.php'); ?>?page=<?php echo $this->plugin_slug; ?>&tab=tour"><?php _e('Tours','wetu-importer'); ?></a></li>
402
-                    <li>Step 2 - The tour import will have created draft <a href="<?php echo admin_url('admin.php'); ?>?page=<?php echo $this->plugin_slug; ?>&tab=accommodation"><?php _e('accommodation','wetu-importer'); ?></a> that will need to be imported.</li>
403
-                    <li>Step 3 - Lastly import the <a href="<?php echo admin_url('admin.php'); ?>?page=<?php echo $this->plugin_slug; ?>&tab=destination"><?php _e('destinations','wetu-importer'); ?></a> draft posts created during the previous two steps.</li>
401
+                    <li>Step 1 - Import your <a href="<?php echo admin_url('admin.php'); ?>?page=<?php echo $this->plugin_slug; ?>&tab=tour"><?php _e('Tours', 'wetu-importer'); ?></a></li>
402
+                    <li>Step 2 - The tour import will have created draft <a href="<?php echo admin_url('admin.php'); ?>?page=<?php echo $this->plugin_slug; ?>&tab=accommodation"><?php _e('accommodation', 'wetu-importer'); ?></a> that will need to be imported.</li>
403
+                    <li>Step 3 - Lastly import the <a href="<?php echo admin_url('admin.php'); ?>?page=<?php echo $this->plugin_slug; ?>&tab=destination"><?php _e('destinations', 'wetu-importer'); ?></a> draft posts created during the previous two steps.</li>
404 404
                 </ul>
405 405
 
406 406
                 <?php /*<h3><?php _e('Additional Tools','wetu-importer'); ?></h3>
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
 					<?php } ?>
412 412
                 </ul>
413 413
 				<?php*/
414
-			}else{
414
+			}else {
415 415
 			   $this->current_importer->display_page();
416 416
             }; ?>
417 417
         </div>
@@ -426,38 +426,38 @@  discard block
 block discarded – undo
426 426
         <form class="ajax-form" id="<?php echo $this->plugin_slug; ?>-search-form" method="get" action="tools.php" data-type="<?php echo $this->tab_slug; ?>">
427 427
             <input type="hidden" name="page" value="<?php echo $this->tab_slug; ?>" />
428 428
 
429
-            <h3><span class="dashicons dashicons-search"></span> <?php _e('Search','wetu-importer'); ?></h3>
429
+            <h3><span class="dashicons dashicons-search"></span> <?php _e('Search', 'wetu-importer'); ?></h3>
430 430
 
431
-			<?php do_action('wetu_importer_search_form',$this); ?>
431
+			<?php do_action('wetu_importer_search_form', $this); ?>
432 432
 
433 433
             <div class="normal-search">
434
-                <input pattern=".{3,}" placeholder="3 characters minimum" class="keyword" name="keyword" value=""> <input class="button button-primary submit" type="submit" value="<?php _e('Search','wetu-importer'); ?>" />
434
+                <input pattern=".{3,}" placeholder="3 characters minimum" class="keyword" name="keyword" value=""> <input class="button button-primary submit" type="submit" value="<?php _e('Search', 'wetu-importer'); ?>" />
435 435
             </div>
436 436
             <div class="advanced-search hidden" style="display:none;">
437
-                <p><?php _e('Enter several keywords, each on a new line.','wetu-importer'); ?></p>
437
+                <p><?php _e('Enter several keywords, each on a new line.', 'wetu-importer'); ?></p>
438 438
                 <textarea rows="10" cols="40" name="bulk-keywords"></textarea>
439
-                <input class="button button-primary submit" type="submit" value="<?php _e('Search','wetu-importer'); ?>" />
439
+                <input class="button button-primary submit" type="submit" value="<?php _e('Search', 'wetu-importer'); ?>" />
440 440
             </div>
441 441
 
442 442
             <p>
443
-                <a class="advanced-search-toggle" href="#"><?php _e('Bulk Search','wetu-importer'); ?></a> |
444
-                <a class="published search-toggle" href="#publish"><?php esc_attr_e('Published','wetu-importer'); ?></a> |
445
-                <a class="pending search-toggle"  href="#pending"><?php esc_attr_e('Pending','wetu-importer'); ?></a> |
446
-                <a class="draft search-toggle"  href="#draft"><?php esc_attr_e('Draft','wetu-importer'); ?></a>
447
-
448
-                <?php if('tour'===$this->tab_slug){ ?>
449
-                    | <a class="import search-toggle"  href="#import"><?php esc_attr_e('WETU','wetu-importer'); ?></a>
450
-                <?php }else if(!empty($this->queued_imports)) { ?>
451
-                    | <a class="import search-toggle"  href="#import"><?php esc_attr_e('WETU Queue','wetu-importer'); ?></a>
443
+                <a class="advanced-search-toggle" href="#"><?php _e('Bulk Search', 'wetu-importer'); ?></a> |
444
+                <a class="published search-toggle" href="#publish"><?php esc_attr_e('Published', 'wetu-importer'); ?></a> |
445
+                <a class="pending search-toggle"  href="#pending"><?php esc_attr_e('Pending', 'wetu-importer'); ?></a> |
446
+                <a class="draft search-toggle"  href="#draft"><?php esc_attr_e('Draft', 'wetu-importer'); ?></a>
447
+
448
+                <?php if ('tour' === $this->tab_slug) { ?>
449
+                    | <a class="import search-toggle"  href="#import"><?php esc_attr_e('WETU', 'wetu-importer'); ?></a>
450
+                <?php }else if (!empty($this->queued_imports)) { ?>
451
+                    | <a class="import search-toggle"  href="#import"><?php esc_attr_e('WETU Queue', 'wetu-importer'); ?></a>
452 452
                 <?php } ?>
453 453
             </p>
454 454
 
455 455
             <div class="ajax-loader" style="display:none;width:100%;text-align:center;">
456
-                <img style="width:64px;" src="<?php echo WETU_IMPORTER_URL.'assets/images/ajaxloader.gif';?>" />
456
+                <img style="width:64px;" src="<?php echo WETU_IMPORTER_URL.'assets/images/ajaxloader.gif'; ?>" />
457 457
             </div>
458 458
 
459 459
             <div class="ajax-loader-small" style="display:none;width:100%;text-align:center;">
460
-                <img style="width:32px;" src="<?php echo WETU_IMPORTER_URL.'assets/images/ajaxloader.gif';?>" />
460
+                <img style="width:32px;" src="<?php echo WETU_IMPORTER_URL.'assets/images/ajaxloader.gif'; ?>" />
461 461
             </div>
462 462
         </form> 
463 463
 		<?php
@@ -506,15 +506,15 @@  discard block
 block discarded – undo
506 506
 	 *
507 507
 	 * @param $tab string
508 508
 	 */
509
-	public function navigation($tab='') {
509
+	public function navigation($tab = '') {
510 510
 		$post_types = array(
511
-			'tour'              => esc_attr('Tours','wetu-importer'),
512
-			'accommodation'     => esc_attr('Accommodation','wetu-importer'),
513
-			'destination'       => esc_attr('Destinations','wetu-importer'),
511
+			'tour'              => esc_attr('Tours', 'wetu-importer'),
512
+			'accommodation'     => esc_attr('Accommodation', 'wetu-importer'),
513
+			'destination'       => esc_attr('Destinations', 'wetu-importer'),
514 514
 		);
515
-		echo '<div class="wet-navigation"><div class="subsubsub"><a class="'.$this->itemd($tab,'','current',false).'" href="'.admin_url('admin.php').'?page='.$this->plugin_slug.'">'.esc_attr('Home','wetu-importer').'</a>';
516
-		foreach($post_types as $post_type => $label){
517
-			echo ' | <a class="'.$this->itemd($tab,$post_type,'current',false).'" href="'.admin_url('admin.php').'?page='.$this->plugin_slug.'&tab='.$post_type.'">'.$label.'</a>';
515
+		echo '<div class="wet-navigation"><div class="subsubsub"><a class="'.$this->itemd($tab, '', 'current', false).'" href="'.admin_url('admin.php').'?page='.$this->plugin_slug.'">'.esc_attr('Home', 'wetu-importer').'</a>';
516
+		foreach ($post_types as $post_type => $label) {
517
+			echo ' | <a class="'.$this->itemd($tab, $post_type, 'current', false).'" href="'.admin_url('admin.php').'?page='.$this->plugin_slug.'&tab='.$post_type.'">'.$label.'</a>';
518 518
 		}
519 519
 		echo '</div><br clear="both"/></div>';
520 520
 	}
@@ -522,23 +522,23 @@  discard block
 block discarded – undo
522 522
 	/**
523 523
 	 * set_taxonomy with some terms
524 524
 	 */
525
-	public function team_member_checkboxes($selected=array()) {
526
-		if(post_type_exists('team')) { ?>
525
+	public function team_member_checkboxes($selected = array()) {
526
+		if (post_type_exists('team')) { ?>
527 527
             <ul>
528 528
 				<?php
529
-				$team_args=array(
529
+				$team_args = array(
530 530
 					'post_type'	=>	'team',
531 531
 					'post_status' => 'publish',
532 532
 					'nopagin' => true,
533 533
 					'fields' => 'ids'
534 534
 				);
535 535
 				$team_members = new WP_Query($team_args);
536
-				if($team_members->have_posts()){
537
-					foreach($team_members->posts as $member){ ?>
538
-                        <li><input class="team" <?php $this->checked($selected,$member); ?> type="checkbox" value="<?php echo $member; ?>" /> <?php echo get_the_title($member); ?></li>
536
+				if ($team_members->have_posts()) {
537
+					foreach ($team_members->posts as $member) { ?>
538
+                        <li><input class="team" <?php $this->checked($selected, $member); ?> type="checkbox" value="<?php echo $member; ?>" /> <?php echo get_the_title($member); ?></li>
539 539
 					<?php }
540
-				}else{ ?>
541
-                    <li><input class="team" type="checkbox" value="0" /> <?php _e('None','wetu-importer'); ?></li>
540
+				}else { ?>
541
+                    <li><input class="team" type="checkbox" value="0" /> <?php _e('None', 'wetu-importer'); ?></li>
542 542
 				<?php }
543 543
 				?>
544 544
             </ul>
@@ -555,12 +555,12 @@  discard block
 block discarded – undo
555 555
 	 * @param $needle string
556 556
 	 * @param $echo bool
557 557
 	 */
558
-	public function checked($haystack=false,$needle='',$echo=true) {
559
-		$return = $this->itemd($haystack,$needle,'checked');
560
-		if('' !== $return) {
558
+	public function checked($haystack = false, $needle = '', $echo = true) {
559
+		$return = $this->itemd($haystack, $needle, 'checked');
560
+		if ('' !== $return) {
561 561
 			if (true === $echo) {
562 562
 				echo $return;
563
-			} else {
563
+			}else {
564 564
 				return $return;
565 565
 			}
566 566
 		}
@@ -573,12 +573,12 @@  discard block
 block discarded – undo
573 573
 	 * @param $needle string
574 574
 	 * @param $echo bool
575 575
 	 */
576
-	public function selected($haystack=false,$needle='',$echo=true) {
577
-		$return = $this->itemd($haystack,$needle,'selected');
578
-		if('' !== $return) {
576
+	public function selected($haystack = false, $needle = '', $echo = true) {
577
+		$return = $this->itemd($haystack, $needle, 'selected');
578
+		if ('' !== $return) {
579 579
 			if (true === $echo) {
580 580
 				echo $return;
581
-			} else {
581
+			}else {
582 582
 				return $return;
583 583
 			}
584 584
 		}
@@ -593,16 +593,16 @@  discard block
 block discarded – undo
593 593
 	 * @param $wrap bool
594 594
 	 * @return $html string
595 595
 	 */
596
-	public function itemd($haystack=false,$needle='',$type='',$wrap=true) {
596
+	public function itemd($haystack = false, $needle = '', $type = '', $wrap = true) {
597 597
 		$html = '';
598
-		if('' !== $type) {
598
+		if ('' !== $type) {
599 599
 			if (!is_array($haystack)) {
600 600
 				$haystack = array($haystack);
601 601
 			}
602 602
 			if (in_array($needle, $haystack)) {
603
-				if(true === $wrap || 'true' === $wrap) {
604
-					$html = $type . '="' . $type . '"';
605
-				}else{
603
+				if (true === $wrap || 'true' === $wrap) {
604
+					$html = $type.'="'.$type.'"';
605
+				}else {
606 606
 					$html = $type;
607 607
 				}
608 608
 			}
@@ -614,9 +614,9 @@  discard block
 block discarded – undo
614 614
 	/**
615 615
 	 * grabs any attachments for the current item
616 616
 	 */
617
-	public function find_attachments($id=false) {
618
-		if(false !== $id){
619
-			if(empty($this->found_attachments)){
617
+	public function find_attachments($id = false) {
618
+		if (false !== $id) {
619
+			if (empty($this->found_attachments)) {
620 620
 
621 621
 				$attachments_args = array(
622 622
 					'post_parent' => $id,
@@ -628,9 +628,9 @@  discard block
 block discarded – undo
628 628
 				);
629 629
 
630 630
 				$attachments = new WP_Query($attachments_args);
631
-				if($attachments->have_posts()){
632
-					foreach($attachments->posts as $attachment){
633
-						$this->found_attachments[$attachment->ID] = str_replace(array('.jpg','.png','.jpeg'),'',$attachment->post_title);
631
+				if ($attachments->have_posts()) {
632
+					foreach ($attachments->posts as $attachment) {
633
+						$this->found_attachments[$attachment->ID] = str_replace(array('.jpg', '.png', '.jpeg'), '', $attachment->post_title);
634 634
 						$this->gallery_meta[] = $attachment->ID;
635 635
 					}
636 636
 				}
@@ -644,18 +644,18 @@  discard block
 block discarded – undo
644 644
 	/**
645 645
 	 * Saves the room data
646 646
 	 */
647
-	public function save_custom_field($value=false,$meta_key,$id,$decrease=false,$unique=true) {
648
-		if(false !== $value){
649
-			if(false !== $decrease){
647
+	public function save_custom_field($value = false, $meta_key, $id, $decrease = false, $unique = true) {
648
+		if (false !== $value) {
649
+			if (false !== $decrease) {
650 650
 				$value = intval($value);
651 651
 				$value--;
652 652
 			}
653
-			$prev = get_post_meta($id,$meta_key,true);
653
+			$prev = get_post_meta($id, $meta_key, true);
654 654
 
655
-			if(false !== $id && '0' !== $id && false !== $prev && true === $unique){
656
-				update_post_meta($id,$meta_key,$value,$prev);
657
-			}else{
658
-				add_post_meta($id,$meta_key,$value,$unique);
655
+			if (false !== $id && '0' !== $id && false !== $prev && true === $unique) {
656
+				update_post_meta($id, $meta_key, $value, $prev);
657
+			}else {
658
+				add_post_meta($id, $meta_key, $value, $unique);
659 659
 			}
660 660
 		}
661 661
 	}
@@ -664,12 +664,12 @@  discard block
 block discarded – undo
664 664
 	 * Grabs the custom fields,  and resaves an array of unique items.
665 665
 	 */
666 666
 	public function cleanup_posts() {
667
-		if(!empty($this->cleanup_posts)){
668
-			foreach($this->cleanup_posts as $id => $key) {
667
+		if (!empty($this->cleanup_posts)) {
668
+			foreach ($this->cleanup_posts as $id => $key) {
669 669
 				$prev_items = get_post_meta($id, $key, false);
670 670
 				$new_items = array_unique($prev_items);
671 671
 				delete_post_meta($id, $key);
672
-				foreach($new_items as $new_item) {
672
+				foreach ($new_items as $new_item) {
673 673
 					add_post_meta($id, $key, $new_item, false);
674 674
 				}
675 675
 			}
@@ -681,51 +681,51 @@  discard block
 block discarded – undo
681 681
 	/**
682 682
 	 * set_taxonomy with some terms
683 683
 	 */
684
-	public function set_taxonomy($taxonomy,$terms,$id) {
685
-		$result=array();
686
-		if(!empty($data))
684
+	public function set_taxonomy($taxonomy, $terms, $id) {
685
+		$result = array();
686
+		if (!empty($data))
687 687
 		{
688
-			foreach($data as $k)
688
+			foreach ($data as $k)
689 689
 			{
690
-				if($id)
690
+				if ($id)
691 691
 				{
692
-					if(!$term = term_exists(trim($k), $tax))
692
+					if (!$term = term_exists(trim($k), $tax))
693 693
 					{
694 694
 						$term = wp_insert_term(trim($k), $tax);
695
-						if ( is_wp_error($term) )
695
+						if (is_wp_error($term))
696 696
 						{
697 697
 							echo $term->get_error_message();
698 698
 						}
699 699
 						else
700 700
 						{
701
-							wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true);
701
+							wp_set_object_terms($id, intval($term['term_id']), $taxonomy, true);
702 702
 						}
703 703
 					}
704 704
 					else
705 705
 					{
706
-						wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true);
706
+						wp_set_object_terms($id, intval($term['term_id']), $taxonomy, true);
707 707
 					}
708 708
 				}
709 709
 				else
710 710
 				{
711
-					$result[]=trim($k);
711
+					$result[] = trim($k);
712 712
 				}
713 713
 			}
714 714
 		}
715 715
 		return $result;
716 716
 	}
717 717
 
718
-	public function set_term($id=false,$name=false,$taxonomy=false,$parent=false){
719
-		if(!$term = term_exists($name, $taxonomy))
718
+	public function set_term($id = false, $name = false, $taxonomy = false, $parent = false) {
719
+		if (!$term = term_exists($name, $taxonomy))
720 720
 		{
721
-			if(false !== $parent){ $parent = array('parent'=>$parent); }
722
-			$term = wp_insert_term(trim($name), $taxonomy,$parent);
723
-			if ( is_wp_error($term) ){echo $term->get_error_message();}
724
-			else { wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); }
721
+			if (false !== $parent) { $parent = array('parent'=>$parent); }
722
+			$term = wp_insert_term(trim($name), $taxonomy, $parent);
723
+			if (is_wp_error($term)) {echo $term->get_error_message(); }
724
+			else { wp_set_object_terms($id, intval($term['term_id']), $taxonomy, true); }
725 725
 		}
726 726
 		else
727 727
 		{
728
-			wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true);
728
+			wp_set_object_terms($id, intval($term['term_id']), $taxonomy, true);
729 729
 		}
730 730
 		return $term['term_id'];
731 731
 	}
@@ -733,18 +733,18 @@  discard block
 block discarded – undo
733 733
 	/**
734 734
 	 * set_taxonomy with some terms
735 735
 	 */
736
-	public function taxonomy_checkboxes($taxonomy=false,$selected=array()) {
736
+	public function taxonomy_checkboxes($taxonomy = false, $selected = array()) {
737 737
 		$return = '';
738
-		if(false !== $taxonomy){
738
+		if (false !== $taxonomy) {
739 739
 			$return .= '<ul>';
740
-			$terms = get_terms(array('taxonomy'=>$taxonomy,'hide_empty'=>false));
740
+			$terms = get_terms(array('taxonomy'=>$taxonomy, 'hide_empty'=>false));
741 741
 
742
-			if(!is_wp_error($terms)){
743
-				foreach($terms as $term){
744
-					$return .= '<li><input class="'.$taxonomy.'" '.$this->checked($selected,$term->term_id,false).' type="checkbox" value="'.$term->term_id.'" /> '.$term->name.'</li>';
742
+			if (!is_wp_error($terms)) {
743
+				foreach ($terms as $term) {
744
+					$return .= '<li><input class="'.$taxonomy.'" '.$this->checked($selected, $term->term_id, false).' type="checkbox" value="'.$term->term_id.'" /> '.$term->name.'</li>';
745 745
 				}
746
-			}else{
747
-				$return .= '<li><input type="checkbox" value="" /> '.__('None','wetu-importer').'</li>';
746
+			}else {
747
+				$return .= '<li><input type="checkbox" value="" /> '.__('None', 'wetu-importer').'</li>';
748 748
 			}
749 749
 			$return .= '</ul>';
750 750
 		}
@@ -755,53 +755,53 @@  discard block
 block discarded – undo
755 755
 	/**
756 756
 	 * Saves the longitude and lattitude, as well as sets the map marker.
757 757
 	 */
758
-	public function set_map_data($data,$id,$zoom = '10') {
758
+	public function set_map_data($data, $id, $zoom = '10') {
759 759
 		$longitude = $latitude = $address = false;
760 760
 
761
-		if(isset($data[0]['position'])){
761
+		if (isset($data[0]['position'])) {
762 762
 
763
-			if(isset($data[0]['position']['driving_latitude'])){
763
+			if (isset($data[0]['position']['driving_latitude'])) {
764 764
 				$latitude = $data[0]['position']['driving_latitude'];
765
-			}elseif(isset($data[0]['position']['latitude'])){
765
+			}elseif (isset($data[0]['position']['latitude'])) {
766 766
 				$latitude = $data[0]['position']['latitude'];
767 767
 			}
768 768
 
769
-			if(isset($data[0]['position']['driving_longitude'])){
769
+			if (isset($data[0]['position']['driving_longitude'])) {
770 770
 				$longitude = $data[0]['position']['driving_longitude'];
771
-			}elseif(isset($data[0]['position']['longitude'])){
771
+			}elseif (isset($data[0]['position']['longitude'])) {
772 772
 				$longitude = $data[0]['position']['longitude'];
773 773
 			}
774 774
 
775 775
 		}
776
-		if(isset($data[0]['content']) && isset($data[0]['content']['contact_information'])){
777
-			if(isset($data[0]['content']['contact_information']['address'])){
776
+		if (isset($data[0]['content']) && isset($data[0]['content']['contact_information'])) {
777
+			if (isset($data[0]['content']['contact_information']['address'])) {
778 778
 				$address = strip_tags($data[0]['content']['contact_information']['address']);
779 779
 
780
-				$address = explode("\n",$address);
781
-				foreach($address as $bitkey => $bit){
780
+				$address = explode("\n", $address);
781
+				foreach ($address as $bitkey => $bit) {
782 782
 					$bit = ltrim(rtrim($bit));
783
-					if(false === $bit || '' === $bit || null === $bit or empty($bit)){
783
+					if (false === $bit || '' === $bit || null === $bit or empty($bit)) {
784 784
 						unset($address[$bitkey]);
785 785
 					}
786 786
 				}
787
-				$address = implode(', ',$address);
787
+				$address = implode(', ', $address);
788 788
 				$address = str_replace(', , ', ', ', $address);
789 789
 			}
790 790
 		}
791 791
 
792
-		if(false !== $longitude){
792
+		if (false !== $longitude) {
793 793
 			$location_data = array(
794
-				'address'	=>	(string)$address,
795
-				'lat'		=>	(string)$latitude,
796
-				'long'		=>	(string)$longitude,
797
-				'zoom'		=>	(string)$zoom,
794
+				'address'	=>	(string) $address,
795
+				'lat'		=>	(string) $latitude,
796
+				'long'		=>	(string) $longitude,
797
+				'zoom'		=>	(string) $zoom,
798 798
 				'elevation'	=>	'',
799 799
 			);
800
-			if(false !== $id && '0' !== $id){
801
-				$prev = get_post_meta($id,'location',true);
802
-				update_post_meta($id,'location',$location_data,$prev);
803
-			}else{
804
-				add_post_meta($id,'location',$location_data,true);
800
+			if (false !== $id && '0' !== $id) {
801
+				$prev = get_post_meta($id, 'location', true);
802
+				update_post_meta($id, 'location', $location_data, $prev);
803
+			}else {
804
+				add_post_meta($id, 'location', $location_data, true);
805 805
 			}
806 806
 		}
807 807
 	}
@@ -811,22 +811,22 @@  discard block
 block discarded – undo
811 811
 	/**
812 812
 	 * Creates the main gallery data
813 813
 	 */
814
-	public function set_featured_image($data,$id) {
815
-		if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){
816
-		    if('tour' === $this->tab_slug){
814
+	public function set_featured_image($data, $id) {
815
+		if (is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])) {
816
+		    if ('tour' === $this->tab_slug) {
817 817
 		        $key = array_rand($data[0]['content']['images']);
818
-                $this->featured_image = $this->attach_image($data[0]['content']['images'][$key],$id);
819
-            }else{
820
-				$this->featured_image = $this->attach_image($data[0]['content']['images'][0],$id);
818
+                $this->featured_image = $this->attach_image($data[0]['content']['images'][$key], $id);
819
+            }else {
820
+				$this->featured_image = $this->attach_image($data[0]['content']['images'][0], $id);
821 821
             }
822 822
 
823 823
 
824
-			if(false !== $this->featured_image){
825
-				delete_post_meta($id,'_thumbnail_id');
826
-				add_post_meta($id,'_thumbnail_id',$this->featured_image,true);
824
+			if (false !== $this->featured_image) {
825
+				delete_post_meta($id, '_thumbnail_id');
826
+				add_post_meta($id, '_thumbnail_id', $this->featured_image, true);
827 827
 
828
-				if(!empty($this->gallery_meta) && !in_array($this->featured_image,$this->gallery_meta)){
829
-					add_post_meta($id,'gallery',$this->featured_image,false);
828
+				if (!empty($this->gallery_meta) && !in_array($this->featured_image, $this->gallery_meta)) {
829
+					add_post_meta($id, 'gallery', $this->featured_image, false);
830 830
 					$this->gallery_meta[] = $this->featured_image;
831 831
 				}
832 832
 			}
@@ -836,8 +836,8 @@  discard block
 block discarded – undo
836 836
 	/**
837 837
 	 * Sets a banner image
838 838
 	 */
839
-	public function set_banner_image($data,$id) {
840
-		if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){
839
+	public function set_banner_image($data, $id) {
840
+		if (is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])) {
841 841
 		    //if(isset($data[0]['destination_image']) && is_array($data[0]['destination_image'])) {
842 842
 				//$temp_banner = $this->attach_image($data[0]['destination_image'], $id, array('width' => '1920', 'height' => '600', 'cropping' => 'c'));
843 843
 			//}else{
@@ -849,14 +849,14 @@  discard block
 block discarded – undo
849 849
 				//}
850 850
             //}
851 851
 
852
-			if(false !== $temp_banner){
852
+			if (false !== $temp_banner) {
853 853
 				$this->banner_image = $temp_banner;
854 854
 
855
-				delete_post_meta($id,'image_group');
855
+				delete_post_meta($id, 'image_group');
856 856
 				$new_banner = array('banner_image'=>array('cmb-field-0'=>$this->banner_image));
857
-				add_post_meta($id,'image_group',$new_banner,true);
857
+				add_post_meta($id, 'image_group', $new_banner, true);
858 858
 
859
-				if(!empty($this->gallery_meta) && !in_array($this->banner_image,$this->gallery_meta)) {
859
+				if (!empty($this->gallery_meta) && !in_array($this->banner_image, $this->gallery_meta)) {
860 860
 					//add_post_meta($id,'gallery',$this->banner_image,false);
861 861
 					//$this->gallery_meta[] = $this->banner_image;
862 862
 				}
@@ -867,24 +867,24 @@  discard block
 block discarded – undo
867 867
 	/**
868 868
 	 * Creates the main gallery data
869 869
 	 */
870
-	public function create_main_gallery($data,$id) {
870
+	public function create_main_gallery($data, $id) {
871 871
 
872
-		if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){
872
+		if (is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])) {
873 873
 			$counter = 0;
874
-			foreach($data[0]['content']['images'] as $image_data){
875
-				if($counter === 0 && false !== $this->featured_image){$counter++;continue;}
876
-				if($counter === 1 && false !== $this->banner_image){$counter++;continue;}
874
+			foreach ($data[0]['content']['images'] as $image_data) {
875
+				if ($counter === 0 && false !== $this->featured_image) {$counter++; continue; }
876
+				if ($counter === 1 && false !== $this->banner_image) {$counter++; continue; }
877 877
 
878
-				$this->gallery_meta[] = $this->attach_image($image_data,$id);
878
+				$this->gallery_meta[] = $this->attach_image($image_data, $id);
879 879
 				$counter++;
880 880
 			}
881 881
 
882
-			if(!empty($this->gallery_meta)){
883
-				delete_post_meta($id,'gallery');
882
+			if (!empty($this->gallery_meta)) {
883
+				delete_post_meta($id, 'gallery');
884 884
 				$this->gallery_meta = array_unique($this->gallery_meta);
885
-				foreach($this->gallery_meta as $gallery_id){
886
-					if(false !== $gallery_id && '' !== $gallery_id && !is_array($gallery_id)){
887
-						add_post_meta($id,'gallery',$gallery_id,false);
885
+				foreach ($this->gallery_meta as $gallery_id) {
886
+					if (false !== $gallery_id && '' !== $gallery_id && !is_array($gallery_id)) {
887
+						add_post_meta($id, 'gallery', $gallery_id, false);
888 888
 					}
889 889
 				}
890 890
 			}
@@ -894,27 +894,27 @@  discard block
 block discarded – undo
894 894
 	/**
895 895
 	 * search_form
896 896
 	 */
897
-	public function get_scaling_url($args=array()) {
897
+	public function get_scaling_url($args = array()) {
898 898
 
899 899
 		$defaults = array(
900 900
 			'width' => '1024',
901 901
 			'height' => '768',
902 902
 			'cropping' => 'w'
903 903
 		);
904
-		if(false !== $this->options){
905
-			if(isset($this->options['width']) && '' !== $this->options['width']){
904
+		if (false !== $this->options) {
905
+			if (isset($this->options['width']) && '' !== $this->options['width']) {
906 906
 				$defaults['width'] = $this->options['width'];
907 907
 			}
908 908
 
909
-			if(isset($this->options['height']) && '' !== $this->options['height']){
909
+			if (isset($this->options['height']) && '' !== $this->options['height']) {
910 910
 				$defaults['height'] = $this->options['height'];
911 911
 			}
912 912
 
913
-			if(isset($this->options['cropping']) && '' !== $this->options['cropping']){
913
+			if (isset($this->options['cropping']) && '' !== $this->options['cropping']) {
914 914
 				$defaults['cropping'] = $this->options['cropping'];
915 915
 			}
916 916
 		}
917
-		$args = wp_parse_args($args,$defaults);
917
+		$args = wp_parse_args($args, $defaults);
918 918
 
919 919
 		$cropping = $args['cropping'];
920 920
 		$width = $args['width'];
@@ -926,43 +926,43 @@  discard block
 block discarded – undo
926 926
 	/**
927 927
 	 * Attaches 1 image
928 928
 	 */
929
-	public function attach_image($v=false,$parent_id,$image_sizes=false){
930
-		if(false !== $v){
931
-			$temp_fragment = explode('/',$v['url_fragment']);
932
-			$url_filename = $temp_fragment[count($temp_fragment)-1];
933
-			$url_filename = str_replace(array('.jpg','.png','.jpeg'),'',$url_filename);
929
+	public function attach_image($v = false, $parent_id, $image_sizes = false) {
930
+		if (false !== $v) {
931
+			$temp_fragment = explode('/', $v['url_fragment']);
932
+			$url_filename = $temp_fragment[count($temp_fragment) - 1];
933
+			$url_filename = str_replace(array('.jpg', '.png', '.jpeg'), '', $url_filename);
934 934
 			$url_filename = trim($url_filename);
935
-			$url_filename = str_replace(" ",'_',$url_filename);
935
+			$url_filename = str_replace(" ", '_', $url_filename);
936 936
 
937
-			if(in_array($url_filename,$this->found_attachments)){
938
-				return array_search($url_filename,$this->found_attachments);
937
+			if (in_array($url_filename, $this->found_attachments)) {
938
+				return array_search($url_filename, $this->found_attachments);
939 939
 			}
940 940
 
941
-			$postdata=array();
942
-			if(empty($v['label']))
941
+			$postdata = array();
942
+			if (empty($v['label']))
943 943
 			{
944
-				$v['label']='';
944
+				$v['label'] = '';
945 945
 			}
946
-			if(!empty($v['description']))
946
+			if (!empty($v['description']))
947 947
 			{
948
-				$desc=wp_strip_all_tags($v['description']);
949
-				$posdata=array('post_excerpt'=>$desc);
948
+				$desc = wp_strip_all_tags($v['description']);
949
+				$posdata = array('post_excerpt'=>$desc);
950 950
 			}
951
-			if(!empty($v['section']))
951
+			if (!empty($v['section']))
952 952
 			{
953
-				$desc=wp_strip_all_tags($v['section']);
954
-				$posdata=array('post_excerpt'=>$desc);
953
+				$desc = wp_strip_all_tags($v['section']);
954
+				$posdata = array('post_excerpt'=>$desc);
955 955
 			}
956 956
 
957
-			$attachID=NULL;
957
+			$attachID = NULL;
958 958
 			//Resizor - add option to setting if required
959
-			$fragment = str_replace(' ','%20',$v['url_fragment']);
959
+			$fragment = str_replace(' ', '%20', $v['url_fragment']);
960 960
 			$url = $this->get_scaling_url($image_sizes).$fragment;
961 961
 
962
-			$attachID = $this->attach_external_image2($url,$parent_id,'',$v['label'],$postdata);
962
+			$attachID = $this->attach_external_image2($url, $parent_id, '', $v['label'], $postdata);
963 963
 
964 964
 			//echo($attachID.' add image');
965
-			if($attachID!=NULL)
965
+			if ($attachID != NULL)
966 966
 			{
967 967
 				return $attachID;
968 968
 			}
@@ -970,13 +970,13 @@  discard block
 block discarded – undo
970 970
 		return 	false;
971 971
 	}
972 972
 
973
-	public function attach_external_image2( $url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array() ) {
973
+	public function attach_external_image2($url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array()) {
974 974
 
975
-		if ( !$url || !$post_id ) { return new WP_Error('missing', "Need a valid URL and post ID..."); }
975
+		if (!$url || !$post_id) { return new WP_Error('missing', "Need a valid URL and post ID..."); }
976 976
 
977
-		require_once(ABSPATH . 'wp-admin/includes/file.php');
978
-		require_once(ABSPATH . 'wp-admin/includes/media.php');
979
-		require_once(ABSPATH . 'wp-admin/includes/image.php');
977
+		require_once(ABSPATH.'wp-admin/includes/file.php');
978
+		require_once(ABSPATH.'wp-admin/includes/media.php');
979
+		require_once(ABSPATH.'wp-admin/includes/image.php');
980 980
 		// Download file to temp location, returns full server path to temp file
981 981
 		//$tmp = download_url( $url );
982 982
 
@@ -985,53 +985,53 @@  discard block
 block discarded – undo
985 985
 
986 986
 		$image = file_get_contents($url);
987 987
 		file_put_contents($tmp, $image);
988
-		chmod($tmp,'777');
988
+		chmod($tmp, '777');
989 989
 
990
-		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
990
+		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
991 991
 		$url_filename = basename($matches[0]);
992
-		$url_filename=str_replace('%20','_',$url_filename);
992
+		$url_filename = str_replace('%20', '_', $url_filename);
993 993
 		// extract filename from url for title
994
-		$url_type = wp_check_filetype($url_filename);                                           // determine file type (ext and mime/type)
994
+		$url_type = wp_check_filetype($url_filename); // determine file type (ext and mime/type)
995 995
 
996 996
 		// override filename if given, reconstruct server path
997
-		if ( !empty( $filename ) && " " != $filename )
997
+		if (!empty($filename) && " " != $filename)
998 998
 		{
999 999
 			$filename = sanitize_file_name($filename);
1000
-			$tmppath = pathinfo( $tmp );
1000
+			$tmppath = pathinfo($tmp);
1001 1001
 
1002 1002
 			$extension = '';
1003
-			if(isset($tmppath['extension'])){
1003
+			if (isset($tmppath['extension'])) {
1004 1004
 				$extension = $tmppath['extension'];
1005 1005
 			}
1006 1006
 
1007
-			$new = $tmppath['dirname'] . "/". $filename . "." . $extension;
1008
-			rename($tmp, $new);                                                                 // renames temp file on server
1009
-			$tmp = $new;                                                                        // push new filename (in path) to be used in file array later
1007
+			$new = $tmppath['dirname']."/".$filename.".".$extension;
1008
+			rename($tmp, $new); // renames temp file on server
1009
+			$tmp = $new; // push new filename (in path) to be used in file array later
1010 1010
 		}
1011 1011
 
1012 1012
 		// assemble file data (should be built like $_FILES since wp_handle_sideload() will be using)
1013
-		$file_array['tmp_name'] = $tmp;                                                         // full server path to temp file
1013
+		$file_array['tmp_name'] = $tmp; // full server path to temp file
1014 1014
 
1015
-		if ( !empty( $filename) && " " != $filename )
1015
+		if (!empty($filename) && " " != $filename)
1016 1016
 		{
1017
-			$file_array['name'] = $filename . "." . $url_type['ext'];                           // user given filename for title, add original URL extension
1017
+			$file_array['name'] = $filename.".".$url_type['ext']; // user given filename for title, add original URL extension
1018 1018
 		}
1019 1019
 		else
1020 1020
 		{
1021
-			$file_array['name'] = $url_filename;                                                // just use original URL filename
1021
+			$file_array['name'] = $url_filename; // just use original URL filename
1022 1022
 		}
1023 1023
 
1024 1024
 		// set additional wp_posts columns
1025
-		if ( empty( $post_data['post_title'] ) )
1025
+		if (empty($post_data['post_title']))
1026 1026
 		{
1027 1027
 
1028
-			$url_filename=str_replace('%20',' ',$url_filename);
1028
+			$url_filename = str_replace('%20', ' ', $url_filename);
1029 1029
 
1030
-			$post_data['post_title'] = basename($url_filename, "." . $url_type['ext']);         // just use the original filename (no extension)
1030
+			$post_data['post_title'] = basename($url_filename, ".".$url_type['ext']); // just use the original filename (no extension)
1031 1031
 		}
1032 1032
 
1033 1033
 		// make sure gets tied to parent
1034
-		if ( empty( $post_data['post_parent'] ) )
1034
+		if (empty($post_data['post_parent']))
1035 1035
 		{
1036 1036
 			$post_data['post_parent'] = $post_id;
1037 1037
 		}
@@ -1039,12 +1039,12 @@  discard block
 block discarded – undo
1039 1039
 		// required libraries for media_handle_sideload
1040 1040
 
1041 1041
 		// do the validation and storage stuff
1042
-		$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
1042
+		$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
1043 1043
 
1044 1044
 		// If error storing permanently, unlink
1045
-		if ( is_wp_error($att_id) )
1045
+		if (is_wp_error($att_id))
1046 1046
 		{
1047
-			unlink($file_array['tmp_name']);   // clean up
1047
+			unlink($file_array['tmp_name']); // clean up
1048 1048
 			return false; // output wp_error
1049 1049
 			//return $att_id; // output wp_error
1050 1050
 		}
@@ -1073,31 +1073,31 @@  discard block
 block discarded – undo
1073 1073
 	/**
1074 1074
 	 * Formats the row for the completed list.
1075 1075
 	 */
1076
-	public function format_completed_row($response){
1076
+	public function format_completed_row($response) {
1077 1077
 		echo '<li class="post-'.$response.'"><span class="dashicons dashicons-yes"></span> <a target="_blank" href="'.get_permalink($response).'">'.get_the_title($response).'</a></li>';
1078 1078
 	}
1079 1079
 
1080 1080
 	/**
1081 1081
 	 * Formats the error.
1082 1082
 	 */
1083
-	public function format_error($response){
1083
+	public function format_error($response) {
1084 1084
 		echo '<li class="post-error"><span class="dashicons dashicons-no"></span>'.$response.'</li>';
1085 1085
 	}
1086 1086
 
1087 1087
 	/**
1088 1088
 	 * Does a multine search
1089 1089
 	 */
1090
-	public function multineedle_stripos($haystack, $needles, $offset=0) {
1090
+	public function multineedle_stripos($haystack, $needles, $offset = 0) {
1091 1091
 		$found = false;
1092 1092
 		$needle_count = count($needles);
1093
-		foreach($needles as $needle) {
1094
-			if(false !== stripos($haystack, $needle, $offset)){
1093
+		foreach ($needles as $needle) {
1094
+			if (false !== stripos($haystack, $needle, $offset)) {
1095 1095
 				$found[] = true;
1096 1096
 			}
1097 1097
 		}
1098
-		if(false !== $found && $needle_count === count($found)){
1098
+		if (false !== $found && $needle_count === count($found)) {
1099 1099
 			return true;
1100
-		}else{
1100
+		}else {
1101 1101
 			return false;
1102 1102
 		}
1103 1103
 	}
@@ -1105,7 +1105,7 @@  discard block
 block discarded – undo
1105 1105
 	/**
1106 1106
 	 * Grab all the current accommodation posts via the lsx_wetu_id field.
1107 1107
 	 */
1108
-	public function find_current_accommodation($post_type='accommodation') {
1108
+	public function find_current_accommodation($post_type = 'accommodation') {
1109 1109
 		global $wpdb;
1110 1110
 		$return = array();
1111 1111
 
@@ -1121,8 +1121,8 @@  discard block
 block discarded – undo
1121 1121
 
1122 1122
 					LIMIT 0,5000
1123 1123
 		");
1124
-		if(null !== $current_accommodation && !empty($current_accommodation)){
1125
-			foreach($current_accommodation as $accom){
1124
+		if (null !== $current_accommodation && !empty($current_accommodation)) {
1125
+			foreach ($current_accommodation as $accom) {
1126 1126
 				$return[$accom->meta_value] = $accom;
1127 1127
 			}
1128 1128
 		}
@@ -1132,31 +1132,31 @@  discard block
 block discarded – undo
1132 1132
 	/**
1133 1133
 	 * Set the Video date
1134 1134
 	 */
1135
-	public function set_video_data($data,$id) {
1136
-		if(!empty($data[0]['content']['youtube_videos']) && is_array($data[0]['content']['youtube_videos'])){
1135
+	public function set_video_data($data, $id) {
1136
+		if (!empty($data[0]['content']['youtube_videos']) && is_array($data[0]['content']['youtube_videos'])) {
1137 1137
 			$videos = false;
1138 1138
 
1139
-			foreach($data[0]['content']['youtube_videos'] as $video){
1139
+			foreach ($data[0]['content']['youtube_videos'] as $video) {
1140 1140
 				$temp_video = array();
1141 1141
 
1142
-				if(isset($video['label'])){
1142
+				if (isset($video['label'])) {
1143 1143
 					$temp_video['title'] = $video['label'];
1144 1144
 				}
1145
-				if(isset($video['description'])){
1145
+				if (isset($video['description'])) {
1146 1146
 					$temp_video['description'] = strip_tags($video['description']);
1147 1147
 				}
1148
-				if(isset($video['url'])){
1148
+				if (isset($video['url'])) {
1149 1149
 					$temp_video['url'] = $video['url'];
1150 1150
 				}
1151 1151
 				$temp_video['thumbnail'] = '';
1152 1152
 				$videos[] = $temp_video;
1153 1153
 			}
1154 1154
 
1155
-			if(false !== $id && '0' !== $id){
1155
+			if (false !== $id && '0' !== $id) {
1156 1156
 				delete_post_meta($id, 'videos');
1157 1157
 			}
1158
-			foreach($videos as $video){
1159
-				add_post_meta($id,'videos',$video,false);
1158
+			foreach ($videos as $video) {
1159
+				add_post_meta($id, 'videos', $video, false);
1160 1160
 			}
1161 1161
 		}
1162 1162
 	}
Please login to merge, or discard this patch.
Braces   +18 added lines, -24 removed lines patch added patch discarded remove patch
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 				if (isset($temp_options['api']['wetu_api_password']) && '' !== $temp_options['api']['wetu_api_password']) {
228 228
 					$this->api_password = $temp_options['api']['wetu_api_password'];
229 229
 				}
230
-			}else{
230
+			} else{
231 231
 				$this->api_key = WETU_API_KEY;
232 232
             }
233 233
 
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
 					<?php } ?>
412 412
                 </ul>
413 413
 				<?php*/
414
-			}else{
414
+			} else{
415 415
 			   $this->current_importer->display_page();
416 416
             }; ?>
417 417
         </div>
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
 
448 448
                 <?php if('tour'===$this->tab_slug){ ?>
449 449
                     | <a class="import search-toggle"  href="#import"><?php esc_attr_e('WETU','wetu-importer'); ?></a>
450
-                <?php }else if(!empty($this->queued_imports)) { ?>
450
+                <?php } else if(!empty($this->queued_imports)) { ?>
451 451
                     | <a class="import search-toggle"  href="#import"><?php esc_attr_e('WETU Queue','wetu-importer'); ?></a>
452 452
                 <?php } ?>
453 453
             </p>
@@ -537,7 +537,7 @@  discard block
 block discarded – undo
537 537
 					foreach($team_members->posts as $member){ ?>
538 538
                         <li><input class="team" <?php $this->checked($selected,$member); ?> type="checkbox" value="<?php echo $member; ?>" /> <?php echo get_the_title($member); ?></li>
539 539
 					<?php }
540
-				}else{ ?>
540
+				} else{ ?>
541 541
                     <li><input class="team" type="checkbox" value="0" /> <?php _e('None','wetu-importer'); ?></li>
542 542
 				<?php }
543 543
 				?>
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
 			if (in_array($needle, $haystack)) {
603 603
 				if(true === $wrap || 'true' === $wrap) {
604 604
 					$html = $type . '="' . $type . '"';
605
-				}else{
605
+				} else{
606 606
 					$html = $type;
607 607
 				}
608 608
 			}
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
 
655 655
 			if(false !== $id && '0' !== $id && false !== $prev && true === $unique){
656 656
 				update_post_meta($id,$meta_key,$value,$prev);
657
-			}else{
657
+			} else{
658 658
 				add_post_meta($id,$meta_key,$value,$unique);
659 659
 			}
660 660
 		}
@@ -695,18 +695,15 @@  discard block
 block discarded – undo
695 695
 						if ( is_wp_error($term) )
696 696
 						{
697 697
 							echo $term->get_error_message();
698
-						}
699
-						else
698
+						} else
700 699
 						{
701 700
 							wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true);
702 701
 						}
703
-					}
704
-					else
702
+					} else
705 703
 					{
706 704
 						wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true);
707 705
 					}
708
-				}
709
-				else
706
+				} else
710 707
 				{
711 708
 					$result[]=trim($k);
712 709
 				}
@@ -720,10 +717,8 @@  discard block
 block discarded – undo
720 717
 		{
721 718
 			if(false !== $parent){ $parent = array('parent'=>$parent); }
722 719
 			$term = wp_insert_term(trim($name), $taxonomy,$parent);
723
-			if ( is_wp_error($term) ){echo $term->get_error_message();}
724
-			else { wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); }
725
-		}
726
-		else
720
+			if ( is_wp_error($term) ){echo $term->get_error_message();} else { wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); }
721
+		} else
727 722
 		{
728 723
 			wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true);
729 724
 		}
@@ -743,7 +738,7 @@  discard block
 block discarded – undo
743 738
 				foreach($terms as $term){
744 739
 					$return .= '<li><input class="'.$taxonomy.'" '.$this->checked($selected,$term->term_id,false).' type="checkbox" value="'.$term->term_id.'" /> '.$term->name.'</li>';
745 740
 				}
746
-			}else{
741
+			} else{
747 742
 				$return .= '<li><input type="checkbox" value="" /> '.__('None','wetu-importer').'</li>';
748 743
 			}
749 744
 			$return .= '</ul>';
@@ -762,13 +757,13 @@  discard block
 block discarded – undo
762 757
 
763 758
 			if(isset($data[0]['position']['driving_latitude'])){
764 759
 				$latitude = $data[0]['position']['driving_latitude'];
765
-			}elseif(isset($data[0]['position']['latitude'])){
760
+			} elseif(isset($data[0]['position']['latitude'])){
766 761
 				$latitude = $data[0]['position']['latitude'];
767 762
 			}
768 763
 
769 764
 			if(isset($data[0]['position']['driving_longitude'])){
770 765
 				$longitude = $data[0]['position']['driving_longitude'];
771
-			}elseif(isset($data[0]['position']['longitude'])){
766
+			} elseif(isset($data[0]['position']['longitude'])){
772 767
 				$longitude = $data[0]['position']['longitude'];
773 768
 			}
774 769
 
@@ -800,7 +795,7 @@  discard block
 block discarded – undo
800 795
 			if(false !== $id && '0' !== $id){
801 796
 				$prev = get_post_meta($id,'location',true);
802 797
 				update_post_meta($id,'location',$location_data,$prev);
803
-			}else{
798
+			} else{
804 799
 				add_post_meta($id,'location',$location_data,true);
805 800
 			}
806 801
 		}
@@ -816,7 +811,7 @@  discard block
 block discarded – undo
816 811
 		    if('tour' === $this->tab_slug){
817 812
 		        $key = array_rand($data[0]['content']['images']);
818 813
                 $this->featured_image = $this->attach_image($data[0]['content']['images'][$key],$id);
819
-            }else{
814
+            } else{
820 815
 				$this->featured_image = $this->attach_image($data[0]['content']['images'][0],$id);
821 816
             }
822 817
 
@@ -1015,8 +1010,7 @@  discard block
 block discarded – undo
1015 1010
 		if ( !empty( $filename) && " " != $filename )
1016 1011
 		{
1017 1012
 			$file_array['name'] = $filename . "." . $url_type['ext'];                           // user given filename for title, add original URL extension
1018
-		}
1019
-		else
1013
+		} else
1020 1014
 		{
1021 1015
 			$file_array['name'] = $url_filename;                                                // just use original URL filename
1022 1016
 		}
@@ -1097,7 +1091,7 @@  discard block
 block discarded – undo
1097 1091
 		}
1098 1092
 		if(false !== $found && $needle_count === count($found)){
1099 1093
 			return true;
1100
-		}else{
1094
+		} else{
1101 1095
 			return false;
1102 1096
 		}
1103 1097
 	}
Please login to merge, or discard this patch.