64 lines
2.3 KiB
PHP
64 lines
2.3 KiB
PHP
<?php
|
|
require('.hta_config/env.php');
|
|
require('./.hta_header.php');
|
|
|
|
// echo 'Notice 404+1';
|
|
|
|
$headerContent = file_get_contents('./.hta_header.php');
|
|
$requestUri = $_SERVER['REQUEST_URI'];
|
|
// echo $requestUri;
|
|
|
|
$urlParts = explode('/', $requestUri);
|
|
|
|
if($urlParts[1] === 'notice'){
|
|
$slug = $urlParts[2];
|
|
} else{
|
|
$slug = $urlParts[1];
|
|
}
|
|
|
|
$querySlug = explode('.', $slug)[0];
|
|
// echo $slug;
|
|
$fileName = $slug;
|
|
|
|
try {
|
|
$conn = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
|
|
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
$stmt = $conn->prepare("SELECT * FROM `scc24` WHERE `slug` = '".$querySlug."'");
|
|
$stmt->execute();
|
|
$content = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
if(isset($content[0]['content']) && $content[0]['content'])
|
|
$pageContent = '<div class="container mx-auto" style="">
|
|
<div class="" style="padding-top:20px; padding-bottom:15px; font-size:25px;"><p style="text-align: center;">'.$content[0]['title'].'</p></div>
|
|
<div class="">'.$content[0]['content'].'</div>
|
|
</div>';
|
|
else $pageContent = '
|
|
<div style="display: flex; flex-direction: column; align-items: center; justify-content: center; margin: 100px 0;"><p style="text-align: center; font-size: 30px; font-weight: bold;">Page not found (404).</p>
|
|
<a href="/">Back to home</a>
|
|
</div>
|
|
';
|
|
} catch (PDOException $e) {
|
|
$in_page_message = "<p class='text-danger'>Error: " . $e->getMessage() . "</p>";
|
|
}
|
|
|
|
// Render page content here
|
|
echo $pageContent;
|
|
|
|
$footerContent = file_get_contents('./.hta_footer.php');
|
|
// if($fileExtension[1] && $fileExtension[1] === 'html'){
|
|
// $filePath = __DIR__ . '/notice/' . $fileName;
|
|
// } else{
|
|
// $filePath = __DIR__ . '/notice/' . $fileName . '.html';
|
|
// }
|
|
if($urlParts[1] === 'notice'){
|
|
$filePath = __DIR__ . '/' . $fileName;
|
|
// echo $filePath;
|
|
$totalPageContent = $headerContent . $pageContent . $footerContent;
|
|
} else{
|
|
$filePath = __DIR__ . $fileName;
|
|
$totalPageContent = $headerContent . $pageContent . $footerContent;
|
|
}
|
|
|
|
|
|
file_put_contents($filePath, $totalPageContent);
|
|
|
|
?>
|