Added in the ability not upload a headerImage and instead use a placeholder. Folder ID is now stored in the DB
Signed-off-by: rodude123 <rodude123@gmail.com>
This commit is contained in:
parent
bae523b62b
commit
7b637dac7b
@ -14,6 +14,7 @@
|
||||
"slim/slim": "^4.10",
|
||||
"rbdwllr/psr-jwt": "^2.0",
|
||||
"tuupola/slim-jwt-auth": "^3.6",
|
||||
"ext-dom": "*"
|
||||
"ext-dom": "*",
|
||||
"ext-libxml": "*"
|
||||
}
|
||||
}
|
||||
|
15
dist/api/blog/blogData.php
vendored
15
dist/api/blog/blogData.php
vendored
@ -145,10 +145,18 @@ class blogData
|
||||
public function createPost(string $title, string $body, string $dateCreated, string $featured, string $categories, UploadedFileInterface $headerImg): int|string
|
||||
{
|
||||
$conn = dbConn();
|
||||
$targetDir = "../blog/imgs/" . $title . "_" . uniqid() . "/";
|
||||
$targetFile = "";
|
||||
$folderID = uniqid();
|
||||
if ($headerImg !== null)
|
||||
{
|
||||
$targetDir = "../blog/imgs/" . $title . "_" . $folderID . "/";
|
||||
mkdir($targetDir, 0777, true);
|
||||
$imagUtils = new imgUtils();
|
||||
$targetFile = $imagUtils->uploadFile($targetDir, $headerImg);
|
||||
}
|
||||
|
||||
$targetFile = array("imgLocation" => ".../blog/imgs/placeholder.png");
|
||||
|
||||
if (!is_array($targetFile))
|
||||
{
|
||||
return $targetFile;
|
||||
@ -192,8 +200,8 @@ class blogData
|
||||
$newBody .= $htmlDoc->saveHTML($node);
|
||||
}
|
||||
|
||||
$stmt = $conn->prepare("INSERT INTO blog (title, dateCreated, dateModified, featured, headerImg, body, categories)
|
||||
VALUES (:title, :dateCreated, :dateModified, :featured, :headerImg, :body, :categories);");
|
||||
$stmt = $conn->prepare("INSERT INTO blog (title, dateCreated, dateModified, featured, headerImg, body, categories, folderID)
|
||||
VALUES (:title, :dateCreated, :dateModified, :featured, :headerImg, :body, :categories, :folderID);");
|
||||
$stmt->bindParam(":title", $title);
|
||||
$stmt->bindParam(":dateCreated", $dateCreated);
|
||||
$stmt->bindParam(":dateModified", $dateCreated);
|
||||
@ -201,6 +209,7 @@ class blogData
|
||||
$stmt->bindParam(":headerImg", $targetFile["imgLocation"]);
|
||||
$stmt->bindParam(":body", $newBody);
|
||||
$stmt->bindParam(":categories", $categories);
|
||||
$stmt->bindParam(":folderID", $folderID);
|
||||
|
||||
if ($stmt->execute())
|
||||
{
|
||||
|
10
dist/api/blog/blogRoutes.php
vendored
10
dist/api/blog/blogRoutes.php
vendored
@ -33,14 +33,20 @@ class blogRoutes implements routesInterface
|
||||
{
|
||||
$data = $request->getParsedBody();
|
||||
$files = $request->getUploadedFiles();
|
||||
if (empty($data["title"]) || empty($data["body"]) || empty($data["dateCreated"]) || empty($data["featured"]) || empty($data["categories"]) || empty($files["headerImg"]))
|
||||
$headerImg = $files["headerImg"];
|
||||
if (empty($data["title"]) || empty($data["body"]) || empty($data["dateCreated"]) || empty($data["featured"]) || empty($data["categories"]))
|
||||
{
|
||||
// uh oh sent some empty data
|
||||
$response->getBody()->write(json_encode(array("error" => "Error, empty data sent")));
|
||||
return $response->withStatus(400);
|
||||
}
|
||||
|
||||
$insertedID = $this->blogData->createPost($data["title"], $data["body"], $data["dateCreated"], $data["featured"], $data["categories"], $files["headerImg"]);
|
||||
if (empty($files["headerImg"]))
|
||||
{
|
||||
$headerImg = null;
|
||||
}
|
||||
|
||||
$insertedID = $this->blogData->createPost($data["title"], $data["body"], $data["dateCreated"], $data["featured"], $data["categories"], $headerImg);
|
||||
if (!is_int($insertedID))
|
||||
{
|
||||
// uh oh something went wrong
|
||||
|
BIN
dist/blog/imgs/placeholder.png
vendored
Normal file
BIN
dist/blog/imgs/placeholder.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.0 KiB |
@ -145,10 +145,18 @@ class blogData
|
||||
public function createPost(string $title, string $body, string $dateCreated, string $featured, string $categories, UploadedFileInterface $headerImg): int|string
|
||||
{
|
||||
$conn = dbConn();
|
||||
$targetDir = "../blog/imgs/" . $title . "_" . uniqid() . "/";
|
||||
$targetFile = "";
|
||||
$folderID = uniqid();
|
||||
if ($headerImg !== null)
|
||||
{
|
||||
$targetDir = "../blog/imgs/" . $title . "_" . $folderID . "/";
|
||||
mkdir($targetDir, 0777, true);
|
||||
$imagUtils = new imgUtils();
|
||||
$targetFile = $imagUtils->uploadFile($targetDir, $headerImg);
|
||||
}
|
||||
|
||||
$targetFile = array("imgLocation" => ".../blog/imgs/placeholder.png");
|
||||
|
||||
if (!is_array($targetFile))
|
||||
{
|
||||
return $targetFile;
|
||||
@ -192,8 +200,8 @@ class blogData
|
||||
$newBody .= $htmlDoc->saveHTML($node);
|
||||
}
|
||||
|
||||
$stmt = $conn->prepare("INSERT INTO blog (title, dateCreated, dateModified, featured, headerImg, body, categories)
|
||||
VALUES (:title, :dateCreated, :dateModified, :featured, :headerImg, :body, :categories);");
|
||||
$stmt = $conn->prepare("INSERT INTO blog (title, dateCreated, dateModified, featured, headerImg, body, categories, folderID)
|
||||
VALUES (:title, :dateCreated, :dateModified, :featured, :headerImg, :body, :categories, :folderID);");
|
||||
$stmt->bindParam(":title", $title);
|
||||
$stmt->bindParam(":dateCreated", $dateCreated);
|
||||
$stmt->bindParam(":dateModified", $dateCreated);
|
||||
@ -201,6 +209,7 @@ class blogData
|
||||
$stmt->bindParam(":headerImg", $targetFile["imgLocation"]);
|
||||
$stmt->bindParam(":body", $newBody);
|
||||
$stmt->bindParam(":categories", $categories);
|
||||
$stmt->bindParam(":folderID", $folderID);
|
||||
|
||||
if ($stmt->execute())
|
||||
{
|
||||
|
@ -33,14 +33,20 @@ class blogRoutes implements routesInterface
|
||||
{
|
||||
$data = $request->getParsedBody();
|
||||
$files = $request->getUploadedFiles();
|
||||
if (empty($data["title"]) || empty($data["body"]) || empty($data["dateCreated"]) || empty($data["featured"]) || empty($data["categories"]) || empty($files["headerImg"]))
|
||||
$headerImg = $files["headerImg"];
|
||||
if (empty($data["title"]) || empty($data["body"]) || empty($data["dateCreated"]) || empty($data["featured"]) || empty($data["categories"]))
|
||||
{
|
||||
// uh oh sent some empty data
|
||||
$response->getBody()->write(json_encode(array("error" => "Error, empty data sent")));
|
||||
return $response->withStatus(400);
|
||||
}
|
||||
|
||||
$insertedID = $this->blogData->createPost($data["title"], $data["body"], $data["dateCreated"], $data["featured"], $data["categories"], $files["headerImg"]);
|
||||
if (empty($files["headerImg"]))
|
||||
{
|
||||
$headerImg = null;
|
||||
}
|
||||
|
||||
$insertedID = $this->blogData->createPost($data["title"], $data["body"], $data["dateCreated"], $data["featured"], $data["categories"], $headerImg);
|
||||
if (!is_int($insertedID))
|
||||
{
|
||||
// uh oh something went wrong
|
||||
|
BIN
src/blog/imgs/placeholder.png
Normal file
BIN
src/blog/imgs/placeholder.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.0 KiB |
Loading…
Reference in New Issue
Block a user