]> git.p6c8.net - jirafeau_project.git/commitdiff
modularization date_int
authorBlackeye <>
Sun, 11 Aug 2024 12:52:16 +0000 (14:52 +0200)
committerBlackeye <>
Sun, 11 Aug 2024 12:52:16 +0000 (14:52 +0200)
lib/functions.php
script.php

index b053aaa55c7ed21a12c87fae315c6923c659bab8..fd0fe2c657957848c6e6251a18956379b45d2eeb 100644 (file)
@@ -1843,3 +1843,36 @@ function jirafeau_get_expiration_time_options() {
         echo '</select>';
  }
 
+ 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;
+}
index be29f3d015dcbdf65ab50bbbbd6114ff3b0de0ca..fce2b83afe1ad2d76aa2cf4a5f6f3636e2acbf14 100644 (file)
@@ -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']) {

patrick-canterino.de