refactoring
This commit is contained in:
@@ -2,6 +2,10 @@
|
|||||||
require_once 'functions/init.php';
|
require_once 'functions/init.php';
|
||||||
require_once 'functions/functions.php';
|
require_once 'functions/functions.php';
|
||||||
|
|
||||||
|
// UI Components
|
||||||
|
foreach (glob('components/admin/*.php') as $file)
|
||||||
|
require_once $file;
|
||||||
|
|
||||||
include_once 'components/head.php';
|
include_once 'components/head.php';
|
||||||
|
|
||||||
if (!isset($_COOKIE['role_id']))
|
if (!isset($_COOKIE['role_id']))
|
||||||
|
|||||||
+48
-51
@@ -6,68 +6,65 @@ include_once 'components/head.php';
|
|||||||
|
|
||||||
include_once 'functions/article_functions.php';
|
include_once 'functions/article_functions.php';
|
||||||
|
|
||||||
// Default view, it'll show articles by recency
|
// UI Components
|
||||||
if (!isset($_GET['article_id']) && !isset($_GET['tag']) && !isset($_GET['author_id'])) {
|
foreach (glob('components/article/*.php') as $file)
|
||||||
$filters = '
|
require_once $file;
|
||||||
<form method="get">
|
|
||||||
<div class="row_no_margin">
|
|
||||||
';
|
|
||||||
|
|
||||||
if (!isset($_GET['sort']) || $_GET['sort'] == 'newest') {
|
if (isset($_POST['form_id'])) {
|
||||||
$ids = article_ids_by_newest();
|
switch ($_POST['form_id']) {
|
||||||
$filters .= '
|
case 'compose':
|
||||||
<p>Newest - Oldest</p>
|
if (isset($_POST['article_id'])) {
|
||||||
<label for="recency_desc"><i class="nf nf-md-sort_clock_descending_outline"></i>
|
$tags = [];
|
||||||
<input id="recency_desc" type="radio" name="sort" value="oldest" onclick="this.form.submit()">
|
for ($i = 0; $i < count($_POST['tags']); $i++)
|
||||||
</label>
|
$tags[] = $_POST['tags'][$i];
|
||||||
';
|
|
||||||
} else if ($_GET['sort'] == 'oldest') {
|
update_article($_POST['article_id'], $_POST['title'], $_POST['excerpt'], $tags, $_POST['markdown']);
|
||||||
$ids = article_ids_by_oldest();
|
header('Location: articles.php?article_id=' . $_POST['article_id']);
|
||||||
$filters .= '
|
} else {
|
||||||
<p>Oldest - Newest</p>
|
$id = create_article($_COOKIE['user_id'], $_POST['title'], $_POST['excerpt'], (isset($_POST['tags']) ? $_POST['tags'] : []), $_POST['markdown']);
|
||||||
<label for="recency_asc"><i class="nf nf-md-sort_clock_ascending_outline"></i>
|
header('Location: articles.php?article_id=' . $id);
|
||||||
<input id="recency_asc" type="radio" name="sort" value="newest" onclick="this.form.submit()">
|
|
||||||
</label>
|
|
||||||
';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$filters .= '
|
break;
|
||||||
</div>
|
}
|
||||||
</form>
|
} else {
|
||||||
';
|
if (isset($_GET['view']))
|
||||||
|
$view = $_GET['view'];
|
||||||
|
else
|
||||||
|
$view = 'list';
|
||||||
|
|
||||||
echo '
|
switch ($view) {
|
||||||
<div class="article_cards_grid">
|
case 'list':
|
||||||
<div class="article_filters">
|
echo article_list();
|
||||||
' . $filters . '
|
break;
|
||||||
</div>
|
case 'filter':
|
||||||
<div class="article_cards">
|
if (isset($_GET['tag']))
|
||||||
';
|
echo article_list(article_ids_by_tag($_GET['tag']));
|
||||||
foreach ($ids as $id)
|
else if (isset($_GET['author_id']))
|
||||||
echo article_card($id);
|
echo article_list(articles_ids_by_author($_GET['author_id']));
|
||||||
echo '
|
break;
|
||||||
</div>
|
case 'sort':
|
||||||
</div>
|
if (isset($_GET['sort']) && $_GET['sort'] == 'oldest')
|
||||||
';
|
echo article_list(article_ids_by_oldest());
|
||||||
} else if (isset($_COOKIE['user_id']) && isset($_GET['article_id'])) {
|
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']);
|
increment_read_counter($_GET['article_id']);
|
||||||
echo article_page_from_markdown($_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 {
|
} else {
|
||||||
$redirect = (isset($_GET['article_id']) ? 'articles.php?article_id=' . $_GET['article_id'] : '');
|
$redirect = (isset($_GET['article_id']) ? 'articles.php?view=read&article_id=' . $_GET['article_id'] : '');
|
||||||
if ($redirect)
|
if ($redirect)
|
||||||
header('Location: user.php?action=login&redirect=' . urlencode($redirect));
|
header('Location: user.php?action=login&redirect=' . urlencode($redirect));
|
||||||
else
|
else
|
||||||
header('Location: articles.php');
|
header('Location: articles.php');
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case 'compose':
|
||||||
|
echo compose_view((isset($_GET['article_id']) ? $_GET['article_id'] : ''));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
include_once 'components/foot.php';
|
include_once 'components/foot.php';
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
function admin_article_view()
|
||||||
|
{
|
||||||
|
$display = '
|
||||||
|
<div class="view_card">
|
||||||
|
<div class="row">
|
||||||
|
<h3>Articles</h3>
|
||||||
|
<a href="admin.php?view=users">View Users</a>
|
||||||
|
</div>
|
||||||
|
<div class="line"></div>
|
||||||
|
<form method="post">
|
||||||
|
<input type="hidden" name="form_id" value="articles">
|
||||||
|
<div class="row">
|
||||||
|
<label for="delete" class="form_checkbox_container">Delete
|
||||||
|
<input type="radio" class="button" name="action" id="delete" value="delete">
|
||||||
|
<span class="checkmark"></span>
|
||||||
|
</label>
|
||||||
|
<input type="submit" class="button narrow" value="Commit">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class="">Select</th>
|
||||||
|
<th>Article ID</th>
|
||||||
|
<th>Author</th>
|
||||||
|
<th>Title</th>
|
||||||
|
<th>Created</th>
|
||||||
|
<th>Updated</th>
|
||||||
|
<th>Published</th>
|
||||||
|
<th>Read Count</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
';
|
||||||
|
$conn = get_connection();
|
||||||
|
$results = $conn->query('SELECT article_id, username, title, read_count, article.created_at, updated_at, published_at, excerpt FROM article INNER JOIN user ON article.author_id = user.user_id;');
|
||||||
|
|
||||||
|
foreach ($results as $key => $result) {
|
||||||
|
$display .= '
|
||||||
|
<tr data-href="articles.php?view=read&article_id=' . $result['article_id'] . '">
|
||||||
|
<td class="excluded_cell">
|
||||||
|
<label class="form_checkbox_container">
|
||||||
|
<input name="selected_articles[]" value="' . $result['article_id'] . '" type="checkbox">
|
||||||
|
<span class="checkmark"></span>
|
||||||
|
</label>
|
||||||
|
</td>
|
||||||
|
<td>' . $result['article_id'] . '</td>
|
||||||
|
<td>' . $result['username'] . '</td>
|
||||||
|
<td>' . $result['title'] . '</td>
|
||||||
|
<td>' . $result['created_at'] . '</td>
|
||||||
|
<td>' . $result['updated_at'] . '</td>
|
||||||
|
<td>' . $result['published_at'] . '</td>
|
||||||
|
<td>' . $result['read_count'] . '</td>
|
||||||
|
</tr>
|
||||||
|
';
|
||||||
|
}
|
||||||
|
|
||||||
|
$display .= '
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
';
|
||||||
|
|
||||||
|
return $display;
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
function admin_user_view()
|
||||||
|
{
|
||||||
|
$display = '
|
||||||
|
<div class="view_card">
|
||||||
|
<div class="row">
|
||||||
|
<h3>Users</h3>
|
||||||
|
<a href="admin.php?view=articles">View Articles</a>
|
||||||
|
</div>
|
||||||
|
<div class="line"></div>
|
||||||
|
<form method="post" enctype="multipart/form-data">
|
||||||
|
<input type="hidden" name="form_id" value="users">
|
||||||
|
<div class="row">
|
||||||
|
<label for="delete" class="form_checkbox_container">Delete
|
||||||
|
<input type="radio" class="button" name="action" id="delete" value="delete">
|
||||||
|
<span class="checkmark"></span>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label id="create_users_from_csv_label" for="create_users_from_csv" class="upload_button">Upload a CSV</label>
|
||||||
|
<input id="create_users_from_csv" class="file_input" name="csv" type="file" accept=".csv">
|
||||||
|
<small class="file_input_feedback">No file selected.</small>
|
||||||
|
|
||||||
|
<input type="submit" class="button narrow" value="Commit">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>Select</th>
|
||||||
|
<th>User ID</th>
|
||||||
|
<th>Username</th>
|
||||||
|
<th>Email</th>
|
||||||
|
<th>Role</th>
|
||||||
|
<th>Created</th>
|
||||||
|
<th>Last Active</th>
|
||||||
|
<th>Active</th>
|
||||||
|
<th>Profile Picture</th>
|
||||||
|
</tr>
|
||||||
|
';
|
||||||
|
$conn = get_connection();
|
||||||
|
$results = $conn->query('SELECT user_id, username, email, last_active, role, created_at, is_active, profile_picture FROM user INNER JOIN roles ON user.role_id = roles.role_id;');
|
||||||
|
|
||||||
|
foreach ($results as $key => $result) {
|
||||||
|
$display .= '
|
||||||
|
<tr data-href="user.php?action=view&user_id=' . $result['user_id'] . '">
|
||||||
|
<td class="excluded_cell">
|
||||||
|
<label class="form_checkbox_container">
|
||||||
|
<input name="selected_users[]" value="' . $result['user_id'] . '" type="checkbox">
|
||||||
|
<span class="checkmark"></span>
|
||||||
|
</label>
|
||||||
|
</td>
|
||||||
|
<td>' . $result['user_id'] . '</td>
|
||||||
|
<td>' . htmlspecialchars($result['username']) . '</td>
|
||||||
|
<td>' . htmlspecialchars($result['email']) . '</td>
|
||||||
|
<td>' . ucwords($result['role']) . '</td>
|
||||||
|
<td>' . $result['created_at'] . '</td>
|
||||||
|
<td>' . $result['last_active'] . '</td>
|
||||||
|
<td>' . $result['is_active'] . '</td>
|
||||||
|
<td><img src="' . $_ENV['PROFILE_IMAGES_PQ_PATH'] . $result['profile_picture'] . '" class="card_profile_picture"></td>
|
||||||
|
</tr>
|
||||||
|
';
|
||||||
|
}
|
||||||
|
|
||||||
|
$display .= '
|
||||||
|
</table>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
';
|
||||||
|
|
||||||
|
return $display;
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 = '
|
||||||
|
<div class="article">
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<h1>' . $article['title'] . '</h1>
|
||||||
|
' . (isset($_COOKIE['user_id']) && $_COOKIE['user_id'] == $article['author_id'] ? '<a href="articles.php?view=compose&article_id=' . $article_id . '"><i class="nf nf-fa-edit"></i></a>' : '') . '
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col_right">
|
||||||
|
<h5>Written by <a href="user.php?action=view&user_id=' . $author['user_id'] . '">' . $author['username'] . '</a></h5>
|
||||||
|
<p>Published on ' . $article['published_at'] . '<br>
|
||||||
|
Lasted edited on ' . $article['updated_at'] . '</p>
|
||||||
|
</div>
|
||||||
|
<div class="card_pic_box">
|
||||||
|
<img src="' . $_ENV['PROFILE_IMAGES_PQ_PATH'] . $author['profile_picture'] . '" class="card_profile_picture" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="line" style="margin-bottom: 15px;"></div>
|
||||||
|
<div class="article_content">
|
||||||
|
' . $article_content . '
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
';
|
||||||
|
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 .= '<div class="tag_row">';
|
||||||
|
|
||||||
|
while ($row = $tags_results->fetch_assoc())
|
||||||
|
$tags_html .= '<a href="/articles.php?view=filter&tag=' . $row['tag'] . '" class="tag">#' . $row['tag'] . '</a>';
|
||||||
|
|
||||||
|
$tags_html .= '</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$author = exec_stmt('SELECT user_id, username, profile_picture FROM user WHERE user_id = ?', 'i', $article['author_id'])->fetch_assoc();
|
||||||
|
|
||||||
|
$card = '
|
||||||
|
<div class="article_card">
|
||||||
|
<div class="row">
|
||||||
|
<h4>' . $article['title'] . '</h4>
|
||||||
|
<div class="card_info_box">
|
||||||
|
<div class="col-right">
|
||||||
|
<a href="user.php?action=view&user_id=' . $author['user_id'] . '">Written by: ' . $author['username'] . '</a>
|
||||||
|
<small>Published: ' . $article['published_at'] . '</small>
|
||||||
|
<small>Updated: ' . $article['updated_at'] . '</small>
|
||||||
|
</div>
|
||||||
|
<div class="card_pic_box">
|
||||||
|
<img src="' . $_ENV['PROFILE_IMAGES_PQ_PATH'] . $author['profile_picture'] . '" class="card_profile_picture">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="line"></div>
|
||||||
|
<p>' . $article['excerpt'] . '</p>
|
||||||
|
<div class="row">
|
||||||
|
<a href="/articles.php?view=read&article_id=' . $article['article_id'] . '" class="button">Read More</a>
|
||||||
|
<div class="tag_box">' . $tags_html . '</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
';
|
||||||
|
|
||||||
|
return $card;
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
function preview()
|
||||||
|
{
|
||||||
|
$preview = '
|
||||||
|
<div class="full-height">
|
||||||
|
<div class="form_card" id="md_preview">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
';
|
||||||
|
|
||||||
|
return $preview;
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
function compose_view($article_id = null)
|
||||||
|
{
|
||||||
|
if (!empty($article_id)) {
|
||||||
|
$conn = get_connection();
|
||||||
|
$stmt = $conn->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 = '
|
||||||
|
<div class="grid-2x1">
|
||||||
|
' . (!empty($existing_markdown) ? form($article_id, $title, $excerpt, $existing_markdown, $tags) : form()) . '
|
||||||
|
' . preview() . '
|
||||||
|
';
|
||||||
|
|
||||||
|
$view .= preview() . '
|
||||||
|
</div>
|
||||||
|
';
|
||||||
|
|
||||||
|
return $view;
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
function form($article_id = null, $title = null, $excerpt = null, $existing_markdown = null, $tags = null)
|
||||||
|
{
|
||||||
|
$raw_tags = article_tags();
|
||||||
|
$tags_boxes = '
|
||||||
|
<div class="checkboxes">
|
||||||
|
<label>Tags</label>
|
||||||
|
';
|
||||||
|
|
||||||
|
foreach ($raw_tags as $row) {
|
||||||
|
$tags_boxes .= '
|
||||||
|
<label class="form_checkbox_container">' . $row['tag'] . '
|
||||||
|
<input name="tags[]" value="' . $row['tag_id'] . '" type="checkbox"' . (isset($tags) && in_array($row['tag_id'], $tags) ? ' checked' : '') . '>
|
||||||
|
<span class="checkmark"></span>
|
||||||
|
</label>
|
||||||
|
';
|
||||||
|
}
|
||||||
|
|
||||||
|
$tags_boxes .= '
|
||||||
|
</div>
|
||||||
|
';
|
||||||
|
|
||||||
|
$form = '
|
||||||
|
<div class="full-height">
|
||||||
|
<div class="form_card" id="composer">
|
||||||
|
<form method="post">
|
||||||
|
<input type="hidden" name="form_id" value="compose">
|
||||||
|
' . (isset($article_id) ? '<input type="hidden" name="article_id" value="' . $article_id . '">' : '') . '
|
||||||
|
|
||||||
|
<label for="title">Title</label>
|
||||||
|
<input id="title" name="title" placeholder="Article Title" required' . (isset($title) ? ' value="' . $title . '"' : '') . '>
|
||||||
|
|
||||||
|
<label for="markdown">Markdown</label>
|
||||||
|
<textarea id="markdown" name="markdown" required>' . (isset($existing_markdown) ? $existing_markdown : '') . '</textarea>
|
||||||
|
|
||||||
|
<label for="excerpt">Excerpt</label>
|
||||||
|
<input id="excerpt" name="excerpt" placeholder="Article Excerpt"' . (isset($excerpt) ? 'value="' . $excerpt . '"' : '') . '>
|
||||||
|
' . $tags_boxes . '
|
||||||
|
<input class="button" type="submit" value="' . (isset($article_id) ? 'Update Article' : 'Create Article') . '">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
';
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
function article_list($list = null)
|
||||||
|
{
|
||||||
|
$content = '';
|
||||||
|
$filters = '
|
||||||
|
<form method="get" action="articles.php">
|
||||||
|
<input type="hidden" name="view" value="sort">
|
||||||
|
<div class="row_no_margin">
|
||||||
|
';
|
||||||
|
|
||||||
|
if (!isset($_GET['sort']) || $_GET['sort'] == 'newest') {
|
||||||
|
$ids = article_ids_by_newest();
|
||||||
|
$filters .= '
|
||||||
|
<p>Newest - Oldest</p>
|
||||||
|
<label for="recency_desc"><i class="nf nf-md-sort_clock_descending_outline"></i>
|
||||||
|
<input id="recency_desc" type="radio" name="sort" value="oldest" onclick="this.form.submit()">
|
||||||
|
</label>
|
||||||
|
';
|
||||||
|
} else if ($_GET['sort'] == 'oldest') {
|
||||||
|
$ids = article_ids_by_oldest();
|
||||||
|
$filters .= '
|
||||||
|
<p>Oldest - Newest</p>
|
||||||
|
<label for="recency_asc"><i class="nf nf-md-sort_clock_ascending_outline"></i>
|
||||||
|
<input id="recency_asc" type="radio" name="sort" value="newest" onclick="this.form.submit()">
|
||||||
|
</label>
|
||||||
|
';
|
||||||
|
}
|
||||||
|
|
||||||
|
$filters .= '
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
';
|
||||||
|
|
||||||
|
$content .= '
|
||||||
|
<div class="article_cards_grid">
|
||||||
|
<div class="article_filters">
|
||||||
|
' . $filters . '
|
||||||
|
</div>
|
||||||
|
<div class="article_cards">
|
||||||
|
';
|
||||||
|
|
||||||
|
if (!isset($list))
|
||||||
|
foreach ($ids as $id)
|
||||||
|
$content .= article_card($id);
|
||||||
|
else
|
||||||
|
foreach ($list as $id)
|
||||||
|
$content .= article_card($id);
|
||||||
|
|
||||||
|
$content .= '
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
';
|
||||||
|
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
+10
-5
@@ -21,16 +21,15 @@ function get_args_from_url()
|
|||||||
if ($_SERVER['SCRIPT_NAME'] == '/user.php') {
|
if ($_SERVER['SCRIPT_NAME'] == '/user.php') {
|
||||||
$args = get_args_from_url();
|
$args = get_args_from_url();
|
||||||
|
|
||||||
if (isset($args['action'])) {
|
if (isset($args['view'])) {
|
||||||
if ($args['action'] == 'signup') {
|
if ($args['view'] == 'signup') {
|
||||||
echo '
|
echo '
|
||||||
<script src="js/profile_picture_cropper_modal.js"></script>
|
<script src="js/profile_picture_cropper_modal.js"></script>
|
||||||
<script src="js/upload.js"></script>
|
<script src="js/upload.js"></script>
|
||||||
';
|
';
|
||||||
} else if ($args['action'] == 'view') {
|
} else if ($args['view'] == 'display') {
|
||||||
echo '
|
echo '
|
||||||
<script src="js/user_actions_modal.js"></script>
|
<script src="js/user_actions_modal.js"></script>
|
||||||
<script src="js/profile_picture_cropper_modal.js"></script>
|
|
||||||
<script src="js/upload.js"></script>
|
<script src="js/upload.js"></script>
|
||||||
';
|
';
|
||||||
}
|
}
|
||||||
@@ -48,11 +47,17 @@ if ($_SERVER['SCRIPT_NAME'] == '/user.php') {
|
|||||||
';
|
';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ($_SERVER['SCRIPT_NAME'] == '/compose.php') {
|
} else if ($_SERVER['SCRIPT_NAME'] == '/articles.php') {
|
||||||
|
$args = get_args_from_url();
|
||||||
|
|
||||||
|
if (isset($args['view'])) {
|
||||||
|
if ($args['view'] == 'compose') {
|
||||||
echo '
|
echo '
|
||||||
<script src="js/md_preview.js"></script>
|
<script src="js/md_preview.js"></script>
|
||||||
';
|
';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
|
|||||||
+2
-8
@@ -6,7 +6,7 @@ $nav = '
|
|||||||
<div class="site_navigation">
|
<div class="site_navigation">
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="/index.php"' . ($current_page == '/index.php' ? ' class="underline"' : '') . '>Home</a></li>
|
<li><a href="/index.php"' . ($current_page == '/index.php' ? ' class="underline"' : '') . '>Home</a></li>
|
||||||
<li><a href="/articles.php?sort=newest"' . ($current_page == '/articles.php' ? ' class="underline"' : '') . '>Articles</a></li>
|
<li><a href="/articles.php?view=sort&sort=newest"' . ($current_page == '/articles.php' ? ' class="underline"' : '') . '>Articles</a></li>
|
||||||
';
|
';
|
||||||
|
|
||||||
if (isset($_COOKIE['role_id']) && $_COOKIE['role_id'] <= 2) {
|
if (isset($_COOKIE['role_id']) && $_COOKIE['role_id'] <= 2) {
|
||||||
@@ -17,13 +17,7 @@ if (isset($_COOKIE['role_id']) && $_COOKIE['role_id'] <= 2) {
|
|||||||
|
|
||||||
if (isset($_COOKIE['user_id'])) {
|
if (isset($_COOKIE['user_id'])) {
|
||||||
$nav .= '
|
$nav .= '
|
||||||
<li><a href="/user.php?action=view&user_id=' . $_COOKIE['user_id'] . '"' . ($current_page == '/user.php' ? ' class="underline"' : '') . '>Account</a></li>
|
<li><a href="/user.php?view=display&user_id=' . $_COOKIE['user_id'] . '"' . ($current_page == '/user.php' ? ' class="underline"' : '') . '>Account</a></li>
|
||||||
';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($_COOKIE['role_id']) && $_COOKIE['role_id'] <= 3) {
|
|
||||||
$nav .= '
|
|
||||||
<li><a href="/compose.php"' . ($current_page == '/compose.php' ? ' class="underline"' : '') . '>Compose</a></li>
|
|
||||||
';
|
';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
function delete_account_form()
|
||||||
|
{
|
||||||
|
$form = '
|
||||||
|
<div class="form_card">
|
||||||
|
<h5 class="underline">Delete Account</h5>
|
||||||
|
<span class="modal_close">×</span>
|
||||||
|
<form method="post">
|
||||||
|
<input type="hidden" name="form_id" value="delete_account_form">
|
||||||
|
<input type="hidden" name="user_id" value="' . $_GET['user_id'] . '">
|
||||||
|
|
||||||
|
<label for="delete_password">Password</label>
|
||||||
|
<input id="delete_password" name="delete_password" type="password" required>
|
||||||
|
|
||||||
|
<label for="delete_verify_password">Verify Password</label>
|
||||||
|
<input id="delete_verify_password" name="delete_verify_password" type="password" required>
|
||||||
|
|
||||||
|
<input type="submit" class="button" value="Delete Account">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
';
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
function login_form($error_msg = '')
|
||||||
|
{
|
||||||
|
$form = '
|
||||||
|
<div class="form_card">
|
||||||
|
<h3 class="underline">Log In</h3>
|
||||||
|
<form method="post">
|
||||||
|
<input type="hidden" name="form_id" value="login_form">
|
||||||
|
|
||||||
|
<label for="username">Username / Email</label>
|
||||||
|
<input id="username" name="username" required>
|
||||||
|
|
||||||
|
<label for="password">Password</label>
|
||||||
|
<input id="password" name="password" type="password" required>
|
||||||
|
|
||||||
|
<label class="form_checkbox_container">Stay Logged In?
|
||||||
|
<input name="stay_logged_in" type="checkbox" value="true">
|
||||||
|
<span class="checkmark"></span>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<input class="button" type="submit" value="Log In">
|
||||||
|
' . $error_msg . '
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
';
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
function profile_cropper()
|
||||||
|
{
|
||||||
|
$display = '
|
||||||
|
<div class="form_card">
|
||||||
|
<img src="IMG_UPLOAD_PATH" id="img_to_crop"/>
|
||||||
|
<div id="img_crop_selection">
|
||||||
|
<div class="corner" id="corner_nw"></div>
|
||||||
|
<div class="corner" id="corner_ne"></div>
|
||||||
|
<div class="corner" id="corner_sw"></div>
|
||||||
|
<div class="corner" id="corner_se"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<button id="crop_button" class="button">Crop</button>
|
||||||
|
<button id="crop_cancel" class="button">Cancel</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
';
|
||||||
|
|
||||||
|
return $display;
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
function request_role_change_form()
|
||||||
|
{
|
||||||
|
$conn = get_connection();
|
||||||
|
$result = $conn->query('SELECT * FROM roles WHERE role_id <> 1');
|
||||||
|
|
||||||
|
$roles = '<div class="checkboxes">';
|
||||||
|
while ($row = $result->fetch_assoc()) {
|
||||||
|
$roles .= '
|
||||||
|
<label class="form_checkbox_container">' . $row['role'] . '
|
||||||
|
<input name="requested_role" value="' . $row['role_id'] . '" type="radio"' . ($row['role_id'] == $_COOKIE['role_id'] ? ' checked' : '') . '>
|
||||||
|
<span class="checkmark"></span>
|
||||||
|
</label>
|
||||||
|
';
|
||||||
|
}
|
||||||
|
|
||||||
|
$roles .= '</div>';
|
||||||
|
|
||||||
|
$form = '
|
||||||
|
<div class="form_card">
|
||||||
|
<h5 class="underline">Request Role</h5>
|
||||||
|
<span class="modal_close">×</span>
|
||||||
|
<form method="post">
|
||||||
|
<input type="hidden" name="form_id" value="request_role_change_form">
|
||||||
|
' . $roles . '
|
||||||
|
|
||||||
|
<input type="submit" class="button" value="Request Role">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
';
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
function reset_pw_form()
|
||||||
|
{
|
||||||
|
$form = '
|
||||||
|
<div class="form_card">
|
||||||
|
<h5 class="underline">Reset Password</h5>
|
||||||
|
<span class="modal_close">×</span>
|
||||||
|
<form method="post">
|
||||||
|
<input type="hidden" name="form_id" value="reset_pw_form">
|
||||||
|
<input type="hidden" name="user_id" value="' . $_GET['user_id'] . '">
|
||||||
|
|
||||||
|
<label for="new_pw">New Password</label>
|
||||||
|
<input id="new_pw" name="new_pw" type="password" required>
|
||||||
|
|
||||||
|
<label for="verify_new_pw">Verify New Password</label>
|
||||||
|
<input id="verify_new_pw" name="verify_new_pw" type="password" required>
|
||||||
|
|
||||||
|
<input type="submit" class="button" value="Reset Password">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
';
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
function signup_form($error_msg = '')
|
||||||
|
{
|
||||||
|
$form = '
|
||||||
|
<div class="form_card">
|
||||||
|
<h3 class="underline">Sign Up</h3>
|
||||||
|
<form method="post" enctype="multipart/form-data">
|
||||||
|
<input type="hidden" name="form_id" value="signup_form">
|
||||||
|
<input type="hidden" name="crop_x" value="" id="crop_x">
|
||||||
|
<input type="hidden" name="crop_y" value="" id="crop_y">
|
||||||
|
<input type="hidden" name="crop_width" value="" id="crop_width">
|
||||||
|
<input name="required_field" id="required_field" value="">
|
||||||
|
|
||||||
|
<label for="username">Username</label>
|
||||||
|
<input id="username" name="username" required>
|
||||||
|
|
||||||
|
<label for="email">Email Address</label>
|
||||||
|
<input id="email" name="email" required>
|
||||||
|
|
||||||
|
<label for="password">Password</label>
|
||||||
|
<input id="password" name="password" type="password" required>
|
||||||
|
|
||||||
|
<label for="verify_password">Verify Password</label>
|
||||||
|
<input id="verify_password" name="verify_password" type="password" required>
|
||||||
|
|
||||||
|
<label for="profile_picture_input" class="upload_button modal_button" id="profile_cropper_button">Upload a Profile Picture</label>
|
||||||
|
<input id="profile_picture_input" class="file_input" name="profile_picture" type="file" accept="image/png, image/jpeg, image/jpg">
|
||||||
|
<small class="file_input_feedback">No file selected.</small>
|
||||||
|
|
||||||
|
<label class="form_checkbox_container">Stay Logged In?
|
||||||
|
<input name="stay_logged_in" type="checkbox" value="true">
|
||||||
|
<span class="checkmark"></span>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<input class="button" type="submit" value="Sign Up">
|
||||||
|
' . $error_msg . '
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div id="modal" class="modal">
|
||||||
|
<div id="display_modal"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="display: none;">
|
||||||
|
<div id="profile_cropper" class="modal_form">' . profile_cropper() . '</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
';
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
function update_email_form()
|
||||||
|
{
|
||||||
|
$form = '
|
||||||
|
<div class="form_card">
|
||||||
|
<h5 class="underline">Update Email</h5>
|
||||||
|
<span class="modal_close">×</span>
|
||||||
|
<form method="post">
|
||||||
|
<input type="hidden" name="form_id" value="update_email_form">
|
||||||
|
<input type="hidden" name="user_id" value="' . $_GET['user_id'] . '">
|
||||||
|
|
||||||
|
<label for="new_email">New Email</label>
|
||||||
|
<input id="new_email" name="new_email" required>
|
||||||
|
|
||||||
|
<label for="verify_new_email">Verify New Email</label>
|
||||||
|
<input id="verify_new_email" name="verify_new_email" required>
|
||||||
|
|
||||||
|
<input type="submit" class="button" value="Update Email">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
';
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
function update_profile_picture_form()
|
||||||
|
{
|
||||||
|
$form = '
|
||||||
|
<div class="form_card">
|
||||||
|
<h5 class="underline">Update Profile Picture</h5>
|
||||||
|
<span class="modal_close">×</span>
|
||||||
|
<form method="post">
|
||||||
|
<input type="hidden" name="form_id" value="update_profile_picture_form">
|
||||||
|
<input type="hidden" name="user_id" value="' . $_GET['user_id'] . '">
|
||||||
|
<input type="hidden" name="crop_x" value="" id="crop_x">
|
||||||
|
<input type="hidden" name="crop_y" value="" id="crop_y">
|
||||||
|
<input type="hidden" name="crop_width" value="" id="crop_width">
|
||||||
|
|
||||||
|
<label for="profile_picture_input" class="upload_button modal_button" id="profile_cropper_button">Upload a Profile Picture</label>
|
||||||
|
<input id="profile_picture_input" class="file_input" name="profile_picture" type="file" accept="image/png, image/jpeg, image/jpg">
|
||||||
|
<small class="file_input_feedback">No file selected.</small>
|
||||||
|
|
||||||
|
<input type="submit" class="button" value="Update Profile Picture">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div id="modal" class="modal">
|
||||||
|
<div id="display_modal"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="display: none;">
|
||||||
|
<div id="profile_cropper" class="modal_form">' . profile_cropper() . '</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
';
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
function update_username_form()
|
||||||
|
{
|
||||||
|
$form = '
|
||||||
|
<div class="form_card">
|
||||||
|
<h5 class="underline">Update Username</h5>
|
||||||
|
<span class="modal_close">×</span>
|
||||||
|
<form method="post">
|
||||||
|
<input type="hidden" name="form_id" value="update_username_form">
|
||||||
|
<input type="hidden" name="user_id" value="' . $_GET['user_id'] . '">
|
||||||
|
|
||||||
|
<label for="new_username">New Username</label>
|
||||||
|
<input id="new_username" name="new_username" required>
|
||||||
|
|
||||||
|
<label for="verify_new_username">Verify New Username</label>
|
||||||
|
<input id="verify_new_username" name="verify_new_username" required>
|
||||||
|
|
||||||
|
<input type="submit" class="button" value="Update Username">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
';
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
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 = '
|
||||||
|
<div class="user_view">
|
||||||
|
<div class="row">
|
||||||
|
<h1>' . $user['username'] . '</h1>
|
||||||
|
<div class="card_pic_box">
|
||||||
|
<img src="' . $_ENV['PROFILE_IMAGES_PQ_PATH'] . $user['profile_picture'] . '" class="profile_picture" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="line"></div>
|
||||||
|
';
|
||||||
|
|
||||||
|
// TODO: Allow user to update profile picture.
|
||||||
|
// <button id="update_profile_picture_form_button" class="modal_button underline">Update Profile Picture</button>
|
||||||
|
// <div id="update_profile_picture_form" class="modal_form">' . update_profile_picture_form() . '</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="request_role_form_button" class="modal_button underline">Request Role</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>
|
||||||
|
</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="request_role_change_form" class="modal_form">' . request_role_change_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">
|
||||||
|
';
|
||||||
|
|
||||||
|
foreach ($ids as $id)
|
||||||
|
$view .= article_card($id);
|
||||||
|
|
||||||
|
$view .= '</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $view;
|
||||||
|
}
|
||||||
-119
@@ -1,119 +0,0 @@
|
|||||||
<?php
|
|
||||||
require_once 'functions/init.php';
|
|
||||||
require_once 'functions/functions.php';
|
|
||||||
include_once 'functions/article_functions.php';
|
|
||||||
|
|
||||||
if (!empty($_POST)) {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($_COOKIE['role_id']) || $_COOKIE['role_id'] == 4)
|
|
||||||
header('Location: articles.php');
|
|
||||||
|
|
||||||
include_once 'components/head.php';
|
|
||||||
|
|
||||||
if (isset($_GET['article_id'])) {
|
|
||||||
$article_id = $_GET['article_id'];
|
|
||||||
|
|
||||||
$conn = get_connection();
|
|
||||||
$stmt = $conn->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 '
|
|
||||||
<div class="grid-2x1">
|
|
||||||
';
|
|
||||||
if (!empty($existing_markdown)) {
|
|
||||||
echo form($article_id, $title, $excerpt, $existing_markdown, $tags);
|
|
||||||
} else {
|
|
||||||
echo form();
|
|
||||||
}
|
|
||||||
|
|
||||||
echo preview();
|
|
||||||
|
|
||||||
echo '
|
|
||||||
</div>
|
|
||||||
';
|
|
||||||
|
|
||||||
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 = '
|
|
||||||
<div class="checkboxes">
|
|
||||||
<label>Tags</label>
|
|
||||||
';
|
|
||||||
|
|
||||||
foreach ($raw_tags as $row) {
|
|
||||||
$tags_boxes .= '
|
|
||||||
<label class="form_checkbox_container">' . $row['tag'] . '
|
|
||||||
<input name="tags[]" value="' . $row['tag_id'] . '" type="checkbox"' . (isset($tags) && in_array($row['tag_id'], $tags) ? ' checked' : '') . '>
|
|
||||||
<span class="checkmark"></span>
|
|
||||||
</label>
|
|
||||||
';
|
|
||||||
}
|
|
||||||
|
|
||||||
$tags_boxes .= '
|
|
||||||
</div>
|
|
||||||
';
|
|
||||||
|
|
||||||
$form = '
|
|
||||||
<div class="full-height">
|
|
||||||
<div class="form_card" id="composer">
|
|
||||||
<form method="post">
|
|
||||||
' . (isset($article_id) ? '<input type="hidden" name="article_id" value="' . $article_id . '">' : '') . '
|
|
||||||
|
|
||||||
<label for="title">Title</label>
|
|
||||||
<input id="title" name="title" placeholder="Article Title" required' . (isset($title) ? ' value="' . $title . '"' : '') . '>
|
|
||||||
|
|
||||||
<label for="markdown">Markdown</label>
|
|
||||||
<textarea id="markdown" name="markdown" required>' . (isset($existing_markdown) ? $existing_markdown : '') . '</textarea>
|
|
||||||
|
|
||||||
<label for="excerpt">Excerpt</label>
|
|
||||||
<input id="excerpt" name="excerpt" placeholder="Article Excerpt"' . (isset($excerpt) ? 'value="' . $excerpt . '"' : '') . '>
|
|
||||||
' . $tags_boxes . '
|
|
||||||
<input class="button" type="submit" value="' . (isset($article_id) ? 'Update Article' : 'Create Article') . '">
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
';
|
|
||||||
|
|
||||||
return $form;
|
|
||||||
}
|
|
||||||
|
|
||||||
function preview()
|
|
||||||
{
|
|
||||||
$preview = '
|
|
||||||
<div class="full-height">
|
|
||||||
<div class="form_card" id="md_preview">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
';
|
|
||||||
|
|
||||||
return $preview;
|
|
||||||
}
|
|
||||||
@@ -13,7 +13,14 @@ function user_id_exists($user_id)
|
|||||||
return true;
|
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)
|
function cookies($user, $time)
|
||||||
{
|
{
|
||||||
@@ -38,34 +45,6 @@ function logout()
|
|||||||
header('Location: articles.php');
|
header('Location: articles.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
function login_form($error_msg = '')
|
|
||||||
{
|
|
||||||
$form = '
|
|
||||||
<div class="form_card">
|
|
||||||
<h3 class="underline">Log In</h3>
|
|
||||||
<form method="post">
|
|
||||||
<input type="hidden" name="form_id" value="login_form">
|
|
||||||
|
|
||||||
<label for="username">Username / Email</label>
|
|
||||||
<input id="username" name="username" required>
|
|
||||||
|
|
||||||
<label for="password">Password</label>
|
|
||||||
<input id="password" name="password" type="password" required>
|
|
||||||
|
|
||||||
<label class="form_checkbox_container">Stay Logged In?
|
|
||||||
<input name="stay_logged_in" type="checkbox" value="true">
|
|
||||||
<span class="checkmark"></span>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<input class="button" type="submit" value="Log In">
|
|
||||||
' . $error_msg . '
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
';
|
|
||||||
|
|
||||||
return $form;
|
|
||||||
}
|
|
||||||
|
|
||||||
function login($username, $password, $stay_logged_in)
|
function login($username, $password, $stay_logged_in)
|
||||||
{
|
{
|
||||||
$password_hash = hash('sha256', $password);
|
$password_hash = hash('sha256', $password);
|
||||||
@@ -97,56 +76,6 @@ function login($username, $password, $stay_logged_in)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function signup_form($error_msg = '')
|
|
||||||
{
|
|
||||||
$form = '
|
|
||||||
<div class="form_card">
|
|
||||||
<h3 class="underline">Sign Up</h3>
|
|
||||||
<form method="post" enctype="multipart/form-data">
|
|
||||||
<input type="hidden" name="form_id" value="signup_form">
|
|
||||||
<input type="hidden" name="crop_x" value="" id="crop_x">
|
|
||||||
<input type="hidden" name="crop_y" value="" id="crop_y">
|
|
||||||
<input type="hidden" name="crop_width" value="" id="crop_width">
|
|
||||||
<input name="required_field" id="required_field" value="">
|
|
||||||
|
|
||||||
<label for="username">Username</label>
|
|
||||||
<input id="username" name="username" required>
|
|
||||||
|
|
||||||
<label for="email">Email Address</label>
|
|
||||||
<input id="email" name="email" required>
|
|
||||||
|
|
||||||
<label for="password">Password</label>
|
|
||||||
<input id="password" name="password" type="password" required>
|
|
||||||
|
|
||||||
<label for="verify_password">Verify Password</label>
|
|
||||||
<input id="verify_password" name="verify_password" type="password" required>
|
|
||||||
|
|
||||||
<label for="profile_picture_input" class="upload_button modal_button" id="profile_cropper_button">Upload a Profile Picture</label>
|
|
||||||
<input id="profile_picture_input" class="file_input" name="profile_picture" type="file" accept="image/png, image/jpeg, image/jpg">
|
|
||||||
<small class="file_input_feedback">No file selected.</small>
|
|
||||||
|
|
||||||
<label class="form_checkbox_container">Stay Logged In?
|
|
||||||
<input name="stay_logged_in" type="checkbox" value="true">
|
|
||||||
<span class="checkmark"></span>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<input class="button" type="submit" value="Sign Up">
|
|
||||||
' . $error_msg . '
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<div id="modal" class="modal">
|
|
||||||
<div id="display_modal"></div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div style="display: none;">
|
|
||||||
<div id="profile_cropper" class="modal_form">' . profile_cropper() . '</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
';
|
|
||||||
|
|
||||||
return $form;
|
|
||||||
}
|
|
||||||
|
|
||||||
function create_user($username, $email, $password, $verify_password, $role_id, $upload = null, $x = null, $y = null, $crop_width = null, $honeypot = null)
|
function create_user($username, $email, $password, $verify_password, $role_id, $upload = null, $x = null, $y = null, $crop_width = null, $honeypot = null)
|
||||||
{
|
{
|
||||||
if (!empty($honeypot)) {
|
if (!empty($honeypot)) {
|
||||||
@@ -200,52 +129,6 @@ function create_user($username, $email, $password, $verify_password, $role_id, $
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function profile_cropper()
|
|
||||||
{
|
|
||||||
$display = '
|
|
||||||
<div class="form_card">
|
|
||||||
<img src="IMG_UPLOAD_PATH" id="img_to_crop"/>
|
|
||||||
<div id="img_crop_selection">
|
|
||||||
<div class="corner" id="corner_nw"></div>
|
|
||||||
<div class="corner" id="corner_ne"></div>
|
|
||||||
<div class="corner" id="corner_sw"></div>
|
|
||||||
<div class="corner" id="corner_se"></div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<button id="crop_button" class="button">Crop</button>
|
|
||||||
<button id="crop_cancel" class="button">Cancel</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
';
|
|
||||||
|
|
||||||
return $display;
|
|
||||||
}
|
|
||||||
|
|
||||||
function reset_pw_form()
|
|
||||||
{
|
|
||||||
$form = '
|
|
||||||
<div class="form_card">
|
|
||||||
<h5 class="underline">Reset Password</h5>
|
|
||||||
<span class="modal_close">×</span>
|
|
||||||
<form method="post">
|
|
||||||
<input type="hidden" name="form_id" value="reset_pw_form">
|
|
||||||
<input type="hidden" name="user_id" value="' . $_GET['user_id'] . '">
|
|
||||||
|
|
||||||
<label for="new_pw">New Password</label>
|
|
||||||
<input id="new_pw" name="new_pw" type="password" required>
|
|
||||||
|
|
||||||
<label for="verify_new_pw">Verify New Password</label>
|
|
||||||
<input id="verify_new_pw" name="verify_new_pw" type="password" required>
|
|
||||||
|
|
||||||
<input type="submit" class="button" value="Reset Password">
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
';
|
|
||||||
|
|
||||||
return $form;
|
|
||||||
}
|
|
||||||
|
|
||||||
function reset_password($user_id, $new_password, $verify_new_password)
|
function reset_password($user_id, $new_password, $verify_new_password)
|
||||||
{
|
{
|
||||||
if ($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);
|
exec_stmt('UPDATE user SET password_hash = ? WHERE user_id = ?', 'si', $password_hash, $user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function update_email_form()
|
|
||||||
{
|
|
||||||
$form = '
|
|
||||||
<div class="form_card">
|
|
||||||
<h5 class="underline">Update Email</h5>
|
|
||||||
<span class="modal_close">×</span>
|
|
||||||
<form method="post">
|
|
||||||
<input type="hidden" name="form_id" value="update_email_form">
|
|
||||||
<input type="hidden" name="user_id" value="' . $_GET['user_id'] . '">
|
|
||||||
|
|
||||||
<label for="new_email">New Email</label>
|
|
||||||
<input id="new_email" name="new_email" required>
|
|
||||||
|
|
||||||
<label for="verify_new_email">Verify New Email</label>
|
|
||||||
<input id="verify_new_email" name="verify_new_email" required>
|
|
||||||
|
|
||||||
<input type="submit" class="button" value="Update Email">
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
';
|
|
||||||
|
|
||||||
return $form;
|
|
||||||
}
|
|
||||||
|
|
||||||
function update_email($user_id, $new_email, $verify_new_email)
|
function update_email($user_id, $new_email, $verify_new_email)
|
||||||
{
|
{
|
||||||
if ($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);
|
exec_stmt('UPDATE user SET email = ? WHERE user_id = ?', 'si', $new_email, $user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function update_username_form()
|
|
||||||
{
|
|
||||||
$form = '
|
|
||||||
<div class="form_card">
|
|
||||||
<h5 class="underline">Update Username</h5>
|
|
||||||
<span class="modal_close">×</span>
|
|
||||||
<form method="post">
|
|
||||||
<input type="hidden" name="form_id" value="update_username_form">
|
|
||||||
<input type="hidden" name="user_id" value="' . $_GET['user_id'] . '">
|
|
||||||
|
|
||||||
<label for="new_username">New Username</label>
|
|
||||||
<input id="new_username" name="new_username" required>
|
|
||||||
|
|
||||||
<label for="verify_new_username">Verify New Username</label>
|
|
||||||
<input id="verify_new_username" name="verify_new_username" required>
|
|
||||||
|
|
||||||
<input type="submit" class="button" value="Update Username">
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
';
|
|
||||||
|
|
||||||
return $form;
|
|
||||||
}
|
|
||||||
|
|
||||||
function update_username($user_id, $new_username, $verify_new_username)
|
function update_username($user_id, $new_username, $verify_new_username)
|
||||||
{
|
{
|
||||||
if ($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);
|
exec_stmt('UPDATE user SET username = ? WHERE user_id = ?', 'si', $new_username, $user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function update_profile_picture_form()
|
|
||||||
{
|
|
||||||
$form = '
|
|
||||||
<div class="form_card">
|
|
||||||
<h5 class="underline">Update Profile Picture</h5>
|
|
||||||
<span class="modal_close">×</span>
|
|
||||||
<form method="post">
|
|
||||||
<input type="hidden" name="form_id" value="update_profile_picture_form">
|
|
||||||
<input type="hidden" name="user_id" value="' . $_GET['user_id'] . '">
|
|
||||||
<input type="hidden" name="crop_x" value="" id="crop_x">
|
|
||||||
<input type="hidden" name="crop_y" value="" id="crop_y">
|
|
||||||
<input type="hidden" name="crop_width" value="" id="crop_width">
|
|
||||||
|
|
||||||
<label for="profile_picture_input" class="upload_button modal_button" id="profile_cropper_button">Upload a Profile Picture</label>
|
|
||||||
<input id="profile_picture_input" class="file_input" name="profile_picture" type="file" accept="image/png, image/jpeg, image/jpg">
|
|
||||||
<small class="file_input_feedback">No file selected.</small>
|
|
||||||
|
|
||||||
<input type="submit" class="button" value="Update Profile Picture">
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<div id="modal" class="modal">
|
|
||||||
<div id="display_modal"></div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div style="display: none;">
|
|
||||||
<div id="profile_cropper" class="modal_form">' . profile_cropper() . '</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
';
|
|
||||||
|
|
||||||
return $form;
|
|
||||||
}
|
|
||||||
|
|
||||||
function update_profile_picture($user_id) {}
|
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 = '<div class="checkboxes">';
|
|
||||||
while ($row = $result->fetch_assoc()) {
|
|
||||||
$roles .= '
|
|
||||||
<label class="form_checkbox_container">' . $row['role'] . '
|
|
||||||
<input name="requested_role" value="' . $row['role_id'] . '" type="radio"' . ($row['role_id'] == $_COOKIE['role_id'] ? ' checked' : '') . '>
|
|
||||||
<span class="checkmark"></span>
|
|
||||||
</label>
|
|
||||||
';
|
|
||||||
}
|
|
||||||
|
|
||||||
$roles .= '</div>';
|
|
||||||
|
|
||||||
$form = '
|
|
||||||
<div class="form_card">
|
|
||||||
<h5 class="underline">Request Role</h5>
|
|
||||||
<span class="modal_close">×</span>
|
|
||||||
<form method="post">
|
|
||||||
<input type="hidden" name="form_id" value="request_role_change_form">
|
|
||||||
' . $roles . '
|
|
||||||
|
|
||||||
<input type="submit" class="button" value="Request Role">
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
';
|
|
||||||
|
|
||||||
return $form;
|
|
||||||
}
|
|
||||||
|
|
||||||
function request_role_change($user_id, $new_role_id)
|
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();
|
$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 = '
|
|
||||||
<div class="form_card">
|
|
||||||
<h5 class="underline">Delete Account</h5>
|
|
||||||
<span class="modal_close">×</span>
|
|
||||||
<form method="post">
|
|
||||||
<input type="hidden" name="form_id" value="delete_account_form">
|
|
||||||
<input type="hidden" name="user_id" value="' . $_GET['user_id'] . '">
|
|
||||||
|
|
||||||
<label for="delete_password">Password</label>
|
|
||||||
<input id="delete_password" name="delete_password" type="password" required>
|
|
||||||
|
|
||||||
<label for="delete_verify_password">Verify Password</label>
|
|
||||||
<input id="delete_verify_password" name="delete_verify_password" type="password" required>
|
|
||||||
|
|
||||||
<input type="submit" class="button" value="Delete Account">
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
';
|
|
||||||
|
|
||||||
return $form;
|
|
||||||
}
|
|
||||||
|
|
||||||
function delete_account($user_id, $password = null, $verify_password = null)
|
function delete_account($user_id, $password = null, $verify_password = null)
|
||||||
{
|
{
|
||||||
if ($user_id == 2025) {
|
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);
|
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 = '
|
|
||||||
<div class="user_view">
|
|
||||||
<div class="row">
|
|
||||||
<h1>' . $user['username'] . '</h1>
|
|
||||||
<div class="card_pic_box">
|
|
||||||
<img src="' . $_ENV['PROFILE_IMAGES_PQ_PATH'] . $user['profile_picture'] . '" class="profile_picture" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="line"></div>
|
|
||||||
';
|
|
||||||
|
|
||||||
// TODO: Allow user to update profile picture.
|
|
||||||
// <button id="update_profile_picture_form_button" class="modal_button underline">Update Profile Picture</button>
|
|
||||||
// <div id="update_profile_picture_form" class="modal_form">' . update_profile_picture_form() . '</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="request_role_form_button" class="modal_button underline">Request Role</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>
|
|
||||||
</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="request_role_change_form" class="modal_form">' . request_role_change_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">
|
|
||||||
';
|
|
||||||
|
|
||||||
foreach ($ids as $id)
|
|
||||||
$view .= article_card($id);
|
|
||||||
|
|
||||||
$view .= '</div>';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $view;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -25,145 +25,6 @@ function create_users_from_csv($csv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function admin_article_view()
|
|
||||||
{
|
|
||||||
$display = '
|
|
||||||
<div class="view_card">
|
|
||||||
<div class="row">
|
|
||||||
<h3>Articles</h3>
|
|
||||||
<a href="admin.php?view=users">View Users</a>
|
|
||||||
</div>
|
|
||||||
<div class="line"></div>
|
|
||||||
<form method="post">
|
|
||||||
<input type="hidden" name="form_id" value="articles">
|
|
||||||
<div class="row">
|
|
||||||
<label for="delete" class="form_checkbox_container">Delete
|
|
||||||
<input type="radio" class="button" name="action" id="delete" value="delete">
|
|
||||||
<span class="checkmark"></span>
|
|
||||||
</label>
|
|
||||||
<input type="submit" class="button narrow" value="Commit">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<table>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th class="">Select</th>
|
|
||||||
<th>Article ID</th>
|
|
||||||
<th>Author</th>
|
|
||||||
<th>Title</th>
|
|
||||||
<th>Created</th>
|
|
||||||
<th>Updated</th>
|
|
||||||
<th>Published</th>
|
|
||||||
<th>Read Count</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
';
|
|
||||||
$conn = get_connection();
|
|
||||||
$results = $conn->query('SELECT article_id, username, title, read_count, article.created_at, updated_at, published_at, excerpt FROM article INNER JOIN user ON article.author_id = user.user_id;');
|
|
||||||
|
|
||||||
foreach ($results as $key => $result) {
|
|
||||||
$display .= '
|
|
||||||
<tr data-href="articles.php?action=view&article_id=' . $result['article_id'] . '">
|
|
||||||
<td class="excluded_cell">
|
|
||||||
<label class="form_checkbox_container">
|
|
||||||
<input name="selected_articles[]" value="' . $result['article_id'] . '" type="checkbox">
|
|
||||||
<span class="checkmark"></span>
|
|
||||||
</label>
|
|
||||||
</td>
|
|
||||||
<td>' . $result['article_id'] . '</td>
|
|
||||||
<td>' . $result['username'] . '</td>
|
|
||||||
<td>' . $result['title'] . '</td>
|
|
||||||
<td>' . $result['created_at'] . '</td>
|
|
||||||
<td>' . $result['updated_at'] . '</td>
|
|
||||||
<td>' . $result['published_at'] . '</td>
|
|
||||||
<td>' . $result['read_count'] . '</td>
|
|
||||||
</tr>
|
|
||||||
';
|
|
||||||
}
|
|
||||||
|
|
||||||
$display .= '
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
';
|
|
||||||
|
|
||||||
return $display;
|
|
||||||
}
|
|
||||||
|
|
||||||
function admin_user_view()
|
|
||||||
{
|
|
||||||
$display = '
|
|
||||||
<div class="view_card">
|
|
||||||
<div class="row">
|
|
||||||
<h3>Users</h3>
|
|
||||||
<a href="admin.php?view=articles">View Articles</a>
|
|
||||||
</div>
|
|
||||||
<div class="line"></div>
|
|
||||||
<form method="post" enctype="multipart/form-data">
|
|
||||||
<input type="hidden" name="form_id" value="users">
|
|
||||||
<div class="row">
|
|
||||||
<label for="delete" class="form_checkbox_container">Delete
|
|
||||||
<input type="radio" class="button" name="action" id="delete" value="delete">
|
|
||||||
<span class="checkmark"></span>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<label id="create_users_from_csv_label" for="create_users_from_csv" class="upload_button">Upload a CSV</label>
|
|
||||||
<input id="create_users_from_csv" class="file_input" name="csv" type="file" accept=".csv">
|
|
||||||
<small class="file_input_feedback">No file selected.</small>
|
|
||||||
|
|
||||||
<input type="submit" class="button narrow" value="Commit">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<table>
|
|
||||||
<tr>
|
|
||||||
<th>Select</th>
|
|
||||||
<th>User ID</th>
|
|
||||||
<th>Username</th>
|
|
||||||
<th>Email</th>
|
|
||||||
<th>Role</th>
|
|
||||||
<th>Created</th>
|
|
||||||
<th>Last Active</th>
|
|
||||||
<th>Active</th>
|
|
||||||
<th>Profile Picture</th>
|
|
||||||
</tr>
|
|
||||||
';
|
|
||||||
$conn = get_connection();
|
|
||||||
$results = $conn->query('SELECT user_id, username, email, last_active, role, created_at, is_active, profile_picture FROM user INNER JOIN roles ON user.role_id = roles.role_id;');
|
|
||||||
|
|
||||||
foreach ($results as $key => $result) {
|
|
||||||
$display .= '
|
|
||||||
<tr data-href="user.php?action=view&user_id=' . $result['user_id'] . '">
|
|
||||||
<td class="excluded_cell">
|
|
||||||
<label class="form_checkbox_container">
|
|
||||||
<input name="selected_users[]" value="' . $result['user_id'] . '" type="checkbox">
|
|
||||||
<span class="checkmark"></span>
|
|
||||||
</label>
|
|
||||||
</td>
|
|
||||||
<td>' . $result['user_id'] . '</td>
|
|
||||||
<td>' . htmlspecialchars($result['username']) . '</td>
|
|
||||||
<td>' . htmlspecialchars($result['email']) . '</td>
|
|
||||||
<td>' . ucwords($result['role']) . '</td>
|
|
||||||
<td>' . $result['created_at'] . '</td>
|
|
||||||
<td>' . $result['last_active'] . '</td>
|
|
||||||
<td>' . $result['is_active'] . '</td>
|
|
||||||
<td><img src="' . $_ENV['PROFILE_IMAGES_PQ_PATH'] . $result['profile_picture'] . '" class="card_profile_picture"></td>
|
|
||||||
</tr>
|
|
||||||
';
|
|
||||||
}
|
|
||||||
|
|
||||||
$display .= '
|
|
||||||
</table>
|
|
||||||
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
';
|
|
||||||
|
|
||||||
return $display;
|
|
||||||
}
|
|
||||||
|
|
||||||
function delete_users($ids)
|
function delete_users($ids)
|
||||||
{
|
{
|
||||||
foreach ($ids as $id) {
|
foreach ($ids as $id) {
|
||||||
|
|||||||
@@ -59,111 +59,6 @@ function article_ids_by_tag($tag)
|
|||||||
return $ids;
|
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 = '
|
|
||||||
<div class="article">
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<h1>' . $article['title'] . '</h1>
|
|
||||||
' . (isset($_COOKIE['user_id']) && $_COOKIE['user_id'] == $article['author_id'] ? '<a href="compose.php?article_id=' . $article_id . '"><i class="nf nf-fa-edit"></i></a>' : '') . '
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col_right">
|
|
||||||
<h5>Written by <a href="user.php?action=view&user_id=' . $author['user_id'] . '">' . $author['username'] . '</a></h5>
|
|
||||||
<p>Published on ' . $article['published_at'] . '<br>
|
|
||||||
Lasted edited on ' . $article['updated_at'] . '</p>
|
|
||||||
</div>
|
|
||||||
<div class="card_pic_box">
|
|
||||||
<img src="' . $_ENV['PROFILE_IMAGES_PQ_PATH'] . $author['profile_picture'] . '" class="card_profile_picture" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="line" style="margin-bottom: 15px;"></div>
|
|
||||||
<div class="article_content">
|
|
||||||
' . $article_content . '
|
|
||||||
</div>
|
|
||||||
</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.
|
|
||||||
*/
|
|
||||||
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 .= '<div class="tag_row">';
|
|
||||||
|
|
||||||
while ($row = $tags_results->fetch_assoc())
|
|
||||||
$tags_html .= '<a href="/articles.php?tag=' . $row['tag'] . '" class="tag">#' . $row['tag'] . '</a>';
|
|
||||||
|
|
||||||
$tags_html .= '</div>';
|
|
||||||
}
|
|
||||||
|
|
||||||
$author = exec_stmt('SELECT user_id, username, profile_picture FROM user WHERE user_id = ?', 'i', $article['author_id'])->fetch_assoc();
|
|
||||||
|
|
||||||
$card = '
|
|
||||||
<div class="article_card">
|
|
||||||
<div class="row">
|
|
||||||
<h4>' . $article['title'] . '</h4>
|
|
||||||
<div class="card_info_box">
|
|
||||||
<div class="col-right">
|
|
||||||
<a href="user.php?action=view&user_id=' . $author['user_id'] . '">Written by: ' . $author['username'] . '</a>
|
|
||||||
<small>Published: ' . $article['published_at'] . '</small>
|
|
||||||
<small>Updated: ' . $article['updated_at'] . '</small>
|
|
||||||
</div>
|
|
||||||
<div class="card_pic_box">
|
|
||||||
<img src="' . $_ENV['PROFILE_IMAGES_PQ_PATH'] . $author['profile_picture'] . '" class="card_profile_picture">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="line"></div>
|
|
||||||
<p>' . $article['excerpt'] . '</p>
|
|
||||||
<div class="row">
|
|
||||||
<a href="/articles.php?article_id=' . $article['article_id'] . '" class="button">Read More</a>
|
|
||||||
<div class="tag_box">' . $tags_html . '</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
';
|
|
||||||
|
|
||||||
return $card;
|
|
||||||
}
|
|
||||||
|
|
||||||
function create_article($author_id, $title, $excerpt, $tags, $markdown_file_contents)
|
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);
|
$id = exec_stmt('INSERT INTO article (author_id, title, excerpt, published_at) VALUES (?, ?, ?, CURRENT_TIMESTAMP)', 'iss', $author_id, $title, $excerpt);
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
session_start();
|
session_start();
|
||||||
header("Content-Security-Policy: default-src 'self'; font-src 'self' https://www.nerdfonts.com/assets/fonts/Symbols-2048-em%20Nerd%20Font%20Complete.woff2; style-src 'self' 'unsafe-inline' https://nerdfonts.com/assets/css/webfont.css https://www.nerdfonts.com/assets/css/webfont.css; script-src 'self'; img-src 'self';");
|
header("Content-Security-Policy: default-src 'self'; font-src 'self' https://www.nerdfonts.com/assets/fonts/Symbols-2048-em%20Nerd%20Font%20Complete.woff2; style-src 'self' 'unsafe-inline' https://nerdfonts.com/assets/css/webfont.css https://www.nerdfonts.com/assets/css/webfont.css; script-src 'self' 'unsafe-inline'; img-src 'self';");
|
||||||
|
|
||||||
// Initialize Composer.
|
// Initialize Composer.
|
||||||
require_once 'vendor/autoload.php';
|
require_once 'vendor/autoload.php';
|
||||||
|
|||||||
+1
-6
@@ -1,10 +1,8 @@
|
|||||||
const largeScreenMediaQuery = window.matchMedia("(min-width: 993px)"); // Example: 768px is a common breakpoint
|
|
||||||
const textarea = document.querySelector('textarea');
|
const textarea = document.querySelector('textarea');
|
||||||
const preview = document.getElementById('md_preview');
|
const preview = document.getElementById('md_preview');
|
||||||
|
|
||||||
if (largeScreenMediaQuery.matches) {
|
|
||||||
textarea.addEventListener('input', function() {
|
textarea.addEventListener('input', function() {
|
||||||
fetch('functions/preview.php', { // Create a separate preview.php file for real-time updates
|
fetch('functions/preview.php', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
@@ -16,6 +14,3 @@ if (largeScreenMediaQuery.matches) {
|
|||||||
preview.innerHTML = decodeURIComponent(data);
|
preview.innerHTML = decodeURIComponent(data);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
preview.style.display = 'none';
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once 'functions/init.php';
|
require_once 'functions/init.php';
|
||||||
|
|
||||||
require_once 'functions/functions.php';
|
require_once 'functions/functions.php';
|
||||||
include_once 'functions/account_functions.php';
|
include_once 'functions/account_functions.php';
|
||||||
|
|
||||||
|
// UI Components
|
||||||
|
foreach (glob('components/user/*.php') as $file)
|
||||||
|
require_once $file;
|
||||||
|
|
||||||
$msg = '';
|
$msg = '';
|
||||||
|
|
||||||
if (isset($_POST['form_id'])) {
|
if (isset($_POST['form_id'])) {
|
||||||
@@ -86,13 +89,19 @@ if (isset($_POST['form_id'])) {
|
|||||||
|
|
||||||
include_once 'components/head.php';
|
include_once 'components/head.php';
|
||||||
|
|
||||||
if ($_GET['action'] == 'login')
|
switch ($_GET['view']) {
|
||||||
|
case 'login':
|
||||||
echo login_form(($msg ? $msg : ''));
|
echo login_form(($msg ? $msg : ''));
|
||||||
else if ($_GET['action'] == 'signup')
|
break;
|
||||||
|
case 'signup':
|
||||||
echo signup_form(($msg ? $msg : ''));
|
echo signup_form(($msg ? $msg : ''));
|
||||||
else if ($_GET['action'] == 'logout')
|
break;
|
||||||
|
case 'logout':
|
||||||
logout();
|
logout();
|
||||||
else if ($_GET['action'] == 'view' && isset($_GET['user_id']))
|
break;
|
||||||
echo user_view($_GET['user_id']);
|
case 'display':
|
||||||
|
echo (isset($_GET['user_id']) ? user_view($_GET['user_id']) : header('Location: .'));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
include_once 'components/foot.php';
|
include_once 'components/foot.php';
|
||||||
|
|||||||
Reference in New Issue
Block a user