sync, implemented sort, viewing user pages & articles written, updating db
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
require_once 'db_functions.php';
|
||||
require_once 'article_functions.php';
|
||||
|
||||
function user_id_exists($user_id)
|
||||
{
|
||||
@@ -175,12 +176,13 @@ function create_user($username, $email, $password, $verify_password, $role_id, $
|
||||
|
||||
crop_image($upload['profile_picture']['tmp_name'], $x, $y, $crop_size, $crop_size);
|
||||
$target = upload($upload['profile_picture'], $_ENV['PROFILE_IMAGES_FQ_PATH'], $id);
|
||||
} else {
|
||||
$target = 'default-profile.png';
|
||||
}
|
||||
|
||||
$conn = get_connection();
|
||||
$stmt = $conn->prepare('INSERT INTO user (user_id, username, email, password_hash, role_id, profile_picture) VALUES (?, ?, ?, ?, ?, ?)');
|
||||
$asdf = (isset($target) ? $target : null);
|
||||
$stmt->bind_param('isssis', $id, $username, $email, $password_hash, $role_id, $asdf);
|
||||
$stmt->bind_param('isssis', $id, $username, $email, $password_hash, $role_id, $target);
|
||||
$stmt->execute();
|
||||
|
||||
return true;
|
||||
@@ -492,9 +494,6 @@ function delete_account($user_id, $password = null, $verify_password = null)
|
||||
|
||||
function user_view($user_id)
|
||||
{
|
||||
if (!isset($_COOKIE['role_id']) || ($_COOKIE['role_id'] > 2 && $_COOKIE['user_id'] != $user_id))
|
||||
header('Location: articles.php');
|
||||
|
||||
$conn = get_connection();
|
||||
$stmt = $conn->prepare('SELECT user_id, username, email, role_id, created_at, last_active, is_active, profile_picture FROM user WHERE user_id = ?');
|
||||
$stmt->bind_param('i', $user_id);
|
||||
@@ -513,33 +512,44 @@ function user_view($user_id)
|
||||
</div>
|
||||
</div>
|
||||
<div class="line"></div>
|
||||
<h3>User Actions</h3>
|
||||
';
|
||||
|
||||
// TODO: Need to setup an email handler.
|
||||
// <a class="modal_button underline">Request Role</a>
|
||||
// <div id="request_role_form" class="modal_form">' . request_role_change_form() . '</div>
|
||||
$view .= '
|
||||
<div class="user_actions">
|
||||
<button id="reset_pw_form_button" class="modal_button underline">Reset Password</button>
|
||||
<button id="update_email_form_button" class="modal_button underline">Update Email</button>
|
||||
<button id="update_username_form_button" class="modal_button underline">Update Username</button>
|
||||
<button id="delete_account_form_button" class="modal_button underline">Delete Account</button>
|
||||
</div>
|
||||
if ((isset($_COOKIE['user_id']) && $_COOKIE['user_id'] == $user_id) || (isset($_COOKIE['role_id']) && $_COOKIE['role_id'] <= 2)) {
|
||||
$view .= '
|
||||
<h3>User Actions</h3>
|
||||
<div class="user_actions">
|
||||
<button id="reset_pw_form_button" class="modal_button underline">Reset Password</button>
|
||||
<button id="update_email_form_button" class="modal_button underline">Update Email</button>
|
||||
<button id="update_username_form_button" class="modal_button underline">Update Username</button>
|
||||
<button id="delete_account_form_button" class="modal_button underline">Delete Account</button>
|
||||
</div>
|
||||
|
||||
<div id="user_actions_modal" class="modal">
|
||||
<div id="modal_content">
|
||||
<div id="user_actions_modal" class="modal">
|
||||
<div id="modal_content"></div>
|
||||
</div>
|
||||
|
||||
<div style="display: none;">
|
||||
<div id="reset_pw_form" class="modal_form">' . reset_pw_form() . '</div>
|
||||
<div id="update_email_form" class="modal_form">' . update_email_form() . '</div>
|
||||
<div id="update_username_form" class="modal_form">' . update_username_form() . '</div>
|
||||
<div id="delete_account_form" class="modal_form">' . delete_account_form() . '</div>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
} else {
|
||||
$ids = articles_ids_by_author($_GET['user_id']);
|
||||
$view .= '
|
||||
<div class="article_cards">
|
||||
';
|
||||
|
||||
<div style="display: none;">
|
||||
<div id="reset_pw_form" class="modal_form">' . reset_pw_form() . '</div>
|
||||
<div id="update_email_form" class="modal_form">' . update_email_form() . '</div>
|
||||
<div id="update_username_form" class="modal_form">' . update_username_form() . '</div>
|
||||
<div id="delete_account_form" class="modal_form">' . delete_account_form() . '</div>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
foreach ($ids as $id)
|
||||
$view .= article_card($id);
|
||||
|
||||
$view .= '</div>';
|
||||
}
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -128,6 +128,17 @@ function read_file($file_path)
|
||||
return $fs;
|
||||
}
|
||||
|
||||
function extract_content_from_tag($string, $start, $end)
|
||||
{
|
||||
$ini = strpos($string, $start);
|
||||
if ($ini != 0)
|
||||
return "nope";
|
||||
|
||||
$ini += strlen($start);
|
||||
$len = strpos($string, $end, $ini) - $ini;
|
||||
return substr($string, $ini, $len);
|
||||
}
|
||||
|
||||
function check_image_upload($target, $filetype, $image)
|
||||
{
|
||||
return true;
|
||||
|
||||
+2
-2
@@ -37,7 +37,7 @@ if (isset($_COOKIE['user_id'])) {
|
||||
$stmt->execute();
|
||||
$user = $stmt->get_result()->fetch_assoc();
|
||||
|
||||
$time = time() + 60 * 60 * 1;
|
||||
$time = time() + 60 * 15;
|
||||
cookies($user, $time);
|
||||
} else if (isset($_COOKIE['remember_user'])) {
|
||||
$conn = get_connection();
|
||||
@@ -64,7 +64,7 @@ if (isset($_COOKIE['user_id'])) {
|
||||
$stmt->bind_param('i', $_COOKIE['user_id']);
|
||||
$stmt->execute();
|
||||
|
||||
$time = time() + 60 * 60 * 1;
|
||||
$time = time() + 60 * 15;
|
||||
cookies($user, $time);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user