@@ -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(false !== $importable_content && in_array('location',$importable_content)){ |
|
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(false !== $importable_content && in_array('location',$importable_content)){ |
|
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 |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | * Display the importer administration screen |
107 | 107 | */ |
108 | 108 | public function display_page() { |
109 | - ?> |
|
109 | + ?> |
|
110 | 110 | <div class="wrap"> |
111 | 111 | <?php screen_icon(); ?> |
112 | 112 | |
@@ -233,13 +233,13 @@ discard block |
||
233 | 233 | $result = $this->update_options(); |
234 | 234 | |
235 | 235 | if(true === $result){ |
236 | - echo '<span style="color:green;">'.esc_attr('Connected','wetu-importer').'</span>'; |
|
237 | - }else{ |
|
238 | - echo '<span style="color:red;">'.wp_kses_post($result).'</span>'; |
|
239 | - } |
|
236 | + echo '<span style="color:green;">'.esc_attr('Connected','wetu-importer').'</span>'; |
|
237 | + }else{ |
|
238 | + echo '<span style="color:red;">'.wp_kses_post($result).'</span>'; |
|
239 | + } |
|
240 | 240 | }else{ |
241 | 241 | echo '<span style="color:green;">'.esc_attr('Connected','wetu-importer').'</span>'; |
242 | - } |
|
242 | + } |
|
243 | 243 | echo '</h3></div>'; |
244 | 244 | } |
245 | 245 | |
@@ -251,8 +251,8 @@ discard block |
||
251 | 251 | $tours = json_decode($data, true); |
252 | 252 | |
253 | 253 | if(isset($tours['error'])){ |
254 | - return $tours['error']; |
|
255 | - }elseif (isset($tours['itineraries']) && !empty($tours['itineraries'])) { |
|
254 | + return $tours['error']; |
|
255 | + }elseif (isset($tours['itineraries']) && !empty($tours['itineraries'])) { |
|
256 | 256 | set_transient('lsx_ti_tours',$tours['itineraries'],60*60*2); |
257 | 257 | return true; |
258 | 258 | } |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | $keyphrases = $_POST['keyword']; |
302 | 302 | }else{ |
303 | 303 | $keyphrases = array(0); |
304 | - } |
|
304 | + } |
|
305 | 305 | |
306 | 306 | if(!is_array($keyphrases)){ |
307 | 307 | $keyphrases = array($keyphrases); |
@@ -330,15 +330,15 @@ discard block |
||
330 | 330 | |
331 | 331 | foreach($tours as $row_key => $row){ |
332 | 332 | |
333 | - if(isset($row['is_disabled']) && true === $row['is_disabled']){ |
|
334 | - continue; |
|
335 | - } |
|
333 | + if(isset($row['is_disabled']) && true === $row['is_disabled']){ |
|
334 | + continue; |
|
335 | + } |
|
336 | 336 | |
337 | - /*if('Sample' === $row['type']){ |
|
337 | + /*if('Sample' === $row['type']){ |
|
338 | 338 | continue; |
339 | 339 | }*/ |
340 | 340 | |
341 | - //If this is a current tour, add its ID to the row. |
|
341 | + //If this is a current tour, add its ID to the row. |
|
342 | 342 | $row['post_id'] = 0; |
343 | 343 | if(false !== $current_tours && array_key_exists($row['identifier'], $current_tours)){ |
344 | 344 | $row['post_id'] = $current_tours[$row['identifier']]->post_id; |
@@ -347,31 +347,31 @@ discard block |
||
347 | 347 | //If we are searching for |
348 | 348 | if(false !== $post_status){ |
349 | 349 | |
350 | - if('import' === $post_status){ |
|
350 | + if('import' === $post_status){ |
|
351 | 351 | |
352 | 352 | if(0 !== $row['post_id']){ |
353 | - continue; |
|
353 | + continue; |
|
354 | 354 | }else{ |
355 | 355 | $searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row); |
356 | - } |
|
356 | + } |
|
357 | 357 | |
358 | 358 | |
359 | - }else{ |
|
359 | + }else{ |
|
360 | 360 | |
361 | 361 | if(0 === $row['post_id']){ |
362 | 362 | continue; |
363 | 363 | }else{ |
364 | 364 | $current_status = get_post_status($row['post_id']); |
365 | 365 | if($current_status !== $post_status){ |
366 | - continue; |
|
367 | - } |
|
366 | + continue; |
|
367 | + } |
|
368 | 368 | |
369 | 369 | } |
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 | //Search through each keyword. |
376 | 376 | foreach($keyphrases as $keyphrase){ |
377 | 377 | |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | $searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row); |
386 | 386 | } |
387 | 387 | } |
388 | - } |
|
388 | + } |
|
389 | 389 | } |
390 | 390 | } |
391 | 391 | |
@@ -450,17 +450,17 @@ discard block |
||
450 | 450 | $content = false; |
451 | 451 | } |
452 | 452 | |
453 | - $jdata=file_get_contents("http://wetu.com/API/Itinerary/V7/Get?id=".$wetu_id); |
|
453 | + $jdata=file_get_contents("http://wetu.com/API/Itinerary/V7/Get?id=".$wetu_id); |
|
454 | 454 | |
455 | - if($jdata) |
|
456 | - { |
|
455 | + if($jdata) |
|
456 | + { |
|
457 | 457 | $jdata=json_decode($jdata,true); |
458 | - if(!empty($jdata)) |
|
459 | - { |
|
460 | - $return = $this->import_row($jdata,$wetu_id,$post_id,$content); |
|
461 | - $this->format_completed_row($return); |
|
462 | - } |
|
463 | - } |
|
458 | + if(!empty($jdata)) |
|
459 | + { |
|
460 | + $return = $this->import_row($jdata,$wetu_id,$post_id,$content); |
|
461 | + $this->format_completed_row($return); |
|
462 | + } |
|
463 | + } |
|
464 | 464 | die(); |
465 | 465 | } |
466 | 466 | |
@@ -468,61 +468,61 @@ discard block |
||
468 | 468 | |
469 | 469 | /** |
470 | 470 | * Connect to wetu |
471 | - * |
|
472 | - * @param $data array |
|
473 | - * @param $wetu_id string |
|
471 | + * |
|
472 | + * @param $data array |
|
473 | + * @param $wetu_id string |
|
474 | 474 | */ |
475 | 475 | public function import_row($data,$wetu_id,$id=0,$importable_content=false,$old1=false,$old2=false) { |
476 | - $post_name = $data_post_content = $data_post_excerpt = ''; |
|
477 | - $post = array( |
|
478 | - 'post_type' => 'tour', |
|
479 | - ); |
|
476 | + $post_name = $data_post_content = $data_post_excerpt = ''; |
|
477 | + $post = array( |
|
478 | + 'post_type' => 'tour', |
|
479 | + ); |
|
480 | 480 | |
481 | - //Set the post_content |
|
481 | + //Set the post_content |
|
482 | 482 | $content_used_general_description = false; |
483 | - if(false !== $importable_content && in_array('description',$importable_content)){ |
|
484 | - $data_post_content = ''; |
|
485 | - |
|
486 | - if(isset($data['description'])){ |
|
487 | - $data_post_content = $data['description']; |
|
488 | - }elseif(isset($data['summary'])){ |
|
489 | - $data_post_content = $data['summary']; |
|
490 | - $content_used_general_description = true; |
|
491 | - } |
|
492 | - $post['post_content'] = wp_strip_all_tags($data_post_content); |
|
493 | - } |
|
494 | - |
|
495 | - //set the post_excerpt |
|
496 | - if(false !== $importable_content && in_array('excerpt',$importable_content)){ |
|
497 | - if(isset($data['summary']) && false === $content_used_general_description){ |
|
498 | - $post['post_excerpt'] = $data['summary']; |
|
499 | - } |
|
500 | - } |
|
501 | - |
|
502 | - //Create or update the post |
|
503 | - if(false !== $id && '0' !== $id){ |
|
504 | - $post['ID'] = $id; |
|
505 | - $post['post_status'] = 'publish'; |
|
506 | - $id = wp_update_post($post); |
|
507 | - $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
508 | - update_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified']),$prev_date); |
|
509 | - }else{ |
|
510 | - |
|
511 | - //Set the name |
|
512 | - if(isset($data['name'])){ |
|
513 | - $post_name = wp_unique_post_slug(sanitize_title($data['name']),$id, 'draft', 'tour', 0); |
|
514 | - } |
|
515 | - $post['post_name'] = $post_name; |
|
516 | - $post['post_title'] = $data['name']; |
|
517 | - $post['post_status'] = 'publish'; |
|
518 | - $id = wp_insert_post($post); |
|
519 | - |
|
520 | - //Save the WETU ID and the Last date it was modified. |
|
521 | - if(false !== $id){ |
|
522 | - add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
523 | - add_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified'])); |
|
524 | - } |
|
525 | - } |
|
483 | + if(false !== $importable_content && in_array('description',$importable_content)){ |
|
484 | + $data_post_content = ''; |
|
485 | + |
|
486 | + if(isset($data['description'])){ |
|
487 | + $data_post_content = $data['description']; |
|
488 | + }elseif(isset($data['summary'])){ |
|
489 | + $data_post_content = $data['summary']; |
|
490 | + $content_used_general_description = true; |
|
491 | + } |
|
492 | + $post['post_content'] = wp_strip_all_tags($data_post_content); |
|
493 | + } |
|
494 | + |
|
495 | + //set the post_excerpt |
|
496 | + if(false !== $importable_content && in_array('excerpt',$importable_content)){ |
|
497 | + if(isset($data['summary']) && false === $content_used_general_description){ |
|
498 | + $post['post_excerpt'] = $data['summary']; |
|
499 | + } |
|
500 | + } |
|
501 | + |
|
502 | + //Create or update the post |
|
503 | + if(false !== $id && '0' !== $id){ |
|
504 | + $post['ID'] = $id; |
|
505 | + $post['post_status'] = 'publish'; |
|
506 | + $id = wp_update_post($post); |
|
507 | + $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
508 | + update_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified']),$prev_date); |
|
509 | + }else{ |
|
510 | + |
|
511 | + //Set the name |
|
512 | + if(isset($data['name'])){ |
|
513 | + $post_name = wp_unique_post_slug(sanitize_title($data['name']),$id, 'draft', 'tour', 0); |
|
514 | + } |
|
515 | + $post['post_name'] = $post_name; |
|
516 | + $post['post_title'] = $data['name']; |
|
517 | + $post['post_status'] = 'publish'; |
|
518 | + $id = wp_insert_post($post); |
|
519 | + |
|
520 | + //Save the WETU ID and the Last date it was modified. |
|
521 | + if(false !== $id){ |
|
522 | + add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
523 | + add_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified'])); |
|
524 | + } |
|
525 | + } |
|
526 | 526 | |
527 | 527 | |
528 | 528 | //Set the price |
@@ -535,9 +535,9 @@ discard block |
||
535 | 535 | $this->set_duration($data,$id); |
536 | 536 | } |
537 | 537 | |
538 | - if(in_array('itineraries',$importable_content) && isset($data['legs']) && !empty($data['legs'])){ |
|
539 | - $this->process_itineraries($data,$id,$importable_content); |
|
540 | - } |
|
538 | + if(in_array('itineraries',$importable_content) && isset($data['legs']) && !empty($data['legs'])){ |
|
539 | + $this->process_itineraries($data,$id,$importable_content); |
|
540 | + } |
|
541 | 541 | |
542 | 542 | if(in_array('map',$importable_content) && isset($data['routes']) && !empty($data['routes'])){ |
543 | 543 | $this->process_map_points($data,$id); |
@@ -548,24 +548,24 @@ discard block |
||
548 | 548 | 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))){ |
549 | 549 | $this->find_attachments($id); |
550 | 550 | } |
551 | - //Set the featured image |
|
552 | - //TODO Test These |
|
553 | - if(false !== $importable_content && in_array('featured_image',$importable_content)){ |
|
554 | - $this->set_featured_image($data,$id); |
|
555 | - } |
|
551 | + //Set the featured image |
|
552 | + //TODO Test These |
|
553 | + if(false !== $importable_content && in_array('featured_image',$importable_content)){ |
|
554 | + $this->set_featured_image($data,$id); |
|
555 | + } |
|
556 | 556 | |
557 | 557 | //TODO Test These |
558 | - if(false !== $importable_content && in_array('banner_image',$importable_content)){ |
|
559 | - $this->set_banner_image($data,$id); |
|
560 | - } |
|
558 | + if(false !== $importable_content && in_array('banner_image',$importable_content)){ |
|
559 | + $this->set_banner_image($data,$id); |
|
560 | + } |
|
561 | 561 | |
562 | 562 | //TODO Test These |
563 | - //Import the main gallery |
|
564 | - if(false !== $importable_content && in_array('gallery',$importable_content)){ |
|
565 | - $this->create_main_gallery($data,$id); |
|
566 | - } |
|
563 | + //Import the main gallery |
|
564 | + if(false !== $importable_content && in_array('gallery',$importable_content)){ |
|
565 | + $this->create_main_gallery($data,$id); |
|
566 | + } |
|
567 | 567 | |
568 | - return $id; |
|
568 | + return $id; |
|
569 | 569 | } |
570 | 570 | |
571 | 571 | /** |
@@ -677,31 +677,31 @@ discard block |
||
677 | 677 | */ |
678 | 678 | public function process_map_points($data,$id) { |
679 | 679 | |
680 | - if(!empty($data['routes'])){ |
|
680 | + if(!empty($data['routes'])){ |
|
681 | 681 | |
682 | - delete_post_meta($id,'wetu_map_points'); |
|
682 | + delete_post_meta($id,'wetu_map_points'); |
|
683 | 683 | |
684 | - $points = array(); |
|
684 | + $points = array(); |
|
685 | 685 | |
686 | - foreach($data['routes'] as $route){ |
|
686 | + foreach($data['routes'] as $route){ |
|
687 | 687 | |
688 | 688 | |
689 | - if(isset($route['points']) && '' !== $route['points']){ |
|
689 | + if(isset($route['points']) && '' !== $route['points']){ |
|
690 | 690 | |
691 | - $temp_points = explode(';',$route['points']); |
|
692 | - $point_counter = count($temp_points); |
|
691 | + $temp_points = explode(';',$route['points']); |
|
692 | + $point_counter = count($temp_points); |
|
693 | 693 | |
694 | 694 | for ($x = 0; $x <= $point_counter; $x++) { |
695 | - $y = $x+1; |
|
695 | + $y = $x+1; |
|
696 | 696 | $points[] = $temp_points[$x].','.$temp_points[$y]; |
697 | 697 | $x++; |
698 | 698 | } |
699 | 699 | } |
700 | - } |
|
701 | - if(!empty($points)){ |
|
700 | + } |
|
701 | + if(!empty($points)){ |
|
702 | 702 | $this->save_custom_field(implode(' ',$points),'wetu_map_points',$id,false,true); |
703 | - } |
|
704 | - } |
|
703 | + } |
|
704 | + } |
|
705 | 705 | |
706 | 706 | } |
707 | 707 | |
@@ -709,7 +709,7 @@ discard block |
||
709 | 709 | * Set the Itinerary Day |
710 | 710 | */ |
711 | 711 | public function set_itinerary_day($day,$id) { |
712 | - $this->save_custom_field($day,'itinerary',$id,false,false); |
|
712 | + $this->save_custom_field($day,'itinerary',$id,false,false); |
|
713 | 713 | } |
714 | 714 | |
715 | 715 | /** |
@@ -717,8 +717,8 @@ discard block |
||
717 | 717 | */ |
718 | 718 | public function set_price($data,$id) { |
719 | 719 | if(isset($data['price']) && ''!== $data['price']){ |
720 | - $price = preg_replace("/[^0-9,.]/", "", $data['price']); |
|
721 | - $this->save_custom_field($price,'price',$id); |
|
720 | + $price = preg_replace("/[^0-9,.]/", "", $data['price']); |
|
721 | + $this->save_custom_field($price,'price',$id); |
|
722 | 722 | } |
723 | 723 | } |
724 | 724 | |
@@ -739,35 +739,35 @@ discard block |
||
739 | 739 | */ |
740 | 740 | public function set_accommodation($day,$id) { |
741 | 741 | |
742 | - $ac_id = false; |
|
742 | + $ac_id = false; |
|
743 | 743 | $this->current_accommodation = $this->find_current_accommodation(); |
744 | 744 | |
745 | 745 | if(isset($day['content_entity_id']) && !empty($day['content_entity_id'])){ |
746 | 746 | |
747 | 747 | if(false !== $this->current_accommodation && !empty($this->current_accommodation) && array_key_exists($day['content_entity_id'],$this->current_accommodation)){ |
748 | - $ac_id = $this->current_accommodation[$day['content_entity_id']]; |
|
748 | + $ac_id = $this->current_accommodation[$day['content_entity_id']]; |
|
749 | 749 | }else{ |
750 | 750 | $ac_id = wp_insert_post(array( |
751 | - 'post_type' => 'accommodation', |
|
752 | - 'post_status' => 'draft', |
|
753 | - 'post_title' => $day['content_entity_id'] |
|
754 | - )); |
|
751 | + 'post_type' => 'accommodation', |
|
752 | + 'post_status' => 'draft', |
|
753 | + 'post_title' => $day['content_entity_id'] |
|
754 | + )); |
|
755 | 755 | $this->save_custom_field($day['content_entity_id'],'lsx_wetu_id',$ac_id); |
756 | 756 | } |
757 | 757 | |
758 | 758 | if('' !== $ac_id && false !== $ac_id){ |
759 | - $this->save_custom_field($ac_id,'accommodation_to_tour',$id,false,false); |
|
759 | + $this->save_custom_field($ac_id,'accommodation_to_tour',$id,false,false); |
|
760 | 760 | $this->save_custom_field($id,'tour_to_accommodation',$ac_id,false,false); |
761 | - } |
|
761 | + } |
|
762 | 762 | } |
763 | 763 | return $ac_id; |
764 | 764 | } |
765 | 765 | |
766 | 766 | /** |
767 | 767 | * Grab all the current accommodation posts via the lsx_wetu_id field. |
768 | - * |
|
769 | - * @param $post_type string |
|
770 | - * @return boolean / array |
|
768 | + * |
|
769 | + * @param $post_type string |
|
770 | + * @return boolean / array |
|
771 | 771 | */ |
772 | 772 | public function find_current_accommodation($post_type='accommodation') { |
773 | 773 | global $wpdb; |
@@ -775,16 +775,16 @@ discard block |
||
775 | 775 | |
776 | 776 | $return = false; |
777 | 777 | if(!empty($accommodation)){ |
778 | - foreach($accommodation as $key => $acc){ |
|
778 | + foreach($accommodation as $key => $acc){ |
|
779 | 779 | $return[$acc->meta_value] = $acc->post_id; |
780 | - } |
|
781 | - } |
|
780 | + } |
|
781 | + } |
|
782 | 782 | return $return; |
783 | 783 | } |
784 | 784 | |
785 | 785 | /** |
786 | 786 | * Grab all the current accommodation posts via the lsx_wetu_id field. |
787 | - * @return boolean / array |
|
787 | + * @return boolean / array |
|
788 | 788 | */ |
789 | 789 | public function find_current_destinations() { |
790 | 790 | return $this->find_current_accommodation('destination'); |
@@ -811,7 +811,7 @@ discard block |
||
811 | 811 | $country_wetu_id = get_post_meta($potential_id,'lsx_wetu_id',true); |
812 | 812 | if(false !== $country_wetu_id){ |
813 | 813 | $this->set_country($country_wetu_id, $id); |
814 | - } |
|
814 | + } |
|
815 | 815 | |
816 | 816 | }else { |
817 | 817 | |
@@ -822,27 +822,27 @@ discard block |
||
822 | 822 | |
823 | 823 | if (!empty($destination_data) && !isset($destination_data['error'])) { |
824 | 824 | |
825 | - $destination_title = $day['destination_content_entity_id']; |
|
825 | + $destination_title = $day['destination_content_entity_id']; |
|
826 | 826 | |
827 | - if(isset($destination_data[0]['name'])){ |
|
827 | + if(isset($destination_data[0]['name'])){ |
|
828 | 828 | $destination_title = $destination_data[0]['name']; |
829 | - } |
|
829 | + } |
|
830 | 830 | |
831 | - if(isset($destination_data[0]['map_object_id']) && isset($destination_data[0]['position']['country_content_entity_id']) |
|
832 | - && $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id']){ |
|
831 | + if(isset($destination_data[0]['map_object_id']) && isset($destination_data[0]['position']['country_content_entity_id']) |
|
832 | + && $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id']){ |
|
833 | 833 | |
834 | 834 | $country_id = $this->set_country($destination_data[0]['position']['country_content_entity_id'], $id); |
835 | - } |
|
835 | + } |
|
836 | 836 | |
837 | - $dest_post = array( |
|
837 | + $dest_post = array( |
|
838 | 838 | 'post_type' => 'destination', |
839 | 839 | 'post_status' => 'draft', |
840 | 840 | 'post_title' => $destination_title |
841 | 841 | ); |
842 | 842 | |
843 | - if(false !== $country_id){ |
|
843 | + if(false !== $country_id){ |
|
844 | 844 | $dest_post['post_parent'] = $country_id; |
845 | - } |
|
845 | + } |
|
846 | 846 | $dest_id = wp_insert_post($dest_post); |
847 | 847 | |
848 | 848 | //Make sure we register the |
@@ -864,50 +864,50 @@ discard block |
||
864 | 864 | * Connects the destinations post type |
865 | 865 | * |
866 | 866 | * @param $dest_id string |
867 | - * @param $country_id array |
|
867 | + * @param $country_id array |
|
868 | 868 | * @param $id string |
869 | 869 | */ |
870 | 870 | public function set_country($country_wetu_id, $id) { |
871 | - $country_id = false; |
|
871 | + $country_id = false; |
|
872 | 872 | $this->current_destinations = $this->find_current_destinations(); |
873 | 873 | |
874 | - if (false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($country_wetu_id, $this->current_destinations)) { |
|
875 | - $country_id = $this->current_destinations[$country_wetu_id]; |
|
876 | - } else { |
|
874 | + if (false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($country_wetu_id, $this->current_destinations)) { |
|
875 | + $country_id = $this->current_destinations[$country_wetu_id]; |
|
876 | + } else { |
|
877 | 877 | |
878 | - $country_json = file_get_contents("http://wetu.com/API/Pins/".$this->api_key."/Get?ids=" . $country_wetu_id); |
|
878 | + $country_json = file_get_contents("http://wetu.com/API/Pins/".$this->api_key."/Get?ids=" . $country_wetu_id); |
|
879 | 879 | |
880 | - if ($country_json) { |
|
881 | - $country_data = json_decode($country_json, true); |
|
880 | + if ($country_json) { |
|
881 | + $country_data = json_decode($country_json, true); |
|
882 | 882 | |
883 | - if (!empty($country_data) && !isset($country_data['error'])) { |
|
883 | + if (!empty($country_data) && !isset($country_data['error'])) { |
|
884 | 884 | |
885 | 885 | //Format the title of the destination if its available, otherwise default to the WETU ID. |
886 | - $country_title = $country_wetu_id; |
|
887 | - if (isset($country_data[0]['name'])) { |
|
886 | + $country_title = $country_wetu_id; |
|
887 | + if (isset($country_data[0]['name'])) { |
|
888 | 888 | $country_title = $country_data[0]['name']; |
889 | - } |
|
889 | + } |
|
890 | 890 | |
891 | 891 | $country_id = wp_insert_post(array( |
892 | - 'post_type' => 'destination', |
|
893 | - 'post_status' => 'draft', |
|
894 | - 'post_title' => $country_title |
|
895 | - )); |
|
892 | + 'post_type' => 'destination', |
|
893 | + 'post_status' => 'draft', |
|
894 | + 'post_title' => $country_title |
|
895 | + )); |
|
896 | 896 | //add the country to the current destination stack |
897 | 897 | $this->current_destinations[$country_wetu_id] = $country_id; |
898 | 898 | |
899 | 899 | //Save the wetu field |
900 | - $this->save_custom_field($country_wetu_id, 'lsx_wetu_id', $country_id); |
|
901 | - } |
|
902 | - } |
|
903 | - } |
|
900 | + $this->save_custom_field($country_wetu_id, 'lsx_wetu_id', $country_id); |
|
901 | + } |
|
902 | + } |
|
903 | + } |
|
904 | 904 | |
905 | - if ('' !== $country_id && false !== $country_id) { |
|
906 | - $this->save_custom_field($country_id, 'destination_to_tour', $id, false, false); |
|
907 | - $this->save_custom_field($id, 'tour_to_destination', $country_id, false, false); |
|
905 | + if ('' !== $country_id && false !== $country_id) { |
|
906 | + $this->save_custom_field($country_id, 'destination_to_tour', $id, false, false); |
|
907 | + $this->save_custom_field($id, 'tour_to_destination', $country_id, false, false); |
|
908 | 908 | |
909 | - return $country_id; |
|
910 | - } |
|
909 | + return $country_id; |
|
910 | + } |
|
911 | 911 | } |
912 | 912 | } |
913 | 913 | $wetu_importer_tours = new WETU_Importer_Tours(); |
914 | 914 | \ No newline at end of file |