From 8a13a1758cb9b1610da19c574107655553ac5c36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Fra=C3=9F?= Date: Wed, 21 May 2025 06:05:12 +0000 Subject: [PATCH] =?UTF-8?q?[mod]=20grundlegende=20Funktionalit=C3=A4t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + source/helpers.php | 70 ++++++++++++ source/index.html.php | 102 +++++++++++++++++ source/logic.php | 129 ++++++++++++++++++++++ source/style.css | 72 ++++++++++++ source/templates/docs-edit.html.tpl | 26 +++++ source/templates/docs-list-entry.html.tpl | 3 + source/templates/docs-list.html.tpl | 6 + tools/build | 12 ++ tools/run | 3 + 10 files changed, 425 insertions(+) create mode 100644 .gitignore create mode 100644 source/helpers.php create mode 100644 source/index.html.php create mode 100644 source/logic.php create mode 100644 source/style.css create mode 100644 source/templates/docs-edit.html.tpl create mode 100644 source/templates/docs-list-entry.html.tpl create mode 100644 source/templates/docs-list.html.tpl create mode 100755 tools/build create mode 100755 tools/run diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ba98a06 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/.geany +/build/ diff --git a/source/helpers.php b/source/helpers.php new file mode 100644 index 0000000..e8086e4 --- /dev/null +++ b/source/helpers.php @@ -0,0 +1,70 @@ + $value) + { + $result = \str_replace(\sprintf('{{%s}}', $key), $value, $result); + } + return $result; +} + + +/** + */ +function render(string $template_name, array $arguments) : string +{ + return string_coin( + cache_get( + string_coin( + 'template.{{name}}', + [ + 'name' => $template_name, + ] + ), + fn() => \file_get_contents( + string_coin( + '{{directory}}/templates/{{name}}.html.tpl', + [ + 'directory' => __DIR__, + 'name' => $template_name, + ] + ) + ) + ), + $arguments + ); +} + + ?> diff --git a/source/index.html.php b/source/index.html.php new file mode 100644 index 0000000..f96639a --- /dev/null +++ b/source/index.html.php @@ -0,0 +1,102 @@ + + + + + + + + + \implode( + "\n", + \array_map( + fn ($entry) => \rosavox\helpers\render( + 'docs-list-entry', + [ + 'link' => \rosavox\helpers\string_coin( + '?mode=edit&id={{id}}', + [ + 'id' => $entry['id'], + ] + ), + 'text' => $entry['doc']['title'], + ] + ), + \rosavox\logic\docs_list() + ) + ), + 'link_new' => '?mode=make', + ] + ) + ); + break; + } + case 'make': + { + echo( + \rosavox\helpers\render( + 'docs-edit', + [ + 'id' => '', + 'title' => '', + 'authors' => '', + 'content' => '', + 'reasoning' => '', + 'link_back' => '?mode=list', + ] + ) + ); + break; + } + case 'edit': + { + $doc = \rosavox\logic\docs_read($id); + echo( + \rosavox\helpers\render( + 'docs-edit', + [ + 'id' => $id_encoded, + 'title' => $doc['title'], + 'authors' => \implode(', ', $doc['authors']), + 'content' => $doc['content'], + 'reasoning' => $doc['reasoning'], + 'link_back' => '?mode=list', + ] + ) + ); + break; + } + case 'save': + { + throw (new \Exception('not implemented yet')); + break; + } + default: + { + throw (new \Exception(\sprintf('invalid mode: %s', $mode))); + break; + } + } + ?> + + diff --git a/source/logic.php b/source/logic.php new file mode 100644 index 0000000..4c9b8de --- /dev/null +++ b/source/logic.php @@ -0,0 +1,129 @@ +} + */ + public static array $pool = []; +} + + +/** + */ +function docs_id_encode(int $id) : string +{ + return \sprintf('%u', $id); +} + + +/** + */ +function docs_id_decode(string $id_encoded) : int +{ + return intval($id_encoded); +} + + +/** + */ +function docs_list() : array +{ + return \array_map( + fn ($id_encoded) => [ + 'id' => docs_id_decode($id_encoded), + 'doc' => docs_state::$pool[$id_encoded], + ], + \array_keys(docs_state::$pool) + ); +} + + +/** + */ +function docs_read(int $id) : array +{ + $id_encoded = docs_id_encode($id); + if (! \array_key_exists($id_encoded, docs_state::$pool)) + { + throw (new Error('not found')); + } + else + { + return docs_state::$pool[$id_encoded]; + } +} + + +/** + */ +function docs_create(array $doc) : int +{ + docs_state::$current_id += 1; + $id = docs_state::$current_id; + $id_encoded = docs_id_encode($id); + docs_state::$pool[$id_encoded] = $doc; + return $id; +} + + +/** + */ +function docs_update(int $id, array $doc) : void +{ + $id_encoded = docs_id_encode($id); + if (! \array_key_exists($id_encoded, docs_state::$pool)) + { + throw (new Error('not found')); + } + else + { + docs_state::$pool[$id_encoded] = $doc; + } +} + + +/** + */ +function docs_delete(int $id) : void +{ + $id_encoded = docs_id_encode($id); + if (! \array_key_exists($id_encoded, docs_state::$pool)) + { + throw (new Error('not found')); + } + else + { + docs_state::$pool[$id_encoded] = null; + unset(docs_state::$pool[$id_encoded]); + } +} + + +/** + */ +function docs_add_examples() : void +{ + docs_create( + [ + 'title' => 'Freibier bei Parteitagen', + 'authors' => [ + 'Björn Biernot', + 'Doreen Dauerdurst', + ], + 'content' => 'Wir haben Durst!', + 'reasoning' => null, + ] + ); +} + + ?> diff --git a/source/style.css b/source/style.css new file mode 100644 index 0000000..9ebd55d --- /dev/null +++ b/source/style.css @@ -0,0 +1,72 @@ +:root +{ + --hue: 0; +} + +html +{ + background-color: hsl(var(--hue), 0%, 0%); + color: hsl(var(--hue), 0%, 100%); + + font-family: sans-serif; +} + +body +{ + max-width: 960px; + margin: auto; + padding: 16px; + + background-color: hsl(var(--hue), 0%, 12.5%); + color: hsl(var(--hue), 0%, 87.5%); +} + +a +{ + background-color: hsl(var(--hue), 0%, 12.5%); + color: hsl(var(--hue), 50%, 50%); + + text-decoration: none; +} + +a:hover +{ + background-color: hsl(var(--hue), 0%, 12.5%); + color: hsl(var(--hue), 50%, 75%); +} + +label +{ + display: block; + margin-bottom: 16px; +} + +label > span +{ + display: block; + font-weight: bold; + margin-bottom: 4px; +} + +input[type="text"] +{ + min-width: 480px; + padding: 4px; + + background-color: hsl(var(--hue), 0%, 25%); + color: hsl(var(--hue), 0%, 100%); + + border: none; +} + +textarea +{ + min-width: 480px; + min-height: 120px; + padding: 4px; + + background-color: hsl(var(--hue), 0%, 25%); + color: hsl(var(--hue), 0%, 100%); + + border: none; +} diff --git a/source/templates/docs-edit.html.tpl b/source/templates/docs-edit.html.tpl new file mode 100644 index 0000000..856cd07 --- /dev/null +++ b/source/templates/docs-edit.html.tpl @@ -0,0 +1,26 @@ +
+
+ + + + + + + +
+ zurück +
diff --git a/source/templates/docs-list-entry.html.tpl b/source/templates/docs-list-entry.html.tpl new file mode 100644 index 0000000..62642cf --- /dev/null +++ b/source/templates/docs-list-entry.html.tpl @@ -0,0 +1,3 @@ +
  • + {{text}} +
  • diff --git a/source/templates/docs-list.html.tpl b/source/templates/docs-list.html.tpl new file mode 100644 index 0000000..17fd3d9 --- /dev/null +++ b/source/templates/docs-list.html.tpl @@ -0,0 +1,6 @@ +
    + + Neu +
    diff --git a/tools/build b/tools/build new file mode 100755 index 0000000..82d8b4d --- /dev/null +++ b/tools/build @@ -0,0 +1,12 @@ +#!/usr/bin/env sh + +## consts + +dir_build="build" +dir_source="source" + + +## exec + +mkdir -p ${dir_build} +cp -r -u -v ${dir_source}/* ${dir_build}/ diff --git a/tools/run b/tools/run new file mode 100755 index 0000000..d5ba096 --- /dev/null +++ b/tools/run @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +php -S localhost:8000 -t build