diff --git a/api/post/create.php b/api/post/create.php index 0b7a5b4..bf0b44a 100644 --- a/api/post/create.php +++ b/api/post/create.php @@ -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()]); } ?> \ No newline at end of file diff --git a/api/post/find.php b/api/post/find.php index 4adcd43..4581b3f 100644 --- a/api/post/find.php +++ b/api/post/find.php @@ -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"); diff --git a/api/post/index.php b/api/post/index.php index 9621bce..0474fc9 100644 --- a/api/post/index.php +++ b/api/post/index.php @@ -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); } diff --git a/docs/SERVER CONFIGURATION.md b/docs/SERVER CONFIGURATION.md index 073a85d..1342a06 100644 --- a/docs/SERVER CONFIGURATION.md +++ b/docs/SERVER CONFIGURATION.md @@ -3,4 +3,4 @@ Restrict access to files: - Any file from `api` directory with prepended `_` -- `config.json` \ No newline at end of file +- `config.json` diff --git a/front/pages/new_post/page.php b/front/pages/new_post/page.php index 2870f13..50eb4ae 100644 --- a/front/pages/new_post/page.php +++ b/front/pages/new_post/page.php @@ -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:
" . $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"); } diff --git a/front/pages/search_posts/page.php b/front/pages/search_posts/page.php index 1fc1bf8..066a407 100644 --- a/front/pages/search_posts/page.php +++ b/front/pages/search_posts/page.php @@ -174,7 +174,6 @@ NTFY_EchoAllNotices(); } else { echo "

Nothing found!

"; } - // TODO: pages ?> diff --git a/front/pages/view_post/page.php b/front/pages/view_post/page.php new file mode 100644 index 0000000..e7618ea --- /dev/null +++ b/front/pages/view_post/page.php @@ -0,0 +1,106 @@ +IsError()) { // Something happened, very likely that post is not found + header("Location: ."); + exit(); +} else { + $postData = $reqResult->GetData(); +} + + + +NTFY_EchoAllNotices(); + + + +?> +
+
+
+
+ Positive votes icon +

+
+
+ Negative votes icon +

+
+
+ Views count icon +

+
+ +
+
+ \n"; + ?> +
+
+
    + $tag\n"; + ?> +
+
+
+ Comments disabled

\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 "

Can't fetch comments

\n"; + } else { + $commentsList = $reqResult->GetData(); + $commentsAmount = count($commentsList); + echo "

Comments: " . strval($commentsAmount) . "

\n"; + foreach ($commentsList as $commentData) { // TODO + echo "
\n"; + echo "
\n"; + echo "\"Guy's\n"; + echo "

\n"; + echo strval($commentData["created_at"]) . "
\n"; //"04/04/2024 04:20
\n"; + echo "Guy\n"; + echo "

\n"; + echo "
\n"; + echo "

cool story bob

\n"; + echo "
\n"; + } + } + } + ?> + +
+
+
diff --git a/front/styles/main.css b/front/styles/main.css index fd735a0..7305937 100644 --- a/front/styles/main.css +++ b/front/styles/main.css @@ -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; +} diff --git a/index.php b/index.php index 6502f19..80cacb7 100644 --- a/index.php +++ b/index.php @@ -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":