forked from UCF/Main-Site-Theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
3407 lines (3013 loc) · 101 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
require_once('third-party/truncate-html.php'); # Includes truncateHtml function
require_once('functions/base.php'); # Base theme functions
require_once('functions/feeds.php'); # Where functions related to feed data live
require_once('custom-taxonomies.php'); # Where per theme taxonomies are defined
require_once('custom-post-types.php'); # Where per theme post types are defined
require_once('functions/admin.php'); # Admin/login functions
require_once('functions/config.php'); # Where per theme settings are registered
require_once('shortcodes.php'); # Per theme shortcodes
//Add theme-specific functions here.
/**
* Slider post type customizations
* Stolen from SmartStart theme
**/
// Custom columns for 'Centerpiece' post type
function edit_centerpiece_columns() {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => 'Name',
'slide_count' => 'Slide Count'
);
return $columns;
}
add_action('manage_edit-centerpiece_columns', 'edit_centerpiece_columns');
// Custom columns content for 'Centerpiece'
function manage_centerpiece_columns( $column, $post_id ) {
global $post;
switch ( $column ) {
case 'slide_count':
print get_post_meta( $post->ID, 'ss_slider_slidecount', true );
break;
default:
break;
}
}
add_action('manage_centerpiece_posts_custom_column', 'manage_centerpiece_columns', 10, 2);
// Sortable custom columns for 'Centerpiece'
function sortable_centerpiece_columns( $columns ) {
$columns['slide_count'] = 'slide_count';
return $columns;
}
add_action('manage_edit-centerpiece_sortable_columns', 'sortable_centerpiece_columns');
// Change default title for 'Centerpiece'
function change_centerpiece_title( $title ){
$screen = get_current_screen();
if ( $screen->post_type == 'centerpiece' )
$title = __('Enter centerpiece name here');
return $title;
}
add_filter('enter_title_here', 'change_centerpiece_title');
/**
* Announcement custom columns
**/
// Custom columns for 'Announcement' post type
function edit_announcement_columns() {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => 'Name',
'start_date' => 'Start Date',
'end_date' => 'End Date',
'publish_date' => 'Publish Date'
);
return $columns;
}
add_action('manage_edit-announcement_columns', 'edit_announcement_columns');
// Custom columns content for 'Announcement'
function manage_announcement_columns( $column, $post_id ) {
global $post;
switch ( $column ) {
case 'start_date':
$start_date = get_post_meta($post->ID, 'announcement_start_date', TRUE) ? date('Y/m/d', strtotime(get_post_meta($post->ID, 'announcement_start_date', TRUE))) : '<span style="font-weight:bold;color:#cc0000;">N/A</span>';
print $start_date;
break;
case 'end_date':
$end_date = get_post_meta($post->ID, 'announcement_end_date', TRUE) ? date('Y/m/d', strtotime(get_post_meta($post->ID, 'announcement_end_date', TRUE))) : '<span style="font-weight:bold;color:#cc0000;">N/A</span>';
print $end_date;
break;
case 'publish_date':
if ($post->post_status == 'publish') {
print get_post_time('Y/m/d', true, $post->ID);
}
break;
default:
break;
}
}
add_action('manage_announcement_posts_custom_column', 'manage_announcement_columns', 10, 2);
// Sortable custom columns for 'Announcement'
function sortable_announcement_columns( $columns ) {
$columns['start_date'] = 'start_date';
$columns['end_date'] = 'end_date';
$columns['publish_date'] = 'publish_date';
return $columns;
}
add_action('manage_edit-announcement_sortable_columns', 'sortable_announcement_columns');
/**
* Allow special tags in post bodies that would get stripped otherwise for most users.
* Modifies $allowedposttags defined in wp-includes/kses.php
*
* http://wordpress.org/support/topic/div-ids-being-stripped-out
* http://wpquicktips.wordpress.com/2010/03/12/how-to-change-the-allowed-html-tags-for-wordpress/
**/
$allowedposttags['input'] = array(
'type' => array(),
'value' => array(),
'id' => array(),
'name' => array(),
'class' => array()
);
$allowedposttags['select'] = array(
'id' => array(),
'name' => array()
);
$allowedposttags['option'] = array(
'id' => array(),
'name' => array(),
'value' => array()
);
$allowedposttags['iframe'] = array(
'type' => array(),
'value' => array(),
'id' => array(),
'name' => array(),
'class' => array(),
'src' => array(),
'height' => array(),
'width' => array(),
'allowfullscreen' => array(),
'frameborder' => array()
);
$allowedposttags['object'] = array(
'height' => array(),
'width' => array()
);
$allowedposttags['param'] = array(
'name' => array(),
'value' => array()
);
$allowedposttags['embed'] = array(
'src' => array(),
'type' => array(),
'allowfullscreen' => array(),
'allowscriptaccess' => array(),
'height' => array(),
'width' => array()
);
// Most of these attributes aren't actually valid for some of
// the tags they're assigned to, but whatever:
$allowedposttags['div'] =
$allowedposttags['a'] =
$allowedposttags['button'] = array(
'id' => array(),
'class' => array(),
'style' => array(),
'width' => array(),
'height' => array(),
'align' => array(),
'aria-hidden' => array(),
'aria-labelledby' => array(),
'autofocus' => array(),
'dir' => array(),
'disabled' => array(),
'form' => array(),
'formaction' => array(),
'formenctype' => array(),
'formmethod' => array(),
'formonvalidate' => array(),
'formtarget' => array(),
'hidden' => array(),
'href' => array(),
'name' => array(),
'rel' => array(),
'rev' => array(),
'role' => array(),
'target' => array(),
'type' => array(),
'title' => array(),
'value' => array(),
// Bootstrap JS stuff:
'data-dismiss' => array(),
'data-toggle' => array(),
'data-target' => array(),
'data-backdrop' => array(),
'data-spy' => array(),
'data-offset' => array(),
'data-animation' => array(),
'data-html' => array(),
'data-placement' => array(),
'data-selector' => array(),
'data-title' => array(),
'data-trigger' => array(),
'data-delay' => array(),
'data-content' => array(),
'data-offset' => array(),
'data-offset-top' => array(),
'data-loading-text' => array(),
'data-complete-text' => array(),
'autocomplete' => array(),
'data-parent' => array(),
);
/**
* Retrieve a YouTube ID from its URL
**/
function get_youtube_id($url){
$shortlink_domain = '/^http\:\/\/(?:www.)?youtu.be/';
if (preg_match($shortlink_domain, $url)) {
$parts = parse_url($url);
return substr($parts['path'], 1, strlen($parts['path']) - 1);
}
else {
$parts = parse_url($url);
parse_str($parts['query'], $parts);
return $parts['v'];
}
}
/**
* Allow shortcodes in widgets
**/
add_filter('widget_text', 'do_shortcode');
/**
* Hide unused admin tools (Links, Comments, etc)
**/
function hide_admin_links() {
remove_menu_page('link-manager.php');
remove_menu_page('edit-comments.php');
}
add_action( 'admin_menu', 'hide_admin_links' );
/**
* Adds a subheader to a page (if one is set for the page.)
**/
function get_page_subheader( $post ) {
ob_start();
$subheader = get_post_meta( $post->ID, 'page_subheader', true );
if ( $subheader ) {
$subheader_post = get_post( $subheader );
$sub_img = get_post_meta( $subheader, 'subheader_sub_image', true );
$sub_img_atts = array(
'class' => 'subheader-subimg',
'alt' => $post->post_title,
'title' => $post->post_title,
);
$student_name = get_post_meta( $subheader, 'subheader_student_name', true );
$student_img = get_post_meta( $subheader, 'subheader_student_image', true );
$student_img_atts = array(
'class' => 'subheader-studentimg',
'alt' => get_post_meta( $subheader, 'subheader_student_name', true ),
'title' => get_post_meta( $subheader, 'subheader_student_name', true ),
);
?>
<div class="col-md-12 col-sm-12">
<div id="subheader" role="complementary">
<div class="row">
<div class="col-md-2 col-sm-2">
<?php echo wp_get_attachment_image( $sub_img, 'subpage-subimg', 0, $sub_img_atts ); ?>
</div>
<div class="col-md-8 col-sm-8">
<blockquote class="subheader-quote">
<?php echo $subheader_post->post_content; ?>
<p class="subheader-author text-right"><?php echo $student_name; ?></p>
</blockquote>
</div>
</div>
<?php echo wp_get_attachment_image( $student_img, 'subpage-studentimg', 0, $student_img_atts ); ?>
</div>
</div>
<?php
}
return ob_get_clean();
}
/**
* Output Spotlights for front page.
*
* Note: this function assumes at least 2 spotlights already exist
* and that only 2 spotlights at a time should ever be displayed.
**/
function frontpage_spotlights() {
$args = array(
'numberposts' => 2,
'post_type' => 'spotlight',
'post_status' => 'publish',
);
$spotlights = get_posts($args);
$spotlight_one = $spotlights[0];
$spotlight_two = $spotlights[1];
$position_one = get_post_meta($spotlight_one->ID, 'spotlight_position', TRUE);
$position_two = get_post_meta($spotlight_two->ID, 'spotlight_position', TRUE);
function output_spotlight($spotlight) {
?>
<div class="home_spotlight_single">
<a href="<?=get_permalink($spotlight->ID)?>" class="ga-event" data-ga-action="Spotlight Link" data-ga-label="<?=$spotlight->post_title?>">
<?php
$thumb_id = get_post_thumbnail_id($spotlight->ID);
$thumb_src = wp_get_attachment_image_src( $thumb_id, 'home-thumb' );
$thumb_src = $thumb_src[0];
?>
<?php if ($thumb_src) { ?>
<img class="print-only spotlight_thumb" src="<?=$thumb_src?>" />
<div class="screen-only spotlight_thumb" style="background-image:url('<?=$thumb_src?>');"><?=$spotlight->post_title?></div>
<?php } ?>
</a>
<h3 class="home_spotlight_title"><a href="<?=get_permalink($spotlight->ID)?>" class="ga-event" data-ga-action="Spotlight Link" data-ga-label="<?=$spotlight->post_title?>"><?=$spotlight->post_title?></a></h3>
<?=truncateHtml($spotlight->post_content, 200)?>
<p><a class="home_spotlight_readmore ga-event" href="<?=get_permalink($spotlight->ID)?>" target="_blank" data-ga-action="Spotlight Link" data-ga-label="<?=$spotlight->post_title?>">Read More…</a></p>
</div>
<?
}
// If neither positions are set, or the two positions conflict with each
// other, just display them in the order they were retrieved:
if (($position_one == '' && $position_two == '') || ($position_one == $position_two)) {
output_spotlight($spotlight_one);
output_spotlight($spotlight_two);
}
// If one is set but not the other, respect the set spotlight's position
// and place the other one in the other slot:
else if ($position_one == '' && $position_two !== '') {
if ($position_two == 'top') {
output_spotlight($spotlight_two);
output_spotlight($spotlight_one);
}
else {
output_spotlight($spotlight_one);
output_spotlight($spotlight_two);
}
}
else if ($position_one !== '' && $position_two == '') {
if ($position_one == 'top') {
output_spotlight($spotlight_one);
output_spotlight($spotlight_two);
}
else {
output_spotlight($spotlight_two);
output_spotlight($spotlight_one);
}
}
// Otherwise, display them in their designated positions:
else {
if ($position_one == 'top') { // we can assume position_two is the opposite
output_spotlight($spotlight_one);
output_spotlight($spotlight_two);
}
else {
output_spotlight($spotlight_two);
output_spotlight($spotlight_one);
}
}
}
/**
* Pulls, parses and caches the weather.
*
* @return array
* @author Chris Conover, Jo Greybill
**/
function get_weather_data() {
$cache_key = 'weather';
// Check if cached weather data already exists
if(($weather = get_transient($cache_key)) !== False) {
return $weather;
} else {
$weather = array('condition' => 'Fair', 'temp' => '80º', 'img' => '34');
// Set a timeout
$opts = array('http' => array(
'method' => 'GET',
'timeout' => WEATHER_FETCH_TIMEOUT,
));
$context = stream_context_create($opts);
// Grab the weather feed
$raw_weather = file_get_contents(WEATHER_URL, false, $context);
if ($raw_weather) {
$json = json_decode($raw_weather);
$weather['condition'] = $json->condition;
$weather['temp'] = $json->temp;
$weather['img'] = (string)$json->imgCode;
// The temp, condition and image code should always be set,
// but in case they're not, we catch them here:
# Catch missing cid
if (!isset($weather['img']) or !$weather['img']){
$weather['img'] = '34';
}
# Catch missing condition
if (!is_string($weather['condition']) or !$weather['condition']){
$weather['condition'] = 'Fair';
}
# Catch missing temp
if (!isset($weather['temp']) or !$weather['temp']){
$weather['temp'] = '80º';
}
}
// Cache the new weather data
set_transient($cache_key, $weather, WEATHER_CACHE_DURATION);
return $weather;
}
}
/**
* Output weather data. Add an optional class for easy Bootstrap styling.
**/
function output_weather_data($cssclass=null) {
$cssclass = is_string($cssclass) ? strip_tags($cssclass) : (string)strip_tags($cssclass);
$weather = get_weather_data();
$condition = $weather['condition'];
$temp = $weather['temp'];
$img = $weather['img']; ?>
<div id="weather_bug" class="<?=$cssclass?> screen-only" role="complementary">
<div id="wb_status_txt" style="background: url(<?php bloginfo('stylesheet_directory'); ?>/static/img/weather/<?=$img?>.png) left center no-repeat;"><span><?=$temp?>F, <?=$condition?></span></div>
</div>
<?php
}
/**
* Get and display announcements.
* Note that, like the old Announcements advanced search, only one
* search parameter (role, keyword, or time) can be set at a time.
* Default (no args) returns all roles within the past week
* (starting from Monday).
**/
function get_announcements($role='all', $keyword=NULL, $time='thisweek') {
// Get some dates for meta_query comparisons:
$today = date('Y-m-d');
$thismonday = date('Y-m-d', strtotime('monday this week'));
$thissunday = date('Y-m-d', strtotime($thismonday.' + 6 days'));
$nextmonday = date('Y-m-d', strtotime('monday next week'));
$nextsunday = date('Y-m-d', strtotime($nextmonday.' + 6 days'));
$firstday_thismonth = date('Y-m-d', strtotime('first day of this month'));
$lastday_thismonth = date('Y-m-d', strtotime('last day of this month'));
$firstday_nextmonth = date('Y-m-d', strtotime('first day of next month'));
$lastday_nextmonth = date('Y-m-d', strtotime('last day of next month'));
// Set up query args based on GET params:
$args = array(
'numberposts' => -1,
'post_type' => 'announcement',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_key' => 'announcement_start_date',
);
// Announcement time queries should allow posts to fall within the week, even if
// their start and end dates do not fall immediately within the given time
// (allow for ongoing events that span during the given time, and then some).
// Announcements should, however, be excluded if their end date has already passed.
if ($role !== 'all') {
$role_args = array(
'tax_query' => array(
array(
'taxonomy' => 'audienceroles',
'field' => 'slug',
'terms' => $role,
)
),
'meta_query' => array(
array(
'key' => 'announcement_start_date',
'value' => $thissunday,
'compare' => '<='
),
array(
'key' => 'announcement_end_date',
'value' => $today,
'compare' => '>='
),
),
);
$args = array_merge($args, $role_args);
}
elseif ($keyword !== NULL) {
$keyword_args = array(
's' => $keyword,
'meta_query' => array(
array(
'key' => 'announcement_start_date',
'value' => $thissunday,
'compare' => '<='
),
array(
'key' => 'announcement_end_date',
'value' => $today,
'compare' => '>='
),
),
);
$args = array_merge($args, $keyword_args);
}
elseif ($time !== 'thisweek') {
switch ($time) {
case 'nextweek':
$time_args = array(
'meta_query' => array(
array(
'key' => 'announcement_start_date',
'value' => $nextsunday,
'compare' => '<='
),
array(
'key' => 'announcement_end_date',
'value' => $nextmonday,
'compare' => '>='
),
array(
'key' => 'announcement_end_date',
'value' => $today,
'compare' => '>='
),
),
);
$args = array_merge($args, $time_args);
break;
case 'thismonth':
$time_args = array(
'meta_query' => array(
array(
'key' => 'announcement_start_date',
'value' => $lastday_thismonth,
'compare' => '<='
),
array(
'key' => 'announcement_end_date',
'value' => $today,
'compare' => '>='
),
),
);
$args = array_merge($args, $time_args);
break;
case 'nextmonth':
$time_args = array(
'meta_query' => array(
array(
'key' => 'announcement_start_date',
'value' => $lastday_nextmonth,
'compare' => '<='
),
array(
'key' => 'announcement_end_date',
'value' => $firstday_nextmonth,
'compare' => '>='
),
array(
'key' => 'announcement_end_date',
'value' => $today,
'compare' => '>='
),
),
);
$args = array_merge($args, $time_args);
break;
case 'thissemester':
// Compare the current month to predefined month values
// to pull announcements from the current semester
// Check for Spring Semester
if (CURRENT_MONTH >= SPRING_MONTH_START && CURRENT_MONTH <= SPRING_MONTH_END) {
$time_args = array(
'meta_query' => array(
array(
'key' => 'announcement_start_date',
'value' => date('Y-m-t', strtotime('May')),
'compare' => '<='
),
array(
'key' => 'announcement_end_date',
'value' => $today,
'compare' => '>='
),
),
);
$args = array_merge($args, $time_args);
}
// Check for Summer Semester
elseif (CURRENT_MONTH >= SUMMER_MONTH_START && CURRENT_MONTH <= SUMMER_MONTH_END) {
$time_args = array(
'meta_query' => array(
array(
'key' => 'announcement_start_date',
'value' => date('Y-m-t', strtotime('July')),
'compare' => '<='
),
array(
'key' => 'announcement_end_date',
'value' => $today,
'compare' => '>='
),
),
);
$args = array_merge($args, $time_args);
}
// else, it's the Fall Semester
else {
$time_args = array(
'meta_query' => array(
array(
'key' => 'announcement_start_date',
'value' => date('Y-m-t', strtotime('December')),
'compare' => '<='
),
array(
'key' => 'announcement_end_date',
'value' => $today,
'compare' => '>='
),
),
);
$args = array_merge($args, $time_args);
}
break;
case 'all':
$time_args = array(
'meta_query' => array(
array(
'key' => 'announcement_end_date',
'value' => $today,
'compare' => '>='
),
),
);
$args = array_merge($args, $time_args);
break;
default:
$time_args = array(
'meta_query' => array(
array(
'key' => 'announcement_start_date',
'value' => $thissunday,
'compare' => '<='
),
array(
'key' => 'announcement_end_date',
'value' => $today,
'compare' => '>='
),
),
);
$args = array_merge($args, $time_args);
break;
}
}
else { // default retrieval args
$fallback_args = array(
'meta_query' => array(
array(
'key' => 'announcement_start_date',
'value' => $thissunday,
'compare' => '<='
),
array(
'key' => 'announcement_end_date',
'value' => $today,
'compare' => '>='
),
),
);
$args = array_merge($args, $fallback_args);
}
// Fetch all announcements based on args given above:
$announcements = get_posts($args);
if (!($announcements)) {
return NULL;
}
else {
// Add relevant metadata to each post object so they
// can be more easily accessed:
foreach ($announcements as $announcement) {
$announcement->announcementStartDate = get_post_meta($announcement->ID, 'announcement_start_date', TRUE);
$announcement->announcementEndDate = get_post_meta($announcement->ID, 'announcement_end_date', TRUE);
$announcement->announcementURL = get_post_meta($announcement->ID, 'announcement_url', TRUE);
$announcement->announcementContactPerson = get_post_meta($announcement->ID, 'announcement_contact', TRUE);
$announcement->announcementPhone = get_post_meta($announcement->ID, 'announcement_phone', TRUE);
$announcement->announcementEmail = get_post_meta($announcement->ID, 'announcement_email', TRUE);
$announcement->announcementPostedBy = get_post_meta($announcement->ID, 'announcement_posted_by', TRUE);
$announcement->announcementRoles = wp_get_post_terms($announcement->ID, 'audienceroles', array("fields" => "names"));
$announcement->announcementKeywords = wp_get_post_terms($announcement->ID, 'keywords', array("fields" => "names"));
$announcement->announcementIsNew = ( date('Ymd') - date('Ymd', strtotime($announcement->post_date) ) <= 2 ) ? true : false;
// Fallback for bad date ranges--force the start date to equal
// the end date if the start date is later than the end date
if ( date('Ymd', strtotime($announcement->announcementStartDate)) > date('Ymd', strtotime($announcement->announcementEndDate)) ) {
$announcement->announcementStartDate = $announcement->announcementEndDate;
}
}
return $announcements;
}
}
/**
* Prints a set of announcements, given an announcements array
* returned from get_announcements().
**/
function print_announcements($announcements, $liststyle='thumbtacks', $spantype='col-md-4 col-sm-4', $perrow=3) {
switch ($liststyle) {
case 'list':
print '<ul class="announcement_list list-unstyled">';
// Simple list of announcements; no descriptions.
// $spantype and $perrow are not used here.
foreach ($announcements as $announcement) {
ob_start(); ?>
<li><h3><a href="<?=get_permalink($announcement->ID)?>"><?=$announcement->post_title?></a></h3></li>
<?php
print ob_get_clean();
}
print '</ul>';
break;
case 'thumbtacks':
// Grid of thumbtack-styled announcements
print '<div class="row">';
$count = 0;
foreach ($announcements as $announcement) {
if ($count % $perrow == 0 && $count !== 0) {
print '</div><div class="row">';
}
ob_start();
?>
<div class="<?=$spantype?>" id="announcement_<?=$announcement->ID?>">
<div class="announcement_wrap">
<div class="thumbtack"></div>
<?php if ($announcement->announcementIsNew == true) { ?><div class="new">New Announcement</div><?php } ?>
<h3><a href="<?=get_permalink($announcement->ID)?>"><?=$announcement->post_title?></a></h3>
<p class="date">
<?php if ($announcement->announcementStartDate == $announcement->announcementEndDate) {
print date('M d', strtotime($announcement->announcementEndDate));
} else {
print date('M d', strtotime($announcement->announcementStartDate)) .' - '. date('M d', strtotime($announcement->announcementEndDate));
}
?>
</p>
<p><?=truncateHtml(strip_tags($announcement->post_content, 200))?></p>
<p class="audience"><strong>Audience:</strong>
<?php
if ($announcement->announcementRoles) {
$rolelist = '';
foreach ($announcement->announcementRoles as $role) {
switch ($role) {
case 'Alumni':
$link = '?role=alumni';
break;
case 'Faculty':
$link = '?role=faculty';
break;
case 'Prospective Students':
$link = '?role=prospective-students';
break;
case 'Public':
$link = '?role=public';
break;
case 'Staff':
$link = '?role=staff';
break;
case 'Students':
$link = '?role=students';
break;
default:
$link = '';
break;
}
$rolelist .= '<a class="print-noexpand" href="'.get_permalink().$link.'">'.$role.'</a>, ';
}
print substr($rolelist, 0, -2);
}
else { print 'n/a'; }
?>
</p>
<p class="keywords"><strong>Keywords:</strong>
<?php
if ($announcement->announcementKeywords) {
$keywordlist = '';
foreach ($announcement->announcementKeywords as $keyword) {
$keywordlist .= '<a class="print-noexpand" href="'.get_permalink().'?keyword='.$keyword.'">'.$keyword.'</a>, ';
}
print substr($keywordlist, 0, -2);
}
else { print 'n/a'; }
?>
</p>
</div>
</div>
<?php
print ob_get_clean();
$count++;
} // endforeach
print '</div>';
break;
default:
break;
}
}
/**
* Takes an announcements array from get_announcements() and outputs an RSS feed.
**/
function announcements_to_rss($announcements) {
header('Content-Type: application/rss+xml; charset=ISO-8859-1');
print '<?xml version="1.0" encoding="ISO-8859-1"?>';
print '<rss version="2.0" xmlns:announcement="'.get_site_url().'/announcements/">';
print '<channel>';
print '<title>University of Central Florida Announcements</title>';
print '<link>http://www.ucf.edu/</link>';
print '<language>en-us</language>';
print '<copyright>ucf.edu</copyright>';
print '<ttl>1</ttl>'; // Time to live (in minutes); force a cache refresh after this time
print '<description>Feed for UCF Announcements.</description>';
function print_item($announcement) {
$output = '';
$output .= '<item>';
// Generic RSS story elements
$output .= '<title>'.htmlentities($announcement->post_title, ENT_COMPAT, 'UTF-8', false).'</title>';
$output .= '<description><![CDATA['.htmlentities(strip_tags($announcement->post_content)).']]></description>';
$output .= '<link>'.get_permalink($announcement->ID).'</link>';
$output .= '<guid>'.get_permalink($announcement->ID).'</guid>';
$output .= '<pubDate>'.date('r', strtotime($announcement->post_date)).'</pubDate>';
// Announcement-specific stuff
$output .= '<announcement:id>'.$announcement->ID.'</announcement:id>';
$output .= '<announcement:postStatus>'.$announcement->post_status.'</announcement:postStatus>';
$output .= '<announcement:postModified>'.$announcement->post_modified.'</announcement:postModified>';
$output .= '<announcement:published>'.$announcement->post_date.'</announcement:published>'; // same as <pubDate>
$output .= '<announcement:permalink>'.get_permalink($announcement->ID).'</announcement:permalink>'; // same as <guid>
$output .= '<announcement:postName>'.$announcement->post_name.'</announcement:postName>';
$output .= '<announcement:startDate>'.$announcement->announcementStartDate.'</announcement:startDate>';
$output .= '<announcement:endDate>'.$announcement->announcementEndDate.'</announcement:endDate>';
$output .= '<announcement:url>'.htmlentities($announcement->announcementURL).'</announcement:url>';
$output .= '<announcement:contactPerson>'.htmlentities($announcement->announcementContactPerson).'</announcement:contactPerson>';
$output .= '<announcement:phone>'.$announcement->announcementPhone.'</announcement:phone>';
$output .= '<announcement:email>'.htmlentities($announcement->announcementEmail).'</announcement:email>'; // need to account for special chars
$output .= '<announcement:postedBy>'.htmlentities($announcement->announcementPostedBy).'</announcement:postedBy>';
$output .= '<announcement:roles>';
if (!empty($announcement->announcementRoles)) {
foreach ($announcement->announcementRoles as $role) {
$roles .= $role.', ';
}
$roles = substr($roles, 0, -2);
$output .= $roles;
}
$output .= '</announcement:roles>';
$output .= '<announcement:keywords>';
if (!empty($announcement->announcementKeywords)) {
foreach ($announcement->announcementKeywords as $keyword) {
$keywords .= htmlentities($keyword, ENT_COMPAT, 'UTF-8', false) .', ';
}
$keywords = substr($keywords, 0, -2);
$output .= $keywords;
}
$output .= '</announcement:keywords>';
$output .= '<announcement:isNew>';
$announcement->announcementIsNew == true ? $output .= 'true' : $output .= 'false';
$output .= '</announcement:isNew>';
$output .= '</item>';
$roles = '';
$keywords = '';
print $output;
}
if ($announcements !== NULL) {
// $announcements will always be an array of objects
foreach ($announcements as $announcement) {
print_item($announcement);
}
}
print '</channel></rss>';
}
/*
* Returns a theme option value or NULL if it doesn't exist
*/
function get_theme_option($key) {
global $theme_options;
return isset($theme_options[$key]) ? $theme_options[$key] : NULL;
}
/*
* Wrap a statement in a ESI include tag with a specified duration if the
* enable_esi theme option is enabled.
*/
function esi_include($statementname, $argset=null) {
if (!$statementname) { return null; }
// Get the statement key
$statementkey = null;
foreach (Config::$esi_whitelist as $key=>$function) {
if ($function['name'] == $statementname) { $statementkey = $key;}
}
if (!$statementkey) { return null; }
// Never include ESI over HTTPS
$enable_esi = get_theme_option('enable_esi');
if(!is_null($enable_esi) && $enable_esi === '1' && is_ssl() == false) {
$argset = ($argset !== null) ? $argset = '&args='.urlencode(base64_encode($argset)) : '';
?>
<esi:include src="<?php echo ESI_INCLUDE_URL?>?statement=<?=$statementkey?><?=$argset?>" />
<?php
} elseif (array_key_exists($statementkey, Config::$esi_whitelist)) {
$statementname = Config::$esi_whitelist[$statementkey]['name'];
$statementargs = Config::$esi_whitelist[$statementkey]['safe_args'];
// If no safe arguments are defined in the whitelist for this statement,
// run call_user_func(); otherwise check arguments and run call_user_func_array()
if (!is_array($statementargs) || $argset == null) {
return call_user_func($statementname);
}
else {
// Convert argset arrays to strings for easy comparison with our whitelist
$argset = is_array($argset) ? serialize($argset) : $argset;
if ($argset !== null && in_array($argset, $statementargs)) {
$argset = (unserialize($argset) !== false) ? unserialize($argset) : array($argset);
return call_user_func_array($statementname, $argset);
}
}
}
else {
return NULL;
}
}
/**
* Pull recent Gravity Forms entries from a given form (intended for Feedback form.)
* If no formid argument is provided, the function will pick the form
* with ID of 1 by default.
* Duration is specified in number of days.
**/
function get_feedback_entries($formid=1, $duration=7, $to=array('webcom@ucf.edu')) {
// Check that GF is actually installed
if (is_plugin_inactive('gravityforms/gravityforms.php')) {
die('Error: Gravity Forms is not activated. Please install/activate Gravity Forms and try again.');
}
// Make sure a valid email address to send to is set