@@ -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,12); |
|
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,12); |
|
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 | |
@@ -773,11 +773,11 @@ discard block |
||
773 | 773 | 'elevation' => '', |
774 | 774 | ); |
775 | 775 | if(false !== $id && '0' !== $id){ |
776 | - $prev = get_post_meta($id,'location',true); |
|
777 | - update_post_meta($id,'location',$location_data,$prev); |
|
778 | - }else{ |
|
779 | - add_post_meta($id,'location',$location_data,true); |
|
780 | - } |
|
776 | + $prev = get_post_meta($id,'location',true); |
|
777 | + update_post_meta($id,'location',$location_data,$prev); |
|
778 | + }else{ |
|
779 | + add_post_meta($id,'location',$location_data,true); |
|
780 | + } |
|
781 | 781 | } |
782 | 782 | } |
783 | 783 | /** |
@@ -791,35 +791,35 @@ discard block |
||
791 | 791 | if(isset($data[0]['position']['country'])){ |
792 | 792 | |
793 | 793 | if(!$term = term_exists(trim($data[0]['position']['country']), 'location')) |
794 | - { |
|
795 | - $term = wp_insert_term(trim($data[0]['position']['country']), 'location'); |
|
796 | - if ( is_wp_error($term) ){ |
|
797 | - echo $term->get_error_message(); |
|
798 | - } |
|
799 | - else { |
|
800 | - wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
801 | - } |
|
802 | - } |
|
803 | - else |
|
804 | - { |
|
805 | - wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
806 | - } |
|
807 | - $country_id = intval($term['term_id']); |
|
808 | - } |
|
794 | + { |
|
795 | + $term = wp_insert_term(trim($data[0]['position']['country']), 'location'); |
|
796 | + if ( is_wp_error($term) ){ |
|
797 | + echo $term->get_error_message(); |
|
798 | + } |
|
799 | + else { |
|
800 | + wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
801 | + } |
|
802 | + } |
|
803 | + else |
|
804 | + { |
|
805 | + wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
806 | + } |
|
807 | + $country_id = intval($term['term_id']); |
|
808 | + } |
|
809 | 809 | |
810 | 810 | if(isset($data[0]['position']['destination'])){ |
811 | 811 | |
812 | 812 | $tax_args = array('parent'=>$country_id); |
813 | 813 | if(!$term = term_exists(trim($data[0]['position']['destination']), 'location')) |
814 | - { |
|
815 | - $term = wp_insert_term(trim($data[0]['position']['destination']), 'location', $tax_args); |
|
816 | - if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
817 | - else { wp_set_object_terms( $id, intval($term['term_id']), 'location',true); } |
|
818 | - } |
|
819 | - else |
|
820 | - { |
|
821 | - wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
822 | - } |
|
814 | + { |
|
815 | + $term = wp_insert_term(trim($data[0]['position']['destination']), 'location', $tax_args); |
|
816 | + if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
817 | + else { wp_set_object_terms( $id, intval($term['term_id']), 'location',true); } |
|
818 | + } |
|
819 | + else |
|
820 | + { |
|
821 | + wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
822 | + } |
|
823 | 823 | } |
824 | 824 | } |
825 | 825 | } |
@@ -829,31 +829,31 @@ discard block |
||
829 | 829 | */ |
830 | 830 | public function connect_destinations($data,$id) { |
831 | 831 | if(isset($data[0]['position'])){ |
832 | - $destinations = false; |
|
833 | - if(isset($data[0]['position']['country'])){ |
|
834 | - $destinations['country'] = $data[0]['position']['country']; |
|
835 | - } |
|
836 | - if(isset($data[0]['position']['destination'])){ |
|
837 | - $destinations['destination'] = $data[0]['position']['destination']; |
|
838 | - } |
|
832 | + $destinations = false; |
|
833 | + if(isset($data[0]['position']['country'])){ |
|
834 | + $destinations['country'] = $data[0]['position']['country']; |
|
835 | + } |
|
836 | + if(isset($data[0]['position']['destination'])){ |
|
837 | + $destinations['destination'] = $data[0]['position']['destination']; |
|
838 | + } |
|
839 | 839 | |
840 | - if(false !== $destinations){ |
|
841 | - $prev_values = get_post_meta($id,'destination_to_accommodation',false); |
|
842 | - if(false === $prev_values || !is_array($prev_values)){ |
|
843 | - $prev_values = array(); |
|
844 | - } |
|
845 | - //print_r($destinations); |
|
840 | + if(false !== $destinations){ |
|
841 | + $prev_values = get_post_meta($id,'destination_to_accommodation',false); |
|
842 | + if(false === $prev_values || !is_array($prev_values)){ |
|
843 | + $prev_values = array(); |
|
844 | + } |
|
845 | + //print_r($destinations); |
|
846 | 846 | $destinations = array_unique($destinations); |
847 | 847 | //print_r($destinations); |
848 | - foreach($destinations as $key => $value){ |
|
849 | - $destination = get_page_by_title(ltrim(rtrim($value)), 'OBJECT', 'destination'); |
|
850 | - if (null !== $destination) { |
|
851 | - if(!in_array($destination->ID,$prev_values)){ |
|
852 | - add_post_meta($id,'destination_to_accommodation',$destination->ID,false); |
|
853 | - add_post_meta($destination->ID,'accommodation_to_destination',$id,false); |
|
854 | - } |
|
855 | - } |
|
856 | - } |
|
848 | + foreach($destinations as $key => $value){ |
|
849 | + $destination = get_page_by_title(ltrim(rtrim($value)), 'OBJECT', 'destination'); |
|
850 | + if (null !== $destination) { |
|
851 | + if(!in_array($destination->ID,$prev_values)){ |
|
852 | + add_post_meta($id,'destination_to_accommodation',$destination->ID,false); |
|
853 | + add_post_meta($destination->ID,'accommodation_to_destination',$id,false); |
|
854 | + } |
|
855 | + } |
|
856 | + } |
|
857 | 857 | } |
858 | 858 | } |
859 | 859 | } |
@@ -865,15 +865,15 @@ discard block |
||
865 | 865 | $terms = false; |
866 | 866 | if(isset($data[0]['category'])){ |
867 | 867 | if(!$term = term_exists(trim($data[0]['category']), 'accommodation-type')) |
868 | - { |
|
869 | - $term = wp_insert_term(trim($data[0]['category']), 'accommodation-type'); |
|
870 | - if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
871 | - else { wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); } |
|
872 | - } |
|
873 | - else |
|
874 | - { |
|
875 | - wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); |
|
876 | - } |
|
868 | + { |
|
869 | + $term = wp_insert_term(trim($data[0]['category']), 'accommodation-type'); |
|
870 | + if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
871 | + else { wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); } |
|
872 | + } |
|
873 | + else |
|
874 | + { |
|
875 | + wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); |
|
876 | + } |
|
877 | 877 | } |
878 | 878 | } |
879 | 879 | |
@@ -897,25 +897,25 @@ discard block |
||
897 | 897 | $temp_room['type'] = 'room'; |
898 | 898 | |
899 | 899 | if(!empty($room['images']) && is_array($room['images'])){ |
900 | - $attachments_args = array( |
|
901 | - 'post_parent' => $id, |
|
902 | - 'post_status' => 'inherit', |
|
903 | - 'post_type' => 'attachment', |
|
904 | - 'order' => 'ASC', |
|
905 | - ); |
|
906 | - $attachments = new WP_Query($attachments_args); |
|
907 | - $found_attachments = array(); |
|
908 | - |
|
909 | - if($attachments->have_posts()){ |
|
910 | - foreach($attachments->posts as $attachment){ |
|
911 | - $found_attachments[] = str_replace(array('.jpg','.png','.jpeg'),'',$attachment->post_title); |
|
912 | - } |
|
913 | - } |
|
900 | + $attachments_args = array( |
|
901 | + 'post_parent' => $id, |
|
902 | + 'post_status' => 'inherit', |
|
903 | + 'post_type' => 'attachment', |
|
904 | + 'order' => 'ASC', |
|
905 | + ); |
|
906 | + $attachments = new WP_Query($attachments_args); |
|
907 | + $found_attachments = array(); |
|
908 | + |
|
909 | + if($attachments->have_posts()){ |
|
910 | + foreach($attachments->posts as $attachment){ |
|
911 | + $found_attachments[] = str_replace(array('.jpg','.png','.jpeg'),'',$attachment->post_title); |
|
912 | + } |
|
913 | + } |
|
914 | 914 | |
915 | 915 | $temp_room['gallery'] = array(); |
916 | 916 | foreach($room['images'] as $image_data){ |
917 | - $temp_room['gallery'][] = $this->attach_image($image_data,$id,$found_attachments); |
|
918 | - } |
|
917 | + $temp_room['gallery'][] = $this->attach_image($image_data,$id,$found_attachments); |
|
918 | + } |
|
919 | 919 | } |
920 | 920 | $rooms[] = $temp_room; |
921 | 921 | } |
@@ -924,7 +924,7 @@ discard block |
||
924 | 924 | delete_post_meta($id, 'units'); |
925 | 925 | } |
926 | 926 | foreach($rooms as $room){ |
927 | - add_post_meta($id,'units',$room,false); |
|
927 | + add_post_meta($id,'units',$room,false); |
|
928 | 928 | } |
929 | 929 | |
930 | 930 | if(isset($data[0]['features']) && isset($data[0]['features']['rooms'])){ |
@@ -934,11 +934,11 @@ discard block |
||
934 | 934 | } |
935 | 935 | |
936 | 936 | if(false !== $id && '0' !== $id){ |
937 | - $prev_rooms = get_post_meta($id,'number_of_rooms',true); |
|
938 | - update_post_meta($id,'number_of_rooms',$room_count,$prev_rooms); |
|
939 | - }else{ |
|
940 | - add_post_meta($id,'number_of_rooms',$room_count,true); |
|
941 | - } |
|
937 | + $prev_rooms = get_post_meta($id,'number_of_rooms',true); |
|
938 | + update_post_meta($id,'number_of_rooms',$room_count,$prev_rooms); |
|
939 | + }else{ |
|
940 | + add_post_meta($id,'number_of_rooms',$room_count,true); |
|
941 | + } |
|
942 | 942 | } |
943 | 943 | } |
944 | 944 | |
@@ -1048,7 +1048,7 @@ discard block |
||
1048 | 1048 | delete_post_meta($id, 'videos'); |
1049 | 1049 | } |
1050 | 1050 | foreach($videos as $video){ |
1051 | - add_post_meta($id,'videos',$video,false); |
|
1051 | + add_post_meta($id,'videos',$video,false); |
|
1052 | 1052 | } |
1053 | 1053 | } |
1054 | 1054 | } |
@@ -1077,17 +1077,17 @@ discard block |
||
1077 | 1077 | |
1078 | 1078 | function set_term($id=false,$name=false,$taxonomy=false,$parent=false){ |
1079 | 1079 | if(!$term = term_exists($name, $taxonomy)) |
1080 | - { |
|
1081 | - if(false !== $parent){ $parent = array('parent'=>$parent); } |
|
1082 | - $term = wp_insert_term(trim($name), $taxonomy,$parent); |
|
1083 | - if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
1084 | - else { wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); } |
|
1085 | - } |
|
1086 | - else |
|
1087 | - { |
|
1088 | - wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); |
|
1089 | - } |
|
1090 | - return $term['term_id']; |
|
1080 | + { |
|
1081 | + if(false !== $parent){ $parent = array('parent'=>$parent); } |
|
1082 | + $term = wp_insert_term(trim($name), $taxonomy,$parent); |
|
1083 | + if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
1084 | + else { wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); } |
|
1085 | + } |
|
1086 | + else |
|
1087 | + { |
|
1088 | + wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); |
|
1089 | + } |
|
1090 | + return $term['term_id']; |
|
1091 | 1091 | } |
1092 | 1092 | |
1093 | 1093 | /** |
@@ -1095,17 +1095,17 @@ discard block |
||
1095 | 1095 | */ |
1096 | 1096 | public function set_featured_image($data,$id) { |
1097 | 1097 | if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){ |
1098 | - $this->featured_image = $this->attach_image($data[0]['content']['images'][0],$id); |
|
1098 | + $this->featured_image = $this->attach_image($data[0]['content']['images'][0],$id); |
|
1099 | 1099 | |
1100 | - if(false !== $this->featured_image){ |
|
1101 | - delete_post_meta($id,'_thumbnail_id'); |
|
1102 | - add_post_meta($id,'_thumbnail_id',$this->featured_image,true); |
|
1100 | + if(false !== $this->featured_image){ |
|
1101 | + delete_post_meta($id,'_thumbnail_id'); |
|
1102 | + add_post_meta($id,'_thumbnail_id',$this->featured_image,true); |
|
1103 | 1103 | |
1104 | - if(!empty($this->gallery_meta) && !in_array($this->featured_image,$this->gallery_meta)){ |
|
1105 | - add_post_meta($id,'gallery',$this->featured_image,false); |
|
1106 | - $this->gallery_meta[] = $this->featured_image; |
|
1107 | - } |
|
1108 | - } |
|
1104 | + if(!empty($this->gallery_meta) && !in_array($this->featured_image,$this->gallery_meta)){ |
|
1105 | + add_post_meta($id,'gallery',$this->featured_image,false); |
|
1106 | + $this->gallery_meta[] = $this->featured_image; |
|
1107 | + } |
|
1108 | + } |
|
1109 | 1109 | } |
1110 | 1110 | } |
1111 | 1111 | |
@@ -1114,18 +1114,18 @@ discard block |
||
1114 | 1114 | */ |
1115 | 1115 | public function set_banner_image($data,$id) { |
1116 | 1116 | if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){ |
1117 | - $this->banner_image = $this->attach_image($data[0]['content']['images'][1],$id,array('width'=>'1920','height'=>'800','cropping'=>'c')); |
|
1118 | - |
|
1119 | - if(false !== $this->banner_image){ |
|
1120 | - delete_post_meta($id,'image_group'); |
|
1121 | - $new_banner = array('banner_image'=>array('cmb-field-0'=>$this->banner_image)); |
|
1122 | - add_post_meta($id,'image_group',$new_banner,true); |
|
1123 | - |
|
1124 | - if(!empty($this->gallery_meta) && !in_array($this->banner_image,$this->gallery_meta)){ |
|
1125 | - add_post_meta($id,'gallery',$this->banner_image,false); |
|
1126 | - $this->gallery_meta[] = $this->banner_image; |
|
1127 | - } |
|
1128 | - } |
|
1117 | + $this->banner_image = $this->attach_image($data[0]['content']['images'][1],$id,array('width'=>'1920','height'=>'800','cropping'=>'c')); |
|
1118 | + |
|
1119 | + if(false !== $this->banner_image){ |
|
1120 | + delete_post_meta($id,'image_group'); |
|
1121 | + $new_banner = array('banner_image'=>array('cmb-field-0'=>$this->banner_image)); |
|
1122 | + add_post_meta($id,'image_group',$new_banner,true); |
|
1123 | + |
|
1124 | + if(!empty($this->gallery_meta) && !in_array($this->banner_image,$this->gallery_meta)){ |
|
1125 | + add_post_meta($id,'gallery',$this->banner_image,false); |
|
1126 | + $this->gallery_meta[] = $this->banner_image; |
|
1127 | + } |
|
1128 | + } |
|
1129 | 1129 | } |
1130 | 1130 | } |
1131 | 1131 | |
@@ -1135,25 +1135,25 @@ discard block |
||
1135 | 1135 | public function create_main_gallery($data,$id) { |
1136 | 1136 | |
1137 | 1137 | if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){ |
1138 | - $counter = 0; |
|
1139 | - foreach($data[0]['content']['images'] as $image_data){ |
|
1140 | - if($counter === 0 && false !== $this->featured_image){$counter++;continue;} |
|
1141 | - if($counter === 1 && false !== $this->banner_image){$counter++;continue;} |
|
1138 | + $counter = 0; |
|
1139 | + foreach($data[0]['content']['images'] as $image_data){ |
|
1140 | + if($counter === 0 && false !== $this->featured_image){$counter++;continue;} |
|
1141 | + if($counter === 1 && false !== $this->banner_image){$counter++;continue;} |
|
1142 | 1142 | |
1143 | - $this->gallery_meta[] = $this->attach_image($image_data,$id); |
|
1144 | - $counter++; |
|
1145 | - } |
|
1143 | + $this->gallery_meta[] = $this->attach_image($image_data,$id); |
|
1144 | + $counter++; |
|
1145 | + } |
|
1146 | 1146 | |
1147 | - if(!empty($this->gallery_meta)){ |
|
1148 | - delete_post_meta($id,'gallery'); |
|
1147 | + if(!empty($this->gallery_meta)){ |
|
1148 | + delete_post_meta($id,'gallery'); |
|
1149 | 1149 | $this->gallery_meta = array_unique($this->gallery_meta); |
1150 | - foreach($this->gallery_meta as $gallery_id){ |
|
1151 | - if(false !== $gallery_id && '' !== $gallery_id && !is_array($gallery_id)){ |
|
1152 | - add_post_meta($id,'gallery',$gallery_id,false); |
|
1153 | - } |
|
1154 | - } |
|
1155 | - } |
|
1156 | - } |
|
1150 | + foreach($this->gallery_meta as $gallery_id){ |
|
1151 | + if(false !== $gallery_id && '' !== $gallery_id && !is_array($gallery_id)){ |
|
1152 | + add_post_meta($id,'gallery',$gallery_id,false); |
|
1153 | + } |
|
1154 | + } |
|
1155 | + } |
|
1156 | + } |
|
1157 | 1157 | } |
1158 | 1158 | |
1159 | 1159 | /** |
@@ -1162,42 +1162,42 @@ discard block |
||
1162 | 1162 | public function attach_image($v=false,$parent_id,$image_sizes=false){ |
1163 | 1163 | if(false !== $v){ |
1164 | 1164 | $temp_fragment = explode('/',$v['url_fragment']); |
1165 | - $url_filename = $temp_fragment[count($temp_fragment)-1]; |
|
1166 | - $url_filename = str_replace(array('.jpg','.png','.jpeg'),'',$url_filename); |
|
1165 | + $url_filename = $temp_fragment[count($temp_fragment)-1]; |
|
1166 | + $url_filename = str_replace(array('.jpg','.png','.jpeg'),'',$url_filename); |
|
1167 | 1167 | |
1168 | - if(in_array($url_filename,$this->found_attachments)){ |
|
1169 | - return array_search($url_filename,$this->found_attachments); |
|
1170 | - } |
|
1168 | + if(in_array($url_filename,$this->found_attachments)){ |
|
1169 | + return array_search($url_filename,$this->found_attachments); |
|
1170 | + } |
|
1171 | 1171 | |
1172 | - $postdata=array(); |
|
1173 | - if(empty($v['label'])) |
|
1174 | - { |
|
1175 | - $v['label']=''; |
|
1176 | - } |
|
1177 | - if(!empty($v['description'])) |
|
1178 | - { |
|
1179 | - $desc=wp_strip_all_tags($v['description']); |
|
1180 | - $posdata=array('post_excerpt'=>$desc); |
|
1181 | - } |
|
1182 | - if(!empty($v['section'])) |
|
1183 | - { |
|
1184 | - $desc=wp_strip_all_tags($v['section']); |
|
1185 | - $posdata=array('post_excerpt'=>$desc); |
|
1186 | - } |
|
1187 | - |
|
1188 | - $attachID=NULL; |
|
1189 | - //Resizor - add option to setting if required |
|
1190 | - $fragment = str_replace(' ','%20',$v['url_fragment']); |
|
1191 | - $url = $this->get_scaling_url($image_sizes).$fragment; |
|
1192 | - $attachID = $this->attach_external_image2($url,$parent_id,'',$v['label'],$postdata); |
|
1193 | - |
|
1194 | - //echo($attachID.' add image'); |
|
1195 | - if($attachID!=NULL) |
|
1196 | - { |
|
1197 | - return $attachID; |
|
1198 | - } |
|
1199 | - } |
|
1200 | - return false; |
|
1172 | + $postdata=array(); |
|
1173 | + if(empty($v['label'])) |
|
1174 | + { |
|
1175 | + $v['label']=''; |
|
1176 | + } |
|
1177 | + if(!empty($v['description'])) |
|
1178 | + { |
|
1179 | + $desc=wp_strip_all_tags($v['description']); |
|
1180 | + $posdata=array('post_excerpt'=>$desc); |
|
1181 | + } |
|
1182 | + if(!empty($v['section'])) |
|
1183 | + { |
|
1184 | + $desc=wp_strip_all_tags($v['section']); |
|
1185 | + $posdata=array('post_excerpt'=>$desc); |
|
1186 | + } |
|
1187 | + |
|
1188 | + $attachID=NULL; |
|
1189 | + //Resizor - add option to setting if required |
|
1190 | + $fragment = str_replace(' ','%20',$v['url_fragment']); |
|
1191 | + $url = $this->get_scaling_url($image_sizes).$fragment; |
|
1192 | + $attachID = $this->attach_external_image2($url,$parent_id,'',$v['label'],$postdata); |
|
1193 | + |
|
1194 | + //echo($attachID.' add image'); |
|
1195 | + if($attachID!=NULL) |
|
1196 | + { |
|
1197 | + return $attachID; |
|
1198 | + } |
|
1199 | + } |
|
1200 | + return false; |
|
1201 | 1201 | } |
1202 | 1202 | public function attach_external_image2( $url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array() ) { |
1203 | 1203 |