ADD: Configuration
This commit is contained in:
parent
da75d69ddf
commit
35e4290e94
|
@ -4,17 +4,18 @@ namespace App\Controllers;
|
|||
|
||||
use Hleb\Scheme\App\Controllers\MainController;
|
||||
use Hleb\Constructor\Handlers\Request;
|
||||
use Data, Content;
|
||||
use Content, Translate;
|
||||
|
||||
class ArticleController extends MainController
|
||||
{
|
||||
public function index($slug)
|
||||
{
|
||||
if (!in_array($lang = Request::get('lang'), Data::LANG)) {
|
||||
if (!in_array($lang = Request::get('lang'), config('general.lang'))) {
|
||||
redirect('/');
|
||||
}
|
||||
|
||||
Data::lang($lang);
|
||||
$lang = $lang ?? config('general.default_lang');
|
||||
Translate::setLang($lang);
|
||||
|
||||
if (!$file = 'files/' . $lang . '/' . $slug . '.md') {
|
||||
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/",
|
||||
"Phphleb\\": "vendor/phphleb/",
|
||||
"Hleb\\": "vendor/phphleb/framework/"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"app/helpers.php"
|
||||
]
|
||||
},
|
||||
"config": {
|
||||
"optimize-autoloader": true
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
<main>
|
||||
<?= $data['contents']; ?>
|
||||
</main>
|
||||
<?php if ($data['headings']) { ?>
|
||||
<?php if ($data['headings']) { ?>
|
||||
<?php if($data['headings']) { ?>
|
||||
<?php if($data['headings']) { ?>
|
||||
<aside>
|
||||
<?= $data['headings']; ?>
|
||||
</aside>
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
</body>
|
||||
<?= getRequestResources()->getBottomStyles(); ?>
|
||||
<?= getRequestResources()->getBottomScripts(); ?>
|
||||
|
||||
</html>
|
|
@ -1,34 +1,29 @@
|
|||
<?php
|
||||
use Hleb\Constructor\Handlers\Request;
|
||||
Request::getHead()->addStyles('/assets/css/style.css?1');
|
||||
Request::getResources()->addBottomScript('/assets/js/app.js?1');
|
||||
$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>
|
||||
<html lang="ru">
|
||||
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<meta name="description" content="<?= $desc; ?>" />
|
||||
<meta name="theme-color" content="#ff786c">
|
||||
<?php getRequestHead()->output(); ?>
|
||||
<link rel="icon" href="/favicon.ico" type="image/x-icon">
|
||||
<title><?= $title; ?> | <?= Data::NAME; ?></title>
|
||||
<link rel="icon" href= "/favicon.ico" type="image/x-icon">
|
||||
<title><?= $title; ?> | <?= config('general.name'); ?></title>
|
||||
</head>
|
||||
|
||||
<body class="<?= $bg; ?><?php if (Request::getCookie('dayNight') == 'dark') { ?> dark<?php } ?>">
|
||||
<header>
|
||||
<header>
|
||||
<div class="wrap">
|
||||
<nav class="navbar">
|
||||
<?= $logo; ?>
|
||||
<div id="toggledark">
|
||||
<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>
|
||||
<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>
|
||||
</div>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
</header>
|
|
@ -1,6 +1,6 @@
|
|||
<?= includeTemplate('header', ['desc' => $desc, 'title' => $title, 'type' => $type]); ?>
|
||||
<div class="box-flex">
|
||||
<?= Data::LOGO_BIG; ?>
|
||||
<?= config('general.logo_big'); ?>
|
||||
<div class="text-max-w500">
|
||||
<?= $help; ?>.
|
||||
</div>
|
||||
|
|
|
@ -180,5 +180,20 @@ error_reporting(E_ALL);
|
|||
*/
|
||||
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