@@ -51,7 +51,7 @@ |
||
| 51 | 51 | */ |
| 52 | 52 | public function display_page() { |
| 53 | 53 | global $post; |
| 54 | - ?> |
|
| 54 | + ?> |
|
| 55 | 55 | <div class="wrap"> |
| 56 | 56 | |
| 57 | 57 | <h3><span class="dashicons dashicons-admin-multisite"></span> <?php _e('Connect your Accommodation','wetu-importer'); ?></h3> |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * Display the importer administration screen |
| 38 | 38 | */ |
| 39 | 39 | public function display_page() { |
| 40 | - ?> |
|
| 40 | + ?> |
|
| 41 | 41 | <div class="wrap"> |
| 42 | 42 | |
| 43 | 43 | <h2><?php _e('Download new banners straight from WETU','wetu-importer'); ?></h2> |
@@ -211,14 +211,14 @@ discard block |
||
| 211 | 211 | $base = rawurlencode($base); |
| 212 | 212 | $type = get_post_mime_type($post_id); |
| 213 | 213 | switch ($type) { |
| 214 | - case 'image/jpeg': |
|
| 215 | - return $base . ".jpg"; break; |
|
| 216 | - case 'image/png': |
|
| 217 | - return $base . ".png"; break; |
|
| 218 | - case 'image/gif': |
|
| 219 | - return $base . ".gif"; break; |
|
| 220 | - default: |
|
| 221 | - return false; |
|
| 214 | + case 'image/jpeg': |
|
| 215 | + return $base . ".jpg"; break; |
|
| 216 | + case 'image/png': |
|
| 217 | + return $base . ".png"; break; |
|
| 218 | + case 'image/gif': |
|
| 219 | + return $base . ".gif"; break; |
|
| 220 | + default: |
|
| 221 | + return false; |
|
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | 224 | |
@@ -122,7 +122,7 @@ discard block |
||
| 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 screen_icon(); ?> |
| 128 | 128 | |
@@ -300,8 +300,8 @@ discard block |
||
| 300 | 300 | $accommodation = json_decode($data, true); |
| 301 | 301 | |
| 302 | 302 | if(isset($accommodation['error'])){ |
| 303 | - return $accommodation['error']; |
|
| 304 | - }elseif (isset($accommodation) && !empty($accommodation)) { |
|
| 303 | + return $accommodation['error']; |
|
| 304 | + }elseif (isset($accommodation) && !empty($accommodation)) { |
|
| 305 | 305 | set_transient('lsx_ti_accommodation',$accommodation,60*60*2); |
| 306 | 306 | return true; |
| 307 | 307 | } |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | $keyphrases = $_POST['keyword']; |
| 350 | 350 | }else{ |
| 351 | 351 | $keyphrases = array(0); |
| 352 | - } |
|
| 352 | + } |
|
| 353 | 353 | |
| 354 | 354 | if(!is_array($keyphrases)){ |
| 355 | 355 | $keyphrases = array($keyphrases); |
@@ -446,13 +446,13 @@ discard block |
||
| 446 | 446 | public function multineedle_stripos($haystack, $needles, $offset=0) { |
| 447 | 447 | $found = false; |
| 448 | 448 | $needle_count = count($needles); |
| 449 | - foreach($needles as $needle) { |
|
| 450 | - if(false !== stripos($haystack, $needle, $offset)){ |
|
| 451 | - $found[] = true; |
|
| 452 | - } |
|
| 453 | - } |
|
| 454 | - if(false !== $found && $needle_count === count($found)){ |
|
| 455 | - return true; |
|
| 449 | + foreach($needles as $needle) { |
|
| 450 | + if(false !== stripos($haystack, $needle, $offset)){ |
|
| 451 | + $found[] = true; |
|
| 452 | + } |
|
| 453 | + } |
|
| 454 | + if(false !== $found && $needle_count === count($found)){ |
|
| 455 | + return true; |
|
| 456 | 456 | }else{ |
| 457 | 457 | return false; |
| 458 | 458 | } |
@@ -521,16 +521,16 @@ discard block |
||
| 521 | 521 | $content = false; |
| 522 | 522 | } |
| 523 | 523 | |
| 524 | - $jdata = file_get_contents( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id ); |
|
| 525 | - if($jdata) |
|
| 526 | - { |
|
| 527 | - $adata=json_decode($jdata,true); |
|
| 528 | - if(!empty($adata)) |
|
| 529 | - { |
|
| 530 | - $return = $this->import_row($adata,$wetu_id,$post_id,$team_members,$content,$safari_brands); |
|
| 531 | - $this->format_completed_row($return); |
|
| 532 | - } |
|
| 533 | - } |
|
| 524 | + $jdata = file_get_contents( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id ); |
|
| 525 | + if($jdata) |
|
| 526 | + { |
|
| 527 | + $adata=json_decode($jdata,true); |
|
| 528 | + if(!empty($adata)) |
|
| 529 | + { |
|
| 530 | + $return = $this->import_row($adata,$wetu_id,$post_id,$team_members,$content,$safari_brands); |
|
| 531 | + $this->format_completed_row($return); |
|
| 532 | + } |
|
| 533 | + } |
|
| 534 | 534 | |
| 535 | 535 | die(); |
| 536 | 536 | } |
@@ -547,148 +547,148 @@ discard block |
||
| 547 | 547 | */ |
| 548 | 548 | public function import_row($data,$wetu_id,$id=0,$team_members=false,$importable_content=false,$safari_brands=false) { |
| 549 | 549 | |
| 550 | - if(trim($data[0]['type'])=='Accommodation') |
|
| 551 | - { |
|
| 552 | - $post_name = $data_post_content = $data_post_excerpt = ''; |
|
| 553 | - $post = array( |
|
| 554 | - 'post_type' => 'accommodation', |
|
| 555 | - ); |
|
| 556 | - |
|
| 557 | - $content_used_general_description = false; |
|
| 558 | - |
|
| 559 | - //Set the post_content |
|
| 560 | - if(false !== $importable_content && in_array('description',$importable_content)){ |
|
| 561 | - if(isset($data[0]['content']['extended_description'])) |
|
| 562 | - { |
|
| 563 | - $data_post_content = $data[0]['content']['extended_description']; |
|
| 564 | - }elseif(isset($data[0]['content']['general_description'])){ |
|
| 565 | - $data_post_content = $data[0]['content']['general_description']; |
|
| 566 | - $content_used_general_description = true; |
|
| 567 | - }elseif(isset($data[0]['content']['teaser_description'])){ |
|
| 568 | - $data_post_content = $data[0]['content']['teaser_description']; |
|
| 569 | - } |
|
| 570 | - $post['post_content'] = wp_strip_all_tags($data_post_content); |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - //set the post_excerpt |
|
| 574 | - if(false !== $importable_content && in_array('excerpt',$importable_content)){ |
|
| 575 | - if(isset($data[0]['content']['teaser_description'])){ |
|
| 576 | - $data_post_excerpt = $data[0]['content']['teaser_description']; |
|
| 577 | - }elseif(isset($data[0]['content']['general_description']) && false === $content_used_general_description){ |
|
| 578 | - $data_post_excerpt = $data[0]['content']['general_description']; |
|
| 579 | - } |
|
| 580 | - $post['post_excerpt'] = $data_post_excerpt; |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - if(false !== $id && '0' !== $id){ |
|
| 584 | - $post['ID'] = $id; |
|
| 550 | + if(trim($data[0]['type'])=='Accommodation') |
|
| 551 | + { |
|
| 552 | + $post_name = $data_post_content = $data_post_excerpt = ''; |
|
| 553 | + $post = array( |
|
| 554 | + 'post_type' => 'accommodation', |
|
| 555 | + ); |
|
| 556 | + |
|
| 557 | + $content_used_general_description = false; |
|
| 558 | + |
|
| 559 | + //Set the post_content |
|
| 560 | + if(false !== $importable_content && in_array('description',$importable_content)){ |
|
| 561 | + if(isset($data[0]['content']['extended_description'])) |
|
| 562 | + { |
|
| 563 | + $data_post_content = $data[0]['content']['extended_description']; |
|
| 564 | + }elseif(isset($data[0]['content']['general_description'])){ |
|
| 565 | + $data_post_content = $data[0]['content']['general_description']; |
|
| 566 | + $content_used_general_description = true; |
|
| 567 | + }elseif(isset($data[0]['content']['teaser_description'])){ |
|
| 568 | + $data_post_content = $data[0]['content']['teaser_description']; |
|
| 569 | + } |
|
| 570 | + $post['post_content'] = wp_strip_all_tags($data_post_content); |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + //set the post_excerpt |
|
| 574 | + if(false !== $importable_content && in_array('excerpt',$importable_content)){ |
|
| 575 | + if(isset($data[0]['content']['teaser_description'])){ |
|
| 576 | + $data_post_excerpt = $data[0]['content']['teaser_description']; |
|
| 577 | + }elseif(isset($data[0]['content']['general_description']) && false === $content_used_general_description){ |
|
| 578 | + $data_post_excerpt = $data[0]['content']['general_description']; |
|
| 579 | + } |
|
| 580 | + $post['post_excerpt'] = $data_post_excerpt; |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + if(false !== $id && '0' !== $id){ |
|
| 584 | + $post['ID'] = $id; |
|
| 585 | 585 | if(isset($data[0]['name'])){ |
| 586 | 586 | $post['post_title'] = $data[0]['name']; |
| 587 | - $post['post_status'] = 'publish'; |
|
| 587 | + $post['post_status'] = 'publish'; |
|
| 588 | 588 | $post['post_name'] = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'accommodation', 0); |
| 589 | 589 | } |
| 590 | - $id = wp_update_post($post); |
|
| 591 | - $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
| 592 | - update_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified']),$prev_date); |
|
| 593 | - }else{ |
|
| 594 | - |
|
| 595 | - //Set the name |
|
| 596 | - if(isset($data[0]['name'])){ |
|
| 597 | - $post_name = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'accommodation', 0); |
|
| 598 | - } |
|
| 599 | - $post['post_name'] = $post_name; |
|
| 600 | - $post['post_title'] = $data[0]['name']; |
|
| 601 | - $post['post_status'] = 'publish'; |
|
| 602 | - $id = wp_insert_post($post); |
|
| 603 | - |
|
| 604 | - //Save the WETU ID and the Last date it was modified. |
|
| 605 | - if(false !== $id){ |
|
| 606 | - add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
| 607 | - add_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified'])); |
|
| 608 | - } |
|
| 609 | - } |
|
| 610 | - //Setup some default for use in the import |
|
| 611 | - if(false !== $importable_content && (in_array('gallery',$importable_content) || in_array('banner_image',$importable_content) || in_array('featured_image',$importable_content))){ |
|
| 590 | + $id = wp_update_post($post); |
|
| 591 | + $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
| 592 | + update_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified']),$prev_date); |
|
| 593 | + }else{ |
|
| 594 | + |
|
| 595 | + //Set the name |
|
| 596 | + if(isset($data[0]['name'])){ |
|
| 597 | + $post_name = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'accommodation', 0); |
|
| 598 | + } |
|
| 599 | + $post['post_name'] = $post_name; |
|
| 600 | + $post['post_title'] = $data[0]['name']; |
|
| 601 | + $post['post_status'] = 'publish'; |
|
| 602 | + $id = wp_insert_post($post); |
|
| 603 | + |
|
| 604 | + //Save the WETU ID and the Last date it was modified. |
|
| 605 | + if(false !== $id){ |
|
| 606 | + add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
| 607 | + add_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified'])); |
|
| 608 | + } |
|
| 609 | + } |
|
| 610 | + //Setup some default for use in the import |
|
| 611 | + if(false !== $importable_content && (in_array('gallery',$importable_content) || in_array('banner_image',$importable_content) || in_array('featured_image',$importable_content))){ |
|
| 612 | 612 | $this->find_attachments($id); |
| 613 | 613 | } |
| 614 | 614 | |
| 615 | - //Set the team member if it is there |
|
| 616 | - if(post_type_exists('team') && false !== $team_members && '' !== $team_members){ |
|
| 617 | - $this->set_team_member($id,$team_members); |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - //Set the safari brand |
|
| 621 | - if(false !== $safari_brands && '' !== $safari_brands){ |
|
| 622 | - $this->set_safari_brands($id,$safari_brands); |
|
| 623 | - |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - if(class_exists('LSX_TO_Maps')){ |
|
| 627 | - $this->set_map_data($data,$id); |
|
| 628 | - $this->set_location_taxonomy($data,$id); |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - if(post_type_exists('destination') && false !== $importable_content && in_array('destination',$importable_content)){ |
|
| 632 | - $this->connect_destinations($data,$id); |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - if(false !== $importable_content && in_array('category',$importable_content)){ |
|
| 636 | - $this->set_taxonomy_style($data,$id); |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - //Set the Room Data |
|
| 640 | - if(false !== $importable_content && in_array('rooms',$importable_content)){ |
|
| 641 | - $this->set_room_data($data,$id); |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - //Set the rating |
|
| 645 | - if(false !== $importable_content && in_array('rating',$importable_content)){ |
|
| 646 | - $this->set_rating($data,$id); |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - //Set the checkin checkout data |
|
| 650 | - if(false !== $importable_content && in_array('checkin',$importable_content)){ |
|
| 651 | - $this->set_checkin_checkout($data,$id); |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - //Set the Spoken Languages |
|
| 655 | - if(false !== $importable_content && in_array('spoken_languages',$importable_content)){ |
|
| 656 | - $this->set_spoken_languages($data,$id); |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - //Set the friendly options |
|
| 660 | - if(false !== $importable_content && in_array('friendly',$importable_content)){ |
|
| 661 | - $this->set_friendly($data,$id); |
|
| 662 | - } |
|
| 663 | - |
|
| 664 | - //Set the special_interests |
|
| 665 | - if(false !== $importable_content && in_array('special_interests',$importable_content)){ |
|
| 666 | - $this->set_special_interests($data,$id); |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - //Import the videos |
|
| 670 | - if(false !== $importable_content && in_array('videos',$importable_content)){ |
|
| 671 | - $this->set_video_data($data,$id); |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - //Import the facilities |
|
| 675 | - if(false !== $importable_content && in_array('facilities',$importable_content)){ |
|
| 676 | - $this->set_facilities($data,$id); |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - //Set the featured image |
|
| 680 | - if(false !== $importable_content && in_array('featured_image',$importable_content)){ |
|
| 681 | - $this->set_featured_image($data,$id); |
|
| 682 | - } |
|
| 683 | - if(false !== $importable_content && in_array('banner_image',$importable_content)){ |
|
| 684 | - $this->set_banner_image($data,$id); |
|
| 685 | - } |
|
| 686 | - //Import the main gallery |
|
| 687 | - if(false !== $importable_content && in_array('gallery',$importable_content)){ |
|
| 688 | - $this->create_main_gallery($data,$id); |
|
| 689 | - } |
|
| 690 | - } |
|
| 691 | - return $id; |
|
| 615 | + //Set the team member if it is there |
|
| 616 | + if(post_type_exists('team') && false !== $team_members && '' !== $team_members){ |
|
| 617 | + $this->set_team_member($id,$team_members); |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + //Set the safari brand |
|
| 621 | + if(false !== $safari_brands && '' !== $safari_brands){ |
|
| 622 | + $this->set_safari_brands($id,$safari_brands); |
|
| 623 | + |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + if(class_exists('LSX_TO_Maps')){ |
|
| 627 | + $this->set_map_data($data,$id); |
|
| 628 | + $this->set_location_taxonomy($data,$id); |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + if(post_type_exists('destination') && false !== $importable_content && in_array('destination',$importable_content)){ |
|
| 632 | + $this->connect_destinations($data,$id); |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + if(false !== $importable_content && in_array('category',$importable_content)){ |
|
| 636 | + $this->set_taxonomy_style($data,$id); |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + //Set the Room Data |
|
| 640 | + if(false !== $importable_content && in_array('rooms',$importable_content)){ |
|
| 641 | + $this->set_room_data($data,$id); |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + //Set the rating |
|
| 645 | + if(false !== $importable_content && in_array('rating',$importable_content)){ |
|
| 646 | + $this->set_rating($data,$id); |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + //Set the checkin checkout data |
|
| 650 | + if(false !== $importable_content && in_array('checkin',$importable_content)){ |
|
| 651 | + $this->set_checkin_checkout($data,$id); |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + //Set the Spoken Languages |
|
| 655 | + if(false !== $importable_content && in_array('spoken_languages',$importable_content)){ |
|
| 656 | + $this->set_spoken_languages($data,$id); |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + //Set the friendly options |
|
| 660 | + if(false !== $importable_content && in_array('friendly',$importable_content)){ |
|
| 661 | + $this->set_friendly($data,$id); |
|
| 662 | + } |
|
| 663 | + |
|
| 664 | + //Set the special_interests |
|
| 665 | + if(false !== $importable_content && in_array('special_interests',$importable_content)){ |
|
| 666 | + $this->set_special_interests($data,$id); |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + //Import the videos |
|
| 670 | + if(false !== $importable_content && in_array('videos',$importable_content)){ |
|
| 671 | + $this->set_video_data($data,$id); |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + //Import the facilities |
|
| 675 | + if(false !== $importable_content && in_array('facilities',$importable_content)){ |
|
| 676 | + $this->set_facilities($data,$id); |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + //Set the featured image |
|
| 680 | + if(false !== $importable_content && in_array('featured_image',$importable_content)){ |
|
| 681 | + $this->set_featured_image($data,$id); |
|
| 682 | + } |
|
| 683 | + if(false !== $importable_content && in_array('banner_image',$importable_content)){ |
|
| 684 | + $this->set_banner_image($data,$id); |
|
| 685 | + } |
|
| 686 | + //Import the main gallery |
|
| 687 | + if(false !== $importable_content && in_array('gallery',$importable_content)){ |
|
| 688 | + $this->create_main_gallery($data,$id); |
|
| 689 | + } |
|
| 690 | + } |
|
| 691 | + return $id; |
|
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | /** |
@@ -698,7 +698,7 @@ discard block |
||
| 698 | 698 | |
| 699 | 699 | delete_post_meta($id, 'team_to_'.$this->tab_slug); |
| 700 | 700 | foreach($team_members as $team){ |
| 701 | - add_post_meta($id,'team_to_'.$this->tab_slug,$team); |
|
| 701 | + add_post_meta($id,'team_to_'.$this->tab_slug,$team); |
|
| 702 | 702 | } |
| 703 | 703 | } |
| 704 | 704 | |
@@ -707,7 +707,7 @@ discard block |
||
| 707 | 707 | */ |
| 708 | 708 | public function set_safari_brands($id,$safari_brands) { |
| 709 | 709 | foreach($safari_brands as $safari_brand){ |
| 710 | - wp_set_object_terms( $id, intval($safari_brand), 'accommodation-brand',true); |
|
| 710 | + wp_set_object_terms( $id, intval($safari_brand), 'accommodation-brand',true); |
|
| 711 | 711 | } |
| 712 | 712 | } |
| 713 | 713 | |
@@ -759,11 +759,11 @@ discard block |
||
| 759 | 759 | 'elevation' => '', |
| 760 | 760 | ); |
| 761 | 761 | if(false !== $id && '0' !== $id){ |
| 762 | - $prev = get_post_meta($id,'location',true); |
|
| 763 | - update_post_meta($id,'location',$location_data,$prev); |
|
| 764 | - }else{ |
|
| 765 | - add_post_meta($id,'location',$location_data,true); |
|
| 766 | - } |
|
| 762 | + $prev = get_post_meta($id,'location',true); |
|
| 763 | + update_post_meta($id,'location',$location_data,$prev); |
|
| 764 | + }else{ |
|
| 765 | + add_post_meta($id,'location',$location_data,true); |
|
| 766 | + } |
|
| 767 | 767 | } |
| 768 | 768 | } |
| 769 | 769 | /** |
@@ -777,35 +777,35 @@ discard block |
||
| 777 | 777 | if(isset($data[0]['position']['country'])){ |
| 778 | 778 | |
| 779 | 779 | if(!$term = term_exists(trim($data[0]['position']['country']), 'location')) |
| 780 | - { |
|
| 781 | - $term = wp_insert_term(trim($data[0]['position']['country']), 'location'); |
|
| 782 | - if ( is_wp_error($term) ){ |
|
| 783 | - echo $term->get_error_message(); |
|
| 784 | - } |
|
| 785 | - else { |
|
| 786 | - wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
| 787 | - } |
|
| 788 | - } |
|
| 789 | - else |
|
| 790 | - { |
|
| 791 | - wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
| 792 | - } |
|
| 793 | - $country_id = intval($term['term_id']); |
|
| 794 | - } |
|
| 780 | + { |
|
| 781 | + $term = wp_insert_term(trim($data[0]['position']['country']), 'location'); |
|
| 782 | + if ( is_wp_error($term) ){ |
|
| 783 | + echo $term->get_error_message(); |
|
| 784 | + } |
|
| 785 | + else { |
|
| 786 | + wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
| 787 | + } |
|
| 788 | + } |
|
| 789 | + else |
|
| 790 | + { |
|
| 791 | + wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
| 792 | + } |
|
| 793 | + $country_id = intval($term['term_id']); |
|
| 794 | + } |
|
| 795 | 795 | |
| 796 | 796 | if(isset($data[0]['position']['destination'])){ |
| 797 | 797 | |
| 798 | 798 | $tax_args = array('parent'=>$country_id); |
| 799 | 799 | if(!$term = term_exists(trim($data[0]['position']['destination']), 'location')) |
| 800 | - { |
|
| 801 | - $term = wp_insert_term(trim($data[0]['position']['destination']), 'location', $tax_args); |
|
| 802 | - if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
| 803 | - else { wp_set_object_terms( $id, intval($term['term_id']), 'location',true); } |
|
| 804 | - } |
|
| 805 | - else |
|
| 806 | - { |
|
| 807 | - wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
| 808 | - } |
|
| 800 | + { |
|
| 801 | + $term = wp_insert_term(trim($data[0]['position']['destination']), 'location', $tax_args); |
|
| 802 | + if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
| 803 | + else { wp_set_object_terms( $id, intval($term['term_id']), 'location',true); } |
|
| 804 | + } |
|
| 805 | + else |
|
| 806 | + { |
|
| 807 | + wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
| 808 | + } |
|
| 809 | 809 | } |
| 810 | 810 | } |
| 811 | 811 | } |
@@ -815,28 +815,28 @@ discard block |
||
| 815 | 815 | */ |
| 816 | 816 | public function connect_destinations($data,$id) { |
| 817 | 817 | if(isset($data[0]['position'])){ |
| 818 | - $destinations = false; |
|
| 819 | - if(isset($data[0]['position']['country'])){ |
|
| 820 | - $destinations['country'] = $data[0]['position']['country']; |
|
| 821 | - } |
|
| 822 | - if(isset($data[0]['position']['destination'])){ |
|
| 823 | - $destinations['destination'] = $data[0]['position']['destination']; |
|
| 824 | - } |
|
| 818 | + $destinations = false; |
|
| 819 | + if(isset($data[0]['position']['country'])){ |
|
| 820 | + $destinations['country'] = $data[0]['position']['country']; |
|
| 821 | + } |
|
| 822 | + if(isset($data[0]['position']['destination'])){ |
|
| 823 | + $destinations['destination'] = $data[0]['position']['destination']; |
|
| 824 | + } |
|
| 825 | 825 | |
| 826 | - if(false !== $destinations){ |
|
| 827 | - $prev_values = get_post_meta($id,'destination_to_accommodation',false); |
|
| 828 | - if(false === $prev_values || !is_array($prev_values)){ |
|
| 829 | - $prev_values = array(); |
|
| 830 | - } |
|
| 831 | - foreach($destinations as $key => $value){ |
|
| 832 | - $destination = get_page_by_title(ltrim(rtrim($value)), 'OBJECT', 'destination'); |
|
| 833 | - if (null !== $destination) { |
|
| 834 | - if(!in_array($destination->ID,$prev_values)){ |
|
| 835 | - add_post_meta($id,'destination_to_accommodation',$destination->ID,false); |
|
| 836 | - add_post_meta($destination->ID,'accommodation_to_destination',$id,false); |
|
| 837 | - } |
|
| 838 | - } |
|
| 839 | - } |
|
| 826 | + if(false !== $destinations){ |
|
| 827 | + $prev_values = get_post_meta($id,'destination_to_accommodation',false); |
|
| 828 | + if(false === $prev_values || !is_array($prev_values)){ |
|
| 829 | + $prev_values = array(); |
|
| 830 | + } |
|
| 831 | + foreach($destinations as $key => $value){ |
|
| 832 | + $destination = get_page_by_title(ltrim(rtrim($value)), 'OBJECT', 'destination'); |
|
| 833 | + if (null !== $destination) { |
|
| 834 | + if(!in_array($destination->ID,$prev_values)){ |
|
| 835 | + add_post_meta($id,'destination_to_accommodation',$destination->ID,false); |
|
| 836 | + add_post_meta($destination->ID,'accommodation_to_destination',$id,false); |
|
| 837 | + } |
|
| 838 | + } |
|
| 839 | + } |
|
| 840 | 840 | } |
| 841 | 841 | } |
| 842 | 842 | } |
@@ -848,15 +848,15 @@ discard block |
||
| 848 | 848 | $terms = false; |
| 849 | 849 | if(isset($data[0]['category'])){ |
| 850 | 850 | if(!$term = term_exists(trim($data[0]['category']), 'accommodation-type')) |
| 851 | - { |
|
| 852 | - $term = wp_insert_term(trim($data[0]['category']), 'accommodation-type'); |
|
| 853 | - if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
| 854 | - else { wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); } |
|
| 855 | - } |
|
| 856 | - else |
|
| 857 | - { |
|
| 858 | - wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); |
|
| 859 | - } |
|
| 851 | + { |
|
| 852 | + $term = wp_insert_term(trim($data[0]['category']), 'accommodation-type'); |
|
| 853 | + if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
| 854 | + else { wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); } |
|
| 855 | + } |
|
| 856 | + else |
|
| 857 | + { |
|
| 858 | + wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); |
|
| 859 | + } |
|
| 860 | 860 | } |
| 861 | 861 | } |
| 862 | 862 | |
@@ -880,25 +880,25 @@ discard block |
||
| 880 | 880 | $temp_room['type'] = 'room'; |
| 881 | 881 | |
| 882 | 882 | if(!empty($room['images']) && is_array($room['images'])){ |
| 883 | - $attachments_args = array( |
|
| 884 | - 'post_parent' => $id, |
|
| 885 | - 'post_status' => 'inherit', |
|
| 886 | - 'post_type' => 'attachment', |
|
| 887 | - 'order' => 'ASC', |
|
| 888 | - ); |
|
| 889 | - $attachments = new WP_Query($attachments_args); |
|
| 890 | - $found_attachments = array(); |
|
| 891 | - |
|
| 892 | - if($attachments->have_posts()){ |
|
| 893 | - foreach($attachments->posts as $attachment){ |
|
| 894 | - $found_attachments[] = str_replace(array('.jpg','.png','.jpeg'),'',$attachment->post_title); |
|
| 895 | - } |
|
| 896 | - } |
|
| 883 | + $attachments_args = array( |
|
| 884 | + 'post_parent' => $id, |
|
| 885 | + 'post_status' => 'inherit', |
|
| 886 | + 'post_type' => 'attachment', |
|
| 887 | + 'order' => 'ASC', |
|
| 888 | + ); |
|
| 889 | + $attachments = new WP_Query($attachments_args); |
|
| 890 | + $found_attachments = array(); |
|
| 891 | + |
|
| 892 | + if($attachments->have_posts()){ |
|
| 893 | + foreach($attachments->posts as $attachment){ |
|
| 894 | + $found_attachments[] = str_replace(array('.jpg','.png','.jpeg'),'',$attachment->post_title); |
|
| 895 | + } |
|
| 896 | + } |
|
| 897 | 897 | |
| 898 | 898 | $temp_room['gallery'] = array(); |
| 899 | 899 | foreach($room['images'] as $image_data){ |
| 900 | - $temp_room['gallery'][] = $this->attach_image($image_data,$id,$found_attachments); |
|
| 901 | - } |
|
| 900 | + $temp_room['gallery'][] = $this->attach_image($image_data,$id,$found_attachments); |
|
| 901 | + } |
|
| 902 | 902 | } |
| 903 | 903 | $rooms[] = $temp_room; |
| 904 | 904 | } |
@@ -907,7 +907,7 @@ discard block |
||
| 907 | 907 | delete_post_meta($id, 'units'); |
| 908 | 908 | } |
| 909 | 909 | foreach($rooms as $room){ |
| 910 | - add_post_meta($id,'units',$room,false); |
|
| 910 | + add_post_meta($id,'units',$room,false); |
|
| 911 | 911 | } |
| 912 | 912 | |
| 913 | 913 | if(isset($data[0]['features']) && isset($data[0]['features']['rooms'])){ |
@@ -917,11 +917,11 @@ discard block |
||
| 917 | 917 | } |
| 918 | 918 | |
| 919 | 919 | if(false !== $id && '0' !== $id){ |
| 920 | - $prev_rooms = get_post_meta($id,'number_of_rooms',true); |
|
| 921 | - update_post_meta($id,'number_of_rooms',$room_count,$prev_rooms); |
|
| 922 | - }else{ |
|
| 923 | - add_post_meta($id,'number_of_rooms',$room_count,true); |
|
| 924 | - } |
|
| 920 | + $prev_rooms = get_post_meta($id,'number_of_rooms',true); |
|
| 921 | + update_post_meta($id,'number_of_rooms',$room_count,$prev_rooms); |
|
| 922 | + }else{ |
|
| 923 | + add_post_meta($id,'number_of_rooms',$room_count,true); |
|
| 924 | + } |
|
| 925 | 925 | } |
| 926 | 926 | } |
| 927 | 927 | |
@@ -1030,7 +1030,7 @@ discard block |
||
| 1030 | 1030 | delete_post_meta($id, 'videos'); |
| 1031 | 1031 | } |
| 1032 | 1032 | foreach($videos as $video){ |
| 1033 | - add_post_meta($id,'videos',$video,false); |
|
| 1033 | + add_post_meta($id,'videos',$video,false); |
|
| 1034 | 1034 | } |
| 1035 | 1035 | } |
| 1036 | 1036 | } |
@@ -1059,17 +1059,17 @@ discard block |
||
| 1059 | 1059 | |
| 1060 | 1060 | function set_term($id=false,$name=false,$taxonomy=false,$parent=false){ |
| 1061 | 1061 | if(!$term = term_exists($name, $taxonomy)) |
| 1062 | - { |
|
| 1063 | - if(false !== $parent){ $parent = array('parent'=>$parent); } |
|
| 1064 | - $term = wp_insert_term(trim($name), $taxonomy,$parent); |
|
| 1065 | - if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
| 1066 | - else { wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); } |
|
| 1067 | - } |
|
| 1068 | - else |
|
| 1069 | - { |
|
| 1070 | - wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); |
|
| 1071 | - } |
|
| 1072 | - return $term['term_id']; |
|
| 1062 | + { |
|
| 1063 | + if(false !== $parent){ $parent = array('parent'=>$parent); } |
|
| 1064 | + $term = wp_insert_term(trim($name), $taxonomy,$parent); |
|
| 1065 | + if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
| 1066 | + else { wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); } |
|
| 1067 | + } |
|
| 1068 | + else |
|
| 1069 | + { |
|
| 1070 | + wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); |
|
| 1071 | + } |
|
| 1072 | + return $term['term_id']; |
|
| 1073 | 1073 | } |
| 1074 | 1074 | |
| 1075 | 1075 | /** |
@@ -1077,17 +1077,17 @@ discard block |
||
| 1077 | 1077 | */ |
| 1078 | 1078 | public function set_featured_image($data,$id) { |
| 1079 | 1079 | if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){ |
| 1080 | - $this->featured_image = $this->attach_image($data[0]['content']['images'][0],$id); |
|
| 1080 | + $this->featured_image = $this->attach_image($data[0]['content']['images'][0],$id); |
|
| 1081 | 1081 | |
| 1082 | - if(false !== $this->featured_image){ |
|
| 1083 | - delete_post_meta($id,'_thumbnail_id'); |
|
| 1084 | - add_post_meta($id,'_thumbnail_id',$this->featured_image,true); |
|
| 1082 | + if(false !== $this->featured_image){ |
|
| 1083 | + delete_post_meta($id,'_thumbnail_id'); |
|
| 1084 | + add_post_meta($id,'_thumbnail_id',$this->featured_image,true); |
|
| 1085 | 1085 | |
| 1086 | - if(!empty($this->gallery_meta) && !in_array($this->featured_image,$this->gallery_meta)){ |
|
| 1087 | - add_post_meta($id,'gallery',$this->featured_image,false); |
|
| 1088 | - $this->gallery_meta[] = $this->featured_image; |
|
| 1089 | - } |
|
| 1090 | - } |
|
| 1086 | + if(!empty($this->gallery_meta) && !in_array($this->featured_image,$this->gallery_meta)){ |
|
| 1087 | + add_post_meta($id,'gallery',$this->featured_image,false); |
|
| 1088 | + $this->gallery_meta[] = $this->featured_image; |
|
| 1089 | + } |
|
| 1090 | + } |
|
| 1091 | 1091 | } |
| 1092 | 1092 | } |
| 1093 | 1093 | |
@@ -1096,18 +1096,18 @@ discard block |
||
| 1096 | 1096 | */ |
| 1097 | 1097 | public function set_banner_image($data,$id) { |
| 1098 | 1098 | if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){ |
| 1099 | - $this->banner_image = $this->attach_image($data[0]['content']['images'][1],$id,array('width'=>'1920','height'=>'800','cropping'=>'c')); |
|
| 1100 | - |
|
| 1101 | - if(false !== $this->banner_image){ |
|
| 1102 | - delete_post_meta($id,'image_group'); |
|
| 1103 | - $new_banner = array('banner_image'=>array('cmb-field-0'=>$this->banner_image)); |
|
| 1104 | - add_post_meta($id,'image_group',$new_banner,true); |
|
| 1105 | - |
|
| 1106 | - if(!empty($this->gallery_meta) && !in_array($this->banner_image,$this->gallery_meta)){ |
|
| 1107 | - add_post_meta($id,'gallery',$this->banner_image,false); |
|
| 1108 | - $this->gallery_meta[] = $this->banner_image; |
|
| 1109 | - } |
|
| 1110 | - } |
|
| 1099 | + $this->banner_image = $this->attach_image($data[0]['content']['images'][1],$id,array('width'=>'1920','height'=>'800','cropping'=>'c')); |
|
| 1100 | + |
|
| 1101 | + if(false !== $this->banner_image){ |
|
| 1102 | + delete_post_meta($id,'image_group'); |
|
| 1103 | + $new_banner = array('banner_image'=>array('cmb-field-0'=>$this->banner_image)); |
|
| 1104 | + add_post_meta($id,'image_group',$new_banner,true); |
|
| 1105 | + |
|
| 1106 | + if(!empty($this->gallery_meta) && !in_array($this->banner_image,$this->gallery_meta)){ |
|
| 1107 | + add_post_meta($id,'gallery',$this->banner_image,false); |
|
| 1108 | + $this->gallery_meta[] = $this->banner_image; |
|
| 1109 | + } |
|
| 1110 | + } |
|
| 1111 | 1111 | } |
| 1112 | 1112 | } |
| 1113 | 1113 | |
@@ -1118,24 +1118,24 @@ discard block |
||
| 1118 | 1118 | |
| 1119 | 1119 | if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){ |
| 1120 | 1120 | |
| 1121 | - $counter = 0; |
|
| 1122 | - foreach($data[0]['content']['images'] as $image_data){ |
|
| 1123 | - if($counter === 0 && false !== $this->featured_image){continue;} |
|
| 1124 | - if($counter === 1 && false !== $this->banner_image){continue;} |
|
| 1125 | - |
|
| 1126 | - $this->gallery_meta[] = $temp_id = $this->attach_image($image_data,$id); |
|
| 1127 | - $counter++; |
|
| 1128 | - } |
|
| 1129 | - |
|
| 1130 | - if(!empty($this->gallery_meta)){ |
|
| 1131 | - delete_post_meta($id,'gallery'); |
|
| 1132 | - foreach($this->gallery_meta as $gallery_id){ |
|
| 1133 | - if(false !== $gallery_id && '' !== $gallery_id && !is_array($gallery_id)){ |
|
| 1134 | - add_post_meta($id,'gallery',$gallery_id,false); |
|
| 1135 | - } |
|
| 1136 | - } |
|
| 1137 | - } |
|
| 1138 | - } |
|
| 1121 | + $counter = 0; |
|
| 1122 | + foreach($data[0]['content']['images'] as $image_data){ |
|
| 1123 | + if($counter === 0 && false !== $this->featured_image){continue;} |
|
| 1124 | + if($counter === 1 && false !== $this->banner_image){continue;} |
|
| 1125 | + |
|
| 1126 | + $this->gallery_meta[] = $temp_id = $this->attach_image($image_data,$id); |
|
| 1127 | + $counter++; |
|
| 1128 | + } |
|
| 1129 | + |
|
| 1130 | + if(!empty($this->gallery_meta)){ |
|
| 1131 | + delete_post_meta($id,'gallery'); |
|
| 1132 | + foreach($this->gallery_meta as $gallery_id){ |
|
| 1133 | + if(false !== $gallery_id && '' !== $gallery_id && !is_array($gallery_id)){ |
|
| 1134 | + add_post_meta($id,'gallery',$gallery_id,false); |
|
| 1135 | + } |
|
| 1136 | + } |
|
| 1137 | + } |
|
| 1138 | + } |
|
| 1139 | 1139 | } |
| 1140 | 1140 | |
| 1141 | 1141 | /** |
@@ -1144,42 +1144,42 @@ discard block |
||
| 1144 | 1144 | public function attach_image($v=false,$parent_id,$image_sizes=false){ |
| 1145 | 1145 | if(false !== $v){ |
| 1146 | 1146 | $temp_fragment = explode('/',$v['url_fragment']); |
| 1147 | - $url_filename = $temp_fragment[count($temp_fragment)-1]; |
|
| 1148 | - $url_filename = str_replace(array('.jpg','.png','.jpeg'),'',$url_filename); |
|
| 1147 | + $url_filename = $temp_fragment[count($temp_fragment)-1]; |
|
| 1148 | + $url_filename = str_replace(array('.jpg','.png','.jpeg'),'',$url_filename); |
|
| 1149 | 1149 | |
| 1150 | - if(in_array($url_filename,$this->found_attachments)){ |
|
| 1151 | - return array_search($url_filename,$this->found_attachments); |
|
| 1152 | - } |
|
| 1150 | + if(in_array($url_filename,$this->found_attachments)){ |
|
| 1151 | + return array_search($url_filename,$this->found_attachments); |
|
| 1152 | + } |
|
| 1153 | 1153 | |
| 1154 | - $postdata=array(); |
|
| 1155 | - if(empty($v['label'])) |
|
| 1156 | - { |
|
| 1157 | - $v['label']=''; |
|
| 1158 | - } |
|
| 1159 | - if(!empty($v['description'])) |
|
| 1160 | - { |
|
| 1161 | - $desc=wp_strip_all_tags($v['description']); |
|
| 1162 | - $posdata=array('post_excerpt'=>$desc); |
|
| 1163 | - } |
|
| 1164 | - if(!empty($v['section'])) |
|
| 1165 | - { |
|
| 1166 | - $desc=wp_strip_all_tags($v['section']); |
|
| 1167 | - $posdata=array('post_excerpt'=>$desc); |
|
| 1168 | - } |
|
| 1169 | - |
|
| 1170 | - $attachID=NULL; |
|
| 1171 | - //Resizor - add option to setting if required |
|
| 1172 | - $fragment = str_replace(' ','%20',$v['url_fragment']); |
|
| 1173 | - $url = $this->get_scaling_url($image_sizes).$fragment; |
|
| 1174 | - $attachID = $this->attach_external_image2($url,$parent_id,'',$v['label'],$postdata); |
|
| 1175 | - |
|
| 1176 | - //echo($attachID.' add image'); |
|
| 1177 | - if($attachID!=NULL) |
|
| 1178 | - { |
|
| 1179 | - return $attachID; |
|
| 1180 | - } |
|
| 1181 | - } |
|
| 1182 | - return false; |
|
| 1154 | + $postdata=array(); |
|
| 1155 | + if(empty($v['label'])) |
|
| 1156 | + { |
|
| 1157 | + $v['label']=''; |
|
| 1158 | + } |
|
| 1159 | + if(!empty($v['description'])) |
|
| 1160 | + { |
|
| 1161 | + $desc=wp_strip_all_tags($v['description']); |
|
| 1162 | + $posdata=array('post_excerpt'=>$desc); |
|
| 1163 | + } |
|
| 1164 | + if(!empty($v['section'])) |
|
| 1165 | + { |
|
| 1166 | + $desc=wp_strip_all_tags($v['section']); |
|
| 1167 | + $posdata=array('post_excerpt'=>$desc); |
|
| 1168 | + } |
|
| 1169 | + |
|
| 1170 | + $attachID=NULL; |
|
| 1171 | + //Resizor - add option to setting if required |
|
| 1172 | + $fragment = str_replace(' ','%20',$v['url_fragment']); |
|
| 1173 | + $url = $this->get_scaling_url($image_sizes).$fragment; |
|
| 1174 | + $attachID = $this->attach_external_image2($url,$parent_id,'',$v['label'],$postdata); |
|
| 1175 | + |
|
| 1176 | + //echo($attachID.' add image'); |
|
| 1177 | + if($attachID!=NULL) |
|
| 1178 | + { |
|
| 1179 | + return $attachID; |
|
| 1180 | + } |
|
| 1181 | + } |
|
| 1182 | + return false; |
|
| 1183 | 1183 | } |
| 1184 | 1184 | public function attach_external_image2( $url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array() ) { |
| 1185 | 1185 | |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * Display the importer administration screen |
| 105 | 105 | */ |
| 106 | 106 | public function display_page() { |
| 107 | - ?> |
|
| 107 | + ?> |
|
| 108 | 108 | <div class="wrap"> |
| 109 | 109 | <?php screen_icon(); ?> |
| 110 | 110 | |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | $keyphrases = $_POST['keyword']; |
| 323 | 323 | }else{ |
| 324 | 324 | $keyphrases = array(0); |
| 325 | - } |
|
| 325 | + } |
|
| 326 | 326 | |
| 327 | 327 | if(!is_array($keyphrases)){ |
| 328 | 328 | $keyphrases = array($keyphrases); |
@@ -351,11 +351,11 @@ discard block |
||
| 351 | 351 | //If we are searching for |
| 352 | 352 | if(false !== $post_status){ |
| 353 | 353 | |
| 354 | - $current_status = get_post_status($row->post_id); |
|
| 355 | - if($current_status !== $post_status){ |
|
| 356 | - continue; |
|
| 357 | - } |
|
| 358 | - $searched_items[sanitize_title($row->name).'-'.$row->meta_value] = $this->format_row($row); |
|
| 354 | + $current_status = get_post_status($row->post_id); |
|
| 355 | + if($current_status !== $post_status){ |
|
| 356 | + continue; |
|
| 357 | + } |
|
| 358 | + $searched_items[sanitize_title($row->name).'-'.$row->meta_value] = $this->format_row($row); |
|
| 359 | 359 | |
| 360 | 360 | |
| 361 | 361 | }else{ |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | $team_members = false; |
| 438 | 438 | } |
| 439 | 439 | |
| 440 | - $safari_brands = false; |
|
| 440 | + $safari_brands = false; |
|
| 441 | 441 | |
| 442 | 442 | if(isset($_POST['content']) && is_array($_POST['content']) && !empty($_POST['content'])){ |
| 443 | 443 | $content = $_POST['content']; |
@@ -447,16 +447,16 @@ discard block |
||
| 447 | 447 | $content = false; |
| 448 | 448 | } |
| 449 | 449 | |
| 450 | - $jdata = file_get_contents( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id ); |
|
| 451 | - if($jdata) |
|
| 452 | - { |
|
| 453 | - $adata=json_decode($jdata,true); |
|
| 454 | - if(!empty($adata)) |
|
| 455 | - { |
|
| 456 | - $return = $this->import_row($adata,$wetu_id,$post_id,$team_members,$content,$safari_brands); |
|
| 457 | - $this->format_completed_row($return); |
|
| 458 | - } |
|
| 459 | - } |
|
| 450 | + $jdata = file_get_contents( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id ); |
|
| 451 | + if($jdata) |
|
| 452 | + { |
|
| 453 | + $adata=json_decode($jdata,true); |
|
| 454 | + if(!empty($adata)) |
|
| 455 | + { |
|
| 456 | + $return = $this->import_row($adata,$wetu_id,$post_id,$team_members,$content,$safari_brands); |
|
| 457 | + $this->format_completed_row($return); |
|
| 458 | + } |
|
| 459 | + } |
|
| 460 | 460 | |
| 461 | 461 | die(); |
| 462 | 462 | } |
@@ -468,82 +468,82 @@ discard block |
||
| 468 | 468 | */ |
| 469 | 469 | public function import_row($data,$wetu_id,$id=0,$team_members=false,$importable_content=false,$safari_brands=false) { |
| 470 | 470 | |
| 471 | - if(trim($data[0]['type'])=='Destination') |
|
| 472 | - { |
|
| 473 | - $post_name = $data_post_content = $data_post_excerpt = ''; |
|
| 474 | - $post = array( |
|
| 475 | - 'post_type' => 'destination', |
|
| 476 | - ); |
|
| 477 | - |
|
| 478 | - $content_used_general_description = false; |
|
| 479 | - |
|
| 480 | - //Set the post_content |
|
| 481 | - if(false !== $importable_content && in_array('description',$importable_content)){ |
|
| 482 | - if(isset($data[0]['content']['extended_description'])) |
|
| 483 | - { |
|
| 484 | - $data_post_content = $data[0]['content']['extended_description']; |
|
| 485 | - }elseif(isset($data[0]['content']['general_description'])){ |
|
| 486 | - $data_post_content = $data[0]['content']['general_description']; |
|
| 487 | - $content_used_general_description = true; |
|
| 488 | - }elseif(isset($data[0]['content']['teaser_description'])){ |
|
| 489 | - $data_post_content = $data[0]['content']['teaser_description']; |
|
| 490 | - } |
|
| 491 | - $post['post_content'] = wp_strip_all_tags($data_post_content); |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - //set the post_excerpt |
|
| 495 | - if(false !== $importable_content && in_array('excerpt',$importable_content)){ |
|
| 496 | - if(isset($data[0]['content']['teaser_description'])){ |
|
| 497 | - $data_post_excerpt = $data[0]['content']['teaser_description']; |
|
| 498 | - }elseif(isset($data[0]['content']['extended_description'])){ |
|
| 471 | + if(trim($data[0]['type'])=='Destination') |
|
| 472 | + { |
|
| 473 | + $post_name = $data_post_content = $data_post_excerpt = ''; |
|
| 474 | + $post = array( |
|
| 475 | + 'post_type' => 'destination', |
|
| 476 | + ); |
|
| 477 | + |
|
| 478 | + $content_used_general_description = false; |
|
| 479 | + |
|
| 480 | + //Set the post_content |
|
| 481 | + if(false !== $importable_content && in_array('description',$importable_content)){ |
|
| 482 | + if(isset($data[0]['content']['extended_description'])) |
|
| 483 | + { |
|
| 484 | + $data_post_content = $data[0]['content']['extended_description']; |
|
| 485 | + }elseif(isset($data[0]['content']['general_description'])){ |
|
| 486 | + $data_post_content = $data[0]['content']['general_description']; |
|
| 487 | + $content_used_general_description = true; |
|
| 488 | + }elseif(isset($data[0]['content']['teaser_description'])){ |
|
| 489 | + $data_post_content = $data[0]['content']['teaser_description']; |
|
| 490 | + } |
|
| 491 | + $post['post_content'] = wp_strip_all_tags($data_post_content); |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + //set the post_excerpt |
|
| 495 | + if(false !== $importable_content && in_array('excerpt',$importable_content)){ |
|
| 496 | + if(isset($data[0]['content']['teaser_description'])){ |
|
| 497 | + $data_post_excerpt = $data[0]['content']['teaser_description']; |
|
| 498 | + }elseif(isset($data[0]['content']['extended_description'])){ |
|
| 499 | 499 | $data_post_excerpt = $data[0]['content']['extended_description']; |
| 500 | 500 | }elseif(isset($data[0]['content']['general_description']) && false === $content_used_general_description){ |
| 501 | - $data_post_excerpt = $data[0]['content']['general_description']; |
|
| 502 | - } |
|
| 503 | - $post['post_excerpt'] = $data_post_excerpt; |
|
| 504 | - } |
|
| 501 | + $data_post_excerpt = $data[0]['content']['general_description']; |
|
| 502 | + } |
|
| 503 | + $post['post_excerpt'] = $data_post_excerpt; |
|
| 504 | + } |
|
| 505 | 505 | |
| 506 | - if(false !== $id && '0' !== $id){ |
|
| 507 | - $post['ID'] = $id; |
|
| 506 | + if(false !== $id && '0' !== $id){ |
|
| 507 | + $post['ID'] = $id; |
|
| 508 | 508 | if(isset($data[0]['name'])){ |
| 509 | 509 | $post['post_title'] = $data[0]['name']; |
| 510 | 510 | $post['post_status'] = 'publish'; |
| 511 | 511 | $post['post_name'] = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'destination', 0); |
| 512 | 512 | } |
| 513 | - $id = wp_update_post($post); |
|
| 514 | - $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
| 515 | - update_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified']),$prev_date); |
|
| 516 | - }else{ |
|
| 517 | - |
|
| 518 | - //Set the name |
|
| 519 | - if(isset($data[0]['name'])){ |
|
| 520 | - $post_name = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'destination', 0); |
|
| 521 | - } |
|
| 522 | - $post['post_name'] = $post_name; |
|
| 523 | - $post['post_title'] = $data[0]['name']; |
|
| 524 | - $post['post_status'] = 'publish'; |
|
| 525 | - $id = wp_insert_post($post); |
|
| 526 | - |
|
| 527 | - //Save the WETU ID and the Last date it was modified. |
|
| 528 | - if(false !== $id){ |
|
| 529 | - add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
| 530 | - add_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified'])); |
|
| 531 | - } |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - //Set the team member if it is there |
|
| 535 | - if(post_type_exists('team') && false !== $team_members && '' !== $team_members){ |
|
| 536 | - $this->set_team_member($id,$team_members); |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - if(class_exists('LSX_TO_Maps')){ |
|
| 540 | - $this->set_map_data($data,$id); |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - //Set the Room Data |
|
| 544 | - if(false !== $importable_content && in_array('videos',$importable_content)){ |
|
| 545 | - $this->set_video_data($data,$id); |
|
| 546 | - } |
|
| 513 | + $id = wp_update_post($post); |
|
| 514 | + $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
| 515 | + update_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified']),$prev_date); |
|
| 516 | + }else{ |
|
| 517 | + |
|
| 518 | + //Set the name |
|
| 519 | + if(isset($data[0]['name'])){ |
|
| 520 | + $post_name = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'destination', 0); |
|
| 521 | + } |
|
| 522 | + $post['post_name'] = $post_name; |
|
| 523 | + $post['post_title'] = $data[0]['name']; |
|
| 524 | + $post['post_status'] = 'publish'; |
|
| 525 | + $id = wp_insert_post($post); |
|
| 526 | + |
|
| 527 | + //Save the WETU ID and the Last date it was modified. |
|
| 528 | + if(false !== $id){ |
|
| 529 | + add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
| 530 | + add_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified'])); |
|
| 531 | + } |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + //Set the team member if it is there |
|
| 535 | + if(post_type_exists('team') && false !== $team_members && '' !== $team_members){ |
|
| 536 | + $this->set_team_member($id,$team_members); |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + if(class_exists('LSX_TO_Maps')){ |
|
| 540 | + $this->set_map_data($data,$id); |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + //Set the Room Data |
|
| 544 | + if(false !== $importable_content && in_array('videos',$importable_content)){ |
|
| 545 | + $this->set_video_data($data,$id); |
|
| 546 | + } |
|
| 547 | 547 | |
| 548 | 548 | //Set the Electricity |
| 549 | 549 | if(false !== $importable_content && in_array('electricity',$importable_content)){ |
@@ -570,8 +570,8 @@ discard block |
||
| 570 | 570 | $this->set_travel_info($data,$id,'climate'); |
| 571 | 571 | } |
| 572 | 572 | |
| 573 | - } |
|
| 574 | - return $id; |
|
| 573 | + } |
|
| 574 | + return $id; |
|
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | /** |
@@ -581,7 +581,7 @@ discard block |
||
| 581 | 581 | |
| 582 | 582 | delete_post_meta($id, 'team_to_'.$this->tab_slug); |
| 583 | 583 | foreach($team_members as $team){ |
| 584 | - add_post_meta($id,'team_to_'.$this->tab_slug,$team); |
|
| 584 | + add_post_meta($id,'team_to_'.$this->tab_slug,$team); |
|
| 585 | 585 | } |
| 586 | 586 | } |
| 587 | 587 | |
@@ -633,11 +633,11 @@ discard block |
||
| 633 | 633 | 'elevation' => '', |
| 634 | 634 | ); |
| 635 | 635 | if(false !== $id && '0' !== $id){ |
| 636 | - $prev = get_post_meta($id,'location',true); |
|
| 637 | - update_post_meta($id,'location',$location_data,$prev); |
|
| 638 | - }else{ |
|
| 639 | - add_post_meta($id,'location',$location_data,true); |
|
| 640 | - } |
|
| 636 | + $prev = get_post_meta($id,'location',true); |
|
| 637 | + update_post_meta($id,'location',$location_data,$prev); |
|
| 638 | + }else{ |
|
| 639 | + add_post_meta($id,'location',$location_data,true); |
|
| 640 | + } |
|
| 641 | 641 | } |
| 642 | 642 | } |
| 643 | 643 | |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | * Display the importer administration screen |
| 79 | 79 | */ |
| 80 | 80 | public function display_page() { |
| 81 | - ?> |
|
| 81 | + ?> |
|
| 82 | 82 | <div class="wrap"> |
| 83 | 83 | <?php screen_icon(); ?> |
| 84 | 84 | |
@@ -100,8 +100,8 @@ discard block |
||
| 100 | 100 | </ul> |
| 101 | 101 | |
| 102 | 102 | <?php } else { |
| 103 | - do_action('lsx_tour_importer_admin_tab_'.$_GET['tab']); |
|
| 104 | - } ?> |
|
| 103 | + do_action('lsx_tour_importer_admin_tab_'.$_GET['tab']); |
|
| 104 | + } ?> |
|
| 105 | 105 | </div> |
| 106 | 106 | <?php |
| 107 | 107 | } |
@@ -148,37 +148,37 @@ discard block |
||
| 148 | 148 | * set_taxonomy with some terms |
| 149 | 149 | */ |
| 150 | 150 | public function set_taxonomy($taxonomy,$terms,$id) { |
| 151 | - $result=array(); |
|
| 152 | - if(!empty($data)) |
|
| 153 | - { |
|
| 154 | - foreach($data as $k) |
|
| 155 | - { |
|
| 156 | - if($id) |
|
| 157 | - { |
|
| 158 | - if(!$term = term_exists(trim($k), $tax)) |
|
| 159 | - { |
|
| 160 | - $term = wp_insert_term(trim($k), $tax); |
|
| 161 | - if ( is_wp_error($term) ) |
|
| 162 | - { |
|
| 163 | - echo $term->get_error_message(); |
|
| 164 | - } |
|
| 165 | - else |
|
| 166 | - { |
|
| 167 | - wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - else |
|
| 171 | - { |
|
| 172 | - wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - else |
|
| 176 | - { |
|
| 177 | - $result[]=trim($k); |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - return $result; |
|
| 151 | + $result=array(); |
|
| 152 | + if(!empty($data)) |
|
| 153 | + { |
|
| 154 | + foreach($data as $k) |
|
| 155 | + { |
|
| 156 | + if($id) |
|
| 157 | + { |
|
| 158 | + if(!$term = term_exists(trim($k), $tax)) |
|
| 159 | + { |
|
| 160 | + $term = wp_insert_term(trim($k), $tax); |
|
| 161 | + if ( is_wp_error($term) ) |
|
| 162 | + { |
|
| 163 | + echo $term->get_error_message(); |
|
| 164 | + } |
|
| 165 | + else |
|
| 166 | + { |
|
| 167 | + wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + else |
|
| 171 | + { |
|
| 172 | + wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + else |
|
| 176 | + { |
|
| 177 | + $result[]=trim($k); |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + return $result; |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
@@ -188,21 +188,21 @@ discard block |
||
| 188 | 188 | if(post_type_exists('team')) { ?> |
| 189 | 189 | <ul> |
| 190 | 190 | <?php |
| 191 | - $team_args=array( |
|
| 192 | - 'post_type' => 'team', |
|
| 193 | - 'post_status' => 'publish', |
|
| 194 | - 'nopagin' => true, |
|
| 195 | - 'fields' => 'ids' |
|
| 196 | - ); |
|
| 197 | - $team_members = new WP_Query($team_args); |
|
| 198 | - if($team_members->have_posts()){ |
|
| 199 | - foreach($team_members->posts as $member){ ?> |
|
| 191 | + $team_args=array( |
|
| 192 | + 'post_type' => 'team', |
|
| 193 | + 'post_status' => 'publish', |
|
| 194 | + 'nopagin' => true, |
|
| 195 | + 'fields' => 'ids' |
|
| 196 | + ); |
|
| 197 | + $team_members = new WP_Query($team_args); |
|
| 198 | + if($team_members->have_posts()){ |
|
| 199 | + foreach($team_members->posts as $member){ ?> |
|
| 200 | 200 | <li><input class="team" checked="<?php $this->checked($selected,$member); ?>" type="checkbox" value="<?php echo $member; ?>" /> <?php echo get_the_title($member); ?></li> |
| 201 | 201 | <?php } |
| 202 | - }else{ ?> |
|
| 202 | + }else{ ?> |
|
| 203 | 203 | <li><input class="team" type="checkbox" value="0" /> <?php _e('None','wetu-importer'); ?></li> |
| 204 | 204 | <?php } |
| 205 | - ?> |
|
| 205 | + ?> |
|
| 206 | 206 | </ul> |
| 207 | 207 | <?php } |
| 208 | 208 | } |
@@ -253,40 +253,40 @@ discard block |
||
| 253 | 253 | if(false !== $id){ |
| 254 | 254 | if(empty($this->found_attachments)){ |
| 255 | 255 | |
| 256 | - $attachments_args = array( |
|
| 257 | - 'post_parent' => $id, |
|
| 258 | - 'post_status' => 'inherit', |
|
| 259 | - 'post_type' => 'attachment', |
|
| 260 | - 'order' => 'ASC', |
|
| 261 | - ); |
|
| 256 | + $attachments_args = array( |
|
| 257 | + 'post_parent' => $id, |
|
| 258 | + 'post_status' => 'inherit', |
|
| 259 | + 'post_type' => 'attachment', |
|
| 260 | + 'order' => 'ASC', |
|
| 261 | + ); |
|
| 262 | 262 | |
| 263 | - $attachments = new WP_Query($attachments_args); |
|
| 264 | - if($attachments->have_posts()){ |
|
| 265 | - foreach($attachments->posts as $attachment){ |
|
| 266 | - $this->found_attachments[$attachment->ID] = str_replace(array('.jpg','.png','.jpeg'),'',$attachment->post_title); |
|
| 267 | - $this->gallery_meta[] = $attachment->ID; |
|
| 268 | - } |
|
| 269 | - } |
|
| 263 | + $attachments = new WP_Query($attachments_args); |
|
| 264 | + if($attachments->have_posts()){ |
|
| 265 | + foreach($attachments->posts as $attachment){ |
|
| 266 | + $this->found_attachments[$attachment->ID] = str_replace(array('.jpg','.png','.jpeg'),'',$attachment->post_title); |
|
| 267 | + $this->gallery_meta[] = $attachment->ID; |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | 270 | } |
| 271 | 271 | } |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | /** |
| 275 | 275 | * Checks to see if an item is selected. |
| 276 | - * |
|
| 277 | - * @param $haystack array|string |
|
| 278 | - * @param $needle string |
|
| 279 | - * @return string |
|
| 276 | + * |
|
| 277 | + * @param $haystack array|string |
|
| 278 | + * @param $needle string |
|
| 279 | + * @return string |
|
| 280 | 280 | */ |
| 281 | 281 | public function checked($haystack=false,$needle='') { |
| 282 | - $return = ''; |
|
| 283 | - if(!is_array($haystack)){ |
|
| 282 | + $return = ''; |
|
| 283 | + if(!is_array($haystack)){ |
|
| 284 | 284 | $haystack = array($haystack); |
| 285 | - } |
|
| 286 | - if(in_array($needle,$haystack)){ |
|
| 285 | + } |
|
| 286 | + if(in_array($needle,$haystack)){ |
|
| 287 | 287 | $return = 'checked'; |
| 288 | - } |
|
| 289 | - return $return; |
|
| 288 | + } |
|
| 289 | + return $return; |
|
| 290 | 290 | } |
| 291 | 291 | } |
| 292 | 292 | $wetu_importer_admin = new WETU_Importer_Admin(); |
| 293 | 293 | \ No newline at end of file |
@@ -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 screen_icon(); ?> |
| 126 | 126 | |
@@ -248,13 +248,13 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |