50 lines
1.9 KiB
PHP
50 lines
1.9 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Generates cards for a given article.
|
|
*/
|
|
function article_card($article_id)
|
|
{
|
|
$article = exec_stmt('SELECT * FROM article WHERE article_id = ?', 'i', $article_id)->fetch_assoc();
|
|
|
|
$tags_results = exec_stmt('SELECT tag FROM article_tags INNER JOIN tags ON article_tags.tag_id = tags.tag_id WHERE article_id = ?', 'i', $article_id);
|
|
|
|
$tags_html = '';
|
|
if ($tags_results != null) {
|
|
$tags_html .= '<div class="tag_row">';
|
|
|
|
while ($row = $tags_results->fetch_assoc())
|
|
$tags_html .= '<a href="/articles.php?view=filter&tag=' . $row['tag'] . '" class="tag">#' . $row['tag'] . '</a>';
|
|
|
|
$tags_html .= '</div>';
|
|
}
|
|
|
|
$author = exec_stmt('SELECT user_id, username, profile_picture FROM user WHERE user_id = ?', 'i', $article['author_id'])->fetch_assoc();
|
|
|
|
$card = '
|
|
<div class="article_card">
|
|
<div class="row_space_between">
|
|
<h4>' . $article['title'] . '</h4>
|
|
<div class="card_info_box">
|
|
<div class="col-right">
|
|
<a href="user.php?view=display&user_id=' . $author['user_id'] . '">Written by: ' . $author['username'] . '</a>
|
|
<small>Published: ' . $article['published_at'] . '</small>
|
|
<small>Updated: ' . $article['updated_at'] . '</small>
|
|
</div>
|
|
<div class="card_pic_box">
|
|
<img src="' . $_ENV['PROFILE_IMAGES_PQ_PATH'] . $author['profile_picture'] . '" class="card_profile_picture">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="line"></div>
|
|
<p>' . $article['excerpt'] . '</p>
|
|
<div class="row_space_between">
|
|
<a href="/articles.php?view=read&article_id=' . $article['article_id'] . '" class="button">Read More</a>
|
|
<div class="tag_box">' . $tags_html . '</div>
|
|
</div>
|
|
</div>
|
|
';
|
|
|
|
return $card;
|
|
}
|