Completed
Push — master ( 29e8a9...4674aa )
by Warwick
02:46
created
classes/class-tours.php 2 patches
Indentation   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 		$tour_options = get_option('wetu_importer_tour_settings',false);
98 98
 		if(false !== $tour_options){
99 99
 			$this->tour_options = $tour_options;
100
-        }
100
+		}
101 101
 	}
102 102
 
103 103
 	/**
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 	 * Display the importer administration screen
121 121
 	 */
122 122
 	public function display_page() {
123
-        ?>
123
+		?>
124 124
         <div class="wrap">
125 125
             <?php screen_icon(); ?>
126 126
 
@@ -248,13 +248,13 @@  discard block
 block discarded – undo
248 248
 			$result = $this->update_options();
249 249
 
250 250
 			if(true === $result){
251
-			    echo '<span style="color:green;">'.esc_attr('Connected','wetu-importer').'</span>';
252
-            }else{
253
-			    echo '<span style="color:red;">'.wp_kses_post($result).'</span>';
254
-            }
251
+				echo '<span style="color:green;">'.esc_attr('Connected','wetu-importer').'</span>';
252
+			}else{
253
+				echo '<span style="color:red;">'.wp_kses_post($result).'</span>';
254
+			}
255 255
 		}else{
256 256
 			echo '<span style="color:green;">'.esc_attr('Connected','wetu-importer').'</span>';
257
-        }
257
+		}
258 258
 		echo '</h3></div>';
259 259
 	}
260 260
 
@@ -266,8 +266,8 @@  discard block
 block discarded – undo
266 266
 		$tours = json_decode($data, true);
267 267
 
268 268
 		if(isset($tours['error'])){
269
-		    return $tours['error'];
270
-        }elseif (isset($tours['itineraries']) && !empty($tours['itineraries'])) {
269
+			return $tours['error'];
270
+		}elseif (isset($tours['itineraries']) && !empty($tours['itineraries'])) {
271 271
 			set_transient('lsx_ti_tours',$tours['itineraries'],60*60*2);
272 272
 			return true;
273 273
 		}
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
 					$keyphrases = $_POST['keyword'];
317 317
 				}else{
318 318
 					$keyphrases = array(0);
319
-                }
319
+				}
320 320
 
321 321
 				if(!is_array($keyphrases)){
322 322
 					$keyphrases = array($keyphrases);
@@ -345,15 +345,15 @@  discard block
 block discarded – undo
345 345
 
346 346
 					foreach($tours as $row_key => $row){
347 347
 
348
-					    if(isset($row['is_disabled']) && true === $row['is_disabled']){
349
-                            continue;
350
-                        }
348
+						if(isset($row['is_disabled']) && true === $row['is_disabled']){
349
+							continue;
350
+						}
351 351
 
352
-                        /*if('Sample' === $row['type']){
352
+						/*if('Sample' === $row['type']){
353 353
                             continue;
354 354
                         }*/
355 355
 
356
-                        //If this is a current tour, add its ID to the row.
356
+						//If this is a current tour, add its ID to the row.
357 357
 						$row['post_id'] = 0;
358 358
 						if(false !== $current_tours && array_key_exists($row['identifier'], $current_tours)){
359 359
 							$row['post_id'] = $current_tours[$row['identifier']]->post_id;
@@ -362,31 +362,31 @@  discard block
 block discarded – undo
362 362
 						//If we are searching for
363 363
 						if(false !== $post_status){
364 364
 
365
-                            if('import' === $post_status){
365
+							if('import' === $post_status){
366 366
 
367 367
 								if(0 !== $row['post_id']){
368
-								    continue;
368
+									continue;
369 369
 								}else{
370 370
 									$searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row);
371
-                                }
371
+								}
372 372
 
373 373
 
374
-                            }else{
374
+							}else{
375 375
 
376 376
 								if(0 === $row['post_id']){
377 377
 									continue;
378 378
 								}else{
379 379
 									$current_status = get_post_status($row['post_id']);
380 380
 									if($current_status !== $post_status){
381
-									    continue;
382
-                                    }
381
+										continue;
382
+									}
383 383
 
384 384
 								}
385 385
 								$searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row);
386 386
 
387
-                            }
387
+							}
388 388
 
389
-                        }else{
389
+						}else{
390 390
 							//Search through each keyword.
391 391
 							foreach($keyphrases as $keyphrase){
392 392
 
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 									$searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row);
401 401
 								}
402 402
 							}
403
-                        }
403
+						}
404 404
 					}		
405 405
 				}
406 406
 
@@ -467,17 +467,17 @@  discard block
 block discarded – undo
467 467
 				$content = false;
468 468
 			}
469 469
 
470
-            $jdata=file_get_contents("http://wetu.com/API/Itinerary/V7/Get?id=".$wetu_id);
470
+			$jdata=file_get_contents("http://wetu.com/API/Itinerary/V7/Get?id=".$wetu_id);
471 471
 
472
-            if($jdata)
473
-            {
472
+			if($jdata)
473
+			{
474 474
 				$jdata=json_decode($jdata,true);
475
-                if(!empty($jdata))
476
-                {
477
-                	$return = $this->import_row($jdata,$wetu_id,$post_id,$content);
478
-                	$this->format_completed_row($return);
479
-                }
480
-            }
475
+				if(!empty($jdata))
476
+				{
477
+					$return = $this->import_row($jdata,$wetu_id,$post_id,$content);
478
+					$this->format_completed_row($return);
479
+				}
480
+			}
481 481
 			die();
482 482
 		}
483 483
 
@@ -485,53 +485,53 @@  discard block
 block discarded – undo
485 485
 
486 486
 	/**
487 487
 	 * Connect to wetu
488
-     *
489
-     * @param $data array
490
-     * @param $wetu_id string
488
+	 *
489
+	 * @param $data array
490
+	 * @param $wetu_id string
491 491
 	 */
492 492
 	public function import_row($data,$wetu_id,$id=0,$importable_content=false,$old1=false,$old2=false) {
493
-        $post_name = $data_post_content = $data_post_excerpt = '';
494
-        $post = array(
495
-          'post_type'		=> 'tour',
496
-        );
493
+		$post_name = $data_post_content = $data_post_excerpt = '';
494
+		$post = array(
495
+		  'post_type'		=> 'tour',
496
+		);
497 497
 
498
-        //Set the post_content
498
+		//Set the post_content
499 499
 		$content_used_general_description = false;
500
-        if(false !== $importable_content && in_array('description',$importable_content)){
501
-            $data_post_content = '';
502
-
503
-            if(isset($data['description'])){
504
-                $data_post_content = $data['description'];
505
-            }elseif(isset($data['summary'])){
506
-                $data_post_content = $data['summary'];
507
-            }
508
-            $post['post_content'] = $data_post_content;
509
-        }
510
-
511
-        //Create or update the post
512
-        if(false !== $id && '0' !== $id){
513
-            $post['ID'] = $id;
514
-	        $post['post_status'] = 'publish';
515
-            $id = wp_update_post($post);
516
-            $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true);
517
-            update_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified']),$prev_date);
518
-        }else{
519
-
520
-            //Set the name
521
-            if(isset($data['name'])){
522
-                $post_name = wp_unique_post_slug(sanitize_title($data['name']),$id, 'draft', 'tour', 0);
523
-            }
524
-            $post['post_name'] = $post_name;
525
-            $post['post_title'] = $data['name'];
526
-            $post['post_status'] = 'publish';
527
-            $id = wp_insert_post($post);
528
-
529
-            //Save the WETU ID and the Last date it was modified.
530
-            if(false !== $id){
531
-                add_post_meta($id,'lsx_wetu_id',$wetu_id);
532
-                add_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified']));
533
-            }
534
-        }
500
+		if(false !== $importable_content && in_array('description',$importable_content)){
501
+			$data_post_content = '';
502
+
503
+			if(isset($data['description'])){
504
+				$data_post_content = $data['description'];
505
+			}elseif(isset($data['summary'])){
506
+				$data_post_content = $data['summary'];
507
+			}
508
+			$post['post_content'] = $data_post_content;
509
+		}
510
+
511
+		//Create or update the post
512
+		if(false !== $id && '0' !== $id){
513
+			$post['ID'] = $id;
514
+			$post['post_status'] = 'publish';
515
+			$id = wp_update_post($post);
516
+			$prev_date = get_post_meta($id,'lsx_wetu_modified_date',true);
517
+			update_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified']),$prev_date);
518
+		}else{
519
+
520
+			//Set the name
521
+			if(isset($data['name'])){
522
+				$post_name = wp_unique_post_slug(sanitize_title($data['name']),$id, 'draft', 'tour', 0);
523
+			}
524
+			$post['post_name'] = $post_name;
525
+			$post['post_title'] = $data['name'];
526
+			$post['post_status'] = 'publish';
527
+			$id = wp_insert_post($post);
528
+
529
+			//Save the WETU ID and the Last date it was modified.
530
+			if(false !== $id){
531
+				add_post_meta($id,'lsx_wetu_id',$wetu_id);
532
+				add_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified']));
533
+			}
534
+		}
535 535
 
536 536
 
537 537
 		//Set the price
@@ -544,9 +544,9 @@  discard block
 block discarded – undo
544 544
 			$this->set_duration($data,$id);
545 545
 		}
546 546
 
547
-        if(in_array('itineraries',$importable_content) && isset($data['legs']) && !empty($data['legs'])){
548
-            $this->process_itineraries($data,$id,$importable_content);
549
-        }
547
+		if(in_array('itineraries',$importable_content) && isset($data['legs']) && !empty($data['legs'])){
548
+			$this->process_itineraries($data,$id,$importable_content);
549
+		}
550 550
 
551 551
 		if(in_array('map',$importable_content) && isset($data['routes']) && !empty($data['routes'])){
552 552
 			$this->process_map_points($data,$id);
@@ -557,24 +557,24 @@  discard block
 block discarded – undo
557 557
 		if(false !== $importable_content && (in_array('itinerary_gallery',$importable_content) || in_array('gallery',$importable_content) || in_array('banner_image',$importable_content) || in_array('featured_image',$importable_content))){
558 558
 			$this->find_attachments($id);
559 559
 		}
560
-        //Set the featured image
561
-        //TODO Test These
562
-        if(false !== $importable_content && in_array('featured_image',$importable_content)){
563
-            $this->set_featured_image($data,$id);
564
-        }
560
+		//Set the featured image
561
+		//TODO Test These
562
+		if(false !== $importable_content && in_array('featured_image',$importable_content)){
563
+			$this->set_featured_image($data,$id);
564
+		}
565 565
 
566 566
 		//TODO Test These
567
-        if(false !== $importable_content && in_array('banner_image',$importable_content)){
568
-            $this->set_banner_image($data,$id);
569
-        }
567
+		if(false !== $importable_content && in_array('banner_image',$importable_content)){
568
+			$this->set_banner_image($data,$id);
569
+		}
570 570
 
571 571
 		//TODO Test These
572
-        //Import the main gallery
573
-        if(false !== $importable_content && in_array('gallery',$importable_content)){
574
-            $this->create_main_gallery($data,$id);
575
-        }
572
+		//Import the main gallery
573
+		if(false !== $importable_content && in_array('gallery',$importable_content)){
574
+			$this->create_main_gallery($data,$id);
575
+		}
576 576
 
577
-        return $id;
577
+		return $id;
578 578
 	}
579 579
 
580 580
 	/**
@@ -700,31 +700,31 @@  discard block
 block discarded – undo
700 700
 	 */
701 701
 	public function process_map_points($data,$id) {
702 702
 
703
-	    if(!empty($data['routes'])){
703
+		if(!empty($data['routes'])){
704 704
 
705
-	        delete_post_meta($id,'wetu_map_points');
705
+			delete_post_meta($id,'wetu_map_points');
706 706
 
707
-	        $points = array();
707
+			$points = array();
708 708
 
709
-	        foreach($data['routes'] as $route){
709
+			foreach($data['routes'] as $route){
710 710
 
711 711
 
712
-	            if(isset($route['points']) && '' !== $route['points']){
712
+				if(isset($route['points']) && '' !== $route['points']){
713 713
 
714
-	                $temp_points = explode(';',$route['points']);
715
-	                $point_counter = count($temp_points);
714
+					$temp_points = explode(';',$route['points']);
715
+					$point_counter = count($temp_points);
716 716
 
717 717
 					for ($x = 0; $x <= $point_counter; $x++) {
718
-					    $y = $x+1;
718
+						$y = $x+1;
719 719
 						$points[] = $temp_points[$x].','.$temp_points[$y];
720 720
 						$x++;
721 721
 					}
722 722
 				}
723
-            }
724
-            if(!empty($points)){
723
+			}
724
+			if(!empty($points)){
725 725
 				$this->save_custom_field(implode(' ',$points),'wetu_map_points',$id,false,true);
726
-            }
727
-        }
726
+			}
727
+		}
728 728
 
729 729
 	}
730 730
 
@@ -732,17 +732,17 @@  discard block
 block discarded – undo
732 732
 	 * Set the Itinerary Day
733 733
 	 */
734 734
 	public function set_itinerary_day($day,$id) {
735
-        $this->save_custom_field($day,'itinerary',$id,false,false);
735
+		$this->save_custom_field($day,'itinerary',$id,false,false);
736 736
 	}
737 737
 
738 738
 	/**
739 739
 	 * Set the price
740 740
 	 */
741 741
 	public function set_price($data,$id) {
742
-	    //Price
742
+		//Price
743 743
 		if(isset($data['price']) && ''!== $data['price']){
744
-            $price = preg_replace("/[^0-9,.]/", "", $data['price']);
745
-            $this->save_custom_field($price,'price',$id);
744
+			$price = preg_replace("/[^0-9,.]/", "", $data['price']);
745
+			$this->save_custom_field($price,'price',$id);
746 746
 		}
747 747
 
748 748
 		//Price includes
@@ -751,7 +751,7 @@  discard block
 block discarded – undo
751 751
 			$this->save_custom_field($data['price_includes'],'included',$id);
752 752
 		}
753 753
 
754
-        //Price Excludes
754
+		//Price Excludes
755 755
 		if(isset($data['price_excludes']) && ''!== $data['price_excludes']){
756 756
 			$this->save_custom_field($data['price_excludes'],'not_included',$id);
757 757
 		}
@@ -775,35 +775,35 @@  discard block
 block discarded – undo
775 775
 	 */
776 776
 	public function set_accommodation($day,$id) {
777 777
 
778
-	    $ac_id = false;
778
+		$ac_id = false;
779 779
 		$this->current_accommodation = $this->find_current_accommodation();
780 780
 		
781 781
 		if(isset($day['content_entity_id']) && !empty($day['content_entity_id'])){
782 782
 
783 783
 			if(false !== $this->current_accommodation && !empty($this->current_accommodation) && array_key_exists($day['content_entity_id'],$this->current_accommodation)){
784
-                $ac_id = $this->current_accommodation[$day['content_entity_id']];
784
+				$ac_id = $this->current_accommodation[$day['content_entity_id']];
785 785
 			}else{
786 786
 				$ac_id = wp_insert_post(array(
787
-                    'post_type' => 'accommodation',
788
-                    'post_status' => 'draft',
789
-                    'post_title' => $day['content_entity_id']
790
-                ));
787
+					'post_type' => 'accommodation',
788
+					'post_status' => 'draft',
789
+					'post_title' => $day['content_entity_id']
790
+				));
791 791
 				$this->save_custom_field($day['content_entity_id'],'lsx_wetu_id',$ac_id);
792 792
 			}
793 793
 
794 794
 			if('' !== $ac_id && false !== $ac_id){
795
-			    $this->save_custom_field($ac_id,'accommodation_to_tour',$id,false,false);
795
+				$this->save_custom_field($ac_id,'accommodation_to_tour',$id,false,false);
796 796
 				$this->save_custom_field($id,'tour_to_accommodation',$ac_id,false,false);
797
-            }
797
+			}
798 798
 		}
799 799
 		return $ac_id;
800 800
 	}
801 801
 
802 802
 	/**
803 803
 	 * Grab all the current accommodation posts via the lsx_wetu_id field.
804
-     *
805
-     * @param $post_type string
806
-     * @return boolean / array
804
+	 *
805
+	 * @param $post_type string
806
+	 * @return boolean / array
807 807
 	 */
808 808
 	public function find_current_accommodation($post_type='accommodation') {
809 809
 		global $wpdb;
@@ -811,16 +811,16 @@  discard block
 block discarded – undo
811 811
 
812 812
 		$return = false;
813 813
 		if(!empty($accommodation)){
814
-		    foreach($accommodation as $key => $acc){
814
+			foreach($accommodation as $key => $acc){
815 815
 				$return[$acc->meta_value] = $acc->post_id;
816
-            }
817
-        }
816
+			}
817
+		}
818 818
 		return $return;
819 819
 	}
820 820
 
821 821
 	/**
822 822
 	 * Grab all the current accommodation posts via the lsx_wetu_id field.
823
-     * @return boolean / array
823
+	 * @return boolean / array
824 824
 	 */
825 825
 	public function find_current_destinations() {
826 826
 		return $this->find_current_accommodation('destination');
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
 				$country_wetu_id = get_post_meta($potential_id,'lsx_wetu_id',true);
848 848
 				if(false !== $country_wetu_id){
849 849
 					$this->set_country($country_wetu_id, $id);
850
-                }
850
+				}
851 851
 
852 852
 			}else {
853 853
 
@@ -858,27 +858,27 @@  discard block
 block discarded – undo
858 858
 
859 859
 					if (!empty($destination_data) && !isset($destination_data['error'])) {
860 860
 
861
-					    $destination_title = $day['destination_content_entity_id'];
861
+						$destination_title = $day['destination_content_entity_id'];
862 862
 
863
-					    if(isset($destination_data[0]['name'])){
863
+						if(isset($destination_data[0]['name'])){
864 864
 							$destination_title = $destination_data[0]['name'];
865
-                        }
865
+						}
866 866
 
867
-					    if(isset($destination_data[0]['map_object_id']) && isset($destination_data[0]['position']['country_content_entity_id'])
868
-                            && $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id']){
867
+						if(isset($destination_data[0]['map_object_id']) && isset($destination_data[0]['position']['country_content_entity_id'])
868
+							&& $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id']){
869 869
 
870 870
 							$country_id = $this->set_country($destination_data[0]['position']['country_content_entity_id'], $id);
871
-                        }
871
+						}
872 872
 
873
-                        $dest_post = array(
873
+						$dest_post = array(
874 874
 							'post_type' => 'destination',
875 875
 							'post_status' => 'draft',
876 876
 							'post_title' => $destination_title
877 877
 						);
878 878
 
879
-					    if(false !== $country_id){
879
+						if(false !== $country_id){
880 880
 							$dest_post['post_parent'] = $country_id;
881
-                        }
881
+						}
882 882
 						$dest_id = wp_insert_post($dest_post);
883 883
 
884 884
 						//Make sure we register the
@@ -900,50 +900,50 @@  discard block
 block discarded – undo
900 900
 	 * Connects the destinations post type
901 901
 	 *
902 902
 	 * @param $dest_id string
903
-     * @param $country_id array
903
+	 * @param $country_id array
904 904
 	 * @param $id string
905 905
 	 */
906 906
 	public function set_country($country_wetu_id, $id) {
907
-	    $country_id = false;
907
+		$country_id = false;
908 908
 		$this->current_destinations = $this->find_current_destinations();
909 909
 
910
-        if (false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($country_wetu_id, $this->current_destinations)) {
911
-            $country_id = $this->current_destinations[$country_wetu_id];
912
-        } else {
910
+		if (false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($country_wetu_id, $this->current_destinations)) {
911
+			$country_id = $this->current_destinations[$country_wetu_id];
912
+		} else {
913 913
 
914
-            $country_json = file_get_contents("http://wetu.com/API/Pins/".$this->api_key."/Get?ids=" . $country_wetu_id);
914
+			$country_json = file_get_contents("http://wetu.com/API/Pins/".$this->api_key."/Get?ids=" . $country_wetu_id);
915 915
 
916
-            if ($country_json) {
917
-                $country_data = json_decode($country_json, true);
916
+			if ($country_json) {
917
+				$country_data = json_decode($country_json, true);
918 918
 
919
-                if (!empty($country_data) && !isset($country_data['error'])) {
919
+				if (!empty($country_data) && !isset($country_data['error'])) {
920 920
 
921 921
 					//Format the title of the destination if its available,  otherwise default to the WETU ID.
922
-                    $country_title = $country_wetu_id;
923
-                    if (isset($country_data[0]['name'])) {
922
+					$country_title = $country_wetu_id;
923
+					if (isset($country_data[0]['name'])) {
924 924
 						$country_title = $country_data[0]['name'];
925
-                    }
925
+					}
926 926
 
927 927
 					$country_id = wp_insert_post(array(
928
-                        'post_type' => 'destination',
929
-                        'post_status' => 'draft',
930
-                        'post_title' => $country_title
931
-                    ));
928
+						'post_type' => 'destination',
929
+						'post_status' => 'draft',
930
+						'post_title' => $country_title
931
+					));
932 932
 					//add the country to the current destination stack
933 933
 					$this->current_destinations[$country_wetu_id] = $country_id;
934 934
 
935 935
 					//Save the wetu field
936
-                    $this->save_custom_field($country_wetu_id, 'lsx_wetu_id', $country_id);
937
-                }
938
-            }
939
-        }
936
+					$this->save_custom_field($country_wetu_id, 'lsx_wetu_id', $country_id);
937
+				}
938
+			}
939
+		}
940 940
 
941
-        if ('' !== $country_id && false !== $country_id) {
942
-            $this->save_custom_field($country_id, 'destination_to_tour', $id, false, false);
943
-            $this->save_custom_field($id, 'tour_to_destination', $country_id, false, false);
941
+		if ('' !== $country_id && false !== $country_id) {
942
+			$this->save_custom_field($country_id, 'destination_to_tour', $id, false, false);
943
+			$this->save_custom_field($id, 'tour_to_destination', $country_id, false, false);
944 944
 
945
-            return $country_id;
946
-        }
945
+			return $country_id;
946
+		}
947 947
 	}
948 948
 }
949 949
 $wetu_importer_tours = new WETU_Importer_Tours();
950 950
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +200 added lines, -200 removed lines patch added patch discarded remove patch
@@ -82,20 +82,20 @@  discard block
 block discarded – undo
82 82
 	public function __construct() {
83 83
 		$this->set_variables();
84 84
 
85
-		add_action( 'lsx_tour_importer_admin_tab_'.$this->tab_slug, array($this,'display_page') );
86
-		add_action('wp_ajax_lsx_tour_importer',array($this,'process_ajax_search'));	
87
-		add_action('wp_ajax_nopriv_lsx_tour_importer',array($this,'process_ajax_search'));		
85
+		add_action('lsx_tour_importer_admin_tab_'.$this->tab_slug, array($this, 'display_page'));
86
+		add_action('wp_ajax_lsx_tour_importer', array($this, 'process_ajax_search'));	
87
+		add_action('wp_ajax_nopriv_lsx_tour_importer', array($this, 'process_ajax_search'));		
88 88
 
89
-		add_action('wp_ajax_lsx_import_items',array($this,'process_ajax_import'));	
90
-		add_action('wp_ajax_nopriv_lsx_import_items',array($this,'process_ajax_import'));
89
+		add_action('wp_ajax_lsx_import_items', array($this, 'process_ajax_import'));	
90
+		add_action('wp_ajax_nopriv_lsx_import_items', array($this, 'process_ajax_import'));
91 91
 
92
-		$temp_options = get_option('_lsx-to_settings',false);
93
-		if(false !== $temp_options && isset($temp_options[$this->plugin_slug]) && !empty($temp_options[$this->plugin_slug])){
92
+		$temp_options = get_option('_lsx-to_settings', false);
93
+		if (false !== $temp_options && isset($temp_options[$this->plugin_slug]) && !empty($temp_options[$this->plugin_slug])) {
94 94
 			$this->options = $temp_options[$this->plugin_slug];
95 95
 		}
96 96
 
97
-		$tour_options = get_option('wetu_importer_tour_settings',false);
98
-		if(false !== $tour_options){
97
+		$tour_options = get_option('wetu_importer_tour_settings', false);
98
+		if (false !== $tour_options) {
99 99
 			$this->tour_options = $tour_options;
100 100
         }
101 101
 	}
@@ -107,11 +107,11 @@  discard block
 block discarded – undo
107 107
 	{
108 108
 		parent::set_variables();
109 109
 
110
-		if ( false !== $this->api_username && false !== $this->api_password ) {
110
+		if (false !== $this->api_username && false !== $this->api_password) {
111 111
 			$this->url    = 'https://wetu.com/API/Itinerary/';
112
-			$this->url_qs = 'username=' . $this->api_username . '&password=' . $this->api_password;
113
-		} elseif ( false !== $this->api_key ) {
114
-			$this->url    = 'https://wetu.com/API/Itinerary/' . $this->api_key;
112
+			$this->url_qs = 'username='.$this->api_username.'&password='.$this->api_password;
113
+		} elseif (false !== $this->api_key) {
114
+			$this->url    = 'https://wetu.com/API/Itinerary/'.$this->api_key;
115 115
 			$this->url_qs = '';
116 116
 		}
117 117
 	}
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
 			<form method="get" action="" id="posts-filter">
132 132
 				<input type="hidden" name="post_type" class="post_type" value="<?php echo $this->tab_slug; ?>" />
133 133
 				
134
-				<p><input class="button button-primary add" type="button" value="<?php _e('Add to List','wetu-importer'); ?>" />
135
-					<input class="button button-primary clear" type="button" value="<?php _e('Clear','wetu-importer'); ?>" />
134
+				<p><input class="button button-primary add" type="button" value="<?php _e('Add to List', 'wetu-importer'); ?>" />
135
+					<input class="button button-primary clear" type="button" value="<?php _e('Clear', 'wetu-importer'); ?>" />
136 136
 				</p>				
137 137
 
138 138
 				<table class="wp-list-table widefat fixed posts">
@@ -141,11 +141,11 @@  discard block
 block discarded – undo
141 141
 					<tbody id="the-list">
142 142
 						<tr class="post-0 type-tour status-none" id="post-0">
143 143
 							<th class="check-column" scope="row">
144
-								<label for="cb-select-0" class="screen-reader-text"><?php _e('Enter a title to search for and press enter','wetu-importer'); ?></label>
144
+								<label for="cb-select-0" class="screen-reader-text"><?php _e('Enter a title to search for and press enter', 'wetu-importer'); ?></label>
145 145
 							</th>
146 146
 							<td class="post-title page-title column-title">
147 147
 								<strong>
148
-									<?php _e('Enter a title to search for','wetu-importer'); ?>
148
+									<?php _e('Enter a title to search for', 'wetu-importer'); ?>
149 149
 								</strong>
150 150
 							</td>
151 151
 							<td class="date column-date">							
@@ -159,8 +159,8 @@  discard block
 block discarded – undo
159 159
 
160 160
 				</table>
161 161
 
162
-				<p><input class="button button-primary add" type="button" value="<?php _e('Add to List','wetu-importer'); ?>" />
163
-					<input class="button button-primary clear" type="button" value="<?php _e('Clear','wetu-importer'); ?>" />
162
+				<p><input class="button button-primary add" type="button" value="<?php _e('Add to List', 'wetu-importer'); ?>" />
163
+					<input class="button button-primary clear" type="button" value="<?php _e('Clear', 'wetu-importer'); ?>" />
164 164
 				</p>
165 165
 			</form> 
166 166
 
@@ -172,36 +172,36 @@  discard block
 block discarded – undo
172 172
 						<div style="width:30%;display:block;float:left;">
173 173
 							<h3><?php _e('What content to Sync from WETU'); ?></h3>
174 174
 							<ul>
175
-								<li><input class="content" checked="<?php $this->checked($this->tour_options,'description'); ?>" type="checkbox" name="content[]" value="description" /> <?php _e('Description','wetu-importer'); ?></li>
176
-								<li><input class="content" checked="<?php $this->checked($this->tour_options,'excerpt'); ?>" type="checkbox" name="content[]" value="excerpt" /> <?php _e('Excerpt','wetu-importer'); ?></li>
175
+								<li><input class="content" checked="<?php $this->checked($this->tour_options, 'description'); ?>" type="checkbox" name="content[]" value="description" /> <?php _e('Description', 'wetu-importer'); ?></li>
176
+								<li><input class="content" checked="<?php $this->checked($this->tour_options, 'excerpt'); ?>" type="checkbox" name="content[]" value="excerpt" /> <?php _e('Excerpt', 'wetu-importer'); ?></li>
177 177
 
178
-                                <li><input class="content" checked="<?php $this->checked($this->tour_options,'price'); ?>" type="checkbox" name="content[]" value="price" /> <?php _e('Price','wetu-importer'); ?></li>
179
-                                <li><input class="content" checked="<?php $this->checked($this->tour_options,'duration'); ?>" type="checkbox" name="content[]" value="duration" /> <?php _e('Duration','wetu-importer'); ?></li>
178
+                                <li><input class="content" checked="<?php $this->checked($this->tour_options, 'price'); ?>" type="checkbox" name="content[]" value="price" /> <?php _e('Price', 'wetu-importer'); ?></li>
179
+                                <li><input class="content" checked="<?php $this->checked($this->tour_options, 'duration'); ?>" type="checkbox" name="content[]" value="duration" /> <?php _e('Duration', 'wetu-importer'); ?></li>
180 180
 
181
-								<li><input class="content" checked="<?php $this->checked($this->tour_options,'category'); ?>" type="checkbox" name="content[]" value="category" /> <?php _e('Category','wetu-importer'); ?></li>
181
+								<li><input class="content" checked="<?php $this->checked($this->tour_options, 'category'); ?>" type="checkbox" name="content[]" value="category" /> <?php _e('Category', 'wetu-importer'); ?></li>
182 182
 
183
-                                <li><input class="content" checked="<?php $this->checked($this->tour_options,'itineraries'); ?>" type="checkbox" name="content[]" value="itineraries" /> <?php _e('Itinerary Days','wetu-importer'); ?></li>
183
+                                <li><input class="content" checked="<?php $this->checked($this->tour_options, 'itineraries'); ?>" type="checkbox" name="content[]" value="itineraries" /> <?php _e('Itinerary Days', 'wetu-importer'); ?></li>
184 184
 
185
-								<?php if(class_exists('TO_Maps')){ ?>
186
-                                    <li><input class="content" checked="<?php $this->checked($this->tour_options,'map'); ?>" type="checkbox" name="content[]" value="map" /> <?php _e('Map Coordinates (generates a KML file)','wetu-importer'); ?></li>
185
+								<?php if (class_exists('TO_Maps')) { ?>
186
+                                    <li><input class="content" checked="<?php $this->checked($this->tour_options, 'map'); ?>" type="checkbox" name="content[]" value="map" /> <?php _e('Map Coordinates (generates a KML file)', 'wetu-importer'); ?></li>
187 187
 								<?php } ?>
188 188
 							</ul>
189 189
 						</div>
190 190
                         <div style="width:30%;display:block;float:left;">
191 191
                             <h3><?php _e('Itinerary Info'); ?></h3>
192 192
                             <ul>
193
-                                <li><input class="content" checked="<?php $this->checked($this->tour_options,'itinerary_description'); ?>" type="checkbox" name="content[]" value="itinerary_description" /> <?php _e('Description','wetu-importer'); ?></li>
194
-                                <li><input class="content" checked="<?php $this->checked($this->tour_options,'itinerary_included'); ?>" type="checkbox" name="content[]" value="itinerary_included" /> <?php _e('Included','wetu-importer'); ?></li>
195
-                                <li><input class="content" checked="<?php $this->checked($this->tour_options,'itinerary_excluded'); ?>" type="checkbox" name="content[]" value="itinerary_excluded" /> <?php _e('Excluded','wetu-importer'); ?></li>
193
+                                <li><input class="content" checked="<?php $this->checked($this->tour_options, 'itinerary_description'); ?>" type="checkbox" name="content[]" value="itinerary_description" /> <?php _e('Description', 'wetu-importer'); ?></li>
194
+                                <li><input class="content" checked="<?php $this->checked($this->tour_options, 'itinerary_included'); ?>" type="checkbox" name="content[]" value="itinerary_included" /> <?php _e('Included', 'wetu-importer'); ?></li>
195
+                                <li><input class="content" checked="<?php $this->checked($this->tour_options, 'itinerary_excluded'); ?>" type="checkbox" name="content[]" value="itinerary_excluded" /> <?php _e('Excluded', 'wetu-importer'); ?></li>
196 196
                             </ul>
197 197
 
198 198
                             <h4><?php _e('Additional Content'); ?></h4>
199 199
                             <ul>
200
-                                <li><input class="content" checked="<?php $this->checked($this->tour_options,'accommodation'); ?>" type="checkbox" name="content[]" value="accommodation" /> <?php _e('Sync Accommodation','wetu-importer'); ?></li>
201
-                                <li><input class="content" checked="<?php $this->checked($this->tour_options,'destination'); ?>" type="checkbox" name="content[]" value="destination" /> <?php _e('Sync Destinations','wetu-importer'); ?></li>
200
+                                <li><input class="content" checked="<?php $this->checked($this->tour_options, 'accommodation'); ?>" type="checkbox" name="content[]" value="accommodation" /> <?php _e('Sync Accommodation', 'wetu-importer'); ?></li>
201
+                                <li><input class="content" checked="<?php $this->checked($this->tour_options, 'destination'); ?>" type="checkbox" name="content[]" value="destination" /> <?php _e('Sync Destinations', 'wetu-importer'); ?></li>
202 202
                             </ul>
203 203
                         </div>
204
-                        <?php if(class_exists('TO_Team')){ ?>
204
+                        <?php if (class_exists('TO_Team')) { ?>
205 205
                             <div style="width:30%;display:block;float:left;">
206 206
                                 <h3><?php _e('Assign a Team Member'); ?></h3>
207 207
                                 <?php $this->team_member_checkboxes($this->tour_options); ?>
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 
214 214
 
215 215
 					<h3><?php _e('Your List'); ?></h3>
216
-                    <p><input class="button button-primary" type="submit" value="<?php _e('Sync','wetu-importer'); ?>" /></p>
216
+                    <p><input class="button button-primary" type="submit" value="<?php _e('Sync', 'wetu-importer'); ?>" /></p>
217 217
 					<table class="wp-list-table widefat fixed posts">
218 218
 						<?php $this->table_header(); ?>
219 219
 
@@ -225,12 +225,12 @@  discard block
 block discarded – undo
225 225
 
226 226
 					</table>
227 227
 
228
-					<p><input class="button button-primary" type="submit" value="<?php _e('Sync','wetu-importer'); ?>" /></p>
228
+					<p><input class="button button-primary" type="submit" value="<?php _e('Sync', 'wetu-importer'); ?>" /></p>
229 229
 				</form>
230 230
 			</div>
231 231
 
232 232
 			<div style="display:none;" class="completed-list-wrapper">
233
-				<h3><?php _e('Completed','wetu-importer'); ?> - <small><?php _e('Import your','wetu-importer'); ?> <a href="<?php echo admin_url('admin.php'); ?>?page=<?php echo $this->plugin_slug; ?>&tab=accommodation"><?php _e('accommodation'); ?></a> <?php _e('next','wetu-importer'); ?></small></h3>
233
+				<h3><?php _e('Completed', 'wetu-importer'); ?> - <small><?php _e('Import your', 'wetu-importer'); ?> <a href="<?php echo admin_url('admin.php'); ?>?page=<?php echo $this->plugin_slug; ?>&tab=accommodation"><?php _e('accommodation'); ?></a> <?php _e('next', 'wetu-importer'); ?></small></h3>
234 234
 				<ul>
235 235
 				</ul>
236 236
 			</div>
@@ -243,17 +243,17 @@  discard block
 block discarded – undo
243 243
 	 */
244 244
 	public function update_options_form() {
245 245
 		$tours = get_transient('lsx_ti_tours');
246
-		echo '<div class="wetu-status"><h3>'.__('Wetu Status','wetu-importer').' - ';
247
-		if('' === $tours || false === $tours || isset($_GET['refresh_tours'])){
246
+		echo '<div class="wetu-status"><h3>'.__('Wetu Status', 'wetu-importer').' - ';
247
+		if ('' === $tours || false === $tours || isset($_GET['refresh_tours'])) {
248 248
 			$result = $this->update_options();
249 249
 
250
-			if(true === $result){
251
-			    echo '<span style="color:green;">'.esc_attr('Connected','wetu-importer').'</span>';
252
-            }else{
250
+			if (true === $result) {
251
+			    echo '<span style="color:green;">'.esc_attr('Connected', 'wetu-importer').'</span>';
252
+            }else {
253 253
 			    echo '<span style="color:red;">'.wp_kses_post($result).'</span>';
254 254
             }
255
-		}else{
256
-			echo '<span style="color:green;">'.esc_attr('Connected','wetu-importer').'</span>';
255
+		}else {
256
+			echo '<span style="color:green;">'.esc_attr('Connected', 'wetu-importer').'</span>';
257 257
         }
258 258
 		echo '</h3></div>';
259 259
 	}
@@ -262,13 +262,13 @@  discard block
 block discarded – undo
262 262
 	 * Save the list of Tours into an option
263 263
 	 */
264 264
 	public function update_options() {
265
-		$data = file_get_contents( $this->url . '/V7/List?' . $this->url_qs . '&own=true&type=All' );
265
+		$data = file_get_contents($this->url.'/V7/List?'.$this->url_qs.'&own=true&type=All');
266 266
 		$tours = json_decode($data, true);
267 267
 
268
-		if(isset($tours['error'])){
268
+		if (isset($tours['error'])) {
269 269
 		    return $tours['error'];
270 270
         }elseif (isset($tours['itineraries']) && !empty($tours['itineraries'])) {
271
-			set_transient('lsx_ti_tours',$tours['itineraries'],60*60*2);
271
+			set_transient('lsx_ti_tours', $tours['itineraries'], 60 * 60 * 2);
272 272
 			return true;
273 273
 		}
274 274
 	}
@@ -292,8 +292,8 @@  discard block
 block discarded – undo
292 292
 
293 293
 					LIMIT 0,500
294 294
 		");
295
-		if(null !== $current_tours && !empty($current_tours)){
296
-			foreach($current_tours as $tour){
295
+		if (null !== $current_tours && !empty($current_tours)) {
296
+			foreach ($current_tours as $tour) {
297 297
 				$return[$tour->meta_value] = $tour;
298 298
 			}
299 299
 		}
@@ -306,36 +306,36 @@  discard block
 block discarded – undo
306 306
 	public function process_ajax_search() {
307 307
 		$return = false;
308 308
 
309
-		if(isset($_POST['action']) && $_POST['action'] === 'lsx_tour_importer' && isset($_POST['type']) && $_POST['type'] === $this->tab_slug){
309
+		if (isset($_POST['action']) && $_POST['action'] === 'lsx_tour_importer' && isset($_POST['type']) && $_POST['type'] === $this->tab_slug) {
310 310
 			$tours = get_transient('lsx_ti_tours');
311
-			if ( false !== $tours) {
311
+			if (false !== $tours) {
312 312
 
313 313
 				$searched_items = false;
314 314
 
315
-				if(isset($_POST['keyword'] )) {
315
+				if (isset($_POST['keyword'])) {
316 316
 					$keyphrases = $_POST['keyword'];
317
-				}else{
317
+				}else {
318 318
 					$keyphrases = array(0);
319 319
                 }
320 320
 
321
-				if(!is_array($keyphrases)){
321
+				if (!is_array($keyphrases)) {
322 322
 					$keyphrases = array($keyphrases);
323 323
 				}
324
-				foreach($keyphrases as &$keyword){
324
+				foreach ($keyphrases as &$keyword) {
325 325
 					$keyword = ltrim(rtrim($keyword));
326 326
 				}
327 327
 
328 328
 				$post_status = false;
329
-				if(in_array('publish',$keyphrases)){
329
+				if (in_array('publish', $keyphrases)) {
330 330
 					$post_status = 'publish';
331 331
 				}
332
-				if(in_array('pending',$keyphrases)){
332
+				if (in_array('pending', $keyphrases)) {
333 333
 					$post_status = 'pending';
334 334
 				}
335
-				if(in_array('draft',$keyphrases)){
335
+				if (in_array('draft', $keyphrases)) {
336 336
 					$post_status = 'draft';
337 337
 				}
338
-				if(in_array('import',$keyphrases)){
338
+				if (in_array('import', $keyphrases)) {
339 339
 					$post_status = 'import';
340 340
 				}
341 341
 
@@ -343,9 +343,9 @@  discard block
 block discarded – undo
343 343
 				if (!empty($tours)) {
344 344
 					$current_tours = $this->find_current_tours();
345 345
 
346
-					foreach($tours as $row_key => $row){
346
+					foreach ($tours as $row_key => $row) {
347 347
 
348
-					    if(isset($row['is_disabled']) && true === $row['is_disabled']){
348
+					    if (isset($row['is_disabled']) && true === $row['is_disabled']) {
349 349
                             continue;
350 350
                         }
351 351
 
@@ -355,29 +355,29 @@  discard block
 block discarded – undo
355 355
 
356 356
                         //If this is a current tour, add its ID to the row.
357 357
 						$row['post_id'] = 0;
358
-						if(false !== $current_tours && array_key_exists($row['identifier'], $current_tours)){
358
+						if (false !== $current_tours && array_key_exists($row['identifier'], $current_tours)) {
359 359
 							$row['post_id'] = $current_tours[$row['identifier']]->post_id;
360 360
 						}
361 361
 
362 362
 						//If we are searching for
363
-						if(false !== $post_status){
363
+						if (false !== $post_status) {
364 364
 
365
-                            if('import' === $post_status){
365
+                            if ('import' === $post_status) {
366 366
 
367
-								if(0 !== $row['post_id']){
367
+								if (0 !== $row['post_id']) {
368 368
 								    continue;
369
-								}else{
369
+								}else {
370 370
 									$searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row);
371 371
                                 }
372 372
 
373 373
 
374
-                            }else{
374
+                            }else {
375 375
 
376
-								if(0 === $row['post_id']){
376
+								if (0 === $row['post_id']) {
377 377
 									continue;
378
-								}else{
378
+								}else {
379 379
 									$current_status = get_post_status($row['post_id']);
380
-									if($current_status !== $post_status){
380
+									if ($current_status !== $post_status) {
381 381
 									    continue;
382 382
                                     }
383 383
 
@@ -386,17 +386,17 @@  discard block
 block discarded – undo
386 386
 
387 387
                             }
388 388
 
389
-                        }else{
389
+                        }else {
390 390
 							//Search through each keyword.
391
-							foreach($keyphrases as $keyphrase){
391
+							foreach ($keyphrases as $keyphrase) {
392 392
 
393 393
 								//Make sure the keyphrase is turned into an array
394
-								$keywords = explode(" ",$keyphrase);
395
-								if(!is_array($keywords)){
394
+								$keywords = explode(" ", $keyphrase);
395
+								if (!is_array($keywords)) {
396 396
 									$keywords = array($keywords);
397 397
 								}
398 398
 
399
-								if($this->multineedle_stripos(ltrim(rtrim($row['name'])), $keywords) !== false){
399
+								if ($this->multineedle_stripos(ltrim(rtrim($row['name'])), $keywords) !== false) {
400 400
 									$searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row);
401 401
 								}
402 402
 							}
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
 					}		
405 405
 				}
406 406
 
407
-				if(false !== $searched_items){
407
+				if (false !== $searched_items) {
408 408
 					ksort($searched_items);
409 409
 					$return = implode($searched_items);
410 410
 				}
@@ -417,11 +417,11 @@  discard block
 block discarded – undo
417 417
 	/**
418 418
 	 * Formats the row for output on the screen.
419 419
 	 */	
420
-	public function format_row($row = false){
421
-		if(false !== $row){
420
+	public function format_row($row = false) {
421
+		if (false !== $row) {
422 422
 
423 423
 			$status = 'import';
424
-			if(0 !== $row['post_id']){
424
+			if (0 !== $row['post_id']) {
425 425
 				$status = '<a href="'.admin_url('/post.php?post='.$row['post_id'].'&action=edit').'" target="_blank">'.get_post_status($row['post_id']).'</a>';
426 426
 			}
427 427
 
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
 					<strong>'.$row['name'].'</strong> - '.$status.'
436 436
 				</td>
437 437
 				<td class="date column-date">
438
-					<abbr title="'.date('Y/m/d',strtotime($row['last_modified'])).'">'.date('Y/m/d',strtotime($row['last_modified'])).'</abbr><br>Last Modified
438
+					<abbr title="'.date('Y/m/d', strtotime($row['last_modified'])).'">'.date('Y/m/d', strtotime($row['last_modified'])).'</abbr><br>Last Modified
439 439
 				</td>
440 440
 				<td class="ssid column-ssid">
441 441
 					'.$row['identifier'].'
@@ -450,31 +450,31 @@  discard block
 block discarded – undo
450 450
 	 */
451 451
 	public function process_ajax_import($force = false) {
452 452
 		$return = false;
453
-		if(isset($_POST['action']) && $_POST['action'] === 'lsx_import_items' && isset($_POST['type']) && $_POST['type'] === $this->tab_slug && isset($_POST['wetu_id'])){
453
+		if (isset($_POST['action']) && $_POST['action'] === 'lsx_import_items' && isset($_POST['type']) && $_POST['type'] === $this->tab_slug && isset($_POST['wetu_id'])) {
454 454
 			
455 455
 			$wetu_id = $_POST['wetu_id'];
456
-			if(isset($_POST['post_id'])){
456
+			if (isset($_POST['post_id'])) {
457 457
 				$post_id = $_POST['post_id'];	
458
-			}else{
458
+			}else {
459 459
 				$post_id = 0;
460 460
 			}
461 461
 
462
-			if(isset($_POST['content']) && is_array($_POST['content']) && !empty($_POST['content'])){
462
+			if (isset($_POST['content']) && is_array($_POST['content']) && !empty($_POST['content'])) {
463 463
 				$content = $_POST['content'];
464
-				add_option('wetu_importer_tour_settings',$content);
465
-			}else{
464
+				add_option('wetu_importer_tour_settings', $content);
465
+			}else {
466 466
 				delete_option('wetu_importer_tour_settings');
467 467
 				$content = false;
468 468
 			}
469 469
 
470
-            $jdata=file_get_contents("http://wetu.com/API/Itinerary/V7/Get?id=".$wetu_id);
470
+            $jdata = file_get_contents("http://wetu.com/API/Itinerary/V7/Get?id=".$wetu_id);
471 471
 
472
-            if($jdata)
472
+            if ($jdata)
473 473
             {
474
-				$jdata=json_decode($jdata,true);
475
-                if(!empty($jdata))
474
+				$jdata = json_decode($jdata, true);
475
+                if (!empty($jdata))
476 476
                 {
477
-                	$return = $this->import_row($jdata,$wetu_id,$post_id,$content);
477
+                	$return = $this->import_row($jdata, $wetu_id, $post_id, $content);
478 478
                 	$this->format_completed_row($return);
479 479
                 }
480 480
             }
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
      * @param $data array
490 490
      * @param $wetu_id string
491 491
 	 */
492
-	public function import_row($data,$wetu_id,$id=0,$importable_content=false,$old1=false,$old2=false) {
492
+	public function import_row($data, $wetu_id, $id = 0, $importable_content = false, $old1 = false, $old2 = false) {
493 493
         $post_name = $data_post_content = $data_post_excerpt = '';
494 494
         $post = array(
495 495
           'post_type'		=> 'tour',
@@ -497,29 +497,29 @@  discard block
 block discarded – undo
497 497
 
498 498
         //Set the post_content
499 499
 		$content_used_general_description = false;
500
-        if(false !== $importable_content && in_array('description',$importable_content)){
500
+        if (false !== $importable_content && in_array('description', $importable_content)) {
501 501
             $data_post_content = '';
502 502
 
503
-            if(isset($data['description'])){
503
+            if (isset($data['description'])) {
504 504
                 $data_post_content = $data['description'];
505
-            }elseif(isset($data['summary'])){
505
+            }elseif (isset($data['summary'])) {
506 506
                 $data_post_content = $data['summary'];
507 507
             }
508 508
             $post['post_content'] = $data_post_content;
509 509
         }
510 510
 
511 511
         //Create or update the post
512
-        if(false !== $id && '0' !== $id){
512
+        if (false !== $id && '0' !== $id) {
513 513
             $post['ID'] = $id;
514 514
 	        $post['post_status'] = 'publish';
515 515
             $id = wp_update_post($post);
516
-            $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true);
517
-            update_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified']),$prev_date);
518
-        }else{
516
+            $prev_date = get_post_meta($id, 'lsx_wetu_modified_date', true);
517
+            update_post_meta($id, 'lsx_wetu_modified_date', strtotime($data['last_modified']), $prev_date);
518
+        }else {
519 519
 
520 520
             //Set the name
521
-            if(isset($data['name'])){
522
-                $post_name = wp_unique_post_slug(sanitize_title($data['name']),$id, 'draft', 'tour', 0);
521
+            if (isset($data['name'])) {
522
+                $post_name = wp_unique_post_slug(sanitize_title($data['name']), $id, 'draft', 'tour', 0);
523 523
             }
524 524
             $post['post_name'] = $post_name;
525 525
             $post['post_title'] = $data['name'];
@@ -527,51 +527,51 @@  discard block
 block discarded – undo
527 527
             $id = wp_insert_post($post);
528 528
 
529 529
             //Save the WETU ID and the Last date it was modified.
530
-            if(false !== $id){
531
-                add_post_meta($id,'lsx_wetu_id',$wetu_id);
532
-                add_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified']));
530
+            if (false !== $id) {
531
+                add_post_meta($id, 'lsx_wetu_id', $wetu_id);
532
+                add_post_meta($id, 'lsx_wetu_modified_date', strtotime($data['last_modified']));
533 533
             }
534 534
         }
535 535
 
536 536
 
537 537
 		//Set the price
538
-		if(false !== $importable_content && in_array('price',$importable_content)){
539
-			$this->set_price($data,$id);
538
+		if (false !== $importable_content && in_array('price', $importable_content)) {
539
+			$this->set_price($data, $id);
540 540
 		}
541 541
 
542 542
 		//Set the Duration
543
-		if(false !== $importable_content && in_array('duration',$importable_content)){
544
-			$this->set_duration($data,$id);
543
+		if (false !== $importable_content && in_array('duration', $importable_content)) {
544
+			$this->set_duration($data, $id);
545 545
 		}
546 546
 
547
-        if(in_array('itineraries',$importable_content) && isset($data['legs']) && !empty($data['legs'])){
548
-            $this->process_itineraries($data,$id,$importable_content);
547
+        if (in_array('itineraries', $importable_content) && isset($data['legs']) && !empty($data['legs'])) {
548
+            $this->process_itineraries($data, $id, $importable_content);
549 549
         }
550 550
 
551
-		if(in_array('map',$importable_content) && isset($data['routes']) && !empty($data['routes'])){
552
-			$this->process_map_points($data,$id);
551
+		if (in_array('map', $importable_content) && isset($data['routes']) && !empty($data['routes'])) {
552
+			$this->process_map_points($data, $id);
553 553
 		}
554 554
 
555 555
 		//TODO Test These
556 556
 		//Setup some default for use in the import
557
-		if(false !== $importable_content && (in_array('itinerary_gallery',$importable_content) || in_array('gallery',$importable_content) || in_array('banner_image',$importable_content) || in_array('featured_image',$importable_content))){
557
+		if (false !== $importable_content && (in_array('itinerary_gallery', $importable_content) || in_array('gallery', $importable_content) || in_array('banner_image', $importable_content) || in_array('featured_image', $importable_content))) {
558 558
 			$this->find_attachments($id);
559 559
 		}
560 560
         //Set the featured image
561 561
         //TODO Test These
562
-        if(false !== $importable_content && in_array('featured_image',$importable_content)){
563
-            $this->set_featured_image($data,$id);
562
+        if (false !== $importable_content && in_array('featured_image', $importable_content)) {
563
+            $this->set_featured_image($data, $id);
564 564
         }
565 565
 
566 566
 		//TODO Test These
567
-        if(false !== $importable_content && in_array('banner_image',$importable_content)){
568
-            $this->set_banner_image($data,$id);
567
+        if (false !== $importable_content && in_array('banner_image', $importable_content)) {
568
+            $this->set_banner_image($data, $id);
569 569
         }
570 570
 
571 571
 		//TODO Test These
572 572
         //Import the main gallery
573
-        if(false !== $importable_content && in_array('gallery',$importable_content)){
574
-            $this->create_main_gallery($data,$id);
573
+        if (false !== $importable_content && in_array('gallery', $importable_content)) {
574
+            $this->create_main_gallery($data, $id);
575 575
         }
576 576
 
577 577
         return $id;
@@ -580,149 +580,149 @@  discard block
 block discarded – undo
580 580
 	/**
581 581
 	 * A loop which runs through each leg on the tour.
582 582
 	 */
583
-	public function process_itineraries($data,$id,$importable_content) {
583
+	public function process_itineraries($data, $id, $importable_content) {
584 584
 		$day_counter = 1;
585 585
 		$leg_counter = 0;
586 586
 
587
-		delete_post_meta($id,'itinerary');
587
+		delete_post_meta($id, 'itinerary');
588 588
 
589
-		if(false !== $importable_content && in_array('accommodation',$importable_content)){
590
-			delete_post_meta($id,'accommodation_to_tour');
589
+		if (false !== $importable_content && in_array('accommodation', $importable_content)) {
590
+			delete_post_meta($id, 'accommodation_to_tour');
591 591
 		}
592
-		if(false !== $importable_content && in_array('destination',$importable_content)){
593
-			delete_post_meta($id,'destination_to_tour');
594
-			delete_post_meta($id,'departs_from');
595
-			delete_post_meta($id,'ends_in');
592
+		if (false !== $importable_content && in_array('destination', $importable_content)) {
593
+			delete_post_meta($id, 'destination_to_tour');
594
+			delete_post_meta($id, 'departs_from');
595
+			delete_post_meta($id, 'ends_in');
596 596
 		}
597 597
 
598 598
 		$departs_from = false;
599 599
 		$ends_in = false;
600 600
 
601
-		foreach($data['legs'] as $leg){
601
+		foreach ($data['legs'] as $leg) {
602 602
 
603
-			if(isset($leg['days']) && !empty($leg['days'])){
603
+			if (isset($leg['days']) && !empty($leg['days'])) {
604 604
 
605 605
 				//Itinerary Accommodation
606 606
 				$current_accommodation = false;
607
-				if(false !== $importable_content && in_array('accommodation',$importable_content)){
608
-					$current_accommodation = $this->set_accommodation($leg,$id);
607
+				if (false !== $importable_content && in_array('accommodation', $importable_content)) {
608
+					$current_accommodation = $this->set_accommodation($leg, $id);
609 609
 				}
610 610
 
611 611
 				//Itinerary Destination
612 612
 				$current_destination = false;
613
-				if(false !== $importable_content && in_array('destination',$importable_content)){
614
-					$current_destination = $this->set_destination($leg,$id);
613
+				if (false !== $importable_content && in_array('destination', $importable_content)) {
614
+					$current_destination = $this->set_destination($leg, $id);
615 615
 				}
616 616
 
617 617
 				//If the Nights are the same mount of days in the array,  then it isnt "By Destination"
618
-				if($leg['nights'] === count($leg['days']) || 0 === $leg['itinerary_leg_id']){
618
+				if ($leg['nights'] === count($leg['days']) || 0 === $leg['itinerary_leg_id']) {
619 619
 
620
-					foreach($leg['days'] as $day){
620
+					foreach ($leg['days'] as $day) {
621 621
 
622 622
 						$current_day = array();
623 623
 
624
-						$current_day['title'] =  esc_attr('Day ','wetu-importer').$day_counter;
624
+						$current_day['title'] = esc_attr('Day ', 'wetu-importer').$day_counter;
625 625
 
626 626
 						//Description
627
-						if(false !== $importable_content && in_array('itinerary_description',$importable_content) && isset($day['notes']) && '' !== $day['notes']){
627
+						if (false !== $importable_content && in_array('itinerary_description', $importable_content) && isset($day['notes']) && '' !== $day['notes']) {
628 628
 							$current_day['description'] = strip_tags($day['notes']);
629
-						}else{
629
+						}else {
630 630
 							$current_day['description'] = '';
631 631
 						}
632 632
 
633 633
 						//Itinerary Gallery
634
-						if(false !== $importable_content && in_array('itinerary_gallery',$importable_content) && isset($day['images'])){
634
+						if (false !== $importable_content && in_array('itinerary_gallery', $importable_content) && isset($day['images'])) {
635 635
 							$current_day['featured_image'] = '';
636
-						}else{
636
+						}else {
637 637
 							$current_day['featured_image'] = '';
638 638
 						}
639 639
 
640 640
 						//Accommodation
641
-						if(false !== $current_accommodation){
641
+						if (false !== $current_accommodation) {
642 642
 							$current_day['accommodation_to_tour'] = array($current_accommodation);
643
-						}else{
643
+						}else {
644 644
 							$current_day['accommodation_to_tour'] = array();
645 645
 						}
646 646
 
647 647
 						//Destination
648
-						if(false !== $current_destination){
648
+						if (false !== $current_destination) {
649 649
 							$current_day['destination_to_tour'] = array($current_destination);
650
-						}else{
650
+						}else {
651 651
 							$current_day['destination_to_tour'] = array();
652 652
 						}
653 653
 
654 654
 						//Included
655
-						if(false !== $importable_content && in_array('itinerary_included',$importable_content) && isset($day['included']) && '' !== $day['included']){
655
+						if (false !== $importable_content && in_array('itinerary_included', $importable_content) && isset($day['included']) && '' !== $day['included']) {
656 656
 							$current_day['included'] = strip_tags($day['included']);
657
-						}else{
657
+						}else {
658 658
 							$current_day['description'] = '';
659 659
 						}
660 660
 
661 661
 						//Excluded
662
-						if(false !== $importable_content && in_array('itinerary_excluded',$importable_content) && isset($day['excluded']) && '' !== $day['excluded']){
662
+						if (false !== $importable_content && in_array('itinerary_excluded', $importable_content) && isset($day['excluded']) && '' !== $day['excluded']) {
663 663
 							$current_day['excluded'] = strip_tags($day['excluded']);
664
-						}else{
664
+						}else {
665 665
 							$current_day['excluded'] = '';
666 666
 						}
667 667
 
668
-						$this->set_itinerary_day($current_day,$id);
668
+						$this->set_itinerary_day($current_day, $id);
669 669
 						$day_counter++;
670 670
 					}
671 671
 
672
-				}else{
673
-					$day_counter = $day_counter + (int)$leg['nights'];
672
+				}else {
673
+					$day_counter = $day_counter + (int) $leg['nights'];
674 674
 				}
675 675
 
676 676
 			}
677 677
 
678 678
 			//If we are in the first leg,  and the destination was attached then save it as the departure field.
679
-			if( 0 === $leg_counter && false !== $current_destination){
679
+			if (0 === $leg_counter && false !== $current_destination) {
680 680
 				$departs_from = $current_destination;
681 681
 			}
682 682
 
683 683
 			//If its the last leg then save it as the ends in.
684
-			if( $leg_counter === (count($data['legs'])-2) && false !== $current_destination){
684
+			if ($leg_counter === (count($data['legs']) - 2) && false !== $current_destination) {
685 685
 				$ends_in = $current_destination;
686 686
 			}
687 687
 			$leg_counter++;
688 688
 		}
689 689
 
690
-		if(false !== $departs_from){
691
-			add_post_meta($id,'departs_from',$departs_from,true);
690
+		if (false !== $departs_from) {
691
+			add_post_meta($id, 'departs_from', $departs_from, true);
692 692
 		}
693
-		if(false !== $ends_in){
694
-			add_post_meta($id,'ends_in',$ends_in,true);
693
+		if (false !== $ends_in) {
694
+			add_post_meta($id, 'ends_in', $ends_in, true);
695 695
 		}
696 696
 	}
697 697
 
698 698
 	/**
699 699
 	 * Run through your routes and save the points as a KML file.
700 700
 	 */
701
-	public function process_map_points($data,$id) {
701
+	public function process_map_points($data, $id) {
702 702
 
703
-	    if(!empty($data['routes'])){
703
+	    if (!empty($data['routes'])) {
704 704
 
705
-	        delete_post_meta($id,'wetu_map_points');
705
+	        delete_post_meta($id, 'wetu_map_points');
706 706
 
707 707
 	        $points = array();
708 708
 
709
-	        foreach($data['routes'] as $route){
709
+	        foreach ($data['routes'] as $route) {
710 710
 
711 711
 
712
-	            if(isset($route['points']) && '' !== $route['points']){
712
+	            if (isset($route['points']) && '' !== $route['points']) {
713 713
 
714
-	                $temp_points = explode(';',$route['points']);
714
+	                $temp_points = explode(';', $route['points']);
715 715
 	                $point_counter = count($temp_points);
716 716
 
717 717
 					for ($x = 0; $x <= $point_counter; $x++) {
718
-					    $y = $x+1;
718
+					    $y = $x + 1;
719 719
 						$points[] = $temp_points[$x].','.$temp_points[$y];
720 720
 						$x++;
721 721
 					}
722 722
 				}
723 723
             }
724
-            if(!empty($points)){
725
-				$this->save_custom_field(implode(' ',$points),'wetu_map_points',$id,false,true);
724
+            if (!empty($points)) {
725
+				$this->save_custom_field(implode(' ', $points), 'wetu_map_points', $id, false, true);
726 726
             }
727 727
         }
728 728
 
@@ -731,29 +731,29 @@  discard block
 block discarded – undo
731 731
 	/**
732 732
 	 * Set the Itinerary Day
733 733
 	 */
734
-	public function set_itinerary_day($day,$id) {
735
-        $this->save_custom_field($day,'itinerary',$id,false,false);
734
+	public function set_itinerary_day($day, $id) {
735
+        $this->save_custom_field($day, 'itinerary', $id, false, false);
736 736
 	}
737 737
 
738 738
 	/**
739 739
 	 * Set the price
740 740
 	 */
741
-	public function set_price($data,$id) {
741
+	public function set_price($data, $id) {
742 742
 	    //Price
743
-		if(isset($data['price']) && ''!== $data['price']){
743
+		if (isset($data['price']) && '' !== $data['price']) {
744 744
             $price = preg_replace("/[^0-9,.]/", "", $data['price']);
745
-            $this->save_custom_field($price,'price',$id);
745
+            $this->save_custom_field($price, 'price', $id);
746 746
 		}
747 747
 
748 748
 		//Price includes
749 749
 
750
-		if(isset($data['price_includes']) && ''!== $data['price_includes']){
751
-			$this->save_custom_field($data['price_includes'],'included',$id);
750
+		if (isset($data['price_includes']) && '' !== $data['price_includes']) {
751
+			$this->save_custom_field($data['price_includes'], 'included', $id);
752 752
 		}
753 753
 
754 754
         //Price Excludes
755
-		if(isset($data['price_excludes']) && ''!== $data['price_excludes']){
756
-			$this->save_custom_field($data['price_excludes'],'not_included',$id);
755
+		if (isset($data['price_excludes']) && '' !== $data['price_excludes']) {
756
+			$this->save_custom_field($data['price_excludes'], 'not_included', $id);
757 757
 		}
758 758
 
759 759
 	}
@@ -761,11 +761,11 @@  discard block
 block discarded – undo
761 761
 	/**
762 762
 	 * Set the duration
763 763
 	 */
764
-	public function set_duration($data,$id) {
765
-		if(isset($data['days']) && !empty($data['days'])){
764
+	public function set_duration($data, $id) {
765
+		if (isset($data['days']) && !empty($data['days'])) {
766 766
 			$price = $data['days'];
767 767
 			$price = preg_replace("/[^0-9,.]/", "", $price);
768
-			$this->save_custom_field($price,'duration',$id);
768
+			$this->save_custom_field($price, 'duration', $id);
769 769
 		}
770 770
 	}
771 771
 
@@ -773,27 +773,27 @@  discard block
 block discarded – undo
773 773
 	/**
774 774
 	 * Connects the Accommodation if its available
775 775
 	 */
776
-	public function set_accommodation($day,$id) {
776
+	public function set_accommodation($day, $id) {
777 777
 
778 778
 	    $ac_id = false;
779 779
 		$this->current_accommodation = $this->find_current_accommodation();
780 780
 		
781
-		if(isset($day['content_entity_id']) && !empty($day['content_entity_id'])){
781
+		if (isset($day['content_entity_id']) && !empty($day['content_entity_id'])) {
782 782
 
783
-			if(false !== $this->current_accommodation && !empty($this->current_accommodation) && array_key_exists($day['content_entity_id'],$this->current_accommodation)){
783
+			if (false !== $this->current_accommodation && !empty($this->current_accommodation) && array_key_exists($day['content_entity_id'], $this->current_accommodation)) {
784 784
                 $ac_id = $this->current_accommodation[$day['content_entity_id']];
785
-			}else{
785
+			}else {
786 786
 				$ac_id = wp_insert_post(array(
787 787
                     'post_type' => 'accommodation',
788 788
                     'post_status' => 'draft',
789 789
                     'post_title' => $day['content_entity_id']
790 790
                 ));
791
-				$this->save_custom_field($day['content_entity_id'],'lsx_wetu_id',$ac_id);
791
+				$this->save_custom_field($day['content_entity_id'], 'lsx_wetu_id', $ac_id);
792 792
 			}
793 793
 
794
-			if('' !== $ac_id && false !== $ac_id){
795
-			    $this->save_custom_field($ac_id,'accommodation_to_tour',$id,false,false);
796
-				$this->save_custom_field($id,'tour_to_accommodation',$ac_id,false,false);
794
+			if ('' !== $ac_id && false !== $ac_id) {
795
+			    $this->save_custom_field($ac_id, 'accommodation_to_tour', $id, false, false);
796
+				$this->save_custom_field($id, 'tour_to_accommodation', $ac_id, false, false);
797 797
             }
798 798
 		}
799 799
 		return $ac_id;
@@ -805,13 +805,13 @@  discard block
 block discarded – undo
805 805
      * @param $post_type string
806 806
      * @return boolean / array
807 807
 	 */
808
-	public function find_current_accommodation($post_type='accommodation') {
808
+	public function find_current_accommodation($post_type = 'accommodation') {
809 809
 		global $wpdb;
810 810
 		$accommodation = parent::find_current_accommodation($post_type);
811 811
 
812 812
 		$return = false;
813
-		if(!empty($accommodation)){
814
-		    foreach($accommodation as $key => $acc){
813
+		if (!empty($accommodation)) {
814
+		    foreach ($accommodation as $key => $acc) {
815 815
 				$return[$acc->meta_value] = $acc->post_id;
816 816
             }
817 817
         }
@@ -833,25 +833,25 @@  discard block
 block discarded – undo
833 833
 	 * @param $id string
834 834
 	 * @return boolean / string
835 835
 	 */
836
-	public function set_destination($day,$id) {
836
+	public function set_destination($day, $id) {
837 837
 		$dest_id = false;
838 838
 		$country_id = false;
839 839
 		$this->current_destinations = $this->find_current_destinations();
840 840
 
841
-		if(isset($day['destination_content_entity_id']) && !empty($day['destination_content_entity_id'])){
841
+		if (isset($day['destination_content_entity_id']) && !empty($day['destination_content_entity_id'])) {
842 842
 
843
-			if(false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($day['destination_content_entity_id'],$this->current_destinations)){
843
+			if (false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($day['destination_content_entity_id'], $this->current_destinations)) {
844 844
 				$dest_id = $this->current_destinations[$day['destination_content_entity_id']];
845 845
 
846 846
 				$potential_id = wp_get_post_parent_id($dest_id);
847
-				$country_wetu_id = get_post_meta($potential_id,'lsx_wetu_id',true);
848
-				if(false !== $country_wetu_id){
847
+				$country_wetu_id = get_post_meta($potential_id, 'lsx_wetu_id', true);
848
+				if (false !== $country_wetu_id) {
849 849
 					$this->set_country($country_wetu_id, $id);
850 850
                 }
851 851
 
852 852
 			}else {
853 853
 
854
-				$destination_json = file_get_contents("http://wetu.com/API/Pins/".$this->api_key."/Get?ids=" . $day['destination_content_entity_id']);
854
+				$destination_json = file_get_contents("http://wetu.com/API/Pins/".$this->api_key."/Get?ids=".$day['destination_content_entity_id']);
855 855
 
856 856
 				if ($destination_json) {
857 857
 					$destination_data = json_decode($destination_json, true);
@@ -860,12 +860,12 @@  discard block
 block discarded – undo
860 860
 
861 861
 					    $destination_title = $day['destination_content_entity_id'];
862 862
 
863
-					    if(isset($destination_data[0]['name'])){
863
+					    if (isset($destination_data[0]['name'])) {
864 864
 							$destination_title = $destination_data[0]['name'];
865 865
                         }
866 866
 
867
-					    if(isset($destination_data[0]['map_object_id']) && isset($destination_data[0]['position']['country_content_entity_id'])
868
-                            && $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id']){
867
+					    if (isset($destination_data[0]['map_object_id']) && isset($destination_data[0]['position']['country_content_entity_id'])
868
+                            && $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id']) {
869 869
 
870 870
 							$country_id = $this->set_country($destination_data[0]['position']['country_content_entity_id'], $id);
871 871
                         }
@@ -876,7 +876,7 @@  discard block
 block discarded – undo
876 876
 							'post_title' => $destination_title
877 877
 						);
878 878
 
879
-					    if(false !== $country_id){
879
+					    if (false !== $country_id) {
880 880
 							$dest_post['post_parent'] = $country_id;
881 881
                         }
882 882
 						$dest_id = wp_insert_post($dest_post);
@@ -909,9 +909,9 @@  discard block
 block discarded – undo
909 909
 
910 910
         if (false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($country_wetu_id, $this->current_destinations)) {
911 911
             $country_id = $this->current_destinations[$country_wetu_id];
912
-        } else {
912
+        }else {
913 913
 
914
-            $country_json = file_get_contents("http://wetu.com/API/Pins/".$this->api_key."/Get?ids=" . $country_wetu_id);
914
+            $country_json = file_get_contents("http://wetu.com/API/Pins/".$this->api_key."/Get?ids=".$country_wetu_id);
915 915
 
916 916
             if ($country_json) {
917 917
                 $country_data = json_decode($country_json, true);
Please login to merge, or discard this patch.