From 5bcba0b6896b5278492894a7b0a11ce71b429aa1 Mon Sep 17 00:00:00 2001 From: David Bailey Date: Thu, 19 Oct 2023 21:54:37 +0200 Subject: [PATCH] refactor: move all HTTP-Website code into www subdirectory --- .htaccess | 6 --- www/.gitignore | 1 + www/.htaccess | 7 ++- composer.json => www/composer.json | 0 composer.lock => www/composer.lock | 0 www/dergstyle.css | 42 ------------------ www/index.php | 11 ----- router.php => www/router.php | 33 +++++++++++--- {static => www/static}/.htaccess | 0 {static => www/static}/banner.js | 0 {static => www/static}/banner/0.png | Bin {static => www/static}/banner/1.png | Bin {static => www/static}/banner/banner0.jpeg | Bin {static => www/static}/dergstyle.css | 0 {static => www/static}/gallerystyle.css | 0 {static => www/static}/icon.jpeg | Bin {static => www/static}/rrrorstyle.css | 0 {templates => www/templates}/about.html | 0 .../templates}/gallery/gallery_entry.html | 0 .../templates}/gallery/gallery_overview.html | 0 {templates => www/templates}/index.html | 0 {templates => www/templates}/root.dergplate | 0 {templates => www/templates}/root.html | 0 {templates => www/templates}/rrror.html | 0 {user_content => www/user_content}/about.md | 0 25 files changed, 33 insertions(+), 67 deletions(-) delete mode 100644 .htaccess create mode 100644 www/.gitignore rename composer.json => www/composer.json (100%) rename composer.lock => www/composer.lock (100%) delete mode 100644 www/dergstyle.css delete mode 100644 www/index.php rename router.php => www/router.php (66%) rename {static => www/static}/.htaccess (100%) rename {static => www/static}/banner.js (100%) rename {static => www/static}/banner/0.png (100%) rename {static => www/static}/banner/1.png (100%) rename {static => www/static}/banner/banner0.jpeg (100%) rename {static => www/static}/dergstyle.css (100%) rename {static => www/static}/gallerystyle.css (100%) rename {static => www/static}/icon.jpeg (100%) rename {static => www/static}/rrrorstyle.css (100%) rename {templates => www/templates}/about.html (100%) rename {templates => www/templates}/gallery/gallery_entry.html (100%) rename {templates => www/templates}/gallery/gallery_overview.html (100%) rename {templates => www/templates}/index.html (100%) rename {templates => www/templates}/root.dergplate (100%) rename {templates => www/templates}/root.html (100%) rename {templates => www/templates}/rrror.html (100%) rename {user_content => www/user_content}/about.md (100%) diff --git a/.htaccess b/.htaccess deleted file mode 100644 index 094dd6c..0000000 --- a/.htaccess +++ /dev/null @@ -1,6 +0,0 @@ - -RewriteEngine On -RewriteBase / - -RewriteCond %{REQUEST_URI} !^/?static/.* -RewriteRule (.*) router.php diff --git a/www/.gitignore b/www/.gitignore new file mode 100644 index 0000000..a725465 --- /dev/null +++ b/www/.gitignore @@ -0,0 +1 @@ +vendor/ \ No newline at end of file diff --git a/www/.htaccess b/www/.htaccess index 605d2f4..094dd6c 100644 --- a/www/.htaccess +++ b/www/.htaccess @@ -1 +1,6 @@ -Allow from all + +RewriteEngine On +RewriteBase / + +RewriteCond %{REQUEST_URI} !^/?static/.* +RewriteRule (.*) router.php diff --git a/composer.json b/www/composer.json similarity index 100% rename from composer.json rename to www/composer.json diff --git a/composer.lock b/www/composer.lock similarity index 100% rename from composer.lock rename to www/composer.lock diff --git a/www/dergstyle.css b/www/dergstyle.css deleted file mode 100644 index 1c31397..0000000 --- a/www/dergstyle.css +++ /dev/null @@ -1,42 +0,0 @@ - -body { - color: #B0B0B0; - background: #302A3F; -} - -:link { - color: cyan; - font-style: italic; - text-decoration: none; - - transition: color 0.2s; -} -:link:hover { - color: lightblue; -} - -ul { - display: flex; - flex-direction: row; - justify-content: center; - - list-style-type: none; - margin-top: 1em; - padding: 0px; -} -ul li { - padding: 0em 0.3em 0em 0.3em; -} - -#big_title { - text-align: center; - font-size: 2.5em; - margin-bottom: 0.2em; -} -#title_separator { - height: 1.5px; - background-color: #ddd; - opacity: 0.5; - margin-left: 2em; - margin-right: 2em; -} diff --git a/www/index.php b/www/index.php deleted file mode 100644 index 6084dcf..0000000 --- a/www/index.php +++ /dev/null @@ -1,11 +0,0 @@ -render('index.html',[ - "a_variable" => "is very spicy. In a good way." -]); -?> diff --git a/router.php b/www/router.php similarity index 66% rename from router.php rename to www/router.php index 57a3318..7d76a83 100644 --- a/router.php +++ b/www/router.php @@ -3,16 +3,30 @@ require_once 'vendor/autoload.php'; -$sql = mysqli_connect('mysql', 'root', 'example', 'mysql'); +$sql = mysqli_connect('mysql', 'root', 'example', 'dragon_fire'); -if (!$sql) -{ - echo 'Connection failed
'; - echo 'Error number: ' . mysqli_connect_errno() . '
'; - echo 'Error message: ' . mysqli_connect_error() . '
'; - die(); +function get_post_by_path($path) { + global $sql; + + $qry = "SELECT * FROM posts WHERE post_path = ?"; + + $stmt = $sql->prepare($qry); + $stmt->bind_param("s", $path); + $stmt->execute(); + + // $result = $stmt->get_result(); + + return $stmt->get_result()->fetch_assoc(); } +//if (!$sql) +// { +// echo 'Connection failed
'; +// echo 'Error number: ' . mysqli_connect_errno() . '
'; +// echo 'Error message: ' . mysqli_connect_error() . '
'; +// die(); +// } + $loader = new \Twig\Loader\FilesystemLoader(['./templates', './user_content']); $twig = new \Twig\Environment($loader,['debug' => true]); @@ -32,6 +46,11 @@ $twig->addRuntimeLoader(new class implements RuntimeLoaderInterface { if($_SERVER['REQUEST_URI'] == '/') { echo $twig->render('root.html'); +} elseif(preg_match('/^\/api\/posts(.*)$/', $_SERVER['REQUEST_URI'], $match)) { + + header('Content-Type: application/json'); + echo json_encode(get_post_by_path($match[1])); + } elseif(preg_match('/^\/about(.html)?$/', $_SERVER['REQUEST_URI'])) { echo $twig->render('about.html'); } elseif(preg_match('/^\/gallery\/([^\?]+)/', $_SERVER['REQUEST_URI'])) { diff --git a/static/.htaccess b/www/static/.htaccess similarity index 100% rename from static/.htaccess rename to www/static/.htaccess diff --git a/static/banner.js b/www/static/banner.js similarity index 100% rename from static/banner.js rename to www/static/banner.js diff --git a/static/banner/0.png b/www/static/banner/0.png similarity index 100% rename from static/banner/0.png rename to www/static/banner/0.png diff --git a/static/banner/1.png b/www/static/banner/1.png similarity index 100% rename from static/banner/1.png rename to www/static/banner/1.png diff --git a/static/banner/banner0.jpeg b/www/static/banner/banner0.jpeg similarity index 100% rename from static/banner/banner0.jpeg rename to www/static/banner/banner0.jpeg diff --git a/static/dergstyle.css b/www/static/dergstyle.css similarity index 100% rename from static/dergstyle.css rename to www/static/dergstyle.css diff --git a/static/gallerystyle.css b/www/static/gallerystyle.css similarity index 100% rename from static/gallerystyle.css rename to www/static/gallerystyle.css diff --git a/static/icon.jpeg b/www/static/icon.jpeg similarity index 100% rename from static/icon.jpeg rename to www/static/icon.jpeg diff --git a/static/rrrorstyle.css b/www/static/rrrorstyle.css similarity index 100% rename from static/rrrorstyle.css rename to www/static/rrrorstyle.css diff --git a/templates/about.html b/www/templates/about.html similarity index 100% rename from templates/about.html rename to www/templates/about.html diff --git a/templates/gallery/gallery_entry.html b/www/templates/gallery/gallery_entry.html similarity index 100% rename from templates/gallery/gallery_entry.html rename to www/templates/gallery/gallery_entry.html diff --git a/templates/gallery/gallery_overview.html b/www/templates/gallery/gallery_overview.html similarity index 100% rename from templates/gallery/gallery_overview.html rename to www/templates/gallery/gallery_overview.html diff --git a/templates/index.html b/www/templates/index.html similarity index 100% rename from templates/index.html rename to www/templates/index.html diff --git a/templates/root.dergplate b/www/templates/root.dergplate similarity index 100% rename from templates/root.dergplate rename to www/templates/root.dergplate diff --git a/templates/root.html b/www/templates/root.html similarity index 100% rename from templates/root.html rename to www/templates/root.html diff --git a/templates/rrror.html b/www/templates/rrror.html similarity index 100% rename from templates/rrror.html rename to www/templates/rrror.html diff --git a/user_content/about.md b/www/user_content/about.md similarity index 100% rename from user_content/about.md rename to www/user_content/about.md