Completed
Push — release-2.1 ( b61572...c939ca )
by Mathias
15s
created

Calendar.template.php ➔ template_bcd()   D

Complexity

Conditions 9
Paths 27

Size

Total Lines 100
Code Lines 29

Duplication

Lines 92
Ratio 92 %

Importance

Changes 0
Metric Value
cc 9
eloc 29
nc 27
nop 0
dl 92
loc 100
rs 4.8196
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 2017 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 (L56-134) 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
	{
27
		echo '
28
			<div id="month_grid">
29
				', template_show_month_grid('prev', true), '
30
				', template_show_month_grid('current', true), '
31
				', template_show_month_grid('next', true), '
32
			</div>';
33
	}
34
35
	// What view are we showing?
36
	if ($context['calendar_view'] == 'viewlist')
37
	{
38
		echo '
39
			<div id="main_grid">
40
				', template_show_upcoming_list('main'), '
41
			</div>';
42
	}
43
	elseif ($context['calendar_view'] == 'viewweek')
44
	{
45
		echo '
46
			<div id="main_grid">
47
				', template_show_week_grid('main'), '
48
			</div>';
49
	}
50
	else
51
	{
52
		echo '
53
			<div id="main_grid">
54
				', template_show_month_grid('main'), '
55
			</div>';
56
	}
57
58
	// Close our wrapper.
59
	echo '
60
		</div><!-- #calendar -->';
61
}
62
63
64
/**
65
 * Display a list of upcoming events, birthdays, and holidays.
66
 *
67
 * @param string $grid_name The grid name
68
 * @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...
69
 */
70
function template_show_upcoming_list($grid_name)
71
{
72
	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...
73
74
	// Bail out if we have nothing to work with
75
	if (!isset($context['calendar_grid_' . $grid_name]))
76
		return false;
77
78
	// Protect programmer sanity
79
	$calendar_data = &$context['calendar_grid_' . $grid_name];
80
81
	// Do we want a title?
82
	if (empty($calendar_data['disable_title']))
83
	{
84
		echo '
85
			<div class="cat_bar">
86
				<h3 class="catbg centertext largetext">
87
					<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>
88
				</h3>
89
			</div>';
90
	}
91
92
	// Give the user some controls to work with
93
	template_calendar_top($calendar_data);
94
95
	// First, list any events
96 View Code Duplication
	if (!empty($calendar_data['events']))
97
	{
98
		echo '
99
			<div>
100
				<div class="title_bar">
101
					<h3 class="titlebg">', str_replace(':', '', $txt['events']), '</h3>
102
				</div>
103
				<ul>';
104
105
		foreach ($calendar_data['events'] as $date => $date_events)
106
		{
107
			foreach ($date_events as $event)
108
			{
109
				echo '
110
					<li class="windowbg">
111
						<strong class="event_title">', $event['link'], '</strong>';
112
113
				if ($event['can_edit'])
114
					echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>';
115
116
				if ($event['can_export'])
117
					echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>';
118
119
				echo '
120
						<br>';
121
122
				if (!empty($event['allday']))
123
				{
124
					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>' : '';
125
				}
126
				else
127
				{
128
					// Display event info relative to user's local timezone
129
					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'] . '">';
130
131
					if ($event['start_date_local'] != $event['end_date_local'])
132
						echo trim($event['end_date_local']) . ', ';
133
134
					echo trim($event['end_time_local']);
135
136
					// Display event info relative to original timezone
137
					if ($event['start_date_local'] . $event['start_time_local'] != $event['start_date_orig'] . $event['start_time_orig'])
138
					{
139
						echo '</time> (<time datetime="' . $event['start_iso_gmdate'] . '">';
140
141
						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'])
142
							echo trim($event['start_date_orig']), ', ';
143
144
						echo trim($event['start_time_orig']), '</time> &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">';
145
146
						if ($event['start_date_orig'] != $event['end_date_orig'])
147
							echo trim($event['end_date_orig']) . ', ';
148
149
						echo trim($event['end_time_orig']), ' ', $event['tz_abbrev'], '</time>)';
150
					}
151
					// Event is scheduled in the user's own timezone? Let 'em know, just to avoid confusion
152
					else
153
						echo ' ', $event['tz_abbrev'], '</time>';
154
				}
155
156
				if (!empty($event['location']))
157
					echo '<br>', $event['location'];
158
159
				echo '
160
					</li>';
161
			}
162
		}
163
164
		echo '
165
				</ul>
166
			</div>';
167
	}
168
169
	// Next, list any birthdays
170
	if (!empty($calendar_data['birthdays']))
171
	{
172
		echo '
173
			<div>
174
				<div class="title_bar">
175
					<h3 class="titlebg">', str_replace(':', '', $txt['birthdays']), '</h3>
176
				</div>
177
				<div class="windowbg">';
178
179
		foreach ($calendar_data['birthdays'] as $date)
180
		{
181
			echo '
182
					<p class="inline">
183
						<strong>', $date['date_local'], '</strong>: ';
184
185
			unset($date['date_local']);
186
187
			$birthdays = array();
188
189
			foreach ($date as $member)
190
				$birthdays[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '">' . $member['name'] . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>';
191
192
			echo implode(', ', $birthdays);
193
194
			echo '
195
					</p>';
196
		}
197
198
		echo '
199
				</div><!-- .windowbg -->
200
			</div>';
201
	}
202
203
	// Finally, list any holidays
204
	if (!empty($calendar_data['holidays']))
205
	{
206
		echo '
207
			<div>
208
				<div class="title_bar">
209
					<h3 class="titlebg">', str_replace(':', '', $txt['calendar_prompt']), '</h3>
210
				</div>
211
				<div class="windowbg">
212
					<p class="inline holidays">';
213
214
		$holidays = array();
215
216
		foreach ($calendar_data['holidays'] as $date)
217
		{
218
			$date_local = $date['date_local'];
219
			unset($date['date_local']);
220
221
			foreach ($date as $holiday)
222
				$holidays[] = $holiday . ' (' . $date_local . ')';
223
		}
224
225
		echo implode(', ', $holidays);
226
227
		echo '
228
					</p>
229
				</div><!-- .windowbg -->
230
			</div>';
231
	}
232
}
233
234
/**
235
 * Display a monthly calendar grid.
236
 *
237
 * @param string $grid_name The grid name
238
 * @param bool $is_mini Is this a mini grid?
239
 * @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...
240
 */
241
function template_show_month_grid($grid_name, $is_mini = false)
242
{
243
	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...
244
245
	// If the grid doesn't exist, no point in proceeding.
246
	if (!isset($context['calendar_grid_' . $grid_name]))
247
		return false;
248
249
	// A handy little pointer variable.
250
	$calendar_data = &$context['calendar_grid_' . $grid_name];
251
252
	// Some conditions for whether or not we should show the week links *here*.
253
	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)))
254
		$show_week_links = true;
255
	else
256
		$show_week_links = false;
257
258
	// Assuming that we've not disabled it, show the title block!
259
	if (empty($calendar_data['disable_title']))
260
	{
261
		echo '
262
			<div class="cat_bar">
263
				<h3 class="catbg centertext largetext">';
264
265
		// Previous Link: If we're showing prev / next and it's not a mini-calendar.
266
		if (empty($calendar_data['previous_calendar']['disabled']) && $calendar_data['show_next_prev'] && $is_mini === false)
267
		{
268
			echo '
269
					<span class="floatleft">
270
						<a href="', $calendar_data['previous_calendar']['href'], '">&#171;</a>
271
					</span>';
272
		}
273
274
		// Next Link: if we're showing prev / next and it's not a mini-calendar.
275 View Code Duplication
		if (empty($calendar_data['next_calendar']['disabled']) && $calendar_data['show_next_prev'] && $is_mini === false)
276
		{
277
			echo '
278
					<span class="floatright">
279
						<a href="', $calendar_data['next_calendar']['href'], '">&#187;</a>
280
					</span>';
281
		}
282
283
		// Arguably the most exciting part, the title!
284
		echo '
285
					<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>
286
				</h3>
287
			</div><!-- .cat_bar -->';
288
	}
289
290
	// Show the controls on main grids
291
	if ($is_mini === false)
292
		template_calendar_top($calendar_data);
293
294
	// Finally, the main calendar table.
295
	echo '
296
			<table class="calendar_table">';
297
298
	// Show each day of the week.
299
	if (empty($calendar_data['disable_day_titles']))
300
	{
301
		echo '
302
				<tr>';
303
304
		// If we're showing week links, there's an extra column ahead of the week links, so let's think ahead and be prepared!
305
		if ($show_week_links === true)
306
			echo '
307
					<th>&nbsp;</th>';
308
309
		// Now, loop through each actual day of the week.
310
		foreach ($calendar_data['week_days'] as $day)
311
		{
312
			echo '
313
					<th class="days" scope="col">', !empty($calendar_data['short_day_titles']) || $is_mini === true ? $txt['days_short'][$day] : $txt['days'][$day], '</th>';
314
		}
315
316
		echo '
317
				</tr>';
318
	}
319
320
	// Our looping begins on a per-week basis.
321
	foreach ($calendar_data['weeks'] as $week)
322
	{
323
324
		// Some useful looping variables.
325
		$current_month_started = false;
326
		$count = 1;
327
		$final_count = 1;
328
329
		echo '
330
				<tr class="days_wrapper">';
331
332
		// This is where we add the actual week link, if enabled on this location.
333
		if ($show_week_links === true)
334
		{
335
			echo '
336
					<td class="windowbg2 weeks">
337
						<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>
338
					</td>';
339
		}
340
341
		// Now loop through each day in the week we're on.
342
		foreach ($week['days'] as $day)
343
		{
344
			// What classes should each day inherit? Day is default.
345
			$classes = array('days');
346
			if (!empty($day['day']))
347
			{
348
349
				// Default Classes (either compact or comfortable and either calendar_today or windowbg).
350
				$classes[] = !empty($calendar_data['size']) && $calendar_data['size'] == 'small' ? 'compact' : 'comfortable';
351
				$classes[] = !empty($day['is_today']) ? 'calendar_today' : 'windowbg';
352
353
				// Additional classes are given for events, holidays, and birthdays.
354 View Code Duplication
				if (!empty($day['events']) && !empty($calendar_data['highlight']['events']))
355
				{
356
					if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1, 3)))
357
						$classes[] = 'events';
358
					elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2, 3)))
359
						$classes[] = 'events';
360
				}
361 View Code Duplication
				if (!empty($day['holidays']) && !empty($calendar_data['highlight']['holidays']))
362
				{
363
					if ($is_mini === true && in_array($calendar_data['highlight']['holidays'], array(1, 3)))
364
						$classes[] = 'holidays';
365
					elseif ($is_mini === false && in_array($calendar_data['highlight']['holidays'], array(2, 3)))
366
						$classes[] = 'holidays';
367
				}
368 View Code Duplication
				if (!empty($day['birthdays']) && !empty($calendar_data['highlight']['birthdays']))
369
				{
370
					if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1, 3)))
371
						$classes[] = 'birthdays';
372
					elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2, 3)))
373
						$classes[] = 'birthdays';
374
				}
375
			}
376
			else
377
			{
378
				// Default Classes (either compact or comfortable and disabled).
379
				$classes[] = !empty($calendar_data['size']) && $calendar_data['size'] == 'small' ? 'compact' : 'comfortable';
380
				$classes[] = 'disabled';
381
			}
382
383
			// Now, implode the classes for each day.
384
			echo '
385
					<td class="', implode(' ', $classes), '">';
386
387
			// If it's within this current month, go ahead and begin.
388
			if (!empty($day['day']))
389
			{
390
391
				// If it's the first day of this month and not a mini-calendar, we'll add the month title - whether short or full.
392
				$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']] . ' ') : '';
393
394
				// The actual day number - be it a link, or just plain old text!
395
				if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
396
					echo '
397
						<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>';
398
				elseif ($is_mini)
399
					echo '
400
						<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>';
401
				else
402
					echo '
403
						<span class="day_text">', $title_prefix, $day['day'], '</span>';
404
405
				// A lot of stuff, we're not showing on mini-calendars to conserve space.
406
				if ($is_mini === false)
407
				{
408
					// Holidays are always fun, let's show them!
409
					if (!empty($day['holidays']))
410
						echo '
411
						<div class="smalltext holiday">
412
							<span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), '
413
						</div>';
414
415
					// Happy Birthday Dear Member!
416
					if (!empty($day['birthdays']))
417
					{
418
						echo '
419
						<div class="smalltext">
420
							<span class="birthday">', $txt['birthdays'], '</span> ';
421
422
						/* Each of the birthdays has:
423
							id, name (person), age (if they have one set?), and is_last. (last in list?) */
424
						$use_js_hide = empty($context['show_all_birthdays']) && count($day['birthdays']) > 15;
425
						$birthday_count = 0;
426
						foreach ($day['birthdays'] as $member)
427
						{
428
							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) ? '' : ', ';
429
430
							// 9...10! Let's stop there.
431
							if ($birthday_count == 10 && $use_js_hide)
432
								// !!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...
433
								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;">, ';
434
435
							++$birthday_count;
436
						}
437
						if ($use_js_hide)
438
							echo '
439
							</span>';
440
441
						echo '
442
						</div><!-- .smalltext -->';
443
					}
444
445
					// Any special posted events?
446
					if (!empty($day['events']))
447
					{
448
						// Sort events by start time (all day events will be listed first)
449
						uasort($day['events'], function($a, $b) {
450
							if ($a['start_timestamp'] == $b['start_timestamp'])
451
								return 0;
452
453
							return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
454
						});
455
456
						echo '
457
						<div class="smalltext lefttext">
458
							<span class="event">', $txt['events'], '</span><br>';
459
460
						/* The events are made up of:
461
							title, href, is_last, can_edit (are they allowed to?), and modify_href. */
462
						foreach ($day['events'] as $event)
463
						{
464
							$event_icons_needed = ($event['can_edit'] || $event['can_export']) ? true : false;
465
466
							echo '
467
							<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' : '', '">
468
								', $event['link'], '<br>
469
								<span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">';
470
471
							if (!empty($event['start_time_local']) && $event['starts_today'] == true)
472
								echo trim(str_replace(':00 ', ' ', $event['start_time_local']));
473
							elseif (!empty($event['end_time_local']) && $event['ends_today'] == true)
474
								echo strtolower($txt['ends']), ' ', trim(str_replace(':00 ', ' ', $event['end_time_local']));
475
							elseif (!empty($event['allday']))
476
								echo $txt['calendar_allday'];
477
478
							echo '
479
								</span>';
480
481 View Code Duplication
							if (!empty($event['location']))
482
								echo '
483
								<br>
484
								<span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
485
486
							if ($event['can_edit'] || $event['can_export'])
487
							{
488
								echo '
489
								<span class="modify_event_links">';
490
491
								// If they can edit the event, show an icon they can click on....
492
								if ($event['can_edit'])
493
								{
494
									echo '
495
									<a class="modify_event" href="', $event['modify_href'], '">
496
										<span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span>
497
									</a>';
498
								}
499
								// Exporting!
500
								if ($event['can_export'])
501
								{
502
									echo '
503
									<a class="modify_event" href="', $event['export_href'], '">
504
										<span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span>
505
									</a>';
506
								}
507
508
								echo '
509
								</span><br class="clear">';
510
							}
511
512
							echo '
513
							</div><!-- .event_wrapper -->';
514
						}
515
516
						echo '
517
						</div><!-- .smalltext -->';
518
					}
519
				}
520
				$current_month_started = $count;
521
			}
522
			// Otherwise, assuming it's not a mini-calendar, we can show previous / next month days!
523
			elseif ($is_mini === false)
524
			{
525
				if (empty($current_month_started) && !empty($context['calendar_grid_prev']))
526
					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...
527
				elseif (!empty($current_month_started) && !empty($context['calendar_grid_next']))
528
					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>';
529
			}
530
531
			// Close this day and increase var count.
532
			echo '
533
					</td>';
534
535
			++$count;
536
		}
537
538
		echo '
539
				</tr>';
540
	}
541
542
	// The end of our main table.
543
	echo '
544
			</table>';
545
}
546
547
/**
548
 * Shows a weekly grid
549
 *
550
 * @param string $grid_name The name of the grid
551
 * @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...
552
 */
553
function template_show_week_grid($grid_name)
554
{
555
	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...
556
557
	// We might have no reason to proceed, if the variable isn't there.
558
	if (!isset($context['calendar_grid_' . $grid_name]))
559
		return false;
560
561
	// Handy pointer.
562
	$calendar_data = &$context['calendar_grid_' . $grid_name];
563
564
	// At the very least, we have one month. Possibly two, though.
565
	$iteration = 1;
566
	foreach ($calendar_data['months'] as $month_data)
567
	{
568
		// For our first iteration, we'll add a nice header!
569
		if ($iteration == 1)
570
		{
571
			echo '
572
				<div class="cat_bar">
573
					<h3 class="catbg centertext largetext">';
574
575
			// Previous Week Link...
576 View Code Duplication
			if (empty($calendar_data['previous_calendar']['disabled']) && !empty($calendar_data['show_next_prev']))
577
			{
578
				echo '
579
						<span class="floatleft">
580
							<a href="', $calendar_data['previous_week']['href'], '">&#171;</a>
581
						</span>';
582
			}
583
584
			// Next Week Link...
585 View Code Duplication
			if (empty($calendar_data['next_calendar']['disabled']) && !empty($calendar_data['show_next_prev']))
586
			{
587
				echo '
588
						<span class="floatright">
589
							<a href="', $calendar_data['next_week']['href'], '">&#187;</a>
590
						</span>';
591
			}
592
593
			// The Month Title + Week Number...
594
			if (!empty($calendar_data['week_title']))
595
				echo $calendar_data['week_title'];
596
597
			echo '
598
					</h3>
599
				</div><!-- .cat_bar -->';
600
601
			// Show the controls
602
			template_calendar_top($calendar_data);
603
		}
604
605
		// Our actual month...
606
		echo '
607
				<div class="week_month_title">
608
					<a href="', $scripturl, '?action=calendar;month=', $month_data['current_month'], '">
609
						', $txt['months_titles'][$month_data['current_month']], '
610
					</a>
611
				</div>';
612
613
		// The main table grid for $this week.
614
		echo '
615
				<table class="table_grid calendar_week">
616
					<tr>
617
						<th class="days" scope="col">', $txt['calendar_day'], '</th>
618
						<th class="days" scope="col">', $txt['events'], '</th>
619
						<th class="days" scope="col">', $txt['calendar_prompt'], '</th>
620
						<th class="days" scope="col">', $txt['birthdays'], '</th>
621
					</tr>';
622
623
		// Each day of the week.
624
		foreach ($month_data['days'] as $day)
625
		{
626
			// How should we be highlighted or otherwise not...?
627
			$classes = array('days');
628
			$classes[] = !empty($calendar_data['size']) && $calendar_data['size'] == 'small' ? 'compact' : 'comfortable';
629
			$classes[] = !empty($day['is_today']) ? 'calendar_today' : 'windowbg';
630
631
			echo '
632
					<tr class="days_wrapper">
633
						<td class="', implode(' ', $classes), ' act_day">';
634
635
			// Should the day number be a link?
636
			if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
637
				echo '
638
							<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>';
639
			else
640
				echo $txt['days'][$day['day_of_week']], ' - ', $day['day'];
641
642
			echo '
643
						</td>
644
						<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'] : '', '">';
645
646
			// Show any events...
647
			if (!empty($day['events']))
648
			{
649
				// Sort events by start time (all day events will be listed first)
650
				uasort($day['events'], function($a, $b) {
651
					if ($a['start_timestamp'] == $b['start_timestamp'])
652
						return 0;
653
					return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
654
				});
655
656
				foreach ($day['events'] as $event)
657
				{
658
					echo '
659
							<div class="event_wrapper">';
660
661
					$event_icons_needed = ($event['can_edit'] || $event['can_export']) ? true : false;
662
663
					echo $event['link'], '<br>
664
								<span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">';
665
666
					if (!empty($event['start_time_local']))
667
						echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' &ndash; ' . trim($event['end_time_local']) : '';
668
					else
669
						echo $txt['calendar_allday'];
670
671
					echo '
672
								</span>';
673
674 View Code Duplication
					if (!empty($event['location']))
675
						echo '<br>
676
								<span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
677
678
					if (!empty($event_icons_needed))
679
					{
680
						echo ' <span class="modify_event_links">';
681
682
						// If they can edit the event, show a star they can click on....
683
						if (!empty($event['can_edit']))
684
						{
685
							echo '
686
									<a class="modify_event" href="', $event['modify_href'], '">
687
										<span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span>
688
									</a>';
689
						}
690
						// Can we export? Sweet.
691
						if (!empty($event['can_export']))
692
						{
693
							echo '
694
									<a class="modify_event" href="', $event['export_href'], '">
695
										<span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span>
696
									</a>';
697
						}
698
699
						echo '
700
								</span><br class="clear">';
701
					}
702
703
					echo '
704
							</div><!-- .event_wrapper -->';
705
				}
706
707
				if (!empty($context['can_post']))
708
				{
709
					echo '
710
							<div class="week_add_event">
711
								<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>
712
							</div>
713
							<br class="clear">';
714
				}
715
			}
716 View Code Duplication
			else
717
			{
718
				if (!empty($context['can_post']))
719
				{
720
					echo '
721
							<div class="week_add_event">
722
								<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>
723
							</div>';
724
				}
725
			}
726
			echo '
727
						</td>
728
						<td class="', implode(' ', $classes), !empty($day['holidays']) ? ' holidays' : ' disabled', ' holiday_col" data-css-prefix="' . $txt['calendar_prompt'] . ' ">';
729
730
			// Show any holidays!
731
			if (!empty($day['holidays']))
732
				echo implode('<br>', $day['holidays']);
733
734
			echo '
735
						</td>
736
						<td class="', implode(' ', $classes), '', !empty($day['birthdays']) ? ' birthdays' : ' disabled', ' birthday_col" data-css-prefix="' . $txt['birthdays'] . ' ">';
737
738
			// Show any birthdays...
739
			if (!empty($day['birthdays']))
740
			{
741 View Code Duplication
				foreach ($day['birthdays'] as $member)
742
				{
743
					echo '
744
							<a href="', $scripturl, '?action=profile;u=', $member['id'], '">', $member['name'], '</a>
745
							', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '
746
							', $member['is_last'] ? '' : '<br>';
747
				}
748
			}
749
			echo '
750
						</td>
751
					</tr>';
752
		}
753
754
		// Increase iteration for loop counting.
755
		++$iteration;
756
757
		echo '
758
				</table>';
759
	}
760
}
761
762
/**
763
 * Calendar controls under the title
764
 *
765
 * Creates the view selector (list, month, week), the date selector (either a
766
 * select menu or a date range chooser, depending on the circumstances), and the
767
 * "Post Event" button.
768
 *
769
 * @param array $calendar_data The data for the calendar grid that this is for
770
 */
771
function template_calendar_top($calendar_data)
772
{
773
	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...
774
775
	echo '
776
		<div class="calendar_top roundframe', empty($calendar_data['disable_title']) ? ' noup' : '', '">
777
			<div id="calendar_viewselector" class="buttonrow floatleft">
778
				<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>
779
				<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>
780
				<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>
781
			</div>
782
			', template_button_strip($context['calendar_buttons'], 'right');
783
784
	if ($context['calendar_view'] == 'viewlist')
785
	{
786
		echo '
787
			<form action="', $scripturl, '?action=calendar;viewlist" id="calendar_range" method="post" accept-charset="', $context['character_set'], '">
788
				<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">
789
				<span>', strtolower($txt['to']), '</span>
790
				<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">
791
				<input type="submit" class="button" style="float:none" id="view_button" value="', $txt['view'], '">
792
			</form>';
793
	}
794
	else
795
	{
796
		echo'
797
			<form action="', $scripturl, '?action=calendar" id="calendar_navigation" method="post" accept-charset="', $context['character_set'], '">
798
				<select name="month" id="input_month">';
799
800
		// Show a select box with all the months.
801
		foreach ($txt['months_short'] as $number => $month)
802
		{
803
			echo '
804
					<option value="', $number, '"', $number == $context['current_month'] ? ' selected' : '', '>', $month, '</option>';
805
		}
806
807
		echo '
808
				</select>
809
				<select name="year">';
810
811
		// Show a link for every year.....
812
		for ($year = $context['calendar_resources']['min_year']; $year <= $context['calendar_resources']['max_year']; $year++)
813
		{
814
			echo '
815
					<option value="', $year, '"', $year == $context['current_year'] ? ' selected' : '', '>', $year, '</option>';
816
		}
817
818
		echo '
819
				</select>
820
				<input type="submit" class="button" id="view_button" value="', $txt['view'], '">
821
			</form>';
822
	}
823
824
	echo'
825
		</div><!-- .calendar_top -->';
826
}
827
828
/**
829
 * Template for posting a calendar event.
830
 */
831
function template_event_post()
832
{
833
	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...
834
835
	echo '
836
		<form action="', $scripturl, '?action=calendar;sa=post" method="post" name="postevent" accept-charset="', $context['character_set'], '" onsubmit="submitonce(this);" style="margin: 0;">';
837
838
	if (!empty($context['event']['new']))
839
		echo '
840
			<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">';
841
842
	// Start the main table.
843
	echo '
844
			<div id="post_event">
845
				<div class="cat_bar">
846
					<h3 class="catbg">
847
						', $context['page_title'], '
848
					</h3>
849
				</div>';
850
851
	if (!empty($context['post_error']['messages']))
852
	{
853
		echo '
854
				<div class="errorbox">
855
					<dl class="event_error">
856
						<dt>
857
							', $context['error_type'] == 'serious' ? '<strong>' . $txt['error_while_submitting'] . '</strong>' : '', '
858
						</dt>
859
						<dt class="error">
860
							', implode('<br>', $context['post_error']['messages']), '
861
						</dt>
862
					</dl>
863
				</div>';
864
	}
865
866
	echo '
867
				<div class="roundframe noup">
868
					<fieldset id="event_main">
869
						<legend><span', isset($context['post_error']['no_event']) ? ' class="error"' : '', '>', $txt['calendar_event_title'], '</span></legend>
870
						<input type="hidden" name="calendar" value="1">
871
						<div class="event_options_left" id="event_title">
872
							<div>
873
								<input type="text" id="evtitle" name="evtitle" maxlength="255" size="55" value="', $context['event']['title'], '" tabindex="', $context['tabindex']++, '">
874
							</div>
875
						</div>';
876
877
	// If this is a new event let the user specify which board they want the linked post to be put into.
878
	if ($context['event']['new'] && !empty($context['event']['categories']))
879
	{
880
		echo '
881
						<div class="event_options_right" id="event_board">
882
							<div>
883
								<span class="label">', $txt['calendar_post_in'], '</span>
884
								<input type="checkbox" style="vertical-align: middle;" name="link_to_board"', (!empty($context['event']['board']) ? ' checked' : ''), ' onclick="toggleLinked(this.form);">
885
								<select name="board"', empty($context['event']['board']) ? ' disabled' : '', '>';
886
887 View Code Duplication
		foreach ($context['event']['categories'] as $category)
888
		{
889
			echo '
890
									<optgroup label="', $category['name'], '">';
891
892
			foreach ($category['boards'] as $board)
893
				echo '
894
										<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '&nbsp;</option>';
895
			echo '
896
									</optgroup>';
897
		}
898
		echo '
899
								</select>
900
							</div>
901
						</div><!-- #event_board -->';
902
	}
903
904
	// Note to theme writers: The JavaScripts expect the input fields for the start and end dates & times to be contained in a wrapper element with the id "event_time_input"
905
	echo '
906
					</fieldset>
907
					<fieldset id="event_options">
908
						<legend>', $txt['calendar_event_options'], '</legend>
909
						<div class="event_options_left" id="event_time_input">
910
							<div>
911
								<span class="label">', $txt['start'], '</span>
912
								<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">
913
								<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' : '', '>
914
							</div>
915
							<div>
916
								<span class="label">', $txt['end'], '</span>
917
								<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' : '', '>
918
								<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' : '', '>
919
							</div>
920
						</div><!-- #event_time_input -->
921
						<div class="event_options_right" id="event_time_options">
922
							<div id="event_allday">
923
								<label for="allday"><span class="label">', $txt['calendar_allday'], '</span></label>
924
								<input type="checkbox" name="allday" id="allday"', !empty($context['event']['allday']) ? ' checked' : '', ' tabindex="', $context['tabindex']++, '">
925
							</div>
926
							<div id="event_timezone">
927
								<span class="label">', $txt['calendar_timezone'], '</span>
928
								<select name="tz" id="tz"', !empty($context['event']['allday']) ? ' disabled' : '', '>';
929
930 View Code Duplication
	foreach ($context['all_timezones'] as $tz => $tzname)
931
		echo '
932
									<option value="', $tz, '"', $tz == $context['event']['tz'] ? ' selected' : '', '>', $tzname, '</option>';
933
934
	echo '
935
								</select>
936
							</div>
937
						</div><!-- #event_time_options -->
938
						<div>
939
							<span class="label">', $txt['location'], '</span>
940
							<input type="text" name="event_location" id="event_location" maxlength="255" value="', !empty($context['event']['location']) ? $context['event']['location'] : '', '" tabindex="', $context['tabindex']++, '">
941
						</div>
942
					</fieldset>';
943
944
	echo '
945
					<input type="submit" value="', empty($context['event']['new']) ? $txt['save'] : $txt['post'], '" class="button">';
946
947
	// Delete button?
948
	if (empty($context['event']['new']))
949
		echo '
950
					<input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['calendar_confirm_delete'], '" class="button you_sure">';
951
952
	echo '
953
					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
954
					<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">
955
956
				</div><!-- .roundframe -->
957
			</div><!-- #post_event -->
958
		</form>';
959
}
960
961 View Code Duplication
function template_bcd()
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...
962
{
963
	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...
964
	$alt = false;
965
966
	echo '
967
		<table class="table_grid" style="margin: 0 auto 0 auto; border: 1px solid #ccc;">
968
			<tr>
969
				<th class="windowbg2" style="font-weight: bold; text-align: center; border-bottom: 1px solid #ccc;" colspan="6">BCD Clock</th>
970
			</tr>
971
			<tr class="windowbg">';
972
973
	foreach ($context['clockicons'] as $t => $v)
974
	{
975
		echo '
976
				<td style="padding-', $alt ? 'right' : 'left', ': 1.5em;">';
977
978
		foreach ($v as $i)
979
		{
980
			echo '
981
					<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '"><br>';
982
		}
983
		echo '
984
				</td>';
985
986
		$alt = !$alt;
987
	}
988
	echo '
989
			</tr>
990
			<tr class="', $alt ? 'windowbg2' : 'windowbg', '" style="border-top: 1px solid #ccc; text-align: center;">
991
				<td colspan="6">
992
					<a href="', $scripturl, '?action=clock;rb">Are you hardcore?</a>
993
				</td>
994
			</tr>
995
		</table>
996
997
		<script>
998
			var icons = new Object();';
999
1000
	foreach ($context['clockicons'] as $t => $v)
1001
	{
1002
		foreach ($v as $i)
1003
			echo '
1004
			icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
1005
	}
1006
1007
	echo '
1008
			function update()
1009
			{
1010
				// Get the current time
1011
				var time = new Date();
1012
				var hour = time.getHours();
1013
				var min = time.getMinutes();
1014
				var sec = time.getSeconds();
1015
1016
				// Break it up into individual digits
1017
				var h1 = parseInt(hour / 10);
1018
				var h2 = hour % 10;
1019
				var m1 = parseInt(min / 10);
1020
				var m2 = min % 10;
1021
				var s1 = parseInt(sec / 10);
1022
				var s2 = sec % 10;
1023
1024
				// For each digit figure out which ones to turn off and which ones to turn on
1025
				var turnon = new Array();';
1026
1027
	foreach ($context['clockicons'] as $t => $v)
1028
	{
1029
		foreach ($v as $i)
1030
			echo '
1031
				if (', $t, ' >= ', $i, ')
1032
				{
1033
					turnon.push("', $t, '_', $i, '");
1034
					', $t, ' -= ', $i, ';
1035
				}';
1036
	}
1037
1038
	echo '
1039
				for (var i in icons)
1040
					if (!in_array(i, turnon))
1041
						icons[i].src = "', $context['offimg'], '";
1042
					else
1043
						icons[i].src = "', $context['onimg'], '";
1044
1045
				window.setTimeout("update();", 500);
1046
			}
1047
			// Checks for variable in theArray.
1048
			function in_array(variable, theArray)
1049
			{
1050
				for (var i = 0; i < theArray.length; i++)
1051
				{
1052
					if (theArray[i] == variable)
1053
						return true;
1054
				}
1055
				return false;
1056
			}
1057
1058
			update();
1059
		</script>';
1060
}
1061
1062 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...
1063
{
1064
	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...
1065
	$alt = false;
1066
1067
	echo '
1068
		<table class="table_grid" style="margin: 0 auto 0 auto; border: 1px solid #ccc;">
1069
			<tr>
1070
				<th class="windowbg2" style="font-weight: bold; text-align: center; border-bottom: 1px solid #ccc;">Binary Clock</th>
1071
			</tr>';
1072
1073
	foreach ($context['clockicons'] as $t => $v)
1074
	{
1075
		echo '
1076
			<tr class="', $alt ? 'windowbg2' : 'windowbg', '">
1077
				<td>';
1078
		foreach ($v as $i)
1079
		{
1080
			echo '
1081
					<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '" style="padding: 2px;">';
1082
		}
1083
		echo '
1084
				</td>
1085
			</tr>';
1086
1087
		$alt = !$alt;
1088
	}
1089
	echo '
1090
			<tr class="', $alt ? 'windowbg2' : 'windowbg', '" style="border-top: 1px solid #ccc; text-align: center;">
1091
				<td>
1092
					<a href="', $scripturl, '?action=clock">Too tough for you?</a>
1093
				</td>
1094
			</tr>
1095
		</table>';
1096
1097
	echo '
1098
		<script>
1099
			var icons = new Object();';
1100
1101
	foreach ($context['clockicons'] as $t => $v)
1102
	{
1103
		foreach ($v as $i)
1104
			echo '
1105
			icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
1106
	}
1107
1108
	echo '
1109
			function update()
1110
			{
1111
				// Get the current time
1112
				var time = new Date();
1113
				var h = time.getHours();
1114
				var m = time.getMinutes();
1115
				var s = time.getSeconds();
1116
1117
				// For each digit figure out which ones to turn off and which ones to turn on
1118
				var turnon = new Array();';
1119
1120
	foreach ($context['clockicons'] as $t => $v)
1121
	{
1122
		foreach ($v as $i)
1123
			echo '
1124
				if (', $t, ' >= ', $i, ')
1125
				{
1126
					turnon.push("', $t, '_', $i, '");
1127
					', $t, ' -= ', $i, ';
1128
				}';
1129
	}
1130
1131
	echo '
1132
				for (var i in icons)
1133
					if (!in_array(i, turnon))
1134
						icons[i].src = "', $context['offimg'], '";
1135
					else
1136
						icons[i].src = "', $context['onimg'], '";
1137
1138
				window.setTimeout("update();", 500);
1139
			}
1140
			// Checks for variable in theArray.
1141
			function in_array(variable, theArray)
1142
			{
1143
				for (var i = 0; i < theArray.length; i++)
1144
				{
1145
					if (theArray[i] == variable)
1146
						return true;
1147
				}
1148
				return false;
1149
			}
1150
1151
			update();
1152
		</script>';
1153
}
1154
1155
function template_omfg()
1156
{
1157
	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...
1158
	$alt = false;
1159
1160
	echo '
1161
		<table class="table_grid" style="margin: 0 auto 0 auto; border: 1px solid #ccc;">
1162
			<tr>
1163
				<th class="windowbg2" style="font-weight: bold; text-align: center; border-bottom: 1px solid #ccc;">OMFG Binary Clock</th>
1164
			</tr>';
1165
1166
	foreach ($context['clockicons'] as $t => $v)
1167
	{
1168
		echo '
1169
			<tr class="', $alt ? 'windowbg2' : 'windowbg', '">
1170
				<td>';
1171
1172
		foreach ($v as $i)
1173
		{
1174
			echo '
1175
					<img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '" style="padding: 2px;">';
1176
		}
1177
		echo '
1178
				</td>
1179
			</tr>';
1180
1181
		$alt = !$alt;
1182
	}
1183
1184
	echo '
1185
		</table>
1186
		<script>
1187
			var icons = new Object();';
1188
1189
	foreach ($context['clockicons'] as $t => $v)
1190
	{
1191
		foreach ($v as $i)
1192
			echo '
1193
			icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
1194
	}
1195
1196
	echo '
1197
			function update()
1198
			{
1199
				// Get the current time
1200
				var time = new Date();
1201
				var month = time.getMonth() + 1;
1202
				var day = time.getDate();
1203
				var year = time.getFullYear();
1204
				year = year % 100;
1205
				var hour = time.getHours();
1206
				var min = time.getMinutes();
1207
				var sec = time.getSeconds();
1208
1209
				// For each digit figure out which ones to turn off and which ones to turn on
1210
				var turnon = new Array();';
1211
1212
	foreach ($context['clockicons'] as $t => $v)
1213
	{
1214
		foreach ($v as $i)
1215
		echo '
1216
				if (', $t, ' >= ', $i, ')
1217
				{
1218
					turnon.push("', $t, '_', $i, '");
1219
					', $t, ' -= ', $i, ';
1220
				}';
1221
	}
1222
1223
	echo '
1224
				for (var i in icons)
1225
					if (!in_array(i, turnon))
1226
						icons[i].src = "', $context['offimg'], '";
1227
					else
1228
						icons[i].src = "', $context['onimg'], '";
1229
1230
				window.setTimeout("update();", 500);
1231
			}
1232
			// Checks for variable in theArray.
1233
			function in_array(variable, theArray)
1234
			{
1235
				for (var i = 0; i < theArray.length; i++)
1236
				{
1237
					if (theArray[i] == variable)
1238
						return true;
1239
				}
1240
				return false;
1241
			}
1242
1243
			update();
1244
		</script>';
1245
}
1246
1247
function template_thetime()
1248
{
1249
	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...
1250
	$alt = false;
1251
1252
	echo '
1253
		<table class="table_grid" style="margin: 0 auto 0 auto; border: 1px solid #ccc;">
1254
			<tr>
1255
				<th class="windowbg2" style="font-weight: bold; text-align: center; border-bottom: 1px solid #ccc;">The time you requested</th>
1256
			</tr>';
1257
1258
	foreach ($context['clockicons'] as $v)
1259
	{
1260
		echo '
1261
			<tr class="', $alt ? 'windowbg2' : 'windowbg', '">
1262
				<td>';
1263
1264
		foreach ($v as $i)
1265
		{
1266
			echo '
1267
					<img src="', $i ? $context['onimg'] : $context['offimg'], '" alt="" style="padding: 2px;">';
1268
		}
1269
		echo '
1270
				</td>
1271
			</tr>';
1272
1273
		$alt = !$alt;
1274
	}
1275
1276
	echo '
1277
		</table>';
1278
}
1279
1280
?>