<?php
if(!defined('MOZG'))
	die('Hacking attempt!');

@include ENGINE_DIR.'/data/config.php';

if(!$config['home_url']) die("MixLife not installed. Please run install.php");

include ENGINE_DIR.'/classes/mysql.php';
include ENGINE_DIR.'/data/db.php';
include ENGINE_DIR.'/classes/templates.php';
if($config['gzip'] == 'yes') include ENGINE_DIR.'/modules/gzip.php';


//FUNC. COOKIES
function clean_url($url) {
	if( $url == '' ) return;
	
	$url = str_replace( "http://", "", strtolower( $url ) );
	$url = str_replace( "https://", "", $url );
	if( substr( $url, 0, 4 ) == 'www.' ) $url = substr( $url, 4 );
	$url = explode( '/', $url );
	$url = reset( $url );
	$url = explode( ':', $url );
	$url = reset( $url );
	
	return $url;
}

$domain_cookie = explode (".", clean_url( $_SERVER['HTTP_HOST'] ));
$domain_cookie_count = count($domain_cookie);
$domain_allow_count = -2;

if($domain_cookie_count > 2){

	if(in_array($domain_cookie[$domain_cookie_count-2], array('com', 'net', 'org') )) 
		$domain_allow_count = -3;
		
	if($domain_cookie[$domain_cookie_count-1] == 'ua' ) 
		$domain_allow_count = -3;
		
	$domain_cookie = array_slice($domain_cookie, $domain_allow_count);
}

$domain_cookie = ".".implode(".", $domain_cookie);

define('DOMAIN', $domain_cookie);

function set_cookie($name, $value, $expires) {
	
	if( $expires ) {
		
		$expires = time() + ($expires * 86400);
	
	} else {
		
		$expires = FALSE;
	
	}
	
	if( PHP_VERSION < 5.2 ) {
		
		setcookie($name, $value, $expires, "/", DOMAIN . "; HttpOnly");
	
	} else {
		
		setcookie($name, $value, $expires, "/", DOMAIN, NULL, TRUE);
	
	}
}

//Смена языка
if($_GET['act'] == 'chage_lang'){
	
	$langId = intval($_GET['id']);
	$config['lang_list'] = nl2br($config['lang_list']);
	$expLangList = explode('<br />', $config['lang_list']);
	$numLangs = count($expLangList);
	
	if($langId > 0 AND $langId <= $numLangs){

		//Меняем язык
		set_cookie("lang", $langId, 365);

	}
	
	$langReferer = $_SERVER['HTTP_REFERER'];
	
	header("Location: {$langReferer}");

}

//lang
$config['lang_list'] = nl2br($config['lang_list']);
$expLangList = explode('<br />', $config['lang_list']);
$numLangs = count($expLangList);
$useLang = intval($_COOKIE['lang']);
if($useLang <= 0) $useLang = 1;
$cil = 0;
foreach($expLangList as $expLangData){

	$cil++;
	
	$expLangName = explode(' | ', $expLangData);
	
	if($cil == $useLang AND $expLangName[0]){
	
		$rMyLang = $expLangName[0];
		$checkLang = $expLangName[1];
		
	}
	
}

if(!$checkLang){
	$rMyLang = 'Русский';
	$checkLang = 'Russian';
}

include ROOT_DIR.'/lang/'.$checkLang.'/site.lng';
include ENGINE_DIR.'/modules/functions.php';

$tpl = new mozg_template;
$tpl->dir = ROOT_DIR.'/templates/'.$config['temp'];
define('TEMPLATE_DIR', $tpl->dir);

$_DOCUMENT_DATE = false;
$Timer = new microTimer();
$Timer->start();

$server_time = intval($_SERVER['REQUEST_TIME']);

include ENGINE_DIR.'/modules/login.php';

if($config['offline'] == "yes") include ENGINE_DIR . '/modules/offline.php';
if($user_info['user_delet'] or $user_info['user_delete_type']!=0) include ENGINE_DIR . '/modules/profile_delet.php';
$sql_banned = $db->super_query("SELECT * FROM ".PREFIX."_banned", true, "banned", true);
if(isset($sql_banned)) $blockip = check_ip($sql_banned); else $blockip = false;
if($user_info['user_ban_date'] >= $server_time OR $user_info['user_ban_date'] == '0' OR $blockip) include ENGINE_DIR . '/modules/profile_ban.php';

//Елси юзер залогинен то обновляем последнюю дату посещения в таблице друзей и на личной стр
if($logged){
$timesetzone = $db->super_query("SELECT timezona FROM `".PREFIX."_users` WHERE user_id = '{$user_info['user_id']}'");
if ($timesetzone['timezona'] == 0){date_default_timezone_set( 'Europe/Kiev' );}
if ($timesetzone['timezona'] == 1){date_default_timezone_set( 'Pacific/Samoa' );}
if ($timesetzone['timezona'] == 2){date_default_timezone_set( 'US/Hawaii' );}
if ($timesetzone['timezona'] == 3){date_default_timezone_set( 'US/Alaska' );}
if ($timesetzone['timezona'] == 4){date_default_timezone_set( 'America/Los_Angeles' );}
if ($timesetzone['timezona'] == 5){date_default_timezone_set( 'America/Denver' );}
if ($timesetzone['timezona'] == 6){date_default_timezone_set( 'America/Chicago' );}
if ($timesetzone['timezona'] == 7){date_default_timezone_set( 'America/New_York' );}
if ($timesetzone['timezona'] == 8){date_default_timezone_set( 'America/Caracas' );}
if ($timesetzone['timezona'] == 9){date_default_timezone_set( 'America/Buenos_Aires' );}
if ($timesetzone['timezona'] == 10){date_default_timezone_set( 'America/Sao_Paulo' );}
if ($timesetzone['timezona'] == 11){date_default_timezone_set( 'Atlantic/Azores' );}
if ($timesetzone['timezona'] == 12){date_default_timezone_set( 'Europe/London' );}
if ($timesetzone['timezona'] == 13){date_default_timezone_set( 'Europe/Berlin' );}
if ($timesetzone['timezona'] == 14){date_default_timezone_set( 'Europe/Kiev' );}
if ($timesetzone['timezona'] == 15){date_default_timezone_set( 'Europe/Moscow' );}
if ($timesetzone['timezona'] == 16){date_default_timezone_set( 'Asia/Yerevan' );}
if ($timesetzone['timezona'] == 17){date_default_timezone_set( 'Asia/Yekaterinburg' );}
if ($timesetzone['timezona'] == 18){date_default_timezone_set( 'Asia/Novosibirsk' );}
if ($timesetzone['timezona'] == 19){date_default_timezone_set( 'Asia/Krasnoyarsk' );}
if ($timesetzone['timezona'] == 20){date_default_timezone_set( 'Asia/Singapore' );}
if ($timesetzone['timezona'] == 21){date_default_timezone_set( 'Asia/Tokyo' );}
if ($timesetzone['timezona'] == 22){date_default_timezone_set( 'Asia/Vladivostok' );}
if ($timesetzone['timezona'] == 23){date_default_timezone_set( 'Australia/Sydney' );}
if ($timesetzone['timezona'] == 24){date_default_timezone_set( 'Asia/Kamchatka' );}    
    
    
    
    
    
    
    
	//Начисления 1 убм.
	if(!$user_info['user_lastupdate']) $user_info['user_lastupdate'] = 1;

	if(date('Y-m-d', $user_info['user_lastupdate']) < date('Y-m-d', $server_time))
		$sql_balance = ", user_balance = user_balance+1, user_lastupdate = '{$server_time}'";

	//Определяем устройство
	if($check_smartphone) $device_user = 1;
	else $device_user = 0;
	
	if(($user_info['user_last_visit'] + 60) <= $server_time){
	
		$db->query("UPDATE LOW_PRIORITY `".PREFIX."_users` SET user_logged_mobile = '{$device_user}', user_last_visit = '{$server_time}' {$sql_balance} WHERE user_id = '{$user_info['user_id']}'");
	
	}
	
}

//Настройки групп пользователей
$user_group = unserialize(serialize(array(
							1 => array( #Администрация
								'addnews' => '1', 
							),
							2 => array( #Главный модератор
								'addnews' => '0', 
							),
							3 => array( #Модератор
								'addnews' => '0', 
							),
							4 => array( #Техподдержка
								'addnews' => '0', 
							), 
							5 => array( #Пользователи
								'addnews' => '0', 
							),
						)));

//Время онлайна
$online_time = $server_time - $config['online_time'];

include ENGINE_DIR.'/mod.php';
?>