forked from PacaHat/Anipaca
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrouter.php
More file actions
78 lines (65 loc) · 2.57 KB
/
router.php
File metadata and controls
78 lines (65 loc) · 2.57 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
// Include the global configuration file
require_once($_SERVER['DOCUMENT_ROOT'] . '/_config.php');
ini_set('display_errors', 1);
error_reporting(E_ALL);
// Get the URI without query strings
$uri = strtok(trim($_SERVER['REQUEST_URI'], '/'), '?');
// Define routes with regex patterns and associated files
$routes = [
// Main Pages
'/^home$/' => 'home.php',
'/^filter$/' => 'filter.php',
'/^search$/' => 'search.php',
'/^az-list(?:\/[a-zA-Z0-9-]+)?$/' => 'src/pages/anime/az-list.php',
// Anime Pages
'/^details$/' => 'src/pages/anime/details.php',
'/^random$/' => 'src/component/anime/random.php',
'/^anime$/' => 'src/pages/anime/anime.php',
'/^details\/([a-zA-Z0-9\-]+)$/' => 'src/pages/anime/details.php',
'/^anime\/([a-zA-Z0-9\-]+)$/' => 'src/pages/anime/anime.php',
'/^watch\/([a-zA-Z0-9\-]+)$/' => 'src/pages/anime/watch.php',
'/^genre\/([a-zA-Z0-9\-]+)$/' => 'src/pages/anime/genre.php',
'/^producer\/([a-zA-Z0-9\-\.]+)\/?$/' => 'src/pages/anime/producer.php',
'/^actors\/([a-zA-Z0-9\-]+)$/' => 'src/pages/anime/actors.php',
'/^character\/([a-zA-Z0-9\-]+)\/?$/' => 'src/pages/anime/character.php',
// User Pages
'/^login$/' => 'src/user/login.php',
'/^register$/' => 'src/user/register.php',
'/^logout$/' => 'src/user/logout.php',
'/^profile$/' => 'src/user/profile.php',
'/^watchlist$/' => 'src/user/watchlist.php',
'/^watchlist\.php(?:\?.*)?$/' => 'src/user/watchlist.php',
'/^changepass$/' => 'src/user/changepass.php',
'/^continue-watching$/' => 'src/user/continue-watching.php',
// Extra Pages
'/^dmca$/' => 'src/pages/extra/dmca.php',
'/^terms$/' => 'src/pages/extra/terms.php',
// Sitemap Routes
'/^sitemaps\/popular\.xml$/' => 'public/sitemap/sitemappopular.xml',
'/^sitemaps\/movie\.xml$/' => 'public/sitemap/sitemapmovie.xml',
'/^sitemaps\/airing\.xml$/' => 'public/sitemap/sitemapairing.xml',
'/^sitemaps\/ongoing-sitemap\.xml$/' => 'public/sitemap/sitemapongoing.xml',
'/^sitemaps\/allanime-sitemap\.xml$/' => 'public/sitemap/sitemapallanime.xml',
'/^sitemaps\/sitemap\.xml$/' => 'public/sitemap/sitemap.php',
'/^sitemap\.xml$/' => 'public/sitemap/sitemap.php',
];
// Route matching
$handled = false;
foreach ($routes as $pattern => $file) {
if (preg_match($pattern, $uri, $matches)) {
// Pass captured groups as GET parameters
if (!empty($matches[1])) {
$_GET['slug'] = $matches[1];
}
include $file;
$handled = true;
break;
}
}
// Fallback to 404 if no route matches
if (!$handled) {
http_response_code(404);
include '404.php';
}
?>