2022-09-23 09:15:16 +00:00
< ? php
require_once __DIR__ . " /app/required.php " ;
use App\Account ;
use App\Image ;
use App\Diff ;
$image_info = new Image ;
$user_info = new Account ;
$diff = new Diff ();
?>
2022-09-21 13:02:38 +00:00
2022-07-21 14:53:04 +00:00
<! DOCTYPE html >
< html >
2022-08-15 10:56:05 +00:00
2022-07-21 14:53:04 +00:00
< head >
2022-09-21 13:37:45 +00:00
< ? php require_once __DIR__ . " /assets/ui/header.php " ; ?>
2022-07-21 14:53:04 +00:00
</ head >
2022-08-15 10:56:05 +00:00
2022-07-21 14:53:04 +00:00
< body >
2022-08-15 10:56:05 +00:00
< ? php
2022-09-21 13:37:45 +00:00
require_once __DIR__ . " /assets/ui/nav.php " ;
2022-09-21 13:02:38 +00:00
/*
|-------------------------------------------------------------
| Get image ID
|-------------------------------------------------------------
| Image ID should be written in the URL of the page as ? id = 69
| If ID cannot be obtained , give error . ID going here ^^
|-------------------------------------------------------------
*/
2022-09-23 09:15:16 +00:00
if ( isset ( $_GET [ 'id' ])) {
2022-09-21 13:02:38 +00:00
// Get all image info
$image = $image_info -> get_image_info ( $conn , $_GET [ 'id' ]);
// Check if image is avalible
2022-09-23 09:15:16 +00:00
if ( ! empty ( $image [ 'imagename' ]) && isset ( $image [ 'imagename' ])) {
2022-09-21 13:02:38 +00:00
$image_present = True ;
} else {
?>
< script >
sniffleAdd ( 'Woops' , 'Something happened, either image with the ID <?php echo $_GET[' id ']; ?> was deleted or never existed, either way it could not be found!' , 'var(--red)' , 'assets/icons/cross.svg' );
</ script >
< ? php
$image_present = False ;
}
2022-08-15 10:56:05 +00:00
} else {
2022-09-21 13:02:38 +00:00
?>
2022-09-22 12:43:22 +00:00
< script >
sniffleAdd ( 'Where is da image?' , 'The link you followed seems to be broken, or there was some other error, who knows!' , 'var(--red)' , 'assets/icons/cross.svg' );
</ script >
2022-09-12 14:15:16 +00:00
< ? php
2022-08-15 10:56:05 +00:00
$image_present = False ;
}
2022-09-21 13:02:38 +00:00
2022-08-15 10:56:05 +00:00
/*
2022-09-21 13:02:38 +00:00
|-------------------------------------------------------------
| Image verification
|-------------------------------------------------------------
| Doublechecking if all information on images exists , if yes
| display it , otherwise don ' t display at all or replace with
| blank or filler info
|-------------------------------------------------------------
2022-08-15 10:56:05 +00:00
*/
2022-09-21 13:02:38 +00:00
if ( $image_present ) {
/*
|-------------------------------------------------------------
| Check user details
|-------------------------------------------------------------
*/
if ( isset ( $image [ 'author' ])) {
// Get all information on the user
$user = $user_info -> get_user_info ( $conn , $image [ 'author' ]);
if ( isset ( $user [ 'username' ])) {
$image_author = $user [ 'username' ];
} else {
$image_author = " Deleted User " ;
}
} else {
$image_author = " No author " ;
}
2022-08-15 10:56:05 +00:00
2022-09-21 13:02:38 +00:00
/*
|-------------------------------------------------------------
| Check if image path is good
|-------------------------------------------------------------
*/
if ( isset ( $image [ 'imagename' ])) {
$image_path = " images/ " . $image [ 'imagename' ];
$image_alt = $image [ 'alt' ];
2022-08-15 10:56:05 +00:00
} else {
2022-09-21 13:02:38 +00:00
$image_path = " assets/no_image.png " ;
$image_alt = " No image could be found, sowwy " ;
2022-08-15 10:56:05 +00:00
}
2022-09-21 13:02:38 +00:00
/*
|-------------------------------------------------------------
| If description not set or empty , replace with filler
|-------------------------------------------------------------
*/
if ( ! isset ( $image_alt ) || empty ( $image_alt )) {
$image_alt = " No description avalible " ;
}
2022-08-15 10:56:05 +00:00
} else {
2022-09-21 13:02:38 +00:00
/*
|-------------------------------------------------------------
| Image was not present
|-------------------------------------------------------------
*/
2022-08-15 10:56:05 +00:00
$image_path = " assets/no_image.png " ;
$image_alt = " No image could be found, sowwy " ;
}
/*
2022-09-21 13:02:38 +00:00
|-------------------------------------------------------------
| Check user privilge
|-------------------------------------------------------------
2022-08-15 10:56:05 +00:00
*/
2022-09-21 13:02:38 +00:00
if ( $image_info -> image_privilage ( $image [ 'author' ]) || $user_info -> is_admin ( $conn , $_SESSION [ 'id' ])) {
$privilaged = True ;
} else {
$privilaged = False ;
}
2022-09-21 16:28:57 +00:00
echo " <div class='fullscreen-image'>
< button onclick = 'closeFullScreen()' >< img src = 'assets/icons/cross.svg' ></ button >
< img >
</ div > " ;
2022-09-21 13:02:38 +00:00
if ( is_file ( " images/previews/ " . $image [ 'imagename' ])) {
echo " <div class='image-container'>
2022-09-21 16:28:57 +00:00
< img class = 'image' id = '".$image[' id ']."' src = 'images/previews/".$image[' imagename ']."' alt = '".$image_alt."' >
< button class = 'preview-button' onclick = 'fullScreen()' >< img src = 'assets/icons/scan.svg' ></ button >
</ div > " ;
2022-09-21 13:02:38 +00:00
} else {
echo " <div class='image-container'>
2022-09-21 16:28:57 +00:00
< img class = 'image' id = '".$image[' id ']."' src = '".$image_path."' alt = '".$image_alt."' >
< button class = 'preview-button' onclick = 'fullScreen()' >< img src = 'assets/icons/scan.svg' ></ button >
</ div > " ;
2022-08-15 10:56:05 +00:00
}
2022-09-21 16:28:57 +00:00
?>
< script >
function fullScreen () {
document . querySelector ( " .preview-button " ) . style . display = " none " ;
2022-09-21 20:39:22 +00:00
document . querySelector ( " html " ) . style . overflow = " hidden " ;
2022-09-21 13:02:38 +00:00
2022-09-21 16:28:57 +00:00
document . querySelector ( " .fullscreen-image " ) . style . display = " block " ;
document . querySelector ( " .fullscreen-image > img " ) . src = " <?php echo $image_path ;?> " ;
setTimeout ( function (){
document . querySelector ( " .fullscreen-image " ) . style . opacity = 1 ;
2022-09-22 12:43:22 +00:00
}, 1 );
2022-09-21 16:28:57 +00:00
}
function closeFullScreen () {
document . querySelector ( " .preview-button " ) . style . display = " block " ;
2022-09-21 20:39:22 +00:00
document . querySelector ( " html " ) . style . overflow = " auto " ;
2022-09-21 16:28:57 +00:00
document . querySelector ( " .fullscreen-image " ) . style . opacity = 0 ;
setTimeout ( function (){
document . querySelector ( " .fullscreen-image " ) . style . display = " none " ;
}, 500 );
}
</ script >
< ? php
2022-09-21 13:02:38 +00:00
2022-08-15 10:56:05 +00:00
/*
2022-09-21 13:02:38 +00:00
|-------------------------------------------------------------
| Start of displaying all info on image
|-------------------------------------------------------------
2022-08-15 10:56:05 +00:00
*/
2022-09-21 13:02:38 +00:00
if ( $image_present ) {
2022-08-15 10:56:05 +00:00
?>
< div class = " image-description default-window " >
< h2 > Description </ h2 >
2022-09-13 13:24:48 +00:00
< p >< ? php echo htmlentities ( $image_alt , ENT_QUOTES ); ?> </p>
2022-08-15 10:56:05 +00:00
</ div >
2022-09-08 19:41:47 +00:00
< div class = " image-detail " >
2022-08-15 10:56:05 +00:00
< h2 > Details </ h2 >
2022-09-08 19:41:47 +00:00
< div >
< div >
< ? php
// User
2022-09-22 19:39:15 +00:00
if ( empty ( $image [ 'author' ])) {
echo " <p>Author: " . $image_author . " </p> " ;
2022-09-14 18:59:02 +00:00
} else {
2022-09-22 12:43:22 +00:00
echo " <p>Author: <a href='profile.php?user= " . $image [ 'author' ] . " ' class='link'> " . $image_author . " </a></p> " ;
2022-09-14 18:59:02 +00:00
}
2022-09-08 19:41:47 +00:00
// Image ID
2022-09-17 21:26:15 +00:00
if ( $image [ 'id' ] == 69 ) {
2022-09-18 20:39:01 +00:00
echo " <p>ID: " . $image [ 'id' ] . " , nice</p> " ;
2022-09-17 21:26:15 +00:00
} else {
echo " <p>ID: " . $image [ 'id' ] . " </p> " ;
}
2022-09-08 19:41:47 +00:00
2022-09-20 18:38:22 +00:00
$upload_time = new DateTime ( $image [ 'upload_date' ]);
echo " <p id='updateTime'>Uploaded at: " . $upload_time -> format ( 'd/m/Y H:i:s T' ) . " </p> " ;
2022-09-08 19:41:47 +00:00
?>
2022-09-13 13:24:48 +00:00
< script >
// Updating time to Viewers local
2022-09-20 18:38:22 +00:00
var updateDate = new Date ( '<?php echo $upload_time->format(' m / d / Y H : i : s T '); ?>' );
2022-09-13 13:24:48 +00:00
var format = { year : 'numeric' ,
month : 'short' ,
day : 'numeric' ,
hour : '2-digit' ,
minute : '2-digit'
};
updateDate = updateDate . toLocaleDateString ( 'en-GB' , format );
2022-09-20 18:38:22 +00:00
$ ( " #updateTime " ) . html ( " Uploaded at: " + updateDate );
2022-09-13 13:24:48 +00:00
</ script >
2022-09-20 18:38:22 +00:00
< p > Last Modified : < ? php echo $diff -> time ( $image [ 'last_modified' ]); ?> </p>
2022-09-08 19:41:47 +00:00
</ div >
< div >
< ? php
// File name
$image_pathinfo = pathinfo ( $image [ 'imagename' ]);
echo " <p>File Name: " . $image_pathinfo [ 'filename' ] . " </p> " ;
// File extention
echo " <p>File Type: " . pathinfo ( $image [ 'imagename' ], PATHINFO_EXTENSION ) . " </p> " ;
// Image resolution
list ( $width , $height ) = getimagesize ( $image_path );
echo " <p>Image resolution: " . $width . " x " . $height . " </p> " ;
2022-09-09 16:39:22 +00:00
function human_filesize ( $bytes , $decimals = 2 ) {
$sz = 'BKMGTP' ;
$factor = floor (( strlen ( $bytes ) - 1 ) / 3 );
return sprintf ( " %. { $decimals } f " , $bytes / pow ( 1024 , $factor )) . @ $sz [ $factor ];
}
echo " <p>File size: " . human_filesize ( filesize ( $image_path ), 2 ) . " </p> " ;
2022-09-08 19:41:47 +00:00
?>
</ div >
</ div >
2022-09-15 11:21:21 +00:00
<!-- Download Image -->
< a id = 'download' class = 'btn btn-good' href = '<?php echo "images/".$image[' imagename ']; ?>' download = '<?php echo $image[' imagename ']; ?>' >< img class = 'svg' src = 'assets/icons/download.svg' > Download image </ a >
< script >
$ ( " #download " ) . click ( function () {
sniffleAdd ( " Info " , " Image download started! " , " var(--green) " , " assets/icons/download.svg " );
});
</ script >
<!-- Copy link -->
2022-09-08 19:41:47 +00:00
< button class = 'btn btn-good' onclick = 'copyLink()' >< img class = 'svg' src = 'assets/icons/clipboard-text.svg' > Copy image link </ button >
2022-08-15 10:56:05 +00:00
< script >
function copyLink () {
navigator . clipboard . writeText ( window . location . href );
sniffleAdd ( " Info " , " Link has been copied! " , " var(--green) " , " assets/icons/clipboard-text.svg " );
}
</ script >
</ div >
< div class = " tags-root default-window " >
< h2 > Tags </ h2 >
< div class = " tags " >
< ? php
// Get image tags
if ( isset ( $image [ 'tags' ]) && ! empty ( $image [ 'tags' ])) {
$image_tags_array = explode ( " " , $image [ 'tags' ]);
foreach ( $image_tags_array as $tag ) {
if ( $tag == " nsfw " ) {
2022-09-07 18:19:17 +00:00
echo " <p id='tag' class='tag btn-bad'> " . $tag . " </p> " ;
2022-08-15 10:56:05 +00:00
} else {
2022-09-07 18:19:17 +00:00
echo " <p id='tag' class='tag btn-good'> " . $tag . " </p> " ;
2022-08-15 10:56:05 +00:00
}
}
} else {
echo " <p>No tags present</p> " ;
}
?>
</ div >
</ div >
< ? php
/*
|-------------------------------------------------------------
| Check if user is privilaged ,
|-------------------------------------------------------------
| If yes , grant them access to the Danger zone , or " the place
| that can fuck things up "
|-------------------------------------------------------------
*/
if ( $privilaged ) {
?>
<!-- Danger zone -->
2022-09-21 16:28:57 +00:00
< div class = 'danger-zone' >
2022-08-15 10:56:05 +00:00
< h2 > Danger zone </ h2 >
<!--
|-------------------------------------------------------------
| Delete
|-------------------------------------------------------------
| sus
| I cannot describe the anxiety this gives me . pls help
|-------------------------------------------------------------
-->
< button id = 'deleteButton' class = 'btn btn-bad' >< img class = 'svg' src = 'assets/icons/trash.svg' > Delete image </ button >
< script >
$ ( '#deleteButton' ) . click ( function () {
var header = " Are you sure? " ;
var description = " Deleting this image is pernament, there is no going back after this!!!!! " ;
var actionBox = " <form id='deleteConfirm' method='POST'> \
2022-09-07 13:40:58 +00:00
< button id = 'deleteSubmit' class = 'btn btn-bad' type = 'submit' >< img class = 'svg' src = 'assets/icons/trash.svg' > Delete image </ button > \
</ form > " ;
2022-08-15 10:56:05 +00:00
flyoutShow ( header , description , actionBox );
$ ( " #deleteConfirm " ) . submit ( function ( event ) {
event . preventDefault ();
var deleteSubmit = $ ( " #deleteSubmit " ) . val ();
2022-09-09 11:41:41 +00:00
$ ( " #sniffle " ) . load ( " app/image/image.php " , {
2022-08-15 10:56:05 +00:00
id : < ? php echo $_GET [ 'id' ]; ?> ,
2022-09-09 11:41:41 +00:00
submit_delete : deleteSubmit
2022-08-15 10:56:05 +00:00
});
});
});
</ 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 .
|-------------------------------------------------------------
-->
< button id = 'descriptionButton' class = 'btn btn-bad' >< img class = 'svg' src = 'assets/icons/edit.svg' > Edit description </ button >
< script >
$ ( '#descriptionButton' ) . click ( function () {
var header = " Enter new Description/Alt " ;
var description = " Whatcha gonna put in there 👀 " ;
var actionBox = " <form id='descriptionConfirm' action='app/image/edit_description.php' method='POST'> \
2022-09-21 14:23:17 +00:00
< input id = 'descriptionInput' class = 'btn btn-neutral space-bottom' type = 'text' placeholder = 'Description/Alt for image' > \
2022-09-07 13:40:58 +00:00
< button id = 'descriptionSubmit' class = 'btn btn-bad' type = 'submit' >< img class = 'svg' src = 'assets/icons/edit.svg' > Update information </ button > \
</ form > " ;
2022-08-15 10:56:05 +00:00
flyoutShow ( header , description , actionBox );
2022-09-19 21:57:11 +00:00
$ ( '#descriptionInput' ) . val ( " <?php if ( $image_alt != " No description avalible " ) echo str_replace(' " ', ' \ " ', $image_alt ); ?> " );
2022-09-13 13:24:48 +00:00
2022-08-15 10:56:05 +00:00
$ ( " #descriptionConfirm " ) . submit ( function ( event ) {
event . preventDefault ();
var descriptionInput = $ ( " #descriptionInput " ) . val ();
var descriptionSubmit = $ ( " #descriptionSubmit " ) . val ();
2022-09-09 11:41:41 +00:00
$ ( " #sniffle " ) . load ( " app/image/image.php " , {
2022-08-15 10:56:05 +00:00
id : < ? php echo $_GET [ 'id' ]; ?> ,
input : descriptionInput ,
2022-09-09 11:41:41 +00:00
submit_description : descriptionSubmit
2022-08-15 10:56:05 +00:00
});
});
});
</ script >
<!--
|-------------------------------------------------------------
| Edit Tags
|-------------------------------------------------------------
| Literally no amount of work will get tags / lists to play well
| with SQL so I gave up and made my own shitty system . It
| works but once I re - add the search function this will make
| anyone cry . I am so sorry .
|-------------------------------------------------------------
-->
< button id = 'tagsButton' class = 'btn btn-bad' >< img class = 'svg' src = 'assets/icons/tag.svg' > Add image tags </ button >
< script >
$ ( '#tagsButton' ) . click ( function () {
var header = " Tags " ;
2022-09-14 19:43:43 +00:00
var description = " Tags are seperated by spaces, only alowed characters are a-z and underscores, all hyphens are converted to underscores. There are also special tags such as nsfw that'll blur images in the overview " ;
2022-08-15 10:56:05 +00:00
var actionBox = " <form id='tagsConfirm' action='app/image/edit_tags.php' method='POST'> \
2022-09-21 14:23:17 +00:00
< input id = 'tagsInput' class = 'btn btn-neutral space-bottom' type = 'text' placeholder = 'Tags are seperated by spaces' > \
2022-09-07 13:40:58 +00:00
< button id = 'tagsSubmit' class = 'btn btn-bad' type = 'submit' >< img class = 'svg' src = 'assets/icons/edit.svg' > Edit tags </ button > \
</ form > " ;
2022-08-15 10:56:05 +00:00
flyoutShow ( header , description , actionBox );
2022-09-07 13:40:58 +00:00
$ ( '#tagsInput' ) . val ( " <?php echo $image['tags'] ; ?> " );
2022-09-07 11:00:53 +00:00
2022-08-15 10:56:05 +00:00
$ ( " #tagsConfirm " ) . submit ( function ( event ) {
event . preventDefault ();
var tagsInput = $ ( " #tagsInput " ) . val ();
var tagsSubmit = $ ( " #tagsSubmit " ) . val ();
2022-09-09 11:41:41 +00:00
$ ( " #sniffle " ) . load ( " app/image/image.php " , {
2022-08-15 10:56:05 +00:00
id : < ? php echo $_GET [ 'id' ]; ?> ,
input : tagsInput ,
2022-09-09 11:41:41 +00:00
submit_tags : tagsSubmit
2022-08-15 10:56:05 +00:00
});
});
});
</ script >
<!--
|-------------------------------------------------------------
| Edit Author
|-------------------------------------------------------------
| You must be a super cool person to see this section ; 3
|-------------------------------------------------------------
-->
< ? php
2022-09-16 16:39:13 +00:00
if ( $user_info -> is_admin ( $conn , $_SESSION [ 'id' ])) {
2022-08-15 10:56:05 +00:00
?>
< button id = 'authorButton' class = 'btn btn-bad' >< img class = 'svg' src = 'assets/icons/edit.svg' > Edit author </ button >
< script >
$ ( '#authorButton' ) . click ( function () {
var header = " Who owns the image????? " ;
var description = " Enter ID of image owner " ;
var actionBox = " <form id='authorConfirm' action='app/image/edit_author.php' method='POST'> \
2022-09-07 13:40:58 +00:00
< input id = 'authorInput' class = 'btn btn-neutral space-bottom' type = 'text' placeholder = 'le author' > \
< button id = 'authorSubmit' class = 'btn btn-bad' type = 'submit' >< img class = 'svg' src = 'assets/icons/edit.svg' > Edit author </ button > \
</ form > " ;
2022-08-15 10:56:05 +00:00
flyoutShow ( header , description , actionBox );
$ ( " #authorConfirm " ) . submit ( function ( event ) {
event . preventDefault ();
var authorInput = $ ( " #authorInput " ) . val ();
var authorSubmit = $ ( " #authorSubmit " ) . val ();
2022-09-09 11:41:41 +00:00
$ ( " #sniffle " ) . load ( " app/image/image.php " , {
2022-08-15 10:56:05 +00:00
id : < ? php echo $_GET [ 'id' ]; ?> ,
input : authorInput ,
2022-09-09 11:41:41 +00:00
submit_author : authorSubmit
2022-08-15 10:56:05 +00:00
});
});
});
</ script >
< ? php
}
echo " </div> " ;
}
/*
|-------------------------------------------------------------
| End of displaying all user info
|-------------------------------------------------------------
*/
}
?>
2022-09-21 13:37:45 +00:00
< ? php require_once __DIR__ . " /assets/ui/footer.php " ; ?>
2022-07-21 14:53:04 +00:00
</ body >
2022-08-15 10:56:05 +00:00
2022-08-12 11:28:19 +00:00
</ html >