-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
69 lines (55 loc) · 2.06 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
require_once('init.php');
include 'templates/head.html';
$_OUTPUT['random'] = rand(1941,2010).'-'.str_pad(rand(1,12), 2, '0', STR_PAD_LEFT).'-'.str_pad(rand(1,28), 2, '0', STR_PAD_LEFT);
if (isset($_GET['date'])):
$_OUTPUT['date'] = $_GET['date'];
endif;
echo $twig -> render(file_get_contents('templates/form.html'), $_OUTPUT);
if (isset($_GET['date'])):
// Convert the input into a timestamp
$timestamp = strtotime($_GET['date']);
$_OUTPUT['date'] = date('l, F jS, Y', $timestamp);
//Loop through the songs
$_OUTPUT['song'] = array();
$_OUTPUT['songcount'] = 0;
foreach($_DATA['songs'] as $loopsong):
//Convert the date to a timestamp
$songdate = strtotime($loopsong['date']);
if ($songdate < $timestamp):
$_OUTPUT['song'] = $loopsong;
break;
endif;
$_OUTPUT['songcount']++;
endforeach;
if (empty($_OUTPUT['song'])):
echo $twig -> render(file_get_contents('templates/nosong.html'), $_OUTPUT);
else:
// Grab the current time as a timestamp
$now = time();
// Calculate the difference between then and now (in seconds)
$elapsed = $now - $timestamp;
// Convert the elapsed time into years
$lightyears = $elapsed/60/60/24/365;
// Calculate the distance in parsecs
$parsecs = $lightyears*0.306594845;
//Loop through the stars
$_OUTPUT['star'] = array();
$_OUTPUT['starcount'] = count($_DATA['stars']);
foreach ($_DATA['stars'] as $loopstar):
if (floatval($parsecs) > floatval($loopstar['distance'])):
$_OUTPUT['star'] = $loopstar;
break;
endif;
$_OUTPUT['starcount']--;
endforeach;
if (empty($_OUTPUT['star'])):
//Nothing matched.
echo $twig -> render(file_get_contents('templates/nostar.html'), $_OUTPUT);
else:
echo $twig -> render(file_get_contents('templates/result.html'), $_OUTPUT);
endif;
endif;
endif;
include 'templates/foot.html';
?>