From 8da2aff2656995b027608359d1ed557d386cbd63 Mon Sep 17 00:00:00 2001 From: Fluffy-Bean Date: Sun, 7 Aug 2022 12:57:13 +0100 Subject: [PATCH] AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA --- app/account/get_info.php | 16 +++ app/account/is_admin.php | 18 +++ app/account/login_status.php | 14 ++ app/format/string_to_tags.php | 18 +++ app/image/delete_image.php | 27 ++++ app/image/edit_author.php | 26 ++++ app/image/edit_description.php | 1 - app/image/edit_tags.php | 41 ++++++ app/image/get_image_info.php | 16 +++ app/image/image_privilage.php | 19 +++ app/server/conn.php | 2 +- app/server/secrete.php | 0 image.php | 235 +++++++++------------------------ index.php | 31 +---- ui/functions.php | 189 -------------------------- ui/required.php | 18 +-- 16 files changed, 270 insertions(+), 401 deletions(-) create mode 100644 app/account/get_info.php create mode 100644 app/account/is_admin.php create mode 100644 app/account/login_status.php create mode 100644 app/format/string_to_tags.php create mode 100644 app/image/get_image_info.php create mode 100644 app/image/image_privilage.php create mode 100644 app/server/secrete.php diff --git a/app/account/get_info.php b/app/account/get_info.php new file mode 100644 index 0000000..cd65e21 --- /dev/null +++ b/app/account/get_info.php @@ -0,0 +1,16 @@ +"); + } +} diff --git a/app/image/edit_author.php b/app/image/edit_author.php index e69de29..fb3874d 100644 --- a/app/image/edit_author.php +++ b/app/image/edit_author.php @@ -0,0 +1,26 @@ +/* + Author confirm +*/ +if (isset($_POST['author_confirm']) && is_admin($_SESSION['id'])) { + // Unset all the variables, needed by flyout + unset($header, $content, $action); + + // getting ready forSQL asky asky + $sql = "UPDATE swag_table SET author=? WHERE id=?"; + + // Checking if databse is doing ok + if ($stmt = mysqli_prepare($conn, $sql)) { + mysqli_stmt_bind_param($stmt, "si", $param_author, $param_id); + + // Setting parameters + $param_author = $_POST['update_author']; + $param_id = $image["id"]; + + // Attempt to execute the prepared statement + if (mysqli_stmt_execute($stmt)) { + header("Location:image.php?id=".$image["id"]."&update=success"); + } else { + header("Location:image.php?id=".$image["id"]."&update=error"); + } + } +} diff --git a/app/image/edit_description.php b/app/image/edit_description.php index 8a9a547..378fa2b 100644 --- a/app/image/edit_description.php +++ b/app/image/edit_description.php @@ -30,4 +30,3 @@ if (isset($_POST['submit'])) { } } } -?> diff --git a/app/image/edit_tags.php b/app/image/edit_tags.php index e69de29..7787578 100644 --- a/app/image/edit_tags.php +++ b/app/image/edit_tags.php @@ -0,0 +1,41 @@ +/* + Tags Confirm +*/ +if (isset($_POST['tags_confirm']) && $privilaged) { + // Unset all the variables, needed by flyout + unset($header, $content, $action); + + // Clean tags before adding + function clean($string) { + // Change to lowercase + $string = strtolower($string); + // Replace hyphens + $string = str_replace('-', '_', $string); + // Regex + $string = preg_replace('/[^A-Za-z0-9\_ ]/', '', $string); + // Return string + return preg_replace('/ +/', ' ', $string); + } + + // Clean input + $tags_string = tag_clean(trim($_POST['add_tags'])); + + // getting ready forSQL asky asky + $sql = "UPDATE swag_table SET tags=? WHERE id=?"; + + // Checking if databse is doing ok + if ($stmt = mysqli_prepare($conn, $sql)) { + mysqli_stmt_bind_param($stmt, "si", $param_tags, $param_id); + + // Setting parameters + $param_tags = $tags_string; + $param_id = $image["id"]; + + // Attempt to execute the prepared statement + if (mysqli_stmt_execute($stmt)) { + header("Location:image.php?id=".$image["id"]."&update=success"); + } else { + header("Location:image.php?id=".$image["id"]."&update=error"); + } + } +} diff --git a/app/image/get_image_info.php b/app/image/get_image_info.php new file mode 100644 index 0000000..b2b9fb6 --- /dev/null +++ b/app/image/get_image_info.php @@ -0,0 +1,16 @@ +connect_error) { - // Send notification that connection couldn't be made + echo ""; } diff --git a/app/server/secrete.php b/app/server/secrete.php new file mode 100644 index 0000000..e69de29 diff --git a/image.php b/image.php index 1a5b507..249dfcc 100644 --- a/image.php +++ b/image.php @@ -1,57 +1,10 @@ Could not find image with ID: ".$_GET['id']."

"; - - // Replacement "no image" image and description - $image_path = "assets/no_image.png"; - $image_alt = "No image could be found, sowwy"; + return "No information provided."; } -} else { - // No ID toast - //echo "

No ID present

"; - - // Replacement "no image" image and description - //$image_path = "assets/no_image.png"; - //$image_alt = "No image could be found, sowwy"; -} - - -/* - Get all user details - - This gets the user info from the image -*/ -if (isset($image['author'])) { - $user = get_user_info($conn, $image['author']); -} - -/* - Check user privilge - - This requires the user to be logged in or an admin -*/ -if (image_privilage($image['author']) || is_admin($_SESSION['id'])) { - $privilaged = True; -} else { - $privilaged = False; } ?> @@ -79,7 +32,63 @@ if (image_privilage($image['author']) || is_admin($_SESSION['id'])) { - + Could not find image with ID: ".$_GET['id']."

"; + + // Replacement "no image" image and description + $image_path = "assets/no_image.png"; + $image_alt = "No image could be found, sowwy"; + } + } else { + // No ID toast + //echo "

No ID present

"; + + // Replacement "no image" image and description + //$image_path = "assets/no_image.png"; + //$image_alt = "No image could be found, sowwy"; + } + + + /* + Get all user details + + This gets the user info from the image + */ + if (isset($image['author'])) { + $user = get_user_info($conn, $image['author']); + } + + /* + Check user privilge + + This requires the user to be logged in or an admin + */ + if (image_privilage($image['author']) || is_admin($_SESSION['id'])) { + $privilaged = True; + } else { + $privilaged = False; + } + + include"ui/nav.php"; ?> - "); - } - } - - /* - Tags Confirm - */ - if (isset($_POST['tags_confirm']) && $privilaged) { - // Unset all the variables, needed by flyout - unset($header, $content, $action); - - // Clean tags before adding - function clean($string) { - // Change to lowercase - $string = strtolower($string); - // Replace hyphens - $string = str_replace('-', '_', $string); - // Regex - $string = preg_replace('/[^A-Za-z0-9\_ ]/', '', $string); - // Return string - return preg_replace('/ +/', ' ', $string); - } - - // Clean input - $tags_string = tag_clean(trim($_POST['add_tags'])); - - // getting ready forSQL asky asky - $sql = "UPDATE swag_table SET tags=? WHERE id=?"; - - // Checking if databse is doing ok - if ($stmt = mysqli_prepare($conn, $sql)) { - mysqli_stmt_bind_param($stmt, "si", $param_tags, $param_id); - - // Setting parameters - $param_tags = $tags_string; - $param_id = $image["id"]; - - // Attempt to execute the prepared statement - if (mysqli_stmt_execute($stmt)) { - header("Location:image.php?id=".$image["id"]."&update=success"); - } else { - header("Location:image.php?id=".$image["id"]."&update=error"); - } - } - } - - /* - Description athor - */ - if (isset($_POST['author_flyout']) && is_admin($_SESSION['id'])) { - $header = "Who owns the image?????"; - $content = "Enter ID of image owner"; - $action = "
- - -
"; - - flyout($header, $content, $action); - } - /* - Author confirm - */ - if (isset($_POST['author_confirm']) && is_admin($_SESSION['id'])) { - // Unset all the variables, needed by flyout - unset($header, $content, $action); - - // getting ready forSQL asky asky - $sql = "UPDATE swag_table SET author=? WHERE id=?"; - - // Checking if databse is doing ok - if ($stmt = mysqli_prepare($conn, $sql)) { - mysqli_stmt_bind_param($stmt, "si", $param_author, $param_id); - - // Setting parameters - $param_author = $_POST['update_author']; - $param_id = $image["id"]; - - // Attempt to execute the prepared statement - if (mysqli_stmt_execute($stmt)) { - header("Location:image.php?id=".$image["id"]."&update=success"); - } else { - header("Location:image.php?id=".$image["id"]."&update=error"); - } - } - } - ?> -
- "; - ?> + ' src='' alt=''>
@@ -314,13 +208,12 @@ if (image_privilage($image['author']) || is_admin($_SESSION['id'])) { var header = "Enter new Description/Alt"; var description = "Whatcha gonna put in there 👀"; var actionBox = "
\ - \ - \ + \ + \
\
"; flyoutShow(header, description, actionBox); }); - $("#descriptionConfirm").submit(function(event) { event.preventDefault(); var descriptionInput = $("#descriptionInput").val(); diff --git a/index.php b/index.php index c6503c2..06e8d0f 100644 --- a/index.php +++ b/index.php @@ -43,35 +43,6 @@ } - - - - "; - - flyout($header, $content, $action); - } - /* - Search Confirm - */ - if (isset($_POST['search_confirm'])) { - // Unset all the variables, needed by flyout - unset($header, $content, $action); - - // Clean input - $tags_string = tag_clean(trim($_POST['search'])); - - header("Location:index.php?q=".$tags_string); - } - if (isset($_GET["q"])) { - echo "

Search results for: ".$_GET['q']."

"; - } - ?> -
".$welcome_message[array_rand($welcome_message, 1)]."

"; ?>
diff --git a/ui/functions.php b/ui/functions.php index e11239b..b3d9bbc 100644 --- a/ui/functions.php +++ b/ui/functions.php @@ -1,190 +1 @@ - At the bottom of the HTML document -*/ -function flyout($header, $content, $action) { - // Used for background dimming - echo "
"; - // Div Start - echo "
"; - - // Header for the flyout, must be included - if (isset($header) && !empty($header)) { - echo "

".$header."

"; - } else { - echo "

Header

"; - } - - // Flyout content, must be included!!!! - if (isset($content) && !empty($content)) { - echo "

".$content."

"; - } else { - echo "

Description

"; - } - - // Flyout button, not required so must need more information when added - if (isset($action) && !empty($action)) { - echo $action; - } - - // Exit button + Div End - echo " -
"; - - // Must be included with flyout.php - echo ""; -} - - -/* - Notification of an action done, takes in min 3 inputs: - - Text is the text that shows up on the notification - Takes in string input - - Level is the level of the notification - high is a good response or the colour green - low is a bad response or the colour red - default is a neutral response or the colour black/gray - - returns notification html including classes - - ===== Programmers note ============================== - I made this so I didn't have to remake the html - portion of the notification, it was annoying. - This also allows for expanding the system later on! - ===================================================== -*/ -function notify($text, $level) { - if ($level == "high") { - $text_string = "

".$text."

"; - } elseif ($level == "low") { - $text_string = "

".$text."

"; - } elseif ($level == "default") { - $text_string = "

".$text."

"; - } else { - $text_string = "

".$text."

"; - } - - return $text_string; -} diff --git a/ui/required.php b/ui/required.php index 838f2b4..1a72f8d 100644 --- a/ui/required.php +++ b/ui/required.php @@ -25,18 +25,18 @@ if (is_file("index.php")) { include $root_dir."app/server/conn.php"; /* - Include functions - - Maybe I should put all the functions in this file? Dunno + Add functions */ -include $root_dir."ui/functions.php"; +include $root_dir."app/account/get_info.php"; +include $root_dir."app/account/is_admin.php"; +include $root_dir."app/account/login_status.php"; -/* - Notification system +include $root_dir."app/format/string_to_tags.php"; - This is the notification system used by the website. Probably a little too much for what its used for -*/ -echo "
"; +include $root_dir."app/image/get_image_info.php"; +include $root_dir."app/image/image_privilage.php"; + +include $root_dir."app/server/secrete.php"; ?>