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
+46 -37
View File
@@ -5,6 +5,7 @@ require_once 'functions/functions.php';
include_once 'components/head.php';
include_once 'functions/article_functions.php';
include_once 'functions/account_functions.php';
// UI Components
foreach (glob('components/article/*.php') as $file)
@@ -22,49 +23,57 @@ if (isset($_POST['form_id'])) {
header('Location: articles.php?article_id=' . $_POST['article_id']);
} else {
$id = create_article($_SESSION['user_id'], $_POST['title'], $_POST['excerpt'], (isset($_POST['tags']) ? $_POST['tags'] : []), $_POST['markdown']);
$emails = exec_stmt('SELECT email FROM user INNER JOIN follows ON user.user_id = follows.follower_user_id WHERE follows.following_user_id = ? AND follows.notify_user = 1', 'i', $_SESSION['user_id'])->fetch_assoc();
notify_users($emails, $_SESSION['username'], $id, $_POST['title'], $_POST['excerpt']);
header('Location: articles.php?article_id=' . $id);
}
break;
case 'follow':
follow_user($_SESSION['user_id'], $_POST['author_id'], ($_POST['follow'] == 'email_notify' ? 1 : 0));
break;
case 'unfollow':
unfollow_user($_SESSION['user_id'], $_POST['author_id']);
break;
}
} else {
if (isset($_GET['view']))
$view = $_GET['view'];
else
$view = 'list';
}
switch ($view) {
case 'list':
echo article_list();
break;
case 'filter':
if (isset($_GET['tag']))
echo article_list(article_ids_by_tag($_GET['tag']));
else if (isset($_GET['author_id']))
echo article_list(articles_ids_by_author($_GET['author_id']));
break;
case 'sort':
if (isset($_GET['sort']) && $_GET['sort'] == 'oldest')
echo article_list(article_ids_by_oldest());
else if (isset($_GET['sort']) && $_GET['sort'] == 'newest')
echo article_list(article_ids_by_newest());
break;
case 'read':
if (isset($_SESSION['user_id']) && isset($_GET['article_id'])) {
increment_read_counter($_GET['article_id']);
echo article_page_from_markdown($_GET['article_id']);
} else {
$redirect = (isset($_GET['article_id']) ? 'articles.php?view=read&article_id=' . $_GET['article_id'] : '');
if ($redirect)
header('Location: user.php?view=login&redirect=' . urlencode($redirect));
else
header('Location: articles.php');
}
break;
case 'compose':
echo compose_view((isset($_GET['article_id']) ? $_GET['article_id'] : ''));
break;
}
if (isset($_GET['view']))
$view = $_GET['view'];
else
$view = 'list';
switch ($view) {
case 'list':
echo article_list();
break;
case 'filter':
if (isset($_GET['tag']))
echo article_list(article_ids_by_tag($_GET['tag']));
else if (isset($_GET['author_id']))
echo article_list(articles_ids_by_author($_GET['author_id']));
break;
case 'sort':
if (isset($_GET['sort']) && $_GET['sort'] == 'oldest')
echo article_list(article_ids_by_oldest());
else if (isset($_GET['sort']) && $_GET['sort'] == 'newest')
echo article_list(article_ids_by_newest());
break;
case 'read':
if (isset($_SESSION['user_id']) && isset($_GET['article_id'])) {
increment_read_counter($_GET['article_id']);
echo article_page_from_markdown($_GET['article_id']);
} else {
$redirect = (isset($_GET['article_id']) ? 'articles.php?view=read&article_id=' . $_GET['article_id'] : '');
if ($redirect)
header('Location: user.php?view=login&redirect=' . urlencode($redirect));
else
header('Location: articles.php');
}
break;
case 'compose':
echo compose_view((isset($_GET['article_id']) ? $_GET['article_id'] : ''));
break;
}
if (($view == 'list' || $view == 'sort') && (isset($_SESSION['role_id']) && $_SESSION['role_id'] <= 3)) {