-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage-events.php
139 lines (113 loc) · 6.16 KB
/
page-events.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
<?php get_header(); ?>
<div id="content" class='main--content'>
<?php wp_nav_menu(array('container' => 'nav', 'theme_location' => 'category-filter', 'fallback_cb' => 'false')); ?>
<div id="events" class="events-page article--single"><h1 class="page--title">Events Calendar</h1>
<?php
$blue_custom_options = get_option('blue_theme_options');
$calendarfeed = esc_url($blue_custom_options['gCal']);
// Your private feed - which you get by right-clicking the 'xml' button in the 'Private Address' section of 'Calendar Details'.
if (!isset($calendarfeed)) {$calendarfeed = "https://www.google.com/calendar/feeds/boisestate.edu_gs6ue8qh2i1tvp94lsqi7jmtd4%40group.calendar.google.com/private-e06dad3bdc55920bd251c7532f042ea1/basic"; }
// Date format you want your details to appear
$dateformat="m.d.Y"; // 10 March 2009 - see http://www.php.net/date for details
$timeformat="g:iA"; // 12.15am
//Time offset - if times are appearing too early or too late on your website, change this.
$offset = -7;
// Adjust for daylight savings
$offset -= date("I");
$offset .= "hours"; // you can use "+1 hour" here for example
// you can also use $offset="now";
// How you want each thing to display.
// By default, this contains all the bits you can grab. You can put ###DATE### in here too if
// you want to, and disable the 'group by date' below.
$event_display.= "<article class='events'><h2> ###TITLE### </h2>";
$event_display.="<p class='events'>###DATE### | ###TIME###";
$event_display .= " | ###WHERE### </p><p class='description'>###DESCRIPTION###</p></article>";
// What happens if there's nothing to display
$event_error="<p>There are no events to display.</p>";
// The separate date header is here
$event_dateheader="";
$GroupByDate=false;
// Change the above to 'false' if you don't want to group this by dates,
// but remember to add ###DATE### in the event_display if you do.
// ...and how many you want to display (leave at 999 for everything)
$items_to_show=12;
// Change this to 'true' to see lots of fancy debug code
$debug_mode=false;
//
//End of configuration block
/////////
if ($debug_mode) {error_reporting (E_ALL); echo "<P>Debug mode is on.</p>";}
// Form the XML address.
$calendar_xml_address = str_replace("/basic","/full?singleevents=true&futureevents=true&orderby=starttime&sortorder=a",$calendarfeed); //This goes and gets future events in your feed.
if ($debug_mode) {
echo "<P>We're going to go and grab <a href='$calendar_xml_address'>this feed</a>.<P>";}
// Set the offset correctly
$offset=(strtotime("now")-strtotime($offset));
if ($debug_mode) {echo "Offset is ".$offset;}
if ( false === ( $cached_calendar = get_transient('blue_calendar_xml'))){
$xml = simplexml_load_file($calendar_xml_address);
set_transient('blue_calendar_xml', $xml->asXML(), 60*60*3); // expiration 60 sec = 1 min * 60 min = 1 hour * 3 hours
}
else{
$xml = simplexml_load_string($cached_calendar);
}
if ($debug_mode) {echo "<P>Successfully retrieved it.</p>";}
$items_shown=0;
if ($xml != ""){
$xml->asXML();
}
?><?php
foreach ($xml->entry as $entry){
$ns_gd = $entry->children('http://schemas.google.com/g/2005');
$description = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?,&//=]+)','<a href="\\1">\\1</a>', $entry->content);
//Do some niceness to the description
//Make any URLs used in the description clickable: thanks Adam
$description = preg_replace("~\n~", "<br />", $description, -1, $count);
// Make email addresses in the description clickable: thanks, Bjorn
$description = eregi_replace('([_.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})','<a
href="mailto:\\1">\\1</a>', $description);
// These are the dates we'll display
$start = $ns_gd->when->attributes()->startTime;
error_log(strlen((string)$start));
if (strlen((string)$start) < 12){
$gCalDate = date($dateformat, strtotime($ns_gd->when->attributes()->startTime));
$gCalEndDate = date($dateformat, strtotime($ns_gd->when->attributes()->endTime)-1);
}
else{
$gCalDate = date($dateformat, strtotime($ns_gd->when->attributes()->startTime)-$offset);
$gCalEndDate = date($dateformat, strtotime($ns_gd->when->attributes()->endTime)-$offset);
}
$gCalStartTime = date($timeformat, strtotime($ns_gd->when->attributes()->startTime)-$offset);
$gCalEndTime = date($timeformat, strtotime($ns_gd->when->attributes()->endTime)-$offset);
// Now, let's run it through some str_replaces, and store it with the date for easy sorting later
$temp_event=$event_display;
$temp_dateheader=$event_dateheader;
$temp_event=str_replace("###DESCRIPTION###",$description,$temp_event);
$temp_event=str_replace("###TITLE###",$entry->title,$temp_event);
$temp_dateheader=str_replace("###DATE###",$gCalDate,$temp_dateheader);
if ($gCalDate == $gCalEndDate){
$temp_event=str_replace("###DATE###",$gCalDate,$temp_event);
$temp_event=str_replace("###TIME###",$gCalStartTime . " - " . $gCalEndTime,$temp_event);
}
else{
$temp_event=str_replace("###DATE###",$gCalDate . " - " . $gCalEndDate,$temp_event);
$temp_event=str_replace("###TIME### |", "" ,$temp_event);
}
$temp_event=str_replace("###WHERE###",$ns_gd->where->attributes()->valueString,$temp_event);
$temp_event=str_replace("###LINK###",$entry->link->attributes()->href,$temp_event);
$temp_event=str_replace("###MAPLINK###","http://maps.google.com/?q=".urlencode($ns_gd->where->attributes()->valueString),$temp_event);
// Accept and translate HTML
$temp_event=str_replace("<","<",$temp_event);
$temp_event=str_replace(">",">",$temp_event);
$temp_event=str_replace(""","\"",$temp_event);
if (($items_to_show>0 AND $items_shown<$items_to_show)) {
if ($GroupByDate) {if ($gCalDate!=$old_date) { echo $temp_dateheader; $old_date=$gCalDate;}}
echo $temp_event;
$items_shown++;
}
}
if (!$items_shown) { echo $event_error; }?>
</div><!--/#articles -->
</div><!--/#main-content-front-->
<?php get_sidebar('single'); ?>
<?php get_footer(); ?>