Completed
Push — release-2.1 ( 2d94b4...31dcfd )
by Mert
07:42
created

Calendar.php ➔ iCalDownload()   F

Complexity

Conditions 17
Paths 12288

Size

Total Lines 96
Code Lines 57

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 17
eloc 57
nc 12288
nop 0
dl 0
loc 96
rs 2
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * This file has only one real task, showing the calendar.
5
 * Original module by Aaron O'Neil - [email protected]
6
 *
7
 * Simple Machines Forum (SMF)
8
 *
9
 * @package SMF
10
 * @author Simple Machines http://www.simplemachines.org
11
 * @copyright 2016 Simple Machines and individual contributors
12
 * @license http://www.simplemachines.org/about/smf/license.php BSD
13
 *
14
 * @version 2.1 Beta 3
15
 */
16
17
if (!defined('SMF'))
18
	die('No direct access...');
19
20
/**
21
 * Show the calendar.
22
 * It loads the specified month's events, holidays, and birthdays.
23
 * It requires the calendar_view permission.
24
 * It depends on the cal_enabled setting, and many of the other cal_ settings.
25
 * It uses the calendar_start_day theme option. (Monday/Sunday)
26
 * It uses the main sub template in the Calendar template.
27
 * It goes to the month and year passed in 'month' and 'year' by get or post.
28
 * It is accessed through ?action=calendar.
29
 * @return void
30
 */
31
function CalendarMain()
32
{
33
	global $txt, $context, $modSettings, $scripturl, $options, $sourcedir, $user_info, $smcFunc;
34
35
	// Permissions, permissions, permissions.
36
	isAllowedTo('calendar_view');
37
38
	// Some global template resources.
39
	$context['calendar_resources'] = array(
40
		'min_year' => $modSettings['cal_minyear'],
41
		'max_year' => $modSettings['cal_maxyear'],
42
	);
43
44
	// Doing something other than calendar viewing?
45
	$subActions = array(
46
		'ical' => 'iCalDownload',
47
		'post' => 'CalendarPost',
48
	);
49
50
	if (isset($_GET['sa']) && isset($subActions[$_GET['sa']]))
51
		return call_helper($subActions[$_GET['sa']]);
52
53
	// You can't do anything if the calendar is off.
54
	if (empty($modSettings['cal_enabled']))
55
		fatal_lang_error('calendar_off', false);
56
57
	// This is gonna be needed...
58
	loadTemplate('Calendar');
59
	loadCSSFile('calendar.css', array('force_current' => false, 'validate' => true, 'rtl' => 'calendar.rtl.css'), 'smf_calendar');
60
61
	// Did the specify an individual event ID? If so, let's splice the year/month in to what we would otherwise be doing.
62
	if (isset($_GET['event']))
63
	{
64
		$evid = (int) $_GET['event'];
65
		if ($evid > 0)
66
		{
67
			$request = $smcFunc['db_query']('', '
68
				SELECT start_date
69
				FROM {db_prefix}calendar
70
				WHERE id_event = {int:event_id}',
71
				array(
72
					'event_id' => $evid,
73
				)
74
			);
75
			if ($row = $smcFunc['db_fetch_assoc']($request))
76
			{
77
				// We know the format is going to be in yyyy-mm-dd from the database, so let's run with that.
78
				list($_REQUEST['year'], $_REQUEST['month']) = explode('-', $row['start_date']);
79
				$_REQUEST['year'] = (int) $_REQUEST['year'];
80
				$_REQUEST['month'] = (int) $_REQUEST['month'];
81
82
				// And we definitely don't want weekly view.
83
				unset ($_GET['viewweek']);
84
85
				// We might use this later.
86
				$context['selected_event'] = $evid;
87
			}
88
			$smcFunc['db_free_result']($request);
89
		}
90
		unset ($_GET['event']);
91
	}
92
93
	// Set the page title to mention the calendar ;).
94
	$context['page_title'] = $txt['calendar'];
95
96
	// Is this a week view?
97
	$context['view_week'] = isset($_GET['viewweek']);
98
99
	// Don't let search engines index weekly calendar pages.
100
	if ($context['view_week'])
101
		$context['robot_no_index'] = true;
102
103
	// Get the current day of month...
104
	require_once($sourcedir . '/Subs-Calendar.php');
105
	$today = getTodayInfo();
106
107
	// If the month and year are not passed in, use today's date as a starting point.
108
	$curPage = array(
109
		'day' => isset($_REQUEST['day']) ? (int) $_REQUEST['day'] : $today['day'],
110
		'month' => isset($_REQUEST['month']) ? (int) $_REQUEST['month'] : $today['month'],
111
		'year' => isset($_REQUEST['year']) ? (int) $_REQUEST['year'] : $today['year']
112
	);
113
114
	// Make sure the year and month are in valid ranges.
115
	if ($curPage['month'] < 1 || $curPage['month'] > 12)
116
		fatal_lang_error('invalid_month', false);
117
	if ($curPage['year'] < $modSettings['cal_minyear'] || $curPage['year'] > $modSettings['cal_maxyear'])
118
		fatal_lang_error('invalid_year', false);
119
	// If we have a day clean that too.
120
	if ($context['view_week'])
121
	{
122
		// Note $isValid is -1 < PHP 5.1
123
		$isValid = mktime(0, 0, 0, $curPage['month'], $curPage['day'], $curPage['year']);
124
		if ($curPage['day'] > 31 || !$isValid || $isValid == -1)
125
			fatal_lang_error('invalid_day', false);
126
	}
127
128
	// Load all the context information needed to show the calendar grid.
129
	$calendarOptions = array(
130
		'start_day' => !empty($options['calendar_start_day']) ? $options['calendar_start_day'] : 0,
131
		'show_birthdays' => in_array($modSettings['cal_showbdays'], array(1, 2)),
132
		'show_events' => in_array($modSettings['cal_showevents'], array(1, 2)),
133
		'show_holidays' => in_array($modSettings['cal_showholidays'], array(1, 2)),
134
		'highlight' => array(
135
			'events' => isset($modSettings['cal_highlight_events']) ? $modSettings['cal_highlight_events'] : 0,
136
			'holidays' => isset($modSettings['cal_highlight_holidays']) ? $modSettings['cal_highlight_holidays'] : 0,
137
			'birthdays' => isset($modSettings['cal_highlight_birthdays']) ? $modSettings['cal_highlight_birthdays'] : 0,
138
		),
139
		'show_week_num' => true,
140
		'short_day_titles' => !empty($modSettings['cal_short_days']),
141
		'short_month_titles' => !empty($modSettings['cal_short_months']),
142
		'show_next_prev' => !empty($modSettings['cal_prev_next_links']),
143
		'show_week_links' => isset($modSettings['cal_week_links']) ? $modSettings['cal_week_links'] : 0,
144
	);
145
146
	// Load up the main view.
147
	if ($context['view_week'])
148
		$context['calendar_grid_main'] = getCalendarWeek($curPage['month'], $curPage['year'], $curPage['day'], $calendarOptions);
149
	else
150
		$context['calendar_grid_main'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions);
151
152
	// Load up the previous and next months.
153
	$context['calendar_grid_current'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions);
154
155
	// Only show previous month if it isn't pre-January of the min-year
156
	if ($context['calendar_grid_current']['previous_calendar']['year'] > $modSettings['cal_minyear'] || $curPage['month'] != 1)
157
		$context['calendar_grid_prev'] = getCalendarGrid($context['calendar_grid_current']['previous_calendar']['month'], $context['calendar_grid_current']['previous_calendar']['year'], $calendarOptions, true);
158
159
	// Only show next month if it isn't post-December of the max-year
160
	if ($context['calendar_grid_current']['next_calendar']['year'] < $modSettings['cal_maxyear'] || $curPage['month'] != 12)
161
		$context['calendar_grid_next'] = getCalendarGrid($context['calendar_grid_current']['next_calendar']['month'], $context['calendar_grid_current']['next_calendar']['year'], $calendarOptions);
162
163
	// Basic template stuff.
164
	$context['allow_calendar_event'] = allowedTo('calendar_post');
165
166
	// If you don't allow events not linked to posts and you're not an admin, we have more work to do...
167
	if ($context['allow_calendar_event'] && empty($modSettings['cal_allow_unlinked']) && !$user_info['is_admin'])
168
	{
169
		$boards_can_post = boardsAllowedTo('post_new');
170
		$context['allow_calendar_event'] &= !empty($boards_can_post);
171
	}
172
173
	$context['can_post'] = $context['allow_calendar_event'];
174
	$context['current_day'] = $curPage['day'];
175
	$context['current_month'] = $curPage['month'];
176
	$context['current_year'] = $curPage['year'];
177
	$context['show_all_birthdays'] = isset($_GET['showbd']);
178
	$context['blocks_disabled'] = !empty($modSettings['cal_disable_prev_next']) ? 1 : 0;
179
180
	// Set the page title to mention the month or week, too
181
	$context['page_title'] .= ' - ' . ($context['view_week'] ? $context['calendar_grid_main']['week_title'] : $txt['months'][$context['current_month']] . ' ' . $context['current_year']);
182
183
	// Load up the linktree!
184
	$context['linktree'][] = array(
185
		'url' => $scripturl . '?action=calendar',
186
		'name' => $txt['calendar']
187
	);
188
	// Add the current month to the linktree.
189
	$context['linktree'][] = array(
190
		'url' => $scripturl . '?action=calendar;year=' . $context['current_year'] . ';month=' . $context['current_month'],
191
		'name' => $txt['months'][$context['current_month']] . ' ' . $context['current_year']
192
	);
193
	// If applicable, add the current week to the linktree.
194
	if ($context['view_week'])
195
		$context['linktree'][] = array(
196
			'url' => $scripturl . '?action=calendar;viewweek;year=' . $context['current_year'] . ';month=' . $context['current_month'] . ';day=' . $context['current_day'],
197
			'name' => $context['calendar_grid_main']['week_title'],
198
		);
199
200
	// Build the calendar button array.
201
	$context['calendar_buttons'] = array();
202
203
	if ($context['can_post'])
204
		$context['calendar_buttons']['post_event'] = array('text' => 'calendar_post_event', 'image' => 'calendarpe.png', 'url' => $scripturl . '?action=calendar;sa=post;month=' . $context['current_month'] . ';year=' . $context['current_year'] . ';' . $context['session_var'] . '=' . $context['session_id']),
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected ','
Loading history...
205
		);
206
207
	// Allow mods to add additional buttons here
208
	call_integration_hook('integrate_calendar_buttons');
209
}
210
211
/**
212
 * This function processes posting/editing/deleting a calendar event.
213
 *
214
 * 	- calls {@link Post.php|Post() Post()} function if event is linked to a post.
215
 *  - calls {@link Subs-Calendar.php|insertEvent() insertEvent()} to insert the event if not linked to post.
216
 *
217
 * It requires the calendar_post permission to use.
218
 * It uses the event_post sub template in the Calendar template.
219
 * It is accessed with ?action=calendar;sa=post.
220
 */
221
function CalendarPost()
222
{
223
	global $context, $txt, $user_info, $sourcedir, $scripturl;
224
	global $modSettings, $topic, $smcFunc;
225
226
	// Well - can they?
227
	isAllowedTo('calendar_post');
228
229
	// We need this for all kinds of useful functions.
230
	require_once($sourcedir . '/Subs-Calendar.php');
231
232
	// Cast this for safety...
233
	if (isset($_REQUEST['eventid']))
234
		$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
235
236
	// Submitting?
237
	if (isset($_POST[$context['session_var']], $_REQUEST['eventid']))
238
	{
239
		checkSession();
240
241
		// Validate the post...
242
		if (!isset($_POST['link_to_board']))
243
			validateEventPost();
244
245
		// If you're not allowed to edit any events, you have to be the poster.
246
		if ($_REQUEST['eventid'] > 0 && !allowedTo('calendar_edit_any'))
247
			isAllowedTo('calendar_edit_' . (!empty($user_info['id']) && getEventPoster($_REQUEST['eventid']) == $user_info['id'] ? 'own' : 'any'));
248
249
		// New - and directing?
250
		if (isset($_POST['link_to_board']) || empty($modSettings['cal_allow_unlinked']))
251
		{
252
			$_REQUEST['calendar'] = 1;
253
			require_once($sourcedir . '/Post.php');
254
			return Post();
255
		}
256
		// New...
257
		elseif ($_REQUEST['eventid'] == -1)
258
		{
259
			$eventOptions = array(
260
				'board' => 0,
261
				'topic' => 0,
262
				'title' => $smcFunc['substr']($_REQUEST['evtitle'], 0, 100),
263
				'member' => $user_info['id'],
264
				'start_date' => sprintf('%04d-%02d-%02d', $_POST['year'], $_POST['month'], $_POST['day']),
265
				'span' => isset($_POST['span']) && $_POST['span'] > 0 ? min((int) $modSettings['cal_maxspan'], (int) $_POST['span'] - 1) : 0,
266
			);
267
			insertEvent($eventOptions);
268
		}
269
270
		// Deleting...
271
		elseif (isset($_REQUEST['deleteevent']))
272
			removeEvent($_REQUEST['eventid']);
273
274
		// ... or just update it?
275
		else
276
		{
277
			$eventOptions = array(
278
				'title' => $smcFunc['substr']($_REQUEST['evtitle'], 0, 100),
279
				'span' => empty($modSettings['cal_allowspan']) || empty($_POST['span']) || $_POST['span'] == 1 || empty($modSettings['cal_maxspan']) || $_POST['span'] > $modSettings['cal_maxspan'] ? 0 : min((int) $modSettings['cal_maxspan'], (int) $_POST['span'] - 1),
280
				'start_date' => strftime('%Y-%m-%d', mktime(0, 0, 0, (int) $_REQUEST['month'], (int) $_REQUEST['day'], (int) $_REQUEST['year'])),
281
			);
282
283
			modifyEvent($_REQUEST['eventid'], $eventOptions);
284
		}
285
286
		updateSettings(array(
287
			'calendar_updated' => time(),
288
		));
289
290
		// No point hanging around here now...
291
		redirectexit($scripturl . '?action=calendar;month=' . $_POST['month'] . ';year=' . $_POST['year']);
292
	}
293
294
	// If we are not enabled... we are not enabled.
295
	if (empty($modSettings['cal_allow_unlinked']) && empty($_REQUEST['eventid']))
296
	{
297
		$_REQUEST['calendar'] = 1;
298
		require_once($sourcedir . '/Post.php');
299
		return Post();
300
	}
301
302
	// New?
303
	if (!isset($_REQUEST['eventid']))
304
	{
305
		$today = getdate();
306
307
		$context['event'] = array(
308
			'boards' => array(),
309
			'board' => 0,
310
			'new' => 1,
311
			'eventid' => -1,
312
			'year' => isset($_REQUEST['year']) ? $_REQUEST['year'] : $today['year'],
313
			'month' => isset($_REQUEST['month']) ? $_REQUEST['month'] : $today['mon'],
314
			'day' => isset($_REQUEST['day']) ? $_REQUEST['day'] : $today['mday'],
315
			'title' => '',
316
			'span' => 1,
317
		);
318
		$context['event']['last_day'] = (int) strftime('%d', mktime(0, 0, 0, $context['event']['month'] == 12 ? 1 : $context['event']['month'] + 1, 0, $context['event']['month'] == 12 ? $context['event']['year'] + 1 : $context['event']['year']));
319
	}
320
	else
321
	{
322
		$context['event'] = getEventProperties($_REQUEST['eventid']);
323
324
		if ($context['event'] === false)
325
			fatal_lang_error('no_access', false);
326
327
		// If it has a board, then they should be editing it within the topic.
328
		if (!empty($context['event']['topic']['id']) && !empty($context['event']['topic']['first_msg']))
329
		{
330
			// We load the board up, for a check on the board access rights...
331
			$topic = $context['event']['topic']['id'];
332
			loadBoard();
333
		}
334
335
		// Make sure the user is allowed to edit this event.
336
		if ($context['event']['member'] != $user_info['id'])
337
			isAllowedTo('calendar_edit_any');
338
		elseif (!allowedTo('calendar_edit_any'))
339
			isAllowedTo('calendar_edit_own');
340
	}
341
342
	// Get list of boards that can be posted in.
343
	$boards = boardsAllowedTo('post_new');
344
	if (empty($boards))
345
	{
346
		// You can post new events but can't link them to anything...
347
		$context['event']['categories'] = array();
348
	}
349
	else
350
	{
351
		// Load the list of boards and categories in the context.
352
		require_once($sourcedir . '/Subs-MessageIndex.php');
353
		$boardListOptions = array(
354
			'included_boards' => in_array(0, $boards) ? null : $boards,
355
			'not_redirection' => true,
356
			'use_permissions' => true,
357
			'selected_board' => $modSettings['cal_defaultboard'],
358
		);
359
		$context['event']['categories'] = getBoardList($boardListOptions);
360
	}
361
362
	// Template, sub template, etc.
363
	loadTemplate('Calendar');
364
	$context['sub_template'] = 'event_post';
365
366
	$context['page_title'] = isset($_REQUEST['eventid']) ? $txt['calendar_edit'] : $txt['calendar_post_event'];
367
	$context['linktree'][] = array(
368
		'name' => $context['page_title'],
369
	);
370
}
371
372
/**
373
 * This function offers up a download of an event in iCal 2.0 format.
374
 *
375
 * Follows the conventions in {@link http://tools.ietf.org/html/rfc5546 RFC5546}
376
 * Sets events as all day events since we don't have hourly events
377
 * Will honor and set multi day events
378
 * Sets a sequence number if the event has been modified
379
 *
380
 * @todo .... allow for week or month export files as well?
381
 */
382
function iCalDownload()
383
{
384
	global $smcFunc, $sourcedir, $forum_version, $modSettings, $webmaster_email, $mbname;
385
386
	// You can't export if the calendar export feature is off.
387
	if (empty($modSettings['cal_export']))
388
		fatal_lang_error('calendar_export_off', false);
389
390
	// Goes without saying that this is required.
391
	if (!isset($_REQUEST['eventid']))
392
		fatal_lang_error('no_access', false);
393
394
	// This is kinda wanted.
395
	require_once($sourcedir . '/Subs-Calendar.php');
396
397
	// Load up the event in question and check it exists.
398
	$event = getEventProperties($_REQUEST['eventid']);
399
400
	if ($event === false)
401
		fatal_lang_error('no_access', false);
402
403
	// Check the title isn't too long - iCal requires some formatting if so.
404
	$title = str_split($event['title'], 30);
405
	foreach ($title as $id => $line)
406
	{
407
		if ($id != 0)
408
			$title[$id] = ' ' . $title[$id];
409
		$title[$id] .= "\n";
410
	}
411
412
	// Format the dates.
413
	$datestamp = date('Ymd\THis\Z', time());
414
	$datestart = $event['year'] . ($event['month'] < 10 ? '0' . $event['month'] : $event['month']) . ($event['day'] < 10 ? '0' . $event['day'] : $event['day']);
415
416
	// Do we have a event that spans several days?
417
	if ($event['span'] > 1)
418
	{
419
		$dateend = strtotime($event['year'] . '-' . ($event['month'] < 10 ? '0' . $event['month'] : $event['month']) . '-' . ($event['day'] < 10 ? '0' . $event['day'] : $event['day']));
420
		$dateend += ($event['span'] - 1) * 86400;
421
		$dateend = date('Ymd', $dateend);
422
	}
423
424
	// This is what we will be sending later
425
	$filecontents = '';
426
	$filecontents .= 'BEGIN:VCALENDAR' . "\n";
427
	$filecontents .= 'METHOD:PUBLISH' . "\n";
428
	$filecontents .= 'PRODID:-//SimpleMachines//SMF ' . (empty($forum_version) ? 2.0 : strtr($forum_version, array('SMF ' => ''))) . '//EN' . "\n";
429
	$filecontents .= 'VERSION:2.0' . "\n";
430
	$filecontents .= 'BEGIN:VEVENT' . "\n";
431
	// @TODO - Should be the members email who created the event rather than $webmaster_email.
432
	$filecontents .= 'ORGANIZER;CN="' . $event['realname'] . '":MAILTO:' . $webmaster_email . "\n";
433
	$filecontents .= 'DTSTAMP:' . $datestamp . "\n";
434
	$filecontents .= 'DTSTART;VALUE=DATE:' . $datestart . "\n";
435
436
	// more than one day
437
	if ($event['span'] > 1)
438
		$filecontents .= 'DTEND;VALUE=DATE:' . $dateend . "\n";
439
440
	// event has changed? advance the sequence for this UID
441
	if ($event['sequence'] > 0)
442
		$filecontents .= 'SEQUENCE:' . $event['sequence'] . "\n";
443
444
	$filecontents .= 'SUMMARY:' . implode('', $title);
445
	$filecontents .= 'UID:' . $event['eventid'] . '@' . str_replace(' ', '-', $mbname) . "\n";
446
	$filecontents .= 'END:VEVENT' . "\n";
447
	$filecontents .= 'END:VCALENDAR';
448
449
	// Send some standard headers.
450
	ob_end_clean();
451
	if (!empty($modSettings['enableCompressedOutput']))
452
		@ob_start('ob_gzhandler');
453
	else
454
		ob_start();
455
456
	// Send the file headers
457
	header('Pragma: ');
458
	header('Cache-Control: no-cache');
459
	if (!isBrowser('gecko'))
460
		header('Content-Transfer-Encoding: binary');
461
	header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT');
462
	header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . 'GMT');
463
	header('Accept-Ranges: bytes');
464
	header('Connection: close');
465
	header('Content-Disposition: attachment; filename="' . $event['title'] . '.ics"');
466
	if (empty($modSettings['enableCompressedOutput']))
467
		header('Content-Length: ' . $smcFunc['strlen']($filecontents));
468
469
	// This is a calendar item!
470
	header('Content-Type: text/calendar');
471
472
	// Chuck out the card.
473
	echo $filecontents;
474
475
	// Off we pop - lovely!
476
	obExit(false);
477
}
478
479
/**
480
 * Nothing to see here. Move along.
481
 */
482
function clock()
483
{
484
	global $settings, $context, $scripturl;
485
486
	$context['onimg'] = $settings['images_url'] . '/bbc/bbc_bg.png';
487
	$context['offimg'] = $settings['images_url'] . '/bbc/bbc_hoverbg.png';
488
489
	$context['page_title'] = 'Anyone know what time it is?';
490
	$context['linktree'][] = array(
491
			'url' => $scripturl . '?action=clock',
492
			'name' => 'Clock',
493
	);
494
	$context['robot_no_index'] = true;
495
496
	$omfg = isset($_REQUEST['omfg']);
497
	$bcd = !isset($_REQUEST['rb']) && !isset($_REQUEST['omfg']) && !isset($_REQUEST['time']);
498
499
	loadTemplate('Calendar');
500
501
	if ($bcd)
502
	{
503
		$context['sub_template'] = 'bcd';
504
		$context['linktree'][] = array('url' => $scripturl . '?action=clock;bcd', 'name' => 'BCD');
505
		$context['clockicons'] = safe_unserialize(base64_decode('YTo2OntzOjI6ImgxIjthOjI6e2k6MDtpOjI7aToxO2k6MTt9czoyOiJoMiI7YTo0OntpOjA7aTo4O2k6MTtpOjQ7aToyO2k6MjtpOjM7aToxO31zOjI6Im0xIjthOjM6e2k6MDtpOjQ7aToxO2k6MjtpOjI7aToxO31zOjI6Im0yIjthOjQ6e2k6MDtpOjg7aToxO2k6NDtpOjI7aToyO2k6MztpOjE7fXM6MjoiczEiO2E6Mzp7aTowO2k6NDtpOjE7aToyO2k6MjtpOjE7fXM6MjoiczIiO2E6NDp7aTowO2k6ODtpOjE7aTo0O2k6MjtpOjI7aTozO2k6MTt9fQ=='));
506
	}
507
	elseif (!$omfg && !isset($_REQUEST['time']))
508
	{
509
		$context['sub_template'] = 'hms';
510
		$context['linktree'][] = array('url' => $scripturl . '?action=clock', 'name' => 'Binary');
511
		$context['clockicons'] = safe_unserialize(base64_decode('YTozOntzOjE6ImgiO2E6NTp7aTowO2k6MTY7aToxO2k6ODtpOjI7aTo0O2k6MztpOjI7aTo0O2k6MTt9czoxOiJtIjthOjY6e2k6MDtpOjMyO2k6MTtpOjE2O2k6MjtpOjg7aTozO2k6NDtpOjQ7aToyO2k6NTtpOjE7fXM6MToicyI7YTo2OntpOjA7aTozMjtpOjE7aToxNjtpOjI7aTo4O2k6MztpOjQ7aTo0O2k6MjtpOjU7aToxO319'));
512
	}
513
	elseif ($omfg)
514
	{
515
		$context['sub_template'] = 'omfg';
516
		$context['linktree'][] = array('url' => $scripturl . '?action=clock;omfg', 'name' => 'OMFG');
517
		$context['clockicons'] = safe_unserialize(base64_decode('YTo2OntzOjQ6InllYXIiO2E6Nzp7aTowO2k6NjQ7aToxO2k6MzI7aToyO2k6MTY7aTozO2k6ODtpOjQ7aTo0O2k6NTtpOjI7aTo2O2k6MTt9czo1OiJtb250aCI7YTo0OntpOjA7aTo4O2k6MTtpOjQ7aToyO2k6MjtpOjM7aToxO31zOjM6ImRheSI7YTo1OntpOjA7aToxNjtpOjE7aTo4O2k6MjtpOjQ7aTozO2k6MjtpOjQ7aToxO31zOjQ6ImhvdXIiO2E6NTp7aTowO2k6MTY7aToxO2k6ODtpOjI7aTo0O2k6MztpOjI7aTo0O2k6MTt9czozOiJtaW4iO2E6Njp7aTowO2k6MzI7aToxO2k6MTY7aToyO2k6ODtpOjM7aTo0O2k6NDtpOjI7aTo1O2k6MTt9czozOiJzZWMiO2E6Njp7aTowO2k6MzI7aToxO2k6MTY7aToyO2k6ODtpOjM7aTo0O2k6NDtpOjI7aTo1O2k6MTt9fQ=='));
518
	}
519
	elseif (isset($_REQUEST['time']))
520
	{
521
		$context['sub_template'] = 'thetime';
522
		$time = getdate($_REQUEST['time'] == 'now' ? time() : (int) $_REQUEST['time']);
523
		$year = $time['year'] % 100;
524
		$month = $time['mon'];
525
		$day = $time['mday'];
526
		$hour = $time['hours'];
527
		$min = $time['minutes'];
528
		$sec = $time['seconds'];
529
		$context['linktree'][] = array('url' => $scripturl . '?action=clock;time=' . $_REQUEST['time'], 'name' => 'Requested Time');
530
		$context['clockicons'] = array(
531
			'year' => array(
532
				64 => false,
533
				32 => false,
534
				16 => false,
535
				8  => false,
536
				4  => false,
537
				2  => false,
538
				1  => false
539
			),
540
			'month' => array(
541
				8  => false,
542
				4  => false,
543
				2  => false,
544
				1  => false
545
			),
546
			'day' => array(
547
				16 => false,
548
				4  => false,
549
				8  => false,
550
				2  => false,
551
				1  => false
552
			),
553
			'hour' => array(
554
				32 => false,
555
				16 => false,
556
				8  => false,
557
				4  => false,
558
				2  => false,
559
				1  => false
560
			),
561
			'min' => array(
562
				32 => false,
563
				16 => false,
564
				8  => false,
565
				4  => false,
566
				2  => false,
567
				1  => false
568
			),
569
			'sec' => array(
570
				32 => false,
571
				16 => false,
572
				8  => false,
573
				4  => false,
574
				2  => false,
575
				1  => false
576
			),
577
		);
578
579
		foreach ($context['clockicons'] as $t => $vs)
580
			foreach ($vs as $v => $dumb)
581
			{
582
				if ($$t >= $v)
583
				{
584
					$$t -= $v;
585
					$context['clockicons'][$t][$v] = true;
586
				}
587
			}
588
	}
589
}
590
591
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...