76 lines
No EOL
1.8 KiB
PHP
76 lines
No EOL
1.8 KiB
PHP
<?php
|
|
|
|
require_once 'db_interface.php';
|
|
require_once 'db_handler/post.php';
|
|
|
|
class PostHandler {
|
|
private $db;
|
|
private $posts;
|
|
|
|
public $markdown_engine;
|
|
|
|
public $site_defaults;
|
|
|
|
function __construct($db_adapter) {
|
|
$this->db = $db_adapter;
|
|
$this->posts = [];
|
|
|
|
$this->site_defaults = null;
|
|
|
|
$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->site_defaults);
|
|
}
|
|
|
|
$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 increment_post_counter(...$opts) {
|
|
$this->db->increment_post_counter(...$opts);
|
|
}
|
|
|
|
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, $this->site_defaults));
|
|
}
|
|
|
|
return $out_list;
|
|
}
|
|
|
|
public function search_posts($search_query) {
|
|
$search_results = $this->db->search_posts($search_query);
|
|
|
|
$out_list = [];
|
|
foreach($search_results as $search_result) {
|
|
array_push($out_list, new Post($this, $search_result, $this->site_defaults));
|
|
}
|
|
|
|
return $out_list;
|
|
}
|
|
}
|
|
|
|
?>
|