Setup initial backend for the blog posts and added in the link to the pages
Signed-off-by: rodude123 <rodude123@gmail.com>
This commit is contained in:
Vendored
+98
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
namespace api;
|
||||
use PDO;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
|
||||
require_once "./config.php";
|
||||
|
||||
/**
|
||||
* Blog Data Class
|
||||
* Define all functions which either get, update, create or delete posts
|
||||
*/
|
||||
class blogData
|
||||
{
|
||||
/**
|
||||
* Get all blog posts
|
||||
* @return array - Array of all blog posts or error message
|
||||
*/
|
||||
function getBlogPosts(): array
|
||||
{
|
||||
$conn = dbConn();
|
||||
$stmt = $conn->prepare("SELECT ID, title, dateCreated, dateModified, body, tags FROM blog ORDER BY dateCreated DESC;");
|
||||
$stmt->execute();
|
||||
|
||||
// set the resulting array to associative
|
||||
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
return $result;
|
||||
}
|
||||
|
||||
return array("errorMessage" => "Error, blog data not found");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a blog post with the given ID
|
||||
* @param string $ID - ID of the blog post to get
|
||||
* @return array - Array of all blog posts or error message
|
||||
*/
|
||||
function getBlogPost(string $ID): array
|
||||
{
|
||||
$conn = dbConn();
|
||||
$stmt = $conn->prepare("SELECT ID, title, dateCreated, dateModified, featured, headerImg, body, tags FROM blog WHERE ID = :ID;");
|
||||
$stmt->bindParam(":ID", $ID);
|
||||
$stmt->execute();
|
||||
|
||||
// set the resulting array to associative
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
return $result;
|
||||
}
|
||||
|
||||
return array("errorMessage" => "Error, blog post could not found");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the latest blog post
|
||||
* @return array - Array of the latest blog post or error message
|
||||
*/
|
||||
function getLatestBlogPost(): array
|
||||
{
|
||||
$conn = dbConn();
|
||||
$stmt = $conn->prepare("SELECT ID, title, dateCreated, dateModified, featured, headerImg, body, tags FROM blog ORDER BY dateCreated DESC LIMIT 1;");
|
||||
$stmt->execute();
|
||||
|
||||
// set the resulting array to associative
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
return $result;
|
||||
}
|
||||
|
||||
return array("errorMessage" => "Error, blog post could not found");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get featured blog post
|
||||
* @return array - Array of the featured blog post or error message
|
||||
*/
|
||||
function getFeaturedBlogPost(): array
|
||||
{
|
||||
$conn = dbConn();
|
||||
$stmt = $conn->prepare("SELECT ID, title, dateCreated, dateModified, featured, headerImg, body, tags FROM blog WHERE featured = 1;");
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($result)
|
||||
{
|
||||
return $result;
|
||||
}
|
||||
|
||||
return array("errorMessage" => "Error, blog post could not found");
|
||||
}
|
||||
}
|
||||
Vendored
+4
-1
@@ -1,4 +1,4 @@
|
||||
<?php /** @noinspection PhpIncludeInspection */
|
||||
<?php
|
||||
|
||||
////////////////// Index file //////////////
|
||||
/// Creates base routes and runs ///
|
||||
@@ -10,7 +10,9 @@ include "middleware.php";
|
||||
include "timelineData.php";
|
||||
include "projectData.php";
|
||||
include "user.php";
|
||||
include "blogData.php";
|
||||
|
||||
use api\blogData;
|
||||
use api\middleware;
|
||||
use api\projectData;
|
||||
use api\timelineData;
|
||||
@@ -33,6 +35,7 @@ new middleware($app);
|
||||
|
||||
$timelineData = new timelineData();
|
||||
$projectData = new projectData();
|
||||
$blogData = new blogData();
|
||||
$user = new user();
|
||||
|
||||
$app->get("/timelineData/{timeline}", function (Request $request, Response $response, array $args)
|
||||
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Test page</title></head><body><a href="#" onclick="return goToURL('post/full-stack-dev-2023-starting-guide');">full-stack-dev-2023-starting-guide</a><p id="url"></p><script src="/blog/index.js"></script></body></html>
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Blog</title></head><body>this is a test<script src="/blog/index.js"></script></body></html>
|
||||
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
Vendored
+1
-1
@@ -1 +1 @@
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1,minimum-scale=1"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Rohit Pai - All Projects</title><link rel="stylesheet" href="css/main.css"><script src="https://kit.fontawesome.com/ed3c25598e.js" crossorigin="anonymous"></script></head><body><nav><input type="checkbox" id="nav-check"> <a href="/"><h1>rohit pai</h1></a><div class="nav-btn"><label for="nav-check"><span></span> <span></span> <span></span></label></div><ul><li><a href="/#about" class="textShadow"><span><</span>about<span>></span></a></li><li><a href="/#curriculumVitae" class="textShadow"><span><</span>cv<span>></span></a></li><li><a href="#allProjects" class="textShadow active"><span><</span>projects<span>></span></a></li><li><a href="/#contact" class="textShadow"><span><</span>contact<span>></span></a></li><li><a href="#" class="textShadow"><span><</span>blog<span>></span></a></li></ul></nav><header><div><h1>full stack developer</h1><a href="/#sayHello" class="btn btnPrimary boxShadowIn boxShadowOut">Contact Me</a> <a href="#allProjects"><i class="fa-solid fa-chevron-down"></i></a></div></header><main><section id="allProjects"><div class="mainProj" id="mainProj"></div><div class="otherProj" id="otherProj"></div></section></main><footer class="flexRow"><div class="spacer"></div><p>© <span id="year"></span> Rohit Pai all rights reserved</p><div class="button"><button id="goBackToTop"><i class="fa-solid fa-chevron-up"></i></button></div></footer><script src="js/typewriter.js"></script><script src="js/projects.js"></script></body></html>
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1,minimum-scale=1"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Rohit Pai - All Projects</title><link rel="stylesheet" href="css/main.css"><script src="https://kit.fontawesome.com/ed3c25598e.js" crossorigin="anonymous"></script></head><body><nav><input type="checkbox" id="nav-check"> <a href="/"><h1>rohit pai</h1></a><div class="nav-btn"><label for="nav-check"><span></span> <span></span> <span></span></label></div><ul><li><a href="/#about" class="textShadow"><span><</span>about<span>></span></a></li><li><a href="/#curriculumVitae" class="textShadow"><span><</span>cv<span>></span></a></li><li><a href="#allProjects" class="textShadow active"><span><</span>projects<span>></span></a></li><li><a href="/#contact" class="textShadow"><span><</span>contact<span>></span></a></li><li><a href="/blog" class="textShadow"><span><</span>blog<span>></span></a></li></ul></nav><header><div><h1>full stack developer</h1><a href="/#sayHello" class="btn btnPrimary boxShadowIn boxShadowOut">Contact Me</a> <a href="#allProjects"><i class="fa-solid fa-chevron-down"></i></a></div></header><main><section id="allProjects"><div class="mainProj" id="mainProj"></div><div class="otherProj" id="otherProj"></div></section></main><footer class="flexRow"><div class="spacer"></div><p>© <span id="year"></span> Rohit Pai all rights reserved</p><div class="button"><button id="goBackToTop"><i class="fa-solid fa-chevron-up"></i></button></div></footer><script src="js/typewriter.js"></script><script src="js/projects.js"></script></body></html>
|
||||
Reference in New Issue
Block a user