Размер файла: 3.16Kb
<?php
/* Настройки системы */
/*error_reporting(E_ALL & ~ E_NOTICE);*/ //В случае тестирования, можно раскомментировать.
mb_internal_encoding('UTF-8');
session_name('SESID');
session_start();
$set = array();
$query = $mysqli->query("SELECT * FROM `settings`");
while($queryy = $query->fetch_assoc())
{
$set[$queryy['name']] = $queryy['value'];
}
/* Авторизация */
if(isset($_COOKIE['login']) AND isset($_COOKIE['password']) AND empty($user_data))
{
$login = mysqli_real_escape_string($mysqli,$_COOKIE['login']);
$password = mysqli_real_escape_string($mysqli,$_COOKIE['password']);
$user = $mysqli->query("SELECT * FROM `users` WHERE `login`='".$login."' AND `password`='".$password."'");
if($user->num_rows > 0)
{
$user_data = $user->fetch_assoc();
}
}
elseif(isset($_SESSION['login']) AND isset($_SESSION['password']) AND empty($user_data))
{
$login = mysqli_real_escape_string($mysqli,$_SESSION['login']);
$password = mysqli_real_escape_string($mysqli,$_SESSION['password']);
$user = $mysqli->query("SELECT * FROM `users` WHERE `login`='".$login."' AND `password`='".$password."'");
if($user->num_rows > 0)
{
$user_data = $user->fetch_assoc();
}
}
/* Основные пользовательские переменные */
$time = time();
$home = $set['home'];
$style = $user_data ? $user_data['style'] : $set['style'];
$pages = $user_data ? $user_data['pages'] : $set['pages'];
/* Определение IP */
$ip = trim(mysqli_real_escape_string($mysqli,htmlspecialchars($_SERVER['REMOTE_ADDR'])));
/* Определение UA */
if (isset($_SERVER['HTTP_X_OPERAMINI_PHONE_UA']))
{
$ua = trim(mysqli_real_escape_string($mysqli,htmlspecialchars($_SERVER['HTTP_X_OPERAMINI_PHONE_UA'])));
}
elseif (isset($_SERVER['HTTP_USER_AGENT']))
{
$ua = trim(mysqli_real_escape_string($mysqli,htmlspecialchars($_SERVER['HTTP_USER_AGENT'])));
}
else
{
$ua = 'Скрыт';
}
$ua = strtok($ua, '/');
$ua = strtok($ua, ' ');
/* Роутер + Основные переменные */
$route = preg_replace('/\0/s', '', $_GET['route']);
$array = explode(";",$route);
if($array[0] AND preg_match('#^([a-zA-Z_]+)$#', $array[0]))
{
$modul = htmlspecialchars($array[0]);
}
if($array[1] AND preg_match('#^([0-9]+)$#', $array[1]))
{
$id = abs(intval($array[1]));
}
if($array[2] AND preg_match('#^([a-zA-Z_]+)$#', $array[2]))
{
$act = htmlspecialchars($array[2]);
}
if($array[3] AND preg_match('#^([0-9]+)$#', $array[3]))
{
$page = abs(intval($array[3]));
}
elseif($array[3] AND preg_match('#^([a-zA-ZА-Яа-я0-9_]+)$#', $array[3]))
{
$ext = $array[3];
}
if($array[4] AND preg_match('#^([0-9]+)$#', $array[4]))
{
$page = abs(intval($array[4]));
}
/* Инициализация шаблонизатора TWIG */
require_once 'Twig/Autoloader.php';
Twig_Autoloader::register();
$loader = new Twig_Loader_Filesystem($_SERVER['DOCUMENT_ROOT'].'/Patterns/'.$style);
$twig = new Twig_Environment($loader, array(
'cache' => $_SERVER['DOCUMENT_ROOT'].'/Data/Cache',
'autoescape'=>false,
'debug'=>false));
?>