Fixed some bugs in the newsletter images, made some minor improvements in other areas. Added in unsubscribe functionality
🚀 Deploy website on push / 🎉 Deploy (push) Successful in 21s
🚀 Deploy website on push / 🎉 Deploy (push) Successful in 21s
Signed-off-by: rodude123 <rodude123@gmail.com>
This commit is contained in:
Vendored
+21
-12
@@ -296,17 +296,18 @@ class blogData
|
||||
$latest = $this->getLatestBlogPost();
|
||||
$prevTitle = $latest["title"];
|
||||
$prevAbstract = $latest["abstract"];
|
||||
$prevHeaderImage = $latest["headerImg"];
|
||||
$prevHeaderImage = substr($latest["headerImg"], 10);
|
||||
$prevHeaderImage = str_ireplace("%2F", "/", $prevHeaderImage);
|
||||
|
||||
$headerImage = $targetFile["imgLocation"];
|
||||
$headerImage = rawurlencode("../" . $targetFile["imgLocation"]);
|
||||
|
||||
$stmt = $conn->prepare("INSERT INTO blog (title, dateCreated, dateModified, featured, headerImg, abstract, body, bodyText, categories, keywords, folderID)
|
||||
VALUES (:title, :dateCreated, :dateModified, :featured, :headerImg, :abstract, :body, :bodyText, :categories, :keywords, :folderID);");
|
||||
$stmt->bindParam(":title", $title);
|
||||
$stmt->bindParam(":dateCreated", $dateCreated);
|
||||
$stmt->bindParam(":dateModified", $dateCreated);
|
||||
$isFeatured = $featured ? 1 : 0;
|
||||
$stmt->bindParam(":featured", $isFeatured);
|
||||
// $isFeatured = $featured ? 1 : 0;
|
||||
$stmt->bindParam(":featured", $featured);
|
||||
$stmt->bindParam(":headerImg", $headerImage);
|
||||
$stmt->bindParam(":abstract", $abstract);
|
||||
$stmt->bindParam(":body", $newBody);
|
||||
@@ -323,6 +324,8 @@ class blogData
|
||||
$stmtEmails = $conn->prepare("SELECT email FROM newsletter;");
|
||||
$stmtEmails->execute();
|
||||
$emails = $stmtEmails->fetchAll(PDO::FETCH_ASSOC);
|
||||
$headerImage = substr($headerImage, 10);
|
||||
$headerImage = str_ireplace("%2F", "/", $headerImage);
|
||||
|
||||
$emailBody = <<<EOD
|
||||
<!DOCTYPE html>
|
||||
@@ -533,7 +536,7 @@ class blogData
|
||||
<div class="postContainer">
|
||||
<h2>latest post</h2>
|
||||
<div class="image">
|
||||
<img src="$headerImage" alt="header image of the latest post">
|
||||
<img src="https://rohitpai.co.uk/$headerImage" alt="header image of the latest post">
|
||||
</div>
|
||||
|
||||
<div class="post">
|
||||
@@ -546,7 +549,7 @@ class blogData
|
||||
<div class="postContainer">
|
||||
<h2>in case you missed the previous post</h2>
|
||||
<div class="image">
|
||||
<img src="$prevHeaderImage" alt="header image of the previous post">
|
||||
<img src="https://rohitpai.co.uk/$prevHeaderImage" alt="header image of the previous post">
|
||||
</div>
|
||||
|
||||
<div class="post">
|
||||
@@ -556,21 +559,26 @@ class blogData
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
EOD;
|
||||
|
||||
foreach ($emails as $email)
|
||||
{
|
||||
$emailFooter = <<<EOD
|
||||
<footer>
|
||||
<div class="nav">
|
||||
<ul>
|
||||
<li><a href="https://rohitpai.co.uk/blog"><https://rohitpai.co.uk/blog></a></li>
|
||||
<li><a href="https://rohitpai.co.uk/blog/unsubscribe"><Unsubscribe></a></li>
|
||||
<li><a href="https://rohitpai.co.uk/blog/unsubscribe/$email"><Unsubscribe></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="date">2023</div>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
EOD;
|
||||
EOD;
|
||||
$emailBody .= $emailFooter;
|
||||
|
||||
foreach ($emails as $email)
|
||||
{
|
||||
$this->sendMail($email["email"], $emailBody, "Hey, Rohit's blog has a new post!");
|
||||
}
|
||||
|
||||
@@ -642,7 +650,8 @@ EOD;
|
||||
unlink($result["headerImg"]);
|
||||
$stmt = $conn->prepare("UPDATE blog SET headerImg = :headerImg WHERE ID = :ID;");
|
||||
$stmt->bindParam(":ID", $ID);
|
||||
$stmt->bindParam(":headerImg", $targetFile["imgLocation"]);
|
||||
$location = urldecode("../" . $targetFile["imgLocation"]);
|
||||
$stmt->bindParam(":headerImg", $location);
|
||||
$stmt->execute();
|
||||
if ($stmt->rowCount() > 0)
|
||||
{
|
||||
@@ -1168,7 +1177,7 @@ EOD;
|
||||
<div class="nav">
|
||||
<ul>
|
||||
<li><a href="https://rohitpai.co.uk/blog"><https://rohitpai.co.uk/blog></a></li>
|
||||
<li><a href="https://rohitpai.co.uk/blog/unsubscribe"><Unsubscribe></a></li>
|
||||
<li><a href="https://rohitpai.co.uk/blog/unsubscribe/$email"><Unsubscribe></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="date">2023</div>
|
||||
|
||||
Reference in New Issue
Block a user