forked from projects/fipamo
added remaining upload types, updated templates for new file types
This commit is contained in:
parent
523b611ac5
commit
2210e39aee
11 changed files with 696 additions and 551 deletions
|
@ -110,7 +110,10 @@ class DashControl
|
||||||
}
|
}
|
||||||
|
|
||||||
$imageList = explode(",", $page["feature"]);
|
$imageList = explode(",", $page["feature"]);
|
||||||
|
$fileList = explode(",", $page["files"]);
|
||||||
|
|
||||||
$images = [];
|
$images = [];
|
||||||
|
$files = [];
|
||||||
foreach ($imageList as $item) {
|
foreach ($imageList as $item) {
|
||||||
$image = trim($item);
|
$image = trim($item);
|
||||||
if ($item != null || $item != "") {
|
if ($item != null || $item != "") {
|
||||||
|
@ -118,6 +121,13 @@ class DashControl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ($fileList as $item) {
|
||||||
|
$file = trim($item);
|
||||||
|
if ($item != null || $item != "") {
|
||||||
|
array_push($files, $item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$pageOptions = [
|
$pageOptions = [
|
||||||
"title" => "Fipamo | Edit Page",
|
"title" => "Fipamo | Edit Page",
|
||||||
"page" => $page,
|
"page" => $page,
|
||||||
|
@ -125,6 +135,7 @@ class DashControl
|
||||||
"token" => Session::get("form_token"),
|
"token" => Session::get("form_token"),
|
||||||
"status" => Session::active(),
|
"status" => Session::active(),
|
||||||
"images" => $images,
|
"images" => $images,
|
||||||
|
"files"=>$files,
|
||||||
"views" => $views,
|
"views" => $views,
|
||||||
];
|
];
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -5,286 +5,314 @@ use function _\find;
|
||||||
|
|
||||||
class Book
|
class Book
|
||||||
{
|
{
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
}
|
|
||||||
|
|
||||||
public function findPageById(string $uuid)
|
|
||||||
{
|
|
||||||
$content = $this->getContents();
|
|
||||||
$page = find($content, ["uuid" => $uuid]);
|
|
||||||
return $page;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function findPageBySlug(string $slug = null)
|
|
||||||
{
|
|
||||||
$content = $this->getContents();
|
|
||||||
if (isset($slug)) {
|
|
||||||
$page = find($content, ["slug" => $slug]);
|
|
||||||
} else {
|
|
||||||
$page = find($content, ["layout" => "index"]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $page;
|
public function findPageById(string $uuid)
|
||||||
}
|
{
|
||||||
|
$content = $this->getContents();
|
||||||
public function editPage($task, $request)
|
$page = find($content, ["uuid" => $uuid]);
|
||||||
{
|
return $page;
|
||||||
$content = $this->getContents();
|
|
||||||
if ($task == "delete") {
|
|
||||||
//$parsed = json_decode(file_get_contents("php://input"), true);
|
|
||||||
//$body = find($content, ["uuid" => $parsed["id"]]);
|
|
||||||
$body = $request->getParsedBody();
|
|
||||||
} else {
|
|
||||||
$body = $request->getParsedBody();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$page = find($content, ["uuid" => $body["uuid"]]);
|
public function findPageBySlug(string $slug = null)
|
||||||
$files = $request->getUploadedFiles();
|
{
|
||||||
|
$content = $this->getContents();
|
||||||
$member = Session::get("member");
|
if (isset($slug)) {
|
||||||
|
$page = find($content, ["slug" => $slug]);
|
||||||
if ($task != "create") {
|
} else {
|
||||||
$path =
|
$page = find($content, ["layout" => "index"]);
|
||||||
date("Y", date($page["rawCreated"])) .
|
|
||||||
"/" .
|
|
||||||
date("m", date($page["rawCreated"]));
|
|
||||||
} else {
|
|
||||||
$path = date("Y") . "/" . date("m");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($files)) {
|
|
||||||
//var_dump($files);
|
|
||||||
if ($task != "create") {
|
|
||||||
$imageList = "";
|
|
||||||
//var_dump($files["page_files"] );
|
|
||||||
foreach ($files["page_files"] as $file) {
|
|
||||||
$type = $file->getClientMediaType();
|
|
||||||
switch ($type) {
|
|
||||||
case "image/jpeg":
|
|
||||||
case "image/png":
|
|
||||||
case "image/gif":
|
|
||||||
case "image/svg":
|
|
||||||
$imagesPath = "/assets/images/blog/" . $path . "/";
|
|
||||||
$imageList =
|
|
||||||
$imageList . $imagesPath . urlencode($file->getClientFileName()). ", ";
|
|
||||||
|
|
||||||
FileUploader::uploadFile(
|
|
||||||
"../public/assets/images/blog/" . $path . "/",
|
|
||||||
$file
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
case "video/mp4":
|
|
||||||
$videosPath = "/assets/video/blog/" . $path . "/";
|
|
||||||
$imageList =
|
|
||||||
$imageList . $videosPath . urlencode($file->getClientFileName()) . ", ";
|
|
||||||
|
|
||||||
FileUploader::uploadFile(
|
|
||||||
"../public/assets/video/blog/" . $path . "/",
|
|
||||||
$file
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$feature = $imageList;
|
|
||||||
//var_dump($feature);
|
return $page;
|
||||||
//return ["message" => "JUST DEBUGGING"];
|
|
||||||
} else {
|
|
||||||
$feature =
|
|
||||||
"/assets/images/blog/" .
|
|
||||||
$path .
|
|
||||||
"/" .
|
|
||||||
$image["feature_image"]->getClientFileName();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (isset($body["feature_image"])) {
|
|
||||||
$url = explode("/", $body["feature_image"]);
|
|
||||||
$feature =
|
|
||||||
"/" .
|
|
||||||
$url[3] .
|
|
||||||
"/" .
|
|
||||||
$url[4] .
|
|
||||||
"/" .
|
|
||||||
$url[5] .
|
|
||||||
"/" .
|
|
||||||
$url[6] .
|
|
||||||
"/" .
|
|
||||||
$url[7] .
|
|
||||||
"/" .
|
|
||||||
$url[8];
|
|
||||||
} else {
|
|
||||||
$task == "create" ? ($feature = "") : ($feature = $body["feature"]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($task == "delete") {
|
public function editPage($task, $request)
|
||||||
$deleted = "true";
|
{
|
||||||
$body["menu"] = "false";
|
$content = $this->getContents();
|
||||||
$body["published"] = "false";
|
if ($task == "delete") {
|
||||||
$body["featured"] = "false";
|
//$parsed = json_decode(file_get_contents("php://input"), true);
|
||||||
} else {
|
//$body = find($content, ["uuid" => $parsed["id"]]);
|
||||||
$deleted = isset($page["deleted"]) ? $page["deleted"] : "false";
|
$body = $request->getParsedBody();
|
||||||
}
|
} else {
|
||||||
|
$body = $request->getParsedBody();
|
||||||
|
}
|
||||||
|
|
||||||
$created =
|
$page = find($content, ["uuid" => $body["uuid"]]);
|
||||||
$task != "create"
|
$files = $request->getUploadedFiles();
|
||||||
|
|
||||||
|
$member = Session::get("member");
|
||||||
|
|
||||||
|
if ($task != "create") {
|
||||||
|
$path =
|
||||||
|
date("Y", date($page["rawCreated"])) .
|
||||||
|
"/" .
|
||||||
|
date("m", date($page["rawCreated"]));
|
||||||
|
} else {
|
||||||
|
$path = date("Y") . "/" . date("m");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($files)) {
|
||||||
|
//var_dump($files);
|
||||||
|
if ($task != "create") {
|
||||||
|
$imageList = "";
|
||||||
|
$fileList = "";
|
||||||
|
//var_dump($files["page_files"] );
|
||||||
|
foreach ($files["page_files"] as $file) {
|
||||||
|
$type = $file->getClientMediaType();
|
||||||
|
switch ($type) {
|
||||||
|
case "image/jpeg":
|
||||||
|
case "image/png":
|
||||||
|
case "image/gif":
|
||||||
|
case "image/svg":
|
||||||
|
$imagesPath = "/assets/images/blog/" . $path . "/";
|
||||||
|
$imageList =
|
||||||
|
$imageList . $imagesPath . urlencode($file->getClientFileName()). ", ";
|
||||||
|
|
||||||
|
FileUploader::uploadFile(
|
||||||
|
"../public/assets/images/blog/" . $path . "/",
|
||||||
|
$file
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case "video/mp4":
|
||||||
|
$videosPath = "/assets/video/blog/" . $path . "/";
|
||||||
|
$imageList =
|
||||||
|
$imageList . $videosPath . urlencode($file->getClientFileName()) . ", ";
|
||||||
|
|
||||||
|
FileUploader::uploadFile(
|
||||||
|
"../public/assets/video/blog/" . $path . "/",
|
||||||
|
$file
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case "audio/mpeg":
|
||||||
|
$soundPath = "/assets/sound/blog/" . $path . "/";
|
||||||
|
$fileList = $fileList . $soundPath . urlencode($file->getClientFileName()). ", ";
|
||||||
|
|
||||||
|
FileUploader::uploadFile(
|
||||||
|
"../public/assets/sound/blog/" . $path . "/",
|
||||||
|
$file
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case 'application/pdf':
|
||||||
|
case 'text/plain':
|
||||||
|
case 'text/rtf':
|
||||||
|
$docPath = "/assets/docs/blog/" . $path . "/";
|
||||||
|
$fileList = $fileList . $docPath . urlencode($file->getClientFileName()). ", ";
|
||||||
|
|
||||||
|
FileUploader::uploadFile(
|
||||||
|
"../public/assets/docs/blog/" . $path . "/",
|
||||||
|
$file
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$feature = $imageList;
|
||||||
|
$files = $fileList;
|
||||||
|
//var_dump($feature);
|
||||||
|
//return ["message" => "JUST DEBUGGING"];
|
||||||
|
} else {
|
||||||
|
//if creating a new page, from file payload and set $feature and $files
|
||||||
|
/*
|
||||||
|
$feature =
|
||||||
|
"/assets/images/blog/" .
|
||||||
|
$path .
|
||||||
|
"/" .
|
||||||
|
$image["feature_image"]->getClientFileName();
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//if no files, do no file stuff
|
||||||
|
/*
|
||||||
|
if (isset($body["feature_image"])) {
|
||||||
|
$url = explode("/", $body["feature_image"]);
|
||||||
|
$feature =
|
||||||
|
"/" .
|
||||||
|
$url[3] .
|
||||||
|
"/" .
|
||||||
|
$url[4] .
|
||||||
|
"/" .
|
||||||
|
$url[5] .
|
||||||
|
"/" .
|
||||||
|
$url[6] .
|
||||||
|
"/" .
|
||||||
|
$url[7] .
|
||||||
|
"/" .
|
||||||
|
$url[8];
|
||||||
|
} else {
|
||||||
|
//$task == "create" ? ($feature = "") : ($feature = $body["feature"]);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($task == "delete") {
|
||||||
|
$deleted = "true";
|
||||||
|
$body["menu"] = "false";
|
||||||
|
$body["published"] = "false";
|
||||||
|
$body["featured"] = "false";
|
||||||
|
} else {
|
||||||
|
$deleted = isset($page["deleted"]) ? $page["deleted"] : "false";
|
||||||
|
}
|
||||||
|
|
||||||
|
$created =
|
||||||
|
$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"] = $feature;
|
$body["feature"] = $feature;
|
||||||
$body["path"] = $path;
|
$body["files"] = $files;
|
||||||
$body["author"] = $member["handle"];
|
$body["path"] = $path;
|
||||||
$body["created"] = $created->format("Y-m-d\TH:i:sP");
|
$body["author"] = $member["handle"];
|
||||||
$body["updated"] = $updated->format("Y-m-d\TH:i:sP");
|
$body["created"] = $created->format("Y-m-d\TH:i:sP");
|
||||||
$body["deleted"] = $deleted;
|
$body["updated"] = $updated->format("Y-m-d\TH:i:sP");
|
||||||
|
$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 {
|
|
||||||
$writePath = "../content/pages/" . $path . "/" . $body["slug"] . ".md";
|
|
||||||
}
|
|
||||||
|
|
||||||
$status = DocTools::writePages($task, $path, $writePath, $write);
|
|
||||||
|
|
||||||
if ($status) {
|
|
||||||
$config = new Settings();
|
|
||||||
$settings = $config->getSettings();
|
|
||||||
$message = "";
|
|
||||||
|
|
||||||
if (
|
|
||||||
$settings["global"]["renderOnSave"] == "true" &&
|
|
||||||
$settings["global"]["dynamicRender"] == "false"
|
|
||||||
) {
|
|
||||||
$render = new Render();
|
|
||||||
$render->renderTags();
|
|
||||||
$render->renderArchive();
|
|
||||||
$render->renderPages();
|
|
||||||
$message = "Filed edited and rendered. NOICE.";
|
|
||||||
} else {
|
|
||||||
$message = "File edited. Nice work";
|
|
||||||
}
|
|
||||||
|
|
||||||
$response = [
|
|
||||||
"message" => $message,
|
|
||||||
"type" => $task == "write" ? "postUpdated" : "postAdded",
|
|
||||||
"id" => $uuid,
|
|
||||||
];
|
|
||||||
|
|
||||||
//TODO: When form submission is successful, make new form token
|
|
||||||
//Session token doesn't reset on the front end, so turning this off for now
|
|
||||||
//$form_token = md5(uniqid(microtime(), true));
|
|
||||||
//Session::set("form_token", $form_token);
|
|
||||||
|
|
||||||
//once saved, update menu
|
|
||||||
$body["path"] = $path;
|
|
||||||
Settings::updateMenu($body);
|
|
||||||
Settings::updateTags();
|
|
||||||
//if new page added, update current index in Settings file
|
|
||||||
if ($task == "create") {
|
|
||||||
Settings::updateIndex();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$response = [
|
|
||||||
"message" => "Uh oh. File save problem. Don't panic",
|
|
||||||
"type" => "postError",
|
|
||||||
"id" => $uuid,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getPages(int $page, int $limit, string $sort = null)
|
|
||||||
{
|
|
||||||
$content = $this->getContents();
|
|
||||||
|
|
||||||
$published = filter($content, function ($item) {
|
|
||||||
return $item["published"] == true && $item["deleted"] == false;
|
|
||||||
});
|
|
||||||
$deleted = filter($content, function ($item) {
|
|
||||||
return $item["deleted"] == true;
|
|
||||||
});
|
|
||||||
|
|
||||||
//$all = $content;
|
|
||||||
$all = filter($content, function ($item) {
|
|
||||||
return $item["deleted"] == false;
|
|
||||||
});
|
|
||||||
$filter = isset($sort) ? $sort : "all";
|
|
||||||
switch ($filter) {
|
|
||||||
case "published":
|
|
||||||
$filtered = $published;
|
|
||||||
break;
|
|
||||||
case "deleted":
|
|
||||||
$filtered = $deleted;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$filtered = $all;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$numOfPages = ceil(count($filtered) / ($limit + 1));
|
|
||||||
$folder = [];
|
|
||||||
|
|
||||||
if (count($filtered) != 0) {
|
|
||||||
if (count($filtered) < $limit) {
|
|
||||||
$limit = count($filtered) - 1;
|
|
||||||
}
|
|
||||||
$range = $page * $limit - $limit;
|
|
||||||
|
|
||||||
if ($range != 0) {
|
|
||||||
$range = $range + 1;
|
|
||||||
}
|
|
||||||
for ($i = 0; $i <= $limit; $i++) {
|
|
||||||
if (isset($filtered[$i + $range])) {
|
|
||||||
array_push($folder, $filtered[$i + $range]);
|
|
||||||
} else {
|
} else {
|
||||||
//chill out
|
$writePath = "../content/pages/" . $path . "/" . $body["slug"] . ".md";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
$status = DocTools::writePages($task, $path, $writePath, $write);
|
||||||
|
|
||||||
|
if ($status) {
|
||||||
|
$config = new Settings();
|
||||||
|
$settings = $config->getSettings();
|
||||||
|
$message = "";
|
||||||
|
|
||||||
|
if ($settings["global"]["renderOnSave"] == "true" &&
|
||||||
|
$settings["global"]["dynamicRender"] == "false"
|
||||||
|
) {
|
||||||
|
$render = new Render();
|
||||||
|
$render->renderTags();
|
||||||
|
$render->renderArchive();
|
||||||
|
$render->renderPages();
|
||||||
|
$message = "Filed edited and rendered. NOICE.";
|
||||||
|
} else {
|
||||||
|
$message = "File edited. Nice work";
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
"message" => $message,
|
||||||
|
"type" => $task == "write" ? "postUpdated" : "postAdded",
|
||||||
|
"id" => $uuid,
|
||||||
|
];
|
||||||
|
|
||||||
|
//TODO: When form submission is successful, make new form token
|
||||||
|
//Session token doesn't reset on the front end, so turning this off for now
|
||||||
|
//$form_token = md5(uniqid(microtime(), true));
|
||||||
|
//Session::set("form_token", $form_token);
|
||||||
|
|
||||||
|
//once saved, update menu
|
||||||
|
$body["path"] = $path;
|
||||||
|
Settings::updateMenu($body);
|
||||||
|
Settings::updateTags();
|
||||||
|
//if new page added, update current index in Settings file
|
||||||
|
if ($task == "create") {
|
||||||
|
Settings::updateIndex();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$response = [
|
||||||
|
"message" => "Uh oh. File save problem. Don't panic",
|
||||||
|
"type" => "postError",
|
||||||
|
"id" => $uuid,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
$prev = $page - 1;
|
public function getPages(int $page, int $limit, string $sort = null)
|
||||||
if ($prev <= 0) {
|
{
|
||||||
$prev = $numOfPages;
|
$content = $this->getContents();
|
||||||
}
|
|
||||||
|
|
||||||
$next = $page + 1;
|
$published = filter($content, function ($item) {
|
||||||
if ($next > $numOfPages) {
|
return $item["published"] == true && $item["deleted"] == false;
|
||||||
$next = 1;
|
});
|
||||||
}
|
$deleted = filter($content, function ($item) {
|
||||||
|
return $item["deleted"] == true;
|
||||||
|
});
|
||||||
|
|
||||||
return [
|
//$all = $content;
|
||||||
"pages" => $folder,
|
$all = filter($content, function ($item) {
|
||||||
"numOfPages" => $numOfPages,
|
return $item["deleted"] == false;
|
||||||
"entryCount" => count($filtered),
|
});
|
||||||
"paginate" => [
|
$filter = isset($sort) ? $sort : "all";
|
||||||
|
switch ($filter) {
|
||||||
|
case "published":
|
||||||
|
$filtered = $published;
|
||||||
|
break;
|
||||||
|
case "deleted":
|
||||||
|
$filtered = $deleted;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$filtered = $all;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$numOfPages = ceil(count($filtered) / ($limit + 1));
|
||||||
|
$folder = [];
|
||||||
|
|
||||||
|
if (count($filtered) != 0) {
|
||||||
|
if (count($filtered) < $limit) {
|
||||||
|
$limit = count($filtered) - 1;
|
||||||
|
}
|
||||||
|
$range = $page * $limit - $limit;
|
||||||
|
|
||||||
|
if ($range != 0) {
|
||||||
|
$range = $range + 1;
|
||||||
|
}
|
||||||
|
for ($i = 0; $i <= $limit; $i++) {
|
||||||
|
if (isset($filtered[$i + $range])) {
|
||||||
|
array_push($folder, $filtered[$i + $range]);
|
||||||
|
} else {
|
||||||
|
//chill out
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$prev = $page - 1;
|
||||||
|
if ($prev <= 0) {
|
||||||
|
$prev = $numOfPages;
|
||||||
|
}
|
||||||
|
|
||||||
|
$next = $page + 1;
|
||||||
|
if ($next > $numOfPages) {
|
||||||
|
$next = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
"pages" => $folder,
|
||||||
|
"numOfPages" => $numOfPages,
|
||||||
|
"entryCount" => count($filtered),
|
||||||
|
"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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,140 +16,159 @@ use function _\orderBy;
|
||||||
|
|
||||||
class Contents
|
class Contents
|
||||||
{
|
{
|
||||||
public $files = [];
|
public $files = [];
|
||||||
public $config = [];
|
public $config = [];
|
||||||
public function __construct($folder)
|
public function __construct($folder)
|
||||||
{
|
{
|
||||||
$this->read($folder);
|
$this->read($folder);
|
||||||
}
|
|
||||||
public function read($folder)
|
|
||||||
{
|
|
||||||
$folders = glob("$folder/*", GLOB_ONLYDIR);
|
|
||||||
foreach ($folders as $folder) {
|
|
||||||
//$this->files[] = $folder . "/";
|
|
||||||
$this->read($folder);
|
|
||||||
}
|
}
|
||||||
$files = array_filter(glob("$folder/*md"), "is_file");
|
public function read($folder)
|
||||||
foreach ($files as $file) {
|
{
|
||||||
$this->files[] = $file;
|
$folders = glob("$folder/*", GLOB_ONLYDIR);
|
||||||
}
|
foreach ($folders as $folder) {
|
||||||
}
|
//$this->files[] = $folder . "/";
|
||||||
|
$this->read($folder);
|
||||||
function getAll()
|
}
|
||||||
{
|
$files = array_filter(glob("$folder/*md"), "is_file");
|
||||||
$environment = new Environment($this->config);
|
foreach ($files as $file) {
|
||||||
$environment->addExtension(new CommonMarkCoreExtension());
|
$this->files[] = $file;
|
||||||
|
|
||||||
// Add the extension
|
|
||||||
$environment->addExtension(new FrontMatterExtension());
|
|
||||||
|
|
||||||
//Add Strikethrough rendering
|
|
||||||
$environment->addExtension(new StrikethroughExtension());
|
|
||||||
|
|
||||||
//add attributes to elements in markdown
|
|
||||||
$environment->addExtension(new AttributesExtension());
|
|
||||||
|
|
||||||
// Instantiate the converter engine and start converting some Markdown!
|
|
||||||
$converter = new MarkdownConverter($environment);
|
|
||||||
|
|
||||||
$contents = [];
|
|
||||||
foreach ($this->files as $file) {
|
|
||||||
//get meta and html from file
|
|
||||||
$result = $converter->convertToHtml(file_get_contents($file));
|
|
||||||
$meta = [];
|
|
||||||
if ($result instanceof RenderedContentWithFrontMatter) {
|
|
||||||
$meta = $result->getFrontMatter();
|
|
||||||
}
|
|
||||||
|
|
||||||
//get raw markdown from file
|
|
||||||
$frontMatterExtension = new FrontMatterExtension();
|
|
||||||
$parsed = $frontMatterExtension
|
|
||||||
->getFrontMatterParser()
|
|
||||||
->parse(file_get_contents($file));
|
|
||||||
|
|
||||||
//never trust the front end. clean it up
|
|
||||||
|
|
||||||
$builder = new SanitizerBuilder();
|
|
||||||
$builder->registerExtension(new BasicExtension());
|
|
||||||
$builder->registerExtension(new IframeExtension());
|
|
||||||
|
|
||||||
//relative-a and relative-image
|
|
||||||
$builder->registerExtension(
|
|
||||||
new \HtmlSanitizer\Extension\Relative\A\AExtension()
|
|
||||||
);
|
|
||||||
$builder->registerExtension(
|
|
||||||
new \HtmlSanitizer\Extension\Relative\Image\ImageExtension()
|
|
||||||
);
|
|
||||||
|
|
||||||
$detergent = [
|
|
||||||
"extensions" => ["basic", "relative-a", "relative-image", "iframe"],
|
|
||||||
"tags" => [
|
|
||||||
"div" => [
|
|
||||||
"allowed_attributes" => ["class", "title", "id", "style"],
|
|
||||||
],
|
|
||||||
"img" => [
|
|
||||||
"allowed_attributes" => ["src", "alt", "title", "class"],
|
|
||||||
],
|
|
||||||
"iframe" => [
|
|
||||||
"allowed_attributes" => ["height", "width", "title", "src"],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
$sanitizer = $builder->build($detergent);
|
|
||||||
|
|
||||||
$scrubbed = $sanitizer->sanitize($result->getContent());
|
|
||||||
|
|
||||||
$featureList = explode(",", $meta["feature"]);
|
|
||||||
$media = [];
|
|
||||||
foreach ($featureList as $file) {
|
|
||||||
$item = trim($file);
|
|
||||||
$ext = explode(".", $item);
|
|
||||||
if ($item != null || $item != "") {
|
|
||||||
array_push($media, ["file"=>$item, "type"=>trim($ext[1])]);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//sort attributes into page object
|
|
||||||
$page = [
|
|
||||||
"id" => $meta["id"],
|
|
||||||
"uuid" => $meta["uuid"],
|
|
||||||
"title" => $meta["title"],
|
|
||||||
"feature" => $meta["feature"],
|
|
||||||
"path" => $meta["path"],
|
|
||||||
"layout" => $meta["layout"],
|
|
||||||
"tags" => $meta["tags"],
|
|
||||||
"author" => $meta["author"],
|
|
||||||
"created" => date("Y M D d", $meta["created"]),
|
|
||||||
"updated" => date("Y M D d", $meta["updated"]),
|
|
||||||
"rawCreated" => $meta["created"],
|
|
||||||
"rawUpdated" => $meta["updated"],
|
|
||||||
"createdYear" => date("Y", $meta["created"]),
|
|
||||||
"createdMonth" => date("m", $meta["created"]),
|
|
||||||
"deleted" => $meta["deleted"],
|
|
||||||
"menu" => $meta["menu"],
|
|
||||||
"featured" => $meta["featured"],
|
|
||||||
"published" => $meta["published"],
|
|
||||||
"slug" => $meta["slug"],
|
|
||||||
"filePath" => $file,
|
|
||||||
"content" => $parsed->getContent(),
|
|
||||||
"html" => $scrubbed,
|
|
||||||
"media" => $media,
|
|
||||||
];
|
|
||||||
//checks for duplicates
|
|
||||||
$uuid = $meta["uuid"];
|
|
||||||
$found = current(
|
|
||||||
array_filter($contents, function ($item) use ($uuid) {
|
|
||||||
return isset($item["uuid"]) && $uuid == $item["uuid"];
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
// if uuid is not present, add it
|
|
||||||
if (!$found) {
|
|
||||||
array_push($contents, $page);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$contents = orderBy($contents, ["id"], ["desc"]);
|
|
||||||
return $contents;
|
function getAll()
|
||||||
}
|
{
|
||||||
|
$environment = new Environment($this->config);
|
||||||
|
$environment->addExtension(new CommonMarkCoreExtension());
|
||||||
|
|
||||||
|
// Add the extension
|
||||||
|
$environment->addExtension(new FrontMatterExtension());
|
||||||
|
|
||||||
|
//Add Strikethrough rendering
|
||||||
|
$environment->addExtension(new StrikethroughExtension());
|
||||||
|
|
||||||
|
//add attributes to elements in markdown
|
||||||
|
$environment->addExtension(new AttributesExtension());
|
||||||
|
|
||||||
|
// Instantiate the converter engine and start converting some Markdown!
|
||||||
|
$converter = new MarkdownConverter($environment);
|
||||||
|
|
||||||
|
$contents = [];
|
||||||
|
foreach ($this->files as $file) {
|
||||||
|
//get meta and html from file
|
||||||
|
$result = $converter->convertToHtml(file_get_contents($file));
|
||||||
|
$meta = [];
|
||||||
|
if ($result instanceof RenderedContentWithFrontMatter) {
|
||||||
|
$meta = $result->getFrontMatter();
|
||||||
|
}
|
||||||
|
|
||||||
|
//get raw markdown from file
|
||||||
|
$frontMatterExtension = new FrontMatterExtension();
|
||||||
|
$parsed = $frontMatterExtension
|
||||||
|
->getFrontMatterParser()
|
||||||
|
->parse(file_get_contents($file));
|
||||||
|
|
||||||
|
//never trust the front end. clean it up
|
||||||
|
|
||||||
|
$builder = new SanitizerBuilder();
|
||||||
|
$builder->registerExtension(new BasicExtension());
|
||||||
|
$builder->registerExtension(new IframeExtension());
|
||||||
|
|
||||||
|
//relative-a and relative-image
|
||||||
|
$builder->registerExtension(
|
||||||
|
new \HtmlSanitizer\Extension\Relative\A\AExtension()
|
||||||
|
);
|
||||||
|
$builder->registerExtension(
|
||||||
|
new \HtmlSanitizer\Extension\Relative\Image\ImageExtension()
|
||||||
|
);
|
||||||
|
|
||||||
|
$detergent = [
|
||||||
|
"extensions" => ["basic", "relative-a", "relative-image", "iframe"],
|
||||||
|
"tags" => [
|
||||||
|
"div" => [
|
||||||
|
"allowed_attributes" => ["class", "title", "id", "style"],
|
||||||
|
],
|
||||||
|
"img" => [
|
||||||
|
"allowed_attributes" => ["src", "alt", "title", "class"],
|
||||||
|
],
|
||||||
|
"iframe" => [
|
||||||
|
"allowed_attributes" => ["height", "width", "title", "src"],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$sanitizer = $builder->build($detergent);
|
||||||
|
|
||||||
|
$scrubbed = $sanitizer->sanitize($result->getContent());
|
||||||
|
$featureList = explode(",", $meta["feature"]);
|
||||||
|
$docs = '';
|
||||||
|
if (isset($meta["files"])) {
|
||||||
|
$fileList = explode(",", $meta["files"]);
|
||||||
|
$docs = $meta["files"];
|
||||||
|
} else {
|
||||||
|
$fileList = [];
|
||||||
|
$docs = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$media = [];
|
||||||
|
$files = [];
|
||||||
|
foreach ($featureList as $file) {
|
||||||
|
$item = trim($file);
|
||||||
|
$ext = pathinfo($item, PATHINFO_EXTENSION);
|
||||||
|
if ($item != null || $item != "") {
|
||||||
|
array_push($media, ["file"=>$item, "type"=>trim($ext)]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($fileList as $file) {
|
||||||
|
$item = trim($file);
|
||||||
|
$ext = pathinfo($item, PATHINFO_EXTENSION);
|
||||||
|
if ($item != null || $item != "") {
|
||||||
|
array_push($files, ["file"=>$item, "type"=>trim($ext)]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//sort attributes into page object
|
||||||
|
$page = [
|
||||||
|
"id" => $meta["id"],
|
||||||
|
"uuid" => $meta["uuid"],
|
||||||
|
"title" => $meta["title"],
|
||||||
|
"feature" => $meta["feature"],
|
||||||
|
"files" => $docs,
|
||||||
|
"path" => $meta["path"],
|
||||||
|
"layout" => $meta["layout"],
|
||||||
|
"tags" => $meta["tags"],
|
||||||
|
"author" => $meta["author"],
|
||||||
|
"created" => date("Y M D d", $meta["created"]),
|
||||||
|
"updated" => date("Y M D d", $meta["updated"]),
|
||||||
|
"rawCreated" => $meta["created"],
|
||||||
|
"rawUpdated" => $meta["updated"],
|
||||||
|
"createdYear" => date("Y", $meta["created"]),
|
||||||
|
"createdMonth" => date("m", $meta["created"]),
|
||||||
|
"deleted" => $meta["deleted"],
|
||||||
|
"menu" => $meta["menu"],
|
||||||
|
"featured" => $meta["featured"],
|
||||||
|
"published" => $meta["published"],
|
||||||
|
"slug" => $meta["slug"],
|
||||||
|
"filePath" => $file,
|
||||||
|
"content" => $parsed->getContent(),
|
||||||
|
"html" => $scrubbed,
|
||||||
|
"media" => $media,
|
||||||
|
"docs"=>$files
|
||||||
|
];
|
||||||
|
//checks for duplicates
|
||||||
|
$uuid = $meta["uuid"];
|
||||||
|
$found = current(
|
||||||
|
array_filter($contents, function ($item) use ($uuid) {
|
||||||
|
return isset($item["uuid"]) && $uuid == $item["uuid"];
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
// if uuid is not present, add it
|
||||||
|
if (!$found) {
|
||||||
|
array_push($contents, $page);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$contents = orderBy($contents, ["id"], ["desc"]);
|
||||||
|
return $contents;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,139 +2,142 @@
|
||||||
|
|
||||||
class DocTools
|
class DocTools
|
||||||
{
|
{
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function writePages($task, $path, $fileLocation, $fileContents)
|
public static function writePages($task, $path, $fileLocation, $fileContents)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if ($task == "create") {
|
if ($task == "create") {
|
||||||
if (!is_dir("../content/pages/" . $path)) {
|
if (!is_dir("../content/pages/" . $path)) {
|
||||||
//Directory does not exist, so lets create it.
|
//Directory does not exist, so lets create it.
|
||||||
mkdir("../content/pages/" . $path, 0755, true);
|
mkdir("../content/pages/" . $path, 0755, true);
|
||||||
|
}
|
||||||
|
file_put_contents($fileLocation, $fileContents);
|
||||||
|
} else {
|
||||||
|
($new = fopen($fileLocation, "w")) or die("Unable to open file!");
|
||||||
|
fwrite($new, $fileContents);
|
||||||
|
fclose($new);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (Error $error) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
file_put_contents($fileLocation, $fileContents);
|
|
||||||
} else {
|
|
||||||
($new = fopen($fileLocation, "w")) or die("Unable to open file!");
|
|
||||||
fwrite($new, $fileContents);
|
|
||||||
fclose($new);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} catch (Error $error) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static function writeSettings($fileLocation, $fileContents)
|
public static function writeSettings($fileLocation, $fileContents)
|
||||||
{
|
{
|
||||||
if (!is_file($fileLocation)) {
|
if (!is_file($fileLocation)) {
|
||||||
file_put_contents($fileLocation, json_encode($fileContents));
|
file_put_contents($fileLocation, json_encode($fileContents));
|
||||||
} else {
|
|
||||||
($new = fopen($fileLocation, "w")) or die("Unable to open file!");
|
|
||||||
fwrite($new, json_encode($fileContents));
|
|
||||||
fclose($new);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function writeHTML($location, $html, $path = null)
|
|
||||||
{
|
|
||||||
if ($path != null) {
|
|
||||||
if (!is_dir($path)) {
|
|
||||||
//Directory does not exist, so lets create it.
|
|
||||||
mkdir($path, 0755, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!is_file($location)) {
|
|
||||||
file_put_contents($location, $html);
|
|
||||||
} else {
|
|
||||||
($new = fopen($location, "w")) or die("Unable to open file!");
|
|
||||||
fwrite($new, $html);
|
|
||||||
fclose($new);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function deleteFolder($path)
|
|
||||||
{
|
|
||||||
if (!empty($path) && is_dir($path)) {
|
|
||||||
$dir = new RecursiveDirectoryIterator(
|
|
||||||
$path,
|
|
||||||
RecursiveDirectoryIterator::SKIP_DOTS
|
|
||||||
); //upper dirs are not included,otherwise DISASTER HAPPENS :)
|
|
||||||
$files = new RecursiveIteratorIterator(
|
|
||||||
$dir,
|
|
||||||
RecursiveIteratorIterator::CHILD_FIRST
|
|
||||||
);
|
|
||||||
foreach ($files as $f) {
|
|
||||||
if (is_file($f)) {
|
|
||||||
unlink($f);
|
|
||||||
} else {
|
} else {
|
||||||
$empty_dirs[] = $f;
|
($new = fopen($fileLocation, "w")) or die("Unable to open file!");
|
||||||
|
fwrite($new, json_encode($fileContents));
|
||||||
|
fclose($new);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (!empty($empty_dirs)) {
|
|
||||||
foreach ($empty_dirs as $eachDir) {
|
|
||||||
rmdir($eachDir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rmdir($path);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static function objectToMD($object)
|
public static function writeHTML($location, $html, $path = null)
|
||||||
{
|
{
|
||||||
$markdown =
|
if ($path != null) {
|
||||||
"---\n" .
|
if (!is_dir($path)) {
|
||||||
"id: " .
|
//Directory does not exist, so lets create it.
|
||||||
$object["id"] .
|
mkdir($path, 0755, true);
|
||||||
"\n" .
|
}
|
||||||
"uuid: " .
|
}
|
||||||
$object["uuid"] .
|
if (!is_file($location)) {
|
||||||
"\n" .
|
file_put_contents($location, $html);
|
||||||
"title: " .
|
} else {
|
||||||
"'" .
|
($new = fopen($location, "w")) or die("Unable to open file!");
|
||||||
$object["title"] .
|
fwrite($new, $html);
|
||||||
"'" .
|
fclose($new);
|
||||||
"\n" .
|
}
|
||||||
"feature: " .
|
}
|
||||||
$object["feature"] .
|
|
||||||
"\n" .
|
|
||||||
"path: " .
|
|
||||||
$object["path"] .
|
|
||||||
"\n" .
|
|
||||||
"layout: " .
|
|
||||||
$object["layout"] .
|
|
||||||
"\n" .
|
|
||||||
"tags: " .
|
|
||||||
$object["tags"] .
|
|
||||||
"\n" .
|
|
||||||
"author: " .
|
|
||||||
$object["author"] .
|
|
||||||
"\n" .
|
|
||||||
"created: " .
|
|
||||||
$object["created"] .
|
|
||||||
"\n" .
|
|
||||||
"updated: " .
|
|
||||||
$object["updated"] .
|
|
||||||
"\n" .
|
|
||||||
"deleted: " .
|
|
||||||
$object["deleted"] .
|
|
||||||
"\n" .
|
|
||||||
"slug: " .
|
|
||||||
$object["slug"] .
|
|
||||||
"\n" .
|
|
||||||
"menu: " .
|
|
||||||
$object["menu"] .
|
|
||||||
"\n" .
|
|
||||||
"published: " .
|
|
||||||
$object["published"] .
|
|
||||||
"\n" .
|
|
||||||
"featured: " .
|
|
||||||
$object["featured"] .
|
|
||||||
"\n---\n" .
|
|
||||||
$object["content"];
|
|
||||||
|
|
||||||
return $markdown;
|
public static function deleteFolder($path)
|
||||||
}
|
{
|
||||||
|
if (!empty($path) && is_dir($path)) {
|
||||||
|
$dir = new RecursiveDirectoryIterator(
|
||||||
|
$path,
|
||||||
|
RecursiveDirectoryIterator::SKIP_DOTS
|
||||||
|
); //upper dirs are not included,otherwise DISASTER HAPPENS :)
|
||||||
|
$files = new RecursiveIteratorIterator(
|
||||||
|
$dir,
|
||||||
|
RecursiveIteratorIterator::CHILD_FIRST
|
||||||
|
);
|
||||||
|
foreach ($files as $f) {
|
||||||
|
if (is_file($f)) {
|
||||||
|
unlink($f);
|
||||||
|
} else {
|
||||||
|
$empty_dirs[] = $f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!empty($empty_dirs)) {
|
||||||
|
foreach ($empty_dirs as $eachDir) {
|
||||||
|
rmdir($eachDir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rmdir($path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function objectToMD($object)
|
||||||
|
{
|
||||||
|
$markdown =
|
||||||
|
"---\n" .
|
||||||
|
"id: " .
|
||||||
|
$object["id"] .
|
||||||
|
"\n" .
|
||||||
|
"uuid: " .
|
||||||
|
$object["uuid"] .
|
||||||
|
"\n" .
|
||||||
|
"title: " .
|
||||||
|
"'" .
|
||||||
|
$object["title"] .
|
||||||
|
"'" .
|
||||||
|
"\n" .
|
||||||
|
"feature: " .
|
||||||
|
$object["feature"] .
|
||||||
|
"\n" .
|
||||||
|
"files: " .
|
||||||
|
$object["files"] .
|
||||||
|
"\n" .
|
||||||
|
"path: " .
|
||||||
|
$object["path"] .
|
||||||
|
"\n" .
|
||||||
|
"layout: " .
|
||||||
|
$object["layout"] .
|
||||||
|
"\n" .
|
||||||
|
"tags: " .
|
||||||
|
$object["tags"] .
|
||||||
|
"\n" .
|
||||||
|
"author: " .
|
||||||
|
$object["author"] .
|
||||||
|
"\n" .
|
||||||
|
"created: " .
|
||||||
|
$object["created"] .
|
||||||
|
"\n" .
|
||||||
|
"updated: " .
|
||||||
|
$object["updated"] .
|
||||||
|
"\n" .
|
||||||
|
"deleted: " .
|
||||||
|
$object["deleted"] .
|
||||||
|
"\n" .
|
||||||
|
"slug: " .
|
||||||
|
$object["slug"] .
|
||||||
|
"\n" .
|
||||||
|
"menu: " .
|
||||||
|
$object["menu"] .
|
||||||
|
"\n" .
|
||||||
|
"published: " .
|
||||||
|
$object["published"] .
|
||||||
|
"\n" .
|
||||||
|
"featured: " .
|
||||||
|
$object["featured"] .
|
||||||
|
"\n---\n" .
|
||||||
|
$object["content"];
|
||||||
|
|
||||||
|
return $markdown;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
{% set date = page['created'] %}
|
{% set date = page['created'] %}
|
||||||
{% set updated = page['updated'] %}
|
{% set updated = page['updated'] %}
|
||||||
{% set media = page['media'] %}
|
{% set media = page['media'] %}
|
||||||
|
{% set files = page['docs'] %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% set id = '' %}
|
{% set id = '' %}
|
||||||
{% set uuid = '' %}
|
{% set uuid = '' %}
|
||||||
|
@ -27,6 +28,7 @@
|
||||||
{% set date = '' %}
|
{% set date = '' %}
|
||||||
{% set updated = '' %}
|
{% set updated = '' %}
|
||||||
{% set media = '' %}
|
{% set media = '' %}
|
||||||
|
{% set files = '' %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
|
@ -71,7 +73,24 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
FILES
|
FILES
|
||||||
<div id="page-files-list"></div>
|
<div id="page-files-list">
|
||||||
|
{% if files|length > 1 %}
|
||||||
|
{% for item in files %}
|
||||||
|
{% if item.type == "mp3"%}
|
||||||
|
<div id="{{loop.index0}}" class="audio-item" data-source="{{ item.file }}"></div>
|
||||||
|
{% else %}
|
||||||
|
<div id="{{loop.index0}}" class="file-item" data-source="{{ item.file }}"></div>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% else %}
|
||||||
|
{% if item.type == "mp3"%}
|
||||||
|
<div id="0" class="audio-item" data-source="{{ files[0].file }}"></div>
|
||||||
|
{% else %}
|
||||||
|
<div id="0" class="file-item" data-source="{{ files[0].file }}"></div>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -141,5 +160,5 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block javascripts %}
|
{% block javascripts %}
|
||||||
<script src="/assets/scripts/Start.js?=dfnmf" type="text/javascript"></script>
|
<script src="/assets/scripts/Start.js?=erty" type="text/javascript"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -27,7 +27,7 @@
|
||||||
{% for page in data['pages'] %}
|
{% for page in data['pages'] %}
|
||||||
{% if page.media[0].type == 'mp4' %}
|
{% if page.media[0].type == 'mp4' %}
|
||||||
|
|
||||||
<a href="/dashboard/page/edit/{{ page.uuid }}" id="{{ page.uuid }}" class="page-link">
|
<a href="/dashboard/page/edit/{{ page.uuid }}" id="{{ page.uuid }}" class="post-video-link">
|
||||||
<video class="post-video" loop muted autoplay>
|
<video class="post-video" loop muted autoplay>
|
||||||
<source src="{{ page.media[0].file }}" type="video/mp4">
|
<source src="{{ page.media[0].file }}" type="video/mp4">
|
||||||
|
|
||||||
|
|
|
@ -3218,10 +3218,10 @@ select {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
#post-edit-index #post-edit-index-wrapper #post-feature #page-file-manager #page-file-wrapper #page-images-list {
|
#post-edit-index #post-edit-index-wrapper #post-feature #page-file-manager #page-file-wrapper #page-images-list, #post-edit-index #post-edit-index-wrapper #post-feature #page-file-manager #page-file-wrapper #page-files-list {
|
||||||
padding: 10px 0 0 0;
|
padding: 10px 0 0 0;
|
||||||
}
|
}
|
||||||
#post-edit-index #post-edit-index-wrapper #post-feature #page-file-manager #page-file-wrapper #page-images-list .img-item {
|
#post-edit-index #post-edit-index-wrapper #post-feature #page-file-manager #page-file-wrapper #page-images-list .img-item, #post-edit-index #post-edit-index-wrapper #post-feature #page-file-manager #page-file-wrapper #page-files-list .img-item {
|
||||||
height: 150px;
|
height: 150px;
|
||||||
width: 23.8%;
|
width: 23.8%;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
|
@ -3229,7 +3229,7 @@ select {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
#post-edit-index #post-edit-index-wrapper #post-feature #page-file-manager #page-file-wrapper #page-images-list .audio-item {
|
#post-edit-index #post-edit-index-wrapper #post-feature #page-file-manager #page-file-wrapper #page-images-list .audio-item, #post-edit-index #post-edit-index-wrapper #post-feature #page-file-manager #page-file-wrapper #page-files-list .audio-item {
|
||||||
height: 150px;
|
height: 150px;
|
||||||
width: 23.8%;
|
width: 23.8%;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
|
@ -3239,7 +3239,7 @@ select {
|
||||||
background: #1D3040;
|
background: #1D3040;
|
||||||
background: url("/assets/images/global/upload-audio.png") no-repeat center center/cover;
|
background: url("/assets/images/global/upload-audio.png") no-repeat center center/cover;
|
||||||
}
|
}
|
||||||
#post-edit-index #post-edit-index-wrapper #post-feature #page-file-manager #page-file-wrapper #page-images-list .video-item {
|
#post-edit-index #post-edit-index-wrapper #post-feature #page-file-manager #page-file-wrapper #page-images-list .video-item, #post-edit-index #post-edit-index-wrapper #post-feature #page-file-manager #page-file-wrapper #page-files-list .video-item {
|
||||||
height: 150px;
|
height: 150px;
|
||||||
width: 23.8%;
|
width: 23.8%;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
|
@ -3249,6 +3249,16 @@ select {
|
||||||
background: #1D3040;
|
background: #1D3040;
|
||||||
background: url("/assets/images/global/upload-video.png") no-repeat center center/cover;
|
background: url("/assets/images/global/upload-video.png") no-repeat center center/cover;
|
||||||
}
|
}
|
||||||
|
#post-edit-index #post-edit-index-wrapper #post-feature #page-file-manager #page-file-wrapper #page-images-list .file-item, #post-edit-index #post-edit-index-wrapper #post-feature #page-file-manager #page-file-wrapper #page-files-list .file-item {
|
||||||
|
height: 150px;
|
||||||
|
width: 23.8%;
|
||||||
|
border-radius: 3px;
|
||||||
|
margin: 0 10px 10px 0;
|
||||||
|
display: inline-block;
|
||||||
|
cursor: pointer;
|
||||||
|
background: #1D3040;
|
||||||
|
background: url("/assets/images/global/upload-doc.png") no-repeat center center/cover;
|
||||||
|
}
|
||||||
#post-edit-index #post-edit-index-wrapper #edit-post {
|
#post-edit-index #post-edit-index-wrapper #edit-post {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 880px;
|
max-width: 880px;
|
||||||
|
|
|
@ -1810,7 +1810,7 @@ class PostActions {
|
||||||
pageInfo.append('form_token', document.getElementById('form_token').value);
|
pageInfo.append('form_token', document.getElementById('form_token').value);
|
||||||
if (files.length > 0 && files != null) for(var i = 0; i < files.length; i++){
|
if (files.length > 0 && files != null) for(var i = 0; i < files.length; i++){
|
||||||
var file = files[i];
|
var file = files[i];
|
||||||
if (file.type.match('image.*') || file.type.match('video.mp4')) pageInfo.append('page_files[]', file, file.name);
|
if (file.type.match('image.*') || file.type.match('video.mp4') || file.type.match('audio.mpeg') || file.type.match('application.pdf') || file.type.match('text.plain') || file.type.match('text.rtf')) pageInfo.append('page_files[]', file, file.name);
|
||||||
else reject('Not an image file');
|
else reject('Not an image file');
|
||||||
}
|
}
|
||||||
else //check to see if image exists
|
else //check to see if image exists
|
||||||
|
@ -5417,7 +5417,10 @@ class FileManager {
|
||||||
'image/png',
|
'image/png',
|
||||||
'image/svg',
|
'image/svg',
|
||||||
'audio/mpeg',
|
'audio/mpeg',
|
||||||
'video/mp4'
|
'video/mp4',
|
||||||
|
'application/pdf',
|
||||||
|
'text/plain',
|
||||||
|
'text/rtf'
|
||||||
];
|
];
|
||||||
this.files = [];
|
this.files = [];
|
||||||
this.sortedFiles = [];
|
this.sortedFiles = [];
|
||||||
|
@ -5444,7 +5447,21 @@ class FileManager {
|
||||||
if (item.className == 'img-item') url = item.style.backgroundImage.slice(4, -1).replace(/"/g, '');
|
if (item.className == 'img-item') url = item.style.backgroundImage.slice(4, -1).replace(/"/g, '');
|
||||||
else url = item.getAttribute('data-source');
|
else url = item.getAttribute('data-source');
|
||||||
currentFiles.push({
|
currentFiles.push({
|
||||||
id: item.getAttribute('id'),
|
earl: url
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this.reindexFiles(currentFiles, 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
_sortablejsDefault.default.create(this.fileList, {
|
||||||
|
onUpdate: (e)=>{
|
||||||
|
notify.alert('REINDEXING FILES', null);
|
||||||
|
let currentFiles = [];
|
||||||
|
let items = e.target.children;
|
||||||
|
for(let index = 0; index < items.length; index++){
|
||||||
|
var item = items[index];
|
||||||
|
let url = item.getAttribute('data-source');
|
||||||
|
currentFiles.push({
|
||||||
earl: url
|
earl: url
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -5476,7 +5493,8 @@ class FileManager {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.files = []; //clear files array
|
this.files = []; //clear files array
|
||||||
this.imageList.innerHTML = '';
|
this.imageList.innerHTML = '';
|
||||||
for(var i = 0, file; file = files[i]; i++){
|
this.fileList.innerHTML = '';
|
||||||
|
for(var i = 0, file1; file1 = files[i]; i++){
|
||||||
var reader = new FileReader(); // Closure to capture the file information
|
var reader = new FileReader(); // Closure to capture the file information
|
||||||
reader.onload = ((theFile)=>{
|
reader.onload = ((theFile)=>{
|
||||||
return function(f) {
|
return function(f) {
|
||||||
|
@ -5516,12 +5534,23 @@ class FileManager {
|
||||||
case 'audio/mpeg':
|
case 'audio/mpeg':
|
||||||
var sound = document.createElement('div');
|
var sound = document.createElement('div');
|
||||||
sound.className = 'audio-item';
|
sound.className = 'audio-item';
|
||||||
|
sound.setAttribute('data-source', f.target.result);
|
||||||
self.fileList.appendChild(sound);
|
self.fileList.appendChild(sound);
|
||||||
|
self.files.push(theFile);
|
||||||
|
break;
|
||||||
|
case 'application/pdf':
|
||||||
|
case 'text/plain':
|
||||||
|
case 'text/rtf':
|
||||||
|
var file = document.createElement('div');
|
||||||
|
file.className = 'file-item';
|
||||||
|
file.setAttribute('data-source', f.target.result);
|
||||||
|
self.fileList.appendChild(file);
|
||||||
|
self.files.push(theFile);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})(file); // Read in the image file as a data URL.
|
})(file1); // Read in the image file as a data URL.
|
||||||
reader.readAsDataURL(file);
|
reader.readAsDataURL(file1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// event handlers
|
// event handlers
|
||||||
|
|
|
@ -59,7 +59,14 @@ export default class PostActions {
|
||||||
if (files.length > 0 && files != null) {
|
if (files.length > 0 && files != null) {
|
||||||
for (var i = 0; i < files.length; i++) {
|
for (var i = 0; i < files.length; i++) {
|
||||||
var file = files[i];
|
var file = files[i];
|
||||||
if (file.type.match('image.*') || file.type.match('video.mp4')) {
|
if (
|
||||||
|
file.type.match('image.*') ||
|
||||||
|
file.type.match('video.mp4') ||
|
||||||
|
file.type.match('audio.mpeg') ||
|
||||||
|
file.type.match('application.pdf') ||
|
||||||
|
file.type.match('text.plain') ||
|
||||||
|
file.type.match('text.rtf')
|
||||||
|
) {
|
||||||
pageInfo.append('page_files[]', file, file.name);
|
pageInfo.append('page_files[]', file, file.name);
|
||||||
} else {
|
} else {
|
||||||
reject('Not an image file');
|
reject('Not an image file');
|
||||||
|
|
|
@ -18,7 +18,10 @@ export default class FileManager {
|
||||||
'image/png',
|
'image/png',
|
||||||
'image/svg',
|
'image/svg',
|
||||||
'audio/mpeg',
|
'audio/mpeg',
|
||||||
'video/mp4'
|
'video/mp4',
|
||||||
|
'application/pdf',
|
||||||
|
'text/plain',
|
||||||
|
'text/rtf'
|
||||||
];
|
];
|
||||||
this.files = [];
|
this.files = [];
|
||||||
this.sortedFiles = [];
|
this.sortedFiles = [];
|
||||||
|
@ -48,7 +51,22 @@ export default class FileManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
currentFiles.push({
|
currentFiles.push({
|
||||||
id: item.getAttribute('id'),
|
earl: url
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this.reindexFiles(currentFiles, 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Sortable.create(this.fileList, {
|
||||||
|
onUpdate: e => {
|
||||||
|
notify.alert('REINDEXING FILES', null);
|
||||||
|
let currentFiles = [];
|
||||||
|
let items = e.target.children;
|
||||||
|
for (let index = 0; index < items.length; index++) {
|
||||||
|
var item = items[index];
|
||||||
|
let url = item.getAttribute('data-source');
|
||||||
|
currentFiles.push({
|
||||||
earl: url
|
earl: url
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -82,6 +100,7 @@ export default class FileManager {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.files = []; //clear files array
|
this.files = []; //clear files array
|
||||||
this.imageList.innerHTML = '';
|
this.imageList.innerHTML = '';
|
||||||
|
this.fileList.innerHTML = '';
|
||||||
for (var i = 0, file; (file = files[i]); i++) {
|
for (var i = 0, file; (file = files[i]); i++) {
|
||||||
var reader = new FileReader();
|
var reader = new FileReader();
|
||||||
// Closure to capture the file information
|
// Closure to capture the file information
|
||||||
|
@ -126,31 +145,22 @@ export default class FileManager {
|
||||||
video.setAttribute('data-source', f.target.result);
|
video.setAttribute('data-source', f.target.result);
|
||||||
self.imageList.appendChild(video);
|
self.imageList.appendChild(video);
|
||||||
self.files.push(theFile);
|
self.files.push(theFile);
|
||||||
/*
|
|
||||||
var video = document.createElement('video');
|
|
||||||
video.setAttribute('id', escape(theFile.name));
|
|
||||||
video.className = 'video-item';
|
|
||||||
video.src = f.target.result;
|
|
||||||
video.controls = 'controls';
|
|
||||||
video.type = f.type;
|
|
||||||
self.imageList.appendChild(video);
|
|
||||||
*/
|
|
||||||
break;
|
break;
|
||||||
case 'audio/mpeg':
|
case 'audio/mpeg':
|
||||||
var sound = document.createElement('div');
|
var sound = document.createElement('div');
|
||||||
sound.className = 'audio-item';
|
sound.className = 'audio-item';
|
||||||
|
sound.setAttribute('data-source', f.target.result);
|
||||||
self.fileList.appendChild(sound);
|
self.fileList.appendChild(sound);
|
||||||
|
self.files.push(theFile);
|
||||||
/*
|
break;
|
||||||
var sound = document.createElement('audio');
|
case 'application/pdf':
|
||||||
sound.setAttribute('id', escape(theFile.name));
|
case 'text/plain':
|
||||||
sound.className = 'audio-item';
|
case 'text/rtf':
|
||||||
sound.src = f.target.result;
|
var file = document.createElement('div');
|
||||||
sound.controls = 'controls';
|
file.className = 'file-item';
|
||||||
sound.type = f.type;
|
file.setAttribute('data-source', f.target.result);
|
||||||
self.imageList.appendChild(sound);
|
self.fileList.appendChild(file);
|
||||||
*/
|
self.files.push(theFile);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -296,7 +296,7 @@
|
||||||
width: 100%
|
width: 100%
|
||||||
margin: 0
|
margin: 0
|
||||||
padding: 0
|
padding: 0
|
||||||
#page-images-list
|
#page-images-list, #page-files-list
|
||||||
padding: 10px 0 0 0
|
padding: 10px 0 0 0
|
||||||
.img-item
|
.img-item
|
||||||
height: 150px
|
height: 150px
|
||||||
|
@ -323,6 +323,15 @@
|
||||||
cursor: pointer
|
cursor: pointer
|
||||||
background: $primary
|
background: $primary
|
||||||
background: url('/assets/images/global/upload-video.png') no-repeat center center / cover
|
background: url('/assets/images/global/upload-video.png') no-repeat center center / cover
|
||||||
|
.file-item
|
||||||
|
height: 150px
|
||||||
|
width: 23.8%
|
||||||
|
border-radius: 3px
|
||||||
|
margin: 0 10px 10px 0
|
||||||
|
display: inline-block
|
||||||
|
cursor: pointer
|
||||||
|
background: $primary
|
||||||
|
background: url('/assets/images/global/upload-doc.png') no-repeat center center / cover
|
||||||
|
|
||||||
|
|
||||||
#edit-post
|
#edit-post
|
||||||
|
|
Loading…
Reference in a new issue