Просмотр файла functions.php

Размер файла: 7.34Kb
<?php
include_once("connect.php");
include_once("config.php");
function ban($username, $ua, $ip)
 {
 global $modername, $banmess;
	$query = mysql_query("SELECT * FROM `ban`
	                      WHERE `user`='".$ua."'
	                      OR `ip`='".$ip."'
	                      OR `username`='".$username."'
	                      AND `time` > UNIX_TIMESTAMP()");
	if(mysql_num_rows($query))
	{
		$rows = mysql_fetch_array($query);
		$modername = $rows['moder'];
		$banmess = $rows['mess'];
		return( true );
	}
	else
	{
		return ( false );
	}
 }

function translate($mess)
{
$array = array(
"Jo" => "Ё",
"jo" => "ё",
"Yo" => "Ё",
"yo" => "ё",
"Zh" => "Ж",
"zh" => "ж",
"*" => "ж",
"Ch" => "Ч",
"ch" => "ч",
"Sh" => "Ш",
"sh" => "ш",
"Shc" => "Щ",
"shc" => "щ",
"''" => 'ъ',
"'" => "ь",
"Ye" => "Э",
"ye" => "э",
"Yu" => "Ю",
"yu" => "ю",
"Ya" => "Я",
"ya" => "я",
"X" => "Ы",
"x" => "ы",
"A" => "А",
"a" => "а",
"B" => "Б",
"b" => "б",
"C" => "Ц",
"c" => "ц",
"D" => "Д",
"d" => "д",
"E" => "Е",
"e" => "е",
"F" => "Ф",
"f" => "ф",
"G" => "Г",
"g" => "г",
"H" => "Х",
"h" => "х",
"I" => "И",
"i" => "и",
"K" => "К",
"k" => "к",
"L" => "Л",
"l" => "л",
"M" => "М",
"m" => "м",
"N" => "Н",
"n" => "н",
"O" => "О",
"o" => "о",
"P" => "П",
"p" => "п",
"Q" => "Ь",
"q" => "ь",
"R" => "Р",
"r" => "р",
"S" => "С",
"s" => "с",
"T" => "Т",
"t" => "т",
"U" => "У",
"u" => "у",
"V" => "В",
"v" => "в",
"W" => "Ш",
"w" => "ш",
"Y" => "Й",
"y" => "й",
"Z" => "З",
"z" => "з"
);
return (strtr($mess, $array));
}

	function smile($matches)
	{
	static $c;
	$arr = array('&lt;1&gt;',
                   '&lt;2&gt;',
                   '&lt;3&gt;',
                   '&lt;4&gt;',
                   '&lt;5&gt;',
                   '&lt;6&gt;',
                   '&lt;7&gt;',
                   '&lt;8&gt;',
                   '&lt;9&gt;',
                   '&lt;10&gt;',
                   '&lt;11&gt;',
                   '&lt;12&gt;',
                   '&lt;13&gt;',
                   '&lt;14&gt;',
                   '&lt;15&gt;',
                   '&lt;16&gt;',
                   '&lt;17&gt;',
                   '&lt;18&gt;',
                   '&lt;19&gt;',
                   '&lt;20&gt;',
				   '&lt;21&gt;',
                   '&lt;22&gt;',
                   '&lt;23&gt;',
                   '&lt;24&gt;',
                   '&lt;25&gt;',
                   '&lt;26&gt;',
                   '&lt;27&gt;',
                   '&lt;28&gt;',
                   '&lt;29&gt;',
                   '&lt;30&gt;',
                   '&lt;31&gt;',
                   '&lt;32&gt;',
                   '&lt;33&gt;',
                   '&lt;34&gt;',
                   '&lt;35&gt;',
                   '&lt;36&gt;',
                   '&lt;37&gt;',
                   '&lt;38&gt;'
    									);
		if($c == 1) return $matches[0];
		if(!in_array($matches[0], $arr)) return $matches[0];

		$c++;

    	$smiles = array(
 		'<img src="smiles/1.gif"  alt=":-)" />', 
'<img src="smiles/2.gif" alt=":-(" />', 
'<img src="smiles/3.gif" alt=":-[" />', 
'<img src="smiles/4.gif" alt="8-)" />', 
'<img src="smiles/5.gif" alt=":-E)" />', 
'<img src="smiles/6.gif" alt=":-P" />', 
'<img src="smiles/7.gif" alt="{beer}" />', 
'<img src="smiles/8.gif" alt="{tee}" />', 
'<img src="smiles/9.gif" alt="{smoke}" />', 
'<img src="smiles/10.gif" alt="{vine}" />', 
'<img src="smiles/11.gif" alt="{kiss}" />', 
'<img src="smiles/12.gif" alt="{heard}" />', 
'<img src="smiles/13.gif" alt="" />', 
'<img src="smiles/14.gif" alt="{ok}" />', 
'<img src="smiles/15.gif" alt="{no}" />', 
'<img src="smiles/16.gif" alt="{cool}" />', 
'<img src="smiles/17.gif" alt="{flower}" />',
'<img src="smiles/18.gif" alt="{cherry}" />', 
'<img src="smiles/19.gif" alt="{ball}" />',
'<img src="smiles/20.gif" alt="{surprise}" />',
'<img src="smiles/21.gif" alt="{cake}" />',
'<img src="smiles/22.gif" alt="{phone}" />',
'<img src="smiles/23.gif" alt="{mobile}" />',
'<img src="smiles/24.gif" alt="{wall}" />',
'<img src="smiles/25.gif" alt="{camel}" />',
'<img src="smiles/26.gif" alt="{cat}" />',
'<img src="smiles/27.gif" alt="{pig}" />',
'<img src="smiles/28.gif" alt="{hammer}" />',
'<img src="smiles/29.gif" alt="{gun}" />',
'<img src="smiles/30.gif" alt="{skull}" />',
'<img src="smiles/31.gif" alt="{rip}" />',
'<img src="smiles/32.gif" alt="{sun}" />',
'<img src="smiles/33.gif" alt="{moon}" />',
'<img src="smiles/34.gif" alt="{lock}" />',
'<img src="smiles/35.gif" alt="{dollar}" />',
'<img src="smiles/36.gif" alt="{fig}" />',
'<img src="smiles/37.gif" alt="{drug}" />',
'<img src="smiles/38.gif" alt="{fuck}" />'
		);

		return str_replace($arr, $smiles, $matches[0]);
	}

	function username2id($username)
	{
		$id = mysql_fetch_array(mysql_query("SELECT id FROM users WHERE username='".$username."'"));
		return( $id['id'] );
	}

	function ClearOnline()
	{
		mysql_query("DELETE FROM session WHERE time < ".(time() - (24 * 60 * 60)));
	}

	function RefreshLastTime($username, $fid, $lastMsgTime)
	{
		mysql_query("UPDATE `counter` SET `time`=".($lastMsgTime)." WHERE `fid`=".$fid." AND `username`='".$username."'");
	}


	function RefreshSid($username)
	{
		mysql_query("UPDATE `session` SET `time`=".time()." WHERE `nickname`='".$username."'");
		mysql_query("UPDATE `users` SET `last_time`=".time()." WHERE `username`='".$username."'");
	}

     function topic2post($id_topic)
     {
		return(mysql_result(mysql_query("SELECT MIN(`id`) FROM `posts` WHERE `id_theme`=".$id_topic), 0));
     }
function topic2postm($id_topic)
     {
		return(mysql_result(mysql_query("SELECT MIN(`id`) FROM `mposts` WHERE `id_theme`=".$id_topic), 0));
     }
	function is_author($id, $user)
	{
		if(mysql_result(mysql_query("SELECT COUNT(*) FROM `themes` WHERE `id`=".$id." AND `name`='".$user."'"), 0))
		{
			return(true);
		}
		else
		{
			return(false);
		}
	}

	function sql($str)
	{
		if(get_magic_quotes_gpc())
		{
			$str = stripslashes($str);
		}
		return(str_replace('$', '&#36;', mysql_escape_string($str)));
	}
	function cutString($string, $len)
{
    if (strlen($string) <= $len)
    {
        return $string;
    }
    return substr($string, 0, $len) . "....";
}
function translatenick($username)
{
$array = array(
"Е" => "E",
"е" => "e",
"А" => "A",
"а" => "a",
"В" => "B",
"С" => "C",
"с" => "c",
"Н" => "H",
"Х" => "X",
"К" => "K",
"М" => "M",
"О" => "O",
"о" => "o",
"Р" => "P",
"р" => "p",
"Т" => "T",
"у" => "y"
);
return (strtr($username, $array));
}
$ua=$_SERVER['HTTP_USER_AGENT'];
$ip=$_SERVER['REMOTE_ADDR'];
$uniq=serialize(array($ip,$ua))."\n";
$store='./count/count.dat'; 
$offset=3600;
$date_now=date('d',time()+$offset);
$date_access=date('d',filemtime($store)+$offset);
if ($date_now!=$date_access && file_exists($store)) 
{
    unlink($store); 
} 
if (!file_exists($store)) 
{
    $hit=1; 
    $host=1; 
} 
else 
{
    $data=file($store); 
    $data[]=$uniq;
    $hit=count($data);
    $ip_ua=array(); 
    $ip_ua[]=$uniq;
    foreach ($data as $v) 
    { 
        if (!in_array($v,$ip_ua))
        $ip_ua[]=$v;
    } 

    $host=count($ip_ua);
} 
$f=fopen($store,'a+');
flock($f,2);
fwrite($f,$uniq);
fclose($f);
$_GET['p']=intval($_GET['p']);
?>