@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | * Display the importer administration screen |
123 | 123 | */ |
124 | 124 | public function display_page() { |
125 | - ?> |
|
125 | + ?> |
|
126 | 126 | <div class="wrap"> |
127 | 127 | <?php screen_icon(); ?> |
128 | 128 | |
@@ -300,8 +300,8 @@ discard block |
||
300 | 300 | $accommodation = json_decode($data, true); |
301 | 301 | |
302 | 302 | if(isset($accommodation['error'])){ |
303 | - return $accommodation['error']; |
|
304 | - }elseif (isset($accommodation) && !empty($accommodation)) { |
|
303 | + return $accommodation['error']; |
|
304 | + }elseif (isset($accommodation) && !empty($accommodation)) { |
|
305 | 305 | set_transient('lsx_ti_accommodation',$accommodation,60*60*2); |
306 | 306 | return true; |
307 | 307 | } |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | $keyphrases = $_POST['keyword']; |
350 | 350 | }else{ |
351 | 351 | $keyphrases = array(0); |
352 | - } |
|
352 | + } |
|
353 | 353 | |
354 | 354 | if(!is_array($keyphrases)){ |
355 | 355 | $keyphrases = array($keyphrases); |
@@ -446,13 +446,13 @@ discard block |
||
446 | 446 | public function multineedle_stripos($haystack, $needles, $offset=0) { |
447 | 447 | $found = false; |
448 | 448 | $needle_count = count($needles); |
449 | - foreach($needles as $needle) { |
|
450 | - if(false !== stripos($haystack, $needle, $offset)){ |
|
451 | - $found[] = true; |
|
452 | - } |
|
453 | - } |
|
454 | - if(false !== $found && $needle_count === count($found)){ |
|
455 | - return true; |
|
449 | + foreach($needles as $needle) { |
|
450 | + if(false !== stripos($haystack, $needle, $offset)){ |
|
451 | + $found[] = true; |
|
452 | + } |
|
453 | + } |
|
454 | + if(false !== $found && $needle_count === count($found)){ |
|
455 | + return true; |
|
456 | 456 | }else{ |
457 | 457 | return false; |
458 | 458 | } |
@@ -521,16 +521,16 @@ discard block |
||
521 | 521 | $content = false; |
522 | 522 | } |
523 | 523 | |
524 | - $jdata = file_get_contents( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id ); |
|
525 | - if($jdata) |
|
526 | - { |
|
527 | - $adata=json_decode($jdata,true); |
|
528 | - if(!empty($adata)) |
|
529 | - { |
|
530 | - $return = $this->import_row($adata,$wetu_id,$post_id,$team_members,$content,$safari_brands); |
|
531 | - $this->format_completed_row($return); |
|
532 | - } |
|
533 | - } |
|
524 | + $jdata = file_get_contents( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id ); |
|
525 | + if($jdata) |
|
526 | + { |
|
527 | + $adata=json_decode($jdata,true); |
|
528 | + if(!empty($adata)) |
|
529 | + { |
|
530 | + $return = $this->import_row($adata,$wetu_id,$post_id,$team_members,$content,$safari_brands); |
|
531 | + $this->format_completed_row($return); |
|
532 | + } |
|
533 | + } |
|
534 | 534 | |
535 | 535 | die(); |
536 | 536 | } |
@@ -547,148 +547,148 @@ discard block |
||
547 | 547 | */ |
548 | 548 | public function import_row($data,$wetu_id,$id=0,$team_members=false,$importable_content=false,$safari_brands=false) { |
549 | 549 | |
550 | - if(trim($data[0]['type'])=='Accommodation') |
|
551 | - { |
|
552 | - $post_name = $data_post_content = $data_post_excerpt = ''; |
|
553 | - $post = array( |
|
554 | - 'post_type' => 'accommodation', |
|
555 | - ); |
|
556 | - |
|
557 | - $content_used_general_description = false; |
|
558 | - |
|
559 | - //Set the post_content |
|
560 | - if(false !== $importable_content && in_array('description',$importable_content)){ |
|
561 | - if(isset($data[0]['content']['extended_description'])) |
|
562 | - { |
|
563 | - $data_post_content = $data[0]['content']['extended_description']; |
|
564 | - }elseif(isset($data[0]['content']['general_description'])){ |
|
565 | - $data_post_content = $data[0]['content']['general_description']; |
|
566 | - $content_used_general_description = true; |
|
567 | - }elseif(isset($data[0]['content']['teaser_description'])){ |
|
568 | - $data_post_content = $data[0]['content']['teaser_description']; |
|
569 | - } |
|
570 | - $post['post_content'] = wp_strip_all_tags($data_post_content); |
|
571 | - } |
|
572 | - |
|
573 | - //set the post_excerpt |
|
574 | - if(false !== $importable_content && in_array('excerpt',$importable_content)){ |
|
575 | - if(isset($data[0]['content']['teaser_description'])){ |
|
576 | - $data_post_excerpt = $data[0]['content']['teaser_description']; |
|
577 | - }elseif(isset($data[0]['content']['general_description']) && false === $content_used_general_description){ |
|
578 | - $data_post_excerpt = $data[0]['content']['general_description']; |
|
579 | - } |
|
580 | - $post['post_excerpt'] = $data_post_excerpt; |
|
581 | - } |
|
582 | - |
|
583 | - if(false !== $id && '0' !== $id){ |
|
584 | - $post['ID'] = $id; |
|
550 | + if(trim($data[0]['type'])=='Accommodation') |
|
551 | + { |
|
552 | + $post_name = $data_post_content = $data_post_excerpt = ''; |
|
553 | + $post = array( |
|
554 | + 'post_type' => 'accommodation', |
|
555 | + ); |
|
556 | + |
|
557 | + $content_used_general_description = false; |
|
558 | + |
|
559 | + //Set the post_content |
|
560 | + if(false !== $importable_content && in_array('description',$importable_content)){ |
|
561 | + if(isset($data[0]['content']['extended_description'])) |
|
562 | + { |
|
563 | + $data_post_content = $data[0]['content']['extended_description']; |
|
564 | + }elseif(isset($data[0]['content']['general_description'])){ |
|
565 | + $data_post_content = $data[0]['content']['general_description']; |
|
566 | + $content_used_general_description = true; |
|
567 | + }elseif(isset($data[0]['content']['teaser_description'])){ |
|
568 | + $data_post_content = $data[0]['content']['teaser_description']; |
|
569 | + } |
|
570 | + $post['post_content'] = wp_strip_all_tags($data_post_content); |
|
571 | + } |
|
572 | + |
|
573 | + //set the post_excerpt |
|
574 | + if(false !== $importable_content && in_array('excerpt',$importable_content)){ |
|
575 | + if(isset($data[0]['content']['teaser_description'])){ |
|
576 | + $data_post_excerpt = $data[0]['content']['teaser_description']; |
|
577 | + }elseif(isset($data[0]['content']['general_description']) && false === $content_used_general_description){ |
|
578 | + $data_post_excerpt = $data[0]['content']['general_description']; |
|
579 | + } |
|
580 | + $post['post_excerpt'] = $data_post_excerpt; |
|
581 | + } |
|
582 | + |
|
583 | + if(false !== $id && '0' !== $id){ |
|
584 | + $post['ID'] = $id; |
|
585 | 585 | if(isset($data[0]['name'])){ |
586 | 586 | $post['post_title'] = $data[0]['name']; |
587 | - $post['post_status'] = 'publish'; |
|
587 | + $post['post_status'] = 'publish'; |
|
588 | 588 | $post['post_name'] = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'accommodation', 0); |
589 | 589 | } |
590 | - $id = wp_update_post($post); |
|
591 | - $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
592 | - update_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified']),$prev_date); |
|
593 | - }else{ |
|
594 | - |
|
595 | - //Set the name |
|
596 | - if(isset($data[0]['name'])){ |
|
597 | - $post_name = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'accommodation', 0); |
|
598 | - } |
|
599 | - $post['post_name'] = $post_name; |
|
600 | - $post['post_title'] = $data[0]['name']; |
|
601 | - $post['post_status'] = 'publish'; |
|
602 | - $id = wp_insert_post($post); |
|
603 | - |
|
604 | - //Save the WETU ID and the Last date it was modified. |
|
605 | - if(false !== $id){ |
|
606 | - add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
607 | - add_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified'])); |
|
608 | - } |
|
609 | - } |
|
610 | - //Setup some default for use in the import |
|
611 | - if(false !== $importable_content && (in_array('gallery',$importable_content) || in_array('banner_image',$importable_content) || in_array('featured_image',$importable_content))){ |
|
590 | + $id = wp_update_post($post); |
|
591 | + $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
592 | + update_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified']),$prev_date); |
|
593 | + }else{ |
|
594 | + |
|
595 | + //Set the name |
|
596 | + if(isset($data[0]['name'])){ |
|
597 | + $post_name = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'accommodation', 0); |
|
598 | + } |
|
599 | + $post['post_name'] = $post_name; |
|
600 | + $post['post_title'] = $data[0]['name']; |
|
601 | + $post['post_status'] = 'publish'; |
|
602 | + $id = wp_insert_post($post); |
|
603 | + |
|
604 | + //Save the WETU ID and the Last date it was modified. |
|
605 | + if(false !== $id){ |
|
606 | + add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
607 | + add_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified'])); |
|
608 | + } |
|
609 | + } |
|
610 | + //Setup some default for use in the import |
|
611 | + if(false !== $importable_content && (in_array('gallery',$importable_content) || in_array('banner_image',$importable_content) || in_array('featured_image',$importable_content))){ |
|
612 | 612 | $this->find_attachments($id); |
613 | 613 | } |
614 | 614 | |
615 | - //Set the team member if it is there |
|
616 | - if(post_type_exists('team') && false !== $team_members && '' !== $team_members){ |
|
617 | - $this->set_team_member($id,$team_members); |
|
618 | - } |
|
619 | - |
|
620 | - //Set the safari brand |
|
621 | - if(false !== $safari_brands && '' !== $safari_brands){ |
|
622 | - $this->set_safari_brands($id,$safari_brands); |
|
623 | - |
|
624 | - } |
|
625 | - |
|
626 | - if(class_exists('LSX_TO_Maps')){ |
|
627 | - $this->set_map_data($data,$id); |
|
628 | - $this->set_location_taxonomy($data,$id); |
|
629 | - } |
|
630 | - |
|
631 | - if(post_type_exists('destination') && false !== $importable_content && in_array('destination',$importable_content)){ |
|
632 | - $this->connect_destinations($data,$id); |
|
633 | - } |
|
634 | - |
|
635 | - if(false !== $importable_content && in_array('category',$importable_content)){ |
|
636 | - $this->set_taxonomy_style($data,$id); |
|
637 | - } |
|
638 | - |
|
639 | - //Set the Room Data |
|
640 | - if(false !== $importable_content && in_array('rooms',$importable_content)){ |
|
641 | - $this->set_room_data($data,$id); |
|
642 | - } |
|
643 | - |
|
644 | - //Set the rating |
|
645 | - if(false !== $importable_content && in_array('rating',$importable_content)){ |
|
646 | - $this->set_rating($data,$id); |
|
647 | - } |
|
648 | - |
|
649 | - //Set the checkin checkout data |
|
650 | - if(false !== $importable_content && in_array('checkin',$importable_content)){ |
|
651 | - $this->set_checkin_checkout($data,$id); |
|
652 | - } |
|
653 | - |
|
654 | - //Set the Spoken Languages |
|
655 | - if(false !== $importable_content && in_array('spoken_languages',$importable_content)){ |
|
656 | - $this->set_spoken_languages($data,$id); |
|
657 | - } |
|
658 | - |
|
659 | - //Set the friendly options |
|
660 | - if(false !== $importable_content && in_array('friendly',$importable_content)){ |
|
661 | - $this->set_friendly($data,$id); |
|
662 | - } |
|
663 | - |
|
664 | - //Set the special_interests |
|
665 | - if(false !== $importable_content && in_array('special_interests',$importable_content)){ |
|
666 | - $this->set_special_interests($data,$id); |
|
667 | - } |
|
668 | - |
|
669 | - //Import the videos |
|
670 | - if(false !== $importable_content && in_array('videos',$importable_content)){ |
|
671 | - $this->set_video_data($data,$id); |
|
672 | - } |
|
673 | - |
|
674 | - //Import the facilities |
|
675 | - if(false !== $importable_content && in_array('facilities',$importable_content)){ |
|
676 | - $this->set_facilities($data,$id); |
|
677 | - } |
|
678 | - |
|
679 | - //Set the featured image |
|
680 | - if(false !== $importable_content && in_array('featured_image',$importable_content)){ |
|
681 | - $this->set_featured_image($data,$id); |
|
682 | - } |
|
683 | - if(false !== $importable_content && in_array('banner_image',$importable_content)){ |
|
684 | - $this->set_banner_image($data,$id); |
|
685 | - } |
|
686 | - //Import the main gallery |
|
687 | - if(false !== $importable_content && in_array('gallery',$importable_content)){ |
|
688 | - $this->create_main_gallery($data,$id); |
|
689 | - } |
|
690 | - } |
|
691 | - return $id; |
|
615 | + //Set the team member if it is there |
|
616 | + if(post_type_exists('team') && false !== $team_members && '' !== $team_members){ |
|
617 | + $this->set_team_member($id,$team_members); |
|
618 | + } |
|
619 | + |
|
620 | + //Set the safari brand |
|
621 | + if(false !== $safari_brands && '' !== $safari_brands){ |
|
622 | + $this->set_safari_brands($id,$safari_brands); |
|
623 | + |
|
624 | + } |
|
625 | + |
|
626 | + if(class_exists('LSX_TO_Maps')){ |
|
627 | + $this->set_map_data($data,$id); |
|
628 | + $this->set_location_taxonomy($data,$id); |
|
629 | + } |
|
630 | + |
|
631 | + if(post_type_exists('destination') && false !== $importable_content && in_array('destination',$importable_content)){ |
|
632 | + $this->connect_destinations($data,$id); |
|
633 | + } |
|
634 | + |
|
635 | + if(false !== $importable_content && in_array('category',$importable_content)){ |
|
636 | + $this->set_taxonomy_style($data,$id); |
|
637 | + } |
|
638 | + |
|
639 | + //Set the Room Data |
|
640 | + if(false !== $importable_content && in_array('rooms',$importable_content)){ |
|
641 | + $this->set_room_data($data,$id); |
|
642 | + } |
|
643 | + |
|
644 | + //Set the rating |
|
645 | + if(false !== $importable_content && in_array('rating',$importable_content)){ |
|
646 | + $this->set_rating($data,$id); |
|
647 | + } |
|
648 | + |
|
649 | + //Set the checkin checkout data |
|
650 | + if(false !== $importable_content && in_array('checkin',$importable_content)){ |
|
651 | + $this->set_checkin_checkout($data,$id); |
|
652 | + } |
|
653 | + |
|
654 | + //Set the Spoken Languages |
|
655 | + if(false !== $importable_content && in_array('spoken_languages',$importable_content)){ |
|
656 | + $this->set_spoken_languages($data,$id); |
|
657 | + } |
|
658 | + |
|
659 | + //Set the friendly options |
|
660 | + if(false !== $importable_content && in_array('friendly',$importable_content)){ |
|
661 | + $this->set_friendly($data,$id); |
|
662 | + } |
|
663 | + |
|
664 | + //Set the special_interests |
|
665 | + if(false !== $importable_content && in_array('special_interests',$importable_content)){ |
|
666 | + $this->set_special_interests($data,$id); |
|
667 | + } |
|
668 | + |
|
669 | + //Import the videos |
|
670 | + if(false !== $importable_content && in_array('videos',$importable_content)){ |
|
671 | + $this->set_video_data($data,$id); |
|
672 | + } |
|
673 | + |
|
674 | + //Import the facilities |
|
675 | + if(false !== $importable_content && in_array('facilities',$importable_content)){ |
|
676 | + $this->set_facilities($data,$id); |
|
677 | + } |
|
678 | + |
|
679 | + //Set the featured image |
|
680 | + if(false !== $importable_content && in_array('featured_image',$importable_content)){ |
|
681 | + $this->set_featured_image($data,$id); |
|
682 | + } |
|
683 | + if(false !== $importable_content && in_array('banner_image',$importable_content)){ |
|
684 | + $this->set_banner_image($data,$id); |
|
685 | + } |
|
686 | + //Import the main gallery |
|
687 | + if(false !== $importable_content && in_array('gallery',$importable_content)){ |
|
688 | + $this->create_main_gallery($data,$id); |
|
689 | + } |
|
690 | + } |
|
691 | + return $id; |
|
692 | 692 | } |
693 | 693 | |
694 | 694 | /** |
@@ -698,7 +698,7 @@ discard block |
||
698 | 698 | |
699 | 699 | delete_post_meta($id, 'team_to_'.$this->tab_slug); |
700 | 700 | foreach($team_members as $team){ |
701 | - add_post_meta($id,'team_to_'.$this->tab_slug,$team); |
|
701 | + add_post_meta($id,'team_to_'.$this->tab_slug,$team); |
|
702 | 702 | } |
703 | 703 | } |
704 | 704 | |
@@ -707,7 +707,7 @@ discard block |
||
707 | 707 | */ |
708 | 708 | public function set_safari_brands($id,$safari_brands) { |
709 | 709 | foreach($safari_brands as $safari_brand){ |
710 | - wp_set_object_terms( $id, intval($safari_brand), 'accommodation-brand',true); |
|
710 | + wp_set_object_terms( $id, intval($safari_brand), 'accommodation-brand',true); |
|
711 | 711 | } |
712 | 712 | } |
713 | 713 | |
@@ -759,11 +759,11 @@ discard block |
||
759 | 759 | 'elevation' => '', |
760 | 760 | ); |
761 | 761 | if(false !== $id && '0' !== $id){ |
762 | - $prev = get_post_meta($id,'location',true); |
|
763 | - update_post_meta($id,'location',$location_data,$prev); |
|
764 | - }else{ |
|
765 | - add_post_meta($id,'location',$location_data,true); |
|
766 | - } |
|
762 | + $prev = get_post_meta($id,'location',true); |
|
763 | + update_post_meta($id,'location',$location_data,$prev); |
|
764 | + }else{ |
|
765 | + add_post_meta($id,'location',$location_data,true); |
|
766 | + } |
|
767 | 767 | } |
768 | 768 | } |
769 | 769 | /** |
@@ -777,35 +777,35 @@ discard block |
||
777 | 777 | if(isset($data[0]['position']['country'])){ |
778 | 778 | |
779 | 779 | if(!$term = term_exists(trim($data[0]['position']['country']), 'location')) |
780 | - { |
|
781 | - $term = wp_insert_term(trim($data[0]['position']['country']), 'location'); |
|
782 | - if ( is_wp_error($term) ){ |
|
783 | - echo $term->get_error_message(); |
|
784 | - } |
|
785 | - else { |
|
786 | - wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
787 | - } |
|
788 | - } |
|
789 | - else |
|
790 | - { |
|
791 | - wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
792 | - } |
|
793 | - $country_id = intval($term['term_id']); |
|
794 | - } |
|
780 | + { |
|
781 | + $term = wp_insert_term(trim($data[0]['position']['country']), 'location'); |
|
782 | + if ( is_wp_error($term) ){ |
|
783 | + echo $term->get_error_message(); |
|
784 | + } |
|
785 | + else { |
|
786 | + wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
787 | + } |
|
788 | + } |
|
789 | + else |
|
790 | + { |
|
791 | + wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
792 | + } |
|
793 | + $country_id = intval($term['term_id']); |
|
794 | + } |
|
795 | 795 | |
796 | 796 | if(isset($data[0]['position']['destination'])){ |
797 | 797 | |
798 | 798 | $tax_args = array('parent'=>$country_id); |
799 | 799 | if(!$term = term_exists(trim($data[0]['position']['destination']), 'location')) |
800 | - { |
|
801 | - $term = wp_insert_term(trim($data[0]['position']['destination']), 'location', $tax_args); |
|
802 | - if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
803 | - else { wp_set_object_terms( $id, intval($term['term_id']), 'location',true); } |
|
804 | - } |
|
805 | - else |
|
806 | - { |
|
807 | - wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
808 | - } |
|
800 | + { |
|
801 | + $term = wp_insert_term(trim($data[0]['position']['destination']), 'location', $tax_args); |
|
802 | + if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
803 | + else { wp_set_object_terms( $id, intval($term['term_id']), 'location',true); } |
|
804 | + } |
|
805 | + else |
|
806 | + { |
|
807 | + wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
808 | + } |
|
809 | 809 | } |
810 | 810 | } |
811 | 811 | } |
@@ -815,28 +815,28 @@ discard block |
||
815 | 815 | */ |
816 | 816 | public function connect_destinations($data,$id) { |
817 | 817 | if(isset($data[0]['position'])){ |
818 | - $destinations = false; |
|
819 | - if(isset($data[0]['position']['country'])){ |
|
820 | - $destinations['country'] = $data[0]['position']['country']; |
|
821 | - } |
|
822 | - if(isset($data[0]['position']['destination'])){ |
|
823 | - $destinations['destination'] = $data[0]['position']['destination']; |
|
824 | - } |
|
818 | + $destinations = false; |
|
819 | + if(isset($data[0]['position']['country'])){ |
|
820 | + $destinations['country'] = $data[0]['position']['country']; |
|
821 | + } |
|
822 | + if(isset($data[0]['position']['destination'])){ |
|
823 | + $destinations['destination'] = $data[0]['position']['destination']; |
|
824 | + } |
|
825 | 825 | |
826 | - if(false !== $destinations){ |
|
827 | - $prev_values = get_post_meta($id,'destination_to_accommodation',false); |
|
828 | - if(false === $prev_values || !is_array($prev_values)){ |
|
829 | - $prev_values = array(); |
|
830 | - } |
|
831 | - foreach($destinations as $key => $value){ |
|
832 | - $destination = get_page_by_title(ltrim(rtrim($value)), 'OBJECT', 'destination'); |
|
833 | - if (null !== $destination) { |
|
834 | - if(!in_array($destination->ID,$prev_values)){ |
|
835 | - add_post_meta($id,'destination_to_accommodation',$destination->ID,false); |
|
836 | - add_post_meta($destination->ID,'accommodation_to_destination',$id,false); |
|
837 | - } |
|
838 | - } |
|
839 | - } |
|
826 | + if(false !== $destinations){ |
|
827 | + $prev_values = get_post_meta($id,'destination_to_accommodation',false); |
|
828 | + if(false === $prev_values || !is_array($prev_values)){ |
|
829 | + $prev_values = array(); |
|
830 | + } |
|
831 | + foreach($destinations as $key => $value){ |
|
832 | + $destination = get_page_by_title(ltrim(rtrim($value)), 'OBJECT', 'destination'); |
|
833 | + if (null !== $destination) { |
|
834 | + if(!in_array($destination->ID,$prev_values)){ |
|
835 | + add_post_meta($id,'destination_to_accommodation',$destination->ID,false); |
|
836 | + add_post_meta($destination->ID,'accommodation_to_destination',$id,false); |
|
837 | + } |
|
838 | + } |
|
839 | + } |
|
840 | 840 | } |
841 | 841 | } |
842 | 842 | } |
@@ -848,15 +848,15 @@ discard block |
||
848 | 848 | $terms = false; |
849 | 849 | if(isset($data[0]['category'])){ |
850 | 850 | if(!$term = term_exists(trim($data[0]['category']), 'accommodation-type')) |
851 | - { |
|
852 | - $term = wp_insert_term(trim($data[0]['category']), 'accommodation-type'); |
|
853 | - if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
854 | - else { wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); } |
|
855 | - } |
|
856 | - else |
|
857 | - { |
|
858 | - wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); |
|
859 | - } |
|
851 | + { |
|
852 | + $term = wp_insert_term(trim($data[0]['category']), 'accommodation-type'); |
|
853 | + if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
854 | + else { wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); } |
|
855 | + } |
|
856 | + else |
|
857 | + { |
|
858 | + wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); |
|
859 | + } |
|
860 | 860 | } |
861 | 861 | } |
862 | 862 | |
@@ -880,25 +880,25 @@ discard block |
||
880 | 880 | $temp_room['type'] = 'room'; |
881 | 881 | |
882 | 882 | if(!empty($room['images']) && is_array($room['images'])){ |
883 | - $attachments_args = array( |
|
884 | - 'post_parent' => $id, |
|
885 | - 'post_status' => 'inherit', |
|
886 | - 'post_type' => 'attachment', |
|
887 | - 'order' => 'ASC', |
|
888 | - ); |
|
889 | - $attachments = new WP_Query($attachments_args); |
|
890 | - $found_attachments = array(); |
|
891 | - |
|
892 | - if($attachments->have_posts()){ |
|
893 | - foreach($attachments->posts as $attachment){ |
|
894 | - $found_attachments[] = str_replace(array('.jpg','.png','.jpeg'),'',$attachment->post_title); |
|
895 | - } |
|
896 | - } |
|
883 | + $attachments_args = array( |
|
884 | + 'post_parent' => $id, |
|
885 | + 'post_status' => 'inherit', |
|
886 | + 'post_type' => 'attachment', |
|
887 | + 'order' => 'ASC', |
|
888 | + ); |
|
889 | + $attachments = new WP_Query($attachments_args); |
|
890 | + $found_attachments = array(); |
|
891 | + |
|
892 | + if($attachments->have_posts()){ |
|
893 | + foreach($attachments->posts as $attachment){ |
|
894 | + $found_attachments[] = str_replace(array('.jpg','.png','.jpeg'),'',$attachment->post_title); |
|
895 | + } |
|
896 | + } |
|
897 | 897 | |
898 | 898 | $temp_room['gallery'] = array(); |
899 | 899 | foreach($room['images'] as $image_data){ |
900 | - $temp_room['gallery'][] = $this->attach_image($image_data,$id,$found_attachments); |
|
901 | - } |
|
900 | + $temp_room['gallery'][] = $this->attach_image($image_data,$id,$found_attachments); |
|
901 | + } |
|
902 | 902 | } |
903 | 903 | $rooms[] = $temp_room; |
904 | 904 | } |
@@ -907,7 +907,7 @@ discard block |
||
907 | 907 | delete_post_meta($id, 'units'); |
908 | 908 | } |
909 | 909 | foreach($rooms as $room){ |
910 | - add_post_meta($id,'units',$room,false); |
|
910 | + add_post_meta($id,'units',$room,false); |
|
911 | 911 | } |
912 | 912 | |
913 | 913 | if(isset($data[0]['features']) && isset($data[0]['features']['rooms'])){ |
@@ -917,11 +917,11 @@ discard block |
||
917 | 917 | } |
918 | 918 | |
919 | 919 | if(false !== $id && '0' !== $id){ |
920 | - $prev_rooms = get_post_meta($id,'number_of_rooms',true); |
|
921 | - update_post_meta($id,'number_of_rooms',$room_count,$prev_rooms); |
|
922 | - }else{ |
|
923 | - add_post_meta($id,'number_of_rooms',$room_count,true); |
|
924 | - } |
|
920 | + $prev_rooms = get_post_meta($id,'number_of_rooms',true); |
|
921 | + update_post_meta($id,'number_of_rooms',$room_count,$prev_rooms); |
|
922 | + }else{ |
|
923 | + add_post_meta($id,'number_of_rooms',$room_count,true); |
|
924 | + } |
|
925 | 925 | } |
926 | 926 | } |
927 | 927 | |
@@ -1030,7 +1030,7 @@ discard block |
||
1030 | 1030 | delete_post_meta($id, 'videos'); |
1031 | 1031 | } |
1032 | 1032 | foreach($videos as $video){ |
1033 | - add_post_meta($id,'videos',$video,false); |
|
1033 | + add_post_meta($id,'videos',$video,false); |
|
1034 | 1034 | } |
1035 | 1035 | } |
1036 | 1036 | } |
@@ -1059,17 +1059,17 @@ discard block |
||
1059 | 1059 | |
1060 | 1060 | function set_term($id=false,$name=false,$taxonomy=false,$parent=false){ |
1061 | 1061 | if(!$term = term_exists($name, $taxonomy)) |
1062 | - { |
|
1063 | - if(false !== $parent){ $parent = array('parent'=>$parent); } |
|
1064 | - $term = wp_insert_term(trim($name), $taxonomy,$parent); |
|
1065 | - if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
1066 | - else { wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); } |
|
1067 | - } |
|
1068 | - else |
|
1069 | - { |
|
1070 | - wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); |
|
1071 | - } |
|
1072 | - return $term['term_id']; |
|
1062 | + { |
|
1063 | + if(false !== $parent){ $parent = array('parent'=>$parent); } |
|
1064 | + $term = wp_insert_term(trim($name), $taxonomy,$parent); |
|
1065 | + if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
1066 | + else { wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); } |
|
1067 | + } |
|
1068 | + else |
|
1069 | + { |
|
1070 | + wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); |
|
1071 | + } |
|
1072 | + return $term['term_id']; |
|
1073 | 1073 | } |
1074 | 1074 | |
1075 | 1075 | /** |
@@ -1077,17 +1077,17 @@ discard block |
||
1077 | 1077 | */ |
1078 | 1078 | public function set_featured_image($data,$id) { |
1079 | 1079 | if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){ |
1080 | - $this->featured_image = $this->attach_image($data[0]['content']['images'][0],$id); |
|
1080 | + $this->featured_image = $this->attach_image($data[0]['content']['images'][0],$id); |
|
1081 | 1081 | |
1082 | - if(false !== $this->featured_image){ |
|
1083 | - delete_post_meta($id,'_thumbnail_id'); |
|
1084 | - add_post_meta($id,'_thumbnail_id',$this->featured_image,true); |
|
1082 | + if(false !== $this->featured_image){ |
|
1083 | + delete_post_meta($id,'_thumbnail_id'); |
|
1084 | + add_post_meta($id,'_thumbnail_id',$this->featured_image,true); |
|
1085 | 1085 | |
1086 | - if(!empty($this->gallery_meta) && !in_array($this->featured_image,$this->gallery_meta)){ |
|
1087 | - add_post_meta($id,'gallery',$this->featured_image,false); |
|
1088 | - $this->gallery_meta[] = $this->featured_image; |
|
1089 | - } |
|
1090 | - } |
|
1086 | + if(!empty($this->gallery_meta) && !in_array($this->featured_image,$this->gallery_meta)){ |
|
1087 | + add_post_meta($id,'gallery',$this->featured_image,false); |
|
1088 | + $this->gallery_meta[] = $this->featured_image; |
|
1089 | + } |
|
1090 | + } |
|
1091 | 1091 | } |
1092 | 1092 | } |
1093 | 1093 | |
@@ -1096,18 +1096,18 @@ discard block |
||
1096 | 1096 | */ |
1097 | 1097 | public function set_banner_image($data,$id) { |
1098 | 1098 | if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){ |
1099 | - $this->banner_image = $this->attach_image($data[0]['content']['images'][1],$id,array('width'=>'1920','height'=>'800','cropping'=>'c')); |
|
1100 | - |
|
1101 | - if(false !== $this->banner_image){ |
|
1102 | - delete_post_meta($id,'image_group'); |
|
1103 | - $new_banner = array('banner_image'=>array('cmb-field-0'=>$this->banner_image)); |
|
1104 | - add_post_meta($id,'image_group',$new_banner,true); |
|
1105 | - |
|
1106 | - if(!empty($this->gallery_meta) && !in_array($this->banner_image,$this->gallery_meta)){ |
|
1107 | - add_post_meta($id,'gallery',$this->banner_image,false); |
|
1108 | - $this->gallery_meta[] = $this->banner_image; |
|
1109 | - } |
|
1110 | - } |
|
1099 | + $this->banner_image = $this->attach_image($data[0]['content']['images'][1],$id,array('width'=>'1920','height'=>'800','cropping'=>'c')); |
|
1100 | + |
|
1101 | + if(false !== $this->banner_image){ |
|
1102 | + delete_post_meta($id,'image_group'); |
|
1103 | + $new_banner = array('banner_image'=>array('cmb-field-0'=>$this->banner_image)); |
|
1104 | + add_post_meta($id,'image_group',$new_banner,true); |
|
1105 | + |
|
1106 | + if(!empty($this->gallery_meta) && !in_array($this->banner_image,$this->gallery_meta)){ |
|
1107 | + add_post_meta($id,'gallery',$this->banner_image,false); |
|
1108 | + $this->gallery_meta[] = $this->banner_image; |
|
1109 | + } |
|
1110 | + } |
|
1111 | 1111 | } |
1112 | 1112 | } |
1113 | 1113 | |
@@ -1118,24 +1118,24 @@ discard block |
||
1118 | 1118 | |
1119 | 1119 | if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){ |
1120 | 1120 | |
1121 | - $counter = 0; |
|
1122 | - foreach($data[0]['content']['images'] as $image_data){ |
|
1123 | - if($counter === 0 && false !== $this->featured_image){continue;} |
|
1124 | - if($counter === 1 && false !== $this->banner_image){continue;} |
|
1125 | - |
|
1126 | - $this->gallery_meta[] = $temp_id = $this->attach_image($image_data,$id); |
|
1127 | - $counter++; |
|
1128 | - } |
|
1129 | - |
|
1130 | - if(!empty($this->gallery_meta)){ |
|
1131 | - delete_post_meta($id,'gallery'); |
|
1132 | - foreach($this->gallery_meta as $gallery_id){ |
|
1133 | - if(false !== $gallery_id && '' !== $gallery_id && !is_array($gallery_id)){ |
|
1134 | - add_post_meta($id,'gallery',$gallery_id,false); |
|
1135 | - } |
|
1136 | - } |
|
1137 | - } |
|
1138 | - } |
|
1121 | + $counter = 0; |
|
1122 | + foreach($data[0]['content']['images'] as $image_data){ |
|
1123 | + if($counter === 0 && false !== $this->featured_image){continue;} |
|
1124 | + if($counter === 1 && false !== $this->banner_image){continue;} |
|
1125 | + |
|
1126 | + $this->gallery_meta[] = $temp_id = $this->attach_image($image_data,$id); |
|
1127 | + $counter++; |
|
1128 | + } |
|
1129 | + |
|
1130 | + if(!empty($this->gallery_meta)){ |
|
1131 | + delete_post_meta($id,'gallery'); |
|
1132 | + foreach($this->gallery_meta as $gallery_id){ |
|
1133 | + if(false !== $gallery_id && '' !== $gallery_id && !is_array($gallery_id)){ |
|
1134 | + add_post_meta($id,'gallery',$gallery_id,false); |
|
1135 | + } |
|
1136 | + } |
|
1137 | + } |
|
1138 | + } |
|
1139 | 1139 | } |
1140 | 1140 | |
1141 | 1141 | /** |
@@ -1144,42 +1144,42 @@ discard block |
||
1144 | 1144 | public function attach_image($v=false,$parent_id,$image_sizes=false){ |
1145 | 1145 | if(false !== $v){ |
1146 | 1146 | $temp_fragment = explode('/',$v['url_fragment']); |
1147 | - $url_filename = $temp_fragment[count($temp_fragment)-1]; |
|
1148 | - $url_filename = str_replace(array('.jpg','.png','.jpeg'),'',$url_filename); |
|
1147 | + $url_filename = $temp_fragment[count($temp_fragment)-1]; |
|
1148 | + $url_filename = str_replace(array('.jpg','.png','.jpeg'),'',$url_filename); |
|
1149 | 1149 | |
1150 | - if(in_array($url_filename,$this->found_attachments)){ |
|
1151 | - return array_search($url_filename,$this->found_attachments); |
|
1152 | - } |
|
1150 | + if(in_array($url_filename,$this->found_attachments)){ |
|
1151 | + return array_search($url_filename,$this->found_attachments); |
|
1152 | + } |
|
1153 | 1153 | |
1154 | - $postdata=array(); |
|
1155 | - if(empty($v['label'])) |
|
1156 | - { |
|
1157 | - $v['label']=''; |
|
1158 | - } |
|
1159 | - if(!empty($v['description'])) |
|
1160 | - { |
|
1161 | - $desc=wp_strip_all_tags($v['description']); |
|
1162 | - $posdata=array('post_excerpt'=>$desc); |
|
1163 | - } |
|
1164 | - if(!empty($v['section'])) |
|
1165 | - { |
|
1166 | - $desc=wp_strip_all_tags($v['section']); |
|
1167 | - $posdata=array('post_excerpt'=>$desc); |
|
1168 | - } |
|
1169 | - |
|
1170 | - $attachID=NULL; |
|
1171 | - //Resizor - add option to setting if required |
|
1172 | - $fragment = str_replace(' ','%20',$v['url_fragment']); |
|
1173 | - $url = $this->get_scaling_url($image_sizes).$fragment; |
|
1174 | - $attachID = $this->attach_external_image2($url,$parent_id,'',$v['label'],$postdata); |
|
1175 | - |
|
1176 | - //echo($attachID.' add image'); |
|
1177 | - if($attachID!=NULL) |
|
1178 | - { |
|
1179 | - return $attachID; |
|
1180 | - } |
|
1181 | - } |
|
1182 | - return false; |
|
1154 | + $postdata=array(); |
|
1155 | + if(empty($v['label'])) |
|
1156 | + { |
|
1157 | + $v['label']=''; |
|
1158 | + } |
|
1159 | + if(!empty($v['description'])) |
|
1160 | + { |
|
1161 | + $desc=wp_strip_all_tags($v['description']); |
|
1162 | + $posdata=array('post_excerpt'=>$desc); |
|
1163 | + } |
|
1164 | + if(!empty($v['section'])) |
|
1165 | + { |
|
1166 | + $desc=wp_strip_all_tags($v['section']); |
|
1167 | + $posdata=array('post_excerpt'=>$desc); |
|
1168 | + } |
|
1169 | + |
|
1170 | + $attachID=NULL; |
|
1171 | + //Resizor - add option to setting if required |
|
1172 | + $fragment = str_replace(' ','%20',$v['url_fragment']); |
|
1173 | + $url = $this->get_scaling_url($image_sizes).$fragment; |
|
1174 | + $attachID = $this->attach_external_image2($url,$parent_id,'',$v['label'],$postdata); |
|
1175 | + |
|
1176 | + //echo($attachID.' add image'); |
|
1177 | + if($attachID!=NULL) |
|
1178 | + { |
|
1179 | + return $attachID; |
|
1180 | + } |
|
1181 | + } |
|
1182 | + return false; |
|
1183 | 1183 | } |
1184 | 1184 | public function attach_external_image2( $url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array() ) { |
1185 | 1185 |
@@ -55,15 +55,15 @@ discard block |
||
55 | 55 | public function __construct() { |
56 | 56 | $this->set_variables(); |
57 | 57 | |
58 | - add_action( 'lsx_tour_importer_admin_tab_'.$this->tab_slug, array($this,'display_page') ); |
|
59 | - add_action('wp_ajax_lsx_tour_importer',array($this,'process_ajax_search')); |
|
60 | - add_action('wp_ajax_nopriv_lsx_tour_importer',array($this,'process_ajax_search')); |
|
58 | + add_action('lsx_tour_importer_admin_tab_'.$this->tab_slug, array($this, 'display_page')); |
|
59 | + add_action('wp_ajax_lsx_tour_importer', array($this, 'process_ajax_search')); |
|
60 | + add_action('wp_ajax_nopriv_lsx_tour_importer', array($this, 'process_ajax_search')); |
|
61 | 61 | |
62 | - add_action('wp_ajax_lsx_import_items',array($this,'process_ajax_import')); |
|
63 | - add_action('wp_ajax_nopriv_lsx_import_items',array($this,'process_ajax_import')); |
|
62 | + add_action('wp_ajax_lsx_import_items', array($this, 'process_ajax_import')); |
|
63 | + add_action('wp_ajax_nopriv_lsx_import_items', array($this, 'process_ajax_import')); |
|
64 | 64 | |
65 | - $temp_options = get_option('_lsx-to_settings',false); |
|
66 | - if(false !== $temp_options && isset($temp_options[$this->plugin_slug]) && !empty($temp_options[$this->plugin_slug])){ |
|
65 | + $temp_options = get_option('_lsx-to_settings', false); |
|
66 | + if (false !== $temp_options && isset($temp_options[$this->plugin_slug]) && !empty($temp_options[$this->plugin_slug])) { |
|
67 | 67 | $this->options = $temp_options[$this->plugin_slug]; |
68 | 68 | } |
69 | 69 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | // $this->url = 'https://wetu.com/API/Pins/'; |
81 | 81 | // $this->url_qs = 'username=' . $this->api_username . '&password=' . $this->api_password; |
82 | 82 | //} elseif ( false !== $this->api_key ) { |
83 | - $this->url = 'https://wetu.com/API/Pins/' . $this->api_key; |
|
83 | + $this->url = 'https://wetu.com/API/Pins/'.$this->api_key; |
|
84 | 84 | $this->url_qs = ''; |
85 | 85 | //} |
86 | 86 | } |
@@ -88,27 +88,27 @@ discard block |
||
88 | 88 | /** |
89 | 89 | * search_form |
90 | 90 | */ |
91 | - public function get_scaling_url($args=array()) { |
|
91 | + public function get_scaling_url($args = array()) { |
|
92 | 92 | |
93 | 93 | $defaults = array( |
94 | 94 | 'width' => '640', |
95 | 95 | 'height' => '480', |
96 | 96 | 'cropping' => 'c' |
97 | 97 | ); |
98 | - if(false !== $this->options){ |
|
99 | - if(isset($this->options['width']) && '' !== $this->options['width']){ |
|
98 | + if (false !== $this->options) { |
|
99 | + if (isset($this->options['width']) && '' !== $this->options['width']) { |
|
100 | 100 | $defaults['width'] = $this->options['width']; |
101 | 101 | } |
102 | 102 | |
103 | - if(isset($this->options['height']) && '' !== $this->options['height']){ |
|
103 | + if (isset($this->options['height']) && '' !== $this->options['height']) { |
|
104 | 104 | $defaults['height'] = $this->options['height']; |
105 | 105 | } |
106 | 106 | |
107 | - if(isset($this->options['cropping']) && '' !== $this->options['cropping']){ |
|
107 | + if (isset($this->options['cropping']) && '' !== $this->options['cropping']) { |
|
108 | 108 | $defaults['cropping'] = $this->options['cropping']; |
109 | 109 | } |
110 | 110 | } |
111 | - $args = wp_parse_args($args,$defaults); |
|
111 | + $args = wp_parse_args($args, $defaults); |
|
112 | 112 | |
113 | 113 | $cropping = $args['cropping']; |
114 | 114 | $width = $args['width']; |
@@ -133,8 +133,8 @@ discard block |
||
133 | 133 | <form method="get" action="" id="posts-filter"> |
134 | 134 | <input type="hidden" name="post_type" class="post_type" value="<?php echo $this->tab_slug; ?>" /> |
135 | 135 | |
136 | - <p><input class="button button-primary add" type="button" value="<?php _e('Add to List','wetu-importer'); ?>" /> |
|
137 | - <input class="button button-primary clear" type="button" value="<?php _e('Clear','wetu-importer'); ?>" /> |
|
136 | + <p><input class="button button-primary add" type="button" value="<?php _e('Add to List', 'wetu-importer'); ?>" /> |
|
137 | + <input class="button button-primary clear" type="button" value="<?php _e('Clear', 'wetu-importer'); ?>" /> |
|
138 | 138 | </p> |
139 | 139 | |
140 | 140 | <table class="wp-list-table widefat fixed posts"> |
@@ -143,11 +143,11 @@ discard block |
||
143 | 143 | <tbody id="the-list"> |
144 | 144 | <tr class="post-0 type-tour status-none" id="post-0"> |
145 | 145 | <th class="check-column" scope="row"> |
146 | - <label for="cb-select-0" class="screen-reader-text"><?php _e('Enter a title to search for and press enter','wetu-importer'); ?></label> |
|
146 | + <label for="cb-select-0" class="screen-reader-text"><?php _e('Enter a title to search for and press enter', 'wetu-importer'); ?></label> |
|
147 | 147 | </th> |
148 | 148 | <td class="post-title page-title column-title"> |
149 | 149 | <strong> |
150 | - <?php _e('Enter a title to search for','wetu-importer'); ?> |
|
150 | + <?php _e('Enter a title to search for', 'wetu-importer'); ?> |
|
151 | 151 | </strong> |
152 | 152 | </td> |
153 | 153 | <td class="date column-date"> |
@@ -161,8 +161,8 @@ discard block |
||
161 | 161 | |
162 | 162 | </table> |
163 | 163 | |
164 | - <p><input class="button button-primary add" type="button" value="<?php _e('Add to List','wetu-importer'); ?>" /> |
|
165 | - <input class="button button-primary clear" type="button" value="<?php _e('Clear','wetu-importer'); ?>" /> |
|
164 | + <p><input class="button button-primary add" type="button" value="<?php _e('Add to List', 'wetu-importer'); ?>" /> |
|
165 | + <input class="button button-primary clear" type="button" value="<?php _e('Clear', 'wetu-importer'); ?>" /> |
|
166 | 166 | </p> |
167 | 167 | </form> |
168 | 168 | |
@@ -174,31 +174,31 @@ discard block |
||
174 | 174 | <div style="width:30%;display:block;float:left;"> |
175 | 175 | <h3><?php _e('What content to Sync from WETU'); ?></h3> |
176 | 176 | <ul> |
177 | - <li><input class="content" type="checkbox" name="content[]" value="description" /> <?php _e('Description','wetu-importer'); ?></li> |
|
178 | - <li><input class="content" type="checkbox" name="content[]" value="excerpt" /> <?php _e('Excerpt','wetu-importer'); ?></li> |
|
179 | - <li><input class="content" type="checkbox" name="content[]" value="gallery" /> <?php _e('Main Gallery','wetu-importer'); ?></li> |
|
180 | - <li><input class="content" type="checkbox" name="content[]" value="category" /> <?php _e('Category','wetu-importer'); ?></li> |
|
181 | - <?php if(class_exists('TO_Maps')){ ?> |
|
182 | - <li><input class="content" type="checkbox" name="content[]" value="location" /> <?php _e('Location','wetu-importer'); ?></li> |
|
177 | + <li><input class="content" type="checkbox" name="content[]" value="description" /> <?php _e('Description', 'wetu-importer'); ?></li> |
|
178 | + <li><input class="content" type="checkbox" name="content[]" value="excerpt" /> <?php _e('Excerpt', 'wetu-importer'); ?></li> |
|
179 | + <li><input class="content" type="checkbox" name="content[]" value="gallery" /> <?php _e('Main Gallery', 'wetu-importer'); ?></li> |
|
180 | + <li><input class="content" type="checkbox" name="content[]" value="category" /> <?php _e('Category', 'wetu-importer'); ?></li> |
|
181 | + <?php if (class_exists('TO_Maps')) { ?> |
|
182 | + <li><input class="content" type="checkbox" name="content[]" value="location" /> <?php _e('Location', 'wetu-importer'); ?></li> |
|
183 | 183 | <?php } ?> |
184 | - <li><input class="content" type="checkbox" name="content[]" value="destination" /> <?php _e('Connect Destinations','wetu-importer'); ?></li> |
|
185 | - <li><input class="content" type="checkbox" name="content[]" value="checkin" /> <?php _e('Check In / Check Out','wetu-importer'); ?></li> |
|
186 | - <li><input class="content" type="checkbox" name="content[]" value="facilities" /> <?php _e('Facilities','wetu-importer'); ?></li> |
|
187 | - <li><input class="content" type="checkbox" name="content[]" value="friendly" /> <?php _e('Friendly','wetu-importer'); ?></li> |
|
188 | - <li><input class="content" type="checkbox" name="content[]" value="rating" /> <?php _e('Rating','wetu-importer'); ?></li> |
|
189 | - <li><input class="content" type="checkbox" name="content[]" value="rooms" /> <?php _e('Rooms','wetu-importer'); ?></li> |
|
190 | - <li><input class="content" type="checkbox" name="content[]" value="special_interests" /> <?php _e('Special Interests','wetu-importer'); ?></li> |
|
191 | - <li><input class="content" type="checkbox" name="content[]" value="spoken_languages" /> <?php _e('Spoken Languages','wetu-importer'); ?></li> |
|
192 | - |
|
193 | - <?php if(class_exists('TO_Videos')){ ?> |
|
194 | - <li><input class="content" type="checkbox" name="content[]" value="videos" /> <?php _e('Videos','wetu-importer'); ?></li> |
|
184 | + <li><input class="content" type="checkbox" name="content[]" value="destination" /> <?php _e('Connect Destinations', 'wetu-importer'); ?></li> |
|
185 | + <li><input class="content" type="checkbox" name="content[]" value="checkin" /> <?php _e('Check In / Check Out', 'wetu-importer'); ?></li> |
|
186 | + <li><input class="content" type="checkbox" name="content[]" value="facilities" /> <?php _e('Facilities', 'wetu-importer'); ?></li> |
|
187 | + <li><input class="content" type="checkbox" name="content[]" value="friendly" /> <?php _e('Friendly', 'wetu-importer'); ?></li> |
|
188 | + <li><input class="content" type="checkbox" name="content[]" value="rating" /> <?php _e('Rating', 'wetu-importer'); ?></li> |
|
189 | + <li><input class="content" type="checkbox" name="content[]" value="rooms" /> <?php _e('Rooms', 'wetu-importer'); ?></li> |
|
190 | + <li><input class="content" type="checkbox" name="content[]" value="special_interests" /> <?php _e('Special Interests', 'wetu-importer'); ?></li> |
|
191 | + <li><input class="content" type="checkbox" name="content[]" value="spoken_languages" /> <?php _e('Spoken Languages', 'wetu-importer'); ?></li> |
|
192 | + |
|
193 | + <?php if (class_exists('TO_Videos')) { ?> |
|
194 | + <li><input class="content" type="checkbox" name="content[]" value="videos" /> <?php _e('Videos', 'wetu-importer'); ?></li> |
|
195 | 195 | <?php } ?> |
196 | 196 | </ul> |
197 | 197 | <h4><?php _e('Additional Content'); ?></h4> |
198 | 198 | <ul> |
199 | - <li><input class="content" type="checkbox" name="content[]" value="featured_image" /> <?php _e('Set Featured Image','wetu-importer'); ?></li> |
|
200 | - <?php if(class_exists('LSX_Banners')){ ?> |
|
201 | - <li><input class="content" type="checkbox" name="content[]" value="banner_image" /> <?php _e('Set Banner Image','wetu-importer'); ?></li> |
|
199 | + <li><input class="content" type="checkbox" name="content[]" value="featured_image" /> <?php _e('Set Featured Image', 'wetu-importer'); ?></li> |
|
200 | + <?php if (class_exists('LSX_Banners')) { ?> |
|
201 | + <li><input class="content" type="checkbox" name="content[]" value="banner_image" /> <?php _e('Set Banner Image', 'wetu-importer'); ?></li> |
|
202 | 202 | <?php } ?> |
203 | 203 | </ul> |
204 | 204 | </div> |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | |
218 | 218 | |
219 | 219 | <h3><?php _e('Your List'); ?></h3> |
220 | - <p><input class="button button-primary" type="submit" value="<?php _e('Sync','wetu-importer'); ?>" /></p> |
|
220 | + <p><input class="button button-primary" type="submit" value="<?php _e('Sync', 'wetu-importer'); ?>" /></p> |
|
221 | 221 | <table class="wp-list-table widefat fixed posts"> |
222 | 222 | <?php $this->table_header(); ?> |
223 | 223 | |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | |
230 | 230 | </table> |
231 | 231 | |
232 | - <p><input class="button button-primary" type="submit" value="<?php _e('Sync','wetu-importer'); ?>" /></p> |
|
232 | + <p><input class="button button-primary" type="submit" value="<?php _e('Sync', 'wetu-importer'); ?>" /></p> |
|
233 | 233 | </form> |
234 | 234 | </div> |
235 | 235 | |
@@ -250,30 +250,30 @@ discard block |
||
250 | 250 | <form class="ajax-form" id="<?php echo $this->plugin_slug; ?>-search-form" method="get" action="tools.php" data-type="<?php echo $this->tab_slug; ?>"> |
251 | 251 | <input type="hidden" name="page" value="<?php echo $this->tab_slug; ?>" /> |
252 | 252 | |
253 | - <h3><span class="dashicons dashicons-search"></span> <?php _e('Search','wetu-importer'); ?></h3> |
|
253 | + <h3><span class="dashicons dashicons-search"></span> <?php _e('Search', 'wetu-importer'); ?></h3> |
|
254 | 254 | <div class="normal-search"> |
255 | - <input pattern=".{3,}" placeholder="3 characters minimum" class="keyword" name="keyword" value=""> <input class="button button-primary submit" type="submit" value="<?php _e('Search','wetu-importer'); ?>" /> |
|
255 | + <input pattern=".{3,}" placeholder="3 characters minimum" class="keyword" name="keyword" value=""> <input class="button button-primary submit" type="submit" value="<?php _e('Search', 'wetu-importer'); ?>" /> |
|
256 | 256 | </div> |
257 | 257 | <div class="advanced-search hidden" style="display:none;"> |
258 | - <p><?php _e('Enter several keywords, each on a new line.','wetu-importer'); ?></p> |
|
258 | + <p><?php _e('Enter several keywords, each on a new line.', 'wetu-importer'); ?></p> |
|
259 | 259 | <textarea rows="10" cols="40" name="bulk-keywords"></textarea> |
260 | - <input class="button button-primary submit" type="submit" value="<?php _e('Search','wetu-importer'); ?>" /> |
|
260 | + <input class="button button-primary submit" type="submit" value="<?php _e('Search', 'wetu-importer'); ?>" /> |
|
261 | 261 | </div> |
262 | 262 | |
263 | 263 | <p> |
264 | - <a class="advanced-search-toggle" href="#"><?php _e('Bulk Search','wetu-importer'); ?></a> | |
|
265 | - <a class="published search-toggle" href="#publish"><?php esc_attr_e('Published','wetu-importer'); ?></a> | |
|
266 | - <a class="pending search-toggle" href="#pending"><?php esc_attr_e('Pending','wetu-importer'); ?></a> | |
|
267 | - <a class="draft search-toggle" href="#draft"><?php esc_attr_e('Draft','wetu-importer'); ?></a> | |
|
268 | - <a class="import search-toggle" href="#import"><?php esc_attr_e('WETU','wetu-importer'); ?></a> |
|
264 | + <a class="advanced-search-toggle" href="#"><?php _e('Bulk Search', 'wetu-importer'); ?></a> | |
|
265 | + <a class="published search-toggle" href="#publish"><?php esc_attr_e('Published', 'wetu-importer'); ?></a> | |
|
266 | + <a class="pending search-toggle" href="#pending"><?php esc_attr_e('Pending', 'wetu-importer'); ?></a> | |
|
267 | + <a class="draft search-toggle" href="#draft"><?php esc_attr_e('Draft', 'wetu-importer'); ?></a> | |
|
268 | + <a class="import search-toggle" href="#import"><?php esc_attr_e('WETU', 'wetu-importer'); ?></a> |
|
269 | 269 | </p> |
270 | 270 | |
271 | 271 | <div class="ajax-loader" style="display:none;width:100%;text-align:center;"> |
272 | - <img style="width:64px;" src="<?php echo WETU_IMPORTER_URL.'assets/images/ajaxloader.gif';?>" /> |
|
272 | + <img style="width:64px;" src="<?php echo WETU_IMPORTER_URL.'assets/images/ajaxloader.gif'; ?>" /> |
|
273 | 273 | </div> |
274 | 274 | |
275 | 275 | <div class="ajax-loader-small" style="display:none;width:100%;text-align:center;"> |
276 | - <img style="width:32px;" src="<?php echo WETU_IMPORTER_URL.'assets/images/ajaxloader.gif';?>" /> |
|
276 | + <img style="width:32px;" src="<?php echo WETU_IMPORTER_URL.'assets/images/ajaxloader.gif'; ?>" /> |
|
277 | 277 | </div> |
278 | 278 | </form> |
279 | 279 | <?php |
@@ -283,9 +283,9 @@ discard block |
||
283 | 283 | * search_form |
284 | 284 | */ |
285 | 285 | public function update_options_form() { |
286 | - echo '<div style="display:none;" class="wetu-status"><h3>'.__('Wetu Status','wetu-importer').'</h3>'; |
|
286 | + echo '<div style="display:none;" class="wetu-status"><h3>'.__('Wetu Status', 'wetu-importer').'</h3>'; |
|
287 | 287 | $accommodation = get_transient('lsx_ti_accommodation'); |
288 | - if('' === $accommodation || false === $accommodation || isset($_GET['refresh_accommodation'])){ |
|
288 | + if ('' === $accommodation || false === $accommodation || isset($_GET['refresh_accommodation'])) { |
|
289 | 289 | $this->update_options(); |
290 | 290 | } |
291 | 291 | echo '</div>'; |
@@ -296,13 +296,13 @@ discard block |
||
296 | 296 | * Save the list of Accommodation into an option |
297 | 297 | */ |
298 | 298 | public function update_options() { |
299 | - $data = file_get_contents( $this->url . '/List?' . $this->url_qs ); |
|
299 | + $data = file_get_contents($this->url.'/List?'.$this->url_qs); |
|
300 | 300 | $accommodation = json_decode($data, true); |
301 | 301 | |
302 | - if(isset($accommodation['error'])){ |
|
302 | + if (isset($accommodation['error'])) { |
|
303 | 303 | return $accommodation['error']; |
304 | 304 | }elseif (isset($accommodation) && !empty($accommodation)) { |
305 | - set_transient('lsx_ti_accommodation',$accommodation,60*60*2); |
|
305 | + set_transient('lsx_ti_accommodation', $accommodation, 60 * 60 * 2); |
|
306 | 306 | return true; |
307 | 307 | } |
308 | 308 | } |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | /** |
311 | 311 | * Grab all the current accommodation posts via the lsx_wetu_id field. |
312 | 312 | */ |
313 | - public function find_current_accommodation($post_type='accommodation') { |
|
313 | + public function find_current_accommodation($post_type = 'accommodation') { |
|
314 | 314 | global $wpdb; |
315 | 315 | $return = array(); |
316 | 316 | |
@@ -326,8 +326,8 @@ discard block |
||
326 | 326 | |
327 | 327 | LIMIT 0,500 |
328 | 328 | "); |
329 | - if(null !== $current_accommodation && !empty($current_accommodation)){ |
|
330 | - foreach($current_accommodation as $accom){ |
|
329 | + if (null !== $current_accommodation && !empty($current_accommodation)) { |
|
330 | + foreach ($current_accommodation as $accom) { |
|
331 | 331 | $return[$accom->meta_value] = $accom; |
332 | 332 | } |
333 | 333 | } |
@@ -339,37 +339,37 @@ discard block |
||
339 | 339 | */ |
340 | 340 | public function process_ajax_search() { |
341 | 341 | $return = false; |
342 | - if(isset($_POST['action']) && $_POST['action'] === 'lsx_tour_importer' && isset($_POST['type']) && $_POST['type'] === 'accommodation'){ |
|
342 | + if (isset($_POST['action']) && $_POST['action'] === 'lsx_tour_importer' && isset($_POST['type']) && $_POST['type'] === 'accommodation') { |
|
343 | 343 | $accommodation = get_transient('lsx_ti_accommodation'); |
344 | 344 | |
345 | - if ( false !== $accommodation ) { |
|
345 | + if (false !== $accommodation) { |
|
346 | 346 | $searched_items = false; |
347 | 347 | |
348 | - if(isset($_POST['keyword'] )) { |
|
348 | + if (isset($_POST['keyword'])) { |
|
349 | 349 | $keyphrases = $_POST['keyword']; |
350 | - }else{ |
|
350 | + }else { |
|
351 | 351 | $keyphrases = array(0); |
352 | 352 | } |
353 | 353 | |
354 | - if(!is_array($keyphrases)){ |
|
354 | + if (!is_array($keyphrases)) { |
|
355 | 355 | $keyphrases = array($keyphrases); |
356 | 356 | } |
357 | - foreach($keyphrases as &$keyword){ |
|
357 | + foreach ($keyphrases as &$keyword) { |
|
358 | 358 | $keyword = ltrim(rtrim($keyword)); |
359 | 359 | } |
360 | 360 | |
361 | 361 | |
362 | 362 | $post_status = false; |
363 | - if(in_array('publish',$keyphrases)){ |
|
363 | + if (in_array('publish', $keyphrases)) { |
|
364 | 364 | $post_status = 'publish'; |
365 | 365 | } |
366 | - if(in_array('pending',$keyphrases)){ |
|
366 | + if (in_array('pending', $keyphrases)) { |
|
367 | 367 | $post_status = 'pending'; |
368 | 368 | } |
369 | - if(in_array('draft',$keyphrases)){ |
|
369 | + if (in_array('draft', $keyphrases)) { |
|
370 | 370 | $post_status = 'draft'; |
371 | 371 | } |
372 | - if(in_array('import',$keyphrases)){ |
|
372 | + if (in_array('import', $keyphrases)) { |
|
373 | 373 | $post_status = 'import'; |
374 | 374 | } |
375 | 375 | |
@@ -377,33 +377,33 @@ discard block |
||
377 | 377 | |
378 | 378 | $current_accommodation = $this->find_current_accommodation(); |
379 | 379 | |
380 | - foreach($accommodation as $row_key => $row){ |
|
380 | + foreach ($accommodation as $row_key => $row) { |
|
381 | 381 | |
382 | 382 | //If this is a current tour, add its ID to the row. |
383 | 383 | $row['post_id'] = 0; |
384 | - if(false !== $current_accommodation && array_key_exists($row['id'], $current_accommodation)){ |
|
384 | + if (false !== $current_accommodation && array_key_exists($row['id'], $current_accommodation)) { |
|
385 | 385 | $row['post_id'] = $current_accommodation[$row['id']]->post_id; |
386 | 386 | } |
387 | 387 | |
388 | 388 | //If we are searching for |
389 | - if(false !== $post_status){ |
|
389 | + if (false !== $post_status) { |
|
390 | 390 | |
391 | - if('import' === $post_status){ |
|
391 | + if ('import' === $post_status) { |
|
392 | 392 | |
393 | - if(0 !== $row['post_id']){ |
|
393 | + if (0 !== $row['post_id']) { |
|
394 | 394 | continue; |
395 | - }else{ |
|
395 | + }else { |
|
396 | 396 | $searched_items[sanitize_title($row['name']).'-'.$row['id']] = $this->format_row($row); |
397 | 397 | } |
398 | 398 | |
399 | 399 | |
400 | - }else{ |
|
400 | + }else { |
|
401 | 401 | |
402 | - if(0 === $row['post_id']){ |
|
402 | + if (0 === $row['post_id']) { |
|
403 | 403 | continue; |
404 | - }else{ |
|
404 | + }else { |
|
405 | 405 | $current_status = get_post_status($row['post_id']); |
406 | - if($current_status !== $post_status){ |
|
406 | + if ($current_status !== $post_status) { |
|
407 | 407 | continue; |
408 | 408 | } |
409 | 409 | |
@@ -411,17 +411,17 @@ discard block |
||
411 | 411 | $searched_items[sanitize_title($row['name']).'-'.$row['id']] = $this->format_row($row); |
412 | 412 | } |
413 | 413 | |
414 | - }else{ |
|
414 | + }else { |
|
415 | 415 | //Search through each keyword. |
416 | - foreach($keyphrases as $keyphrase){ |
|
416 | + foreach ($keyphrases as $keyphrase) { |
|
417 | 417 | |
418 | 418 | //Make sure the keyphrase is turned into an array |
419 | - $keywords = explode(" ",$keyphrase); |
|
420 | - if(!is_array($keywords)){ |
|
419 | + $keywords = explode(" ", $keyphrase); |
|
420 | + if (!is_array($keywords)) { |
|
421 | 421 | $keywords = array($keywords); |
422 | 422 | } |
423 | 423 | |
424 | - if($this->multineedle_stripos(ltrim(rtrim($row['name'])), $keywords) !== false){ |
|
424 | + if ($this->multineedle_stripos(ltrim(rtrim($row['name'])), $keywords) !== false) { |
|
425 | 425 | $searched_items[sanitize_title($row['name']).'-'.$row['id']] = $this->format_row($row); |
426 | 426 | } |
427 | 427 | } |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | } |
431 | 431 | |
432 | 432 | |
433 | - if(false !== $searched_items){ |
|
433 | + if (false !== $searched_items) { |
|
434 | 434 | ksort($searched_items); |
435 | 435 | $return = implode($searched_items); |
436 | 436 | } |
@@ -443,17 +443,17 @@ discard block |
||
443 | 443 | /** |
444 | 444 | * Does a multine search |
445 | 445 | */ |
446 | - public function multineedle_stripos($haystack, $needles, $offset=0) { |
|
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)){ |
|
449 | + foreach ($needles as $needle) { |
|
450 | + if (false !== stripos($haystack, $needle, $offset)) { |
|
451 | 451 | $found[] = true; |
452 | 452 | } |
453 | 453 | } |
454 | - if(false !== $found && $needle_count === count($found)){ |
|
454 | + if (false !== $found && $needle_count === count($found)) { |
|
455 | 455 | return true; |
456 | - }else{ |
|
456 | + }else { |
|
457 | 457 | return false; |
458 | 458 | } |
459 | 459 | } |
@@ -461,11 +461,11 @@ discard block |
||
461 | 461 | /** |
462 | 462 | * Formats the row for output on the screen. |
463 | 463 | */ |
464 | - public function format_row($row = false){ |
|
465 | - if(false !== $row){ |
|
464 | + public function format_row($row = false) { |
|
465 | + if (false !== $row) { |
|
466 | 466 | |
467 | 467 | $status = 'import'; |
468 | - if(0 !== $row['post_id']){ |
|
468 | + if (0 !== $row['post_id']) { |
|
469 | 469 | $status = '<a href="'.admin_url('/post.php?post='.$row['post_id'].'&action=edit').'" target="_blank">'.get_post_status($row['post_id']).'</a>'; |
470 | 470 | } |
471 | 471 | |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | <strong>'.$row['name'].'</strong> - '.$status.' |
480 | 480 | </td> |
481 | 481 | <td class="date column-date"> |
482 | - <abbr title="'.date('Y/m/d',strtotime($row['last_modified'])).'">'.date('Y/m/d',strtotime($row['last_modified'])).'</abbr><br>Last Modified |
|
482 | + <abbr title="'.date('Y/m/d', strtotime($row['last_modified'])).'">'.date('Y/m/d', strtotime($row['last_modified'])).'</abbr><br>Last Modified |
|
483 | 483 | </td> |
484 | 484 | <td class="ssid column-ssid"> |
485 | 485 | '.$row['id'].' |
@@ -494,40 +494,40 @@ discard block |
||
494 | 494 | */ |
495 | 495 | public function process_ajax_import() { |
496 | 496 | $return = false; |
497 | - if(isset($_POST['action']) && $_POST['action'] === 'lsx_import_items' && isset($_POST['type']) && $_POST['type'] === 'accommodation' && isset($_POST['wetu_id'])){ |
|
497 | + if (isset($_POST['action']) && $_POST['action'] === 'lsx_import_items' && isset($_POST['type']) && $_POST['type'] === 'accommodation' && isset($_POST['wetu_id'])) { |
|
498 | 498 | |
499 | 499 | $wetu_id = $_POST['wetu_id']; |
500 | - if(isset($_POST['post_id'])){ |
|
500 | + if (isset($_POST['post_id'])) { |
|
501 | 501 | $post_id = $_POST['post_id']; |
502 | - }else{ |
|
502 | + }else { |
|
503 | 503 | $post_id = 0; |
504 | 504 | } |
505 | 505 | |
506 | - if(isset($_POST['team_members'])){ |
|
506 | + if (isset($_POST['team_members'])) { |
|
507 | 507 | $team_members = $_POST['team_members']; |
508 | - }else{ |
|
508 | + }else { |
|
509 | 509 | $team_members = false; |
510 | 510 | } |
511 | 511 | |
512 | - if(isset($_POST['safari_brands'])){ |
|
512 | + if (isset($_POST['safari_brands'])) { |
|
513 | 513 | $safari_brands = $_POST['safari_brands']; |
514 | - }else{ |
|
514 | + }else { |
|
515 | 515 | $safari_brands = false; |
516 | 516 | } |
517 | 517 | |
518 | - if(isset($_POST['content']) && is_array($_POST['content']) && !empty($_POST['content'])){ |
|
518 | + if (isset($_POST['content']) && is_array($_POST['content']) && !empty($_POST['content'])) { |
|
519 | 519 | $content = $_POST['content']; |
520 | - }else{ |
|
520 | + }else { |
|
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) |
|
524 | + $jdata = file_get_contents($this->url.'/Get?'.$this->url_qs.'&ids='.$wetu_id); |
|
525 | + if ($jdata) |
|
526 | 526 | { |
527 | - $adata=json_decode($jdata,true); |
|
528 | - if(!empty($adata)) |
|
527 | + $adata = json_decode($jdata, true); |
|
528 | + if (!empty($adata)) |
|
529 | 529 | { |
530 | - $return = $this->import_row($adata,$wetu_id,$post_id,$team_members,$content,$safari_brands); |
|
530 | + $return = $this->import_row($adata, $wetu_id, $post_id, $team_members, $content, $safari_brands); |
|
531 | 531 | $this->format_completed_row($return); |
532 | 532 | } |
533 | 533 | } |
@@ -539,15 +539,15 @@ discard block |
||
539 | 539 | /** |
540 | 540 | * Formats the row for the completed list. |
541 | 541 | */ |
542 | - public function format_completed_row($response){ |
|
542 | + public function format_completed_row($response) { |
|
543 | 543 | echo '<li class="post-'.$response.'"><span class="dashicons dashicons-yes"></span> <a target="_blank" href="'.get_permalink($response).'">'.get_the_title($response).'</a></li>'; |
544 | 544 | } |
545 | 545 | /** |
546 | 546 | * Connect to wetu |
547 | 547 | */ |
548 | - public function import_row($data,$wetu_id,$id=0,$team_members=false,$importable_content=false,$safari_brands=false) { |
|
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') |
|
550 | + if (trim($data[0]['type']) == 'Accommodation') |
|
551 | 551 | { |
552 | 552 | $post_name = $data_post_content = $data_post_excerpt = ''; |
553 | 553 | $post = array( |
@@ -557,44 +557,44 @@ discard block |
||
557 | 557 | $content_used_general_description = false; |
558 | 558 | |
559 | 559 | //Set the post_content |
560 | - if(false !== $importable_content && in_array('description',$importable_content)){ |
|
561 | - if(isset($data[0]['content']['extended_description'])) |
|
560 | + if (false !== $importable_content && in_array('description', $importable_content)) { |
|
561 | + if (isset($data[0]['content']['extended_description'])) |
|
562 | 562 | { |
563 | 563 | $data_post_content = $data[0]['content']['extended_description']; |
564 | - }elseif(isset($data[0]['content']['general_description'])){ |
|
564 | + }elseif (isset($data[0]['content']['general_description'])) { |
|
565 | 565 | $data_post_content = $data[0]['content']['general_description']; |
566 | 566 | $content_used_general_description = true; |
567 | - }elseif(isset($data[0]['content']['teaser_description'])){ |
|
567 | + }elseif (isset($data[0]['content']['teaser_description'])) { |
|
568 | 568 | $data_post_content = $data[0]['content']['teaser_description']; |
569 | 569 | } |
570 | 570 | $post['post_content'] = wp_strip_all_tags($data_post_content); |
571 | 571 | } |
572 | 572 | |
573 | 573 | //set the post_excerpt |
574 | - if(false !== $importable_content && in_array('excerpt',$importable_content)){ |
|
575 | - if(isset($data[0]['content']['teaser_description'])){ |
|
574 | + if (false !== $importable_content && in_array('excerpt', $importable_content)) { |
|
575 | + if (isset($data[0]['content']['teaser_description'])) { |
|
576 | 576 | $data_post_excerpt = $data[0]['content']['teaser_description']; |
577 | - }elseif(isset($data[0]['content']['general_description']) && false === $content_used_general_description){ |
|
577 | + }elseif (isset($data[0]['content']['general_description']) && false === $content_used_general_description) { |
|
578 | 578 | $data_post_excerpt = $data[0]['content']['general_description']; |
579 | 579 | } |
580 | 580 | $post['post_excerpt'] = $data_post_excerpt; |
581 | 581 | } |
582 | 582 | |
583 | - if(false !== $id && '0' !== $id){ |
|
583 | + if (false !== $id && '0' !== $id) { |
|
584 | 584 | $post['ID'] = $id; |
585 | - if(isset($data[0]['name'])){ |
|
585 | + if (isset($data[0]['name'])) { |
|
586 | 586 | $post['post_title'] = $data[0]['name']; |
587 | 587 | $post['post_status'] = 'publish'; |
588 | - $post['post_name'] = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'accommodation', 0); |
|
588 | + $post['post_name'] = wp_unique_post_slug(sanitize_title($data[0]['name']), $id, 'draft', 'accommodation', 0); |
|
589 | 589 | } |
590 | 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{ |
|
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 | 594 | |
595 | 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); |
|
596 | + if (isset($data[0]['name'])) { |
|
597 | + $post_name = wp_unique_post_slug(sanitize_title($data[0]['name']), $id, 'draft', 'accommodation', 0); |
|
598 | 598 | } |
599 | 599 | $post['post_name'] = $post_name; |
600 | 600 | $post['post_title'] = $data[0]['name']; |
@@ -602,90 +602,90 @@ discard block |
||
602 | 602 | $id = wp_insert_post($post); |
603 | 603 | |
604 | 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'])); |
|
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 | 608 | } |
609 | 609 | } |
610 | 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))){ |
|
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 | 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); |
|
616 | + if (post_type_exists('team') && false !== $team_members && '' !== $team_members) { |
|
617 | + $this->set_team_member($id, $team_members); |
|
618 | 618 | } |
619 | 619 | |
620 | 620 | //Set the safari brand |
621 | - if(false !== $safari_brands && '' !== $safari_brands){ |
|
622 | - $this->set_safari_brands($id,$safari_brands); |
|
621 | + if (false !== $safari_brands && '' !== $safari_brands) { |
|
622 | + $this->set_safari_brands($id, $safari_brands); |
|
623 | 623 | |
624 | 624 | } |
625 | 625 | |
626 | - if(class_exists('LSX_TO_Maps')){ |
|
627 | - $this->set_map_data($data,$id); |
|
628 | - $this->set_location_taxonomy($data,$id); |
|
626 | + if (class_exists('LSX_TO_Maps')) { |
|
627 | + $this->set_map_data($data, $id); |
|
628 | + $this->set_location_taxonomy($data, $id); |
|
629 | 629 | } |
630 | 630 | |
631 | - if(post_type_exists('destination') && false !== $importable_content && in_array('destination',$importable_content)){ |
|
632 | - $this->connect_destinations($data,$id); |
|
631 | + if (post_type_exists('destination') && false !== $importable_content && in_array('destination', $importable_content)) { |
|
632 | + $this->connect_destinations($data, $id); |
|
633 | 633 | } |
634 | 634 | |
635 | - if(false !== $importable_content && in_array('category',$importable_content)){ |
|
636 | - $this->set_taxonomy_style($data,$id); |
|
635 | + if (false !== $importable_content && in_array('category', $importable_content)) { |
|
636 | + $this->set_taxonomy_style($data, $id); |
|
637 | 637 | } |
638 | 638 | |
639 | 639 | //Set the Room Data |
640 | - if(false !== $importable_content && in_array('rooms',$importable_content)){ |
|
641 | - $this->set_room_data($data,$id); |
|
640 | + if (false !== $importable_content && in_array('rooms', $importable_content)) { |
|
641 | + $this->set_room_data($data, $id); |
|
642 | 642 | } |
643 | 643 | |
644 | 644 | //Set the rating |
645 | - if(false !== $importable_content && in_array('rating',$importable_content)){ |
|
646 | - $this->set_rating($data,$id); |
|
645 | + if (false !== $importable_content && in_array('rating', $importable_content)) { |
|
646 | + $this->set_rating($data, $id); |
|
647 | 647 | } |
648 | 648 | |
649 | 649 | //Set the checkin checkout data |
650 | - if(false !== $importable_content && in_array('checkin',$importable_content)){ |
|
651 | - $this->set_checkin_checkout($data,$id); |
|
650 | + if (false !== $importable_content && in_array('checkin', $importable_content)) { |
|
651 | + $this->set_checkin_checkout($data, $id); |
|
652 | 652 | } |
653 | 653 | |
654 | 654 | //Set the Spoken Languages |
655 | - if(false !== $importable_content && in_array('spoken_languages',$importable_content)){ |
|
656 | - $this->set_spoken_languages($data,$id); |
|
655 | + if (false !== $importable_content && in_array('spoken_languages', $importable_content)) { |
|
656 | + $this->set_spoken_languages($data, $id); |
|
657 | 657 | } |
658 | 658 | |
659 | 659 | //Set the friendly options |
660 | - if(false !== $importable_content && in_array('friendly',$importable_content)){ |
|
661 | - $this->set_friendly($data,$id); |
|
660 | + if (false !== $importable_content && in_array('friendly', $importable_content)) { |
|
661 | + $this->set_friendly($data, $id); |
|
662 | 662 | } |
663 | 663 | |
664 | 664 | //Set the special_interests |
665 | - if(false !== $importable_content && in_array('special_interests',$importable_content)){ |
|
666 | - $this->set_special_interests($data,$id); |
|
665 | + if (false !== $importable_content && in_array('special_interests', $importable_content)) { |
|
666 | + $this->set_special_interests($data, $id); |
|
667 | 667 | } |
668 | 668 | |
669 | 669 | //Import the videos |
670 | - if(false !== $importable_content && in_array('videos',$importable_content)){ |
|
671 | - $this->set_video_data($data,$id); |
|
670 | + if (false !== $importable_content && in_array('videos', $importable_content)) { |
|
671 | + $this->set_video_data($data, $id); |
|
672 | 672 | } |
673 | 673 | |
674 | 674 | //Import the facilities |
675 | - if(false !== $importable_content && in_array('facilities',$importable_content)){ |
|
676 | - $this->set_facilities($data,$id); |
|
675 | + if (false !== $importable_content && in_array('facilities', $importable_content)) { |
|
676 | + $this->set_facilities($data, $id); |
|
677 | 677 | } |
678 | 678 | |
679 | 679 | //Set the featured image |
680 | - if(false !== $importable_content && in_array('featured_image',$importable_content)){ |
|
681 | - $this->set_featured_image($data,$id); |
|
680 | + if (false !== $importable_content && in_array('featured_image', $importable_content)) { |
|
681 | + $this->set_featured_image($data, $id); |
|
682 | 682 | } |
683 | - if(false !== $importable_content && in_array('banner_image',$importable_content)){ |
|
684 | - $this->set_banner_image($data,$id); |
|
683 | + if (false !== $importable_content && in_array('banner_image', $importable_content)) { |
|
684 | + $this->set_banner_image($data, $id); |
|
685 | 685 | } |
686 | 686 | //Import the main gallery |
687 | - if(false !== $importable_content && in_array('gallery',$importable_content)){ |
|
688 | - $this->create_main_gallery($data,$id); |
|
687 | + if (false !== $importable_content && in_array('gallery', $importable_content)) { |
|
688 | + $this->create_main_gallery($data, $id); |
|
689 | 689 | } |
690 | 690 | } |
691 | 691 | return $id; |
@@ -694,63 +694,63 @@ discard block |
||
694 | 694 | /** |
695 | 695 | * Set the team memberon each item. |
696 | 696 | */ |
697 | - public function set_team_member($id,$team_members) { |
|
697 | + public function set_team_member($id, $team_members) { |
|
698 | 698 | |
699 | 699 | delete_post_meta($id, 'team_to_'.$this->tab_slug); |
700 | - foreach($team_members as $team){ |
|
701 | - add_post_meta($id,'team_to_'.$this->tab_slug,$team); |
|
700 | + foreach ($team_members as $team) { |
|
701 | + add_post_meta($id, 'team_to_'.$this->tab_slug, $team); |
|
702 | 702 | } |
703 | 703 | } |
704 | 704 | |
705 | 705 | /** |
706 | 706 | * Set the safari brand |
707 | 707 | */ |
708 | - public function set_safari_brands($id,$safari_brands) { |
|
709 | - foreach($safari_brands as $safari_brand){ |
|
710 | - wp_set_object_terms( $id, intval($safari_brand), 'accommodation-brand',true); |
|
708 | + public function set_safari_brands($id, $safari_brands) { |
|
709 | + foreach ($safari_brands as $safari_brand) { |
|
710 | + wp_set_object_terms($id, intval($safari_brand), 'accommodation-brand', true); |
|
711 | 711 | } |
712 | 712 | } |
713 | 713 | |
714 | 714 | /** |
715 | 715 | * Saves the longitude and lattitude, as well as sets the map marker. |
716 | 716 | */ |
717 | - public function set_map_data($data,$id) { |
|
717 | + public function set_map_data($data, $id) { |
|
718 | 718 | $longitude = $latitude = $address = false; |
719 | 719 | $zoom = '15'; |
720 | 720 | |
721 | - if(isset($data[0]['position'])){ |
|
721 | + if (isset($data[0]['position'])) { |
|
722 | 722 | |
723 | - if(isset($data[0]['position']['driving_latitude'])){ |
|
723 | + if (isset($data[0]['position']['driving_latitude'])) { |
|
724 | 724 | $latitude = $data[0]['position']['driving_latitude']; |
725 | - }elseif(isset($data[0]['position']['latitude'])){ |
|
725 | + }elseif (isset($data[0]['position']['latitude'])) { |
|
726 | 726 | $latitude = $data[0]['position']['latitude']; |
727 | 727 | } |
728 | 728 | |
729 | - if(isset($data[0]['position']['driving_longitude'])){ |
|
729 | + if (isset($data[0]['position']['driving_longitude'])) { |
|
730 | 730 | $longitude = $data[0]['position']['driving_longitude']; |
731 | - }elseif(isset($data[0]['position']['longitude'])){ |
|
731 | + }elseif (isset($data[0]['position']['longitude'])) { |
|
732 | 732 | $longitude = $data[0]['position']['longitude']; |
733 | 733 | } |
734 | 734 | |
735 | 735 | } |
736 | - if(isset($data[0]['content']) && isset($data[0]['content']['contact_information'])){ |
|
737 | - if(isset($data[0]['content']['contact_information']['address'])){ |
|
736 | + if (isset($data[0]['content']) && isset($data[0]['content']['contact_information'])) { |
|
737 | + if (isset($data[0]['content']['contact_information']['address'])) { |
|
738 | 738 | $address = strip_tags($data[0]['content']['contact_information']['address']); |
739 | 739 | |
740 | - $address = explode("\n",$address); |
|
741 | - foreach($address as $bitkey => $bit){ |
|
740 | + $address = explode("\n", $address); |
|
741 | + foreach ($address as $bitkey => $bit) { |
|
742 | 742 | $bit = ltrim(rtrim($bit)); |
743 | - if(false === $bit || '' === $bit || null === $bit or empty($bit)){ |
|
743 | + if (false === $bit || '' === $bit || null === $bit or empty($bit)) { |
|
744 | 744 | unset($address[$bitkey]); |
745 | 745 | } |
746 | 746 | } |
747 | - $address = implode(', ',$address); |
|
747 | + $address = implode(', ', $address); |
|
748 | 748 | $address = str_replace(', , ', ', ', $address); |
749 | 749 | } |
750 | 750 | } |
751 | 751 | |
752 | 752 | |
753 | - if(false !== $longitude){ |
|
753 | + if (false !== $longitude) { |
|
754 | 754 | $location_data = array( |
755 | 755 | 'address' => $address, |
756 | 756 | 'lat' => $latitude, |
@@ -758,53 +758,53 @@ discard block |
||
758 | 758 | 'zoom' => $zoom, |
759 | 759 | 'elevation' => '', |
760 | 760 | ); |
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); |
|
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 | 766 | } |
767 | 767 | } |
768 | 768 | } |
769 | 769 | /** |
770 | 770 | * Saves the longitude and lattitude, as well as sets the map marker. |
771 | 771 | */ |
772 | - public function set_location_taxonomy($data,$id) { |
|
772 | + public function set_location_taxonomy($data, $id) { |
|
773 | 773 | $taxonomy = 'location'; |
774 | 774 | $terms = false; |
775 | - if(isset($data[0]['position'])){ |
|
775 | + if (isset($data[0]['position'])) { |
|
776 | 776 | $country_id = 0; |
777 | - if(isset($data[0]['position']['country'])){ |
|
777 | + if (isset($data[0]['position']['country'])) { |
|
778 | 778 | |
779 | - if(!$term = term_exists(trim($data[0]['position']['country']), 'location')) |
|
779 | + if (!$term = term_exists(trim($data[0]['position']['country']), 'location')) |
|
780 | 780 | { |
781 | 781 | $term = wp_insert_term(trim($data[0]['position']['country']), 'location'); |
782 | - if ( is_wp_error($term) ){ |
|
782 | + if (is_wp_error($term)) { |
|
783 | 783 | echo $term->get_error_message(); |
784 | 784 | } |
785 | 785 | else { |
786 | - wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
786 | + wp_set_object_terms($id, intval($term['term_id']), 'location', true); |
|
787 | 787 | } |
788 | 788 | } |
789 | 789 | else |
790 | 790 | { |
791 | - wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
791 | + wp_set_object_terms($id, intval($term['term_id']), 'location', true); |
|
792 | 792 | } |
793 | 793 | $country_id = intval($term['term_id']); |
794 | 794 | } |
795 | 795 | |
796 | - if(isset($data[0]['position']['destination'])){ |
|
796 | + if (isset($data[0]['position']['destination'])) { |
|
797 | 797 | |
798 | 798 | $tax_args = array('parent'=>$country_id); |
799 | - if(!$term = term_exists(trim($data[0]['position']['destination']), 'location')) |
|
799 | + if (!$term = term_exists(trim($data[0]['position']['destination']), 'location')) |
|
800 | 800 | { |
801 | 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); } |
|
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 | 804 | } |
805 | 805 | else |
806 | 806 | { |
807 | - wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
807 | + wp_set_object_terms($id, intval($term['term_id']), 'location', true); |
|
808 | 808 | } |
809 | 809 | } |
810 | 810 | } |
@@ -813,27 +813,27 @@ discard block |
||
813 | 813 | /** |
814 | 814 | * Connects the destinations post type |
815 | 815 | */ |
816 | - public function connect_destinations($data,$id) { |
|
817 | - if(isset($data[0]['position'])){ |
|
816 | + public function connect_destinations($data, $id) { |
|
817 | + if (isset($data[0]['position'])) { |
|
818 | 818 | $destinations = false; |
819 | - if(isset($data[0]['position']['country'])){ |
|
819 | + if (isset($data[0]['position']['country'])) { |
|
820 | 820 | $destinations['country'] = $data[0]['position']['country']; |
821 | 821 | } |
822 | - if(isset($data[0]['position']['destination'])){ |
|
822 | + if (isset($data[0]['position']['destination'])) { |
|
823 | 823 | $destinations['destination'] = $data[0]['position']['destination']; |
824 | 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)){ |
|
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 | 829 | $prev_values = array(); |
830 | 830 | } |
831 | - foreach($destinations as $key => $value){ |
|
831 | + foreach ($destinations as $key => $value) { |
|
832 | 832 | $destination = get_page_by_title(ltrim(rtrim($value)), 'OBJECT', 'destination'); |
833 | 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); |
|
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 | 837 | } |
838 | 838 | } |
839 | 839 | } |
@@ -844,18 +844,18 @@ discard block |
||
844 | 844 | /** |
845 | 845 | * Set the Travel Style |
846 | 846 | */ |
847 | - public function set_taxonomy_style($data,$id) { |
|
847 | + public function set_taxonomy_style($data, $id) { |
|
848 | 848 | $terms = false; |
849 | - if(isset($data[0]['category'])){ |
|
850 | - if(!$term = term_exists(trim($data[0]['category']), 'accommodation-type')) |
|
849 | + if (isset($data[0]['category'])) { |
|
850 | + if (!$term = term_exists(trim($data[0]['category']), 'accommodation-type')) |
|
851 | 851 | { |
852 | 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); } |
|
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 | 855 | } |
856 | 856 | else |
857 | 857 | { |
858 | - wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); |
|
858 | + wp_set_object_terms($id, intval($term['term_id']), 'accommodation-type', true); |
|
859 | 859 | } |
860 | 860 | } |
861 | 861 | } |
@@ -863,23 +863,23 @@ discard block |
||
863 | 863 | /** |
864 | 864 | * Saves the room data |
865 | 865 | */ |
866 | - public function set_room_data($data,$id) { |
|
867 | - if(!empty($data[0]['rooms']) && is_array($data[0]['rooms'])){ |
|
866 | + public function set_room_data($data, $id) { |
|
867 | + if (!empty($data[0]['rooms']) && is_array($data[0]['rooms'])) { |
|
868 | 868 | $rooms = false; |
869 | 869 | |
870 | - foreach($data[0]['rooms'] as $room){ |
|
870 | + foreach ($data[0]['rooms'] as $room) { |
|
871 | 871 | |
872 | 872 | $temp_room = array(); |
873 | - if(isset($room['name'])){ |
|
873 | + if (isset($room['name'])) { |
|
874 | 874 | $temp_room['title'] = $room['name']; |
875 | 875 | } |
876 | - if(isset($room['description'])){ |
|
876 | + if (isset($room['description'])) { |
|
877 | 877 | $temp_room['description'] = strip_tags($room['description']); |
878 | 878 | } |
879 | 879 | $temp_room['price'] = 0; |
880 | 880 | $temp_room['type'] = 'room'; |
881 | 881 | |
882 | - if(!empty($room['images']) && is_array($room['images'])){ |
|
882 | + if (!empty($room['images']) && is_array($room['images'])) { |
|
883 | 883 | $attachments_args = array( |
884 | 884 | 'post_parent' => $id, |
885 | 885 | 'post_status' => 'inherit', |
@@ -889,38 +889,38 @@ discard block |
||
889 | 889 | $attachments = new WP_Query($attachments_args); |
890 | 890 | $found_attachments = array(); |
891 | 891 | |
892 | - if($attachments->have_posts()){ |
|
893 | - foreach($attachments->posts as $attachment){ |
|
894 | - $found_attachments[] = str_replace(array('.jpg','.png','.jpeg'),'',$attachment->post_title); |
|
892 | + if ($attachments->have_posts()) { |
|
893 | + foreach ($attachments->posts as $attachment) { |
|
894 | + $found_attachments[] = str_replace(array('.jpg', '.png', '.jpeg'), '', $attachment->post_title); |
|
895 | 895 | } |
896 | 896 | } |
897 | 897 | |
898 | 898 | $temp_room['gallery'] = array(); |
899 | - foreach($room['images'] as $image_data){ |
|
900 | - $temp_room['gallery'][] = $this->attach_image($image_data,$id,$found_attachments); |
|
899 | + foreach ($room['images'] as $image_data) { |
|
900 | + $temp_room['gallery'][] = $this->attach_image($image_data, $id, $found_attachments); |
|
901 | 901 | } |
902 | 902 | } |
903 | 903 | $rooms[] = $temp_room; |
904 | 904 | } |
905 | 905 | |
906 | - if(false !== $id && '0' !== $id){ |
|
906 | + if (false !== $id && '0' !== $id) { |
|
907 | 907 | delete_post_meta($id, 'units'); |
908 | 908 | } |
909 | - foreach($rooms as $room){ |
|
910 | - add_post_meta($id,'units',$room,false); |
|
909 | + foreach ($rooms as $room) { |
|
910 | + add_post_meta($id, 'units', $room, false); |
|
911 | 911 | } |
912 | 912 | |
913 | - if(isset($data[0]['features']) && isset($data[0]['features']['rooms'])){ |
|
913 | + if (isset($data[0]['features']) && isset($data[0]['features']['rooms'])) { |
|
914 | 914 | $room_count = $data[0]['features']['rooms']; |
915 | - }else{ |
|
915 | + }else { |
|
916 | 916 | $room_count = count($data[0]['rooms']); |
917 | 917 | } |
918 | 918 | |
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); |
|
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 | 924 | } |
925 | 925 | } |
926 | 926 | } |
@@ -928,31 +928,31 @@ discard block |
||
928 | 928 | /** |
929 | 929 | * Set the ratings |
930 | 930 | */ |
931 | - public function set_rating($data,$id) { |
|
931 | + public function set_rating($data, $id) { |
|
932 | 932 | |
933 | - if(!empty($data[0]['features']) && isset($data[0]['features']['star_authority'])){ |
|
933 | + if (!empty($data[0]['features']) && isset($data[0]['features']['star_authority'])) { |
|
934 | 934 | $rating_type = $data[0]['features']['star_authority']; |
935 | - }else{ |
|
935 | + }else { |
|
936 | 936 | $rating_type = 'Unspecified2'; |
937 | 937 | } |
938 | - $this->save_custom_field($rating_type,'rating_type',$id); |
|
938 | + $this->save_custom_field($rating_type, 'rating_type', $id); |
|
939 | 939 | |
940 | - if(!empty($data[0]['features']) && isset($data[0]['features']['stars'])){ |
|
941 | - $this->save_custom_field($data[0]['features']['stars'],'rating',$id,true); |
|
940 | + if (!empty($data[0]['features']) && isset($data[0]['features']['stars'])) { |
|
941 | + $this->save_custom_field($data[0]['features']['stars'], 'rating', $id, true); |
|
942 | 942 | } |
943 | 943 | } |
944 | 944 | |
945 | 945 | /** |
946 | 946 | * Set the spoken_languages |
947 | 947 | */ |
948 | - public function set_spoken_languages($data,$id) { |
|
949 | - if(!empty($data[0]['features']) && isset($data[0]['features']['spoken_languages']) && !empty($data[0]['features']['spoken_languages'])){ |
|
948 | + public function set_spoken_languages($data, $id) { |
|
949 | + if (!empty($data[0]['features']) && isset($data[0]['features']['spoken_languages']) && !empty($data[0]['features']['spoken_languages'])) { |
|
950 | 950 | $languages = false; |
951 | - foreach($data[0]['features']['spoken_languages'] as $spoken_language){ |
|
951 | + foreach ($data[0]['features']['spoken_languages'] as $spoken_language) { |
|
952 | 952 | $languages[] = sanitize_title($spoken_language); |
953 | 953 | } |
954 | - if(false !== $languages){ |
|
955 | - $this->save_custom_field($languages,'spoken_languages',$id); |
|
954 | + if (false !== $languages) { |
|
955 | + $this->save_custom_field($languages, 'spoken_languages', $id); |
|
956 | 956 | } |
957 | 957 | } |
958 | 958 | } |
@@ -960,14 +960,14 @@ discard block |
||
960 | 960 | /** |
961 | 961 | * Set the friendly |
962 | 962 | */ |
963 | - public function set_friendly($data,$id) { |
|
964 | - if(!empty($data[0]['features']) && isset($data[0]['features']['suggested_visitor_types']) && !empty($data[0]['features']['suggested_visitor_types'])){ |
|
963 | + public function set_friendly($data, $id) { |
|
964 | + if (!empty($data[0]['features']) && isset($data[0]['features']['suggested_visitor_types']) && !empty($data[0]['features']['suggested_visitor_types'])) { |
|
965 | 965 | $friendly_options = false; |
966 | - foreach($data[0]['features']['suggested_visitor_types'] as $visitor_type){ |
|
966 | + foreach ($data[0]['features']['suggested_visitor_types'] as $visitor_type) { |
|
967 | 967 | $friendly_options[] = sanitize_title($visitor_type); |
968 | 968 | } |
969 | - if(false !== $friendly_options){ |
|
970 | - $this->save_custom_field($friendly_options,'suggested_visitor_types',$id); |
|
969 | + if (false !== $friendly_options) { |
|
970 | + $this->save_custom_field($friendly_options, 'suggested_visitor_types', $id); |
|
971 | 971 | } |
972 | 972 | } |
973 | 973 | } |
@@ -975,14 +975,14 @@ discard block |
||
975 | 975 | /** |
976 | 976 | * Set the special interests |
977 | 977 | */ |
978 | - public function set_special_interests($data,$id) { |
|
979 | - if(!empty($data[0]['features']) && isset($data[0]['features']['special_interests']) && !empty($data[0]['features']['special_interests'])){ |
|
978 | + public function set_special_interests($data, $id) { |
|
979 | + if (!empty($data[0]['features']) && isset($data[0]['features']['special_interests']) && !empty($data[0]['features']['special_interests'])) { |
|
980 | 980 | $interests = false; |
981 | - foreach($data[0]['features']['special_interests'] as $special_interest){ |
|
981 | + foreach ($data[0]['features']['special_interests'] as $special_interest) { |
|
982 | 982 | $interests[] = sanitize_title($special_interest); |
983 | 983 | } |
984 | - if(false !== $interests){ |
|
985 | - $this->save_custom_field($interests,'special_interests',$id); |
|
984 | + if (false !== $interests) { |
|
985 | + $this->save_custom_field($interests, 'special_interests', $id); |
|
986 | 986 | } |
987 | 987 | } |
988 | 988 | } |
@@ -990,47 +990,47 @@ discard block |
||
990 | 990 | /** |
991 | 991 | * Set the Check in and Check out Date |
992 | 992 | */ |
993 | - public function set_checkin_checkout($data,$id) { |
|
993 | + public function set_checkin_checkout($data, $id) { |
|
994 | 994 | |
995 | - if(!empty($data[0]['features']) && isset($data[0]['features']['check_in_time'])){ |
|
996 | - $time = str_replace('h',':',$data[0]['features']['check_in_time']); |
|
997 | - $time = date('h:ia',strtotime($time)); |
|
998 | - $this->save_custom_field($time,'checkin_time',$id); |
|
995 | + if (!empty($data[0]['features']) && isset($data[0]['features']['check_in_time'])) { |
|
996 | + $time = str_replace('h', ':', $data[0]['features']['check_in_time']); |
|
997 | + $time = date('h:ia', strtotime($time)); |
|
998 | + $this->save_custom_field($time, 'checkin_time', $id); |
|
999 | 999 | } |
1000 | - if(!empty($data[0]['features']) && isset($data[0]['features']['check_out_time'])){ |
|
1001 | - $time = str_replace('h',':',$data[0]['features']['check_out_time']); |
|
1002 | - $time = date('h:ia',strtotime($time)); |
|
1003 | - $this->save_custom_field($time,'checkout_time',$id); |
|
1000 | + if (!empty($data[0]['features']) && isset($data[0]['features']['check_out_time'])) { |
|
1001 | + $time = str_replace('h', ':', $data[0]['features']['check_out_time']); |
|
1002 | + $time = date('h:ia', strtotime($time)); |
|
1003 | + $this->save_custom_field($time, 'checkout_time', $id); |
|
1004 | 1004 | } |
1005 | 1005 | } |
1006 | 1006 | |
1007 | 1007 | /** |
1008 | 1008 | * Set the Video date |
1009 | 1009 | */ |
1010 | - public function set_video_data($data,$id) { |
|
1011 | - if(!empty($data[0]['content']['youtube_videos']) && is_array($data[0]['content']['youtube_videos'])){ |
|
1010 | + public function set_video_data($data, $id) { |
|
1011 | + if (!empty($data[0]['content']['youtube_videos']) && is_array($data[0]['content']['youtube_videos'])) { |
|
1012 | 1012 | $videos = false; |
1013 | 1013 | |
1014 | - foreach($data[0]['content']['youtube_videos'] as $video){ |
|
1014 | + foreach ($data[0]['content']['youtube_videos'] as $video) { |
|
1015 | 1015 | $temp_video = ''; |
1016 | - if(isset($video['label'])){ |
|
1016 | + if (isset($video['label'])) { |
|
1017 | 1017 | $temp_video['title'] = $video['label']; |
1018 | 1018 | } |
1019 | - if(isset($video['description'])){ |
|
1019 | + if (isset($video['description'])) { |
|
1020 | 1020 | $temp_video['description'] = strip_tags($video['description']); |
1021 | 1021 | } |
1022 | - if(isset($video['url'])){ |
|
1022 | + if (isset($video['url'])) { |
|
1023 | 1023 | $temp_video['url'] = $video['url']; |
1024 | 1024 | } |
1025 | 1025 | $temp_video['thumbnail'] = ''; |
1026 | 1026 | $videos[] = $temp_video; |
1027 | 1027 | } |
1028 | 1028 | |
1029 | - if(false !== $id && '0' !== $id){ |
|
1029 | + if (false !== $id && '0' !== $id) { |
|
1030 | 1030 | delete_post_meta($id, 'videos'); |
1031 | 1031 | } |
1032 | - foreach($videos as $video){ |
|
1033 | - add_post_meta($id,'videos',$video,false); |
|
1032 | + foreach ($videos as $video) { |
|
1033 | + add_post_meta($id, 'videos', $video, false); |
|
1034 | 1034 | } |
1035 | 1035 | } |
1036 | 1036 | } |
@@ -1038,7 +1038,7 @@ discard block |
||
1038 | 1038 | /** |
1039 | 1039 | * Set the Facilities |
1040 | 1040 | */ |
1041 | - public function set_facilities($data,$id) { |
|
1041 | + public function set_facilities($data, $id) { |
|
1042 | 1042 | |
1043 | 1043 | $parent_facilities = array( |
1044 | 1044 | 'available_services' => 'Available Services', |
@@ -1046,28 +1046,28 @@ discard block |
||
1046 | 1046 | 'room_facilities' => 'Room Facilities', |
1047 | 1047 | 'activities_on_site' => 'Activities on Site' |
1048 | 1048 | ); |
1049 | - foreach($parent_facilities as $key => $label){ |
|
1049 | + foreach ($parent_facilities as $key => $label) { |
|
1050 | 1050 | $terms = false; |
1051 | - if(isset($data[0]['features']) && isset($data[0]['features'][$key])){ |
|
1052 | - $parent_id = $this->set_term($id,$label,'facility'); |
|
1051 | + if (isset($data[0]['features']) && isset($data[0]['features'][$key])) { |
|
1052 | + $parent_id = $this->set_term($id, $label, 'facility'); |
|
1053 | 1053 | } |
1054 | - foreach($data[0]['features'][$key] as $child_facility){ |
|
1055 | - $this->set_term($id,$child_facility,'facility',$parent_id); |
|
1054 | + foreach ($data[0]['features'][$key] as $child_facility) { |
|
1055 | + $this->set_term($id, $child_facility, 'facility', $parent_id); |
|
1056 | 1056 | } |
1057 | 1057 | } |
1058 | 1058 | } |
1059 | 1059 | |
1060 | - function set_term($id=false,$name=false,$taxonomy=false,$parent=false){ |
|
1061 | - if(!$term = term_exists($name, $taxonomy)) |
|
1060 | + function set_term($id = false, $name = false, $taxonomy = false, $parent = false) { |
|
1061 | + if (!$term = term_exists($name, $taxonomy)) |
|
1062 | 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); } |
|
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 | 1067 | } |
1068 | 1068 | else |
1069 | 1069 | { |
1070 | - wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); |
|
1070 | + wp_set_object_terms($id, intval($term['term_id']), $taxonomy, true); |
|
1071 | 1071 | } |
1072 | 1072 | return $term['term_id']; |
1073 | 1073 | } |
@@ -1075,16 +1075,16 @@ discard block |
||
1075 | 1075 | /** |
1076 | 1076 | * Creates the main gallery data |
1077 | 1077 | */ |
1078 | - public function set_featured_image($data,$id) { |
|
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); |
|
1078 | + public function set_featured_image($data, $id) { |
|
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); |
|
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); |
|
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 | 1088 | $this->gallery_meta[] = $this->featured_image; |
1089 | 1089 | } |
1090 | 1090 | } |
@@ -1094,17 +1094,17 @@ discard block |
||
1094 | 1094 | /** |
1095 | 1095 | * Sets a banner image |
1096 | 1096 | */ |
1097 | - public function set_banner_image($data,$id) { |
|
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')); |
|
1097 | + public function set_banner_image($data, $id) { |
|
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 | 1100 | |
1101 | - if(false !== $this->banner_image){ |
|
1102 | - delete_post_meta($id,'image_group'); |
|
1101 | + if (false !== $this->banner_image) { |
|
1102 | + delete_post_meta($id, 'image_group'); |
|
1103 | 1103 | $new_banner = array('banner_image'=>array('cmb-field-0'=>$this->banner_image)); |
1104 | - add_post_meta($id,'image_group',$new_banner,true); |
|
1104 | + add_post_meta($id, 'image_group', $new_banner, true); |
|
1105 | 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); |
|
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 | 1108 | $this->gallery_meta[] = $this->banner_image; |
1109 | 1109 | } |
1110 | 1110 | } |
@@ -1114,24 +1114,24 @@ discard block |
||
1114 | 1114 | /** |
1115 | 1115 | * Creates the main gallery data |
1116 | 1116 | */ |
1117 | - public function create_main_gallery($data,$id) { |
|
1117 | + public function create_main_gallery($data, $id) { |
|
1118 | 1118 | |
1119 | - if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){ |
|
1119 | + if (is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])) { |
|
1120 | 1120 | |
1121 | 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;} |
|
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 | 1125 | |
1126 | - $this->gallery_meta[] = $temp_id = $this->attach_image($image_data,$id); |
|
1126 | + $this->gallery_meta[] = $temp_id = $this->attach_image($image_data, $id); |
|
1127 | 1127 | $counter++; |
1128 | 1128 | } |
1129 | 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); |
|
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 | 1135 | } |
1136 | 1136 | } |
1137 | 1137 | } |
@@ -1141,53 +1141,53 @@ discard block |
||
1141 | 1141 | /** |
1142 | 1142 | * Attaches 1 image |
1143 | 1143 | */ |
1144 | - public function attach_image($v=false,$parent_id,$image_sizes=false){ |
|
1145 | - if(false !== $v){ |
|
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); |
|
1144 | + public function attach_image($v = false, $parent_id, $image_sizes = false) { |
|
1145 | + if (false !== $v) { |
|
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); |
|
1149 | 1149 | |
1150 | - if(in_array($url_filename,$this->found_attachments)){ |
|
1151 | - return array_search($url_filename,$this->found_attachments); |
|
1150 | + if (in_array($url_filename, $this->found_attachments)) { |
|
1151 | + return array_search($url_filename, $this->found_attachments); |
|
1152 | 1152 | } |
1153 | 1153 | |
1154 | - $postdata=array(); |
|
1155 | - if(empty($v['label'])) |
|
1154 | + $postdata = array(); |
|
1155 | + if (empty($v['label'])) |
|
1156 | 1156 | { |
1157 | - $v['label']=''; |
|
1157 | + $v['label'] = ''; |
|
1158 | 1158 | } |
1159 | - if(!empty($v['description'])) |
|
1159 | + if (!empty($v['description'])) |
|
1160 | 1160 | { |
1161 | - $desc=wp_strip_all_tags($v['description']); |
|
1162 | - $posdata=array('post_excerpt'=>$desc); |
|
1161 | + $desc = wp_strip_all_tags($v['description']); |
|
1162 | + $posdata = array('post_excerpt'=>$desc); |
|
1163 | 1163 | } |
1164 | - if(!empty($v['section'])) |
|
1164 | + if (!empty($v['section'])) |
|
1165 | 1165 | { |
1166 | - $desc=wp_strip_all_tags($v['section']); |
|
1167 | - $posdata=array('post_excerpt'=>$desc); |
|
1166 | + $desc = wp_strip_all_tags($v['section']); |
|
1167 | + $posdata = array('post_excerpt'=>$desc); |
|
1168 | 1168 | } |
1169 | 1169 | |
1170 | - $attachID=NULL; |
|
1170 | + $attachID = NULL; |
|
1171 | 1171 | //Resizor - add option to setting if required |
1172 | - $fragment = str_replace(' ','%20',$v['url_fragment']); |
|
1172 | + $fragment = str_replace(' ', '%20', $v['url_fragment']); |
|
1173 | 1173 | $url = $this->get_scaling_url($image_sizes).$fragment; |
1174 | - $attachID = $this->attach_external_image2($url,$parent_id,'',$v['label'],$postdata); |
|
1174 | + $attachID = $this->attach_external_image2($url, $parent_id, '', $v['label'], $postdata); |
|
1175 | 1175 | |
1176 | 1176 | //echo($attachID.' add image'); |
1177 | - if($attachID!=NULL) |
|
1177 | + if ($attachID != NULL) |
|
1178 | 1178 | { |
1179 | 1179 | return $attachID; |
1180 | 1180 | } |
1181 | 1181 | } |
1182 | 1182 | return false; |
1183 | 1183 | } |
1184 | - public function attach_external_image2( $url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array() ) { |
|
1184 | + public function attach_external_image2($url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array()) { |
|
1185 | 1185 | |
1186 | - if ( !$url || !$post_id ) { return new WP_Error('missing', "Need a valid URL and post ID..."); } |
|
1186 | + if (!$url || !$post_id) { return new WP_Error('missing', "Need a valid URL and post ID..."); } |
|
1187 | 1187 | |
1188 | - require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
1189 | - require_once(ABSPATH . 'wp-admin/includes/media.php'); |
|
1190 | - require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
1188 | + require_once(ABSPATH.'wp-admin/includes/file.php'); |
|
1189 | + require_once(ABSPATH.'wp-admin/includes/media.php'); |
|
1190 | + require_once(ABSPATH.'wp-admin/includes/image.php'); |
|
1191 | 1191 | // Download file to temp location, returns full server path to temp file |
1192 | 1192 | //$tmp = download_url( $url ); |
1193 | 1193 | |
@@ -1196,53 +1196,53 @@ discard block |
||
1196 | 1196 | |
1197 | 1197 | $image = file_get_contents($url); |
1198 | 1198 | file_put_contents($tmp, $image); |
1199 | - chmod($tmp,'777'); |
|
1199 | + chmod($tmp, '777'); |
|
1200 | 1200 | |
1201 | - preg_match('/[^\?]+\.(tif|TIFF|jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG|pdf|PDF|bmp|BMP)/', $url, $matches); // fix file filename for query strings |
|
1201 | + preg_match('/[^\?]+\.(tif|TIFF|jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG|pdf|PDF|bmp|BMP)/', $url, $matches); // fix file filename for query strings |
|
1202 | 1202 | $url_filename = basename($matches[0]); |
1203 | - $url_filename=str_replace('%20','_',$url_filename); |
|
1203 | + $url_filename = str_replace('%20', '_', $url_filename); |
|
1204 | 1204 | // extract filename from url for title |
1205 | - $url_type = wp_check_filetype($url_filename); // determine file type (ext and mime/type) |
|
1205 | + $url_type = wp_check_filetype($url_filename); // determine file type (ext and mime/type) |
|
1206 | 1206 | |
1207 | 1207 | // override filename if given, reconstruct server path |
1208 | - if ( !empty( $filename ) && " " != $filename ) |
|
1208 | + if (!empty($filename) && " " != $filename) |
|
1209 | 1209 | { |
1210 | 1210 | $filename = sanitize_file_name($filename); |
1211 | - $tmppath = pathinfo( $tmp ); |
|
1211 | + $tmppath = pathinfo($tmp); |
|
1212 | 1212 | |
1213 | 1213 | $extension = ''; |
1214 | - if(isset($tmppath['extension'])){ |
|
1214 | + if (isset($tmppath['extension'])) { |
|
1215 | 1215 | $extension = $tmppath['extension']; |
1216 | 1216 | } |
1217 | 1217 | |
1218 | - $new = $tmppath['dirname'] . "/". $filename . "." . $extension; |
|
1219 | - rename($tmp, $new); // renames temp file on server |
|
1220 | - $tmp = $new; // push new filename (in path) to be used in file array later |
|
1218 | + $new = $tmppath['dirname']."/".$filename.".".$extension; |
|
1219 | + rename($tmp, $new); // renames temp file on server |
|
1220 | + $tmp = $new; // push new filename (in path) to be used in file array later |
|
1221 | 1221 | } |
1222 | 1222 | |
1223 | 1223 | // assemble file data (should be built like $_FILES since wp_handle_sideload() will be using) |
1224 | - $file_array['tmp_name'] = $tmp; // full server path to temp file |
|
1224 | + $file_array['tmp_name'] = $tmp; // full server path to temp file |
|
1225 | 1225 | |
1226 | - if ( !empty( $filename) && " " != $filename ) |
|
1226 | + if (!empty($filename) && " " != $filename) |
|
1227 | 1227 | { |
1228 | - $file_array['name'] = $filename . "." . $url_type['ext']; // user given filename for title, add original URL extension |
|
1228 | + $file_array['name'] = $filename.".".$url_type['ext']; // user given filename for title, add original URL extension |
|
1229 | 1229 | } |
1230 | 1230 | else |
1231 | 1231 | { |
1232 | - $file_array['name'] = $url_filename; // just use original URL filename |
|
1232 | + $file_array['name'] = $url_filename; // just use original URL filename |
|
1233 | 1233 | } |
1234 | 1234 | |
1235 | 1235 | // set additional wp_posts columns |
1236 | - if ( empty( $post_data['post_title'] ) ) |
|
1236 | + if (empty($post_data['post_title'])) |
|
1237 | 1237 | { |
1238 | 1238 | |
1239 | - $url_filename=str_replace('%20',' ',$url_filename); |
|
1239 | + $url_filename = str_replace('%20', ' ', $url_filename); |
|
1240 | 1240 | |
1241 | - $post_data['post_title'] = basename($url_filename, "." . $url_type['ext']); // just use the original filename (no extension) |
|
1241 | + $post_data['post_title'] = basename($url_filename, ".".$url_type['ext']); // just use the original filename (no extension) |
|
1242 | 1242 | } |
1243 | 1243 | |
1244 | 1244 | // make sure gets tied to parent |
1245 | - if ( empty( $post_data['post_parent'] ) ) |
|
1245 | + if (empty($post_data['post_parent'])) |
|
1246 | 1246 | { |
1247 | 1247 | $post_data['post_parent'] = $post_id; |
1248 | 1248 | } |
@@ -1250,12 +1250,12 @@ discard block |
||
1250 | 1250 | // required libraries for media_handle_sideload |
1251 | 1251 | |
1252 | 1252 | // do the validation and storage stuff |
1253 | - $att_id = media_handle_sideload( $file_array, $post_id, null, $post_data ); // $post_data can override the items saved to wp_posts table, like post_mime_type, guid, post_parent, post_title, post_content, post_status |
|
1253 | + $att_id = media_handle_sideload($file_array, $post_id, null, $post_data); // $post_data can override the items saved to wp_posts table, like post_mime_type, guid, post_parent, post_title, post_content, post_status |
|
1254 | 1254 | |
1255 | 1255 | // If error storing permanently, unlink |
1256 | - if ( is_wp_error($att_id) ) |
|
1256 | + if (is_wp_error($att_id)) |
|
1257 | 1257 | { |
1258 | - unlink($file_array['tmp_name']); // clean up |
|
1258 | + unlink($file_array['tmp_name']); // clean up |
|
1259 | 1259 | return false; // output wp_error |
1260 | 1260 | //return $att_id; // output wp_error |
1261 | 1261 | } |