generated from mirzaev/pot
переработка шаблонизатора, работа над аутентификацией
This commit is contained in:
@@ -1,47 +1,32 @@
|
||||
{% extends "core.html" %}
|
||||
|
||||
{% use 'nodes/account.html' with css as account_css, body as account_body, js as account_js %}
|
||||
{% use "core.html" with css as core_css, body as core_body, js as core_js, js_init as core_js_init %}
|
||||
{% use "header.html" with css as header_css, body as header_body, js as header_js, js_init as header_js_init %}
|
||||
{% use "aside.html" with css as aside_css, body as aside_body, js as aside_js, js_init as aside_js_init %}
|
||||
{% use 'graph/index.html' with css as graph_css, body as graph_body, js as graph_js, js_init as graph_js_init %}
|
||||
|
||||
{% block css %}
|
||||
{{ block('core_css') }}
|
||||
{{ block('header_css') }}
|
||||
{{ block('aside_css') }}
|
||||
{{ block('graph_css') }}
|
||||
{{ block('account_css') }}
|
||||
{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
{{ block('core_body') }}
|
||||
{{ block('aside_body') }}
|
||||
{{ block('header_body') }}
|
||||
|
||||
<main>
|
||||
<noscript>К сожалению мой сайт ещё пока не готов для работы без javascript</noscript>
|
||||
{% block main %}
|
||||
{{ block('account_body') }}
|
||||
{{ nodes.account|raw }}
|
||||
{% endblock %}
|
||||
{{ block('graph_body') }}
|
||||
</main>
|
||||
|
||||
{# {% include 'footer.html' %} #}
|
||||
{# <div class="background"></div> #}
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
{{ block('core_js') }}
|
||||
{{ block('header_js') }}
|
||||
{{ block('aside_js') }}
|
||||
{{ block('graph_js') }}
|
||||
{{ block('account_js') }}
|
||||
{% endblock %}
|
||||
|
||||
{% block js_init %}
|
||||
{{ block('core_js_init') }}
|
||||
{{ block('header_js_init') }}
|
||||
{{ block('aside_js_init') }}
|
||||
{{ block('graph_js_init') }}
|
||||
{% endblock %}
|
||||
|
@@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace mirzaev\site\account\views;
|
||||
|
||||
use mirzaev\minimal\controller;
|
||||
|
||||
use Twig\Loader\FilesystemLoader;
|
||||
use Twig\Environment as view;
|
||||
|
||||
/**
|
||||
* Менеджер представлений
|
||||
*
|
||||
* @package mirzaev\site\account\controllers
|
||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||
*/
|
||||
final class manager extends controller
|
||||
{
|
||||
public function render(string $file, array $vars = []): ?string
|
||||
{
|
||||
// Генерация представления
|
||||
return (new view(new FilesystemLoader(VIEWS)))->render($file, $vars);
|
||||
}
|
||||
}
|
30
mirzaev/site/account/system/views/nodes/authentication.html
Normal file
30
mirzaev/site/account/system/views/nodes/authentication.html
Normal file
@@ -0,0 +1,30 @@
|
||||
{% block css %}
|
||||
<link type="text/css" rel="stylesheet" href="/css/account.css">
|
||||
<link type="text/css" rel="stylesheet" href="/css/icons/arrow_right.css">
|
||||
{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<section id="authentication">
|
||||
{% if account %}
|
||||
{{ account.getKey() }}
|
||||
{% if vk %}
|
||||
{{ vk.mail }}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<section class="header unselectable">
|
||||
<h1>Аутентификация</h1>
|
||||
</section>
|
||||
<section class="body">
|
||||
<label>
|
||||
<input type="text" name="mail" id="mail" value="{{ account.mail ?? session.buffer.mail ?? cookie.buffer_mail }}" oninplut="remember('mail', this.value, 2000)">
|
||||
<button class="accept" onclick="account.check(this.parentElement.querySelector('[name=mail]').value) ? account.authentication() : account.registration()"><i class="arrow right"></i></button>
|
||||
</label>
|
||||
<input type="password" name="password" id="password">
|
||||
</section>
|
||||
{% endif %}
|
||||
</section>
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
<script type="text/javascript" src="/js/account.js"></script>
|
||||
{% endblock %}
|
176
mirzaev/site/account/system/views/templater.php
Normal file
176
mirzaev/site/account/system/views/templater.php
Normal file
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace mirzaev\site\account\views;
|
||||
|
||||
// Файлы проекта
|
||||
use mirzaev\minimal\controller;
|
||||
|
||||
// Шаблонизатор представлений
|
||||
use Twig\Loader\FilesystemLoader,
|
||||
Twig\Environment as twig;
|
||||
|
||||
// Встроенные библиотеки
|
||||
use ArrayAccess;
|
||||
|
||||
/**
|
||||
* Шаблонизатор представлений
|
||||
*
|
||||
* @package mirzaev\site\account\controllers
|
||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||
*/
|
||||
final class templater extends controller implements ArrayAccess
|
||||
{
|
||||
/**
|
||||
* Реестр глобальных переменных
|
||||
*/
|
||||
public array $variables = [];
|
||||
|
||||
/**
|
||||
* Инстанция окружения twig
|
||||
*/
|
||||
public twig $twig;
|
||||
|
||||
/**
|
||||
* Конструктор
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// Инициализация шаблонизатора
|
||||
$this->twig = new twig(new FilesystemLoader(VIEWS));
|
||||
|
||||
// Инициализация глобальных переменных
|
||||
$this->twig->addGlobal('cookie', $_COOKIE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Отрисовка HTML-документа
|
||||
*
|
||||
* @param string $file Относительный директории представлений путь до файла представления
|
||||
* @param ?array $variables Реестр переменных
|
||||
*
|
||||
* @return ?string HTML-документ
|
||||
*/
|
||||
public function render(string $file, ?array $variables = null): ?string
|
||||
{
|
||||
// Генерация представления
|
||||
return $this->twig->render($file, $variables ?? $this->variables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Записать
|
||||
*
|
||||
* Записывает переменную в реестр глобальных переменных
|
||||
*
|
||||
* @param string $name Название
|
||||
* @param mixed $value Содержимое
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __set(string $name, mixed $value = null): void
|
||||
{
|
||||
$this->variables[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Прочитать
|
||||
*
|
||||
* Читает переменную из реестра глобальных переменных
|
||||
*
|
||||
* @param string $name Название
|
||||
*
|
||||
* @return mixed Данные переменной из реестра глобальных переменных
|
||||
*/
|
||||
public function __get(string $name): mixed
|
||||
{
|
||||
return $this->variables[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверить инициализированность
|
||||
*
|
||||
* Проверяет инициализированность переменной в буфере переменных представления
|
||||
*
|
||||
* @param string $name Название
|
||||
*
|
||||
* @return bool Переменная инициализирована?
|
||||
*/
|
||||
public function __isset(string $name): bool
|
||||
{
|
||||
return isset($this->variables[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Удалить
|
||||
*
|
||||
* Деинициализирует переменную в реестре глобальных переменных
|
||||
*
|
||||
* @param string $name Название
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __unset(string $name): void
|
||||
{
|
||||
unset($this->variables[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Записать
|
||||
*
|
||||
* Записывает переменную в реестр глобальных переменных
|
||||
*
|
||||
* @param mixed $offset Сдвиг, либо идентификатор
|
||||
* @param mixed $value Содержимое
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function offsetSet(mixed $offset, mixed $value): void
|
||||
{
|
||||
$this->variables[$offset] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Прочитать
|
||||
*
|
||||
* Читает переменную из реестра глобальных переменных
|
||||
*
|
||||
* @param mixed $offset Сдвиг, либо идентификатор
|
||||
*
|
||||
* @return mixed Данные переменной из реестра глобальных переменных
|
||||
*/
|
||||
public function &offsetGet(mixed $offset): mixed
|
||||
{
|
||||
return $this->variables[$offset];
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверить инициализированность
|
||||
*
|
||||
* Проверяет инициализированность переменной в реестре глобальных переменных
|
||||
*
|
||||
* @param mixed $offset Сдвиг, либо идентификатор
|
||||
*
|
||||
* @return bool Переменная инициализирована?
|
||||
*/
|
||||
public function offsetExists(mixed $offset): bool
|
||||
{
|
||||
return isset($this->variables[$offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Удалить
|
||||
*
|
||||
* Деинициализирует переменную в реестре глобальных переменных
|
||||
*
|
||||
* @param mixed $offset Сдвиг, либо идентификатор
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function offsetUnset(mixed $offset): void
|
||||
{
|
||||
unset($this->variables[$offset]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user