From 6407669a5ab0a8da8787a6a6b6b50e6ef349ecf1 Mon Sep 17 00:00:00 2001 From: Fluffy-Bean Date: Wed, 5 Oct 2022 12:47:05 +0000 Subject: [PATCH] Removing unessesary if statements and cleanup --- account.php | 158 ++++++------ app/account/account.php | 4 +- app/app.php | 51 ++-- app/settings/manifest.json | 2 +- group.php | 194 +++++++------- image.php | 502 +++++++++++++++---------------------- index.php | 8 + password-reset.php | 38 +-- profile.php | 91 +++---- upload.php | 34 ++- 10 files changed, 489 insertions(+), 593 deletions(-) diff --git a/account.php b/account.php index 31b9fe5..527cdb2 100644 --- a/account.php +++ b/account.php @@ -1,13 +1,13 @@ get_user_info($conn, $_SESSION['id']); ?> @@ -15,10 +15,10 @@ - + - + is_loggedin()) { @@ -43,35 +43,37 @@ event.preventDefault(); // Check if image avalible var file = $("#image").val(); - if (file != "") { - // Make form - var formData = new FormData(); - // Get image - var image_data = $("#image").prop("files")[0]; - formData.append("image", image_data); - // Submit data - var submit = $("#pfpSubmit").val(); - formData.append("pfp_submit", submit); - - // Upload the information - $.ajax({ - url: 'app/account/account.php', - type: 'post', - data: formData, - contentType: false, - processData: false, - success: function(response) { - $("#newSniff").html(response); - } - }); - - // Empty values - $("#image").val(""); - $("#submit").val(""); - } else { + if (file == "") { sniffleAdd('Gwha!', 'Pls provide image', 'var(--warning)', 'assets/icons/file-search.svg'); + return; } + + // Make form + var formData = new FormData(); + + // Get image + var image_data = $("#image").prop("files")[0]; + formData.append("image", image_data); + // Submit data + var submit = $("#pfpSubmit").val(); + formData.append("pfp_submit", submit); + + // Upload the information + $.ajax({ + url: 'app/account/account.php', + type: 'post', + data: formData, + contentType: false, + processData: false, + success: function(response) { + $("#newSniff").html(response); + } + }); + + // Empty values + $("#image").val(""); + $("#submit").val(""); }); @@ -89,18 +91,18 @@ "; + } elseif (empty($image_list)) { + echo "
+

Nothing here!

+

There are no images in the group, add some!

+
"; + } else { + echo ""; + } + } else { + echo " + echo ""; + } + ?> - + \ No newline at end of file diff --git a/image.php b/image.php index fc354b6..9f05330 100644 --- a/image.php +++ b/image.php @@ -1,143 +1,53 @@ get_image_info($conn, $_GET['id']); + if (empty($image) || !isset($image)) { + $_SESSION['err'] = "Image could not be found!"; + header("Location: index.php"); + } + + $image_path = "images/".$image['imagename']; + $image_alt = $image['alt']; + $image_colour = $make_stuff->get_image_colour($image_path); + + if (empty($image_colour)) $image_colour = "var(--bg)"; + ?> + + get_user_info($conn, $image['author']); ?> - + get_image_info($conn, $_GET['id']); - - // Check if image is avalible - if (!empty($image['imagename']) && isset($image['imagename'])) { - $image_present = True; - } else { - ?> - - - - get_user_info($conn, $image['author']); - - if (isset($user['username'])) { - $image_author = $user['username']; - } else { - $image_author = "Deleted User"; - } - } else { - $image_author = "No author"; - } - - /* - |------------------------------------------------------------- - | Check if image path is good - |------------------------------------------------------------- - */ - if (isset($image['imagename'])) { - $image_path = "images/".$image['imagename']; - $image_alt = $image['alt']; - - $image_colour = $make_stuff->get_image_colour($image_path); - if (!empty($image_colour)) { - $image_colour = $image_colour; - } else { - $image_colour = "var(--bg)"; - } - ?> - - image_privilage($image['author']) || $user_info->is_admin($conn, $_SESSION['id'])) { - $privilaged = True; - } else { - $privilaged = False; - } + include __DIR__."/assets/ui/nav.php"; echo "
@@ -146,13 +56,13 @@ if (is_file("images/previews/".$image['imagename'])) { echo "
- ".$image_alt." - + ".$image_alt." +
"; } else { echo "
- ".$image_alt." - + ".$image_alt." +
"; } @@ -180,22 +90,18 @@ }, 500); } -

Description

-

+ No description provided.

"; + } else { + echo "

".$image['description']."

"; + } + ?>
-

Details

@@ -203,9 +109,13 @@ Author: ".$image_author."

"; + if (isset($author['username'])) { + echo "

Author: ".$author['username']."

"; + } else { + echo "

Author: Deleted user

"; + } } else { - echo "

Author: ".$image_author."

"; + echo "

Author: ".$author['username']."

"; } // Image ID @@ -220,13 +130,8 @@ ?> @@ -280,186 +184,180 @@

Tags

- ".$tag."

"; - } else { - echo "

".$tag."

"; + ".$tag."

"; + } else { + echo "

".$tag."

"; + } } + } else { + echo "

No tags present

"; } - } else { - echo "

No tags present

"; - } ?>
- -
-

Danger zone

+ /* + |------------------------------------------------------------- + | Check if user is privilaged, + |------------------------------------------------------------- + | If yes, grant them access to the Danger zone, or "the place + | that can fuck things up" + |------------------------------------------------------------- + */ + if ($image_info->image_privilage($image['author']) || $user_info->is_admin($conn, $_SESSION['id'])) { + ?> + +
+

Danger zone

- - - - - - - - - - - - - - is_admin($conn, $_SESSION['id'])) { - ?> - + --> + - + + + + + + + + + is_admin($conn, $_SESSION['id'])) { + ?> + + + "; } - - /* - |------------------------------------------------------------- - | End of displaying all user info - |------------------------------------------------------------- - */ - } ?> - + \ No newline at end of file diff --git a/index.php b/index.php index 43c31e3..b7c4563 100644 --- a/index.php +++ b/index.php @@ -44,6 +44,14 @@ } } } + if (isset($_SESSION['err'])) { + ?> + + +is_loggedin() != true) { + header("location: account.php"); + } +?> - + - is_loggedin() != true) { - header("location: account.php"); - exit; - } - ?> +

Reset Password

@@ -39,9 +38,10 @@ - + \ No newline at end of file diff --git a/profile.php b/profile.php index 634707f..f6eed56 100644 --- a/profile.php +++ b/profile.php @@ -1,18 +1,21 @@ get_user_info($conn, $_GET['user']); + if (!isset($_GET['user']) || empty($_GET['user'])) header("Location: index.php"); + + $user = $user_info->get_user_info($conn, $_GET['user']); + if (empty($user) || !isset($user)) { + $_SESSION['err'] = "You have followed a broken link to a profile that does not exist!"; + header("Location: index.php"); + } $join_date = new DateTime($user['created_at']); ?> @@ -21,55 +24,45 @@ - + - +
"; + if (is_file("images/pfp/".$user['pfp_path'])) { + echo ""; - $pfp_colour = $make_stuff->get_image_colour("images/pfp/".$user['pfp_path']); - if (empty($pfp_colour)) $pfp_colour = "var(--bg-3)"; - ?> - - "; - } + $pfp_colour = $make_stuff->get_image_colour("images/pfp/".$user['pfp_path']); + if (empty($pfp_colour)) $pfp_colour = "var(--bg-3)"; ?> -

- is_admin($conn, $user['id'])) { - echo "Admin"; + -

Failed to load user info

"; + echo ""; } ?> +

+ is_admin($conn, $user['id'])) echo "Admin"; + ?> +

+
+

Member since: format('d/m/Y T'); ?>

+

+
- NSFW - -
"; + NSFW + +
"; } else { echo ""; } } @@ -128,9 +121,7 @@ diff --git a/upload.php b/upload.php index c9bd7a4..4d66c64 100644 --- a/upload.php +++ b/upload.php @@ -1,28 +1,24 @@ - +is_loggedin()) { + header("location: account.php"); + } +?> - + - is_loggedin()) { - ?> - - +

Upload image

@@ -42,8 +38,6 @@ const [file] = image.files if (file) { imagePreview.src = URL.createObjectURL(file); - } else { - imagePreview.src = "assets/no_image.png"; } } @@ -95,7 +89,7 @@ }); - + \ No newline at end of file