Вход Регистрация
Файл: system/function.php
Строк: 121
<?php
/**
*    Author: Elime;
*    ICQ: 618878;
*    E-mail: elime4@gmail.com;
*/

/* Проверка голосования */
function check_vote($file_id, $ip, $db)
{
    
$result = $db->result("SELECT COUNT(*) FROM `like` WHERE `file_id`='".num($file_id)."' AND `ip`='".num($ip)."'");
    if(
$result)
    {
        return 
true;
    }
    else
    {
        return 
false;
    }
}


/* Проверка прав пользователя */
function check_right($user_id, $right, $db)
{
    if(
$user_id == 1) return true;    
    return 
$db->result("SELECT COUNT(*) FROM `rights` WHERE `user_id`='".$user_id."' AND `right`='".$right."'");
}


/* Вывод длительности видео */
function duration($time)
{
    return 
date('i:s', $time);
}


/* Изменение размеров изображения */
function imageresize($infile, $outfile, $neww, $newh, $quality)
{
    
$im = imagecreatefromjpeg($infile);
    
$k1 = $neww / imagesx($im);
    
$k2 = $newh / imagesy($im);
    
$k = $k1 > $k2 ? $k2 : $k1;
    
    
$w = intval(imagesx($im) * $k);
    
$h = intval(imagesy($im) * $k);
    
    
$im1 = imagecreatetruecolor($w, $h);
    
imagecopyresampled($im1, $im, 0, 0, 0, 0, $w, $h, imagesx($im), imagesy($im));
    
    
imagejpeg($im1, $outfile, $quality);
    
imagedestroy($im);
    
imagedestroy($im1);
}


/* Функция рекурсивного удаления папки */
function remove_dir($path)
{
    if(
file_exists($path) && is_dir($path))
    {
        
$dirHandle = opendir($path);
        while (
false !== ($file = readdir($dirHandle)))
        {
            if (
$file!='.' && $file!='..')
            { 
                
$tmpPath = $path.'/'.$file;
                
chmod($tmpPath, 0777);
                if (
is_dir($tmpPath))
                {
                    
remove_dir($tmpPath);
               }
                else
                { 
                      if(
file_exists($tmpPath))
                    { 
                          
unlink($tmpPath);
                    }
                  }
            }
        }
        
closedir($dirHandle);
        if(
file_exists($path))
        {
            
rmdir($path);
        }
    }
    else
    {
        return 
false;
    }
    return 
true;
}


/* Транслит */
function translit($var)
{
    if (
preg_match('/[^A-Za-z0-9_-]/', $var))
    {
        
$tr = array(
            
"А"=>"a", "Б"=>"b", "В"=>"v", "Г"=>"g",
            
"Д"=>"d", "Е"=>"e", "Ж"=>"j", "З"=>"z", "И"=>"i",
            
"Й"=>"y", "К"=>"k", "Л"=>"l", "М"=>"m", "Н"=>"n",
            
"О"=>"o", "П"=>"p", "Р"=>"r", "С"=>"s", "Т"=>"t",
            
"У"=>"u", "Ф"=>"f", "Х"=>"h", "Ц"=>"ts", "Ч"=>"ch",
            
"Ш"=>"sh", "Щ"=>"sch", "Ъ"=>"","Ы"=>"yi", "Ь"=>"",
            
"Э"=>"e", "Ю"=>"yu", "Я"=>"ya", "а"=>"a", "б"=>"b",
            
"в"=>"v", "г"=>"g", "д"=>"d", "е"=>"e", "ж"=>"j",
            
"з"=>"z", "и"=>"i", "й"=>"y", "к"=>"k", "л"=>"l",
            
"м"=>"m", "н"=>"n", "о"=>"o", "п"=>"p", "р"=>"r",
            
"с"=>"s", "т"=>"t", "у"=>"u", "ф"=>"f", "х"=>"h",
            
"ц"=>"ts", "ч"=>"ch", "ш"=>"sh", "щ"=>"sch", "ъ"=>"y",
            
"ы"=>"yi", "ь"=>"", "э"=>"e", "ю"=>"yu", "я"=>"ya", 
            
" "=> "_",  "/"=> "_");
        
$var = strtr($var, $tr);
        
$var = strtolower($var);
        return 
preg_replace('/[^.A-Za-z0-9_-]/', '', $var);
    }
    else
    {
        
$var = strtolower($var);
        return 
$var;
    }
}


/* Вывод размера файла */
function size($in)
{
    if(
$in>=1073741824)
    {
        return 
round($in/1073741824, 2).' GB';
    }
    elseif(
$in>=1048576)
    {
        return 
round($in/1048576, 2).' MB';
    }
    elseif(
$in>=1024)
    {
        return 
round($in/1024, 2).' KB';
    }
    else
    {
        return 
round($in).' B';
    }
}


/* Кодирование IP адреса */
function ip_code($ip)
{
    return 
sprintf("%un", ip2long($ip));
}


/* Декодирование IP адреса */
function ip_decode($ip_code)
{
    return 
long2ip($ip_code);
}


/* Вывод в ремени в человеческом виде */
function timeformat($time = NULL)
{
    
$labelTime = date('d.m.Y', $time);
    
$arrM = array(
        
'01'=>'янв', '02'=>'фев', '03'=>'мар', '04'=>'апр',
        
'05'=>'май', '06'=>'июн', '07'=>'июл', '08'=>'авг',
        
'09'=>'сен', '10'=>'окт', '11'=>'ноя', '12'=>'дек'
    
); 
    
    if(
$labelTime == date('d.m.Y'))
    {
        return 
'Сегодня в '.date('H:i', $time);
    }
    elseif(
$labelTime == (date('d') - 1).'.'.date('m.Y'))
    {
        return 
'Вчера в '.date('H:i', $time);
    }
    else
    {
        return 
date('d', $time).' '.$arrM[date('m', $time)].' '.date('Y', $time).' в '.date('H:i', $time);
    }
}


/* Правильное склонение слова */
function ru_word($number, $votes = array('часов', 'час', 'часа'))
{
    
$numberLast = intval(substr(strval($number),-1,1));
    
$numberPreLast = intval(substr(strval($number),-2,2));
 
    if((
$numberLast == 0) or ((5<=$numberLast) and ($numberLast<=9)) or((11<=$numberPreLast) and ($numberPreLast<=19)))
    {
        
$type=0;
    }
    elseif((
$numberLast==1) and ($numberPreLast!=11))
    {
        
$type=1;
    }
    elseif((
2<=$numberLast) and ($numberLast<=4))
    {
        
$type=2;
    }
    return 
$number.' '.$votes[$type];
}


/* Функция для отправки сообщений пользователю */
function message($text = '', $url = '')
{
    
$_SESSION['message'] = $text;
    if(empty(
$url))
    {
        
$url = $_SERVER['REQUEST_URI'];
    }
    
header('Location: '.$url);
    exit();
}


/* Переадресация */
function go($url = '')
{
    
header('Location: '.$url);
    exit();
}


/* Фильтрация при записи в БД */
function in($var)
{
    return 
mysql_real_escape_string(trim($var));
}


/* Фильтрация при выводе из БД */
function out($var)
{
    return 
htmlspecialchars(stripslashes($var));
}


/* Фильтрация чисел */
function num($var)
{
    return 
abs(intval($var));
}


/* Антиреклама */
function advert($var)
{
    return 
preg_replace('#([a-z0-9\s-.]){3,20}(.|,)([a-z\s]){2,4}#si', '[реклама]', $var);
}
?>
Онлайн: 2
Реклама