refactoring

This commit is contained in:
2025-04-13 15:57:16 -06:00
parent 27bfe8e7b3
commit 8f2c241c3d
29 changed files with 867 additions and 841 deletions
+41
View File
@@ -0,0 +1,41 @@
<?php
/*
* Reads the markdown file for a given article and generates the HTML for it.
*/
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');
$parsedown = new Parsedown();
$parsedown->setSafeMode(true);
$article_content = $parsedown->text($markdown);
$html = '
<div class="article">
<div class="row">
<h1>' . $article['title'] . '</h1>
' . (isset($_COOKIE['user_id']) && $_COOKIE['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>
<div class="card_pic_box">
<img src="' . $_ENV['PROFILE_IMAGES_PQ_PATH'] . $author['profile_picture'] . '" class="card_profile_picture" />
</div>
</div>
<div class="line" style="margin-bottom: 15px;"></div>
<div class="article_content">
' . $article_content . '
</div>
</div>
';
return $html;
}