init
This commit is contained in:
210
index.php
Normal file
210
index.php
Normal file
@@ -0,0 +1,210 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @file index.php
|
||||||
|
* @brief Главный входной файл сайта, инициализация сессий, подключение конфигов, загрузка страниц и формирование HTML.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @brief Путь к текущей директории */
|
||||||
|
$path = dirname(__FILE__) . '/';
|
||||||
|
|
||||||
|
/* if(isset($_SESSION)) { file_put_contents($path . '/error.txt', "" . PHP_EOL, FILE_APPEND); }*/
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
/** @brief Установка флага доступа для текущей сессии */
|
||||||
|
$_SESSION['access'] = true;
|
||||||
|
|
||||||
|
include_once $path . 'data/func.php';
|
||||||
|
includePluginsPhp();
|
||||||
|
|
||||||
|
SetConfig();
|
||||||
|
/** @brief Массив администраторов */
|
||||||
|
$configAdmins = adminsConfig();
|
||||||
|
|
||||||
|
/** @brief URI запроса, преобразованный в формат страницы */
|
||||||
|
$REQUEST_URI = $_SERVER['REQUEST_URI'] === '/' ? GetRequestURL('/index.html')['str'] : GetRequestURL($_SERVER['REQUEST_URI'])['str'];
|
||||||
|
|
||||||
|
/** @brief Текущий язык сайта */
|
||||||
|
$config['lng'] = SetLanguage();
|
||||||
|
|
||||||
|
/** @brief Результат функции URLstr для текущей страницы */
|
||||||
|
$ansv = URLstr($path . 'data/filepath.'.$config['lng'].'.php', $REQUEST_URI);
|
||||||
|
|
||||||
|
/** @brief URL текущей страницы */
|
||||||
|
$config['page_url'] = $ansv['FileURL'];
|
||||||
|
|
||||||
|
/** @brief Оригинальный URI запроса */
|
||||||
|
$config['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
|
||||||
|
|
||||||
|
if (!isset($_SESSION['page_url'])) {
|
||||||
|
$_SESSION['page_url'] = $config['page_url'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$methodRpc = null;
|
||||||
|
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] === "POST" && strpos($_SERVER["CONTENT_TYPE"] ?? "", "application/json") !== false) {
|
||||||
|
jsonrpcRequest();
|
||||||
|
$methodRpc = json_decode(file_get_contents("php://input"), true)["method"] ?? null;
|
||||||
|
}
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['handleRequestAction'])) {
|
||||||
|
handleRequest($_POST['handleRequestAction']);
|
||||||
|
}
|
||||||
|
setcookie('Login', $_SESSION['Login'] === 'true' ? 'true' : 'false', time() + 2419200, "/");
|
||||||
|
|
||||||
|
/** @brief Разрешённые действия для очистки URL страницы из сессии */
|
||||||
|
$allowed = ['loginUser', 'setLng'];
|
||||||
|
|
||||||
|
if (($_POST['handleRequestAction'] && !in_array($_POST['handleRequestAction'], $allowed)) ||
|
||||||
|
($methodRpc && !in_array($methodRpc, $allowed))) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
if ($_POST['handleRequestAction'] || $methodRpc) {
|
||||||
|
unset($_SESSION['page_url']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$config['server'] = 'http://'.$_SERVER['HTTP_HOST'].'/';
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_URI']=='/')
|
||||||
|
$REQUESTxURI =GetRequestURL('/index.html');
|
||||||
|
else
|
||||||
|
$REQUESTxURI =GetRequestURL($_SERVER['REQUEST_URI']);
|
||||||
|
|
||||||
|
/** @brief URI текущей страницы */
|
||||||
|
$REQUEST_URI = $REQUESTxURI['str'];
|
||||||
|
|
||||||
|
/** @brief Путь к корневой директории */
|
||||||
|
$config['path'] = $path;
|
||||||
|
|
||||||
|
/** @brief Полный URL запроса */
|
||||||
|
$config['request_url'] = $REQUEST_URI;
|
||||||
|
|
||||||
|
/** @brief Шаблон страницы */
|
||||||
|
$config['template'] = $ansv['template'];
|
||||||
|
|
||||||
|
/** @brief Название сайта */
|
||||||
|
$config['sitename'] = $ansv['sitename'];
|
||||||
|
|
||||||
|
/** @brief Заголовок страницы */
|
||||||
|
$config['title'] = $ansv['title'];
|
||||||
|
|
||||||
|
/** @brief Sitemap или структура URL */
|
||||||
|
$config['smap'] = $ansv['URLLine'];
|
||||||
|
|
||||||
|
/** @brief Подключённые плагины для страницы */
|
||||||
|
$config['page_plugins'] = $ansv['page_plugins'];
|
||||||
|
|
||||||
|
/** @brief Меню выбора языка */
|
||||||
|
$config['LngMenu'] = LngMenu();
|
||||||
|
|
||||||
|
/* if ($REQUESTxURI['act']=='edit' && $REQUESTxURI['act']!=''){ echo $editXML->saveXML(); } else{ */
|
||||||
|
|
||||||
|
/** @brief Массив элементов меню страницы */
|
||||||
|
$menu = explode(',', $ansv['page']['PageMenu']);
|
||||||
|
|
||||||
|
/** @brief Верхнее меню сайта */
|
||||||
|
$config['TopMenu'] = GetXMLMenu($ansv['XML']->index, $REQUEST_URI, $menu[0], 'h');
|
||||||
|
|
||||||
|
/** @brief Боковое меню сайта */
|
||||||
|
$config['sideMenu'] = GetSideXMLMenu($ansv['XML']->index, $REQUEST_URI, $menu[0]);
|
||||||
|
|
||||||
|
/** @brief Основное меню сайта */
|
||||||
|
$config['SiteMenu'] = GetXMLMenu($ansv['XML']->index, $REQUEST_URI, $menu[1], 'h');
|
||||||
|
|
||||||
|
/* && $config['REQUEST_URI']=='/' */
|
||||||
|
if (empty($config['TopMenu'])) {
|
||||||
|
if ($_SESSION['Login'] == 'false') {
|
||||||
|
$_SESSION['formType'] = 'log_err';
|
||||||
|
} else {
|
||||||
|
$_SESSION['formType']= 'log_on';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_file($path . $config['page_url'].".page.php")) {
|
||||||
|
$xmlstr = simplexml_load_file($path . $config['page_url'].".page.php");
|
||||||
|
} else {
|
||||||
|
error405(true, $config['encoding']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* $EditPage['url'] = $path .'content/scan/index.page.php'; $EditPage['page'] = simplexml_load_file($EditPage['url']); */
|
||||||
|
|
||||||
|
/** @brief Полное название сайта с текущей страницей */
|
||||||
|
$config['sitename'] .= ' > ' . $config['title'];
|
||||||
|
|
||||||
|
/** @brief CSS-класс заголовка контента */
|
||||||
|
$config['ctitle'] = $xmlstr->content['tclass'];
|
||||||
|
|
||||||
|
/** @brief CSS-класс блока контента */
|
||||||
|
$config['cfloat'] = $xmlstr->content['bclass'];
|
||||||
|
|
||||||
|
/** @brief Права доступа текущего пользователя к странице */
|
||||||
|
$access = FindPageUser($ansv['page']['users'], $_SESSION['username']);
|
||||||
|
|
||||||
|
if ($access) {
|
||||||
|
$config['left'] = GetBlock($xmlstr->lblock->block, 'left');
|
||||||
|
$config['left'] .= getNews($xmlstr->lblock->block, 'left');
|
||||||
|
$config['left'] = "<div id='left-float'>" . $config['left'] . "</div>";
|
||||||
|
|
||||||
|
$config['right'] = GetBlock($xmlstr->rblock->block, 'right');
|
||||||
|
$config['right'] .= getNews($xmlstr->rblock->block, "right");
|
||||||
|
$config['right'] = "<div id='right-float'>" . $config['right'] . "</div>";
|
||||||
|
|
||||||
|
$center = '<div class="center-float">' . GetBlock($xmlstr->cblock->block, 'center') . '<div>';
|
||||||
|
$config['content'] = $xmlstr->content->{$config['lng']};
|
||||||
|
} else {
|
||||||
|
if ($_SESSION['log_in']) {
|
||||||
|
$xmlstr = simplexml_load_file($path . 'content/adm/user.page.php');
|
||||||
|
} else {
|
||||||
|
$xmlstr = simplexml_load_file($path . 'content/adm/access.page.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
$config['left'] = '';
|
||||||
|
$config['right'] = '';
|
||||||
|
$center = '<div class="center-float">' . GetBlock($xmlstr->cblock->block, 'center') . '<div>';
|
||||||
|
$config['content'] = $xmlstr->content->$config['lng'];
|
||||||
|
}
|
||||||
|
foreach ($config as $key=>$value) if ($key!="request_url")
|
||||||
|
$config['content'] =str_replace('%'.$key.'%', $value, $config['content']);
|
||||||
|
$config['content'] =str_replace('%center%', $center, $config['content']);
|
||||||
|
$config['home'] ='index.html';
|
||||||
|
|
||||||
|
if (isset($_SESSION['username'])) {
|
||||||
|
$config['User'] = $_SESSION['username'];
|
||||||
|
} else {
|
||||||
|
$config['User'] = 'Гость';
|
||||||
|
}
|
||||||
|
setcookie('User', $config['User'], time() + 2419200, '/');
|
||||||
|
|
||||||
|
$html .= '<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">';
|
||||||
|
$html .= file_get_contents($path . 'data/top.php');
|
||||||
|
$html .= file_get_contents($path . 'template/'.$config['template'].'/page.php');
|
||||||
|
/* $html .= file_get_contents($path . 'data/foot.php'); */
|
||||||
|
$html .= '<link rel="stylesheet" href="/data/fonts/fonts.css">';
|
||||||
|
|
||||||
|
$lang = include $path . 'data/lang.php';
|
||||||
|
$lng = $_SESSION['lng'] ?? 'en';
|
||||||
|
$Js = file_get_contents($path . 'data/Basic_functions.js');
|
||||||
|
foreach ($lang[$lng] as $key => $value) {
|
||||||
|
$Js = str_replace('{{' . $key . '}}', $value, $Js);
|
||||||
|
}
|
||||||
|
$html .= '<script>' . $Js . '</script>';
|
||||||
|
|
||||||
|
$html .= loadPluginsInCenterBlock();
|
||||||
|
$html .= includePlugin(['plugin' => 'siteSettings']);
|
||||||
|
$html .= includePlugin(['plugin' => 'auth']);
|
||||||
|
/* $html .= includePlugin(['plugin' => 'editor']); */
|
||||||
|
/* $html .= includePlugin(['plugin' => 'manager']); */
|
||||||
|
/* $html .= includePlugin(['plugin' => 'site_tree']); */
|
||||||
|
/* $html .= includePlugin(['plugin' => 'pickr']); */
|
||||||
|
|
||||||
|
$html .= '<div id="news-placeholder">'.getNews($xmlstr->rblock->block, "center").'</div>';
|
||||||
|
|
||||||
|
foreach ($config as $key=>$value)if ($key!="request_url")
|
||||||
|
$html =str_replace('%'.$key.'%', $value, $html);
|
||||||
|
|
||||||
|
header('Content-type: text/html; charset='. $config['encoding']);
|
||||||
|
|
||||||
|
echo $html;
|
||||||
|
|
||||||
|
/* var_dump($REQUEST_URI); echo password_hash("gena", PASSWORD_DEFAULT); //a004b486e740bb4580a04125975893b0 gettype( } */
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user