diff --git a/admin.php b/admin.php
index 9db80fa..b6c32eb 100644
--- a/admin.php
+++ b/admin.php
@@ -2,49 +2,53 @@
require_once 'functions/init.php';
require_once 'functions/functions.php';
+// UI Components
+foreach (glob('components/admin/*.php') as $file)
+ require_once $file;
+
include_once 'components/head.php';
if (!isset($_COOKIE['role_id']))
- header('Location: user.php');
+ header('Location: user.php');
else if ($_COOKIE['role_id'] >= 3)
- header('Location: user.php?action=view&user_id=' . $_COOKIE['user_id']);
+ header('Location: user.php?action=view&user_id=' . $_COOKIE['user_id']);
include_once 'functions/admin_functions.php';
if (isset($_POST['action']) && isset($_POST['form_id']) || isset($_FILES['csv'])) {
- if (!empty($_FILES['csv']['name'])) {
- upload($_FILES['csv'], $_ENV['UPLOAD_TMP_FQ_PATH'], 'new_users');
- create_users_from_csv($_ENV['UPLOAD_TMP_FQ_PATH'] . 'new_users.csv');
- delete_file($_ENV['UPLOAD_TMP_FQ_PATH'] . 'new_users.csv');
- } else {
- switch ($_POST['action']) {
- case 'delete':
- if ($_POST['form_id'] == 'users')
- foreach ($_POST['selected_users'] as $id)
- delete_account($id);
- else if ($_POST['form_id'] == 'articles')
- foreach ($_POST['selected_articles'] as $id)
- delete_article($id);
- break;
+ if (!empty($_FILES['csv']['name'])) {
+ upload($_FILES['csv'], $_ENV['UPLOAD_TMP_FQ_PATH'], 'new_users');
+ create_users_from_csv($_ENV['UPLOAD_TMP_FQ_PATH'] . 'new_users.csv');
+ delete_file($_ENV['UPLOAD_TMP_FQ_PATH'] . 'new_users.csv');
+ } else {
+ switch ($_POST['action']) {
+ case 'delete':
+ if ($_POST['form_id'] == 'users')
+ foreach ($_POST['selected_users'] as $id)
+ delete_account($id);
+ else if ($_POST['form_id'] == 'articles')
+ foreach ($_POST['selected_articles'] as $id)
+ delete_article($id);
+ break;
- case 'view':
- header('Location: user.php?action=view&user_id=' . $_POST['selected_users'][0]);
+ case 'view':
+ header('Location: user.php?action=view&user_id=' . $_POST['selected_users'][0]);
+ }
}
- }
}
if (isset($_GET['view'])) {
- switch ($_GET['view']) {
- case 'users':
- echo admin_user_view();
- break;
+ switch ($_GET['view']) {
+ case 'users':
+ echo admin_user_view();
+ break;
- case 'articles':
- echo admin_article_view();
- break;
- }
+ case 'articles':
+ echo admin_article_view();
+ break;
+ }
} else {
- echo admin_article_view();
+ echo admin_article_view();
}
include_once 'components/foot.php';
diff --git a/articles.php b/articles.php
index 6277c82..063b92c 100644
--- a/articles.php
+++ b/articles.php
@@ -6,68 +6,65 @@ include_once 'components/head.php';
include_once 'functions/article_functions.php';
-// Default view, it'll show articles by recency
-if (!isset($_GET['article_id']) && !isset($_GET['tag']) && !isset($_GET['author_id'])) {
- $filters = '
-
- ';
-
- echo '
-
-
- ' . $filters . '
-
-
- ';
- foreach ($ids as $id)
- echo article_card($id);
- echo '
-
-
- ';
-} else if (isset($_COOKIE['user_id']) && isset($_GET['article_id'])) {
- increment_read_counter($_GET['article_id']);
- echo article_page_from_markdown($_GET['article_id']);
-} else if (isset($_GET['author_id'])) {
- $ids = articles_ids_by_author($_GET['author_id']);
-
- foreach ($ids as $id)
- echo article_card($id);
-} else if (isset($_GET['tag'])) {
- $ids = article_ids_by_tag($_GET['tag']);
-
- foreach ($ids as $id)
- echo article_card($id);
} else {
- $redirect = (isset($_GET['article_id']) ? 'articles.php?article_id=' . $_GET['article_id'] : '');
- if ($redirect)
- header('Location: user.php?action=login&redirect=' . urlencode($redirect));
+ if (isset($_GET['view']))
+ $view = $_GET['view'];
else
- header('Location: articles.php');
+ $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';
diff --git a/components/admin/article_view.php b/components/admin/article_view.php
new file mode 100644
index 0000000..88c1c9a
--- /dev/null
+++ b/components/admin/article_view.php
@@ -0,0 +1,68 @@
+
+
+
+
+
+ ';
+
+ return $display;
+}
diff --git a/components/admin/user_view.php b/components/admin/user_view.php
new file mode 100644
index 0000000..665294a
--- /dev/null
+++ b/components/admin/user_view.php
@@ -0,0 +1,71 @@
+
+
+
+
+
+ ';
+
+ return $display;
+}
diff --git a/components/article/article.php b/components/article/article.php
new file mode 100644
index 0000000..6eaa64f
--- /dev/null
+++ b/components/article/article.php
@@ -0,0 +1,41 @@
+fetch_assoc();
+ $author = exec_stmt('SELECT user_id, username, profile_picture FROM user WHERE user_id = ?', 'i', $article['author_id'])->fetch_assoc();
+ $markdown = read_file_one_string($_ENV['ARTICLES_FQ_PATH'] . $article_id . '/article.md');
+
+ $parsedown = new Parsedown();
+ $parsedown->setSafeMode(true);
+ $article_content = $parsedown->text($markdown);
+
+ $html = '
+
+
+
+
' . $article['title'] . '
+ ' . (isset($_COOKIE['user_id']) && $_COOKIE['user_id'] == $article['author_id'] ? '
' : '') . '
+
+
+
+
+
Published on ' . $article['published_at'] . '
+ Lasted edited on ' . $article['updated_at'] . '
+
+
+

+
+
+
+
+ ' . $article_content . '
+
+
+ ';
+
+ return $html;
+}
diff --git a/components/article/card.php b/components/article/card.php
new file mode 100644
index 0000000..d58f1c5
--- /dev/null
+++ b/components/article/card.php
@@ -0,0 +1,49 @@
+fetch_assoc();
+
+ $tags_results = exec_stmt('SELECT tag FROM article_tags INNER JOIN tags ON article_tags.tag_id = tags.tag_id WHERE article_id = ?', 'i', $article_id);
+
+ $tags_html = '';
+ if ($tags_results != null) {
+ $tags_html .= '';
+
+ while ($row = $tags_results->fetch_assoc())
+ $tags_html .= '
#' . $row['tag'] . '';
+
+ $tags_html .= '
';
+ }
+
+ $author = exec_stmt('SELECT user_id, username, profile_picture FROM user WHERE user_id = ?', 'i', $article['author_id'])->fetch_assoc();
+
+ $card = '
+
+
+
' . $article['title'] . '
+
+
+
+

+
+
+
+
+
' . $article['excerpt'] . '
+
+
+ ';
+
+ return $card;
+}
diff --git a/components/article/compose_preview.php b/components/article/compose_preview.php
new file mode 100644
index 0000000..66f2962
--- /dev/null
+++ b/components/article/compose_preview.php
@@ -0,0 +1,12 @@
+
+
+
+
+ ';
+
+ return $preview;
+}
diff --git a/components/article/compose_view.php b/components/article/compose_view.php
new file mode 100644
index 0000000..7221e62
--- /dev/null
+++ b/components/article/compose_view.php
@@ -0,0 +1,36 @@
+prepare('SELECT * FROM article WHERE article_id = ?');
+ $stmt->bind_param('i', $article_id);
+ $stmt->execute();
+ $article = $stmt->get_result()->fetch_assoc();
+
+ $stmt = $conn->prepare('SELECT tag_id FROM article_tags WHERE article_id = ?');
+ $stmt->bind_param('i', $article_id);
+ $stmt->execute();
+ $result = $stmt->get_result();
+ $tags = [];
+ while ($row = $result->fetch_assoc())
+ $tags[] = $row['tag_id'];
+
+ $title = $article['title'];
+ $excerpt = $article['excerpt'];
+ $existing_markdown = read_file_one_string($_ENV['ARTICLES_FQ_PATH'] . $article_id . '/article.md');
+ }
+
+ $view = '
+
+ ' . (!empty($existing_markdown) ? form($article_id, $title, $excerpt, $existing_markdown, $tags) : form()) . '
+ ' . preview() . '
+ ';
+
+ $view .= preview() . '
+
+ ';
+
+ return $view;
+}
diff --git a/components/article/composer.php b/components/article/composer.php
new file mode 100644
index 0000000..2c89871
--- /dev/null
+++ b/components/article/composer.php
@@ -0,0 +1,46 @@
+
+
+ ';
+
+ foreach ($raw_tags as $row) {
+ $tags_boxes .= '
+
+ ';
+ }
+
+ $tags_boxes .= '
+
+ ';
+
+ $form = '
+
+';
+
+ return $form;
+}
diff --git a/components/article/list.php b/components/article/list.php
new file mode 100644
index 0000000..962fd8a
--- /dev/null
+++ b/components/article/list.php
@@ -0,0 +1,55 @@
+
+
+
+ ';
+
+ if (!isset($_GET['sort']) || $_GET['sort'] == 'newest') {
+ $ids = article_ids_by_newest();
+ $filters .= '
+
Newest - Oldest
+
+ ';
+ } else if ($_GET['sort'] == 'oldest') {
+ $ids = article_ids_by_oldest();
+ $filters .= '
+
Oldest - Newest
+
+ ';
+ }
+
+ $filters .= '
+
+
+ ';
+
+ $content .= '
+
+
+ ' . $filters . '
+
+
+ ';
+
+ if (!isset($list))
+ foreach ($ids as $id)
+ $content .= article_card($id);
+ else
+ foreach ($list as $id)
+ $content .= article_card($id);
+
+ $content .= '
+
+
+ ';
+
+ return $content;
+}
diff --git a/components/foot.php b/components/foot.php
index c7dc6ca..bdddf1d 100644
--- a/components/foot.php
+++ b/components/foot.php
@@ -21,37 +21,42 @@ function get_args_from_url()
if ($_SERVER['SCRIPT_NAME'] == '/user.php') {
$args = get_args_from_url();
- if (isset($args['action'])) {
- if ($args['action'] == 'signup') {
+ if (isset($args['view'])) {
+ if ($args['view'] == 'signup') {
echo '
-
-
- ';
- } else if ($args['action'] == 'view') {
+
+
+ ';
+ } else if ($args['view'] == 'display') {
echo '
-
-
-
+
+
';
}
}
} else if ($_SERVER['SCRIPT_NAME'] == '/admin.php') {
echo '
-
+
';
$args = get_args_from_url();
if (isset($args['view'])) {
if ($args['view'] == 'users') {
echo '
-
- ';
+
+ ';
+ }
+ }
+} else if ($_SERVER['SCRIPT_NAME'] == '/articles.php') {
+ $args = get_args_from_url();
+
+ if (isset($args['view'])) {
+ if ($args['view'] == 'compose') {
+ echo '
+
+ ';
}
}
-} else if ($_SERVER['SCRIPT_NAME'] == '/compose.php') {
- echo '
-
- ';
}
?>
diff --git a/components/nav.php b/components/nav.php
index f61067f..05c82b1 100644
--- a/components/nav.php
+++ b/components/nav.php
@@ -6,7 +6,7 @@ $nav = '
+ ';
+
+ return $form;
+}
diff --git a/components/user/login.php b/components/user/login.php
new file mode 100644
index 0000000..20af59c
--- /dev/null
+++ b/components/user/login.php
@@ -0,0 +1,28 @@
+
+ Log In
+
+
+ ';
+
+ return $form;
+}
diff --git a/components/user/profile_cropper.php b/components/user/profile_cropper.php
new file mode 100644
index 0000000..f648bff
--- /dev/null
+++ b/components/user/profile_cropper.php
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+ ';
+
+ return $display;
+}
diff --git a/components/user/request_role_change.php b/components/user/request_role_change.php
new file mode 100644
index 0000000..769c694
--- /dev/null
+++ b/components/user/request_role_change.php
@@ -0,0 +1,33 @@
+query('SELECT * FROM roles WHERE role_id <> 1');
+
+ $roles = '';
+ while ($row = $result->fetch_assoc()) {
+ $roles .= '
+
+ ';
+ }
+
+ $roles .= '
';
+
+ $form = '
+
+
Request Role
+ ×
+
+
+ ';
+
+ return $form;
+}
diff --git a/components/user/reset_password.php b/components/user/reset_password.php
new file mode 100644
index 0000000..87eb895
--- /dev/null
+++ b/components/user/reset_password.php
@@ -0,0 +1,24 @@
+
+ Reset Password
+ ×
+
+
+ ';
+
+ return $form;
+}
diff --git a/components/user/signup.php b/components/user/signup.php
new file mode 100644
index 0000000..420466b
--- /dev/null
+++ b/components/user/signup.php
@@ -0,0 +1,50 @@
+
+ Sign Up
+
+
+
+
+
+
' . profile_cropper() . '
+
+
+ ';
+
+ return $form;
+}
diff --git a/components/user/update_email.php b/components/user/update_email.php
new file mode 100644
index 0000000..ca04d6d
--- /dev/null
+++ b/components/user/update_email.php
@@ -0,0 +1,24 @@
+
+ Update Email
+ ×
+
+
+ ';
+
+ return $form;
+}
diff --git a/components/user/update_profile_picture.php b/components/user/update_profile_picture.php
new file mode 100644
index 0000000..2b3782d
--- /dev/null
+++ b/components/user/update_profile_picture.php
@@ -0,0 +1,33 @@
+
+ Update Profile Picture
+ ×
+
+
+
+
+
+
' . profile_cropper() . '
+
+
+ ';
+
+ return $form;
+}
diff --git a/components/user/update_username.php b/components/user/update_username.php
new file mode 100644
index 0000000..1b3d2ce
--- /dev/null
+++ b/components/user/update_username.php
@@ -0,0 +1,24 @@
+
+ Update Username
+ ×
+
+
+ ';
+
+ return $form;
+}
diff --git a/components/user/user_view.php b/components/user/user_view.php
new file mode 100644
index 0000000..89c4efb
--- /dev/null
+++ b/components/user/user_view.php
@@ -0,0 +1,59 @@
+fetch_assoc();
+ if ($user == null)
+ header('Location: articles.php');
+
+ $view = '
+
+
+
' . $user['username'] . '
+
+

+
+
+
+ ';
+
+ // TODO: Allow user to update profile picture.
+ //
+ //
' . update_profile_picture_form() . '
+ if ((isset($_COOKIE['user_id']) && $_COOKIE['user_id'] == $user_id) || (isset($_COOKIE['role_id']) && $_COOKIE['role_id'] <= 2)) {
+ $view .= '
+
User Actions
+
+
+
+
+
+
+
+
+
+
+
+
' . reset_pw_form() . '
+
' . update_email_form() . '
+
' . update_username_form() . '
+
' . request_role_change_form() . '
+
' . delete_account_form() . '
+
+
+ ';
+ } else {
+ $ids = articles_ids_by_author($_GET['user_id']);
+ $view .= '
+
+ ';
+
+ foreach ($ids as $id)
+ $view .= article_card($id);
+
+ $view .= '
';
+ }
+
+ return $view;
+}
diff --git a/compose.php b/compose.php
deleted file mode 100644
index 780bf0b..0000000
--- a/compose.php
+++ /dev/null
@@ -1,119 +0,0 @@
-prepare('SELECT * FROM article WHERE article_id = ?');
- $stmt->bind_param('i', $article_id);
- $stmt->execute();
- $article = $stmt->get_result()->fetch_assoc();
-
- $stmt = $conn->prepare('SELECT tag_id FROM article_tags WHERE article_id = ?');
- $stmt->bind_param('i', $article_id);
- $stmt->execute();
- $result = $stmt->get_result();
- $tags = [];
- while ($row = $result->fetch_assoc())
- $tags[] = $row['tag_id'];
-
- $title = $article['title'];
- $excerpt = $article['excerpt'];
- $existing_markdown = read_file_one_string($_ENV['ARTICLES_FQ_PATH'] . $article_id . '/article.md');
-}
-
-echo '
-
-';
-if (!empty($existing_markdown)) {
- echo form($article_id, $title, $excerpt, $existing_markdown, $tags);
-} else {
- echo form();
-}
-
-echo preview();
-
-echo '
-
-';
-
-include_once 'components/foot.php';
-
-function form($article_id = null, $title = null, $excerpt = null, $existing_markdown = null, $tags = null)
-{
- $raw_tags = article_tags();
- $tags_boxes = '
-
-
- ';
-
- foreach ($raw_tags as $row) {
- $tags_boxes .= '
-
- ';
- }
-
- $tags_boxes .= '
-
- ';
-
- $form = '
-
-';
-
- return $form;
-}
-
-function preview()
-{
- $preview = '
-
- ';
-
- return $preview;
-}
diff --git a/functions/account_functions.php b/functions/account_functions.php
index f6c20f6..5c1be10 100644
--- a/functions/account_functions.php
+++ b/functions/account_functions.php
@@ -13,7 +13,14 @@ function user_id_exists($user_id)
return true;
}
-function username_exists($username) {}
+function username_exists($username)
+{
+ $result = exec_stmt('SELECT username FROM user WHERE username = "?"', 'i', $username)->fetch_assoc();
+
+ if ($result == null)
+ return false;
+ return true;
+}
function cookies($user, $time)
{
@@ -38,34 +45,6 @@ function logout()
header('Location: articles.php');
}
-function login_form($error_msg = '')
-{
- $form = '
-
-
Log In
-
-
- ';
-
- return $form;
-}
-
function login($username, $password, $stay_logged_in)
{
$password_hash = hash('sha256', $password);
@@ -97,56 +76,6 @@ function login($username, $password, $stay_logged_in)
return true;
}
-function signup_form($error_msg = '')
-{
- $form = '
-
- ';
-
- return $form;
-}
-
function create_user($username, $email, $password, $verify_password, $role_id, $upload = null, $x = null, $y = null, $crop_width = null, $honeypot = null)
{
if (!empty($honeypot)) {
@@ -200,52 +129,6 @@ function create_user($username, $email, $password, $verify_password, $role_id, $
return true;
}
-function profile_cropper()
-{
- $display = '
-
- ';
-
- return $display;
-}
-
-function reset_pw_form()
-{
- $form = '
-
-
Reset Password
- ×
-
-
- ';
-
- return $form;
-}
-
function reset_password($user_id, $new_password, $verify_new_password)
{
if ($new_password != $verify_new_password) {
@@ -262,30 +145,6 @@ function reset_password($user_id, $new_password, $verify_new_password)
exec_stmt('UPDATE user SET password_hash = ? WHERE user_id = ?', 'si', $password_hash, $user_id);
}
-function update_email_form()
-{
- $form = '
-
-
Update Email
- ×
-
-
- ';
-
- return $form;
-}
-
function update_email($user_id, $new_email, $verify_new_email)
{
if ($new_email != $verify_new_email) {
@@ -301,30 +160,6 @@ function update_email($user_id, $new_email, $verify_new_email)
exec_stmt('UPDATE user SET email = ? WHERE user_id = ?', 'si', $new_email, $user_id);
}
-function update_username_form()
-{
- $form = '
-
-
Update Username
- ×
-
-
- ';
-
- return $form;
-}
-
function update_username($user_id, $new_username, $verify_new_username)
{
if ($new_username != $verify_new_username) {
@@ -343,74 +178,8 @@ function update_username($user_id, $new_username, $verify_new_username)
exec_stmt('UPDATE user SET username = ? WHERE user_id = ?', 'si', $new_username, $user_id);
}
-function update_profile_picture_form()
-{
- $form = '
-
- ';
-
- return $form;
-}
-
function update_profile_picture($user_id) {}
-function request_role_change_form()
-{
- $conn = get_connection();
- $result = $conn->query('SELECT * FROM roles WHERE role_id <> 1');
-
- $roles = '';
- while ($row = $result->fetch_assoc()) {
- $roles .= '
-
- ';
- }
-
- $roles .= '
';
-
- $form = '
-
-
Request Role
- ×
-
-
- ';
-
- return $form;
-}
-
function request_role_change($user_id, $new_role_id)
{
$user = exec_stmt('SELECT user_id, username, email, roles.role, created_at FROM user INNER JOIN roles WHERE user.role_id = roles.role_id AND user_id = ?', 'i', $user_id)->fetch_assoc();
@@ -436,30 +205,6 @@ function request_role_change($user_id, $new_role_id)
);
}
-function delete_account_form()
-{
- $form = '
-
-
Delete Account
- ×
-
-
- ';
-
- return $form;
-}
-
function delete_account($user_id, $password = null, $verify_password = null)
{
if ($user_id == 2025) {
@@ -522,62 +267,3 @@ function delete_account($user_id, $password = null, $verify_password = null)
exec_stmt('DELETE FROM user WHERE user_id = ?', 'i', $user_id);
}
}
-
-function user_view($user_id)
-{
- $user = exec_stmt('SELECT user_id, username, email, role_id, created_at, last_active, is_active, profile_picture FROM user WHERE user_id = ?', 'i', $user_id)->fetch_assoc();
- if ($user == null)
- header('Location: articles.php');
-
- $view = '
-
-
-
' . $user['username'] . '
-
-

-
-
-
- ';
-
- // TODO: Allow user to update profile picture.
- //
- //
' . update_profile_picture_form() . '
- if ((isset($_COOKIE['user_id']) && $_COOKIE['user_id'] == $user_id) || (isset($_COOKIE['role_id']) && $_COOKIE['role_id'] <= 2)) {
- $view .= '
-
User Actions
-
-
-
-
-
-
-
-
-
-
-
-
' . reset_pw_form() . '
-
' . update_email_form() . '
-
' . update_username_form() . '
-
' . request_role_change_form() . '
-
' . delete_account_form() . '
-
-
- ';
- } else {
- $ids = articles_ids_by_author($_GET['user_id']);
- $view .= '
-
- ';
-
- foreach ($ids as $id)
- $view .= article_card($id);
-
- $view .= '
';
- }
-
- return $view;
-}
diff --git a/functions/admin_functions.php b/functions/admin_functions.php
index d3790e2..7f9d91f 100644
--- a/functions/admin_functions.php
+++ b/functions/admin_functions.php
@@ -6,167 +6,28 @@ require_once 'article_functions.php';
function create_users_from_csv($csv)
{
- $csv = read_file($csv);
- while ($record = fgets($csv)) {
- $fields = explode(',', $record);
+ $csv = read_file($csv);
+ while ($record = fgets($csv)) {
+ $fields = explode(',', $record);
- $username = $fields[0];
- $email = $fields[1];
- $password = $fields[2];
- $role_id = $fields[3];
+ $username = $fields[0];
+ $email = $fields[1];
+ $password = $fields[2];
+ $role_id = $fields[3];
- create_user(
- $username,
- $email,
- $password,
- $password,
- $role_id,
- );
- }
-}
-
-function admin_article_view()
-{
- $display = '
-
-
-
-
-
- ';
-
- return $display;
-}
-
-function admin_user_view()
-{
- $display = '
-
- ';
-
- return $display;
+ create_user(
+ $username,
+ $email,
+ $password,
+ $password,
+ $role_id,
+ );
+ }
}
function delete_users($ids)
{
- foreach ($ids as $id) {
- delete_account($id);
- }
+ foreach ($ids as $id) {
+ delete_account($id);
+ }
}
diff --git a/functions/article_functions.php b/functions/article_functions.php
index 05b5010..6f9c7d0 100644
--- a/functions/article_functions.php
+++ b/functions/article_functions.php
@@ -59,111 +59,6 @@ function article_ids_by_tag($tag)
return $ids;
}
-/*
- * Reads the markdown file for a given article and generates the HTML for it.
- */
-function article_page_from_markdown($article_id)
-{
- $article = exec_stmt('SELECT * FROM article WHERE article_id = ?', 'i', $article_id)->fetch_assoc();
- $author = exec_stmt('SELECT user_id, username, profile_picture FROM user WHERE user_id = ?', 'i', $article['author_id'])->fetch_assoc();
- $markdown = read_file_one_string($_ENV['ARTICLES_FQ_PATH'] . $article_id . '/article.md');
-
- $parsedown = new Parsedown();
- $parsedown->setSafeMode(true);
- $article_content = $parsedown->text($markdown);
-
- $html = '
-
-
-
-
' . $article['title'] . '
- ' . (isset($_COOKIE['user_id']) && $_COOKIE['user_id'] == $article['author_id'] ? '
' : '') . '
-
-
-
-
-
Published on ' . $article['published_at'] . '
- Lasted edited on ' . $article['updated_at'] . '
-
-
-

-
-
-
-
- ' . $article_content . '
-
-
- ';
-
- return $html;
-}
-
-function article_filters()
-{
- $filters = '
-
- ';
-
- return $filters;
-}
-
-/*
- * Generates cards for a given article.
- */
-function article_card($article_id)
-{
- $article = exec_stmt('SELECT * FROM article WHERE article_id = ?', 'i', $article_id)->fetch_assoc();
-
- $tags_results = exec_stmt('SELECT tag FROM article_tags INNER JOIN tags ON article_tags.tag_id = tags.tag_id WHERE article_id = ?', 'i', $article_id);
-
- $tags_html = '';
- if ($tags_results != null) {
- $tags_html .= '';
-
- while ($row = $tags_results->fetch_assoc())
- $tags_html .= '
#' . $row['tag'] . '';
-
- $tags_html .= '
';
- }
-
- $author = exec_stmt('SELECT user_id, username, profile_picture FROM user WHERE user_id = ?', 'i', $article['author_id'])->fetch_assoc();
-
- $card = '
-
-
-
' . $article['title'] . '
-
-
-
-

-
-
-
-
-
' . $article['excerpt'] . '
-
-
- ';
-
- return $card;
-}
-
function create_article($author_id, $title, $excerpt, $tags, $markdown_file_contents)
{
$id = exec_stmt('INSERT INTO article (author_id, title, excerpt, published_at) VALUES (?, ?, ?, CURRENT_TIMESTAMP)', 'iss', $author_id, $title, $excerpt);
diff --git a/functions/init.php b/functions/init.php
index 97cddb8..d67324b 100644
--- a/functions/init.php
+++ b/functions/init.php
@@ -1,6 +1,6 @@
response.text())
- .then(data => {
- preview.innerHTML = decodeURIComponent(data);
- });
- });
-} else {
- preview.style.display = 'none';
-}
+textarea.addEventListener('input', function() {
+ fetch('functions/preview.php', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/x-www-form-urlencoded',
+ },
+ body: 'markdown=' + encodeURIComponent(this.value),
+ })
+ .then(response => response.text())
+ .then(data => {
+ preview.innerHTML = decodeURIComponent(data);
+ });
+});
diff --git a/user.php b/user.php
index 47fe111..1f8f3d9 100644
--- a/user.php
+++ b/user.php
@@ -1,9 +1,12 @@