Completed
Push — release-2.1 ( c34e3e...16d0a0 )
by Jeremy
13:16
created

Calendar.template.php ➔ template_hms()   B

Complexity

Conditions 7
Paths 27

Size

Total Lines 92

Duplication

Lines 92
Ratio 100 %

Importance

Changes 0
Metric Value
cc 7
nc 27
nop 0
dl 92
loc 92
rs 7.2412
c 0
b 0
f 0

How to fix   Long Method   

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
 * Simple Machines Forum (SMF)
4
 *
5
 * @package SMF
6
 * @author Simple Machines http://www.simplemachines.org
7
 * @copyright 2018 Simple Machines and individual contributors
8
 * @license http://www.simplemachines.org/about/smf/license.php BSD
9
 *
10
 * @version 2.1 Beta 4
11
 */
12
13
/**
14
 * Our main calendar template, which encapsulates weeks and months.
15
 */
16
function template_main()
0 ignored issues
show
Best Practice introduced by
The function template_main() has been defined more than once; this definition is ignored, only the first definition in Themes/default/BoardIndex.template.php (L54-132) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
17
{
18
	global $context;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
19
20
	// The main calendar wrapper.
21
	echo '
22
		<div id="calendar">';
23
24
	// Show the mini-blocks if they're enabled.
25
	if (empty($context['blocks_disabled']))
26
		echo '
27
			<div id="month_grid">
28
				', template_show_month_grid('prev', true), '
29
				', template_show_month_grid('current', true), '
30
				', template_show_month_grid('next', true), '
31
			</div>';
32
33
	// What view are we showing?
34
	if ($context['calendar_view'] == 'viewlist')
35
		echo '
36
			<div id="main_grid">
37
				', template_show_upcoming_list('main'), '
38
			</div>';
39
	elseif ($context['calendar_view'] == 'viewweek')
40
		echo '
41
			<div id="main_grid">
42
				', template_show_week_grid('main'), '
43
			</div>';
44
	else
45
		echo '
46
			<div id="main_grid">
47
				', template_show_month_grid('main'), '
48
			</div>';
49
50
	// Close our wrapper.
51
	echo '
52
		</div><!-- #calendar -->';
53
}
54
55
56
/**
57
 * Display a list of upcoming events, birthdays, and holidays.
58
 *
59
 * @param string $grid_name The grid name
60
 * @return void|bool Returns false if the grid doesn't exist.
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use false|null.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
61
 */
62
function template_show_upcoming_list($grid_name)
63
{
64
	global $context, $scripturl, $txt;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
65
66
	// Bail out if we have nothing to work with
67
	if (!isset($context['calendar_grid_' . $grid_name]))
68
		return false;
69
70
	// Protect programmer sanity
71
	$calendar_data = &$context['calendar_grid_' . $grid_name];
72
73
	// Do we want a title?
74
	if (empty($calendar_data['disable_title']))
75
		echo '
76
			<div class="cat_bar">
77
				<h3 class="catbg centertext largetext">
78
					<a href="', $scripturl, '?action=calendar;viewlist;year=', $calendar_data['start_year'], ';month=', $calendar_data['start_month'], ';day=', $calendar_data['start_day'], '">', $txt['calendar_upcoming'], '</a>
79
				</h3>
80
			</div>';
81
82
	// Give the user some controls to work with
83
	template_calendar_top($calendar_data);
84
85
	// First, list any events
86 View Code Duplication
	if (!empty($calendar_data['events']))
87
	{
88
		echo '
89
			<div>
90
				<div class="title_bar">
91
					<h3 class="titlebg">', str_replace(':', '', $txt['events']), '</h3>
92
				</div>
93
				<ul>';
94
95
		foreach ($calendar_data['events'] as $date => $date_events)
96
		{
97
			foreach ($date_events as $event)
98
			{
99
				echo '
100
					<li class="windowbg">
101
						<strong class="event_title">', $event['link'], '</strong>';
102
103
				if ($event['can_edit'])
104
					echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>';
105
106
				if ($event['can_export'])
107
					echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>';
108
109
				echo '
110
						<br>';
111
112
				if (!empty($event['allday']))
113
				{
114
					echo '<time datetime="' . $event['start_iso_gmdate'] . '">', trim($event['start_date_local']), '</time>', ($event['start_date'] != $event['end_date']) ? ' &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">' . trim($event['end_date_local']) . '</time>' : '';
115
				}
116
				else
117
				{
118
					// Display event info relative to user's local timezone
119
					echo '<time datetime="' . $event['start_iso_gmdate'] . '">', trim($event['start_date_local']), ', ', trim($event['start_time_local']), '</time> &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">';
120
121
					if ($event['start_date_local'] != $event['end_date_local'])
122
						echo trim($event['end_date_local']) . ', ';
123
124
					echo trim($event['end_time_local']);
125
126
					// Display event info relative to original timezone
127
					if ($event['start_date_local'] . $event['start_time_local'] != $event['start_date_orig'] . $event['start_time_orig'])
128
					{
129
						echo '</time> (<time datetime="' . $event['start_iso_gmdate'] . '">';
130
131
						if ($event['start_date_orig'] != $event['start_date_local'] || $event['end_date_orig'] != $event['end_date_local'] || $event['start_date_orig'] != $event['end_date_orig'])
132
							echo trim($event['start_date_orig']), ', ';
133
134
						echo trim($event['start_time_orig']), '</time> &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">';
135
136
						if ($event['start_date_orig'] != $event['end_date_orig'])
137
							echo trim($event['end_date_orig']) . ', ';
138
139
						echo trim($event['end_time_orig']), ' ', $event['tz_abbrev'], '</time>)';
140
					}
141
					// Event is scheduled in the user's own timezone? Let 'em know, just to avoid confusion
142
					else
143
						echo ' ', $event['tz_abbrev'], '</time>';
144
				}
145
146
				if (!empty($event['location']))
147
					echo '<br>', $event['location'];
148
149
				echo '
150
					</li>';
151
			}
152
		}
153
154
		echo '
155
				</ul>
156
			</div>';
157
	}
158
159
	// Next, list any birthdays
160
	if (!empty($calendar_data['birthdays']))
161
	{
162
		echo '
163
			<div>
164
				<div class="title_bar">
165
					<h3 class="titlebg">', str_replace(':', '', $txt['birthdays']), '</h3>
166
				</div>
167
				<div class="windowbg">';
168
169
		foreach ($calendar_data['birthdays'] as $date)
170
		{
171
			echo '
172
					<p class="inline">
173
						<strong>', $date['date_local'], '</strong>: ';
174
175
			unset($date['date_local']);
176
177
			$birthdays = array();
178
179
			foreach ($date as $member)
180
				$birthdays[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '">' . $member['name'] . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>';
181
182
			echo implode(', ', $birthdays);
183
184
			echo '
185
					</p>';
186
		}
187
188
		echo '
189
				</div><!-- .windowbg -->
190
			</div>';
191
	}
192
193
	// Finally, list any holidays
194
	if (!empty($calendar_data['holidays']))
195
	{
196
		echo '
197
			<div>
198
				<div class="title_bar">
199
					<h3 class="titlebg">', str_replace(':', '', $txt['calendar_prompt']), '</h3>
200
				</div>
201
				<div class="windowbg">
202
					<p class="inline holidays">';
203
204
		$holidays = array();
205
206
		foreach ($calendar_data['holidays'] as $date)
207
		{
208
			$date_local = $date['date_local'];
209
			unset($date['date_local']);
210
211
			foreach ($date as $holiday)
212
				$holidays[] = $holiday . ' (' . $date_local . ')';
213
		}
214
215
		echo implode(', ', $holidays);
216
217
		echo '
218
					</p>
219
				</div><!-- .windowbg -->
220
			</div>';
221
	}
222
}
223
224
/**
225
 * Display a monthly calendar grid.
226
 *
227
 * @param string $grid_name The grid name
228
 * @param bool $is_mini Is this a mini grid?
229
 * @return void|bool Returns false if the grid doesn't exist.
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use false|null.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
230
 */
231
function template_show_month_grid($grid_name, $is_mini = false)
232
{
233
	global $context, $txt, $scripturl, $modSettings;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
234
235
	// If the grid doesn't exist, no point in proceeding.
236
	if (!isset($context['calendar_grid_' . $grid_name]))
237
		return false;
238
239
	// A handy little pointer variable.
240
	$calendar_data = &$context['calendar_grid_' . $grid_name];
241
242
	// Some conditions for whether or not we should show the week links *here*.
243
	if (isset($calendar_data['show_week_links']) && ($calendar_data['show_week_links'] == 3 || (($calendar_data['show_week_links'] == 1 && $is_mini === true) || $calendar_data['show_week_links'] == 2 && $is_mini === false)))
244
		$show_week_links = true;
245
	else
246
		$show_week_links = false;
247
248
	// Assuming that we've not disabled it, show the title block!
249
	if (empty($calendar_data['disable_title']))
250
	{
251
		echo '
252
			<div class="cat_bar">
253
				<h3 class="catbg centertext largetext">';
254
255
		// Previous Link: If we're showing prev / next and it's not a mini-calendar.
256
		if (empty($calendar_data['previous_calendar']['disabled']) && $calendar_data['show_next_prev'] && $is_mini === false)
257
			echo '
258
					<span class="floatleft">
259
						<a href="', $calendar_data['previous_calendar']['href'], '">&#171;</a>
260
					</span>';
261
262
		// Next Link: if we're showing prev / next and it's not a mini-calendar.
263 View Code Duplication
		if (empty($calendar_data['next_calendar']['disabled']) && $calendar_data['show_next_prev'] && $is_mini === false)
264
			echo '
265
					<span class="floatright">
266
						<a href="', $calendar_data['next_calendar']['href'], '">&#187;</a>
267
					</span>';
268
269
		// Arguably the most exciting part, the title!
270
		echo '
271
					<a href="', $scripturl, '?action=calendar;', $context['calendar_view'], ';year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], '">', $txt['months_titles'][$calendar_data['current_month']], ' ', $calendar_data['current_year'], '</a>
272
				</h3>
273
			</div><!-- .cat_bar -->';
274
	}
275
276
	// Show the controls on main grids
277
	if ($is_mini === false)
278
		template_calendar_top($calendar_data);
279
280
	// Finally, the main calendar table.
281
	echo '
282
			<table class="calendar_table">';
283
284
	// Show each day of the week.
285
	if (empty($calendar_data['disable_day_titles']))
286
	{
287
		echo '
288
				<tr>';
289
290
		// If we're showing week links, there's an extra column ahead of the week links, so let's think ahead and be prepared!
291
		if ($show_week_links === true)
292
			echo '
293
					<th></th>';
294
295
		// Now, loop through each actual day of the week.
296
		foreach ($calendar_data['week_days'] as $day)
297
			echo '
298
					<th class="days" scope="col">', !empty($calendar_data['short_day_titles']) || $is_mini === true ? $txt['days_short'][$day] : $txt['days'][$day], '</th>';
299
300
		echo '
301
				</tr>';
302
	}
303
304
	// Our looping begins on a per-week basis.
305
	foreach ($calendar_data['weeks'] as $week)
306
	{
307
		// Some useful looping variables.
308
		$current_month_started = false;
309
		$count = 1;
310
		$final_count = 1;
311
312
		echo '
313
				<tr class="days_wrapper">';
314
315
		// This is where we add the actual week link, if enabled on this location.
316
		if ($show_week_links === true)
317
			echo '
318
					<td class="windowbg weeks">
319
						<a href="', $scripturl, '?action=calendar;viewweek;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $week['days'][0]['day'], '" title="', $txt['calendar_view_week'], '">&#187;</a>
320
					</td>';
321
322
		// Now loop through each day in the week we're on.
323
		foreach ($week['days'] as $day)
324
		{
325
			// What classes should each day inherit? Day is default.
326
			$classes = array('days');
327
			if (!empty($day['day']))
328
			{
329
				// Default Classes (either compact or comfortable and either calendar_today or windowbg).
330
				$classes[] = !empty($calendar_data['size']) && $calendar_data['size'] == 'small' ? 'compact' : 'comfortable';
331
				$classes[] = !empty($day['is_today']) ? 'calendar_today' : 'windowbg';
332
333
				// Additional classes are given for events, holidays, and birthdays.
334 View Code Duplication
				if (!empty($day['events']) && !empty($calendar_data['highlight']['events']))
335
				{
336
					if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1, 3)))
337
						$classes[] = 'events';
338
					elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2, 3)))
339
						$classes[] = 'events';
340
				}
341 View Code Duplication
				if (!empty($day['holidays']) && !empty($calendar_data['highlight']['holidays']))
342
				{
343
					if ($is_mini === true && in_array($calendar_data['highlight']['holidays'], array(1, 3)))
344
						$classes[] = 'holidays';
345
					elseif ($is_mini === false && in_array($calendar_data['highlight']['holidays'], array(2, 3)))
346
						$classes[] = 'holidays';
347
				}
348 View Code Duplication
				if (!empty($day['birthdays']) && !empty($calendar_data['highlight']['birthdays']))
349
				{
350
					if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1, 3)))
351
						$classes[] = 'birthdays';
352
					elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2, 3)))
353
						$classes[] = 'birthdays';
354
				}
355
			}
356
			else
357
			{
358
				// Default Classes (either compact or comfortable and disabled).
359
				$classes[] = !empty($calendar_data['size']) && $calendar_data['size'] == 'small' ? 'compact' : 'comfortable';
360
				$classes[] = 'disabled';
361
			}
362
363
			// Now, implode the classes for each day.
364
			echo '
365
					<td class="', implode(' ', $classes), '">';
366
367
			// If it's within this current month, go ahead and begin.
368
			if (!empty($day['day']))
369
			{
370
				// If it's the first day of this month and not a mini-calendar, we'll add the month title - whether short or full.
371
				$title_prefix = !empty($day['is_first_of_month']) && $context['current_month'] == $calendar_data['current_month'] && $is_mini === false ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$calendar_data['current_month']] . ' ' : $txt['months_titles'][$calendar_data['current_month']] . ' ') : '';
372
373
				// The actual day number - be it a link, or just plain old text!
374
				if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
375
					echo '
376
						<a href="', $scripturl, '?action=calendar;sa=post;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>';
377
				elseif ($is_mini)
378
					echo '
379
						<a href="', $scripturl, '?action=calendar;', $context['calendar_view'], ';year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>';
380
				else
381
					echo '
382
						<span class="day_text">', $title_prefix, $day['day'], '</span>';
383
384
				// A lot of stuff, we're not showing on mini-calendars to conserve space.
385
				if ($is_mini === false)
386
				{
387
					// Holidays are always fun, let's show them!
388
					if (!empty($day['holidays']))
389
						echo '
390
						<div class="smalltext holiday">
391
							<span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), '
392
						</div>';
393
394
					// Happy Birthday Dear Member!
395
					if (!empty($day['birthdays']))
396
					{
397
						echo '
398
						<div class="smalltext">
399
							<span class="birthday">', $txt['birthdays'], '</span> ';
400
401
						/* Each of the birthdays has:
402
							id, name (person), age (if they have one set?), and is_last. (last in list?) */
403
						$use_js_hide = empty($context['show_all_birthdays']) && count($day['birthdays']) > 15;
404
						$birthday_count = 0;
405
						foreach ($day['birthdays'] as $member)
406
						{
407
							echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '"><span class="fix_rtl_names">', $member['name'], '</span>', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', $member['is_last'] || ($count == 10 && $use_js_hide) ? '' : ', ';
408
409
							// 9...10! Let's stop there.
410
							if ($birthday_count == 10 && $use_js_hide)
411
								// !!TODO - Inline CSS and JavaScript should be moved.
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
412
								echo '<span class="hidelink" id="bdhidelink_', $day['day'], '">...<br><a href="', $scripturl, '?action=calendar;month=', $calendar_data['current_month'], ';year=', $calendar_data['current_year'], ';showbd" onclick="document.getElementById(\'bdhide_', $day['day'], '\').style.display = \'\'; document.getElementById(\'bdhidelink_', $day['day'], '\').style.display = \'none\'; return false;">(', sprintf($txt['calendar_click_all'], count($day['birthdays'])), ')</a></span><span id="bdhide_', $day['day'], '" style="display: none;">, ';
413
414
							++$birthday_count;
415
						}
416
						if ($use_js_hide)
417
							echo '
418
							</span>';
419
420
						echo '
421
						</div><!-- .smalltext -->';
422
					}
423
424
					// Any special posted events?
425
					if (!empty($day['events']))
426
					{
427
						// Sort events by start time (all day events will be listed first)
428
						uasort($day['events'], function($a, $b) {
429
							if ($a['start_timestamp'] == $b['start_timestamp'])
430
								return 0;
431
432
							return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
433
						});
434
435
						echo '
436
						<div class="smalltext lefttext">
437
							<span class="event">', $txt['events'], '</span><br>';
438
439
						/* The events are made up of:
440
							title, href, is_last, can_edit (are they allowed to?), and modify_href. */
441
						foreach ($day['events'] as $event)
442
						{
443
							$event_icons_needed = ($event['can_edit'] || $event['can_export']) ? true : false;
444
445
							echo '
446
							<div class="event_wrapper', $event['starts_today'] == true ? ' event_starts_today' : '', $event['ends_today'] == true ? ' event_ends_today' : '', $event['allday'] == true ? ' allday' : '', $event['is_selected'] ? ' sel_event' : '', '">
447
								', $event['link'], '<br>
448
								<span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">';
449
450
							if (!empty($event['start_time_local']) && $event['starts_today'] == true)
451
								echo trim(str_replace(':00 ', ' ', $event['start_time_local']));
452
							elseif (!empty($event['end_time_local']) && $event['ends_today'] == true)
453
								echo strtolower($txt['ends']), ' ', trim(str_replace(':00 ', ' ', $event['end_time_local']));
454
							elseif (!empty($event['allday']))
455
								echo $txt['calendar_allday'];
456
457
							echo '
458
								</span>';
459
460 View Code Duplication
							if (!empty($event['location']))
461
								echo '
462
								<br>
463
								<span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
464
465
							if ($event['can_edit'] || $event['can_export'])
466
							{
467
								echo '
468
								<span class="modify_event_links">';
469
470
								// If they can edit the event, show an icon they can click on....
471
								if ($event['can_edit'])
472
									echo '
473
									<a class="modify_event" href="', $event['modify_href'], '">
474
										<span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span>
475
									</a>';
476
477
								// Exporting!
478
								if ($event['can_export'])
479
									echo '
480
									<a class="modify_event" href="', $event['export_href'], '">
481
										<span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span>
482
									</a>';
483
484
								echo '
485
								</span><br class="clear">';
486
							}
487
488
							echo '
489
							</div><!-- .event_wrapper -->';
490
						}
491
492
						echo '
493
						</div><!-- .smalltext -->';
494
					}
495
				}
496
				$current_month_started = $count;
497
			}
498
			// Otherwise, assuming it's not a mini-calendar, we can show previous / next month days!
499
			elseif ($is_mini === false)
500
			{
501
				if (empty($current_month_started) && !empty($context['calendar_grid_prev']))
502
					echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_prev']['current_year'], ';month=', $context['calendar_grid_prev']['current_month'], '">', $context['calendar_grid_prev']['last_of_month'] - $calendar_data['shift']-- +1, '</a>';
0 ignored issues
show
Coding Style introduced by
Increment and decrement operators cannot be used in an arithmetic operation
Loading history...
503
				elseif (!empty($current_month_started) && !empty($context['calendar_grid_next']))
504
					echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_next']['current_year'], ';month=', $context['calendar_grid_next']['current_month'], '">', $current_month_started + 1 == $count ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$context['calendar_grid_next']['current_month']] . ' ' : $txt['months_titles'][$context['calendar_grid_next']['current_month']] . ' ') : '', $final_count++, '</a>';
505
			}
506
507
			// Close this day and increase var count.
508
			echo '
509
					</td>';
510
511
			++$count;
512
		}
513
514
		echo '
515
				</tr>';
516
	}
517
518
	// The end of our main table.
519
	echo '
520
			</table>';
521
}
522
523
/**
524
 * Shows a weekly grid
525
 *
526
 * @param string $grid_name The name of the grid
527
 * @return void|bool Returns false if the grid doesn't exist
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use false|null.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
528
 */
529
function template_show_week_grid($grid_name)
530
{
531
	global $context, $txt, $scripturl, $modSettings;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
532
533
	// We might have no reason to proceed, if the variable isn't there.
534
	if (!isset($context['calendar_grid_' . $grid_name]))
535
		return false;
536
537
	// Handy pointer.
538
	$calendar_data = &$context['calendar_grid_' . $grid_name];
539
540
	// At the very least, we have one month. Possibly two, though.
541
	$iteration = 1;
542
	foreach ($calendar_data['months'] as $month_data)
543
	{
544
		// For our first iteration, we'll add a nice header!
545
		if ($iteration == 1)
546
		{
547
			echo '
548
				<div class="cat_bar">
549
					<h3 class="catbg centertext largetext">';
550
551
			// Previous Week Link...
552 View Code Duplication
			if (empty($calendar_data['previous_calendar']['disabled']) && !empty($calendar_data['show_next_prev']))
553
				echo '
554
						<span class="floatleft">
555
							<a href="', $calendar_data['previous_week']['href'], '">&#171;</a>
556
						</span>';
557
558
			// Next Week Link...
559 View Code Duplication
			if (empty($calendar_data['next_calendar']['disabled']) && !empty($calendar_data['show_next_prev']))
560
				echo '
561
						<span class="floatright">
562
							<a href="', $calendar_data['next_week']['href'], '">&#187;</a>
563
						</span>';
564
565
			// The Month Title + Week Number...
566
			if (!empty($calendar_data['week_title']))
567
				echo $calendar_data['week_title'];
568
569
			echo '
570
					</h3>
571
				</div><!-- .cat_bar -->';
572
573
			// Show the controls
574
			template_calendar_top($calendar_data);
575
		}
576
577
		// Our actual month...
578
		echo '
579
				<div class="week_month_title">
580
					<a href="', $scripturl, '?action=calendar;month=', $month_data['current_month'], '">
581
						', $txt['months_titles'][$month_data['current_month']], '
582
					</a>
583
				</div>';
584
585
		// The main table grid for $this week.
586
		echo '
587
				<table class="table_grid calendar_week">
588
					<tr>
589
						<th class="days" scope="col">', $txt['calendar_day'], '</th>
590
						<th class="days" scope="col">', $txt['events'], '</th>
591
						<th class="days" scope="col">', $txt['calendar_prompt'], '</th>
592
						<th class="days" scope="col">', $txt['birthdays'], '</th>
593
					</tr>';
594
595
		// Each day of the week.
596
		foreach ($month_data['days'] as $day)
597
		{
598
			// How should we be highlighted or otherwise not...?
599
			$classes = array('days');
600
			$classes[] = !empty($calendar_data['size']) && $calendar_data['size'] == 'small' ? 'compact' : 'comfortable';
601
			$classes[] = !empty($day['is_today']) ? 'calendar_today' : 'windowbg';
602
603
			echo '
604
					<tr class="days_wrapper">
605
						<td class="', implode(' ', $classes), ' act_day">';
606
607
			// Should the day number be a link?
608
			if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
609
				echo '
610
							<a href="', $scripturl, '?action=calendar;sa=post;month=', $month_data['current_month'], ';year=', $month_data['current_year'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['days'][$day['day_of_week']], ' - ', $day['day'], '</a>';
611
			else
612
				echo $txt['days'][$day['day_of_week']], ' - ', $day['day'];
613
614
			echo '
615
						</td>
616
						<td class="', implode(' ', $classes), '', empty($day['events']) ? (' disabled' . ($context['can_post'] ? ' week_post' : '')) : ' events', ' event_col" data-css-prefix="' . $txt['events'] . ' ', (empty($day['events']) && empty($context['can_post'])) ? $txt['none'] : '', '">';
617
618
			// Show any events...
619
			if (!empty($day['events']))
620
			{
621
				// Sort events by start time (all day events will be listed first)
622
				uasort($day['events'], function($a, $b) {
623
					if ($a['start_timestamp'] == $b['start_timestamp'])
624
						return 0;
625
					return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
626
				});
627
628
				foreach ($day['events'] as $event)
629
				{
630
					echo '
631
							<div class="event_wrapper">';
632
633
					$event_icons_needed = ($event['can_edit'] || $event['can_export']) ? true : false;
634
635
					echo $event['link'], '<br>
636
								<span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">';
637
638
					if (!empty($event['start_time_local']))
639
						echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' &ndash; ' . trim($event['end_time_local']) : '';
640
					else
641
						echo $txt['calendar_allday'];
642
643
					echo '
644
								</span>';
645
646 View Code Duplication
					if (!empty($event['location']))
647
						echo '<br>
648
								<span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
649
650
					if (!empty($event_icons_needed))
651
					{
652
						echo ' <span class="modify_event_links">';
653
654
						// If they can edit the event, show a star they can click on....
655
						if (!empty($event['can_edit']))
656
							echo '
657
									<a class="modify_event" href="', $event['modify_href'], '">
658
										<span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span>
659
									</a>';
660
661
						// Can we export? Sweet.
662
						if (!empty($event['can_export']))
663
							echo '
664
									<a class="modify_event" href="', $event['export_href'], '">
665
										<span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span>
666
									</a>';
667
668
						echo '
669
								</span><br class="clear">';
670
					}
671
672
					echo '
673
							</div><!-- .event_wrapper -->';
674
				}
675
676 View Code Duplication
				if (!empty($context['can_post']))
677
				{
678
					echo '
679
							<div class="week_add_event">
680
								<a href="', $scripturl, '?action=calendar;sa=post;month=', $month_data['current_month'], ';year=', $month_data['current_year'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['calendar_post_event'], '</a>
681
							</div>
682
							<br class="clear">';
683
				}
684
			}
685 View Code Duplication
			else
686
			{
687
				if (!empty($context['can_post']))
688
					echo '
689
							<div class="week_add_event">
690
								<a href="', $scripturl, '?action=calendar;sa=post;month=', $month_data['current_month'], ';year=', $month_data['current_year'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['calendar_post_event'], '</a>
691
							</div>';
692
			}
693
			echo '
694
						</td>
695
						<td class="', implode(' ', $classes), !empty($day['holidays']) ? ' holidays' : ' disabled', ' holiday_col" data-css-prefix="' . $txt['calendar_prompt'] . ' ">';
696
697
			// Show any holidays!
698
			if (!empty($day['holidays']))
699
				echo implode('<br>', $day['holidays']);
700
701
			echo '
702
						</td>
703
						<td class="', implode(' ', $classes), '', !empty($day['birthdays']) ? ' birthdays' : ' disabled', ' birthday_col" data-css-prefix="' . $txt['birthdays'] . ' ">';
704
705
			// Show any birthdays...
706
			if (!empty($day['birthdays']))
707
			{
708 View Code Duplication
				foreach ($day['birthdays'] as $member)
709
					echo '
710
							<a href="', $scripturl, '?action=profile;u=', $member['id'], '">', $member['name'], '</a>
711
							', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '
712
							', $member['is_last'] ? '' : '<br>';
713
			}
714
			echo '
715
						</td>
716
					</tr>';
717
		}
718
719
		// Increase iteration for loop counting.
720
		++$iteration;
721
722
		echo '
723
				</table>';
724
	}
725
}
726
727
/**
728
 * Calendar controls under the title
729
 *
730
 * Creates the view selector (list, month, week), the date selector (either a
731
 * select menu or a date range chooser, depending on the circumstances), and the
732
 * "Post Event" button.
733
 *
734
 * @param array $calendar_data The data for the calendar grid that this is for
735
 */
736
function template_calendar_top($calendar_data)
737
{
738
	global $context, $scripturl, $txt;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
739
740
	echo '
741
		<div class="calendar_top roundframe', empty($calendar_data['disable_title']) ? ' noup' : '', '">
742
			<div id="calendar_viewselector" class="buttonrow floatleft">
743
				<a href="', $scripturl, '?action=calendar;viewlist;year=', $context['current_year'], ';month=', $context['current_month'], ';day=', $context['current_day'], '" class="button', $context['calendar_view'] == 'viewlist' ? ' active' : '', '">', $txt['calendar_list'], '</a>
744
				<a href="', $scripturl, '?action=calendar;viewmonth;year=', $context['current_year'], ';month=', $context['current_month'], ';day=', $context['current_day'], '" class="button', $context['calendar_view'] == 'viewmonth' ? ' active' : '', '">', $txt['calendar_month'], '</a>
745
				<a href="', $scripturl, '?action=calendar;viewweek;year=', $context['current_year'], ';month=', $context['current_month'], ';day=', $context['current_day'], '" class="button', $context['calendar_view'] == 'viewweek' ? ' active' : '', '">', $txt['calendar_week'], '</a>
746
			</div>
747
			', template_button_strip($context['calendar_buttons'], 'right');
748
749
	if ($context['calendar_view'] == 'viewlist')
750
	{
751
		echo '
752
			<form action="', $scripturl, '?action=calendar;viewlist" id="calendar_range" method="post" accept-charset="', $context['character_set'], '">
753
				<input type="text" name="start_date" id="start_date" maxlength="10" value="', $calendar_data['start_date'], '" tabindex="', $context['tabindex']++, '" class="date_input start" data-type="date">
754
				<span>', strtolower($txt['to']), '</span>
755
				<input type="text" name="end_date" id="end_date" maxlength="10" value="', $calendar_data['end_date'], '" tabindex="', $context['tabindex']++, '" class="date_input end" data-type="date">
756
				<input type="submit" class="button" style="float:none" id="view_button" value="', $txt['view'], '">
757
			</form>';
758
	}
759
	else
760
	{
761
		echo'
762
			<form action="', $scripturl, '?action=calendar" id="calendar_navigation" method="post" accept-charset="', $context['character_set'], '">
763
				<select name="month" id="input_month">';
764
765
		// Show a select box with all the months.
766
		foreach ($txt['months_short'] as $number => $month)
767
			echo '
768
					<option value="', $number, '"', $number == $context['current_month'] ? ' selected' : '', '>', $month, '</option>';
769
770
		echo '
771
				</select>
772
				<select name="year">';
773
774
		// Show a link for every year...
775
		for ($year = $context['calendar_resources']['min_year']; $year <= $context['calendar_resources']['max_year']; $year++)
776
			echo '
777
					<option value="', $year, '"', $year == $context['current_year'] ? ' selected' : '', '>', $year, '</option>';
778
779
		echo '
780
				</select>
781
				<input type="submit" class="button" id="view_button" value="', $txt['view'], '">
782
			</form>';
783
	}
784
785
	echo'
786
		</div><!-- .calendar_top -->';
787
}
788
789
/**
790
 * Template for posting a calendar event.
791
 */
792
function template_event_post()
793
{
794
	global $context, $txt, $scripturl, $modSettings;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
795
796
	echo '
797
		<form action="', $scripturl, '?action=calendar;sa=post" method="post" name="postevent" accept-charset="', $context['character_set'], '" onsubmit="submitonce(this);">';
798
799
	if (!empty($context['event']['new']))
800
		echo '
801
			<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">';
802
803
	// Start the main table.
804
	echo '
805
			<div id="post_event">
806
				<div class="cat_bar">
807
					<h3 class="catbg">
808
						', $context['page_title'], '
809
					</h3>
810
				</div>';
811
812
	if (!empty($context['post_error']['messages']))
813
		echo '
814
				<div class="errorbox">
815
					<dl class="event_error">
816
						<dt>
817
							', $context['error_type'] == 'serious' ? '<strong>' . $txt['error_while_submitting'] . '</strong>' : '', '
818
						</dt>
819
						<dt class="error">
820
							', implode('<br>', $context['post_error']['messages']), '
821
						</dt>
822
					</dl>
823
				</div>';
824
825
	echo '
826
				<div class="roundframe noup">
827
					<fieldset id="event_main">
828
						<legend><span', isset($context['post_error']['no_event']) ? ' class="error"' : '', '>', $txt['calendar_event_title'], '</span></legend>
829
						<input type="hidden" name="calendar" value="1">
830
						<div class="event_options_left" id="event_title">
831
							<div>
832
								<input type="text" id="evtitle" name="evtitle" maxlength="255" size="55" value="', $context['event']['title'], '" tabindex="', $context['tabindex']++, '">
833
							</div>
834
						</div>';
835
836
	// If this is a new event let the user specify which board they want the linked post to be put into.
837
	if ($context['event']['new'] && !empty($context['event']['categories']))
838
	{
839
		echo '
840
						<div class="event_options_right" id="event_board">
841
							<div>
842
								<span class="label">', $txt['calendar_post_in'], '</span>
843
								<input type="checkbox" name="link_to_board"', (!empty($context['event']['board']) ? ' checked' : ''), ' onclick="toggleLinked(this.form);">
844
								<select name="board"', empty($context['event']['board']) ? ' disabled' : '', '>';
845
846 View Code Duplication
		foreach ($context['event']['categories'] as $category)
847
		{
848
			echo '
849
									<optgroup label="', $category['name'], '">';
850
851
			foreach ($category['boards'] as $board)
852
				echo '
853
										<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '</option>';
854
			echo '
855
									</optgroup>';
856
		}
857
		echo '
858
								</select>
859
							</div>
860
						</div><!-- #event_board -->';
861
	}
862
863
	// Note to theme writers: The JavaScript expects the input fields for the start and end dates & times to be contained in a wrapper element with the id "event_time_input"
864
	echo '
865
					</fieldset>
866
					<fieldset id="event_options">
867
						<legend>', $txt['calendar_event_options'], '</legend>
868
						<div class="event_options_left" id="event_time_input">
869
							<div>
870
								<span class="label">', $txt['start'], '</span>
871
								<input type="text" name="start_date" id="start_date" maxlength="10" value="', $context['event']['start_date'], '" tabindex="', $context['tabindex']++, '" class="date_input start" data-type="date">
872
								<input type="text" name="start_time" id="start_time" maxlength="11" value="', $context['event']['start_time_local'], '" tabindex="', $context['tabindex']++, '" class="time_input start" data-type="time"', !empty($context['event']['allday']) ? ' disabled' : '', '>
873
							</div>
874
							<div>
875
								<span class="label">', $txt['end'], '</span>
876
								<input type="text" name="end_date" id="end_date" maxlength="10" value="', $context['event']['end_date'], '" tabindex="', $context['tabindex']++, '" class="date_input end" data-type="date"', $modSettings['cal_maxspan'] == 1 ? ' disabled' : '', '>
877
								<input type="text" name="end_time" id="end_time" maxlength="11" value="', $context['event']['end_time_local'], '" tabindex="', $context['tabindex']++, '" class="time_input end" data-type="time"', !empty($context['event']['allday']) ? ' disabled' : '', '>
878
							</div>
879
						</div><!-- #event_time_input -->
880
						<div class="event_options_right" id="event_time_options">
881
							<div id="event_allday">
882
								<label for="allday"><span class="label">', $txt['calendar_allday'], '</span></label>
883
								<input type="checkbox" name="allday" id="allday"', !empty($context['event']['allday']) ? ' checked' : '', ' tabindex="', $context['tabindex']++, '">
884
							</div>
885
							<div id="event_timezone">
886
								<span class="label">', $txt['calendar_timezone'], '</span>
887
								<select name="tz" id="tz"', !empty($context['event']['allday']) ? ' disabled' : '', '>';
888
889 View Code Duplication
	foreach ($context['all_timezones'] as $tz => $tzname)
890
		echo '
891
									<option', is_numeric($tz) ? ' value="" disabled' : ' value="' . $tz . '"', $tz === $context['event']['tz'] ? ' selected' : '', '>', $tzname, '</option>';
892
893
	echo '
894
								</select>
895
							</div>
896
						</div><!-- #event_time_options -->
897
						<div>
898
							<span class="label">', $txt['location'], '</span>
899
							<input type="text" name="event_location" id="event_location" maxlength="255" value="', !empty($context['event']['location']) ? $context['event']['location'] : '', '" tabindex="', $context['tabindex']++, '">
900
						</div>
901
					</fieldset>';
902
903
	echo '
904
					<input type="submit" value="', empty($context['event']['new']) ? $txt['save'] : $txt['post'], '" class="button">';
905
906
	// Delete button?
907
	if (empty($context['event']['new']))
908
		echo '
909
					<input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['calendar_confirm_delete'], '" class="button you_sure">';
910
911
	echo '
912
					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
913
					<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">
914
915
				</div><!-- .roundframe -->
916
			</div><!-- #post_event -->
917
		</form>';
918
}
919
920
function template_bcd()
921
{
922
	global $context, $scripturl;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
923
	$alt = false;
924
925
	echo '
926
		<table class="table_grid" style="margin: 0 auto 0 auto; border: 1px solid #ccc;">
927
			<tr>
928
				<th class="windowbg" style="font-weight: bold; text-align: center; border-bottom: 1px solid #ccc;" colspan="6">BCD Clock</th>
929
			</tr>
930
			<tr class="windowbg">';
931
932
	foreach ($context['clockicons'] as $t => $v)
933
	{
934
		echo '
935
				<td style="padding-', $alt ? 'right' : 'left', ': 1.5em;">';
936
937
		foreach ($v as $i)
938
			echo '
939
					<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '"><br>';
940
941
		echo '
942
				</td>';
943
944
		$alt = !$alt;
945
	}
946
	echo '
947
			</tr>
948
			<tr class="windowbg" style="border-top: 1px solid #ccc; text-align: center;">
949
				<td colspan="6">
950
					<a href="', $scripturl, '?action=clock;rb">Are you hardcore?</a>
951
				</td>
952
			</tr>
953
		</table>
954
955
		<script>
956
			var icons = new Object();';
957
958
	foreach ($context['clockicons'] as $t => $v)
959
	{
960
		foreach ($v as $i)
961
			echo '
962
			icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
963
	}
964
965
	echo '
966
			function update()
967
			{
968
				// Get the current time
969
				var time = new Date();
970
				var hour = time.getHours();
971
				var min = time.getMinutes();
972
				var sec = time.getSeconds();
973
974
				// Break it up into individual digits
975
				var h1 = parseInt(hour / 10);
976
				var h2 = hour % 10;
977
				var m1 = parseInt(min / 10);
978
				var m2 = min % 10;
979
				var s1 = parseInt(sec / 10);
980
				var s2 = sec % 10;
981
982
				// For each digit figure out which ones to turn off and which ones to turn on
983
				var turnon = new Array();';
984
985
	foreach ($context['clockicons'] as $t => $v)
986
	{
987
		foreach ($v as $i)
988
			echo '
989
				if (', $t, ' >= ', $i, ')
990
				{
991
					turnon.push("', $t, '_', $i, '");
992
					', $t, ' -= ', $i, ';
993
				}';
994
	}
995
996
	echo '
997
				for (var i in icons)
998
					if (!in_array(i, turnon))
999
						icons[i].src = "', $context['offimg'], '";
1000
					else
1001
						icons[i].src = "', $context['onimg'], '";
1002
1003
				window.setTimeout("update();", 500);
1004
			}
1005
			// Checks for variable in theArray.
1006
			function in_array(variable, theArray)
1007
			{
1008
				for (var i = 0; i < theArray.length; i++)
1009
				{
1010
					if (theArray[i] == variable)
1011
						return true;
1012
				}
1013
				return false;
1014
			}
1015
1016
			update();
1017
		</script>';
1018
}
1019
1020 View Code Duplication
function template_hms()
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1021
{
1022
	global $context, $scripturl;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1023
	$alt = false;
1024
1025
	echo '
1026
		<table class="table_grid" style="margin: 0 auto 0 auto; border: 1px solid #ccc;">
1027
			<tr>
1028
				<th class="windowbg" style="font-weight: bold; text-align: center; border-bottom: 1px solid #ccc;">Binary Clock</th>
1029
			</tr>';
1030
1031
	foreach ($context['clockicons'] as $t => $v)
1032
	{
1033
		echo '
1034
			<tr class="windowbg">
1035
				<td>';
1036
1037
		foreach ($v as $i)
1038
			echo '
1039
					<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '" style="padding: 2px;">';
1040
1041
		echo '
1042
				</td>
1043
			</tr>';
1044
1045
		$alt = !$alt;
1046
	}
1047
	echo '
1048
			<tr class="windowbg" style="border-top: 1px solid #ccc; text-align: center;">
1049
				<td>
1050
					<a href="', $scripturl, '?action=clock">Too tough for you?</a>
1051
				</td>
1052
			</tr>
1053
		</table>';
1054
1055
	echo '
1056
		<script>
1057
			var icons = new Object();';
1058
1059
	foreach ($context['clockicons'] as $t => $v)
1060
	{
1061
		foreach ($v as $i)
1062
			echo '
1063
			icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
1064
	}
1065
1066
	echo '
1067
			function update()
1068
			{
1069
				// Get the current time
1070
				var time = new Date();
1071
				var h = time.getHours();
1072
				var m = time.getMinutes();
1073
				var s = time.getSeconds();
1074
1075
				// For each digit figure out which ones to turn off and which ones to turn on
1076
				var turnon = new Array();';
1077
1078
	foreach ($context['clockicons'] as $t => $v)
1079
	{
1080
		foreach ($v as $i)
1081
			echo '
1082
				if (', $t, ' >= ', $i, ')
1083
				{
1084
					turnon.push("', $t, '_', $i, '");
1085
					', $t, ' -= ', $i, ';
1086
				}';
1087
	}
1088
1089
	echo '
1090
				for (var i in icons)
1091
					if (!in_array(i, turnon))
1092
						icons[i].src = "', $context['offimg'], '";
1093
					else
1094
						icons[i].src = "', $context['onimg'], '";
1095
1096
				window.setTimeout("update();", 500);
1097
			}
1098
			// Checks for variable in theArray.
1099
			function in_array(variable, theArray)
1100
			{
1101
				for (var i = 0; i < theArray.length; i++)
1102
				{
1103
					if (theArray[i] == variable)
1104
						return true;
1105
				}
1106
				return false;
1107
			}
1108
1109
			update();
1110
		</script>';
1111
}
1112
1113 View Code Duplication
function template_omfg()
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1114
{
1115
	global $context;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1116
	$alt = false;
1117
1118
	echo '
1119
		<table class="table_grid" style="margin: 0 auto 0 auto; border: 1px solid #ccc;">
1120
			<tr>
1121
				<th class="windowbg" style="font-weight: bold; text-align: center; border-bottom: 1px solid #ccc;">OMFG Binary Clock</th>
1122
			</tr>';
1123
1124
	foreach ($context['clockicons'] as $t => $v)
1125
	{
1126
		echo '
1127
			<tr class="windowbg">
1128
				<td>';
1129
1130
		foreach ($v as $i)
1131
			echo '
1132
					<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '" style="padding: 2px;">';
1133
1134
		echo '
1135
				</td>
1136
			</tr>';
1137
1138
		$alt = !$alt;
1139
	}
1140
1141
	echo '
1142
		</table>
1143
		<script>
1144
			var icons = new Object();';
1145
1146
	foreach ($context['clockicons'] as $t => $v)
1147
	{
1148
		foreach ($v as $i)
1149
			echo '
1150
			icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
1151
	}
1152
1153
	echo '
1154
			function update()
1155
			{
1156
				// Get the current time
1157
				var time = new Date();
1158
				var month = time.getMonth() + 1;
1159
				var day = time.getDate();
1160
				var year = time.getFullYear();
1161
				year = year % 100;
1162
				var hour = time.getHours();
1163
				var min = time.getMinutes();
1164
				var sec = time.getSeconds();
1165
1166
				// For each digit figure out which ones to turn off and which ones to turn on
1167
				var turnon = new Array();';
1168
1169
	foreach ($context['clockicons'] as $t => $v)
1170
	{
1171
		foreach ($v as $i)
1172
		echo '
1173
				if (', $t, ' >= ', $i, ')
1174
				{
1175
					turnon.push("', $t, '_', $i, '");
1176
					', $t, ' -= ', $i, ';
1177
				}';
1178
	}
1179
1180
	echo '
1181
				for (var i in icons)
1182
					if (!in_array(i, turnon))
1183
						icons[i].src = "', $context['offimg'], '";
1184
					else
1185
						icons[i].src = "', $context['onimg'], '";
1186
1187
				window.setTimeout("update();", 500);
1188
			}
1189
			// Checks for variable in theArray.
1190
			function in_array(variable, theArray)
1191
			{
1192
				for (var i = 0; i < theArray.length; i++)
1193
				{
1194
					if (theArray[i] == variable)
1195
						return true;
1196
				}
1197
				return false;
1198
			}
1199
1200
			update();
1201
		</script>';
1202
}
1203
1204
function template_thetime()
1205
{
1206
	global $context;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1207
	$alt = false;
1208
1209
	echo '
1210
		<table class="table_grid" style="margin: 0 auto 0 auto; border: 1px solid #ccc;">
1211
			<tr>
1212
				<th class="windowbg" style="font-weight: bold; text-align: center; border-bottom: 1px solid #ccc;">The time you requested</th>
1213
			</tr>';
1214
1215
	foreach ($context['clockicons'] as $v)
1216
	{
1217
		echo '
1218
			<tr class="windowbg">
1219
				<td>';
1220
1221
		foreach ($v as $i)
1222
			echo '
1223
					<img src="', $i ? $context['onimg'] : $context['offimg'], '" alt="" style="padding: 2px;">';
1224
1225
		echo '
1226
				</td>
1227
			</tr>';
1228
1229
		$alt = !$alt;
1230
	}
1231
1232
	echo '
1233
		</table>';
1234
}
1235
1236
?>