<?
 
 function ced($id)
          {
   $ban = mysql_fetch_assoc(mysql_query("SELECT * FROM `ban` WHERE `who` = '".$id."' and `end` > '".time()."' LIMIT 1"));
  if($ban != 0){ 
return '<b>[БАН]</b>';
}
         
}
          function TextGuard($text)
          {
    
          return trim(htmlspecialchars(mysql_escape_string($text)));
          
          }
  
  
  
  
  
          function gradient($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 '';
          
          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 = "";
  
          for ($i=1;$i<=$levels;$i++)
          {
          
          for ($ii=0;$ii<4;$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 .= "<font color=\"#".$rgb[0].$rgb[1].$rgb[2]."\">" . $text[$i -1 ] . "</font>";
  
          }

          return iconv("windows-1251",  "UTF-8", $output);
  
          }






  
  function ustatus($id){
  $users = mysql_fetch_array(mysql_query('select * from `user` where `id` = "'.$id.'" limit 1'));
  if($users['sex'] == 1){ 
  if($users['online'] > time()-180) return '<img src="/modules/bl/files/'.$users['icon'].'.png" alt="*" width="16" height="16"/>';
  else return '<img src="/modules/profile/images/off.png"/>';
  }elseif($users['sex'] == 2){
  if($users['online'] > time()-180) return '<img src="/modules/bl/files/'.$users['icon1'].'.png" alt="*" width="16" height="16"/>';
  else return '<img src="/modules/profile/images/off.png"/>';  
  }}

  function uname($id){
  $users = mysql_fetch_array(mysql_query('select * from `user` where `id` = "'.$id.'" limit 1'));
  if($users != 0){

  $nicks = mysql_query("SELECT * FROM `nicks` where `who` = '".$users['id']."' ORDER BY `id` DESC LIMIT 1");
  while($nicks2 = mysql_fetch_assoc($nicks)){
  $users['login'] = $nicks2['new'];
  }
  
  $gradient = mysql_fetch_array(mysql_query('select * from `gradient` where `who` = "'.$id.'" limit 1'));
  if($gradient != 0 && $gradient['start'] != NULL && $gradient['end'] != NULL) return '<b>'.gradient($users['login'],$gradient['start'],$gradient['end']).'</b>'; else return '<b>'.$users['login'].'</b>';
  
  }else{
  
  return '<a href="/us2">Система</a>';
  
  }
  }

  function grad_status($id){

 $users = mysql_fetch_array(mysql_query('select * from `user` where `id` = "'.$id.'" limit 1'));

if(empty($users['status2'])){
  
 return 'Не заполнен';

  }else{
 
  if($users != 0){

 

  $gradient = mysql_fetch_array(mysql_query('select * from `grad_status` where `who` = "'.$id.'" limit 1'));
  if($gradient != 0 && $gradient['start'] != NULL && $gradient['end'] != NULL) return '<b>'.gradient($users['status2'],$gradient['start'],$gradient['end']).'</b>'; else return '<b>'.$users['status2'].'</b>';
  
  }else{
  
  return ''.$user['status2'].'';
  }
}
}

  function uaccess($id){
  $users = mysql_fetch_array(mysql_query('select * from `user` where `id` = "'.$id.'" limit 1'));
  
  if($users != 0){
  
  if($users['status'] >= 1){
  
  if($users['status'] == 1) $access = '<font color="green">[мд]</font>'; elseif($users['status'] == 2) $access = '<font color="red">[адм]</font>';
  elseif($users['status'] == 3) $access = '<font color="orangered">[ст.адм]</font>'; elseif($users['status'] == 4) $access = '<font color="orange">[соз]</font>';

  return ''.$access.'';

  }
  
  }
  
  }
  
  
          function user($id)
          {
          
          $us = mysql_fetch_array(mysql_query('select * from `user` where `id` = "'.$id.'" limit 1'));
          
          if($us == 0)
          {
          
          return 'Система';
          
          }
          else
          {

          $nicks = mysql_query("SELECT * FROM `nicks` where `who` = '".$us['id']."' ORDER BY `id` DESC LIMIT 1");
  
          while($nicks2 = mysql_fetch_assoc($nicks)){
          
          $us['login'] = $nicks2['new'];
  
          }
                    
          
          $gradient = mysql_fetch_array(mysql_query('select * from `gradient` where `who` = "'.$id.'" limit 1'));
  
          if($gradient != 0 && $gradient['start'] != NULL && $gradient['end'] != NULL) $us_login = '<b>'.gradient($us['login'],$gradient['start'],$gradient['end']).'</b>'; else $us_login = $us['login'];
          
switch($us['status']) {

case '1': $us_access = 'мд';
break;

case '2': $us_access = 'адм';
break;

case '3': $us_access = 'ст.адм';
break;
    
case '4': $us_access = 'соз';
break;  
}     
if($us['status'] >= 1) $us_access2 = ' <font color="green">['.$us_access.']</font>';

return '<img src="/modules/profile/images/'.($us['sex'] == 1 ? 'm' : 'j').($us['online'] > (time()-180) ? 'on' : 'of').'.png" alt="*"/> <a href="/us'.$us['id'].'"><b>'.$us_login.'</b></a> '.$us_access2;

echo ''.$us_prepis2.'';     
}  
}

 
function slv($str,$msg1,$msg2,$msg3) {

$str = (int)$str;
$str1 = abs($str) % 100;
$str2 = $str % 10;
if ($str1 > 10 && $str1 < 20) return $str .' '. $msg3;
if ($str2 > 1 && $str2 < 5) return $str .' '. $msg2;
if ($str2 == 1) return $str .' '. $msg1;
  
return $str .' '. $msg3;
}
  
function times($times=NULL){

$time = time();
if(($time-$times)<=60){
$timesp = slv((($time-$times)),'секунду','секунды','секунд').' назад';
return $timesp;
} else if(($time-$times)<=3600){$timesp = slv((($time-$times)/60),'минуту','минуты','минут').' назад';
return $timesp;
} else {
$today = date("j M Y", $time);
$today = date("j M Y", $time);
$yesterday = date("j M Y", strtotime("-1 day"));
$timesp=date("j M Y  в H:i", $times);
$timesp = str_replace($today, 'Сегодня', $timesp);
$timesp = str_replace($yesterday, 'Вчера', $timesp);
$timesp = strtr($timesp, array ("Jan" => "Янв","Feb" => "Фев","Mar" => "Марта","May" => "Мая","Apr" => "Апр","Jun" => "Июня","Jul" => "Июля","Aug" => "Авг","Sep" => "Сент","Oct" => "Окт","Nov" => "Ноября","Dec" => "Дек",));

return $timesp;}
}
  
function times2($string) {

$day=floor($string/86400); 
$hours=floor(($string/3600)-$day*24); 
$min=floor(($string-$hours*3600-$day*86400)/60); 
$sec=$string-($min*60+$hours*3600+$day*86400);

if($day > 0) $day2 = $day.' дней';
if($hours > 0 ) $hours2 = $hours.' часов';
if($min > 0 ) $min2 = $min.' минут';
if($sec > 0 ) $sec2 = $sec.' секунд';

return $day2.' '.$hours2.' '.$min2.' '.$sec2; 
}

function antispam($text){
$text = trim($text);
$anti = mysql_query("SELECT * FROM `antispam` ");
while($spam = mysql_fetch_array($anti)){
$text = str_replace($spam['site'],''.$spam['zamena'].'',$text);
}
return $text;
}
  
function bbcode($mes){

$mes=stripslashes($mes);

$mes = preg_replace("#(?:http:\/\/)?(.*?)(.gif|.png|.jpeg|.jpg)#",'<img src="http://\1\2" alt="Изображение">', $mes);


$mes = preg_replace('#\[url\](.*?)\[/url\]#si', '<a href="\1">Ссылка</a>', $mes);

$mes = preg_replace('#\[b\](.*?)\[/b\]#si', '<b>\1</b>', $mes);
$mes = preg_replace('#\[i\](.*?)\[/i\]#si', '<i>\1</i>', $mes);
$mes = preg_replace('#\[red\](.*?)\[\/red\]#si', '<span style="color:#FF0000;">\1</span>', $mes);
$mes = preg_replace('#\[blue\](.*?)\[\/blue\]#si', '<span style="color:#00008b;">\1</span>', $mes);
$mes = preg_replace('#\[white\](.*?)\[\/white\]#si', '<span style="color:#ffffff;">\1</span>', $mes);
$mes = preg_replace('#\[green\](.*?)\[\/green\]#si', '<span style="color:#006400;">\1</span>', $mes);
$mes = preg_replace('#\[u\](.*?)\[/u\]#si', '<u>\1</u>', $mes);
$mes = preg_replace('#\[cit\](.*?)\[/cit\]#si', '<div class="cit">\1</div>', $mes);
$mes = preg_replace('#\[url=(.*?)\](.*?)\[/url\]#si', '<a href="\1">\2</a>', $mes);

$mes=str_replace("\r\n","<br/>",$mes);
$mes=str_replace("[br]","<br/>",$mes);
$mes = preg_replace('#\[code\](.*?)\[/code\]#si', '<div class="cit"><code>\1</code></div>', $mes);

return $mes; 
}
  
function smiles($text){
$text = trim($text);
$smiles = mysql_query("SELECT * FROM `smiles` ORDER BY `id` DESC");
while($smiles2 = mysql_fetch_array($smiles)){
$text = str_replace($smiles2['name'],' <img src="/smiles/'.$smiles2['img'].'" alt="'.$smiles2['name'].'"/> ',$text);
}
return $text;
}

?>