everything(everything): simply saving work
This commit is contained in:
parent
0f2761cd61
commit
76ca7b9c32
25 changed files with 1330 additions and 561 deletions
57
www/src/db_handler/post_handler.php
Normal file
57
www/src/db_handler/post_handler.php
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
require_once 'db_interface.php';
|
||||
require_once 'db_handler/post.php';
|
||||
|
||||
class PostHandler {
|
||||
private $db;
|
||||
private $posts;
|
||||
|
||||
public $markdown_engine;
|
||||
|
||||
function __construct($db_adapter) {
|
||||
$this->db = $db_adapter;
|
||||
$this->posts = [];
|
||||
|
||||
$this->markdown_engine = null;
|
||||
}
|
||||
|
||||
public function get_post($key) {
|
||||
$key = sanitize_post_path($key);
|
||||
|
||||
if(isset($this->posts[$key])) {
|
||||
return $this->posts[$key];
|
||||
}
|
||||
|
||||
$post_data = $this->db->get_postdata($key);
|
||||
$post = null;
|
||||
if(isset($post_data)) {
|
||||
$post = new Post($this, $post_data);
|
||||
}
|
||||
|
||||
$this->posts[$key] = $post;
|
||||
|
||||
return $post;
|
||||
}
|
||||
|
||||
public function get_markdown_for($post) {
|
||||
return $this->db->get_post_markdown($post->id);
|
||||
}
|
||||
|
||||
public function render_post($post) {
|
||||
return $this->markdown_engine($post);
|
||||
}
|
||||
|
||||
public function get_children_for($post, ...$search_opts) {
|
||||
$child_list = $this->db->get_post_children($post->path, ...$search_opts);
|
||||
|
||||
$out_list = [];
|
||||
foreach($child_list as $child_data) {
|
||||
array_push($out_list, new Post($this, $child_data));
|
||||
}
|
||||
|
||||
return $out_list;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue