activated site restore from zip, fixed imgs to rendering src
This commit is contained in:
parent
b98707bb0d
commit
9afec7554c
9 changed files with 181 additions and 28 deletions
|
@ -13,6 +13,7 @@ class InitAPI
|
|||
$result = Setup::init($request);
|
||||
break;
|
||||
case "restore":
|
||||
$result = Setup::restore($request);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,9 +40,15 @@ class APIControl
|
|||
}
|
||||
|
||||
switch (isset($args["third"]) ? $args["third"] : "none") {
|
||||
case "restore":
|
||||
case "init":
|
||||
$result = InitApi::handleInitTasks($args["third"], $body);
|
||||
$task = $args["third"];
|
||||
$result = InitApi::handleInitTasks(
|
||||
$task,
|
||||
$task == "init" ? $body : $request
|
||||
);
|
||||
break;
|
||||
|
||||
case "login":
|
||||
$result = AuthAPI::login($body);
|
||||
break;
|
||||
|
|
|
@ -16,7 +16,9 @@ class Render
|
|||
$settings = $config->getSettings();
|
||||
$this->menu = $settings["menu"];
|
||||
$this->pageInfo = [
|
||||
"keywords" => $settings["global"]["keywords"],
|
||||
"keywords" => isset($settings["global"]["keywords"])
|
||||
? $settings["global"]["keywords"]
|
||||
: "fipamo, blog, jamstack, php, markdown, js",
|
||||
"description" => $settings["global"]["descriptions"],
|
||||
"image" => $settings["global"]["background"],
|
||||
];
|
||||
|
@ -66,11 +68,21 @@ class Render
|
|||
//render markdown content and clean it
|
||||
$parser = new Parser();
|
||||
$rendered = $parser->parse($page["content"]);
|
||||
$sanitizer = \HtmlSanitizer\Sanitizer::create([
|
||||
$sanitizer = HtmlSanitizer\Sanitizer::create([
|
||||
"extensions" => ["basic", "image", "list", "code"],
|
||||
"tags" => [
|
||||
"img" => [
|
||||
"allowed_attributes" => ["src", "alt", "title", "class"],
|
||||
"allowed_hosts" => null,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$preclean = $sanitizer->sanitize($rendered->getContent());
|
||||
$cleaned = strip_tags($preclean, [
|
||||
|
||||
//just clean renderd string for now, Sanitize doesn't like relative img urls
|
||||
//so another option is needed
|
||||
$cleaned = strip_tags($rendered->getContent(), [
|
||||
"a",
|
||||
"br",
|
||||
"p",
|
||||
|
@ -159,6 +171,13 @@ class Render
|
|||
$html = $this->twig->render($template, $pageOptions);
|
||||
|
||||
$location = "../public/tags/" . $item["slug"] . ".html";
|
||||
|
||||
//if tags folder doesn't exist, make it
|
||||
if (!is_dir("../public/tags")) {
|
||||
mkdir("../public/tags", 0755, true);
|
||||
} else {
|
||||
}
|
||||
|
||||
if (!is_file($location)) {
|
||||
file_put_contents($location, $html);
|
||||
} else {
|
||||
|
|
|
@ -109,7 +109,9 @@ class Settings
|
|||
if (isset($key)) {
|
||||
$member = Session::get("member");
|
||||
$found = find($this->folks, ["handle" => $member["handle"]]);
|
||||
if ($found) {
|
||||
return $found[$key];
|
||||
}
|
||||
} else {
|
||||
return $this->folks;
|
||||
}
|
||||
|
|
|
@ -55,6 +55,33 @@ class DocTools
|
|||
}
|
||||
}
|
||||
|
||||
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 =
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
|
||||
use function _\find;
|
||||
class SetUp
|
||||
{
|
||||
public static function status()
|
||||
|
@ -91,7 +91,104 @@ class SetUp
|
|||
return $result;
|
||||
}
|
||||
|
||||
public static function restore()
|
||||
public static function restore($request)
|
||||
{
|
||||
$result = [
|
||||
"type" => "requestLame",
|
||||
"message" => "Still working on it.",
|
||||
];
|
||||
$body = $request->getParsedBody();
|
||||
|
||||
$backup = $request->getUploadedFiles();
|
||||
$file = $backup["backup-upload"];
|
||||
$name = $file->getClientFileName();
|
||||
|
||||
//park it so it can be read
|
||||
$file->moveTo("../content" . "/" . $name);
|
||||
|
||||
//open it and get files to verify user
|
||||
$zip = new ZipArchive();
|
||||
if ($zip->open("../content" . "/" . $name) === true) {
|
||||
$folks = json_decode($zip->getFromName("settings/folks.json"), true);
|
||||
$found = find($folks, ["handle" => $body["restore_member_handle"]]);
|
||||
|
||||
//if member is found in back up, check pass
|
||||
if ($found) {
|
||||
if (password_verify($body["restore_member_pass"], $found["password"])) {
|
||||
//backup verified, restore site
|
||||
|
||||
//set new secret key for older folks configs
|
||||
$newFolks = [];
|
||||
if (!isset($found["secret"])) {
|
||||
$found["secret"] = StringTools::randomString(12);
|
||||
}
|
||||
array_push($newFolks, $found);
|
||||
//dump files in folder
|
||||
$zip->extractTo("../content");
|
||||
|
||||
//move to appropriate spots
|
||||
rename(
|
||||
"../content/settings/settings.json",
|
||||
"../config/settings.json"
|
||||
);
|
||||
|
||||
//rename("../content/settings/folks.json", "../config/folks.json");
|
||||
DocTools::writeSettings("../config/folks.json", $newFolks);
|
||||
|
||||
rename("../content/settings/tags.json", "../config/tags.json");
|
||||
|
||||
rename(
|
||||
"../content/public/assets/images/blog",
|
||||
"../public/assets/images/blog"
|
||||
);
|
||||
|
||||
rename("../content/content/pages/", "../content/pages");
|
||||
|
||||
//legacy check for old file structure
|
||||
if (is_file("../content/pages/index.md")) {
|
||||
if (!is_dir("../content/pages/start")) {
|
||||
//Directory does not exist, so lets create it.
|
||||
mkdir("../content/pages/start", 0755, true);
|
||||
//move start page to appropriate spot
|
||||
rename(
|
||||
"../content/pages/index.md",
|
||||
"../content/pages/start/index.md"
|
||||
);
|
||||
}
|
||||
} else {
|
||||
//chill
|
||||
}
|
||||
|
||||
//clean up
|
||||
|
||||
DocTools::deleteFolder("../content/settings");
|
||||
DocTools::deleteFolder("../content/public");
|
||||
DocTools::deleteFolder("../content/content");
|
||||
|
||||
echo "AUTH VERIFIED";
|
||||
} else {
|
||||
$result = [
|
||||
"type" => "requestLame",
|
||||
"message" => "Check that password, champ.",
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$result = [
|
||||
"type" => "requestLame",
|
||||
"message" => "No member found by that name, hoss",
|
||||
];
|
||||
}
|
||||
|
||||
$zip->close();
|
||||
$zipPath = "../content/" . $name;
|
||||
//trash zip when done
|
||||
unlink($zipPath);
|
||||
} else {
|
||||
$result = [
|
||||
"type" => "requestLame",
|
||||
"message" => "Could not open backup. RATS!",
|
||||
];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ export default class Base {
|
|||
handleRestore(e) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
let admin = new FipamoAdminAPI();
|
||||
let api = new FipamoApi();
|
||||
var form = document.getElementById("init-restore");
|
||||
admin
|
||||
.handleInitRestore(form)
|
||||
|
@ -105,7 +105,7 @@ export default class Base {
|
|||
} else {
|
||||
notify.alert(response.message, true);
|
||||
setTimeout(() => {
|
||||
//window.location = '/@/dashboard';
|
||||
window.location = "/dashboard";
|
||||
}, 700);
|
||||
}
|
||||
})
|
||||
|
|
|
@ -6,6 +6,7 @@ export const CONTENT_TYPE_JSON = "json";
|
|||
export const CONTENT_TYPE_FORM = "x-www-form-urlencoded";
|
||||
export const API_STATUS = "/api/v1/status";
|
||||
export const API_INIT = "/api/v1/init";
|
||||
export const API_RESTORE = "/api/v1/restore";
|
||||
export const API_LOGIN = "/api/v1/login";
|
||||
export const API_GET_PAGES = "/api/v1/page/published";
|
||||
export const API_GET_PAGE = "/api/v1/page/single";
|
||||
|
@ -52,6 +53,25 @@ export default class FipamoAPI {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
handleInitRestore(form) {
|
||||
return new Promise((resolve, reject) => {
|
||||
var url, event, method, type, data;
|
||||
|
||||
url = API_RESTORE;
|
||||
event = DataEvent.API_BACKUP_RESTORE;
|
||||
method = REQUEST_TYPE_POST;
|
||||
type = CONTENT_TYPE_FORM;
|
||||
data = new FormData(form);
|
||||
this._request(url, event, method, type, data)
|
||||
.then((result) => {
|
||||
resolve(result);
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
getPages(num) {
|
||||
let pageNum = num;
|
||||
if (pageNum === null || pageNum === "" || !pageNum) pageNum = 1;
|
||||
|
|
|
@ -22,7 +22,6 @@ export const API_REINDEX_PAGES = "/api/v1/settings/reindex";
|
|||
export const API_CREATE_BACKUP = "/api/v1/backup/create";
|
||||
export const API_DOWNLOAD_BACKUP = "/api/v1/backup/download";
|
||||
export const API_RESTORE_BACKUP = "/api/v1/backup/restore";
|
||||
export const API_INIT_RESTORE_BACKUP = "/api/v1/backup/init-restore";
|
||||
export const API_SEND_MAIL = "/api/v1/mailer";
|
||||
import * as DataEvent from "../com/events/DataEvent";
|
||||
export default class APIUtils {
|
||||
|
@ -227,24 +226,6 @@ export default class APIUtils {
|
|||
});
|
||||
});
|
||||
}
|
||||
handleInitRestore(form) {
|
||||
return new Promise((resolve, reject) => {
|
||||
var url, event, method, type, data;
|
||||
|
||||
url = API_INIT_RESTORE_BACKUP;
|
||||
event = DataEvent.API_BACKUP_RESTORE;
|
||||
method = REQUEST_TYPE_POST;
|
||||
type = CONTENT_TYPE_FORM;
|
||||
data = new FormData(form);
|
||||
this._request(url, event, method, type, data)
|
||||
.then((result) => {
|
||||
resolve(result);
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
handleReindex(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
|
Loading…
Reference in a new issue