18
18
a fallback to display the actual month/year.
19
19
*/
20
20
21
- $ begun = FALSE ; $ errors = array ();
21
+ $ begun = false ; $ errors = array ();
22
22
$ id = isset ($ _GET ['id ' ]) ? (int ) $ _GET ['id ' ] : 0 ;
23
23
$ cy = isset ($ _GET ['cy ' ]) ? (int ) $ _GET ['cy ' ] : 0 ;
24
24
$ cm = isset ($ _GET ['cm ' ]) ? (int ) $ _GET ['cm ' ] : 0 ;
37
37
if ($ event = load_event ($ id )) {
38
38
site_header ("Event: " . stripslashes (htmlentities ($ event ['sdesc ' ], ENT_QUOTES | ENT_IGNORE , 'UTF-8 ' )), $ site_header_config );
39
39
display_event ($ event , 0 );
40
- $ begun = TRUE ;
40
+ $ begun = true ;
41
41
}
42
42
// Unable to find event, put this to the error messages' list
43
43
else {
49
49
elseif ($ cy && $ cm && $ cd ) {
50
50
51
51
// Check if date is valid
52
- if (checkdate ($ cm ,$ cd ,$ cy )) {
52
+ if (checkdate ($ cm , $ cd , $ cy )) {
53
53
54
54
// Date integer for that day
55
55
$ date = mktime (0 , 0 , 1 , $ cm , $ cd , $ cy );
63
63
display_event ($ event , 0 );
64
64
echo "<br> " ;
65
65
}
66
- $ begun = TRUE ;
66
+ $ begun = true ;
67
67
}
68
68
69
69
// Unable to load events for that day
70
70
else {
71
- $ errors [] = "There are no events for the specified date ( " .date ("F j, Y " ,$ date )."). " ;
71
+ $ errors [] = "There are no events for the specified date ( " .date ("F j, Y " , $ date )."). " ;
72
72
}
73
73
}
74
74
80
80
}
81
81
82
82
// Check if month and year is valid
83
- if ($ cm && $ cy && !checkdate ($ cm ,1 , $ cy )) {
83
+ if ($ cm && $ cy && !checkdate ($ cm , 1 , $ cy )) {
84
84
$ errors [] = "The specified year and month ( " .htmlentities ("$ cy, $ cm " , ENT_QUOTES | ENT_IGNORE , 'UTF-8 ' ).") are not valid. " ;
85
85
unset($ cm , $ cy );
86
86
}
87
87
88
88
// Give defaults for the month and day values if they were invalid
89
- if (empty ($ cm )) { $ cm = date ("m " ); }
90
- if (empty ($ cy )) { $ cy = date ("Y " ); }
89
+ if (empty ($ cm )) {
90
+ $ cm = date ("m " );
91
+ }
92
+ if (empty ($ cy )) {
93
+ $ cy = date ("Y " );
94
+ }
91
95
92
96
// Start of the month date
93
97
$ date = mktime (0 , 0 , 1 , $ cm , 1 , $ cy );
94
98
95
99
if (!$ begun ) {
96
- site_header ("Events: " .date ("F Y " , $ date ), $ site_header_config );
97
- ?>
100
+ site_header ("Events: " .date ("F Y " , $ date ), $ site_header_config ); ?>
98
101
<div class="tip">
99
102
<p>
100
103
If you would like to suggest an upcoming event to be listed on this
110
113
}
111
114
112
115
// Get events list for a whole month
113
- $ events = load_events ($ date , TRUE );
116
+ $ events = load_events ($ date , true );
114
117
115
118
// If there was an error, or there are no events, this is an error
116
- if ($ events === FALSE || count ($ events ) == 0 ) {
119
+ if ($ events === false || count ($ events ) == 0 ) {
117
120
$ errors [] = "No events found for this month " ;
118
121
}
119
122
125
128
}
126
129
127
130
// Beginning and end of this month
128
- $ bom = mktime (0 , 0 , 1 , $ cm , 1 , $ cy );
131
+ $ bom = mktime (0 , 0 , 1 , $ cm , 1 , $ cy );
129
132
$ eom = mktime (0 , 0 , 1 , $ cm +1 , 0 , $ cy );
130
133
131
134
// Link to previous month (but do not link to too early dates)
132
- $ prev_link = (function () use ($ cm , $ cy ) {
135
+ $ prev_link = (function () use ($ cm , $ cy ) {
133
136
$ lm = mktime (0 , 0 , 1 , $ cm , 0 , $ cy );
134
137
$ year = date ('Y ' , $ lm );
135
138
if (!valid_year ($ year )) {
138
141
139
142
$ month = date ('m ' , $ lm );
140
143
$ monthName = date ('F ' , $ lm );
141
- return sprintf ('<a href="/cal.php?cm=%s&cy=%s">%s, %s</a> ' ,
142
- urlencode ($ month ),
143
- urlencode ($ year ),
144
- htmlentities ($ monthName ),
145
- htmlentities ($ year ));
144
+ return sprintf (
145
+ '<a href="/cal.php?cm=%s&cy=%s">%s, %s</a> ' ,
146
+ urlencode ($ month ),
147
+ urlencode ($ year ),
148
+ htmlentities ($ monthName ),
149
+ htmlentities ($ year )
150
+ );
146
151
})();
147
152
148
153
// Link to next month (but do not link to too early dates)
149
- $ next_link = (function () use ($ cm , $ cy ) {
154
+ $ next_link = (function () use ($ cm , $ cy ) {
150
155
$ nm = mktime (0 , 0 , 1 , $ cm +1 , 1 , $ cy );
151
156
$ year = date ('Y ' , $ nm );
152
157
if (!valid_year ($ year )) {
155
160
156
161
$ month = date ('m ' , $ nm );
157
162
$ monthName = date ('F ' , $ nm );
158
- return sprintf ('<a href="/cal.php?cm=%s&cy=%s">%s, %s</a> ' ,
159
- urlencode ($ month ),
160
- urlencode ($ year ),
161
- htmlentities ($ monthName ),
162
- htmlentities ($ year ));
163
+ return sprintf (
164
+ '<a href="/cal.php?cm=%s&cy=%s">%s, %s</a> ' ,
165
+ urlencode ($ month ),
166
+ urlencode ($ year ),
167
+ htmlentities ($ monthName ),
168
+ htmlentities ($ year )
169
+ );
163
170
})();
164
171
165
172
// Print out navigation links for previous and next month
174
181
175
182
// Print out headers for weekdays
176
183
for ($ i = 0 ; $ i < 7 ; $ i ++) {
177
- echo '<th width="14%"> ' , date ("l " ,mktime (0 ,0 , 1 , 4 , $ i +1 ,2001 )), "</th> \n" ;
184
+ echo '<th width="14%"> ' , date ("l " , mktime (0 , 0 , 1 , 4 , $ i +1 , 2001 )), "</th> \n" ;
178
185
}
179
186
echo "</tr> \n<tr> " ;
180
187
181
188
// Generate the requisite number of blank days to get things started
182
- for ($ days = $ i = date ("w " ,$ bom ); $ i > 0 ; $ i --) {
189
+ for ($ days = $ i = date ("w " , $ bom ); $ i > 0 ; $ i --) {
183
190
echo '<td class="notaday"> </td> ' ;
184
191
}
185
192
186
193
// Print out all the days in this month
187
- for ($ i = 1 ; $ i <= date ("t " ,$ bom ); $ i ++) {
194
+ for ($ i = 1 ; $ i <= date ("t " , $ bom ); $ i ++) {
188
195
189
196
// Print out day number and all events for the day
190
197
echo '<td><a class="day" href="/cal.php ' , "?cm= $ cm&cd= $ i&cy= $ cy " ,
191
198
'"> ' ,$ i ,'</a> ' ;
192
- display_events_for_day (date ("Y-m- " ,$ bom ).sprintf ("%02d " ,$ i ), $ events );
199
+ display_events_for_day (date ("Y-m- " , $ bom ).sprintf ("%02d " , $ i ), $ events );
193
200
echo '</td> ' ;
194
201
195
202
// Break HTML table row if at end of week
196
- if (++$ days % 7 == 0 ) echo "</tr> \n<tr> " ;
203
+ if (++$ days % 7 == 0 ) {
204
+ echo "</tr> \n<tr> " ;
205
+ }
197
206
}
198
207
199
208
// Generate the requisite number of blank days to wrap things up
@@ -218,11 +227,11 @@ function date_for_recur($recur, $day, $bom, $eom)
218
227
if ($ recur > 0 ) {
219
228
$ bomd = date ("w " , $ bom ) + 1 ;
220
229
$ days = (($ day - $ bomd + 7 ) % 7 ) + (($ recur - 1 ) * 7 );
221
- return mktime (0 ,0 , 1 , date ("m " ,$ bom ), $ days + 1 , date ("Y " ,$ bom ));
230
+ return mktime (0 , 0 , 1 , date ("m " , $ bom ), $ days + 1 , date ("Y " , $ bom ));
222
231
}
223
232
224
233
// ${recur}th to last $day of the month
225
- $ eomd = date ("w " ,$ eom ) + 1 ;
234
+ $ eomd = date ("w " , $ eom ) + 1 ;
226
235
$ days = (($ eomd - $ day + 7 ) % 7 ) + ((abs ($ recur ) - 1 ) * 7 );
227
236
228
237
return mktime (0 , 0 , 1 , date ("m " , $ bom )+1 , -$ days , date ("Y " , $ bom ));
@@ -256,57 +265,63 @@ function display_events_for_day($day, $events): void
256
265
function load_event ($ id )
257
266
{
258
267
// Open events CSV file, return on error
259
- $ fp = @fopen ("backend/events.csv " ,'r ' );
260
- if (!$ fp ) { return FALSE ; }
268
+ $ fp = @fopen ("backend/events.csv " , 'r ' );
269
+ if (!$ fp ) {
270
+ return false ;
271
+ }
261
272
262
273
// Read as we can, event by event
263
274
while (!feof ($ fp )) {
275
+ $ event = read_event ($ fp );
264
276
265
- $ event = read_event ($ fp );
266
-
267
- // Return with the event, if it's ID is the one
268
- // we search for (also close the file)
269
- if ($ event !== FALSE && $ event ['id ' ] == $ id ) {
270
- fclose ($ fp );
271
- return $ event ;
272
- }
277
+ // Return with the event, if it's ID is the one
278
+ // we search for (also close the file)
279
+ if ($ event !== false && $ event ['id ' ] == $ id ) {
280
+ fclose ($ fp );
281
+ return $ event ;
282
+ }
273
283
}
274
284
275
285
// Close file, and return sign of failure
276
286
fclose ($ fp );
277
- return FALSE ;
287
+ return false ;
278
288
}
279
289
280
290
// Load a list of events. Either for a particular day ($from) or a whole
281
291
// month (if second parameter specified with TRUE)
282
- function load_events ($ from , $ whole_month = FALSE )
292
+ function load_events ($ from , $ whole_month = false )
283
293
{
284
294
// Take advantage of the equality behavior of this date format
285
295
$ from_date = date ("Y-m-d " , $ from );
286
- $ bom = mktime (0 , 0 , 1 , date ("m " ,$ from ), 1 , date ("Y " ,$ from ));
287
- $ eom = mktime (0 , 0 , 1 , date ("m " ,$ from ) + 1 , 0 , date ("Y " ,$ from ));
296
+ $ bom = mktime (0 , 0 , 1 , date ("m " , $ from ), 1 , date ("Y " , $ from ));
297
+ $ eom = mktime (0 , 0 , 1 , date ("m " , $ from ) + 1 , 0 , date ("Y " , $ from ));
288
298
$ to_date = date ("Y-m-d " , $ whole_month ? $ eom : $ from );
289
299
290
300
// Set arrays to their default
291
301
$ events = $ seen = array ();
292
302
293
303
// Try to open the events file for reading, return if unable to
294
- $ fp = @fopen ("backend/events.csv " ,'r ' );
295
- if (!$ fp ) { return FALSE ; }
304
+ $ fp = @fopen ("backend/events.csv " , 'r ' );
305
+ if (!$ fp ) {
306
+ return false ;
307
+ }
296
308
297
309
// For all events, read in the event and check it if fits our scope
298
310
while (!feof ($ fp )) {
299
311
300
312
// Read the event data into $event, or continue with next
301
313
// line, if there was an error with this line
302
- if (($ event = read_event ($ fp )) === FALSE ) {
314
+ if (($ event = read_event ($ fp )) === false ) {
303
315
continue ;
304
316
}
305
317
306
318
// Keep event's seen list up to date
307
319
// (for repeating events with the same ID)
308
- if (!isset ($ seen [$ event ['id ' ]])) { $ seen [$ event ['id ' ]] = 1 ; }
309
- else { continue ; }
320
+ if (!isset ($ seen [$ event ['id ' ]])) {
321
+ $ seen [$ event ['id ' ]] = 1 ;
322
+ } else {
323
+ continue ;
324
+ }
310
325
311
326
// Check if event is in our scope, depending on type
312
327
switch ($ event ['type ' ]) {
@@ -318,6 +333,7 @@ function load_events($from, $whole_month = FALSE)
318
333
// Fall through. Now it is just like a single-day event
319
334
320
335
// Single-day event
336
+ // no break
321
337
case 1 :
322
338
if ($ event ['start ' ] >= $ from_date && $ event ['start ' ] <= $ to_date ) {
323
339
$ events [] = $ event ;
@@ -329,7 +345,7 @@ function load_events($from, $whole_month = FALSE)
329
345
if (($ event ['start ' ] >= $ from_date && $ event ['start ' ] <= $ to_date )
330
346
|| ($ event ['end ' ] >= $ from_date && $ event ['end ' ] <= $ to_date )
331
347
|| ($ event ['start ' ] <= $ from_date && $ event ['end ' ] >= $ to_date )) {
332
- $ events [] = $ event ;
348
+ $ events [] = $ event ;
333
349
}
334
350
break ;
335
351
}
@@ -345,12 +361,14 @@ function load_events($from, $whole_month = FALSE)
345
361
function read_event ($ fp )
346
362
{
347
363
// We were unable to read a line from the file, return
348
- if (($ linearr = fgetcsv ($ fp , 8192 )) === FALSE ) {
349
- return FALSE ;
364
+ if (($ linearr = fgetcsv ($ fp , 8192 )) === false ) {
365
+ return false ;
350
366
}
351
367
352
368
// Corrupt line in CSV file
353
- if (count ($ linearr ) < 13 ) { return FALSE ; }
369
+ if (count ($ linearr ) < 13 ) {
370
+ return false ;
371
+ }
354
372
355
373
// Get components
356
374
list (
@@ -386,11 +404,11 @@ function valid_year($year)
386
404
387
405
// We only allow this and the next year for displays
388
406
if ($ year != $ current_year && $ year != $ current_year +1 ) {
389
- return FALSE ;
407
+ return false ;
390
408
}
391
409
392
410
// The year is all right
393
- return TRUE ;
411
+ return true ;
394
412
}
395
413
396
414
?>
0 commit comments