@ -8,130 +8,127 @@ class SetUp
{
{
public static function status()
public static function status()
{
{
if (file_exists("../config/settings.json" )) {
if (file_exists('../config/settings.json' )) {
return true;
return true;
} else {
} else {
return false;
return false;
}
}
}
}
public static function init($body)
public static function init($body)
{
{
//grab template files
//grab template files
$newFolks = json_decode(
$newFolks = json_decode(
file_get_contents("../config/init/folks-template.json" ),
file_get_contents('../config/init/folks-template.json' ),
true
true
);
);
$newSettings = json_decode(
$newSettings = json_decode(
file_get_contents("../config/init/settings-template.json" ),
file_get_contents('../config/init/settings-template.json' ),
true
true
);
);
//get form values
//get form values
//$body = $request->getParsedBody();
//$body = $request->getParsedBody();
$handle = $body["new_member_handle" ];
$handle = $body['new_member_handle' ];
$email = $body["new_member_email" ];
$email = $body['new_member_email' ];
$pass = $body["new_member_pass" ];
$pass = $body['new_member_pass' ];
$title = $body["new_member_title" ];
$title = $body['new_member_title' ];
$now = new \Moment\Moment();
$now = new \Moment\Moment();
//setup folks config
//setup folks config
$hash = password_hash($pass, PASSWORD_DEFAULT);
$hash = password_hash($pass, PASSWORD_DEFAULT);
$newFolks[0]["id"] = 0;
$newFolks[0]['id'] = 0;
$newFolks[0]["handle"] = $handle;
$newFolks[0]['handle'] = $handle;
$newFolks[0]["email"] = $email;
$newFolks[0]['email'] = $email;
$newFolks[0]["password" ] = $hash;
$newFolks[0]['password' ] = $hash;
$newFolks[0]["key"] = password_hash($email, PASSWORD_DEFAULT);
$newFolks[0]['key'] = password_hash($email, PASSWORD_DEFAULT);
$newFolks[0]["secret"] = StringTools::randomString(12);
$newFolks[0]['secret'] = StringTools::randomString(12);
$newFolks[0]["role"] = "hnic" ;
$newFolks[0]['role'] = 'hnic' ;
$newFolks[0]["created"] = $now->format("Y-m-d\TH:i:sP");
$newFolks[0]['created'] = $now->format("Y-m-d\TH:i:sP");
$newFolks[0]["updated"] = $now->format("Y-m-d\TH:i:sP");
$newFolks[0]['updated'] = $now->format("Y-m-d\TH:i:sP");
//set up settings config
//set up settings config
$newSettings["global"]["title" ] = $title;
$newSettings['global']['title' ] = $title;
//create index file
//create index file
//$rightNow = $now->format("Y-m-d\TH:i:sP");
//$rightNow = $now->format("Y-m-d\TH:i:sP");
//var_dump($now->format("Y-m-d\TH:i:sP"));
//var_dump($now->format("Y-m-d\TH:i:sP"));
$index = [
$index = [
"id" => 1,
'id' => 1,
"uuid" => StringTools::createUUID(),
'uuid' => StringTools::createUUID(),
"title" => "FIRST!",
'title' => 'FIRST!',
"feature" => "/assets/images/global/default-bg.jpg",
'feature' => '/assets/images/global/default-bg.jpg',
"files" => "",
'files' => '',
"path" => "content/pages/start",
'path' => 'content/pages/start',
"layout" => "index",
'layout' => 'index',
"tags" => "start, welcome",
'tags' => 'start, welcome',
"author" => $handle,
'author' => $handle,
"created" => $now->format("Y-m-d\TH:i:sP"),
'created' => $now->format("Y-m-d\TH:i:sP"),
"updated" => $now->format("Y-m-d\TH:i:sP"),
'updated' => $now->format("Y-m-d\TH:i:sP"),
"deleted" => "false",
'deleted' => 'false',
"slug" => "first",
'slug' => 'first',
"menu" => "false",
'menu' => 'false',
"featured" => "false",
'featured' => 'false',
"published" => "true",
'published' => 'true',
"content" =>
'content' => "# F**k Yes \n\nIf you're seeing this, you're up and running. NICE WORK!\n\nFrom here, feel free to start dropping pages to your heart's content.\n\nFor some tips about using Fipamo, check out the ![docs](https://code.playvicio.us/Are0h/Fipamo/wiki/02-Usage)\n\nAll good? Feel free to edit this page to whatever you want!\n\nYOU'RE THE CAPTAIN NOW.",
"# F**k Yes \n\nIf you're seeing this, you're up and running. NICE WORK!\n\nFrom here, feel free to start dropping pages to your heart's content.\n\nFor some tips about using Fipamo, check out the ![docs](https://code.playvicio.us/Are0h/Fipamo/wiki/02-Usage)\n\nAll good? Feel free to edit this page to whatever you want!\n\nYOU'RE THE CAPTAIN NOW.",
];
];
$freshIndex = DocTools::objectToMD($index);
$freshIndex = DocTools::objectToMD($index);
//once all files created, write down
//once all files created, write down
DocTools::writeSettings("../config/settings.json" , $newSettings);
DocTools::writeSettings('../config/settings.json' , $newSettings);
DocTools::writeSettings("../config/folks.json" , $newFolks);
DocTools::writeSettings('../config/folks.json' , $newFolks);
DocTools::writeSettings("../config/tags.json" , []);
DocTools::writeSettings('../config/tags.json' , []);
DocTools::writePages(
DocTools::writePages(
"create" ,
'create' ,
"start" ,
'start' ,
"../content/pages/start/index.md" ,
'../content/pages/start/index.md' ,
$freshIndex
$freshIndex
);
);
//if there is an older session file, get rid of it
//if there is an older session file, get rid of it
if (is_file("../content/.session" )) {
if (is_file('../content/.session' )) {
unlink("../content/.session" );
unlink('../content/.session' );
}
}
$result = ["type" => "blogInitGood", "message" => "Site Created" ];
$result = ['type' => 'blogInitGood', 'message' => 'Site Created' ];
return $result;
return $result;
}
}
public static function restore($request)
public static function restore($request)
{
{
$result = [
$result = [
"type" => "requestLame" ,
'type' => 'requestLame' ,
"message" => "Still working on it." ,
'message' => 'Still working on it.' ,
];
];
$body = $request->getParsedBody();
$body = $request->getParsedBody();
$backup = $request->getUploadedFiles();
$backup = $request->getUploadedFiles();
$file = $backup["backup-upload" ];
$file = $backup['backup-upload' ];
//NOTE: If this fails check 'post_max_size' in php.ini
//NOTE: If this fails check 'post_max_size' in php.ini
$size = $file->getSize();
$size = $file->getSize();
$name = $file->getClientFileName();
$name = $file->getClientFileName();
//park it so it can be read
//park it so it can be read
$file->moveTo("../content" . "/" . $name);
$file->moveTo('../content' . '/' . $name);
//open it and get files to verify user
//open it and get files to verify user
$zip = new \ZipArchive();
$zip = new \ZipArchive();
if ($zip->open("../content" . "/" . $name) === true) {
if ($zip->open('../content' . '/' . $name) === true) {
$folks = json_decode($zip->getFromName("settings/folks.json" ), true);
$folks = json_decode($zip->getFromName('settings/folks.json' ), true);
$found = find($folks, ["handle" => $body["restore_member_handle" ]]);
$found = find($folks, ['handle' => $body['restore_member_handle' ]]);
//if member is found in back up, check pass
//if member is found in back up, check pass
if ($found) {
if ($found) {
if (password_verify($body["restore_member_pass"], $found["password" ])) {
if (password_verify($body['restore_member_pass'], $found['password' ])) {
//backup verified, restore site
//backup verified, restore site
//set new secret key for older folks configs
//set new secret key for older folks configs
$newFolks = [];
$newFolks = [];
if (!isset($found["secret" ])) {
if (!isset($found['secret' ])) {
$found["secret" ] = StringTools::randomString(12);
$found['secret' ] = StringTools::randomString(12);
}
}
array_push($newFolks, $found);
array_push($newFolks, $found);
//dump files in folder
//dump files in folder
$zip->extractTo("../content" );
$zip->extractTo('../content' );
//move to appropriate spots
//move to appropriate spots
/*
/*
@ -143,49 +140,49 @@ class SetUp
//load up old config file
//load up old config file
$newConfig = json_decode(
$newConfig = json_decode(
file_get_contents("../content/settings/settings.json" ),
file_get_contents('../content/settings/settings.json' ),
true
true
);
);
//check for key, add if not there
//check for key, add if not there
if (!isset($newConfig["global"]["externalAPI" ])) {
if (!isset($newConfig['global']['externalAPI' ])) {
$newConfig["global"]["externalAPI"] = "false" ;
$newConfig['global']['externalAPI'] = 'false' ;
}
}
//write new config file
//write new config file
DocTools::writeSettings("../config/settings.json" , $newConfig);
DocTools::writeSettings('../config/settings.json' , $newConfig);
//rename("../content/settings/folks.json", "../config/folks.json");
//rename("../content/settings/folks.json", "../config/folks.json");
DocTools::writeSettings("../config/folks.json" , $newFolks);
DocTools::writeSettings('../config/folks.json' , $newFolks);
rename("../content/settings/tags.json", "../config/tags.json" );
rename('../content/settings/tags.json', '../config/tags.json' );
//images path for blog and user
//images path for blog and user
$blogImagePath = "../public/assets/images/blog" ;
$blogImagePath = '../public/assets/images/blog' ;
$userImagePath = "../public/assets/images/user" ;
$userImagePath = '../public/assets/images/user' ;
//check to see if image dirs are empty, if not chill
//check to see if image dirs are empty, if not chill
if ($globs = glob($blogImagePath . "/*" )) {
if ($globs = glob($blogImagePath . '/*' )) {
//directory not empty, relax
//directory not empty, relax
} else {
} else {
rename("../content/public/assets/images/blog" , $blogImagePath);
rename('../content/public/assets/images/blog' , $blogImagePath);
}
}
if ($globs = glob($userImagePath . "/*" )) {
if ($globs = glob($userImagePath . '/*' )) {
//directory not empty, relax
//directory not empty, relax
} else {
} else {
rename("../content/public/assets/images/user" , $userImagePath);
rename('../content/public/assets/images/user' , $userImagePath);
}
}
rename("../content/content/pages/", "../content/pages" );
rename('../content/content/pages/', '../content/pages' );
//legacy check for old file structure
//legacy check for old file structure
if (is_file("../content/pages/index.md" )) {
if (is_file('../content/pages/index.md' )) {
if (!is_dir("../content/pages/start" )) {
if (!is_dir('../content/pages/start' )) {
//Directory does not exist, so lets create it.
//Directory does not exist, so lets create it.
mkdir("../content/pages/start" , 0755, true);
mkdir('../content/pages/start' , 0755, true);
//move start page to appropriate spot
//move start page to appropriate spot
rename(
rename(
"../content/pages/index.md" ,
'../content/pages/index.md' ,
"../content/pages/start/index.md"
'../content/pages/start/index.md'
);
);
}
}
} else {
} else {
@ -194,34 +191,34 @@ class SetUp
//clean up
//clean up
DocTools::deleteFolder("../content/settings" );
DocTools::deleteFolder('../content/settings' );
DocTools::deleteFolder("../content/public" );
DocTools::deleteFolder('../content/public' );
DocTools::deleteFolder("../content/content" );
DocTools::deleteFolder('../content/content' );
$result = [
$result = [
"type" => "requestGood" ,
'type' => 'requestGood' ,
"message" => "Site Restored! Redirecting" ,
'message' => 'Site Restored! Redirecting' ,
];
];
} else {
} else {
$result = [
$result = [
"type" => "requestLame" ,
'type' => 'requestLame' ,
"message" => "Check that password, champ." ,
'message' => 'Check that password, champ.' ,
];
];
}
}
} else {
} else {
$result = [
$result = [
"type" => "requestLame" ,
'type' => 'requestLame' ,
"message" => "No member found by that name, hoss" ,
'message' => 'No member found by that name, hoss' ,
];
];
}
}
$zip->close();
$zip->close();
$zipPath = "../content/" . $name;
$zipPath = '../content/' . $name;
//trash zip when done
//trash zip when done
unlink($zipPath);
unlink($zipPath);
} else {
} else {
$result = [
$result = [
"type" => "requestLame" ,
'type' => 'requestLame' ,
"message" => "Could not open backup. RATS!" ,
'message' => 'Could not open backup. RATS!' ,
];
];
}
}
return $result;
return $result;