@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function set_variables() |
100 | 100 | { |
101 | - parent::set_variables(); |
|
101 | + parent::set_variables(); |
|
102 | 102 | |
103 | 103 | if ( false !== $this->api_username && false !== $this->api_password ) { |
104 | 104 | $this->url = 'https://wetu.com/API/Itinerary/'; |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | * Display the importer administration screen |
124 | 124 | */ |
125 | 125 | public function display_page() { |
126 | - ?> |
|
126 | + ?> |
|
127 | 127 | <div class="wrap"> |
128 | 128 | <?php $this->navigation('tour'); ?> |
129 | 129 | |
@@ -247,15 +247,15 @@ discard block |
||
247 | 247 | /** |
248 | 248 | * displays the options for the tours |
249 | 249 | */ |
250 | - public function tour_search_options() { |
|
251 | - ?> |
|
250 | + public function tour_search_options() { |
|
251 | + ?> |
|
252 | 252 | <p class="tour-search-options"> |
253 | 253 | <label for="type"><input class="content" checked type="radio" name="type[]" value="all" /> <?php _e('All','wetu-importer'); ?></label> |
254 | 254 | <label for="type"><input class="content" type="radio" name="type[]" value="sample" /> <?php _e('Sample','wetu-importer'); ?></label> |
255 | 255 | <label for="type"><input class="content" type="radio" name="type[]" value="personal" /> <?php _e('Personal','wetu-importer'); ?></label> |
256 | 256 | </p> |
257 | 257 | <?php |
258 | - } |
|
258 | + } |
|
259 | 259 | |
260 | 260 | /** |
261 | 261 | * search_form |
@@ -267,16 +267,16 @@ discard block |
||
267 | 267 | $result = $this->update_options(); |
268 | 268 | |
269 | 269 | if(true === $result){ |
270 | - echo '<span style="color:green;">'.esc_attr('Connected','wetu-importer').'</span>'; |
|
271 | - if(!isset($_GET['refresh_tours'])){ |
|
272 | - echo ' - <small><a href="'.admin_url('admin.php').'?page='.$this->plugin_slug.'&tab=tour&refresh_tours=true">'.esc_attr('Refresh','wetu-importer').'</a></small>'; |
|
273 | - } |
|
274 | - }else{ |
|
275 | - echo '<span style="color:red;">'.wp_kses_post($result).'</span>'; |
|
276 | - } |
|
270 | + echo '<span style="color:green;">'.esc_attr('Connected','wetu-importer').'</span>'; |
|
271 | + if(!isset($_GET['refresh_tours'])){ |
|
272 | + echo ' - <small><a href="'.admin_url('admin.php').'?page='.$this->plugin_slug.'&tab=tour&refresh_tours=true">'.esc_attr('Refresh','wetu-importer').'</a></small>'; |
|
273 | + } |
|
274 | + }else{ |
|
275 | + echo '<span style="color:red;">'.wp_kses_post($result).'</span>'; |
|
276 | + } |
|
277 | 277 | }else{ |
278 | 278 | echo '<span style="color:green;">'.esc_attr('Connected','wetu-importer').'</span> - <small><a href="'.admin_url('admin.php').'?page='.$this->plugin_slug.'&tab=tour&refresh_tours=true">'.esc_attr('Refresh','wetu-importer').'</a></small>'; |
279 | - } |
|
279 | + } |
|
280 | 280 | echo '</h3></div>'; |
281 | 281 | } |
282 | 282 | |
@@ -288,8 +288,8 @@ discard block |
||
288 | 288 | $tours = json_decode($data, true); |
289 | 289 | |
290 | 290 | if(isset($tours['error'])){ |
291 | - return $tours['error']; |
|
292 | - }elseif (isset($tours['itineraries']) && !empty($tours['itineraries'])) { |
|
291 | + return $tours['error']; |
|
292 | + }elseif (isset($tours['itineraries']) && !empty($tours['itineraries'])) { |
|
293 | 293 | set_transient('lsx_ti_tours',$tours['itineraries'],60*60*2); |
294 | 294 | return true; |
295 | 295 | } |
@@ -492,71 +492,71 @@ discard block |
||
492 | 492 | $content = false; |
493 | 493 | } |
494 | 494 | |
495 | - $jdata=file_get_contents("http://wetu.com/API/Itinerary/V7/Get?id=".$wetu_id); |
|
495 | + $jdata=file_get_contents("http://wetu.com/API/Itinerary/V7/Get?id=".$wetu_id); |
|
496 | 496 | |
497 | - if($jdata) |
|
498 | - { |
|
497 | + if($jdata) |
|
498 | + { |
|
499 | 499 | $jdata=json_decode($jdata,true); |
500 | - if(!empty($jdata)) |
|
501 | - { |
|
502 | - $return = $this->import_row($jdata,$wetu_id,$post_id,$content); |
|
503 | - $this->format_completed_row($return); |
|
504 | - $this->cleanup_posts(); |
|
505 | - $this->attach_destination_images($content); |
|
506 | - } |
|
507 | - } |
|
500 | + if(!empty($jdata)) |
|
501 | + { |
|
502 | + $return = $this->import_row($jdata,$wetu_id,$post_id,$content); |
|
503 | + $this->format_completed_row($return); |
|
504 | + $this->cleanup_posts(); |
|
505 | + $this->attach_destination_images($content); |
|
506 | + } |
|
507 | + } |
|
508 | 508 | } |
509 | 509 | } |
510 | 510 | |
511 | 511 | /** |
512 | 512 | * Connect to wetu |
513 | - * |
|
514 | - * @param $data array |
|
515 | - * @param $wetu_id string |
|
513 | + * |
|
514 | + * @param $data array |
|
515 | + * @param $wetu_id string |
|
516 | 516 | */ |
517 | 517 | public function import_row($data,$wetu_id,$id=0,$importable_content=false,$old1=false,$old2=false) { |
518 | - $post_name = $data_post_content = $data_post_excerpt = ''; |
|
519 | - $post = array( |
|
520 | - 'post_type' => 'tour', |
|
521 | - ); |
|
518 | + $post_name = $data_post_content = $data_post_excerpt = ''; |
|
519 | + $post = array( |
|
520 | + 'post_type' => 'tour', |
|
521 | + ); |
|
522 | 522 | |
523 | - //Set the post_content |
|
523 | + //Set the post_content |
|
524 | 524 | $content_used_general_description = false; |
525 | - if(false !== $importable_content && in_array('description',$importable_content)){ |
|
526 | - $data_post_content = ''; |
|
527 | - |
|
528 | - if(isset($data['description'])){ |
|
529 | - $data_post_content = $data['description']; |
|
530 | - }elseif(isset($data['summary'])){ |
|
531 | - $data_post_content = $data['summary']; |
|
532 | - } |
|
533 | - $post['post_content'] = $data_post_content; |
|
534 | - } |
|
535 | - |
|
536 | - //Create or update the post |
|
537 | - if(false !== $id && '0' !== $id){ |
|
538 | - $post['ID'] = $id; |
|
539 | - $post['post_status'] = 'publish'; |
|
540 | - $id = wp_update_post($post); |
|
541 | - $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
542 | - update_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified']),$prev_date); |
|
543 | - }else{ |
|
544 | - |
|
545 | - //Set the name |
|
546 | - if(isset($data['name'])){ |
|
547 | - $post_name = wp_unique_post_slug(sanitize_title($data['name']),$id, 'draft', 'tour', 0); |
|
548 | - } |
|
549 | - $post['post_name'] = $post_name; |
|
550 | - $post['post_title'] = $data['name']; |
|
551 | - $post['post_status'] = 'publish'; |
|
552 | - $id = wp_insert_post($post); |
|
553 | - |
|
554 | - //Save the WETU ID and the Last date it was modified. |
|
555 | - if(false !== $id){ |
|
556 | - add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
557 | - add_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified'])); |
|
558 | - } |
|
559 | - } |
|
525 | + if(false !== $importable_content && in_array('description',$importable_content)){ |
|
526 | + $data_post_content = ''; |
|
527 | + |
|
528 | + if(isset($data['description'])){ |
|
529 | + $data_post_content = $data['description']; |
|
530 | + }elseif(isset($data['summary'])){ |
|
531 | + $data_post_content = $data['summary']; |
|
532 | + } |
|
533 | + $post['post_content'] = $data_post_content; |
|
534 | + } |
|
535 | + |
|
536 | + //Create or update the post |
|
537 | + if(false !== $id && '0' !== $id){ |
|
538 | + $post['ID'] = $id; |
|
539 | + $post['post_status'] = 'publish'; |
|
540 | + $id = wp_update_post($post); |
|
541 | + $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
542 | + update_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified']),$prev_date); |
|
543 | + }else{ |
|
544 | + |
|
545 | + //Set the name |
|
546 | + if(isset($data['name'])){ |
|
547 | + $post_name = wp_unique_post_slug(sanitize_title($data['name']),$id, 'draft', 'tour', 0); |
|
548 | + } |
|
549 | + $post['post_name'] = $post_name; |
|
550 | + $post['post_title'] = $data['name']; |
|
551 | + $post['post_status'] = 'publish'; |
|
552 | + $id = wp_insert_post($post); |
|
553 | + |
|
554 | + //Save the WETU ID and the Last date it was modified. |
|
555 | + if(false !== $id){ |
|
556 | + add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
557 | + add_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified'])); |
|
558 | + } |
|
559 | + } |
|
560 | 560 | |
561 | 561 | |
562 | 562 | //Set the price |
@@ -569,15 +569,15 @@ discard block |
||
569 | 569 | $this->set_duration($data,$id); |
570 | 570 | } |
571 | 571 | |
572 | - if(false !== $importable_content && in_array('itineraries',$importable_content) && isset($data['legs']) && !empty($data['legs'])){ |
|
573 | - $this->process_itineraries($data,$id,$importable_content); |
|
574 | - } |
|
572 | + if(false !== $importable_content && in_array('itineraries',$importable_content) && isset($data['legs']) && !empty($data['legs'])){ |
|
573 | + $this->process_itineraries($data,$id,$importable_content); |
|
574 | + } |
|
575 | 575 | |
576 | 576 | if(in_array('map',$importable_content) && isset($data['routes']) && !empty($data['routes'])){ |
577 | 577 | $this->set_map_data($data,$id); |
578 | 578 | } |
579 | 579 | |
580 | - return $id; |
|
580 | + return $id; |
|
581 | 581 | } |
582 | 582 | |
583 | 583 | /** |
@@ -739,17 +739,17 @@ discard block |
||
739 | 739 | * Set the Itinerary Day |
740 | 740 | */ |
741 | 741 | public function set_itinerary_day($day,$id) { |
742 | - $this->save_custom_field($day,'itinerary',$id,false,false); |
|
742 | + $this->save_custom_field($day,'itinerary',$id,false,false); |
|
743 | 743 | } |
744 | 744 | |
745 | 745 | /** |
746 | 746 | * Set the price |
747 | 747 | */ |
748 | 748 | public function set_price($data,$id) { |
749 | - //Price |
|
749 | + //Price |
|
750 | 750 | if(isset($data['price']) && ''!== $data['price']){ |
751 | - $price = preg_replace("/[^0-9,.]/", "", $data['price']); |
|
752 | - $this->save_custom_field($price,'price',$id); |
|
751 | + $price = preg_replace("/[^0-9,.]/", "", $data['price']); |
|
752 | + $this->save_custom_field($price,'price',$id); |
|
753 | 753 | } |
754 | 754 | |
755 | 755 | //Price includes |
@@ -757,7 +757,7 @@ discard block |
||
757 | 757 | $this->save_custom_field($data['price_includes'],'included',$id); |
758 | 758 | } |
759 | 759 | |
760 | - //Price Excludes |
|
760 | + //Price Excludes |
|
761 | 761 | if(isset($data['price_excludes']) && ''!== $data['price_excludes']){ |
762 | 762 | $this->save_custom_field($data['price_excludes'],'not_included',$id); |
763 | 763 | } |
@@ -780,35 +780,35 @@ discard block |
||
780 | 780 | */ |
781 | 781 | public function set_accommodation($day,$id) { |
782 | 782 | |
783 | - $ac_id = false; |
|
783 | + $ac_id = false; |
|
784 | 784 | $this->current_accommodation = $this->find_current_accommodation(); |
785 | 785 | |
786 | 786 | if(isset($day['content_entity_id']) && !empty($day['content_entity_id'])){ |
787 | 787 | |
788 | 788 | if(false !== $this->current_accommodation && !empty($this->current_accommodation) && array_key_exists($day['content_entity_id'],$this->current_accommodation)){ |
789 | - $ac_id = $this->current_accommodation[$day['content_entity_id']]; |
|
789 | + $ac_id = $this->current_accommodation[$day['content_entity_id']]; |
|
790 | 790 | }else{ |
791 | 791 | $ac_id = wp_insert_post(array( |
792 | - 'post_type' => 'accommodation', |
|
793 | - 'post_status' => 'draft', |
|
794 | - 'post_title' => $day['content_entity_id'] |
|
795 | - )); |
|
792 | + 'post_type' => 'accommodation', |
|
793 | + 'post_status' => 'draft', |
|
794 | + 'post_title' => $day['content_entity_id'] |
|
795 | + )); |
|
796 | 796 | $this->save_custom_field($day['content_entity_id'],'lsx_wetu_id',$ac_id); |
797 | 797 | } |
798 | 798 | |
799 | 799 | if('' !== $ac_id && false !== $ac_id){ |
800 | - $this->save_custom_field($ac_id,'accommodation_to_tour',$id,false,false); |
|
800 | + $this->save_custom_field($ac_id,'accommodation_to_tour',$id,false,false); |
|
801 | 801 | $this->save_custom_field($id,'tour_to_accommodation',$ac_id,false,false); |
802 | - } |
|
802 | + } |
|
803 | 803 | } |
804 | 804 | return $ac_id; |
805 | 805 | } |
806 | 806 | |
807 | 807 | /** |
808 | 808 | * Grab all the current accommodation posts via the lsx_wetu_id field. |
809 | - * |
|
810 | - * @param $post_type string |
|
811 | - * @return boolean / array |
|
809 | + * |
|
810 | + * @param $post_type string |
|
811 | + * @return boolean / array |
|
812 | 812 | */ |
813 | 813 | public function find_current_accommodation($post_type='accommodation') { |
814 | 814 | global $wpdb; |
@@ -816,16 +816,16 @@ discard block |
||
816 | 816 | |
817 | 817 | $return = false; |
818 | 818 | if(!empty($accommodation)){ |
819 | - foreach($accommodation as $key => $acc){ |
|
819 | + foreach($accommodation as $key => $acc){ |
|
820 | 820 | $return[$acc->meta_value] = $acc->post_id; |
821 | - } |
|
822 | - } |
|
821 | + } |
|
822 | + } |
|
823 | 823 | return $return; |
824 | 824 | } |
825 | 825 | |
826 | 826 | /** |
827 | 827 | * Grab all the current accommodation posts via the lsx_wetu_id field. |
828 | - * @return boolean / array |
|
828 | + * @return boolean / array |
|
829 | 829 | */ |
830 | 830 | public function find_current_destinations() { |
831 | 831 | return $this->find_current_accommodation('destination'); |
@@ -853,7 +853,7 @@ discard block |
||
853 | 853 | $country_wetu_id = get_post_meta($potential_id,'lsx_wetu_id',true); |
854 | 854 | if(false !== $country_wetu_id){ |
855 | 855 | $country_id = $this->set_country($country_wetu_id, $id); |
856 | - } |
|
856 | + } |
|
857 | 857 | |
858 | 858 | }else { |
859 | 859 | |
@@ -864,27 +864,27 @@ discard block |
||
864 | 864 | |
865 | 865 | if (!empty($destination_data) && !isset($destination_data['error'])) { |
866 | 866 | |
867 | - $destination_title = $day['destination_content_entity_id']; |
|
867 | + $destination_title = $day['destination_content_entity_id']; |
|
868 | 868 | |
869 | - if(isset($destination_data[0]['name'])){ |
|
869 | + if(isset($destination_data[0]['name'])){ |
|
870 | 870 | $destination_title = $destination_data[0]['name']; |
871 | - } |
|
871 | + } |
|
872 | 872 | |
873 | - if(isset($destination_data[0]['map_object_id']) && isset($destination_data[0]['position']['country_content_entity_id']) |
|
874 | - && $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id']){ |
|
873 | + if(isset($destination_data[0]['map_object_id']) && isset($destination_data[0]['position']['country_content_entity_id']) |
|
874 | + && $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id']){ |
|
875 | 875 | |
876 | 876 | $country_id = $this->set_country($destination_data[0]['position']['country_content_entity_id'], $id); |
877 | - } |
|
877 | + } |
|
878 | 878 | |
879 | - $dest_post = array( |
|
879 | + $dest_post = array( |
|
880 | 880 | 'post_type' => 'destination', |
881 | 881 | 'post_status' => 'draft', |
882 | 882 | 'post_title' => $destination_title |
883 | 883 | ); |
884 | 884 | |
885 | - if(false !== $country_id){ |
|
885 | + if(false !== $country_id){ |
|
886 | 886 | $dest_post['post_parent'] = $country_id; |
887 | - } |
|
887 | + } |
|
888 | 888 | $dest_id = wp_insert_post($dest_post); |
889 | 889 | |
890 | 890 | //Make sure we register the |
@@ -902,16 +902,16 @@ discard block |
||
902 | 902 | |
903 | 903 | // Save the first destination so we can grab the tour featured image and banner |
904 | 904 | if(0 === $leg_counter){ |
905 | - $this->destination_images[$id] = array($dest_id,$day['destination_content_entity_id']); |
|
906 | - } |
|
905 | + $this->destination_images[$id] = array($dest_id,$day['destination_content_entity_id']); |
|
906 | + } |
|
907 | 907 | |
908 | 908 | //Add this relation info so we can make sure certain items are set as countries. |
909 | 909 | if(0 !== $country_id && false !== $country_id){ |
910 | - $this->relation_meta[$dest_id] = $country_id; |
|
910 | + $this->relation_meta[$dest_id] = $country_id; |
|
911 | 911 | $this->relation_meta[$country_id] = 0; |
912 | - }else{ |
|
912 | + }else{ |
|
913 | 913 | $this->relation_meta[$dest_id] = 0; |
914 | - } |
|
914 | + } |
|
915 | 915 | } |
916 | 916 | } |
917 | 917 | return $dest_id; |
@@ -921,53 +921,53 @@ discard block |
||
921 | 921 | * Connects the destinations post type |
922 | 922 | * |
923 | 923 | * @param $dest_id string |
924 | - * @param $country_id array |
|
924 | + * @param $country_id array |
|
925 | 925 | * @param $id string |
926 | - * |
|
927 | - * @return string |
|
926 | + * |
|
927 | + * @return string |
|
928 | 928 | */ |
929 | 929 | public function set_country($country_wetu_id, $id) { |
930 | - $country_id = false; |
|
930 | + $country_id = false; |
|
931 | 931 | $this->current_destinations = $this->find_current_destinations(); |
932 | 932 | |
933 | - if (false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($country_wetu_id, $this->current_destinations)) { |
|
934 | - $country_id = $this->current_destinations[$country_wetu_id]; |
|
935 | - } else { |
|
933 | + if (false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($country_wetu_id, $this->current_destinations)) { |
|
934 | + $country_id = $this->current_destinations[$country_wetu_id]; |
|
935 | + } else { |
|
936 | 936 | |
937 | - $country_json = file_get_contents("http://wetu.com/API/Pins/".$this->api_key."/Get?ids=" . $country_wetu_id); |
|
937 | + $country_json = file_get_contents("http://wetu.com/API/Pins/".$this->api_key."/Get?ids=" . $country_wetu_id); |
|
938 | 938 | |
939 | - if ($country_json) { |
|
940 | - $country_data = json_decode($country_json, true); |
|
939 | + if ($country_json) { |
|
940 | + $country_data = json_decode($country_json, true); |
|
941 | 941 | |
942 | - if (!empty($country_data) && !isset($country_data['error'])) { |
|
942 | + if (!empty($country_data) && !isset($country_data['error'])) { |
|
943 | 943 | |
944 | 944 | //Format the title of the destination if its available, otherwise default to the WETU ID. |
945 | - $country_title = $country_wetu_id; |
|
946 | - if (isset($country_data[0]['name'])) { |
|
945 | + $country_title = $country_wetu_id; |
|
946 | + if (isset($country_data[0]['name'])) { |
|
947 | 947 | $country_title = $country_data[0]['name']; |
948 | - } |
|
948 | + } |
|
949 | 949 | |
950 | 950 | $country_id = wp_insert_post(array( |
951 | - 'post_type' => 'destination', |
|
952 | - 'post_status' => 'draft', |
|
953 | - 'post_title' => $country_title |
|
954 | - )); |
|
951 | + 'post_type' => 'destination', |
|
952 | + 'post_status' => 'draft', |
|
953 | + 'post_title' => $country_title |
|
954 | + )); |
|
955 | 955 | //add the country to the current destination stack |
956 | 956 | $this->current_destinations[$country_wetu_id] = $country_id; |
957 | 957 | |
958 | 958 | //Save the wetu field |
959 | - $this->save_custom_field($country_wetu_id, 'lsx_wetu_id', $country_id); |
|
960 | - } |
|
961 | - } |
|
962 | - } |
|
963 | - |
|
964 | - if ('' !== $country_id && false !== $country_id) { |
|
965 | - $this->save_custom_field($country_id, 'destination_to_tour', $id, false, false); |
|
966 | - $this->save_custom_field($id, 'tour_to_destination', $country_id, false, false); |
|
959 | + $this->save_custom_field($country_wetu_id, 'lsx_wetu_id', $country_id); |
|
960 | + } |
|
961 | + } |
|
962 | + } |
|
963 | + |
|
964 | + if ('' !== $country_id && false !== $country_id) { |
|
965 | + $this->save_custom_field($country_id, 'destination_to_tour', $id, false, false); |
|
966 | + $this->save_custom_field($id, 'tour_to_destination', $country_id, false, false); |
|
967 | 967 | $this->cleanup_posts[$country_id] = 'tour_to_destination'; |
968 | 968 | |
969 | - return $country_id; |
|
970 | - } |
|
969 | + return $country_id; |
|
970 | + } |
|
971 | 971 | } |
972 | 972 | |
973 | 973 | /** |
@@ -980,9 +980,9 @@ discard block |
||
980 | 980 | * @return string |
981 | 981 | */ |
982 | 982 | public function attach_destination_images($importable_content=array()) { |
983 | - if(false !== $this->destination_images){ |
|
983 | + if(false !== $this->destination_images){ |
|
984 | 984 | |
985 | - foreach($this->destination_images as $tour => $destination){ |
|
985 | + foreach($this->destination_images as $tour => $destination){ |
|
986 | 986 | |
987 | 987 | $url = 'https://wetu.com/API/Pins/' . $this->api_key; |
988 | 988 | $url_qs = ''; |
@@ -1003,7 +1003,7 @@ discard block |
||
1003 | 1003 | } |
1004 | 1004 | } |
1005 | 1005 | } |
1006 | - } |
|
1007 | - } |
|
1006 | + } |
|
1007 | + } |
|
1008 | 1008 | } |
1009 | 1009 | } |
1010 | 1010 | \ No newline at end of file |