|
|
@ -2,12 +2,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
namespace brain\data;
|
|
|
|
namespace brain\data;
|
|
|
|
|
|
|
|
|
|
|
|
use brain\data\Contents;
|
|
|
|
|
|
|
|
use brain\data\Settings;
|
|
|
|
|
|
|
|
use brain\utility\DocTools;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use function _\filter;
|
|
|
|
use function _\filter;
|
|
|
|
use function _\find;
|
|
|
|
use function _\find;
|
|
|
|
|
|
|
|
use brain\utility\DocTools;
|
|
|
|
|
|
|
|
use brain\utility\FileUploader;
|
|
|
|
|
|
|
|
use brain\utility\StringTools;
|
|
|
|
|
|
|
|
|
|
|
|
class Book
|
|
|
|
class Book
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -18,7 +17,8 @@ class Book
|
|
|
|
public function findPageById(string $uuid)
|
|
|
|
public function findPageById(string $uuid)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$content = $this->getContents();
|
|
|
|
$content = $this->getContents();
|
|
|
|
$page = find($content, ["uuid" => $uuid]);
|
|
|
|
$page = find($content, ['uuid' => $uuid]);
|
|
|
|
|
|
|
|
|
|
|
|
return $page;
|
|
|
|
return $page;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -26,9 +26,9 @@ class Book
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$content = $this->getContents();
|
|
|
|
$content = $this->getContents();
|
|
|
|
if (isset($slug)) {
|
|
|
|
if (isset($slug)) {
|
|
|
|
$page = find($content, ["slug" => $slug]);
|
|
|
|
$page = find($content, ['slug' => $slug]);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$page = find($content, ["layout" => "index"]);
|
|
|
|
$page = find($content, ['layout' => 'index']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $page;
|
|
|
|
return $page;
|
|
|
@ -37,7 +37,7 @@ class Book
|
|
|
|
public function editPage($task, $request)
|
|
|
|
public function editPage($task, $request)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$content = $this->getContents();
|
|
|
|
$content = $this->getContents();
|
|
|
|
if ($task == "delete") {
|
|
|
|
if ($task == 'delete') {
|
|
|
|
// $parsed = json_decode(file_get_contents("php://input"), true);
|
|
|
|
// $parsed = json_decode(file_get_contents("php://input"), true);
|
|
|
|
// $body = find($content, ["uuid" => $parsed["id"]]);
|
|
|
|
// $body = find($content, ["uuid" => $parsed["id"]]);
|
|
|
|
$body = $request->getParsedBody();
|
|
|
|
$body = $request->getParsedBody();
|
|
|
@ -45,70 +45,70 @@ class Book
|
|
|
|
$body = $request->getParsedBody();
|
|
|
|
$body = $request->getParsedBody();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$page = find($content, ["uuid" => $body["uuid"]]);
|
|
|
|
$page = find($content, ['uuid' => $body['uuid']]);
|
|
|
|
$files = $request->getUploadedFiles();
|
|
|
|
$files = $request->getUploadedFiles();
|
|
|
|
|
|
|
|
|
|
|
|
$member = Session::get("member");
|
|
|
|
$member = Session::get('member');
|
|
|
|
|
|
|
|
|
|
|
|
if ($task != "create") {
|
|
|
|
if ($task != 'create') {
|
|
|
|
$path =
|
|
|
|
$path =
|
|
|
|
date("Y", date($page["rawCreated"])) .
|
|
|
|
date('Y', date($page['rawCreated'])).
|
|
|
|
"/" .
|
|
|
|
'/'.
|
|
|
|
date("m", date($page["rawCreated"]));
|
|
|
|
date('m', date($page['rawCreated']));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$path = date("Y") . "/" . date("m");
|
|
|
|
$path = date('Y').'/'.date('m');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$page_feature = '';
|
|
|
|
$page_feature = '';
|
|
|
|
$page_files = '';
|
|
|
|
$page_files = '';
|
|
|
|
|
|
|
|
|
|
|
|
if (isset($files["page_files"])) {
|
|
|
|
if (isset($files['page_files'])) {
|
|
|
|
$imageList = "";
|
|
|
|
$imageList = '';
|
|
|
|
$fileList = "";
|
|
|
|
$fileList = '';
|
|
|
|
// var_dump($files["page_files"] );
|
|
|
|
// var_dump($files["page_files"] );
|
|
|
|
foreach ($files["page_files"] as $file) {
|
|
|
|
foreach ($files['page_files'] as $file) {
|
|
|
|
$type = $file->getClientMediaType();
|
|
|
|
$type = $file->getClientMediaType();
|
|
|
|
switch ($type) {
|
|
|
|
switch ($type) {
|
|
|
|
case "image/jpeg":
|
|
|
|
case 'image/jpeg':
|
|
|
|
case "image/png":
|
|
|
|
case 'image/png':
|
|
|
|
case "image/gif":
|
|
|
|
case 'image/gif':
|
|
|
|
case "image/svg":
|
|
|
|
case 'image/svg':
|
|
|
|
$imagesPath = "/assets/images/blog/" . $path . "/";
|
|
|
|
$imagesPath = '/assets/images/blog/'.$path.'/';
|
|
|
|
$imageList =
|
|
|
|
$imageList =
|
|
|
|
$imageList . $imagesPath . urlencode($file->getClientFileName()) . ", ";
|
|
|
|
$imageList.$imagesPath.urlencode($file->getClientFileName()).', ';
|
|
|
|
|
|
|
|
|
|
|
|
FileUploader::uploadFile(
|
|
|
|
FileUploader::uploadFile(
|
|
|
|
"../public/assets/images/blog/" . $path . "/",
|
|
|
|
'../public/assets/images/blog/'.$path.'/',
|
|
|
|
$file
|
|
|
|
$file
|
|
|
|
);
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case "video/mp4":
|
|
|
|
case 'video/mp4':
|
|
|
|
$videosPath = "/assets/video/blog/" . $path . "/";
|
|
|
|
$videosPath = '/assets/video/blog/'.$path.'/';
|
|
|
|
$imageList =
|
|
|
|
$imageList =
|
|
|
|
$imageList . $videosPath . urlencode($file->getClientFileName()) . ", ";
|
|
|
|
$imageList.$videosPath.urlencode($file->getClientFileName()).', ';
|
|
|
|
|
|
|
|
|
|
|
|
FileUploader::uploadFile(
|
|
|
|
FileUploader::uploadFile(
|
|
|
|
"../public/assets/video/blog/" . $path . "/",
|
|
|
|
'../public/assets/video/blog/'.$path.'/',
|
|
|
|
$file
|
|
|
|
$file
|
|
|
|
);
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case "audio/mpeg":
|
|
|
|
case 'audio/mpeg':
|
|
|
|
$soundPath = "/assets/sound/blog/" . $path . "/";
|
|
|
|
$soundPath = '/assets/sound/blog/'.$path.'/';
|
|
|
|
$fileList = $fileList . $soundPath . urlencode($file->getClientFileName()) . ", ";
|
|
|
|
$fileList = $fileList.$soundPath.urlencode($file->getClientFileName()).', ';
|
|
|
|
|
|
|
|
|
|
|
|
FileUploader::uploadFile(
|
|
|
|
FileUploader::uploadFile(
|
|
|
|
"../public/assets/sound/blog/" . $path . "/",
|
|
|
|
'../public/assets/sound/blog/'.$path.'/',
|
|
|
|
$file
|
|
|
|
$file
|
|
|
|
);
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'application/pdf':
|
|
|
|
case 'application/pdf':
|
|
|
|
case 'text/plain':
|
|
|
|
case 'text/plain':
|
|
|
|
case 'text/rtf':
|
|
|
|
case 'text/rtf':
|
|
|
|
$docPath = "/assets/docs/blog/" . $path . "/";
|
|
|
|
$docPath = '/assets/docs/blog/'.$path.'/';
|
|
|
|
$fileList = $fileList . $docPath . urlencode($file->getClientFileName()) . ", ";
|
|
|
|
$fileList = $fileList.$docPath.urlencode($file->getClientFileName()).', ';
|
|
|
|
|
|
|
|
|
|
|
|
FileUploader::uploadFile(
|
|
|
|
FileUploader::uploadFile(
|
|
|
|
"../public/assets/docs/blog/" . $path . "/",
|
|
|
|
'../public/assets/docs/blog/'.$path.'/',
|
|
|
|
$file
|
|
|
|
$file
|
|
|
|
);
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@ -118,48 +118,48 @@ class Book
|
|
|
|
$page_files = $fileList;
|
|
|
|
$page_files = $fileList;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// if no files, just reset string from page object
|
|
|
|
// if no files, just reset string from page object
|
|
|
|
$page_feature = $page["feature"];
|
|
|
|
$page_feature = $page['feature'];
|
|
|
|
$page_files = $page["files"];
|
|
|
|
$page_files = $page['files'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($task == "delete") {
|
|
|
|
if ($task == 'delete') {
|
|
|
|
$deleted = "true";
|
|
|
|
$deleted = 'true';
|
|
|
|
$body["menu"] = "false";
|
|
|
|
$body['menu'] = 'false';
|
|
|
|
$body["published"] = "false";
|
|
|
|
$body['published'] = 'false';
|
|
|
|
$body["featured"] = "false";
|
|
|
|
$body['featured'] = 'false';
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$deleted = isset($page["deleted"]) ? $page["deleted"] : "false";
|
|
|
|
$deleted = isset($page['deleted']) ? $page['deleted'] : 'false';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$created =
|
|
|
|
$created =
|
|
|
|
$task != "create"
|
|
|
|
$task != 'create'
|
|
|
|
? new \Moment\Moment($page["rawCreated"])
|
|
|
|
? new \Moment\Moment($page['rawCreated'])
|
|
|
|
: new \Moment\Moment();
|
|
|
|
: new \Moment\Moment();
|
|
|
|
$updated = new \Moment\Moment();
|
|
|
|
$updated = new \Moment\Moment();
|
|
|
|
|
|
|
|
|
|
|
|
// grab current index from settings and update
|
|
|
|
// grab current index from settings and update
|
|
|
|
$id = $task != "create" ? $body["id"] : Settings::getCurrentIndex();
|
|
|
|
$id = $task != 'create' ? $body['id'] : Settings::getCurrentIndex();
|
|
|
|
$uuid = $task != "create" ? $body["uuid"] : StringTools::createUUID();
|
|
|
|
$uuid = $task != 'create' ? $body['uuid'] : StringTools::createUUID();
|
|
|
|
// now that variables are done, set to body object and then convert to markdown to save
|
|
|
|
// now that variables are done, set to body object and then convert to markdown to save
|
|
|
|
|
|
|
|
|
|
|
|
$body["id"] = $id;
|
|
|
|
$body['id'] = $id;
|
|
|
|
$body["uuid"] = $uuid;
|
|
|
|
$body['uuid'] = $uuid;
|
|
|
|
$body["feature"] = $page_feature;
|
|
|
|
$body['feature'] = $page_feature;
|
|
|
|
$body["files"] = $page_files;
|
|
|
|
$body['files'] = $page_files;
|
|
|
|
$body["path"] = $path;
|
|
|
|
$body['path'] = $path;
|
|
|
|
$body["author"] = $member["handle"];
|
|
|
|
$body['author'] = $member['handle'];
|
|
|
|
$body["created"] = $created->format("Y-m-d\TH:i:sP");
|
|
|
|
$body['created'] = $created->format("Y-m-d\TH:i:sP");
|
|
|
|
$body["updated"] = $updated->format("Y-m-d\TH:i:sP");
|
|
|
|
$body['updated'] = $updated->format("Y-m-d\TH:i:sP");
|
|
|
|
$body["deleted"] = $deleted;
|
|
|
|
$body['deleted'] = $deleted;
|
|
|
|
|
|
|
|
|
|
|
|
$write = DocTools::objectToMD($body);
|
|
|
|
$write = DocTools::objectToMD($body);
|
|
|
|
|
|
|
|
|
|
|
|
// if layout is index, change path to file
|
|
|
|
// if layout is index, change path to file
|
|
|
|
|
|
|
|
|
|
|
|
if ($body["layout"] == "index") {
|
|
|
|
if ($body['layout'] == 'index') {
|
|
|
|
$writePath = "../content/pages/start/index.md";
|
|
|
|
$writePath = '../content/pages/start/index.md';
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$writePath = "../content/pages/" . $path . "/" . $body["slug"] . ".md";
|
|
|
|
$writePath = '../content/pages/'.$path.'/'.$body['slug'].'.md';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$status = DocTools::writePages($task, $path, $writePath, $write);
|
|
|
|
$status = DocTools::writePages($task, $path, $writePath, $write);
|
|
|
@ -167,25 +167,25 @@ class Book
|
|
|
|
if ($status) {
|
|
|
|
if ($status) {
|
|
|
|
$config = new Settings();
|
|
|
|
$config = new Settings();
|
|
|
|
$settings = $config->getSettings();
|
|
|
|
$settings = $config->getSettings();
|
|
|
|
$message = "";
|
|
|
|
$message = '';
|
|
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
if (
|
|
|
|
$settings["global"]["renderOnSave"] == "true" &&
|
|
|
|
$settings['global']['renderOnSave'] == 'true' &&
|
|
|
|
$settings["global"]["dynamicRender"] == "false"
|
|
|
|
$settings['global']['dynamicRender'] == 'false'
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
$render = new Render();
|
|
|
|
$render = new Render();
|
|
|
|
$render->renderTags();
|
|
|
|
$render->renderTags();
|
|
|
|
$render->renderArchive();
|
|
|
|
$render->renderArchive();
|
|
|
|
$render->renderPages();
|
|
|
|
$render->renderPages();
|
|
|
|
$message = "Filed edited and rendered. NOICE.";
|
|
|
|
$message = 'Filed edited and rendered. NOICE.';
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$message = "File edited. Nice work";
|
|
|
|
$message = 'File edited. Nice work';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
$response = [
|
|
|
|
"message" => $message,
|
|
|
|
'message' => $message,
|
|
|
|
"type" => $task == "write" ? "postUpdated" : "postAdded",
|
|
|
|
'type' => $task == 'write' ? 'postUpdated' : 'postAdded',
|
|
|
|
"id" => $uuid,
|
|
|
|
'id' => $uuid,
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: When form submission is successful, make new form token
|
|
|
|
// TODO: When form submission is successful, make new form token
|
|
|
@ -194,18 +194,18 @@ class Book
|
|
|
|
// Session::set("form_token", $form_token);
|
|
|
|
// Session::set("form_token", $form_token);
|
|
|
|
|
|
|
|
|
|
|
|
// once saved, update menu
|
|
|
|
// once saved, update menu
|
|
|
|
$body["path"] = $path;
|
|
|
|
$body['path'] = $path;
|
|
|
|
Settings::updateMenu($body);
|
|
|
|
Settings::updateMenu($body);
|
|
|
|
Settings::updateTags();
|
|
|
|
Settings::updateTags();
|
|
|
|
// if new page added, update current index in Settings file
|
|
|
|
// if new page added, update current index in Settings file
|
|
|
|
if ($task == "create") {
|
|
|
|
if ($task == 'create') {
|
|
|
|
Settings::updateIndex();
|
|
|
|
Settings::updateIndex();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$response = [
|
|
|
|
$response = [
|
|
|
|
"message" => "Uh oh. File save problem. Don't panic",
|
|
|
|
'message' => "Uh oh. File save problem. Don't panic",
|
|
|
|
"type" => "postError",
|
|
|
|
'type' => 'postError',
|
|
|
|
"id" => $uuid,
|
|
|
|
'id' => $uuid,
|
|
|
|
];
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -217,22 +217,22 @@ class Book
|
|
|
|
$content = $this->getContents();
|
|
|
|
$content = $this->getContents();
|
|
|
|
|
|
|
|
|
|
|
|
$published = filter($content, function ($item) {
|
|
|
|
$published = filter($content, function ($item) {
|
|
|
|
return $item["published"] == true && $item["deleted"] == false;
|
|
|
|
return $item['published'] == true && $item['deleted'] == false;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$deleted = filter($content, function ($item) {
|
|
|
|
$deleted = filter($content, function ($item) {
|
|
|
|
return $item["deleted"] == true;
|
|
|
|
return $item['deleted'] == true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// $all = $content;
|
|
|
|
// $all = $content;
|
|
|
|
$all = filter($content, function ($item) {
|
|
|
|
$all = filter($content, function ($item) {
|
|
|
|
return $item["deleted"] == false;
|
|
|
|
return $item['deleted'] == false;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$filter = isset($sort) ? $sort : "all";
|
|
|
|
$filter = isset($sort) ? $sort : 'all';
|
|
|
|
switch ($filter) {
|
|
|
|
switch ($filter) {
|
|
|
|
case "published":
|
|
|
|
case 'published':
|
|
|
|
$filtered = $published;
|
|
|
|
$filtered = $published;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case "deleted":
|
|
|
|
case 'deleted':
|
|
|
|
$filtered = $deleted;
|
|
|
|
$filtered = $deleted;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
@ -251,7 +251,7 @@ class Book
|
|
|
|
if ($range != 0) {
|
|
|
|
if ($range != 0) {
|
|
|
|
$range = $range + 1;
|
|
|
|
$range = $range + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for ($i = 0; $i <= $limit; $i++) {
|
|
|
|
for ($i = 0; $i <= $limit; ++$i) {
|
|
|
|
if (isset($filtered[$i + $range])) {
|
|
|
|
if (isset($filtered[$i + $range])) {
|
|
|
|
array_push($folder, $filtered[$i + $range]);
|
|
|
|
array_push($folder, $filtered[$i + $range]);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -271,26 +271,28 @@ class Book
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
return [
|
|
|
|
"pages" => $folder,
|
|
|
|
'pages' => $folder,
|
|
|
|
"numOfPages" => $numOfPages,
|
|
|
|
'numOfPages' => $numOfPages,
|
|
|
|
"entryCount" => count($filtered),
|
|
|
|
'entryCount' => count($filtered),
|
|
|
|
"paginate" => [
|
|
|
|
'paginate' => [
|
|
|
|
"sort" => $sort,
|
|
|
|
'sort' => $sort,
|
|
|
|
"nextPage" => $next,
|
|
|
|
'nextPage' => $next,
|
|
|
|
"prevPage" => $prev,
|
|
|
|
'prevPage' => $prev,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
"stats" => [
|
|
|
|
'stats' => [
|
|
|
|
"all" => count($all),
|
|
|
|
'all' => count($all),
|
|
|
|
"published" => count($published),
|
|
|
|
'published' => count($published),
|
|
|
|
"deleted" => count($deleted),
|
|
|
|
'deleted' => count($deleted),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getContents()
|
|
|
|
public function getContents()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// test new contents data class
|
|
|
|
// test new contents data class
|
|
|
|
// $new = (new Contents("../content/pages"))->getAll();
|
|
|
|
// $new = (new Contents("../content/pages"))->getAll();
|
|
|
|
$contents = (new Contents("../content/pages"))->getAll();
|
|
|
|
$contents = (new Contents('../content/pages'))->getAll();
|
|
|
|
|
|
|
|
|
|
|
|
return $contents;
|
|
|
|
return $contents;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|