@@ -97,7 +97,7 @@ discard block |
||
| 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 |
||
| 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 $this->navigation('tour'); ?> |
| 126 | 126 | |
@@ -249,16 +249,16 @@ discard block |
||
| 249 | 249 | $result = $this->update_options(); |
| 250 | 250 | |
| 251 | 251 | if(true === $result){ |
| 252 | - echo '<span style="color:green;">'.esc_attr('Connected','wetu-importer').'</span>'; |
|
| 253 | - if(!isset($_GET['refresh_tours'])){ |
|
| 254 | - echo ' - <small><a href="'.admin_url('admin.php').'?page='.$this->plugin_slug.'&tab=tour&refresh_tours=true">'.esc_attr('Refresh','wetu-importer').'</a></small>'; |
|
| 255 | - } |
|
| 256 | - }else{ |
|
| 257 | - echo '<span style="color:red;">'.wp_kses_post($result).'</span>'; |
|
| 258 | - } |
|
| 252 | + echo '<span style="color:green;">'.esc_attr('Connected','wetu-importer').'</span>'; |
|
| 253 | + if(!isset($_GET['refresh_tours'])){ |
|
| 254 | + echo ' - <small><a href="'.admin_url('admin.php').'?page='.$this->plugin_slug.'&tab=tour&refresh_tours=true">'.esc_attr('Refresh','wetu-importer').'</a></small>'; |
|
| 255 | + } |
|
| 256 | + }else{ |
|
| 257 | + echo '<span style="color:red;">'.wp_kses_post($result).'</span>'; |
|
| 258 | + } |
|
| 259 | 259 | }else{ |
| 260 | 260 | 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>'; |
| 261 | - } |
|
| 261 | + } |
|
| 262 | 262 | echo '</h3></div>'; |
| 263 | 263 | } |
| 264 | 264 | |
@@ -270,8 +270,8 @@ discard block |
||
| 270 | 270 | $tours = json_decode($data, true); |
| 271 | 271 | |
| 272 | 272 | if(isset($tours['error'])){ |
| 273 | - return $tours['error']; |
|
| 274 | - }elseif (isset($tours['itineraries']) && !empty($tours['itineraries'])) { |
|
| 273 | + return $tours['error']; |
|
| 274 | + }elseif (isset($tours['itineraries']) && !empty($tours['itineraries'])) { |
|
| 275 | 275 | set_transient('lsx_ti_tours',$tours['itineraries'],60*60*2); |
| 276 | 276 | return true; |
| 277 | 277 | } |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | $keyphrases = $_POST['keyword']; |
| 321 | 321 | }else{ |
| 322 | 322 | $keyphrases = array(0); |
| 323 | - } |
|
| 323 | + } |
|
| 324 | 324 | |
| 325 | 325 | if(!is_array($keyphrases)){ |
| 326 | 326 | $keyphrases = array($keyphrases); |
@@ -349,15 +349,15 @@ discard block |
||
| 349 | 349 | |
| 350 | 350 | foreach($tours as $row_key => $row){ |
| 351 | 351 | |
| 352 | - if(isset($row['is_disabled']) && true === $row['is_disabled']){ |
|
| 353 | - continue; |
|
| 354 | - } |
|
| 352 | + if(isset($row['is_disabled']) && true === $row['is_disabled']){ |
|
| 353 | + continue; |
|
| 354 | + } |
|
| 355 | 355 | |
| 356 | - /*if('Sample' === $row['type']){ |
|
| 356 | + /*if('Sample' === $row['type']){ |
|
| 357 | 357 | continue; |
| 358 | 358 | }*/ |
| 359 | 359 | |
| 360 | - //If this is a current tour, add its ID to the row. |
|
| 360 | + //If this is a current tour, add its ID to the row. |
|
| 361 | 361 | $row['post_id'] = 0; |
| 362 | 362 | if(false !== $current_tours && array_key_exists($row['identifier'], $current_tours)){ |
| 363 | 363 | $row['post_id'] = $current_tours[$row['identifier']]->post_id; |
@@ -366,31 +366,31 @@ discard block |
||
| 366 | 366 | //If we are searching for |
| 367 | 367 | if(false !== $post_status){ |
| 368 | 368 | |
| 369 | - if('import' === $post_status){ |
|
| 369 | + if('import' === $post_status){ |
|
| 370 | 370 | |
| 371 | 371 | if(0 !== $row['post_id']){ |
| 372 | - continue; |
|
| 372 | + continue; |
|
| 373 | 373 | }else{ |
| 374 | 374 | $searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row); |
| 375 | - } |
|
| 375 | + } |
|
| 376 | 376 | |
| 377 | 377 | |
| 378 | - }else{ |
|
| 378 | + }else{ |
|
| 379 | 379 | |
| 380 | 380 | if(0 === $row['post_id']){ |
| 381 | 381 | continue; |
| 382 | 382 | }else{ |
| 383 | 383 | $current_status = get_post_status($row['post_id']); |
| 384 | 384 | if($current_status !== $post_status){ |
| 385 | - continue; |
|
| 386 | - } |
|
| 385 | + continue; |
|
| 386 | + } |
|
| 387 | 387 | |
| 388 | 388 | } |
| 389 | 389 | $searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row); |
| 390 | 390 | |
| 391 | - } |
|
| 391 | + } |
|
| 392 | 392 | |
| 393 | - }else{ |
|
| 393 | + }else{ |
|
| 394 | 394 | //Search through each keyword. |
| 395 | 395 | foreach($keyphrases as $keyphrase){ |
| 396 | 396 | |
@@ -404,7 +404,7 @@ discard block |
||
| 404 | 404 | $searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row); |
| 405 | 405 | } |
| 406 | 406 | } |
| 407 | - } |
|
| 407 | + } |
|
| 408 | 408 | } |
| 409 | 409 | } |
| 410 | 410 | |
@@ -471,18 +471,18 @@ discard block |
||
| 471 | 471 | $content = false; |
| 472 | 472 | } |
| 473 | 473 | |
| 474 | - $jdata=file_get_contents("http://wetu.com/API/Itinerary/V7/Get?id=".$wetu_id); |
|
| 474 | + $jdata=file_get_contents("http://wetu.com/API/Itinerary/V7/Get?id=".$wetu_id); |
|
| 475 | 475 | |
| 476 | - if($jdata) |
|
| 477 | - { |
|
| 476 | + if($jdata) |
|
| 477 | + { |
|
| 478 | 478 | $jdata=json_decode($jdata,true); |
| 479 | - if(!empty($jdata)) |
|
| 480 | - { |
|
| 481 | - $return = $this->import_row($jdata,$wetu_id,$post_id,$content); |
|
| 482 | - $this->format_completed_row($return); |
|
| 483 | - $this->cleanup_posts(); |
|
| 484 | - } |
|
| 485 | - } |
|
| 479 | + if(!empty($jdata)) |
|
| 480 | + { |
|
| 481 | + $return = $this->import_row($jdata,$wetu_id,$post_id,$content); |
|
| 482 | + $this->format_completed_row($return); |
|
| 483 | + $this->cleanup_posts(); |
|
| 484 | + } |
|
| 485 | + } |
|
| 486 | 486 | die(); |
| 487 | 487 | } |
| 488 | 488 | |
@@ -490,53 +490,53 @@ discard block |
||
| 490 | 490 | |
| 491 | 491 | /** |
| 492 | 492 | * Connect to wetu |
| 493 | - * |
|
| 494 | - * @param $data array |
|
| 495 | - * @param $wetu_id string |
|
| 493 | + * |
|
| 494 | + * @param $data array |
|
| 495 | + * @param $wetu_id string |
|
| 496 | 496 | */ |
| 497 | 497 | public function import_row($data,$wetu_id,$id=0,$importable_content=false,$old1=false,$old2=false) { |
| 498 | - $post_name = $data_post_content = $data_post_excerpt = ''; |
|
| 499 | - $post = array( |
|
| 500 | - 'post_type' => 'tour', |
|
| 501 | - ); |
|
| 498 | + $post_name = $data_post_content = $data_post_excerpt = ''; |
|
| 499 | + $post = array( |
|
| 500 | + 'post_type' => 'tour', |
|
| 501 | + ); |
|
| 502 | 502 | |
| 503 | - //Set the post_content |
|
| 503 | + //Set the post_content |
|
| 504 | 504 | $content_used_general_description = false; |
| 505 | - if(false !== $importable_content && in_array('description',$importable_content)){ |
|
| 506 | - $data_post_content = ''; |
|
| 507 | - |
|
| 508 | - if(isset($data['description'])){ |
|
| 509 | - $data_post_content = $data['description']; |
|
| 510 | - }elseif(isset($data['summary'])){ |
|
| 511 | - $data_post_content = $data['summary']; |
|
| 512 | - } |
|
| 513 | - $post['post_content'] = $data_post_content; |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - //Create or update the post |
|
| 517 | - if(false !== $id && '0' !== $id){ |
|
| 518 | - $post['ID'] = $id; |
|
| 519 | - $post['post_status'] = 'publish'; |
|
| 520 | - $id = wp_update_post($post); |
|
| 521 | - $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
| 522 | - update_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified']),$prev_date); |
|
| 523 | - }else{ |
|
| 524 | - |
|
| 525 | - //Set the name |
|
| 526 | - if(isset($data['name'])){ |
|
| 527 | - $post_name = wp_unique_post_slug(sanitize_title($data['name']),$id, 'draft', 'tour', 0); |
|
| 528 | - } |
|
| 529 | - $post['post_name'] = $post_name; |
|
| 530 | - $post['post_title'] = $data['name']; |
|
| 531 | - $post['post_status'] = 'publish'; |
|
| 532 | - $id = wp_insert_post($post); |
|
| 533 | - |
|
| 534 | - //Save the WETU ID and the Last date it was modified. |
|
| 535 | - if(false !== $id){ |
|
| 536 | - add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
| 537 | - add_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified'])); |
|
| 538 | - } |
|
| 539 | - } |
|
| 505 | + if(false !== $importable_content && in_array('description',$importable_content)){ |
|
| 506 | + $data_post_content = ''; |
|
| 507 | + |
|
| 508 | + if(isset($data['description'])){ |
|
| 509 | + $data_post_content = $data['description']; |
|
| 510 | + }elseif(isset($data['summary'])){ |
|
| 511 | + $data_post_content = $data['summary']; |
|
| 512 | + } |
|
| 513 | + $post['post_content'] = $data_post_content; |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + //Create or update the post |
|
| 517 | + if(false !== $id && '0' !== $id){ |
|
| 518 | + $post['ID'] = $id; |
|
| 519 | + $post['post_status'] = 'publish'; |
|
| 520 | + $id = wp_update_post($post); |
|
| 521 | + $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
| 522 | + update_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified']),$prev_date); |
|
| 523 | + }else{ |
|
| 524 | + |
|
| 525 | + //Set the name |
|
| 526 | + if(isset($data['name'])){ |
|
| 527 | + $post_name = wp_unique_post_slug(sanitize_title($data['name']),$id, 'draft', 'tour', 0); |
|
| 528 | + } |
|
| 529 | + $post['post_name'] = $post_name; |
|
| 530 | + $post['post_title'] = $data['name']; |
|
| 531 | + $post['post_status'] = 'publish'; |
|
| 532 | + $id = wp_insert_post($post); |
|
| 533 | + |
|
| 534 | + //Save the WETU ID and the Last date it was modified. |
|
| 535 | + if(false !== $id){ |
|
| 536 | + add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
| 537 | + add_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified'])); |
|
| 538 | + } |
|
| 539 | + } |
|
| 540 | 540 | |
| 541 | 541 | |
| 542 | 542 | //Set the price |
@@ -549,9 +549,9 @@ discard block |
||
| 549 | 549 | $this->set_duration($data,$id); |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | - if(in_array('itineraries',$importable_content) && isset($data['legs']) && !empty($data['legs'])){ |
|
| 553 | - $this->process_itineraries($data,$id,$importable_content); |
|
| 554 | - } |
|
| 552 | + if(in_array('itineraries',$importable_content) && isset($data['legs']) && !empty($data['legs'])){ |
|
| 553 | + $this->process_itineraries($data,$id,$importable_content); |
|
| 554 | + } |
|
| 555 | 555 | |
| 556 | 556 | if(in_array('map',$importable_content) && isset($data['routes']) && !empty($data['routes'])){ |
| 557 | 557 | $this->process_map_points($data,$id); |
@@ -562,24 +562,24 @@ discard block |
||
| 562 | 562 | 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))){ |
| 563 | 563 | $this->find_attachments($id); |
| 564 | 564 | } |
| 565 | - //Set the featured image |
|
| 566 | - //TODO Test These |
|
| 567 | - if(false !== $importable_content && in_array('featured_image',$importable_content)){ |
|
| 568 | - $this->set_featured_image($data,$id); |
|
| 569 | - } |
|
| 565 | + //Set the featured image |
|
| 566 | + //TODO Test These |
|
| 567 | + if(false !== $importable_content && in_array('featured_image',$importable_content)){ |
|
| 568 | + $this->set_featured_image($data,$id); |
|
| 569 | + } |
|
| 570 | 570 | |
| 571 | 571 | //TODO Test These |
| 572 | - if(false !== $importable_content && in_array('banner_image',$importable_content)){ |
|
| 573 | - $this->set_banner_image($data,$id); |
|
| 574 | - } |
|
| 572 | + if(false !== $importable_content && in_array('banner_image',$importable_content)){ |
|
| 573 | + $this->set_banner_image($data,$id); |
|
| 574 | + } |
|
| 575 | 575 | |
| 576 | 576 | //TODO Test These |
| 577 | - //Import the main gallery |
|
| 578 | - if(false !== $importable_content && in_array('gallery',$importable_content)){ |
|
| 579 | - $this->create_main_gallery($data,$id); |
|
| 580 | - } |
|
| 577 | + //Import the main gallery |
|
| 578 | + if(false !== $importable_content && in_array('gallery',$importable_content)){ |
|
| 579 | + $this->create_main_gallery($data,$id); |
|
| 580 | + } |
|
| 581 | 581 | |
| 582 | - return $id; |
|
| 582 | + return $id; |
|
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | /** |
@@ -707,31 +707,31 @@ discard block |
||
| 707 | 707 | */ |
| 708 | 708 | public function process_map_points($data,$id) { |
| 709 | 709 | |
| 710 | - if(!empty($data['routes'])){ |
|
| 710 | + if(!empty($data['routes'])){ |
|
| 711 | 711 | |
| 712 | - delete_post_meta($id,'wetu_map_points'); |
|
| 712 | + delete_post_meta($id,'wetu_map_points'); |
|
| 713 | 713 | |
| 714 | - $points = array(); |
|
| 714 | + $points = array(); |
|
| 715 | 715 | |
| 716 | - foreach($data['routes'] as $route){ |
|
| 716 | + foreach($data['routes'] as $route){ |
|
| 717 | 717 | |
| 718 | 718 | |
| 719 | - if(isset($route['points']) && '' !== $route['points']){ |
|
| 719 | + if(isset($route['points']) && '' !== $route['points']){ |
|
| 720 | 720 | |
| 721 | - $temp_points = explode(';',$route['points']); |
|
| 722 | - $point_counter = count($temp_points); |
|
| 721 | + $temp_points = explode(';',$route['points']); |
|
| 722 | + $point_counter = count($temp_points); |
|
| 723 | 723 | |
| 724 | 724 | for ($x = 0; $x <= $point_counter; $x++) { |
| 725 | - $y = $x+1; |
|
| 725 | + $y = $x+1; |
|
| 726 | 726 | $points[] = $temp_points[$x].','.$temp_points[$y]; |
| 727 | 727 | $x++; |
| 728 | 728 | } |
| 729 | 729 | } |
| 730 | - } |
|
| 731 | - if(!empty($points)){ |
|
| 730 | + } |
|
| 731 | + if(!empty($points)){ |
|
| 732 | 732 | $this->save_custom_field(implode(' ',$points),'wetu_map_points',$id,false,true); |
| 733 | - } |
|
| 734 | - } |
|
| 733 | + } |
|
| 734 | + } |
|
| 735 | 735 | |
| 736 | 736 | } |
| 737 | 737 | |
@@ -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,11 +902,11 @@ discard block |
||
| 902 | 902 | |
| 903 | 903 | //Add this relation info so we can make sure certain items are set as countries. |
| 904 | 904 | if(0 !== $country_id && false !== $country_id){ |
| 905 | - $this->relation_meta[$dest_id] = $country_id; |
|
| 905 | + $this->relation_meta[$dest_id] = $country_id; |
|
| 906 | 906 | $this->relation_meta[$country_id] = 0; |
| 907 | - }else{ |
|
| 907 | + }else{ |
|
| 908 | 908 | $this->relation_meta[$dest_id] = 0; |
| 909 | - } |
|
| 909 | + } |
|
| 910 | 910 | } |
| 911 | 911 | } |
| 912 | 912 | return $dest_id; |
@@ -916,51 +916,51 @@ discard block |
||
| 916 | 916 | * Connects the destinations post type |
| 917 | 917 | * |
| 918 | 918 | * @param $dest_id string |
| 919 | - * @param $country_id array |
|
| 919 | + * @param $country_id array |
|
| 920 | 920 | * @param $id string |
| 921 | 921 | */ |
| 922 | 922 | public function set_country($country_wetu_id, $id) { |
| 923 | - $country_id = false; |
|
| 923 | + $country_id = false; |
|
| 924 | 924 | $this->current_destinations = $this->find_current_destinations(); |
| 925 | 925 | |
| 926 | - if (false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($country_wetu_id, $this->current_destinations)) { |
|
| 927 | - $country_id = $this->current_destinations[$country_wetu_id]; |
|
| 928 | - } else { |
|
| 926 | + if (false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($country_wetu_id, $this->current_destinations)) { |
|
| 927 | + $country_id = $this->current_destinations[$country_wetu_id]; |
|
| 928 | + } else { |
|
| 929 | 929 | |
| 930 | - $country_json = file_get_contents("http://wetu.com/API/Pins/".$this->api_key."/Get?ids=" . $country_wetu_id); |
|
| 930 | + $country_json = file_get_contents("http://wetu.com/API/Pins/".$this->api_key."/Get?ids=" . $country_wetu_id); |
|
| 931 | 931 | |
| 932 | - if ($country_json) { |
|
| 933 | - $country_data = json_decode($country_json, true); |
|
| 932 | + if ($country_json) { |
|
| 933 | + $country_data = json_decode($country_json, true); |
|
| 934 | 934 | |
| 935 | - if (!empty($country_data) && !isset($country_data['error'])) { |
|
| 935 | + if (!empty($country_data) && !isset($country_data['error'])) { |
|
| 936 | 936 | |
| 937 | 937 | //Format the title of the destination if its available, otherwise default to the WETU ID. |
| 938 | - $country_title = $country_wetu_id; |
|
| 939 | - if (isset($country_data[0]['name'])) { |
|
| 938 | + $country_title = $country_wetu_id; |
|
| 939 | + if (isset($country_data[0]['name'])) { |
|
| 940 | 940 | $country_title = $country_data[0]['name']; |
| 941 | - } |
|
| 941 | + } |
|
| 942 | 942 | |
| 943 | 943 | $country_id = wp_insert_post(array( |
| 944 | - 'post_type' => 'destination', |
|
| 945 | - 'post_status' => 'draft', |
|
| 946 | - 'post_title' => $country_title |
|
| 947 | - )); |
|
| 944 | + 'post_type' => 'destination', |
|
| 945 | + 'post_status' => 'draft', |
|
| 946 | + 'post_title' => $country_title |
|
| 947 | + )); |
|
| 948 | 948 | //add the country to the current destination stack |
| 949 | 949 | $this->current_destinations[$country_wetu_id] = $country_id; |
| 950 | 950 | |
| 951 | 951 | //Save the wetu field |
| 952 | - $this->save_custom_field($country_wetu_id, 'lsx_wetu_id', $country_id); |
|
| 953 | - } |
|
| 954 | - } |
|
| 955 | - } |
|
| 956 | - |
|
| 957 | - if ('' !== $country_id && false !== $country_id) { |
|
| 958 | - $this->save_custom_field($country_id, 'destination_to_tour', $id, false, false); |
|
| 959 | - $this->save_custom_field($id, 'tour_to_destination', $country_id, false, false); |
|
| 952 | + $this->save_custom_field($country_wetu_id, 'lsx_wetu_id', $country_id); |
|
| 953 | + } |
|
| 954 | + } |
|
| 955 | + } |
|
| 956 | + |
|
| 957 | + if ('' !== $country_id && false !== $country_id) { |
|
| 958 | + $this->save_custom_field($country_id, 'destination_to_tour', $id, false, false); |
|
| 959 | + $this->save_custom_field($id, 'tour_to_destination', $country_id, false, false); |
|
| 960 | 960 | $this->cleanup_posts[$country_id] = 'tour_to_destination'; |
| 961 | 961 | |
| 962 | - return $country_id; |
|
| 963 | - } |
|
| 962 | + return $country_id; |
|
| 963 | + } |
|
| 964 | 964 | } |
| 965 | 965 | } |
| 966 | 966 | $wetu_importer_tours = new WETU_Importer_Tours(); |
| 967 | 967 | \ No newline at end of file |