Вход Регистрация
Файл: public_html/modules/user/album.php
Строк: 304
<?php
/**********************************
*    @package: PerfCMS              *
*    @year: 2013                      *
*    @author: Master301              *
*    @icq: 647767701                   *
**********************************/
ob_start();
if(!isset(
$user)) {
    
header('location: /');
    exit;
}

function 
replece_ext_photo($file) { $file = str_replace('.JPG','',$file);
$file = str_replace('.JPEG','',$file);
$file = str_replace('.GIF','',$file);
$file = str_replace('.PNG','',$file);
$file = str_replace('.jpg','',$file);
$file = str_replace('.jpeg','',$file);
$file = str_replace('.gif','',$file);
$file = str_replace('.png','',$file);
$file .= '.png';return $file;
}

function 
album_add_photo($file) { if ($file['name'] and !$file['error']) { if($_FILES['pic']['size'] < 2000*1024) { $p = pathinfo($file['name']);
$ext = strtolower($p['extension']);
$ext_full = $p['extension'];
if(
$ext == 'jpg' or $ext == 'png' or $ext == 'gif') { $doc = ROOT.'/files/albums/';
$name = ''.time().'.'.$ext;
if (
is_uploaded_file($file['tmp_name'])) { if (file_exists($doc.$name)) { unlink($doc.$name);
}
if (
copy($file['tmp_name'], $doc.$name)) {
$con_name = input($file['name']);
$con2_name = str_replace('.'.$ext_full,'',$con_name);
return 
'yes___'.$name.'_***_***_'.$con2_name.'_***_***_'.str_replace($ext_full,'',$name);
}
}
} else { return 
3; }
} else { return 
2; }
}
return 
false;
}
function 
res_user_nick($id) { global $db; $q = $db->query("select * from `users` where `id`='".$id."'");
if (
$q->rowcount()) { $row = $q->fetch();
if (!empty(
$row['nick'])) { return $row['nick'];
}
}
return 
'<u>Удалён</u>';
}
$page = htmlspecialchars(mysql_real_escape_string($_GET['page'])); if (empty($page)) {$page = 1;}

$locate = 'in_profile';
$id = abs(intval($_GET['id']));
$nid = $db->query("select * from `photoalbums` where `id`='".$id."' and `users`='".$user['id']."'")->rowcount();
if (
$id and $nid) { $a = $db->query("select * from `photoalbums` where `id`='".$id."' and `users`='".$user['id']."'")->fetch();
$photo = abs(intval($_GET['photo']));
$view_photo = 0;
if (
$photo) { $vi = $db->query("select * from `photoalbums_items` where `id`='".$photo."' and `album`='".$id."'");
if (
$vi->rowcount()) { if ($_POST['commentary']) { $msg = input($_POST['msg']);
if (
strlen($msg) < 500 and !empty($msg)) { $db->query("insert into `photoalbums_comm` (`photo`,`msg`,`users`,`time`) values ('".$photo."','".$msg."','".$user['id']."','".time()."')");
header('location: /user/album/?id='.$id.'&photo='.$photo.'');
}
}
$view_photo = 1;
$via = $vi->fetch();
$set = input($_GET['set']);
if (
$set == 'del') { $otv = input($_GET['otv']);
if (
$otv == 'no') {
header('location: /user/album/?id='.$id.'&photo='.$photo.'');
}
if (
$otv == 'yes') { $file = ROOT.'/files/albums/'.$via['pic'];
if (
file_exists($file)) {unlink($file);}
$file = ROOT.'/files/albums/preview/'.replece_ext_photo($via['pic']);
if (
file_exists($file)) {unlink($file);}
$db->query("delete from `photoalbums_rating` where `photo`='".$via['id']."'");
$db->query("delete from `photoalbums_comm` where `photo`='".$via['id']."'");
$db->query("delete from `photoalbums_items` where `id`='".$via['id']."'");
header('location: /user/album/?id='.$id.'&photo='.$photo.'');
}

$title = $via['name'];
require_once(
SYS.'/view/header.php');
$tpl->div('title', '<b><a href="/user/album/?id='.$id.'">'.$a['name'].'</a> &#187; <a href="/user/album/?id='.$id.'&photo='.$photo.'">'.$via['name'].'</a> &#187; Удаление</b>');
$tpl->div('menu','Действительно хотите удалить фото "'.$via['name'].'"?<br/><a href="/user/album/?id='.$id.'&photo='.$photo.'&set=del&otv=yes">Да</a> | <a href="/user/album/?id='.$id.'&photo='.$photo.'&set=del&otv=no">Нет</a><br/>');
} else {

$title = $via['name'];
require_once(
SYS.'/view/header.php');
$tpl->div('title', '<b><a href="/user/album/?id='.$id.'">'.$a['name'].'</a> &#187; '.$via['name'].'</b>');
if (!empty(
$via['opis'])) {$opis = '<br/>'.output($via['opis']).'';} else {$opis = '';}
if (
file_exists(ROOT.'/files/albums/preview/'.replece_ext_photo($cfa['pic']))) {
$post = '<a href="/files/albums/preview/'.$via['pic'].'"><img src="/files/albums/'.$via['pic'].'" style="max-width: 300px; max-height: 350px;" alt="'.$via['name'].'"/></a>'.$opis.'<br/>';
} else {
$post = '<a href="/files/albums/'.$via['pic'].'"><img src="/files/albums/'.$via['pic'].'" style="max-width: 300px; max-height: 350px;" alt="'.$via['name'].'"/></a>'.$opis.'<br/>';
}
$post .= 'Альбом: <a href="/user/album/?id='.$id.'">'.$a['name'].'</a><br/>';
$fetch_user = $db->query("select * from `users` where `id`='".$a['users']."' limit 1")->fetch();
$add_users = $fetch_user['nick'];
$post .= 'Добавил: <a href="/user/'.$a['users'].'/">'.$add_users.'</a><br/>';
$post .= 'Дата: '.rtime($via['time']).'<br/>';
$post .= '[<a href="/user/album/?id='.$id.'&photo='.$photo.'&set=del">удалить</a>]';
$tpl->div('menu',$post);
$tpl->div('title','Комментарии');
$komrow = $db->query("select * from `photoalbums_comm` where `photo`='".$via['id']."'")->rowcount();
$pages = new Paginator($komrow, $ames);
if (
$komrow) { if ($komrow > 1) {
$kom = $db->query("select * from `photoalbums_comm` where `photo`='".$via['id']."' order by `id` desc limit $start, $ames");
} else {
$kom = $db->query("select * from `photoalbums_comm` where `photo`='".$via['id']."'");
}
while (
$comm = $kom->fetch()) { $comm_post = res_user_nick($comm['users']).' ('.rtime($comm['time']).')<br/>'.output($comm['msg']).'<br/>';
$tpl->div('menu',$comm_post);
}

} else {
$tpl->div('menu','Нет комментариев!');
}
$pages->view('/user/album/?id='.$id.'&photo='.$photo.'&');
$form_post = '<form action="" method="POST">';
$form_post .= 'Сообщение: <br/>';
$form_post .= '<textarea name="msg"></textarea><br/>';
$form_post .= '<input type="submit" name="commentary" value="Добавить"/><br/>';
$form_post .= '</form>';
$tpl->div('menu',$form_post);
}
}
}
if (!
$view_photo) {
////////////////
$add = input($_GET['add']);
if (
$add == 'photo') { $title = $a['name'];
require_once(
SYS.'/view/header.php');
$tpl->div('title', '<b><a href="/user/album/?id='.$id.'">'.$a['name'].'</a> &#187; Новое фото</b>');
if (
$_POST) {
$opis = input($_POST['opis']);
if (!
$opis) {$opis = '';}
if (
strlen($opis) > 1000) { $err = 'Описание слишком длинное!';
}
$upload = album_add_photo($_FILES['pic']);
if (
preg_match("/yes___/i",$upload) and strlen($opis) < 1000) { $file = str_replace('yes___','',$upload);
$fil = explode('_***_***_',$file);
//////////////

import_lib('upload.class');
$handle = new upload(ROOT.'/files/albums/'.$fil[0]);
if (
$handle->uploaded) {
$handle->allowed = array('image/*');
$handle->file_new_name_body     = $fil[3];
$handle->image_convert         = $ext;
$handle->image_resize            = true;
$handle->image_x                = 300;
$handle->image_y                = 350;
$size=getimagesize(ROOT.'/files/albums/'.$fil[0]);
if (
$size) {
$width=$size[0];
$height=$size[1];
}
if (
$width < 300 and $height < 350) {
$handle->image_x                = $width;
$handle->image_y                = $height;
}
$handle->process(ROOT.'/files/albums/preview/'.$fil[3]);
}

//////////////
$db->query("insert into `photoalbums_items` (`album`,`pic`,`name`,`opis`,`time`) values ('".$id."','".$fil[0]."','".$fil[1]."','".$opis."','".time()."')");
$_SESSION['add_photo_msg'] = 'Фото успешно загружено!';
header('location: /user/album/?id='.$id.'&add=photo&page='.$page.'');
exit;
} else { if (
strlen($opis) < 1000) { if ($upload == 2) {$err = 'Фото больше 2MB!';}
if (
$upload == 3) {$err = 'Доступные форматы jpg,png,gif!';} if (!$upload) {$err = 'Фото не загружено!';}
}
echo 
'<div class="error">'.$err.'<br/></div>';
}
}
$photo_msg = input($_SESSION['add_photo_msg']);
if (
$photo_msg) { echo '<div class="menu">'.$photo_msg.'<br/></div>';
$_SESSION['add_photo_msg'] = '';
}
echo 
'<div class="menu">';
echo 
'<form enctype="multipart/form-data" action="" method="POST">';
echo 
'Фото: (<2MB)<br/>';
echo 
'<input type="hidden" name="MAX_FILE_SIZE" value="25000000">';
echo 
'<input type="file" name="pic"/><br/>';
echo 
'Описание:<br/>';
echo 
'<textarea name="opis"></textarea><br/>';
echo 
'<input type="submit" value="Добавить"/><br/>';
echo 
'</form>';
echo 
'</div>';
} else {
$title = $a['name'];
require_once(
SYS.'/view/header.php');
$tpl->div('title', '<b>'.$a['name'].'</b>');
$tpl->div('menu','<a href="/user/album/?id='.$id.'&add=photo">Добавить фото</a><br/>');
$cf = $db->query("select * from `photoalbums_items` where `album`='".$a['id']."'")->rowcount();
if (
$cf) {
$pages = new Paginator($cf, $ames);
$cfq = $db->query("select * from `photoalbums_items` where `album`='".$a['id']."' ORDER BY `id` DESC limit $start, $ames");
while (
$cfa = $cfq->fetch()) { if ($cfa['opis']) {$opis = '<br/>'.output($cfa['opis']).'';} else {$opis = '';}
if (
strlen($opis) > 100) {$opis = substr($opis,0,100);$opis .= '...';}
if (
file_exists(ROOT.'/files/albums/preview/'.replece_ext_photo($cfa['pic']))) { $post = img('photo.png').'<a href="/user/album/?id='.$id.'&page='.$page.'&photo='.$cfa['id'].'">'.$cfa['name'].'<br/><img src="/files/albums/preview/'.replece_ext_photo($cfa['pic']).'" style="max-width: 150px; max-height: 150px;" alt="'.$cfa['name'].'"/></a>'.$opis.'<br/>';
} else {
$post = img('photo.png').'<a href="/user/album/?id='.$id.'&page='.$page.'&photo='.$cfa['id'].'">'.$cfa['name'].'<br/><img src="/files/albums/'.$cfa['pic'].'" style="max-width: 150px; max-height: 150px;" alt="'.$cfa['name'].'"/></a>'.$opis.'<br/>';
}
$row_com = $db->query("select * from `photoalbums_comm` where `photo`='".$cfa['id']."'")->rowcount();
$post .= 'Комментариев: ['.$row_com.']<br/>';
$tpl->div('menu',$post);
}
$pages->view('/user/album/?id='.$id.'&');
} else {
$post = 'Нет фотографий';
$tpl->div('menu',$post);
}
}
///////////////
}
} else {
$add = input($_GET['add']);
$edit = abs(intval($_GET['edit']));
if (
$edit) { $ncz = $db->query("select * from `photoalbums` where `id`='".$edit."' and `users`='".$user['id']."'")->rowcount();
} else {
$ncz = 0;}
if (
$add == 'album' or $ncz) { $title = $lang->word('new_album');
require_once(
SYS.'/view/header.php');
$tpl->div('title', '<b>'.$lang->word('new_album').'</b>');
$err = array();
$win = input($_SESSION['form_add_mss']);
$name = '';
$opis = '';
if (
$_POST) { $name = input($_POST['name']);
$opis = input($_POST['opis']);
if (empty(
$name)) { $err[] = $lang->word('err_post_empty_name');
} else { if (
strlen($name) > 0 and strlen($name) > 50) { $err[] = $lang->word('err_post_length_name');
}
}
if (empty(
$opis)) {
$err[] = $lang->word('err_post_empty_opis');
} else {
if (
strlen($opis) > 0 and strlen($opis) > 250) {
$err[] = $lang->word('err_post_length_opis');
}
}
if (!
count($err)) { if ($edit and $ncz) { $act = $db->query("update `photoalbums` set `name`='".$name."',`opis`='".$opis."' where `id`='".$edit."' and `users`='".$user['id']."'");
$_SESSION['form_add_mss'] = $lang->word('success_edit_album');
} else {
$_SESSION['form_add_mss'] = $lang->word('success_add_album');
$act = $db->query("insert into `photoalbums` (`name`,`opis`,`users`) values ('".$name."','".$opis."','".$user['id']."')");
} if (
$act) {
if (
$edit and $ncz) {
header('location: /user/album/?edit='.$edit.'&page='.$page.'');
} else {
header('location: /user/album/?add=album');
}
} else {
$_SESSION['form_add_mss'] = '';
$err[] = $lang->word('err_post_form_data');
}
}
}
if (
count($err)) {
$err_log = '';
foreach(
$err as $err_val) { $err_log .= $err_val.'!<br/>';
}
$tpl->div('error', $err_log);
}
if (
$win) {
$tpl->div('menu', $win.'!<br>');
$_SESSION['form_add_mss'] = '';
}
if (
$edit and $ncz) { $a = $db->query("select * from `photoalbums` where `id`='".$edit."' and `users`='".$user['id']."'")->fetch();
$name = $a['name'];
$opis = $a['opis'];
}
$form = '<form action="" method="POST">';
$form .= $lang->word('form_album_name').':<br/>';
$form .= '<input type="text" name="name" value="'.$name.'"/><br/>';
$form .= $lang->word('form_album_opis').':<br/>';
$form .= '<textarea name="opis">'.$opis.'</textarea><br/>';
if (
$edit and $ncz) { $form .= '<input type="submit" value="'.$lang->word('form_album_submit_value_edit').'"/><br/>';
} else {
$form .= '<input type="submit" value="'.$lang->word('form_album_submit_value').'"/><br/>';
}
$tpl->div('post', $form);
} else {
$title = $lang->word('user_album');
require_once(
SYS.'/view/header.php');
$tpl->div('title', '<b>'.$lang->word('user_album').'</b>');
$del = abs(intval($_GET['del']));
$nd = $db->query("select * from `photoalbums` where `id`='".$del."' and `users`='".$user['id']."'")->rowcount();
if (
$del and $nd) {
$reply = input($_GET['reply']);
if (
$reply == 'no') { header('location: /user/album/?page='.$page.'');
exit;
}
if (
$reply == 'yes') { $db->query("delete from `photoalbums` where `id`='".$del."'");

$q = $db->query("select * from `photoalbums_items` where `album`='".$del."'");
$n = $q->rowcount();
if (
$n) { while ($a = $q->fetch()) { $file = ROOT.'/files/albums/preview/'.replece_ext_photo($a['pic']); if (file_exists($file)) {unlink($file);}
$file = ROOT.'/files/albums/'.$a['pic'];
if (
file_exists($file)) {unlink($file);}
if (
$q->rowcount()) {
$db->query("delete from `photoalbums_comm` where `photo`='".$a['id']."'");
}
$db->query("delete from `photoalbums_rating` where `photo`='".$via['id']."'");

}
}

$db->query("delete from `photoalbums_items` where `album`='".$del."'");

header('location: /user/album/?page='.$page.'');
exit;
}

$a = $db->query("select * from `photoalbums` where `id`='".$del."' limit 1")->fetch();
$post = $lang->word('del_album_name_quest').' "'.$a['name'].'"?<br/>';
$post .= '<a href="/user/album/?del='.$del.'&page='.$page.'&reply=yes">'.$lang->word('del_otvet_yes').'</a> | <a href="/user/album/?del='.$del.'&page='.$page.'&reply=no">'.$lang->word('del_otvet_no').'</a><br/>';
$tpl->div('menu', $post);
} else {
$tpl->div('menu', '<a href="/user/album/?add=album">'.$lang->word('add_album').'</a><br/>');
$n = $db->query("select * from `photoalbums` where `users`='".$user['id']."'")->rowcount();
$pages = new Paginator($n, $ames);
if (
$n) { $q = $db->query("select * from `photoalbums` where `users`='".$user['id']."' ORDER BY `id` DESC LIMIT $start, $ames");
while(
$a = $q->fetch()) { $num = $db->query("select * from `photoalbums_items` where `album`='".$a['id']."'")->rowcount();
$post = img('album.png').' <a href="/user/album/?id='.$a['id'].'">'.$a['name'].'</a> ('.$num.') <a href="/user/album/?del='.$a['id'].'&page='.$page.'">'.img('delete_11.png').'</a> <a href="/user/album/?edit='.$a['id'].'&page='.$page.'">'.img('edit_11.png').'</a><br/>';
if (!empty(
$a['opis'])) {
if (
strlen($a['opis']) > 100) {$a['opis'] = substr($a['opis'],0,100);$a['opis'] .= '...';}
$post .= ''.output($a['opis']).'<br/>';
}
$tpl->div('menu', $post);
}
$pages->view('/user/album/?');
} else {
$tpl->div('menu', $lang->word('user_not_albums'));
}
}
}
}
if (
$add == 'album' or $nd or ($edit and $ncz) or ($id and $nid)) {$beck_album = NAV .'<a href="/user/album/">'.$lang->word('user_album').'</a><br/>';} else {$beck_album = '';}
$tpl->div('block', $beck_album.NAV .'<a href="/user/panel/">'.$lang->word('user_panel').'</a><br/>'
                    
. HICO .'<a href="/">'. $lang->word('home').'</a>');
require_once(
SYS .'/view/footer.php');
?>
Онлайн: 3
Реклама