File size: 8.21Kb
<?php defined('ACCESS') OR die('No direct script access...');
/*
* Author - Tw1nGo
* VK - https://vk.com/tw1ngo93
*/
if (isset($_GET['id']))
{
$photo = mysql_fetch_assoc(mysql_query("SELECT * FROM `photos_user` WHERE `id` = '".abs(intval($_GET['id']))."' LIMIT 1"));
$album = mysql_fetch_assoc(mysql_query("SELECT * FROM `photos` WHERE `id` = '".$photo['id_album']."' LIMIT 1"));
$ank = mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `id` = '".$album['id_user']."' LIMIT 1"));
}
if (!isset($album) || $album['id'] <= 0){
header("Location: /");
exit;
}
if (!isset($_GET['id']) || !isset($photo) || $photo['id'] <= 0){
header("Location: ?act=album&id=".$album['id']."");
exit;
}
if (isset($user) && $user['id'] == $ank['id'] || $user['level'] >= 4)
{
// Кнопка отмены
if (isset($_POST['cancel'])){
header("Location: ?act=photo&id=".$photo['id']."");
exit;
}
if (isset($_POST['cfms']) && isset($_POST['name']) && isset($_POST['text']))
{
$name = esc(stripcslashes(htmlspecialchars($_POST['name'])),1);
if (!preg_match("#^([A-zА-я0-9\-\_\(\)\,\.\ ])+$#ui",$name))$err = 'В названии фото запрещенные символы!';
if (strlen2($name) < 3 )$err = 'Короткое название, min: 3.';
if (strlen2($name) > 50 )$err = 'Длинное название, min: 50.';
$name = my_esc($name);
$msg = $_POST['text'];
if (strlen2($msg) > 500)$err = 'Длинное описание, max: 500.';
$msg = my_esc($msg);
$adult = 0;
$album_id = mysql_fetch_assoc(mysql_query("SELECT * FROM `photos` WHERE `id` = '".intval($_POST['aid'])."' LIMIT 1"));
if (!isset($err))
{
mysql_query("UPDATE `photos_user` SET `id_album` = '$album_id[id]', `name` = '$name', `metka` = '$adult', `msg` = '$msg' WHERE `id` = '$photo[id]' LIMIT 1");
$_SESSION['message'] = 'Фотография успешно изменена.';
header("Location: ?act=photo&id=".$photo['id']."");
exit;
}
}
if(isset($_GET['rotate']) && ($_GET['rotate'] == 'right' || $_GET['rotate'] == 'left') && is_file(H.'files/photos/size50/'.$photo['id'].''.$photo['hash'].'.jpg') && is_file(H.'files/photos/size100/'.$photo['id'].''.$photo['hash'].'.jpg') && is_file(H.'files/photos/size200/'.$photo['id'].''.$photo['hash'].'.jpg') && is_file(H.'files/photos/original/'.$photo['id'].''.$photo['hash'].'.jpg'))
{
$rotate=$_GET['rotate'];
if($rotate == 'left')
$degrees = 90;
else
$degrees = 270;
// Файл и угол поворота
$icon50 = H.'files/photos/size50/'.$photo['id'].''.$photo['hash'].'.jpg';
$icon128 = H.'files/photos/size100/'.$photo['id'].''.$photo['hash'].'.jpg';
$icon640 = H.'files/photos/size200/'.$photo['id'].''.$photo['hash'].'.jpg';
$icon0 = H.'files/photos/original/'.$photo['id'].''.$photo['hash'].'.jpg';
// Загрузка изображения
$source0 = imagecreatefromstring(file_get_contents($icon0));
$source640 = imagecreatefromstring(file_get_contents($icon640));
$source128 = imagecreatefromstring(file_get_contents($icon128));
$source50 = imagecreatefromstring(file_get_contents($icon50));
// Поворот
$rotate50 = imagerotate($source50, $degrees, 0);
$rotate128 = imagerotate($source128, $degrees, 0);
$rotate640 = imagerotate($source640, $degrees, 0);
$rotate0 = imagerotate($source0, $degrees, 0);
// Ввод
if (is_file(H.'files/photos/size50/'.$photo['id'].''.$photo['hash'].'.jpg'))
unlink(H.'files/photos/size50/'.$photo['id'].''.$photo['hash'].'.jpg');
imagejpeg($rotate50, H.'files/photos/size50/'.$photo['id'].''.$photo['hash'].'.jpg');
if (is_file(H.'files/photos/size100/'.$photo['id'].''.$photo['hash'].'.jpg'))
unlink(H.'files/photos/size100/'.$photo['id'].''.$photo['hash'].'.jpg');
imagejpeg($rotate128, H.'files/photos/size100/'.$photo['id'].''.$photo['hash'].'.jpg');
if (is_file(H.'files/photos/size200/'.$photo['id'].''.$photo['hash'].'.jpg'))
unlink(H.'files/photos/size200/'.$photo['id'].''.$photo['hash'].'.jpg');
imagejpeg($rotate640,H.'files/photos/size200/'.$photo['id'].''.$photo['hash'].'.jpg');
if (is_file(H.'files/photos/original/'.$photo['id'].''.$photo['hash'].'.jpg'))
unlink(H.'files/photos/original/'.$photo['id'].''.$photo['hash'].'.jpg');
imagejpeg($rotate0,H.'files/photos/original/'.$photo['id'].''.$photo['hash'].'.jpg');
header("Location: ?act=edit_photo&id=".$photo['id']."");
exit;
}
$set['title'] = ''.text($photo['name']).'';
include_once '../sys/inc/thead.php';
shapka_VK(true, '?act=photo&id='.$photo['id'].'', 'Фотография');
$cnt = mysql_fetch_assoc(mysql_query("
SELECT COUNT(ph.id) AS 'cnt',
SUM(IF(ph.id > '$photo[id]', 1, 0)) AS 'left',
SUM(IF(ph.id < '$photo[id]', 1, 0)) AS 'right',
(SELECT id FROM photos_user WHERE id > $photo[id] AND id_album = $album[id] ORDER BY id ASC LIMIT 1) AS 'id_left',
(SELECT id FROM photos_user WHERE id < $photo[id] AND id_album = $album[id] ORDER BY id DESC LIMIT 1) AS 'id_right'
FROM photos_user AS ph
WHERE ph.id_album = '$album[id]'
"));
?>
<div class="pcont fit_box">
<div class="media_view photo_view">
<div class="pv_summary">Редактирование фотографии <?php echo ($cnt['left'] + 1); ?> из <?php echo ($cnt['cnt']); ?></div>
<div class="pv_tag_wrap"></div>
<div class="pv_body pv_touch pv_touch_full pv_icons_hide">
<a class="thumb_item" href="/files/photos/size200/<?= $photo['id'] . $photo['hash']?>.jpg"><div class="pv_photo_wrap" id="pv_photo_tags" onclick="return photo.closeTags(event);">
<img src="/files/photos/size200/<?= $photo['id'] . $photo['hash']?>.jpg" class="ph_img" alt=""></div>
</a>
<div class="pv_nav">
<table class="row_table pv_nav_cont"><tbody><tr>
<?
if($cnt['left']){
?>
<td class="pv_nav_left">
<a href="?act=edit_photo&id=<?= $cnt['id_left']?>" class="pv_nav_link" onclick="return photo.prev(event);">
<span class="pv_icon" style="opacity: 1;"><i class="i_icon"></i></span>
<span class="pv_nav_label">« пред.</span>
</a>
</td>
<?
}
?>
<td class="pv_nav_z">
<a href="/files/photos/original/<?= $photo['id'] . $photo['hash']?>.jpg" class="pv_nav_link" onclick="return photo.fullscreen('/files/photos/original/<?= $photo['id'] . $photo['hash']?>.jpg', event);">
<span class="pv_icon"><i class="i_icon"></i></span>
</a>
</td>
<?
if($cnt['right']){
?>
<td class="pv_nav_right">
<a href="?act=edit_photo&id=<?= $cnt['id_right']?>" class="pv_nav_link" onclick="return photo.next(event);">
<span class="pv_icon" style="opacity: 1;"><i class="i_icon"></i></span>
<span class="pv_nav_label">след. »</span>
</a>
</td>
<?
}
?>
</tr></tbody></table>
</div>
</div>
</div>
<div class="pv_footer bl_cont">
<div class="form_item">
<div class="fi_row">
<table class="row_table"><tbody><tr>
<td class="row_table_column" width="50%">
<a class="button wide_button" href="?act=edit_photo&id=<?= $photo['id']?>&rotate=left">Повернуть влево</a>
</td>
<td class="row_table_last_column" width="50%">
<a class="button wide_button" href="?act=edit_photo&id=<?= $photo['id']?>&rotate=right">Повернуть вправо</a>
</td>
</tr></tbody></table>
</div>
<form action="?act=edit_photo&id=<?= $photo['id']?>" method="post">
<dl class="fi_row">
<dt class="fi_label">Название фотографии:</dt>
<dd class="iwrap">
<input class="textfield" name="name" value="<?= text($photo['name'])?>" placeholder="Название" type="text">
</dd>
</dl>
<dl class="fi_row">
<dt class="fi_label">Описание фотографии:</dt>
<dd class="iwrap">
<textarea name="text" class="textfield" rows="4" placeholder="Описание"><?= text($photo['msg'])?></textarea>
</dd>
</dl>
<dl class="fi_row">
<dt class="fi_label">Альбом фотографии:</dt>
<dd>
<select name="aid">
<?
$q = mysql_query("SELECT * FROM `photos` WHERE `id_user` = '$ank[id]' ORDER BY `id` DESC");
while ($album_id = mysql_fetch_assoc($q))
{
?>
<option <?= ($album['id'] == $album_id['id'] ? 'selected="selected"' : null)?> value="<?= $album_id['id']?>"><?= text($album_id['name'])?></option>
<?
}
?>
</select>
</dd>
</dl>
<div class="fi_row">
<input class="button" value="Сохранить" name="cfms" type="submit">
<div class="near_btn"><a href="?act=photo&id=<?= $photo['id']?>">Отмена</a></div>
</div>
</form>
</div></div>
</div>
<?
}
else{
header("Location: /?");
exit;
}