Файл: soc-set/core/functions.php
Строк: 629
<?php
function head($title = 'Главная') {
global $user;
/* Стиль сайта */
$default = '/style/style.css';
if (empty($user) || empty($user['site_version'])) {
$url = $default;
} else {
$url = 'style/manyak.css';
}
echo '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru"><head><meta http-equiv="Content-Type" content="application/vnd.wap.xhtml+xml; charset=UTF-8" />
<meta name="name" content="Социальная сеть" /><meta name="description" content="Общение здесь=)" />
<link rel="stylesheet" href="'.HOME.'/'.$url.'" type="text/css"/>
<title>'.$title.'</title></head><body>
'.DIV_BODY.'<div>
';
if (!empty($user)) {
DB::$dbs->query("UPDATE ".USERS." SET `location` = ? WHERE `user_id` = ? ",array($title, num($_SESSION['user_id'])));
}
}
function logo () {
global $user;
if (empty($user) || empty($user['site_version'])) {
$logo = HOME . '/style/img/logo3.png';
} else {
$logo = HOME . '/style/img/logo.png';
}
return $logo;
}
function nav ($array) {
if (empty($array)) {
echo '<div class="title30">
<div class="menu_i">
<table style="width:100%" cellspacing="0" cellpadding="0"><tr>
<td style="vertical-align:top;width:20%;white-space: nowrap;"><a href="'.HOME.'/" class="top_menu_link">Главная</a> </td>
</tr></table></div></div>';
} else {
echo '<div class="title30">
<div class="menu_i">
<table style="width:100%" cellspacing="0" cellpadding="0"><tr>
<td style="vertical-align:top;width:20%;white-space: nowrap;"><a href="'.HOME.'/" class="top_menu_link">Главная</a> </td>';
foreach ($array AS $value) {
echo '<td style="vertical-align:top;width:20%;white-space: nowrap;">'.navURL($value).'</td>';
}
echo '</tr></table></div></div>';
}
}
function navURL ($value) {
$str = str_replace('Кабинет', '<a href="'.HOME.'/menu" class="top_menu_link"/>' . $value . '</a>', $value);
$str = str_replace('Статус', '<a href="'.HOME.'/menu/status" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Основная фотография', '<a href="'.HOME.'/menu/photo" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Редактирование анкеты', '<a href="'.HOME.'/menu/anceta" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Анкета в знакомствах', '<a href="'.HOME.'/menu/love" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Настройки', '<a href="'.HOME.'/menu/sett" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Поиск города', '<a href="'.HOME.'/menu/city" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Друзья', '<a href="'.HOME.'/friends/" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Мои заявки', '<a href="'.HOME.'/friends/my_appl/" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Заявки дружить', '<a href="'.HOME.'/friends/user_appl/" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Черный список', '<a href="'.HOME.'/blacklist/" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Гарем', '<a href="'.HOME.'/harem/" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Мой гарем', '<a href="'.HOME.'/harem/my/" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Покупка в гарем', '<a href="'.HOME.'/harem/kup/" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Отпускаем из гарема', '<a href="'.HOME.'/harem/otpusk/" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Самые дорогие', '<a href="'.HOME.'/harem/dorog/" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Самые богатые', '<a href="'.HOME.'/harem/bogat/" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Информация', '<a href="'.HOME.'/faq/" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Смайлы', '<a href="'.HOME.'/smiles" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('BB-коды', '<a href="'.HOME.'/bb" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Зарабатывай баллы', '<a href="'.HOME.'/balls" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Диалоги', '<a href="'.HOME.'/mail/" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Лента', '<a href="'.HOME.'/lenta/" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Новости', '<a href="'.HOME.'/news/" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Чат', '<a href="'.HOME.'/chat/" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Форум', '<a href="'.HOME.'/forum/" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Блог', '<a href="'.HOME.'/blog/" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Фотоальбомы', '<a href="'.HOME.'/album/" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Беседка', '<a href="'.HOME.'/guestbook/" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Сообщества', '<a href="'.HOME.'/groups/" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Загрузки', '<a href="'.HOME.'/loads/" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Дуэли', '<a href="'.HOME.'/duel/" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Магазин', '<a href="'.HOME.'/shop/" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('Поддержка', '<a href="'.HOME.'/touch/" class="top_menu_link"/>' . $value . '</a>', $str);
$str = str_replace('В ферму', '<a href="'.HOME.'/fermer/" class="top_menu_link"/>' . $value . '</a>', $str);
return $str;
}
function panel() {
global $user;
/* Сообщения */
$all = DB::$dbs->querySingle("SELECT COUNT(*) FROM ".DIALOG_MSG." WHERE `user_friend` = ? AND `status` = ? ", array($user['user_id'], 1));
/* Лента */
$lenta = DB::$dbs->querySingle("SELECT COUNT(*) FROM ".LENTA." WHERE `user_id` = ? AND `status` = ? ", array($user['user_id'], 1));
echo '<div class="title30">
<div class="menu_i">
<table style="width:100%" cellspacing="0" cellpadding="0"><tr>
<td style="vertical-align:top;width:20%;white-space: nowrap;"><a href="'.HOME.'/page" class="top_menu_link">Я</a> </td>
<td style="vertical-align:top;width:20%;white-space: nowrap;"><a href="'.HOME.'/menu" class="top_menu_link">Кабинет</a> </td>
<td style="vertical-align:top;width:20%;white-space: nowrap;"><a href="'.HOME.'/mail/" class="top_menu_link">Диалоги'.($all > 0 ? '[+'.$all.']' : NULL).'</a> </td>
<td style="vertical-align:top;width:20%;white-space: nowrap;"><a href="'.HOME.'/lenta/" class="top_menu_link">Лента'.($lenta > 0 ? '[+'.$lenta.']' : NULL).'</a></td>
</tr></table></div></div>';
}
function lenta($text, $id) {
global $user;
if ($user['user_id'] != $id) {
DB::$dbs->query("INSERT INTO ".LENTA." (`user_id`, `time`, `text`, `status`) VALUES (?, ?, ?, ?)", array($id, time(), $text, 1));
}
}
function balls_operation ($balls) {
global $user;
DB::$dbs->query("UPDATE ".USERS." SET `balls` = ? WHERE `user_id` = ? ",array(($user['balls'] + $balls), $user['user_id']));
}
function num($int) {
return intval($int);
}
function html($str) {
return trim(strtr(htmlspecialchars(stripcslashes($str),ENT_QUOTES,'UTF-8'), array('$'=>'$','%'=>'%','_'=>'_')));
}
function color_nick ($id) {
global $color, $gradient_1, $gradient_2;
$ank = DB::$dbs->queryFetch("SELECT `nick`, `color_nick` FROM ".USERS." WHERE `user_id` = ?",array($id));
if (empty($ank['color_nick'])) {
$nick = $ank['nick'];
} else {
$data = explode(":", $ank['color_nick']);
if ($data[0] == 'color') {
$nick = '<font color="'.$color[$data[1]].'">'.$ank['nick'].'</font>';
} else {
$nick = GradientLetter($ank['nick'], $gradient_1[$data[1]], $gradient_2[$data[1]]);
}
}
return '<font style="font-size: 13px;">' . $nick . '</font>';
}
function user_choice($id, $choice) {
if ($choice == 'name') {
$result = DB::$dbs->queryFetch("SELECT `name` FROM ".USERS." WHERE `user_id` = ?",array(num($id)));
return $result['name'];
}
if ($choice == 'nick') {
$result = DB::$dbs->queryFetch("SELECT `nick` FROM ".USERS." WHERE `user_id` = ?",array(num($id)));
return $result['nick'];
}
if ($choice == 'gender') {
$result = DB::$dbs->queryFetch("SELECT `gender` FROM ".USERS." WHERE `user_id` = ?",array(num($id)));
return $result['gender'];
}
if ($choice == 'link') {
$result = DB::$dbs->queryFetch("SELECT `user_id`, `nick`, `gender` FROM ".USERS." WHERE `user_id` = ?",array(num($id)));
return onlineIcon($result['user_id']) . ' <a href="' . HOME . '/id' . $result['user_id'] . '">' . color_nick($result['user_id']) . '</a>';
}
}
function check_auth() {
if (empty($_SESSION['user_id'])) {
header("Location: ".HOME."/auth");
}
return false;
}
function gender ($gender) {
if ($gender == 0) {
return 'Женский';
} else {
return 'Мужской';
}
}
function getIP2()
{
if($_ENV["HTTP_VIA"])
{
if($_ENV["HTTP_X_FORWARDED_FOR"]!="unknown")
{
$ip = $_ENV["HTTP_X_FORWARDED_FOR"];
if($ip=="")
{
$ip=$_SERVER["REMOTE_ADDR"];
}
}
else
{
$ip=$_SERVER["REMOTE_ADDR"];
}
}
else
{
$ip=$_SERVER["REMOTE_ADDR"];
}
return $ip;
}
function city ($id) {
$city = DB::$dbs->queryFetch("SELECT * FROM ".CITY." WHERE `city_id` = ? ",array($id));
$region = DB::$dbs->queryFetch("SELECT `name` FROM ".REGION." WHERE `region_id` = ? ",array($city['region_id']));
$country = DB::$dbs->queryFetch("SELECT `name` FROM ".COUNTRY." WHERE `country_id` = ? ",array($city['country_id']));
return '<b>' . $city['name'] . '</b> (' . $region['name'] . ', ' . $country['name'] . ')';
}
function gen_timer_start() {
global $timer_start_time;
$start_time = microtime();
$start_array = explode(" ",$start_time);
$timer_start_time = $start_array[1] + $start_array[0];
return $timer_start_time;
}
function gen_timer_stop() {
global $timer_start_time;
$end_time = microtime();
$end_array = explode(" ",$end_time);
$timer_stop_time = $end_array[1] + $end_array[0];
$time = $timer_stop_time - $timer_start_time;
$time = substr($time,0,5);
return "[$time сек.]";
}
function vrem ($time = '', $format = 'd.m.y / H:i') {
define("SITE_TIME", time());
if (!is_numeric($time)) {
$time = SITE_TIME;
}
$shift = 0;
$date = date($format, $time + $shift);
$today = date("d.m.y", SITE_TIME + $shift);
$yesterday = date("d.m.y", strtotime("-1 day") + $shift);
$date = str_replace($today, 'Сегодня', $date);
$date = str_replace($yesterday, 'Вчера', $date);
$search = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
$replace = array('Января', 'Февраля', 'Марта', 'Апреля', 'Мая', 'Июня', 'Июля', 'Августа', 'Сентября', 'Октября', 'Ноября', 'Декабря');
$date = str_replace($search, $replace, $date);
return $date;
}
function level ($id) {
$pos = DB::$dbs->queryFetch("SELECT * FROM ".POSITIONS." WHERE `id` = ? ",array($id));
if (empty($pos['id'])) {
return 'Стажер';
} else {
return $pos['position'];
}
}
function privilegy ($privilegy, $id = NULL) {
global $user;
$sql = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".PRIVILEGE." WHERE `pos` = ? && `privil` = ?", array($user['level'], $privilegy));
/*
if ($sql == TRUE && $id == $user['user_id']) {
return TRUE;
}
*/
if (!empty($id)) {
$ank = DB::$dbs->queryFetch("SELECT `level` FROM ".USERS." WHERE `user_id` = ? ",array($id));
$pos = DB::$dbs->queryFetch("SELECT `prioritet` FROM ".POSITIONS." WHERE `id` = ? ",array($ank['level']));
$mypos = DB::$dbs->queryFetch("SELECT `prioritet` FROM ".POSITIONS." WHERE `id` = ? ",array($user['level']));
if ($sql == TRUE) {
if ($pos['prioritet'] >= $mypos['prioritet']) {
return FALSE;
} else {
return TRUE;
}
} else {
return FALSE;
}
} else {
return DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".PRIVILEGE." WHERE `pos` = ? && `privil` = ?", array($user['level'], $privilegy));
}
}
function img_resize($src, $dest, $width, $height, $rgb=0xFFFFFF, $quality=85)
{
if (!file_exists($src)) return false;
$size = getimagesize($src);
if ($size === false) return false;
// Определяем исходный формат по MIME-информации, предоставленной
// функцией getimagesize, и выбираем соответствующую формату
// imagecreatefrom-функцию.
$format = strtolower(substr($size['mime'], strpos($size['mime'], '/')+1));
$icfunc = "imagecreatefrom" . $format;
if (!function_exists($icfunc)) return false;
$x_ratio = $width / $size[0];
$y_ratio = $height / $size[1];
$ratio = min($x_ratio, $y_ratio);
$use_x_ratio = ($x_ratio == $ratio);
$new_width = $use_x_ratio ? $width : floor($size[0] * $ratio);
$new_height = !$use_x_ratio ? $height : floor($size[1] * $ratio);
$new_left = $use_x_ratio ? 0 : floor(($width - $new_width) / 2);
$new_top = !$use_x_ratio ? 0 : floor(($height - $new_height) / 2);
$isrc = $icfunc($src);
$idest = imagecreatetruecolor($width, $height);
imagefill($idest, 0, 0, $rgb);
imagecopyresampled($idest, $isrc, $new_left, $new_top, 0, 0,
$new_width, $new_height, $size[0], $size[1]);
imagejpeg($idest, $dest, $quality);
imagedestroy($isrc);
imagedestroy($idest);
return true;
}
function calc_age($data)
{
$ex_age = explode('/', $data);
$age = date('Y') - $ex_age[2];
if (date('m') < $ex_age[1] || (date('m') == $ex_age[1] && date('d') < $ex_age[0])) {
$age--;
}
$age = (int)$age;
if ($age == date('Y')) $age = 0;
return $age;
}
function text ($str) {
$str = smiles($str);
$str = BBcode($str);
$str = nl2br($str);
return $str;
}
function bbsmile() {
echo DIV_LI . '<a href="'.HOME.'/smiles">Смайлы</a> | <a href="'.HOME.'/bb">BB-коды</a>' . CLOSE_DIV;
}
function userLink($id, $link = NULL) {
$user = DB::$dbs->queryFetch("SELECT `user_id`, `nick` FROM ".USERS." WHERE `user_id` = ?",array($id));
$url = (empty($link) || $link == 'page' ? onlineIcon($user['user_id']) . ' ' : NULL) . '<a href="'.HOME.'/id'.$id.'">'.(empty($link) ? color_nick($user['user_id']) : $link).'</a>';
return $url;
}
function smiles($str) {
$sql = DB::$dbs->query("SELECT `url`, `name` FROM ".SMILES."");
while($smile = $sql -> fetch()) {
$str = str_replace($smile['name'], '<img src="'.HOME.'/files/smiles/' . $smile['url'] . '" alt="'.$smile['name'].'"/>', $str);
}
return $str;
}
function BBcode($msg)
{
$bbcode=array();
$bbcode['/[i](.+)[/i]/isU']='<em>$1</em>';
$bbcode['/[b](.+)[/b]/isU']='<strong>$1</strong>';
$bbcode['/[u](.+)[/u]/isU']='<span style="text-decoration:underline;">$1</span>';
$bbcode['/[big](.+)[/big]/isU']='<span style="font-size:large;">$1</span>';
$bbcode['/[small](.+)[/small]/isU']='<span style="font-size:small;">$1</span>';
$bbcode['/[red](.+)[/red]/isU']='<span style="color:#ff0000;">$1</span>';
$bbcode['/[yellow](.+)[/yellow]/isU']='<span style="color:#ffff22;">$1</span>';
$bbcode['/[green](.+)[/green]/isU']='<span style="color:#00bb00;">$1</span>';
$bbcode['/[blue](.+)[/blue]/isU']='<span style="color:#0000bb;">$1</span>';
$bbcode['/[white](.+)[/white]/isU']='<span style="color:#ffffff;">$1</span>';
$bbcode['/[size=([0-9]+)](.+)[/size]/isU']='<span style="font-size:$1px;">$2</span>';
if (count($bbcode))$msg= preg_replace(array_keys($bbcode), array_values($bbcode), $msg);
$msg = preg_replace('#[google](.*?)[/google]#si', '<a href="http://www.google.ru/search?q=$1">Поиск в <span style="color:#0000ff">G</span><span style="color:#ff0000">o</span><span style="color:#FFD700">o</span><span style="color:#0000ff">g</span><span style="color:#008000">l</span><span style="color:#ff0000">e</span>: <i>$1</i></a> ', $msg);
$msg = preg_replace('#[googleimg](.*?)[/googleimg]#si', '<a href="http://www.google.com.ua/images?q=$1">Поиск картинок <span style="color:#0000ff">G</span><span style="color:#ff0000">o</span><span style="color:#FFD700">o</span><span style="color:#0000ff">g</span><span style="color:#008000">l</span><span style="color:#ff0000">e</span>: <i>$1</i></a> ', $msg);
return $msg;
}
function get_size($size)
{
if ($size < 1024) $size = $size . 'Bt';
if ($size > 1024 and $size < 1048576) $size = round($size / 1024, 1) . 'Kb';
if ($size >= 1048576) $size = round(($size / 1024) / 1024, 1) . 'Mb';
return $size;
}
function SubstrMaus($text, $len, $start = 0, $mn = ' (...)') {
$text = trim($text);
if (function_exists('mb_substr')) {
return mb_substr($text, $start, $len) . (mb_strlen($text) > $len - $start ? $mn : null);
}
if (function_exists('iconv')) {
return iconv_substr($text, $start, $len) . (iconv_strlen($text) > $len - $start ? $mn : null);
}
return $text;
}
# Анкета
function smok($id) {
$user = DB::$dbs->queryFetch("SELECT `gender`, `smok` FROM ".USERS." WHERE `user_id` = ?",array($id));
if ($user['gender'] == 0) {
$array = array(1 => 'Не курила', 2 => 'Бросила', 3 => 'Бросаю', 4 => 'Только когда выпью', 5 => 'Дымлю как паровоз',
6 => 'Курю, но не табак');
} else {
$array = array(1 => 'Не курил', 2 => 'Бросил', 3 => 'Бросаю', 4 => 'Только когда выпью', 5 => 'Дымлю как паровоз',
6 => 'Курю, но не табак');
}
return $array[$user[smok]];
}
function alco($id) {
$user = DB::$dbs->queryFetch("SELECT `gender`, `alco` FROM ".USERS." WHERE `user_id` = ?",array($id));
if ($user['gender'] == 0) {
$array = array(1 => 'Мне и так весело', 2 => 'Завязала', 3 => 'Иногда можно', 4 => 'Скоро брошу', 5 => 'Пила, пью и буду пить');
} else {
$array = array(1 => 'Мне и так весело', 2 => 'Завязал', 3 => 'Иногда можно', 4 => 'Скоро брошу', 5 => 'Пил, пью и буду пить');
}
return $array[$user[alco]];
}
function narco($id) {
$user = DB::$dbs->queryFetch("SELECT `gender`, `narco` FROM ".USERS." WHERE `user_id` = ?",array($id));
if ($user['gender'] == 0) {
$array = array(1 => 'Никогда не пробовала', 2 => 'Категорически против', 3 => 'Пробовала', 4 => 'Не понравилось', 5 => 'Редко и легкие',
6 => 'Не могу без них');
} else {
$array = array(1 => 'Никогда не пробовал', 2 => 'Категорически против', 3 => 'Пробовал', 4 => 'Не понравилось', 5 => 'Редко и легкие',
6 => 'Не могу без них');
}
return $array[$user[narco]];
}
function poznakom($id) {
$user = DB::$dbs->queryFetch("SELECT `poznakom`, `age1`, `age2` FROM ".USERS." WHERE `user_id` = ?",array($id));
$array = array(1 => 'девушкой', 2 => 'парнем');
return $array[$user[poznakom]] . (!empty($user['age1']) && !empty($user['age2']) ? ' в возрасте с ' . $user['age1'] . ' до ' . $user['age2'] . ' лет': NULL);
}
function goal($id) {
$user = DB::$dbs->queryFetch("SELECT `goal` FROM ".USERS." WHERE `user_id` = ?",array($id));
$array = array(1 => 'Дружба', 2 => 'Общение', 3 => 'Флирт', 4 => 'Любовь', 5 => 'Свидание на одну ночь', 6 => 'Серьезные отношения');
return $array[$user[goal]];
}
function family_status($id) {
$user = DB::$dbs->queryFetch("SELECT `gender`, `family_status` FROM ".USERS." WHERE `user_id` = ?",array($id));
if ($user['gender'] == 0) {
$array = array(1 => 'Свободна', 2 => 'Замужем', 3 => 'Занята', 4 => 'В поиске второй половинки', 5 => 'Ничего серьезного',
6 => 'Всегда готова');
} else {
$array = array(1 => 'Свободен', 2 => 'Женат', 3 => 'Занят', 4 => 'В поиске второй половинки', 5 => 'Ничего серьезного',
6 => 'Всегда готов');
}
return $array[$user[family_status]];
}
function children($id) {
$user = DB::$dbs->queryFetch("SELECT `children` FROM ".USERS." WHERE `user_id` = ?",array($id));
$array = array(1 => 'Пока нет', 2 => 'Нет и не будет', 3 => 'Есть', 4 => 'Нет, но хочу', 5 => 'Уже взрослые');
return $array[$user[children]];
}
function orientation($id) {
$user = DB::$dbs->queryFetch("SELECT `orientation` FROM ".USERS." WHERE `user_id` = ?",array($id));
$array = array(1 => 'Гетеро', 2 => 'Гомо', 3 => 'Би');
return $array[$user[orientation]];
}
function birthday($day = NULL, $month = NULL, $year = NULL) {
$array = array(1 => 'января', 2 => 'февраля', 3 => 'марта', 4 => 'апреля', 5 => 'мая', 6 => 'июня', 7 => 'июля', 8 => 'августа',
9 => 'сентября', 10 => 'октября', 11 => 'ноября', 12 => 'декабря');
return $day . ' ' . $array[$month] . ' ' . $year . 'г.';
}
function GradientLetter($text, $from='', $to='', $mode = 'hex') {
$text = iconv("UTF-8", "windows-1251", $text);
if ($mode == 'hex') {
$to = hexdec($to['0'].$to['1']).','.hexdec($to['2'].$to['3']).','.hexdec($to['4'].$to['5']);
$from = hexdec($from['0'].$from['1']).",".hexdec($from['2'].$from['3']).",".hexdec($from['4'].$from['5']);
}
if (empty($text)) return null; else $levels = strlen($text);
if (empty($from)) $from = array(0, 0, 255); else $from = explode(',', $from);
if (empty($to)) $to = array(255, 0, 0); else $to = explode(',', $to); $output = null;
for ($i = 1; $i <= $levels; $i++) {
for ($ii = 0; $ii < 3; $ii++) {
$tmp[$ii] = $from[$ii] - $to[$ii];
$tmp[$ii] = floor($tmp[$ii] / $levels);
$rgb[$ii] = $from[$ii] - ($tmp[$ii] * $i);
if ($rgb[$ii] > 255) $rgb[$ii] = 255;
$rgb[$ii] = dechex($rgb[$ii]);
$rgb[$ii] = strtoupper($rgb[$ii]);
if (strlen($rgb[$ii]) < 2) $rgb[$ii] = '0'.$rgb[$ii];
}
$output .= '<span style="color: #'.$rgb['0'].$rgb['1'].$rgb['2'].'">'.$text[$i-1].'</span>';
}
return iconv("windows-1251", "UTF-8", $output);
}
/* Показ онлайн-статуса */
function onlineIcon ($id) {
$ank = DB::$dbs->queryFetch("SELECT `user_id`, `last_time`, `gender`, `vip` FROM ".USERS." WHERE `user_id` = ?",array($id));
if ($ank['last_time'] > (time() - 2000)) {
if (empty($ank['gender'])) {
/* Ж */
$online = '<img src="'.HOME.'/img/xstatus/woman_on.gif" />';
} else {
/* М */
$online = '<img src="'.HOME.'/img/xstatus/man_on.gif" />';
}
} else {
if (empty($ank['gender'])) {
/* Ж */
$online = '<img src="'.HOME.'/img/xstatus/woman_off.gif" />';
} else {
/* М */
$online = '<img src="'.HOME.'/img/xstatus/man_off.gif" />';
}
}
if ($ank['vip'] > time()) {
$vip = '<img src="'.HOME.'/img/vip.png" />';
}
return (!empty($vip) ? $vip : NULL) . $online;
}
function mobile_detect() {
global $user;
$user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
$accept = strtolower($_SERVER['HTTP_ACCEPT']);
if ((strpos($accept, 'text/vnd.wap.wml') !== false) || (strpos($accept, 'application/vnd.wap.xhtml+xml') !== false)) {
DB::$dbs->query("UPDATE ".USERS." SET `is_mobile` = ? WHERE `user_id` = ?", array(1, $user['user_id']));
return true;
}
if (isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE'])) {
DB::$dbs->query("UPDATE ".USERS." SET `is_mobile` = ? WHERE `user_id` = ?", array(1, $user['user_id']));
return true;
}
if (preg_match('/android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)/|plucker|pocket|psp|symbian|treo|up.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i', $user_agent)
|| preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|/(k|l|u)|50|54|e-|e/|-[a-w])|libw|lynx|m1-w|m3ga|m50/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(-|2|g)|yas-|your|zeto|zte-/i', substr($user_agent, 0, 4))) {
DB::$dbs->query("UPDATE ".USERS." SET `is_mobile` = ? WHERE `user_id` = ?", array(1, $user['user_id']));
return true;
}
DB::$dbs->query("UPDATE ".USERS." SET `is_mobile` = ? WHERE `user_id` = ?", array(2, $user['user_id']));
return false;
}
/* Антиспам */
function antiSpam($str) {
# Преобразуем строку в нижний регистр
$str = mb_convert_case($str, MB_CASE_LOWER, "UTF-8");
# Подозрительные слова в личных сообщениях
$mailSpam = array('заходи', 'приглашаю', 'ждем тебя', 'wap', 'соц', 'модера', 'заеби', 'гандон', 'уебан');
foreach ($mailSpam AS $value) {
if(preg_match("/".$value."/i",$str)) {
return true;
exit();
}
}
return false;
}
function antilink($str) {
$str = mb_convert_case($str, MB_CASE_LOWER, "UTF-8");
if(preg_match("/vou-vou.ru/i",$str)) {
return false;
}
$domains = array('.com', '.net', '.ru', '.su', '.in', '.biz', '.name', '.mobi', '.wen',
'. com', '. net', '. ru', '. su', '. in', '. biz', '. name', '. mobi', '. wen',
'http://', 'www.', 'www .'
);
foreach ($domains AS $value) {
if(preg_match("/".$value."/i",$str)) {
return true;
exit();
}
}
return false;
}
?>