From c70851504652267c95194a98756c6875271cdda7 Mon Sep 17 00:00:00 2001 From: Mathias Magnusson Date: Tue, 23 Sep 2025 00:07:35 +0200 Subject: Implement reviews --- .gitignore | 1 + README.md | 19 +++++++++++++ compose.yaml | 3 ++ include/layout.php | 14 ++++++++- include/sqlite.php | 19 +++++++++++++ nginx.conf | 3 +- public/index.php | 12 +------- public/kontakt.php | 10 ------- "public/omd\303\266men.php" | 32 --------------------- "public/omd\303\266men/edit.php" | 33 +++++++++++++++++++++ "public/omd\303\266men/index.php" | 60 +++++++++++++++++++++++++++++++++++++++ public/style.css | 6 ++-- 12 files changed, 155 insertions(+), 57 deletions(-) create mode 100644 .gitignore create mode 100644 include/sqlite.php delete mode 100644 "public/omd\303\266men.php" create mode 100644 "public/omd\303\266men/edit.php" create mode 100644 "public/omd\303\266men/index.php" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..82f0c3a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/data/ diff --git a/README.md b/README.md index bcb3b44..ceed5e5 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,22 @@ Optimize images: ```sh magick $x.jpg -interlace Plane -quality 80 inter-$x.jpg ``` + +Init database: +```sh +mkdir data +sqlite3 data/data.db +``` + +```sql +PRAGMA journal_mode=WAL; +create table reviews ( + name text not null, + content text not null +) strict; +``` + +```sh +chmod a+w data/ +chmod a+w data/data.db +``` diff --git a/compose.yaml b/compose.yaml index 6e78b8c..244a83c 100644 --- a/compose.yaml +++ b/compose.yaml @@ -7,6 +7,9 @@ services: volumes: - ./public:/var/www/trädgårdstomten/public:ro - ./include:/var/www/trädgårdstomten/include:ro + - ./data:/data:rw + - type: tmpfs + target: /tmp nginx: image: docker.io/nginx:1.27-alpine restart: unless-stopped diff --git a/include/layout.php b/include/layout.php index ba79595..7bc67d2 100644 --- a/include/layout.php +++ b/include/layout.php @@ -1,6 +1,6 @@ @@ -13,8 +13,20 @@ function layout(&$context): void { + +
+
+

Trädgårdstomten ✂️

+
+ +
"; }); } diff --git a/include/sqlite.php b/include/sqlite.php new file mode 100644 index 0000000..6759e36 --- /dev/null +++ b/include/sqlite.php @@ -0,0 +1,19 @@ +prepare($q); + foreach ($values as $key => $value) { + $stmt->bindValue(is_int($key) ? $key + 1 : $key, $value); + } + return $stmt->execute(); +} + +function lastRowId() { + global $db; + + return $db->lastInsertRowId(); +} diff --git a/nginx.conf b/nginx.conf index 7c34523..34be30d 100644 --- a/nginx.conf +++ b/nginx.conf @@ -5,9 +5,10 @@ server { } server { - listen 8009; + listen 8009 default_server; server_name xn--trdgrdstomten-cfbr.se; root /var/www/trädgårdstomten/public; + rewrite ^/([^/]+/)*[^.]+[^/]$ $http_x_forwarded_proto://$host$request_uri/ permanent; set_real_ip_from 127.0.0.1/8; gzip on; default_type "text/html"; diff --git a/public/index.php b/public/index.php index 8e6f565..0dd4d48 100644 --- a/public/index.php +++ b/public/index.php @@ -1,16 +1,6 @@ -
-
-

Trädgårdstomten ✂️

-
- -
-
+

Jag heter Lucas Magnusson, är 26 år gammal och har flera års yrkeserfarenhet och är även utbildad inom trädgård. Jag har alltid varit intresserad av allt som diff --git a/public/kontakt.php b/public/kontakt.php index a23e0c6..ed60c0d 100644 --- a/public/kontakt.php +++ b/public/kontakt.php @@ -1,14 +1,4 @@ -

-
-

Trädgårdstomten ✂️

-
- -

Kontakta mig gärna så hör jag av mig så fort jag kan!


diff --git "a/public/omd\303\266men.php" "b/public/omd\303\266men.php" deleted file mode 100644 index c4a912a..0000000 --- "a/public/omd\303\266men.php" +++ /dev/null @@ -1,32 +0,0 @@ - -
-
-

Trädgårdstomten ✂️

-
- -
-
-
-
- - -
- - -
- -
-
- -
diff --git "a/public/omd\303\266men/edit.php" "b/public/omd\303\266men/edit.php" new file mode 100644 index 0000000..00b2d3b --- /dev/null +++ "b/public/omd\303\266men/edit.php" @@ -0,0 +1,33 @@ +fetchArray(); + +if ($_SERVER["REQUEST_METHOD"] === "POST") { + $name = $_POST["name"]; + $content = $_POST["content"]; + + query("update reviews set name = ?, content = ? where rowid = ?", $name, $content, $rowid); + + header("HX-Redirect: /omd%c3%b6men/"); + exit; +} + +require "../../include/layout.php"; layout($_); +?> + +
+ + +
+ + +
+ +
diff --git "a/public/omd\303\266men/index.php" "b/public/omd\303\266men/index.php" new file mode 100644 index 0000000..53a9123 --- /dev/null +++ "b/public/omd\303\266men/index.php" @@ -0,0 +1,60 @@ +fetchArray()) { + $row["editable"] = isset($_SESSION["editable review"]) && $_SESSION["editable review"] === $row["rowid"]; + $row = (object) $row; + $reviews[] = $row; +} + +require "../../include/layout.php"; layout($_); +?> +
+
+
+ + +
+
+ + +
+ +

Du kommer kunna redigera ditt omdöme tills du stänger fliken

+
+
+ + + +
+

name) ?>:

+

content) ?>

+ editable) { ?> + + +
+ +
diff --git a/public/style.css b/public/style.css index 6f145db..c157f7d 100644 --- a/public/style.css +++ b/public/style.css @@ -1,3 +1,5 @@ +@import "https://www.nerdfonts.com/assets/css/webfont.css"; + * { margin: 0; box-sizing: border-box; @@ -62,7 +64,7 @@ main { margin-inline: auto; } -main article { +#about-text { padding-bottom: 4em; display: grid; gap: 2em; @@ -71,7 +73,7 @@ main article { } @media (min-width: 500px) { - main article { + #about-text { grid-template-columns: auto auto; grid-template-areas: "p1 img" "p2 p2" "p3 p3"; } -- cgit v1.2.3