Completed
Push — master ( a3fb73...557ceb )
by Warwick
02:41
created
classes/class-connect-accommodation.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@
 block discarded – undo
51 51
 	 */
52 52
 	public function display_page() {
53 53
 		global $post;
54
-        ?>
54
+		?>
55 55
         <div class="wrap">
56 56
 
57 57
             <h3><span class="dashicons dashicons-admin-multisite"></span> <?php _e('Connect your Accommodation','wetu-importer'); ?></h3>
Please login to merge, or discard this patch.
classes/lsx-banners-integration.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	 * Display the importer administration screen
38 38
 	 */
39 39
 	public function display_page() {
40
-        ?>
40
+		?>
41 41
         <div class="wrap">
42 42
 			
43 43
             <h2><?php _e('Download new banners straight from WETU','wetu-importer'); ?></h2>
@@ -211,14 +211,14 @@  discard block
 block discarded – undo
211 211
 		$base = rawurlencode($base);
212 212
 	  $type = get_post_mime_type($post_id);
213 213
 	  switch ($type) {
214
-	    case 'image/jpeg':
215
-	    	return $base . ".jpg"; break;
216
-	    case 'image/png':
217
-	    	return $base . ".png"; break;
218
-	    case 'image/gif':
219
-	      	return $base . ".gif"; break;
220
-	    default:
221
-	      return false;
214
+		case 'image/jpeg':
215
+			return $base . ".jpg"; break;
216
+		case 'image/png':
217
+			return $base . ".png"; break;
218
+		case 'image/gif':
219
+		  	return $base . ".gif"; break;
220
+		default:
221
+		  return false;
222 222
 	  }
223 223
 	}	
224 224
 
Please login to merge, or discard this patch.
classes/class-importer.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -188,11 +188,11 @@  discard block
 block discarded – undo
188 188
 		$temp_options = get_option('_lsx-to_settings',false);
189 189
 
190 190
 		if(isset($_GET['tab']) || isset($_POST['type'])) {
191
-		    if(isset($_GET['tab'])) {
191
+			if(isset($_GET['tab'])) {
192 192
 				$this->tab_slug = $_GET['tab'];
193 193
 			}else{
194 194
 				$this->tab_slug = $_POST['type'];
195
-            }
195
+			}
196 196
 		}
197 197
 
198 198
 		if(isset($temp_options[$this->plugin_slug])) {
@@ -301,10 +301,10 @@  discard block
 block discarded – undo
301 301
 
302 302
 	// DISPLAY FUNCTIONS
303 303
 
304
-    /*
304
+	/*
305 305
      * Load the importer class you want to use
306 306
      */
307
-    public function load_class(){
307
+	public function load_class(){
308 308
 
309 309
 		switch($this->tab_slug){
310 310
 			case 'accommodation':
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
 				break;
325 325
 		}
326 326
 
327
-    }
327
+	}
328 328
 
329 329
 	/**
330 330
 	 * Registers the admin page which will house the importer form.
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
 				<?php
381 381
 			}else{
382 382
 			   $this->current_importer->display_page();
383
-            }; ?>
383
+			}; ?>
384 384
         </div>
385 385
 		<?php
386 386
 	}
@@ -998,7 +998,7 @@  discard block
 block discarded – undo
998 998
 	 * Run through the accommodation grabbed from the DB.
999 999
 	 */
1000 1000
 	public function process_ajax_search() {
1001
-	    $this->current_importer->process_ajax_search();
1001
+		$this->current_importer->process_ajax_search();
1002 1002
 	}
1003 1003
 
1004 1004
 	/**
Please login to merge, or discard this patch.
classes/class-accommodation.php 1 patch
Indentation   +207 added lines, -207 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 	 */
71 71
 	public function set_variables()
72 72
 	{
73
-	    parent::set_variables();
73
+		parent::set_variables();
74 74
 		// ** This request only works with API KEY **
75 75
 		//if ( false !== $this->api_username && false !== $this->api_password ) {
76 76
 		//	$this->url    = 'https://wetu.com/API/Pins/';
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 	 * Display the importer administration screen
96 96
 	 */
97 97
 	public function display_page() {
98
-        ?>
98
+		?>
99 99
         <div class="wrap">
100 100
             <?php $this->navigation('accommodation'); ?>
101 101
 
@@ -236,8 +236,8 @@  discard block
 block discarded – undo
236 236
 		$accommodation = json_decode($data, true);
237 237
 
238 238
 		if(isset($accommodation['error'])){
239
-		    return $accommodation['error'];
240
-        }elseif (isset($accommodation) && !empty($accommodation)) {
239
+			return $accommodation['error'];
240
+		}elseif (isset($accommodation) && !empty($accommodation)) {
241 241
 			set_transient('lsx_ti_accommodation',$accommodation,60*60*2);
242 242
 			return true;
243 243
 		}
@@ -253,8 +253,8 @@  discard block
 block discarded – undo
253 253
 			$accommodation = get_transient('lsx_ti_accommodation');
254 254
 
255 255
 			if(false === $accommodation){
256
-			    $this->update_options();
257
-            }
256
+				$this->update_options();
257
+			}
258 258
 
259 259
 			if ( false !== $accommodation ) {
260 260
 				$searched_items = false;
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
 					$keyphrases = $_POST['keyword'];
264 264
 				}else{
265 265
 					$keyphrases = array(0);
266
-                }
266
+				}
267 267
 
268 268
 				if(!is_array($keyphrases)){
269 269
 					$keyphrases = array($keyphrases);
@@ -420,17 +420,17 @@  discard block
 block discarded – undo
420 420
 				$content = false;
421 421
 			}
422 422
 
423
-            $jdata = file_get_contents( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id );
424
-            if($jdata)
425
-            {
426
-                $adata=json_decode($jdata,true);
427
-                if(!empty($adata))
428
-                {
429
-                	$return = $this->import_row($adata,$wetu_id,$post_id,$team_members,$content,$safari_brands);
430
-                	$this->format_completed_row($return);
423
+			$jdata = file_get_contents( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id );
424
+			if($jdata)
425
+			{
426
+				$adata=json_decode($jdata,true);
427
+				if(!empty($adata))
428
+				{
429
+					$return = $this->import_row($adata,$wetu_id,$post_id,$team_members,$content,$safari_brands);
430
+					$this->format_completed_row($return);
431 431
 					$this->cleanup_posts();
432
-                }
433
-            }
432
+				}
433
+			}
434 434
 		}
435 435
 	}
436 436
 
@@ -439,147 +439,147 @@  discard block
 block discarded – undo
439 439
 	 */
440 440
 	public function import_row($data,$wetu_id,$id=0,$team_members=false,$importable_content=false,$safari_brands=false) {
441 441
 
442
-        if(trim($data[0]['type'])=='Accommodation')
443
-        {
444
-	        $post_name = $data_post_content = $data_post_excerpt = '';
445
-	        $post = array(
446
-	          'post_type'		=> 'accommodation',
447
-	        );
448
-
449
-	        $content_used_general_description = false;
450
-
451
-	        //Set the post_content
452
-	        if(false !== $importable_content && in_array('description',$importable_content)){
453
-		        if(isset($data[0]['content']['extended_description']))
454
-		        {
455
-		            $data_post_content = $data[0]['content']['extended_description'];
456
-		        }elseif(isset($data[0]['content']['general_description'])){
457
-		            $data_post_content = $data[0]['content']['general_description'];
458
-		            $content_used_general_description = true;
459
-		        }elseif(isset($data[0]['content']['teaser_description'])){
460
-		        	$data_post_content = $data[0]['content']['teaser_description'];
461
-		        }
462
-	        	$post['post_content'] = wp_strip_all_tags($data_post_content);
463
-	        }
464
-
465
-	        //set the post_excerpt
466
-	        if(false !== $importable_content && in_array('excerpt',$importable_content)){
467
-		        if(isset($data[0]['content']['teaser_description'])){
468
-		        	$data_post_excerpt = $data[0]['content']['teaser_description'];
469
-		        }elseif(isset($data[0]['content']['general_description']) && false === $content_used_general_description){
470
-		            $data_post_excerpt = $data[0]['content']['general_description'];
471
-		        }	   
472
-		        $post['post_excerpt'] = $data_post_excerpt;     	
473
-	        }
474
-
475
-	        if(false !== $id && '0' !== $id){
476
-	        	$post['ID'] = $id;
442
+		if(trim($data[0]['type'])=='Accommodation')
443
+		{
444
+			$post_name = $data_post_content = $data_post_excerpt = '';
445
+			$post = array(
446
+			  'post_type'		=> 'accommodation',
447
+			);
448
+
449
+			$content_used_general_description = false;
450
+
451
+			//Set the post_content
452
+			if(false !== $importable_content && in_array('description',$importable_content)){
453
+				if(isset($data[0]['content']['extended_description']))
454
+				{
455
+					$data_post_content = $data[0]['content']['extended_description'];
456
+				}elseif(isset($data[0]['content']['general_description'])){
457
+					$data_post_content = $data[0]['content']['general_description'];
458
+					$content_used_general_description = true;
459
+				}elseif(isset($data[0]['content']['teaser_description'])){
460
+					$data_post_content = $data[0]['content']['teaser_description'];
461
+				}
462
+				$post['post_content'] = wp_strip_all_tags($data_post_content);
463
+			}
464
+
465
+			//set the post_excerpt
466
+			if(false !== $importable_content && in_array('excerpt',$importable_content)){
467
+				if(isset($data[0]['content']['teaser_description'])){
468
+					$data_post_excerpt = $data[0]['content']['teaser_description'];
469
+				}elseif(isset($data[0]['content']['general_description']) && false === $content_used_general_description){
470
+					$data_post_excerpt = $data[0]['content']['general_description'];
471
+				}	   
472
+				$post['post_excerpt'] = $data_post_excerpt;     	
473
+			}
474
+
475
+			if(false !== $id && '0' !== $id){
476
+				$post['ID'] = $id;
477 477
 				if(isset($data[0]['name'])){
478 478
 					$post['post_title'] = $data[0]['name'];
479
-	        		$post['post_status'] = 'publish';
479
+					$post['post_status'] = 'publish';
480 480
 					$post['post_name'] = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'accommodation', 0);
481 481
 				}
482
-	        	$id = wp_update_post($post);
483
-	        	$prev_date = get_post_meta($id,'lsx_wetu_modified_date',true);
484
-	        	update_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified']),$prev_date);
485
-	        }else{
486
-
487
-		        //Set the name
488
-		        if(isset($data[0]['name'])){
489
-		            $post_name = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'accommodation', 0);
490
-		        }
491
-	        	$post['post_name'] = $post_name;
492
-	        	$post['post_title'] = $data[0]['name'];
493
-	        	$post['post_status'] = 'publish';
494
-	        	$id = wp_insert_post($post);
495
-
496
-	        	//Save the WETU ID and the Last date it was modified.
497
-	        	if(false !== $id){
498
-	        		add_post_meta($id,'lsx_wetu_id',$wetu_id);
499
-	        		add_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified']));
500
-	        	}
501
-	        }
502
-	        //Setup some default for use in the import
503
-	        if(false !== $importable_content && (in_array('gallery',$importable_content) || in_array('banner_image',$importable_content) || in_array('featured_image',$importable_content))){
482
+				$id = wp_update_post($post);
483
+				$prev_date = get_post_meta($id,'lsx_wetu_modified_date',true);
484
+				update_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified']),$prev_date);
485
+			}else{
486
+
487
+				//Set the name
488
+				if(isset($data[0]['name'])){
489
+					$post_name = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'accommodation', 0);
490
+				}
491
+				$post['post_name'] = $post_name;
492
+				$post['post_title'] = $data[0]['name'];
493
+				$post['post_status'] = 'publish';
494
+				$id = wp_insert_post($post);
495
+
496
+				//Save the WETU ID and the Last date it was modified.
497
+				if(false !== $id){
498
+					add_post_meta($id,'lsx_wetu_id',$wetu_id);
499
+					add_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified']));
500
+				}
501
+			}
502
+			//Setup some default for use in the import
503
+			if(false !== $importable_content && (in_array('gallery',$importable_content) || in_array('banner_image',$importable_content) || in_array('featured_image',$importable_content))){
504 504
 				$this->find_attachments($id);
505 505
 			}
506 506
 
507
-	        //Set the team member if it is there
508
-	        if(post_type_exists('team') && false !== $team_members && '' !== $team_members){
509
-	        	$this->set_team_member($id,$team_members);
510
-	    	}
511
-
512
-	        //Set the safari brand
513
-	        if(false !== $safari_brands && '' !== $safari_brands){
514
-	        	$this->set_safari_brands($id,$safari_brands);
515
-
516
-	    	}	    	
517
-
518
-	        if(class_exists('LSX_TO_Maps')){
519
-	        	$this->set_map_data($data,$id,9);
520
-	        }
521
-
522
-	        if(post_type_exists('destination') && false !== $importable_content && in_array('destination',$importable_content)){
523
-	        	$this->connect_destinations($data,$id);
524
-	        }
525
-
526
-	        if(false !== $importable_content && in_array('category',$importable_content)){
527
-	        	$this->set_taxonomy_style($data,$id);
528
-	        }
529
-
530
-	        //Set the Room Data
531
-	        if(false !== $importable_content && in_array('rooms',$importable_content)){
532
-	        	$this->set_room_data($data,$id);
533
-	    	}
534
-
535
-	    	//Set the rating
536
-	    	if(false !== $importable_content && in_array('rating',$importable_content)){
537
-	       		$this->set_rating($data,$id);
538
-	    	}
539
-
540
-	    	//Set the checkin checkout data
541
-	    	if(false !== $importable_content && in_array('checkin',$importable_content)){
542
-	        	$this->set_checkin_checkout($data,$id);
543
-	        }
544
-
545
-	    	//Set the Spoken Languages
546
-	    	if(false !== $importable_content && in_array('spoken_languages',$importable_content)){
547
-	       		$this->set_spoken_languages($data,$id);
548
-	    	}
549
-
550
-	    	//Set the friendly options
551
-	    	if(false !== $importable_content && in_array('friendly',$importable_content)){
552
-	       		$this->set_friendly($data,$id);
553
-	    	}
554
-
555
-	    	//Set the special_interests
556
-	    	if(false !== $importable_content && in_array('special_interests',$importable_content)){
557
-	       		$this->set_special_interests($data,$id);
558
-	    	}	    		    		        
559
-
560
-	        //Import the videos
561
-	        if(false !== $importable_content && in_array('videos',$importable_content)){
562
-	        	$this->set_video_data($data,$id);
563
-	        }
564
-
565
-	        //Import the facilities
566
-	        if(false !== $importable_content && in_array('facilities',$importable_content)){
567
-	        	$this->set_facilities($data,$id);
568
-	        }	        
569
-
570
-	        //Set the featured image
571
-	        if(false !== $importable_content && in_array('featured_image',$importable_content)){
572
-	        	$this->set_featured_image($data,$id);
573
-	        }
574
-	        if(false !== $importable_content && in_array('banner_image',$importable_content)){
575
-	        	$this->set_banner_image($data,$id);
576
-	        }	        
577
-	        //Import the main gallery
578
-	        if(false !== $importable_content && in_array('gallery',$importable_content)){	    	
579
-	    		$this->create_main_gallery($data,$id);
580
-	        }	        	        	        
581
-        }
582
-        return $id;
507
+			//Set the team member if it is there
508
+			if(post_type_exists('team') && false !== $team_members && '' !== $team_members){
509
+				$this->set_team_member($id,$team_members);
510
+			}
511
+
512
+			//Set the safari brand
513
+			if(false !== $safari_brands && '' !== $safari_brands){
514
+				$this->set_safari_brands($id,$safari_brands);
515
+
516
+			}	    	
517
+
518
+			if(class_exists('LSX_TO_Maps')){
519
+				$this->set_map_data($data,$id,9);
520
+			}
521
+
522
+			if(post_type_exists('destination') && false !== $importable_content && in_array('destination',$importable_content)){
523
+				$this->connect_destinations($data,$id);
524
+			}
525
+
526
+			if(false !== $importable_content && in_array('category',$importable_content)){
527
+				$this->set_taxonomy_style($data,$id);
528
+			}
529
+
530
+			//Set the Room Data
531
+			if(false !== $importable_content && in_array('rooms',$importable_content)){
532
+				$this->set_room_data($data,$id);
533
+			}
534
+
535
+			//Set the rating
536
+			if(false !== $importable_content && in_array('rating',$importable_content)){
537
+		   		$this->set_rating($data,$id);
538
+			}
539
+
540
+			//Set the checkin checkout data
541
+			if(false !== $importable_content && in_array('checkin',$importable_content)){
542
+				$this->set_checkin_checkout($data,$id);
543
+			}
544
+
545
+			//Set the Spoken Languages
546
+			if(false !== $importable_content && in_array('spoken_languages',$importable_content)){
547
+		   		$this->set_spoken_languages($data,$id);
548
+			}
549
+
550
+			//Set the friendly options
551
+			if(false !== $importable_content && in_array('friendly',$importable_content)){
552
+		   		$this->set_friendly($data,$id);
553
+			}
554
+
555
+			//Set the special_interests
556
+			if(false !== $importable_content && in_array('special_interests',$importable_content)){
557
+		   		$this->set_special_interests($data,$id);
558
+			}	    		    		        
559
+
560
+			//Import the videos
561
+			if(false !== $importable_content && in_array('videos',$importable_content)){
562
+				$this->set_video_data($data,$id);
563
+			}
564
+
565
+			//Import the facilities
566
+			if(false !== $importable_content && in_array('facilities',$importable_content)){
567
+				$this->set_facilities($data,$id);
568
+			}	        
569
+
570
+			//Set the featured image
571
+			if(false !== $importable_content && in_array('featured_image',$importable_content)){
572
+				$this->set_featured_image($data,$id);
573
+			}
574
+			if(false !== $importable_content && in_array('banner_image',$importable_content)){
575
+				$this->set_banner_image($data,$id);
576
+			}	        
577
+			//Import the main gallery
578
+			if(false !== $importable_content && in_array('gallery',$importable_content)){	    	
579
+				$this->create_main_gallery($data,$id);
580
+			}	        	        	        
581
+		}
582
+		return $id;
583 583
 	}
584 584
 
585 585
 	/**
@@ -589,7 +589,7 @@  discard block
 block discarded – undo
589 589
 
590 590
 		delete_post_meta($id, 'team_to_'.$this->tab_slug);
591 591
 		foreach($team_members as $team){
592
-        	add_post_meta($id,'team_to_'.$this->tab_slug,$team);			
592
+			add_post_meta($id,'team_to_'.$this->tab_slug,$team);			
593 593
 		}
594 594
 	}
595 595
 
@@ -598,7 +598,7 @@  discard block
 block discarded – undo
598 598
 	 */
599 599
 	public function set_safari_brands($id,$safari_brands) {
600 600
 		foreach($safari_brands as $safari_brand){
601
-        	wp_set_object_terms( $id, intval($safari_brand), 'accommodation-brand',true);			
601
+			wp_set_object_terms( $id, intval($safari_brand), 'accommodation-brand',true);			
602 602
 		}
603 603
 	}
604 604
 
@@ -607,32 +607,32 @@  discard block
 block discarded – undo
607 607
 	 */
608 608
 	public function connect_destinations($data,$id) {
609 609
 		if(isset($data[0]['position'])){
610
-		    $destinations = false;
611
-		    if(isset($data[0]['position']['country'])){
612
-		    	$destinations['country'] = $data[0]['position']['country'];
613
-		    }
614
-		    if(isset($data[0]['position']['destination'])){
615
-		    	$destinations['destination'] = $data[0]['position']['destination'];
616
-		    }
610
+			$destinations = false;
611
+			if(isset($data[0]['position']['country'])){
612
+				$destinations['country'] = $data[0]['position']['country'];
613
+			}
614
+			if(isset($data[0]['position']['destination'])){
615
+				$destinations['destination'] = $data[0]['position']['destination'];
616
+			}
617 617
 		    
618
-		    if(false !== $destinations){	
619
-		    	$prev_values = get_post_meta($id,'destination_to_accommodation',false);
620
-		    	if(false === $prev_values || !is_array($prev_values)){
621
-		    		$prev_values = array();
622
-		    	}
623
-		    	//print_r($destinations);
618
+			if(false !== $destinations){	
619
+				$prev_values = get_post_meta($id,'destination_to_accommodation',false);
620
+				if(false === $prev_values || !is_array($prev_values)){
621
+					$prev_values = array();
622
+				}
623
+				//print_r($destinations);
624 624
 				$destinations = array_unique($destinations);
625 625
 				//print_r($destinations);
626
-			    foreach($destinations as $key => $value){
627
-				    $destination = get_page_by_title(ltrim(rtrim($value)), 'OBJECT', 'destination');
628
-	                if (null !== $destination) {
629
-	                	if(!in_array($destination->ID,$prev_values)){
630
-	                   		add_post_meta($id,'destination_to_accommodation',$destination->ID,false);
631
-	                   		add_post_meta($destination->ID,'accommodation_to_destination',$id,false);
626
+				foreach($destinations as $key => $value){
627
+					$destination = get_page_by_title(ltrim(rtrim($value)), 'OBJECT', 'destination');
628
+					if (null !== $destination) {
629
+						if(!in_array($destination->ID,$prev_values)){
630
+					   		add_post_meta($id,'destination_to_accommodation',$destination->ID,false);
631
+					   		add_post_meta($destination->ID,'accommodation_to_destination',$id,false);
632 632
 							$this->cleanup_posts[$destination->ID] = 'accommodation_to_destination';
633
-	                	}
634
-	                } 		    	
635
-			    }	
633
+						}
634
+					} 		    	
635
+				}	
636 636
 			}
637 637
 		}
638 638
 	}	
@@ -644,15 +644,15 @@  discard block
 block discarded – undo
644 644
 		$terms = false;
645 645
 		if(isset($data[0]['category'])){
646 646
 			if(!$term = term_exists(trim($data[0]['category']), 'accommodation-type'))
647
-	        {
648
-	            $term = wp_insert_term(trim($data[0]['category']), 'accommodation-type');
649
-	            if ( is_wp_error($term) ){echo $term->get_error_message();}
650
-	            else { wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); }
651
-	        }
652
-	        else
653
-	        {
654
-	            wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true);
655
-	        }				
647
+			{
648
+				$term = wp_insert_term(trim($data[0]['category']), 'accommodation-type');
649
+				if ( is_wp_error($term) ){echo $term->get_error_message();}
650
+				else { wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); }
651
+			}
652
+			else
653
+			{
654
+				wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true);
655
+			}				
656 656
 		}
657 657
 	}		
658 658
 
@@ -676,25 +676,25 @@  discard block
 block discarded – undo
676 676
 				$temp_room['type'] = 'room';
677 677
 
678 678
 				if(!empty($room['images']) && is_array($room['images'])){
679
-			    	$attachments_args = array(
680
-			    			'post_parent' => $id,
681
-			    			'post_status' => 'inherit',
682
-			    			'post_type' => 'attachment',
683
-			    			'order' => 'ASC',
684
-			    	);   	
685
-			    	$attachments = new WP_Query($attachments_args);
686
-			    	$found_attachments = array();
687
-
688
-			    	if($attachments->have_posts()){
689
-			    		foreach($attachments->posts as $attachment){
690
-			    			$found_attachments[] = str_replace(array('.jpg','.png','.jpeg'),'',$attachment->post_title);
691
-			    		}
692
-			    	}
679
+					$attachments_args = array(
680
+							'post_parent' => $id,
681
+							'post_status' => 'inherit',
682
+							'post_type' => 'attachment',
683
+							'order' => 'ASC',
684
+					);   	
685
+					$attachments = new WP_Query($attachments_args);
686
+					$found_attachments = array();
687
+
688
+					if($attachments->have_posts()){
689
+						foreach($attachments->posts as $attachment){
690
+							$found_attachments[] = str_replace(array('.jpg','.png','.jpeg'),'',$attachment->post_title);
691
+						}
692
+					}
693 693
 
694 694
 					$temp_room['gallery'] = array();
695 695
 					foreach($room['images'] as $image_data){
696
-			    		$temp_room['gallery'][] = $this->attach_image($image_data,$id,$found_attachments);
697
-			    	}
696
+						$temp_room['gallery'][] = $this->attach_image($image_data,$id,$found_attachments);
697
+					}
698 698
 				}
699 699
 				$rooms[] = $temp_room;
700 700
 			}
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
 				delete_post_meta($id, 'units');				
704 704
 			}
705 705
 			foreach($rooms as $room){
706
-		        add_post_meta($id,'units',$room,false);			
706
+				add_post_meta($id,'units',$room,false);			
707 707
 			}
708 708
 
709 709
 			if(isset($data[0]['features']) && isset($data[0]['features']['rooms'])){
@@ -713,11 +713,11 @@  discard block
 block discarded – undo
713 713
 			}
714 714
 
715 715
 			if(false !== $id && '0' !== $id){
716
-	        	$prev_rooms = get_post_meta($id,'number_of_rooms',true);
717
-	        	update_post_meta($id,'number_of_rooms',$room_count,$prev_rooms);
718
-	        }else{
719
-	        	add_post_meta($id,'number_of_rooms',$room_count,true);
720
-	        }
716
+				$prev_rooms = get_post_meta($id,'number_of_rooms',true);
717
+				update_post_meta($id,'number_of_rooms',$room_count,$prev_rooms);
718
+			}else{
719
+				add_post_meta($id,'number_of_rooms',$room_count,true);
720
+			}
721 721
 		}
722 722
 	}
723 723
 
@@ -827,7 +827,7 @@  discard block
 block discarded – undo
827 827
 				delete_post_meta($id, 'videos');				
828 828
 			}
829 829
 			foreach($videos as $video){
830
-		        add_post_meta($id,'videos',$video,false);			
830
+				add_post_meta($id,'videos',$video,false);			
831 831
 			}
832 832
 		}
833 833
 	}	
Please login to merge, or discard this patch.
classes/class-tours.php 1 patch
Indentation   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 	 */
99 99
 	public function set_variables()
100 100
 	{
101
-	    parent::set_variables();
101
+		parent::set_variables();
102 102
 
103 103
 		if ( false !== $this->api_username && false !== $this->api_password ) {
104 104
 			$this->url    = 'https://wetu.com/API/Itinerary/';
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 	 * Display the importer administration screen
124 124
 	 */
125 125
 	public function display_page() {
126
-        ?>
126
+		?>
127 127
         <div class="wrap">
128 128
 			<?php $this->navigation('tour'); ?>
129 129
 
@@ -247,15 +247,15 @@  discard block
 block discarded – undo
247 247
 	/**
248 248
 	 * displays the options for the tours
249 249
 	 */
250
-    public function tour_search_options() {
251
-        ?>
250
+	public function tour_search_options() {
251
+		?>
252 252
             <p class="tour-search-options">
253 253
                 <label for="type"><input class="content" checked type="radio" name="type[]" value="all" /> <?php _e('All','wetu-importer'); ?></label>
254 254
                 <label for="type"><input class="content" type="radio" name="type[]" value="sample" /> <?php _e('Sample','wetu-importer'); ?></label>
255 255
                 <label for="type"><input class="content" type="radio" name="type[]" value="personal" /> <?php _e('Personal','wetu-importer'); ?></label>
256 256
             </p>
257 257
         <?php
258
-    }
258
+	}
259 259
 
260 260
 	/**
261 261
 	 * search_form
@@ -267,16 +267,16 @@  discard block
 block discarded – undo
267 267
 			$result = $this->update_options();
268 268
 
269 269
 			if(true === $result){
270
-			    echo '<span style="color:green;">'.esc_attr('Connected','wetu-importer').'</span>';
271
-			    if(!isset($_GET['refresh_tours'])){
272
-			        echo ' - <small><a href="'.admin_url('admin.php').'?page='.$this->plugin_slug.'&tab=tour&refresh_tours=true">'.esc_attr('Refresh','wetu-importer').'</a></small>';
273
-                }
274
-            }else{
275
-			    echo '<span style="color:red;">'.wp_kses_post($result).'</span>';
276
-            }
270
+				echo '<span style="color:green;">'.esc_attr('Connected','wetu-importer').'</span>';
271
+				if(!isset($_GET['refresh_tours'])){
272
+					echo ' - <small><a href="'.admin_url('admin.php').'?page='.$this->plugin_slug.'&tab=tour&refresh_tours=true">'.esc_attr('Refresh','wetu-importer').'</a></small>';
273
+				}
274
+			}else{
275
+				echo '<span style="color:red;">'.wp_kses_post($result).'</span>';
276
+			}
277 277
 		}else{
278 278
 			echo '<span style="color:green;">'.esc_attr('Connected','wetu-importer').'</span> - <small><a href="'.admin_url('admin.php').'?page='.$this->plugin_slug.'&tab=tour&refresh_tours=true">'.esc_attr('Refresh','wetu-importer').'</a></small>';
279
-        }
279
+		}
280 280
 		echo '</h3></div>';
281 281
 	}
282 282
 
@@ -288,8 +288,8 @@  discard block
 block discarded – undo
288 288
 		$tours = json_decode($data, true);
289 289
 
290 290
 		if(isset($tours['error'])){
291
-		    return $tours['error'];
292
-        }elseif (isset($tours['itineraries']) && !empty($tours['itineraries'])) {
291
+			return $tours['error'];
292
+		}elseif (isset($tours['itineraries']) && !empty($tours['itineraries'])) {
293 293
 			set_transient('lsx_ti_tours',$tours['itineraries'],60*60*2);
294 294
 			return true;
295 295
 		}
@@ -492,71 +492,71 @@  discard block
 block discarded – undo
492 492
 				$content = false;
493 493
 			}
494 494
 
495
-            $jdata=file_get_contents("http://wetu.com/API/Itinerary/V7/Get?id=".$wetu_id);
495
+			$jdata=file_get_contents("http://wetu.com/API/Itinerary/V7/Get?id=".$wetu_id);
496 496
 
497
-            if($jdata)
498
-            {
497
+			if($jdata)
498
+			{
499 499
 				$jdata=json_decode($jdata,true);
500
-                if(!empty($jdata))
501
-                {
502
-                	$return = $this->import_row($jdata,$wetu_id,$post_id,$content);
503
-                	$this->format_completed_row($return);
504
-                	$this->cleanup_posts();
505
-                	$this->attach_destination_images($content);
506
-                }
507
-            }
500
+				if(!empty($jdata))
501
+				{
502
+					$return = $this->import_row($jdata,$wetu_id,$post_id,$content);
503
+					$this->format_completed_row($return);
504
+					$this->cleanup_posts();
505
+					$this->attach_destination_images($content);
506
+				}
507
+			}
508 508
 		}
509 509
 	}
510 510
 
511 511
 	/**
512 512
 	 * Connect to wetu
513
-     *
514
-     * @param $data array
515
-     * @param $wetu_id string
513
+	 *
514
+	 * @param $data array
515
+	 * @param $wetu_id string
516 516
 	 */
517 517
 	public function import_row($data,$wetu_id,$id=0,$importable_content=false,$old1=false,$old2=false) {
518
-        $post_name = $data_post_content = $data_post_excerpt = '';
519
-        $post = array(
520
-          'post_type'		=> 'tour',
521
-        );
518
+		$post_name = $data_post_content = $data_post_excerpt = '';
519
+		$post = array(
520
+		  'post_type'		=> 'tour',
521
+		);
522 522
 
523
-        //Set the post_content
523
+		//Set the post_content
524 524
 		$content_used_general_description = false;
525
-        if(false !== $importable_content && in_array('description',$importable_content)){
526
-            $data_post_content = '';
527
-
528
-            if(isset($data['description'])){
529
-                $data_post_content = $data['description'];
530
-            }elseif(isset($data['summary'])){
531
-                $data_post_content = $data['summary'];
532
-            }
533
-            $post['post_content'] = $data_post_content;
534
-        }
535
-
536
-        //Create or update the post
537
-        if(false !== $id && '0' !== $id){
538
-            $post['ID'] = $id;
539
-	        $post['post_status'] = 'publish';
540
-            $id = wp_update_post($post);
541
-            $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true);
542
-            update_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified']),$prev_date);
543
-        }else{
544
-
545
-            //Set the name
546
-            if(isset($data['name'])){
547
-                $post_name = wp_unique_post_slug(sanitize_title($data['name']),$id, 'draft', 'tour', 0);
548
-            }
549
-            $post['post_name'] = $post_name;
550
-            $post['post_title'] = $data['name'];
551
-            $post['post_status'] = 'publish';
552
-            $id = wp_insert_post($post);
553
-
554
-            //Save the WETU ID and the Last date it was modified.
555
-            if(false !== $id){
556
-                add_post_meta($id,'lsx_wetu_id',$wetu_id);
557
-                add_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified']));
558
-            }
559
-        }
525
+		if(false !== $importable_content && in_array('description',$importable_content)){
526
+			$data_post_content = '';
527
+
528
+			if(isset($data['description'])){
529
+				$data_post_content = $data['description'];
530
+			}elseif(isset($data['summary'])){
531
+				$data_post_content = $data['summary'];
532
+			}
533
+			$post['post_content'] = $data_post_content;
534
+		}
535
+
536
+		//Create or update the post
537
+		if(false !== $id && '0' !== $id){
538
+			$post['ID'] = $id;
539
+			$post['post_status'] = 'publish';
540
+			$id = wp_update_post($post);
541
+			$prev_date = get_post_meta($id,'lsx_wetu_modified_date',true);
542
+			update_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified']),$prev_date);
543
+		}else{
544
+
545
+			//Set the name
546
+			if(isset($data['name'])){
547
+				$post_name = wp_unique_post_slug(sanitize_title($data['name']),$id, 'draft', 'tour', 0);
548
+			}
549
+			$post['post_name'] = $post_name;
550
+			$post['post_title'] = $data['name'];
551
+			$post['post_status'] = 'publish';
552
+			$id = wp_insert_post($post);
553
+
554
+			//Save the WETU ID and the Last date it was modified.
555
+			if(false !== $id){
556
+				add_post_meta($id,'lsx_wetu_id',$wetu_id);
557
+				add_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified']));
558
+			}
559
+		}
560 560
 
561 561
 
562 562
 		//Set the price
@@ -569,15 +569,15 @@  discard block
 block discarded – undo
569 569
 			$this->set_duration($data,$id);
570 570
 		}
571 571
 
572
-        if(false !== $importable_content && in_array('itineraries',$importable_content) && isset($data['legs']) && !empty($data['legs'])){
573
-            $this->process_itineraries($data,$id,$importable_content);
574
-        }
572
+		if(false !== $importable_content && in_array('itineraries',$importable_content) && isset($data['legs']) && !empty($data['legs'])){
573
+			$this->process_itineraries($data,$id,$importable_content);
574
+		}
575 575
 
576 576
 		if(in_array('map',$importable_content) && isset($data['routes']) && !empty($data['routes'])){
577 577
 			$this->set_map_data($data,$id);
578 578
 		}
579 579
 
580
-        return $id;
580
+		return $id;
581 581
 	}
582 582
 
583 583
 	/**
@@ -739,17 +739,17 @@  discard block
 block discarded – undo
739 739
 	 * Set the Itinerary Day
740 740
 	 */
741 741
 	public function set_itinerary_day($day,$id) {
742
-        $this->save_custom_field($day,'itinerary',$id,false,false);
742
+		$this->save_custom_field($day,'itinerary',$id,false,false);
743 743
 	}
744 744
 
745 745
 	/**
746 746
 	 * Set the price
747 747
 	 */
748 748
 	public function set_price($data,$id) {
749
-	    //Price
749
+		//Price
750 750
 		if(isset($data['price']) && ''!== $data['price']){
751
-            $price = preg_replace("/[^0-9,.]/", "", $data['price']);
752
-            $this->save_custom_field($price,'price',$id);
751
+			$price = preg_replace("/[^0-9,.]/", "", $data['price']);
752
+			$this->save_custom_field($price,'price',$id);
753 753
 		}
754 754
 
755 755
 		//Price includes
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
 			$this->save_custom_field($data['price_includes'],'included',$id);
758 758
 		}
759 759
 
760
-        //Price Excludes
760
+		//Price Excludes
761 761
 		if(isset($data['price_excludes']) && ''!== $data['price_excludes']){
762 762
 			$this->save_custom_field($data['price_excludes'],'not_included',$id);
763 763
 		}
@@ -780,35 +780,35 @@  discard block
 block discarded – undo
780 780
 	 */
781 781
 	public function set_accommodation($day,$id) {
782 782
 
783
-	    $ac_id = false;
783
+		$ac_id = false;
784 784
 		$this->current_accommodation = $this->find_current_accommodation();
785 785
 		
786 786
 		if(isset($day['content_entity_id']) && !empty($day['content_entity_id'])){
787 787
 
788 788
 			if(false !== $this->current_accommodation && !empty($this->current_accommodation) && array_key_exists($day['content_entity_id'],$this->current_accommodation)){
789
-                $ac_id = $this->current_accommodation[$day['content_entity_id']];
789
+				$ac_id = $this->current_accommodation[$day['content_entity_id']];
790 790
 			}else{
791 791
 				$ac_id = wp_insert_post(array(
792
-                    'post_type' => 'accommodation',
793
-                    'post_status' => 'draft',
794
-                    'post_title' => $day['content_entity_id']
795
-                ));
792
+					'post_type' => 'accommodation',
793
+					'post_status' => 'draft',
794
+					'post_title' => $day['content_entity_id']
795
+				));
796 796
 				$this->save_custom_field($day['content_entity_id'],'lsx_wetu_id',$ac_id);
797 797
 			}
798 798
 
799 799
 			if('' !== $ac_id && false !== $ac_id){
800
-			    $this->save_custom_field($ac_id,'accommodation_to_tour',$id,false,false);
800
+				$this->save_custom_field($ac_id,'accommodation_to_tour',$id,false,false);
801 801
 				$this->save_custom_field($id,'tour_to_accommodation',$ac_id,false,false);
802
-            }
802
+			}
803 803
 		}
804 804
 		return $ac_id;
805 805
 	}
806 806
 
807 807
 	/**
808 808
 	 * Grab all the current accommodation posts via the lsx_wetu_id field.
809
-     *
810
-     * @param $post_type string
811
-     * @return boolean / array
809
+	 *
810
+	 * @param $post_type string
811
+	 * @return boolean / array
812 812
 	 */
813 813
 	public function find_current_accommodation($post_type='accommodation') {
814 814
 		global $wpdb;
@@ -816,16 +816,16 @@  discard block
 block discarded – undo
816 816
 
817 817
 		$return = false;
818 818
 		if(!empty($accommodation)){
819
-		    foreach($accommodation as $key => $acc){
819
+			foreach($accommodation as $key => $acc){
820 820
 				$return[$acc->meta_value] = $acc->post_id;
821
-            }
822
-        }
821
+			}
822
+		}
823 823
 		return $return;
824 824
 	}
825 825
 
826 826
 	/**
827 827
 	 * Grab all the current accommodation posts via the lsx_wetu_id field.
828
-     * @return boolean / array
828
+	 * @return boolean / array
829 829
 	 */
830 830
 	public function find_current_destinations() {
831 831
 		return $this->find_current_accommodation('destination');
@@ -853,7 +853,7 @@  discard block
 block discarded – undo
853 853
 				$country_wetu_id = get_post_meta($potential_id,'lsx_wetu_id',true);
854 854
 				if(false !== $country_wetu_id){
855 855
 					$country_id = $this->set_country($country_wetu_id, $id);
856
-                }
856
+				}
857 857
 
858 858
 			}else {
859 859
 
@@ -864,27 +864,27 @@  discard block
 block discarded – undo
864 864
 
865 865
 					if (!empty($destination_data) && !isset($destination_data['error'])) {
866 866
 
867
-					    $destination_title = $day['destination_content_entity_id'];
867
+						$destination_title = $day['destination_content_entity_id'];
868 868
 
869
-					    if(isset($destination_data[0]['name'])){
869
+						if(isset($destination_data[0]['name'])){
870 870
 							$destination_title = $destination_data[0]['name'];
871
-                        }
871
+						}
872 872
 
873
-					    if(isset($destination_data[0]['map_object_id']) && isset($destination_data[0]['position']['country_content_entity_id'])
874
-                            && $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id']){
873
+						if(isset($destination_data[0]['map_object_id']) && isset($destination_data[0]['position']['country_content_entity_id'])
874
+							&& $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id']){
875 875
 
876 876
 							$country_id = $this->set_country($destination_data[0]['position']['country_content_entity_id'], $id);
877
-                        }
877
+						}
878 878
 
879
-                        $dest_post = array(
879
+						$dest_post = array(
880 880
 							'post_type' => 'destination',
881 881
 							'post_status' => 'draft',
882 882
 							'post_title' => $destination_title
883 883
 						);
884 884
 
885
-					    if(false !== $country_id){
885
+						if(false !== $country_id){
886 886
 							$dest_post['post_parent'] = $country_id;
887
-                        }
887
+						}
888 888
 						$dest_id = wp_insert_post($dest_post);
889 889
 
890 890
 						//Make sure we register the
@@ -902,16 +902,16 @@  discard block
 block discarded – undo
902 902
 
903 903
 				// Save the first destination so we can grab the tour featured image and banner
904 904
 				if(0 === $leg_counter){
905
-				    $this->destination_images[$id] = array($dest_id,$day['destination_content_entity_id']);
906
-                }
905
+					$this->destination_images[$id] = array($dest_id,$day['destination_content_entity_id']);
906
+				}
907 907
 
908 908
 				//Add this relation info so we can make sure certain items are set as countries.
909 909
 				if(0 !== $country_id && false !== $country_id){
910
-                    $this->relation_meta[$dest_id] = $country_id;
910
+					$this->relation_meta[$dest_id] = $country_id;
911 911
 					$this->relation_meta[$country_id] = 0;
912
-                }else{
912
+				}else{
913 913
 					$this->relation_meta[$dest_id] = 0;
914
-                }
914
+				}
915 915
 			}
916 916
 		}
917 917
 		return $dest_id;
@@ -921,53 +921,53 @@  discard block
 block discarded – undo
921 921
 	 * Connects the destinations post type
922 922
 	 *
923 923
 	 * @param $dest_id string
924
-     * @param $country_id array
924
+	 * @param $country_id array
925 925
 	 * @param $id string
926
-     *
927
-     * @return string
926
+	 *
927
+	 * @return string
928 928
 	 */
929 929
 	public function set_country($country_wetu_id, $id) {
930
-	    $country_id = false;
930
+		$country_id = false;
931 931
 		$this->current_destinations = $this->find_current_destinations();
932 932
 
933
-        if (false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($country_wetu_id, $this->current_destinations)) {
934
-            $country_id = $this->current_destinations[$country_wetu_id];
935
-        } else {
933
+		if (false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($country_wetu_id, $this->current_destinations)) {
934
+			$country_id = $this->current_destinations[$country_wetu_id];
935
+		} else {
936 936
 
937
-            $country_json = file_get_contents("http://wetu.com/API/Pins/".$this->api_key."/Get?ids=" . $country_wetu_id);
937
+			$country_json = file_get_contents("http://wetu.com/API/Pins/".$this->api_key."/Get?ids=" . $country_wetu_id);
938 938
 
939
-            if ($country_json) {
940
-                $country_data = json_decode($country_json, true);
939
+			if ($country_json) {
940
+				$country_data = json_decode($country_json, true);
941 941
 
942
-                if (!empty($country_data) && !isset($country_data['error'])) {
942
+				if (!empty($country_data) && !isset($country_data['error'])) {
943 943
 
944 944
 					//Format the title of the destination if its available,  otherwise default to the WETU ID.
945
-                    $country_title = $country_wetu_id;
946
-                    if (isset($country_data[0]['name'])) {
945
+					$country_title = $country_wetu_id;
946
+					if (isset($country_data[0]['name'])) {
947 947
 						$country_title = $country_data[0]['name'];
948
-                    }
948
+					}
949 949
 
950 950
 					$country_id = wp_insert_post(array(
951
-                        'post_type' => 'destination',
952
-                        'post_status' => 'draft',
953
-                        'post_title' => $country_title
954
-                    ));
951
+						'post_type' => 'destination',
952
+						'post_status' => 'draft',
953
+						'post_title' => $country_title
954
+					));
955 955
 					//add the country to the current destination stack
956 956
 					$this->current_destinations[$country_wetu_id] = $country_id;
957 957
 
958 958
 					//Save the wetu field
959
-                    $this->save_custom_field($country_wetu_id, 'lsx_wetu_id', $country_id);
960
-                }
961
-            }
962
-        }
963
-
964
-        if ('' !== $country_id && false !== $country_id) {
965
-            $this->save_custom_field($country_id, 'destination_to_tour', $id, false, false);
966
-            $this->save_custom_field($id, 'tour_to_destination', $country_id, false, false);
959
+					$this->save_custom_field($country_wetu_id, 'lsx_wetu_id', $country_id);
960
+				}
961
+			}
962
+		}
963
+
964
+		if ('' !== $country_id && false !== $country_id) {
965
+			$this->save_custom_field($country_id, 'destination_to_tour', $id, false, false);
966
+			$this->save_custom_field($id, 'tour_to_destination', $country_id, false, false);
967 967
 			$this->cleanup_posts[$country_id] = 'tour_to_destination';
968 968
 
969
-            return $country_id;
970
-        }
969
+			return $country_id;
970
+		}
971 971
 	}
972 972
 
973 973
 	/**
@@ -980,9 +980,9 @@  discard block
 block discarded – undo
980 980
 	 * @return string
981 981
 	 */
982 982
 	public function attach_destination_images($importable_content=array()) {
983
-	    if(false !== $this->destination_images){
983
+		if(false !== $this->destination_images){
984 984
 
985
-	        foreach($this->destination_images as $tour => $destination){
985
+			foreach($this->destination_images as $tour => $destination){
986 986
 
987 987
 				$url = 'https://wetu.com/API/Pins/' . $this->api_key;
988 988
 				$url_qs = '';
@@ -1003,7 +1003,7 @@  discard block
 block discarded – undo
1003 1003
 						}
1004 1004
 					}
1005 1005
 				}
1006
-            }
1007
-        }
1006
+			}
1007
+		}
1008 1008
 	}
1009 1009
 }
1010 1010
\ No newline at end of file
Please login to merge, or discard this patch.