Просмотр файла sys/fnc.php

Размер файла: 5.16Kb
<?php
Error_Reporting(E_ALL & ~E_NOTICE);
Error_Reporting (ERROR | WARNING);
session_start();
$DB_HOST='localhost';//адрес хоста базы
$DB_USER='root';//имя пользователя базы
$DB_PASS='pass';//пароль пользователя базы
$DB_BASE='vkcms';//база
$str=10;//сколько сообщений выводить на страницу





$db = new mysqli($DB_HOST,$DB_USER,$DB_PASS,$DB_BASE);
$db->query('set charset utf8'); 
$db->query('SET names utf8'); 
$db->query('set character_set_client="utf8"'); 
$db->query('set character_set_connection="utf8"'); 
$db->query('set character_set_result="utf8"');


$time=time();



function vremja($time)
{



$timep="".date("j M  в H:i", $time)."";
$time_p[0]=date("j n ", $time);
$time_p[1]=date("H:i", $time);


if ($time_p[0]==date("j n Y"))$timep=date("H:i:s", $time);

if ($time_p[0]==date("j n Y", time()-60*60*24))$timep="Вчера в $time_p[1]";




$timep=str_replace("Jan","Янв",$timep);
$timep=str_replace("Feb","Фев",$timep);
$timep=str_replace("Mar","Марта",$timep);
$timep=str_replace("May","Мая",$timep);
$timep=str_replace("Apr","Апр",$timep);
$timep=str_replace("Jun","Июня",$timep);
$timep=str_replace("Jul","Июля",$timep);
$timep=str_replace("Aug","Авг",$timep);
$timep=str_replace("Sep","Сент",$timep);
$timep=str_replace("Oct","Окт",$timep);
$timep=str_replace("Nov","Ноября",$timep);
$timep=str_replace("Dec","Дек",$timep);
return $timep;
}



function mess_str($pref,$page,$dop)
{
	global $db,$str;
	$mess = $db->query("select * from `".$pref."` $dop");
	$mess_col=$mess->num_rows;
	$str_col=ceil($mess_col/$str);
	for($i=1; $i<$str_col+1; $i++)
	{
		if(($page/$str+1)==$i)
		{
			echo $i;
		}
		else
		{
			echo'<a href="javascript:'.$pref.'_mess_str('.($i-1)*$str.')">'.$i.'</a>';
		}
	}
	$mess->close();
}


// ------------------ Функция вставки BB-кода --------------------//
function bbcod($msg) {
	$msg=str_replace("\n",'<br>',$msg);
	$msg = preg_replace('#\[img\](.*?)\[/img\]#si', '<img src="\1" width="240">', $msg);
	$msg = preg_replace_callback('#\[code\](.*?)\[/code\]#i', 'highlight_code', $msg);
	$msg = preg_replace_callback('#\[hide\](.*?)\[/hide\]#i', 'hidden_text', $msg);

	$msg = preg_replace_callback('#\[spoiler=(.*?)\](.*?)\[/spoiler\]#si', 'spoiler_text',$msg);
	$msg = preg_replace_callback('#\[spoiler\](.*?)\[/spoiler\]#si', 'spoiler_text',$msg);

	$msg = preg_replace('#\[url=(.*)\](.*)\[\/url\]#mUsi','<a href=\1>\2</a>', $msg);
	$msg = str_replace('http://youtu.be/','//www.youtube.com/embed/', $msg);
	$msg = preg_replace('#\[youtube\](.*?)\[/youtube\]#si', '<iframe width="280" height="210" src="\1" frameborder="0"></iframe>', $msg);
	$msg = preg_replace('#\[big\](.*?)\[/big\]#si', '<big>\1</big>', $msg);
	$msg = preg_replace('#\[b\](.*?)\[/b\]#si', '<b>\1</b>', $msg);
	$msg = preg_replace('#\[i\](.*?)\[/i\]#si', '<i>\1</i>', $msg);
	$msg = preg_replace('#\[u\](.*?)\[/u\]#si', '<u>\1</u>', $msg);
	$msg = preg_replace('#\[small\](.*?)\[/small\]#si', '<small>\1</small>', $msg);
	$msg = preg_replace('#\[red\](.*?)\[/red\]#si', '<span style="color:#ff0000">\1</span>', $msg);
	$msg = preg_replace('#\[green\](.*?)\[/green\]#si', '<span style="color:#00cc00">\1</span>', $msg);
	$msg = preg_replace('#\[blue\](.*?)\[/blue\]#si', '<span style="color:#0000ff">\1</span>', $msg);
	$msg = preg_replace('#\[q\](.*?)\[/q\]#si', '<div class="q">\1</div>', $msg);
	$msg = preg_replace('#\[del\](.*?)\[/del\]#si', '<del>\1</del>', $msg);
	return $msg;
}


function filtr($msg)
{
	global $db;
	
	$msg=trim($msg);
	$msg = $db->real_escape_string($msg);
	$msg=htmlspecialchars($msg);
	return $msg;
}
/*
function bbcod($msg)
{
	$msg=str_replace('[br]','<br>',$msg);
	$msg=str_replace("\n",'<br>',$msg);
	$msg=str_replace('[cit]','<i>',$msg);
	$msg=str_replace('[/cit]','</i><p>',$msg);
	return $msg;
}
*/

function ajax()
{
?>




	<script type="text/javascript">


	//подключение
	function getXmlHttp()
	{
		var xmlhttp;
		
		try 
		{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		
		catch (e) 
		{
			try 
			{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			
			catch (E) 
			{
				xmlhttp = false;
			}
			
		}

		if (!xmlhttp && typeof XMLHttpRequest!='undefined') 
		{
			xmlhttp = new XMLHttpRequest();
		}
		
		return xmlhttp;
	}


	</script>
	
	<?
	$dir=opendir("ajax/");
	while($file=readdir($dir))
	{
		if(($file!=".") and ($file!=".."))
		{
			echo'<script type="text/javascript" src="ajax/'.$file.'"></script>';
		}
	}
	closedir($dir);
	
	
}








$log=$_SESSION['login'];
$pass=$_SESSION['password'];

if(!empty($log) and !empty($pass))
{
	
		$u=$db->query("select * from `user` where `user`='$log' and `pass`='$pass'");
		if($u->num_rows==0)
		{
			unset($_SESSION['login']);
			unset($_SESSION['password']);
			unset($log);
			unset($pass);
			$u->close();
		}
		else
		{
			$user = $u->fetch_array();
		}
}
else
{
	unset($_SESSION['login']);
	unset($_SESSION['password']);
	unset($log);
	unset($pass);
}
?>