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" />