World shittest gallery implementation 😳

This commit is contained in:
Michał 2022-09-23 23:02:59 +00:00
parent 6d3012a4f7
commit e19bab45cd
7 changed files with 273 additions and 19 deletions

View file

@ -25,9 +25,9 @@ if (isset($_POST['group_submit'])) {
if ($stmt = mysqli_prepare($conn, $sql)) {
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "i", $param_user_id);
$param_user_id = $_POST['group_id'];
$stmt->execute();
$query = $stmt->get_result();
@ -47,7 +47,9 @@ if (isset($_POST['group_submit'])) {
?>
<script>
sniffleAdd('Success!!!', 'Updates the image group! Redirecting.... soon', 'var(--green)', 'assets/icons/check.svg');
setTimeout(function(){window.location.href = "group.php?id=<?php echo $_POST['group_id']; ?>";}, 2000);
setTimeout(function() {
window.location.href = "group.php?id=<?php echo $_POST['group_id']; ?>";
}, 2000);
</script>
<?php
} else {
@ -67,3 +69,75 @@ if (isset($_POST['group_submit'])) {
}
}
}
/*
|-------------------------------------------------------------
| Edit Description
|-------------------------------------------------------------
| This script took probably over 24hours to write, mostly
| because of my stupidity. But it (mostly) works now which is
| good. Reason for all the includes and session_start is due
| to the need of checking if the person owns the image. If this
| check is not done, someone could come by and just edit the
| Jquery code on the front-end and change the image ID. Which
| isnt too great :p
|-------------------------------------------------------------
*/
if (isset($_POST['title_submit'])) {
$sql = "SELECT author FROM groups WHERE id= ?";
if ($stmt = mysqli_prepare($conn, $sql)) {
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "i", $param_user_id);
$param_user_id = $_POST['group_id'];
$stmt->execute();
$query = $stmt->get_result();
if ($_SESSION['id'] == $query || $user_info->is_admin($conn, $_SESSION['id'])) {
// getting ready forSQL asky asky
$sql = "UPDATE groups SET group_name = ? WHERE id = ?";
// Checking if databse is doing ok
if ($stmt = mysqli_prepare($conn, $sql)) {
mysqli_stmt_bind_param($stmt, "si", $param_title, $param_id);
// Setting parameters
$param_title = $_POST['group_title'];
$param_id = $_POST['group_id'];
// Attempt to execute the prepared statement
if (mysqli_stmt_execute($stmt)) {
?>
<script>
sniffleAdd('Success!!!', 'The title has been updated successfully! You may need to refresh the page to see the new information.', 'var(--green)', 'assets/icons/check.svg');
flyoutClose();
</script>
<?php
} else {
?>
<script>
sniffleAdd('Error :c', 'An error occured on the servers', 'var(--red)', 'assets/icons/cross.svg');
flyoutClose();
</script>
<?php
}
} else {
?>
<script>
sniffleAdd('Error :c', 'An error occured on the servers', 'var(--red)', 'assets/icons/cross.svg');
flyoutClose();
</script>
<?php
}
} else {
?>
<script>
sniffleAdd('Denied', 'It seems that you do not have the right permitions to edit this image.', 'var(--red)', 'assets/icons/cross.svg');
flyoutClose();
</script>
<?php
}
}
}

View file

@ -24,7 +24,7 @@
"Eat hotchip and lie"
],
"license":"GPL 3.0",
"version": "22.09.22",
"version": "22.09.23",
"user_name": "[your name]",
"is_testing": "true",
"upload_max": "32"

View file

@ -622,6 +622,56 @@ nav .btn {
outline: #8C977D solid 0.3rem;
}
.group-name {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
transition: opacity 0.1s cubic-bezier(0.19, 1, 0.22, 1);
z-index: 6;
opacity: 0;
font-size: 17px;
}
.group-name h1,
.group-name h2,
.group-name h3,
.group-name h4,
.group-name h5 {
font-family: "Lexend Deca", sans-serif;
text-rendering: optimizeLegibility;
}
.group-name p,
.group-name a,
.group-name button,
.group-name input {
font-family: "Secular One", sans-serif;
text-rendering: optimizeLegibility;
}
.gallery-group {
width: 100%;
height: 100%;
top: 0;
bottom: 0;
left: 0;
right: 0;
position: absolute;
z-index: 5;
}
.group-item:hover .gallery-group {
-webkit-backdrop-filter: brightness(0.5);
backdrop-filter: brightness(0.5);
}
.group-item:hover .nsfw-warning > * {
display: none;
}
.group-item:hover .group-name {
opacity: 1;
}
/*
|-------------------------------------------------------------
| profile

View file

@ -412,7 +412,48 @@
.selectedImage {
outline: $page-accent solid 0.3rem;
}
.group-name {
@include defaultFont();
margin: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
transition: opacity 0.1s cubic-bezier(.19, 1, .22, 1);
z-index: 6;
opacity: 0;
font-size: 17px;
}
.gallery-group {
width: 100%;
height: 100%;
top: 0;
bottom: 0;
left: 0;
right: 0;
position: absolute;
z-index: 5;
}
.group-item:hover {
& .gallery-group {
backdrop-filter: brightness(0.5);
}
& .nsfw-warning > * {
display: none;
}
}
.group-item:hover .group-name {
opacity: 1;
}
/*
|-------------------------------------------------------------
| profile

View file

@ -36,14 +36,37 @@
$group = mysqli_fetch_array($query);
$image_list = explode(" ", $group['image_list']);
$image_list = array_reverse(explode(" ", $group['image_list']));
}
}
?>
<h2><?php echo $group['group_name']; ?></h2>
<p>By: <?php echo $group['author']; ?></p>
<p>Made on: <?php echo $group['created_at']; ?></p>
<p>Updated on: <?php echo $group['last_modified']; ?></p>
<?php
$user = $user_info->get_user_info($conn, $group['author']);
if (isset($user['username'])) {
echo "<p>By: ".$user['username']."</p>";
} else {
echo "<p>By: Deleted User</p>";
}
$upload_time = new DateTime($group['created_on']);
echo "<p id='updateTime'>Created at: ".$upload_time->format('d/m/Y H:i:s T')."</p>";
?>
<script>
// Updating time to Viewers local
var updateDate = new Date('<?php echo $upload_time->format('m/d/Y H:i:s T'); ?>');
var format = {year: 'numeric',
month: 'short',
day: 'numeric'
};
updateDate = updateDate.toLocaleDateString('en-GB', format);
$("#updateTime").html("Created at: "+updateDate);
</script>
<p>Last Modified: <?php echo $diff->time($group['last_modified']); ?></p>
<?php
if ($_SESSION['id'] == $group['author'] || $user_info->is_admin($conn, $_SESSION['id'])) {
$privilaged = True;
@ -54,7 +77,33 @@
if (isset($_GET['mode']) && $_GET['mode'] == "edit") {
if (!$privilaged) header("Location: group.php?id=".$_GET['id']);
echo "<button class='btn btn-bad'>Delete Group</button>";
echo "<button class='btn btn-bad'>Delete</button>";
?>
<button id='editTitle' class='btn btn-bad'>Update title</button>
<script>
$('#editTitle').click(function() {
var header = "Enter new Description/Alt";
var description = "Newwww photo group name!";
var actionBox = "<form id='titleForm' action='app/image/edit_description.php' method='POST'>\
<input id='titleText' class='btn btn-neutral' type='text' placeholder='New title'>\
<button id='titleSubmit' class='btn btn-bad' type='submit'><img class='svg' src='assets/icons/edit.svg'>Update title</button>\
</form>";
flyoutShow(header, description, actionBox);
$("#titleForm").submit(function(event) {
event.preventDefault();
var titleText = $("#titleText").val();
var titleSubmit = $("#titleSubmit").val();
$("#sniffle").load("app/image/group.php", {
group_id: <?php echo $_GET['id']; ?>,
group_title: titleText,
title_submit: titleSubmit
});
});
});
</script>
<?php
$image_request = mysqli_query($conn, "SELECT * FROM images");
echo "<form id='groupForm'>";
@ -65,9 +114,9 @@
echo "<input style='display: none;' type='checkbox' id='".$image['id']."' name='".$image['id']."'/>";
}
}
echo "<button id='groupSubmit' class='btn btn-good' type='submit'>Save Group</button></form>";
echo "<button id='groupSubmit' class='btn btn-good' type='submit'>Update Images</button></form>";
echo "<a href='group.php?id=".$_GET['id']."' class='btn btn-neutral'>Cancel</a>";
echo "<a href='group.php?id=".$_GET['id']."' class='btn btn-neutral'>Back</a>";
} else {
if ($privilaged) echo "<a href='group.php?id=".$_GET['id']."&mode=edit' class='btn btn-neutral'>Edit</a>";
}

View file

@ -327,13 +327,13 @@
</script>
<!--
|-------------------------------------------------------------
| Edit Description
|-------------------------------------------------------------
| Most people reading through the code will probably say how
| shit it is. YOU HAVE NO FUCKING CLUE HOW LONG THIS TOOK ME
| TO FIGURE OUT. i hate js.
|-------------------------------------------------------------
|-------------------------------------------------------------
| Edit Description
|-------------------------------------------------------------
| Most people reading through the code will probably say how
| shit it is. YOU HAVE NO FUCKING CLUE HOW LONG THIS TOOK ME
| TO FIGURE OUT. i hate js.
|-------------------------------------------------------------
-->
<button id='descriptionButton' class='btn btn-bad'><img class='svg' src='assets/icons/edit.svg'>Edit description</button>
<script>

View file

@ -1,4 +1,10 @@
<?php require_once __DIR__."/app/required.php"; ?>
<?php
require_once __DIR__."/app/required.php";
use App\Image;
$image_info = new Image;
?>
<!DOCTYPE html>
<html>
@ -48,6 +54,40 @@
?>
</div>
<div class="gallery-root">
<?php
// Reading images from table
$group_list = mysqli_query($conn, "SELECT * FROM groups ORDER BY id DESC");
foreach ($group_list as $group) {
$image_list = array_reverse(explode(" ", $group['image_list']));
$image = $image_info->get_image_info($conn, $image_list[array_rand($image_list, 1)]);
// Getting thumbnail
if (file_exists("images/thumbnails/".$image['imagename'])) {
$image_path = "images/thumbnails/".$image['imagename'];
} else {
$image_path = "images/".$image['imagename'];
}
// Check for NSFW tag
if (str_contains($image['tags'], "nsfw")) {
echo "<div class='gallery-item group-item'>
<a href='group.php?id=".$group['id']."' class='nsfw-warning gallery-group'><img class='svg' src='assets/icons/warning_red.svg'><span>NSFW</span></a>
<a href='group.php?id=".$group['id']."'><img class='gallery-image nsfw-blur' loading='lazy' src='".$image_path."' id='".$group['id']."'></a>
<p class='group-name'>".$group['group_name']."</p>
</div>";
} else {
echo "<div class='gallery-item group-item'>
<a href='group.php?id=".$group['id']."' class='gallery-group'></a>
<a href='group.php?id=".$group['id']."'><img class='gallery-image' loading='lazy' src='".$image_path."' id='".$group['id']."'></a>
<p class='group-name'>".$group['group_name']."</p>
</div>";
}
}
?>
</div>
<div class="gallery-root">
<?php
// Reading images from table