feat: ✨ add upload functionality
This commit is contained in:
parent
f6b8611d90
commit
8b9be26987
3 changed files with 72 additions and 12 deletions
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Spatie\YamlFrontMatter\YamlFrontMatter;
|
||||
|
||||
class MySQLAdapter {
|
||||
public $raw;
|
||||
|
||||
|
@ -37,6 +39,33 @@ class MySQLAdapter {
|
|||
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) {
|
||||
$qry = "SELECT * FROM posts WHERE post_path = ?";
|
||||
|
||||
|
@ -65,7 +94,7 @@ class MySQLAdapter {
|
|||
ORDER BY post_create_time DESC
|
||||
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) {
|
||||
return $this->_prepare_post_data($data);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue