diff --git a/.hta_404.php b/.hta_404.php index 9080657..9f9ebf2 100644 --- a/.hta_404.php +++ b/.hta_404.php @@ -1,77 +1,76 @@ prepare("SELECT * FROM `scc24` WHERE `slug` = :slug"); -// $stmt->bindParam(':slug', $slug, PDO::PARAM_STR); -// $stmt->execute(); -// return $stmt->fetch(PDO::FETCH_ASSOC); -// } +function fetchFromDatabase($slug, $pdo) { + $stmt = $pdo->prepare("SELECT * FROM `scc24` WHERE `slug` = :slug"); + $stmt->bindParam(':slug', $slug, PDO::PARAM_STR); + $stmt->execute(); + return $stmt->fetch(PDO::FETCH_ASSOC); +} -// function saveToCache($filePath, $content) { -// if (!file_put_contents($filePath, $content)) { -// error_log("Failed to write cache file: $filePath"); -// } -// } +function saveToCache($filePath, $content) { + if (!file_put_contents($filePath, $content)) { + error_log("Failed to write cache file: $filePath"); + } +} -// if (empty($slug)) { -// // echo "Slug not provided!"; -// // exit; -// } +if (empty($slug)) { + // echo "Slug not provided!"; + // exit; +} -// $fileName = $slug . ".html"; -// $filePath = __DIR__ . '/notice/' . $fileName; +$fileName = $slug . ".html"; +$filePath = __DIR__ . '/notice/' . $fileName; -// ob_start(); +ob_start(); -// $shouldCache = false; // Flag to determine if content should be cached. +$shouldCache = false; // Flag to determine if content should be cached. -// if (!serveStaticFile($filePath)) { -// try { -// $pdo = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass); -// $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); -// $content = fetchFromDatabase($slug, $pdo); -// if ($content && isset($content['content']) && $content['content']) { -// echo '
-//
-//

' . htmlspecialchars($content['title']) . '

-//
-//
' . $content['content'] . '
-//
'; -// $shouldCache = true; // Mark content as cacheable. -// } else { -// echo '

Page not found (404).

-// Back to home -//
'; -// } -// } catch (PDOException $e) { -// echo "

Error: " . htmlspecialchars($e->getMessage()) . "

"; -// } -// } +if (!serveStaticFile($filePath)) { + try { + $pdo = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass); + $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $content = fetchFromDatabase($slug, $pdo); + if ($content && isset($content['content']) && $content['content']) { + echo '
+
+

' . htmlspecialchars($content['title']) . '

+
+
' . $content['content'] . '
+
'; + $shouldCache = true; // Mark content as cacheable. + } else { + echo '

Page not found (404).

+ Back to home +
'; + } + } catch (PDOException $e) { + echo "

Error: " . htmlspecialchars($e->getMessage()) . "

"; + } +} -// $htmlContent = ob_get_clean(); +$htmlContent = ob_get_clean(); -// // Save to cache only if content was found. -// if ($shouldCache) { -// saveToCache($filePath, $htmlContent); -// } +// Save to cache only if content was found. +if ($shouldCache) { + saveToCache($filePath, $htmlContent); +} -// echo $htmlContent; -?> -

404 New

\ No newline at end of file +echo $htmlContent; +?> \ No newline at end of file