101 lines
3.1 KiB
PHP
101 lines
3.1 KiB
PHP
<?php
|
|
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);
|
|
|
|
$ids = [];
|
|
|
|
while ($row = mysqli_fetch_array($results))
|
|
$ids[] = $row['article_id'];
|
|
|
|
return $ids;
|
|
}
|
|
|
|
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);
|
|
|
|
$ids = [];
|
|
|
|
while ($row = mysqli_fetch_array($results))
|
|
$ids[] = $row['article_id'];
|
|
|
|
return $ids;
|
|
}
|
|
|
|
/*
|
|
* Reads the markdown file for a given article and generates the HTML for it.
|
|
*/
|
|
function article_page_from_markdown($article_id)
|
|
{
|
|
$query = 'SELECT * FROM article WHERE article_id = ' . $article_id . ';';
|
|
$article = query_db_one_result($query);
|
|
$markdown = read_file_one_string($_ENV['ARTICLES_PATH'] . $article_id . '/article.md');
|
|
|
|
$parsedown = new Parsedown();
|
|
|
|
$html = '<div class="article">';
|
|
$html .= $parsedown->text($markdown);
|
|
$html .= '</div>';
|
|
|
|
return $html;
|
|
}
|
|
|
|
/*
|
|
* Generates cards for a given article.
|
|
*/
|
|
function article_card($article_id)
|
|
{
|
|
$article_query = 'SELECT * FROM article WHERE article_id = ' . $article_id . ';';
|
|
$article = query_db_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_html = '';
|
|
if ($tags_results != null) {
|
|
$tags_html .= '<div class="tag_row">';
|
|
|
|
while ($row = mysqli_fetch_array($tags_results))
|
|
$tags_html .= '<a href="/articles.php?tag=' . $row['tag'] . '" class="tag">#' . $row['tag'] . '</a>';
|
|
|
|
$tags_html .= '</div>';
|
|
}
|
|
|
|
$author_query = 'SELECT username, profile_picture FROM user WHERE user_id = ' . $article['author_id'] . ';';
|
|
$author = query_db_one_result($author_query);
|
|
|
|
$card = '
|
|
<div class="article_card">
|
|
<div class="row">
|
|
<h4>' . $article['title'] . '</h4>
|
|
<div class="card_info_box">
|
|
<div class="col-right">
|
|
<small>Written by: ' . $author['username'] . '</small>
|
|
<small>Published: ' . $article['published_at'] . '</small>
|
|
</div>
|
|
<div class="card_pic_box">
|
|
<img src="/profile_pictures/' . $author['profile_picture'] . '" class="card_profile_picture">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="line"></div>
|
|
<p>' . $article['excerpt'] . '</p>
|
|
<div class="row">
|
|
<a href="/articles.php?article_id=' . $article['article_id'] . '" class="button">Read More</a>
|
|
<div class="tag_box">' . $tags_html . '</div>
|
|
</div>
|
|
</div>
|
|
';
|
|
|
|
return $card;
|
|
}
|
|
|
|
/*
|
|
* Displays the article creation wizard and opens a new markdown file.
|
|
*/
|
|
function create_article() {}
|