sync, implemented sort, viewing user pages & articles written, updating db
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
require_once 'db_functions.php';
|
||||
|
||||
function article_ids_by_recency()
|
||||
function article_ids_by_newest()
|
||||
{
|
||||
$conn = get_connection();
|
||||
$results = $conn->query('SELECT article_id FROM article ORDER BY published_at DESC');
|
||||
@@ -14,6 +14,19 @@ function article_ids_by_recency()
|
||||
return $ids;
|
||||
}
|
||||
|
||||
function article_ids_by_oldest()
|
||||
{
|
||||
$conn = get_connection();
|
||||
$results = $conn->query('SELECT article_id FROM article ORDER BY published_at ASC');
|
||||
|
||||
$ids = [];
|
||||
|
||||
while ($row = $results->fetch_assoc())
|
||||
$ids[] = $row['article_id'];
|
||||
|
||||
return $ids;
|
||||
}
|
||||
|
||||
function articles_ids_by_author($author_id)
|
||||
{
|
||||
$conn = get_connection();
|
||||
@@ -77,6 +90,13 @@ function article_page_from_markdown($article_id)
|
||||
$markdown = read_file_one_string($_ENV['ARTICLES_FQ_PATH'] . $article_id . '/article.md');
|
||||
|
||||
$parsedown = new Parsedown();
|
||||
$article_content = $parsedown->text($markdown);
|
||||
$article_toc = '';
|
||||
|
||||
$lines = preg_split("/\r\n|\n|\r/", $article_content);
|
||||
foreach ($lines as $line)
|
||||
if (str_contains($line, '<h4>'))
|
||||
$article_toc .= '<p>' . extract_content_from_tag($line, '<h4>', '</h4>') . '</p>';
|
||||
|
||||
$html = '
|
||||
<div class="article">
|
||||
@@ -91,14 +111,37 @@ function article_page_from_markdown($article_id)
|
||||
</div>
|
||||
</div>
|
||||
<div class="line" style="margin-bottom: 15px;"></div>
|
||||
<div class="article_grid">
|
||||
<div class="article_toc">
|
||||
' . $article_toc . '
|
||||
</div>
|
||||
<div class="article_content">
|
||||
' . $article_content . '
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
|
||||
$html .= $parsedown->text($markdown);
|
||||
$html .= '</div>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
function article_filters()
|
||||
{
|
||||
$filters = '
|
||||
<form method="get">
|
||||
<label for="recency_desc"><i class="nf nf-md-sort_clock_ascending_outline"></i>
|
||||
<input id="recency_desc" type="radio" name="sort" value="oldest" onclick="this.form.submit()">
|
||||
</label>
|
||||
|
||||
<label for="recency_asc"><i class="nf nf-md-sort_clock_descending_outline"></i>
|
||||
<input id="recency_asc" type="radio" name="sort" value="newest" onclick="this.form.submit()">
|
||||
</label>
|
||||
</form>
|
||||
';
|
||||
|
||||
return $filters;
|
||||
}
|
||||
|
||||
/*
|
||||
* Generates cards for a given article.
|
||||
*/
|
||||
@@ -188,6 +231,7 @@ function create_article($author_id, $title, $excerpt, $tags, $markdown_file_cont
|
||||
return $id;
|
||||
}
|
||||
|
||||
|
||||
function delete_article($article_id)
|
||||
{
|
||||
$conn = get_connection();
|
||||
|
||||
Reference in New Issue
Block a user