<?
/*
* Загрузка ядра
*/



require '_system/core.php';

// Изменение тем пользователя
if (!isset($_SESSION['design'])) {
	$iphone = strpos($_SERVER['HTTP_USER_AGENT'], "iPhone");
	$android = strpos($_SERVER['HTTP_USER_AGENT'], "Android");
	$palmpre = strpos($_SERVER['HTTP_USER_AGENT'], "webOS");
	$berry = strpos($_SERVER['HTTP_USER_AGENT'], "BlackBerry");
	$ipod = strpos($_SERVER['HTTP_USER_AGENT'], "iPod");
	$mobile = strpos($_SERVER['HTTP_USER_AGENT'], "Mobile");
	$symb = strpos($_SERVER['HTTP_USER_AGENT'], "Symbian");
	$operam = strpos($_SERVER['HTTP_USER_AGENT'], "Opera M");
	$htc = strpos($_SERVER['HTTP_USER_AGENT'], "HTC_");
	$fennec = strpos($_SERVER['HTTP_USER_AGENT'], "Fennec/");
	$winphone = strpos($_SERVER['HTTP_USER_AGENT'], "WindowsPhone");
	$wp7 = strpos($_SERVER['HTTP_USER_AGENT'], "WP7");
	$wp8 = strpos($_SERVER['HTTP_USER_AGENT'], "WP8");

	if ($ipad || $iphone || $android || $palmpre || $ipod || $berry || $mobile || $symb || $operam || $htc || $fennec || $winphone || $wp7 || $wp8 === true) {
	    $_SESSION['design'] = 'default';
	} else {
		  $_SESSION['design'] = 'web';
	}
}

// Тема для гостей
if (isset($_SESSION['design']) && !isset($_SESSION['id_user'])) {
	$system['design'] = $_SESSION['design'];
}

require '_system/user.php';

if (isset($_GET['version']) && preg_match("#^([A-zА-я0-9\-\_\.]+)$#ui", $_GET['version'])) {
	if (is_dir('themes/' . $_GET['version'])) {
		if (isset($user['id'])) {
			$sql -> update("UPDATE `users` SET `design` = '" . $_GET['version'] . "' WHERE `id` = '$user[id]' LIMIT 1");
		} else {
			$_SESSION['design'] = $_GET['version'];
		}
		if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != null)
        header("Location: ".text($_SERVER['HTTP_REFERER']));
        else header('Location: /');
		exit;
	}
}

// Главная сайта 
if ($design == 'web' && $func == 'home') {
	$func = 'home2';
}

/**
* 
* @var Загрузка раздела 
* 
*/

if (is_file(ROOT.'plugins/' . $func . '.php')) {
	require ROOT.'plugins/' . $func . '.php';
}else{
    header("Location: /404.html".SID);
}

require '_system/end.php';
?>