<?

    function _string($string) {
      
    $string = trim($string);
    
          $string = mysql_escape_string($string);
      
    $string = htmlspecialchars($string);

    return $string;
    
    }
    
    function _num($i) {
    
      $i = (int) abs($i);
    
    return $i;
    
    }
    
    function n_f($i) {

    if($i >= 10 && $i < 100) {
    
      $i = number_format($i, 0, '', '`');
    
      $i = round($i,3).'k';
    
    }
elseif($i >= 100) {

      $i = number_format($i, 0, '', '`');
    
      $i = round($i,3).'m';

    }
    else
    {
      
      $i = number_format($i, 0, '', '`');
     
    }
       
    return $i;
    
    }

    function pages($path) {
  
    global $page, $pages;
        
      if($page - 1 > 0) {

        echo '<a wicket:id="pageLink" href="'.$path.'page='.($page - 1).'" class="pg" title="2"><span wicket:id="pageNumber">«</span></a>
</wicket:container><wicket:container wicket:id="pages">';
        
      }
        
      if($page == $pages && $page - 4 > 0) {

        echo '<a href="'.$path.'page='.($page - 4).'">
		<a wicket:id="pageLink" href="'.$path.'page='.($page - 4).'" class="pg" title="2"><span wicket:id="pageNumber">'.($page - 4).'</span></a>
</wicket:container><wicket:container wicket:id="pages"><wicket:container wicket:id="pages"></a>';
        
      }

        
      if($page == $pages && $page - 3 > 0) {

        echo '<a href="'.$path.'page='.($page - 3).'">
		<a wicket:id="pageLink" href="'.$path.'page='.($page - 3).'" class="pg" title="2"><span wicket:id="pageNumber">'.($page - 3).'</span></a>
</wicket:container><wicket:container wicket:id="pages"><wicket:container wicket:id="pages"></a>';
        
      }
        
      if($page - 2 > 0) {

        echo '<a href="'.$path.'page='.($page - 2).'">
		<a wicket:id="pageLink" href="'.$path.'page='.($page - 2).'" class="pg" title="2"><span wicket:id="pageNumber">'.($page - 2).'</span></a>
</wicket:container><wicket:container wicket:id="pages"><wicket:container wicket:id="pages"></a>';
        
      }

        
      if($page - 1 > 0) {

        echo '<a href="'.$path.'page='.($page - 1).'">
		<a wicket:id="pageLink" href="'.$path.'page='.($page - 1).'" class="pg" title="2"><span wicket:id="pageNumber">'.($page - 1).'</span></a>
</wicket:container><wicket:container wicket:id="pages"><wicket:container wicket:id="pages"></a>';
        
      }


      echo $page;
        
       
      if($page + 1 <= $pages) {

        echo '<a href="'.$path.'page='.($page + 1).'">
		<a wicket:id="pageLink" href="'.$path.'page='.($page + 1).'" class="pg" title="2"><span wicket:id="pageNumber">'.($page + 1).'</span></a>
</wicket:container><wicket:container wicket:id="pages"><wicket:container wicket:id="pages"></a>';
        
      }

        
      if($page + 2 <= $pages) {

        echo '<a href="'.$path.'page='.($page + 2).'">
		<a wicket:id="pageLink" href="'.$path.'page='.($page + 2).'" class="pg" title="2"><span wicket:id="pageNumber">'.($page + 2).'</span></a>
</wicket:container><wicket:container wicket:id="pages"><wicket:container wicket:id="pages"></a>';
        
      }
        
      if($page == 1 && $page + 3 <= $pages) {

        echo '<a href="'.$path.'page='.($page + 3).'">
		<a wicket:id="pageLink" href="'.$path.'page='.($page + 3).'" class="pg" title="2"><span wicket:id="pageNumber">'.($page + 3).'</span></a>
</wicket:container><wicket:container wicket:id="pages"><wicket:container wicket:id="pages"></a>';
        
      }
        
      if($page == 1 && $page + 4 <= $pages) {

        echo '<a href="'.$path.'page='.($page + 4).'">
		<a wicket:id="pageLink" href="'.$path.'page='.($page + 4).'" class="pg" title="2"><span wicket:id="pageNumber">'.($page + 4).'</span></a>
</wicket:container><wicket:container wicket:id="pages"><wicket:container wicket:id="pages"></a>';
        
      }

        
      if($page + 1 <= $pages) {

        echo '<a wicket:id="pageLink" href="'.$path.'page='.($page + 1).'" class="pg" title="2"><span wicket:id="pageNumber">»</span></a>
</wicket:container><wicket:container wicket:id="pages">';

      }
	}
    
	
function bbcode($str)
{

//$str = strip_tags($str);
//$str=preg_replace("/@(.+)\@/Usi","<a href='/site.php?nick=\\1'>\\1</a>",$str);
//$str = preg_replace("/@(. )/si","<a href='/site.php?nick=\\1'>\\1</a>",$str);
$str=preg_replace("/\[b\](.+)\[\/b\]/Usi","<strong>\\1</strong>",$str);
$str=preg_replace("/\[i\](.+)\[\/i\]/Usi","<em>\\1</em>",$str);
$str=preg_replace("/\[u\](.+)\[\/u\]/Usi","<u>\\1</u>",$str);
$str=preg_replace("/\[s\](.+)\[\/s\]/Usi","<s>\\1</s>",$str);
//$str=preg_replace("/\[b\](.+)\[\/b\]/Usi","<big>\\1</big>",$str);
$str=preg_replace("/\[small\](.+)\[\/small\]/Usi","<small>\\1</small>",$str);
$str=preg_replace("/\[sup\](.+)\[\/sup\]/Usi","<sup>\\1</sup>",$str);
$str=preg_replace("/\[sub\](.+)\[\/sub\]/Usi","<sub>\\1</sub>",$str);
$str=preg_replace("/\[code\](.+)\[\/code\]/Usi","<code>\\1</code>",$str);
$str=preg_replace("/\[color=(.*)](.*)\[\/color\]/Usi", "<font color='\\1'>\\2</font>", $str);
$str=preg_replace("/\[rang=(.*)](.*)\[\/rang\]/Usi", "<div style='background-color:\\1'>\\2</div>", $str);
$str=preg_replace("/\[size=(.*)\](.*)\[\/size\]/Usi", "<span style=\"font-size:\\1\">\\2</span>", $str);
$str=preg_replace("/\[img=(.*)\]/Usi","<img src='\\1' border=\"0\"/>",$str);
$str=preg_replace("/\[br]/Usi","<br>",$str);
$str=preg_replace("/\[hr]/Usi","<hr>",$str);
//$str = preg_replace("/@(.*)/si","<a href='/site.php?nick=\\1'>$1</a>",$str);
$str=preg_replace("/\[url=(.*)\](.*)\[\/url\]/Usi","<a href='\\1'>\\2</a>",$str);
$str=preg_replace("/\[center](.*)\[\/center\]/Usi","<div align=center>\\1</div>",$str);
$str=preg_replace("/\[right](.*)\[\/right\]/Usi","<div align=right>\\1</div>",$str);
$str=preg_replace("/\[left](.*)\[\/left\]/Usi","<div align=left>\\1</div>",$str);
$str=str_replace("\r\n","<br/>",$str);
return $str;
}

function bbfunc($str)
{

$str=preg_replace("/\<strong\>(. )\<\/strong\>/Usi","[b]\\1[/b]",$str);
$str=preg_replace("/\<em\>(. )\<\/em\>/Usi","[i]\\1[/i]",$str);
$str=preg_replace("/\<u\>(. )\<\/u\>/Usi","[u]\\1[/u]",$str);
$str=preg_replace("/\<s\>(. )\<\/s\>/Usi","[s]\\1[/s]",$str);
$str=preg_replace("/\<big\>(. )\<\/big\>/Usi","[big]\\1[/big]",$str);
$str=preg_replace("/\<small\>(. )\<\/small\>/Usi","[small]\\1[/small]",$str);
$str=preg_replace("/\<sup\>(. )\<\/sup\>/Usi","[sup]\\1[/sup]",$str);
$str=preg_replace("/\<sub\>(. )\<\/sub\>/Usi","[sub]\\1[/sub]",$str);
$str=preg_replace("/\<code\>(. )\<\/code\>/Usi","[code]\\1[/code]",$str);
$str=preg_replace("/\<br\/>/Usi", "\n", $str);
$str=preg_replace("/\<span style=\"color:(.*)\">(.*)\<\/span\>/Usi","[color=\\1]\\2[/color]", $str);
$str=preg_replace("/\<span style=\"font-size:(.*)\">(.*)\<\/span\>/Usi", "[size=\\1]\\2[/size]", $str);
$str=preg_replace("/\<img src='(.*)'\ alt='(.*)'\ border=\"0\"\/>/Usi","[img=\\1]\\2[/img]",$str);

//$str = strip_tags($str);

return $str;
}

	
    function smiles($string) {
    
      $string = str_replace(array(':)',':смайл'), '<img src="/images/smiles/1.png" alt="*"/>',      $string);
      $string = str_replace(array(':(','(('),'<img src="/images/smiles/2.png" alt="*"/>',      $string);
      $string = str_replace(array(')))',':лол'),'<img src="/images/smiles/3.png" alt="*"/>',     $string);
      $string = str_replace(array(':злой'),'<img src="/images/smiles/4.png" alt="*"/>',        $string);
      $string = str_replace(array(':язык'),'<img src="/images/smiles/5.png" alt="*"/>',         $string);
      $string = str_replace(array(':плак'),'<img src="/images/smiles/6.png" alt="*"/>',       $string);
      $string = str_replace(array(';)',':подмиг'),'<img src="/images/smiles/7.png" alt="*"/>', $string);
      $string = str_replace(array(':вау'),'<img src="/images/smiles/8.png" alt="*"/>',        $string);
      $string = str_replace(array(':шок'),'<img src="/images/smiles/9.png" alt="*"/>', $string);
      $string = str_replace(array(':крут'),'<img src="/images/smiles/10.png" alt="*"/>',        $string);
      $string = str_replace(array(':фу'),'<img src="/images/smiles/11.png" alt="*"/>',        $string);
      $string = str_replace(array(':класс'),'<img src="/images/smiles/12.png" alt="*"/>',        $string);
      $string = str_replace(array(':плохо'),'<img src="/images/smiles/13.png" alt="*"/>',        $string);
      $string = str_replace(array(':класс2'),'<img src="/images/smiles/14.png" alt="*"/>',        $string);
      $string = str_replace(array(':бомба'),'<img src="/images/smiles/15.png" alt="*"/>',        $string);
      $string = str_replace(array(':дружба'),'<img src="/images/smiles/16.png" alt="*"/>',        $string);
      $string = str_replace(array(':куку'),'<img src="/images/smiles/17.png" alt="*"/>',        $string);
      $string = str_replace(array(':очки'),'<img src="/images/smiles/18.png" alt="*"/>',        $string);	  
	  $string = str_replace(array(':дум'),'<img src="/images/smiles/19.png" alt="*"/>',        $string);
      $string = str_replace(array(':дум2'),'<img src="/images/smiles/20.png" alt="*"/>',        $string);
      $string = str_replace(array(':фэйспалм'),'<img src="/images/smiles/21.png" alt="*"/>',        $string);
      $string = str_replace(array(':агресия'),'<img src="/images/smiles/22.png" alt="*"/>',        $string);
      $string = str_replace(array(':золото'),'<img src="/images/smiles/23.png" alt="*"/>',        $string);
	  $string = str_replace(array(':рубин'),'<img src="/images/smiles/24.png" alt="*"/>',        $string);
	  $string = str_replace(array(':алмаз'),'<img src="/images/smiles/25.png" alt="*"/>',        $string);
      $string = str_replace(array('ru','com','ua','cf','ml','ga','сайт','http://'),'<img src="/images/smiles/27.png" alt="*"/>',        $string);
      $string = str_replace(array(':демон'),'<img src="/images/smiles/26.png" alt="*"/>',        $string);
      $string = str_replace(array(':кот'),'<img src="/images/smiles/27.png" alt="*"/>',          $string);   
      $string = str_replace(array(':незнаю'),'<img src="/images/smiles/28.png" alt="*"/>',        $string);      
      $string = str_replace(array(':хочуспать'),'<img src="/images/smiles/29.png" alt="*"/>',        $string);
      $string = str_replace(array(':сплю'),'<img src="/images/smiles/30.png" alt="*"/>',        $string);
	  $string = str_replace(array(':роза'),'<img src="/images/smiles/31.png" alt="*"/>',        $string);
	  $string = str_replace(array(':поцелуй'),'<img src="/images/smiles/32.png" alt="*"/>',        $string);
$string=bbcode($string);
    return $string;
    
    }


    function _time($i) {

      $h  = floor(($i / 3600) - $d * 24); 
      
      $m  = floor(($i - $h * 3600 - $d * 86400) / 60); 
      
      $s  = $i - ($m * 60 + $h * 3600 + $d * 86400);
    
      
    return ($h > 0 ? ($h < 10 ? '0':'').$h.':':'').($m > 0 ? ($m < 10 ? '0':'').$m.':':'00:').($s > 0 ? ($s < 10 ? '0':'').$s:'00');
    
    }
    
    function bb($string) {
      
      $string = str_replace("\r\n","<br/>",$string);
    
    return $string;
    
    }
    
    function _times($i) {

      $d  = floor($i / 86400); 
      
      $h  = floor(($i / 3600) - $d * 24); 
      
      $m  = floor(($i - $h * 3600 - $d * 86400) / 60); 
      
      $s  = $i - ($m * 60 + $h * 3600 + $d * 86400);

    
      if($d > 0) {
      
        $result = $d.' д';
       
      }
      elseif($h > 0)
                 {
       
        $result = $h.' ч';
                
      }elseif($m > 0)
                 {
       
      $result = $m.' мин';
                
      }elseif($s >= 0)
                 {
       
      $result = $s.' сек';
                
      }

  return $result.' назад';
  
  }


?>