-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrouter.php
More file actions
64 lines (56 loc) · 2.04 KB
/
Copy pathrouter.php
File metadata and controls
64 lines (56 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
* Router for PHP built-in webserver
* Usage: php -S localhost:8080 router.php
*/
$uri = urldecode(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
// Allow direct access to PHP test files
if (preg_match('/\.php$/i', $uri) && $uri !== '/index.php' && file_exists(__DIR__ . $uri)) {
require __DIR__ . $uri;
return true;
}
// Allow access to theme assets and cache images
if (preg_match('/\.(css|js|jpg|jpeg|png|gif|svg|ico|woff|woff2|ttf|eot)$/i', $uri)) {
// Handle cache images with automatic download
if (strpos($uri, '/cache/') === 0) {
$config = require __DIR__ . '/setup.php';
require_once __DIR__ . '/src/Core/ImageCache.php';
$imageCache = new \Hackorama\Core\ImageCache($config);
if ($imageCache->serveImage($uri)) {
return true;
}
// If image cache fails, try local file
$filePath = __DIR__ . '/public' . $uri;
}
// Then check if it's a theme file with full path
elseif (strpos($uri, '/themes/') === 0) {
$filePath = __DIR__ . $uri;
} else {
// Otherwise check in theme directory
$filePath = __DIR__ . '/themes/Alaska2' . $uri;
}
if (isset($filePath) && file_exists($filePath)) {
$mimeTypes = [
'css' => 'text/css',
'js' => 'application/javascript',
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'png' => 'image/png',
'gif' => 'image/gif',
'svg' => 'image/svg+xml',
'ico' => 'image/x-icon',
'woff' => 'application/font-woff',
'woff2' => 'application/font-woff2',
'ttf' => 'application/x-font-ttf',
'eot' => 'application/vnd.ms-fontobject',
];
$ext = strtolower(pathinfo($uri, PATHINFO_EXTENSION));
if (isset($mimeTypes[$ext])) {
header('Content-Type: ' . $mimeTypes[$ext]);
}
readfile($filePath);
return true;
}
}
// All other requests go to index.php
require __DIR__ . '/index.php';