-
Notifications
You must be signed in to change notification settings - Fork 0
/
schedule.php
266 lines (225 loc) · 6.79 KB
/
schedule.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
<?
// Set the base of the planner directory
$BASE = ".";
include_once("$BASE/autoload.inc");
// Define constants to be used in algorithms
define(ONE_DAY, 60*60*24);
define(ONE_WEEK, ONE_DAY * 7);
?>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Content-Type" content="text/html; charset=utf-8">
<meta name="Author" content="Andrew Marcus">
<title><? echo $styles['title']; ?> | Schedule</title>
<link href="../styles.css" rel="stylesheet" type="text/css">
<style type="text/css">
.year {
font-weight: bold;
font-size: 1.1em;
border-top: 1px solid <? echo $styles['hr_color']; ?>;
}
.date {
font-weight: bold;
}
.location {
font-size: 0.9em;
padding-left: 10px;
}
.title {
font-weight: bold;
padding-left: 10px;
color: #D47A13;
}
.description {
padding-top: 0.5em;
padding-left: 10px;
display: none;
}
span.updated {
font-weight: bold;
font-color: <? echo $styles['hr_color']; ?>
}
.expander {
font-weight: normal;
font-size: 0.9em;
}
.col-left {
float: left;
width: 49%;
padding-right: 5px;
}
.col-right {
float: right;
width: 49%;
padding-left: 5px;
}
</style>
<script type="text/javascript" language="javascript">
function toggleDescription(index) {
if (document.getElementById) {
var link = document.getElementById("link" + index);
var div = document.getElementById("descr" + index);
}
else if (document.all) {
var link = document.all["link" + index];
var div = document.all["descr" + index];
}
if (link != null) {
link.innerHTML = (link.innerHTML == "Show" ? "Hide" : "Show");
}
if (div != null) {
div.style.display = (div.style.display == "block" ? "none" : "block");
}
}
</script>
</head>
<body>
<div align="center">
<a href="<? echo $styles['main_site']; ?>"><img src="<? echo $styles['main_logo']; ?>" border="0" height=103 width=150></a>
</div>
<h2><? echo $styles['name']; ?> Schedule</h2>
<!p To see our practice schedule and a complete list of our events, <a href="http://www.google.com/calendar/embed?src=lohrgpkg1ag430e3l8oo2p5ki0%40group.calendar.google.com" view the complete calendar </a. </p>
<p class="backbutton"><a href="<? echo $styles['main_site']; ?>">Back</a></p>
<div class="container">
<div class="col-left">
<h3>Upcoming Confirmed Events</h3>
<? displayEvents(false); ?>
</div>
<div class="col-right">
<h3>Recent Events</h3>
<? displayEvents(true); ?>
</div>
</div>
<br clear="all"/>
<p class="credits">Powered by <a href="http://www.google.com/calendar">Google Calendars</a>, with some help from <a href="http://www.amarcus.org">Andrew Marcus</a></p>
</body>
</html>
<?
function displayEvents($reverse) {
$calendar = PCalendar::instance();
$calendar->getEventMaps(false, $reverse);
$calendar->store();
$year = "";
foreach ($calendar->eventTimeMap as $startTime => $ids) {
$startDate = PCalendar::parseISODateTime($startTime);
$startStamp = $startDate["timestamp"];
foreach ($ids as $id) {
$event = $calendar->getEvent($id);
$title = format($event->getTitle());
// Skip events whose title contains the words "practice" or "rehearsal" or ends in a question mark
if (contains($title, array("practice", "rehearsal", "audition", "?", "canceled", "cancelled"))) {
continue;
}
$newyear = date("Y", $startStamp);
// Sort all events into buckets by year
if ($newyear != $year) {
$year = $newyear;
?>
<p class="year"><? echo "$year" ?></p>
<?
}
// Get the end date
$endDate = $event->getEndTime();
$dateView = calculateDateView($startDate, $endDate);
// Render the event
printEvent($dateView, $title, $event);
}
}
}
// Describes the formatting for a single event
function printEvent($dateView, $title, $event) {
static $div_index;
if (!isset($div_index)) {
$div_index = 0;
}
$link_id = "link" . $div_index;
$div_id = "descr" . $div_index;
$details = $event->getDetails();
$location = $event->getLocation();
// Has this event been updated in the last week?
$updated = $event->getModifiedTime();
if ($updated["timestamp"] + ONE_WEEK > time()) {
$is_updated = true;
}
else {
$is_updated = false;
}
?>
<p class="calendar">
<div class="date"><? echo $dateView; ?></div>
<div class="title"><? echo $title; ?><? echo $is_updated ? ' <span class="updated">*</span>': ''; ?>
<? if (!empty($details)) : ?>
<span class="expander"><a href="javascript:toggleDescription(<? echo $div_index ?>)">[<span id="<? echo $link_id ?>">Show</span> Details]</a></span>
<? endif; ?>
</div>
<? if (!empty($location)) : ?>
<? $mapLink = "http://maps.google.com/maps?f=q&hl=en&q=" . urlencode($location); ?>
<div class="location"><? echo format($location); ?> [<a target="_blank" href="<? echo $mapLink; ?>">Map It</a>]</div>
<? endif; ?>
<? if (!empty($details)) : ?>
<div class="description" id="<? echo $div_id ?>"><? echo formatDescription($details); ?></div>
<? $div_index++; ?>
<? endif; ?>
</p>
<?
}
function calculateDateView($startISODate, $endISODate) {
// Get the start date
$startStamp = $startISODate["timestamp"];
$startMonth = $startISODate["month"];
$startDay = $startISODate["day"];
$startTime = $startISODate["timePart"];
// Get the end date
$endStamp = $endISODate["timestamp"];
$endMonth = $endISODate["month"];
$endDay = $endISODate["day"];
$endTime = $endISODate["timePart"];
// Render something useful as the start and end date
$dateView = date("D, M d", $startStamp);
// If the event spans more than one day, include an ending day
if ($endStamp > $startStamp + ONE_DAY) {
// If the event ends at midnight, report it in the previous day
if ($endTime == "") {
$dateView .= " to " . date("D, M d", $endStamp - ONE_DAY);
} else {
$dateView .= " to " . date("D, M d", $endStamp);
}
}
// Now print the start time of the event
if ($startTime != "") {
$dateView .= " - $startTime";
}
if ($endTime != "" && $endTime != $startTime) {
$dateView .= " to $endTime";
}
return preg_replace("/ /", " ", $dateView);
}
function format($str) {
return stripslashes(urldecode($str));
}
function formatDescription($str) {
$str = format($str);
$str = convertUrls($str);
$str = preg_replace("/ /", " ", $str);
$str = preg_replace("/\n/", "<br/>", $str);
return $str;
}
function convertUrls($str) {
$str = preg_replace("/<a rel=nofollow href=\"(\\S*)\" class=linkified target=_blank>\\S*?<\\/a>/i", "\\0", $str);
// $str = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a href=\"\\0\">\\0</a>", $str);
return $str;
}
function is_substr($haystack, $needle){
return stristr($haystack, $needle) ? true : false;
}
function contains($haystack, $needles) {
foreach ($needles as $needle) {
if (is_substr($haystack, $needle)) {
return true;
}
}
return false;
}
?>