<?php
/*
=====================================================
Файл: edit_foto.php
-----------------------------------------------------
Назначение: Загрузка и редактирование основного фото (аватара)
=====================================================
*/
if( ! defined( 'DATALIFEENGINE' ) ) {
die( "Hacking attempt!" );
}
include_once ENGINE_DIR . '/classes/parse.class.php';
// Обновление информации о пользователе
if( $allow_userinfo and $doaction == "adduserinfo" ) {
if( $_POST['dle_allow_hash'] == "" or $_POST['dle_allow_hash'] != $dle_login_hash ) {
die( "Hacking attempt! User ID not valid" );
}
$row = $db->super_query( "SELECT * FROM " . USERPREFIX . "_users WHERE name = '$user'" );
$image = $_FILES['image']['tmp_name'];
$image_name = $_FILES['image']['name'];
$image_size = $_FILES['image']['size'];
$img_name_arr = explode( ".", $image_name );
$type = end( $img_name_arr );
if( $image_name != "" ) $image_name = totranslit( stripslashes( $img_name_arr[0] ) ) . "." . totranslit( $type );
// Загрузка файла
if( is_uploaded_file( $image ) and ! $stop ) {
if( intval( $user_group[$member_id['user_group']]['max_foto'] ) > 0 ) {
if( $image_size < 100000 ) {
$allowed_extensions = array ("jpg", "png", "jpe", "jpeg", "gif" );
if( (in_array( $type, $allowed_extensions ) or in_array( strtolower( $type ), $allowed_extensions )) and $image_name ) {
include_once ENGINE_DIR . '/classes/thumb.class.php';
$res = @move_uploaded_file( $image, ROOT_DIR . "/uploads/fotos/" . $row['user_id'] . "." . $type );
if( $res ) {
@chmod( ROOT_DIR . "/uploads/fotos/" . $row['user_id'] . "." . $type, 0666 );
$thumb = new thumbnail( ROOT_DIR . "/uploads/fotos/" . $row['user_id'] . "." . $type );
if( $thumb->size_auto( $user_group[$member_id['user_group']]['max_foto'] ) ) {
$thumb->jpeg_quality( $config['jpeg_quality'] );
$thumb->save( ROOT_DIR . "/uploads/fotos/foto_" . $row['user_id'] . "." . $type );
} else {
@rename( ROOT_DIR . "/uploads/fotos/" . $row['user_id'] . "." . $type, ROOT_DIR . "/uploads/fotos/foto_" . $row['user_id'] . "." . $type );
}
@chmod( ROOT_DIR . "/uploads/fotos/foto_" . $row['user_id'] . "." . $type, 0666 );
$foto_name = "foto_" . $row['user_id'] . "." . $type;
$db->query( "UPDATE " . USERPREFIX . "_users set foto='$foto_name' where name='$user'" );
} else
$stop .= $lang['news_err_14'];
} else
$stop .= $lang['news_err_15'];
} else
$stop .= $lang['news_err_16'];
} else
$stop .= $lang['news_err_32'];
@unlink( ROOT_DIR . "/uploads/fotos/" . $row['user_id'] . "." . $type );
}
// Удаление фото
if( $_POST['del_foto'] == "yes" ) {
@unlink( ROOT_DIR . "/uploads/fotos/" . $row['foto'] );
$db->query( "UPDATE " . USERPREFIX . "_users set foto='' WHERE name='$user'" );
}
$db->free();
}
// Просмотр профиля пользователя
$parse = new ParseFilter( );
$user_found = FALSE;
if (is_numeric($user))
$sql_result = $db->query("SELECT * FROM " . USERPREFIX . "_users where user_id = '$user'");
else $sql_result = $db->query("SELECT * FROM " . USERPREFIX . "_users where name = '$user'");
// подгружаем шаблон
$tpl->load_template( 'user_edit_foto.tpl' );
while ( $row = $db->get_row( $sql_result ) ) {
$user_found = TRUE;
if( $row['banned'] == 'yes' ) $user_group[$row['user_group']]['group_name'] = $lang['user_ban'];
// вывод текущего фото
if( $row['foto'] and (file_exists( ROOT_DIR . "/uploads/fotos/" . $row['foto'] )) ) $tpl->set( '{foto}', $config['http_home_url'] . "uploads/fotos/" . $row['foto'] );
else $tpl->set( '{foto}', "{THEME}/images/noavatar.png" );
// показываем только зареганным пользователям
if( $is_logged and ($member_id['user_id'] == $row['user_id'] or $member_id['user_group'] == 1) ) {
$tpl->set( '[not-logged]', "" );
$tpl->set( '[/not-logged]', "" );
} else
$tpl->set_block( "'\\[not-logged\\](.*?)\\[/not-logged\\]'si", "<!-- profile -->" );
if( $config['allow_alt_url'] == "yes" ) $link_profile = $config['http_home_url'] . "user_edit_foto/" . urlencode( $row['user_id'] ) . "/";
else $link_profile = $PHP_SELF . "?do=user_edit_foto&user=" . urlencode( $row['user_id'] );
if( $is_logged and ($member_id['user_id'] == $row['user_id'] or $member_id['user_group'] == 1) ) {
$tpl->copy_template = "<form method=\"post\" name=\"userinfo\" id=\"userinfo\" enctype=\"multipart/form-data\" action=\"{$link_profile}\">" . $tpl->copy_template . "
<input type=\"hidden\" name=\"doaction\" value=\"adduserinfo\" />
<input type=\"hidden\" name=\"dle_allow_hash\" value=\"{$dle_login_hash}\" />
</form>";
}
$tpl->compile( 'content' ); // компилим шаблон
}
$tpl->clear(); // очищаем
$db->free( $sql_result );
if( $user_found == FALSE ) {
$allow_active_news = false;
msgbox( $lang['all_err_1'], $lang['news_err_26'] );
}
?>