Файл: foto/img.php
Строк: 38
<?php
include_once $_SERVER['DOCUMENT_ROOT'].'/sys/inc/home.php';
include_once H.'sys/inc/start.php';
include_once H.'sys/inc/sess.php';
include_once H.'sys/inc/settings.php';
$p = (int) $_GET['id'];
if (isset($_GET['size'])) {
$w = $z = (int) $_GET['size'];
}
$u = (isset($_SESSION['id_user']) ? $_SESSION['id_user'] : -1);
$pwd = (isset($_SESSION['pass']) ? $_SESSION['pass'] : 0);
$cache = new Cache(600);
// Размеры для кеширования
$cached = array(50, 128, 640);
$cacheLv = 'photo_access.'.$u.'.'.$p;
$access = $cache->read($cacheLv);
if ($access) {
$p = $access;
}
$cacheId = false;
if (isset($w) && in_array($w, $cached) && $w != 0) {
$cacheId = 'photo.'.$p.'.'.$w;
if ($w == 50) {
$w = (int) $set['photo_size_50'];
} elseif ($w == 128) {
$w = (int) $set['photo_size_128'];
} elseif ($w == 640) {
$w = (int) $set['photo_size_640'];
}
}
$imageCache = $cache->read($cacheId, false, true);
if (!$access && $p) {
include_once H.'sys/inc/db_connect.php';
$photo = mysql_fetch_assoc(mysql_query("
SELECT ph.id, ph.name, ph.avatar, pg.privat, pg.pass, pg.id_user, pu.group_access, pu.level, ps.privat_str, IF (pf.user, 1, 0) AS frends
FROM gallery_foto AS ph
JOIN gallery AS pg ON ph.id_gallery = pg.id
JOIN user AS pu ON pu.id = pg.id_user
LEFT JOIN user_set AS ps ON ps.id_user = pg.id_user
LEFT JOIN frends AS pf ON (pf.user = '$u' AND pf.frend = pg.id_user) OR (pf.user = pg.id_user AND pf.frend = '$u')
WHERE ph.id = '$p'
"));
if ($u != $photo['id_user'] && $photo['avatar'] == 0) {
if ($photo['privat_str'] == 0 || (($photo['privat_str'] == 2 || $photo['privat'] == 1) && !$photo['frends']) || $photo['privat'] == 2) {
$p = 0;
}
if ($photo['privat'] == 3) {
if ($pwd != $photo['pass']) {
$p = 0;
}
}
}
if ($u && $p == 0) {
$user = mysql_fetch_assoc(mysql_query("
SELECT * FROM user
WHERE id = '$u'
"));
if ($user['group_access'] > $photo['group_access']) {
$p = $photo['id'];
}
}
if (!$access) {
$access = $cache->write($cacheLv, $p);
}
}
if ($imageCache) {
$file = $imageCache;
}
else {
$file = H.'sys/gallery/foto/' . $p . '.jpg';
}
$image = $foo = new upload($file);
header('Cache-control: public');
header('Expires: ' . gmdate("D, d M Y H:i:s", time() + 60*60*24*7) . ' GMT');
header('Content-type: ' . $image->file_src_mime);
if ($imageCache) {
die($image->Process());
}
if (isset($_GET['crop']))
{
$image->image_resize = true;
if (preg_match('/^([0-9]{1,3}x[0-9]{1,3})$/i', $_GET['crop']))
{
$prop = explode('x', $_GET['crop']);
if ($prop[0] > 0 && $image->image_src_x > $prop[0])
$image->image_x = (int) $prop[0];
if ($prop[1] > 0 && $image->image_src_y > $prop[1])
$image->image_y = (int) $prop[1];
$image->image_ratio_crop = true;
}
elseif (preg_match('/^([0-9]{1,3})$/i', $_GET['crop']))
{
if ($image->image_src_x > $_GET['crop']) {
$image->image_x = $_GET['crop'];
$image->image_ratio_y = true;
}
}
}
elseif (isset($w) && $w && $image->image_src_x > $w) {
$image->image_resize = true;
$image->image_x = $w;
if ($z == 50) {
$image->image_y = $w;
$image->image_ratio_crop = true;
} else {
$image->image_ratio_y = true;
}
}
$output = $image->Process();
if (!$imageCache) {
$cache->write($cacheId, $output);
}
die($output);