<?
define('H', $_SERVER['DOCUMENT_ROOT'].'/');
include_once H .'core/includes/system.php';

$LinkCheck = strpos($urlPage, 'r_page_cms') !== false;
if ($LinkCheck) {
	Redirection('/');
}

$get_page_cms = isset($_REQUEST['r_page_cms']) ? $_REQUEST['r_page_cms'] : null;
$urlType = explode('/', $get_page_cms);
if (empty($urlType[0])) {$urlType[0] = 'main';}
if (empty($urlType[1]))	{$urlType[1] = 'index';}

/*
	Фильтрация данных через функцию обратного вызова 
*/

$urlType = array_filter($urlType, function($text) { 
		return htmlentities($text, ENT_QUOTES, 'UTF-8');
	}
);

$ifone = file_exists(H . 'pages/'. $urlType[0] .'/'. $urlType[1] .'.php');
$iftwo = preg_match('/\.php$/i', isset($get_page_cms) ? $get_page_cms : false) == false;

if ($ifone AND $iftwo) {	
	include H . 'pages/'. $urlType[0] .'/'. $urlType[1] .'.php';
} else {
	$PageConfig = ['title' => 'Ошибка, страница не найдена'];
	PageConfig($PageConfig);
	$t->assign('data', 
		[
			'msg' => 'Страницы не существует, или она удалена',
			'err' => 404,
			'urlType' => $urlType,
			'urlPage' => $urlPage,		
		]
	);
	echo $t->fetch('main.error');
}

list($msec, $sec) = explode(chr(32), microtime());
$GenPage = number_format(($sec + $msec) - $set['GenPage'], 3);
if (isset($PageConfig) AND @$PageConfig['foot'] != 'hide') {
	$t->assign('GenPage', $GenPage);
	echo $t->fetch('foot');
}
unset($message,$message_err,$ifone, $iftwo);