View file inc/func.php

File size: 20.96Kb
<?php

######ket noi data###
if(file_exists('inc/db_conf.php') OR file_exists('../inc/db_conf.php')){
require 'db_conf.php';
$db = mysql_connect(dbhost,dbuser,dbpass) or die('Lỗi kết nối!');
mysql_query("SET NAMES `utf8`, $db");
mysql_select_db(dbname, $db) or die('Database không tồn tại!');
}else{
header('location: /install');
}
####khoi tao session
session_start();
ob_start();

define('homeurl','http://'.$_SERVER['HTTP_HOST']);



#####khoi tao bien user###

if(isset($_COOKIE['user']) && isset($_COOKIE['pass']))
{
$user = $_COOKIE['user'];
$userid = $_COOKIE['userid'];
}elseif(isset($_SESSION['user']) && isset($_SESSION['pass']))
{
$user = $_SESSION['user'];
$userid = $_SESSION['userid'];
}else{
$user = NULL;
$userid = NULL;
}

if($user != NULL){
$q_users = mysql_query("SELECT * FROM `users` WHERE `username` = '".$user."' ");
$datauser = mysql_fetch_assoc($q_users);
}

if(isset($_GET['lang']))
{

	$lang = htmlentities($_GET['lang']);
	if(!is_dir('./inc/lang/'.$lang))

		die('language not found');
	
	if($user){
		$lang = htmlentities($_GET['lang']);
		mysql_query("UPDATE `users` SET `language` = '$lang' WHERE `id` = '$userid';");
	}
	if(!$user){
		$lang = htmlentities($_GET['lang']);
		$_SESSION['lang'] = $lang;
	}
	header('Location: '.$_SERVER['HTTP_REFERER']);
}
require 'lang.php';

function bk_head($title) {

echo '<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
   <title>Baka Social - '.$title.'</title>
   <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
   <link rel="stylesheet" type="text/css" href="/style/style.css"/>
   <meta name="title" content="Baka social - Mạng xã hội giải trí trên mobile" />
   <meta name="description" content="Mạng xã hội giải trí tổng hợp hay cho mọi người"/>
   <meta property="og:site_name" content="Mạng xã hội giải trí trên mobile"/>
   <meta property="og:image" content="logo.png"/>
   <meta property="og:title" content="Baka social - Mạng xã hội giải trí trên mobile"/>
   <meta property="og:description" content="Mạng xã hội giải trí tổng hợp hay cho mọi người" />
   <meta property="og:type" content="article"/>
   <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
   <meta property="og:url" content="http://bakasocial.tk/"/>
</head>
<body>';

}

function bk_foot() {
if($_SERVER['PHP_SELF']=="/index.php" OR $_SERVER['PHP_SELF']=="/reg.php"){
echo '<div class="shadow"><a href="?lang=vn" title="Vietnames"><img src="/images/flag/vn.gif" height="11" width="16" alt="vn" /></a>&nbsp;<a href="?lang=ru" title="Русский"><img src="/images/flag/ru.gif" height="" width="" alt="ru" /></a>&nbsp;<a href="?lang=en" title="English"><img src="/images/flag/en.gif" height="11" width="16" alt="eng" /></a></div>';
}
echo '<div class="foot"><b style="font-size:10px;">&copy; ' . date("Y") . ' Baka Community<br />Code By <a href="'.homeurl.'">&hearts; baka a.k.a crazy</a></div></body></html>';
ob_end_flush();

}

function tagtv($name){
$sql=mysql_query("SELECT * FROM `users` WHERE `username`='{$name}'");
$m=mysql_num_rows($sql);
if($m==0){
$link='@'.$name.'';

}else{
$u=mysql_fetch_array($sql);
$link='@<a href="'.homeurl.'/u/'.$u['id'].'">'.$u['username'].'</a>';
}
return $link;
}

function bk_check($str) {
$str = trim($str);
$str = htmlspecialchars($str);
$str = mysql_real_escape_string($str);
return $str;
}

function tags($var)
    {
        $var = k_word($var);
        $var = preg_replace(array ('#@([\w\d]{2,})#se'), array ("''.tagtv('$1').''"), str_replace("]\n", "]", $var));
        $var = highlight_bb($var);
        return $var;
    }

function highlight_bb($var)
    {
        // Список поиска
        $search = array(
            '#\[b](.+?)\[/b]#is',
            '#\[i](.+?)\[/i]#is',
            '#\[u](.+?)\[/u]#is',
            '#\[s](.+?)\[/s]#is',
            '#\[small](.+?)\[/small]#is',
            '#\[big](.+?)\[/big]#is',
            '#\[red](.+?)\[/red]#is',
	'#\[vred](.+?)\[/vred]#is',
            '#\[green](.+?)\[/green]#is',
	'#\[vgreen](.+?)\[/vgreen]#is',
            '#\[blue](.+?)\[/blue]#is',
	'#\[vblue](.+?)\[/vblue]#is',
            '!\[color=(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z\-]+)](.+?)\[/color]!is',
            '!\[bg=(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z\-]+)](.+?)\[/bg]!is',
            '#\[quote](.+?)\[/quote]#is',
            '#\[c](.+?)\[/c]#is',
            '#\[\*](.+?)\[/\*]#is',
	'#\[code](.+?)\[/code]#is',
	'#\[php](.+?)\[/php]#is',
	'#\[text](.+?)\[/text]#is',
	'#\[list](.+?)\[/list]#is',
	'#\[dl](.+?)\[/dl]#is',
	'#\[phai](.+?)\[/phai]#is',
	'#\[right](.+?)\[/right]#is',
	'#\[trai](.+?)\[/trai]#is',
	'#\[left](.+?)\[/left]#is',
	'#\[giua](.+?)\[/giua]#is',
	'#\[center](.+?)\[/center]#is',
	'#\[html](.+?)\[/html]#is',
	'#\[quote=(.+?)\](.+?)\[/quote]#is',
	'#\[img=(.+?)\](.+?)\[/img]#is',
	'#\[img=(.+?)\]#is',
	'#\[img](.+?)\[/img]#is',
	'#\[cimg](.+?)\[/cimg]#is',
	'#\[size=(.+?)\](.+?)\[/size]#is',
	'#\[font=(.+?)\](.+?)\[/font]#is',
        '#\[size=(.+?)\](.+?)\[/size]#is',
	'#\[mp3](.+?)\[/mp3]#is'
        );
        // Список замены
        $replace = array(
            '<span style="font-weight: bold">$1</span>', // Жирный
            '<span style="font-style:italic">$1</span>', // Курсив
            '<span style="text-decoration:underline">$1</span>',
            '<span style="text-decoration:line-through">$1</span>',
            '<span style="font-size:x-small">$1</span>',
            '<span style="font-size:large">$1</span>',
            '<span style="color:red">$1</span>',
	'<span style="text-shadow: 1px 3px 9px red;">$1</span>',
            '<span style="color:green">$1</span>',
	'<span style="text-shadow: 1px 3px 9px green;">$1</span>',
            '<span style="color:blue">$1</span>',
	'<span style="text-shadow: 1px 3px 9px blue;">$1</span>',
            '<span style="color:$1">$2</span>',
            '<span style="background-color:$1">$2</span>',
            '<span class="quote" style="display:block">$2</span>',
            '<div class="bbcode_container"><div class="bbcode_quote"><div class="quote_container"><div class="bbcode_quote_container"></div> \1</div></div></div>',
            '<span class="bblist">$1</span>',
	'<div class="tt">PHP CODE</div><div class="shadow">$1</div>',
	'<div class="tt">PHP CODE</div><div class="shadow">$1<br /><br /><b>//http://bakasocial.tk</b></div>',
	'<b>TEXT (coppy):</b><br><textarea>$1</textarea><br>',
	'<ul>$1</ul>',
	'<div class="quote"><img src="/images/download.gif"><b><a href="$1"><font color="green">Tải về tập tin</b></font></a></br></div>',
	'<div align="right">$1</div>',
	'<div align="right">$1</div>',
	'<div align="left">$1</div>',
	'<div align="left">$1</div>',
	'<div align="center">$1</div>',
	'<div align="center">$1</div>',
	'<div class="bbcode_container"><div class="bbcode_description" style="padding-bottom: 2px;">HTML Code:</div><div style="width: auto; max-height: 200px; white-space: nowrap; overflow: scroll; border: 1px inset; padding: 4px; background: none repeat scroll 0% 0% rgb(242, 246, 248); text-align: left; direction: ltr;"><pre class="bbcode_code" style=""><p>$1</p></pre></div></div>',
	'<div class="quote">$1 đã viết</div><div class="quote">$2</div>',
	'<center><a href="$1"><img src="$1" alt="$2" border="0" /></a></center><br/>',
	'<center><a href="$1"><img src="$1" alt="$1" border="0" /></a></center><br/>',
	'<center><a href="$1"><img src="$1" alt="$1" border="0" /></a></center><br/>',
	'<center><a href="$1"><img src="/cimg.php?img=$1" alt="$1" /></a></center><br/>',
	'<font style="font-size:$1px;">$2</font>',
	'<font face="$1">$2</font>',
        '<font style="font-size:$1;">$2</font>',
	'<center><embed height="80" quality="high" src="http://static.mp3.zing.vn/skins/gentle/flash/mp3player.swf?xmlURL=http://mp3.zing.vn/play/?pid=$1||4&amp;songID=0&amp;_mp3=&amp;autoplay=false&amp;wmode=transparent" type="application/x-shockwave-flash" width="430" wmode="transparent"></embed></center>'
        );
        return preg_replace($search, $replace, $var);
    }	
		
	
function k_word($var)
    {
        $search1 = array(
'(tm)',
'(TM)',
'(c)', 
'(C)',
'(r)',
'(R)',
':bull',
'=))',
':3',
':cry',
':P',
'O:)',
'3:)',
'o.O',
':O',
'-_-',
'>:O',
':*',
'<3',
'^_^',
'8)',
'8|',
'(^^^)',
':|]',
'<(")',
':v',
'(y)',
'lồn',
'buồi',
'cặc',
'cặt',
'đụ',
'địt mẹ'
        );
        $replace1 = array(
'™',
'™',
'©',
'©',
'®',
'®',
'• ',
'<img src="'.homeurl.'/smiles/cuoi.gif" alt="cười lăn lộn">',
'<img src="'.homeurl.'/smiles/icon/curly-lips-emoticon.png" alt="3">',
'<img src="'.homeurl.'/smiles/icon/facebook-cry-emoticon-crying-symbol.png">',
'<img src="'.homeurl.'/smiles/icon/facebook-tongue-out-emoticon.png">',
'<img src="'.homeurl.'/smiles/icon/angel emoticon.png">',
'<img src="'.homeurl.'/smiles/icon/devil emoticon.png">',
'<img src="'.homeurl.'/smiles/icon/confused-emoticon-wtf-symbol-for-facebook.png">',
'<img src="'.homeurl.'/smiles/icon/surprised emoticon.png">',
'<img src="'.homeurl.'/smiles/icon/squint emoticon.png">',
'<img src="'.homeurl.'/smiles/icon/angry emoticon.png">',
'<img src="'.homeurl.'/smiles/icon/kiss emoticon.png">',
'<img src="'.homeurl.'/smiles/icon/heart emoticon.png">',
'<img src="'.homeurl.'/smiles/icon/kiki emoticon.png">',
'<img src="'.homeurl.'/smiles/icon/glasses emoticon.png">',
'<img src="'.homeurl.'/smiles/icon/sunglasses emoticon.png">',
'<img src="'.homeurl.'/smiles/icon/shark emoticon.png">',
'<img src="'.homeurl.'/smiles/icon/robot emoticon.png">',
'<img src="'.homeurl.'/smiles/icon/facebook-penguine-emoticon.png">',
'<img src="'.homeurl.'/smiles/icon/pacman-emoticon.png">',
'<img src="'.homeurl.'/smiles/icon/thumb-up-facebook-emoticon-like-symbol.png">',
'*** ',
'*** ',
'*** ',
'*** ',
'*** ',
'*** '
        );
        return str_replace($search1, $replace1, $var);
}

function rewrite($text)
{
$text = html_entity_decode(trim($text), ENT_QUOTES, 'UTF-8');
$text=str_replace(" ","-", $text);$text=str_replace("--","-", $text);
$text=str_replace("@","-",$text);$text=str_replace("/","-",$text);
$text=str_replace("\"","",$text);$text=str_replace("'","",$text);
$text=str_replace("<","",$text);$text=str_replace(">","",$text);
$text=str_replace(",","",$text);$text=str_replace("?","",$text);
$text=str_replace(";","",$text);$text=str_replace(".","",$text);
$text=str_replace("[","",$text);$text=str_replace("]","",$text);
$text=str_replace("(","",$text);$text=str_replace(")","",$text);
$text=str_replace("́","", $text);
$text=str_replace("̀","", $text);
$text=str_replace("̃","", $text);
$text=str_replace("̣","", $text);
$text=str_replace("̉","", $text);
$text=str_replace("*","",$text);$text=str_replace("!","",$text);
$text=str_replace("$","-",$text);$text=str_replace("&","-and-",$text);
$text=str_replace("%","",$text);$text=str_replace("#","",$text);
$text=str_replace("^","",$text);$text=str_replace("=","",$text);
$text=str_replace("+","",$text);$text=str_replace("~","",$text);
$text=str_replace("`","",$text);$text=str_replace("--","-",$text);
$text = preg_replace("/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/", 'a', $text);
$text = preg_replace("/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/", 'a', $text);
$text = preg_replace("/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/", 'e', $text);
$text = preg_replace("/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/", 'e', $text);
$text = preg_replace("/(ì|í|ị|ỉ|ĩ)/", 'i', $text);
$text = preg_replace("/(ì|í|ị|ỉ|ĩ)/", 'i', $text);
$text = preg_replace("/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/", 'o', $text);
$text = preg_replace("/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/", 'o', $text);
$text = preg_replace("/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/", 'u', $text);
$text = preg_replace("/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/", 'u', $text);
$text = preg_replace("/(ỳ|ý|ỵ|ỷ|ỹ)/", 'y', $text);
$text = preg_replace("/(đ)/", 'd', $text);
$text = preg_replace("/(ỳ|ý|ỵ|ỷ|ỹ)/", 'y', $text);
$text = preg_replace("/(đ)/", 'd', $text);
$text = preg_replace("/(À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ)/", 'A', $text);
$text = preg_replace("/(À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ)/", 'A', $text);
$text = preg_replace("/(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)/", 'E', $text);
$text = preg_replace("/(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)/", 'E', $text);
$text = preg_replace("/(Ì|Í|Ị|Ỉ|Ĩ)/", 'I', $text);
$text = preg_replace("/(Ì|Í|Ị|Ỉ|Ĩ)/", 'I', $text);
$text = preg_replace("/(Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ)/", 'O', $text);
$text = preg_replace("/(Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ)/", 'O', $text);
$text = preg_replace("/(Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)/", 'U', $text);
$text = preg_replace("/(Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)/", 'U', $text);
$text = preg_replace("/(Ỳ|Ý|Ỵ|Ỷ|Ỹ)/", 'Y', $text);
$text = preg_replace("/(Đ)/", 'D', $text);
$text = preg_replace("/(Ỳ|Ý|Ỵ|Ỷ|Ỹ)/", 'Y', $text);
$text = preg_replace("/(Đ)/", 'D', $text);
$text=strtolower($text);
return $text;
}

function err($des){
echo '<div class="notic"><i>'.$des.'</i></div>';
}

function num($str)
{
	return intval(trim($str));
}

function check_mail($mail) {
if (strlen($mail) == 0) return false;
if (eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,4})$", $mail)) return true;
return false;
}

function user_info($id,$str)
{
    $query = mysql_query("SELECT * FROM users WHERE id = '$id' ");
    $req = mysql_fetch_assoc($query);
    return $req[$str];
}


function online($id) {
$on = mysql_fetch_array(mysql_query("SELECT `last_active` FROM  users WHERE `id` = '$id' "));
if($on['last_active'] > (time()-300)) {
   $out =  '<img src = "/images/on.png">';
   } else {
   $out = '<img src = "/images/off.png">';
   }
return $out;
}

function user($id)
{
	$users = mysql_fetch_array(mysql_query("SELECT `id`, `username`, `last_active` FROM `users` WHERE `id` = '$id' LIMIT 1 "));
	if($users['last_active'] > (time()-300)){
	$out = '<img src = "/images/on.png">';
	}else{
	$out = '<img src = "/images/off.png">';
}
	echo '<a href="/u/' . $users['id'] . '" title="' . $users['username'] . '">' . $users['username'] . '' .$out. '</a>';
}

function avatar($id, $w, $h) {
	$req = mysql_query("SELECT * FROM `users` WHERE `id`='".$id."' LIMIT 1");
	$p = mysql_fetch_assoc($req);
	
	if($p['avatar']){
	echo '<a href = "/u/'.$p['id'].'"><img src="/gallery/photos/'.$p['id'].'/micro/'.$p['avatar'].'" width="'.$w.'" height="'.$h.'" /></a>';
	} else {
		$gender = mysql_fetch_assoc(mysql_query("SELECT `gender` FROM `users` WHERE `id` = '".$id."'"), 0);
    echo '<a href = "/u/'.$p['id'].'"><img src="/images/'.$gender['gender'].'.png" width="' . $w . '" height="' . $h . '" /></a>';


	}
}

function pages($page,$count_pages,$link)
{
if($count_pages > 1 && $page < $count_pages){
echo '<a href="'.$link.($page+1).'">See more..</a>';
}
}

function time_post($from, $to = '') {
 if (empty($to))
 $to = time();
 $diff = (int) abs($to - $from);
 if ($diff <= 60) {
 $since = sprintf('vừa xong');
 } elseif ($diff <= 3600) {
 $mins = round($diff / 60);
 if ($mins <= 1) {
 $mins = 1;
 }
 /* translators: min=minute */
 $since = sprintf('%s phút trước', $mins);
 } else if (($diff <= 86400) && ($diff > 3600)) {
 $hours = round($diff / 3600);
 if ($hours <= 1) {
 $hours = 1;
 }
 $since = sprintf('%s giờ trước', $hours);
 } elseif ($diff >= 86400) {
 $days = round($diff / 86400);
 if ($days <= 1) {
 $days = 1;
 }
 $since = sprintf('%s ngày trước', $days);
 }
 return $since;
 }
 
 function bbcode($str)
{
$str = preg_replace('#[code](.*?)[/code]#si', '<div class="quote" style="color:blue">Copy Mã</div><textarea cols="15" rows="2" class="baiviet" style="color:#777777;text-align:left;">1</textarea><br>', $str);
$str = preg_replace('#[vblue](.*?)[/vblue]#si', '<span style="text-shadow: 1px 3px 9px blue;">1</span>', $str);
$str = preg_replace('#[vgreen](.*?)[/vgreen]#si', '<span style="text-shadow: 1px 3px 9px green;">1</span>', $str);
$str = preg_replace('#[vred](.*?)[/vred]#si', '<span style="text-shadow: 1px 3px 9px red;">1</span>', $str);
$str = preg_replace('#[b](.*?)[/b]#si', '<span style="font-weight: bold;">1</span>', $str);
$str = preg_replace('#[i](.*?)[/i]#si', '<span style="font-style:italic;">1</span>', $str);
$str = preg_replace('#[u](.*?)[/u]#si', '<span style="text-decoration:underline;">1</span>', $str);
$str = preg_replace('#[s](.*?)[/s]#si', '<span style="text-decoration: line-through;">1</span>', $str);
$str = preg_replace('#[img=(.+?)]#is', '<a href="1"><img src="1" alt="Hình" border="0" width="120"/></a><br/>', $str);
$str = preg_replace('#[img](.+?)[/img]#is', '<a href="1"><img src="1" alt="Hình" border="0" width="120"/></a><br/>', $str);
$str = preg_replace('#[img=(.+?)][/img]#is', '<a href="1"><img src="1" alt="Hình" border="0" width="120"/></a><br/>', $str);
$str = preg_replace('#[COLOR=(.+?)](.+?)[/COLOR]#is', '<font style="color:1;">2</font>', $str );
$str = preg_replace('#[c=(.+?)](.*?)[/c]#si', '<div class="quote"><b style="color:blue;">1 Viết:</b><br>2</div>', $str);
$str = preg_replace('#[color=(.+?)](.+?)[/color]#is', '<font style="color:1;">2</font>', $str );
$str = preg_replace('#[br]#is', '<br />', $str );
$str = preg_replace('#[BR]#is', '<br />', $str );
$str = preg_replace('#[SIZE=(.+?)](.+?)[/SIZE]#is', '<font style="font-size:1;">2</font>', $str );
$str = preg_replace('#\[size=(.+?)\](.+?)\[/size\]#is', '<font style="font-size:\1;">\2</font>', $str );
$str = preg_replace('#\[FONT=(.+?)\](.+?)\[/FONT\]#is', '<font face="\1">\2</font>', $str );
$str = preg_replace('#\[font=(.+?)\](.+?)\[/font\]#is', '<font face="\1">\2</font>', $str );
$str = preg_replace("#\[url=(.+?)\](.+?)\[/url\]#is", "".("<a href=\"\\1\">\\2</a>")."", $str );
$str = preg_replace("#\[URL=(.+?)\](.+?)\[/URL\]#is", "".("<a href=\"\\1\">\\2</a>")."", $str );
$str = preg_replace('#\[phai\](.+?)\[/phai\]#is', '<div align="right">\1</div>', $str );
$str = preg_replace('#\[center\](.+?)\[/center\]#is', '<div align="center">\1</div>', $str );
$str = preg_replace('#\[CENTER\](.+?)\[/CENTER\]#is', '<div align="center">\1</div>', $str );
$str = preg_replace('#\[LEFT\](.+?)\[/LEFT\]#is', '<div align="left">\1</div>', $str );
$str = preg_replace('#\[left\](.+?)\[/left\]#is', '<div align="left">\1</div>', $str );
$str = preg_replace('#\[right\](.+?)\[/right\]#is', '<div align="right">\1</div>', $str );
$str = preg_replace('#\[RIGHT\](.+?)\[/RIGHT\]#is', '<div align="right">\1</div>', $str );
$str = preg_replace('#\[trai\](.+?)\[/trai\]#is', '<div align="left">\1</div>', $str );
$str = preg_replace('#\[giua\](.+?)\[/giua\]#is', '<div align="center">\1</div>', $str );
$str = preg_replace('#\[red\](.*?)\[/red\]#si', '<span style="color:red">\1</span>', $str);
$str = preg_replace('#\[green\](.*?)\[/green\]#si', '<span style="color:green">\1</span>', $str);
$str = preg_replace('#\[blue\](.*?)\[/blue\]#si', '<span style="color:blue">\1</span>', $str);
return $str;

}

function smiles($str)
{

$query = mysql_query('SELECT * FROM `smiles`');
while($result = mysql_fetch_assoc($query))
{
$str = str_replace(htmlspecialchars(stripslashes($result['text'])),'<img src="/smiles/'.htmlspecialchars(stripslashes($result['image'])).'" alt=""/>', $str);
}
return $str;
}

function friends($uid,$fid)
{

	if($uid == $fid){ return 3; }
	
	$req = mysql_query("SELECT id FROM friends WHERE  (uid = '$uid' AND fid = '$fid' ) OR (uid = '$fid' AND fid = '$uid')  ");
	if(mysql_num_rows($req) > 0){ return 2; }
	
	$res = mysql_query("SELECT id FROM friend_reqs WHERE (uid = '$uid' AND fid = '$fid' ) OR (uid = '$fid' AND fid = '$uid') ");
	if(mysql_num_rows($res) > 0){ return 1; }
	
	return 0;
}	

function is_friend($uid,$fid)
{

if($uid == $fid){ return ;}

$req = mysql_query("SELECT id FROM friends WHERE (uid = '$uid' AND fid = '$fid' ) OR (uid = '$fid' AND fid = '$uid') ");
	if(mysql_num_rows($req) > 0){
return ; }

	$res = mysql_query("SELECT id FROM friend_reqs WHERE (uid = '$uid' AND fid = '$fid' ) OR (uid = '$fid' AND fid = '$uid') ");
	if(mysql_num_rows($res) > 0){ 
	return '<input type="button" class="login" value="Request pending!">';
	}

	return '<a href="../friends/add.php?fid='. $fid .'"><input type="button" value="Add Friend" class="blue"></a>';
}

function checkfriend($uid,$id)
{
if ($uid == $id) { return 0; }
$req = mysql_query("SELECT id FROM friends WHERE (uid = '$uid' AND fid = '$id' ) OR (uid = '$id' AND fid = '$uid') ");
	if(mysql_num_rows($req) > 0){
return 1; 
}else{
return 2;
}
}
?>