feat(auth,api): begin work on API input
This commit is contained in:
parent
0dcf36052e
commit
c607d57221
11 changed files with 44 additions and 11 deletions
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
interface AnalyticsInterface {
|
interface AnalyticsInterface {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
function sanitize_post_path($post_path) {
|
function sanitize_post_path($post_path) {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once 'analytics_interface.php';
|
require_once 'analytics_interface.php';
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Post implements ArrayAccess {
|
class Post implements ArrayAccess {
|
||||||
|
@ -180,7 +179,7 @@ class Post implements ArrayAccess {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function to_array($options = []) {
|
public function to_array($options = []) {
|
||||||
$out_data = $this->data;
|
$out_data = array_merge($this->site_defaults, $this->data);
|
||||||
|
|
||||||
if(isset($options['markdown'])) {
|
if(isset($options['markdown'])) {
|
||||||
$out_data['markdown'] = $this->get_markdown();
|
$out_data['markdown'] = $this->get_markdown();
|
||||||
|
@ -189,7 +188,14 @@ class Post implements ArrayAccess {
|
||||||
$out_data['html'] = $this->get_html();
|
$out_data['html'] = $this->get_html();
|
||||||
}
|
}
|
||||||
if(isset($options['children'])) {
|
if(isset($options['children'])) {
|
||||||
die();
|
$children = $this->get_child_posts();
|
||||||
|
$child_arrays = [];
|
||||||
|
|
||||||
|
foreach($children AS $child) {
|
||||||
|
array_push($child_arrays, $child->to_array());
|
||||||
|
}
|
||||||
|
|
||||||
|
$out_data['children'] = $child_arrays;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $out_data;
|
return $out_data;
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
|
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Highlight\Highlighter;
|
use Highlight\Highlighter;
|
||||||
|
|
|
@ -4,19 +4,21 @@ $data_time_start = microtime(true);
|
||||||
|
|
||||||
require_once '../vendor/autoload.php';
|
require_once '../vendor/autoload.php';
|
||||||
|
|
||||||
require_once 'setup_site_config.php';
|
require_once 'setup/site_config.php';
|
||||||
require_once 'setup_db.php';
|
require_once 'setup/db.php';
|
||||||
|
|
||||||
require_once 'fontawesome.php';
|
require_once 'fontawesome.php';
|
||||||
require_once 'dergdown.php';
|
require_once 'dergdown.php';
|
||||||
|
|
||||||
require_once 'setup_twig.php';
|
require_once 'setup/twig.php';
|
||||||
|
|
||||||
$REQUEST_URI = parse_url($_SERVER['REQUEST_URI']);
|
$REQUEST_URI = parse_url($_SERVER['REQUEST_URI']);
|
||||||
$REQUEST_PATH = $REQUEST_URI['path'];
|
$REQUEST_PATH = $REQUEST_URI['path'];
|
||||||
|
|
||||||
parse_str($REQUEST_URI['query'] ?? '', $REQUEST_QUERY);
|
parse_str($REQUEST_URI['query'] ?? '', $REQUEST_QUERY);
|
||||||
|
|
||||||
|
require_once 'setup/permissions.php';
|
||||||
|
|
||||||
if(preg_match('/^\/api/', $REQUEST_PATH)) {
|
if(preg_match('/^\/api/', $REQUEST_PATH)) {
|
||||||
require_once 'serve/api.php';
|
require_once 'serve/api.php';
|
||||||
}
|
}
|
||||||
|
|
13
www/src/serve/api.php
Normal file
13
www/src/serve/api.php
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
if(preg_match('/^\/api\/posts(.*)$/', $REQUEST_PATH, $match)) {
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
$post = $adapter->get_post($match[1]);
|
||||||
|
|
||||||
|
echo $post->to_json($REQUEST_QUERY);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
17
www/src/setup/permissions.php
Normal file
17
www/src/setup/permissions.php
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$ACCESS_PERMISSIONS = [
|
||||||
|
"read" => true,
|
||||||
|
"upload" => false
|
||||||
|
];
|
||||||
|
|
||||||
|
$ACCESS_KEY = $REQUEST_QUERY['ACCESS_KEY'] ?? $_COOKIE['ACCESS_KEY'] ?? '';
|
||||||
|
|
||||||
|
if($ACCESS_KEY == $SITE_CONFIG['ACCESS_KEY']) {
|
||||||
|
$ACCESS_PERMISSIONS = [
|
||||||
|
"read" => true,
|
||||||
|
"upload" => true
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
Loading…
Add table
Add a link
Reference in a new issue