Created individual categories page
Signed-off-by: rodude123 <rodude123@gmail.com>
This commit is contained in:
Vendored
+8
-8
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace api\blog;
|
||||
|
||||
use api\utils\imgUtils;
|
||||
use DOMDocument;
|
||||
use PDO;
|
||||
@@ -125,7 +127,7 @@ class blogData
|
||||
public function getCategories(): array
|
||||
{
|
||||
$conn = dbConn();
|
||||
$stmt = $conn->prepare("SELECT categories FROM blog;");
|
||||
$stmt = $conn->prepare("SELECT DISTINCT categories FROM blog;");
|
||||
$stmt->execute();
|
||||
|
||||
// set the resulting array to associative
|
||||
@@ -415,7 +417,7 @@ class blogData
|
||||
}
|
||||
else
|
||||
{
|
||||
rename($from . $file,$to . $file);
|
||||
rename($from . $file, $to . $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -430,17 +432,15 @@ class blogData
|
||||
|
||||
/**
|
||||
* Get all posts with the given category
|
||||
* @param mixed $category - Category of the post
|
||||
* @param string $category - Category of the post
|
||||
* @return array - Array of all posts with the given category or error message
|
||||
*/
|
||||
public function getPostsByCategory(mixed $category)
|
||||
public function getPostsByCategory(string $category): array
|
||||
{
|
||||
$conn = dbConn();
|
||||
$stmt = $conn->prepare("SELECT * FROM blog WHERE categories = :category;");
|
||||
$stmt = $conn->prepare("SELECT * FROM blog WHERE LOCATE(:category, categories) > 0;");
|
||||
$stmt->bindParam(":category", $category);
|
||||
$stmt->execute();
|
||||
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
|
||||
return $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
}
|
||||
Vendored
+4
-3
@@ -12,6 +12,7 @@ use Slim\App;
|
||||
class blogRoutes implements routesInterface
|
||||
{
|
||||
private blogData $blogData;
|
||||
|
||||
/**
|
||||
* constructor used to instantiate a base blog routes, to be used in the index.php file.
|
||||
* @param App $app - the slim app used to create the routes
|
||||
@@ -134,14 +135,14 @@ class blogRoutes implements routesInterface
|
||||
return $response->withStatus(400);
|
||||
}
|
||||
|
||||
if (!preg_match('/(?:^|,)(?=[^"]|(")?)"?((?(1)(?:[^"]|"")*|[^,"]*))"?(?=,|$)/mx', $data["categories"]))
|
||||
if (!preg_match('/[a-zA-Z0-9 ]+, |\w+/mx', $data["categories"]))
|
||||
{
|
||||
// uh oh sent some empty data
|
||||
$response->getBody()->write(json_encode(array("error" => "Categories must be in a CSV format")));
|
||||
return $response->withStatus(400);
|
||||
}
|
||||
|
||||
$message = $this->blogData->updatePost($args["id"], $data["title"], intval($data["featured"]), $data["abstract"], $data["body"], $data["dateModified"], $data["categories"]);
|
||||
$message = $this->blogData->updatePost($args["id"], $data["title"], intval($data["featured"]), $data["abstract"], $data["body"], $data["dateModified"], $data["categories"]);
|
||||
|
||||
if ($message === "post not found")
|
||||
{
|
||||
@@ -218,7 +219,7 @@ class blogRoutes implements routesInterface
|
||||
return $response->withStatus(400);
|
||||
}
|
||||
|
||||
if (!preg_match('/(?:^|,)(?=[^"]|(")?)"?((?(1)(?:[^"]|"")*|[^,"]*))"?(?=,|$)/mx', $data["categories"]))
|
||||
if (!preg_match('/[a-zA-Z0-9 ]+, |\w+/mx', $data["categories"]))
|
||||
{
|
||||
// uh oh sent some empty data
|
||||
$response->getBody()->write(json_encode(array("error" => "Categories must be in a CSV format")));
|
||||
|
||||
Vendored
+1
-1
@@ -39,7 +39,7 @@ new userRoutes($app);
|
||||
$app->post("/contact", function (Request $request, Response $response)
|
||||
{
|
||||
$data = $request->getParsedBody();
|
||||
if(empty($data["fName"]) || empty($data["lName"]) || empty($data["email"]) || empty($data["subject"]) || empty($data["message"]))
|
||||
if (empty($data["fName"]) || empty($data["lName"]) || empty($data["email"]) || empty($data["subject"]) || empty($data["message"]))
|
||||
{
|
||||
$response->getBody()->write(json_encode(array("errorMessage" => "Please fill out all the fields")));
|
||||
return $response->withStatus(400);
|
||||
|
||||
Vendored
+3
-1
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace api\project;
|
||||
|
||||
use api\utils\imgUtils;
|
||||
use PDO;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
@@ -162,7 +164,7 @@ class projectData
|
||||
* @param UploadedFileInterface $img - Image preview of the project
|
||||
* @return string|array - String with error message or array with the new image location
|
||||
*/
|
||||
public function uploadImage(int $ID, UploadedFileInterface $img): string | array
|
||||
public function uploadImage(int $ID, UploadedFileInterface $img): string|array
|
||||
{
|
||||
|
||||
$conn = dbConn();
|
||||
|
||||
Vendored
+2
-1
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace api\project;
|
||||
require_once __DIR__ . "/../utils/routesInterface.php";
|
||||
require_once "projectData.php";
|
||||
@@ -37,7 +38,7 @@ class projectRoutes implements routesInterface
|
||||
|
||||
$response->getBody()->write($json);
|
||||
|
||||
if(array_key_exists("errorMessage", $result))
|
||||
if (array_key_exists("errorMessage", $result))
|
||||
{
|
||||
$response->withStatus(404);
|
||||
}
|
||||
|
||||
Vendored
+3
-3
@@ -31,7 +31,7 @@ class timelineData
|
||||
}
|
||||
return array("errorMessage" => "Error, edu data not found");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all work data
|
||||
* @return array - Array of all work data or error message
|
||||
@@ -178,7 +178,7 @@ class timelineData
|
||||
|
||||
return "error";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create new education data
|
||||
* @param string $dateFrom - Start date
|
||||
@@ -202,7 +202,7 @@ class timelineData
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create new work data
|
||||
* @param string $dateFrom - Start date
|
||||
|
||||
Vendored
+2
-1
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace api\timeline;
|
||||
require_once __DIR__ . "/../utils/routesInterface.php";
|
||||
require_once "timelineData.php";
|
||||
@@ -39,7 +40,7 @@ class timelineRoutes implements routesInterface
|
||||
return $response;
|
||||
}
|
||||
|
||||
if($args["timeline"] == "work")
|
||||
if ($args["timeline"] == "work")
|
||||
{
|
||||
$response->getBody()->write(json_encode($this->timelineData->getWorkData()));
|
||||
return $response;
|
||||
|
||||
Vendored
+5
-3
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace api\user;
|
||||
|
||||
use Firebase\JWT\JWT;
|
||||
use PDO;
|
||||
|
||||
@@ -54,7 +56,7 @@ class userData
|
||||
"exp" => $future
|
||||
];
|
||||
|
||||
return JWT::encode($payload,$secretKey,"HS256");
|
||||
return JWT::encode($payload, $secretKey, "HS256");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,7 +110,7 @@ class userData
|
||||
</body>
|
||||
</html>
|
||||
";
|
||||
|
||||
|
||||
mail($email, "Reset Password Verification Code", $message, $headers1);
|
||||
return $token;
|
||||
}
|
||||
@@ -116,7 +118,7 @@ class userData
|
||||
/**
|
||||
* Change password for an email with new password
|
||||
* @param $email string Email
|
||||
* @param $password string Password
|
||||
* @param $password string Password
|
||||
* @return bool - true if the password was changed, false if not
|
||||
*/
|
||||
public function changePassword(string $email, string $password): bool
|
||||
|
||||
Vendored
+2
-1
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace api\user;
|
||||
require_once __DIR__ . "/../utils/routesInterface.php";
|
||||
require_once __DIR__ . "/../utils/routesInterface.php";
|
||||
require_once "userData.php";
|
||||
|
||||
use api\utils\routesInterface;
|
||||
|
||||
Vendored
+3
-3
@@ -45,7 +45,7 @@ class middleware
|
||||
$app->addBodyParsingMiddleware();
|
||||
$app->addRoutingMiddleware();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* SameSite Cookie Configuration
|
||||
* @param App $app - Slim App
|
||||
@@ -68,7 +68,7 @@ class middleware
|
||||
return $response->withHeader("Content-Type", "application/json");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* JWT Authentication
|
||||
* @param App $app - Slim App
|
||||
@@ -131,5 +131,5 @@ class middleware
|
||||
$app->addErrorMiddleware(true, true, true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user