@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | * Display the importer administration screen |
| 137 | 137 | */ |
| 138 | 138 | public function display_page() { |
| 139 | - ?> |
|
| 139 | + ?> |
|
| 140 | 140 | <div class="wrap"> |
| 141 | 141 | <?php screen_icon(); ?> |
| 142 | 142 | |
@@ -314,8 +314,8 @@ discard block |
||
| 314 | 314 | $accommodation = json_decode($data, true); |
| 315 | 315 | |
| 316 | 316 | if(isset($accommodation['error'])){ |
| 317 | - return $accommodation['error']; |
|
| 318 | - }elseif (isset($accommodation) && !empty($accommodation)) { |
|
| 317 | + return $accommodation['error']; |
|
| 318 | + }elseif (isset($accommodation) && !empty($accommodation)) { |
|
| 319 | 319 | set_transient('lsx_ti_accommodation',$accommodation,60*60*2); |
| 320 | 320 | return true; |
| 321 | 321 | } |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | $keyphrases = $_POST['keyword']; |
| 364 | 364 | }else{ |
| 365 | 365 | $keyphrases = array(0); |
| 366 | - } |
|
| 366 | + } |
|
| 367 | 367 | |
| 368 | 368 | if(!is_array($keyphrases)){ |
| 369 | 369 | $keyphrases = array($keyphrases); |
@@ -460,13 +460,13 @@ discard block |
||
| 460 | 460 | public function multineedle_stripos($haystack, $needles, $offset=0) { |
| 461 | 461 | $found = false; |
| 462 | 462 | $needle_count = count($needles); |
| 463 | - foreach($needles as $needle) { |
|
| 464 | - if(false !== stripos($haystack, $needle, $offset)){ |
|
| 465 | - $found[] = true; |
|
| 466 | - } |
|
| 467 | - } |
|
| 468 | - if(false !== $found && $needle_count === count($found)){ |
|
| 469 | - return true; |
|
| 463 | + foreach($needles as $needle) { |
|
| 464 | + if(false !== stripos($haystack, $needle, $offset)){ |
|
| 465 | + $found[] = true; |
|
| 466 | + } |
|
| 467 | + } |
|
| 468 | + if(false !== $found && $needle_count === count($found)){ |
|
| 469 | + return true; |
|
| 470 | 470 | }else{ |
| 471 | 471 | return false; |
| 472 | 472 | } |
@@ -537,16 +537,16 @@ discard block |
||
| 537 | 537 | $content = false; |
| 538 | 538 | } |
| 539 | 539 | |
| 540 | - $jdata = file_get_contents( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id ); |
|
| 541 | - if($jdata) |
|
| 542 | - { |
|
| 543 | - $adata=json_decode($jdata,true); |
|
| 544 | - if(!empty($adata)) |
|
| 545 | - { |
|
| 546 | - $return = $this->import_row($adata,$wetu_id,$post_id,$team_members,$content,$safari_brands); |
|
| 547 | - $this->format_completed_row($return); |
|
| 548 | - } |
|
| 549 | - } |
|
| 540 | + $jdata = file_get_contents( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id ); |
|
| 541 | + if($jdata) |
|
| 542 | + { |
|
| 543 | + $adata=json_decode($jdata,true); |
|
| 544 | + if(!empty($adata)) |
|
| 545 | + { |
|
| 546 | + $return = $this->import_row($adata,$wetu_id,$post_id,$team_members,$content,$safari_brands); |
|
| 547 | + $this->format_completed_row($return); |
|
| 548 | + } |
|
| 549 | + } |
|
| 550 | 550 | |
| 551 | 551 | die(); |
| 552 | 552 | } |
@@ -563,148 +563,148 @@ discard block |
||
| 563 | 563 | */ |
| 564 | 564 | public function import_row($data,$wetu_id,$id=0,$team_members=false,$importable_content=false,$safari_brands=false) { |
| 565 | 565 | |
| 566 | - if(trim($data[0]['type'])=='Accommodation') |
|
| 567 | - { |
|
| 568 | - $post_name = $data_post_content = $data_post_excerpt = ''; |
|
| 569 | - $post = array( |
|
| 570 | - 'post_type' => 'accommodation', |
|
| 571 | - ); |
|
| 572 | - |
|
| 573 | - $content_used_general_description = false; |
|
| 574 | - |
|
| 575 | - //Set the post_content |
|
| 576 | - if(false !== $importable_content && in_array('description',$importable_content)){ |
|
| 577 | - if(isset($data[0]['content']['extended_description'])) |
|
| 578 | - { |
|
| 579 | - $data_post_content = $data[0]['content']['extended_description']; |
|
| 580 | - }elseif(isset($data[0]['content']['general_description'])){ |
|
| 581 | - $data_post_content = $data[0]['content']['general_description']; |
|
| 582 | - $content_used_general_description = true; |
|
| 583 | - }elseif(isset($data[0]['content']['teaser_description'])){ |
|
| 584 | - $data_post_content = $data[0]['content']['teaser_description']; |
|
| 585 | - } |
|
| 586 | - $post['post_content'] = wp_strip_all_tags($data_post_content); |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - //set the post_excerpt |
|
| 590 | - if(false !== $importable_content && in_array('excerpt',$importable_content)){ |
|
| 591 | - if(isset($data[0]['content']['teaser_description'])){ |
|
| 592 | - $data_post_excerpt = $data[0]['content']['teaser_description']; |
|
| 593 | - }elseif(isset($data[0]['content']['general_description']) && false === $content_used_general_description){ |
|
| 594 | - $data_post_excerpt = $data[0]['content']['general_description']; |
|
| 595 | - } |
|
| 596 | - $post['post_excerpt'] = $data_post_excerpt; |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - if(false !== $id && '0' !== $id){ |
|
| 600 | - $post['ID'] = $id; |
|
| 566 | + if(trim($data[0]['type'])=='Accommodation') |
|
| 567 | + { |
|
| 568 | + $post_name = $data_post_content = $data_post_excerpt = ''; |
|
| 569 | + $post = array( |
|
| 570 | + 'post_type' => 'accommodation', |
|
| 571 | + ); |
|
| 572 | + |
|
| 573 | + $content_used_general_description = false; |
|
| 574 | + |
|
| 575 | + //Set the post_content |
|
| 576 | + if(false !== $importable_content && in_array('description',$importable_content)){ |
|
| 577 | + if(isset($data[0]['content']['extended_description'])) |
|
| 578 | + { |
|
| 579 | + $data_post_content = $data[0]['content']['extended_description']; |
|
| 580 | + }elseif(isset($data[0]['content']['general_description'])){ |
|
| 581 | + $data_post_content = $data[0]['content']['general_description']; |
|
| 582 | + $content_used_general_description = true; |
|
| 583 | + }elseif(isset($data[0]['content']['teaser_description'])){ |
|
| 584 | + $data_post_content = $data[0]['content']['teaser_description']; |
|
| 585 | + } |
|
| 586 | + $post['post_content'] = wp_strip_all_tags($data_post_content); |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + //set the post_excerpt |
|
| 590 | + if(false !== $importable_content && in_array('excerpt',$importable_content)){ |
|
| 591 | + if(isset($data[0]['content']['teaser_description'])){ |
|
| 592 | + $data_post_excerpt = $data[0]['content']['teaser_description']; |
|
| 593 | + }elseif(isset($data[0]['content']['general_description']) && false === $content_used_general_description){ |
|
| 594 | + $data_post_excerpt = $data[0]['content']['general_description']; |
|
| 595 | + } |
|
| 596 | + $post['post_excerpt'] = $data_post_excerpt; |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + if(false !== $id && '0' !== $id){ |
|
| 600 | + $post['ID'] = $id; |
|
| 601 | 601 | if(isset($data[0]['name'])){ |
| 602 | 602 | $post['post_title'] = $data[0]['name']; |
| 603 | - $post['post_status'] = 'publish'; |
|
| 603 | + $post['post_status'] = 'publish'; |
|
| 604 | 604 | $post['post_name'] = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'accommodation', 0); |
| 605 | 605 | } |
| 606 | - $id = wp_update_post($post); |
|
| 607 | - $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
| 608 | - update_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified']),$prev_date); |
|
| 609 | - }else{ |
|
| 610 | - |
|
| 611 | - //Set the name |
|
| 612 | - if(isset($data[0]['name'])){ |
|
| 613 | - $post_name = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'accommodation', 0); |
|
| 614 | - } |
|
| 615 | - $post['post_name'] = $post_name; |
|
| 616 | - $post['post_title'] = $data[0]['name']; |
|
| 617 | - $post['post_status'] = 'publish'; |
|
| 618 | - $id = wp_insert_post($post); |
|
| 619 | - |
|
| 620 | - //Save the WETU ID and the Last date it was modified. |
|
| 621 | - if(false !== $id){ |
|
| 622 | - add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
| 623 | - add_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified'])); |
|
| 624 | - } |
|
| 625 | - } |
|
| 626 | - //Setup some default for use in the import |
|
| 627 | - if(false !== $importable_content && (in_array('gallery',$importable_content) || in_array('banner_image',$importable_content) || in_array('featured_image',$importable_content))){ |
|
| 606 | + $id = wp_update_post($post); |
|
| 607 | + $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
| 608 | + update_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified']),$prev_date); |
|
| 609 | + }else{ |
|
| 610 | + |
|
| 611 | + //Set the name |
|
| 612 | + if(isset($data[0]['name'])){ |
|
| 613 | + $post_name = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'accommodation', 0); |
|
| 614 | + } |
|
| 615 | + $post['post_name'] = $post_name; |
|
| 616 | + $post['post_title'] = $data[0]['name']; |
|
| 617 | + $post['post_status'] = 'publish'; |
|
| 618 | + $id = wp_insert_post($post); |
|
| 619 | + |
|
| 620 | + //Save the WETU ID and the Last date it was modified. |
|
| 621 | + if(false !== $id){ |
|
| 622 | + add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
| 623 | + add_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified'])); |
|
| 624 | + } |
|
| 625 | + } |
|
| 626 | + //Setup some default for use in the import |
|
| 627 | + if(false !== $importable_content && (in_array('gallery',$importable_content) || in_array('banner_image',$importable_content) || in_array('featured_image',$importable_content))){ |
|
| 628 | 628 | $this->find_attachments($id); |
| 629 | 629 | } |
| 630 | 630 | |
| 631 | - //Set the team member if it is there |
|
| 632 | - if(post_type_exists('team') && false !== $team_members && '' !== $team_members){ |
|
| 633 | - $this->set_team_member($id,$team_members); |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - //Set the safari brand |
|
| 637 | - if(false !== $safari_brands && '' !== $safari_brands){ |
|
| 638 | - $this->set_safari_brands($id,$safari_brands); |
|
| 639 | - |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - if(class_exists('LSX_TO_Maps')){ |
|
| 643 | - $this->set_map_data($data,$id); |
|
| 644 | - $this->set_location_taxonomy($data,$id); |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - if(post_type_exists('destination') && false !== $importable_content && in_array('destination',$importable_content)){ |
|
| 648 | - $this->connect_destinations($data,$id); |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - if(false !== $importable_content && in_array('category',$importable_content)){ |
|
| 652 | - $this->set_taxonomy_style($data,$id); |
|
| 653 | - } |
|
| 654 | - |
|
| 655 | - //Set the Room Data |
|
| 656 | - if(false !== $importable_content && in_array('rooms',$importable_content)){ |
|
| 657 | - $this->set_room_data($data,$id); |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - //Set the rating |
|
| 661 | - if(false !== $importable_content && in_array('rating',$importable_content)){ |
|
| 662 | - $this->set_rating($data,$id); |
|
| 663 | - } |
|
| 664 | - |
|
| 665 | - //Set the checkin checkout data |
|
| 666 | - if(false !== $importable_content && in_array('checkin',$importable_content)){ |
|
| 667 | - $this->set_checkin_checkout($data,$id); |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - //Set the Spoken Languages |
|
| 671 | - if(false !== $importable_content && in_array('spoken_languages',$importable_content)){ |
|
| 672 | - $this->set_spoken_languages($data,$id); |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - //Set the friendly options |
|
| 676 | - if(false !== $importable_content && in_array('friendly',$importable_content)){ |
|
| 677 | - $this->set_friendly($data,$id); |
|
| 678 | - } |
|
| 679 | - |
|
| 680 | - //Set the special_interests |
|
| 681 | - if(false !== $importable_content && in_array('special_interests',$importable_content)){ |
|
| 682 | - $this->set_special_interests($data,$id); |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - //Import the videos |
|
| 686 | - if(false !== $importable_content && in_array('videos',$importable_content)){ |
|
| 687 | - $this->set_video_data($data,$id); |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - //Import the facilities |
|
| 691 | - if(false !== $importable_content && in_array('facilities',$importable_content)){ |
|
| 692 | - $this->set_facilities($data,$id); |
|
| 693 | - } |
|
| 694 | - |
|
| 695 | - //Set the featured image |
|
| 696 | - if(false !== $importable_content && in_array('featured_image',$importable_content)){ |
|
| 697 | - $this->set_featured_image($data,$id); |
|
| 698 | - } |
|
| 699 | - if(false !== $importable_content && in_array('banner_image',$importable_content)){ |
|
| 700 | - $this->set_banner_image($data,$id); |
|
| 701 | - } |
|
| 702 | - //Import the main gallery |
|
| 703 | - if(false !== $importable_content && in_array('gallery',$importable_content)){ |
|
| 704 | - $this->create_main_gallery($data,$id); |
|
| 705 | - } |
|
| 706 | - } |
|
| 707 | - return $id; |
|
| 631 | + //Set the team member if it is there |
|
| 632 | + if(post_type_exists('team') && false !== $team_members && '' !== $team_members){ |
|
| 633 | + $this->set_team_member($id,$team_members); |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + //Set the safari brand |
|
| 637 | + if(false !== $safari_brands && '' !== $safari_brands){ |
|
| 638 | + $this->set_safari_brands($id,$safari_brands); |
|
| 639 | + |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + if(class_exists('LSX_TO_Maps')){ |
|
| 643 | + $this->set_map_data($data,$id); |
|
| 644 | + $this->set_location_taxonomy($data,$id); |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + if(post_type_exists('destination') && false !== $importable_content && in_array('destination',$importable_content)){ |
|
| 648 | + $this->connect_destinations($data,$id); |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + if(false !== $importable_content && in_array('category',$importable_content)){ |
|
| 652 | + $this->set_taxonomy_style($data,$id); |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + //Set the Room Data |
|
| 656 | + if(false !== $importable_content && in_array('rooms',$importable_content)){ |
|
| 657 | + $this->set_room_data($data,$id); |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + //Set the rating |
|
| 661 | + if(false !== $importable_content && in_array('rating',$importable_content)){ |
|
| 662 | + $this->set_rating($data,$id); |
|
| 663 | + } |
|
| 664 | + |
|
| 665 | + //Set the checkin checkout data |
|
| 666 | + if(false !== $importable_content && in_array('checkin',$importable_content)){ |
|
| 667 | + $this->set_checkin_checkout($data,$id); |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + //Set the Spoken Languages |
|
| 671 | + if(false !== $importable_content && in_array('spoken_languages',$importable_content)){ |
|
| 672 | + $this->set_spoken_languages($data,$id); |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + //Set the friendly options |
|
| 676 | + if(false !== $importable_content && in_array('friendly',$importable_content)){ |
|
| 677 | + $this->set_friendly($data,$id); |
|
| 678 | + } |
|
| 679 | + |
|
| 680 | + //Set the special_interests |
|
| 681 | + if(false !== $importable_content && in_array('special_interests',$importable_content)){ |
|
| 682 | + $this->set_special_interests($data,$id); |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + //Import the videos |
|
| 686 | + if(false !== $importable_content && in_array('videos',$importable_content)){ |
|
| 687 | + $this->set_video_data($data,$id); |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + //Import the facilities |
|
| 691 | + if(false !== $importable_content && in_array('facilities',$importable_content)){ |
|
| 692 | + $this->set_facilities($data,$id); |
|
| 693 | + } |
|
| 694 | + |
|
| 695 | + //Set the featured image |
|
| 696 | + if(false !== $importable_content && in_array('featured_image',$importable_content)){ |
|
| 697 | + $this->set_featured_image($data,$id); |
|
| 698 | + } |
|
| 699 | + if(false !== $importable_content && in_array('banner_image',$importable_content)){ |
|
| 700 | + $this->set_banner_image($data,$id); |
|
| 701 | + } |
|
| 702 | + //Import the main gallery |
|
| 703 | + if(false !== $importable_content && in_array('gallery',$importable_content)){ |
|
| 704 | + $this->create_main_gallery($data,$id); |
|
| 705 | + } |
|
| 706 | + } |
|
| 707 | + return $id; |
|
| 708 | 708 | } |
| 709 | 709 | |
| 710 | 710 | /** |
@@ -714,7 +714,7 @@ discard block |
||
| 714 | 714 | |
| 715 | 715 | delete_post_meta($id, 'team_to_'.$this->tab_slug); |
| 716 | 716 | foreach($team_members as $team){ |
| 717 | - add_post_meta($id,'team_to_'.$this->tab_slug,$team); |
|
| 717 | + add_post_meta($id,'team_to_'.$this->tab_slug,$team); |
|
| 718 | 718 | } |
| 719 | 719 | } |
| 720 | 720 | |
@@ -723,7 +723,7 @@ discard block |
||
| 723 | 723 | */ |
| 724 | 724 | public function set_safari_brands($id,$safari_brands) { |
| 725 | 725 | foreach($safari_brands as $safari_brand){ |
| 726 | - wp_set_object_terms( $id, intval($safari_brand), 'accommodation-brand',true); |
|
| 726 | + wp_set_object_terms( $id, intval($safari_brand), 'accommodation-brand',true); |
|
| 727 | 727 | } |
| 728 | 728 | } |
| 729 | 729 | |
@@ -775,11 +775,11 @@ discard block |
||
| 775 | 775 | 'elevation' => '', |
| 776 | 776 | ); |
| 777 | 777 | if(false !== $id && '0' !== $id){ |
| 778 | - $prev = get_post_meta($id,'location',true); |
|
| 779 | - update_post_meta($id,'location',$location_data,$prev); |
|
| 780 | - }else{ |
|
| 781 | - add_post_meta($id,'location',$location_data,true); |
|
| 782 | - } |
|
| 778 | + $prev = get_post_meta($id,'location',true); |
|
| 779 | + update_post_meta($id,'location',$location_data,$prev); |
|
| 780 | + }else{ |
|
| 781 | + add_post_meta($id,'location',$location_data,true); |
|
| 782 | + } |
|
| 783 | 783 | } |
| 784 | 784 | } |
| 785 | 785 | /** |
@@ -793,35 +793,35 @@ discard block |
||
| 793 | 793 | if(isset($data[0]['position']['country'])){ |
| 794 | 794 | |
| 795 | 795 | if(!$term = term_exists(trim($data[0]['position']['country']), 'location')) |
| 796 | - { |
|
| 797 | - $term = wp_insert_term(trim($data[0]['position']['country']), 'location'); |
|
| 798 | - if ( is_wp_error($term) ){ |
|
| 799 | - echo $term->get_error_message(); |
|
| 800 | - } |
|
| 801 | - else { |
|
| 802 | - wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
| 803 | - } |
|
| 804 | - } |
|
| 805 | - else |
|
| 806 | - { |
|
| 807 | - wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
| 808 | - } |
|
| 809 | - $country_id = intval($term['term_id']); |
|
| 810 | - } |
|
| 796 | + { |
|
| 797 | + $term = wp_insert_term(trim($data[0]['position']['country']), 'location'); |
|
| 798 | + if ( is_wp_error($term) ){ |
|
| 799 | + echo $term->get_error_message(); |
|
| 800 | + } |
|
| 801 | + else { |
|
| 802 | + wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
| 803 | + } |
|
| 804 | + } |
|
| 805 | + else |
|
| 806 | + { |
|
| 807 | + wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
| 808 | + } |
|
| 809 | + $country_id = intval($term['term_id']); |
|
| 810 | + } |
|
| 811 | 811 | |
| 812 | 812 | if(isset($data[0]['position']['destination'])){ |
| 813 | 813 | |
| 814 | 814 | $tax_args = array('parent'=>$country_id); |
| 815 | 815 | if(!$term = term_exists(trim($data[0]['position']['destination']), 'location')) |
| 816 | - { |
|
| 817 | - $term = wp_insert_term(trim($data[0]['position']['destination']), 'location', $tax_args); |
|
| 818 | - if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
| 819 | - else { wp_set_object_terms( $id, intval($term['term_id']), 'location',true); } |
|
| 820 | - } |
|
| 821 | - else |
|
| 822 | - { |
|
| 823 | - wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
| 824 | - } |
|
| 816 | + { |
|
| 817 | + $term = wp_insert_term(trim($data[0]['position']['destination']), 'location', $tax_args); |
|
| 818 | + if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
| 819 | + else { wp_set_object_terms( $id, intval($term['term_id']), 'location',true); } |
|
| 820 | + } |
|
| 821 | + else |
|
| 822 | + { |
|
| 823 | + wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
| 824 | + } |
|
| 825 | 825 | } |
| 826 | 826 | } |
| 827 | 827 | } |
@@ -831,31 +831,31 @@ discard block |
||
| 831 | 831 | */ |
| 832 | 832 | public function connect_destinations($data,$id) { |
| 833 | 833 | if(isset($data[0]['position'])){ |
| 834 | - $destinations = false; |
|
| 835 | - if(isset($data[0]['position']['country'])){ |
|
| 836 | - $destinations['country'] = $data[0]['position']['country']; |
|
| 837 | - } |
|
| 838 | - if(isset($data[0]['position']['destination'])){ |
|
| 839 | - $destinations['destination'] = $data[0]['position']['destination']; |
|
| 840 | - } |
|
| 834 | + $destinations = false; |
|
| 835 | + if(isset($data[0]['position']['country'])){ |
|
| 836 | + $destinations['country'] = $data[0]['position']['country']; |
|
| 837 | + } |
|
| 838 | + if(isset($data[0]['position']['destination'])){ |
|
| 839 | + $destinations['destination'] = $data[0]['position']['destination']; |
|
| 840 | + } |
|
| 841 | 841 | |
| 842 | - if(false !== $destinations){ |
|
| 843 | - $prev_values = get_post_meta($id,'destination_to_accommodation',false); |
|
| 844 | - if(false === $prev_values || !is_array($prev_values)){ |
|
| 845 | - $prev_values = array(); |
|
| 846 | - } |
|
| 847 | - //print_r($destinations); |
|
| 842 | + if(false !== $destinations){ |
|
| 843 | + $prev_values = get_post_meta($id,'destination_to_accommodation',false); |
|
| 844 | + if(false === $prev_values || !is_array($prev_values)){ |
|
| 845 | + $prev_values = array(); |
|
| 846 | + } |
|
| 847 | + //print_r($destinations); |
|
| 848 | 848 | $destinations = array_unique($destinations); |
| 849 | 849 | //print_r($destinations); |
| 850 | - foreach($destinations as $key => $value){ |
|
| 851 | - $destination = get_page_by_title(ltrim(rtrim($value)), 'OBJECT', 'destination'); |
|
| 852 | - if (null !== $destination) { |
|
| 853 | - if(!in_array($destination->ID,$prev_values)){ |
|
| 854 | - add_post_meta($id,'destination_to_accommodation',$destination->ID,false); |
|
| 855 | - add_post_meta($destination->ID,'accommodation_to_destination',$id,false); |
|
| 856 | - } |
|
| 857 | - } |
|
| 858 | - } |
|
| 850 | + foreach($destinations as $key => $value){ |
|
| 851 | + $destination = get_page_by_title(ltrim(rtrim($value)), 'OBJECT', 'destination'); |
|
| 852 | + if (null !== $destination) { |
|
| 853 | + if(!in_array($destination->ID,$prev_values)){ |
|
| 854 | + add_post_meta($id,'destination_to_accommodation',$destination->ID,false); |
|
| 855 | + add_post_meta($destination->ID,'accommodation_to_destination',$id,false); |
|
| 856 | + } |
|
| 857 | + } |
|
| 858 | + } |
|
| 859 | 859 | } |
| 860 | 860 | } |
| 861 | 861 | } |
@@ -867,15 +867,15 @@ discard block |
||
| 867 | 867 | $terms = false; |
| 868 | 868 | if(isset($data[0]['category'])){ |
| 869 | 869 | if(!$term = term_exists(trim($data[0]['category']), 'accommodation-type')) |
| 870 | - { |
|
| 871 | - $term = wp_insert_term(trim($data[0]['category']), 'accommodation-type'); |
|
| 872 | - if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
| 873 | - else { wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); } |
|
| 874 | - } |
|
| 875 | - else |
|
| 876 | - { |
|
| 877 | - wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); |
|
| 878 | - } |
|
| 870 | + { |
|
| 871 | + $term = wp_insert_term(trim($data[0]['category']), 'accommodation-type'); |
|
| 872 | + if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
| 873 | + else { wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); } |
|
| 874 | + } |
|
| 875 | + else |
|
| 876 | + { |
|
| 877 | + wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); |
|
| 878 | + } |
|
| 879 | 879 | } |
| 880 | 880 | } |
| 881 | 881 | |
@@ -899,25 +899,25 @@ discard block |
||
| 899 | 899 | $temp_room['type'] = 'room'; |
| 900 | 900 | |
| 901 | 901 | if(!empty($room['images']) && is_array($room['images'])){ |
| 902 | - $attachments_args = array( |
|
| 903 | - 'post_parent' => $id, |
|
| 904 | - 'post_status' => 'inherit', |
|
| 905 | - 'post_type' => 'attachment', |
|
| 906 | - 'order' => 'ASC', |
|
| 907 | - ); |
|
| 908 | - $attachments = new WP_Query($attachments_args); |
|
| 909 | - $found_attachments = array(); |
|
| 910 | - |
|
| 911 | - if($attachments->have_posts()){ |
|
| 912 | - foreach($attachments->posts as $attachment){ |
|
| 913 | - $found_attachments[] = str_replace(array('.jpg','.png','.jpeg'),'',$attachment->post_title); |
|
| 914 | - } |
|
| 915 | - } |
|
| 902 | + $attachments_args = array( |
|
| 903 | + 'post_parent' => $id, |
|
| 904 | + 'post_status' => 'inherit', |
|
| 905 | + 'post_type' => 'attachment', |
|
| 906 | + 'order' => 'ASC', |
|
| 907 | + ); |
|
| 908 | + $attachments = new WP_Query($attachments_args); |
|
| 909 | + $found_attachments = array(); |
|
| 910 | + |
|
| 911 | + if($attachments->have_posts()){ |
|
| 912 | + foreach($attachments->posts as $attachment){ |
|
| 913 | + $found_attachments[] = str_replace(array('.jpg','.png','.jpeg'),'',$attachment->post_title); |
|
| 914 | + } |
|
| 915 | + } |
|
| 916 | 916 | |
| 917 | 917 | $temp_room['gallery'] = array(); |
| 918 | 918 | foreach($room['images'] as $image_data){ |
| 919 | - $temp_room['gallery'][] = $this->attach_image($image_data,$id,$found_attachments); |
|
| 920 | - } |
|
| 919 | + $temp_room['gallery'][] = $this->attach_image($image_data,$id,$found_attachments); |
|
| 920 | + } |
|
| 921 | 921 | } |
| 922 | 922 | $rooms[] = $temp_room; |
| 923 | 923 | } |
@@ -926,7 +926,7 @@ discard block |
||
| 926 | 926 | delete_post_meta($id, 'units'); |
| 927 | 927 | } |
| 928 | 928 | foreach($rooms as $room){ |
| 929 | - add_post_meta($id,'units',$room,false); |
|
| 929 | + add_post_meta($id,'units',$room,false); |
|
| 930 | 930 | } |
| 931 | 931 | |
| 932 | 932 | if(isset($data[0]['features']) && isset($data[0]['features']['rooms'])){ |
@@ -936,11 +936,11 @@ discard block |
||
| 936 | 936 | } |
| 937 | 937 | |
| 938 | 938 | if(false !== $id && '0' !== $id){ |
| 939 | - $prev_rooms = get_post_meta($id,'number_of_rooms',true); |
|
| 940 | - update_post_meta($id,'number_of_rooms',$room_count,$prev_rooms); |
|
| 941 | - }else{ |
|
| 942 | - add_post_meta($id,'number_of_rooms',$room_count,true); |
|
| 943 | - } |
|
| 939 | + $prev_rooms = get_post_meta($id,'number_of_rooms',true); |
|
| 940 | + update_post_meta($id,'number_of_rooms',$room_count,$prev_rooms); |
|
| 941 | + }else{ |
|
| 942 | + add_post_meta($id,'number_of_rooms',$room_count,true); |
|
| 943 | + } |
|
| 944 | 944 | } |
| 945 | 945 | } |
| 946 | 946 | |
@@ -1049,7 +1049,7 @@ discard block |
||
| 1049 | 1049 | delete_post_meta($id, 'videos'); |
| 1050 | 1050 | } |
| 1051 | 1051 | foreach($videos as $video){ |
| 1052 | - add_post_meta($id,'videos',$video,false); |
|
| 1052 | + add_post_meta($id,'videos',$video,false); |
|
| 1053 | 1053 | } |
| 1054 | 1054 | } |
| 1055 | 1055 | } |
@@ -1078,17 +1078,17 @@ discard block |
||
| 1078 | 1078 | |
| 1079 | 1079 | function set_term($id=false,$name=false,$taxonomy=false,$parent=false){ |
| 1080 | 1080 | if(!$term = term_exists($name, $taxonomy)) |
| 1081 | - { |
|
| 1082 | - if(false !== $parent){ $parent = array('parent'=>$parent); } |
|
| 1083 | - $term = wp_insert_term(trim($name), $taxonomy,$parent); |
|
| 1084 | - if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
| 1085 | - else { wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); } |
|
| 1086 | - } |
|
| 1087 | - else |
|
| 1088 | - { |
|
| 1089 | - wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); |
|
| 1090 | - } |
|
| 1091 | - return $term['term_id']; |
|
| 1081 | + { |
|
| 1082 | + if(false !== $parent){ $parent = array('parent'=>$parent); } |
|
| 1083 | + $term = wp_insert_term(trim($name), $taxonomy,$parent); |
|
| 1084 | + if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
| 1085 | + else { wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); } |
|
| 1086 | + } |
|
| 1087 | + else |
|
| 1088 | + { |
|
| 1089 | + wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); |
|
| 1090 | + } |
|
| 1091 | + return $term['term_id']; |
|
| 1092 | 1092 | } |
| 1093 | 1093 | |
| 1094 | 1094 | /** |
@@ -1096,17 +1096,17 @@ discard block |
||
| 1096 | 1096 | */ |
| 1097 | 1097 | public function set_featured_image($data,$id) { |
| 1098 | 1098 | if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){ |
| 1099 | - $this->featured_image = $this->attach_image($data[0]['content']['images'][0],$id); |
|
| 1099 | + $this->featured_image = $this->attach_image($data[0]['content']['images'][0],$id); |
|
| 1100 | 1100 | |
| 1101 | - if(false !== $this->featured_image){ |
|
| 1102 | - delete_post_meta($id,'_thumbnail_id'); |
|
| 1103 | - add_post_meta($id,'_thumbnail_id',$this->featured_image,true); |
|
| 1101 | + if(false !== $this->featured_image){ |
|
| 1102 | + delete_post_meta($id,'_thumbnail_id'); |
|
| 1103 | + add_post_meta($id,'_thumbnail_id',$this->featured_image,true); |
|
| 1104 | 1104 | |
| 1105 | - if(!empty($this->gallery_meta) && !in_array($this->featured_image,$this->gallery_meta)){ |
|
| 1106 | - add_post_meta($id,'gallery',$this->featured_image,false); |
|
| 1107 | - $this->gallery_meta[] = $this->featured_image; |
|
| 1108 | - } |
|
| 1109 | - } |
|
| 1105 | + if(!empty($this->gallery_meta) && !in_array($this->featured_image,$this->gallery_meta)){ |
|
| 1106 | + add_post_meta($id,'gallery',$this->featured_image,false); |
|
| 1107 | + $this->gallery_meta[] = $this->featured_image; |
|
| 1108 | + } |
|
| 1109 | + } |
|
| 1110 | 1110 | } |
| 1111 | 1111 | } |
| 1112 | 1112 | |
@@ -1115,18 +1115,18 @@ discard block |
||
| 1115 | 1115 | */ |
| 1116 | 1116 | public function set_banner_image($data,$id) { |
| 1117 | 1117 | if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){ |
| 1118 | - $this->banner_image = $this->attach_image($data[0]['content']['images'][1],$id,array('width'=>'1920','height'=>'800','cropping'=>'c')); |
|
| 1119 | - |
|
| 1120 | - if(false !== $this->banner_image){ |
|
| 1121 | - delete_post_meta($id,'image_group'); |
|
| 1122 | - $new_banner = array('banner_image'=>array('cmb-field-0'=>$this->banner_image)); |
|
| 1123 | - add_post_meta($id,'image_group',$new_banner,true); |
|
| 1124 | - |
|
| 1125 | - if(!empty($this->gallery_meta) && !in_array($this->banner_image,$this->gallery_meta)){ |
|
| 1126 | - add_post_meta($id,'gallery',$this->banner_image,false); |
|
| 1127 | - $this->gallery_meta[] = $this->banner_image; |
|
| 1128 | - } |
|
| 1129 | - } |
|
| 1118 | + $this->banner_image = $this->attach_image($data[0]['content']['images'][1],$id,array('width'=>'1920','height'=>'800','cropping'=>'c')); |
|
| 1119 | + |
|
| 1120 | + if(false !== $this->banner_image){ |
|
| 1121 | + delete_post_meta($id,'image_group'); |
|
| 1122 | + $new_banner = array('banner_image'=>array('cmb-field-0'=>$this->banner_image)); |
|
| 1123 | + add_post_meta($id,'image_group',$new_banner,true); |
|
| 1124 | + |
|
| 1125 | + if(!empty($this->gallery_meta) && !in_array($this->banner_image,$this->gallery_meta)){ |
|
| 1126 | + add_post_meta($id,'gallery',$this->banner_image,false); |
|
| 1127 | + $this->gallery_meta[] = $this->banner_image; |
|
| 1128 | + } |
|
| 1129 | + } |
|
| 1130 | 1130 | } |
| 1131 | 1131 | } |
| 1132 | 1132 | |
@@ -1136,25 +1136,25 @@ discard block |
||
| 1136 | 1136 | public function create_main_gallery($data,$id) { |
| 1137 | 1137 | |
| 1138 | 1138 | if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){ |
| 1139 | - $counter = 0; |
|
| 1140 | - foreach($data[0]['content']['images'] as $image_data){ |
|
| 1141 | - if($counter === 0 && false !== $this->featured_image){$counter++;continue;} |
|
| 1142 | - if($counter === 1 && false !== $this->banner_image){$counter++;continue;} |
|
| 1139 | + $counter = 0; |
|
| 1140 | + foreach($data[0]['content']['images'] as $image_data){ |
|
| 1141 | + if($counter === 0 && false !== $this->featured_image){$counter++;continue;} |
|
| 1142 | + if($counter === 1 && false !== $this->banner_image){$counter++;continue;} |
|
| 1143 | 1143 | |
| 1144 | - $this->gallery_meta[] = $this->attach_image($image_data,$id); |
|
| 1145 | - $counter++; |
|
| 1146 | - } |
|
| 1144 | + $this->gallery_meta[] = $this->attach_image($image_data,$id); |
|
| 1145 | + $counter++; |
|
| 1146 | + } |
|
| 1147 | 1147 | |
| 1148 | - if(!empty($this->gallery_meta)){ |
|
| 1149 | - delete_post_meta($id,'gallery'); |
|
| 1148 | + if(!empty($this->gallery_meta)){ |
|
| 1149 | + delete_post_meta($id,'gallery'); |
|
| 1150 | 1150 | $this->gallery_meta = array_unique($this->gallery_meta); |
| 1151 | - foreach($this->gallery_meta as $gallery_id){ |
|
| 1152 | - if(false !== $gallery_id && '' !== $gallery_id && !is_array($gallery_id)){ |
|
| 1153 | - add_post_meta($id,'gallery',$gallery_id,false); |
|
| 1154 | - } |
|
| 1155 | - } |
|
| 1156 | - } |
|
| 1157 | - } |
|
| 1151 | + foreach($this->gallery_meta as $gallery_id){ |
|
| 1152 | + if(false !== $gallery_id && '' !== $gallery_id && !is_array($gallery_id)){ |
|
| 1153 | + add_post_meta($id,'gallery',$gallery_id,false); |
|
| 1154 | + } |
|
| 1155 | + } |
|
| 1156 | + } |
|
| 1157 | + } |
|
| 1158 | 1158 | } |
| 1159 | 1159 | |
| 1160 | 1160 | /** |
@@ -1163,42 +1163,42 @@ discard block |
||
| 1163 | 1163 | public function attach_image($v=false,$parent_id,$image_sizes=false){ |
| 1164 | 1164 | if(false !== $v){ |
| 1165 | 1165 | $temp_fragment = explode('/',$v['url_fragment']); |
| 1166 | - $url_filename = $temp_fragment[count($temp_fragment)-1]; |
|
| 1167 | - $url_filename = str_replace(array('.jpg','.png','.jpeg'),'',$url_filename); |
|
| 1166 | + $url_filename = $temp_fragment[count($temp_fragment)-1]; |
|
| 1167 | + $url_filename = str_replace(array('.jpg','.png','.jpeg'),'',$url_filename); |
|
| 1168 | 1168 | |
| 1169 | - if(in_array($url_filename,$this->found_attachments)){ |
|
| 1170 | - return array_search($url_filename,$this->found_attachments); |
|
| 1171 | - } |
|
| 1169 | + if(in_array($url_filename,$this->found_attachments)){ |
|
| 1170 | + return array_search($url_filename,$this->found_attachments); |
|
| 1171 | + } |
|
| 1172 | 1172 | |
| 1173 | - $postdata=array(); |
|
| 1174 | - if(empty($v['label'])) |
|
| 1175 | - { |
|
| 1176 | - $v['label']=''; |
|
| 1177 | - } |
|
| 1178 | - if(!empty($v['description'])) |
|
| 1179 | - { |
|
| 1180 | - $desc=wp_strip_all_tags($v['description']); |
|
| 1181 | - $posdata=array('post_excerpt'=>$desc); |
|
| 1182 | - } |
|
| 1183 | - if(!empty($v['section'])) |
|
| 1184 | - { |
|
| 1185 | - $desc=wp_strip_all_tags($v['section']); |
|
| 1186 | - $posdata=array('post_excerpt'=>$desc); |
|
| 1187 | - } |
|
| 1188 | - |
|
| 1189 | - $attachID=NULL; |
|
| 1190 | - //Resizor - add option to setting if required |
|
| 1191 | - $fragment = str_replace(' ','%20',$v['url_fragment']); |
|
| 1192 | - $url = $this->get_scaling_url($image_sizes).$fragment; |
|
| 1193 | - $attachID = $this->attach_external_image2($url,$parent_id,'',$v['label'],$postdata); |
|
| 1194 | - |
|
| 1195 | - //echo($attachID.' add image'); |
|
| 1196 | - if($attachID!=NULL) |
|
| 1197 | - { |
|
| 1198 | - return $attachID; |
|
| 1199 | - } |
|
| 1200 | - } |
|
| 1201 | - return false; |
|
| 1173 | + $postdata=array(); |
|
| 1174 | + if(empty($v['label'])) |
|
| 1175 | + { |
|
| 1176 | + $v['label']=''; |
|
| 1177 | + } |
|
| 1178 | + if(!empty($v['description'])) |
|
| 1179 | + { |
|
| 1180 | + $desc=wp_strip_all_tags($v['description']); |
|
| 1181 | + $posdata=array('post_excerpt'=>$desc); |
|
| 1182 | + } |
|
| 1183 | + if(!empty($v['section'])) |
|
| 1184 | + { |
|
| 1185 | + $desc=wp_strip_all_tags($v['section']); |
|
| 1186 | + $posdata=array('post_excerpt'=>$desc); |
|
| 1187 | + } |
|
| 1188 | + |
|
| 1189 | + $attachID=NULL; |
|
| 1190 | + //Resizor - add option to setting if required |
|
| 1191 | + $fragment = str_replace(' ','%20',$v['url_fragment']); |
|
| 1192 | + $url = $this->get_scaling_url($image_sizes).$fragment; |
|
| 1193 | + $attachID = $this->attach_external_image2($url,$parent_id,'',$v['label'],$postdata); |
|
| 1194 | + |
|
| 1195 | + //echo($attachID.' add image'); |
|
| 1196 | + if($attachID!=NULL) |
|
| 1197 | + { |
|
| 1198 | + return $attachID; |
|
| 1199 | + } |
|
| 1200 | + } |
|
| 1201 | + return false; |
|
| 1202 | 1202 | } |
| 1203 | 1203 | public function attach_external_image2( $url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array() ) { |
| 1204 | 1204 | |