<?php
require_once('blocks/inf.php');
function bbb($input){

 $input=str_replace ("<br><br>","\r\n\r\n", $input);
 $input=str_replace ("<br>","\r\n", $input);

 $find = array ("[b]", "[/b]", "[i]", "[/i]", "[u]", "[/u]");

 $replace = array ("'<b>'i", "'</b>'i", "'<i>'i", "'</i>'i", "'<u>'i", "'</u>'i");

 $input = preg_replace($replace, $find, $input);

 $cdom = "http://".$_SERVER['HTTP_HOST']."/";
 $input = str_replace("<img src=\"".$cdom."copilca/smile/1.gif\" border=\"0\" alt=\"\">",":-_",$input);
 $input = str_replace("<img src=\"".$cdom."copilca/smile/2.gif\" border=\"0\" alt=\"\">",":-8",$input);
 $input = str_replace("<img src=\"".$cdom."copilca/smile/3.gif\" border=\"0\" alt=\"\">",":-(",$input);
 $input = str_replace("<img src=\"".$cdom."copilca/smile/4.gif\" border=\"0\" alt=\"\">",":~)",$input);
 $input = str_replace("<img src=\"".$cdom."copilca/smile/5.gif\" border=\"0\" alt=\"\">",":-9",$input);
 $input = str_replace("<img src=\"".$cdom."copilca/smile/6.gif\" border=\"0\" alt=\"\">","8-)",$input);
 $input = str_replace("<img src=\"".$cdom."copilca/smile/7.gif\" border=\"0\" alt=\"\">","9-)",$input);
 $input = str_replace("<img src=\"".$cdom."copilca/smile/8.gif\" border=\"0\" alt=\"\">","10-)",$input);
 $input = str_replace("<img src=\"".$cdom."copilca/smile/9.gif\" border=\"0\" alt=\"\">","11-)",$input);
 $input = str_replace("<img src=\"".$cdom."copilca/smile/10.gif\" border=\"0\" alt=\"\">","12-)",$input);
 $input = str_replace("<img src=\"".$cdom."copilca/smile/11.gif\" border=\"0\" alt=\"\">","13-)",$input);

 return $input;
}
# имя пользователя по ид
function get_us_name($id){
$sql = mysql_query("SELECT `username` FROM `b_users` WHERE `id`='$id' LIMIT 1");
if(mysql_num_rows($sql) > 0){
return mysql_result($sql,0);
}else{
return "Неизвестный";
}
}
#вывод даты 
function date_get($data){
$dates = date("d.m",$data);
$date = date("d.m");
if($date == $dates) {
$date = "<b>Сегодня</b> ";
$date .= date("H:i", $data);
}else{
$date = date("d.m.y", $data);
}
return $date;
}
function valideint($str) {
return (isset($str)) ? filter_var($str, FILTER_VALIDATE_INT) : false;
}
function valideurl($str) {
return (isset($str)) ? filter_var($str, FILTER_VALIDATE_URL) : false;
}
function validefloat($str) {
return (isset($str)) ? filter_var($str, FILTER_VALIDATE_FLOAT) : false;
}
function valideip($str) {
return (isset($str)) ? filter_var($str, FILTER_VALIDATE_IP) : false;
}
function validemail($str) {
return (isset($str)) ? filter_var($str, FILTER_VALIDATE_EMAIL) : false;
}
function validetext($text) {
	$text = strip_tags($text);
	$text = str_replace('<', '', $text);
    $text = str_replace('>', '', $text);
    $text = str_replace('$', 'y.e', $text);
    $text = str_replace(';', '', $text);
    $text = str_replace('"', '', $text);
    $text = str_replace('\'', '', $text);
    $text = str_replace('`', '', $text);
	$text = trim($text);
	return $text;
}

function check_email($email) {
// Проверяем корректность введенного email на уровне формата 
if(!preg_match("/^(?:[a-z0-9]+(?:[-_]?[a-z0-9\.\-\_]+)?@[a-z0-9]+(?:\.?[a-z0-9]+)?\.[a-z]{2,5})$/i", substr($email, 0, 50))) { 
    return ''; 
} else {
  return $email;
}
}

function check_text($text){
	$text=strip_tags($text);
	$text=str_replace('"','&quot;',$text);
	$text=str_replace("'",'',$text);
	$text=str_replace(';','',$text);
	$text=str_replace('`','',$text);
	$text=str_replace('$','',$text);
	$text=trim($text);
	return $text;
}

function p_floor($val, $d){
	return floor($val*pow(10,$d))/pow(10,$d);
}

function getHost($url) {
	$host = str_replace("www.www.","www.", trim($url));
	$host = @parse_url($host);
	$host = trim($host['host'] ? $host['host'] : array_shift(explode('/', $host['path'], 2)));

	if(in_array("www", explode(".", $host))) {
		$just_domain = explode("www.", $host);
		return $just_domain[1];
	}else{
		return $host;
	}
}
function text_limit($text, $limit){
if(strlen($text)>$limit) {$text = substr($text,0,$limit);}
return $text;
}
function text($text){
		$text = str_replace(";"," ",$text);
		$text = str_replace("$"," ",$text);
		$text = str_replace("'"," ",$text);
		$text = str_replace("<"," ",$text);
		$text = str_replace(">"," ",$text);
		$text = strip_tags($text);
		$text = htmlspecialchars($text, ENT_QUOTES,'WINDOWS-1251');
		return $text;

}

function payment_title($title){
$title = str_replace("WebMoney", "<span style='color:#067BC1;'>WebMoney</span>", $title);
$title = str_replace("QiWi", "<span style='color:#067BC1;'><font color='#FE9903'>Q</font>iWi</span>", $title);
$title = str_replace("YandexMoney", "<span><font color='#FA1B0E'>Y</font>andexMoney</span>", $title);
$title = str_replace("LiqPay", "<span style='color:#7FC50F;'>LiqPay</span>", $title);
$title = str_replace("PerfectMoney", "<span style='color:#EC0000;'>PerfectMoney</span>", $title);
$title = str_replace("Payeer", "<span>Pay<font color='#2795D1'>eer</font></span>", $title);
return $title;
}

# количество рефералов
function count_referals($id){
return mysql_result(mysql_query("SELECT COUNT(id) FROM `b_users` WHERE `referer`='$id'"),0);
}

#отправка почты (новая)
function mail_ls_n($tema, $text, $toid, $tous, $fromid, $fromus ){
$tema = encoding(check_text($tema));
$text = encoding(check_text($text));
$text = nl2br($text);
mysql_query("INSERT INTO `b_mails` (`text`,`toid`,`tous`,`fromid`,`fromus`,`timemessage`,`read`) VALUES ('$tema','$toid','".strtolower($tous)."','$fromid','".strtolower($fromus)."','".time()."','5')") or die(mysql_error());
$ident = mysql_result(mysql_query("SELECT `id` FROM `b_mails` ORDER BY `id` DESC LIMIT 1"),0);
mysql_query("INSERT INTO `b_mails` (`text`,`toid`,`tous`,`fromid`,`fromus`,`timemessage`,`ident`) VALUES ('$text','$toid','".strtolower($tous)."','$fromid','".strtolower($fromus)."','".time()."','$ident')") or die(mysql_error());
}



# статусы
function user_status($reyting, $num){
$st_sql = mysql_query("SELECT * FROM `b_status` ORDER BY `id` ASC") or die(mysql_error());
while($st_row = mysql_fetch_assoc($st_sql)) {
$status[] = $st_row["status"];
$min_reyt[] = $st_row["min_reyt"];
$max_reyt[] = $st_row["max_reyt"];
$max_out[] = $st_row["max_out"];
$serf_mail[] = $st_row["serf_mail"];
$s_task[] = $st_row["task"];
$coll_out[] = $st_row["coll_out"];
}
if($reyting <= $max_reyt[0]) { if($num == 1){return $status[0];} if($num == 2){return $max_out[0];} if($num == 3){return $serf_mail[0];} if($num == 4){return $s_task[0];} if($num == 5){return $coll_out[0];}
}elseif($reyting >= $min_reyt[1] AND $reyting < $max_reyt[1]){if($num == 1){return $status[1];} if($num == 2){return $max_out[1];} if($num == 3){return $serf_mail[1];} if($num == 4){return $s_task[1];} if($num == 5){return $coll_out[1];}
}elseif($reyting >= $min_reyt[2] AND $reyting < $max_reyt[2]){if($num == 1){return $status[2];} if($num == 2){return $max_out[2];} if($num == 3){return $serf_mail[2];} if($num == 4){return $s_task[2];} if($num == 5){return $coll_out[2];}
}elseif($reyting >= $min_reyt[3] AND $reyting < $max_reyt[3]){if($num == 1){return $status[3];} if($num == 2){return $max_out[3];} if($num == 3){return $serf_mail[3];} if($num == 4){return $s_task[3];} if($num == 5){return $coll_out[3];}
}elseif($reyting >= $min_reyt[4] AND $reyting < $max_reyt[4]){if($num == 1){return $status[4];} if($num == 2){return $max_out[4];} if($num == 3){return $serf_mail[4];} if($num == 4){return $s_task[4];} if($num == 5){return $coll_out[4];}
}elseif($reyting >= $min_reyt[5] AND $reyting < $max_reyt[5]){if($num == 1){return $status[5];} if($num == 2){return $max_out[5];} if($num == 3){return $serf_mail[5];} if($num == 4){return $s_task[5];} if($num == 5){return $coll_out[5];}
}elseif($reyting > $min_reyt[6]){if($num == 1){return $status[6];} if($num == 2){return $max_out[6];} if($num == 3){return $serf_mail[6];} if($num == 4){return $s_task[6];} if($num == 5){return $coll_out[6];}
}
}

function coll_out($str){
if($str == 0) { return "Неограничено";} 
else if($str == 1){ return "3 часа";}
else if($str == 2){ return "6 часов";}
else if($str == 3){ return "12 часов";}
else if($str == 4){ return "24 часа";}
else if($str == 5){ return "36 часов";}
else if($str == 6){ return "48 часо";}
}

# отчисления от рефералов 2 уровня
function ref_ot2($src){
return floor((($src*pow(10,0))/pow(10,0))/12);
}

function payment_comis_p($src, $summa){
if($src == 2) { $out = $summa + 0.01; 
}elseif($src == 3) { $out = ($summa + max( 0.01, round( $summa * 0.5 ) / 100 )); 
}elseif($src == 4) { $out = ($summa + (ceil($summa * 2.9 ) / 100)); 
}elseif($src == 5) { $out= $summa + 0.01; 
}elseif($src == 6) { $out= ($summa + max( 0.01, round( $summa * 1 ) / 100 )); 
}else{ $out = $summa; }
return $out;
}

function payment_comis_m($src, $summa){
if($src == 1) {
if($summa >= 1.25) { $out = $summa - (($summa * 0.8)/100); }else{ $out = $summa - 0.01; }
}elseif($src == 3) { $out = ($summa - max( 0.01, round( $summa * 0.5 ) / 100 ));
}else{ $out = $summa; }
return $out;
}

function wm_atestat($wm_attestat){
if($wm_attestat == 0) { return "<img src='/images/ajax-loader.gif' align='absmiddle' title='Аттестат неопредлен' style='cursor:pointer;'>";
}elseif($wm_attestat == 100){ return "<img src='/images/att/att_100.ico' align='absmiddle' title='Аттестат Псевдонима' style='cursor:pointer;'>";
}elseif($wm_attestat == 110){ return "<img src='/images/att/att_110.ico' align='absmiddle' title='Формальный Аттестат' style='cursor:pointer;'>";
}elseif($wm_attestat == 120){ return "<img src='/images/att/att_120.ico' align='absmiddle' title='Начальный Аттестат' style='cursor:pointer;'>";
}elseif($wm_attestat == 130){ return "<img src='/images/att/att_130.ico' align='absmiddle' title='Персональный Аттестат' style='cursor:pointer;'>";
}elseif($wm_attestat == 135){ return "<img src='/images/att/att_135.ico' align='absmiddle' title='Аттестат Продавца' style='cursor:pointer;'>";
}elseif($wm_attestat == 136){ return "<img src='/images/att/att_136.ico' align='absmiddle' title='Аттестат Capitaller' style='cursor:pointer;'>";
}elseif($wm_attestat == 140){ return "<img src='/images/att/att_140.ico' align='absmiddle' title='Аттестат Разработчика' style='cursor:pointer;'>";
}elseif($wm_attestat == 150){ return "<img src='/images/att/att_150.ico' align='absmiddle' title='Аттестат Регистратора' style='cursor:pointer;'>";
}elseif($wm_attestat == 170){ return "<img src='/images/att/att_170.ico' align='absmiddle' title='Аттестат Гаранта' style='cursor:pointer;'>";
}elseif($wm_attestat == 190){ return "<img src='/images/att/att_190.ico' align='absmiddle' title='Аттестат Сервиса' style='cursor:pointer;'>";
}elseif($wm_attestat == 300){ return "<img src='/images/att/att_300.ico' align='absmiddle' title='Аттестат Оператора' style='cursor:pointer;'>";}
}

function is_img_size($width, $height, $urltest) {
$size = getimagesize($urltest);
$w = $size["0"];
$h = $size["1"];
if($w==intval($width) && $h==intval($height)) {
return "true";
}else{
return false;
}
}

function image_valid($type) {
	$file_types  = array(
		'image/pjpeg' => 'jpg',
		'image/jpeg' => 'jpg',
		'image/jpeg' => 'jpeg',
		'image/gif' => 'gif',
		'image/X-PNG' => 'png',
		'image/PNG' => 'png',
		'image/png' => 'png',
		'image/x-png' => 'png',
		'image/JPG' => 'jpg',
		'image/GIF' => 'gif',
		'image/bmp' => 'bmp',
		'image/bmp' => 'BMP'
	);
    
	if(!array_key_exists($type, $file_types)) {
		return "false";
	}else{
		return "true";
	}
}

function is_url_img($urltest) {
	$timeout = 5;
	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $urltest);
	curl_setopt($curl, CURLOPT_USERAGENT, "MySpider/1.0");
	curl_setopt($curl, CURLOPT_HEADER, 1);
	$headers = array("Accept: text/html, text/plain, application/xml", "Accept-Language: ru, ru-RU", "Accept-Charset: windows-1251", "Accept-Encoding: identity", "Connection: close","Cookie: test=5");
	curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	//curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
	$content = curl_exec($curl);
	$status1 = curl_getinfo($curl, CURLINFO_HTTP_CODE);
	$status2 = curl_getinfo($curl, CURLINFO_CONTENT_TYPE);

	if($status2==false) {
		return 'URL баннера не существует!';
		return false;
	}elseif(image_valid($status2) === "false"){
		return 'Не верно указана ссылка на баннер!';
		return false;
	}elseif($status1==200) {
		return "true";
	}elseif($status1==0) {
		return 'URL баннера не существует!';
		return false;
	}elseif($status1==302) {
		return 'Не верно указана ссылка на баннер!';
		return false;
	}else{
		return 'URL баннера не существует!';
		return false;
	}
}

function is_url($urltest) {
	$timeout = 5;
	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $urltest);
	curl_setopt($curl, CURLOPT_USERAGENT, "MySpider/1.0");
	curl_setopt($curl, CURLOPT_HEADER, 1);
	$headers = array("Accept: text/html, text/plain, application/xml", "Accept-Language: ru, ru-RU", "Accept-Charset: windows-1251", "Accept-Encoding: identity", "Connection: close","Cookie: test=5");
	curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	//curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
	$content = curl_exec($curl);
	$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

	if($status==404) {
		return 'Не верно указана ссылка на сайт!';
		curl_close($curl);
		return false;
	}elseif($status==200|$status==302) {
		return "true";
	}elseif($status==0) {
		return 'Ссылка не существует0!';
		curl_close($curl);
		return false;
	}else{
		return 'Ссылка не существует!';
		curl_close($curl);
		return false;
	}
	curl_close($curl);
}

function bbcode($text, $mode) {
  $str_search = array(
  "#\[br\]#is",
  "#\[p\](.+?)\[\/p\]#is",
  "#\[b\](.+?)\[\/b\]#is",
  "#\[i\](.+?)\[\/i\]#is",
  "#\[s\](.+?)\[\/s\]#is",
  "#\[u\](.+?)\[\/u\]#is",
  "#\[url=(.+?)\](.+?)\[\/url\]#is",
  "#\[url\](.+?)\[\/url\]#is",
  "#\[img\](.+?)\[\/img\]#is",
  "#\[size=(.+?)\](.+?)\[\/size\]#is",
  "#\[color=(.+?)\](.+?)\[\/color\]#is",
  "#\[list\](.+?)\[\/list\]#is",
  "#\[list=(1|a|I)\](.+?)\[\/list\]#is",
  "#\[\*\](.*)#",
  "#\[h(1|2|3|4|5|6)\](.+?)\[/h\\1\]#is");
  $str_replace = array(
  "<br />",
  "</p><p>\\1</p>",
  "<strong>\\1</strong>",
  "<span style='font-style:italic'>\\1</span>",
  "<span style='text-decoration:line-through'>\\1</span>",
  "<span style='text-decoration:underline'>\\1</span>",
  "<a href='\\1'>\\2</a>",
  "<a href='\\1'>\\1</a>",
  "<img src='\\1' />",
  "<span style='font-size:\\1pt'>\\2</span>",
  "<span style='color:\\1'>\\2</span>",
  "<ul>\\1</ul>",
  "<ol type='\\1'>\\2</ol>",
  "<li>\\1</li>",
  "<h \\1>\\2</h>");
  if ($mode=="html")
  {
  return preg_replace($str_search, $str_replace, $text);
  }else{
  return preg_replace($str_replace, $str_search, $text);
  }
}
#перекодировка
function encoding($string){
if(function_exists('iconv')) {
if(@!iconv('cp1251', 'utf-8', $string)) { $string = iconv('utf-8', 'cp1251', $string);}
return $string;
} else {
if (detectUTF8($string)) { return $string;       
} else {
return cp1251_utf8($string);
}
}
}
function getCountryByIp($ipAddress){
$details = json_decode(file_get_contents("http://ipinfo.io/{$ipAddress}"));
RETURN $details->country;
}
function send_mime_mail($name_from, // имя отправителя
                         $email_from, // email отправителя
                         $email_to, // email получателя
                         $data_charset, // кодировка переданных данных
                         $send_charset, // кодировка письма
                         $subject, // тема письма
                         $body // текст письма
                         ) {
   $to = $email_to;
   $subject = mime_header_encode($subject, $data_charset, $send_charset);
   $from =  mime_header_encode($name_from, $data_charset, $send_charset).' <' . $email_from . '>';
   if($data_charset != $send_charset) {
     $body = iconv($data_charset, $send_charset, $body);
   }
  
   $headers ="Content-type: text/html; charset=\"".$send_charset."\"\n";
   $headers .="From: $from\n";
   $headers.="Mime-Version: 1.0\n";

   return mail($to, $subject, $body, $headers);
}

function mime_header_encode($str, $data_charset, $send_charset) {
   if($data_charset != $send_charset) {
     $str = iconv($data_charset, $send_charset, $str);
   }
   return '=?' . $send_charset . '?B?' . base64_encode($str) . '?=';
}
function tuc($mensaje)
{
	if (preg_match("/^[a-zA-Z0-9\-_]{1,255}$/i", $mensaje))
	{
		return $mensaje;
	}else{
		$mensaje='';
		return $mensaje;
	}
}
function limitatexto( $texto, $limite )
  {
    if( strlen($texto)>$limite )
      {
        $texto = substr( $texto,0,$limite );
      }
    return $texto;

  }


function mostrarTemplate($tema, $variables)
{
    extract($variables);
    eval("?>".$tema."<?");
}

function parsearTags($mensaje)
{
    $mensaje = str_replace("[citar]", "<blockquote><hr width='100%' size='2'>", $mensaje);
    $mensaje = str_replace("[/citar]", "<hr width='100%' size='2'></blockquote>", $mensaje);
    return $mensaje;
}



function limpiar($mensaje){
$mensaje = htmlentities(stripslashes(trim($mensaje)));
$mensaje = str_replace("'"," ",$mensaje);
$mensaje = str_replace(";"," ",$mensaje);
$mensaje = str_replace("$"," ",$mensaje);
return $mensaje;
}

function generate_password($number){
    $arr = array('a','b','c','d','e','f',
                 'g','h','i','j','k','l',
                 'm','n','o','p','r','s',
                 't','u','v','x','y','z',
                 'A','B','C','D','E','F',
                 'G','H','I','J','K','L',
                 'M','N','O','P','R','S',
                 'T','U','V','X','Y','Z',
                 '1','2','3','4','5','6',
                 '7','8','9','0');
    // Генерируем пароль
    $pass = "";
    for($i = 0; $i < $number; $i++){
      // Вычисляем случайный индекс массива
      $index = rand(0, count($arr) - 1);
      $pass .= $arr[$index];
    }
    return $pass;
  }

function generate_code($number){
    $arr = array('1','2','3','4','5','6',
                 '7','8','9','0');
    // Генерируем код
    $pass = "";
    for($i = 0; $i < $number; $i++){
      // Вычисляем случайный индекс массива
      $index = rand(0, count($arr) - 1);
      $pass .= $arr[$index];
    }
    return $pass;
  }

function uc($mensaje){
if (!preg_match("/^[a-zA-Zа-яА-Я0-9\-_]{1,255}$/i", $mensaje)) {
	$mensaje = htmlentities(stripslashes(strtolower(trim($mensaje))));
	$mensaje = str_replace("'"," ",$mensaje);
	$mensaje = str_replace(";"," ",$mensaje);
	$mensaje = str_replace("$"," ",$mensaje);
	return $mensaje;
}else{ return $mensaje; }
}

function getRealIP(){

   if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
      $client_ip =
         ( !empty($_SERVER['REMOTE_ADDR']) ) ?
            $_SERVER['REMOTE_ADDR']
            :
            ( ( !empty($_ENV['REMOTE_ADDR']) ) ?
               $_ENV['REMOTE_ADDR']
               :
               "unknown" );
      $entries = explode('[, ]', $_SERVER['HTTP_X_FORWARDED_FOR']);

      reset($entries);
      while (list(, $entry) = each($entries)){
         $entry = trim($entry);
         if ( preg_match("/^([d]{1,3}).([d]{1,3}).([d]{1,3}).([d]{1,3})$/", $entry, $ip_list) ){
            $private_ip = array(
                  '/^0\./',
                  '/^127\.0\.0\.1/',
                  '/^192\.168\..*/',
                  '/^172\.((1[6-9])|(2[0-9])|(3[0-1]))\..*/',
                  '/^10\..*/');

            $found_ip = preg_replace($private_ip, $client_ip, $ip_list[1]);

            if ($client_ip != $found_ip)
            {
               $client_ip = $found_ip;
               break;
            }
         }
      }
   }else{
      $client_ip =
         ( !empty($_SERVER['REMOTE_ADDR']) ) ?
            $_SERVER['REMOTE_ADDR']
            :
            ( ( !empty($_ENV['REMOTE_ADDR']) ) ?
               $_ENV['REMOTE_ADDR']
               :
               "unknown" );
   }

   return $client_ip;

}
//получения wmid через кошелек
function getwmid($wmid) {
    $getwmid = file_get_contents('http://passport.webmoney.ru/asp/CertView.asp?purse=' . $wmid);
    $pos = strpos($getwmid, 'https://events.webmoney.ru/user.aspx?');
    $getwmid = substr($getwmid, $pos);
    $pos = strpos($getwmid, '"><img src=');
    $getwmid = substr($getwmid, 0, $pos);
    $getwmid = substr($getwmid, strlen($getwmid)-12);
    if (!is_numeric($getwmid) or strlen($getwmid) != 12) {
        $wmid = 1;
    } else {
        $wmid = $getwmid;
    }
    return $wmid;
}
function bbTags($var){
$bb = array('[b]', '[/b]');
$tag = array('<b>', '</b>');
return str_ireplace($bb, $tag, $var);
}

function smile($var){
for($x = 1; $x <= 50; $x++){
$symbol[] = '[:'.$x.':]';
}
for($x = 1; $x <= 50; $x++){
$graph[] = '<img src="/css/img/smille/'.$x.'.gif">';
}
return str_replace($symbol, $graph, $var);
}






function view_text($source){
$source = stripslashes( $source );
$source = nl2br(bbcode($source,"html"));
return $source;
}

function smyle_cng($smyle){
$_pattern = array();
$_replace = array();
for($x = 1; $x <= 50; $x++){
$_pattern[] = "[:$x:]";
$_replace[] = '<img class="smile" src="/css/img/smille/'.$x.'.gif" alt="[:'.$x.':]">';
}
$text = str_ireplace($_pattern, $_replace, $smyle);
return $text;
}

function smyle_v($smyle){
    $text = '<img class="smile" src="/css/img/smille/'.$smyle.'.gif" alt="[:'.$smyle.':]">';
    return $text;
}

function quotes($source){
$count_start = substr_count ($source, "[quote");
$count_end = substr_count ($source, "[/quote]");
if ($count_start AND $count_start == $count_end) {
$source = str_ireplace( "[quote=]", "<div>", $source );
$source = preg_replace( "#\[quote=(.+?)\]#i", "<!--QuoteBegin \\1 --><div class=\"f-title_quote\">Цитата: \\1</div><div class=\"f-quote\"><!--QuoteEBegin-->", $source );
$source = str_ireplace( "[/quote]", "<!--QuoteEnd--></div><!--QuoteEEnd-->", $source );
}
return $source;
}

function times($time){
$month_name = array( 1 => 'января',2 => 'февраля',3 => 'марта',4 => 'апреля',5 => 'мая',6 => 'июня',7 => 'июля',8 => 'августа',9 => 'сентября',10 => 'октября',11 => 'ноября',12 => 'декабря');
$month = $month_name[ date( 'n',$time ) ];
$day   = date( 'j',$time );
$year  = date( 'Y',$time );
$hour  = date( 'G',$time );
$min   = date( 'i',$time );
$date = $day . ' ' . $month . ' ' . $year . ' в ' . $hour . ':' . $min;
$dates = $hour . ':' . $min;
$dif = time()- $time;
$qwe = round($time/86400);
if($dif<59){
return $dif." сек. назад";
}elseif($dif/60>1 and $dif/60<59){
return round($dif/60)." мин. назад";
}else{
return $date;
}
}


?>