Advertisement
jargon

// Shared :: "Linedancer 2/Unix Compliance.php"

Nov 3rd, 2024
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.59 KB | Gaming | 0 0
  1. <?php
  2. // Shared :: "Linedancer 2/Unix Compliance.php"
  3.  
  4. function UnixPathTrim($path) {
  5.     $path = str_replace("\\", "/", $path);
  6.    
  7.     // Remove document root prefix if present
  8.     if (strpos($path, $_SERVER['DOCUMENT_ROOT']) === 0) {
  9.         $path = substr($path, strlen($_SERVER['DOCUMENT_ROOT']));
  10.     }
  11.    
  12.     return $path;
  13. }
  14.  
  15. function UnixPathSlashes($path) {
  16.     $path = UnixPathTrim($path);
  17.     $parts = explode("/", $path);
  18.     $normalizedPath = $_SERVER['DOCUMENT_ROOT'];
  19.  
  20.     foreach ($parts as $part) {
  21.         // Check if path is a directory
  22.         if (glob($normalizedPath, GLOB_ONLYDIR)) {
  23.             $normalizedPath .= "/{$part}";
  24.         } elseif (glob($normalizedPath)) {
  25.             $normalizedPath .= "/{$part}";
  26.             break;
  27.         }
  28.     }
  29.    
  30.     return $normalizedPath;
  31. }
  32.  
  33. function UnixPath($path) {
  34.     $path = UnixPathSlashes($path);
  35.     $path = UnixPathTrim($path);
  36.     $parts = explode("/", $path);
  37.     $normalizedPath = $_SERVER['DOCUMENT_ROOT'];
  38.  
  39.     foreach ($parts as $part) {
  40.         $caseInsensitivePart = "";
  41.  
  42.         // Generate case-insensitive pattern
  43.         for ($i = 0; $i < strlen($part); $i++) {
  44.             $char = $part[$i];
  45.             $caseInsensitivePart .= (strtolower($char) !== strtoupper($char)) ? "{" . strtolower($char) . "," . strtoupper($char) . "}" : $char;
  46.         }
  47.        
  48.         // Apply glob with case-insensitive pattern
  49.         $matchedDir = glob("{$normalizedPath}/{$caseInsensitivePart}", GLOB_ONLYDIR | GLOB_BRACE);
  50.         $matchedFile = glob("{$normalizedPath}/{$caseInsensitivePart}", GLOB_BRACE);
  51.  
  52.         if ($matchedDir) {
  53.             $normalizedPath .= "/{$part}";
  54.         } elseif ($matchedFile) {
  55.             $normalizedPath .= "/{$part}";
  56.             break;
  57.         }
  58.     }
  59.    
  60.     return $normalizedPath;
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement