Completed
Push — master ( 4f6f4e...0094c4 )
by Warwick
02:24
created
classes/class-tours.php 1 patch
Indentation   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 	 */
98 98
 	public function set_variables()
99 99
 	{
100
-	    parent::set_variables();
100
+		parent::set_variables();
101 101
 
102 102
 		if ( false !== $this->api_username && false !== $this->api_password ) {
103 103
 			$this->url    = 'https://wetu.com/API/Itinerary/';
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 	 * Display the importer administration screen
123 123
 	 */
124 124
 	public function display_page() {
125
-        ?>
125
+		?>
126 126
         <div class="wrap">
127 127
 			<?php $this->navigation('tour'); ?>
128 128
 
@@ -254,20 +254,20 @@  discard block
 block discarded – undo
254 254
 			$result = $this->update_options();
255 255
 
256 256
 			if(true === $result){
257
-			    echo '<span style="color:green;">'.esc_attr('Connected','wetu-importer').'</span>';
258
-                echo ' - <small><a href="#">'.esc_attr('Refresh','wetu-importer').'</a></small>';
259
-            }else{
260
-			    echo '<span style="color:red;">'.wp_kses_post($result).'</span>';
261
-            }
257
+				echo '<span style="color:green;">'.esc_attr('Connected','wetu-importer').'</span>';
258
+				echo ' - <small><a href="#">'.esc_attr('Refresh','wetu-importer').'</a></small>';
259
+			}else{
260
+				echo '<span style="color:red;">'.wp_kses_post($result).'</span>';
261
+			}
262 262
 		}else{
263 263
 			echo '<span style="color:green;">'.esc_attr('Connected','wetu-importer').'</span> - <small><a href="#">'.esc_attr('Refresh','wetu-importer').'</a></small>';
264
-        }
264
+		}
265 265
 		echo '</h3>';
266 266
 
267 267
 		$form_options = get_option('lsx_ti_tours_api_options');
268 268
 		if(false === $form_options){
269 269
 			$form_options = array(0);
270
-        }
270
+		}
271 271
 		?>
272 272
         <form method="get" class="tour-refresh-form" action="<?php echo admin_url('admin.php'); ?>">
273 273
 
@@ -295,15 +295,15 @@  discard block
 block discarded – undo
295 295
 	 */
296 296
 	public function update_options() {
297 297
 
298
-	    $own = '';
299
-	    $options = array();
298
+		$own = '';
299
+		$options = array();
300 300
 
301
-	    delete_option('lsx_ti_tours_api_options');
301
+		delete_option('lsx_ti_tours_api_options');
302 302
 
303
-	    if(isset($_GET['own'])){
303
+		if(isset($_GET['own'])){
304 304
 			$this->url_qs .= '&own=true';
305 305
 			$options[] = 'own';
306
-        }
306
+		}
307 307
 
308 308
 		if(isset($_GET['type'])){
309 309
 			$this->url_qs .= '&type='.implode('',$_GET['type']);
@@ -319,8 +319,8 @@  discard block
 block discarded – undo
319 319
 		$tours = json_decode($data, true);
320 320
 
321 321
 		if(isset($tours['error'])){
322
-		    return $tours['error'];
323
-        }elseif (isset($tours['itineraries']) && !empty($tours['itineraries'])) {
322
+			return $tours['error'];
323
+		}elseif (isset($tours['itineraries']) && !empty($tours['itineraries'])) {
324 324
 			set_transient('lsx_ti_tours',$tours['itineraries'],60*60*2);
325 325
 			return true;
326 326
 		}
@@ -523,71 +523,71 @@  discard block
 block discarded – undo
523 523
 				$content = false;
524 524
 			}
525 525
 
526
-            $jdata=file_get_contents("http://wetu.com/API/Itinerary/V7/Get?id=".$wetu_id);
526
+			$jdata=file_get_contents("http://wetu.com/API/Itinerary/V7/Get?id=".$wetu_id);
527 527
 
528
-            if($jdata)
529
-            {
528
+			if($jdata)
529
+			{
530 530
 				$jdata=json_decode($jdata,true);
531
-                if(!empty($jdata))
532
-                {
533
-                	$return = $this->import_row($jdata,$wetu_id,$post_id,$content);
534
-                	$this->format_completed_row($return);
535
-                	$this->cleanup_posts();
536
-                	$this->attach_destination_images($content);
537
-                }
538
-            }
531
+				if(!empty($jdata))
532
+				{
533
+					$return = $this->import_row($jdata,$wetu_id,$post_id,$content);
534
+					$this->format_completed_row($return);
535
+					$this->cleanup_posts();
536
+					$this->attach_destination_images($content);
537
+				}
538
+			}
539 539
 		}
540 540
 	}
541 541
 
542 542
 	/**
543 543
 	 * Connect to wetu
544
-     *
545
-     * @param $data array
546
-     * @param $wetu_id string
544
+	 *
545
+	 * @param $data array
546
+	 * @param $wetu_id string
547 547
 	 */
548 548
 	public function import_row($data,$wetu_id,$id=0,$importable_content=false,$old1=false,$old2=false) {
549
-        $post_name = $data_post_content = $data_post_excerpt = '';
550
-        $post = array(
551
-          'post_type'		=> 'tour',
552
-        );
549
+		$post_name = $data_post_content = $data_post_excerpt = '';
550
+		$post = array(
551
+		  'post_type'		=> 'tour',
552
+		);
553 553
 
554
-        //Set the post_content
554
+		//Set the post_content
555 555
 		$content_used_general_description = false;
556
-        if(false !== $importable_content && in_array('description',$importable_content)){
557
-            $data_post_content = '';
558
-
559
-            if(isset($data['description'])){
560
-                $data_post_content = $data['description'];
561
-            }elseif(isset($data['summary'])){
562
-                $data_post_content = $data['summary'];
563
-            }
564
-            $post['post_content'] = $data_post_content;
565
-        }
566
-
567
-        //Create or update the post
568
-        if(false !== $id && '0' !== $id){
569
-            $post['ID'] = $id;
570
-	        $post['post_status'] = 'publish';
571
-            $id = wp_update_post($post);
572
-            $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true);
573
-            update_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified']),$prev_date);
574
-        }else{
575
-
576
-            //Set the name
577
-            if(isset($data['name'])){
578
-                $post_name = wp_unique_post_slug(sanitize_title($data['name']),$id, 'draft', 'tour', 0);
579
-            }
580
-            $post['post_name'] = $post_name;
581
-            $post['post_title'] = $data['name'];
582
-            $post['post_status'] = 'publish';
583
-            $id = wp_insert_post($post);
584
-
585
-            //Save the WETU ID and the Last date it was modified.
586
-            if(false !== $id){
587
-                add_post_meta($id,'lsx_wetu_id',$wetu_id);
588
-                add_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified']));
589
-            }
590
-        }
556
+		if(false !== $importable_content && in_array('description',$importable_content)){
557
+			$data_post_content = '';
558
+
559
+			if(isset($data['description'])){
560
+				$data_post_content = $data['description'];
561
+			}elseif(isset($data['summary'])){
562
+				$data_post_content = $data['summary'];
563
+			}
564
+			$post['post_content'] = $data_post_content;
565
+		}
566
+
567
+		//Create or update the post
568
+		if(false !== $id && '0' !== $id){
569
+			$post['ID'] = $id;
570
+			$post['post_status'] = 'publish';
571
+			$id = wp_update_post($post);
572
+			$prev_date = get_post_meta($id,'lsx_wetu_modified_date',true);
573
+			update_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified']),$prev_date);
574
+		}else{
575
+
576
+			//Set the name
577
+			if(isset($data['name'])){
578
+				$post_name = wp_unique_post_slug(sanitize_title($data['name']),$id, 'draft', 'tour', 0);
579
+			}
580
+			$post['post_name'] = $post_name;
581
+			$post['post_title'] = $data['name'];
582
+			$post['post_status'] = 'publish';
583
+			$id = wp_insert_post($post);
584
+
585
+			//Save the WETU ID and the Last date it was modified.
586
+			if(false !== $id){
587
+				add_post_meta($id,'lsx_wetu_id',$wetu_id);
588
+				add_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified']));
589
+			}
590
+		}
591 591
 
592 592
 
593 593
 		//Set the price
@@ -600,15 +600,15 @@  discard block
 block discarded – undo
600 600
 			$this->set_duration($data,$id);
601 601
 		}
602 602
 
603
-        if(false !== $importable_content && in_array('itineraries',$importable_content) && isset($data['legs']) && !empty($data['legs'])){
604
-            $this->process_itineraries($data,$id,$importable_content);
605
-        }
603
+		if(false !== $importable_content && in_array('itineraries',$importable_content) && isset($data['legs']) && !empty($data['legs'])){
604
+			$this->process_itineraries($data,$id,$importable_content);
605
+		}
606 606
 
607 607
 		if(in_array('map',$importable_content) && isset($data['routes']) && !empty($data['routes'])){
608 608
 			$this->set_map_data($data,$id);
609 609
 		}
610 610
 
611
-        return $id;
611
+		return $id;
612 612
 	}
613 613
 
614 614
 	/**
@@ -770,17 +770,17 @@  discard block
 block discarded – undo
770 770
 	 * Set the Itinerary Day
771 771
 	 */
772 772
 	public function set_itinerary_day($day,$id) {
773
-        $this->save_custom_field($day,'itinerary',$id,false,false);
773
+		$this->save_custom_field($day,'itinerary',$id,false,false);
774 774
 	}
775 775
 
776 776
 	/**
777 777
 	 * Set the price
778 778
 	 */
779 779
 	public function set_price($data,$id) {
780
-	    //Price
780
+		//Price
781 781
 		if(isset($data['price']) && ''!== $data['price']){
782
-            $price = preg_replace("/[^0-9,.]/", "", $data['price']);
783
-            $this->save_custom_field($price,'price',$id);
782
+			$price = preg_replace("/[^0-9,.]/", "", $data['price']);
783
+			$this->save_custom_field($price,'price',$id);
784 784
 		}
785 785
 
786 786
 		//Price includes
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
 			$this->save_custom_field($data['price_includes'],'included',$id);
789 789
 		}
790 790
 
791
-        //Price Excludes
791
+		//Price Excludes
792 792
 		if(isset($data['price_excludes']) && ''!== $data['price_excludes']){
793 793
 			$this->save_custom_field($data['price_excludes'],'not_included',$id);
794 794
 		}
@@ -811,35 +811,35 @@  discard block
 block discarded – undo
811 811
 	 */
812 812
 	public function set_accommodation($day,$id) {
813 813
 
814
-	    $ac_id = false;
814
+		$ac_id = false;
815 815
 		$this->current_accommodation = $this->find_current_accommodation();
816 816
 		
817 817
 		if(isset($day['content_entity_id']) && !empty($day['content_entity_id'])){
818 818
 
819 819
 			if(false !== $this->current_accommodation && !empty($this->current_accommodation) && array_key_exists($day['content_entity_id'],$this->current_accommodation)){
820
-                $ac_id = $this->current_accommodation[$day['content_entity_id']];
820
+				$ac_id = $this->current_accommodation[$day['content_entity_id']];
821 821
 			}else{
822 822
 				$ac_id = wp_insert_post(array(
823
-                    'post_type' => 'accommodation',
824
-                    'post_status' => 'draft',
825
-                    'post_title' => $day['content_entity_id']
826
-                ));
823
+					'post_type' => 'accommodation',
824
+					'post_status' => 'draft',
825
+					'post_title' => $day['content_entity_id']
826
+				));
827 827
 				$this->save_custom_field($day['content_entity_id'],'lsx_wetu_id',$ac_id);
828 828
 			}
829 829
 
830 830
 			if('' !== $ac_id && false !== $ac_id){
831
-			    $this->save_custom_field($ac_id,'accommodation_to_tour',$id,false,false);
831
+				$this->save_custom_field($ac_id,'accommodation_to_tour',$id,false,false);
832 832
 				$this->save_custom_field($id,'tour_to_accommodation',$ac_id,false,false);
833
-            }
833
+			}
834 834
 		}
835 835
 		return $ac_id;
836 836
 	}
837 837
 
838 838
 	/**
839 839
 	 * Grab all the current accommodation posts via the lsx_wetu_id field.
840
-     *
841
-     * @param $post_type string
842
-     * @return boolean / array
840
+	 *
841
+	 * @param $post_type string
842
+	 * @return boolean / array
843 843
 	 */
844 844
 	public function find_current_accommodation($post_type='accommodation') {
845 845
 		global $wpdb;
@@ -847,16 +847,16 @@  discard block
 block discarded – undo
847 847
 
848 848
 		$return = false;
849 849
 		if(!empty($accommodation)){
850
-		    foreach($accommodation as $key => $acc){
850
+			foreach($accommodation as $key => $acc){
851 851
 				$return[$acc->meta_value] = $acc->post_id;
852
-            }
853
-        }
852
+			}
853
+		}
854 854
 		return $return;
855 855
 	}
856 856
 
857 857
 	/**
858 858
 	 * Grab all the current accommodation posts via the lsx_wetu_id field.
859
-     * @return boolean / array
859
+	 * @return boolean / array
860 860
 	 */
861 861
 	public function find_current_destinations() {
862 862
 		return $this->find_current_accommodation('destination');
@@ -884,7 +884,7 @@  discard block
 block discarded – undo
884 884
 				$country_wetu_id = get_post_meta($potential_id,'lsx_wetu_id',true);
885 885
 				if(false !== $country_wetu_id){
886 886
 					$country_id = $this->set_country($country_wetu_id, $id);
887
-                }
887
+				}
888 888
 
889 889
 			}else {
890 890
 
@@ -895,27 +895,27 @@  discard block
 block discarded – undo
895 895
 
896 896
 					if (!empty($destination_data) && !isset($destination_data['error'])) {
897 897
 
898
-					    $destination_title = $day['destination_content_entity_id'];
898
+						$destination_title = $day['destination_content_entity_id'];
899 899
 
900
-					    if(isset($destination_data[0]['name'])){
900
+						if(isset($destination_data[0]['name'])){
901 901
 							$destination_title = $destination_data[0]['name'];
902
-                        }
902
+						}
903 903
 
904
-					    if(isset($destination_data[0]['map_object_id']) && isset($destination_data[0]['position']['country_content_entity_id'])
905
-                            && $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id']){
904
+						if(isset($destination_data[0]['map_object_id']) && isset($destination_data[0]['position']['country_content_entity_id'])
905
+							&& $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id']){
906 906
 
907 907
 							$country_id = $this->set_country($destination_data[0]['position']['country_content_entity_id'], $id);
908
-                        }
908
+						}
909 909
 
910
-                        $dest_post = array(
910
+						$dest_post = array(
911 911
 							'post_type' => 'destination',
912 912
 							'post_status' => 'draft',
913 913
 							'post_title' => $destination_title
914 914
 						);
915 915
 
916
-					    if(false !== $country_id){
916
+						if(false !== $country_id){
917 917
 							$dest_post['post_parent'] = $country_id;
918
-                        }
918
+						}
919 919
 						$dest_id = wp_insert_post($dest_post);
920 920
 
921 921
 						//Make sure we register the
@@ -933,16 +933,16 @@  discard block
 block discarded – undo
933 933
 
934 934
 				// Save the first destination so we can grab the tour featured image and banner
935 935
 				if(0 === $leg_counter){
936
-				    $this->destination_images[$id] = array($dest_id,$day['destination_content_entity_id']);
937
-                }
936
+					$this->destination_images[$id] = array($dest_id,$day['destination_content_entity_id']);
937
+				}
938 938
 
939 939
 				//Add this relation info so we can make sure certain items are set as countries.
940 940
 				if(0 !== $country_id && false !== $country_id){
941
-                    $this->relation_meta[$dest_id] = $country_id;
941
+					$this->relation_meta[$dest_id] = $country_id;
942 942
 					$this->relation_meta[$country_id] = 0;
943
-                }else{
943
+				}else{
944 944
 					$this->relation_meta[$dest_id] = 0;
945
-                }
945
+				}
946 946
 			}
947 947
 		}
948 948
 		return $dest_id;
@@ -952,53 +952,53 @@  discard block
 block discarded – undo
952 952
 	 * Connects the destinations post type
953 953
 	 *
954 954
 	 * @param $dest_id string
955
-     * @param $country_id array
955
+	 * @param $country_id array
956 956
 	 * @param $id string
957
-     *
958
-     * @return string
957
+	 *
958
+	 * @return string
959 959
 	 */
960 960
 	public function set_country($country_wetu_id, $id) {
961
-	    $country_id = false;
961
+		$country_id = false;
962 962
 		$this->current_destinations = $this->find_current_destinations();
963 963
 
964
-        if (false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($country_wetu_id, $this->current_destinations)) {
965
-            $country_id = $this->current_destinations[$country_wetu_id];
966
-        } else {
964
+		if (false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($country_wetu_id, $this->current_destinations)) {
965
+			$country_id = $this->current_destinations[$country_wetu_id];
966
+		} else {
967 967
 
968
-            $country_json = file_get_contents("http://wetu.com/API/Pins/".$this->api_key."/Get?ids=" . $country_wetu_id);
968
+			$country_json = file_get_contents("http://wetu.com/API/Pins/".$this->api_key."/Get?ids=" . $country_wetu_id);
969 969
 
970
-            if ($country_json) {
971
-                $country_data = json_decode($country_json, true);
970
+			if ($country_json) {
971
+				$country_data = json_decode($country_json, true);
972 972
 
973
-                if (!empty($country_data) && !isset($country_data['error'])) {
973
+				if (!empty($country_data) && !isset($country_data['error'])) {
974 974
 
975 975
 					//Format the title of the destination if its available,  otherwise default to the WETU ID.
976
-                    $country_title = $country_wetu_id;
977
-                    if (isset($country_data[0]['name'])) {
976
+					$country_title = $country_wetu_id;
977
+					if (isset($country_data[0]['name'])) {
978 978
 						$country_title = $country_data[0]['name'];
979
-                    }
979
+					}
980 980
 
981 981
 					$country_id = wp_insert_post(array(
982
-                        'post_type' => 'destination',
983
-                        'post_status' => 'draft',
984
-                        'post_title' => $country_title
985
-                    ));
982
+						'post_type' => 'destination',
983
+						'post_status' => 'draft',
984
+						'post_title' => $country_title
985
+					));
986 986
 					//add the country to the current destination stack
987 987
 					$this->current_destinations[$country_wetu_id] = $country_id;
988 988
 
989 989
 					//Save the wetu field
990
-                    $this->save_custom_field($country_wetu_id, 'lsx_wetu_id', $country_id);
991
-                }
992
-            }
993
-        }
994
-
995
-        if ('' !== $country_id && false !== $country_id) {
996
-            $this->save_custom_field($country_id, 'destination_to_tour', $id, false, false);
997
-            $this->save_custom_field($id, 'tour_to_destination', $country_id, false, false);
990
+					$this->save_custom_field($country_wetu_id, 'lsx_wetu_id', $country_id);
991
+				}
992
+			}
993
+		}
994
+
995
+		if ('' !== $country_id && false !== $country_id) {
996
+			$this->save_custom_field($country_id, 'destination_to_tour', $id, false, false);
997
+			$this->save_custom_field($id, 'tour_to_destination', $country_id, false, false);
998 998
 			$this->cleanup_posts[$country_id] = 'tour_to_destination';
999 999
 
1000
-            return $country_id;
1001
-        }
1000
+			return $country_id;
1001
+		}
1002 1002
 	}
1003 1003
 
1004 1004
 	/**
@@ -1011,9 +1011,9 @@  discard block
 block discarded – undo
1011 1011
 	 * @return string
1012 1012
 	 */
1013 1013
 	public function attach_destination_images($importable_content=array()) {
1014
-	    if(false !== $this->destination_images){
1014
+		if(false !== $this->destination_images){
1015 1015
 
1016
-	        foreach($this->destination_images as $tour => $destination){
1016
+			foreach($this->destination_images as $tour => $destination){
1017 1017
 
1018 1018
 				$url = 'https://wetu.com/API/Pins/' . $this->api_key;
1019 1019
 				$url_qs = '';
@@ -1034,7 +1034,7 @@  discard block
 block discarded – undo
1034 1034
 						}
1035 1035
 					}
1036 1036
 				}
1037
-            }
1038
-        }
1037
+			}
1038
+		}
1039 1039
 	}
1040 1040
 }
1041 1041
\ No newline at end of file
Please login to merge, or discard this patch.