// WR-Gallery v 1.3 // 16.09.07 г. // Miha-ingener@yandex.ru // mod 790
error_reporting(0);
if (!is_file("config.php")) {Header("Location: admin.php"); exit;}
include "config.php";
$shapka="
";
$ip=$_SERVER["REMOTE_ADDR"];
//$se=md5(date("ymdH"));
//$se=md5($ip);
$se=crc32($ip);
//$se=$ip;
//@$ref = $_SERVER['HTTP_REFERER'];
if (isset($_GET['se'])) {$se2=$_GET['se'];} else {$se2="";}
// Лог флуд ботов -------------
//------------------------------------------
if (isset($_GET['gid'])) {$gid=$_GET['gid'];} else {if(isset($_GET['msnum'])){$gid=0;} else {$gid=-1;}} // Текущая тема
if (isset($_GET['page'])) {$page=$_GET['page'];} else {$page=1;} // Страницы
if (is_file("listgallery.dat")) {$list=file("listgallery.dat");} // Список тем
// Список категорий ----------------------
function listcat($event){
GLOBAL $list;
GLOBAL $limitnew;
GLOBAL $gid;
$listcat="";
if($limitnew || $list){
$listcat=" Последние".($limitnew?" $limitnew":"")."";
$listcat.="◊Все";
}
if (isset($list)) {
$listcat.="
Темы: ";
foreach($list as $str){
$listdt=explode("|", trim($str));
$listcat.="$listdt[1]₪";
}
}
return $listcat;
}
// ---------------------------------------
// Название темы -------------------------
function themename($gid){
GLOBAL $list;
$tname="";
foreach($list as $str){
if(strtok($str, "|")==$gid){
$tname=strtok("|");
break;
}
}
return $tname;
}
// -----------------------------------------
/***********************************************************************************
Функция img_resize(): генерация thumbnails
Параметры:
$src - имя исходного файла
$dest - имя генерируемого файла
$width, $height - ширина и высота генерируемого изображения, в пикселях
$size - текущие размеры
$quality - качество генерируемого JPEG, по умолчанию - максимальное (100)
***********************************************************************************/
function img_resize($src, $dest, $width, $height, $size, $name, $quality=80)
{
if (!file_exists($src)) return false;
if ($size==false) return false;
// Определяем исходный формат по MIME-информации, предоставленной
// функцией getimagesize, и выбираем соответствующую формату
// imagecreatefrom-функцию.
$format=substr(strstr($size['mime'], '/'), 1);
$icfunc="imagecreatefrom".$format;
if (!function_exists($icfunc)) return false;
// Увеличение лимита памяти для фоток больше 3000х2000
if ($size[0]>3000 || $size[1]>2000) {ini_set("memory_limit", "128M");}
$isrc = $icfunc($src);
$idest = imagecreatetruecolor($width, $height);
//imageInterlace($idest,1); // чередование 1-вкл. 0-выкл.
imagecopyresampled($idest, $isrc, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
// выводим надпись ---------------------------
if($width>200){
GLOBAL $watermark_w, $watermark_h;
function _Kiril_latin ($path){return strtr($path,array("а"=>"a", "б"=>"b", "в"=>"v", "г"=>"g", "д"=>"d", "е"=>"e", "ё"=>"jo", "ж"=>"zh", "з"=>"z", "и"=>"i", "й"=>"j", "к"=>"k", "л"=>"l", "м"=>"m", "н"=>"n", "о"=>"o", "п"=>"p", "р"=>"r", "с"=>"s", "т"=>"t", "у"=>"u", "ф"=>"f", "х"=>"x", "ц"=>"c", "ч"=>"ch", "ш"=>"sh", "щ"=>"shh", "ъ"=>"''", "ы"=>"y", "ь"=>"'", "э"=>"je", "ю"=>"ju", "я"=>"ya", "йо"=>"j/o", "йе"=>"j/e", "А"=>"A", "Б"=>"B", "В"=>"V", "Г"=>"G", "Д"=>"D", "Е"=>"E", "Ё"=>"JO", "Ж"=>"ZH", "З"=>"Z", "И"=>"I", "Й"=>"J", "К"=>"K", "Л"=>"L", "М"=>"M", "Н"=>"N", "О"=>"O", "П"=>"P", "Р"=>"R", "С"=>"S", "Т"=>"T", "У"=>"U", "Ф"=>"F", "Х"=>"X", "Ц"=>"C", "Ч"=>"CH", "Ш"=>"SH", "Щ"=>"SHH", "Ъ"=>"''", "Ы"=>"Y", "Ь"=>"'", "Э"=>"JE", "Ю"=>"JU", "Я"=>"YA", "ЙО"=>"J/O", "ЙЕ"=>"J/E")); }
$host=$_SERVER["HTTP_HOST"]; // Хост галереи
//$host=_Kiril_latin($host);
//$colororanj = imagecolorallocate($idest, 255, 100, 0); // Оранжевый
$textcolor = imagecolorallocate($idest, 255, 255, 255); // Цвет текста белый
$backcolor = imagecolorallocate($idest, 0, 0, 0); // Цвет каймы текста чёрный
// текст горизонтально -----------------------------------------
if ($watermark_w==1){
$texthx=$width-strlen($host)*7.25; // X горизонтального текста
$texthy=$height-15; // Y горизонтального текста
// кайма текст горизонтально
imagestring($idest, 3, $texthx-1, $texthy, $host, $backcolor);
imagestring($idest, 3, $texthx+1, $texthy, $host, $backcolor);
imagestring($idest, 3, $texthx, $texthy-1, $host, $backcolor);
imagestring($idest, 3, $texthx, $texthy+1, $host, $backcolor);
// -------------------------
imagestring($idest, 3, $texthx, $texthy, $host, $textcolor);
}
// ---------------------------------------------------------------
// текст вертикально ---------------------------------------------
if ($watermark_h==1 && $_POST['name']){
$textvx=$width-16; // X вертикального текста
$textvy=$height-20; // Y вертикального текста
$copyrite=_Kiril_latin($name);
// кайма текст вертикально
imagestringup($idest, 3, $textvx-1, $textvy, $copyrite, $backcolor);
imagestringup($idest, 3, $textvx+1, $textvy, $copyrite, $backcolor);
imagestringup($idest, 3, $textvx, $textvy-1, $copyrite, $backcolor);
imagestringup($idest, 3, $textvx, $textvy+1, $copyrite, $backcolor);
// -----------------------
imagestringup($idest, 3, $textvx, $textvy, $copyrite, $textcolor);
}
// -------------------------------------------------------------
}
imagejpeg($idest, $dest, $quality);
@chmod("$dest", 0644);
imagedestroy($isrc);
imagedestroy($idest);
return true;
}
// ------------------------------------
// Сообщение --------------------------------
function error($err){
GLOBAL $shapka;
echo "$shapka
$err
"; exit;
}
// -----------------------------------------
if (isset($_GET['event'])) {
$event=$_GET['event'];
// Идентификация админа --------------
$pswrd="";
$admin="";
if (isset($_POST['pswrd'])){$pswrd=$_POST['pswrd'];}
if (isset($_GET['pswrd'])){$pswrd=$_GET['pswrd'];}
if($pswrd==$password){$admin=1;}
// -----------------------------------
// Добавление комментария или файла ------------------------
if (($event=="addmsg" && ($freemsg==1 || $admin)) || ($event=="add" && ($freepost==1 || $admin))) {
$msg=$_POST['msg'];
$name=$_POST['name'];
$msg=trim($msg);
$name=trim($name);
$msg=str_replace("|","I",$msg);
$name=str_replace("|","I",$name);
// спам-щит если больше одной ссылки - спам.
if (((substr_count(strtolower($msg), "http:")>1) || (stristr($msg, " href")) || (stristr($msg, "url="))) && !$admin){error("Спам!");}
// -----------------------------------
$email=$_POST['email'];
$email=trim($email); // Вырезаем с концов ПРОБЕЛьные символы
$email=str_replace("|","I",$email); // чтоб БД не "уронили"!
if($name=="" && !$admin){$name=$ip;}
if (strlen($msg)>$maxmsg){$obrez=(strlen($msg)-$maxmsg); $msg=substr_replace($msg, "...", $maxmsg); echo "
Ваше сообщение было обрезано на $obrez смволов.";}
//if (!eregi("^([0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-wyz][a-z](fo|g|l|m|mes|o|op|pa|ro|seum|t|u|v|z)?)$", $email) || (strlen($email) > $maxzag)){error("$back и введите корректный E-mail адрес!"}
if ($event=="addmsg") {
if (isset($_GET['msnum'])) {$msnum=$_GET['msnum'];} else {error("Ошибка - нет ID файла!");}
if ($msg=="") {error("$back Комментарий пуст.");}
// проверка ID коммента -------------
$lines=file($datafile);
$i=count($lines);
while($i-->0){
$lin=explode('|',$lines[$i]);
if ($lin[10]==$msnum){
$msnum=$lin[10];
break;
}
}
if ($i<0) {error("Балуемся?");}
// ----------------------------------
if (isset($_POST['type']) && ctype_digit($_POST['type']) && $_POST['type']>0 && $_POST['type']<11) {$type=$_POST['type'];} else {$type="";}
$bevent=$_GET['bevent'];
// 0 имя|1 емайл|2 коммент|3 дата|4 оценка|6 ip|
$day=mktime();
$text="$name|$email|$msg|$day|$type|$ip|";
$recfile="$datadir/$msnum.dat";
} else {
@set_time_limit(0);
$fotoname=$_FILES['file']['name']; // загрузка файла
$ext=strtolower(substr(strrchr($fotoname, "."), 1)); // расширение файла
// Контроль типа
$type_file=$_FILES['file']['type'];
if (stristr($type_file, "image/bmp")){error("$back Загрузка файлов BMP запрещена.
Откройте его в Paint и сохраните как JPEG или отправьте в архиве.");}
if (stristr($type_file, "xml") || stristr($type_file, "htm") || stristr($ext, "php") || stristr($ext, "htm") || stristr($ext, "exe")){error("$back загрузка таких файлов запрещена.
Запакуйте его в архив.");}
// -------------
$id=date("YmdHis");
$fotoname=$id.".".$ext; // Переименовываем в цифровой код
//$fotoname=uniqid("").".".$ext; // Альтернативный код
// 4. Проверяем, может быть файл с таким именем уже есть на сервере
if (file_exists("$datadir/$fotoname")) {error("$back Неудача! Попробуйте повторить.");}
$fotosize=$_FILES['file']['size']; // размер файла
if(!move_uploaded_file($_FILES['file']['tmp_name'], $datadir."/".$fotoname)){error("$back Не удалось сохранить файл!");}
$fotoksize=round($fotosize/10.24)/100; // размер в Кб.
$size=getimagesize("$datadir/$fotoname");
// Превью ----------------------------------------------
if ($size[0]>=$smwidth || $size[1]>=$smheight) {
$smallfoto="sm-$fotoname";
$reswidth=$smheight*$size[0]/$size[1];
if ($reswidth>$smwidth){
$reswidth=$smwidth;
$resheight=$smwidth*$size[1]/$size[0];
} else {$resheight=$smheight;}
if(!img_resize("$datadir/$fotoname", "$datadir/$smallfoto", $reswidth, $resheight, $size, $name)){$smallfoto="$fotoname";}
} else {$smallfoto="$fotoname";}
// ------------------------------------------------------
if(isset($_POST['gid'])){$gid=$_POST['gid'];}
// Если больше 100 Кб жать. Кроме гифов -------------
//if ($size[0]>$maxwidth || $size[1]>$maxheight) { // От размера
if ($fotosize>$max_file_size && $size[1]>0 && $ext!="gif") { // От веса
$reswidth=$maxheight*$size[0]/$size[1];
if ($reswidth>$maxwidth){
$reswidth=$maxwidth;
$resheight=$maxwidth*$size[1]/$size[0];
} else {$resheight=$maxheight;}
img_resize("$datadir/$fotoname", "$datadir/$fotoname", $reswidth, $resheight, $size, $name);
} else {
if($ext!="gif"){img_resize("$datadir/$fotoname", "$datadir/$fotoname", $size[0], $size[1], $size, $name);}
}
// ------------------------------------------------------
@chmod("$datadir/$fotoname", 0644); // Для AGAVA
clearstatcache(); // очистка кеша, иначе не смотрит новый размер
$fotoksize=round(filesize("$datadir/$fotoname")/10.24)/100;
$size=getimagesize("$datadir/$fotoname");
$recfile="$datafile";
// Иконки по типам файлов
switch($ext){
case "zip": case "rar": case "cab": case "7z": case "arj": $smallfoto="../images/rar.gif"; break;
case "avi": case "3gp": case "flv": case "wmv": case "mp4": case "mpeg": case "mpg": case "mpe": case "mov": $smallfoto="../images/video.gif"; break;
case "midi": case "mid": case "kar": case "wav": case "mp3": case "wma": $smallfoto="../images/mus.gif"; break;
case "txt": case "doc": case "djvu": case "mht": $smallfoto="../images/txt.gif"; break;
case "chm": $smallfoto="../images/winhelp.gif"; break;
case "pdf": $smallfoto="../images/pgf.gif"; break;
case "swf": $smallfoto="../images/swf.gif"; break;
default: if($size[1]==0){$smallfoto="../images/file.gif";}
}
// 0 собщение|1 ник|2 емайл|3 дата|4 время|5 фото_малое|6 фото_большое|7 размер_Кб|8 ширина|9 высота|10 UID|11 Рейтинг|12 Проголосовало|13 Категория|14 ip|
$text="$msg|$name|$email|$date|$time|$smallfoto|$fotoname|$fotoksize|$size[0]|$size[1]|$id|-1|0|$gid|$ip|";
}
$text=str_replace( " " ,' ' ,$text);
$text=str_replace( "&" ,'&' ,$text);
$text=str_replace( "" ,'-->' ,$text);
$text=preg_replace( "/
");} else {
error("
Комментарий добавлен.
");
}
exit;
}
// Конец добавление комментария или файла ------------------------
// Форма загрузки ----------------------------------------
elseif ($event=="addform") {
if ($freepost==1 || $admin){
if ($se2==$se) { // бот-щит 2
//if ($ref){ // бот-щит 3
//if ($gid<=0) {$gid=1;} // Тема для загрузки по умолчанию
echo "$shapka
Разрешена загрузка файлов размером не более ".ini_get('upload_max_filesize')."