|
<?php
/*
-----------------------------------------
Функции сайта
Файл: function.php
-------------------------------------------
*/
/****** Создаем переменную адреса *****/
$HOME = 'http://'.$_SERVER['HTTP_HOST'];
/******* Запускаем сессии ******/
session_start();
ob_start();
###############################
######## Фильтрация ###########
###############################
function strong($msg){
$msg = trim($msg);
$msg = htmlspecialchars($msg);
$msg = mysql_escape_string($msg);
return $msg;
}
###############################
####### Подключаем БД #########
###############################
require_once ('config.php'); //Подключаем конфиг с параметрами
$mysql_connect = mysql_connect(dbhost, dbuser, dbpass) or die('Сайт не доступен ,возможно Вы не прописали БД!');
mysql_query('SET NAMES `utf8`', $mysql_connect);
mysql_select_db(dbname, $mysql_connect) or die('Нету подключения к БД');
###############################
##### Проверяем сылку гет #####
###############################
foreach ($_GET as $links) {
if (!is_string($links) || !preg_match('#^(?:[a-z0-9_\-/]+|\.+(?!/))*$#i', $links)) {
header ('Location: '.$HOME.'s');
exit;
}
}
unset($links);
###############################
############ Куки #############
###############################
if (isset($_COOKIE['uslog']) and isset($_COOKIE['uspass'])) {
$uslog = strong($_COOKIE['uslog']);
$uspass = strong($_COOKIE['uspass']);
$dbs = mysql_query("SELECT * FROM `users` WHERE `login` = '".$uslog."' and `pass` = '".$uspass."' LIMIT 1");
$user = mysql_fetch_assoc($dbs);
if (isset($user['id'])) {
if ($user['login'] != $uslog or $user['pass'] != $uspass) {
setcookie('uslog', '', time() - 86400*31);
setcookie('uspass', '', time() - 86400*31);
}
}
$users = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `login` = '".$uslog."' and `pass`='".$uspass."' LIMIT 1"));
mysql_query("UPDATE `users` SET `viz`='".time()."', `ip`='".$_SERVER['REMOTE_ADDR']."',`browser`='".$_SERVER['HTTP_USER_AGENT']."',`gde`='".$_SERVER['REQUEST_URI']."' WHERE `id`='".$users['id']."'");
$vremja = time() - $users['viz'];
if($vremja < 120) {
$newtime = $user['online'] + $vremja;
}
if(isset($user['id']) && $users['login']!=$uslog or $users['pass']!=$uspass) {
setcookie('uslog', '', time() - 86400*31);
setcookie('uspass', '', time() - 86400*31);
}
}
###############################
########### BB Коды ###########
###############################
function bb($mes){
$mes = stripslashes($mes);
$mes = preg_replace('#\[br\](.*?)#si', '<br>\1', $mes);
$mes = preg_replace('#\[cit\](.*?)\[/cit\]#si', '<div class="cit">\1</div>', $mes);
$mes = preg_replace('#\[b\](.*?)\[/b\]#si', '<span style="font-weight: bold;"> \1 </span>', $mes);
$mes = preg_replace('/\[url\s?=\s?([\'"]?)(?:http:\/\/)?(.*?)\1\](.*?)\[\/url\]/', ' <a href="http://$2"> $3 </a> ', $mes);
//$mes=preg_replace('!(http://[\S]+)([\s]|$)!i','<a href="\1\2">\1\2</a>',$mes);
$mes = preg_replace('#\[black\](.*?)\[\/black\]#si', '<span style="color:#000000;">\1</span>', $mes);
$mes = preg_replace('#\[red\](.*?)\[\/red\]#si', '<span style="color:#FF0000;">\1</span>', $mes);
$mes = preg_replace('/\[php\](.*?)\[\/php]/sui', '<pre><code class="php">\1</code></pre>', $mes);
$mes = preg_replace('/\[sql\](.*?)\[\/sql]/sui', '<pre><code class="sql">\1</code></pre>', $mes);
$mes = preg_replace('/\[html\](.*?)\[\/html]/sui', '<pre><code class="html">\1</code></pre>', $mes);
$mes = preg_replace('/\[css\](.*?)\[\/css]/sui', '<pre><code class="css">\1</code></pre>', $mes);
$mes = preg_replace('/\[js\](.*?)\[\/js]/sui', '<pre><code class="javascript">\1</code></pre>', $mes);
return $mes;
}
###############################
######### Функция ника ########
###############################
function nick($id){
$users = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '".$id."' LIMIT 1"));
//-----Если пол == 1(мужской)-----//
if($users['level'] == 0)
{
if($users['sex'] == 1)
{
//-----Если онлайн-----//
if($users['viz'] > time()-360)
{
$p = '<img src="'.$HOME.'/images/onl/on_1.gif" alt="*" title="Онлайн" />';
} else {
$p = '<img src="'.$HOME.'/images/onl/off_1.gif" alt="*" title = "Оффлайн"/>';
}
}
}
//-----Если пол == 2(жен)-----//
if($users['level'] == 0)
{
if($users['sex'] == 2)
{
if($users['viz'] > time()-360)
{
$p = '<img src="'.$HOME.'/images/onl/on_0.gif" alt="*" title = "Онлайн"/>';
} else {
$p = '<img src="'.$HOME.'/images/onl/off_0.gif" alt="*" title = "Оффлайн"/>';
}
}
}
#########################
###Модер пацан##############
elseif($users['level'] == 1)
{
if($users['sex'] == 1)
{
if($users['viz'] > time()-360)
{
$p = '<img src="'.$HOME.'/images/onl/mod_on_1.gif" alt="*" title = "Онлайн"/>';
} else {
$p = '<img src="'.$HOME.'/images/onl/mod_off_1.gif" alt="*" title = "Оффлайн"/>';
}
}
}
#####################################################
#########################
###Модер баба##############
if($users['level'] == 1)
{
if($users['sex'] == 2)
{
if($users['viz'] > time()-360)
{
$p = '<img src="'.$HOME.'/images/onl/mod_on_0.gif" alt="*" title = "Онлайн"/>';
} else {
$p = '<img src="'.$HOME.'/images/onl/mod_off_0.gif" alt="*" title = "Оффлайн"/>';
}
}
}
#####################################################
#########################
###Админ пацан##############
elseif($users['level'] >= 2)
{
if($users['sex'] == 1)
{
if($users['viz'] > time()-360)
{
$p = '<img src="'.$HOME.'/images/onl/admin_1.gif" alt="*" title = "Онлайн"/>';
} else {
$p = '<img src="'.$HOME.'/images/onl/off_1.gif" alt="*" title = "Оффлайн"/>';
}
}
}
#####################################################
#########################
###Админ баба##############
if($users['level'] >= 2)
{
if($users['sex'] == 2)
{
if($users['viz'] > time()-360)
{
$p = '<img src="'.$HOME.'/images/onl/admin_0.gif" alt="*" title = "Онлайн"/>';
} else {
$p = '<img src="'.$HOME.'/images/onl/off_0.gif" alt="*" title = "Оффлайн"/>';
}
}
}
#####################################################
return (empty($users)?'[Удален]':''.$p.' <a href="/user_'.$users['id'].'"><b> '.$users['login'].' </b></a>');
}
###############################
########### Листинг ###########
###############################
function page($k_page=1) {
$page = 1;
$page = strong($page);
$k_page = strong($k_page);
if(isset($_GET['selection'])) {
if ($_GET['selection']=='top')
$page = strong(intval($k_page));
elseif(is_numeric($_GET['selection']))
$page = strong(intval($_GET['selection']));
}
if ($page<1)$page=1;
if ($page>$k_page)$page=$k_page;
return $page;
}
// Определяем кол-во страниц
function k_page($k_post = 0,$k_p_str = 10) {
if ($k_post != 0) {
$v_pages = ceil($k_post/$k_p_str);
return $v_pages;
}
else return 1;
}
function str($link='?',$k_page=1,$page=1){
if ($page<1)$page=1;
$page = strong($page);
$k_page = strong($k_page);
echo '<div class="links">';
if ($page>1)echo '<a href="'.$link.'selection='.($page-1).'"><< Назад</a> ';
else echo "<< Назад ";
echo " | ";
if ($page<$k_page)echo ' <a href="'.$link.'selection='.($page+1).'" >Вперед >></a>';
else echo " Вперед >>";
echo '
';
if ($page != 1)
echo '<a href="'.$link.'selection=1" >1</a>';
else echo '<b>1</b>';
for ($ot=-3; $ot<=3; $ot++){
if ($page+$ot>1 && $page+$ot<$k_page){
if ($ot==-3 && $page+$ot>2)echo " ..";
if ($ot!=0)echo '|<a href="'.$link.'selection='.($page+$ot).'" >'.($page+$ot).'</a>';
else echo '|<b>'.($page+$ot).'</b>';
if ($ot==3 && $page+$ot<$k_page-1)echo "|..";}}
if ($page!=$k_page)echo '|<a href="'.$link.'selection=top" >'.$k_page.'</a>';
elseif ($k_page>1)echo '|<b>'.$k_page.'</b>';
echo '</div>';
}
###############################
############ Время ############
###############################
function vremja($time = NULL) {
if(!$time) $time = time();
$data = date('j.n.y', $time);
if($data == date('j.n.y')) $res = 'Сегодня в '. date('G:i', $time);
elseif($data == date('j.n.y', time() - 86400)) $res = 'Вчера в '. date('G:i', $time);
else {
$m = array('0',
'Янв', 'Фев',
'Мар', 'Апр', 'Май',
'Июн', 'Июл', 'Авг',
'Сен', 'Окт', 'Ноя',
'Дек');
$res = date('j '. $m[date('n', $time)] .' Y в G:i', $time);
}
return $res;
}
###############################
############ Смайлы ############
###############################
function smile($msg){
$msg = trim($msg);
$s = mysql_query("SELECT * FROM `smile` ORDER BY `id` DESC");
while($smile = mysql_fetch_array($s))
{
$msg = str_replace($smile['name'],' <img src="'.$HOME.'/files/smile/'.$smile['icon'].'" alt="'.$smile['name'].'"/> ',$msg);
}
return $msg;
}
###############################
############ размер файла ############
###############################
function getSize($files) {
$array = get_headers($files);
foreach ($array AS $key => $value) {
if (preg_match('#Content-Length:#i', $value)) {
$res = $array[$key];
}
}
if (!empty($res)) {
$size = explode(" ", $res);
return $size[1];
} else {
return 'error';
}
}
mysql_query("UPDATE `users` SET `viz` = ".time()." WHERE `id` = '$user[id]' LIMIT 1");
//////////////
$timeactiv=time() - $user['viz'];
if($timeactiv < 120)
{
$newtimeactiv=$user['time']+$timeactiv;
mysql_query("UPDATE `users` SET `time` ='$newtimeactiv', `perehodu` = '".($user['perehodu']+1)."' WHERE `id` = '$user[id]' LIMIT 1");
echo mysql_error();
}
//////////////
require_once ('ban.php');
?>