ADD: Configuration
This commit is contained in:
parent
da75d69ddf
commit
35e4290e94
|
@ -4,18 +4,19 @@ namespace App\Controllers;
|
||||||
|
|
||||||
use Hleb\Scheme\App\Controllers\MainController;
|
use Hleb\Scheme\App\Controllers\MainController;
|
||||||
use Hleb\Constructor\Handlers\Request;
|
use Hleb\Constructor\Handlers\Request;
|
||||||
use Data, Content;
|
use Content, Translate;
|
||||||
|
|
||||||
class ArticleController extends MainController
|
class ArticleController extends MainController
|
||||||
{
|
{
|
||||||
public function index($slug)
|
public function index($slug)
|
||||||
{
|
{
|
||||||
if (!in_array($lang = Request::get('lang'), Data::LANG)) {
|
if (!in_array($lang = Request::get('lang'), config('general.lang'))) {
|
||||||
redirect('/');
|
redirect('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
Data::lang($lang);
|
$lang = $lang ?? config('general.default_lang');
|
||||||
|
Translate::setLang($lang);
|
||||||
|
|
||||||
if (!$file = 'files/' . $lang . '/' . $slug . '.md') {
|
if (!$file = 'files/' . $lang . '/' . $slug . '.md') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Exception;
|
||||||
|
|
||||||
|
class ConfigException extends \Exception
|
||||||
|
{
|
||||||
|
public static function NotFoundException(string $file): self
|
||||||
|
{
|
||||||
|
return new self("Configuration file does not exist: `{$file}`.");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Exception\ConfigException;
|
||||||
|
|
||||||
|
class Configuration
|
||||||
|
{
|
||||||
|
private static $path = HLEB_SEARCH_DBASE_CONFIG_FILE;
|
||||||
|
|
||||||
|
private static $cache = [];
|
||||||
|
|
||||||
|
public static function get($name, $default = null)
|
||||||
|
{
|
||||||
|
$file = false !== strpos($name, '.') ? strstr($name, '.', true) : $name;
|
||||||
|
|
||||||
|
$key = ltrim(strstr($name, '.'), '.');
|
||||||
|
|
||||||
|
self::$path = realpath(self::$path);
|
||||||
|
|
||||||
|
if (!self::$path) {
|
||||||
|
echo 'Config path does not exist';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_file(self::$path . '/' . $file . '.php')) {
|
||||||
|
throw ConfigException::NotFoundException($file);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!array_key_exists(self::$path . '/' . $file . '.php', self::$cache)) {
|
||||||
|
|
||||||
|
$data = include self::$path . '/' . $file . '.php';
|
||||||
|
|
||||||
|
if (!is_array($data)) {
|
||||||
|
echo ('This is not an array: ' . self::$path . '/' . $file . '.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
self::$cache[self::$path . '/' . $file . '.php'] = $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($name === $file) {
|
||||||
|
return self::$cache[self::$path . '/' . $file . '.php'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array_key_exists($key, self::$cache[self::$path . '/' . $file . '.php'])) {
|
||||||
|
return self::$cache[self::$path . '/' . $file . '.php'][$key];
|
||||||
|
}
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,20 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
// Constants to use
|
|
||||||
class Data
|
|
||||||
{
|
|
||||||
const LANG = ['ru', 'en'];
|
|
||||||
const DEFAULT_LANG = ['ru', 'en'];
|
|
||||||
|
|
||||||
const NAME = 'LibArea';
|
|
||||||
|
|
||||||
const LOGO_BIG = '<img class="logo" alt="LibArea" src="/assets/images/LibArea_limpid.png">';
|
|
||||||
const LOGO_SMALL = '<a title="LibArea" href="/">LibArea</a>';
|
|
||||||
|
|
||||||
|
|
||||||
public static function lang($lang = 'ru')
|
|
||||||
{
|
|
||||||
$lang = $lang ?? self::DEFAULT_LANG;
|
|
||||||
Translate::setLang($lang);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Global "helper" functions.
|
||||||
|
*
|
||||||
|
* Глобальные «вспомогательные» функции.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// @param string|null $key
|
||||||
|
function __(string $key = null, array $params = [])
|
||||||
|
{
|
||||||
|
if ($key === null) {
|
||||||
|
return $key;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Translate::get($key, $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
function url(string $key = null, array $params = [])
|
||||||
|
{
|
||||||
|
if ($key === null) {
|
||||||
|
return $key;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hleb_get_by_name($key, $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
function config(string $key = null)
|
||||||
|
{
|
||||||
|
if ($key === null) {
|
||||||
|
return $key;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Configuration::get($key);
|
||||||
|
}
|
|
@ -34,7 +34,10 @@
|
||||||
"App\\": "app/",
|
"App\\": "app/",
|
||||||
"Phphleb\\": "vendor/phphleb/",
|
"Phphleb\\": "vendor/phphleb/",
|
||||||
"Hleb\\": "vendor/phphleb/framework/"
|
"Hleb\\": "vendor/phphleb/framework/"
|
||||||
}
|
},
|
||||||
|
"files": [
|
||||||
|
"app/helpers.php"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"optimize-autoloader": true
|
"optimize-autoloader": true
|
||||||
|
|
|
@ -2,15 +2,15 @@
|
||||||
|
|
||||||
<div id="contentWrapper" class="wrap">
|
<div id="contentWrapper" class="wrap">
|
||||||
<main>
|
<main>
|
||||||
<?= $data['contents']; ?>
|
<?= $data['contents']; ?>
|
||||||
</main>
|
</main>
|
||||||
<?php if ($data['headings']) { ?>
|
<?php if($data['headings']) { ?>
|
||||||
<?php if ($data['headings']) { ?>
|
<?php if($data['headings']) { ?>
|
||||||
<aside>
|
<aside>
|
||||||
<?= $data['headings']; ?>
|
<?= $data['headings']; ?>
|
||||||
</aside>
|
</aside>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?= includeTemplate('footer'); ?>
|
<?= includeTemplate('footer'); ?>
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
</body>
|
</body>
|
||||||
<?= getRequestResources()->getBottomStyles(); ?>
|
<?= getRequestResources()->getBottomStyles(); ?>
|
||||||
<?= getRequestResources()->getBottomScripts(); ?>
|
<?= getRequestResources()->getBottomScripts(); ?>
|
||||||
|
|
||||||
</html>
|
</html>
|
|
@ -1,34 +1,29 @@
|
||||||
<?php
|
<?php
|
||||||
use Hleb\Constructor\Handlers\Request;
|
Request::getHead()->addStyles('/assets/css/style.css?1');
|
||||||
Request::getHead()->addStyles('/assets/css/style.css?1');
|
Request::getResources()->addBottomScript('/assets/js/app.js?1');
|
||||||
Request::getResources()->addBottomScript('/assets/js/app.js?1');
|
|
||||||
$bg = $type == 'main' ? 'bg' : 'no';
|
$bg = $type == 'main' ? 'bg' : 'no';
|
||||||
$logo = $type == 'main' ? '<div class="p40"></div>' : Data::LOGO_SMALL;
|
$logo = $type == 'main' ? '<div class="p40"></div>' : config('general.logo_small');
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="ru">
|
<html lang="ru">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
<meta name="description" content="<?= $desc; ?>" />
|
<meta name="description" content="<?= $desc; ?>" />
|
||||||
<meta name="theme-color" content="#ff786c">
|
<meta name="theme-color" content="#ff786c">
|
||||||
<?php getRequestHead()->output(); ?>
|
<?php getRequestHead()->output(); ?>
|
||||||
<link rel="icon" href="/favicon.ico" type="image/x-icon">
|
<link rel="icon" href= "/favicon.ico" type="image/x-icon">
|
||||||
<title><?= $title; ?> | <?= Data::NAME; ?></title>
|
<title><?= $title; ?> | <?= config('general.name'); ?></title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body class="<?= $bg; ?><?php if (Request::getCookie('dayNight') == 'dark') { ?> dark<?php } ?>">
|
<body class="<?= $bg; ?><?php if (Request::getCookie('dayNight') == 'dark') { ?> dark<?php } ?>">
|
||||||
<header>
|
<header>
|
||||||
<div class="wrap">
|
<div class="wrap">
|
||||||
<nav class="navbar">
|
<nav class="navbar">
|
||||||
<?= $logo; ?>
|
<?= $logo; ?>
|
||||||
<div id="toggledark">
|
<div id="toggledark">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24px" height="24px">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24px" height="24px"><path d="M 11 0 L 11 3 L 13 3 L 13 0 L 11 0 z M 4.2226562 2.8085938 L 2.8085938 4.2226562 L 4.9296875 6.34375 L 6.34375 4.9296875 L 4.2226562 2.8085938 z M 19.777344 2.8085938 L 17.65625 4.9296875 L 19.070312 6.34375 L 21.191406 4.2226562 L 19.777344 2.8085938 z M 12 5 C 8.1458514 5 5 8.1458514 5 12 C 5 15.854149 8.1458514 19 12 19 C 15.854149 19 19 15.854149 19 12 C 19 8.1458514 15.854149 5 12 5 z M 12 7 C 14.773268 7 17 9.2267316 17 12 C 17 14.773268 14.773268 17 12 17 C 9.2267316 17 7 14.773268 7 12 C 7 9.2267316 9.2267316 7 12 7 z M 0 11 L 0 13 L 3 13 L 3 11 L 0 11 z M 21 11 L 21 13 L 24 13 L 24 11 L 21 11 z M 4.9296875 17.65625 L 2.8085938 19.777344 L 4.2226562 21.191406 L 6.34375 19.070312 L 4.9296875 17.65625 z M 19.070312 17.65625 L 17.65625 19.070312 L 19.777344 21.191406 L 21.191406 19.777344 L 19.070312 17.65625 z M 11 21 L 11 24 L 13 24 L 13 21 L 11 21 z"/></svg>
|
||||||
<path d="M 11 0 L 11 3 L 13 3 L 13 0 L 11 0 z M 4.2226562 2.8085938 L 2.8085938 4.2226562 L 4.9296875 6.34375 L 6.34375 4.9296875 L 4.2226562 2.8085938 z M 19.777344 2.8085938 L 17.65625 4.9296875 L 19.070312 6.34375 L 21.191406 4.2226562 L 19.777344 2.8085938 z M 12 5 C 8.1458514 5 5 8.1458514 5 12 C 5 15.854149 8.1458514 19 12 19 C 15.854149 19 19 15.854149 19 12 C 19 8.1458514 15.854149 5 12 5 z M 12 7 C 14.773268 7 17 9.2267316 17 12 C 17 14.773268 14.773268 17 12 17 C 9.2267316 17 7 14.773268 7 12 C 7 9.2267316 9.2267316 7 12 7 z M 0 11 L 0 13 L 3 13 L 3 11 L 0 11 z M 21 11 L 21 13 L 24 13 L 24 11 L 21 11 z M 4.9296875 17.65625 L 2.8085938 19.777344 L 4.2226562 21.191406 L 6.34375 19.070312 L 4.9296875 17.65625 z M 19.070312 17.65625 L 17.65625 19.070312 L 19.777344 21.191406 L 21.191406 19.777344 L 19.070312 17.65625 z M 11 21 L 11 24 L 13 24 L 13 21 L 11 21 z" />
|
</div>
|
||||||
</svg>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</header>
|
||||||
</div>
|
|
||||||
</header>
|
|
|
@ -1,14 +1,14 @@
|
||||||
<?= includeTemplate('header', ['desc' => $desc, 'title' => $title, 'type' => $type]); ?>
|
<?= includeTemplate('header', ['desc' => $desc, 'title' => $title, 'type' => $type]); ?>
|
||||||
<div class="box-flex">
|
<div class="box-flex">
|
||||||
<?= Data::LOGO_BIG; ?>
|
<?= config('general.logo_big'); ?>
|
||||||
<div class="text-max-w500">
|
<div class="text-max-w500">
|
||||||
<?= $help; ?>.
|
<?= $help; ?>.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="box-flex">
|
<div class="box-flex">
|
||||||
<a class="button-large" href="<?= getUrlByName('welcome', ['lang' => 'ru']); ?>">Русский</a>
|
<a class="button-large" href="<?= getUrlByName('welcome', ['lang' => 'ru']); ?>">Русский</a>
|
||||||
<a class="button-large" href="<?= getUrlByName('welcome', ['lang' => 'en']); ?>">English</a>
|
<a class="button-large" href="<?= getUrlByName('welcome', ['lang' => 'en']); ?>">English</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?= includeTemplate('footer'); ?>
|
<?= includeTemplate('footer'); ?>
|
||||||
|
|
|
@ -180,5 +180,20 @@ error_reporting(E_ALL);
|
||||||
*/
|
*/
|
||||||
define( 'HLEB_PROJECT_VALIDITY_URL', "/^[a-z0-9\_\-\/\.\@]+$/u" );
|
define( 'HLEB_PROJECT_VALIDITY_URL', "/^[a-z0-9\_\-\/\.\@]+$/u" );
|
||||||
|
|
||||||
|
/*
|
||||||
|
|-----------------------------------------------------------------------------
|
||||||
|
| The path to the configuration files
|
||||||
|
|-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Database configuration files and general site settings
|
||||||
|
|
|
||||||
|
|-----------------------------------------------------------------------------
|
||||||
|
| Путь к файлам конфигурации
|
||||||
|
|-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Файлы конфигурации базы данных и общие настройки сайта
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
define('HLEB_SEARCH_DBASE_CONFIG_FILE', realpath(HLEB_GLOBAL_DIRECTORY . '/config'));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue