implemented database, article cards, and parsing from markdown.
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
require 'db_functions.php';
|
||||
|
||||
/*
|
||||
* Reads the markdown file for a given article and generates the HTML for it.
|
||||
*/
|
||||
function article_page_from_markdown($article_id)
|
||||
{
|
||||
$query = 'SELECT * FROM articles WHERE article_id = ' . $article_id . ';';
|
||||
$article = query_db_one_result($query);
|
||||
$markdown = read_file_one_string($_ENV['ARTICLES_PATH'] . $article_id . '/' . $article['markdown_file_path']);
|
||||
|
||||
// Instantiate Parsedown
|
||||
$parsedown = new Parsedown();
|
||||
|
||||
// Example usage
|
||||
$html = $parsedown->text($markdown);
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/*
|
||||
* Generates cards for a given article.
|
||||
*/
|
||||
function article_card($article_id)
|
||||
{
|
||||
$article_query = 'SELECT * FROM articles 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 = '<div class="tag_row">';
|
||||
|
||||
while ($row = mysqli_fetch_array($tags_results))
|
||||
$tags_html .= '<a href="/article.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="/article.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() {}
|
||||
Reference in New Issue
Block a user