71 lines
2.5 KiB
PHP
71 lines
2.5 KiB
PHP
<?php
|
|
require_once 'functions/init.php';
|
|
require_once 'functions/functions.php';
|
|
|
|
include_once 'components/head.php';
|
|
|
|
include_once 'functions/article_functions.php';
|
|
|
|
// UI Components
|
|
foreach (glob('components/article/*.php') as $file)
|
|
require_once $file;
|
|
|
|
if (isset($_POST['form_id'])) {
|
|
switch ($_POST['form_id']) {
|
|
case 'compose':
|
|
if (isset($_POST['article_id'])) {
|
|
$tags = [];
|
|
for ($i = 0; $i < count($_POST['tags']); $i++)
|
|
$tags[] = $_POST['tags'][$i];
|
|
|
|
update_article($_POST['article_id'], $_POST['title'], $_POST['excerpt'], $tags, $_POST['markdown']);
|
|
header('Location: articles.php?article_id=' . $_POST['article_id']);
|
|
} else {
|
|
$id = create_article($_COOKIE['user_id'], $_POST['title'], $_POST['excerpt'], (isset($_POST['tags']) ? $_POST['tags'] : []), $_POST['markdown']);
|
|
header('Location: articles.php?article_id=' . $id);
|
|
}
|
|
|
|
break;
|
|
}
|
|
} else {
|
|
if (isset($_GET['view']))
|
|
$view = $_GET['view'];
|
|
else
|
|
$view = 'list';
|
|
|
|
switch ($view) {
|
|
case 'list':
|
|
echo article_list();
|
|
break;
|
|
case 'filter':
|
|
if (isset($_GET['tag']))
|
|
echo article_list(article_ids_by_tag($_GET['tag']));
|
|
else if (isset($_GET['author_id']))
|
|
echo article_list(articles_ids_by_author($_GET['author_id']));
|
|
break;
|
|
case 'sort':
|
|
if (isset($_GET['sort']) && $_GET['sort'] == 'oldest')
|
|
echo article_list(article_ids_by_oldest());
|
|
else if (isset($_GET['sort']) && $_GET['sort'] == 'newest')
|
|
echo article_list(article_ids_by_newest());
|
|
break;
|
|
case 'read':
|
|
if (isset($_COOKIE['user_id']) && isset($_GET['article_id'])) {
|
|
increment_read_counter($_GET['article_id']);
|
|
echo article_page_from_markdown($_GET['article_id']);
|
|
} else {
|
|
$redirect = (isset($_GET['article_id']) ? 'articles.php?view=read&article_id=' . $_GET['article_id'] : '');
|
|
if ($redirect)
|
|
header('Location: user.php?action=login&redirect=' . urlencode($redirect));
|
|
else
|
|
header('Location: articles.php');
|
|
}
|
|
break;
|
|
case 'compose':
|
|
echo compose_view((isset($_GET['article_id']) ? $_GET['article_id'] : ''));
|
|
break;
|
|
}
|
|
}
|
|
|
|
include_once 'components/foot.php';
|