implemented following users to receive (opt-in) email notifications when they publish an article.

This commit is contained in:
2025-04-14 22:32:32 -06:00
parent fdcc1a3349
commit 420022dbf8
11 changed files with 248 additions and 82 deletions
+36 -4
View File
@@ -8,6 +8,7 @@ function article_page_from_markdown($article_id)
$article = exec_stmt('SELECT * FROM article WHERE article_id = ?', 'i', $article_id)->fetch_assoc();
$author = exec_stmt('SELECT user_id, username, profile_picture FROM user WHERE user_id = ?', 'i', $article['author_id'])->fetch_assoc();
$markdown = read_file_one_string($_ENV['ARTICLES_FQ_PATH'] . $article_id . '/article.md');
$following = exec_stmt('SELECT follower_user_id, following_user_id FROM follows WHERE follower_user_id = ? AND following_user_id = ?', 'ii', $_SESSION['user_id'], $author['user_id'])->fetch_assoc();
$parsedown = new Parsedown();
$parsedown->setSafeMode(true);
@@ -21,10 +22,41 @@ function article_page_from_markdown($article_id)
' . (isset($_SESSION['user_id']) && $_SESSION['user_id'] == $article['author_id'] ? '<a href="articles.php?view=compose&article_id=' . $article_id . '"><i class="nf nf-fa-edit"></i></a>' : '') . '
</div>
<div class="row">
<div class="col_right">
<h5>Written by <a href="user.php?action=view&user_id=' . $author['user_id'] . '">' . $author['username'] . '</a></h5>
<p>Published on ' . $article['published_at'] . '<br>
Lasted edited on ' . $article['updated_at'] . '</p>
<div class="row">
<div class="col_right">
<h5>Written by <a href="user.php?view=display&user_id=' . $author['user_id'] . '">' . $author['username'] . '</a></h5>
<p>Published on ' . $article['published_at'] . '<br>
Lasted edited on ' . $article['updated_at'] . '</p>
</div>
';
if ($_SESSION['user_id'] != $author['user_id'] && !$following) {
$html .= '
<div class="dropdown">
<span>Follow</span>
<div class="dropdown_content">
<form method="post">
<input type="hidden" name="form_id" value="follow">
<input type="hidden" name="author_id" value="' . $author['user_id'] . '">
<button name="follow" value="no_notify" class="button"><i class="nf nf-md-bell_cancel"></i></button>
<button name="follow" value="email_notify" class="button"><i class="nf nf-cod-mail"></i></button>
</form>
</div>
</div>
';
} else if ($following) {
$html .= '
<div class="margin_right">
<form method="post">
<input type="hidden" name="form_id" value="unfollow">
<input type="hidden" name="author_id" value="' . $author['user_id'] . '">
<input type="submit" value="Unfollow">
</form>
</div>
';
}
$html .= '
</div>
<div class="card_pic_box">
<img src="' . $_ENV['PROFILE_IMAGES_PQ_PATH'] . $author['profile_picture'] . '" class="card_profile_picture" />
+1 -1
View File
@@ -27,7 +27,7 @@ function article_card($article_id)
<h4>' . $article['title'] . '</h4>
<div class="card_info_box">
<div class="col-right">
<a href="user.php?action=view&user_id=' . $author['user_id'] . '">Written by: ' . $author['username'] . '</a>
<a href="user.php?view=display&user_id=' . $author['user_id'] . '">Written by: ' . $author['username'] . '</a>
<small>Published: ' . $article['published_at'] . '</small>
<small>Updated: ' . $article['updated_at'] . '</small>
</div>
+38 -2
View File
@@ -1,14 +1,50 @@
<?php
include_once 'components/article/card.php';
function user_view($user_id)
{
if ($_SESSION['user_id'] != $user_id)
$following = exec_stmt('SELECT follower_user_id, following_user_id FROM follows WHERE follower_user_id = ? AND following_user_id = ?', 'ii', $_SESSION['user_id'], $user_id)->fetch_assoc();
$user = exec_stmt('SELECT user_id, username, email, role_id, created_at, last_active, is_active, profile_picture FROM user WHERE user_id = ?', 'i', $user_id)->fetch_assoc();
if ($user == null)
header('Location: articles.php');
header('Location: articles.php?view=sort&sort=newest');
$view = '
<div class="user_view">
<div class="row">
<h1>' . $user['username'] . '</h1>
<div class="row">
<h1>' . $user['username'] . '</h1>
';
if ($_SESSION['user_id'] != $user_id && !$following) {
$view .= '
<div class="dropdown">
<span>Follow</span>
<div class="dropdown_content">
<form method="post">
<input type="hidden" name="form_id" value="follow">
<input type="hidden" name="author_id" value="' . $user_id . '">
<button name="follow" value="no_notify" class="button"><i class="nf nf-md-bell_cancel"></i></button>
<button name="follow" value="email_notify" class="button"><i class="nf nf-cod-mail"></i></button>
</form>
</div>
</div>
';
} else if ($following) {
$view .= '
<div class="margin_right">
<form method="post">
<input type="hidden" name="form_id" value="unfollow">
<input type="hidden" name="author_id" value="' . $user_id . '">
<input type="submit" value="Unfollow">
</form>
</div>
';
}
$view .= '
</div>
<div class="card_pic_box">
<img src="' . $_ENV['PROFILE_IMAGES_PQ_PATH'] . $user['profile_picture'] . '" class="profile_picture" />
</div>