Файл: system/class/user.php
Строк: 354
<?
////////////////////////////////////////////////////////////////
////////////////Файл,отвечающий за функции и операции///////////
///////////////////по работе с пользователями///////////////////
//Функция вывода Имя Фамилия или если не указаны-просто ник
final class fuser {
//Функция проверки авторизации
public function aut($return=false) {
global $db;
if(ROOT!=null)define('ROOT',ROOT); else define(ROOT,'/');
if ((isset($_SESSION['uid']) && isset($_SESSION['pass']))or(isset($_COOKIE['uid']) && isset($_COOKIE['pass']))) {
$uid = abs(intval($_SESSION['uid']));
$pass = shit($_SESSION['pass']);
$sql = $db -> query("SELECT `id` FROM `users` WHERE `id` = '".$uid."' AND `pass` = '".$pass."' LIMIT 1");
if ($sql -> num_rows == 0) {
$aut=false;
setcookie('uid');
setcookie('pass');
unset($_SESSION['uid']);
unset($_SESSION['pass']);
if($return==false)header('Location: '.ROOT.'aut.php'); else return false;
exit();
}else return true; exit;
}else{
if($return==false)header('Location: '.ROOT.'aut.php'); else return false;
exit();
}
}
///проверяем нахождение пользователя и записываем нужное
public function where($where){
global $db;
$where=shit($where);
//главная стандартно
$wh='<a href="/">На главной</a>';
if(preg_match("#/users.php#si",$where))$wh='<a href="/users.php">Пользователи</a>';
if(preg_match("#/online.php#si",$where))$wh='<a href="/online.php">Кто онлайн</a>';
//анкеты
if(preg_match("#/id([0-9])#",$where)){
$id=intval(abs(preg_replace("#/id([0-9])#",'1', $where)));
$arr = $db -> query("SELECT * FROM `users` WHERE `id` = '".$id."'")->fetch_array();
if($arr['id']!=null)$wh='<a href="/id'.$arr['id'].'"/>'.language('Анкета').' '.$arr['login'].'</a>';
}
//выводим в power.php на добавление
return $wh;
}
///определение возраста
public function vozrast($d,$m,$y) {
if($m > date('m') || $m == date('m') && $d > date('d'))
return (date('Y') - $y - 1);
else
return (date('Y') - $y);
}
///Определяем ОС устройства
public function browser($my_browser) {
$oses = array (
'iPhone' => '(iPhone)','Android' => '(android)','iPad' => '(iPad)',
'Blackberry OS' => '(rim)','Windows 3.11' => 'Win16','Windows 95' => '(Windows 95)|(Win95)|(Windows_95)',
'Windows 98' => '(Windows 98)|(Win98)','Windows 2000' => '(Windows NT 5.0)|(Windows 2000)',
'Windows XP' => '(Windows NT 5.1)|(Windows XP)','Windows 2003' => '(Windows NT 5.2)',
'Windows Vista' => '(Windows NT 6.0)|(Windows Vista)','Windows 7' => '(Windows NT 6.1)|(Windows 7)',
'Windows 8' => '(Windows NT 6.2)|(Windows 8)','Windows NT 4.0' => '(Windows NT 4.0)|(WinNT4.0)|(WinNT)|(Windows NT)',
'Windows ME' => 'Windows ME','Open BSD'=>'OpenBSD','Sun OS'=>'SunOS','Linux'=>'(Linux)|(X11)',
'Safari' => '(Safari)','Macintosh'=>'(Mac_PowerPC)|(Macintosh)','QNX'=>'QNX','BeOS'=>'BeOS','OS/2'=>'OS/2',
'Google' => '(Googlebot)','Yahoo! | AOL' => '(Slurp) | (Yahoo! Slurp) | (Yammybot)','MSN | Live' => '(MSNBot)',
'Ask' => '(Teoma)','AltaVista' => '(Scooter)','Alexa' => '(ia_archiver)','Lycos' => '(Lycos)',
'Яндекс' => '(Yandex)','Рамблер' => '(StackRambler)','Мэйл.ру' => '(Mail.Ru)','Aport' => '(Aport)',
'Search Bot'=>'(nuhk)|(Openbot)|(Slurp/cat)');
foreach($oses as $os=>$pattern){if(preg_match('#'.$pattern.'#si', $my_browser)) {return $os;}}
return 'Other';
}
///Маскировка email адреса
public function email_mask($email,$maska='*',$count=3){
$maska=str_repeat($maska, $count);
return preg_replace('/^(.)[^@]*/', '$1'.$maska.'', $email);
}
///Класс ленты
public function lenta($uid,$mess,$type,$where,$status=1,$url=null,$stena_id=0) {
global $db;
$sql = $db -> query("SELECT * FROM `users` WHERE `id` = '".$uid."' LIMIT 1");
if ($sql-> num_rows > 0) {
//
if($where=='friends'){
$sql = $db -> query("SELECT * FROM `nuts` where `time`<>'0' and `user`='".$uid."' and `where`='frends'");
while ($u = $sql -> fetch_assoc()) {
$db -> query("INSERT INTO `lenta` (`uid`,`text`,`type`,`where`,`time`,`url`,`from`) VALUES ('".$uid."','".$mess."','".$type."','".$u['idwh']."','".time()."','".$url."','".$stena_id."')");
}
}
if($where=='user'){
$db -> query("INSERT INTO `lenta` (`uid`,`text`,`type`,`where`,`time`,`status`,`from`,`url`) VALUES ('".$uid."','".$mess."','".$type."','".$uid."','".time()."','".$status."','".$stena_id."','".$url."')");
}
//
}
}
///функция склонения в зависимости от пола
public function ifsex($id,$text_m,$text_w){
global $db;
$us = $db -> query("SELECT `sex` FROM `users` where `id`='".$id."'")-> fetch_assoc();
if($us['sex']=='m') return language($text_m); else return language($text_w);
}
///вывод места проживания
public function region($city,$type=1,$view_none=0){
global $db;
$city=intval(abs($city));
$sql = $db -> query("SELECT * FROM `country_city` WHERE `id` = '".$city."' LIMIT 1");
if ($sql-> num_rows > 0) {
$city=$sql->fetch_assoc();
$region = $db -> query("SELECT * FROM `country_region` WHERE `id` = '".$city['region']."' LIMIT 1")->fetch_assoc();
$country = $db -> query("SELECT * FROM `country` WHERE `id` = '".$city['country']."' LIMIT 1")->fetch_assoc();
if($type==1)$view=$city['name']; // вывод: Город
if($type==2)$view=$city['name'].' ('.$region['name'].')'; // вывод: Город (Регион)
if($type==3)$view=$city['name'].' ('.$country['name'].')'; // вывод: Город (Страна)
if($type==4)$view=$region['name']; // вывод: Регион
if($type==5)$view=$country['name']; // вывод: Страна
}else if($view_none==1) $view='Не указан'; else $view=null;
return $view;
}
///поиск города по имени
public function cityname($name){
global $db;
$name=mysql_real_escape_string(htmlspecialchars(trim($name)));
$back=null;
$sql = $db -> query("SELECT * FROM `country_city` WHERE `name` = '".$name."' LIMIT 1");
if ($sql-> num_rows > 0) {
$city=$sql->fetch_assoc();
$back=$city['id'];
}
return $back;
}
///Класс системных уведомлений
public function sysmail($mess,$id) {
global $db;
$nas = $db -> query("SELECT `name`,`parametr` FROM `settings` where `name`='sys_mail'");
while ($assoc = $nas -> fetch_assoc()) {
$nastr[$assoc['name']]=$assoc['parametr'];
}
$nas->free();
if($nastr['sys_mail']!='0'){
$id = abs(intval($id));
$dialog = abs(intval($dialog));
$mess = shit($mess);
$user = $db -> dbcount('COUNT(`id`)','users',"`id`='".$id."'");
if($user>0){
$sq1 = $db -> query("SELECT `id` FROM `dialogs` WHERE `user`='".$id."' and `oid`='2' LIMIT 1");
$sq2= $db -> query("SELECT `id` FROM `dialogs` WHERE `oid`='".$id."' and `user`='2' LIMIT 1");
if (($sq1-> num_rows == 0)and($sq2-> num_rows == 0)) {
$db -> query("INSERT INTO `dialogs` (`user`,`oid`,`time`) VALUES ('".$id."','2','".time()."')");
$dialog = $db -> insert_id;
$db -> query("INSERT INTO `mail` (`fid`,`oid`,`dialog`,`text`,`time`) VALUES ('".$id."','2','".$dialog."','".$mess."','".time()."')");
}else{
if ($sq1-> num_rows > 0) {
$d=$sq1->fetch_assoc();
}elseif($sq2-> num_rows > 0){
$d=$sq2->fetch_assoc();
}
$dialog=$d['id'];
$db -> query("INSERT INTO `mail` (`fid`,`oid`,`dialog`,`text`,`time`) VALUES ('".$id."','2','".$dialog."','".$mess."','".time()."')");
$db -> query("Update `dialogs` set `time`='".time()."' where `id`='".$dialog."'");
}
}
}
}
///Обработчик ссылок на сайте(лента)
public function lenta_tag($text){
$text = preg_replace('/[gomy=(?:http://)?(.*?)](.*?)[/gomy]/',' <a href="'.ROOT.'1">2</a> ', $text);
$text = preg_replace('#[img](.*?)[/img]#si', '<img src="1" style="padding:5px;">', $text);
return $text;
}
///проверка: является ли пользователь другом
public function friends($id,$ya){
global $db;
$sql = $db -> query("SELECT * FROM `nuts` WHERE `where`='frends' and `user`='".$id."' and `idwh`='".$ya."' and `time`<>'0' or `where`='frends' and `user`='".$ya."' and `idwh`='".$id."' LIMIT 1");
if($sql->num_rows>0){
return true;
}else return false;
}
///проверка: нахожусь ли я в игноре у пользователя
public function ignor($id,$ya){
global $db;
$sql = $db -> query("SELECT * FROM `nuts` WHERE `where`='ignor' and `idwh`='".$id."' and `user`='".$ya."' LIMIT 1");
if($sql->num_rows>0){
return true;
}else return false;
}
////Вывод аватара
public function avatar($id,$w=56,$h=55,$url=0){
global $db;
$nas = $db -> query("SELECT `name`,`parametr` FROM `settings` where `name`='ststyle'");
while ($assoc = $nas -> fetch_assoc()) {
$nastr[$assoc['name']]=$assoc['parametr'];
}
$nas->free();
$arr = $db -> query("SELECT `login`,`foto`,`sex` FROM `users` WHERE `id` = '".$id."' LIMIT 1");
if ($arr -> num_rows > 0) {
$array = $arr -> fetch_assoc();
if($url==0){
$url1='<a href="/id'.$id.'">';
$url2='</a>';
}else{$url1=$url2=null;}
if($array['foto']!=0){
$foto = $db -> query("SELECT `url`,`what` FROM `files` where `id`='".$array['foto']."'")->fetch_assoc();
$avatar=$url1.'<img class="avatar" src="/system/resize.php?img=../downloads/'.$foto['what'].'/'.$foto['url'].'&width='.$w.'&height='.$h.'&i=0">'.$url2;
}else{
$avatar=$url1.'<img class="avatar" src="/styles/'.STYLE.'/images/'.$array['sex'].'.png" width='.$w.' height='.$h.' alt="'.language('Аватар').'"/>'.$url2;
}
}else $avatar=null;
if($avatar!=null)$avatar=$avatar;
return $avatar;
}
///
//Функция вывода онлайн или нет
public function online($user,$off=false){
global $db;
$arr = $db -> query("SELECT `login`,`lasttime` FROM `users` WHERE `id` = '".$user."'")->fetch_array();
if ($arr> 0){
if($online=1){
$only = $db -> query("SELECT `login` FROM `online` WHERE `login` = '".$arr['login']."'")->fetch_array();
if($only>''){
$log='<span class="online">'.language('В сети').'</span>';
}else{
if($off==true)$log='<span class="offline">'.language('Не в сети').'</span>';
}
}
}else $log=null;
return $log;
}
//Функция вывода ника
public function login($user,$url=1) {
global $db;
$arr = $db -> query("SELECT `login` FROM `users` WHERE `id` = '".$user."'")->fetch_array();
if ($arr> 0){
if($url==1)$log='<a href="'.ROOT.'id'.$user.'">'.$arr['login'].'</a>'; else $log=$arr['login'];
}else $log='['.language('Удален').']';
return $log;
}
//Функция вывода Имя Фамилия или если не указаны-просто ник
public function famname($user,$url=1) {
global $db;
$arr = $db -> query("SELECT `login`,`name`,`fami` FROM `users` WHERE `id` = '".$user."'")->fetch_array();
if ($arr> 0){
if(mb_strlen($arr['name'])>0 or mb_strlen($arr['fami'])>0)
{
if($url==1)$log='<a href="'.ROOT.'id'.$user.'">'.$arr['name'].' '.$arr['fami'].'</a>'; else $log=$arr['name'].' '.$arr['fami'];
}else{
if($url==1)$log='<a href="'.ROOT.'id'.$user.'">'.$arr['login'].'</a>'; else $log=$arr['login'];
}
}else $log='['.language('Удален').']';
return $log;
}
//вывод зодиака
public function zodiak($d,$m)
{
if ($d != NULL and $m != NULL) {
if (($d >= 20 and $m == 3)or($d <= 20 and $m == 4)){
$znak = '<img src="/styles/'.STYLE.'/images/zodiak/zodiac_aries.png" title = "'.language('Овен').'" alt="'.language('Овен').'"/>';
}
if (($d >= 20 and $m == 4)or($d <= 21 and $m == 5)){
$znak = '<img src="/styles/'.STYLE.'/images/zodiak/zodiac_taurus.png" title = "'.language('Телец').'" alt="'.language('Телец').'"/>';
}
if (($d >= 21 and $m == 5)or($d <= 21 and $m == 6)){
$znak = '<img src="/styles/'.STYLE.'/images/zodiak/zodiac_gemini.png" title = "'.language('Близнецы').'" alt="'.language('Близнецы').'"/>';
}
if (($d >= 21 and $m == 6)or($d <= 22 and $m == 7)){
$znak = '<img src="/styles/'.STYLE.'/images/zodiak/zodiac_cancer.png" title = "'.language('Рак').'" alt="'.language('Рак').'"/>';
}
if (($d >= 22 and $m == 7)or($d <= 22 and $m == 8)){
$znak = '<img src="/styles/'.STYLE.'/images/zodiak/zodiac_leo.png" title = "'.language('Лев').'" alt="'.language('Лев').'"/>';
}
if (($d >= 23 and $m == 8)or($d <= 20 and $m == 9)){
$znak = '<img src="/styles/'.STYLE.'/images/zodiak/zodiac_virgo.png" title = "'.language('Дева').'" alt="'.language('Дева').'"/>';
}
if (($d >= 23 and $m == 9)or($d <= 23 and $m == 10)){
$znak = '<img src="/styles/'.STYLE.'/images/zodiak/zodiac_libra.png" title = "'.language('Весы').'" alt="'.language('Весы').'"/>';
}
if (($d >= 24 and $m == 10)or($d <= 22 and $m == 11)){
$znak = '<img src="/styles/'.STYLE.'/images/zodiak/zodiac_scorpio.png" title = "'.language('Скорпион').'" alt="'.language('Скорпион').'"/>';
}
if (($d >= 23 and $m == 11)or($d <= 21 and $m == 12)){
$znak = '<img src="/styles/'.STYLE.'/images/zodiak/zodiac_sagittarius.png" title = "'.language('Стрелец').'" alt="'.language('Стрелец').'"/>';
}
if (($d >= 22 and $m == 12)or($d <= 20 and $m == 1)){
$znak = '<img src="/styles/'.STYLE.'/images/zodiak/zodiac_capricorn.png" title = "'.language('Козерог').'" alt="'.language('Козерог').'"/>';
}
if (($d >= 21 and $m == 1)or($d <= 18 and $m == 2)){
$znak = '<img src="/styles/'.STYLE.'/images/zodiak/zodiac.png" title = "'.language('Водолей').'" alt="'.language('Водолей').'"/>';
}
if (($d >= 19 and $m == 2)or($d <= 20 and $m == 3)){
$znak = '<img src="/styles/'.STYLE.'/images/zodiak/zodiac_pisces.png" title = "'.language('Рыбы').'" alt="'.language('Рыбы').'"/>';
}
return $znak;
}
}
}
?>