Completed
Push — master ( 29e8a9...4674aa )
by Warwick
02:46
created
classes/class-tours.php 1 patch
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.