Создание поста

Метод API для создания поста; страница фронта и стили для него; новый тип ошибки при неудачной загрузке файла; фикс функции проверки строки на соответствие кодировке ASCII; фикс парсинга тегов; умное создание превью (проверка на случай, если превью получилось больше оригинала); исправление функции сохранения изображения; фикс функции создания поста, которая взаимодействует с БД; добавлена проверка корректности подписи к посту; добавление новых пунктов в навигацию; небольшое улучшение QoL в плане конфига.
This commit is contained in:
2024-02-09 00:13:23 +03:00
parent de456dea0a
commit 705e8cd6a2
15 changed files with 321 additions and 85 deletions

View File

@@ -22,12 +22,16 @@ require_once("api/user/index.php");
<?php
// If user is logged in
if ($LOGGED_IN) {
// Showing user profile button
$res = User_GetInfoByID($THIS_USER);
if ($res->IsError())
$res->ThrowJSONError();
$uname = $res->GetData()["login"];
echo "<a class=\"useraccount\" title=\"Account page\" href=\"./?do=user_info&id=$THIS_USER\">$uname</a>";
echo "<a class=\"useraccount\" title=\"Account page\" href=\"./?do=user_info&id=$THIS_USER\">$uname</a>\n";
unset($res);
// Showing post creation button
echo "<a title=\"Create new post\" href=\"./?do=new_post\">New post</a>\n";
} else { // If user is NOT logged in
?>
<a title="Login in existing account" href="./?do=login">Login</a>

View File

@@ -2,6 +2,7 @@
// Login page
// Includes
require_once("api/user/login.php");
require_once("front/pages/main_nav.php");
@@ -34,7 +35,7 @@ NTFY_EchoAllNotices();
?>
<div class="visualbox">
<h1>Login</h1>
<form class="login" action="./?do=login" accept-charset="UTF-8" method="post">
<form class="basicform" action="./?do=login" accept-charset="UTF-8" method="post">
<div>
<label for="login">Username</label><br>
<input type="text" name="login" id="login" <?php if (isset($_POST["login"])) { echo "value=\"" . $_POST["login"] . "\""; } ?>>

View File

@@ -3,47 +3,51 @@
$MARKUP_CURRENT_PAGE = "class=\"current\"";
$MARKUP_CURRENT_PAGE_LOGIN = "";
$MARKUP_CURRENT_PAGE_REGISTER = "";
$MARKUP_CURRENT_PAGE_VIEWTAGS = "";
$MARKUP_CURRENT_PAGE_STATS = "";
if ($WHAT_PAGE_IS_CURRENT["login"])
$MARKUP_CURRENT_PAGE_LOGIN = $MARKUP_CURRENT_PAGE;
elseif ($WHAT_PAGE_IS_CURRENT["register"])
$MARKUP_CURRENT_PAGE_REGISTER = $MARKUP_CURRENT_PAGE;
elseif ($WHAT_PAGE_IS_CURRENT["view_tags"])
$MARKUP_CURRENT_PAGE_VIEWTAGS = $MARKUP_CURRENT_PAGE;
elseif ($WHAT_PAGE_IS_CURRENT["view_stats"])
$MARKUP_CURRENT_PAGE_STATS = $MARKUP_CURRENT_PAGE;
?>
<nav class="main">
<ul>
<li>
<p><a title="Main site page" href="./?do=main">Index</p></a>
<p><a title="Main site page" href="./?do=main">Main</p></a>
</li>
<span>|</span>
<li <?php echo $MARKUP_CURRENT_PAGE_LOGIN; ?>>
<?php
if ($LOGGED_IN) {
// Getting user nickname
$res = User_GetInfoByID($THIS_USER);
if ($res->IsError())
$res->ThrowJSONError();
$uname = $res->GetData()["login"];
?>
<li>
<p><a title="User page" href="./?do=user_info&amp;id=<?php echo $THIS_USER; ?>">Me (<?php echo $uname; ?>)</p></a>
</li>
<span>|</span>
<li>
<p><a title="Create new post" href="./?do=new_post">New post</p></a>
</li>
<?php
} else {
?>
<li>
<p><a title="Login in existing account" href="./?do=login">Login</p></a>
</li>
<span>|</span>
<li <?php echo $MARKUP_CURRENT_PAGE_REGISTER; ?>>
<li>
<p><a title="Create new account" href="./?do=register">Register</p></a>
</li>
<?php
}
?>
<span>|</span>
<li>
<p><a title="A paginated list of every post" href="./?do=search_posts">Posts</p></a>
</li>
<span>|</span>
<li <?php echo $MARKUP_CURRENT_PAGE_VIEWTAGS; ?>>
<li>
<p><a title="A paginated list of every tag" href="./?do=view_tags">Tags</p></a>
</li>
<span>|</span>
<li <?php echo $MARKUP_CURRENT_PAGE_STATS; ?>>
<li>
<p><a title="Statistics of current instance" href="./?do=view_stats">Stats</p></a>
</li>
<span>|</span>

View File

@@ -0,0 +1,61 @@
<?php
// Post creation page
// Includes
require_once("api/post/create.php");
require_once("front/pages/main_nav.php");
require_once("front/notifications.php");
// Redirecting to main page if not logged in
if (!$LOGGED_IN) {
header("Location: .");
exit();
}
// Processing POST-request
if (isset($_POST) && $_POST) {
if (isset($_POST["tags"]) && $_POST["tags"] && isset($_FILES["pic"])) {
if (isset($_POST["title"]) && !$_POST["title"])
unset($_POST["title"]);
$result = Post_Create_Method($_POST, $_FILES);
if ($result->IsError()) { // Something happened
NTFY_AddNotice("Failed to create post! Reason:<br>" . $result->GetError());
} /*else { // All OK
header("Location: .");
exit();
} TODO: redirect to page with new post */
} else {
NTFY_AddNotice("You must supply image and tags for post");
}
}
NTFY_EchoAllNotices();
?>
<div class="visualbox">
<h1>New post</h1>
<form class="basicform" action="./?do=new_post" accept-charset="UTF-8" method="post" enctype="multipart/form-data">
<div>
<label for="pic">Select image:</label><br>
<input type="file" name="pic" id="pic">
</div>
<div>
<label for="tags">Comma-separated tags list:</label><br>
<textarea placeholder="tag_1, tag_2, tag_3, ..., tag_N" name="tags" id="tags" style="width: 98%;" rows="1"><?php if (isset($_POST["tags"])) { echo $_POST["tags"]; } ?></textarea>
</div>
<div>
<label for="title">Post title:</label><br>
<textarea placeholder="Lorem ipsum dolor sit amet..." name="title" id="title" style="width: 98%;" rows="2"><?php if (isset($_POST["title"]) && !$_POST["title"]) { echo $_POST["title"]; } ?></textarea>
</div>
<div>
<input type="submit" value="Submit">
</div>
</form>
</div>

View File

@@ -50,7 +50,7 @@ NTFY_EchoAllNotices();
<?php
if ($REGISTRATION_IS_OPEN) {
?>
<form class="login" action="./?do=register" accept-charset="UTF-8" method="post">
<form class="basicform" action="./?do=register" accept-charset="UTF-8" method="post">
<div>
<label for="login">Your desired username:</label><br>
<input type="text" name="login" id="login" spellcheck="false" <?php if (isset($_POST["login"])) { echo "value=\"" . $_POST["login"] . "\""; } ?>>

View File

@@ -92,7 +92,7 @@ div.notification_success {
/* Input */
/* Text input */
input[type=text], input[type=password] {
input[type=text], input[type=password], textarea {
color: #00c07c;
background-color: transparent;
border: 2px solid #009049;
@@ -102,11 +102,11 @@ input[type=text], input[type=password] {
text-shadow: 0 0 6px black;
transition: all 0.25s;
}
input[type=text]:hover, input[type=password]:hover {
input[type=text]:hover, input[type=password]:hover, textarea:hover {
border: 2px solid transparent;
border-bottom: 2px solid #009049;
}
input[type=text]:focus, input[type=password]:focus {
input[type=text]:focus, input[type=password]:focus, textarea:focus {
border: 2px solid transparent;
border-bottom: 2px solid #49f49f;
outline: none;
@@ -139,3 +139,33 @@ input[type=submit]:focus {
input[type=checkbox] {
cursor: pointer;
}
/* File picker */
input[type=file] {
color: #00c07c;
text-shadow: 0 0 6px #000a;
font-family: Verdana, Sans-Serif;
font-size: 16px;
margin: 4px 0;
}
input[type=file]::file-selector-button {
background-color: transparent;
border: 2px solid #009049;
border-radius: 3px;
color: #00c07c;
text-shadow: 0 0 6px #000a;
font-family: Verdana, Sans-Serif;
font-size: 16px;
cursor: pointer;
transition: all 0.2s;
}
input[type=file]::file-selector-button:hover {
border: 2px solid transparent;
border-bottom: 2px solid #009049;
background-color: #009049a0;
color: #49f49f;
}
input[type=file]::file-selector-button:focus {
border: 2px solid #49f49f;
outline: none;
}

View File

@@ -32,12 +32,14 @@ nav.main ul {
box-shadow: 0 0 5px #000;
text-shadow: 0 0 2px black, 0 0 6px black;
text-align: center;
display: flex;
flex-flow: row wrap;
justify-content: space-around;
}
nav.main ul li {
display: inline-block;
margin-left: 2.5vw;
margin-right: 2.5vw;
}
nav.main ul li a {
@@ -90,15 +92,19 @@ td {
/* Other */
form.login div {
/* Basic form form login and registration */
form.basicform div {
margin-bottom: 14px;
}
form.login a {
form.basicform a {
font-size: 80%;
}
form.login label[for="tos_check"] {
/* Additionals for form */
form.basicform label[for="tos_check"] {
cursor: pointer;
}