View file modules/users/profile.php

File size: 8.46Kb
<?php
$title_main = $lang['profile'].' - GOload '.$lang['title'];
require_once SYS.'/header.php';

if (!isset($user)) {
    go('/');
}

if (isset($_GET['user'])) {
    $id = abs(intval($_GET['user']));
} else {
    $id = abs(intval($user['id']));
}

echo '
		<script src="/assets/js/lazy.min.js"></script>
		<script>
			$(function() {
				$(".img_load").Lazy();
			});
		</script>
		<div class="block col-md-8">
			<h6 class="round_title">
				<a class="left" onclick="window.history.back();">
					<img src="/assets/img/left.svg" alt="back">
				</a>
				<div class="title back"><a href="/">'.$title.'</a> | '.$lang['profile'].'</div>
			</h6>

';

$find = $db->query('SELECT COUNT(`id`) FROM `users`WHERE `id` = '.$id)->fetch_row()[0];
if ($find != 0) {
    $us = $db->query('SELECT * FROM `users` WHERE `id` = '.$id)->fetch_assoc();
} else {
    error($lang['user_not_found']);
}

if (file_exists(H.'/modules/users/photos/'.$us['id'].'.png')) {
    $photo = '/modules/users/photos/'.$us['id'].'.png?t='.time();
} else {
    $photo = '/assets/img/user.png';
}

$time = time();
if ($us['date_last'] > ($time - 60)) {
    $onl = $lang['online'];
} else {
    $onl = $lang['last_online'].' '.vremya($us['date_last']);
}

echo '
			<main class="container container-profile container-profile-main">
				<style id="style">.user-profile-content .user-head:before {background-image: url('.$photo.');}</style>
				<div class="user-profile-content">
					<div class="user-head">
						<div class="container container-profile user-info">
							<div class="avatar animated fadeInUpBig">
								<img src="'.$photo.'" id="photo" class="img-circle">
							</div>
							<div class="info">	
								<div class="uname animated fadeInUpBig">
									<a href="/user/settings">
										<h4>'.$us['login'].'</h4>
									</a>
								</div>
								<p class="status animated fadeInUpBig">'.$onl.'</p>';

if ($user['id'] == $us['id']) {
echo '
								<label for="fileInput" class="butt butt-upload butt-follow butt_links animated fadeInUpBig">
									<span>'.$lang['upload_photo'].'</span>
								</label>
								<input id="fileInput" type="file" accept="image/*" class="none">
								<a href="/logout" class="butt butt-info butt_links animated fadeInUpBig">
									<span>'.$lang['logout'].'</span>
								</a>

								<script>
									const input = document.getElementById("fileInput");
									const photo = document.getElementById("photo");
									const smallPhoto = document.getElementById("smallPhoto");
									const style = document.getElementById("style");

									const upload = (file) => {
										const formData = new FormData;
										formData.append("photo", file);
										fetch("https://'.$_SERVER['HTTP_HOST'].'/user/photo", {
											method: "POST",
											body: formData
										}).then(
											response => response.json()
										).then(
											response => {
												if (response.success) {
													photo.src = response.data.photo,
													smallPhoto.src = response.data.photo,
													style.innerHTML = `.user-profile-content .user-head:before {background-image: url(${response.data.photo}) !important;}`
												} else {
													alert(response.data.message)
												}
											}
										).catch(
											error => console.error(error)
										)
									};

									const fileSelect = () => upload(input.files[0]);

									input.addEventListener("change", fileSelect, false);
								</script>';
}

list($k_post) = $db->query('SELECT COUNT(*) FROM `file` WHERE `user` = '.$us['id'])->fetch_row();

echo '
							</div>
						</div>
					</div>

					<div class="include">
						<div class="container container-profile user-posts__container">
';
if (!empty($k_post)) echo '
			<div class="sort">
				<div class="sort_btn">
					<span>'.$lang['file_count'].':</span>
					<b>'.$k_post.'</b>
				</div>
			</div>
';
echo '
			<div class="link">
';

$max = 30;
$k_page = k_page($k_post, $max);
$page = page($k_page);
$start = $max * $page - $max;

$file = $db->query("SELECT * FROM `file` WHERE `user` = '".$us['id']."' ORDER BY `id` DESC LIMIT $start, $max");
while ($a = $file->fetch_assoc()) {
if ($a['del'] != 0) {
   $avto = $a['del'] * 86400;
} else {
   $avto = $set['del'] * 86400;
}
if ($a['pass'] == 0) {
echo '
				<div class="file">
					<div class="file_top">
						<span class="file_author"><img style="margin-right: 8px;" src="/assets/img/user.svg" alt="user">'.mb_strimwidth($a['avtor'], 0, 18, "...").'</span>
						<span class="file_date">'.vremya($a['time']-$avto).'</span>
					</div>
					<div class="file_more">
						<img src="/assets/img/more.svg" alt="more">
						<div class="more_links">'; if (isset($admin) or $a['user'] = $user['id']) echo '
							<a href="/delete'.$a['id'].'">'.$lang['delete_btn'].'</a>'; echo '
							<a href="/report'.$a['id'].'">'.$lang['report'].'</a>
						</div>
					</div>
					<a href="/file'.$a['id'].'" class="file_block">
						<span class="file_name">'.$a['name'].'</span>';

if ($a['format'] == 'jpeg' or $a['format'] == 'jpg' or $a['format'] == 'png' or $a['format'] == 'ico' or $a['format'] == 'bmp' or $a['format'] == 'svg') {
echo '
						<div class="file_image">
							<img class="img_load'; if ($a['nsfw'] == 'true') { echo ' nsfw';} echo '" data-src="/files/'.$a['file'].'" alt="">
						</div>';
} elseif ($a['format'] == 'gif') {
echo '
						<div class="file_image">
							<img class="img_load'; if ($a['nsfw'] == 'true') { echo ' nsfw';} echo '" data-src="/modules/viewer/gif.php?image='.$a['file'].'" alt="">
						</div>';
} elseif ($a['format'] == 'psd') {
echo '
						<div class="file_image">
							<img class="img_load'; if ($a['nsfw'] == 'true') { echo ' nsfw';} echo '" data-src="/modules/viewer/psd.php?file='.$a['file'].'" alt="">
						</div>';
} elseif ($a['format'] == 'mp4' or $a['format'] == 'webm') {
echo '
						<div class="file_image file_video">
							<i class="material-icons play_ic">play_arrow</i>
							<img class="img_load'; if ($a['nsfw'] == 'true') { echo ' nsfw';} echo '" data-src="/modules/viewer/video.php?file='.$a['file'].'" alt="">
						</div>';
}
echo '
						<div class="file_info">
							<span style="margin-right:16px;"><img src="/assets/img/down.svg" alt="load">'.count_round($a['up']).'</span>
							<span><img src="/assets/img/info.svg" alt="size">'.sizer(filesize('files/'.$a['file'])).'</span>'; if ($a['nsfw'] == 'true') { echo '
							<span style="margin-left:16px;" title="'.$lang['nsfw_file'].'"><img src="/assets/img/warning.svg" alt="NSFW">NSFW</span>';} echo '
							<span style="margin-left:auto;"><img src="/assets/img/views.svg" alt="views">'.count_round($a['views']).'</span>
						</div>
					</a>
				</div>
';
} else {
echo '
				<div class="file">
					<div class="file_top">
						<span class="file_author"><img style="margin-right: 8px;" src="/assets/img/lock.svg" alt="lock">'.mb_strimwidth($a['avtor'], 0, 18, "...").'</span>
						<span class="file_date">'.vremya($a['time']-$avto).'</span>
					</div>
					<div class="file_more">
						<img src="/assets/img/more.svg" alt="more">
						<div class="more_links">'; if (isset($admin) or $a['user'] = $user['id']) echo '
							<a href="/delete'.$a['id'].'">'.$lang['delete_btn'].'</a>'; echo '
							<a href="/report'.$a['id'].'">'.$lang['report'].'</a>
						</div>
					</div>
					<a href="/file'.$a['id'].'" class="file_block">
						<span class="file_name">'.$a['name'].'</span>
						<div class="file_info">
							<span style="margin-right:16px;"><img src="/assets/img/down.svg" alt="load">'.count_round($a['up']).'</span>
							<span><img src="/assets/img/info.svg" alt="size">'.sizer(filesize('files/'.$a['file'])).'</span>'; if ($a['nsfw'] == 'true') { echo '
							<span style="margin-left:16px;" title="'.$lang['nsfw_file'].'"><img src="/assets/img/warning.svg" alt="NSFW">NSFW</span>';} echo '
							<span style="margin-left:auto;"><img src="/assets/img/views.svg" alt="views">'.count_round($a['views']).'</span>
						</div>
					</a>
				</div>

';
}

}

echo '
			</div>
';

if (empty($k_post)) echo '
			<div class="menu">
				<div style="text-align: center;padding: 8px;">
					<div class="error-logo" style="float: initial;"></div>
					<div>
						<div class="error-message">'.$lang['no_files'].'! :((</div>

						<div>
							<a href="/add_file">'.$lang['add_file'].'</a>
						</div>
					</div>
				</div>
			</div>';

if (isset($_GET['user'])) {
	$user_id = '?user='.$id;
} else {
	$user_id = null;
}
if ($k_page > 1) echo pagination('/profile', $k_page, $page, $user_id);

echo '
						</div>
					</div>
				</div>
			</main>';

echo '
		</div>
';

?>