Use REQUEST_URI for route matching
This will simplify the .htaccess/nginx config.
This commit is contained in:
30
index.php
30
index.php
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
$lang = empty($_GET['lang']) ? 'cs' : $_GET['lang'];
|
||||
$page = $_GET['page'] ?? '';
|
||||
preg_match('(^/krk/(?:(?P<lang>en|de)/)?(?P<page>.*?)(\.html)?$)', $_SERVER['REQUEST_URI'] ?? '', $match);
|
||||
$lang = empty($match['lang']) ? 'cs' : $match['lang'];
|
||||
$page = $match['page'] ?? '';
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
@@ -129,11 +130,12 @@ hs.lang = {
|
||||
<div class="content">
|
||||
<div class="header"><span class="title"><?php include './pages/title_krk.php'; ?></span><br><span class="slogan"><?php include './pages/slogan.php'; ?></span>
|
||||
<?php
|
||||
$pageFileName = preg_replace('(([^/]+)/$)', '\1/\1', $page);
|
||||
echo '<span class="floatright">';
|
||||
if (file_exists(__DIR__ . "/pages/$page-de.php") || file_exists(__DIR__ . "/pages/$page/$page-de.php")) {
|
||||
if (file_exists(__DIR__ . "/pages/$page/$page-de.php")) {
|
||||
if (file_exists(__DIR__ . "/pages/$page-de.php") || file_exists(__DIR__ . "/pages/$pageFileName-de.php")) {
|
||||
if (file_exists(__DIR__ . "/pages/$pageFileName-de.php")) {
|
||||
$lngc = 'de';
|
||||
$icona = "<a href=\"/krk/$lngc/$page/$page.html\"><img src=\"/images/" . $lngc . 'f.png" alt=""></a>';
|
||||
$icona = "<a href=\"/krk/$lngc/$page\"><img src=\"/images/" . $lngc . 'f.png" alt=""></a>';
|
||||
} else {
|
||||
$lngc = 'de';
|
||||
$icona = "<a href=\"/krk/$lngc/" . htmlspecialchars($page) . '.html"><img src="/images/' . $lngc . 'f.png" alt=""></a>';
|
||||
@@ -145,10 +147,10 @@ if (file_exists(__DIR__ . "/pages/$page-de.php") || file_exists(__DIR__ . "/page
|
||||
echo $icona;
|
||||
}
|
||||
}
|
||||
if (file_exists('pages/' . htmlspecialchars($page) . '-en.php') || file_exists('pages/' . htmlspecialchars($page) . '/' . htmlspecialchars($page) . '-en.php')) {
|
||||
if (file_exists('pages/' . htmlspecialchars($page) . '/' . htmlspecialchars($page) . '-en.php')) {
|
||||
if (file_exists('pages/' . htmlspecialchars($page) . '-en.php') || file_exists('pages/' . $pageFileName . '-en.php')) {
|
||||
if (file_exists('pages/' . $pageFileName . '-en.php')) {
|
||||
$lngc = 'en';
|
||||
$icona = "<a href=\"/krk/$lngc/" . htmlspecialchars($page) . '/' . htmlspecialchars($page) . '.html"><img src="/images/' . $lngc . 'f.png" alt=""></a>';
|
||||
$icona = "<a href=\"/krk/$lngc/" . htmlspecialchars($page) . '"><img src="/images/' . $lngc . 'f.png" alt=""></a>';
|
||||
} else {
|
||||
$lngc = 'en';
|
||||
$icona = "<a href=\"/krk/$lngc/" . htmlspecialchars($page) . '.html"><img src="/images/' . $lngc . 'f.png" alt=""></a>';
|
||||
@@ -167,10 +169,10 @@ if (file_exists('pages/' . htmlspecialchars($page) . '-en.php') || file_exists('
|
||||
echo $icona;
|
||||
}
|
||||
}
|
||||
if (file_exists('pages/' . htmlspecialchars($page) . '.php') || file_exists('pages/' . htmlspecialchars($page) . '/' . htmlspecialchars($page) . '.php')) {
|
||||
if (file_exists('pages/' . htmlspecialchars($page) . '/' . htmlspecialchars($page) . '.php')) {
|
||||
if (file_exists('pages/' . htmlspecialchars($page) . '.php') || file_exists('pages/' . $pageFileName . '.php')) {
|
||||
if (file_exists('pages/' . $pageFileName . '.php')) {
|
||||
$lngc = '';
|
||||
$icona = '<a href="/krk/' . htmlspecialchars($page) . '/' . htmlspecialchars($page) . '.html"><img src="/images/' . $lngc . 'f.png" alt=""></a>';
|
||||
$icona = '<a href="/krk/' . htmlspecialchars($page) . '"><img src="/images/' . $lngc . 'f.png" alt=""></a>';
|
||||
} else {
|
||||
$lngc = '';
|
||||
$icona = '<a href="/krk/' . htmlspecialchars($page) . '.html"><img src="/images/' . $lngc . 'f.png" alt=""></a>';
|
||||
@@ -226,11 +228,11 @@ if ($page !== '') {
|
||||
} else {
|
||||
$jazycek = '';
|
||||
}
|
||||
if ($page == 'mcr_2009') {
|
||||
if ($page == 'mcr_2009/') {
|
||||
include "./pages/mcr_2009/mcr_2009$jazycek.php";
|
||||
} elseif ($page == 'mcr_2009/probihani_loucna') {
|
||||
} elseif ($page == 'mcr_2009/probihani_loucna/') {
|
||||
include "./pages/mcr_2009/probihani_loucna/probihani_loucna$jazycek.php";
|
||||
} elseif ($page == 'clanky') {
|
||||
} elseif ($page == 'clanky/') {
|
||||
include "./pages/clanky/clanky$jazycek.php";
|
||||
} elseif ($lang === 'cs' && file_exists(__DIR__ . "/pages/$escaped_page.php")) {
|
||||
include "./pages/$escaped_page.php";
|
||||
|
||||
Reference in New Issue
Block a user