' . $article['title'] . '
' . $article['excerpt'] . '
';
return $card;
}
function create_article($author_id, $title, $excerpt, $tags, $markdown_file_contents)
{
$stmt = 'INSERT INTO article (author_id, title, excerpt, published_at) VALUES (' . $author_id . ', "' . $title . '", "' . $excerpt . '", CURRENT_TIMESTAMP);';
$id = exec_statement($stmt, 0);
$path = $_ENV['ARTICLES_PATH'] . $id . '/';
mkdir($path);
$fs = fopen($path . 'article.md', 'a');
fwrite($fs, $markdown_file_contents);
fclose($fs);
$stmt = 'INSERT INTO article_tags (article_id, tag_id) VALUES ';
for ($i = 0; $i < count($tags); $i++) {
$stmt .= '(' . $id . ', ' . $tags[$i] . ')';
if ($i < count($tags) - 1)
$stmt .= ', ';
if ($i == count($tags) - 1)
$stmt .= ';';
}
echo $stmt;
pretty_dump($tags);
if (count($tags) > 0)
exec_statement($stmt, 0);
return $id;
}
function delete_article($article_id)
{
$stmt = 'DELETE FROM article WHERE article_id = ' . $article_id . ';';
return exec_statement($stmt, 1);
}
function delete_articles_by_author($author_id)
{
$stmt = 'DELETE FROM article WHERE author_id = "' . $author_id . '";';
return exec_statement($stmt, 1);
}