Файл: trus/system/function.php
Строк: 217
<?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 '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.'');
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);
}
}
$config = mysql_fetch_assoc(mysql_query("SELECT * FROM `config` WHERE `id` = '1'"));
$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;
mysql_query("UPDATE `users` SET `online` ='".$newtime."' WHERE `id`='".$users['id']."'");
}
if(isset($user['id']) && $users['login']!=$uslog or $users['pass']!=$uspass) {
setcookie('uslog', '', time() - 86400*31);
setcookie('uspass', '', time() - 86400*31);
}
}
###############################
########### Листинг ###########
###############################
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="listt">';
if ($page != 1)
echo '<span class="pagination_button"><a href="'.$link.'selection=1" >1</a></span> '; /// не нажат
else echo '<span class="pagination_select">1</span> '; /// нажат
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 '<span class="pagination_button"><a href="'.$link.'selection='.($page+$ot).'" >'.($page+$ot).'</a></span> ';
else echo '<span class="pagination_select"> '.($page+$ot).'</span> ';
if ($ot==3 && $page+$ot<$k_page-1)echo "|..";}}
if ($page!=$k_page)echo '<span class="pagination_button"><a href="'.$link.'selection=top" >'.$k_page.'</a></span> ';
elseif ($k_page>1)echo '<span class="pagination_select">'.$k_page.'</span> ';
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;
}
###############################
############ Время2#####
###############################
function vremja2($time = NULL) {
if(!$time) $time = time();
$data = date('j.n.y', $time);
$m = array('0',
'1', '2',
'3', '4', '5',
'6', '7', '8',
'9', '10', '11',
'12');
$res = date('j.'. $m[date('n', $time)] .'.Y', $time);
return $res;
}
###############################
############ Размер ####
###############################
function size($filesize) {
if ($filesize < 1000000) {
$kb = round($filesize / 1000, 1);
$result = $kb.' Kb';
} else {
$mb = round($filesize / 1000000, 1);
$result = $mb.' Mb';
}
return $result;
}
#########################################################################
function user($user = NULL) {
// Определение браузера
$ank = mysql_fetch_array(mysql_query("SELECT * FROM `load_ka4` WHERE `id` = '$user' LIMIT 1"));
$ua = strtolower($ank['browser']);
$path_pc = ' <img src="/design/PC.png" /> ';
$path_mob = ' <img src="/design/phone.png" /> ';
if (preg_match('#(orca)#ui', $ua)) $browser = $path_pc .'<img src="/design/browsers/orca.png" alt="" />';
elseif (preg_match('#(lunascape)#ui', $ua)) $browser = $path_pc .'<img src="/design/browsers/lunascape.png" alt="" />';
elseif (preg_match('#(arora)#ui', $ua)) $browser = $path_pc .'<img src="/design/browsers/arora.png" />';
elseif (preg_match('#(coolnovo)#ui', $ua)) $browser = $path_pc .'<img src="/design/browsers/coolnovo.png" alt="" />';
elseif (preg_match('#(kylo)#ui', $ua)) $browser = $path_pc .'<img src="/design/browsers/kylo.png" alt="" />';
elseif (preg_match('#(flock)#ui', $ua)) $browser = $path_pc .'<img src="/design/browsers/flock.png" alt="" />';
elseif (preg_match('#(rockmelt)#ui', $ua)) $browser = $path_pc .'<img src="/design/browsers/rockmelt.png" alt="" />';
elseif (preg_match('#(cometbird)#ui', $ua)) $browser = $path_pc .'<img src="/design/browsers/cometbird.png" alt="" />';
elseif (preg_match('#(seamonkey)#ui', $ua)) $browser = $path_pc .'<img src="/design/browsers/seamonkey.png" alt="" />';
elseif (preg_match('#(iron)#ui', $ua)) $browser = $path_pc .'<img src="/design/browsers/iron.png" alt="" />';
elseif (preg_match('#(presto)#ui', $ua)) $browser = $path_pc .'<img src="/design/browsers/opera.png" alt="" />';
elseif (preg_match('#(yabrowser)#ui', $ua)) $browser = $path_pc .'<img src="/design/browsers/yabrowser.png" alt="" />';
elseif (preg_match('#(chrome)#ui', $ua)) $browser = $path_pc .'<img src="/design/browsers/chrome.png" alt="" />';
elseif (preg_match('#(msie)#ui', $ua)) $browser = $path_pc .'<img src="/design/browsers/msie.png" alt="" />';
elseif (preg_match('#(maxthon)#ui', $ua)) $browser = $path_pc .'<img src="/design/browsers/maxthon.png" alt="" />';
elseif (preg_match('#(safari)#ui', $ua)) $browser = $path_pc .'<img src="/design/browsers/safari.png" alt="" />';
elseif (preg_match('#(qtweb)#ui', $ua)) $browser = $path_pc .'<img src="/design/browsers/qtweb.png" alt="" />';
elseif (preg_match('#(firefox)#ui', $ua)) $browser = $path_pc .'<img src="/design/browsers/firefox.png" alt="" />';
// Мобильные браузеры
if (preg_match('#(sonyericsson)#ui', $ua)) $browser = $path_mob .'<img src="/design/browsers/sony_ericsson.png" alt="" />';
elseif (preg_match('#(ipod)#ui', $ua)) $browser = $path_mob .'<img src="/design/browsers/apple.png" alt="" />';
elseif (preg_match('#(iphone)#ui', $ua)) $browser = $path_mob .'<img src="/design/browsers/apple.png" alt="" />';
elseif (preg_match('#(android)#ui', $ua)) $browser = $path_mob .'<img src="/design/browsers/android.png" alt="" />';
elseif (preg_match('#(symbian)#ui', $ua)) $browser = $path_mob .'<img src="/design/browsers/symbian.png" alt="" />';
elseif (preg_match('#(windowsphone)#ui', $ua)) $browser = $path_mob .'<img src="/design/browsers/windows.png" alt="" />';
elseif (preg_match('#(wp7)#ui', $ua)) $browser = $path_mob .'<img src="/design/browsers/windows.png" alt="" />';
elseif (preg_match('#(wp8)#ui', $ua)) $browser = $path_mob .'<img src="/design/browsers/windows.png" alt="" />';
elseif (preg_match('#(webos)#ui', $ua)) $browser = $path_mob .'<img src="/design/browsers/hp.png" alt="" />';
elseif (preg_match('#(blackberry)#ui', $ua)) $browser = $path_mob .'<img src="/design/browsers/blackberry.png" alt="" />';
elseif (preg_match('#(htc)#ui', $ua)) $browser = $path_mob .'<img src="/design/browsers/htc.png" alt="" />';
elseif (preg_match('#(opera m)#ui', $ua)) $browser = $path_mob .'<img src="/design/browsers/opera.png" alt="" />';
echo $browser;
$arr = array('nokia',
'samsung',
'siemens',
'fly',
'motorola',
'sharp',
'sony',
'lg',
'acer',
'alcatel',
'asus',
'gigabyte',
'highscreen',
'huawei',
'philips',
'zte',
'mts',
'midp-2.0',
'ucweb');
foreach ($arr as $value) {
if (strpos($ua, $value) !== false) {
$browser = $path_mob;
echo $browser;
}
}
}
#########################################################################
function nick($id){
global $HOME;
$useri = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '".$id."' LIMIT 1"));
return (empty($useri)?'[Гость]':''.$p.' <a href="/user_'.$useri['id'].'"><b>'.$useri['login'].'</b></a> '.$us.'');
}
?>