pull/7/head
dev2 siliconpin 2024-12-16 08:50:41 +00:00
parent ff87ffd713
commit 7efb5727c3
1 changed files with 61 additions and 62 deletions

View File

@ -1,77 +1,76 @@
<?php <?php
require('.hta_config/env.php'); require('.hta_config/env.php');
// $requestUri = $_SERVER['REQUEST_URI']; $requestUri = $_SERVER['REQUEST_URI'];
// $slug = getSlug($requestUri); $slug = getSlug($requestUri);
// function getSlug($requestUri) { function getSlug($requestUri) {
// $parts = explode('/', $requestUri); $parts = explode('/', $requestUri);
// return isset($parts[2]) ? $parts[2] : ''; return isset($parts[2]) ? $parts[2] : '';
// } }
// function serveStaticFile($filePath) { function serveStaticFile($filePath) {
// if (file_exists($filePath)) { if (file_exists($filePath)) {
// echo file_get_contents($filePath); echo file_get_contents($filePath);
// return true; return true;
// } }
// return false; return false;
// } }
// function fetchFromDatabase($slug, $pdo) { function fetchFromDatabase($slug, $pdo) {
// $stmt = $pdo->prepare("SELECT * FROM `scc24` WHERE `slug` = :slug"); $stmt = $pdo->prepare("SELECT * FROM `scc24` WHERE `slug` = :slug");
// $stmt->bindParam(':slug', $slug, PDO::PARAM_STR); $stmt->bindParam(':slug', $slug, PDO::PARAM_STR);
// $stmt->execute(); $stmt->execute();
// return $stmt->fetch(PDO::FETCH_ASSOC); return $stmt->fetch(PDO::FETCH_ASSOC);
// } }
// function saveToCache($filePath, $content) { function saveToCache($filePath, $content) {
// if (!file_put_contents($filePath, $content)) { if (!file_put_contents($filePath, $content)) {
// error_log("Failed to write cache file: $filePath"); error_log("Failed to write cache file: $filePath");
// } }
// } }
// if (empty($slug)) { if (empty($slug)) {
// // echo "Slug not provided!"; // echo "Slug not provided!";
// // exit; // exit;
// } }
// $fileName = $slug . ".html"; $fileName = $slug . ".html";
// $filePath = __DIR__ . '/notice/' . $fileName; $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)) { if (!serveStaticFile($filePath)) {
// try { try {
// $pdo = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass); $pdo = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
// $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// $content = fetchFromDatabase($slug, $pdo); $content = fetchFromDatabase($slug, $pdo);
// if ($content && isset($content['content']) && $content['content']) { if ($content && isset($content['content']) && $content['content']) {
// echo '<div class="container mx-auto"> echo '<div class="container mx-auto">
// <div style="padding-top:20px; padding-bottom:15px; font-size:25px;"> <div style="padding-top:20px; padding-bottom:15px; font-size:25px;">
// <p style="text-align: center;">' . htmlspecialchars($content['title']) . '</p> <p style="text-align: center;">' . htmlspecialchars($content['title']) . '</p>
// </div> </div>
// <div>' . $content['content'] . '</div> <div>' . $content['content'] . '</div>
// </div>'; </div>';
// $shouldCache = true; // Mark content as cacheable. $shouldCache = true; // Mark content as cacheable.
// } else { } else {
// echo '<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> echo '<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> <a href="/">Back to home</a>
// </div>'; </div>';
// } }
// } catch (PDOException $e) { } catch (PDOException $e) {
// echo "<p class='text-danger'>Error: " . htmlspecialchars($e->getMessage()) . "</p>"; echo "<p class='text-danger'>Error: " . htmlspecialchars($e->getMessage()) . "</p>";
// } }
// } }
// $htmlContent = ob_get_clean(); $htmlContent = ob_get_clean();
// // Save to cache only if content was found. // Save to cache only if content was found.
// if ($shouldCache) { if ($shouldCache) {
// saveToCache($filePath, $htmlContent); saveToCache($filePath, $htmlContent);
// } }
// echo $htmlContent; echo $htmlContent;
?> ?>
<h2>404 New</h2>