feat: ✨ add upload functionality
This commit is contained in:
parent
f6b8611d90
commit
8b9be26987
3 changed files with 72 additions and 12 deletions
|
@ -32,29 +32,42 @@ $twig->addRuntimeLoader(new class implements RuntimeLoaderInterface {
|
|||
}
|
||||
});
|
||||
|
||||
if($_SERVER['REQUEST_URI'] == '/') {
|
||||
$SURI = $_SERVER['REQUEST_URI'];
|
||||
|
||||
if($SURI == '/') {
|
||||
echo $twig->render('root.html');
|
||||
} elseif(preg_match('/^\/api\/posts(.*)$/', $_SERVER['REQUEST_URI'], $match)) {
|
||||
} elseif(preg_match('/^\/api/', $SURI)) {
|
||||
if(preg_match('/^\/api\/posts(.*)$/', $SURI, $match)) {
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(get_post_by_path($match[1]));
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($adapter->get_post_by_path($match[1]));
|
||||
|
||||
} elseif(preg_match('/^\/api\/subposts(.*)$/', $_SERVER['REQUEST_URI'], $match)) {
|
||||
} elseif(preg_match('/^\/api\/subposts(.*)$/', $SURI, $match)) {
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(get_subposts($match[1]));
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(get_subposts($match[1]));
|
||||
} elseif($SURI == '/api/upload') {
|
||||
|
||||
if(array_key_exists('post_data', $_FILES)) {
|
||||
$upload_content = file_get_contents($_FILES['post_data']['tmp_name']);
|
||||
$upload_path = $_POST['post_path'];
|
||||
|
||||
$adapter->save_markdown_post($upload_path, $upload_content);
|
||||
}
|
||||
|
||||
echo $twig->render('upload.html');
|
||||
}
|
||||
} elseif(true) {
|
||||
$post = $adapter->get_post_by_path($_SERVER['REQUEST_URI']);
|
||||
$post = $adapter->get_post_by_path($SURI);
|
||||
|
||||
echo $twig->render('about.html', [
|
||||
"post" => $post,
|
||||
"subposts" => $post['subposts']
|
||||
]);
|
||||
|
||||
} elseif(preg_match('/^\/about(.html)?$/', $_SERVER['REQUEST_URI'])) {
|
||||
} elseif(preg_match('/^\/about(.html)?$/', $SURI)) {
|
||||
echo $twig->render('about.html');
|
||||
} elseif(preg_match('/^\/gallery\/([^\?]+)/', $_SERVER['REQUEST_URI'])) {
|
||||
} elseif(preg_match('/^\/gallery\/([^\?]+)/', $SURI)) {
|
||||
echo $twig->render('/gallery/gallery_entry.html', [
|
||||
'image_url' => '/static/banner/0.png',
|
||||
'image_title' => 'Test!',
|
||||
|
@ -66,7 +79,7 @@ if($_SERVER['REQUEST_URI'] == '/') {
|
|||
echo $twig->render('rrror.html',[
|
||||
"error_code" => '404 Hoard not found!',
|
||||
"error_description" => "Well, we searched
|
||||
far and wide for `" . $_SERVER['REQUEST_URI'] . "` but
|
||||
far and wide for `" . $SURI . "` but
|
||||
somehow it must have gotten lost... Sorry!"
|
||||
]);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue