diff --git a/.forgejo/workflows/lint.yaml b/.forgejo/workflows/lint.yaml
new file mode 100644
index 0000000..46a5a88
--- /dev/null
+++ b/.forgejo/workflows/lint.yaml
@@ -0,0 +1,14 @@
+on: [push]
+
+jobs:
+ phplint:
+ runs-on: docker
+ steps:
+ - uses: actions/checkout@v3
+ - uses: docker://cytopia/phplint:alpine
+ with:
+ cmd: -i ./vendor/.* *.php
+ - uses: github.com/DavidAnson/markdownlint-cli2-action@v13
+ with:
+ globs: '**/*.md'
+ continue-on-error: true
\ No newline at end of file
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/docker_dev/Dockerfile b/docker_dev/Dockerfile
index 60a6a66..4f96be7 100644
--- a/docker_dev/Dockerfile
+++ b/docker_dev/Dockerfile
@@ -1,7 +1,7 @@
FROM composer
WORKDIR /app
-COPY composer.* .
+COPY www/composer.* .
RUN composer install
FROM php:apache
@@ -12,6 +12,7 @@ RUN chmod -R a+r ./vendor
RUN a2enmod rewrite
RUN a2enmod headers
+RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
-COPY . .
+COPY www/ .
RUN chmod -R a+r $(ls -I vendor)
diff --git a/docker_dev/MysqlDockerfile b/docker_dev/MysqlDockerfile
new file mode 100644
index 0000000..be3c855
--- /dev/null
+++ b/docker_dev/MysqlDockerfile
@@ -0,0 +1,4 @@
+FROM mysql:8.0-debian
+
+WORKDIR /docker-entrypoint-initdb.d
+COPY mysql_schema.sql ./
\ No newline at end of file
diff --git a/docker_dev/compose.yaml b/docker_dev/compose.yaml
index 5e8c99b..e1a79b0 100644
--- a/docker_dev/compose.yaml
+++ b/docker_dev/compose.yaml
@@ -9,18 +9,28 @@ services:
watch:
- path: ./
action: rebuild
- - path: ../.
+ - path: ../www/
action: sync
- target: /usr/local/apache2/htdocs/
+ target: /var/www/html
+ ignore:
+ - ../.git
+ - mysql_schema.sql
mysql:
- image: mysql:8.0-debian
+ build:
+ dockerfile: MysqlDockerfile
# NOTE: use of "mysql_native_password" is not recommended: https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password
# (this is just an example, not intended to be a production configuration)
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: example
- volumes:
- - sqlvolume:/var/lib/mysql
+ ports:
+ - 3306:3306
+ develop:
+ watch:
+ - path: mysql_schema.sql
+ action: rebuild
+# volumes:
+# - sqlvolume:/var/lib/mysql
volumes:
sqlvolume: {}
diff --git a/docker_dev/mysql_schema.sql b/docker_dev/mysql_schema.sql
new file mode 100644
index 0000000..6b954b7
--- /dev/null
+++ b/docker_dev/mysql_schema.sql
@@ -0,0 +1,48 @@
+
+CREATE DATABASE dragon_fire;
+
+USE dragon_fire;
+
+CREATE TABLE posts (
+ post_id INTEGER AUTO_INCREMENT,
+
+ post_path VARCHAR(255) NOT NULL,
+ post_path_depth INTEGER NOT NULL DEFAULT 0,
+
+ post_title TEXT,
+ post_description TEXT,
+ post_brief TEXT,
+
+ post_content MEDIUMTEXT,
+ post_content_type TEXT,
+
+ PRIMARY KEY(post_id),
+ CONSTRAINT unique_post_path UNIQUE (post_path),
+
+ INDEX(post_path),
+ INDEX(post_path_depth, post_path)
+);
+
+CREATE TABLE post_tags (
+ post_id INTEGER,
+ tag VARCHAR(255),
+
+ CONSTRAINT post_fkey
+ FOREIGN KEY(post_id) REFERENCES posts(post_id)
+ ON DELETE CASCADE,
+
+ INDEX(post_id),
+ INDEX(tag)
+);
+
+
+INSERT INTO posts (post_path, post_title, post_content)
+VALUES (
+ '/about',
+ 'About the Dergs',
+'
+# About the dergs indeed
+
+This is just a simple test. Might be nice, though!
+'
+);
\ No newline at end of file
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 9e2c99d..7d76a83 100644
--- a/router.php
+++ b/www/router.php
@@ -2,6 +2,31 @@
require_once 'vendor/autoload.php';
+
+$sql = mysqli_connect('mysql', 'root', 'example', 'dragon_fire');
+
+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]);
@@ -21,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