t
This commit is contained in:
74
.hta_404.php
74
.hta_404.php
@@ -1,41 +1,61 @@
|
||||
<?php
|
||||
require('.hta_config/env.php');
|
||||
require('./.hta_header.php');
|
||||
|
||||
$headerContent = file_get_contents('./.hta_header.php');
|
||||
|
||||
$requestUri = $_SERVER['REQUEST_URI'];
|
||||
// echo $requestUri;
|
||||
|
||||
$urlParts = explode('/', $requestUri);
|
||||
|
||||
if($urlParts[1] === 'notice'){
|
||||
|
||||
if ($urlParts[1] === 'notice') {
|
||||
$slug = $urlParts[2];
|
||||
} else{
|
||||
} else {
|
||||
$slug = $urlParts[1];
|
||||
}
|
||||
|
||||
$querySlug = explode('.', $slug)[0];
|
||||
// echo $querySlug;
|
||||
$fileName = $slug;
|
||||
|
||||
function saveHtmlFile($fileName, $headerContent, $pageContent){
|
||||
$footerContent = file_get_contents('./.hta_footer.php');
|
||||
$totalPageContent = $headerContent . $pageContent . $footerContent;
|
||||
$filePath = __DIR__ . '/' . $fileName;
|
||||
|
||||
if (file_put_contents($filePath, $totalPageContent)) {
|
||||
// echo "<p class='text-success'>Page saved successfully at $filePath.</p>";
|
||||
} else {
|
||||
// echo "<p class='text-danger'>Failed to save the page.</p>";
|
||||
}
|
||||
}
|
||||
|
||||
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 = $conn->prepare("SELECT * FROM `scc24` WHERE type='page' AND `slug` = :querySlug");
|
||||
$stmt->bindParam(':querySlug', $querySlug, PDO::PARAM_STR);
|
||||
$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>
|
||||
|
||||
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;">' . htmlspecialchars($content[0]['title']) . '</p>
|
||||
</div>
|
||||
<div class="">' . $content[0]['content'] . '</div>
|
||||
</div>';
|
||||
|
||||
// Call the function to save the HTML file
|
||||
saveHtmlFile($fileName, $headerContent, $pageContent);
|
||||
} 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>
|
||||
';
|
||||
</div>';
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$in_page_message = "<p class='text-danger'>Error: " . $e->getMessage() . "</p>";
|
||||
$pageContent = "<p class='text-danger'>Error: " . $e->getMessage() . "</p>";
|
||||
}
|
||||
|
||||
// Render page content here
|
||||
@@ -43,22 +63,6 @@
|
||||
|
||||
$footerContent = file_get_contents('./.hta_footer.php');
|
||||
|
||||
// if($fileExtension[1] && $fileExtension[1] === 'html'){
|
||||
// $filePath = __DIR__ . '/notice/' . $fileName;
|
||||
// } else{
|
||||
// $filePath = __DIR__ . '/notice/' . $fileName . '.html';
|
||||
// }
|
||||
// Function to save HTML file
|
||||
|
||||
|
||||
if($urlParts[1] === 'notice'){
|
||||
$filePath = __DIR__ . '/notice/' . $fileName;
|
||||
$totalPageContent = $headerContent . $pageContent . $footerContent;
|
||||
} else{
|
||||
$filePath = __DIR__ . '/.hta_slug/' . $fileName;
|
||||
$totalPageContent = $headerContent . $pageContent . $footerContent;
|
||||
}
|
||||
|
||||
|
||||
file_put_contents($filePath, $totalPageContent);
|
||||
|
||||
?>
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user