@@ -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> |
@@ -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 |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * Display the importer administration screen |
105 | 105 | */ |
106 | 106 | public function display_page() { |
107 | - ?> |
|
107 | + ?> |
|
108 | 108 | <div class="wrap"> |
109 | 109 | <?php $this->navigation('destination'); ?> |
110 | 110 | |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | $keyphrases = $_POST['keyword']; |
331 | 331 | }else{ |
332 | 332 | $keyphrases = array(0); |
333 | - } |
|
333 | + } |
|
334 | 334 | |
335 | 335 | if(!is_array($keyphrases)){ |
336 | 336 | $keyphrases = array($keyphrases); |
@@ -359,11 +359,11 @@ discard block |
||
359 | 359 | //If we are searching for |
360 | 360 | if(false !== $post_status){ |
361 | 361 | |
362 | - $current_status = get_post_status($row->post_id); |
|
363 | - if($current_status !== $post_status){ |
|
364 | - continue; |
|
365 | - } |
|
366 | - $searched_items[sanitize_title($row->name).'-'.$row->meta_value] = $this->format_row($row); |
|
362 | + $current_status = get_post_status($row->post_id); |
|
363 | + if($current_status !== $post_status){ |
|
364 | + continue; |
|
365 | + } |
|
366 | + $searched_items[sanitize_title($row->name).'-'.$row->meta_value] = $this->format_row($row); |
|
367 | 367 | |
368 | 368 | |
369 | 369 | }else{ |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | $team_members = false; |
446 | 446 | } |
447 | 447 | |
448 | - $safari_brands = false; |
|
448 | + $safari_brands = false; |
|
449 | 449 | |
450 | 450 | if(isset($_POST['content']) && is_array($_POST['content']) && !empty($_POST['content'])){ |
451 | 451 | $content = $_POST['content']; |
@@ -456,16 +456,16 @@ discard block |
||
456 | 456 | $content = false; |
457 | 457 | } |
458 | 458 | |
459 | - $jdata = file_get_contents( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id ); |
|
460 | - if($jdata) |
|
461 | - { |
|
462 | - $adata=json_decode($jdata,true); |
|
463 | - if(!empty($adata)) |
|
464 | - { |
|
465 | - $return = $this->import_row($adata,$wetu_id,$post_id,$team_members,$content,$safari_brands); |
|
466 | - $this->format_completed_row($return); |
|
467 | - } |
|
468 | - } |
|
459 | + $jdata = file_get_contents( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id ); |
|
460 | + if($jdata) |
|
461 | + { |
|
462 | + $adata=json_decode($jdata,true); |
|
463 | + if(!empty($adata)) |
|
464 | + { |
|
465 | + $return = $this->import_row($adata,$wetu_id,$post_id,$team_members,$content,$safari_brands); |
|
466 | + $this->format_completed_row($return); |
|
467 | + } |
|
468 | + } |
|
469 | 469 | |
470 | 470 | die(); |
471 | 471 | } |
@@ -477,82 +477,82 @@ discard block |
||
477 | 477 | */ |
478 | 478 | public function import_row($data,$wetu_id,$id=0,$team_members=false,$importable_content=false,$safari_brands=false) { |
479 | 479 | |
480 | - if(trim($data[0]['type'])=='Destination') |
|
481 | - { |
|
482 | - $post_name = $data_post_content = $data_post_excerpt = ''; |
|
483 | - $post = array( |
|
484 | - 'post_type' => 'destination', |
|
485 | - ); |
|
486 | - |
|
487 | - $content_used_general_description = false; |
|
488 | - |
|
489 | - //Set the post_content |
|
490 | - if(false !== $importable_content && in_array('description',$importable_content)){ |
|
491 | - if(isset($data[0]['content']['extended_description'])) |
|
492 | - { |
|
493 | - $data_post_content = $data[0]['content']['extended_description']; |
|
494 | - }elseif(isset($data[0]['content']['general_description'])){ |
|
495 | - $data_post_content = $data[0]['content']['general_description']; |
|
496 | - $content_used_general_description = true; |
|
497 | - }elseif(isset($data[0]['content']['teaser_description'])){ |
|
498 | - $data_post_content = $data[0]['content']['teaser_description']; |
|
499 | - } |
|
500 | - $post['post_content'] = wp_strip_all_tags($data_post_content); |
|
501 | - } |
|
502 | - |
|
503 | - //set the post_excerpt |
|
504 | - if(false !== $importable_content && in_array('excerpt',$importable_content)){ |
|
505 | - if(isset($data[0]['content']['teaser_description'])){ |
|
506 | - $data_post_excerpt = $data[0]['content']['teaser_description']; |
|
507 | - }elseif(isset($data[0]['content']['extended_description'])){ |
|
480 | + if(trim($data[0]['type'])=='Destination') |
|
481 | + { |
|
482 | + $post_name = $data_post_content = $data_post_excerpt = ''; |
|
483 | + $post = array( |
|
484 | + 'post_type' => 'destination', |
|
485 | + ); |
|
486 | + |
|
487 | + $content_used_general_description = false; |
|
488 | + |
|
489 | + //Set the post_content |
|
490 | + if(false !== $importable_content && in_array('description',$importable_content)){ |
|
491 | + if(isset($data[0]['content']['extended_description'])) |
|
492 | + { |
|
493 | + $data_post_content = $data[0]['content']['extended_description']; |
|
494 | + }elseif(isset($data[0]['content']['general_description'])){ |
|
495 | + $data_post_content = $data[0]['content']['general_description']; |
|
496 | + $content_used_general_description = true; |
|
497 | + }elseif(isset($data[0]['content']['teaser_description'])){ |
|
498 | + $data_post_content = $data[0]['content']['teaser_description']; |
|
499 | + } |
|
500 | + $post['post_content'] = wp_strip_all_tags($data_post_content); |
|
501 | + } |
|
502 | + |
|
503 | + //set the post_excerpt |
|
504 | + if(false !== $importable_content && in_array('excerpt',$importable_content)){ |
|
505 | + if(isset($data[0]['content']['teaser_description'])){ |
|
506 | + $data_post_excerpt = $data[0]['content']['teaser_description']; |
|
507 | + }elseif(isset($data[0]['content']['extended_description'])){ |
|
508 | 508 | $data_post_excerpt = $data[0]['content']['extended_description']; |
509 | 509 | }elseif(isset($data[0]['content']['general_description']) && false === $content_used_general_description){ |
510 | - $data_post_excerpt = $data[0]['content']['general_description']; |
|
511 | - } |
|
512 | - $post['post_excerpt'] = $data_post_excerpt; |
|
513 | - } |
|
510 | + $data_post_excerpt = $data[0]['content']['general_description']; |
|
511 | + } |
|
512 | + $post['post_excerpt'] = $data_post_excerpt; |
|
513 | + } |
|
514 | 514 | |
515 | - if(false !== $id && '0' !== $id){ |
|
516 | - $post['ID'] = $id; |
|
515 | + if(false !== $id && '0' !== $id){ |
|
516 | + $post['ID'] = $id; |
|
517 | 517 | if(isset($data[0]['name'])){ |
518 | 518 | $post['post_title'] = $data[0]['name']; |
519 | 519 | $post['post_status'] = 'publish'; |
520 | 520 | $post['post_name'] = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'destination', 0); |
521 | 521 | } |
522 | - $id = wp_update_post($post); |
|
523 | - $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
524 | - update_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified']),$prev_date); |
|
525 | - }else{ |
|
526 | - |
|
527 | - //Set the name |
|
528 | - if(isset($data[0]['name'])){ |
|
529 | - $post_name = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'destination', 0); |
|
530 | - } |
|
531 | - $post['post_name'] = $post_name; |
|
532 | - $post['post_title'] = $data[0]['name']; |
|
533 | - $post['post_status'] = 'publish'; |
|
534 | - $id = wp_insert_post($post); |
|
535 | - |
|
536 | - //Save the WETU ID and the Last date it was modified. |
|
537 | - if(false !== $id){ |
|
538 | - add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
539 | - add_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified'])); |
|
540 | - } |
|
541 | - } |
|
542 | - |
|
543 | - //Set the team member if it is there |
|
544 | - if(post_type_exists('team') && false !== $team_members && '' !== $team_members){ |
|
545 | - $this->set_team_member($id,$team_members); |
|
546 | - } |
|
547 | - |
|
548 | - if(class_exists('LSX_TO_Maps')){ |
|
549 | - $this->set_map_data($data,$id,4); |
|
550 | - } |
|
551 | - |
|
552 | - //Set the Room Data |
|
553 | - if(false !== $importable_content && in_array('videos',$importable_content)){ |
|
554 | - $this->set_video_data($data,$id); |
|
555 | - } |
|
522 | + $id = wp_update_post($post); |
|
523 | + $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
524 | + update_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified']),$prev_date); |
|
525 | + }else{ |
|
526 | + |
|
527 | + //Set the name |
|
528 | + if(isset($data[0]['name'])){ |
|
529 | + $post_name = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'destination', 0); |
|
530 | + } |
|
531 | + $post['post_name'] = $post_name; |
|
532 | + $post['post_title'] = $data[0]['name']; |
|
533 | + $post['post_status'] = 'publish'; |
|
534 | + $id = wp_insert_post($post); |
|
535 | + |
|
536 | + //Save the WETU ID and the Last date it was modified. |
|
537 | + if(false !== $id){ |
|
538 | + add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
539 | + add_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified'])); |
|
540 | + } |
|
541 | + } |
|
542 | + |
|
543 | + //Set the team member if it is there |
|
544 | + if(post_type_exists('team') && false !== $team_members && '' !== $team_members){ |
|
545 | + $this->set_team_member($id,$team_members); |
|
546 | + } |
|
547 | + |
|
548 | + if(class_exists('LSX_TO_Maps')){ |
|
549 | + $this->set_map_data($data,$id,4); |
|
550 | + } |
|
551 | + |
|
552 | + //Set the Room Data |
|
553 | + if(false !== $importable_content && in_array('videos',$importable_content)){ |
|
554 | + $this->set_video_data($data,$id); |
|
555 | + } |
|
556 | 556 | |
557 | 557 | //Set the Electricity |
558 | 558 | if(false !== $importable_content && in_array('electricity',$importable_content)){ |
@@ -597,7 +597,7 @@ discard block |
||
597 | 597 | } |
598 | 598 | |
599 | 599 | } |
600 | - return $id; |
|
600 | + return $id; |
|
601 | 601 | } |
602 | 602 | |
603 | 603 | /** |
@@ -607,7 +607,7 @@ discard block |
||
607 | 607 | |
608 | 608 | delete_post_meta($id, 'team_to_'.$this->tab_slug); |
609 | 609 | foreach($team_members as $team){ |
610 | - add_post_meta($id,'team_to_'.$this->tab_slug,$team); |
|
610 | + add_post_meta($id,'team_to_'.$this->tab_slug,$team); |
|
611 | 611 | } |
612 | 612 | } |
613 | 613 | |
@@ -658,11 +658,11 @@ discard block |
||
658 | 658 | 'elevation' => '', |
659 | 659 | ); |
660 | 660 | if(false !== $id && '0' !== $id){ |
661 | - $prev = get_post_meta($id,'location',true); |
|
662 | - update_post_meta($id,'location',$location_data,$prev); |
|
663 | - }else{ |
|
664 | - add_post_meta($id,'location',$location_data,true); |
|
665 | - } |
|
661 | + $prev = get_post_meta($id,'location',true); |
|
662 | + update_post_meta($id,'location',$location_data,$prev); |
|
663 | + }else{ |
|
664 | + add_post_meta($id,'location',$location_data,true); |
|
665 | + } |
|
666 | 666 | } |
667 | 667 | } |
668 | 668 |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | $tour_options = get_option('wetu_importer_tour_settings',false); |
98 | 98 | if(false !== $tour_options){ |
99 | 99 | $this->tour_options = $tour_options; |
100 | - } |
|
100 | + } |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | * Display the importer administration screen |
121 | 121 | */ |
122 | 122 | public function display_page() { |
123 | - ?> |
|
123 | + ?> |
|
124 | 124 | <div class="wrap"> |
125 | 125 | <?php $this->navigation('tour'); ?> |
126 | 126 | |
@@ -249,16 +249,16 @@ discard block |
||
249 | 249 | $result = $this->update_options(); |
250 | 250 | |
251 | 251 | if(true === $result){ |
252 | - echo '<span style="color:green;">'.esc_attr('Connected','wetu-importer').'</span>'; |
|
253 | - if(!isset($_GET['refresh_tours'])){ |
|
254 | - echo ' - <small><a href="'.admin_url('admin.php').'?page='.$this->plugin_slug.'&tab=tour&refresh_tours=true">'.esc_attr('Refresh','wetu-importer').'</a></small>'; |
|
255 | - } |
|
256 | - }else{ |
|
257 | - echo '<span style="color:red;">'.wp_kses_post($result).'</span>'; |
|
258 | - } |
|
252 | + echo '<span style="color:green;">'.esc_attr('Connected','wetu-importer').'</span>'; |
|
253 | + if(!isset($_GET['refresh_tours'])){ |
|
254 | + echo ' - <small><a href="'.admin_url('admin.php').'?page='.$this->plugin_slug.'&tab=tour&refresh_tours=true">'.esc_attr('Refresh','wetu-importer').'</a></small>'; |
|
255 | + } |
|
256 | + }else{ |
|
257 | + echo '<span style="color:red;">'.wp_kses_post($result).'</span>'; |
|
258 | + } |
|
259 | 259 | }else{ |
260 | 260 | echo '<span style="color:green;">'.esc_attr('Connected','wetu-importer').'</span> - <small><a href="'.admin_url('admin.php').'?page='.$this->plugin_slug.'&tab=tour&refresh_tours=true">'.esc_attr('Refresh','wetu-importer').'</a></small>'; |
261 | - } |
|
261 | + } |
|
262 | 262 | echo '</h3></div>'; |
263 | 263 | } |
264 | 264 | |
@@ -270,8 +270,8 @@ discard block |
||
270 | 270 | $tours = json_decode($data, true); |
271 | 271 | |
272 | 272 | if(isset($tours['error'])){ |
273 | - return $tours['error']; |
|
274 | - }elseif (isset($tours['itineraries']) && !empty($tours['itineraries'])) { |
|
273 | + return $tours['error']; |
|
274 | + }elseif (isset($tours['itineraries']) && !empty($tours['itineraries'])) { |
|
275 | 275 | set_transient('lsx_ti_tours',$tours['itineraries'],60*60*2); |
276 | 276 | return true; |
277 | 277 | } |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | $keyphrases = $_POST['keyword']; |
321 | 321 | }else{ |
322 | 322 | $keyphrases = array(0); |
323 | - } |
|
323 | + } |
|
324 | 324 | |
325 | 325 | if(!is_array($keyphrases)){ |
326 | 326 | $keyphrases = array($keyphrases); |
@@ -349,15 +349,15 @@ discard block |
||
349 | 349 | |
350 | 350 | foreach($tours as $row_key => $row){ |
351 | 351 | |
352 | - if(isset($row['is_disabled']) && true === $row['is_disabled']){ |
|
353 | - continue; |
|
354 | - } |
|
352 | + if(isset($row['is_disabled']) && true === $row['is_disabled']){ |
|
353 | + continue; |
|
354 | + } |
|
355 | 355 | |
356 | - /*if('Sample' === $row['type']){ |
|
356 | + /*if('Sample' === $row['type']){ |
|
357 | 357 | continue; |
358 | 358 | }*/ |
359 | 359 | |
360 | - //If this is a current tour, add its ID to the row. |
|
360 | + //If this is a current tour, add its ID to the row. |
|
361 | 361 | $row['post_id'] = 0; |
362 | 362 | if(false !== $current_tours && array_key_exists($row['identifier'], $current_tours)){ |
363 | 363 | $row['post_id'] = $current_tours[$row['identifier']]->post_id; |
@@ -366,31 +366,31 @@ discard block |
||
366 | 366 | //If we are searching for |
367 | 367 | if(false !== $post_status){ |
368 | 368 | |
369 | - if('import' === $post_status){ |
|
369 | + if('import' === $post_status){ |
|
370 | 370 | |
371 | 371 | if(0 !== $row['post_id']){ |
372 | - continue; |
|
372 | + continue; |
|
373 | 373 | }else{ |
374 | 374 | $searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row); |
375 | - } |
|
375 | + } |
|
376 | 376 | |
377 | 377 | |
378 | - }else{ |
|
378 | + }else{ |
|
379 | 379 | |
380 | 380 | if(0 === $row['post_id']){ |
381 | 381 | continue; |
382 | 382 | }else{ |
383 | 383 | $current_status = get_post_status($row['post_id']); |
384 | 384 | if($current_status !== $post_status){ |
385 | - continue; |
|
386 | - } |
|
385 | + continue; |
|
386 | + } |
|
387 | 387 | |
388 | 388 | } |
389 | 389 | $searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row); |
390 | 390 | |
391 | - } |
|
391 | + } |
|
392 | 392 | |
393 | - }else{ |
|
393 | + }else{ |
|
394 | 394 | //Search through each keyword. |
395 | 395 | foreach($keyphrases as $keyphrase){ |
396 | 396 | |
@@ -404,7 +404,7 @@ discard block |
||
404 | 404 | $searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row); |
405 | 405 | } |
406 | 406 | } |
407 | - } |
|
407 | + } |
|
408 | 408 | } |
409 | 409 | } |
410 | 410 | |
@@ -471,18 +471,18 @@ discard block |
||
471 | 471 | $content = false; |
472 | 472 | } |
473 | 473 | |
474 | - $jdata=file_get_contents("http://wetu.com/API/Itinerary/V7/Get?id=".$wetu_id); |
|
474 | + $jdata=file_get_contents("http://wetu.com/API/Itinerary/V7/Get?id=".$wetu_id); |
|
475 | 475 | |
476 | - if($jdata) |
|
477 | - { |
|
476 | + if($jdata) |
|
477 | + { |
|
478 | 478 | $jdata=json_decode($jdata,true); |
479 | - if(!empty($jdata)) |
|
480 | - { |
|
481 | - $return = $this->import_row($jdata,$wetu_id,$post_id,$content); |
|
482 | - $this->format_completed_row($return); |
|
483 | - $this->cleanup_posts(); |
|
484 | - } |
|
485 | - } |
|
479 | + if(!empty($jdata)) |
|
480 | + { |
|
481 | + $return = $this->import_row($jdata,$wetu_id,$post_id,$content); |
|
482 | + $this->format_completed_row($return); |
|
483 | + $this->cleanup_posts(); |
|
484 | + } |
|
485 | + } |
|
486 | 486 | die(); |
487 | 487 | } |
488 | 488 | |
@@ -490,53 +490,53 @@ discard block |
||
490 | 490 | |
491 | 491 | /** |
492 | 492 | * Connect to wetu |
493 | - * |
|
494 | - * @param $data array |
|
495 | - * @param $wetu_id string |
|
493 | + * |
|
494 | + * @param $data array |
|
495 | + * @param $wetu_id string |
|
496 | 496 | */ |
497 | 497 | public function import_row($data,$wetu_id,$id=0,$importable_content=false,$old1=false,$old2=false) { |
498 | - $post_name = $data_post_content = $data_post_excerpt = ''; |
|
499 | - $post = array( |
|
500 | - 'post_type' => 'tour', |
|
501 | - ); |
|
498 | + $post_name = $data_post_content = $data_post_excerpt = ''; |
|
499 | + $post = array( |
|
500 | + 'post_type' => 'tour', |
|
501 | + ); |
|
502 | 502 | |
503 | - //Set the post_content |
|
503 | + //Set the post_content |
|
504 | 504 | $content_used_general_description = false; |
505 | - if(false !== $importable_content && in_array('description',$importable_content)){ |
|
506 | - $data_post_content = ''; |
|
507 | - |
|
508 | - if(isset($data['description'])){ |
|
509 | - $data_post_content = $data['description']; |
|
510 | - }elseif(isset($data['summary'])){ |
|
511 | - $data_post_content = $data['summary']; |
|
512 | - } |
|
513 | - $post['post_content'] = $data_post_content; |
|
514 | - } |
|
515 | - |
|
516 | - //Create or update the post |
|
517 | - if(false !== $id && '0' !== $id){ |
|
518 | - $post['ID'] = $id; |
|
519 | - $post['post_status'] = 'publish'; |
|
520 | - $id = wp_update_post($post); |
|
521 | - $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
522 | - update_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified']),$prev_date); |
|
523 | - }else{ |
|
524 | - |
|
525 | - //Set the name |
|
526 | - if(isset($data['name'])){ |
|
527 | - $post_name = wp_unique_post_slug(sanitize_title($data['name']),$id, 'draft', 'tour', 0); |
|
528 | - } |
|
529 | - $post['post_name'] = $post_name; |
|
530 | - $post['post_title'] = $data['name']; |
|
531 | - $post['post_status'] = 'publish'; |
|
532 | - $id = wp_insert_post($post); |
|
533 | - |
|
534 | - //Save the WETU ID and the Last date it was modified. |
|
535 | - if(false !== $id){ |
|
536 | - add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
537 | - add_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified'])); |
|
538 | - } |
|
539 | - } |
|
505 | + if(false !== $importable_content && in_array('description',$importable_content)){ |
|
506 | + $data_post_content = ''; |
|
507 | + |
|
508 | + if(isset($data['description'])){ |
|
509 | + $data_post_content = $data['description']; |
|
510 | + }elseif(isset($data['summary'])){ |
|
511 | + $data_post_content = $data['summary']; |
|
512 | + } |
|
513 | + $post['post_content'] = $data_post_content; |
|
514 | + } |
|
515 | + |
|
516 | + //Create or update the post |
|
517 | + if(false !== $id && '0' !== $id){ |
|
518 | + $post['ID'] = $id; |
|
519 | + $post['post_status'] = 'publish'; |
|
520 | + $id = wp_update_post($post); |
|
521 | + $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
522 | + update_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified']),$prev_date); |
|
523 | + }else{ |
|
524 | + |
|
525 | + //Set the name |
|
526 | + if(isset($data['name'])){ |
|
527 | + $post_name = wp_unique_post_slug(sanitize_title($data['name']),$id, 'draft', 'tour', 0); |
|
528 | + } |
|
529 | + $post['post_name'] = $post_name; |
|
530 | + $post['post_title'] = $data['name']; |
|
531 | + $post['post_status'] = 'publish'; |
|
532 | + $id = wp_insert_post($post); |
|
533 | + |
|
534 | + //Save the WETU ID and the Last date it was modified. |
|
535 | + if(false !== $id){ |
|
536 | + add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
537 | + add_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified'])); |
|
538 | + } |
|
539 | + } |
|
540 | 540 | |
541 | 541 | |
542 | 542 | //Set the price |
@@ -549,9 +549,9 @@ discard block |
||
549 | 549 | $this->set_duration($data,$id); |
550 | 550 | } |
551 | 551 | |
552 | - if(in_array('itineraries',$importable_content) && isset($data['legs']) && !empty($data['legs'])){ |
|
553 | - $this->process_itineraries($data,$id,$importable_content); |
|
554 | - } |
|
552 | + if(in_array('itineraries',$importable_content) && isset($data['legs']) && !empty($data['legs'])){ |
|
553 | + $this->process_itineraries($data,$id,$importable_content); |
|
554 | + } |
|
555 | 555 | |
556 | 556 | if(in_array('map',$importable_content) && isset($data['routes']) && !empty($data['routes'])){ |
557 | 557 | $this->process_map_points($data,$id); |
@@ -562,24 +562,24 @@ discard block |
||
562 | 562 | 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))){ |
563 | 563 | $this->find_attachments($id); |
564 | 564 | } |
565 | - //Set the featured image |
|
566 | - //TODO Test These |
|
567 | - if(false !== $importable_content && in_array('featured_image',$importable_content)){ |
|
568 | - $this->set_featured_image($data,$id); |
|
569 | - } |
|
565 | + //Set the featured image |
|
566 | + //TODO Test These |
|
567 | + if(false !== $importable_content && in_array('featured_image',$importable_content)){ |
|
568 | + $this->set_featured_image($data,$id); |
|
569 | + } |
|
570 | 570 | |
571 | 571 | //TODO Test These |
572 | - if(false !== $importable_content && in_array('banner_image',$importable_content)){ |
|
573 | - $this->set_banner_image($data,$id); |
|
574 | - } |
|
572 | + if(false !== $importable_content && in_array('banner_image',$importable_content)){ |
|
573 | + $this->set_banner_image($data,$id); |
|
574 | + } |
|
575 | 575 | |
576 | 576 | //TODO Test These |
577 | - //Import the main gallery |
|
578 | - if(false !== $importable_content && in_array('gallery',$importable_content)){ |
|
579 | - $this->create_main_gallery($data,$id); |
|
580 | - } |
|
577 | + //Import the main gallery |
|
578 | + if(false !== $importable_content && in_array('gallery',$importable_content)){ |
|
579 | + $this->create_main_gallery($data,$id); |
|
580 | + } |
|
581 | 581 | |
582 | - return $id; |
|
582 | + return $id; |
|
583 | 583 | } |
584 | 584 | |
585 | 585 | /** |
@@ -707,31 +707,31 @@ discard block |
||
707 | 707 | */ |
708 | 708 | public function process_map_points($data,$id) { |
709 | 709 | |
710 | - if(!empty($data['routes'])){ |
|
710 | + if(!empty($data['routes'])){ |
|
711 | 711 | |
712 | - delete_post_meta($id,'wetu_map_points'); |
|
712 | + delete_post_meta($id,'wetu_map_points'); |
|
713 | 713 | |
714 | - $points = array(); |
|
714 | + $points = array(); |
|
715 | 715 | |
716 | - foreach($data['routes'] as $route){ |
|
716 | + foreach($data['routes'] as $route){ |
|
717 | 717 | |
718 | 718 | |
719 | - if(isset($route['points']) && '' !== $route['points']){ |
|
719 | + if(isset($route['points']) && '' !== $route['points']){ |
|
720 | 720 | |
721 | - $temp_points = explode(';',$route['points']); |
|
722 | - $point_counter = count($temp_points); |
|
721 | + $temp_points = explode(';',$route['points']); |
|
722 | + $point_counter = count($temp_points); |
|
723 | 723 | |
724 | 724 | for ($x = 0; $x <= $point_counter; $x++) { |
725 | - $y = $x+1; |
|
725 | + $y = $x+1; |
|
726 | 726 | $points[] = $temp_points[$x].','.$temp_points[$y]; |
727 | 727 | $x++; |
728 | 728 | } |
729 | 729 | } |
730 | - } |
|
731 | - if(!empty($points)){ |
|
730 | + } |
|
731 | + if(!empty($points)){ |
|
732 | 732 | $this->save_custom_field(implode(' ',$points),'wetu_map_points',$id,false,true); |
733 | - } |
|
734 | - } |
|
733 | + } |
|
734 | + } |
|
735 | 735 | |
736 | 736 | } |
737 | 737 | |
@@ -739,17 +739,17 @@ discard block |
||
739 | 739 | * Set the Itinerary Day |
740 | 740 | */ |
741 | 741 | public function set_itinerary_day($day,$id) { |
742 | - $this->save_custom_field($day,'itinerary',$id,false,false); |
|
742 | + $this->save_custom_field($day,'itinerary',$id,false,false); |
|
743 | 743 | } |
744 | 744 | |
745 | 745 | /** |
746 | 746 | * Set the price |
747 | 747 | */ |
748 | 748 | public function set_price($data,$id) { |
749 | - //Price |
|
749 | + //Price |
|
750 | 750 | if(isset($data['price']) && ''!== $data['price']){ |
751 | - $price = preg_replace("/[^0-9,.]/", "", $data['price']); |
|
752 | - $this->save_custom_field($price,'price',$id); |
|
751 | + $price = preg_replace("/[^0-9,.]/", "", $data['price']); |
|
752 | + $this->save_custom_field($price,'price',$id); |
|
753 | 753 | } |
754 | 754 | |
755 | 755 | //Price includes |
@@ -757,7 +757,7 @@ discard block |
||
757 | 757 | $this->save_custom_field($data['price_includes'],'included',$id); |
758 | 758 | } |
759 | 759 | |
760 | - //Price Excludes |
|
760 | + //Price Excludes |
|
761 | 761 | if(isset($data['price_excludes']) && ''!== $data['price_excludes']){ |
762 | 762 | $this->save_custom_field($data['price_excludes'],'not_included',$id); |
763 | 763 | } |
@@ -780,35 +780,35 @@ discard block |
||
780 | 780 | */ |
781 | 781 | public function set_accommodation($day,$id) { |
782 | 782 | |
783 | - $ac_id = false; |
|
783 | + $ac_id = false; |
|
784 | 784 | $this->current_accommodation = $this->find_current_accommodation(); |
785 | 785 | |
786 | 786 | if(isset($day['content_entity_id']) && !empty($day['content_entity_id'])){ |
787 | 787 | |
788 | 788 | if(false !== $this->current_accommodation && !empty($this->current_accommodation) && array_key_exists($day['content_entity_id'],$this->current_accommodation)){ |
789 | - $ac_id = $this->current_accommodation[$day['content_entity_id']]; |
|
789 | + $ac_id = $this->current_accommodation[$day['content_entity_id']]; |
|
790 | 790 | }else{ |
791 | 791 | $ac_id = wp_insert_post(array( |
792 | - 'post_type' => 'accommodation', |
|
793 | - 'post_status' => 'draft', |
|
794 | - 'post_title' => $day['content_entity_id'] |
|
795 | - )); |
|
792 | + 'post_type' => 'accommodation', |
|
793 | + 'post_status' => 'draft', |
|
794 | + 'post_title' => $day['content_entity_id'] |
|
795 | + )); |
|
796 | 796 | $this->save_custom_field($day['content_entity_id'],'lsx_wetu_id',$ac_id); |
797 | 797 | } |
798 | 798 | |
799 | 799 | if('' !== $ac_id && false !== $ac_id){ |
800 | - $this->save_custom_field($ac_id,'accommodation_to_tour',$id,false,false); |
|
800 | + $this->save_custom_field($ac_id,'accommodation_to_tour',$id,false,false); |
|
801 | 801 | $this->save_custom_field($id,'tour_to_accommodation',$ac_id,false,false); |
802 | - } |
|
802 | + } |
|
803 | 803 | } |
804 | 804 | return $ac_id; |
805 | 805 | } |
806 | 806 | |
807 | 807 | /** |
808 | 808 | * Grab all the current accommodation posts via the lsx_wetu_id field. |
809 | - * |
|
810 | - * @param $post_type string |
|
811 | - * @return boolean / array |
|
809 | + * |
|
810 | + * @param $post_type string |
|
811 | + * @return boolean / array |
|
812 | 812 | */ |
813 | 813 | public function find_current_accommodation($post_type='accommodation') { |
814 | 814 | global $wpdb; |
@@ -816,16 +816,16 @@ discard block |
||
816 | 816 | |
817 | 817 | $return = false; |
818 | 818 | if(!empty($accommodation)){ |
819 | - foreach($accommodation as $key => $acc){ |
|
819 | + foreach($accommodation as $key => $acc){ |
|
820 | 820 | $return[$acc->meta_value] = $acc->post_id; |
821 | - } |
|
822 | - } |
|
821 | + } |
|
822 | + } |
|
823 | 823 | return $return; |
824 | 824 | } |
825 | 825 | |
826 | 826 | /** |
827 | 827 | * Grab all the current accommodation posts via the lsx_wetu_id field. |
828 | - * @return boolean / array |
|
828 | + * @return boolean / array |
|
829 | 829 | */ |
830 | 830 | public function find_current_destinations() { |
831 | 831 | return $this->find_current_accommodation('destination'); |
@@ -853,7 +853,7 @@ discard block |
||
853 | 853 | $country_wetu_id = get_post_meta($potential_id,'lsx_wetu_id',true); |
854 | 854 | if(false !== $country_wetu_id){ |
855 | 855 | $country_id = $this->set_country($country_wetu_id, $id); |
856 | - } |
|
856 | + } |
|
857 | 857 | |
858 | 858 | }else { |
859 | 859 | |
@@ -864,27 +864,27 @@ discard block |
||
864 | 864 | |
865 | 865 | if (!empty($destination_data) && !isset($destination_data['error'])) { |
866 | 866 | |
867 | - $destination_title = $day['destination_content_entity_id']; |
|
867 | + $destination_title = $day['destination_content_entity_id']; |
|
868 | 868 | |
869 | - if(isset($destination_data[0]['name'])){ |
|
869 | + if(isset($destination_data[0]['name'])){ |
|
870 | 870 | $destination_title = $destination_data[0]['name']; |
871 | - } |
|
871 | + } |
|
872 | 872 | |
873 | - if(isset($destination_data[0]['map_object_id']) && isset($destination_data[0]['position']['country_content_entity_id']) |
|
874 | - && $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id']){ |
|
873 | + if(isset($destination_data[0]['map_object_id']) && isset($destination_data[0]['position']['country_content_entity_id']) |
|
874 | + && $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id']){ |
|
875 | 875 | |
876 | 876 | $country_id = $this->set_country($destination_data[0]['position']['country_content_entity_id'], $id); |
877 | - } |
|
877 | + } |
|
878 | 878 | |
879 | - $dest_post = array( |
|
879 | + $dest_post = array( |
|
880 | 880 | 'post_type' => 'destination', |
881 | 881 | 'post_status' => 'draft', |
882 | 882 | 'post_title' => $destination_title |
883 | 883 | ); |
884 | 884 | |
885 | - if(false !== $country_id){ |
|
885 | + if(false !== $country_id){ |
|
886 | 886 | $dest_post['post_parent'] = $country_id; |
887 | - } |
|
887 | + } |
|
888 | 888 | $dest_id = wp_insert_post($dest_post); |
889 | 889 | |
890 | 890 | //Make sure we register the |
@@ -902,11 +902,11 @@ discard block |
||
902 | 902 | |
903 | 903 | //Add this relation info so we can make sure certain items are set as countries. |
904 | 904 | if(0 !== $country_id && false !== $country_id){ |
905 | - $this->relation_meta[$dest_id] = $country_id; |
|
905 | + $this->relation_meta[$dest_id] = $country_id; |
|
906 | 906 | $this->relation_meta[$country_id] = 0; |
907 | - }else{ |
|
907 | + }else{ |
|
908 | 908 | $this->relation_meta[$dest_id] = 0; |
909 | - } |
|
909 | + } |
|
910 | 910 | } |
911 | 911 | } |
912 | 912 | return $dest_id; |
@@ -916,51 +916,51 @@ discard block |
||
916 | 916 | * Connects the destinations post type |
917 | 917 | * |
918 | 918 | * @param $dest_id string |
919 | - * @param $country_id array |
|
919 | + * @param $country_id array |
|
920 | 920 | * @param $id string |
921 | 921 | */ |
922 | 922 | public function set_country($country_wetu_id, $id) { |
923 | - $country_id = false; |
|
923 | + $country_id = false; |
|
924 | 924 | $this->current_destinations = $this->find_current_destinations(); |
925 | 925 | |
926 | - if (false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($country_wetu_id, $this->current_destinations)) { |
|
927 | - $country_id = $this->current_destinations[$country_wetu_id]; |
|
928 | - } else { |
|
926 | + if (false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($country_wetu_id, $this->current_destinations)) { |
|
927 | + $country_id = $this->current_destinations[$country_wetu_id]; |
|
928 | + } else { |
|
929 | 929 | |
930 | - $country_json = file_get_contents("http://wetu.com/API/Pins/".$this->api_key."/Get?ids=" . $country_wetu_id); |
|
930 | + $country_json = file_get_contents("http://wetu.com/API/Pins/".$this->api_key."/Get?ids=" . $country_wetu_id); |
|
931 | 931 | |
932 | - if ($country_json) { |
|
933 | - $country_data = json_decode($country_json, true); |
|
932 | + if ($country_json) { |
|
933 | + $country_data = json_decode($country_json, true); |
|
934 | 934 | |
935 | - if (!empty($country_data) && !isset($country_data['error'])) { |
|
935 | + if (!empty($country_data) && !isset($country_data['error'])) { |
|
936 | 936 | |
937 | 937 | //Format the title of the destination if its available, otherwise default to the WETU ID. |
938 | - $country_title = $country_wetu_id; |
|
939 | - if (isset($country_data[0]['name'])) { |
|
938 | + $country_title = $country_wetu_id; |
|
939 | + if (isset($country_data[0]['name'])) { |
|
940 | 940 | $country_title = $country_data[0]['name']; |
941 | - } |
|
941 | + } |
|
942 | 942 | |
943 | 943 | $country_id = wp_insert_post(array( |
944 | - 'post_type' => 'destination', |
|
945 | - 'post_status' => 'draft', |
|
946 | - 'post_title' => $country_title |
|
947 | - )); |
|
944 | + 'post_type' => 'destination', |
|
945 | + 'post_status' => 'draft', |
|
946 | + 'post_title' => $country_title |
|
947 | + )); |
|
948 | 948 | //add the country to the current destination stack |
949 | 949 | $this->current_destinations[$country_wetu_id] = $country_id; |
950 | 950 | |
951 | 951 | //Save the wetu field |
952 | - $this->save_custom_field($country_wetu_id, 'lsx_wetu_id', $country_id); |
|
953 | - } |
|
954 | - } |
|
955 | - } |
|
956 | - |
|
957 | - if ('' !== $country_id && false !== $country_id) { |
|
958 | - $this->save_custom_field($country_id, 'destination_to_tour', $id, false, false); |
|
959 | - $this->save_custom_field($id, 'tour_to_destination', $country_id, false, false); |
|
952 | + $this->save_custom_field($country_wetu_id, 'lsx_wetu_id', $country_id); |
|
953 | + } |
|
954 | + } |
|
955 | + } |
|
956 | + |
|
957 | + if ('' !== $country_id && false !== $country_id) { |
|
958 | + $this->save_custom_field($country_id, 'destination_to_tour', $id, false, false); |
|
959 | + $this->save_custom_field($id, 'tour_to_destination', $country_id, false, false); |
|
960 | 960 | $this->cleanup_posts[$country_id] = 'tour_to_destination'; |
961 | 961 | |
962 | - return $country_id; |
|
963 | - } |
|
962 | + return $country_id; |
|
963 | + } |
|
964 | 964 | } |
965 | 965 | } |
966 | 966 | $wetu_importer_tours = new WETU_Importer_Tours(); |
967 | 967 | \ No newline at end of file |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * Display the importer administration screen |
94 | 94 | */ |
95 | 95 | public function display_page() { |
96 | - ?> |
|
96 | + ?> |
|
97 | 97 | <div class="wrap"> |
98 | 98 | <?php screen_icon(); ?> |
99 | 99 | |
@@ -115,8 +115,8 @@ discard block |
||
115 | 115 | </ul> |
116 | 116 | |
117 | 117 | <?php } else { |
118 | - do_action('lsx_tour_importer_admin_tab_'.$_GET['tab']); |
|
119 | - } ?> |
|
118 | + do_action('lsx_tour_importer_admin_tab_'.$_GET['tab']); |
|
119 | + } ?> |
|
120 | 120 | </div> |
121 | 121 | <?php |
122 | 122 | } |
@@ -163,37 +163,37 @@ discard block |
||
163 | 163 | * set_taxonomy with some terms |
164 | 164 | */ |
165 | 165 | public function set_taxonomy($taxonomy,$terms,$id) { |
166 | - $result=array(); |
|
167 | - if(!empty($data)) |
|
168 | - { |
|
169 | - foreach($data as $k) |
|
170 | - { |
|
171 | - if($id) |
|
172 | - { |
|
173 | - if(!$term = term_exists(trim($k), $tax)) |
|
174 | - { |
|
175 | - $term = wp_insert_term(trim($k), $tax); |
|
176 | - if ( is_wp_error($term) ) |
|
177 | - { |
|
178 | - echo $term->get_error_message(); |
|
179 | - } |
|
180 | - else |
|
181 | - { |
|
182 | - wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); |
|
183 | - } |
|
184 | - } |
|
185 | - else |
|
186 | - { |
|
187 | - wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); |
|
188 | - } |
|
189 | - } |
|
190 | - else |
|
191 | - { |
|
192 | - $result[]=trim($k); |
|
193 | - } |
|
194 | - } |
|
195 | - } |
|
196 | - return $result; |
|
166 | + $result=array(); |
|
167 | + if(!empty($data)) |
|
168 | + { |
|
169 | + foreach($data as $k) |
|
170 | + { |
|
171 | + if($id) |
|
172 | + { |
|
173 | + if(!$term = term_exists(trim($k), $tax)) |
|
174 | + { |
|
175 | + $term = wp_insert_term(trim($k), $tax); |
|
176 | + if ( is_wp_error($term) ) |
|
177 | + { |
|
178 | + echo $term->get_error_message(); |
|
179 | + } |
|
180 | + else |
|
181 | + { |
|
182 | + wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); |
|
183 | + } |
|
184 | + } |
|
185 | + else |
|
186 | + { |
|
187 | + wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); |
|
188 | + } |
|
189 | + } |
|
190 | + else |
|
191 | + { |
|
192 | + $result[]=trim($k); |
|
193 | + } |
|
194 | + } |
|
195 | + } |
|
196 | + return $result; |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
@@ -203,21 +203,21 @@ discard block |
||
203 | 203 | if(post_type_exists('team')) { ?> |
204 | 204 | <ul> |
205 | 205 | <?php |
206 | - $team_args=array( |
|
207 | - 'post_type' => 'team', |
|
208 | - 'post_status' => 'publish', |
|
209 | - 'nopagin' => true, |
|
210 | - 'fields' => 'ids' |
|
211 | - ); |
|
212 | - $team_members = new WP_Query($team_args); |
|
213 | - if($team_members->have_posts()){ |
|
214 | - foreach($team_members->posts as $member){ ?> |
|
206 | + $team_args=array( |
|
207 | + 'post_type' => 'team', |
|
208 | + 'post_status' => 'publish', |
|
209 | + 'nopagin' => true, |
|
210 | + 'fields' => 'ids' |
|
211 | + ); |
|
212 | + $team_members = new WP_Query($team_args); |
|
213 | + if($team_members->have_posts()){ |
|
214 | + foreach($team_members->posts as $member){ ?> |
|
215 | 215 | <li><input class="team" <?php $this->checked($selected,$member); ?> type="checkbox" value="<?php echo $member; ?>" /> <?php echo get_the_title($member); ?></li> |
216 | 216 | <?php } |
217 | - }else{ ?> |
|
217 | + }else{ ?> |
|
218 | 218 | <li><input class="team" type="checkbox" value="0" /> <?php _e('None','wetu-importer'); ?></li> |
219 | 219 | <?php } |
220 | - ?> |
|
220 | + ?> |
|
221 | 221 | </ul> |
222 | 222 | <?php } |
223 | 223 | } |
@@ -269,36 +269,36 @@ discard block |
||
269 | 269 | if(false !== $id){ |
270 | 270 | if(empty($this->found_attachments)){ |
271 | 271 | |
272 | - $attachments_args = array( |
|
273 | - 'post_parent' => $id, |
|
274 | - 'post_status' => 'inherit', |
|
275 | - 'post_type' => 'attachment', |
|
276 | - 'order' => 'ASC', |
|
277 | - 'nopagin' => 'true', |
|
278 | - 'posts_per_page' => '-1' |
|
279 | - ); |
|
272 | + $attachments_args = array( |
|
273 | + 'post_parent' => $id, |
|
274 | + 'post_status' => 'inherit', |
|
275 | + 'post_type' => 'attachment', |
|
276 | + 'order' => 'ASC', |
|
277 | + 'nopagin' => 'true', |
|
278 | + 'posts_per_page' => '-1' |
|
279 | + ); |
|
280 | 280 | |
281 | - $attachments = new WP_Query($attachments_args); |
|
282 | - if($attachments->have_posts()){ |
|
283 | - foreach($attachments->posts as $attachment){ |
|
284 | - $this->found_attachments[$attachment->ID] = str_replace(array('.jpg','.png','.jpeg'),'',$attachment->post_title); |
|
285 | - $this->gallery_meta[] = $attachment->ID; |
|
286 | - } |
|
287 | - } |
|
281 | + $attachments = new WP_Query($attachments_args); |
|
282 | + if($attachments->have_posts()){ |
|
283 | + foreach($attachments->posts as $attachment){ |
|
284 | + $this->found_attachments[$attachment->ID] = str_replace(array('.jpg','.png','.jpeg'),'',$attachment->post_title); |
|
285 | + $this->gallery_meta[] = $attachment->ID; |
|
286 | + } |
|
287 | + } |
|
288 | 288 | } |
289 | 289 | } |
290 | 290 | } |
291 | 291 | |
292 | 292 | /** |
293 | 293 | * Checks to see if an item is checked. |
294 | - * |
|
295 | - * @param $haystack array|string |
|
296 | - * @param $needle string |
|
297 | - * @param $echo bool |
|
294 | + * |
|
295 | + * @param $haystack array|string |
|
296 | + * @param $needle string |
|
297 | + * @param $echo bool |
|
298 | 298 | */ |
299 | 299 | public function checked($haystack=false,$needle='',$echo=true) { |
300 | - $return = $this->itemd($haystack,$needle,'checked'); |
|
301 | - if('' !== $return) { |
|
300 | + $return = $this->itemd($haystack,$needle,'checked'); |
|
301 | + if('' !== $return) { |
|
302 | 302 | if (true === $echo) { |
303 | 303 | echo $return; |
304 | 304 | } else { |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | * |
313 | 313 | * @param $haystack array|string |
314 | 314 | * @param $needle string |
315 | - * @param $echo bool |
|
315 | + * @param $echo bool |
|
316 | 316 | */ |
317 | 317 | public function selected($haystack=false,$needle='',$echo=true) { |
318 | 318 | $return = $this->itemd($haystack,$needle,'selected'); |
@@ -330,9 +330,9 @@ discard block |
||
330 | 330 | * |
331 | 331 | * @param $haystack array|string |
332 | 332 | * @param $needle string |
333 | - * @param $type string |
|
334 | - * @param $wrap bool |
|
335 | - * @return $html string |
|
333 | + * @param $type string |
|
334 | + * @param $wrap bool |
|
335 | + * @return $html string |
|
336 | 336 | */ |
337 | 337 | public function itemd($haystack=false,$needle='',$type='',$wrap=true) { |
338 | 338 | $html = ''; |
@@ -341,14 +341,14 @@ discard block |
||
341 | 341 | $haystack = array($haystack); |
342 | 342 | } |
343 | 343 | if (in_array($needle, $haystack)) { |
344 | - if(true === $wrap || 'true' === $wrap) { |
|
344 | + if(true === $wrap || 'true' === $wrap) { |
|
345 | 345 | $html = $type . '"' . $type . '"'; |
346 | 346 | }else{ |
347 | 347 | $html = $type; |
348 | - } |
|
348 | + } |
|
349 | 349 | } |
350 | 350 | } |
351 | - return $html; |
|
351 | + return $html; |
|
352 | 352 | |
353 | 353 | } |
354 | 354 | |
@@ -358,26 +358,26 @@ discard block |
||
358 | 358 | * @param $tab string |
359 | 359 | */ |
360 | 360 | public function navigation($tab='') { |
361 | - $post_types = array( |
|
362 | - 'tour' => esc_attr('Tours','wetu-importer'), |
|
363 | - 'accommodation' => esc_attr('Accommodation','wetu-importer'), |
|
364 | - 'destination' => esc_attr('Destinations','wetu-importer'), |
|
365 | - ); |
|
361 | + $post_types = array( |
|
362 | + 'tour' => esc_attr('Tours','wetu-importer'), |
|
363 | + 'accommodation' => esc_attr('Accommodation','wetu-importer'), |
|
364 | + 'destination' => esc_attr('Destinations','wetu-importer'), |
|
365 | + ); |
|
366 | 366 | |
367 | 367 | |
368 | 368 | echo '<div class="wet-navigation"><div class="subsubsub"><a class="'.$this->itemd($tab,'','current',false).'" href="'.admin_url('admin.php').'?page='.$this->plugin_slug.'">'.esc_attr('Home','wetu-importer').'</a>'; |
369 | 369 | foreach($post_types as $post_type => $label){ |
370 | - echo ' | <a class="'.$this->itemd($tab,$post_type,'current',false).'" href="'.admin_url('admin.php').'?page='.$this->plugin_slug.'&tab='.$post_type.'">'.$label.'</a>'; |
|
371 | - } |
|
372 | - echo '</div><br clear="both"/></div>'; |
|
370 | + echo ' | <a class="'.$this->itemd($tab,$post_type,'current',false).'" href="'.admin_url('admin.php').'?page='.$this->plugin_slug.'&tab='.$post_type.'">'.$label.'</a>'; |
|
371 | + } |
|
372 | + echo '</div><br clear="both"/></div>'; |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | /** |
376 | 376 | * Grabs the custom fields, and resaves an array of unique items. |
377 | 377 | */ |
378 | 378 | public function cleanup_posts() { |
379 | - if(!empty($this->cleanup_posts)){ |
|
380 | - foreach($this->cleanup_posts as $id => $key) { |
|
379 | + if(!empty($this->cleanup_posts)){ |
|
380 | + foreach($this->cleanup_posts as $id => $key) { |
|
381 | 381 | $prev_items = get_post_meta($id, $key, false); |
382 | 382 | $new_items = array_unique($prev_items); |
383 | 383 | delete_post_meta($id, $key); |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | add_post_meta($id, $key, $new_item, false); |
386 | 386 | } |
387 | 387 | } |
388 | - } |
|
388 | + } |
|
389 | 389 | } |
390 | 390 | |
391 | 391 |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | * Display the importer administration screen |
137 | 137 | */ |
138 | 138 | public function display_page() { |
139 | - ?> |
|
139 | + ?> |
|
140 | 140 | <div class="wrap"> |
141 | 141 | <?php $this->navigation('accommodation'); ?> |
142 | 142 | |
@@ -315,8 +315,8 @@ discard block |
||
315 | 315 | $accommodation = json_decode($data, true); |
316 | 316 | |
317 | 317 | if(isset($accommodation['error'])){ |
318 | - return $accommodation['error']; |
|
319 | - }elseif (isset($accommodation) && !empty($accommodation)) { |
|
318 | + return $accommodation['error']; |
|
319 | + }elseif (isset($accommodation) && !empty($accommodation)) { |
|
320 | 320 | set_transient('lsx_ti_accommodation',$accommodation,60*60*2); |
321 | 321 | return true; |
322 | 322 | } |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | $keyphrases = $_POST['keyword']; |
365 | 365 | }else{ |
366 | 366 | $keyphrases = array(0); |
367 | - } |
|
367 | + } |
|
368 | 368 | |
369 | 369 | if(!is_array($keyphrases)){ |
370 | 370 | $keyphrases = array($keyphrases); |
@@ -461,13 +461,13 @@ discard block |
||
461 | 461 | public function multineedle_stripos($haystack, $needles, $offset=0) { |
462 | 462 | $found = false; |
463 | 463 | $needle_count = count($needles); |
464 | - foreach($needles as $needle) { |
|
465 | - if(false !== stripos($haystack, $needle, $offset)){ |
|
466 | - $found[] = true; |
|
467 | - } |
|
468 | - } |
|
469 | - if(false !== $found && $needle_count === count($found)){ |
|
470 | - return true; |
|
464 | + foreach($needles as $needle) { |
|
465 | + if(false !== stripos($haystack, $needle, $offset)){ |
|
466 | + $found[] = true; |
|
467 | + } |
|
468 | + } |
|
469 | + if(false !== $found && $needle_count === count($found)){ |
|
470 | + return true; |
|
471 | 471 | }else{ |
472 | 472 | return false; |
473 | 473 | } |
@@ -538,17 +538,17 @@ discard block |
||
538 | 538 | $content = false; |
539 | 539 | } |
540 | 540 | |
541 | - $jdata = file_get_contents( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id ); |
|
542 | - if($jdata) |
|
543 | - { |
|
544 | - $adata=json_decode($jdata,true); |
|
545 | - if(!empty($adata)) |
|
546 | - { |
|
547 | - $return = $this->import_row($adata,$wetu_id,$post_id,$team_members,$content,$safari_brands); |
|
548 | - $this->format_completed_row($return); |
|
541 | + $jdata = file_get_contents( $this->url . '/Get?' . $this->url_qs . '&ids=' . $wetu_id ); |
|
542 | + if($jdata) |
|
543 | + { |
|
544 | + $adata=json_decode($jdata,true); |
|
545 | + if(!empty($adata)) |
|
546 | + { |
|
547 | + $return = $this->import_row($adata,$wetu_id,$post_id,$team_members,$content,$safari_brands); |
|
548 | + $this->format_completed_row($return); |
|
549 | 549 | $this->cleanup_posts(); |
550 | - } |
|
551 | - } |
|
550 | + } |
|
551 | + } |
|
552 | 552 | |
553 | 553 | die(); |
554 | 554 | } |
@@ -565,147 +565,147 @@ discard block |
||
565 | 565 | */ |
566 | 566 | public function import_row($data,$wetu_id,$id=0,$team_members=false,$importable_content=false,$safari_brands=false) { |
567 | 567 | |
568 | - if(trim($data[0]['type'])=='Accommodation') |
|
569 | - { |
|
570 | - $post_name = $data_post_content = $data_post_excerpt = ''; |
|
571 | - $post = array( |
|
572 | - 'post_type' => 'accommodation', |
|
573 | - ); |
|
574 | - |
|
575 | - $content_used_general_description = false; |
|
576 | - |
|
577 | - //Set the post_content |
|
578 | - if(false !== $importable_content && in_array('description',$importable_content)){ |
|
579 | - if(isset($data[0]['content']['extended_description'])) |
|
580 | - { |
|
581 | - $data_post_content = $data[0]['content']['extended_description']; |
|
582 | - }elseif(isset($data[0]['content']['general_description'])){ |
|
583 | - $data_post_content = $data[0]['content']['general_description']; |
|
584 | - $content_used_general_description = true; |
|
585 | - }elseif(isset($data[0]['content']['teaser_description'])){ |
|
586 | - $data_post_content = $data[0]['content']['teaser_description']; |
|
587 | - } |
|
588 | - $post['post_content'] = wp_strip_all_tags($data_post_content); |
|
589 | - } |
|
590 | - |
|
591 | - //set the post_excerpt |
|
592 | - if(false !== $importable_content && in_array('excerpt',$importable_content)){ |
|
593 | - if(isset($data[0]['content']['teaser_description'])){ |
|
594 | - $data_post_excerpt = $data[0]['content']['teaser_description']; |
|
595 | - }elseif(isset($data[0]['content']['general_description']) && false === $content_used_general_description){ |
|
596 | - $data_post_excerpt = $data[0]['content']['general_description']; |
|
597 | - } |
|
598 | - $post['post_excerpt'] = $data_post_excerpt; |
|
599 | - } |
|
600 | - |
|
601 | - if(false !== $id && '0' !== $id){ |
|
602 | - $post['ID'] = $id; |
|
568 | + if(trim($data[0]['type'])=='Accommodation') |
|
569 | + { |
|
570 | + $post_name = $data_post_content = $data_post_excerpt = ''; |
|
571 | + $post = array( |
|
572 | + 'post_type' => 'accommodation', |
|
573 | + ); |
|
574 | + |
|
575 | + $content_used_general_description = false; |
|
576 | + |
|
577 | + //Set the post_content |
|
578 | + if(false !== $importable_content && in_array('description',$importable_content)){ |
|
579 | + if(isset($data[0]['content']['extended_description'])) |
|
580 | + { |
|
581 | + $data_post_content = $data[0]['content']['extended_description']; |
|
582 | + }elseif(isset($data[0]['content']['general_description'])){ |
|
583 | + $data_post_content = $data[0]['content']['general_description']; |
|
584 | + $content_used_general_description = true; |
|
585 | + }elseif(isset($data[0]['content']['teaser_description'])){ |
|
586 | + $data_post_content = $data[0]['content']['teaser_description']; |
|
587 | + } |
|
588 | + $post['post_content'] = wp_strip_all_tags($data_post_content); |
|
589 | + } |
|
590 | + |
|
591 | + //set the post_excerpt |
|
592 | + if(false !== $importable_content && in_array('excerpt',$importable_content)){ |
|
593 | + if(isset($data[0]['content']['teaser_description'])){ |
|
594 | + $data_post_excerpt = $data[0]['content']['teaser_description']; |
|
595 | + }elseif(isset($data[0]['content']['general_description']) && false === $content_used_general_description){ |
|
596 | + $data_post_excerpt = $data[0]['content']['general_description']; |
|
597 | + } |
|
598 | + $post['post_excerpt'] = $data_post_excerpt; |
|
599 | + } |
|
600 | + |
|
601 | + if(false !== $id && '0' !== $id){ |
|
602 | + $post['ID'] = $id; |
|
603 | 603 | if(isset($data[0]['name'])){ |
604 | 604 | $post['post_title'] = $data[0]['name']; |
605 | - $post['post_status'] = 'publish'; |
|
605 | + $post['post_status'] = 'publish'; |
|
606 | 606 | $post['post_name'] = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'accommodation', 0); |
607 | 607 | } |
608 | - $id = wp_update_post($post); |
|
609 | - $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
610 | - update_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified']),$prev_date); |
|
611 | - }else{ |
|
612 | - |
|
613 | - //Set the name |
|
614 | - if(isset($data[0]['name'])){ |
|
615 | - $post_name = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'accommodation', 0); |
|
616 | - } |
|
617 | - $post['post_name'] = $post_name; |
|
618 | - $post['post_title'] = $data[0]['name']; |
|
619 | - $post['post_status'] = 'publish'; |
|
620 | - $id = wp_insert_post($post); |
|
621 | - |
|
622 | - //Save the WETU ID and the Last date it was modified. |
|
623 | - if(false !== $id){ |
|
624 | - add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
625 | - add_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified'])); |
|
626 | - } |
|
627 | - } |
|
628 | - //Setup some default for use in the import |
|
629 | - if(false !== $importable_content && (in_array('gallery',$importable_content) || in_array('banner_image',$importable_content) || in_array('featured_image',$importable_content))){ |
|
608 | + $id = wp_update_post($post); |
|
609 | + $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
610 | + update_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified']),$prev_date); |
|
611 | + }else{ |
|
612 | + |
|
613 | + //Set the name |
|
614 | + if(isset($data[0]['name'])){ |
|
615 | + $post_name = wp_unique_post_slug(sanitize_title($data[0]['name']),$id, 'draft', 'accommodation', 0); |
|
616 | + } |
|
617 | + $post['post_name'] = $post_name; |
|
618 | + $post['post_title'] = $data[0]['name']; |
|
619 | + $post['post_status'] = 'publish'; |
|
620 | + $id = wp_insert_post($post); |
|
621 | + |
|
622 | + //Save the WETU ID and the Last date it was modified. |
|
623 | + if(false !== $id){ |
|
624 | + add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
625 | + add_post_meta($id,'lsx_wetu_modified_date',strtotime($data[0]['last_modified'])); |
|
626 | + } |
|
627 | + } |
|
628 | + //Setup some default for use in the import |
|
629 | + if(false !== $importable_content && (in_array('gallery',$importable_content) || in_array('banner_image',$importable_content) || in_array('featured_image',$importable_content))){ |
|
630 | 630 | $this->find_attachments($id); |
631 | 631 | } |
632 | 632 | |
633 | - //Set the team member if it is there |
|
634 | - if(post_type_exists('team') && false !== $team_members && '' !== $team_members){ |
|
635 | - $this->set_team_member($id,$team_members); |
|
636 | - } |
|
637 | - |
|
638 | - //Set the safari brand |
|
639 | - if(false !== $safari_brands && '' !== $safari_brands){ |
|
640 | - $this->set_safari_brands($id,$safari_brands); |
|
641 | - |
|
642 | - } |
|
643 | - |
|
644 | - if(class_exists('LSX_TO_Maps')){ |
|
645 | - $this->set_map_data($data,$id,9); |
|
646 | - } |
|
647 | - |
|
648 | - if(post_type_exists('destination') && false !== $importable_content && in_array('destination',$importable_content)){ |
|
649 | - $this->connect_destinations($data,$id); |
|
650 | - } |
|
651 | - |
|
652 | - if(false !== $importable_content && in_array('category',$importable_content)){ |
|
653 | - $this->set_taxonomy_style($data,$id); |
|
654 | - } |
|
655 | - |
|
656 | - //Set the Room Data |
|
657 | - if(false !== $importable_content && in_array('rooms',$importable_content)){ |
|
658 | - $this->set_room_data($data,$id); |
|
659 | - } |
|
660 | - |
|
661 | - //Set the rating |
|
662 | - if(false !== $importable_content && in_array('rating',$importable_content)){ |
|
663 | - $this->set_rating($data,$id); |
|
664 | - } |
|
665 | - |
|
666 | - //Set the checkin checkout data |
|
667 | - if(false !== $importable_content && in_array('checkin',$importable_content)){ |
|
668 | - $this->set_checkin_checkout($data,$id); |
|
669 | - } |
|
670 | - |
|
671 | - //Set the Spoken Languages |
|
672 | - if(false !== $importable_content && in_array('spoken_languages',$importable_content)){ |
|
673 | - $this->set_spoken_languages($data,$id); |
|
674 | - } |
|
675 | - |
|
676 | - //Set the friendly options |
|
677 | - if(false !== $importable_content && in_array('friendly',$importable_content)){ |
|
678 | - $this->set_friendly($data,$id); |
|
679 | - } |
|
680 | - |
|
681 | - //Set the special_interests |
|
682 | - if(false !== $importable_content && in_array('special_interests',$importable_content)){ |
|
683 | - $this->set_special_interests($data,$id); |
|
684 | - } |
|
685 | - |
|
686 | - //Import the videos |
|
687 | - if(false !== $importable_content && in_array('videos',$importable_content)){ |
|
688 | - $this->set_video_data($data,$id); |
|
689 | - } |
|
690 | - |
|
691 | - //Import the facilities |
|
692 | - if(false !== $importable_content && in_array('facilities',$importable_content)){ |
|
693 | - $this->set_facilities($data,$id); |
|
694 | - } |
|
695 | - |
|
696 | - //Set the featured image |
|
697 | - if(false !== $importable_content && in_array('featured_image',$importable_content)){ |
|
698 | - $this->set_featured_image($data,$id); |
|
699 | - } |
|
700 | - if(false !== $importable_content && in_array('banner_image',$importable_content)){ |
|
701 | - $this->set_banner_image($data,$id); |
|
702 | - } |
|
703 | - //Import the main gallery |
|
704 | - if(false !== $importable_content && in_array('gallery',$importable_content)){ |
|
705 | - $this->create_main_gallery($data,$id); |
|
706 | - } |
|
707 | - } |
|
708 | - return $id; |
|
633 | + //Set the team member if it is there |
|
634 | + if(post_type_exists('team') && false !== $team_members && '' !== $team_members){ |
|
635 | + $this->set_team_member($id,$team_members); |
|
636 | + } |
|
637 | + |
|
638 | + //Set the safari brand |
|
639 | + if(false !== $safari_brands && '' !== $safari_brands){ |
|
640 | + $this->set_safari_brands($id,$safari_brands); |
|
641 | + |
|
642 | + } |
|
643 | + |
|
644 | + if(class_exists('LSX_TO_Maps')){ |
|
645 | + $this->set_map_data($data,$id,9); |
|
646 | + } |
|
647 | + |
|
648 | + if(post_type_exists('destination') && false !== $importable_content && in_array('destination',$importable_content)){ |
|
649 | + $this->connect_destinations($data,$id); |
|
650 | + } |
|
651 | + |
|
652 | + if(false !== $importable_content && in_array('category',$importable_content)){ |
|
653 | + $this->set_taxonomy_style($data,$id); |
|
654 | + } |
|
655 | + |
|
656 | + //Set the Room Data |
|
657 | + if(false !== $importable_content && in_array('rooms',$importable_content)){ |
|
658 | + $this->set_room_data($data,$id); |
|
659 | + } |
|
660 | + |
|
661 | + //Set the rating |
|
662 | + if(false !== $importable_content && in_array('rating',$importable_content)){ |
|
663 | + $this->set_rating($data,$id); |
|
664 | + } |
|
665 | + |
|
666 | + //Set the checkin checkout data |
|
667 | + if(false !== $importable_content && in_array('checkin',$importable_content)){ |
|
668 | + $this->set_checkin_checkout($data,$id); |
|
669 | + } |
|
670 | + |
|
671 | + //Set the Spoken Languages |
|
672 | + if(false !== $importable_content && in_array('spoken_languages',$importable_content)){ |
|
673 | + $this->set_spoken_languages($data,$id); |
|
674 | + } |
|
675 | + |
|
676 | + //Set the friendly options |
|
677 | + if(false !== $importable_content && in_array('friendly',$importable_content)){ |
|
678 | + $this->set_friendly($data,$id); |
|
679 | + } |
|
680 | + |
|
681 | + //Set the special_interests |
|
682 | + if(false !== $importable_content && in_array('special_interests',$importable_content)){ |
|
683 | + $this->set_special_interests($data,$id); |
|
684 | + } |
|
685 | + |
|
686 | + //Import the videos |
|
687 | + if(false !== $importable_content && in_array('videos',$importable_content)){ |
|
688 | + $this->set_video_data($data,$id); |
|
689 | + } |
|
690 | + |
|
691 | + //Import the facilities |
|
692 | + if(false !== $importable_content && in_array('facilities',$importable_content)){ |
|
693 | + $this->set_facilities($data,$id); |
|
694 | + } |
|
695 | + |
|
696 | + //Set the featured image |
|
697 | + if(false !== $importable_content && in_array('featured_image',$importable_content)){ |
|
698 | + $this->set_featured_image($data,$id); |
|
699 | + } |
|
700 | + if(false !== $importable_content && in_array('banner_image',$importable_content)){ |
|
701 | + $this->set_banner_image($data,$id); |
|
702 | + } |
|
703 | + //Import the main gallery |
|
704 | + if(false !== $importable_content && in_array('gallery',$importable_content)){ |
|
705 | + $this->create_main_gallery($data,$id); |
|
706 | + } |
|
707 | + } |
|
708 | + return $id; |
|
709 | 709 | } |
710 | 710 | |
711 | 711 | /** |
@@ -715,7 +715,7 @@ discard block |
||
715 | 715 | |
716 | 716 | delete_post_meta($id, 'team_to_'.$this->tab_slug); |
717 | 717 | foreach($team_members as $team){ |
718 | - add_post_meta($id,'team_to_'.$this->tab_slug,$team); |
|
718 | + add_post_meta($id,'team_to_'.$this->tab_slug,$team); |
|
719 | 719 | } |
720 | 720 | } |
721 | 721 | |
@@ -724,7 +724,7 @@ discard block |
||
724 | 724 | */ |
725 | 725 | public function set_safari_brands($id,$safari_brands) { |
726 | 726 | foreach($safari_brands as $safari_brand){ |
727 | - wp_set_object_terms( $id, intval($safari_brand), 'accommodation-brand',true); |
|
727 | + wp_set_object_terms( $id, intval($safari_brand), 'accommodation-brand',true); |
|
728 | 728 | } |
729 | 729 | } |
730 | 730 | |
@@ -774,11 +774,11 @@ discard block |
||
774 | 774 | 'elevation' => '', |
775 | 775 | ); |
776 | 776 | if(false !== $id && '0' !== $id){ |
777 | - $prev = get_post_meta($id,'location',true); |
|
778 | - update_post_meta($id,'location',$location_data,$prev); |
|
779 | - }else{ |
|
780 | - add_post_meta($id,'location',$location_data,true); |
|
781 | - } |
|
777 | + $prev = get_post_meta($id,'location',true); |
|
778 | + update_post_meta($id,'location',$location_data,$prev); |
|
779 | + }else{ |
|
780 | + add_post_meta($id,'location',$location_data,true); |
|
781 | + } |
|
782 | 782 | } |
783 | 783 | } |
784 | 784 | |
@@ -787,32 +787,32 @@ discard block |
||
787 | 787 | */ |
788 | 788 | public function connect_destinations($data,$id) { |
789 | 789 | if(isset($data[0]['position'])){ |
790 | - $destinations = false; |
|
791 | - if(isset($data[0]['position']['country'])){ |
|
792 | - $destinations['country'] = $data[0]['position']['country']; |
|
793 | - } |
|
794 | - if(isset($data[0]['position']['destination'])){ |
|
795 | - $destinations['destination'] = $data[0]['position']['destination']; |
|
796 | - } |
|
790 | + $destinations = false; |
|
791 | + if(isset($data[0]['position']['country'])){ |
|
792 | + $destinations['country'] = $data[0]['position']['country']; |
|
793 | + } |
|
794 | + if(isset($data[0]['position']['destination'])){ |
|
795 | + $destinations['destination'] = $data[0]['position']['destination']; |
|
796 | + } |
|
797 | 797 | |
798 | - if(false !== $destinations){ |
|
799 | - $prev_values = get_post_meta($id,'destination_to_accommodation',false); |
|
800 | - if(false === $prev_values || !is_array($prev_values)){ |
|
801 | - $prev_values = array(); |
|
802 | - } |
|
803 | - //print_r($destinations); |
|
798 | + if(false !== $destinations){ |
|
799 | + $prev_values = get_post_meta($id,'destination_to_accommodation',false); |
|
800 | + if(false === $prev_values || !is_array($prev_values)){ |
|
801 | + $prev_values = array(); |
|
802 | + } |
|
803 | + //print_r($destinations); |
|
804 | 804 | $destinations = array_unique($destinations); |
805 | 805 | //print_r($destinations); |
806 | - foreach($destinations as $key => $value){ |
|
807 | - $destination = get_page_by_title(ltrim(rtrim($value)), 'OBJECT', 'destination'); |
|
808 | - if (null !== $destination) { |
|
809 | - if(!in_array($destination->ID,$prev_values)){ |
|
810 | - add_post_meta($id,'destination_to_accommodation',$destination->ID,false); |
|
811 | - add_post_meta($destination->ID,'accommodation_to_destination',$id,false); |
|
806 | + foreach($destinations as $key => $value){ |
|
807 | + $destination = get_page_by_title(ltrim(rtrim($value)), 'OBJECT', 'destination'); |
|
808 | + if (null !== $destination) { |
|
809 | + if(!in_array($destination->ID,$prev_values)){ |
|
810 | + add_post_meta($id,'destination_to_accommodation',$destination->ID,false); |
|
811 | + add_post_meta($destination->ID,'accommodation_to_destination',$id,false); |
|
812 | 812 | $this->cleanup_posts[$destination->ID] = 'accommodation_to_destination'; |
813 | - } |
|
814 | - } |
|
815 | - } |
|
813 | + } |
|
814 | + } |
|
815 | + } |
|
816 | 816 | } |
817 | 817 | } |
818 | 818 | } |
@@ -824,15 +824,15 @@ discard block |
||
824 | 824 | $terms = false; |
825 | 825 | if(isset($data[0]['category'])){ |
826 | 826 | if(!$term = term_exists(trim($data[0]['category']), 'accommodation-type')) |
827 | - { |
|
828 | - $term = wp_insert_term(trim($data[0]['category']), 'accommodation-type'); |
|
829 | - if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
830 | - else { wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); } |
|
831 | - } |
|
832 | - else |
|
833 | - { |
|
834 | - wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); |
|
835 | - } |
|
827 | + { |
|
828 | + $term = wp_insert_term(trim($data[0]['category']), 'accommodation-type'); |
|
829 | + if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
830 | + else { wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); } |
|
831 | + } |
|
832 | + else |
|
833 | + { |
|
834 | + wp_set_object_terms( $id, intval($term['term_id']), 'accommodation-type',true); |
|
835 | + } |
|
836 | 836 | } |
837 | 837 | } |
838 | 838 | |
@@ -856,25 +856,25 @@ discard block |
||
856 | 856 | $temp_room['type'] = 'room'; |
857 | 857 | |
858 | 858 | if(!empty($room['images']) && is_array($room['images'])){ |
859 | - $attachments_args = array( |
|
860 | - 'post_parent' => $id, |
|
861 | - 'post_status' => 'inherit', |
|
862 | - 'post_type' => 'attachment', |
|
863 | - 'order' => 'ASC', |
|
864 | - ); |
|
865 | - $attachments = new WP_Query($attachments_args); |
|
866 | - $found_attachments = array(); |
|
867 | - |
|
868 | - if($attachments->have_posts()){ |
|
869 | - foreach($attachments->posts as $attachment){ |
|
870 | - $found_attachments[] = str_replace(array('.jpg','.png','.jpeg'),'',$attachment->post_title); |
|
871 | - } |
|
872 | - } |
|
859 | + $attachments_args = array( |
|
860 | + 'post_parent' => $id, |
|
861 | + 'post_status' => 'inherit', |
|
862 | + 'post_type' => 'attachment', |
|
863 | + 'order' => 'ASC', |
|
864 | + ); |
|
865 | + $attachments = new WP_Query($attachments_args); |
|
866 | + $found_attachments = array(); |
|
867 | + |
|
868 | + if($attachments->have_posts()){ |
|
869 | + foreach($attachments->posts as $attachment){ |
|
870 | + $found_attachments[] = str_replace(array('.jpg','.png','.jpeg'),'',$attachment->post_title); |
|
871 | + } |
|
872 | + } |
|
873 | 873 | |
874 | 874 | $temp_room['gallery'] = array(); |
875 | 875 | foreach($room['images'] as $image_data){ |
876 | - $temp_room['gallery'][] = $this->attach_image($image_data,$id,$found_attachments); |
|
877 | - } |
|
876 | + $temp_room['gallery'][] = $this->attach_image($image_data,$id,$found_attachments); |
|
877 | + } |
|
878 | 878 | } |
879 | 879 | $rooms[] = $temp_room; |
880 | 880 | } |
@@ -883,7 +883,7 @@ discard block |
||
883 | 883 | delete_post_meta($id, 'units'); |
884 | 884 | } |
885 | 885 | foreach($rooms as $room){ |
886 | - add_post_meta($id,'units',$room,false); |
|
886 | + add_post_meta($id,'units',$room,false); |
|
887 | 887 | } |
888 | 888 | |
889 | 889 | if(isset($data[0]['features']) && isset($data[0]['features']['rooms'])){ |
@@ -893,11 +893,11 @@ discard block |
||
893 | 893 | } |
894 | 894 | |
895 | 895 | if(false !== $id && '0' !== $id){ |
896 | - $prev_rooms = get_post_meta($id,'number_of_rooms',true); |
|
897 | - update_post_meta($id,'number_of_rooms',$room_count,$prev_rooms); |
|
898 | - }else{ |
|
899 | - add_post_meta($id,'number_of_rooms',$room_count,true); |
|
900 | - } |
|
896 | + $prev_rooms = get_post_meta($id,'number_of_rooms',true); |
|
897 | + update_post_meta($id,'number_of_rooms',$room_count,$prev_rooms); |
|
898 | + }else{ |
|
899 | + add_post_meta($id,'number_of_rooms',$room_count,true); |
|
900 | + } |
|
901 | 901 | } |
902 | 902 | } |
903 | 903 | |
@@ -1007,7 +1007,7 @@ discard block |
||
1007 | 1007 | delete_post_meta($id, 'videos'); |
1008 | 1008 | } |
1009 | 1009 | foreach($videos as $video){ |
1010 | - add_post_meta($id,'videos',$video,false); |
|
1010 | + add_post_meta($id,'videos',$video,false); |
|
1011 | 1011 | } |
1012 | 1012 | } |
1013 | 1013 | } |
@@ -1036,17 +1036,17 @@ discard block |
||
1036 | 1036 | |
1037 | 1037 | function set_term($id=false,$name=false,$taxonomy=false,$parent=false){ |
1038 | 1038 | if(!$term = term_exists($name, $taxonomy)) |
1039 | - { |
|
1040 | - if(false !== $parent){ $parent = array('parent'=>$parent); } |
|
1041 | - $term = wp_insert_term(trim($name), $taxonomy,$parent); |
|
1042 | - if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
1043 | - else { wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); } |
|
1044 | - } |
|
1045 | - else |
|
1046 | - { |
|
1047 | - wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); |
|
1048 | - } |
|
1049 | - return $term['term_id']; |
|
1039 | + { |
|
1040 | + if(false !== $parent){ $parent = array('parent'=>$parent); } |
|
1041 | + $term = wp_insert_term(trim($name), $taxonomy,$parent); |
|
1042 | + if ( is_wp_error($term) ){echo $term->get_error_message();} |
|
1043 | + else { wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); } |
|
1044 | + } |
|
1045 | + else |
|
1046 | + { |
|
1047 | + wp_set_object_terms( $id, intval($term['term_id']), $taxonomy,true); |
|
1048 | + } |
|
1049 | + return $term['term_id']; |
|
1050 | 1050 | } |
1051 | 1051 | |
1052 | 1052 | /** |
@@ -1054,17 +1054,17 @@ discard block |
||
1054 | 1054 | */ |
1055 | 1055 | public function set_featured_image($data,$id) { |
1056 | 1056 | if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){ |
1057 | - $this->featured_image = $this->attach_image($data[0]['content']['images'][0],$id); |
|
1057 | + $this->featured_image = $this->attach_image($data[0]['content']['images'][0],$id); |
|
1058 | 1058 | |
1059 | - if(false !== $this->featured_image){ |
|
1060 | - delete_post_meta($id,'_thumbnail_id'); |
|
1061 | - add_post_meta($id,'_thumbnail_id',$this->featured_image,true); |
|
1059 | + if(false !== $this->featured_image){ |
|
1060 | + delete_post_meta($id,'_thumbnail_id'); |
|
1061 | + add_post_meta($id,'_thumbnail_id',$this->featured_image,true); |
|
1062 | 1062 | |
1063 | - if(!empty($this->gallery_meta) && !in_array($this->featured_image,$this->gallery_meta)){ |
|
1064 | - add_post_meta($id,'gallery',$this->featured_image,false); |
|
1065 | - $this->gallery_meta[] = $this->featured_image; |
|
1066 | - } |
|
1067 | - } |
|
1063 | + if(!empty($this->gallery_meta) && !in_array($this->featured_image,$this->gallery_meta)){ |
|
1064 | + add_post_meta($id,'gallery',$this->featured_image,false); |
|
1065 | + $this->gallery_meta[] = $this->featured_image; |
|
1066 | + } |
|
1067 | + } |
|
1068 | 1068 | } |
1069 | 1069 | } |
1070 | 1070 | |
@@ -1073,18 +1073,18 @@ discard block |
||
1073 | 1073 | */ |
1074 | 1074 | public function set_banner_image($data,$id) { |
1075 | 1075 | if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){ |
1076 | - $this->banner_image = $this->attach_image($data[0]['content']['images'][1],$id,array('width'=>'1920','height'=>'800','cropping'=>'c')); |
|
1077 | - |
|
1078 | - if(false !== $this->banner_image){ |
|
1079 | - delete_post_meta($id,'image_group'); |
|
1080 | - $new_banner = array('banner_image'=>array('cmb-field-0'=>$this->banner_image)); |
|
1081 | - add_post_meta($id,'image_group',$new_banner,true); |
|
1082 | - |
|
1083 | - if(!empty($this->gallery_meta) && !in_array($this->banner_image,$this->gallery_meta)){ |
|
1084 | - add_post_meta($id,'gallery',$this->banner_image,false); |
|
1085 | - $this->gallery_meta[] = $this->banner_image; |
|
1086 | - } |
|
1087 | - } |
|
1076 | + $this->banner_image = $this->attach_image($data[0]['content']['images'][1],$id,array('width'=>'1920','height'=>'800','cropping'=>'c')); |
|
1077 | + |
|
1078 | + if(false !== $this->banner_image){ |
|
1079 | + delete_post_meta($id,'image_group'); |
|
1080 | + $new_banner = array('banner_image'=>array('cmb-field-0'=>$this->banner_image)); |
|
1081 | + add_post_meta($id,'image_group',$new_banner,true); |
|
1082 | + |
|
1083 | + if(!empty($this->gallery_meta) && !in_array($this->banner_image,$this->gallery_meta)){ |
|
1084 | + add_post_meta($id,'gallery',$this->banner_image,false); |
|
1085 | + $this->gallery_meta[] = $this->banner_image; |
|
1086 | + } |
|
1087 | + } |
|
1088 | 1088 | } |
1089 | 1089 | } |
1090 | 1090 | |
@@ -1094,25 +1094,25 @@ discard block |
||
1094 | 1094 | public function create_main_gallery($data,$id) { |
1095 | 1095 | |
1096 | 1096 | if(is_array($data[0]['content']['images']) && !empty($data[0]['content']['images'])){ |
1097 | - $counter = 0; |
|
1098 | - foreach($data[0]['content']['images'] as $image_data){ |
|
1099 | - if($counter === 0 && false !== $this->featured_image){$counter++;continue;} |
|
1100 | - if($counter === 1 && false !== $this->banner_image){$counter++;continue;} |
|
1097 | + $counter = 0; |
|
1098 | + foreach($data[0]['content']['images'] as $image_data){ |
|
1099 | + if($counter === 0 && false !== $this->featured_image){$counter++;continue;} |
|
1100 | + if($counter === 1 && false !== $this->banner_image){$counter++;continue;} |
|
1101 | 1101 | |
1102 | - $this->gallery_meta[] = $this->attach_image($image_data,$id); |
|
1103 | - $counter++; |
|
1104 | - } |
|
1102 | + $this->gallery_meta[] = $this->attach_image($image_data,$id); |
|
1103 | + $counter++; |
|
1104 | + } |
|
1105 | 1105 | |
1106 | - if(!empty($this->gallery_meta)){ |
|
1107 | - delete_post_meta($id,'gallery'); |
|
1106 | + if(!empty($this->gallery_meta)){ |
|
1107 | + delete_post_meta($id,'gallery'); |
|
1108 | 1108 | $this->gallery_meta = array_unique($this->gallery_meta); |
1109 | - foreach($this->gallery_meta as $gallery_id){ |
|
1110 | - if(false !== $gallery_id && '' !== $gallery_id && !is_array($gallery_id)){ |
|
1111 | - add_post_meta($id,'gallery',$gallery_id,false); |
|
1112 | - } |
|
1113 | - } |
|
1114 | - } |
|
1115 | - } |
|
1109 | + foreach($this->gallery_meta as $gallery_id){ |
|
1110 | + if(false !== $gallery_id && '' !== $gallery_id && !is_array($gallery_id)){ |
|
1111 | + add_post_meta($id,'gallery',$gallery_id,false); |
|
1112 | + } |
|
1113 | + } |
|
1114 | + } |
|
1115 | + } |
|
1116 | 1116 | } |
1117 | 1117 | |
1118 | 1118 | /** |
@@ -1121,42 +1121,42 @@ discard block |
||
1121 | 1121 | public function attach_image($v=false,$parent_id,$image_sizes=false){ |
1122 | 1122 | if(false !== $v){ |
1123 | 1123 | $temp_fragment = explode('/',$v['url_fragment']); |
1124 | - $url_filename = $temp_fragment[count($temp_fragment)-1]; |
|
1125 | - $url_filename = str_replace(array('.jpg','.png','.jpeg'),'',$url_filename); |
|
1124 | + $url_filename = $temp_fragment[count($temp_fragment)-1]; |
|
1125 | + $url_filename = str_replace(array('.jpg','.png','.jpeg'),'',$url_filename); |
|
1126 | 1126 | |
1127 | - if(in_array($url_filename,$this->found_attachments)){ |
|
1128 | - return array_search($url_filename,$this->found_attachments); |
|
1129 | - } |
|
1127 | + if(in_array($url_filename,$this->found_attachments)){ |
|
1128 | + return array_search($url_filename,$this->found_attachments); |
|
1129 | + } |
|
1130 | 1130 | |
1131 | - $postdata=array(); |
|
1132 | - if(empty($v['label'])) |
|
1133 | - { |
|
1134 | - $v['label']=''; |
|
1135 | - } |
|
1136 | - if(!empty($v['description'])) |
|
1137 | - { |
|
1138 | - $desc=wp_strip_all_tags($v['description']); |
|
1139 | - $posdata=array('post_excerpt'=>$desc); |
|
1140 | - } |
|
1141 | - if(!empty($v['section'])) |
|
1142 | - { |
|
1143 | - $desc=wp_strip_all_tags($v['section']); |
|
1144 | - $posdata=array('post_excerpt'=>$desc); |
|
1145 | - } |
|
1146 | - |
|
1147 | - $attachID=NULL; |
|
1148 | - //Resizor - add option to setting if required |
|
1149 | - $fragment = str_replace(' ','%20',$v['url_fragment']); |
|
1150 | - $url = $this->get_scaling_url($image_sizes).$fragment; |
|
1151 | - $attachID = $this->attach_external_image2($url,$parent_id,'',$v['label'],$postdata); |
|
1152 | - |
|
1153 | - //echo($attachID.' add image'); |
|
1154 | - if($attachID!=NULL) |
|
1155 | - { |
|
1156 | - return $attachID; |
|
1157 | - } |
|
1158 | - } |
|
1159 | - return false; |
|
1131 | + $postdata=array(); |
|
1132 | + if(empty($v['label'])) |
|
1133 | + { |
|
1134 | + $v['label']=''; |
|
1135 | + } |
|
1136 | + if(!empty($v['description'])) |
|
1137 | + { |
|
1138 | + $desc=wp_strip_all_tags($v['description']); |
|
1139 | + $posdata=array('post_excerpt'=>$desc); |
|
1140 | + } |
|
1141 | + if(!empty($v['section'])) |
|
1142 | + { |
|
1143 | + $desc=wp_strip_all_tags($v['section']); |
|
1144 | + $posdata=array('post_excerpt'=>$desc); |
|
1145 | + } |
|
1146 | + |
|
1147 | + $attachID=NULL; |
|
1148 | + //Resizor - add option to setting if required |
|
1149 | + $fragment = str_replace(' ','%20',$v['url_fragment']); |
|
1150 | + $url = $this->get_scaling_url($image_sizes).$fragment; |
|
1151 | + $attachID = $this->attach_external_image2($url,$parent_id,'',$v['label'],$postdata); |
|
1152 | + |
|
1153 | + //echo($attachID.' add image'); |
|
1154 | + if($attachID!=NULL) |
|
1155 | + { |
|
1156 | + return $attachID; |
|
1157 | + } |
|
1158 | + } |
|
1159 | + return false; |
|
1160 | 1160 | } |
1161 | 1161 | public function attach_external_image2( $url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array() ) { |
1162 | 1162 |