<?php
/**********************************************/
/* Автор скрипта: Александр Есин */
/* E-Mail: [email protected] ([email protected]) */
/* ICQ: 6464729 */
/* Site: http://ticlove.ru */
/**********************************************/
?>
<?php
if (!defined('SECURED')) die("SORRY! Unknown Error!");
function function_online($time)
{
if ($time > (time() - ONLINE_TIME)) return TRUE;
else return FALSE;
}
function function_smile($str) {
for ($i = 1; $i < 51; $i++) $str = str_replace(':sm'.$i.':', '<img src="http://'.$_SERVER["HTTP_HOST"].'/smiles/'.$i.'.gif" alt=":sm'.$i.':" />', $str);
return $str;
}
function plural_form($number, $after, $style) {
$cases = array (2, 0, 1, 1, 1, 2);
$all = '';
if (strlen($number) == 1 or strlen($number) == 2 or strlen($number) == 3)
{
$all = $number;
}
else if (strlen($number) == 4)
{
$all .= substr($number, 0, 1).' ';
$all .= substr($number, -3);
}
else if (strlen($number) == 5)
{
$all .= substr($number, 0, 2).' ';
$all .= substr($number, -3);
}
else if (strlen($number) == 6)
{
$all .= substr($number, 0, 3).' ';
$all .= substr($number, -3);
}
else if (strlen($number) == 7)
{
$all .= substr($number, 0, 1).' ';
$all .= substr($number, 1, 3).' ';
$all .= substr($number, -3);
}
else if (strlen($number) == 8)
{
$all .= substr($number, 0, -6).' ';
$all .= substr($number, 2, -3). ' ';
$all .= substr($number, -3);
}
else $all = $number;
echo '<span id="'.$style.'">'.$all.'</span> '.$after[ ($number%100>4 && $number%100<20)? 2: $cases[min($number%10, 5)] ];
}
function function_bigword($msg, $col)
{
$msg = iconv('utf-8', 'windows-1251', $msg);
$msg = wordwrap($msg, $col, ' ', 1);
return iconv('windows-1251', 'utf-8', $msg);
}
function function_vizit($time)
{
$timep = date("j M Y в H:i", $time);
$time_p[0] = date("j n Y", $time);
$time_p[1] = date("H:i", $time);
if ($time_p[0] == date("j n Y", time()))
{
$timep = 'сегодня в '.$time_p[1];
}
else if ($time_p[0] == date("j n Y", time()-86400))
{
$timep = 'вчера в '.$time_p[1];
}
else if ($time_p[0] == date("j n Y", time()-172800))
{
$timep = '3 дня назад в '.$time_p[1];
}
else if (date("j n Y", time()))
{
$timep = $timep;
}
$timep = str_replace("Jan", "января", $timep);
$timep = str_replace("Feb", "февраля", $timep);
$timep = str_replace("Mar", "марта", $timep);
$timep = str_replace("May", "мая", $timep);
$timep = str_replace("Apr", "апреля", $timep);
$timep = str_replace("Jun", "июня", $timep);
$timep = str_replace("Jul", "июля", $timep);
$timep = str_replace("Aug", "августа", $timep);
$timep = str_replace("Sep", "сентября", $timep);
$timep = str_replace("Oct", "октября", $timep);
$timep = str_replace("Nov", "ноября", $timep);
$timep = str_replace("Dec", "декабря", $timep);
return $timep;
}
function function_reg_Month($mes) {
if ($mes == '01') $month = 'январь';
if ($mes == '02') $month = 'февраль';
if ($mes == '03') $month = 'март';
if ($mes == '04') $month = 'апрель';
if ($mes == '05') $month = 'май';
if ($mes == '06') $month = 'июнь';
if ($mes == '07') $month = 'июль';
if ($mes == '08') $month = 'август';
if ($mes == '09') $month = 'сентябрь';
if ($mes == '10') $month = 'октябрь';
if ($mes == '11') $month = 'ноябрь';
if ($mes == '12') $month = 'декабрь';
return $month;
}
function function_whatMonth($mes) {
if ($mes == '01') $month = 'Января';
if ($mes == '02') $month = 'Февраля';
if ($mes == '03') $month = 'Марта';
if ($mes == '04') $month = 'Апреля';
if ($mes == '05') $month = 'Мая';
if ($mes == '06') $month = 'Июня';
if ($mes == '07') $month = 'Июля';
if ($mes == '08') $month = 'Августа';
if ($mes == '09') $month = 'Сентября';
if ($mes == '10') $month = 'Октября';
if ($mes == '11') $month = 'Ноября';
if ($mes == '12') $month = 'Декабря';
return $month;
}
function function_rating($rat) {
$rating = round($rat, 1);
if ($rating == 0) $rate = 0;
else if ($rating > 0 && $rating < 1) $rate = 01;
else if ($rating == 1) $rate = 1;
else if ($rating > 1 && $rating < 2) $rate = 12;
else if ($rating == 2) $rate = 2;
else if ($rating > 2 && $rating < 3) $rate = 23;
else if ($rating == 3) $rate = 3;
else if ($rating > 3 && $rating < 4) $rate = 34;
else if ($rating == 4) $rate = 4;
else if ($rating > 4 && $rating < 5) $rate = 45;
else if ($rating == 5) $rate = 5;
echo 'Рейтинг фото: <span class="rating_color">'.$rat.'</span>';
}
function site_version() {
if (isset($_SERVER['HTTP_X_OPERAMINI_PHONE_UA'])) $u_agent = $_SERVER['HTTP_X_OPERAMINI_PHONE_UA'];
else $u_agent = $_SERVER['HTTP_USER_AGENT'];
if (preg_match('/MSIE/i', $u_agent) or preg_match('/Firefox/i', $u_agent) or preg_match('/Safari/i', $u_agent) or preg_match('/Chrome/i', $u_agent) or preg_match('/Flock/i', $u_agent) or preg_match('/Opera/i', $u_agent) or preg_match('/Netscape/i', $u_agent)) return TRUE;
else return FALSE;
}
function getBrowser() {
if (isset($_SERVER['HTTP_X_OPERAMINI_PHONE_UA'])) $u_agent = $_SERVER['HTTP_X_OPERAMINI_PHONE_UA'];
else $u_agent = $_SERVER['HTTP_USER_AGENT'];
$ub = '';
if (preg_match('/MSIE/i', $u_agent))
{
$ub = "Internet Explorer";
}
else if (preg_match('/Firefox/i', $u_agent))
{
$ub = "Mozilla Firefox";
}
else if (preg_match('/Safari/i', $u_agent))
{
$ub = "Apple Safari";
}
else if (preg_match('/Chrome/i', $u_agent))
{
$ub = "Google Chrome";
}
else if (preg_match('/Flock/i', $u_agent))
{
$ub = "Flock";
}
else if (preg_match('/Opera/i', $u_agent))
{
$ub = "Opera";
}
else if (preg_match('/Netscape/i', $u_agent))
{
$ub = "Netscape";
}
return $ub;
}
function function_sql($str)
{
if (get_magic_quotes_gpc()) $str = stripslashes($str);
if (!is_numeric($str)) $str = mysql_real_escape_string($str);
return $str;
}
// функция проверки мыла
function function_email($address)
{
$return = false;
if (preg_match('/^[\w.-]+@([\w.-]+)\.[a-z]{2,6}$/i', $address, $domain)) {
$domain = explode('.', $domain[0]);
// Split the domain into sections wherein the last element is either 'co', 'org', or the likes, or the primary domain name
foreach ($domain as $part) { // Iterate through the parts
if (substr($part, 0, 1) == '_' || substr($part, strlen($part) - 1, 1) == '_')
$return = false; // The first or last character is _
else
$return = true; // The parts are fine. The address seems syntactically valid
}
}
return $return;
}
//формат гггг-мм-дд
function function_vozrast($date)
{
return mysql_result(mysql_query("SELECT (YEAR(CURRENT_DATE) - YEAR('".$date."')) - (DAYOFYEAR(CURRENT_DATE) < DAYOFYEAR('".$date."')) AS `age`;"), 0, 0);
}
//формат гггг-мм-дд
function function_vozrast_n($date)
{
$year = mysql_result(mysql_query("SELECT (YEAR(CURRENT_DATE) - YEAR('".$date."')) - (DAYOFYEAR(CURRENT_DATE) < DAYOFYEAR('".$date."')) AS `age`;"), 0, 0);
if ($year == 21 or $year == 31 or $year == 41 or $year == 51 or $year == 61 or $year == 71 or $year == 81) $l = 'год';
else if ($year >= 22 && $year <= 24 or $year >= 32 && $year <= 34 or $year >= 42 && $year <= 44 or $year >= 52 && $year <= 54 or $year >= 62 && $year <= 64 or $year >= 72 && $year <= 74 or $year >= 82 && $year <= 84) $l = 'года';
else $l = 'лет';
return $year.' '.$l;
}
function function_name_vozr($year)
{
if ($year == 21 or $year == 31 or $year == 41 or $year == 51 or $year == 61 or $year == 71 or $year == 81) $l = 'года';
else if ($year >= 22 && $year <= 24 or $year >= 32 && $year <= 34 or $year >= 42 && $year <= 44 or $year >= 52 && $year <= 54 or $year >= 62 && $year <= 64 or $year >= 72 && $year <= 74 or $year >= 82 && $year <= 84) $l = 'года';
else $l = 'лет';
return $year.' '.$l;
}
function function_zodiak($mes, $den)
{
switch($mes)
{
case 1:
return (21 < $den ? '<span class="horo_img horo_11">Водолей</span>' : '<span class="horo_img horo_10">Козерог</span>'); break;
case 2: return (20 < $den ? '<span class="horo_img horo_12">Рыба</span>' : '<span class="horo_img horo_11">Водолей</span>'); break;
case 3: return (22 < $den ? '<span class="horo_img horo_1">Овен</span>' : '<span class="horo_img horo_12">Рыба</span>'); break;
case 4: return (22 < $den ? '<span class="horo_img horo_2">Телец</span>' : '<span class="horo_img horo_1">Овен</span>'); break;
case 5: return (22 < $den ? '<span class="horo_img horo_3">Близнецы</span>' : '<span class="horo_img horo_2">Телец</span>'); break;
case 6: return (23 < $den ? '<span class="horo_img horo_4">Рак</span>' : '<span class="horo_img horo_3">Близнецы</span>'); break;
case 7: return (24 < $den ? '<span class="horo_img horo_5">Лев</span>' : '<span class="horo_img horo_4">Рак</span>'); break;
case 8: return (24 < $den ? '<span class="horo_img horo_6">Дева</span>' : '<span class="horo_img horo_5">Лев</span>'); break;
case 9: return (24 < $den ? '<span class="horo_img horo_7">Весы</span>' : '<span class="horo_img horo_6">Дева</span>'); break;
case 10: return (24 < $den ? '<span class="horo_img horo_8">Скорпион</span>' : '<span class="horo_img horo_7">Весы</span>'); break;
case 11: return (23 < $den ? '<span class="horo_img horo_9">Стрелец</span>' : '<span class="horo_img horo_8">Скорпион</span>'); break;
case 12: return (23 < $den ? '<span class="horo_img horo_10">Козерог</span>' : '<span class="horo_img horo_9">Стрелец</span>'); break;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ----------------------- Постраничная навигация (Страницы) ------------------------//
function function_page($link, $posts, $start, $count_p, $koll = 8) {
if ($count_p > 0) {
if ($count_p > $posts) {
echo '<ul class="pager">';
//if ($start != 0) echo '<li><a href="'.$link.'start='.($start - $posts).'" title="Назад"><<<</a></li>';
}
$ba = ceil($count_p / $posts);
$ba2 = $ba * $posts - $posts;
$min = $start - $posts * ($koll - 1);
$max = $start + $posts * $koll;
if ($min < $count_p && $min > 0) {
if ($min - $posts > 0) echo '<li><a href="'.$link.'start=0">1</a></li><li><a>...</a></li>';
else echo '<li><a href="'.$link.'start=0">1</a></li>';
}
for($i = $min; $i < $max;) {
if ($i < $count_p && $i >= 0) {
$ii = floor(1 + $i / $posts);
if ($start == $i) {
if ($ba > 1) echo '<li><span class="cur">'.$ii.'</span></li>';
} else echo '<li><a href="'.$link.'start='.$i.'">'.$ii.'</a></li>';
}
$i += $posts;
}
if ($max < $count_p) {
if ($max + $posts < $count_p) echo '<li><a>...</a></li><li><a href="'.$link.'start='.$ba2.'">'.$ba.'</a></li>';
else echo '<li><a href="'.$link.'start='.$ba2.'">'.$ba.'</a></li>';
}
if ($count_p > $posts) {
//if ($count_p > $start + $posts) echo '<li><a class="p" href="'.$link.'start='.($start + $posts).'" title="Вперед">>>></a></li>';
echo '</ul>';
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function page($link, $posts, $start, $count_p, $end_url, $koll = 6) {
if ($count_p > 0) {
if ($count_p > $posts) {
echo '<ul class="pager">';
//echo 'Страницы: ';
//if ($start != 0) echo '<li><a href="'.$link.'/'.($start - $posts).'/'.$end_url.'" title="Назад"><<<</a></li>';
//else echo '<li><<<</li>';
}
$ba = ceil($count_p / $posts);
$ba2 = $ba * $posts - $posts;
$min = $start - $posts * ($koll - 1);
$max = $start + $posts * $koll;
if ($min < $count_p && $min > 0) {
if ($min - $posts > 0) echo '<li><a href="'.$link.'/0/'.$end_url.'">1</a></li><li><a>...</a></li>';
else echo '<li><a href="'.$link.'/0/'.$end_url.'">1</a></li>';
}
for($i = $min; $i < $max;) {
if ($i < $count_p && $i >= 0) {
$ii = floor(1 + $i / $posts);
if ($start == $i) {
if ($ba > 1) echo '<li><span class="cur">'.$ii.'</span></li>';
} else echo '<li><a href="'.$link.'/'.$i.'/'.$end_url.'">'.$ii.'</a></li>';
}
$i += $posts;
}
if ($max < $count_p) {
if ($max + $posts < $count_p) echo '<li><a>...</a></li><li><a href="'.$link.'/'.$ba2.'/'.$end_url.'">'.$ba.'</a></li>';
else echo '<li><a href="'.$link.'/'.$ba2.'/'.$end_url.'">'.$ba.'</a></li>';
}
if ($count_p > $posts) {
//if ($count_p > $start + $posts) echo '<li><a class="p" href="'.$link.'/'.($start + $posts).'/'.$end_url.'" title="Вперед">>>></a></li>';
//else echo '<li> >>></li>';
echo '</ul>';
}
}
}
function function_creat_foto($path, $where, $type1 = "")
{
$inf = getimagesize($path);
$src_ratio = $inf[0] / $inf[1];
if ($inf[0] > $inf[1]) { // если фото горизонтальное, обрезаем и подгоняем под 1024*768
$x = $inf[1] / 1.333;
$y = $inf[1];
$sdl = ($inf[0] - $x) / 2;
}
else if ($inf[0] < $inf[1]) { // если фото вертикальное, подгоняем под правильный формат
$x = $inf[0];
$y = $inf[1];
$rr = $x / $y;
if ($rr > 0.75){ // 600*1024
$x = $y * 0.75;
$sdl = ($inf[0] - $x) / 2;
}
else { // 800*1024
$y = $x / 0.75;
$sdl = 0;
}
}
else if ($inf[0] == $inf[1]) {
$x = $inf[0] / 1.333;
$y = $inf[0];
$sdl = 0;
}
if ($type1 == "") $type1 = "jpg";
switch ($type1) {
case 'jpg' : $src_img = @imagecreatefromjpeg($path); break;
case 'gif' : $src_img = @imagecreatefromgif($path); break;
case 'png' : $src_img = @imagecreatefrompng($path); break;
}
$dest_img = imagecreatetruecolor($x, $y);
imagecopyresampled($dest_img, $src_img, 0, 0, $sdl, 0, $inf[0], $inf[1], $inf[0], $inf[1]);
switch ($type1){
case 'jpg' : imagejpeg($dest_img, $where, "100"); break;
case 'gif' : imagegif($dest_img, $where); break;
case 'png' : imagepng($dest_img, $where); break;
}
imagedestroy($dest_img);
imagedestroy($src_img);
return true;
}
function function_small_foto($path, $where, $x, $y, $type1 = "")
{
$ratio = $x/$y;
$inf = getimagesize($path);
$src_ratio=$inf[0]/$inf[1];
if ($ratio<$src_ratio)
{
$y = $x/$src_ratio;
}
else
{
$x = $y*$src_ratio;
}
if ($x>$inf[0]) {$x=$inf[0]; $y=$inf[1]; }
if ($type1=="") $type1="jpg";
switch ($type1){
case 'jpg' : $src_img = imagecreatefromjpeg($path); break;
case 'jpeg' : $src_img = imagecreatefromjpeg($path); break;
case 'gif' : $src_img = imagecreatefromgif($path); break;
case 'png' : $src_img = imagecreatefrompng($path); break;
}
$dest_img = imagecreatetruecolor($x, $y);
imagecopyresampled($dest_img, $src_img, 0, 0, 0, 0, $x, $y, $inf[0], $inf[1]);
switch ($type1){
case 'jpg' : imagejpeg($dest_img, $where,"100");break;
case 'jpeg' : imagejpeg($dest_img, $where,"100");break;
case 'gif' : imagegif($dest_img, $where); break;
case 'png' : imagepng($dest_img, $where); break;
}
imagedestroy($dest_img);
imagedestroy($src_img);
return true;
}
function del_dir_photos($dir)
{
if ($handle = opendir($dir))
{
while (($file = readdir($handle)) <> false)
{
if (is_file($dir."/".$file))
{
if ($file <> '.htaccess')
{
chmod($dir."/".$file, 0777);
unlink($dir."/".$file);
}
}
else if (is_dir($dir."/".$file) && ($file <> ".") && ($file <> ".."))
{
chmod($dir."/".$file, 0777);
rdir($dir."/".$file);
}
}
closedir($handle);
chmod($dir, 0777);
if (rmdir($dir))
{
return true;
}
else
{
return false;
}
}
}
?>