@@ -51,7 +51,7 @@ |
||
51 | 51 | */ |
52 | 52 | public function display_page() { |
53 | 53 | global $post; |
54 | - ?> |
|
54 | + ?> |
|
55 | 55 | <div class="wrap"> |
56 | 56 | |
57 | 57 | <h3><span class="dashicons dashicons-admin-multisite"></span> <?php _e('Connect your Accommodation','wetu-importer'); ?></h3> |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | * Display the importer administration screen |
93 | 93 | */ |
94 | 94 | public function display_page() { |
95 | - ?> |
|
95 | + ?> |
|
96 | 96 | <div class="wrap"> |
97 | 97 | <?php screen_icon(); ?> |
98 | 98 | |
@@ -218,13 +218,13 @@ discard block |
||
218 | 218 | $result = $this->update_options(); |
219 | 219 | |
220 | 220 | if(true === $result){ |
221 | - echo '<span style="color:green;">'.esc_attr('Connected','ti-tours').'</span>'; |
|
222 | - }else{ |
|
223 | - echo '<span style="color:red;">'.wp_kses_post($result).'</span>'; |
|
224 | - } |
|
221 | + echo '<span style="color:green;">'.esc_attr('Connected','ti-tours').'</span>'; |
|
222 | + }else{ |
|
223 | + echo '<span style="color:red;">'.wp_kses_post($result).'</span>'; |
|
224 | + } |
|
225 | 225 | }else{ |
226 | 226 | echo '<span style="color:green;">'.esc_attr('Connected','ti-tours').'</span>'; |
227 | - } |
|
227 | + } |
|
228 | 228 | echo '</h3></div>'; |
229 | 229 | } |
230 | 230 | |
@@ -236,8 +236,8 @@ discard block |
||
236 | 236 | $tours = json_decode($data, true); |
237 | 237 | |
238 | 238 | if(isset($tours['error'])){ |
239 | - return $tours['error']; |
|
240 | - }elseif (isset($tours['itineraries']) && !empty($tours['itineraries'])) { |
|
239 | + return $tours['error']; |
|
240 | + }elseif (isset($tours['itineraries']) && !empty($tours['itineraries'])) { |
|
241 | 241 | set_transient('lsx_ti_tours',$tours['itineraries'],60*60*2); |
242 | 242 | return true; |
243 | 243 | } |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | $keyphrases = $_POST['keyword']; |
285 | 285 | }else{ |
286 | 286 | $keyphrases = array(0); |
287 | - } |
|
287 | + } |
|
288 | 288 | |
289 | 289 | if(!is_array($keyphrases)){ |
290 | 290 | $keyphrases = array($keyphrases); |
@@ -313,15 +313,15 @@ discard block |
||
313 | 313 | |
314 | 314 | foreach($tours as $row_key => $row){ |
315 | 315 | |
316 | - if(isset($row['is_disabled']) && true === $row['is_disabled']){ |
|
317 | - continue; |
|
318 | - } |
|
316 | + if(isset($row['is_disabled']) && true === $row['is_disabled']){ |
|
317 | + continue; |
|
318 | + } |
|
319 | 319 | |
320 | - if('Sample' === $row['type']){ |
|
321 | - continue; |
|
322 | - } |
|
320 | + if('Sample' === $row['type']){ |
|
321 | + continue; |
|
322 | + } |
|
323 | 323 | |
324 | - //If this is a current tour, add its ID to the row. |
|
324 | + //If this is a current tour, add its ID to the row. |
|
325 | 325 | $row['post_id'] = 0; |
326 | 326 | if(false !== $current_tours && array_key_exists($row['identifier'], $current_tours)){ |
327 | 327 | $row['post_id'] = $current_tours[$row['identifier']]->post_id; |
@@ -330,31 +330,31 @@ discard block |
||
330 | 330 | //If we are searching for |
331 | 331 | if(false !== $post_status){ |
332 | 332 | |
333 | - if('import' === $post_status){ |
|
333 | + if('import' === $post_status){ |
|
334 | 334 | |
335 | 335 | if(0 !== $row['post_id']){ |
336 | - continue; |
|
336 | + continue; |
|
337 | 337 | }else{ |
338 | 338 | $searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row); |
339 | - } |
|
339 | + } |
|
340 | 340 | |
341 | 341 | |
342 | - }else{ |
|
342 | + }else{ |
|
343 | 343 | |
344 | 344 | if(0 === $row['post_id']){ |
345 | 345 | continue; |
346 | 346 | }else{ |
347 | 347 | $current_status = get_post_status($row['post_id']); |
348 | 348 | if($current_status !== $post_status){ |
349 | - continue; |
|
350 | - } |
|
349 | + continue; |
|
350 | + } |
|
351 | 351 | |
352 | 352 | } |
353 | 353 | $searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row); |
354 | 354 | |
355 | - } |
|
355 | + } |
|
356 | 356 | |
357 | - }else{ |
|
357 | + }else{ |
|
358 | 358 | //Search through each keyword. |
359 | 359 | foreach($keyphrases as $keyphrase){ |
360 | 360 | |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | $searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row); |
369 | 369 | } |
370 | 370 | } |
371 | - } |
|
371 | + } |
|
372 | 372 | } |
373 | 373 | } |
374 | 374 | |
@@ -433,17 +433,17 @@ discard block |
||
433 | 433 | $content = false; |
434 | 434 | } |
435 | 435 | |
436 | - $jdata=file_get_contents("http://wetu.com/API/Itinerary/V7/Get?id=".$wetu_id); |
|
436 | + $jdata=file_get_contents("http://wetu.com/API/Itinerary/V7/Get?id=".$wetu_id); |
|
437 | 437 | |
438 | - if($jdata) |
|
439 | - { |
|
438 | + if($jdata) |
|
439 | + { |
|
440 | 440 | $jdata=json_decode($jdata,true); |
441 | - if(!empty($jdata)) |
|
442 | - { |
|
443 | - $return = $this->import_row($jdata,$wetu_id,$post_id,$content); |
|
444 | - $this->format_completed_row($return); |
|
445 | - } |
|
446 | - } |
|
441 | + if(!empty($jdata)) |
|
442 | + { |
|
443 | + $return = $this->import_row($jdata,$wetu_id,$post_id,$content); |
|
444 | + $this->format_completed_row($return); |
|
445 | + } |
|
446 | + } |
|
447 | 447 | die(); |
448 | 448 | } |
449 | 449 | |
@@ -451,60 +451,60 @@ discard block |
||
451 | 451 | |
452 | 452 | /** |
453 | 453 | * Connect to wetu |
454 | - * |
|
455 | - * @param $data array |
|
456 | - * @param $wetu_id string |
|
454 | + * |
|
455 | + * @param $data array |
|
456 | + * @param $wetu_id string |
|
457 | 457 | */ |
458 | 458 | public function import_row($data,$wetu_id,$id=0,$importable_content=false,$old1=false,$old2=false) { |
459 | - $post_name = $data_post_content = $data_post_excerpt = ''; |
|
460 | - $post = array( |
|
461 | - 'post_type' => 'tour', |
|
462 | - ); |
|
459 | + $post_name = $data_post_content = $data_post_excerpt = ''; |
|
460 | + $post = array( |
|
461 | + 'post_type' => 'tour', |
|
462 | + ); |
|
463 | 463 | |
464 | - //Set the post_content |
|
464 | + //Set the post_content |
|
465 | 465 | $content_used_general_description = false; |
466 | - if(false !== $importable_content && in_array('description',$importable_content)){ |
|
467 | - $data_post_content = ''; |
|
468 | - |
|
469 | - if(isset($data['description'])){ |
|
470 | - $data_post_content = $data['description']; |
|
471 | - }elseif(isset($data['summary'])){ |
|
472 | - $data_post_content = $data['summary']; |
|
473 | - $content_used_general_description = true; |
|
474 | - } |
|
475 | - $post['post_content'] = wp_strip_all_tags($data_post_content); |
|
476 | - } |
|
477 | - |
|
478 | - //set the post_excerpt |
|
479 | - if(false !== $importable_content && in_array('excerpt',$importable_content)){ |
|
480 | - if(isset($data['summary']) && false === $content_used_general_description){ |
|
481 | - $post['post_excerpt'] = $data['summary']; |
|
482 | - } |
|
483 | - } |
|
484 | - |
|
485 | - //Create or update the post |
|
486 | - if(false !== $id && '0' !== $id){ |
|
487 | - $post['ID'] = $id; |
|
488 | - $id = wp_update_post($post); |
|
489 | - $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
490 | - update_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified']),$prev_date); |
|
491 | - }else{ |
|
492 | - |
|
493 | - //Set the name |
|
494 | - if(isset($data['name'])){ |
|
495 | - $post_name = wp_unique_post_slug(sanitize_title($data['name']),$id, 'draft', 'tour', 0); |
|
496 | - } |
|
497 | - $post['post_name'] = $post_name; |
|
498 | - $post['post_title'] = $data['name']; |
|
499 | - $post['post_status'] = 'pending'; |
|
500 | - $id = wp_insert_post($post); |
|
501 | - |
|
502 | - //Save the WETU ID and the Last date it was modified. |
|
503 | - if(false !== $id){ |
|
504 | - add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
505 | - add_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified'])); |
|
506 | - } |
|
507 | - } |
|
466 | + if(false !== $importable_content && in_array('description',$importable_content)){ |
|
467 | + $data_post_content = ''; |
|
468 | + |
|
469 | + if(isset($data['description'])){ |
|
470 | + $data_post_content = $data['description']; |
|
471 | + }elseif(isset($data['summary'])){ |
|
472 | + $data_post_content = $data['summary']; |
|
473 | + $content_used_general_description = true; |
|
474 | + } |
|
475 | + $post['post_content'] = wp_strip_all_tags($data_post_content); |
|
476 | + } |
|
477 | + |
|
478 | + //set the post_excerpt |
|
479 | + if(false !== $importable_content && in_array('excerpt',$importable_content)){ |
|
480 | + if(isset($data['summary']) && false === $content_used_general_description){ |
|
481 | + $post['post_excerpt'] = $data['summary']; |
|
482 | + } |
|
483 | + } |
|
484 | + |
|
485 | + //Create or update the post |
|
486 | + if(false !== $id && '0' !== $id){ |
|
487 | + $post['ID'] = $id; |
|
488 | + $id = wp_update_post($post); |
|
489 | + $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
490 | + update_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified']),$prev_date); |
|
491 | + }else{ |
|
492 | + |
|
493 | + //Set the name |
|
494 | + if(isset($data['name'])){ |
|
495 | + $post_name = wp_unique_post_slug(sanitize_title($data['name']),$id, 'draft', 'tour', 0); |
|
496 | + } |
|
497 | + $post['post_name'] = $post_name; |
|
498 | + $post['post_title'] = $data['name']; |
|
499 | + $post['post_status'] = 'pending'; |
|
500 | + $id = wp_insert_post($post); |
|
501 | + |
|
502 | + //Save the WETU ID and the Last date it was modified. |
|
503 | + if(false !== $id){ |
|
504 | + add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
505 | + add_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified'])); |
|
506 | + } |
|
507 | + } |
|
508 | 508 | |
509 | 509 | |
510 | 510 | //Set the price |
@@ -517,9 +517,9 @@ discard block |
||
517 | 517 | $this->set_duration($data,$id); |
518 | 518 | } |
519 | 519 | |
520 | - if(in_array('itineraries',$importable_content) && isset($data['legs']) && !empty($data['legs'])){ |
|
521 | - $this->process_itineraries($data,$id,$importable_content); |
|
522 | - } |
|
520 | + if(in_array('itineraries',$importable_content) && isset($data['legs']) && !empty($data['legs'])){ |
|
521 | + $this->process_itineraries($data,$id,$importable_content); |
|
522 | + } |
|
523 | 523 | |
524 | 524 | if(in_array('map',$importable_content) && isset($data['routes']) && !empty($data['routes'])){ |
525 | 525 | $this->process_map_points($data,$id); |
@@ -530,24 +530,24 @@ discard block |
||
530 | 530 | if(false !== $importable_content && (in_array('itinerary_gallery',$importable_content) || in_array('gallery',$importable_content) || in_array('banner_image',$importable_content) || in_array('featured_image',$importable_content))){ |
531 | 531 | $this->find_attachments($id); |
532 | 532 | } |
533 | - //Set the featured image |
|
534 | - //TODO Test These |
|
535 | - if(false !== $importable_content && in_array('featured_image',$importable_content)){ |
|
536 | - $this->set_featured_image($data,$id); |
|
537 | - } |
|
533 | + //Set the featured image |
|
534 | + //TODO Test These |
|
535 | + if(false !== $importable_content && in_array('featured_image',$importable_content)){ |
|
536 | + $this->set_featured_image($data,$id); |
|
537 | + } |
|
538 | 538 | |
539 | 539 | //TODO Test These |
540 | - if(false !== $importable_content && in_array('banner_image',$importable_content)){ |
|
541 | - $this->set_banner_image($data,$id); |
|
542 | - } |
|
540 | + if(false !== $importable_content && in_array('banner_image',$importable_content)){ |
|
541 | + $this->set_banner_image($data,$id); |
|
542 | + } |
|
543 | 543 | |
544 | 544 | //TODO Test These |
545 | - //Import the main gallery |
|
546 | - if(false !== $importable_content && in_array('gallery',$importable_content)){ |
|
547 | - $this->create_main_gallery($data,$id); |
|
548 | - } |
|
545 | + //Import the main gallery |
|
546 | + if(false !== $importable_content && in_array('gallery',$importable_content)){ |
|
547 | + $this->create_main_gallery($data,$id); |
|
548 | + } |
|
549 | 549 | |
550 | - return $id; |
|
550 | + return $id; |
|
551 | 551 | } |
552 | 552 | |
553 | 553 | /** |
@@ -635,31 +635,31 @@ discard block |
||
635 | 635 | */ |
636 | 636 | public function process_map_points($data,$id) { |
637 | 637 | |
638 | - if(!empty($data['routes'])){ |
|
638 | + if(!empty($data['routes'])){ |
|
639 | 639 | |
640 | - delete_post_meta($id,'wetu_map_points'); |
|
640 | + delete_post_meta($id,'wetu_map_points'); |
|
641 | 641 | |
642 | - $points = array(); |
|
642 | + $points = array(); |
|
643 | 643 | |
644 | - foreach($data['routes'] as $route){ |
|
644 | + foreach($data['routes'] as $route){ |
|
645 | 645 | |
646 | 646 | |
647 | - if(isset($route['points']) && '' !== $route['points']){ |
|
647 | + if(isset($route['points']) && '' !== $route['points']){ |
|
648 | 648 | |
649 | - $temp_points = explode(';',$route['points']); |
|
650 | - $point_counter = count($temp_points); |
|
649 | + $temp_points = explode(';',$route['points']); |
|
650 | + $point_counter = count($temp_points); |
|
651 | 651 | |
652 | 652 | for ($x = 0; $x <= $point_counter; $x++) { |
653 | - $y = $x+1; |
|
653 | + $y = $x+1; |
|
654 | 654 | $points[] = $temp_points[$x].','.$temp_points[$y]; |
655 | 655 | $x++; |
656 | 656 | } |
657 | 657 | } |
658 | - } |
|
659 | - if(!empty($points)){ |
|
658 | + } |
|
659 | + if(!empty($points)){ |
|
660 | 660 | $this->save_custom_field(implode(' ',$points),'wetu_map_points',$id,false,true); |
661 | - } |
|
662 | - } |
|
661 | + } |
|
662 | + } |
|
663 | 663 | |
664 | 664 | } |
665 | 665 | |
@@ -667,7 +667,7 @@ discard block |
||
667 | 667 | * Set the Itinerary Day |
668 | 668 | */ |
669 | 669 | public function set_itinerary_day($day,$id) { |
670 | - $this->save_custom_field($day,'itinerary',$id,false,false); |
|
670 | + $this->save_custom_field($day,'itinerary',$id,false,false); |
|
671 | 671 | } |
672 | 672 | |
673 | 673 | /** |
@@ -675,8 +675,8 @@ discard block |
||
675 | 675 | */ |
676 | 676 | public function set_price($data,$id) { |
677 | 677 | if(isset($data['price']) && ''!== $data['price']){ |
678 | - $price = preg_replace("/[^0-9,.]/", "", $data['price']); |
|
679 | - $this->save_custom_field($price,'price',$id); |
|
678 | + $price = preg_replace("/[^0-9,.]/", "", $data['price']); |
|
679 | + $this->save_custom_field($price,'price',$id); |
|
680 | 680 | } |
681 | 681 | } |
682 | 682 | |
@@ -697,7 +697,7 @@ discard block |
||
697 | 697 | */ |
698 | 698 | public function set_accommodation($day,$id) { |
699 | 699 | |
700 | - $ac_id = false; |
|
700 | + $ac_id = false; |
|
701 | 701 | if(false === $this->current_accommodation) { |
702 | 702 | $this->current_accommodation = $this->find_current_accommodation(); |
703 | 703 | } |
@@ -705,29 +705,29 @@ discard block |
||
705 | 705 | if(isset($day['content_entity_id']) && !empty($day['content_entity_id'])){ |
706 | 706 | |
707 | 707 | if(false !== $this->current_accommodation && !empty($this->current_accommodation) && array_key_exists($day['content_entity_id'],$this->current_accommodation)){ |
708 | - $ac_id = $this->current_accommodation[$day['content_entity_id']]; |
|
708 | + $ac_id = $this->current_accommodation[$day['content_entity_id']]; |
|
709 | 709 | }else{ |
710 | 710 | $ac_id = wp_insert_post(array( |
711 | - 'post_type' => 'accommodation', |
|
712 | - 'post_status' => 'draft', |
|
713 | - 'post_title' => $day['content_entity_id'] |
|
714 | - )); |
|
711 | + 'post_type' => 'accommodation', |
|
712 | + 'post_status' => 'draft', |
|
713 | + 'post_title' => $day['content_entity_id'] |
|
714 | + )); |
|
715 | 715 | $this->save_custom_field($day['content_entity_id'],'lsx_wetu_id',$ac_id); |
716 | 716 | } |
717 | 717 | |
718 | 718 | if('' !== $ac_id && false !== $ac_id){ |
719 | - $this->save_custom_field($ac_id,'accommodation_to_tour',$id,false,false); |
|
719 | + $this->save_custom_field($ac_id,'accommodation_to_tour',$id,false,false); |
|
720 | 720 | $this->save_custom_field($id,'tour_to_accommodation',$ac_id,false,false); |
721 | - } |
|
721 | + } |
|
722 | 722 | } |
723 | 723 | return $ac_id; |
724 | 724 | } |
725 | 725 | |
726 | 726 | /** |
727 | 727 | * Grab all the current accommodation posts via the lsx_wetu_id field. |
728 | - * |
|
729 | - * @param $post_type string |
|
730 | - * @return boolean / array |
|
728 | + * |
|
729 | + * @param $post_type string |
|
730 | + * @return boolean / array |
|
731 | 731 | */ |
732 | 732 | public function find_current_accommodation($post_type='accommodation') { |
733 | 733 | global $wpdb; |
@@ -735,16 +735,16 @@ discard block |
||
735 | 735 | |
736 | 736 | $return = false; |
737 | 737 | if(!empty($accommodation)){ |
738 | - foreach($accommodation as $key => $acc){ |
|
738 | + foreach($accommodation as $key => $acc){ |
|
739 | 739 | $return[$acc->meta_value] = $acc->post_id; |
740 | - } |
|
741 | - } |
|
740 | + } |
|
741 | + } |
|
742 | 742 | return $return; |
743 | 743 | } |
744 | 744 | |
745 | 745 | /** |
746 | 746 | * Grab all the current accommodation posts via the lsx_wetu_id field. |
747 | - * @return boolean / array |
|
747 | + * @return boolean / array |
|
748 | 748 | */ |
749 | 749 | public function find_current_destinations() { |
750 | 750 | return $this->find_current_accommodation('destination'); |
@@ -774,7 +774,7 @@ discard block |
||
774 | 774 | $country_wetu_id = get_post_meta($potential_id,'lsx_wetu_id',true); |
775 | 775 | if(false !== $country_wetu_id){ |
776 | 776 | $this->set_country($country_wetu_id, $id); |
777 | - } |
|
777 | + } |
|
778 | 778 | |
779 | 779 | }else { |
780 | 780 | |
@@ -785,27 +785,27 @@ discard block |
||
785 | 785 | |
786 | 786 | if (!empty($destination_data) && !isset($destination_data['error'])) { |
787 | 787 | |
788 | - $destination_title = $day['destination_content_entity_id']; |
|
788 | + $destination_title = $day['destination_content_entity_id']; |
|
789 | 789 | |
790 | - if(isset($destination_data[0]['name'])){ |
|
790 | + if(isset($destination_data[0]['name'])){ |
|
791 | 791 | $destination_title = $destination_data[0]['name']; |
792 | - } |
|
792 | + } |
|
793 | 793 | |
794 | - if(isset($destination_data[0]['map_object_id']) && isset($destination_data[0]['position']['country_content_entity_id']) |
|
795 | - && $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id']){ |
|
794 | + if(isset($destination_data[0]['map_object_id']) && isset($destination_data[0]['position']['country_content_entity_id']) |
|
795 | + && $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id']){ |
|
796 | 796 | |
797 | 797 | $country_id = $this->set_country($destination_data[0]['position']['country_content_entity_id'], $id); |
798 | - } |
|
798 | + } |
|
799 | 799 | |
800 | - $dest_post = array( |
|
800 | + $dest_post = array( |
|
801 | 801 | 'post_type' => 'destination', |
802 | 802 | 'post_status' => 'draft', |
803 | 803 | 'post_title' => $destination_title |
804 | 804 | ); |
805 | 805 | |
806 | - if(false !== $country_id){ |
|
806 | + if(false !== $country_id){ |
|
807 | 807 | $dest_post['post_parent'] = $country_id; |
808 | - } |
|
808 | + } |
|
809 | 809 | $dest_id = wp_insert_post($dest_post); |
810 | 810 | |
811 | 811 | $this->save_custom_field($day['destination_content_entity_id'], 'lsx_wetu_id', $dest_id); |
@@ -824,48 +824,48 @@ discard block |
||
824 | 824 | * Connects the destinations post type |
825 | 825 | * |
826 | 826 | * @param $dest_id string |
827 | - * @param $country_id array |
|
827 | + * @param $country_id array |
|
828 | 828 | * @param $id string |
829 | 829 | */ |
830 | 830 | public function set_country($country_wetu_id, $id) { |
831 | - $country_id = false; |
|
831 | + $country_id = false; |
|
832 | 832 | |
833 | 833 | if(false === $this->current_destinations) { |
834 | 834 | $this->current_destinations = $this->find_current_destinations(); |
835 | 835 | } |
836 | 836 | |
837 | - if (false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($country_wetu_id, $this->current_destinations)) { |
|
838 | - $country_id = $this->current_destinations[$country_wetu_id]; |
|
839 | - } else { |
|
837 | + if (false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($country_wetu_id, $this->current_destinations)) { |
|
838 | + $country_id = $this->current_destinations[$country_wetu_id]; |
|
839 | + } else { |
|
840 | 840 | |
841 | - $country_json = file_get_contents("http://wetu.com/API/Pins/".$this->api_key."/Get?ids=" . $country_wetu_id); |
|
841 | + $country_json = file_get_contents("http://wetu.com/API/Pins/".$this->api_key."/Get?ids=" . $country_wetu_id); |
|
842 | 842 | |
843 | - if ($country_json) { |
|
844 | - $country_data = json_decode($country_json, true); |
|
843 | + if ($country_json) { |
|
844 | + $country_data = json_decode($country_json, true); |
|
845 | 845 | |
846 | - if (!empty($country_data) && !isset($country_data['error'])) { |
|
846 | + if (!empty($country_data) && !isset($country_data['error'])) { |
|
847 | 847 | |
848 | - $country_title = $country_wetu_id; |
|
849 | - if (isset($country_data[0]['name'])) { |
|
848 | + $country_title = $country_wetu_id; |
|
849 | + if (isset($country_data[0]['name'])) { |
|
850 | 850 | $country_title = $country_data[0]['name']; |
851 | - } |
|
851 | + } |
|
852 | 852 | |
853 | 853 | $country_id = wp_insert_post(array( |
854 | - 'post_type' => 'destination', |
|
855 | - 'post_status' => 'draft', |
|
856 | - 'post_title' => $country_title |
|
857 | - )); |
|
858 | - $this->save_custom_field($country_wetu_id, 'lsx_wetu_id', $country_id); |
|
859 | - } |
|
860 | - } |
|
861 | - } |
|
862 | - |
|
863 | - if ('' !== $country_id && false !== $country_id) { |
|
864 | - $this->save_custom_field($country_id, 'destination_to_tour', $id, false, false); |
|
865 | - $this->save_custom_field($id, 'tour_to_destination', $country_id, false, false); |
|
866 | - |
|
867 | - return $country_id; |
|
868 | - } |
|
854 | + 'post_type' => 'destination', |
|
855 | + 'post_status' => 'draft', |
|
856 | + 'post_title' => $country_title |
|
857 | + )); |
|
858 | + $this->save_custom_field($country_wetu_id, 'lsx_wetu_id', $country_id); |
|
859 | + } |
|
860 | + } |
|
861 | + } |
|
862 | + |
|
863 | + if ('' !== $country_id && false !== $country_id) { |
|
864 | + $this->save_custom_field($country_id, 'destination_to_tour', $id, false, false); |
|
865 | + $this->save_custom_field($id, 'tour_to_destination', $country_id, false, false); |
|
866 | + |
|
867 | + return $country_id; |
|
868 | + } |
|
869 | 869 | } |
870 | 870 | } |
871 | 871 | $wetu_importer_tours = new WETU_Importer_Tours(); |
872 | 872 | \ No newline at end of file |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * Display the importer administration screen |
38 | 38 | */ |
39 | 39 | public function display_page() { |
40 | - ?> |
|
40 | + ?> |
|
41 | 41 | <div class="wrap"> |
42 | 42 | |
43 | 43 | <h2><?php _e('Download new banners straight from WETU','wetu-importer'); ?></h2> |
@@ -211,14 +211,14 @@ discard block |
||
211 | 211 | $base = rawurlencode($base); |
212 | 212 | $type = get_post_mime_type($post_id); |
213 | 213 | switch ($type) { |
214 | - case 'image/jpeg': |
|
215 | - return $base . ".jpg"; break; |
|
216 | - case 'image/png': |
|
217 | - return $base . ".png"; break; |
|
218 | - case 'image/gif': |
|
219 | - return $base . ".gif"; break; |
|
220 | - default: |
|
221 | - return false; |
|
214 | + case 'image/jpeg': |
|
215 | + return $base . ".jpg"; break; |
|
216 | + case 'image/png': |
|
217 | + return $base . ".png"; break; |
|
218 | + case 'image/gif': |
|
219 | + return $base . ".gif"; break; |
|
220 | + default: |
|
221 | + return false; |
|
222 | 222 | } |
223 | 223 | } |
224 | 224 |
@@ -63,15 +63,15 @@ discard block |
||
63 | 63 | parent::set_variables(); |
64 | 64 | |
65 | 65 | if(false !== $this->api_key){ |
66 | - $this->url = 'https://wetu.com/API/Pins/'.$this->api_key; |
|
67 | - } |
|
66 | + $this->url = 'https://wetu.com/API/Pins/'.$this->api_key; |
|
67 | + } |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
71 | 71 | * Display the importer administration screen |
72 | 72 | */ |
73 | 73 | public function display_page() { |
74 | - ?> |
|
74 | + ?> |
|
75 | 75 | <div class="wrap"> |
76 | 76 | <?php screen_icon(); ?> |
77 | 77 | |
@@ -308,11 +308,11 @@ discard block |
||
308 | 308 | //If we are searching for |
309 | 309 | if(false !== $post_status){ |
310 | 310 | |
311 | - $current_status = get_post_status($row->post_id); |
|
312 | - if($current_status !== $post_status){ |
|
313 | - continue; |
|
314 | - } |
|
315 | - $searched_items[sanitize_title($row->name).'-'.$row->meta_value] = $this->format_row($row); |
|
311 | + $current_status = get_post_status($row->post_id); |
|
312 | + if($current_status !== $post_status){ |
|
313 | + continue; |
|
314 | + } |
|
315 | + $searched_items[sanitize_title($row->name).'-'.$row->meta_value] = $this->format_row($row); |
|
316 | 316 | |
317 | 317 | |
318 | 318 | }else{ |
@@ -349,13 +349,13 @@ discard block |
||
349 | 349 | public function multineedle_stripos($haystack, $needles, $offset=0) { |
350 | 350 | $found = false; |
351 | 351 | $needle_count = count($needles); |
352 | - foreach($needles as $needle) { |
|
353 | - if(false !== stripos($haystack, $needle, $offset)){ |
|
354 | - $found[] = true; |
|
355 | - } |
|
356 | - } |
|
357 | - if(false !== $found && $needle_count === count($found)){ |
|
358 | - return true; |
|
352 | + foreach($needles as $needle) { |
|
353 | + if(false !== stripos($haystack, $needle, $offset)){ |
|
354 | + $found[] = true; |
|
355 | + } |
|
356 | + } |
|
357 | + if(false !== $found && $needle_count === count($found)){ |
|
358 | + return true; |
|
359 | 359 | }else{ |
360 | 360 | return false; |
361 | 361 | } |
@@ -412,7 +412,7 @@ discard block |
||
412 | 412 | $team_members = false; |
413 | 413 | } |
414 | 414 | |
415 | - $safari_brands = false; |
|
415 | + $safari_brands = false; |
|
416 | 416 | |
417 | 417 | if(isset($_POST['content']) && is_array($_POST['content']) && !empty($_POST['content'])){ |
418 | 418 | $content = $_POST['content']; |
@@ -420,16 +420,16 @@ discard block |
||
420 | 420 | $content = false; |
421 | 421 | } |
422 | 422 | |
423 | - $jdata=file_get_contents($this->url."/Get?ids=".$wetu_id); |
|
424 | - if($jdata) |
|
425 | - { |
|
426 | - $adata=json_decode($jdata,true); |
|
427 | - if(!empty($adata)) |
|
428 | - { |
|
429 | - $return = $this->import_row($adata,$wetu_id,$post_id,$team_members,$content,$safari_brands); |
|
430 | - $this->format_completed_row($return); |
|
431 | - } |
|
432 | - } |
|
423 | + $jdata=file_get_contents($this->url."/Get?ids=".$wetu_id); |
|
424 | + if($jdata) |
|
425 | + { |
|
426 | + $adata=json_decode($jdata,true); |
|
427 | + if(!empty($adata)) |
|
428 | + { |
|
429 | + $return = $this->import_row($adata,$wetu_id,$post_id,$team_members,$content,$safari_brands); |
|
430 | + $this->format_completed_row($return); |
|
431 | + } |
|
432 | + } |
|
433 | 433 | |
434 | 434 | die(); |
435 | 435 | } |
@@ -441,82 +441,82 @@ discard block |
||
441 | 441 | */ |
442 | 442 | public function import_row($data,$wetu_id,$id=0,$team_members=false,$importable_content=false,$safari_brands=false) { |
443 | 443 | |
444 | - if(trim($data[0]['type'])=='Destination') |
|
445 | - { |
|
446 | - $post_name = $data_post_content = $data_post_excerpt = ''; |
|
447 | - $post = array( |
|
448 | - 'post_type' => 'destination', |
|
449 | - ); |
|
450 | - |
|
451 | - $content_used_general_description = false; |
|
452 | - |
|
453 | - //Set the post_content |
|
454 | - if(false !== $importable_content && in_array('description',$importable_content)){ |
|
455 | - if(isset($data[0]['content']['extended_description'])) |
|
456 | - { |
|
457 | - $data_post_content = $data[0]['content']['extended_description']; |
|
458 | - }elseif(isset($data[0]['content']['general_description'])){ |
|
459 | - $data_post_content = $data[0]['content']['general_description']; |
|
460 | - $content_used_general_description = true; |
|
461 | - }elseif(isset($data[0]['content']['teaser_description'])){ |
|
462 | - $data_post_content = $data[0]['content']['teaser_description']; |
|
463 | - } |
|
464 | - $post['post_content'] = wp_strip_all_tags($data_post_content); |
|
465 | - } |
|
466 | - |
|
467 | - //set the post_excerpt |
|
468 | - if(false !== $importable_content && in_array('excerpt',$importable_content)){ |
|
469 | - if(isset($data[0]['content']['teaser_description'])){ |
|
470 | - $data_post_excerpt = $data[0]['content']['teaser_description']; |
|
471 | - }elseif(isset($data[0]['content']['extended_description'])){ |
|
444 | + if(trim($data[0]['type'])=='Destination') |
|
445 | + { |
|
446 | + $post_name = $data_post_content = $data_post_excerpt = ''; |
|
447 | + $post = array( |
|
448 | + 'post_type' => 'destination', |
|
449 | + ); |
|
450 | + |
|
451 | + $content_used_general_description = false; |
|
452 | + |
|
453 | + //Set the post_content |
|
454 | + if(false !== $importable_content && in_array('description',$importable_content)){ |
|
455 | + if(isset($data[0]['content']['extended_description'])) |
|
456 | + { |
|
457 | + $data_post_content = $data[0]['content']['extended_description']; |
|
458 | + }elseif(isset($data[0]['content']['general_description'])){ |
|
459 | + $data_post_content = $data[0]['content']['general_description']; |
|
460 | + $content_used_general_description = true; |
|
461 | + }elseif(isset($data[0]['content']['teaser_description'])){ |
|
462 | + $data_post_content = $data[0]['content']['teaser_description']; |
|
463 | + } |
|
464 | + $post['post_content'] = wp_strip_all_tags($data_post_content); |
|
465 | + } |
|
466 | + |
|
467 | + //set the post_excerpt |
|
468 | + if(false !== $importable_content && in_array('excerpt',$importable_content)){ |
|
469 | + if(isset($data[0]['content']['teaser_description'])){ |
|
470 | + $data_post_excerpt = $data[0]['content']['teaser_description']; |
|
471 | + }elseif(isset($data[0]['content']['extended_description'])){ |
|
472 | 472 | $data_post_excerpt = $data[0]['content']['extended_description']; |
473 | 473 | }elseif(isset($data[0]['content']['general_description']) && false === $content_used_general_description){ |
474 | - $data_post_excerpt = $data[0]['content']['general_description']; |
|
475 | - } |
|
476 | - $post['post_excerpt'] = $data_post_excerpt; |
|
477 | - } |
|
474 | + $data_post_excerpt = $data[0]['content']['general_description']; |
|
475 | + } |
|
476 | + $post['post_excerpt'] = $data_post_excerpt; |
|
477 | + } |
|
478 | 478 | |
479 | - if(false !== $id && '0' !== $id){ |
|
480 | - $post['ID'] = $id; |
|
479 | + if(false !== $id && '0' !== $id){ |
|
480 | + $post['ID'] = $id; |
|
481 | 481 | if(isset($data[0]['name'])){ |
482 | 482 | $post['post_title'] = $data[0]['name']; |
483 | 483 | $post['post_status'] = 'pending'; |
484 | 484 | $post['post_name'] = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'destination', 0); |
485 | 485 | } |
486 | - $id = wp_update_post($post); |
|
487 | - $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
488 | - update_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified']),$prev_date); |
|
489 | - }else{ |
|
490 | - |
|
491 | - //Set the name |
|
492 | - if(isset($data[0]['name'])){ |
|
493 | - $post_name = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'destination', 0); |
|
494 | - } |
|
495 | - $post['post_name'] = $post_name; |
|
496 | - $post['post_title'] = $data[0]['name']; |
|
497 | - $post['post_status'] = 'pending'; |
|
498 | - $id = wp_insert_post($post); |
|
499 | - |
|
500 | - //Save the WETU ID and the Last date it was modified. |
|
501 | - if(false !== $id){ |
|
502 | - add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
503 | - add_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified'])); |
|
504 | - } |
|
505 | - } |
|
506 | - |
|
507 | - //Set the team member if it is there |
|
508 | - if(post_type_exists('team') && false !== $team_members && '' !== $team_members){ |
|
509 | - $this->set_team_member($id,$team_members); |
|
510 | - } |
|
511 | - |
|
512 | - if(false !== $importable_content && in_array('location',$importable_content)){ |
|
513 | - $this->set_map_data($data,$id); |
|
514 | - } |
|
515 | - |
|
516 | - //Set the Room Data |
|
517 | - if(false !== $importable_content && in_array('videos',$importable_content)){ |
|
518 | - $this->set_video_data($data,$id); |
|
519 | - } |
|
486 | + $id = wp_update_post($post); |
|
487 | + $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
488 | + update_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified']),$prev_date); |
|
489 | + }else{ |
|
490 | + |
|
491 | + //Set the name |
|
492 | + if(isset($data[0]['name'])){ |
|
493 | + $post_name = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'destination', 0); |
|
494 | + } |
|
495 | + $post['post_name'] = $post_name; |
|
496 | + $post['post_title'] = $data[0]['name']; |
|
497 | + $post['post_status'] = 'pending'; |
|
498 | + $id = wp_insert_post($post); |
|
499 | + |
|
500 | + //Save the WETU ID and the Last date it was modified. |
|
501 | + if(false !== $id){ |
|
502 | + add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
503 | + add_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified'])); |
|
504 | + } |
|
505 | + } |
|
506 | + |
|
507 | + //Set the team member if it is there |
|
508 | + if(post_type_exists('team') && false !== $team_members && '' !== $team_members){ |
|
509 | + $this->set_team_member($id,$team_members); |
|
510 | + } |
|
511 | + |
|
512 | + if(false !== $importable_content && in_array('location',$importable_content)){ |
|
513 | + $this->set_map_data($data,$id); |
|
514 | + } |
|
515 | + |
|
516 | + //Set the Room Data |
|
517 | + if(false !== $importable_content && in_array('videos',$importable_content)){ |
|
518 | + $this->set_video_data($data,$id); |
|
519 | + } |
|
520 | 520 | |
521 | 521 | //Set the Electricity |
522 | 522 | if(false !== $importable_content && in_array('electricity',$importable_content)){ |
@@ -543,8 +543,8 @@ discard block |
||
543 | 543 | $this->set_travel_info($data,$id,'climate'); |
544 | 544 | } |
545 | 545 | |
546 | - } |
|
547 | - return $id; |
|
546 | + } |
|
547 | + return $id; |
|
548 | 548 | } |
549 | 549 | |
550 | 550 | /** |
@@ -554,7 +554,7 @@ discard block |
||
554 | 554 | |
555 | 555 | delete_post_meta($id, 'team_to_'.$this->tab_slug); |
556 | 556 | foreach($team_members as $team){ |
557 | - add_post_meta($id,'team_to_'.$this->tab_slug,$team); |
|
557 | + add_post_meta($id,'team_to_'.$this->tab_slug,$team); |
|
558 | 558 | } |
559 | 559 | } |
560 | 560 | |
@@ -606,11 +606,11 @@ discard block |
||
606 | 606 | 'elevation' => '', |
607 | 607 | ); |
608 | 608 | if(false !== $id && '0' !== $id){ |
609 | - $prev = get_post_meta($id,'location',true); |
|
610 | - update_post_meta($id,'location',$location_data,$prev); |
|
611 | - }else{ |
|
612 | - add_post_meta($id,'location',$location_data,true); |
|
613 | - } |
|
609 | + $prev = get_post_meta($id,'location',true); |
|
610 | + update_post_meta($id,'location',$location_data,$prev); |
|
611 | + }else{ |
|
612 | + add_post_meta($id,'location',$location_data,true); |
|
613 | + } |
|
614 | 614 | } |
615 | 615 | } |
616 | 616 |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * Display the importer administration screen |
79 | 79 | */ |
80 | 80 | public function display_page() { |
81 | - ?> |
|
81 | + ?> |
|
82 | 82 | <div class="wrap"> |
83 | 83 | <?php screen_icon(); ?> |
84 | 84 | |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | </ul> |
101 | 101 | |
102 | 102 | <?php } else { |
103 | - do_action('lsx_tour_importer_admin_tab_'.$_GET['tab']); |
|
104 | - } ?> |
|
103 | + do_action('lsx_tour_importer_admin_tab_'.$_GET['tab']); |
|
104 | + } ?> |
|
105 | 105 | </div> |
106 | 106 | <?php |
107 | 107 | } |
@@ -148,37 +148,37 @@ discard block |
||
148 | 148 | * set_taxonomy with some terms |
149 | 149 | */ |
150 | 150 | public function set_taxonomy($taxonomy,$terms,$id) { |
151 | - $result=array(); |
|
152 | - if(!empty($data)) |
|
153 | - { |
|
154 | - foreach($data as $k) |
|
155 | - { |
|
156 | - if($id) |
|
157 | - { |
|
158 | - if(!$term = term_exists(trim($k), $tax)) |
|
159 | - { |
|
160 | - $term = wp_insert_term(trim($k), $tax); |
|
161 | - if ( is_wp_error($term) ) |
|
162 | - { |
|
163 | - echo $term->get_error_message(); |
|
164 | - } |
|
165 | - else |
|
166 | - { |
|
167 | - wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); |
|
168 | - } |
|
169 | - } |
|
170 | - else |
|
171 | - { |
|
172 | - wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); |
|
173 | - } |
|
174 | - } |
|
175 | - else |
|
176 | - { |
|
177 | - $result[]=trim($k); |
|
178 | - } |
|
179 | - } |
|
180 | - } |
|
181 | - return $result; |
|
151 | + $result=array(); |
|
152 | + if(!empty($data)) |
|
153 | + { |
|
154 | + foreach($data as $k) |
|
155 | + { |
|
156 | + if($id) |
|
157 | + { |
|
158 | + if(!$term = term_exists(trim($k), $tax)) |
|
159 | + { |
|
160 | + $term = wp_insert_term(trim($k), $tax); |
|
161 | + if ( is_wp_error($term) ) |
|
162 | + { |
|
163 | + echo $term->get_error_message(); |
|
164 | + } |
|
165 | + else |
|
166 | + { |
|
167 | + wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); |
|
168 | + } |
|
169 | + } |
|
170 | + else |
|
171 | + { |
|
172 | + wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); |
|
173 | + } |
|
174 | + } |
|
175 | + else |
|
176 | + { |
|
177 | + $result[]=trim($k); |
|
178 | + } |
|
179 | + } |
|
180 | + } |
|
181 | + return $result; |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
@@ -188,21 +188,21 @@ discard block |
||
188 | 188 | if(post_type_exists('team')) { ?> |
189 | 189 | <ul> |
190 | 190 | <?php |
191 | - $team_args=array( |
|
192 | - 'post_type' => 'team', |
|
193 | - 'post_status' => 'publish', |
|
194 | - 'nopagin' => true, |
|
195 | - 'fields' => 'ids' |
|
196 | - ); |
|
197 | - $team_members = new WP_Query($team_args); |
|
198 | - if($team_members->have_posts()){ |
|
199 | - foreach($team_members->posts as $member){ ?> |
|
191 | + $team_args=array( |
|
192 | + 'post_type' => 'team', |
|
193 | + 'post_status' => 'publish', |
|
194 | + 'nopagin' => true, |
|
195 | + 'fields' => 'ids' |
|
196 | + ); |
|
197 | + $team_members = new WP_Query($team_args); |
|
198 | + if($team_members->have_posts()){ |
|
199 | + foreach($team_members->posts as $member){ ?> |
|
200 | 200 | <li><input class="team" type="checkbox" value="<?php echo $member; ?>" /> <?php echo get_the_title($member); ?></li> |
201 | 201 | <?php } |
202 | - }else{ ?> |
|
202 | + }else{ ?> |
|
203 | 203 | <li><input class="team" type="checkbox" value="0" /> <?php _e('None','wetu-importer'); ?></li> |
204 | 204 | <?php } |
205 | - ?> |
|
205 | + ?> |
|
206 | 206 | </ul> |
207 | 207 | <?php } |
208 | 208 | } |
@@ -253,20 +253,20 @@ discard block |
||
253 | 253 | if(false !== $id){ |
254 | 254 | if(empty($this->found_attachments)){ |
255 | 255 | |
256 | - $attachments_args = array( |
|
257 | - 'post_parent' => $id, |
|
258 | - 'post_status' => 'inherit', |
|
259 | - 'post_type' => 'attachment', |
|
260 | - 'order' => 'ASC', |
|
261 | - ); |
|
256 | + $attachments_args = array( |
|
257 | + 'post_parent' => $id, |
|
258 | + 'post_status' => 'inherit', |
|
259 | + 'post_type' => 'attachment', |
|
260 | + 'order' => 'ASC', |
|
261 | + ); |
|
262 | 262 | |
263 | - $attachments = new WP_Query($attachments_args); |
|
264 | - if($attachments->have_posts()){ |
|
265 | - foreach($attachments->posts as $attachment){ |
|
266 | - $this->found_attachments[$attachment->ID] = str_replace(array('.jpg','.png','.jpeg'),'',$attachment->post_title); |
|
267 | - $this->gallery_meta[] = $attachment->ID; |
|
268 | - } |
|
269 | - } |
|
263 | + $attachments = new WP_Query($attachments_args); |
|
264 | + if($attachments->have_posts()){ |
|
265 | + foreach($attachments->posts as $attachment){ |
|
266 | + $this->found_attachments[$attachment->ID] = str_replace(array('.jpg','.png','.jpeg'),'',$attachment->post_title); |
|
267 | + $this->gallery_meta[] = $attachment->ID; |
|
268 | + } |
|
269 | + } |
|
270 | 270 | } |
271 | 271 | } |
272 | 272 | } |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | parent::set_variables(); |
63 | 63 | |
64 | 64 | if(false !== $this->api_key){ |
65 | - $this->url = 'https://wetu.com/API/Pins/'.$this->api_key; |
|
66 | - } |
|
65 | + $this->url = 'https://wetu.com/API/Pins/'.$this->api_key; |
|
66 | + } |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * Display the importer administration screen |
104 | 104 | */ |
105 | 105 | public function display_page() { |
106 | - ?> |
|
106 | + ?> |
|
107 | 107 | <div class="wrap"> |
108 | 108 | <?php screen_icon(); ?> |
109 | 109 | |
@@ -418,13 +418,13 @@ discard block |
||
418 | 418 | public function multineedle_stripos($haystack, $needles, $offset=0) { |
419 | 419 | $found = false; |
420 | 420 | $needle_count = count($needles); |
421 | - foreach($needles as $needle) { |
|
422 | - if(false !== stripos($haystack, $needle, $offset)){ |
|
423 | - $found[] = true; |
|
424 | - } |
|
425 | - } |
|
426 | - if(false !== $found && $needle_count === count($found)){ |
|
427 | - return true; |
|
421 | + foreach($needles as $needle) { |
|
422 | + if(false !== stripos($haystack, $needle, $offset)){ |
|
423 | + $found[] = true; |
|
424 | + } |
|
425 | + } |
|
426 | + if(false !== $found && $needle_count === count($found)){ |
|
427 | + return true; |
|
428 | 428 | }else{ |
429 | 429 | return false; |
430 | 430 | } |
@@ -493,16 +493,16 @@ discard block |
||
493 | 493 | $content = false; |
494 | 494 | } |
495 | 495 | |
496 | - $jdata=file_get_contents($this->url."/Get?ids=".$wetu_id); |
|
497 | - if($jdata) |
|
498 | - { |
|
499 | - $adata=json_decode($jdata,true); |
|
500 | - if(!empty($adata)) |
|
501 | - { |
|
502 | - $return = $this->import_row($adata,$wetu_id,$post_id,$team_members,$content,$safari_brands); |
|
503 | - $this->format_completed_row($return); |
|
504 | - } |
|
505 | - } |
|
496 | + $jdata=file_get_contents($this->url."/Get?ids=".$wetu_id); |
|
497 | + if($jdata) |
|
498 | + { |
|
499 | + $adata=json_decode($jdata,true); |
|
500 | + if(!empty($adata)) |
|
501 | + { |
|
502 | + $return = $this->import_row($adata,$wetu_id,$post_id,$team_members,$content,$safari_brands); |
|
503 | + $this->format_completed_row($return); |
|
504 | + } |
|
505 | + } |
|
506 | 506 | |
507 | 507 | die(); |
508 | 508 | } |
@@ -519,147 +519,147 @@ discard block |
||
519 | 519 | */ |
520 | 520 | public function import_row($data,$wetu_id,$id=0,$team_members=false,$importable_content=false,$safari_brands=false) { |
521 | 521 | |
522 | - if(trim($data[0]['type'])=='Accommodation') |
|
523 | - { |
|
524 | - $post_name = $data_post_content = $data_post_excerpt = ''; |
|
525 | - $post = array( |
|
526 | - 'post_type' => 'accommodation', |
|
527 | - ); |
|
528 | - |
|
529 | - $content_used_general_description = false; |
|
530 | - |
|
531 | - //Set the post_content |
|
532 | - if(false !== $importable_content && in_array('description',$importable_content)){ |
|
533 | - if(isset($data[0]['content']['extended_description'])) |
|
534 | - { |
|
535 | - $data_post_content = $data[0]['content']['extended_description']; |
|
536 | - }elseif(isset($data[0]['content']['general_description'])){ |
|
537 | - $data_post_content = $data[0]['content']['general_description']; |
|
538 | - $content_used_general_description = true; |
|
539 | - }elseif(isset($data[0]['content']['teaser_description'])){ |
|
540 | - $data_post_content = $data[0]['content']['teaser_description']; |
|
541 | - } |
|
542 | - $post['post_content'] = wp_strip_all_tags($data_post_content); |
|
543 | - } |
|
544 | - |
|
545 | - //set the post_excerpt |
|
546 | - if(false !== $importable_content && in_array('excerpt',$importable_content)){ |
|
547 | - if(isset($data[0]['content']['teaser_description'])){ |
|
548 | - $data_post_excerpt = $data[0]['content']['teaser_description']; |
|
549 | - }elseif(isset($data[0]['content']['general_description']) && false === $content_used_general_description){ |
|
550 | - $data_post_excerpt = $data[0]['content']['general_description']; |
|
551 | - } |
|
552 | - $post['post_excerpt'] = $data_post_excerpt; |
|
553 | - } |
|
554 | - |
|
555 | - if(false !== $id && '0' !== $id){ |
|
556 | - $post['ID'] = $id; |
|
522 | + if(trim($data[0]['type'])=='Accommodation') |
|
523 | + { |
|
524 | + $post_name = $data_post_content = $data_post_excerpt = ''; |
|
525 | + $post = array( |
|
526 | + 'post_type' => 'accommodation', |
|
527 | + ); |
|
528 | + |
|
529 | + $content_used_general_description = false; |
|
530 | + |
|
531 | + //Set the post_content |
|
532 | + if(false !== $importable_content && in_array('description',$importable_content)){ |
|
533 | + if(isset($data[0]['content']['extended_description'])) |
|
534 | + { |
|
535 | + $data_post_content = $data[0]['content']['extended_description']; |
|
536 | + }elseif(isset($data[0]['content']['general_description'])){ |
|
537 | + $data_post_content = $data[0]['content']['general_description']; |
|
538 | + $content_used_general_description = true; |
|
539 | + }elseif(isset($data[0]['content']['teaser_description'])){ |
|
540 | + $data_post_content = $data[0]['content']['teaser_description']; |
|
541 | + } |
|
542 | + $post['post_content'] = wp_strip_all_tags($data_post_content); |
|
543 | + } |
|
544 | + |
|
545 | + //set the post_excerpt |
|
546 | + if(false !== $importable_content && in_array('excerpt',$importable_content)){ |
|
547 | + if(isset($data[0]['content']['teaser_description'])){ |
|
548 | + $data_post_excerpt = $data[0]['content']['teaser_description']; |
|
549 | + }elseif(isset($data[0]['content']['general_description']) && false === $content_used_general_description){ |
|
550 | + $data_post_excerpt = $data[0]['content']['general_description']; |
|
551 | + } |
|
552 | + $post['post_excerpt'] = $data_post_excerpt; |
|
553 | + } |
|
554 | + |
|
555 | + if(false !== $id && '0' !== $id){ |
|
556 | + $post['ID'] = $id; |
|
557 | 557 | if(isset($data[0]['name'])){ |
558 | 558 | $post['post_title'] = $data[0]['name']; |
559 | 559 | $post['post_name'] = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'accommodation', 0); |
560 | 560 | } |
561 | - $id = wp_update_post($post); |
|
562 | - $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
563 | - update_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified']),$prev_date); |
|
564 | - }else{ |
|
565 | - |
|
566 | - //Set the name |
|
567 | - if(isset($data[0]['name'])){ |
|
568 | - $post_name = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'accommodation', 0); |
|
569 | - } |
|
570 | - $post['post_name'] = $post_name; |
|
571 | - $post['post_title'] = $data[0]['name']; |
|
572 | - $post['post_status'] = 'pending'; |
|
573 | - $id = wp_insert_post($post); |
|
574 | - |
|
575 | - //Save the WETU ID and the Last date it was modified. |
|
576 | - if(false !== $id){ |
|
577 | - add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
578 | - add_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified'])); |
|
579 | - } |
|
580 | - } |
|
581 | - //Setup some default for use in the import |
|
582 | - if(false !== $importable_content && (in_array('gallery',$importable_content) || in_array('banner_image',$importable_content) || in_array('featured_image',$importable_content))){ |
|
561 | + $id = wp_update_post($post); |
|
562 | + $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
563 | + update_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified']),$prev_date); |
|
564 | + }else{ |
|
565 | + |
|
566 | + //Set the name |
|
567 | + if(isset($data[0]['name'])){ |
|
568 | + $post_name = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'accommodation', 0); |
|
569 | + } |
|
570 | + $post['post_name'] = $post_name; |
|
571 | + $post['post_title'] = $data[0]['name']; |
|
572 | + $post['post_status'] = 'pending'; |
|
573 | + $id = wp_insert_post($post); |
|
574 | + |
|
575 | + //Save the WETU ID and the Last date it was modified. |
|
576 | + if(false !== $id){ |
|
577 | + add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
578 | + add_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified'])); |
|
579 | + } |
|
580 | + } |
|
581 | + //Setup some default for use in the import |
|
582 | + if(false !== $importable_content && (in_array('gallery',$importable_content) || in_array('banner_image',$importable_content) || in_array('featured_image',$importable_content))){ |
|
583 | 583 | $this->find_attachments($id); |
584 | 584 | } |
585 | 585 | |
586 | - //Set the team member if it is there |
|
587 | - if(post_type_exists('team') && false !== $team_members && '' !== $team_members){ |
|
588 | - $this->set_team_member($id,$team_members); |
|
589 | - } |
|
590 | - |
|
591 | - //Set the safari brand |
|
592 | - if(false !== $safari_brands && '' !== $safari_brands){ |
|
593 | - $this->set_safari_brands($id,$safari_brands); |
|
594 | - |
|
595 | - } |
|
596 | - |
|
597 | - if(false !== $importable_content && in_array('location',$importable_content)){ |
|
598 | - $this->set_map_data($data,$id); |
|
599 | - $this->set_location_taxonomy($data,$id); |
|
600 | - } |
|
601 | - |
|
602 | - if(post_type_exists('destination') && false !== $importable_content && in_array('destination',$importable_content)){ |
|
603 | - $this->connect_destinations($data,$id); |
|
604 | - } |
|
605 | - |
|
606 | - if(false !== $importable_content && in_array('category',$importable_content)){ |
|
607 | - $this->set_taxonomy_style($data,$id); |
|
608 | - } |
|
609 | - |
|
610 | - //Set the Room Data |
|
611 | - if(false !== $importable_content && in_array('rooms',$importable_content)){ |
|
612 | - $this->set_room_data($data,$id); |
|
613 | - } |
|
614 | - |
|
615 | - //Set the rating |
|
616 | - if(false !== $importable_content && in_array('rating',$importable_content)){ |
|
617 | - $this->set_rating($data,$id); |
|
618 | - } |
|
619 | - |
|
620 | - //Set the checkin checkout data |
|
621 | - if(false !== $importable_content && in_array('checkin',$importable_content)){ |
|
622 | - $this->set_checkin_checkout($data,$id); |
|
623 | - } |
|
624 | - |
|
625 | - //Set the Spoken Languages |
|
626 | - if(false !== $importable_content && in_array('spoken_languages',$importable_content)){ |
|
627 | - $this->set_spoken_languages($data,$id); |
|
628 | - } |
|
629 | - |
|
630 | - //Set the friendly options |
|
631 | - if(false !== $importable_content && in_array('friendly',$importable_content)){ |
|
632 | - $this->set_friendly($data,$id); |
|
633 | - } |
|
634 | - |
|
635 | - //Set the special_interests |
|
636 | - if(false !== $importable_content && in_array('special_interests',$importable_content)){ |
|
637 | - $this->set_special_interests($data,$id); |
|
638 | - } |
|
639 | - |
|
640 | - //Import the videos |
|
641 | - if(false !== $importable_content && in_array('videos',$importable_content)){ |
|
642 | - $this->set_video_data($data,$id); |
|
643 | - } |
|
644 | - |
|
645 | - //Import the facilities |
|
646 | - if(false !== $importable_content && in_array('facilities',$importable_content)){ |
|
647 | - $this->set_facilities($data,$id); |
|
648 | - } |
|
649 | - |
|
650 | - //Set the featured image |
|
651 | - if(false !== $importable_content && in_array('featured_image',$importable_content)){ |
|
652 | - $this->set_featured_image($data,$id); |
|
653 | - } |
|
654 | - if(false !== $importable_content && in_array('banner_image',$importable_content)){ |
|
655 | - $this->set_banner_image($data,$id); |
|
656 | - } |
|
657 | - //Import the main gallery |
|
658 | - if(false !== $importable_content && in_array('gallery',$importable_content)){ |
|
659 | - $this->create_main_gallery($data,$id); |
|
660 | - } |
|
661 | - } |
|
662 | - return $id; |
|
586 | + //Set the team member if it is there |
|
587 | + if(post_type_exists('team') && false !== $team_members && '' !== $team_members){ |
|
588 | + $this->set_team_member($id,$team_members); |
|
589 | + } |
|
590 | + |
|
591 | + //Set the safari brand |
|
592 | + if(false !== $safari_brands && '' !== $safari_brands){ |
|
593 | + $this->set_safari_brands($id,$safari_brands); |
|
594 | + |
|
595 | + } |
|
596 | + |
|
597 | + if(false !== $importable_content && in_array('location',$importable_content)){ |
|
598 | + $this->set_map_data($data,$id); |
|
599 | + $this->set_location_taxonomy($data,$id); |
|
600 | + } |
|
601 | + |
|
602 | + if(post_type_exists('destination') && false !== $importable_content && in_array('destination',$importable_content)){ |
|
603 | + $this->connect_destinations($data,$id); |
|
604 | + } |
|
605 | + |
|
606 | + if(false !== $importable_content && in_array('category',$importable_content)){ |
|
607 | + $this->set_taxonomy_style($data,$id); |
|
608 | + } |
|
609 | + |
|
610 | + //Set the Room Data |
|
611 | + if(false !== $importable_content && in_array('rooms',$importable_content)){ |
|
612 | + $this->set_room_data($data,$id); |
|
613 | + } |
|
614 | + |
|
615 | + //Set the rating |
|
616 | + if(false !== $importable_content && in_array('rating',$importable_content)){ |
|
617 | + $this->set_rating($data,$id); |
|
618 | + } |
|
619 | + |
|
620 | + //Set the checkin checkout data |
|
621 | + if(false !== $importable_content && in_array('checkin',$importable_content)){ |
|
622 | + $this->set_checkin_checkout($data,$id); |
|
623 | + } |
|
624 | + |
|
625 | + //Set the Spoken Languages |
|
626 | + if(false !== $importable_content && in_array('spoken_languages',$importable_content)){ |
|
627 | + $this->set_spoken_languages($data,$id); |
|
628 | + } |
|
629 | + |
|
630 | + //Set the friendly options |
|
631 | + if(false !== $importable_content && in_array('friendly',$importable_content)){ |
|
632 | + $this->set_friendly($data,$id); |
|
633 | + } |
|
634 | + |
|
635 | + //Set the special_interests |
|
636 | + if(false !== $importable_content && in_array('special_interests',$importable_content)){ |
|
637 | + $this->set_special_interests($data,$id); |
|
638 | + } |
|
639 | + |
|
640 | + //Import the videos |
|
641 | + if(false !== $importable_content && in_array('videos',$importable_content)){ |
|
642 | + $this->set_video_data($data,$id); |
|
643 | + } |
|
644 | + |
|
645 | + //Import the facilities |
|
646 | + if(false !== $importable_content && in_array('facilities',$importable_content)){ |
|
647 | + $this->set_facilities($data,$id); |
|
648 | + } |
|
649 | + |
|
650 | + //Set the featured image |
|
651 | + if(false !== $importable_content && in_array('featured_image',$importable_content)){ |
|
652 | + $this->set_featured_image($data,$id); |
|
653 | + } |
|
654 | + if(false !== $importable_content && in_array('banner_image',$importable_content)){ |
|
655 | + $this->set_banner_image($data,$id); |
|
656 | + } |
|
657 | + //Import the main gallery |
|
658 | + if(false !== $importable_content && in_array('gallery',$importable_content)){ |
|
659 | + $this->create_main_gallery($data,$id); |
|
660 | + } |
|
661 | + } |
|
662 | + return $id; |
|
663 | 663 | } |
664 | 664 | |
665 | 665 | /** |
@@ -669,7 +669,7 @@ discard block |
||
669 | 669 | |
670 | 670 | delete_post_meta($id, 'team_to_'.$this->tab_slug); |
671 | 671 | foreach($team_members as $team){ |
672 | - add_post_meta($id,'team_to_'.$this->tab_slug,$team); |
|
672 | + add_post_meta($id,'team_to_'.$this->tab_slug,$team); |
|
673 | 673 | } |
674 | 674 | } |
675 | 675 | |
@@ -678,7 +678,7 @@ discard block |
||
678 | 678 | */ |
679 | 679 | public function set_safari_brands($id,$safari_brands) { |
680 | 680 | foreach($safari_brands as $safari_brand){ |
681 | - wp_set_object_terms( $id, intval($safari_brand), 'accommodation-brand',true); |
|
681 | + wp_set_object_terms( $id, intval($safari_brand), 'accommodation-brand',true); |
|
682 | 682 | } |
683 | 683 | } |
684 | 684 | |
@@ -730,11 +730,11 @@ discard block |
||
730 | 730 | 'elevation' => '', |
731 | 731 | ); |
732 | 732 | if(false !== $id && '0' !== $id){ |
733 | - $prev = get_post_meta($id,'location',true); |
|
734 | - update_post_meta($id,'location',$location_data,$prev); |
|
735 | - }else{ |
|
736 | - add_post_meta($id,'location',$location_data,true); |
|
737 | - } |
|
733 | + $prev = get_post_meta($id,'location',true); |
|
734 | + update_post_meta($id,'location',$location_data,$prev); |
|
735 | + }else{ |
|
736 | + add_post_meta($id,'location',$location_data,true); |
|
737 | + } |
|
738 | 738 | } |
739 | 739 | } |
740 | 740 | /** |
@@ -748,35 +748,35 @@ discard block |
||
748 | 748 | if(isset($data[0]['position']['country'])){ |
749 | 749 | |
750 | 750 | if(!$term = term_exists(trim($data[0]['position']['country']), 'location')) |
751 | - { |
|
752 | - $term = wp_insert_term(trim($data[0]['position']['country']), 'location'); |
|
753 | - if ( is_wp_error($term) ){ |
|
754 | - echo $term->get_error_message(); |
|
755 | - } |
|
756 | - else { |
|
757 | - wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
758 | - } |
|
759 | - } |
|
760 | - else |
|
761 | - { |
|
762 | - wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
763 | - } |
|
764 | - $country_id = intval($term['term_id']); |
|
765 | - } |
|
751 | + { |
|
752 | + $term = wp_insert_term(trim($data[0]['position']['country']), 'location'); |
|
753 | + if ( is_wp_error($term) ){ |
|
754 | + echo $term->get_error_message(); |
|
755 | + } |
|
756 | + else { |
|
757 | + wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
758 | + } |
|
759 | + } |
|
760 | + else |
|
761 | + { |
|
762 | + wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
763 | + } |
|
764 | + $country_id = intval($term['term_id']); |
|
765 | + } |
|
766 | 766 | |
767 | 767 | if(isset($data[0]['position']['destination'])){ |
768 | 768 | |
769 | 769 | $tax_args = array('parent'=>$country_id); |
770 | 770 | if(!$term = term_exists(trim($data[0]['position']['destination']), 'location')) |
771 | - { |
|
772 | - $term = wp_insert_term(trim($data[0]['position']['destination']), 'location', $tax_args); |
|
773 | - if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
774 | - else { wp_set_object_terms( $id, intval($term['term_id']), 'location',true); } |
|
775 | - } |
|
776 | - else |
|
777 | - { |
|
778 | - wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
779 | - } |
|
771 | + { |
|
772 | + $term = wp_insert_term(trim($data[0]['position']['destination']), 'location', $tax_args); |
|
773 | + if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
774 | + else { wp_set_object_terms( $id, intval($term['term_id']), 'location',true); } |
|
775 | + } |
|
776 | + else |
|
777 | + { |
|
778 | + wp_set_object_terms( $id, intval($term['term_id']), 'location',true); |
|
779 | + } |
|
780 | 780 | } |
781 | 781 | } |
782 | 782 | } |
@@ -786,28 +786,28 @@ discard block |
||
786 | 786 | */ |
787 | 787 | public function connect_destinations($data,$id) { |
788 | 788 | if(isset($data[0]['position'])){ |
789 | - $destinations = false; |
|
790 | - if(isset($data[0]['position']['country'])){ |
|
791 | - $destinations['country'] = $data[0]['position']['country']; |
|
792 | - } |
|
793 | - if(isset($data[0]['position']['destination'])){ |
|
794 | - $destinations['destination'] = $data[0]['position']['destination']; |
|
795 | - } |
|
789 | + $destinations = false; |
|
790 | + if(isset($data[0]['position']['country'])){ |
|
791 | + $destinations['country'] = $data[0]['position']['country']; |
|
792 | + } |
|
793 | + if(isset($data[0]['position']['destination'])){ |
|
794 | + $destinations['destination'] = $data[0]['position']['destination']; |
|
795 | + } |
|
796 | 796 | |
797 | - if(false !== $destinations){ |
|
798 | - $prev_values = get_post_meta($id,'destination_to_accommodation',false); |
|
799 | - if(false === $prev_values || !is_array($prev_values)){ |
|
800 | - $prev_values = array(); |
|
801 | - } |
|
802 | - foreach($destinations as $key => $value){ |
|
803 | - $destination = get_page_by_title(ltrim(rtrim($value)), 'OBJECT', 'destination'); |
|
804 | - if (null !== $destination) { |
|
805 | - if(!in_array($destination->ID,$prev_values)){ |
|
806 | - add_post_meta($id,'destination_to_accommodation',$destination->ID,false); |
|
807 | - add_post_meta($destination->ID,'accommodation_to_destination',$id,false); |
|
808 | - } |
|
809 | - } |
|
810 | - } |
|
797 | + if(false !== $destinations){ |
|
798 | + $prev_values = get_post_meta($id,'destination_to_accommodation',false); |
|
799 | + if(false === $prev_values || !is_array($prev_values)){ |
|
800 | + $prev_values = array(); |
|
801 | + } |
|
802 | + foreach($destinations as $key => $value){ |
|
803 | + $destination = get_page_by_title(ltrim(rtrim($value)), 'OBJECT', 'destination'); |
|
804 | + if (null !== $destination) { |
|
805 | + if(!in_array($destination->ID,$prev_values)){ |
|
806 | + add_post_meta($id,'destination_to_accommodation',$destination->ID,false); |
|
807 | + add_post_meta($destination->ID,'accommodation_to_destination',$id,false); |
|
808 | + } |
|
809 | + } |
|
810 | + } |
|
811 | 811 | } |
812 | 812 | } |
813 | 813 | } |
@@ -819,15 +819,15 @@ discard block |
||
819 | 819 | $terms = false; |
820 | 820 | if(isset($data[0]['category'])){ |
821 | 821 | if(!$term = term_exists(trim($data[0]['category']), 'accommodation-type')) |
822 | - { |
|
823 | - $term = wp_insert_term(trim($data[0]['category']), 'accommodation-type'); |
|
824 | - if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
825 | - else { wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); } |
|
826 | - } |
|
827 | - else |
|
828 | - { |
|
829 | - wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); |
|
830 | - } |
|
822 | + { |
|
823 | + $term = wp_insert_term(trim($data[0]['category']), 'accommodation-type'); |
|
824 | + if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
825 | + else { wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); } |
|
826 | + } |
|
827 | + else |
|
828 | + { |
|
829 | + wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); |
|
830 | + } |
|
831 | 831 | } |
832 | 832 | } |
833 | 833 | |
@@ -851,25 +851,25 @@ discard block |
||
851 | 851 | $temp_room['type'] = 'room'; |
852 | 852 | |
853 | 853 | if(!empty($room['images']) && is_array($room['images'])){ |
854 | - $attachments_args = array( |
|
855 | - 'post_parent' => $id, |
|
856 | - 'post_status' => 'inherit', |
|
857 | - 'post_type' => 'attachment', |
|
858 | - 'order' => 'ASC', |
|
859 | - ); |
|
860 | - $attachments = new WP_Query($attachments_args); |
|
861 | - $found_attachments = array(); |
|
862 | - |
|
863 | - if($attachments->have_posts()){ |
|
864 | - foreach($attachments->posts as $attachment){ |
|
865 | - $found_attachments[] = str_replace(array('.jpg','.png','.jpeg'),'',$attachment->post_title); |
|
866 | - } |
|
867 | - } |
|
854 | + $attachments_args = array( |
|
855 | + 'post_parent' => $id, |
|
856 | + 'post_status' => 'inherit', |
|
857 | + 'post_type' => 'attachment', |
|
858 | + 'order' => 'ASC', |
|
859 | + ); |
|
860 | + $attachments = new WP_Query($attachments_args); |
|
861 | + $found_attachments = array(); |
|
862 | + |
|
863 | + if($attachments->have_posts()){ |
|
864 | + foreach($attachments->posts as $attachment){ |
|
865 | + $found_attachments[] = str_replace(array('.jpg','.png','.jpeg'),'',$attachment->post_title); |
|
866 | + } |
|
867 | + } |
|
868 | 868 | |
869 | 869 | $temp_room['gallery'] = array(); |
870 | 870 | foreach($room['images'] as $image_data){ |
871 | - $temp_room['gallery'][] = $this->attach_image($image_data,$id,$found_attachments); |
|
872 | - } |
|
871 | + $temp_room['gallery'][] = $this->attach_image($image_data,$id,$found_attachments); |
|
872 | + } |
|
873 | 873 | } |
874 | 874 | $rooms[] = $temp_room; |
875 | 875 | } |
@@ -878,7 +878,7 @@ discard block |
||
878 | 878 | delete_post_meta($id, 'units'); |
879 | 879 | } |
880 | 880 | foreach($rooms as $room){ |
881 | - add_post_meta($id,'units',$room,false); |
|
881 | + add_post_meta($id,'units',$room,false); |
|
882 | 882 | } |
883 | 883 | |
884 | 884 | if(isset($data[0]['features']) && isset($data[0]['features']['rooms'])){ |
@@ -888,11 +888,11 @@ discard block |
||
888 | 888 | } |
889 | 889 | |
890 | 890 | if(false !== $id && '0' !== $id){ |
891 | - $prev_rooms = get_post_meta($id,'number_of_rooms',true); |
|
892 | - update_post_meta($id,'number_of_rooms',$room_count,$prev_rooms); |
|
893 | - }else{ |
|
894 | - add_post_meta($id,'number_of_rooms',$room_count,true); |
|
895 | - } |
|
891 | + $prev_rooms = get_post_meta($id,'number_of_rooms',true); |
|
892 | + update_post_meta($id,'number_of_rooms',$room_count,$prev_rooms); |
|
893 | + }else{ |
|
894 | + add_post_meta($id,'number_of_rooms',$room_count,true); |
|
895 | + } |
|
896 | 896 | } |
897 | 897 | } |
898 | 898 | |
@@ -1001,7 +1001,7 @@ discard block |
||
1001 | 1001 | delete_post_meta($id, 'videos'); |
1002 | 1002 | } |
1003 | 1003 | foreach($videos as $video){ |
1004 | - add_post_meta($id,'videos',$video,false); |
|
1004 | + add_post_meta($id,'videos',$video,false); |
|
1005 | 1005 | } |
1006 | 1006 | } |
1007 | 1007 | } |
@@ -1030,17 +1030,17 @@ discard block |
||
1030 | 1030 | |
1031 | 1031 | function set_term($id=false,$name=false,$taxonomy=false,$parent=false){ |
1032 | 1032 | if(!$term = term_exists($name, $taxonomy)) |
1033 | - { |
|
1034 | - if(false !== $parent){ $parent = array('parent'=>$parent); } |
|
1035 | - $term = wp_insert_term(trim($name), $taxonomy,$parent); |
|
1036 | - if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
1037 | - else { wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); } |
|
1038 | - } |
|
1039 | - else |
|
1040 | - { |
|
1041 | - wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); |
|
1042 | - } |
|
1043 | - return $term['term_id']; |
|
1033 | + { |
|
1034 | + if(false !== $parent){ $parent = array('parent'=>$parent); } |
|
1035 | + $term = wp_insert_term(trim($name), $taxonomy,$parent); |
|
1036 | + if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
1037 | + else { wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); } |
|
1038 | + } |
|
1039 | + else |
|
1040 | + { |
|
1041 | + wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); |
|
1042 | + } |
|
1043 | + return $term['term_id']; |
|
1044 | 1044 | } |
1045 | 1045 | |
1046 | 1046 | /** |
@@ -1048,17 +1048,17 @@ discard block |
||
1048 | 1048 | */ |
1049 | 1049 | public function set_featured_image($data,$id) { |
1050 | 1050 | if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){ |
1051 | - $this->featured_image = $this->attach_image($data[0]['content']['images'][0],$id); |
|
1051 | + $this->featured_image = $this->attach_image($data[0]['content']['images'][0],$id); |
|
1052 | 1052 | |
1053 | - if(false !== $this->featured_image){ |
|
1054 | - delete_post_meta($id,'_thumbnail_id'); |
|
1055 | - add_post_meta($id,'_thumbnail_id',$this->featured_image,true); |
|
1053 | + if(false !== $this->featured_image){ |
|
1054 | + delete_post_meta($id,'_thumbnail_id'); |
|
1055 | + add_post_meta($id,'_thumbnail_id',$this->featured_image,true); |
|
1056 | 1056 | |
1057 | - if(!empty($this->gallery_meta) && !in_array($this->featured_image,$this->gallery_meta)){ |
|
1058 | - add_post_meta($id,'gallery',$this->featured_image,false); |
|
1059 | - $this->gallery_meta[] = $this->featured_image; |
|
1060 | - } |
|
1061 | - } |
|
1057 | + if(!empty($this->gallery_meta) && !in_array($this->featured_image,$this->gallery_meta)){ |
|
1058 | + add_post_meta($id,'gallery',$this->featured_image,false); |
|
1059 | + $this->gallery_meta[] = $this->featured_image; |
|
1060 | + } |
|
1061 | + } |
|
1062 | 1062 | } |
1063 | 1063 | } |
1064 | 1064 | |
@@ -1067,18 +1067,18 @@ discard block |
||
1067 | 1067 | */ |
1068 | 1068 | public function set_banner_image($data,$id) { |
1069 | 1069 | if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){ |
1070 | - $this->banner_image = $this->attach_image($data[0]['content']['images'][1],$id,array('width'=>'1920','height'=>'800','cropping'=>'c')); |
|
1071 | - |
|
1072 | - if(false !== $this->banner_image){ |
|
1073 | - delete_post_meta($id,'image_group'); |
|
1074 | - $new_banner = array('banner_image'=>array('cmb-field-0'=>$this->banner_image)); |
|
1075 | - add_post_meta($id,'image_group',$new_banner,true); |
|
1076 | - |
|
1077 | - if(!empty($this->gallery_meta) && !in_array($this->banner_image,$this->gallery_meta)){ |
|
1078 | - add_post_meta($id,'gallery',$this->banner_image,false); |
|
1079 | - $this->gallery_meta[] = $this->banner_image; |
|
1080 | - } |
|
1081 | - } |
|
1070 | + $this->banner_image = $this->attach_image($data[0]['content']['images'][1],$id,array('width'=>'1920','height'=>'800','cropping'=>'c')); |
|
1071 | + |
|
1072 | + if(false !== $this->banner_image){ |
|
1073 | + delete_post_meta($id,'image_group'); |
|
1074 | + $new_banner = array('banner_image'=>array('cmb-field-0'=>$this->banner_image)); |
|
1075 | + add_post_meta($id,'image_group',$new_banner,true); |
|
1076 | + |
|
1077 | + if(!empty($this->gallery_meta) && !in_array($this->banner_image,$this->gallery_meta)){ |
|
1078 | + add_post_meta($id,'gallery',$this->banner_image,false); |
|
1079 | + $this->gallery_meta[] = $this->banner_image; |
|
1080 | + } |
|
1081 | + } |
|
1082 | 1082 | } |
1083 | 1083 | } |
1084 | 1084 | |
@@ -1089,24 +1089,24 @@ discard block |
||
1089 | 1089 | |
1090 | 1090 | if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){ |
1091 | 1091 | |
1092 | - $counter = 0; |
|
1093 | - foreach($data[0]['content']['images'] as $image_data){ |
|
1094 | - if($counter === 0 && false !== $this->featured_image){continue;} |
|
1095 | - if($counter === 1 && false !== $this->banner_image){continue;} |
|
1096 | - |
|
1097 | - $this->gallery_meta[] = $temp_id = $this->attach_image($image_data,$id); |
|
1098 | - $counter++; |
|
1099 | - } |
|
1100 | - |
|
1101 | - if(!empty($this->gallery_meta)){ |
|
1102 | - delete_post_meta($id,'gallery'); |
|
1103 | - foreach($this->gallery_meta as $gallery_id){ |
|
1104 | - if(false !== $gallery_id && '' !== $gallery_id && !is_array($gallery_id)){ |
|
1105 | - add_post_meta($id,'gallery',$gallery_id,false); |
|
1106 | - } |
|
1107 | - } |
|
1108 | - } |
|
1109 | - } |
|
1092 | + $counter = 0; |
|
1093 | + foreach($data[0]['content']['images'] as $image_data){ |
|
1094 | + if($counter === 0 && false !== $this->featured_image){continue;} |
|
1095 | + if($counter === 1 && false !== $this->banner_image){continue;} |
|
1096 | + |
|
1097 | + $this->gallery_meta[] = $temp_id = $this->attach_image($image_data,$id); |
|
1098 | + $counter++; |
|
1099 | + } |
|
1100 | + |
|
1101 | + if(!empty($this->gallery_meta)){ |
|
1102 | + delete_post_meta($id,'gallery'); |
|
1103 | + foreach($this->gallery_meta as $gallery_id){ |
|
1104 | + if(false !== $gallery_id && '' !== $gallery_id && !is_array($gallery_id)){ |
|
1105 | + add_post_meta($id,'gallery',$gallery_id,false); |
|
1106 | + } |
|
1107 | + } |
|
1108 | + } |
|
1109 | + } |
|
1110 | 1110 | } |
1111 | 1111 | |
1112 | 1112 | /** |
@@ -1115,42 +1115,42 @@ discard block |
||
1115 | 1115 | public function attach_image($v=false,$parent_id,$image_sizes=false){ |
1116 | 1116 | if(false !== $v){ |
1117 | 1117 | $temp_fragment = explode('/',$v['url_fragment']); |
1118 | - $url_filename = $temp_fragment[count($temp_fragment)-1]; |
|
1119 | - $url_filename = str_replace(array('.jpg','.png','.jpeg'),'',$url_filename); |
|
1118 | + $url_filename = $temp_fragment[count($temp_fragment)-1]; |
|
1119 | + $url_filename = str_replace(array('.jpg','.png','.jpeg'),'',$url_filename); |
|
1120 | 1120 | |
1121 | - if(in_array($url_filename,$this->found_attachments)){ |
|
1122 | - return array_search($url_filename,$this->found_attachments); |
|
1123 | - } |
|
1121 | + if(in_array($url_filename,$this->found_attachments)){ |
|
1122 | + return array_search($url_filename,$this->found_attachments); |
|
1123 | + } |
|
1124 | 1124 | |
1125 | - $postdata=array(); |
|
1126 | - if(empty($v['label'])) |
|
1127 | - { |
|
1128 | - $v['label']=''; |
|
1129 | - } |
|
1130 | - if(!empty($v['description'])) |
|
1131 | - { |
|
1132 | - $desc=wp_strip_all_tags($v['description']); |
|
1133 | - $posdata=array('post_excerpt'=>$desc); |
|
1134 | - } |
|
1135 | - if(!empty($v['section'])) |
|
1136 | - { |
|
1137 | - $desc=wp_strip_all_tags($v['section']); |
|
1138 | - $posdata=array('post_excerpt'=>$desc); |
|
1139 | - } |
|
1140 | - |
|
1141 | - $attachID=NULL; |
|
1142 | - //Resizor - add option to setting if required |
|
1143 | - $fragment = str_replace(' ','%20',$v['url_fragment']); |
|
1144 | - $url = $this->get_scaling_url($image_sizes).$fragment; |
|
1145 | - $attachID = $this->attach_external_image2($url,$parent_id,'',$v['label'],$postdata); |
|
1146 | - |
|
1147 | - //echo($attachID.' add image'); |
|
1148 | - if($attachID!=NULL) |
|
1149 | - { |
|
1150 | - return $attachID; |
|
1151 | - } |
|
1152 | - } |
|
1153 | - return false; |
|
1125 | + $postdata=array(); |
|
1126 | + if(empty($v['label'])) |
|
1127 | + { |
|
1128 | + $v['label']=''; |
|
1129 | + } |
|
1130 | + if(!empty($v['description'])) |
|
1131 | + { |
|
1132 | + $desc=wp_strip_all_tags($v['description']); |
|
1133 | + $posdata=array('post_excerpt'=>$desc); |
|
1134 | + } |
|
1135 | + if(!empty($v['section'])) |
|
1136 | + { |
|
1137 | + $desc=wp_strip_all_tags($v['section']); |
|
1138 | + $posdata=array('post_excerpt'=>$desc); |
|
1139 | + } |
|
1140 | + |
|
1141 | + $attachID=NULL; |
|
1142 | + //Resizor - add option to setting if required |
|
1143 | + $fragment = str_replace(' ','%20',$v['url_fragment']); |
|
1144 | + $url = $this->get_scaling_url($image_sizes).$fragment; |
|
1145 | + $attachID = $this->attach_external_image2($url,$parent_id,'',$v['label'],$postdata); |
|
1146 | + |
|
1147 | + //echo($attachID.' add image'); |
|
1148 | + if($attachID!=NULL) |
|
1149 | + { |
|
1150 | + return $attachID; |
|
1151 | + } |
|
1152 | + } |
|
1153 | + return false; |
|
1154 | 1154 | } |
1155 | 1155 | public function attach_external_image2( $url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array() ) { |
1156 | 1156 |