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