07b422a9c3
This one is a doozy, so let's breakt it down into what areas where touched. - updated package json to remove unneeded dependencies. - rebuilt file uploading to simply a very convuluted process - began proces to replace icons with https://tabler-icons.io - began process of removing the need for css preprocessor and using pure css - login completed - dashboard index completed - page edit ui completed - page edit ui text editor tweaked so syntax highlighting is cleaner and more accurate The settings and navigation UIs still remain and then polishing the responsive for the new css structure
180 lines
6.4 KiB
PHP
180 lines
6.4 KiB
PHP
<?php
|
|
|
|
namespace brain\api\v1;
|
|
|
|
use brain\data\Book;
|
|
use brain\data\Settings;
|
|
use brain\data\Session;
|
|
use brain\utility\StringTools;
|
|
|
|
use function _\filter;
|
|
|
|
class PagesAPI
|
|
{
|
|
public function __construct()
|
|
{
|
|
}
|
|
|
|
public static function getPageContent($request, $args)
|
|
{
|
|
$task = $args['fourth'];
|
|
$pages = (new Book('../content/pages'))->getContents();
|
|
$content = [];
|
|
foreach ($pages as $page) {
|
|
$entry = [
|
|
'id' => $page['id'],
|
|
'uuid' => $page['uuid'],
|
|
'title' => $page['title'],
|
|
'feature' => $page['feature'],
|
|
'path' => $page['path'],
|
|
'layout' => $page['layout'],
|
|
'tags' => $page['tags'],
|
|
'author' => $page['author'],
|
|
'created' => $page['created'],
|
|
'updated' => $page['updated'],
|
|
'deleted' => $page['deleted'],
|
|
'menu' => $page['menu'],
|
|
'featured' => $page['featured'],
|
|
'published' => $page['published'],
|
|
'slug' => $page['slug'],
|
|
'content' => StringTools::sanitizeContent($page['content']),
|
|
];
|
|
|
|
array_push($content, $entry);
|
|
}
|
|
switch ($task) {
|
|
case 'published':
|
|
$published = filter($content, function ($item) {
|
|
return $item['published'] == true && $item['deleted'] == false;
|
|
});
|
|
|
|
$result = ['pages' => $published, 'totalItems' => count($published)];
|
|
break;
|
|
case 'featured':
|
|
$featured = filter($content, function ($item) {
|
|
return $item['featured'] == true && $item['deleted'] == false;
|
|
});
|
|
|
|
$result = [
|
|
'pages' => $featured,
|
|
'totalItems' => count($featured),
|
|
];
|
|
break;
|
|
case 'menu':
|
|
$menu = filter($content, function ($item) {
|
|
return $item['menu'] == true && $item['deleted'] == false;
|
|
});
|
|
|
|
$result = ['pages' => $menu, 'totalItems' => count($menu)];
|
|
break;
|
|
case 'single':
|
|
$uuid = $args['fifth'];
|
|
$page = (new Book('../content/pages'))->findPageById($uuid);
|
|
|
|
$entry = [
|
|
'id' => $page['id'],
|
|
'uuid' => $page['uuid'],
|
|
'title' => $page['title'],
|
|
'feature' => $page['feature'],
|
|
'path' => $page['path'],
|
|
'layout' => $page['layout'],
|
|
'tags' => $page['tags'],
|
|
'author' => $page['author'],
|
|
'created' => $page['created'],
|
|
'updated' => $page['updated'],
|
|
'deleted' => $page['deleted'],
|
|
'menu' => $page['menu'],
|
|
'featured' => $page['featured'],
|
|
'published' => $page['published'],
|
|
'slug' => $page['slug'],
|
|
'content' => StringTools::sanitizeContent($page['content']),
|
|
];
|
|
$result = $entry;
|
|
break;
|
|
case 'tags':
|
|
$result = Settings::getTags();
|
|
break;
|
|
default:
|
|
$result = [
|
|
'message' => "Hm, no task. That's unfortunate",
|
|
'type' => 'TASK_NONE',
|
|
];
|
|
break;
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
public static function handlePageTask($request, $args)
|
|
{
|
|
$task = $args['fourth'];
|
|
switch ($task) {
|
|
case 'delete':
|
|
case 'create':
|
|
case 'write':
|
|
$body = json_decode(file_get_contents("php://input"), true);
|
|
$passed = true;
|
|
if (!isset($body['form_token'])) {
|
|
$result = [
|
|
'message' => 'No form token. Not good, sport.',
|
|
'type' => 'TASK_FORM_AUTH',
|
|
];
|
|
} else {
|
|
if ($body['form_token'] == Session::get('form_token')) {
|
|
$keys = [
|
|
'id',
|
|
'uuid',
|
|
'layout',
|
|
'current_title',
|
|
'content',
|
|
'title',
|
|
'created',
|
|
'slug',
|
|
'tags',
|
|
'menu',
|
|
'featured',
|
|
'published',
|
|
'form_token',
|
|
'imageList',
|
|
"fileList",
|
|
"remote"
|
|
];
|
|
|
|
foreach ($body as $key => $item) {
|
|
if (!in_array($key, $keys)) {
|
|
//found unnecessary key, so reject submission
|
|
var_dump($key);
|
|
$passed = false;
|
|
}
|
|
}
|
|
if ($passed) {
|
|
$result = (new Book())->editPage($task, $request);
|
|
} else {
|
|
$result = [
|
|
'message' => 'Unneccessary key found. Post not authorized, slick.',
|
|
'type' => 'TASK_FORM_AUTH',
|
|
];
|
|
}
|
|
} else {
|
|
$result = [
|
|
'message' => 'Form token, auth failed. Uh oh.',
|
|
'type' => 'TASK_FORM_AUTH',
|
|
];
|
|
}
|
|
}
|
|
|
|
break;
|
|
case 'add-entry-image':
|
|
$result = ImagesAPI::uploadImage($request);
|
|
break;
|
|
default:
|
|
$result = [
|
|
'message' => "Hm, no task. That's unfortunate",
|
|
'type' => 'TASK_NONE',
|
|
];
|
|
break;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
}
|