/
functions.php
executable file
·1674 lines (1432 loc) · 49 KB
/
functions.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
/**
* @package WordPress
* @subpackage WP-Bootstrap
*/
// Register classes
require_once('class/GlobalVariables.php');
require_once('class/GlobalFunctions.class.php');
require_once('class/wp_bootstrap_navwalker.php');
// drag and drop menu support
register_nav_menu( 'primary', 'Primary Menu' );
register_nav_menu( 'footer-left', 'Footer Left Menu' );
register_nav_menu( 'footer-middle', 'Footer Middle Menu' );
register_nav_menu( 'footer-right', 'Footer Right Menu' );
register_nav_menu( 'terroni-talk', 'Terroni Talks Header Menu' );
//widget support for a right sidebar
register_sidebar(array(
'name' => 'Open Table',
'id' => 'open-table',
'description' => 'Widget for Open Table',
'before_widget' => '<div id="%1$s">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>'
));
//widget support for the footer
/*
register_sidebar(array(
'name' => 'Footer SideBar',
'id' => 'footer-sidebar',
'description' => 'Widgets in this area will be shown in the footer.',
'before_widget' => '<div id="%1$s">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>'
));
*/
//This theme uses post thumbnails
add_theme_support( 'post-thumbnails' );
//Apply do_shortcode() to widgets so that shortcodes will be executed in widgets
add_filter('widget_text', 'do_shortcode');
// add session in init.
add_action('init', 'tl_wp_init', 1);
// init function
function tl_wp_init()
{
myStartSession();
do_output_buffer();
} // tl_wp_init
function myStartSession()
{
if(!session_id()) {
session_start();
}
}
function do_output_buffer()
{
ob_start();
}
/**
* MANAGE REMOVING OR ADDING STUFF (aka Function Snippets)
* comment in or out what you want
*/
// remove stuff, uncomment to enable
//require_once( get_template_directory() . '/snippets/remove-stuff.php' );
// add stuff
//require_once( get_template_directory() . '/snippets/add-stuff.php' );
//
//
/* TL WP Functions
============================================================================= */
/* Global Variable Definitions
======================================== */
define('HTML_TEMPLATE_ANCHOR', '<a href="%s" title="%s"%s>%s</a>');
define('HTML_TEMPLATE_UNORDERED_LIST', '<ul%s>%s</ul>');
define('HTML_TEMPLATE_LIST', '<li%s>%s</li>');
define('HTML_TEMPLATE_NAV', '<nav id="%s"%s>%s</nav>');
define('HTML_TEMPLATE_IMAGE', '<img src="%1$s" alt="%2$s" title="%2$s"%3$s />');
define('HTML_TEMPLATE_AREA', '<area shape="rect" coords="%1$s" alt="%2$s" title="%2$s" href="%3$s" target="_blank" />');
/* AJAX Functions
======================================== */
/* Shortcode Functions
======================================== */
add_shortcode('tl_wp_stackable', 'TL_WP_Shortcode_Stackable');
add_shortcode('tl_wp_book_an_event', 'TL_WP_Shortcode_Book_An_Event');
add_shortcode('tl_wp_blog', 'TL_WP_Shortcode_Blog');
/*
* This function will get the stackable ACF and output the HTML
*
* @author Trusty Logic Inc
* @copyright 2015 02 24
*
* @param $_atts Attributes array
* @param $_content content
*
* @return HTML of the stackable HTML
*/
function TL_WP_Shortcode_Stackable( $_atts, $_content = null )
{
global $post;
shortcode_atts(
array(
'amount' => ''
),
$_atts
);
return TL_WP_Get_Stackable();
} // TL_WP_Shortcode_Stackable
/*
* This function will create the form to book an event
*
* @author Trusty Logic Inc
* @copyright 2015 02 24
*
* @param $_atts Attributes array
* @param $_content content
*
* @return HTML of the event booking
*/
function TL_WP_Shortcode_Book_An_Event( $_atts, $_content = null )
{
global $post;
shortcode_atts(
array(
'amount' => ''
),
$_atts
);
$m_return = TL_WP_Create_Book_An_Event_Form();
return $m_return;
} // TL_WP_Shortcode_Book_An_Event
/*
* This funciton will get the blog posts for Terroni Talk
*
* @author Trusty Logic Inc
* @copyright 2015 05 23
*
* @param $_atts Attributes array
* @param $_content content
*
* @return HTML for the blogs
*/
function TL_WP_Shortcode_Blog( $_atts, $_content = null )
{
global $post;
shortcode_atts(
array(
'amount' => ''
),
$_atts
);
$m_return = '';
return $m_return;
} // TL_WP_Shortcode_Blog
/*
* This will get all the blog posts and create the view
*
* @author Trusty Logic Inc
* @copyright 2015 05 24
*
* @return HTML of the
*/
function TL_WP_Blog_Landing()
{
global $post;
$m_return = array();
$args = array(
'posts_per_page' => -1,
'category_name' => 'blog',
'orderby' => 'date',
'order' => 'DESC',
);
$posts_array = get_posts( $args );
$m_template = '<div class="blog-landing-header"%s>%s</div>';
foreach($posts_array as $post) // get them posts
{
$subTitle = get_field('blog_sub_title');
$videoPoster = get_field('blog_video_poster');
$videoUrl = get_field('blog_video_url');
$image = get_field('blog_image');
$m_tmp = '';
$m_tmpBody = '';
// first, check to see what exists?
if(strlen($videoUrl)>0)
{
// add autoplay
$videoUrl .= (strpos($videoUrl, '?') !== FALSE)
? '&'
: '?';
$videoUrl .= 'autoplay=1';
// need to create the container with the video
$m_tmp = sprintf(
$m_template,
'',
sprintf(
HTML_TEMPLATE_ANCHOR,
'javascript:void(0);',
'Click to play video',
' class="vertical"',
sprintf(
HTML_TEMPLATE_IMAGE,
get_template_directory_uri() . '/images/icons/icn-video-play.png',
'',
''
)
) .
'<div class="embed-responsive hideObj"><iframe class="embed-responsive-item" src="'.$videoUrl.'"></iframe></div>'
);
}
elseif($image)
{
$m_tmp = sprintf(
$m_template,
' style="background-image:url('.$image['url'].');"',
' '
);
} // if
$m_tmpBody = sprintf(
'<h1>%s</h1>%s%s',
$post->post_title,
((strlen($subTitle = get_field('blog_sub_title'))>0) ? '<h2>'.$subTitle.'</h2>' : ''),
sprintf(
HTML_TEMPLATE_ANCHOR,
get_permalink($post->ID),
'Click to view article',
'',
'Read Article'
)
);
$m_return[] = array('header' => $m_tmp, 'body' => $m_tmpBody);
} // foreach
$m_return = sprintf(
'<script type="text/javascript">tlwp.blogLanding = %s;</script>',
json_encode($m_return)
);
return $m_return;
} // TL_WP_Blog_Landing
/*
* This will get the three latest blog posts
*
* @author Trusty Logic Inc
* @copyright 2015 05 20
*
* @param $_numPosts - number of posts to retrieve from blog
*
* @return HTML of the event booking
*/
function TL_WP_Latest_Blog_Posts($_numPosts = 3)
{
global $post;
$m_return = '';
// retrieve x posts and show them as thumbnails
$numCols = 12 / $_numPosts;
$args = array(
'posts_per_page' => $_numPosts,
'category_name' => 'blog',
'orderby' => 'date',
'order' => 'DESC',
);
$posts_array = get_posts( $args );
foreach($posts_array as $post) // get them posts
{
$image = get_field('blog_image');
$title = $post->post_title;
$id = $post->ID;
$imageUrl = ($image)
? $image['url']
: ''; // put a default here
$m_return .= sprintf(
'<div class="col-sm-%s"><div class="full-width blog-latest-article"><p>%s</p><p><strong>%s</strong></p><p>%s</p></div></div>',
$numCols,
sprintf(
HTML_TEMPLATE_IMAGE,
$imageUrl,
'',
' class="img-responsive"'
),
$title,
sprintf(
HTML_TEMPLATE_ANCHOR,
get_permalink($id),
'Click here to read article',
' class="btn-read-article"',
'Read Article'
)
);
} // foreach
wp_reset_postdata();
return '<div id="blog-latest" class="container"><div class="row">'.$m_return.'</div></div>';
} // TL_WP_Latest_Blog_Posts
/*
* This will create the open table reservation form
*
* @author Trusty Logic Inc
* @copyright 2015 05 20
*
* @param $_standAlone - different container
*
* @return HTML of the event booking
*/
function TL_WP_Create_Reservation_Form($_standAlone = false)
{
wp_enqueue_style( 'tl-wp-jquery-ui', get_template_directory_uri().'/packages/jquery-ui/jquery-ui.min.css' );
wp_enqueue_script( 'tl-wp-jquery-ui-js', get_template_directory_uri().'/packages/jquery-ui/jquery-ui.min.js', array( 'jquery' ), '1.11.4', true );
global $post;
$m_return = '';
$templateLocation = '';
// need to create stuff based on standAlone param
if(!$_standAlone)
{
$reservationId = get_field('open_table_reservation_id');
}
else // need to create
{
$reservationId = -1;
// retrieve all locations
$m_arrTitles = array('terroni-toronto' => 'TERRONI Toronto', 'terroni-los-angeles' => 'TERRONI Los Angeles');
foreach($m_arrTitles as $key => $item) // get the locations
{
$m_tmpLocations = '';
$post = get_page_by_path($key);
$args = array(
'post_parent' => $post->ID,
'post_type' => 'page',
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC'
);
$locations = get_children($args);
foreach($locations as $post) // get the location
{
// get the reservation id
$tmpReservationId = get_field('open_table_reservation_id');
if(strlen($tmpReservationId)>0) // add it
$m_tmpLocations .= sprintf(
'<option value="%s">%s</option>',
$tmpReservationId,
$post->post_title
);
} // foreach
if(strlen($m_tmpLocations)>0)
$templateLocation .= sprintf(
'<optgroup label="%s">%s</optgroup>',
$item,
$m_tmpLocations
);
} // foreach
$templateLocation = sprintf(
'
<div class="field people">
<span><img src="%1$s/icn-people.png" alt="Select A Location" /></span>
<select name="Location" id="Location">%2$s</select>
<i><img src="%1$s/icn-arrow-down.png" alt="Select A Location" /></i>
</div>
',
get_template_directory_uri() . '/images/icons',
$templateLocation
);
wp_reset_postdata();
} // if
if(strlen($reservationId)>0)
{
$m_return = sprintf(
'
<div class="menu">
<h2><span>Reservations</span></h2>
<form id="openTableForm" action="http://www.opentable.com/restaurant-search.aspx" target="_blank" method="get">
%4$s
<div class="field calendar">
<span><img src="%1$s/icn-calendar.png" alt="Select a Date" /></span>
<input id="datepicker" type="text" value="%2$s" readonly name="StartDate" />
<i><img src="%1$s/icn-arrow-down.png" alt="Select a Date" /></i>
</div>
<div class="field time">
<span><img src="%1$s/icn-time.png" alt="Select A Time" /></span>
<select id="ResTime" name="ResTime">
<option value="12:00 AM">12:00 AM</option>
<option value="12:30 AM">12:30 AM</option>
<option value="1:00 AM">1:00 AM</option>
<option value="1:30 AM">1:30 AM</option>
<option value="2:00 AM">2:00 AM</option>
<option value="2:30 AM">2:30 AM</option>
<option value="3:00 AM">3:00 AM</option>
<option value="3:30 AM">3:30 AM</option>
<option value="4:00 AM">4:00 AM</option>
<option value="4:30 AM">4:30 AM</option>
<option value="5:00 AM">5:00 AM</option>
<option value="5:30 AM">5:30 AM</option>
<option value="6:00 AM">6:00 AM</option>
<option value="6:30 AM">6:30 AM</option>
<option value="7:00 AM">7:00 AM</option>
<option value="7:30 AM">7:30 AM</option>
<option value="8:00 AM">8:00 AM</option>
<option value="8:30 AM">8:30 AM</option>
<option value="9:00 AM">9:00 AM</option>
<option value="9:30 AM">9:30 AM</option>
<option value="10:00 AM">10:00 AM</option>
<option value="10:30 AM">10:30 AM</option>
<option value="11:00 AM">11:00 AM</option>
<option value="11:30 AM">11:30 AM</option>
<option value="12:00 PM">12:00 PM</option>
<option value="12:30 PM">12:30 PM</option>
<option value="1:00 PM">1:00 PM</option>
<option value="1:30 PM">1:30 PM</option>
<option value="2:00 PM">2:00 PM</option>
<option value="2:30 PM">2:30 PM</option>
<option value="3:00 PM">3:00 PM</option>
<option value="3:30 PM">3:30 PM</option>
<option value="4:00 PM">4:00 PM</option>
<option value="4:30 PM">4:30 PM</option>
<option value="5:00 PM">5:00 PM</option>
<option value="5:30 PM">5:30 PM</option>
<option selected="selected" value="6:00 PM">6:00 PM</option>
<option value="6:30 PM">6:30 PM</option>
<option value="7:00 PM">7:00 PM</option>
<option value="7:30 PM">7:30 PM</option>
<option value="8:00 PM">8:00 PM</option>
<option value="8:30 PM">8:30 PM</option>
<option value="9:00 PM">9:00 PM</option>
<option value="9:30 PM">9:30 PM</option>
<option value="10:00 PM">10:00 PM</option>
<option value="10:30 PM">10:30 PM</option>
<option value="11:00 PM">11:00 PM</option>
<option value="11:30 PM">11:30 PM</option>
</select>
<i><img src="%1$s/icn-arrow-down.png" alt="Select A Time" /></i>
</div>
<div class="field people">
<span><img src="%1$s/icn-people.png" alt="Select The Number Of People" /></span>
<select name="PartySize" id="PartySize">
<option value="1">1 person</option>
<option selected="selected" value="2">2 people</option>
<option value="3">3 people</option>
<option value="4">4 people</option>
<option value="5">5 people</option>
<option value="6">6 people</option>
<option value="7">7 people</option>
<option value="8">8 people</option>
<option value="9">9 people</option>
<option value="10">10 people</option>
<option value="11">11 people</option>
<option value="12">12 people</option>
<option value="13">13 people</option>
<option value="14">14 people</option>
<option value="15">15 people</option>
<option value="16">16 people</option>
<option value="17">17 people</option>
<option value="18">18 people</option>
<option value="19">19 people</option>
<option value="20">20 people</option>
</select>
<i><img src="%1$s/icn-arrow-down.png" alt="Select The Number Of People" /></i>
</div>
<hr>
<a class="button" id="submitOpenTableForm" href="javascript:void(0);">Book a Table</a>
<input type="hidden" name="RestaurantID" id="RestaurantID" value="%3$s">
<input type="hidden" name="rid" id="rid" value="%3$s">
<input type="hidden" name="GeoID" id="GeoID" value="74">
<input type="hidden" name="txtDateFormat" id="txtDateFormat" value="dd\/MM\/yyyy">
<input type="hidden" name="RestaurantReferralID" id="RestaurantReferralID" value="%3$s">
<input type="hidden" name="hover" id="hover" value="true">
<input type="hidden" name="wt" id="wt" value="true">
<input type="hidden" name="KeepThis" id="KeepThis" value="true">
</form>
</div>
',
get_template_directory_uri() . '/images/icons',
date('d/m/Y'),
$reservationId,
$templateLocation
);
$m_container = ($_standAlone)
? '<section class="reservations-stand-alone reservations">%s</section>'
: '
<section class="overlay reservations">
<div class="overlayContainer">
<div class="close-container"><a href="javascript:void(0);" title="close"><img src="'.get_template_directory_uri() . '/images/icons/icn-close.png" alt="close" /></a></div>
%s
</div>
</section>
';
$m_return = sprintf($m_container, $m_return);
} // if
return $m_return;
} // TL_WP_Create_Reservation_Form
/*
* This will create the carousels for the book an event
*
* @author Trusty Logic Inc
* @copyright 2015 05 20
*
* @return HTML of the event booking
*/
function TL_WP_Book_An_Event_Carousel()
{
global $post;
$m_return = '';
// carousel container
$carousel = '
<div class="master-carousel-container full-width">
<div class="container">
<div class="row">
<div class="col-sm-12 text-center"><div class="inline-block">%s</div></div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-sm-12"><div class="all-carousel-container">%s</div></div>
</div>
</div>
<div class="container">
<div class="row" data-section="carousel-description">
<div class="col-sm-6 col-sm-offset-3 text-center"><div class="inline-block"></div></div>
</div>
</div>
</div>
';
$m_arrTitles = array('terroni-toronto' => 'Toronto', 'terroni-los-angeles' => 'Los Angeles');
$m_finalLocations = '';
$m_finalLocationsMobile = '';
$m_finalLocationsMain = '';
$m_finalLocationsMainMobile = '';
$m_tmpCarouselHTML = '';
$m_counter = 0;
foreach($m_arrTitles as $key => $item) // get the locations
{
$m_tmpLocations = '';
$m_tmpLocationsMobile = '';
$post = get_page_by_path($key);
$args = array(
'post_parent' => $post->ID,
'post_type' => 'page',
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC'
);
$locations = get_children($args);
$m_counterSub = 0;
foreach($locations as $post) // get the location
{
$tmpPostId = $post->ID;
$locationTextTop = get_field('location_text_top');
$locationTextBottom = get_field('location_text_bottom');
$finalText = (strlen($locationTextTop)>0) ? '<span class="text-top">'.$locationTextTop.'</span>' : '';
$finalText .= (strlen($locationTextBottom)>0) ? (strlen($finalText)>0 ? '<br />' : '') . '<span class="text-bottom">'.$locationTextBottom.'</span>' : '';
$finalText = sprintf(
HTML_TEMPLATE_ANCHOR,
'javascript:void(0);',
'Show rooms from this location',
' class="btn-location'.(($m_counterSub==0) ? ' active' : '').'" data-id="'.$tmpPostId.'"',
$finalText
);
if(strlen($carouselHtml = TL_WP_Create_Carousel($tmpPostId, $m_counterSub+$m_counter))>0) // carousel is available
{
$m_tmpLocations .= $finalText;
$m_tmpCarouselHTML .= $carouselHtml;
$finalTextMobile = (strlen($locationTextTop)>0) ? $locationTextTop : '';
$finalTextMobile .= (strlen($locationTextBottom)>0) ? ' ' . $locationTextBottom : '';
$m_tmpLocationsMobile .= sprintf(
'<option value="%s">%s</option>',
$tmpPostId,
$finalTextMobile
);
} // if
$m_counterSub++;
} // foreach
// create some HTML views
if(strlen($m_tmpLocations)>0)
{
$m_finalLocations .= sprintf(
'<div class="location-links%s" data-location="%s">%s</div>',
(($m_counter == 0) ? ' active' : ''),
$key,
$m_tmpLocations
);
$m_finalLocationsMobile .= sprintf(
'<select data-location="%s"%s>%s</select>',
$key,
(($m_counter == 0) ? ' class="active"' : ''),
$m_tmpLocationsMobile
);
$m_finalLocationsMain .= sprintf(
HTML_TEMPLATE_ANCHOR,
'javascript:void(0);',
'Locations in ' . $item,
' class="btn-location-main'.(($m_counter==0) ? ' active' : '').'" data-key="'.$key.'"',
$item
);
$m_finalLocationsMainMobile .= sprintf(
'<option value="%s">%s</option>',
$key,
$item
);
} // if
$m_counter++;
} // foreach
if(strlen($m_finalLocationsMain)>0) // create the outer container
$m_finalLocationsMain = sprintf(
'<div class="location-main-container clearfix">%s%s</div>',
'<div class="hidden-xs">'.$m_finalLocationsMain.'</div>',
'<div class="visible-xs-block"><select>'.$m_finalLocationsMainMobile.'</select></div>'
);
if(strlen($m_finalLocations)>0) // create the outer container
$m_finalLocations = sprintf(
'<div class="location-sub-container clearfix">%s%s</div>',
'<div class="hidden-xs">'.$m_finalLocations.'</div>',
'<div class="visible-xs-block">'.$m_finalLocationsMobile.'</div>'
);
$m_return = sprintf(
$carousel,
$m_finalLocationsMain . $m_finalLocations,
$m_tmpCarouselHTML
);
wp_reset_postdata();
return $m_return;
} // TL_WP_Book_An_Event_Carousel
/* Admin
======================================= */
if(is_admin())
{
wp_enqueue_script( 'tl-wp-admin', get_template_directory_uri().'/scripts/admin.js', array( 'jquery' ), '1.0.0', true );
wp_enqueue_style('tl-wp-admin', get_template_directory_uri().'/admin.css');
} // if
/* Site Functions
======================================== */
/*
* This is the front page logic
*
* @author Trusty Logic Inc.
* @version 2015-05-09
*
* @return homepage logic
*/
function TL_WP_Get_Stackable()
{
global $post;
$m_return = array();
if(have_rows('stackable')) // check if this post has the stackable ACF
{
while(have_rows('stackable')) // get the information
{
the_row();
$type = get_sub_field('stackable_column_type');
$m_arrTmp = array();
while(have_rows('stackable_columns')) // get the column info
{
the_row();
$image = get_sub_field('stackable_image');
$textTop = trim(get_sub_field('stackable_text_top'));
$textBottom = trim(get_sub_field('stackable_text_bottom'));
$link = get_sub_field('stackable_link');
$outboundLink = get_sub_field('stackable_outbound_link');
$active = get_sub_field('stackable_active');
if($active) // need to add to the array
{
$m_arrTmp[] = array(
'image' => $image,
'text-top' => $textTop,
'text-bottom' => $textBottom,
'link' => $link,
'outbound-link' => $outboundLink
);
} // if
} // while
if(count($m_arrTmp)>0) // add it to the array
$m_return[] = array('type' => $type, 'data' => $m_arrTmp);
} // while
} // if
wp_reset_postdata();
$m_return = TL_WP_ACF_Stackable($m_return);
return $m_return;
} // TL_WP_Get_Stackable
/*
* This is the logic for the location parent, which will show a stackable view
*
* @author Trusty Logic Inc.
* @version 2015-05-10
*
* @return homepage logic
*/
function TL_WP_Location_Parent()
{
global $post;
// retrieve the children of the parents
$args = array(
'post_parent' => $post->ID,
'post_type' => 'page',
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC'
);
$locations = get_children($args);
foreach($locations as $post) // get the information
{
$type = 'regular';
$m_arrTmp = array();
$m_arrTmp[] = array(
'image' => get_field('location_image'),
'text-top' => trim(get_field('location_text_top')),
'text-bottom' => trim(get_field('location_text_bottom')),
'link' => $post,
'outbound-link' => ''
);
$m_return[] = array('type' => $type, 'data' => $m_arrTmp);
} // foreach
wp_reset_postdata();
$m_return = TL_WP_ACF_Stackable($m_return);
return $m_return;
} // TL_WP_Location_Parent
/*
* This will take the stackable ACF and create the HTML logic
*
* @author Trusty Logic Inc.
* @version 2015-05-09
*
* @param $_arrData - data for creating the stackable
*
* @return HTML of the stackable
*/
function TL_WP_ACF_Stackable($_arrData = array())
{
$m_return = '';
foreach($_arrData as $item) // go through the data
{
$m_arrTmp = array();
$m_tmp = '';
foreach($item['data'] as $data) // loop through the data
{
$tooltip = $data['text-top'] . ((strlen($data['text-bottom'])>0) ? ' ' . $data['text-bottom'] : '');
$imageHTML = ($data['image'])
? ' style="background-image:url('.$data['image']['url'].');"'
: '';
$textFinal = '<span class="text-top">'.$data['text-top'].'</span>' .
(
(strlen($data['text-bottom'])>0)
? '<br /><span class="text-bottom">'.$data['text-bottom'].'</span>'
: ''
);
$linkFinal = '#';
$extraAttr = '';
if($data['link']) // creat the proper link and extra attr
$linkFinal = get_permalink($data['link']->ID);
else
{
if(array_key_exists('outbound-link', $data)) // add this
{
$linkFinal = $data['outbound-link'];
$extraAttr = ' target="_blank"';
} // if
} // if
$m_arrTmp[] = array(
'html' => sprintf(
HTML_TEMPLATE_ANCHOR,
$linkFinal,
$tooltip,
' class="vertical stackable" data-type="'.$item['type'].'"' . $extraAttr,
$textFinal
),
'image' => $imageHTML
);
} // foreach
foreach($m_arrTmp as $itemTmp) // create the columns
{
$m_tmp .= sprintf(
'<div class="col-sm-%s stackable-column"%s>%s</div>',
(TLWP_MAX_COLS / count($m_arrTmp)),
$itemTmp['image'],
$itemTmp['html']
);
} // foreach
$m_return .= sprintf(
'<div class="row no-gutter" data-col="%s">%s</div>',
((count($m_arrTmp)>1) ? 'two_col' : 'one_col'),
$m_tmp
);
} // foreach
if(strlen($m_return)>0) // finish it off
{
$m_return = sprintf(
'<div class="container-fluid" data-type="stackable">%s</div>',
$m_return
);
} // if
return $m_return;
} // TL_WP_ACF_Stackable
/*
* This will create the menu look
*
* @author Trusty Logic Inc.
* @version 2015-05-11
*
* @return HTML of the menu
*/
function TL_WP_Location_Menu()
{
global $post;
$m_return = '';
$m_menu = '';
$m_menuTabs = '';
$m_menuTabsMobile = '';
$m_counter = 0;
if(have_rows('location_menu'))
{
while(have_rows('location_menu')) // get the information
{
the_row();
$m_tmp = '';
$title = get_sub_field('location_menu_title');
$slug = 'menu-'.GlobalFunctions::Slugify($title);
$m_menuTabs .= sprintf(
HTML_TEMPLATE_ANCHOR,
'javascript:void(0);',
'Click here to view the ' . $title,
(($m_counter == 0) ? ' class="active"' : '') .' data-table-id="'.$slug.'"',
$title
);
$m_menuTabsMobile .= sprintf(
'<option value="%s"%s>%s</option>',
$slug,
(($m_counter == 0) ? ' selected="selected"' : ''),
$title
);
while(have_rows('location_menu_Items')) // get the menu items
{
the_row();
$name = trim(get_sub_field('location_menu_item_name'));
$desc = trim(get_sub_field('location_menu_item_description'));
$price = trim(get_sub_field('location_menu_item_price'));
$active = get_sub_field('location_menu_item_active');
if($active) // add to the menu
{
$m_tmp .= sprintf(
'<tr><td data-col="meal">%s%s</td><td data-col="price"><strong>%s</strong></td></tr>',
((strlen($name)>0) ? '<strong>'.$name.'</strong><br />' : ''),
((strlen($desc)>0) ? $desc : ''),
$price
);
} // if
} // while
$m_menu .= sprintf(
'<table id="%s" class="table table-condensed%s"><tbody>%s</tbody></table>',
$slug,
(($m_counter == 0) ? ' active' : ''),
$m_tmp
);
$m_counter++;
} // while
} // if