Начат запил страницы отображающей пост

This commit is contained in:
Shr3dd3r 2024-04-27 20:47:41 +03:00
parent 62b7b68976
commit e538a76b09
9 changed files with 237 additions and 17 deletions

View File

@ -186,7 +186,7 @@ function Post_Create (
if ($s->execute() === false)
return new ReturnT(err_code: E_DBE_INSERTFAIL, err_desc: "failed to create post record in DB");
$result = true;
$result = $db->insert_id;
return new ReturnT(data: $result);
}
@ -199,10 +199,12 @@ function Post_Create (
* METHOD
* Create single publication
* Request fields:
* tags - list of tags, should be delimited by comma
* tags - list of tags, should be delimited by comma
* title - optional title for post
* Files fields:
* pic - id of file object in $_FILES variable
* pic - id of file object in $_FILES variable
* Return value:
* id - unique identifier of created post
*/
function Post_Create_Method (array $req, array $files): ReturnT {
global $Config, $LOGGED_IN, $THIS_USER;
@ -341,7 +343,7 @@ if (Utils_ThisFileIsRequested(__FILE__)) {
if ($result->IsError())
$result->ThrowJSONError();
else
JSON_ReturnData(["success" => $result->GetData()]);
JSON_ReturnData(["id" => $result->GetData()]);
}
?>

View File

@ -5,6 +5,7 @@
// Includes
if (isset($IS_FRONTEND) && $IS_FRONTEND) {
require_once("api/_config.php");
require_once("api/_auth.php");
require_once("api/_utils.php");
require_once("api/_input_checks.php");
@ -13,6 +14,7 @@ if (isset($IS_FRONTEND) && $IS_FRONTEND) {
require_once("api/user/index.php");
require_once("api/post/index.php");
} else {
require_once("../_config.php");
require_once("../_auth.php");
require_once("../_utils.php");
require_once("../_input_checks.php");

View File

@ -41,12 +41,10 @@ function Post_AddView (int $id): ReturnT {
global $db;
$s = $db->prepare("UPDATE posts SET views = views + 1 WHERE id = ?");
$s->bind_param("s", $id);
$s->execute();
$d = $s->get_result()->fetch_assoc();
$s->bind_param("i", $id);
if (!(bool)$d)
return new ReturnT(err_code: E_UIN_WRONGID, err_desc: "failed to increment number of views");
if (!$s->execute())
return new ReturnT(err_code: E_DBE_UNKNOWN, err_desc: "failed to execute statement");
return new ReturnT(data: true);
}

View File

@ -3,4 +3,4 @@
Restrict access to files:
- Any file from `api` directory with prepended `_`
- `config.json`
- `config.json`

View File

@ -26,10 +26,10 @@ if (isset($_POST) && $_POST) {
$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: .");
} else { // All OK
header("Location: ./?do=view_post&id=" + strval($result->GetData()));
exit();
} TODO: redirect to page with new post */
}
} else {
NTFY_AddNotice("You must supply image and tags for post");
}

View File

@ -174,7 +174,6 @@ NTFY_EchoAllNotices();
} else {
echo "<h2 style=\"color: gray; font-style: italic;\">Nothing found!</h2>";
}
// TODO: pages
?>
</div>
</div>

View File

@ -0,0 +1,106 @@
<?php
// View post by ID
// Includes
// API
require_once("api/post/index.php");
require_once("api/comments/index.php");
// Markup includes
require_once("front/pages/main_nav.php");
require_once("front/notifications.php");
// Processing request
$reqResult = Post_GetByID_Method($_GET);
$postData = null;
if ($reqResult->IsError()) { // Something happened, very likely that post is not found
header("Location: .");
exit();
} else {
$postData = $reqResult->GetData();
}
NTFY_EchoAllNotices();
?>
<div class="visualbox">
<div class="postviewer">
<div class="stats">
<div title="Positive votes">
<img src="front/images/plus.png" alt="Positive votes icon">
<p><?php echo $postData["votes_up"]; ?></p>
</div>
<div title="Negative votes">
<img src="front/images/minus.png" alt="Negative votes icon">
<p><?php echo $postData["votes_down"]; ?></p>
</div>
<div title="Views count">
<img src="front/images/eye.png" alt="Views count icon">
<p><?php echo $postData["views"]; ?></p>
</div>
<!--TODO: reset button for moderators-->
</div>
<div class="picture">
<?php
echo "<img src=\"" . $postData["pic_path"] . "\" alt=\"" . $postData["tags"] . "\" title=\"" . $postData["tags"] . "\">\n";
?>
</div>
<div class="tags">
<ul>
<?php
$tagsArr = explode(",", $postData["tags"]);
foreach ($tagsArr as $tag)
echo "<li>$tag</li>\n";
?>
</ul>
</div>
<div class="comments">
<?php
if (!$postData["comments_enabled"]) {
echo "<p style=\"color: gray;\"><i>Comments disabled</i></p>\n";
} else { // TODO: this part down is untested (and incomplete), so beware
$reqResult = Comments_GetSectionRange_Method(array("id" => $postData["comment_section_id"]));
if ($reqResult->IsError()) {
echo "<p style=\"color: gray;\"><i>Can't fetch comments</i></p>\n";
} else {
$commentsList = $reqResult->GetData();
$commentsAmount = count($commentsList);
echo "<p>Comments: " . strval($commentsAmount) . "</p>\n";
foreach ($commentsList as $commentData) { // TODO
echo "<div class=\"entry\">\n";
echo "<div class=\"meta\">\n";
echo "<img src=\"front/images/pfp_placeholder.png\" alt=\"Guy's pfp\">\n";
echo "<p>\n";
echo strval($commentData["created_at"]) . "<br>\n"; //"04/04/2024 04:20<br>\n";
echo "<a href=\"./noway\">Guy</a>\n";
echo "</p>\n";
echo "</div>\n";
echo "<p>cool story bob</p>\n";
echo "</div>\n";
}
}
}
?>
<!--
<p>Comments: 54</p>
<div class="entry">
<div class="meta">
<img src="front/images/pfp_placeholder.png" alt="Guy's pfp">
<p>
04/04/2024 04:20<br>
<a href="./noway">Guy</a>
</p>
</div>
<p>cool story bob</p>
</div>
-->
</div>
</div>
</div>

View File

@ -27,6 +27,7 @@ nav.main ul {
margin-right: 10px;
padding: 7px;
backdrop-filter: blur(6px);
background-color: #094e5970;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
box-shadow: 0 0 5px #000;
@ -34,8 +35,8 @@ nav.main ul {
text-align: center;
display: flex;
flex-flow: row wrap;
justify-content: space-around;
flex-flow: row wrap;
justify-content: space-around;
}
nav.main ul li {
@ -154,7 +155,6 @@ div.postsearchcolumn form input[type="text"] {
display: inline-block;
}
div.postsearchcolumn form input[type="submit"] {
border-top-left-radius: 0px;
border-bottom-left-radius: 0px;
@ -217,3 +217,109 @@ div.postlist a.entry div.stats p {
div.postlist a.entry:hover div.stats p {
color: #49f49f;
}
/* Post viewer */
div.postviewer div.stats {
margin-bottom: 0.5em;
}
div.postviewer div.stats * {
display: inline-block;
}
div.postviewer div.stats div {
margin-right: 1em;
}
div.postviewer div.stats img {
width: 1em;
height: 1em;
}
div.postviewer div.picture {
background-color: #aaa3;
border-radius: 3px;
text-align: center;
overflow: clip;
}
div.postviewer div.picture img {
max-width: 100%;
min-width: 50px;
vertical-align: center;
margin-bottom: -4.5px;
}
div.postviewer div.tags {
/* background-color: #aaa3;
background-color: #0002;
border: 2px solid #aaa7;
border-bottom: 2px solid #aaa7;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px; */
}
div.postviewer div.tags ul {
text-align: center;
padding: 0 0 4px 0;
margin: 0;
}
div.postviewer div.tags ul li {
background-color: #009049a0;
color: #00c07c;
text-shadow: 0 0 2px #000c, 0 0 2px #000c;
box-shadow: 0 0 3px #0005;
border-radius: 2px;
padding: 4px;
margin: 4px 0 0 0;
display: inline-block;
transition: all 0.2s;
cursor: default;
}
div.postviewer div.tags ul li:hover {
color: #49f49f;
box-shadow: 0 0 5px #0007;
}
div.postviewer div.comments {}
div.postviewer div.comments p {
margin: 8px 0 8px 0;
}
div.postviewer div.comments div.entry {
margin-top: 8px;
padding: 5px;
border: 1px solid #009049;
border-radius: 3px;
align-items: center;
}
div.postviewer div.comments div.entry p {
display: inline-block;
vertical-align: top;
margin: 0 0 0 0;
}
div.postviewer div.comments div.entry div.meta {
display: inline-block;
width: 12%;
text-align: center;
border-right: 1px solid #009049;
}
div.postviewer div.comments div.entry div.meta img {
display: inline-block;
vertical-align: middle;
width: 64px;
height: 64px;
margin: 0 8px 0 0;
}
div.postviewer div.comments div.entry div.meta p {
display: inline-block;
vertical-align: top;
}

View File

@ -26,6 +26,13 @@ else
// Picking current page
switch ($PICKED_PAGE) {
// Direct-link pages
// Post viewing page
case "view_post":
$PAGE_TITLE = "Post #" . $_GET["id"]; // NOTICE: not good
$PAGE_STYLE = "front/styles/main.css";
$PAGE_FILE = "front/pages/view_post/page.php";
break;
// Available-on-login pages
// Post creation page
case "new_post":