setting sync and settings image uploading turned back on

beta
Ro 4 years ago
parent b68d4c190e
commit 179f007fab

@ -6,24 +6,70 @@ class ImagesAPI
{ {
} }
public static function uploadImage($request) public static function uploadImage($request, $type = null)
{ {
$image = $request->getUploadedFiles(); $file = $request->getUploadedFiles();
$uploadPath = "";
$path = date("Y") . "/" . date("m"); $path = date("Y") . "/" . date("m");
$response = [];
switch ($type) {
case "avatar":
$image = $file["avatar_upload"];
$uploadPath = "../public/assets/images/user/" . $path;
break;
case "background":
$image = $file["background_upload"];
$uploadPath = "../public/assets/images/user/" . $path;
break;
default:
$image = $file["post_image"];
$path = date("Y") . "/" . date("m");
$uploadPath = "../public/assets/images/blog/" . $path;
break;
}
$uploadPath = "../public/assets/images/blog/" . $path; $result = FileUploader::uploadFile($uploadPath, $image);
FileUploader::uploadFile($uploadPath, $image["post_image"]); switch ($type) {
case "avatar":
$response = [
"message" => "Avatar Added. You look great!",
"type" => "avatarUploaded",
"url" =>
"/assets/images/user/" . $path . "/" . $image->getClientFileName(),
];
$response = [ //update member data
"message" => "Image Added. Very slick", Member::updateData(
"type" => "postImageAdded", "avi",
"url" => "/assets/images/user/" . $path . "/" . $image->getClientFileName()
"/assets/images/blog/" . );
$path .
"/" . break;
$image["post_image"]->getClientFileName(), case "background":
]; $response = [
"message" => "Background plugged in. That's nice!",
"type" => "siteBackgroundUploaded",
"url" =>
"/assets/images/user/" . $path . "/" . $image->getClientFileName(),
];
//update settings file
Settings::updateGlobalData(
"background",
"/assets/images/user/" . $path . "/" . $image->getClientFileName()
);
break;
default:
$response = [
"message" => "Image Added. Very slick",
"type" => "postImageAdded",
"url" =>
"/assets/images/blog/" . $path . "/" . $image->getClientFileName(),
];
break;
}
return $response; return $response;
} }

@ -8,10 +8,9 @@ class SettingsAPI
{ {
} }
public static function handleSettingsTask($request, $args) public static function handleSettingsTask($request, $args, $body = null)
{ {
$task = $args["fourth"]; $task = $args["fourth"];
echo $task;
switch ($task) { switch ($task) {
case "publish": case "publish":
$view = Twig::fromRequest($request); $view = Twig::fromRequest($request);
@ -38,6 +37,20 @@ class SettingsAPI
"type" => "TASK_NONE", "type" => "TASK_NONE",
]; ];
break;
case "add-avatar":
$result = ImagesAPI::uploadImage($request, "avatar");
break;
case "add-feature-background":
$result = ImagesAPI::uploadImage($request, "background");
break;
case "sync":
Settings::sync($body);
$result = [
"message" => "Settings Synced. You're doing great!",
"type" => "settingsUpdated",
];
break; break;
default: default:
$result = [ $result = [

@ -59,7 +59,7 @@ class APIControl
case "settings": case "settings":
$token = $request->getHeader("fipamo-access-token"); $token = $request->getHeader("fipamo-access-token");
if (Session::verifyToken($token[0])) { if (Session::verifyToken($token[0])) {
$result = SettingsAPI::handleSettingsTask($request, $args); $result = SettingsAPI::handleSettingsTask($request, $args, $body);
} else { } else {
$result = [ $result = [
"message" => "API access denied, homie", "message" => "API access denied, homie",

@ -36,6 +36,7 @@ class DashControl
"currentTheme" => $settings["global"]["theme"], "currentTheme" => $settings["global"]["theme"],
"themes" => $themes, "themes" => $themes,
"mailOption" => $settings["email"]["active"], "mailOption" => $settings["email"]["active"],
"status" => Session::active(),
]; ];
} else { } else {
header("Location: /dashboard"); header("Location: /dashboard");

@ -0,0 +1,33 @@
<?php
use function _\find;
class Member
{
public function __construct()
{
}
public static function updateData(string $key, string $data)
{
$folks = (new Settings())->getFolks();
$member = Session::get("member");
$found = find($folks, ["handle" => $member["handle"]]);
$found[$key] = $data;
//record time updated
$updated = new \Moment\Moment();
$found["updated"] = $updated->format("Y-m-d\TH:i:sP");
$newFolks = [];
array_push($newFolks, $found);
//save updated file
DocTools::writeSettings("../config/folks.json", $newFolks);
//update member data in session
$member = [
"handle" => $found["handle"],
"email" => $found["email"],
"role" => $found["role"],
"avatar" => $found["avi"],
];
Session::set("member", $member);
}
}

@ -26,6 +26,27 @@ class Settings
} }
} }
public static function sync($data)
{
$settings = self::$settings;
$settings["global"]["base_url"] = $data["global"]["base_url"];
$settings["global"]["title"] = $data["global"]["title"];
$settings["global"]["descriptions"] = $data["global"]["descriptions"];
$settings["global"]["base_url"] = $data["global"]["base_url"];
$settings["global"]["private"] = $data["global"]["private"];
$settings["global"]["renderOnSave"] = $data["global"]["renderOnSave"];
$settings["global"]["theme"] = $data["global"]["theme"];
Member::updateData("handle", $data["member"]["handle"]);
Member::updateData("email", $data["member"]["email"]);
$settings["email"]["active"] = $data["email"]["active"];
$settings["email"]["smtp"] = $data["email"]["smtp"];
$settings["email"]["mailgun"] = $data["email"]["mailgun"];
DocTools::writeSettings("../config/settings.json", $settings);
}
public function getThemes() public function getThemes()
{ {
return $this->themes; return $this->themes;
@ -47,6 +68,13 @@ class Settings
return self::$settings; return self::$settings;
} }
public static function updateGlobalData($key, $data)
{
$settings = self::$settings;
$settings["global"][$key] = $data;
DocTools::writeSettings("../config/settings.json", $settings);
}
public static function getCurrentIndex() public static function getCurrentIndex()
{ {
$settings = self::$settings; $settings = self::$settings;

@ -8,6 +8,7 @@ class FileUploader
string $directory, string $directory,
UploadedFileInterface $file UploadedFileInterface $file
) { ) {
$response = [];
try { try {
if (!is_dir($directory)) { if (!is_dir($directory)) {
//Directory does not exist, so lets create it. //Directory does not exist, so lets create it.
@ -22,8 +23,10 @@ class FileUploader
$file->moveTo($directory . "/" . $file->getClientFileName()); $file->moveTo($directory . "/" . $file->getClientFileName());
} catch (Error $e) { } catch (Error $e) {
echo "failed to upload image: " . $e->getMessage(); echo $e;
throw new Error("Failed to upload image file");
//echo "failed to upload image: " . $e->getMessage();
//throw new Error("Failed to upload image file");
} }
} }
} }

@ -35,7 +35,7 @@
</div> </div>
</div> </div>
<div id="site-background"> <div id="site-background">
<label>Header</label> <label>Site Header</label>
<img id="background" src="{{background}}" alt="image for site background" for="background-upload"/> <img id="background" src="{{background}}" alt="image for site background" for="background-upload"/>
<input id="background-upload" type="file" name="backgrond-upload" /> <input id="background-upload" type="file" name="backgrond-upload" />
</div> </div>

@ -11,6 +11,7 @@ include "../brain/controller/RouteControl.inc.php";
include "../brain/data/Auth.inc.php"; include "../brain/data/Auth.inc.php";
include "../brain/utility/StringTools.inc.php"; include "../brain/utility/StringTools.inc.php";
include "../brain/data/Session.inc.php"; include "../brain/data/Session.inc.php";
include "../brain/data/Member.inc.php";
include "../brain/utility/FileUploader.inc.php"; include "../brain/utility/FileUploader.inc.php";
include "../brain/utility/DocTools.inc.php"; include "../brain/utility/DocTools.inc.php";

Loading…
Cancel
Save