This commit is contained in:
parent
76ca7b9c32
commit
0dcf36052e
18 changed files with 152 additions and 112 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
26
www/src/serve/ajax.php
Normal 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);
|
||||
|
||||
?>
|
|
@ -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();
|
|
@ -40,4 +40,6 @@ function post_to_html($post) {
|
|||
}
|
||||
$adapter->markdown_engine = "post_to_html";
|
||||
|
||||
$adapter->site_defaults = $SITE_CONFIG['site_defaults'];
|
||||
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue