Explorar o código

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

poesty hai 1 ano
pai
achega
e7264929b8
Modificáronse 2 ficheiros con 11 adicións e 16 borrados
  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
 <?php
   function convert_link($link) {
   function convert_link($link) {
-    if (isset($_SERVER["REQUEST_SCHEME"]))
+    if (! function_exists('str_ends_with')) {
-      $scheme = $_SERVER["REQUEST_SCHEME"];
+        function str_ends_with(string $haystack, string $needle): bool
-    elseif (isset($_SERVER["HTTPS"]))
+        {
-      $scheme = "https";
+            $needle_len = strlen($needle);
-    else
+            return ($needle_len === 0 || 0 === substr_compare($haystack, $needle, - $needle_len));
-      $scheme = "http";
+        }
-
+    }
-    $host = $_SERVER["HTTP_HOST"];
-    $uri = $_SERVER["REQUEST_URI"];
-
-    $base = $scheme . "://" . $host . preg_replace("/\/.*.php/", "/", strtok($uri, "?"));
-
-    unset($scheme);
-    unset($host);
-    unset($uri);
 
 
     $host = parse_url($link, PHP_URL_HOST);
     $host = parse_url($link, PHP_URL_HOST);
     $path = ltrim(parse_url($link, PHP_URL_PATH), "/");
     $path = ltrim(parse_url($link, PHP_URL_PATH), "/");
@@ -53,7 +45,7 @@
     } else
     } else
       return $link;
       return $link;
 
 
-    return $base . $file . ".php?" . http_build_query($data);
+    return $file . ".php?" . http_build_query($data);
   };
   };
 
 
   function prefix_link($link, $parameter) {
   function prefix_link($link, $parameter) {