styling, navigation bar, theming, article lists, page routing.
This commit is contained in:
@@ -1,20 +1,46 @@
|
||||
<?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 articles WHERE article_id = ' . $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['markdown_file_path']);
|
||||
$markdown = read_file_one_string($_ENV['ARTICLES_PATH'] . $article_id . '/article.md');
|
||||
|
||||
// Instantiate Parsedown
|
||||
$parsedown = new Parsedown();
|
||||
|
||||
// Example usage
|
||||
$html = $parsedown->text($markdown);
|
||||
$html = '<div class="article">';
|
||||
$html .= $parsedown->text($markdown);
|
||||
$html .= '</div>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
@@ -24,17 +50,20 @@ function article_page_from_markdown($article_id)
|
||||
*/
|
||||
function article_card($article_id)
|
||||
{
|
||||
$article_query = 'SELECT * FROM articles WHERE article_id = ' . $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 = '<div class="tag_row">';
|
||||
$tags_html = '';
|
||||
if ($tags_results != null) {
|
||||
$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>';
|
||||
while ($row = mysqli_fetch_array($tags_results))
|
||||
$tags_html .= '<a href="/articles.php?tag=' . $row['tag'] . '" class="tag">#' . $row['tag'] . '</a>';
|
||||
|
||||
$tags_html .= '</div>';
|
||||
$tags_html .= '</div>';
|
||||
}
|
||||
|
||||
$author_query = 'SELECT username, profile_picture FROM user WHERE user_id = ' . $article['author_id'] . ';';
|
||||
$author = query_db_one_result($author_query);
|
||||
@@ -56,7 +85,7 @@ function article_card($article_id)
|
||||
<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>
|
||||
<a href="/articles.php?article_id=' . $article['article_id'] . '" class="button">Read More</a>
|
||||
<div class="tag_box">' . $tags_html . '</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user