2022-09-23 17:26:15 +00:00
< ? php
require_once __DIR__ . " /app/required.php " ;
use App\Account ;
2022-09-24 14:08:14 +00:00
use App\Image ;
use App\Group ;
2022-09-23 17:26:15 +00:00
use App\Diff ;
$user_info = new Account ;
2022-09-24 14:08:14 +00:00
$image_info = new Image ;
$group_info = new Group ;
$diff = new Diff ();
2022-09-24 16:47:34 +00:00
if ( isset ( $_GET [ 'id' ])) {
$group = $group_info -> get_group_info ( $conn , $_GET [ 'id' ]);
2022-09-25 15:49:11 +00:00
if ( ! isset ( $group ) || empty ( $group )) {
header ( " Location: group.php " );
$_SESSION [ 'err' ] = " You followed a broken link " ;
}
2022-09-24 16:47:34 +00:00
}
2022-09-27 14:10:08 +00:00
if ( isset ( $_SESSION [ 'err' ])) {
?>
< script >
2022-09-27 21:39:02 +00:00
sniffleAdd ( " Error " , " <?php echo $_SESSION['msg'] ; ?> " , " var(--warning) " , " assets/icons/trash.svg " );
2022-09-27 14:10:08 +00:00
</ script >
< ? php
unset ( $_SESSION [ 'err' ]);
}
2022-09-23 17:26:15 +00:00
?>
<! DOCTYPE html >
< html >
2022-09-24 14:08:14 +00:00
< head >
< ? php require_once __DIR__ . " /assets/ui/header.php " ; ?>
</ head >
2022-09-23 17:26:15 +00:00
< body >
2022-09-25 18:17:47 +00:00
< ? php
require_once __DIR__ . " /assets/ui/nav.php " ;
if ( isset ( $_SESSION [ 'msg' ])) {
?>
< script >
sniffleAdd ( " Info " , " <?php echo $_SESSION['msg'] ; ?> " , " var(--green) " , " assets/icons/check.svg " );
</ script >
< ? php
unset ( $_SESSION [ 'msg' ]);
}
?>
2022-09-23 17:26:15 +00:00
2022-09-24 14:08:14 +00:00
< ? php
if ( isset ( $_GET [ 'id' ])) {
$image_list = array_reverse ( explode ( " " , $group [ 'image_list' ]));
2022-09-23 17:26:15 +00:00
2022-09-25 12:01:23 +00:00
echo " <div class='group-banner defaultDecoration defaultSpacing defaultFonts'>
< div class = 'group-description' > " ;
2022-09-23 23:02:59 +00:00
2022-09-24 14:08:14 +00:00
$author_info = $user_info -> get_user_info ( $conn , $group [ 'author' ]);
2022-09-25 18:17:47 +00:00
echo " <h2> " . $group [ 'group_name' ] . " <span>by</span><a href='profile.php?user= " . $author_info [ 'id' ] . " '> " . $author_info [ 'username' ] . " </a></h2> " ;
2022-09-24 14:08:14 +00:00
$group_members = $group_info -> get_group_members ( $conn , $_GET [ 'id' ]);
2022-09-24 16:47:34 +00:00
if ( ! empty ( $group_members )) {
$members_array = array ();
foreach ( $group_members as $member ) {
$member_info = $user_info -> get_user_info ( $conn , $member );
2022-09-25 18:17:47 +00:00
if ( ! empty ( $member_info [ 'username' ])) $members_array [] = " <a href='profile.php?user= " . $member_info [ 'id' ] . " '> " . $member_info [ 'username' ] . " </a> " ;
2022-09-24 16:47:34 +00:00
}
2022-09-25 18:17:47 +00:00
echo " <p>Featured: " . implode ( " , " , $members_array ) . " </p> " ;
2022-09-23 23:02:59 +00:00
}
2022-09-25 12:01:23 +00:00
if ( ! empty ( $group [ 'image_list' ])) echo " <p>Images: " . count ( explode ( " " , $group [ 'image_list' ])) . " </p> " ;
2022-09-23 23:02:59 +00:00
$upload_time = new DateTime ( $group [ 'created_on' ]);
2022-09-25 15:49:11 +00:00
echo " <p id='updateTime'>Created at: " . $upload_time -> format ( 'd/m/Y H:i:s T' ) . " </p> " ;
2022-09-24 14:08:14 +00:00
?>
< script >
var updateDate = new Date ( '<?php echo $upload_time->format(' m / d / Y H : i : s T '); ?>' );
updateDate = updateDate . toLocaleDateString ( 'en-GB' , { year : 'numeric' , month : 'short' , day : 'numeric' });
$ ( " #updateTime " ) . html ( " Created at: " + updateDate );
</ script >
< ? php
echo " <p>Last Modified: " . $diff -> time ( $group [ 'last_modified' ]) . " </p> " ;
if ( $_GET [ 'mode' ] == " edit " ) {
if ( $_SESSION [ 'id' ] == $group [ 'author' ] || $user_info -> is_admin ( $conn , $_SESSION [ 'id' ])) {
2022-09-29 14:10:23 +00:00
echo " <br> " ;
2022-09-24 17:07:22 +00:00
echo " <button id='deleteGroup' class='btn btn-bad'>Delete</button> " ;
?>
< script >
$ ( '#deleteGroup' ) . click ( function () {
var header = " Are you surrrrrre? " ;
var description = " The images will still be up, but all your hard work setting this group up will be gone! " ;
var actionBox = " <form id='titleForm' method='POST'> \
< button id = 'deleteSubmit' class = 'btn btn-bad' type = 'submit' >< img class = 'svg' src = 'assets/icons/trash.svg' > Delete group </ button > \
</ form > " ;
flyoutShow ( header , description , actionBox );
$ ( " #titleForm " ) . submit ( function ( event ) {
event . preventDefault ();
var deleteSubmit = $ ( " #deleteSubmit " ) . val ();
2022-09-28 15:35:41 +00:00
$ ( " #newSniff " ) . load ( " app/image/group.php " , {
2022-09-24 17:07:22 +00:00
group_id : < ? php echo $_GET [ 'id' ]; ?> ,
group_delete : deleteSubmit
});
});
});
</ script >
< ? php
2022-09-24 14:08:14 +00:00
echo " <button id='editTitle' class='btn btn-bad'>Update title</button> " ;
?>
< script >
$ ( '#editTitle' ) . click ( function () {
2022-09-25 12:01:23 +00:00
var header = " Newwww photo group name! " ;
var description = " What will it be? uwu " ;
2022-09-24 14:08:14 +00:00
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 ();
2022-09-28 15:35:41 +00:00
$ ( " #newSniff " ) . load ( " app/image/group.php " , {
2022-09-24 14:08:14 +00:00
group_id : < ? php echo $_GET [ 'id' ]; ?> ,
group_title : titleText ,
title_submit : titleSubmit
});
});
});
</ script >
< ? php
2022-09-23 17:26:15 +00:00
2022-09-29 14:10:23 +00:00
echo " <br> " ;
2022-09-23 17:26:15 +00:00
2022-09-29 14:10:23 +00:00
$image_request = mysqli_query ( $conn , " SELECT * FROM images " );
2022-09-24 14:08:14 +00:00
echo " <form id='groupForm'> " ;
while ( $image = mysqli_fetch_array ( $image_request )) {
if ( in_array ( $image [ 'id' ], $image_list )) {
echo " <input style='display: none;' type='checkbox' id=' " . $image [ 'id' ] . " ' name=' " . $image [ 'id' ] . " ' checked/> " ;
} else {
echo " <input style='display: none;' type='checkbox' id=' " . $image [ 'id' ] . " ' name=' " . $image [ 'id' ] . " '/> " ;
}
}
2022-09-25 12:01:23 +00:00
echo " <button id='groupSubmit' class='btn btn-good' type='submit'>Save changes</button>
2022-09-24 14:08:14 +00:00
</ form > " ;
echo " <a href='group.php?id= " . $_GET [ 'id' ] . " ' class='btn btn-neutral'>Back</a> " ;
}
2022-09-23 17:26:15 +00:00
} else {
2022-09-24 14:08:14 +00:00
if ( $_SESSION [ 'id' ] == $group [ 'author' ] || $user_info -> is_admin ( $conn , $_SESSION [ 'id' ])) {
echo " <a href='group.php?id= " . $_GET [ 'id' ] . " &mode=edit' class='btn btn-neutral'>Edit</a> " ;
}
2022-09-28 19:38:18 +00:00
?>
< button class = 'btn btn-good' onclick = 'copyLink()' >< img class = 'svg' src = 'assets/icons/clipboard-text.svg' > Copy link </ button >
< script >
function copyLink () {
navigator . clipboard . writeText ( window . location . href );
sniffleAdd ( " Info " , " Link has been copied! " , " var(--success) " , " assets/icons/clipboard-text.svg " );
}
</ script >
< ? php
2022-09-23 17:26:15 +00:00
}
2022-09-24 14:08:14 +00:00
echo " </div> " ;
2022-09-25 12:01:23 +00:00
$cover_image = $image_info -> get_image_info ( $conn , $image_list [ array_rand ( $image_list , 1 )]);
if ( ! empty ( $cover_image [ 'imagename' ])) {
2022-09-25 15:49:11 +00:00
?>
< div class = 'group-cover' >
< span ></ span >
< img < ? php if ( str_contains ( $cover_image [ 'tags' ], " nsfw " )) echo " class='nsfw-blur' " ; ?> src='images/<?php echo $cover_image['imagename']; ?>'/>
</ div >
< ? php
2022-09-25 12:01:23 +00:00
}
echo " </div> " ;
2022-09-24 14:08:14 +00:00
}
?>
2022-09-23 17:26:15 +00:00
2022-09-25 12:01:23 +00:00
< ? php
if ( empty ( $group [ 'image_list' ]) && $_GET [ 'mode' ] != " edit " && ! empty ( $_GET [ 'id' ])) {
2022-09-29 13:43:08 +00:00
echo " <div class='info-text defaultFonts' style='text-align: center !important;'>
2022-09-29 11:27:44 +00:00
< h1 > Nothing here !</ h1 >
< p > There are no images in the group , add some !</ p >
</ div > " ;
2022-09-25 12:01:23 +00:00
echo " <div id='gallery' class='gallery-root defaultDecoration' style='display: none;'> " ;
} else {
echo " <div id='gallery' class='gallery-root defaultDecoration' > " ;
}
2022-09-24 14:08:14 +00:00
if ( isset ( $_GET [ 'id' ]) && ! empty ( $_GET [ 'id' ])) {
if ( isset ( $_GET [ 'mode' ]) && $_GET [ 'mode' ] == " edit " ) {
$image_request = mysqli_query ( $conn , " SELECT * FROM images ORDER BY id DESC " );
2022-09-23 17:26:15 +00:00
2022-09-24 14:08:14 +00:00
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 ( in_array ( $image [ 'id' ], $image_list )) {
echo " <div id=' " . $image [ 'id' ] . " ' class='gallery-item selectedImage'>
< img class = 'gallery-image' loading = 'lazy' src = '".$image_path."' id = '".$image[' id ']."' >
</ div > " ;
} else {
echo " <div id=' " . $image [ 'id' ] . " ' class='gallery-item'>
< img class = 'gallery-image' loading = 'lazy' src = '".$image_path."' id = '".$image[' id ']."' >
</ div > " ;
}
2022-09-23 17:26:15 +00:00
}
2022-09-24 14:08:14 +00:00
?>
< script >
$ ( " .gallery-item " ) . click ( function () {
if ( this . classList . contains ( " selectedImage " )) {
deselect ( this );
} else {
select ( this );
}
});
function select ( item ) {
document . getElementById ( item . id ) . checked = true ;
item . classList . add ( " selectedImage " );
}
function deselect ( item ) {
document . getElementById ( item . id ) . checked = false ;
item . classList . remove ( " selectedImage " );
2022-09-23 17:26:15 +00:00
}
2022-09-24 14:08:14 +00:00
function getList () {
var checkedBoxes = document . querySelectorAll ( 'input[type=checkbox]:checked' );
var images = [];
2022-09-23 17:26:15 +00:00
2022-09-24 14:08:14 +00:00
checkedBoxes . forEach ( element => { images . push ( element . id ); });
2022-09-23 17:26:15 +00:00
2022-09-24 14:08:14 +00:00
return images ;
}
2022-09-23 17:26:15 +00:00
2022-09-24 14:08:14 +00:00
$ ( " #groupForm " ) . submit ( function ( event ) {
event . preventDefault ();
2022-09-23 17:26:15 +00:00
2022-09-24 14:08:14 +00:00
var groupSubmit = $ ( " #groupSubmit " ) . val ();
var images = getList ();
2022-09-23 17:26:15 +00:00
2022-09-24 16:47:34 +00:00
if ( images <= 0 ) {
2022-09-27 21:39:02 +00:00
sniffleAdd ( 'Oppsie' , 'Groups need at least 1 image in them. Alternativly, you can delete this group.' , 'var(--warning)' , 'assets/icons/cross.svg' );
2022-09-24 16:47:34 +00:00
} else {
2022-09-28 15:35:41 +00:00
$ ( " #newSniff " ) . load ( " app/image/group.php " , {
2022-09-24 16:47:34 +00:00
group_images : images ,
group_id : < ? php echo $_GET [ 'id' ]; ?> ,
group_submit : groupSubmit
});
}
2022-09-24 14:08:14 +00:00
});
</ script >
< ? php
} else {
foreach ( $image_list as $image ) {
// Reading images from table
try {
$image_request = mysqli_query ( $conn , " SELECT * FROM images WHERE id = " . $image );
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' ];
}
// Check for NSFW tag
if ( str_contains ( $image [ 'tags' ], " nsfw " )) {
echo " <div class='gallery-item'>
< a href = 'image.php?id=".$image[' id ']."' class = 'nsfw-warning' >< img class = 'svg' src = 'assets/icons/warning_red.svg' >< span > NSFW </ span ></ a >
< a href = 'image.php?id=".$image[' id ']."' >< img class = 'gallery-image nsfw-blur' loading = 'lazy' src = '".$image_path."' id = '".$image[' id ']."' ></ a >
</ div > " ;
} else {
echo " <div class='gallery-item'>
< a href = 'image.php?id=".$image[' id ']."' >< img class = 'gallery-image' loading = 'lazy' src = '".$image_path."' id = '".$image[' id ']."' ></ a >
</ div > " ;
}
}
} catch ( Exception $e ) {
$e ;
2022-09-23 17:26:15 +00:00
}
2022-09-24 14:08:14 +00:00
}
}
} elseif ( ! isset ( $_GET [ 'id' ]) && empty ( $_GET [ 'id' ])) {
2022-09-25 12:01:23 +00:00
if ( $_SESSION [ " loggedin " ]) {
2022-09-24 16:47:34 +00:00
echo " <div class='group-make'>
< button id = 'createGroup' >< img class = 'svg' src = 'assets/icons/plus.svg' >< span > Make new group </ span ></ button >
</ div > " ;
?>
< script >
2022-09-25 15:49:11 +00:00
$ ( '#createGroup' ) . click ( function () {
2022-09-28 15:35:41 +00:00
$ ( " #newSniff " ) . load ( " app/image/group.php " , {
2022-09-24 16:47:34 +00:00
new_group_submit : " uwu "
});
});
</ script >
< ? php
}
2022-09-24 14:08:14 +00:00
$group_list = mysqli_query ( $conn , " SELECT * FROM groups ORDER BY id DESC " );
2022-09-23 17:26:15 +00:00
2022-09-29 15:19:07 +00:00
if ( mysqli_num_rows ( $group_list ) == 0 && ! $_SESSION [ " loggedin " ]) {
2022-09-29 11:56:14 +00:00
?>
< style >
. gallery - root {
display : none ;
}
</ style >
< script >
2022-09-29 13:43:08 +00:00
$ ( 'body' ) . append ( " <div class='info-text defaultFonts' style='text-align: center !important;'><h1>There are no groups yet</h1><p>Login to make a group!</p></div> " );
2022-09-29 11:56:14 +00:00
</ script >
< ? php
}
2022-09-24 14:08:14 +00:00
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 )]);
2022-09-23 17:26:15 +00:00
2022-09-24 14:08:14 +00:00
// Getting thumbnail
2022-09-24 16:47:34 +00:00
if ( ! empty ( $image [ 'imagename' ])) {
if ( file_exists ( " images/thumbnails/ " . $image [ 'imagename' ])) {
$image_path = " images/thumbnails/ " . $image [ 'imagename' ];
} else {
$image_path = " images/ " . $image [ 'imagename' ];
}
2022-09-24 14:08:14 +00:00
} else {
2022-09-24 16:47:34 +00:00
$image_path = " assets/no_image.png " ;
2022-09-24 14:08:14 +00:00
}
2022-09-24 16:47:34 +00:00
2022-09-23 17:26:15 +00:00
2022-09-24 14:08:14 +00:00
// 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 >
< a href = 'group.php?id=".$group[' id ']."' class = 'group-name' > " . $group['group_name'] . " </ a >
</ 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 >
< a href = 'group.php?id=".$group[' id ']."' class = 'group-name' > " . $group['group_name'] . " </ a >
</ div > " ;
2022-09-23 17:26:15 +00:00
}
}
}
?>
</ div >
< ? php require_once __DIR__ . " /assets/ui/footer.php " ; ?>
</ body >
</ html >