From 117541049ca0a09a13a40fc0a5e686e334334fae Mon Sep 17 00:00:00 2001 From: Blackeye <> Date: Sun, 11 Aug 2024 14:52:16 +0200 Subject: [PATCH] modularization date_int --- lib/functions.php | 33 +++++++++++++++++++++++++ script.php | 62 ++--------------------------------------------- 2 files changed, 35 insertions(+), 60 deletions(-) diff --git a/lib/functions.php b/lib/functions.php index b053aaa..fd0fe2c 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -1843,3 +1843,36 @@ function jirafeau_get_expiration_time_options() { echo ''; } + function jirafeau_datestr_to_int ($time_str) { + $time = time(); + switch ($time_str) { + case 'minute': + $time += JIRAFEAU_MINUTE; + break; + case 'hour': + $time += JIRAFEAU_HOUR; + break; + case 'day': + $time += JIRAFEAU_DAY; + break; + case 'week': + $time += JIRAFEAU_WEEK; + break; + case 'fortnight': + $time += JIRAFEAU_FORTNIGHT; + break; + case 'month': + $time += JIRAFEAU_MONTH; + break; + case 'quarter': + $time += JIRAFEAU_QUARTER; + break; + case 'year': + $time += JIRAFEAU_YEAR; + break; + default: + $time = JIRAFEAU_INFINITY; + break; + } + return $time; +} diff --git a/script.php b/script.php index be29f3d..fce2b83 100644 --- a/script.php +++ b/script.php @@ -92,40 +92,11 @@ if (isset($_FILES['file']) && is_writable(VAR_FILES) exit; } - $time = time(); if (!isset($_POST['time']) || !$cfg['availabilities'][$_POST['time']]) { echo 'Error 4: The parameter time is invalid.'; exit; } else { - switch ($_POST['time']) { - case 'minute': - $time += JIRAFEAU_MINUTE; - break; - case 'hour': - $time += JIRAFEAU_HOUR; - break; - case 'day': - $time += JIRAFEAU_DAY; - break; - case 'week': - $time += JIRAFEAU_WEEK; - break; - case 'fortnight': - $time += JIRAFEAU_FORTNIGHT; - break; - case 'month': - $time += JIRAFEAU_MONTH; - break; - case 'quarter': - $time += JIRAFEAU_QUARTER; - break; - case 'year': - $time += JIRAFEAU_YEAR; - break; - default: - $time = JIRAFEAU_INFINITY; - break; - } + $time = jirafeau_datestr_to_int($_POST['time']); } // Check file size @@ -468,40 +439,11 @@ elseif (isset($_GET['init_async'])) { exit; } - $time = time(); if (!isset($_POST['time']) || !$cfg['availabilities'][$_POST['time']]) { echo 'Error 22'; exit; } else { - switch ($_POST['time']) { - case 'minute': - $time += JIRAFEAU_MINUTE; - break; - case 'hour': - $time += JIRAFEAU_HOUR; - break; - case 'day': - $time += JIRAFEAU_DAY; - break; - case 'week': - $time += JIRAFEAU_WEEK; - break; - case 'fortnight': - $time += JIRAFEAU_FORTNIGHT; - break; - case 'month': - $time += JIRAFEAU_MONTH; - break; - case 'quarter': - $time += JIRAFEAU_QUARTER; - break; - case 'year': - $time += JIRAFEAU_YEAR; - break; - default: - $time = JIRAFEAU_INFINITY; - break; - } + $time = jirafeau_datestr_to_int($_POST['time']); } if ($cfg['store_uploader_ip']) { -- 2.34.1