Browse Source

Enable subfolder support, add str_ends_with function, and remove unused code

poesty 1 year ago
parent
commit
e7264929b8
2 changed files with 11 additions and 16 deletions
  1. 3 0
      .htaccess
  2. 8 16
      utilities/link.php

+ 3 - 0
.htaccess

@@ -0,0 +1,3 @@
+RewriteEngine on
+RewriteCond %{REQUEST_URI} !^/Tent/pages/
+RewriteRule ^(.*)$ /Tent/pages/$1 [L]

+ 8 - 16
utilities/link.php

@@ -1,20 +1,12 @@
 <?php
   function convert_link($link) {
-    if (isset($_SERVER["REQUEST_SCHEME"]))
-      $scheme = $_SERVER["REQUEST_SCHEME"];
-    elseif (isset($_SERVER["HTTPS"]))
-      $scheme = "https";
-    else
-      $scheme = "http";
-
-    $host = $_SERVER["HTTP_HOST"];
-    $uri = $_SERVER["REQUEST_URI"];
-
-    $base = $scheme . "://" . $host . preg_replace("/\/.*.php/", "/", strtok($uri, "?"));
-
-    unset($scheme);
-    unset($host);
-    unset($uri);
+    if (! function_exists('str_ends_with')) {
+        function str_ends_with(string $haystack, string $needle): bool
+        {
+            $needle_len = strlen($needle);
+            return ($needle_len === 0 || 0 === substr_compare($haystack, $needle, - $needle_len));
+        }
+    }
 
     $host = parse_url($link, PHP_URL_HOST);
     $path = ltrim(parse_url($link, PHP_URL_PATH), "/");
@@ -53,7 +45,7 @@
     } else
       return $link;
 
-    return $base . $file . ".php?" . http_build_query($data);
+    return $file . ".php?" . http_build_query($data);
   };
 
   function prefix_link($link, $parameter) {