-
Notifications
You must be signed in to change notification settings - Fork 5
/
wp-restaurant-listings-template.php
1331 lines (1113 loc) · 36.9 KB
/
wp-restaurant-listings-template.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Template Functions
*
* Template functions specifically created for restaurant listings
*
* @package RestaurantListings/Template
* @version 1.0.0
*/
/**
* Gets and includes template files.
*
* @since 1.0.0
* @param mixed $template_name
* @param array $args (default: array())
* @param string $template_path (default: '')
* @param string $default_path (default: '')
*/
function get_restaurant_listings_template( $template_name, $args = array(), $template_path = 'restaurant_listings', $default_path = '' ) {
if ( $args && is_array( $args ) ) {
extract( $args );
}
include locate_restaurant_listings_template( $template_name, $template_path, $default_path );
}
/**
* Locates a template and return the path for inclusion.
*
* This is the load order:
*
* yourtheme / $template_path / $template_name
* yourtheme / $template_name
* $default_path / $template_name
*
* @since 1.0.0
* @param string $template_name
* @param string $template_path (default: 'restaurant_listings')
* @param string|bool $default_path (default: '') False to not load a default
* @return string
*/
function locate_restaurant_listings_template( $template_name, $template_path = 'restaurant_listings', $default_path = '' ) {
// Look within passed path within the theme - this is priority
$template = locate_template(
array(
trailingslashit( $template_path ) . $template_name,
$template_name
)
);
// Get default template
if ( ! $template && $default_path !== false ) {
$default_path = $default_path ? $default_path : RESTAURANT_LISTING_PLUGIN_DIR . '/templates/';
if ( file_exists( trailingslashit( $default_path ) . $template_name ) ) {
$template = trailingslashit( $default_path ) . $template_name;
}
}
// Return what we found
return apply_filters( 'restaurant_listings_locate_template', $template, $template_name, $template_path );
}
/**
* Gets template part (for templates in loops).
*
* @since 1.0.0
* @param string $slug
* @param string $name (default: '')
* @param string $template_path (default: 'restaurant_listings')
* @param string|bool $default_path (default: '') False to not load a default
*/
function get_restaurant_listings_template_part( $slug, $name = '', $template_path = 'restaurant_listings', $default_path = '' ) {
$template = '';
if ( $name ) {
$template = locate_restaurant_listings_template( "{$slug}-{$name}.php", $template_path, $default_path );
}
// If template file doesn't exist, look in yourtheme/slug.php and yourtheme/restaurant_listings/slug.php
if ( ! $template ) {
$template = locate_restaurant_listings_template( "{$slug}.php", $template_path, $default_path );
}
if ( $template ) {
load_template( $template, false );
}
}
/**
* Adds custom body classes.
*
* @since 1.0.0
* @param array $classes
* @return array
*/
function restaurant_listings_body_class( $classes ) {
$classes = (array) $classes;
$classes[] = sanitize_title( wp_get_theme() );
return array_unique( $classes );
}
add_filter( 'body_class', 'restaurant_listings_body_class' );
/**
* Get restaurants pagination for [restaurants] shortcode.
*
* @since 1.0.0
* @param int $max_num_pages
* @param int $current_page
* @return string
*/
function get_restaurant_listings_pagination( $max_num_pages, $current_page = 1 ) {
ob_start();
get_restaurant_listings_template( 'restaurant-pagination.php', array( 'max_num_pages' => $max_num_pages, 'current_page' => absint( $current_page ) ) );
return ob_get_clean();
}
/**
* Displays the restaurants status.
*
* @since 1.0.0
* @param int|WP_Post $post
*/
function the_restaurant_status( $post = null ) {
echo get_the_restaurant_status( $post );
}
/**
* Gets the restaurants status.
*
* @since 1.0.0
* @param int|WP_Post $post
* @return string
*/
function get_the_restaurant_status( $post = null ) {
$post = get_post( $post );
$status = $post->post_status;
$statuses = get_restaurant_listings_post_statuses();
if ( isset( $statuses[ $status ] ) ) {
$status = $statuses[ $status ];
} else {
$status = __( 'Inactive', 'wp-restaurant-listings' );
}
return apply_filters( 'the_restaurant_status', $status, $post );
}
/**
* Checks whether or not the position has been featured.
*
* @since 1.0.0
* @param WP_Post|int $post
* @return boolean
*/
function is_restaurant_featured( $post = null ) {
$post = get_post( $post );
return $post->_featured ? true : false;
}
/**
* Displays the permalink for the restaurant listings post.
*
* @since 1.0.0
* @param int|WP_Post $post (default: null)
* @return void
*/
function the_restaurant_permalink( $post = null ) {
echo get_the_restaurant_permalink( $post );
}
/**
* Gets the permalink for a restaurant listings.
*
* @since 1.0.0
* @param int|WP_Post $post (default: null)
* @return string
*/
function get_the_restaurant_permalink( $post = null ) {
$post = get_post( $post );
$link = get_permalink( $post );
return apply_filters( 'the_restaurant_permalink', $link, $post );
}
/**
* Displays the restaurant title for the listings.
*
* @since 1.0.0
* @param int|WP_Post $post
* @return string
*/
function the_restaurant_title( $post = null ) {
if ( $restaurant_title = get_the_restaurant_title( $post ) ) {
echo $restaurant_title;
}
}
/**
* Gets the restaurant title for the listings.
*
* @since 1.0.0
* @param int|WP_Post $post (default: null)
* @return string|bool|null
*/
function get_the_restaurant_title( $post = null ) {
$post = get_post( $post );
if ( $post->post_type !== 'restaurant_listings' ) {
return;
}
$title = esc_html( get_the_title( $post ) );
/**
* Filter for the restaurant title.
*
* @since 1.0.0
* @param string $title Title to be filtered.
* @param int|WP_Post $post
*/
return apply_filters( 'the_restaurant_title', $title, $post );
}
/**
* Displays multiple restaurant types for the listings.
*
* @since 1.0.0
*
* @param int|WP_Post $post Current post object.
* @param string $separator String to join the term names with.
*/
function the_restaurant_types( $post = null, $separator = ', ' ) {
if ( ! get_option( 'restaurant_listings_enable_types' ) ) {
return;
}
$restaurant_types = get_the_restaurant_types( $post );
if ( $restaurant_types ) {
$names = wp_list_pluck( $restaurant_types, 'name' );
echo esc_html( implode( $separator, $names ) );
}
}
/**
* Gets the restaurant type for the listings.
*
* @since 1.0.0
*
* @param int|WP_Post $post (default: null).
* @return bool|array
*/
function get_the_restaurant_types( $post = null ) {
$post = get_post( $post );
if ( 'restaurant_listings' !== $post->post_type ) {
return false;
}
$types = get_the_terms( $post->ID, 'restaurant_listings_type' );
if ( empty( $types ) || is_wp_error( $types ) ) {
$types = array();
}
// Return single if not enabled.
if ( ! empty( $types ) && ! restaurant_listings_multi_restaurant_type() ) {
$types = array( current( $types ) );
}
/**
* Filter the returned restaurant types for a post.
*
* @since 1.0.0
*
* @param array $types
* @param WP_Post $post
*/
return apply_filters( 'the_restaurant_types', $types, $post );
}
/**
* Restaurant price range
*
* @param WP_Post $post post object.
* @return void
*/
function the_restaurant_price_range( $post = null ) {
$restaurant_price_range = get_the_restaurant_price_range( $post );
if ( $restaurant_price_range ) {
echo '<div class="price-range">' . $restaurant_price_range . '</div>';
}
}
function get_the_restaurant_price_range( $post = null ) {
$post = get_post( $post );
if ( $post->post_type !== 'restaurant_listings' ) {
return;
}
$currency_symbol = get_option('restaurant_listings_currency');
return apply_filters( 'the_restaurant_price_range', str_repeat( $currency_symbol, absint( $post->_restaurant_price_range ) ), $post );
}
/**
* Returns the registration fields used when an account is required.
*
* @since 1.0.0
*
* @return array $registration_fields
*/
function wprl_get_registration_fields() {
$generate_username_from_email = restaurant_listings_generate_username_from_email();
$use_standard_password_setup_email = wprl_use_standard_password_setup_email();
$account_required = restaurant_listings_user_requires_account();
$registration_fields = array();
if ( restaurant_listings_enable_registration() ) {
if ( ! $generate_username_from_email ) {
$registration_fields['create_account_username'] = array(
'type' => 'text',
'label' => __( 'Username', 'wp-restaurant-listings' ),
'required' => $account_required,
'value' => isset( $_POST['create_account_username'] ) ? $_POST['create_account_username'] : '',
);
}
if ( ! $use_standard_password_setup_email ) {
$registration_fields['create_account_password'] = array(
'type' => 'password',
'label' => __( 'Password', 'wp-restaurant-listings' ),
'autocomplete' => false,
'required' => $account_required,
);
$password_hint = wprl_get_password_rules_hint();
if ( $password_hint ) {
$registration_fields['create_account_password']['description'] = $password_hint;
}
$registration_fields['create_account_password_verify'] = array(
'type' => 'password',
'label' => __( 'Verify Password', 'wp-restaurant-listings' ),
'autocomplete' => false,
'required' => $account_required,
);
}
$registration_fields['create_account_email'] = array(
'type' => 'text',
'label' => __( 'Your email', 'wp-restaurant-listings' ),
'placeholder' => __( '[email protected]', 'wp-restaurant-listings' ),
'required' => $account_required,
'value' => isset( $_POST['create_account_email'] ) ? $_POST['create_account_email'] : '',
);
}
/**
* Filters the fields used at registration.
*
* @since 1.0.0
*
* @param array $registration_fields
*/
return apply_filters( 'wprl_get_registration_fields', $registration_fields );
}
/**
* Displays the published date of the restaurant listings.
*
* @since 1.0.0
* @param int|WP_Post $post (default: null)
*/
function the_restaurant_publish_date( $post = null ) {
$date_format = get_option( 'restaurant_listings_date_format' );
if ( 'default' === $date_format ) {
$display_date = __( 'Posted on ', 'wp-restaurant-listings' ) . date_i18n( get_option( 'date_format' ), get_post_time( 'U' ) );
} else {
$display_date = sprintf( __( 'Posted %s ago', 'wp-restaurant-listings' ), human_time_diff( get_post_time( 'U' ), current_time( 'timestamp' ) ) );
}
echo '<time datetime="' . get_post_time( 'Y-m-d' ) . '">' . $display_date . '</time>';
}
/**
* Gets the published date of the restaurant listings.
*
* @since 1.0.0
* @param int|WP_Post $post (default: null)
* @return string|int|false
*/
function get_the_restaurant_publish_date( $post = null ) {
$date_format = get_option( 'restaurant_listings_date_format' );
if ( $date_format === 'default' ) {
return get_post_time( get_option( 'date_format' ) );
} else {
return sprintf( __( 'Posted %s ago', 'wp-restaurant-listings' ), human_time_diff( get_post_time( 'U' ), current_time( 'timestamp' ) ) );
}
}
/**
* Displays the location for the restaurant listings.
*
* @since 1.0.0
* @param bool $map_link whether or not to link to Google Maps
* @param int|WP_Post $post
*/
function the_restaurant_location( $map_link = true, $post = null ) {
$location = get_the_restaurant_location( $post );
if ( $location ) {
if ( $map_link ) {
// If linking to google maps, we don't want anything but text here
echo apply_filters( 'the_restaurant_location_map_link', '<a class="google_map_link" href="' . get_the_restaurant_direction_link() .'" target="_blank">' . esc_html( strip_tags( $location ) ) . '</a>', $location, $post );
} else {
echo wp_kses_post( $location );
}
} else {
echo wp_kses_post( apply_filters( 'the_restaurant_location_anywhere_text', __( 'Anywhere', 'wp-restaurant-listings' ) ) );
}
}
function get_the_restaurant_direction_link() {
$location = get_the_restaurant_location();
return apply_filters( 'get_the_restaurant_direction_link', esc_url( 'http://maps.google.com/maps?q=' . urlencode( strip_tags( $location ) ) . '&zoom=14&size=512x512&maptype=roadmap&sensor=false' ) );
}
/**
* Gets the location for the restaurant listings.
*
* @since 1.0.0
* @param int|WP_Post $post (default: null)
* @return string|null
*/
function get_the_restaurant_location( $post = null ) {
$post = get_post( $post );
if ( $post->post_type !== 'restaurant_listings' ) {
return;
}
return apply_filters( 'the_restaurant_location', $post->_restaurant_location, $post );
}
/**
* @param null $post
*/
function the_restaurant_street( $post = null ) {
if ( $street = get_the_restaurant_street( $post ) ) {
echo '<span class="neighborhood-str-list">'. $street.'</span>';
}
}
/**
* @param null $post
* @return mixed|void
*/
function get_the_restaurant_street( $post = null ) {
$post = get_post( $post );
if ( $post->post_type !== 'restaurant_listings' ) {
return;
}
return apply_filters( 'get_the_restaurant_street', $post->geolocation_street, $post );
}
/**
* @param null $post
*/
function the_restaurant_latest_story( $post = null ) {
$comment = get_the_restaurant_latest_story( $post );
if ( $comment instanceof WP_Comment ) {
?>
<div id="comment-<?php $comment->comment_ID ?>" class="comment_container">
<div class="comment-avatar">
<?php
echo get_avatar( $comment, apply_filters( 'restaurant_listings_review_gravatar_size', '60' ), '' );
?>
</div>
<div class="comment-text">
<div class="discription">
<?php echo $comment->comment_content ?>
</div>
</div>
</div>
<?php
}
}
/**
* @param null $post
* @return mixed|void
*/
function get_the_restaurant_latest_story( $post = null ) {
$post = get_post( $post );
$comment = new stdClass();
if ( $post->post_type !== 'restaurant_listings' ) {
return;
}
$comments = get_comments(array( 'status' => 'approve', 'post_id' => $post->ID, 'number' => 1, 'orderby' => array('comment_date'), 'order' => 'DESC' ) );
is_array($comments) && sizeof($comments) > 0 && $comment = $comments[0];
return apply_filters( 'the_restaurant_location', $comment, $post );
}
/**
* Displays the restaurant logo.
*
* @since 1.0.0
* @param string $size (default: 'full')
* @param mixed $default (default: null)
* @param int|WP_Post $post (default: null)
*/
function the_restaurant_logo( $size = 'thumbnail', $default = null, $post = null ) {
$logo = get_the_restaurant_logo( $post, $size );
if ( has_post_thumbnail( $post ) ) {
echo '<img class="restaurant_logo" src="' . esc_attr( $logo ) . '" alt="' . esc_attr( get_the_restaurant_name( $post ) ) . '" />';
} elseif ( $default ) {
echo '<img class="restaurant_logo" src="' . esc_attr( $default ) . '" alt="' . esc_attr( get_the_restaurant_name( $post ) ) . '" />';
} else {
echo '<img class="restaurant_logo" src="' . esc_attr( apply_filters( 'restaurant_listings_default_restaurant_logo', RESTAURANT_LISTING_PLUGIN_URL . '/assets/images/restaurant.png' ) ) . '" alt="' . esc_attr( get_the_restaurant_name( $post ) ) . '" />';
}
}
/**
* Gets the restaurant logo.
*
* @since 1.0.0
* @param int|WP_Post $post (default: null)
* @param string $size
* @return string Image SRC
*/
function get_the_restaurant_logo( $post = null, $size = 'thumbnail' ) {
$post = get_post( $post );
if ( has_post_thumbnail( $post->ID ) ) {
$src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), $size );
return $src ? $src[0] : '';
}
return '';
}
/**
* Resizes and returns the url of an image.
*
* @since 1.0.0
* @param string $logo
* @param string $size
* @return string
*/
function restaurant_listings_get_resized_image( $logo, $size ) {
global $_wp_additional_image_sizes;
if ( $size !== 'full' && strstr( $logo, WP_CONTENT_URL ) && ( isset( $_wp_additional_image_sizes[ $size ] ) || in_array( $size, array( 'thumbnail', 'medium', 'large' ) ) ) ) {
if ( in_array( $size, array( 'thumbnail', 'medium', 'large' ) ) ) {
$img_width = get_option( $size . '_size_w' );
$img_height = get_option( $size . '_size_h' );
$img_crop = get_option( $size . '_size_crop' );
} else {
$img_width = $_wp_additional_image_sizes[ $size ]['width'];
$img_height = $_wp_additional_image_sizes[ $size ]['height'];
$img_crop = $_wp_additional_image_sizes[ $size ]['crop'];
}
$upload_dir = wp_upload_dir();
$logo_path = str_replace( array( $upload_dir['baseurl'], $upload_dir['url'], WP_CONTENT_URL ), array( $upload_dir['basedir'], $upload_dir['path'], WP_CONTENT_DIR ), $logo );
$path_parts = pathinfo( $logo_path );
$dims = $img_width . 'x' . $img_height;
$resized_logo_path = str_replace( '.' . $path_parts['extension'], '-' . $dims . '.' . $path_parts['extension'], $logo_path );
if ( strstr( $resized_logo_path, 'http:' ) || strstr( $resized_logo_path, 'https:' ) ) {
return $logo;
}
if ( ! file_exists( $resized_logo_path ) ) {
ob_start();
$image = wp_get_image_editor( $logo_path );
if ( ! is_wp_error( $image ) ) {
$resize = $image->resize( $img_width, $img_height, $img_crop );
if ( ! is_wp_error( $resize ) ) {
$save = $image->save( $resized_logo_path );
if ( ! is_wp_error( $save ) ) {
$logo = dirname( $logo ) . '/' . basename( $resized_logo_path );
}
}
}
ob_get_clean();
} else {
$logo = dirname( $logo ) . '/' . basename( $resized_logo_path );
}
}
return $logo;
}
/**
* Displays the restaurant video.
*
* @since 1.0.0
* @param int|WP_Post $post
*/
function the_restaurant_video( $post = null ) {
$video_embed = false;
$video = get_the_restaurant_video( $post );
$filetype = wp_check_filetype( $video );
if( ! empty( $video ) ){
// FV Wordpress Flowplayer Support for advanced video formats
if ( shortcode_exists( 'flowplayer' ) ) {
$video_embed = '[flowplayer src="' . esc_attr( $video ) . '"]';
} elseif ( ! empty( $filetype[ 'ext' ] ) ) {
$video_embed = wp_video_shortcode( array( 'src' => $video ) );
} else {
$video_embed = wp_oembed_get( $video );
}
}
$video_embed = apply_filters( 'the_restaurant_video_embed', $video_embed, $post );
if ( $video_embed ) {
echo '<div class="restaurant_video">' . $video_embed . '</div>';
}
}
/**
* Gets the restaurant video URL.
*
* @since 1.0.0
* @param int|WP_Post $post (default: null)
* @return string|null
*/
function get_the_restaurant_video( $post = null ) {
$post = get_post( $post );
if ( $post->post_type !== 'restaurant_listings' ) {
return;
}
return apply_filters( 'the_restaurant_video', $post->_restaurant_video, $post );
}
/**
* Displays or retrieves the current restaurant name with optional content.
*
* @since 1.0.0
* @param string $before (default: '')
* @param string $after (default: '')
* @param bool $echo (default: true)
* @param int|WP_Post|null $post (default: null)
* @return string|void
*/
function the_restaurant_name( $before = '', $after = '', $echo = true, $post = null ) {
$restaurant_name = get_the_restaurant_name( $post );
if ( strlen( $restaurant_name ) == 0 )
return;
$restaurant_name = esc_attr( strip_tags( $restaurant_name ) );
$restaurant_name = $before . $restaurant_name . $after;
if ( $echo )
echo $restaurant_name;
else
return $restaurant_name;
}
/**
* Gets the restaurant name.
*
* @since 1.0.0
* @param int $post (default: null)
* @return string
*/
function get_the_restaurant_name( $post = null ) {
$post = get_post( $post );
if ( $post->post_type !== 'restaurant_listings' ) {
return '';
}
return apply_filters( 'the_restaurant_name', $post->_restaurant_name, $post );
}
/**
* Gets the restaurant website.
*
* @since 1.0.0
* @param int $post (default: null)
* @return null|string
*/
function get_the_restaurant_website( $post = null ) {
$post = get_post( $post );
if ( $post->post_type !== 'restaurant_listings' )
return;
$website = $post->_restaurant_website;
if ( $website && ! strstr( $website, 'http:' ) && ! strstr( $website, 'https:' ) ) {
$website = 'http://' . $website;
}
return apply_filters( 'the_restaurant_website', $website, $post );
}
/**
* Displays or retrieves the current restaurant tagline with optional content.
*
* @since 1.0.0
* @param string $before (default: '')
* @param string $after (default: '')
* @param bool $echo (default: true)
* @param int|WP_Post|null $post (default: null)
* @return string|void
*/
function the_restaurant_tagline( $before = '', $after = '', $echo = true, $post = null ) {
$restaurant_tagline = get_the_restaurant_tagline( $post );
if ( strlen( $restaurant_tagline ) == 0 )
return;
$restaurant_tagline = esc_attr( strip_tags( $restaurant_tagline ) );
$restaurant_tagline = $before . $restaurant_tagline . $after;
if ( $echo )
echo $restaurant_tagline;
else
return $restaurant_tagline;
}
/**
* Gets the restaurant tagline.
*
* @since 1.0.0
* @param int|WP_Post|null $post (default: null)
* @return string|null
*/
function get_the_restaurant_tagline( $post = null ) {
$post = get_post( $post );
if ( $post->post_type !== 'restaurant_listings' )
return;
return apply_filters( 'the_restaurant_tagline', $post->_restaurant_tagline, $post );
}
/**
* Displays or retrieves the current restaurant Twitter link with optional content.
*
* @since 1.0.0
* @param string $before (default: '')
* @param string $after (default: '')
* @param bool $echo (default: true)
* @param int|WP_Post|null $post (default: null)
* @return string|void
*/
function the_restaurant_twitter( $before = '', $after = '', $echo = true, $post = null ) {
$restaurant_twitter = get_the_restaurant_twitter( $post );
if ( strlen( $restaurant_twitter ) == 0 )
return;
$restaurant_twitter = esc_attr( strip_tags( $restaurant_twitter ) );
$restaurant_twitter = $before . '<a href="http://twitter.com/' . $restaurant_twitter . '" class="restaurant_twitter" target="_blank">' . $restaurant_twitter . '</a>' . $after;
if ( $echo )
echo $restaurant_twitter;
else
return $restaurant_twitter;
}
/**
* Gets the restaurant Twitter link.
*
* @since 1.0.0
* @param int|WP_Post|null $post (default: null)
* @return string|null
*/
function get_the_restaurant_twitter( $post = null ) {
$post = get_post( $post );
if ( $post->post_type !== 'restaurant_listings' )
return;
$restaurant_twitter = $post->_restaurant_twitter;
if ( strlen( $restaurant_twitter ) == 0 )
return;
if ( strpos( $restaurant_twitter, '@' ) === 0 )
$restaurant_twitter = substr( $restaurant_twitter, 1 );
return apply_filters( 'the_restaurant_twitter', $restaurant_twitter, $post );
}
/**
* Listings Phone Number
*
*
* @return void
*/
function the_restaurant_phone() {
global $post;
$phone = $post->_restaurant_phone;
if ( ! $phone ) {
return;
}
?>
<div class="restaurant_listings-phone">
<span itemprop="telephone"><a href="tel:<?php echo esc_attr( preg_replace( "/[^0-9,.]/", '', $phone ) ); ?>"><?php echo
esc_attr( $phone ); ?></a></span>
</div>
<?php
}
/**
* Listings Email
*
* @since 1.0.0
*
* @return void
*/
function the_restaurant_email() {
$email = get_post()->_application;
if ( ! $email || ! is_email( $email ) ) {
return;
}
?>
<div class="listings-email">
<a itemprop="email" href="mailto:<?php echo esc_attr( $email ); ?>"><?php echo antispambot( $email ); ?></a>
</div>
<?php
}
/**
* Listings URL
*
*
* @return void
*/
function the_restaurant_url() {
global $post;
$url = get_the_restaurant_website( $post->ID );
if ( ! $url ) {
return;
}
$url = esc_url( $url );
$base = parse_url( $url );
$base = $base[ 'host' ];
?>
<div class="restaurant_listings-url">
<span itemprop="url"><a href="<?php echo $url; ?>" rel="nofollow" target="_blank"><?php echo esc_attr( $base ); ?></a></span>
</div>
<?php
}
/**
* Listings Category
*
* @return void
*/
function the_restaurant_category() {
global $post;
if ( ! get_option( 'restaurant_listings_enable_categories' ) ) {
return;
}
?>
<div class="content-single-restaurant_listings-title-category">
<?php echo restaurant_listings_category_list( $post->ID, ', ', '<span class="posted_in"> ', '</span>' ); ?>
</div>
<?php
}
/**
* @param null $post
*/
function the_restaurant_rating( $post = null ) {
$post = get_post( $post );
if ( $post->post_type !== 'restaurant_listings' )
return;
$rating_count = array_sum( WP_Restaurant_Listings_Comments::get_rating_counts_for_restaurant($post) );
$review_count = WP_Restaurant_Listings_Comments::get_review_count_for_restaurant($post);
$average = WP_Restaurant_Listings_Comments::get_average_rating_for_restaurant($post);
if ( $rating_count > 0 ) : ?>
<div class="restaurant-rating">
<div class="star-rating">
<?php echo get_restaurant_star_rating_html( $average, $rating_count ); ?>
</div>
<?php if ( comments_open() ) : ?><a href="#reviews" class="restaurant-listings-review-link" rel="nofollow">(<?php printf( _n( '%s customer review', '%s customer reviews', $review_count, 'wp-restaurant-listings' ), '<span class="count">' . esc_html( $review_count ) . '</span>' ); ?>)</a><?php endif ?>
</div>
<?php endif;
}
function get_restaurant_star_rating_html( $rating, $count = 0 ) {
$html = '<span style="width:' . ( ( $rating / 5 ) * 100 ) . '%">';
if ( 0 < $count ) {
/* translators: 1: rating 2: rating count */
$html .= sprintf( _n( 'Rated %1$s out of 5 based on %2$s customer rating', 'Rated %1$s out of 5 based on %2$s customer ratings', $count, 'wp-restaurant-listings' ), '<strong class="rating">' . esc_html( $rating ) . '</strong>', '<span class="rating">' . esc_html( $count ) . '</span>' );
} else {
/* translators: %s: rating */
$html .= sprintf( esc_html__( 'Rated %s out of 5', 'wp-restaurant-listings' ), '<strong class="rating">' . esc_html( $rating ) . '</strong>' );
}
$html .= '</span>';
return apply_filters( 'get_restaurant_star_rating_html', $html, $rating, $count );
}
/**
* Displays or retrieves the current restaurant opening hours
*
*/
function the_restaurant_opening_hours() {
global $post;
if ( $post->post_type !== 'restaurant_listings' )
return;
$hours = get_post_meta( $post->ID, '_restaurant_hours', true );
if ( ! $hours ) {
return;
}
global $wp_locale;
$numericdays = restaurant_listings_get_days_of_week();
foreach ( $numericdays as $key => $i ) {
$day = $wp_locale->get_weekday( $i );
$start = isset( $hours[ $i ][ 'start' ] ) ? $hours[ $i ][ 'start' ] : false;
$end = isset( $hours[ $i ][ 'end' ] ) ? $hours[ $i ][ 'end' ] : false;
if ( ! ( $start && $end ) ) {
continue;
}
$days[ $day ] = array( $start, $end );
}
if ( empty( $days ) ) {
return;
}
?>
<div class="business-hours-drop-wrapper">
<div class="business-hours-drop-element">
<div class="business-hours-drop-content-inner">
<?php foreach ( $days as $day => $hours ) : ?>
<p class="business-hour" itemprop="openingHours" content="<?php echo $day; ?> <?php echo date_i18n( 'Ga', strtotime( $hours[0] ) ); ?>-<?php echo date( 'Ga', strtotime( $hours[1] ) ); ?>" data-day="<?php echo $day ?>">
<span class="day"><?php echo $day ?></span>
<span class="business-hour-time">
<?php if ( __( 'Closed', 'wp-restaurant-listings' ) == $hours[0] ) : ?>
<?php _e( 'Closed', 'wp-restaurant-listings' ); ?>