···
const COOKIE_LIFETIME = 60 * 60 * 24 * 365; // 1 year
4
-
const SITE_URL = 'https://tz.rita.moe';
4
+
const SITE_BASE = 'https://tz.rita.moe'; // Base URL of the site, no trailing slash
$nonce = bin2hex(random_bytes(16));
···
if (isset($_POST['datetime']) && isset($_POST['timezone'])) {
61
-
// -- Redirect to submitted date
62
-
$postTZ = $_POST['timezone'];
61
+
// -- Redirect to submitted date
62
+
// @NOTE(Kody): I'm fine not validating all inputs here.
63
+
// Either it will fall in the catch block, or fail at the validation after the redirect.
64
-
// Handle if timezone is an offset
65
-
if (is_numeric($_POST['timezone'])) {
66
-
$isNeg = str_starts_with($postTZ, '-');
67
-
$h = str_pad(abs(intdiv($postTZ, 60)), 2, '0', STR_PAD_LEFT);
68
-
$m = str_pad($postTZ % 60, 2, '0', STR_PAD_LEFT);
69
-
$postTZ = ($isNeg ? '-' : '+') . $h . $m;
65
+
// Handle if timezone is an offset
66
+
$postTZ = $_POST['timezone'];
67
+
if (is_numeric($_POST['timezone'])) {
68
+
$isNeg = str_starts_with($postTZ, '-');
69
+
$h = str_pad(abs(intdiv($postTZ, 60)), 2, '0', STR_PAD_LEFT);
70
+
$m = str_pad($postTZ % 60, 2, '0', STR_PAD_LEFT);
71
+
$postTZ = ($isNeg ? '-' : '+') . $h . $m;
72
-
// Make our date object
73
-
$dateObj = new DateTime($_POST['datetime'], new DateTimeZone($postTZ));
74
+
// Make our date object
75
+
$dateObj = new DateTime($_POST['datetime'], new DateTimeZone($postTZ));
75
-
// Redirect, with the "+" replaced by "_"
76
-
header('Location: /' . str_replace('+', '_', $dateObj->format('c')));
77
+
// Redirect, with the "+" replaced by "_"
78
+
header('Location: /' . str_replace('+', '_', $dateObj->format('c')));
} elseif ($_SERVER['REQUEST_URI'] !== '/') {
81
+
// -- Show date infos
$req = substr($_SERVER['REQUEST_URI'], 1);
82
-
// -- Show date infos
83
-
// First check if date is following the format
85
+
// Check if date is following the format
$re = '/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[\_|-]\d{2}:\d{2}$/';
if (!preg_match($re, $req)) {
···
95
-
$error = 'Invalid date format or date out of range.';
97
+
$error = 'Date is not valid, or wrong format.';
···
195
-
<input type="hidden" id="url" value="<?= htmlspecialchars(SITE_URL . $_SERVER['REQUEST_URI'], ENT_QUOTES, 'UTF-8') ?>"/>
197
+
<input type="hidden" id="url" value="<?= htmlspecialchars(SITE_BASE . $_SERVER['REQUEST_URI'], ENT_QUOTES, 'UTF-8') ?>"/>
<script nonce="<?= $nonce ?>">
···
if (navigator.canShare) {
// Use native navigator share
226
-
url: '<?= htmlspecialchars(SITE_URL . $_SERVER['REQUEST_URI'], ENT_QUOTES, 'UTF-8') ?>'
228
+
url: '<?= htmlspecialchars(SITE_BASE . $_SERVER['REQUEST_URI'], ENT_QUOTES, 'UTF-8') ?>'
} else if (navigator.clipboard) {
230
-
navigator.clipboard.writeText('<?= htmlspecialchars(SITE_URL . $_SERVER['REQUEST_URI'], ENT_QUOTES, 'UTF-8') ?>')
232
+
navigator.clipboard.writeText('<?= htmlspecialchars(SITE_BASE . $_SERVER['REQUEST_URI'], ENT_QUOTES, 'UTF-8') ?>')
alert('URL copied to clipboard!')