Compare commits
2 commits
f6b8611d90
...
8b01664b71
Author | SHA1 | Date | |
---|---|---|---|
8b01664b71 | |||
8b9be26987 |
5 changed files with 89 additions and 12 deletions
8
test_entries/about/neira.md
Normal file
8
test_entries/about/neira.md
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
---
|
||||||
|
---
|
||||||
|
|
||||||
|
# About her
|
||||||
|
|
||||||
|
|
||||||
|
This is some test content, to simulate a little markdown page for... Well, our website.
|
||||||
|
I wouldn't worry too much about it. Just know it's here :)
|
9
test_entries/about/neira/subtest.md
Normal file
9
test_entries/about/neira/subtest.md
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
---
|
||||||
|
tags:
|
||||||
|
- neira
|
||||||
|
- comfy
|
||||||
|
- testing
|
||||||
|
title: Subtest, it's nice :>
|
||||||
|
---
|
||||||
|
|
||||||
|
## Subtests, because it's nice
|
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Spatie\YamlFrontMatter\YamlFrontMatter;
|
||||||
|
|
||||||
class MySQLAdapter {
|
class MySQLAdapter {
|
||||||
public $raw;
|
public $raw;
|
||||||
|
|
||||||
|
@ -37,6 +39,33 @@ class MySQLAdapter {
|
||||||
return $post_data;
|
return $post_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function save_markdown_post($post_path, $post_data) {
|
||||||
|
$frontmatter_post = YamlFrontMatter::parse($post_data);
|
||||||
|
|
||||||
|
$post_path = chop($post_path, '/');
|
||||||
|
$path_depth = substr_count($post_path, "/");
|
||||||
|
|
||||||
|
$post_content = $frontmatter_post->body();
|
||||||
|
$post_metadata = $frontmatter_post->matter();
|
||||||
|
|
||||||
|
$post_metadata['type'] = 'text/markdown';
|
||||||
|
|
||||||
|
var_dump($post_path, $post_content, $post_metadata);
|
||||||
|
|
||||||
|
$qry = "
|
||||||
|
INSERT INTO posts
|
||||||
|
(post_path, post_path_depth, post_metadata, post_content)
|
||||||
|
VALUES
|
||||||
|
( ?, ?, ?, ?) AS new
|
||||||
|
ON DUPLICATE KEY UPDATE post_metadata=new.post_metadata, post_content=new.post_content;";
|
||||||
|
|
||||||
|
$this->_exec($qry, "siss",
|
||||||
|
$post_path,
|
||||||
|
$path_depth,
|
||||||
|
json_encode($post_metadata),
|
||||||
|
$post_content);
|
||||||
|
}
|
||||||
|
|
||||||
function get_post_by_path($post_path, $with_subposts = true) {
|
function get_post_by_path($post_path, $with_subposts = true) {
|
||||||
$qry = "SELECT * FROM posts WHERE post_path = ?";
|
$qry = "SELECT * FROM posts WHERE post_path = ?";
|
||||||
|
|
||||||
|
@ -65,7 +94,7 @@ class MySQLAdapter {
|
||||||
ORDER BY post_create_time DESC
|
ORDER BY post_create_time DESC
|
||||||
LIMIT 10";
|
LIMIT 10";
|
||||||
|
|
||||||
$post_data = $this->_exec($qry, "si", $path, $path_depth)->fetch_all(MYSQLI_ASSOC);
|
$post_data = $this->_exec($qry, "si", $path, $path_depth+1)->fetch_all(MYSQLI_ASSOC);
|
||||||
|
|
||||||
$fn = function($data) {
|
$fn = function($data) {
|
||||||
return $this->_prepare_post_data($data);
|
return $this->_prepare_post_data($data);
|
||||||
|
|
|
@ -32,29 +32,42 @@ $twig->addRuntimeLoader(new class implements RuntimeLoaderInterface {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if($_SERVER['REQUEST_URI'] == '/') {
|
$SURI = $_SERVER['REQUEST_URI'];
|
||||||
|
|
||||||
|
if($SURI == '/') {
|
||||||
echo $twig->render('root.html');
|
echo $twig->render('root.html');
|
||||||
} elseif(preg_match('/^\/api\/posts(.*)$/', $_SERVER['REQUEST_URI'], $match)) {
|
} elseif(preg_match('/^\/api/', $SURI)) {
|
||||||
|
if(preg_match('/^\/api\/posts(.*)$/', $SURI, $match)) {
|
||||||
|
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
echo json_encode(get_post_by_path($match[1]));
|
echo json_encode($adapter->get_post_by_path($match[1]));
|
||||||
|
|
||||||
} elseif(preg_match('/^\/api\/subposts(.*)$/', $_SERVER['REQUEST_URI'], $match)) {
|
} elseif(preg_match('/^\/api\/subposts(.*)$/', $SURI, $match)) {
|
||||||
|
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
echo json_encode(get_subposts($match[1]));
|
echo json_encode(get_subposts($match[1]));
|
||||||
|
} elseif($SURI == '/api/upload') {
|
||||||
|
|
||||||
|
if(array_key_exists('post_data', $_FILES)) {
|
||||||
|
$upload_content = file_get_contents($_FILES['post_data']['tmp_name']);
|
||||||
|
$upload_path = $_POST['post_path'];
|
||||||
|
|
||||||
|
$adapter->save_markdown_post($upload_path, $upload_content);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $twig->render('upload.html');
|
||||||
|
}
|
||||||
} elseif(true) {
|
} elseif(true) {
|
||||||
$post = $adapter->get_post_by_path($_SERVER['REQUEST_URI']);
|
$post = $adapter->get_post_by_path($SURI);
|
||||||
|
|
||||||
echo $twig->render('about.html', [
|
echo $twig->render('about.html', [
|
||||||
"post" => $post,
|
"post" => $post,
|
||||||
"subposts" => $post['subposts']
|
"subposts" => $post['subposts']
|
||||||
]);
|
]);
|
||||||
|
|
||||||
} elseif(preg_match('/^\/about(.html)?$/', $_SERVER['REQUEST_URI'])) {
|
} elseif(preg_match('/^\/about(.html)?$/', $SURI)) {
|
||||||
echo $twig->render('about.html');
|
echo $twig->render('about.html');
|
||||||
} elseif(preg_match('/^\/gallery\/([^\?]+)/', $_SERVER['REQUEST_URI'])) {
|
} elseif(preg_match('/^\/gallery\/([^\?]+)/', $SURI)) {
|
||||||
echo $twig->render('/gallery/gallery_entry.html', [
|
echo $twig->render('/gallery/gallery_entry.html', [
|
||||||
'image_url' => '/static/banner/0.png',
|
'image_url' => '/static/banner/0.png',
|
||||||
'image_title' => 'Test!',
|
'image_title' => 'Test!',
|
||||||
|
@ -66,7 +79,7 @@ if($_SERVER['REQUEST_URI'] == '/') {
|
||||||
echo $twig->render('rrror.html',[
|
echo $twig->render('rrror.html',[
|
||||||
"error_code" => '404 Hoard not found!',
|
"error_code" => '404 Hoard not found!',
|
||||||
"error_description" => "Well, we searched
|
"error_description" => "Well, we searched
|
||||||
far and wide for `" . $_SERVER['REQUEST_URI'] . "` but
|
far and wide for `" . $SURI . "` but
|
||||||
somehow it must have gotten lost... Sorry!"
|
somehow it must have gotten lost... Sorry!"
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
18
www/templates/upload.html
Normal file
18
www/templates/upload.html
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
|
||||||
|
|
||||||
|
{% extends "root.html" %}
|
||||||
|
|
||||||
|
{% block second_title %}
|
||||||
|
<h2> UPLOAD CONTENT </h2>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{%block main_content%}
|
||||||
|
<article>
|
||||||
|
<form method="post" enctype="multipart/form-data">
|
||||||
|
<input type="text" id="post_path" name="post_path"/>
|
||||||
|
<input type="file" id="post_data" name="post_data"/>
|
||||||
|
|
||||||
|
<button>Submit</button>
|
||||||
|
</form>
|
||||||
|
</article>
|
||||||
|
{%endblock%}
|
Loading…
Add table
Add a link
Reference in a new issue