Файл: WM_dvig/system/function.php
Строк: 97
<?php
//Сессии
$t = microtime(1);
session_start();
ob_start();
//Фильтрация
function guard($msg){
$text = htmlspecialchars($msg);
$text = trim($msg);
$text = mysql_escape_string($msg);
return $msg;
}
//Смайлы
function smiles($msg) {
$msg = trim($msg);
$a = mysql_query("SELECT * FROM `smiles`");
while($b = mysql_fetch_array($a))
{
$msg = str_replace($b['name'],' <img src="/files/smiles/'.$b['icon'].'" alt="'.$b['name'].'" style="max-width: 24px; max-height: 24px;"/> ',$msg);
}
return $msg;
}
//Функция вывода текста
function text($text){
$text = smiles(nl2br($text));
return $text;
}
//БД
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('На сайте проходят Тех. работы.');
//GET
foreach($_GET as $links) {
if(!is_string($links) || !preg_match('#^(?:[a-z0-9_-/]+|.+(?!/))*$#i', $links)) {
header ('Location: /');
exit();
}
}
unset($links);
//$user
if (isset($_COOKIE['uslog']) and isset($_COOKIE['uspass'])) {
$uslog = guard($_COOKIE['uslog']);
$uspass = guard($_COOKIE['uspass']);
$user = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `login` = '".$uslog."' and `pass` = '".$uspass."' LIMIT 1"));
if(isset($user['id'])) {
if($user['login'] != $uslog or $user['pass'] != $uspass) {
setcookie('uslog', '', time() - 86400*31);
setcookie('uspass', '', time() - 86400*31);
}
}
mysql_query("UPDATE `users` SET `vizit` = '".time()."', `ip` = '".$_SERVER['REMOTE_ADDR']."', `browser` = '".$_SERVER['HTTP_USER_AGENT']."', `gde` = '".$_SERVER['REQUEST_URI']."' WHERE `id`='".$user['id']."'");
}
//Функция ника
function nick($id){
$us = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '".$id."' LIMIT 1"));
if($us['sex'] == 1) {
if($us['vizit'] > time()-720) {
$icon = '<img src="/img/ank/m.png" alt="*"/>';
} else {
$icon = '<img src="/img/ank/mf.png" alt="*"/>';
}
}
else
if($us['sex'] == 2) {
if($us['vizit'] > time()-720) {
$icon = '<img src="/img/ank/j.png" alt="*"/>';
} else {
$icon = '<img src="/img/ank/jf.png" alt="*"/>';
}
}
return (empty($us)?'[Delete]':$icon.' <a href="/id'.$us['id'].'"><b>'.$us['login'].'</b></a>');
}
//Время
function slv($str,$msg1,$msg2,$msg3) {
$str = (int)$str;
$str1 = abs($str) % 100;
$str2 = $str % 10;
if ($str1 > 10 && $str1 < 20) return $str .' '. $msg3;
if ($str2 > 1 && $str2 < 5) return $str .' '. $msg2;
if ($str2 == 1) return $str .' '. $msg1;
return $str .' '. $msg3;
}
function times($times=NULL){
global $db;
$time = time();
if(($time-$times)<=60){
$timesp = slv((($time-$times)),'секунду','секунды','секунд').' назад';
return $timesp;
}else if(($time-$times)<=3600){$timesp = slv((($time-$times)/60),'минуту','минуты','минут').' назад';
return $timesp;
}else{
$today = date("j M Y", $time);
$today = date("j M Y", $time);
$yesterday = date("j M Y", strtotime("-1 day"));
$timesp=date("j M Y в H:i", $times);
$timesp = str_replace($today, 'Сегодня', $timesp);
$timesp = str_replace($yesterday, 'Вчера', $timesp);
$timesp = strtr($timesp, array ("Jan" => "Янв","Feb" => "Фев","Mar" => "Марта","May" => "Мая","Apr" => "Апр","Jun" => "Июня","Jul" => "Июля","Aug" => "Авг","Sep" => "Сент","Oct" => "Окт","Nov" => "Ноября","Dec" => "Дек",));
return $timesp;}
}
//Листинг
function page($k_page=1) {
$page = 1;
$page = guard($page);
$k_page = guard($k_page);
if(isset($_GET['selection'])) {
if ($_GET['selection']=='top')
$page = guard(intval($k_page));
elseif(is_numeric($_GET['selection']))
$page = guard(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 = guard($page);
$k_page = guard($k_page);
echo '<div class="hit" style="border-top:1px dashed #e6b464">';
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 '<br />';
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>';
}
?>