implemented editing articles

This commit is contained in:
2025-04-08 16:40:40 -06:00
parent e5b3e048b8
commit e829e2e566
5 changed files with 99 additions and 57 deletions
+38 -1
View File
@@ -101,7 +101,11 @@ function article_page_from_markdown($article_id)
$html = '
<div class="article">
<h3>' . $article['title'] . '</h3>
<div class="row">
<h3>' . $article['title'] . '</h3>
' . (isset($article_id) ? '<a href="compose.php?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>
@@ -232,6 +236,39 @@ function create_article($author_id, $title, $excerpt, $tags, $markdown_file_cont
return $id;
}
function update_article($article_id, $title, $excerpt, $tags, $markdown_file_contents)
{
$conn = get_connection();
$stmt = $conn->prepare('UPDATE article SET title = ?, excerpt = ?, updated_at = CURRENT_TIMESTAMP WHERE article_id = ?');
$stmt->bind_param('ssi', $title, $excerpt, $article_id);
$stmt->execute();
$path = $_ENV['ARTICLES_FQ_PATH'] . $article_id . '/';
$fs = fopen($path . 'article.md', 'w');
fwrite($fs, $markdown_file_contents);
fclose($fs);
$stmt = $conn->prepare('DELETE from article_tags WHERE article_id = ?');
$stmt->bind_param('i', $article_id);
$stmt->execute();
if (count($tags) > 0) {
$tag_insert_stmt = 'INSERT INTO article_tags (article_id, tag_id) VALUES ';
$input = '';
for ($i = 0; $i < count($tags); $i++) {
$tag_insert_stmt .= '(' . $article_id . ', ?)';
if ($i < count($tags) - 1)
$tag_insert_stmt .= ', ';
$input .= 'i';
}
$stmt = $conn->prepare($tag_insert_stmt);
$stmt->bind_param($input, ...$tags);
$stmt->execute();
}
}
function delete_article($article_id)
{