From 23c54d6bd716351679eb76ad8db83c0096eb557c Mon Sep 17 00:00:00 2001 From: Fluffy-Bean Date: Sun, 31 Jul 2022 12:50:52 +0100 Subject: [PATCH] Added search function --- assets/icons/binoculars.svg | 1 + css/master.css | 2 + image.php | 17 +++++-- index.php | 90 ++++++++++++++++++++++++++++++++----- scripts/flyout.js | 2 +- ui/flyout.php | 2 +- ui/header.php | 2 + 7 files changed, 101 insertions(+), 15 deletions(-) create mode 100644 assets/icons/binoculars.svg diff --git a/assets/icons/binoculars.svg b/assets/icons/binoculars.svg new file mode 100644 index 0000000..cd7ac61 --- /dev/null +++ b/assets/icons/binoculars.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/css/master.css b/css/master.css index 110beee..207035b 100644 --- a/css/master.css +++ b/css/master.css @@ -369,6 +369,8 @@ form * { border: none; border-radius: var(--rad); + + transition: outline 0.1s cubic-bezier(.19,1,.22,1); } .btn:hover { outline: var(--white) 3px solid; diff --git a/image.php b/image.php index 0645e91..84bdd43 100644 --- a/image.php +++ b/image.php @@ -61,8 +61,19 @@ if (isset($image['author'])) { - "; ?> - "; ?> + + + + "; + + list($meta_width, $meta_height) = getimagesize($image_path); + echo ""; + echo ""; + + echo ""?> + + + Successfully deleted image: ".$_GET['id']."

"; @@ -22,6 +25,45 @@ if ($_GET["login"] == "success") { echo "

O hi ".$_SESSION['username']."

"; } + + // Show search + if ($_GET["srch"] == "show") { + $header = "Search for a tags!"; + $content = "Here you can search for funnies! Like raccoons!!!!!!!!!"; + $action = "
+ + +
"; + + flyout($header, $content, $action); + } + /* + Search Confirm + */ + if (isset($_POST['search_confirm'])) { + // 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 = clean(trim($_POST['search'])); + + header("Location:https://superdupersecteteuploadtest.fluffybean.gay?q=".$tags_string); + } + if (isset($_GET["q"])) { + echo "

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

"; + } ?>
@@ -47,22 +89,50 @@ $image_request = mysqli_query($conn, "SELECT * FROM swag_table"); while ($image = mysqli_fetch_array($image_request)) { - // Getting thumbnail - if (file_exists("images/thumbnails/".$image['imagename'])) { - $image_path = "images/thumbnails/".$image['imagename']; - } else { - $image_path = "images/".$image['imagename']; - } + // If search is set + if (isset($_GET['q']) && !empty($_GET['q'])) { + // Make search into an array + $search_array = explode(" ", $_GET['q']); - // Image loading - echo ""; + // Get images tags for comparing + $image_tag_array = explode(" ", $image['tags']); + + // Compare arrays + $compare_results = array_intersect($image_tag_array, $search_array); + if (count($compare_results) > 0) { + // Getting thumbnail + if (file_exists("images/thumbnails/".$image['imagename'])) { + $image_path = "images/thumbnails/".$image['imagename']; + } else { + $image_path = "images/".$image['imagename']; + } + + // Image loading + echo ""; + } + } else { + // Getting thumbnail + if (file_exists("images/thumbnails/".$image['imagename'])) { + $image_path = "images/thumbnails/".$image['imagename']; + } else { + $image_path = "images/".$image['imagename']; + } + + // Image loading + echo ""; + } } ?>
"; + include("ui/top.html"); include("ui/footer.php"); ?> diff --git a/scripts/flyout.js b/scripts/flyout.js index bc67a99..d9a3a70 100644 --- a/scripts/flyout.js +++ b/scripts/flyout.js @@ -1,4 +1,4 @@ -console.log(" . . /|/| . . . . . . . \n .. /0 0 \\ . . . . . .. \n (III% . \\________, . . \n .. .\\_, .%###%/ \\'\\,.. \n . . . .||#####| |'\\ \\. \n .. . . ||. . .|/. .\\V. \n . . . .|| . . || . . . \n .. . . ||. . .||. . .. \n . . . .|| . . || . . . \n .. . . ||. . .||. . .. \n . . . .|| . . || . . . \n .. . . ||. . .||. . .. \n . . . .|| . . || . . . \n .. . . ||. . .||. . .. \n . . . .|| . . || . . . \n .. . . ||. . .||. . .. \n . . . .|| . . || . . . \n .. . . ||. . .||. . .. \n . . . .|| . . || . . . \n .. . . ||. . .||. . .. \n . . . .|| . . || . . . \n .. . . ||. . .||. . .. \n . . . cc/ . .cc/ . . .") +console.log(" . . /|/| . . . . . . . \n .. /0 0 \\ . . . . . .. \n (III% . \\________, . . \n .. .\\_, .%###%/ \\'\\,.. \n . . . .||#####| |'\\ \\. \n .. . . ||. . .|/. .\\V. \n . . . .|| . . || . . . \n .. . . ||. . .||. . .. \n . . . .|| . . || . . . \n .. . . ||. . .||. . .. \n . . . .|| . . || . . . \n .. . . ||. . .||. . .. \n . . . .|| . . || . . . \n .. . . ||. . .||. . .. \n . . . .|| . . || . . . \n .. . . ||. . .||. . .. \n . . . .|| . . || . . . \n .. . . ||. . .||. . .. \n . . . .|| . . || . . . \n .. . . ||. . .||. . .. \n . . . .|| . . || . . . \n .. . . ||. . .||. . .. \n . . . cc/ . .cc/ . . ."); let show = document.querySelectorAll(".flyout-display"); let hide = document.querySelector(".flyout-close"); diff --git a/ui/flyout.php b/ui/flyout.php index ed41760..2310f19 100644 --- a/ui/flyout.php +++ b/ui/flyout.php @@ -19,7 +19,7 @@ function flyout($flyout_header, $flyout_content, $flyout_action) { } // Exit button + Div End - echo " + echo " "; } ?> diff --git a/ui/header.php b/ui/header.php index 9f316e8..c63da21 100644 --- a/ui/header.php +++ b/ui/header.php @@ -16,6 +16,8 @@ if (is_dir("assets/icons/")) { Home"; echo "
"; + echo "Search"; + echo "
"; if (isset($_SESSION["username"])) { echo "Upload";