implemented article composer functionality + interface, login & signup functionality + interface, auth permission functionality reflected in the nav, and determined a unified accent color accessible in dark and light mode

This commit is contained in:
Joshua Ashton
2025-03-25 13:09:05 -06:00
parent c0fc9e9d00
commit 0a27cd1f5c
11 changed files with 624 additions and 53 deletions
+60 -10
View File
@@ -4,7 +4,7 @@ require 'db_functions.php';
function article_ids_by_recency()
{
$query = 'SELECT article_id FROM article ORDER BY published_at DESC;';
$results = query_db_one_or_more_results($query);
$results = query_one_or_more_results($query);
$ids = [];
@@ -14,10 +14,22 @@ function article_ids_by_recency()
return $ids;
}
function article_tags()
{
$query = 'SELECT * FROM tags;';
$results = query_one_or_more_results($query);
$tags = [];
while ($row = mysqli_fetch_array($results))
$tags[] = $row;
return $tags;
}
function article_ids_by_tag($tag_id)
{
$query = 'SELECT article_id FROM article_tags INNER JOIN tags ON article_tags.tag_id = tags.tag_id WHERE tag = "' . $tag_id . '";';
$results = query_db_one_or_more_results($query);
$results = query_one_or_more_results($query);
$ids = [];
@@ -33,12 +45,13 @@ function article_ids_by_tag($tag_id)
function article_page_from_markdown($article_id)
{
$query = 'SELECT * FROM article WHERE article_id = ' . $article_id . ';';
$article = query_db_one_result($query);
$article = query_one_result($query);
$markdown = read_file_one_string($_ENV['ARTICLES_PATH'] . $article_id . '/article.md');
$parsedown = new Parsedown();
$html = '<div class="article">';
$html .= '<h3>' . $article['title'] . '</h3>';
$html .= $parsedown->text($markdown);
$html .= '</div>';
@@ -51,10 +64,10 @@ function article_page_from_markdown($article_id)
function article_card($article_id)
{
$article_query = 'SELECT * FROM article WHERE article_id = ' . $article_id . ';';
$article = query_db_one_result($article_query);
$article = query_one_result($article_query);
$article_tags_query = 'SELECT tag FROM article_tags INNER JOIN tags ON article_tags.tag_id = tags.tag_id WHERE article_id = ' . $article_id . ';';
$tags_results = query_db_one_or_more_results($article_tags_query);
$tags_results = query_one_or_more_results($article_tags_query);
$tags_html = '';
if ($tags_results != null) {
$tags_html .= '<div class="tag_row">';
@@ -66,7 +79,7 @@ function article_card($article_id)
}
$author_query = 'SELECT username, profile_picture FROM user WHERE user_id = ' . $article['author_id'] . ';';
$author = query_db_one_result($author_query);
$author = query_one_result($author_query);
$card = '
<div class="article_card">
@@ -94,7 +107,44 @@ function article_card($article_id)
return $card;
}
/*
* Displays the article creation wizard and opens a new markdown file.
*/
function create_article() {}
function create_article($author_id, $title, $excerpt, $tags, $markdown_file_contents)
{
$stmt = 'INSERT INTO article (author_id, title, excerpt, published_at) VALUES (' . $author_id . ', "' . $title . '", "' . $excerpt . '", CURRENT_TIMESTAMP);';
$id = exec_statement($stmt, 0);
$path = $_ENV['ARTICLES_PATH'] . $id . '/';
mkdir($path);
$fs = fopen($path . 'article.md', 'a');
fwrite($fs, $markdown_file_contents);
fclose($fs);
$stmt = 'INSERT INTO article_tags (article_id, tag_id) VALUES ';
for ($i = 0; $i < count($tags); $i++) {
$stmt .= '(' . $id . ', ' . $tags[$i] . ')';
if ($i < count($tags) - 1)
$stmt .= ', ';
if ($i == count($tags) - 1)
$stmt .= ';';
}
echo $stmt;
pretty_dump($tags);
if (count($tags) > 0)
exec_statement($stmt, 0);
return $id;
}
function delete_article($article_id)
{
$stmt = 'DELETE FROM article WHERE article_id = ' . $article_id . ';';
return exec_statement($stmt, 1);
}
function delete_articles_by_author($author_id)
{
$stmt = 'DELETE FROM article WHERE author_id = "' . $author_id . '";';
return exec_statement($stmt, 1);
}