add-to-blog #34
@ -14,6 +14,7 @@
|
|||||||
"slim/slim": "^4.10",
|
"slim/slim": "^4.10",
|
||||||
"rbdwllr/psr-jwt": "^2.0",
|
"rbdwllr/psr-jwt": "^2.0",
|
||||||
"tuupola/slim-jwt-auth": "^3.6",
|
"tuupola/slim-jwt-auth": "^3.6",
|
||||||
"ext-dom": "*"
|
"ext-dom": "*",
|
||||||
|
"ext-libxml": "*"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
21
dist/api/blog/blogData.php
vendored
21
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
|
public function createPost(string $title, string $body, string $dateCreated, string $featured, string $categories, UploadedFileInterface $headerImg): int|string
|
||||||
{
|
{
|
||||||
$conn = dbConn();
|
$conn = dbConn();
|
||||||
$targetDir = "../blog/imgs/" . $title . "_" . uniqid() . "/";
|
$targetFile = "";
|
||||||
mkdir($targetDir, 0777, true);
|
$folderID = uniqid();
|
||||||
$imagUtils = new imgUtils();
|
if ($headerImg !== null)
|
||||||
$targetFile = $imagUtils->uploadFile($targetDir, $headerImg);
|
{
|
||||||
|
$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))
|
if (!is_array($targetFile))
|
||||||
{
|
{
|
||||||
return $targetFile;
|
return $targetFile;
|
||||||
@ -192,8 +200,8 @@ class blogData
|
|||||||
$newBody .= $htmlDoc->saveHTML($node);
|
$newBody .= $htmlDoc->saveHTML($node);
|
||||||
}
|
}
|
||||||
|
|
||||||
$stmt = $conn->prepare("INSERT INTO blog (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);");
|
VALUES (:title, :dateCreated, :dateModified, :featured, :headerImg, :body, :categories, :folderID);");
|
||||||
$stmt->bindParam(":title", $title);
|
$stmt->bindParam(":title", $title);
|
||||||
$stmt->bindParam(":dateCreated", $dateCreated);
|
$stmt->bindParam(":dateCreated", $dateCreated);
|
||||||
$stmt->bindParam(":dateModified", $dateCreated);
|
$stmt->bindParam(":dateModified", $dateCreated);
|
||||||
@ -201,6 +209,7 @@ class blogData
|
|||||||
$stmt->bindParam(":headerImg", $targetFile["imgLocation"]);
|
$stmt->bindParam(":headerImg", $targetFile["imgLocation"]);
|
||||||
$stmt->bindParam(":body", $newBody);
|
$stmt->bindParam(":body", $newBody);
|
||||||
$stmt->bindParam(":categories", $categories);
|
$stmt->bindParam(":categories", $categories);
|
||||||
|
$stmt->bindParam(":folderID", $folderID);
|
||||||
|
|
||||||
if ($stmt->execute())
|
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();
|
$data = $request->getParsedBody();
|
||||||
$files = $request->getUploadedFiles();
|
$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
|
// uh oh sent some empty data
|
||||||
$response->getBody()->write(json_encode(array("error" => "Error, empty data sent")));
|
$response->getBody()->write(json_encode(array("error" => "Error, empty data sent")));
|
||||||
return $response->withStatus(400);
|
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))
|
if (!is_int($insertedID))
|
||||||
{
|
{
|
||||||
// uh oh something went wrong
|
// 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
|
public function createPost(string $title, string $body, string $dateCreated, string $featured, string $categories, UploadedFileInterface $headerImg): int|string
|
||||||
{
|
{
|
||||||
$conn = dbConn();
|
$conn = dbConn();
|
||||||
$targetDir = "../blog/imgs/" . $title . "_" . uniqid() . "/";
|
$targetFile = "";
|
||||||
mkdir($targetDir, 0777, true);
|
$folderID = uniqid();
|
||||||
$imagUtils = new imgUtils();
|
if ($headerImg !== null)
|
||||||
$targetFile = $imagUtils->uploadFile($targetDir, $headerImg);
|
{
|
||||||
|
$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))
|
if (!is_array($targetFile))
|
||||||
{
|
{
|
||||||
return $targetFile;
|
return $targetFile;
|
||||||
@ -192,8 +200,8 @@ class blogData
|
|||||||
$newBody .= $htmlDoc->saveHTML($node);
|
$newBody .= $htmlDoc->saveHTML($node);
|
||||||
}
|
}
|
||||||
|
|
||||||
$stmt = $conn->prepare("INSERT INTO blog (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);");
|
VALUES (:title, :dateCreated, :dateModified, :featured, :headerImg, :body, :categories, :folderID);");
|
||||||
$stmt->bindParam(":title", $title);
|
$stmt->bindParam(":title", $title);
|
||||||
$stmt->bindParam(":dateCreated", $dateCreated);
|
$stmt->bindParam(":dateCreated", $dateCreated);
|
||||||
$stmt->bindParam(":dateModified", $dateCreated);
|
$stmt->bindParam(":dateModified", $dateCreated);
|
||||||
@ -201,6 +209,7 @@ class blogData
|
|||||||
$stmt->bindParam(":headerImg", $targetFile["imgLocation"]);
|
$stmt->bindParam(":headerImg", $targetFile["imgLocation"]);
|
||||||
$stmt->bindParam(":body", $newBody);
|
$stmt->bindParam(":body", $newBody);
|
||||||
$stmt->bindParam(":categories", $categories);
|
$stmt->bindParam(":categories", $categories);
|
||||||
|
$stmt->bindParam(":folderID", $folderID);
|
||||||
|
|
||||||
if ($stmt->execute())
|
if ($stmt->execute())
|
||||||
{
|
{
|
||||||
|
@ -33,14 +33,20 @@ class blogRoutes implements routesInterface
|
|||||||
{
|
{
|
||||||
$data = $request->getParsedBody();
|
$data = $request->getParsedBody();
|
||||||
$files = $request->getUploadedFiles();
|
$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
|
// uh oh sent some empty data
|
||||||
$response->getBody()->write(json_encode(array("error" => "Error, empty data sent")));
|
$response->getBody()->write(json_encode(array("error" => "Error, empty data sent")));
|
||||||
return $response->withStatus(400);
|
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))
|
if (!is_int($insertedID))
|
||||||
{
|
{
|
||||||
// uh oh something went wrong
|
// 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