Файл: user/avatar.php
Строк: 223
<?php
/* DCMS Special
* Дата последнего редактирования 21.12.2015
* Модифицировал densnet
*/
foreach (array('start', 'compress', 'sess', 'settings', 'db_connect', 'ipua', 'fnc', 'user') as $inc) {
require_once "../sys/inc/{$inc}.php";
}
only_reg();
$set['title'] = 'Мой аватар';
require_once H . 'sys/inc/thead.php';
aut();
err();
#Навигация
echo "<nav class='navbar navbar-light' style='background-color: #607D8B; color: #fff;'>";
echo "<ul class='nav navbar-nav'>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link' href='/'><i class='material-icons'>home</i></a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link'><i class='material-icons'>keyboard_arrow_right</i></a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link' href='/?umenu'>Кабинет</a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link'><i class='material-icons'>keyboard_arrow_right</i></a></li>";
echo "<li class='nav-item' style='margin-left: 1px;'><a class='nav-link'>Аватар</a></li>";
echo "</ul>";
echo "</nav>";
if (isset($_GET['act']) && $_GET['act'] == 'delete' && isset($_GET['ok'])) {
@unlink(H . "user/avatar/$user[id].jpg");
@unlink(H . "user/avatar/$user[id].gif");
@unlink(H . "user/avatar/$user[id].png");
msg('Фото успешно удалено');
mysql_query("DELETE FROM `avatar_comments` WHERE `avatar_id`= '$user[id]' ");
mysql_query("DELETE FROM `avatar_like` WHERE `id_komm`= '$user[id]' ");
header("Refresh: 3; url=/user/avatar.php?");
echo "<div class='list-group-item'><a href='/user/avatar.php?'><i class='material-icons'>keyboard_backspace</i> Вернуться</a></div>";
require_once H . 'sys/inc/tfoot.php';
exit;
}
if (isset($_GET['act']) && $_GET['act'] == 'foto') {
if (isset($_GET['rotate']) && ($_GET['rotate'] == 'right' || $_GET['rotate'] == 'left')) {
$rotate = $_GET['rotate'];
if ($rotate == 'left') {
$degrees = 90;
} else {
$degrees = 270;
}
$file = H . "user/avatar/$user[id].jpg";
$source = imagecreatefromjpeg($file);
$rotate1 = imagerotate($source, $degrees, 0);
imagejpeg($rotate1, H . "user/avatar/$user[id].jpg", 90);
msg("Фото успешно отредактировано. Обновите страницу");
header("Refresh: 3; url=/user/avatar.php?");
echo "<div class='list-group-item'><a href='/user/avatar.php?'><i class='material-icons'>keyboard_backspace</i> Вернуться</a></div>";
require_once H . 'sys/inc/tfoot.php';
exit;
}
}
if (isset($_FILES['file'])) {
if (preg_match('#.jpe?g$#i', $_FILES['file']['name']) && $imgc = @imagecreatefromstring(file_get_contents($_FILES['file']['tmp_name']))) {
$img_x = imagesx($imgc);
$img_y = imagesy($imgc);
if ($img_x > $set['max_upload_foto_x'] || $img_y > $set['max_upload_foto_y']) {
$err = 'Размер изображения превышает ограничения в ' . $set['max_upload_foto_x'] . '*' . $set['max_upload_foto_y'];
}
if ($img_x > 640 || $img_y > 640) {
if ($img_x == $img_y) {
$dstW = 640; // ширина
$dstH = 640; // высота
} elseif ($img_x > $img_y) {
$prop = $img_x / $img_y;
$dstW = 640;
$dstH = ceil($dstW / $prop);
} else {
$prop = $img_y / $img_x;
$dstH = 640;
$dstW = ceil($dstH / $prop);
}
copy($_FILES['file']['tmp_name'], H . 'sys/tmp/' . $user['id'] . '_' . md5_file($_FILES['file']['tmp_name']) . '.wall.tmp');
chmod(H . 'sys/tmp/' . $user['id'] . '_' . md5_file($_FILES['file']['tmp_name']) . '.wall.tmp', 0777);
if (isset($_SESSION['file'])) {
$next_f = count($_SESSION['file']);
} else {
$next_f = 0;
}
$file = esc(stripcslashes(htmlspecialchars($_FILES['file']['name'])));
$_SESSION['file'][$next_f]['name'] = preg_replace('#.[^.]*$#i', NULL, $file); // имя файла без расширения
$_SESSION['file'][$next_f]['ras'] = strtolower(preg_replace('#^.*.#i', NULL, $file));
$_SESSION['file'][$next_f]['tmp_name'] = H . 'sys/tmp/' . $user['id'] . '_' . md5_file($_FILES['file']['tmp_name']) . '.wall.tmp';
$_SESSION['file'][$next_f]['size'] = filesize(H . 'sys/tmp/' . $user['id'] . '_' . md5_file($_FILES['file']['tmp_name']) . '.wall.tmp');
$_SESSION['file'][$next_f]['type'] = $_FILES['file']['type'];
if (isset($_SESSION['file']) && isset($user)) {
for ($i = 0; $i < count($_SESSION['file']); $i++) {
if (isset($_SESSION['file'][$i]) && is_file($_SESSION['file'][$i]['tmp_name'])) {
$msg = "" . ($user['sex'] ? 'Обновил' : 'Обновила') . " свою фотографию";
mysql_query("INSERT INTO `wall` (`id_user`,`id_wall`,`time`,`msg`) values('$user[id]','$user[id]','$time','$msg')");
$q = mysql_query("SELECT * FROM `wall` ORDER BY `id` DESC LIMIT 1");
while ($post = mysql_fetch_assoc($q)) {
mysql_query("INSERT INTO `wall_files` (`id_wall`, `name`, `ras`, `size`, `type`) values('$post[id]', '" . $_SESSION['file'][$i]['name'] . "', '" . $_SESSION['file'][$i]['ras'] . "', '" . $_SESSION['file'][$i]['size'] . "', '" . $_SESSION['file'][$i]['type'] . "')");
}
$file_id = mysql_insert_id();
copy($_SESSION['file'][$i]['tmp_name'], H . 'sys/wall/' . $file_id . '.frf');
unlink($_SESSION['file'][$i]['tmp_name']);
}
}
unset($_SESSION['file']);
}
$imgc = img_copyright($imgc); // наложение копирайта
imagejpeg($imgc, H . "user/avatar/$user[id].jpg", 90);
@chmod(H . "user/avatar/$user[id].jpg", 0777);
} else {
$imgc = img_copyright($imgc); // наложение копирайта
imagejpeg($imgc, H . "user/avatar/$user[id].jpg", 90);
@chmod(H . "user/avatar/$user[id].jpg", 0777);
}
imagedestroy($imgc);
msg("Фото успешно установлено");
mysql_query("DELETE FROM `avatar_comments` WHERE `avatar_id`= '$user[id]' ");
mysql_query("DELETE FROM `avatar_like` WHERE `id_komm`= '$user[id]' ");
header("Refresh: 3; url=/user/avatar.php?");
echo "<div class='list-group-item'><a href='/user/avatar.php?'><i class='material-icons'>keyboard_backspace</i> Вернуться</a></div>";
require_once H . 'sys/inc/tfoot.php';
exit;
} elseif (preg_match('#.gif$#i', $_FILES['file']['name']) && $imgc = @imagecreatefromgif($_FILES['file']['tmp_name'])) {
include_once 'sys/inc/gif_resize.php';
$screen = gif_resize(fread(fopen($_FILES['file']['tmp_name'], "rb"), filesize($_FILES['file']['tmp_name'])), 48, 48);
$avs = glob(H . "user/avatar/$user[id].*");
if ($avs) {
foreach ($avs as $value) {
@chmod($value, 0777);
@unlink($value);
}
}
file_put_contents(H . "user/avatar/$user[id].gif", $screen);
@chmod(H . "user/avatar/$user[id].gif", 0777);
copy($_FILES['file']['tmp_name'], H . 'sys/tmp/' . $user['id'] . '_' . md5_file($_FILES['file']['tmp_name']) . '.wall.tmp');
chmod(H . 'sys/tmp/' . $user['id'] . '_' . md5_file($_FILES['file']['tmp_name']) . '.wall.tmp', 0777);
if (isset($_SESSION['file'])) {
$next_f = count($_SESSION['file']);
} else {
$next_f = 0;
}
$file = esc(stripcslashes(htmlspecialchars($_FILES['file']['name'])));
$_SESSION['file'][$next_f]['name'] = preg_replace('#.[^.]*$#i', NULL, $file); // имя файла без расширения
$_SESSION['file'][$next_f]['ras'] = strtolower(preg_replace('#^.*.#i', NULL, $file));
$_SESSION['file'][$next_f]['tmp_name'] = H . 'sys/tmp/' . $user['id'] . '_' . md5_file($_FILES['file']['tmp_name']) . '.wall.tmp';
$_SESSION['file'][$next_f]['size'] = filesize(H . 'sys/tmp/' . $user['id'] . '_' . md5_file($_FILES['file']['tmp_name']) . '.wall.tmp');
$_SESSION['file'][$next_f]['type'] = $_FILES['file']['type'];
if (isset($_SESSION['file']) && isset($user)) {
for ($i = 0; $i < count($_SESSION['file']); $i++) {
if (isset($_SESSION['file'][$i]) && is_file($_SESSION['file'][$i]['tmp_name'])) {
$msg = "" . ($user['sex'] ? 'Обновил' : 'Обновила') . " свою фотографию";
mysql_query("INSERT INTO `wall` (`id_user`,`id_wall`,`time`,`msg`) values('$user[id]','$user[id]','$time','$msg')");
$q = mysql_query("SELECT * FROM `wall` ORDER BY `id` DESC LIMIT 1");
while ($post = mysql_fetch_assoc($q)) {
mysql_query("INSERT INTO `wall_files` (`id_wall`, `name`, `ras`, `size`, `type`) values('$post[id]', '" . $_SESSION['file'][$i]['name'] . "', '" . $_SESSION['file'][$i]['ras'] . "', '" . $_SESSION['file'][$i]['size'] . "', '" . $_SESSION['file'][$i]['type'] . "')");
}
$file_id = mysql_insert_id();
copy($_SESSION['file'][$i]['tmp_name'], H . 'sys/wall/' . $file_id . '.frf');
unlink($_SESSION['file'][$i]['tmp_name']);
}
}
unset($_SESSION['file']);
}
msg("Фото успешно установлено");
mysql_query("DELETE FROM `avatar_comments` WHERE `avatar_id`= '$user[id]' ");
mysql_query("DELETE FROM `avatar_like` WHERE `id_komm`= '$user[id]' ");
header("Refresh: 3; url=/user/avatar.php?");
echo "<div class='list-group-item'><a href='/user/avatar.php?'><i class='material-icons'>keyboard_backspace</i> Вернуться</a></div>";
require_once H . 'sys/inc/tfoot.php';
exit;
} elseif (preg_match('#.png$#i', $_FILES['file']['name']) && $imgc = @imagecreatefrompng($_FILES['file']['tmp_name'])) {
if (imagesx($imgc) > 1000 || imagesy($imgc) > 1000) {
$img_x = imagesx($imgc);
$img_y = imagesy($imgc);
if ($img_x == $img_y) {
$dstW = 1000; // ширина
$dstH = 1000; // высота
} elseif ($img_x > $img_y) {
$prop = $img_x / $img_y;
$dstW = 1000;
$dstH = ceil($dstW / $prop);
} else {
$prop = $img_y / $img_x;
$dstH = 1000;
$dstW = ceil($dstH / $prop);
}
$screen = ImageCreate($dstW, $dstH);
imagecopyresampled($screen, $imgc, 0, 0, 0, 0, $dstW, $dstH, $img_x, $img_y);
imagedestroy($imgc);
$avs = glob(H . "user/avatar/$user[id].*");
if ($avs) {
foreach ($avs as $value) {
@chmod($value, 0777);
@unlink($value);
}
}
imagepng($screen, H . "user/avatar/$user[id].png");
@chmod(H . "user/avatar/$user[id].png", 0777);
imagedestroy($screen);
} else {
copy($_FILES['file']['tmp_name'], H . "user/avatar/$user[id].png");
}
copy($_FILES['file']['tmp_name'], H . 'sys/tmp/' . $user['id'] . '_' . md5_file($_FILES['file']['tmp_name']) . '.wall.tmp');
chmod(H . 'sys/tmp/' . $user['id'] . '_' . md5_file($_FILES['file']['tmp_name']) . '.wall.tmp', 0777);
if (isset($_SESSION['file'])) {
$next_f = count($_SESSION['file']);
} else {
$next_f = 0;
}
$file = esc(stripcslashes(htmlspecialchars($_FILES['file']['name'])));
$_SESSION['file'][$next_f]['name'] = preg_replace('#.[^.]*$#i', NULL, $file); // имя файла без расширения
$_SESSION['file'][$next_f]['ras'] = strtolower(preg_replace('#^.*.#i', NULL, $file));
$_SESSION['file'][$next_f]['tmp_name'] = H . 'sys/tmp/' . $user['id'] . '_' . md5_file($_FILES['file']['tmp_name']) . '.wall.tmp';
$_SESSION['file'][$next_f]['size'] = filesize(H . 'sys/tmp/' . $user['id'] . '_' . md5_file($_FILES['file']['tmp_name']) . '.wall.tmp');
$_SESSION['file'][$next_f]['type'] = $_FILES['file']['type'];
if (isset($_SESSION['file']) && isset($user)) {
for ($i = 0; $i < count($_SESSION['file']); $i++) {
if (isset($_SESSION['file'][$i]) && is_file($_SESSION['file'][$i]['tmp_name'])) {
$msg = "" . ($user['sex'] ? 'Обновил' : 'Обновила') . " свою фотографию";
mysql_query("INSERT INTO `wall` (`id_user`,`id_wall`,`time`,`msg`) values('$user[id]','$user[id]','$time','$msg')");
$q = mysql_query("SELECT * FROM `wall` ORDER BY `id` DESC LIMIT 1");
while ($post = mysql_fetch_assoc($q)) {
mysql_query("INSERT INTO `wall_files` (`id_wall`, `name`, `ras`, `size`, `type`) values('$post[id]', '" . $_SESSION['file'][$i]['name'] . "', '" . $_SESSION['file'][$i]['ras'] . "', '" . $_SESSION['file'][$i]['size'] . "', '" . $_SESSION['file'][$i]['type'] . "')");
}
$file_id = mysql_insert_id();
copy($_SESSION['file'][$i]['tmp_name'], H . 'sys/wall/' . $file_id . '.frf');
unlink($_SESSION['file'][$i]['tmp_name']);
}
}
unset($_SESSION['file']);
}
msg("Фото успешно установлено");
mysql_query("DELETE FROM `avatar_comments` WHERE `avatar_id`= '$user[id]' ");
mysql_query("DELETE FROM `avatar_like` WHERE `id_komm`= '$user[id]' ");
header("Refresh: 3; url=/user/avatar.php?");
echo "<div class='list-group-item'><a href='/user/avatar.php?'><i class='material-icons'>keyboard_backspace</i> Вернуться</a></div>";
require_once H . 'sys/inc/tfoot.php';
exit;
} else {
$err[] = 'Неверный формат файла';
}
}
if (isset($_GET['act']) && $_GET['act'] == 'delete') {
echo '<div class="card">';
echo "<div class='card-header'>Удаление <a style = 'float:right;color: grey;' href = '?'>Закрыть</a></div>";
echo "<form method='post' class='card-block' action='?act=delete&ok'>n";
echo "Вы действительно хотите удалить фото?<br />";
echo "<button class='waves-effect waves-light btn'><i class='material-icons'>delete</i> Удалить</button>";
echo "</form>";
echo "</div>";
}
$ava = avatar_path($user['id']);
if (isset($_POST['delete'])) {
header("Location: ?act=delete" . SID);
exit;
}
echo '<div class="card">';
if ($ava) {
echo "<div class='card-header'>Ваше текущее фото</div>";
} else {
echo "<div class='card-header'>Загрузка фото</div>";
}
echo "<form method='post' class='card-block' enctype='multipart/form-data' action='?$passgen'>n";
if ($ava) {
echo "<center>";
avatar_p($user['id'], '300');
echo "<br /><a href='?act=foto&rotate=left'><i class='material-icons'>rotate_left</i></a> <a href='?act=foto&rotate=right'><i class='material-icons'>rotate_right</i></a>n";
echo "</center><br />";
}
echo "<div class='alert alert-warning' role='alert'>";
echo "Можно загружать изображения форматов: GIF, JPG, PNG<br/>";
echo "Качественное преобразование GIF-анимации не гарантируется<br/>";
echo "</div>";
echo "<div class='file-field input-field'>";
echo "<div class='btn'><span>Файл</span>";
echo "<input name='file' type='file' accept='image/*,image/gif,image/png,image/jpeg' multiple>";
echo "</div>";
echo "<div class='file-path-wrapper'>";
echo "<input class='file-path validate' type='text' placeholder='Выберите изображение'>";
echo "</div>";
echo "</div>";
if ($ava) {
echo "<button class='waves-effect waves-light btn'>Заменить</button> ";
echo "<button class='waves-effect waves-light btn' name='delete'><i class='material-icons'>delete</i> Удалить фото</button>";
} else {
echo "<button class='waves-effect waves-light btn'>Загрузить</button>";
}
echo "</form>";
echo "</div>";
require_once H . 'sys/inc/tfoot.php';