... unsure
Some checks reported warnings
/ phplint (push) Has been cancelled

This commit is contained in:
David Bailey 2024-08-24 13:09:28 +02:00
parent 76ca7b9c32
commit 0dcf36052e
18 changed files with 152 additions and 112 deletions

View file

@ -7,7 +7,7 @@ class Post implements ArrayAccess {
private $content_html;
private $content_markdown;
public $site_defaults;
private $site_defaults;
public $data;
@ -15,6 +15,7 @@ class Post implements ArrayAccess {
public $raw_data;
private $_child_posts;
private $_parent_post;
public static function _generate_404($post_data) {
$post_data ??= [
@ -61,13 +62,13 @@ class Post implements ArrayAccess {
return $icon_mapping[$type] ?? 'unknown';
}
function __construct($post_handler, $post_data) {
function __construct($post_handler, $post_data, $site_defaults) {
$this->handler = $post_handler;
$this->content_html = null;
$this->content_markdown = null;
$this->site_defaults = null;
$this->site_defaults = $site_defaults;
if(!isset($post_data) or !isset($post_data['id'])) {
$post_data = $this->_generate_404($post_data);
@ -75,9 +76,17 @@ class Post implements ArrayAccess {
$data = $post_data;
if($data['path'] == '') {
$data['path'] = '/';
$data['title'] ??= 'root';
$data['basename'] ??= 'root';
}
$post_data['host'] ??= 'localhost:8081';
$data['url'] ??= 'https://' . $post_data['host'] . $post_data['path'];
$data['url'] ??= 'http://' . $post_data['host'] . $post_data['path'];
$data['basename'] ??= basename($data['path']);
$data['title'] ??= basename($data['path']);
@ -111,6 +120,9 @@ class Post implements ArrayAccess {
if($name == 'child_posts') {
return $this->get_child_posts();
}
if($name == 'parent') {
return $this->get_parent_post();
}
if(isset($this->data[$name])) {
return $this->data[$name];
@ -137,10 +149,10 @@ class Post implements ArrayAccess {
return !is_null($this->offsetGet($offset));
}
public function offsetSet($offset, $value) : void {
throw RuntimeError("Setting of post data is not allowed!");
$this->data[$offset] = $value;
}
public function offsetUnset($offset) : void {
throw RuntimeError("Unsetting of post data is not allowed!");
unset($this->data[$offset]);
}
public function get_html() {
@ -156,14 +168,11 @@ class Post implements ArrayAccess {
}
public function get_child_posts(...$search_args) {
var_dump($search_args);
if(count($search_args) == 0) {
$this->child_posts ??=
$this->_child_posts ??=
$this->handler->get_children_for($this);
return $this->child_posts;
return $this->_child_posts;
}
else {
return $this->handler->get_children_for($this, ...$search_args);
@ -195,10 +204,9 @@ class Post implements ArrayAccess {
if($parent_path == '')
return null;
$this->parent_post ??= new PostData($this->handler,
$this->handler->get_post_by_path($parent_path));
$this->_parent_post ??= $this->handler->get_post($parent_path);
return $this->parent_post;
return $this->_parent_post;
}
}

View file

@ -9,10 +9,14 @@ class PostHandler {
public $markdown_engine;
public $site_defaults;
function __construct($db_adapter) {
$this->db = $db_adapter;
$this->posts = [];
$this->site_defaults = null;
$this->markdown_engine = null;
}
@ -26,7 +30,7 @@ class PostHandler {
$post_data = $this->db->get_postdata($key);
$post = null;
if(isset($post_data)) {
$post = new Post($this, $post_data);
$post = new Post($this, $post_data, $this->site_defaults);
}
$this->posts[$key] = $post;
@ -39,7 +43,7 @@ class PostHandler {
}
public function render_post($post) {
return $this->markdown_engine($post);
return ($this->markdown_engine)($post);
}
public function get_children_for($post, ...$search_opts) {
@ -47,7 +51,7 @@ class PostHandler {
$out_list = [];
foreach($child_list as $child_data) {
array_push($out_list, new Post($this, $child_data));
array_push($out_list, new Post($this, $child_data, $this->site_defaults));
}
return $out_list;

View file

@ -126,13 +126,17 @@ echo "Done!\n\n";
test_accounce("Setting post markdown...");
$sql_adapter->set_postdata([
'path' => '/testing/markdowntest',
'markdown' => 'Inline markdown test should work...'
'markdown' => 'Inline markdown test should work...',
'title' => "A Markdown Test"
]);
$post = $sql_adapter->get_postdata('/testing/markdowntest');
var_dump($sql_adapter->get_post_markdown($post['id']));
$sql_adapter->set_post_markdown($post['id'],
'This is one hell of a cute test!'
'
This is one hell of a cute test!
> Just checking in...
'
);
var_dump($sql_adapter->get_post_markdown($post['id']));
unset($post);

View file

@ -12,8 +12,20 @@ require_once 'dergdown.php';
require_once 'setup_twig.php';
$PARSED_URL = parse_url($_SERVER['REQUEST_URI']);
$REQUEST_URI = parse_url($_SERVER['REQUEST_URI']);
$REQUEST_PATH = $REQUEST_URI['path'];
parse_str($REQUEST_URI['query'] ?? '', $REQUEST_QUERY);
if(preg_match('/^\/api/', $REQUEST_PATH)) {
require_once 'serve/api.php';
}
elseif(preg_match('/^\/ajax/', $REQUEST_PATH)) {
require_once 'serve/ajax.php';
}
else {
require_once 'serve/post.php';
}
require_once 'serve_post.php';
?>

26
www/src/serve/ajax.php Normal file
View file

@ -0,0 +1,26 @@
<?php
$match = null;
preg_match('/^\/ajax\/(.*)$/', $REQUEST_PATH, $match);
if(!isset($match)) {
die();
}
$AJAX_REQUEST_TEMPLATE = $match[1];
$ajax_args = [
];
if(isset($REQUEST_QUERY['page'])) {
$ajax_args['page'] = $adapter->get_post($REQUEST_QUERY['page']);
}
$ajax_args['fa'] = $FONT_AWESOME_ARRAY;
$ajax_args['page'] ??= $SITE_CONFIG['site_defaults'];
echo $twig->render('/ajax/' . $AJAX_REQUEST_TEMPLATE, $ajax_args);
?>

View file

@ -2,26 +2,24 @@
require_once 'fontawesome.php';
$post = $adapter->get_post($PARSED_URL['path']);
if(isset($post)) {
$post->site_defaults = $SITE_CONFIG['site_defaults'];
}
$post = $adapter->get_post($REQUEST_PATH);
function render_root_template($template, $args = []) {
global $twig;
global $FONT_AWESOME_ARRAY;
global $SITE_CONFIG;
$args['fontawesome'] = $FONT_AWESOME_ARRAY;
$args['fa'] = $FONT_AWESOME_ARRAY;
$args['page'] ??= $SITE_CONFIG['site_defaults'];
$page = $args['page'];
$page['base'] ??= $page['url'];
$args['opengraph'] = [
"site_name" => $page['site_name'] ?? 'UNSET SITE NAME',
"title" => $page['title'] ?? 'UNSET TITLE',
"url" => $page['url'] ?? 'UNSET URL',
"description" => $page['description'] ?? 'UNSET DESCRIPTION'
"site_name" => $page['site_name'] ?? 'Nameless Site',
"title" => $page['title'] ?? 'Titleless',
"url" => $page['url'] ?? $page['path'] ?? 'No URL set',
"description" => $page['description'] ?? 'No description set'
];
$args['banners'] = json_encode($page['banners'] ?? []);
@ -32,7 +30,11 @@ function render_root_template($template, $args = []) {
echo $twig->render($template, $args);
}
render_root_template('root.html', [
function render_pathed_content_template($template, $args = []) {
render_root_template($template, $args);
}
render_pathed_content_template('post_types/markdown.html', [
'page' => $post
]);
die();

View file

@ -40,4 +40,6 @@ function post_to_html($post) {
}
$adapter->markdown_engine = "post_to_html";
$adapter->site_defaults = $SITE_CONFIG['site_defaults'];
?>

View file

@ -311,12 +311,21 @@ body.htmx-request::before {
.folder-listing input {
display: none;
}
.folder-listing input + ul {
.folder-listing input ~ ul {
display: none;
}
.folder-listing input:checked + ul {
.folder-listing input:checked ~ ul {
display: block;
}
.folder-listing label > :nth-child(2) {
display: none;
}
.folder-listing input:checked ~ label > :nth-child(1) {
display: none;
}
.folder-listing input:checked ~ label > :nth-child(2) {
display: inline-block;
}
#navbar-expand-label {
cursor: pointer;

View file

@ -1,13 +0,0 @@
<li class="folder-listing">
<span hx-boost="false"
hx-get="/ajax/open_folder_listing{{ post.post_path }}"
hx-target="closest li"
hx-swap="outerHTML">
{{ fa[post.post_metadata.icon] | raw }}
</span>
<a href={{post.post_path}}>
{{ post.post_metadata.title }}
</a>
</li>

View file

@ -0,0 +1,27 @@
<li class="folder-listing">
{% set folder_key = random() %}
<input type="checkbox" id="folder-open-{{folder_key}}" name="folder-open-{{folder_key}}">
<label for="folder-open-{{folder_key}}"
hx-trigger="click once queue:last, mouseenter once queue:all, intersect once queue:all"
hx-get="/ajax/compact_filelist/listing.html?page={{ post.path }}"
hx-target="next ul">
{{ fa['folder'] | raw }}
{{ fa['folder-open'] | raw }}
</label>
<a href={{post.path}}>
{{ post.basename }} - {{ post.title }}
</a>
<ul class="folder-listing">
<li>
<span>
Loading...
</span>
</li>
</ul>
</li>

View file

@ -0,0 +1,4 @@
{% for post in page.child_posts %}
{{ include('ajax/compact_filelist/entry.html') }}
{% endfor %}

View file

@ -1,4 +0,0 @@
{% for post in subposts %}
{{ include('ajax/folder_listing_entry.html') }}
{% endfor %}

View file

@ -1,26 +0,0 @@
<li class="folder-listing">
{% set folder_key = random() %}
<label for="folder-open-{{folder_key}}"
hx-trigger="click once queue:all"
hx-get="/ajax/folder_listing{{post.post_path}}"
hx-target="next ul">
{{ fa[post.post_metadata.icon] | raw }}
</label>
<a href={{post.post_path}}>
{{ post.post_metadata.title }}
</a>
<input type="checkbox" id="folder-open-{{folder_key}}">
<ul class="folder-listing">
<li>
<span>
Loading...
</span>
</li>
</ul>
</li>

View file

@ -1,20 +0,0 @@
<li class="folder-listing">
<span hx-boost="false"
hx-get="/ajax/closed_folder_listing{{ post.post_path }}"
hx-target="closest li"
hx-swap="outerHTML">
{{ fa[post.post_metadata.icon] | raw }}
</span>
<a href={{post.post_path}}>
{{ post.post_metadata.title }}
</a>
<ul class="folder-listing">
{% for post in subposts %}
{{ include('ajax/closed_folder_listing.html') }}
{% endfor %}
</ul>
</li>

View file

@ -1,11 +1,11 @@
<div id="post_file_bar">
<menu id="post_file_titles">
<li>
{{ post.post_metadata.title }}
{{ page.basename }}
</li>
</menu>
<menu id="post_file_path">
{% set split_post = post.post_path |split('/') %}
{% set split_post = page.path |split('/') %}
{% for i in range(0, split_post|length - 1) %}
<li>
{% if i != 0 %}
@ -22,7 +22,7 @@
<li style="margin-left: auto;">
<label for="navbar-expander" id="navbar-expand-label"> {{ fa['bars'] | raw }} </label>
<a rel="alternate" type="application/rss+xml" target="_blank"
style="padding-left: 0.3rem;" href="/feed/rss{{post.post_path}}">
style="padding-left: 0.3rem;" href="/feed/rss{{page.path}}">
{{ fa['rss']|raw }}
</a>
</li>
@ -32,7 +32,7 @@
<div class="navbar-expand">
Full path:
<ul class="navbar-full-path">
{% set split_post = post.post_path |split('/') %}
{% set split_post = page.path |split('/') %}
{% for i in range(0, split_post|length - 1) %}
<li>
{% if i != 0 %}
@ -47,8 +47,8 @@
</ul>
Dev links:
<a hx-boost="false" href="/raw{{post.post_path}}">raw</a>
<a hx-boost="false" href="/api/posts{{post.post_path}}">api</a>
<a hx-boost="false" href="/raw{{page.path}}">raw</a>
<a hx-boost="false" href="/api/posts{{page.path}}">api</a>
<h4>Folder browser: </h4>
@ -58,12 +58,10 @@
{{ fa['turn-up'] | raw}}
</span>
<a href={{post.parent_path}}>..</a>
<a href={{page.parent.path}}>..</a>
</li>
{% for post in subposts %}
{{ include('ajax/folder_listing_entry.html') }}
{% endfor %}
{{ include('ajax/compact_filelist/listing.html') }}
</ul>
</div>
</div>

View file

@ -6,11 +6,11 @@
{{ parent() }}
<link rel="alternate" type="application/atom+xml" title="{{og.site_name}} Feed for {{post.post_path}}" href="{{site_config.uri_prefix}}/feed/atom{{post.post_path}}">
<link rel="alternate" type="application/atom+xml" title="{{opengraph.site_name}} Feed for {{page.path}}" href="{{page.uri_prefix}}/feed/atom{{page.path}}">
{% endblock %}
{% block second_title %}
<h2> {{ post.post_metadata.title }} </h2>
<h2> {{ page.title }} </h2>
{% endblock %}
{%block main_content%}
@ -22,7 +22,7 @@
{%endblock%}
<span id="content_footer">
This article was created on {{ post.post_create_time }}, last edited {{ post.post_update_time }}, and was viewed {{ post.post_access_count }} times~
This page was created on {{ page.created_at }}, last edited {{ page.updated_at }}, and was viewed {{ page.view_count }} times~
</span>
</article>

View file

@ -9,5 +9,9 @@
{%endblock %}
{%block content_article%}
{{ content_html|raw }}
{% if page.title %}
<h1 class="content-title"> {{ page.title }} </h1>
{% endif %}
{{ page.html|raw }}
{% endblock %}

View file

@ -12,7 +12,6 @@
<link rel="stylesheet" href="/static/article_blop.css">
<link rel="stylesheet" href="/static/gallerystyle.css">
<link rel="icon" type="image/x-icon" href="/static/icon.jpeg">
<meta name="viewport" content="width=device-width,initial-scale=1">
@ -20,6 +19,10 @@
<script src="/static/htmx.min.js"></script>
<script id="main_banner_script" src="/static/banner.js"></script>
{% if page.base %}
<base href="{{ page.base }}">
{% endif %}
{% block feed_links %}
<link rel="alternate" type="application/rss+xml" title="{{opengraph.site_name}} Global Feed" href="{{site_config.uri_prefix}}/feed">
{% endblock %}