Merged in feature/MAPG-89-create-a-better-templating-engine (pull request #156)

Feature/MAPG-89 create a better templating engine
This commit is contained in:
Bence Pőcze 2020-06-26 22:50:14 +00:00
commit de009637de
29 changed files with 526 additions and 136 deletions

2
cache/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

1
mapg
View File

@ -7,5 +7,6 @@ $app = new Symfony\Component\Console\Application('MapGuesser Console', '');
$app->add(new MapGuesser\Cli\DatabaseMigration()); $app->add(new MapGuesser\Cli\DatabaseMigration());
$app->add(new MapGuesser\Cli\AddUserCommand()); $app->add(new MapGuesser\Cli\AddUserCommand());
$app->add(new MapGuesser\Cli\LinkViewCommand());
$app->run(); $app->run();

View File

@ -47,5 +47,6 @@ if ($match !== null) {
} }
} }
$content = new MapGuesser\Response\HtmlContent('error/404');
header('Content-Type: text/html; charset=UTF-8', true, 404); header('Content-Type: text/html; charset=UTF-8', true, 404);
require ROOT . '/views/error/404.php'; echo $content->render();

View File

@ -17,6 +17,11 @@ button::-moz-focus-inner, input::-moz-focus-inner {
border: 0; border: 0;
} }
/* to be compatible with browsers that don't know <main> */
main {
display: block;
}
::selection { ::selection {
background-color: #28a745; background-color: #28a745;
color: #ffffff; color: #ffffff;
@ -324,10 +329,11 @@ main {
padding: 6px 12px; padding: 6px 12px;
} }
div.full { main.full {
position: relative; position: relative;
width: 100%; width: 100%;
height: calc(100% - 40px); height: calc(100% - 40px);
padding: 0;
} }
footer { footer {

View File

@ -21,6 +21,9 @@ echo "Migrating DB..."
if [ -z "${DEV}" ] || [ "${DEV}" -eq "0" ]; then if [ -z "${DEV}" ] || [ "${DEV}" -eq "0" ]; then
echo "Minifying JS, CSS and SVG files..." echo "Minifying JS, CSS and SVG files..."
${ROOT_DIR}/scripts/minify.sh ${ROOT_DIR}/scripts/minify.sh
echo "Linking view files..."
(cd ${ROOT_DIR} && ./mapg view:link)
fi fi
touch ${ROOT_DIR}/installed touch ${ROOT_DIR}/installed

View File

@ -20,4 +20,7 @@ echo "Migrating DB..."
if [ -z "${DEV}" ] || [ "${DEV}" -eq "0" ]; then if [ -z "${DEV}" ] || [ "${DEV}" -eq "0" ]; then
echo "Minifying JS, CSS and SVG files..." echo "Minifying JS, CSS and SVG files..."
${ROOT_DIR}/scripts/minify.sh ${ROOT_DIR}/scripts/minify.sh
echo "Linking view files..."
(cd ${ROOT_DIR} && ./mapg view:link)
fi fi

View File

@ -0,0 +1,69 @@
<?php namespace MapGuesser\Cli;
use FilesystemIterator;
use MapGuesser\View\Linker;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class LinkViewCommand extends Command
{
public function configure()
{
$this->setName('view:link')
->setDescription('Linking of views.')
->addArgument('view', InputArgument::OPTIONAL, 'View file to be linked.');
}
public function execute(InputInterface $input, OutputInterface $output): int
{
$views = [];
$view = $input->getArgument('view');
if ($view !== null) {
$views[] = $view;
} else {
$folder = ROOT . '/views';
$folderLength = strlen($folder) + 1;
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($folder, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $file) {
if ($file->isDir() || $file->getExtension() !== 'php') {
continue;
}
$view = substr($file->getPath(), $folderLength) . '/' . $file->getBasename('.php');
if (strpos($view, 'templates') === 0) {
continue;
}
$views[] = $view;
}
}
try {
foreach ($views as $view) {
$generator = new Linker($view);
$generator->generate();
}
} catch (\Exception $e) {
$output->writeln('<error>Linking view(s) failed!</error>');
$output->writeln('');
$output->writeln((string) $e);
$output->writeln('');
return 1;
}
$output->writeln('<info>View(s) successfully linked!</info>');
return 0;
}
}

View File

@ -1,21 +1,28 @@
<?php namespace MapGuesser\Response; <?php namespace MapGuesser\Response;
use MapGuesser\View\Linker;
class HtmlContent extends ContentBase class HtmlContent extends ContentBase
{ {
private string $template; private string $view;
public function __construct(string $template, array &$data = []) public function __construct(string $view, array &$data = [])
{ {
$this->template = $template; $this->view = $view;
$this->data = &$data; $this->data = &$data;
} }
public function &render(): string public function &render(): string
{ {
if (!empty($_ENV['DEV'])) {
$generator = new Linker($this->view);
$generator->generate();
}
extract($this->data); extract($this->data);
ob_start(); ob_start();
require ROOT . '/views/' . $this->template . '.php'; require ROOT . '/cache/views/' . $this->view . '.php';
$content = ob_get_contents(); $content = ob_get_contents();
ob_end_clean(); ob_end_clean();

103
src/View/Linker.php Normal file
View File

@ -0,0 +1,103 @@
<?php namespace MapGuesser\View;
class Linker
{
private string $view;
public function __construct(string $view)
{
$this->view = $view;
}
public function generate(): void
{
$input = ROOT . '/views/' . $this->view . '.php';
$temporaryFiles = [];
$sections = [];
$extra = ['', ''];
do {
$parser = new Parser($input);
$fragment = $parser->parse();
$extends = $fragment->getExtends();
$sections = array_merge($sections, $fragment->getSections()); //TODO: detect if section defined multiple times
$extra[0] = $fragment->getExtra()[0] . $extra[0];
$extra[1] = $extra[1] . $fragment->getExtra()[1];
if ($extends === null) {
$this->writeFinal($extra, $input, ROOT . '/cache/views/' . $this->view . '.php');
break;
}
$tmpFile = tempnam(sys_get_temp_dir(), 'mapg-view-');
$temporaryFiles[] = $tmpFile;
$this->extendTemplate($sections, ROOT . '/views/' . $extends . '.php', $tmpFile);
$input = $tmpFile;
} while (true);
foreach ($temporaryFiles as $tmpFile) {
unlink($tmpFile);
}
}
private function extendTemplate(array $sections, string $file, string $output): void
{
$inputFileHandle = fopen($file, 'r');
if (!$inputFileHandle) {
throw new \Exception('Cannot open file ' . $file);
}
$outputFileHandle = fopen($output, 'w');
if (!$outputFileHandle) {
throw new \Exception('Cannot open file ' . $output . 'for writing.');
}
$lineNumber = 0;
while (($line = fgets($inputFileHandle)) !== false) {
++$lineNumber;
if (preg_match('/^\s*@yields\(\'([\w\/]+)\'\)\s*$/', $line, $matches)) {
if (isset($sections[$matches[1]])) {
fwrite($outputFileHandle, $sections[$matches[1]]);
}
} else {
fwrite($outputFileHandle, $line);
}
}
fclose($inputFileHandle);
fclose($outputFileHandle);
}
private function writeFinal(array $extra, string $file, string $output): void
{
$dirname = pathinfo($output, PATHINFO_DIRNAME);
if (!is_dir($dirname)) {
mkdir($dirname, 0755, true);
}
$inputFileHandle = fopen($file, 'r');
if (!$inputFileHandle) {
throw new \Exception('Cannot open file ' . $file);
}
$outputFileHandle = fopen($output, 'w');
if (!$outputFileHandle) {
throw new \Exception('Cannot open file ' . $output . 'for writing.');
}
fwrite($outputFileHandle, $extra[0]);
while (($line = fgets($inputFileHandle)) !== false) {
fwrite($outputFileHandle, $line);
}
fwrite($outputFileHandle, $extra[1]);
fclose($inputFileHandle);
fclose($outputFileHandle);
}
}

View File

@ -0,0 +1,32 @@
<?php namespace MapGuesser\View;
class ParsedFragment
{
private ?string $extends;
private array $sections;
private array $extra;
public function __construct(?string $extends, array $sections, array $extra)
{
$this->extends = $extends;
$this->sections = $sections;
$this->extra = $extra;
}
public function getExtends(): ?string
{
return $this->extends;
}
public function getSections(): array
{
return $this->sections;
}
public function getExtra(): array
{
return $this->extra;
}
}

128
src/View/Parser.php Normal file
View File

@ -0,0 +1,128 @@
<?php namespace MapGuesser\View;
class Parser
{
private string $file;
public function __construct(string $file)
{
$this->file = $file;
}
public function parse(): ParsedFragment
{
$sectionOpen = null;
$extraOpen = false;
$extends = null;
$sections = [];
$extra = ['', ''];
$fileHandle = fopen($this->file, 'r');
if (!$fileHandle) {
throw new \Exception('Cannot open file ' . $this->file);
}
$lineNumber = 0;
while (($line = fgets($fileHandle)) !== false) {
++$lineNumber;
if (($extendsMatched = $this->matchExtends($line)) !== null) {
if ($extends !== null) {
throw new \Exception('Error in file ' . $this->file . ' in line ' . $lineNumber . ' - There is already an \'@extends\' declared.');
}
$extends = $extendsMatched;
continue;
}
if (($sectionMatched = $this->matchSection($line)) !== null) {
if ($extends === null) {
throw new \Exception('Error in file ' . $this->file . ' in line ' . $lineNumber . ' - \'@section\' has no meaning if view extends nothing.');
}
if ($sectionOpen !== null) {
throw new \Exception('Parse error in file ' . $this->file . ' in line ' . $lineNumber . ' - A \'@section\' is already open (no \'@endsection\' found).');
}
$sectionOpen = $sectionMatched;
$sections[$sectionOpen] = '';
continue;
}
if ($this->matchEndSection($line)) {
if ($sectionOpen === null) {
throw new \Exception('Parse error in file ' . $this->file . ' in line ' . $lineNumber . ' - Cannot end section until no \'@section\' is open.');
}
$sectionOpen = null;
}
if ($this->matchExtra($line)) {
if ($extraOpen) {
throw new \Exception('Parse error in file ' . $this->file . ' in line ' . $lineNumber . ' - An \'@extra\' is already open (no \'@endextra\' found).');
}
$extraOpen = true;
continue;
}
if ($this->matchEndExtra($line)) {
if (!$extraOpen) {
throw new \Exception('Parse error in file ' . $this->file . ' in line ' . $lineNumber . ' - Cannot end extra until no \'@extra\' is open.');
}
$extraOpen = false;
}
if ($sectionOpen !== null) {
$sections[$sectionOpen] .= $line;
}
if ($extraOpen) {
$offset = $extends === null ? 0 : 1;
$extra[$offset] .= $line;
}
}
fclose($fileHandle);
return new ParsedFragment($extends, $sections, $extra);
}
private function matchExtends(string $line): ?string
{
if (preg_match('/^\s*@extends\(\'([\w\/]+)\'\)\s*$/', $line, $matches)) {
return $matches[1];
}
return null;
}
private function matchSection(string $line): ?string
{
if (preg_match('/^\s*@section\(\'(\w+)\'\)\s*$/', $line, $matches)) {
return $matches[1];
}
return null;
}
private function matchEndSection(string $line): bool
{
return preg_match('/^\s*@endsection(?:\(\))?\s*$/', $line);
}
private function matchExtra(string $line): bool
{
return preg_match('/^\s*@extra(?:\(\))?\s*$/', $line);
}
private function matchEndExtra(string $line): bool
{
return preg_match('/^\s*@endextra(?:\(\))?\s*$/', $line);
}
}

View File

@ -1,5 +1,6 @@
<?php require ROOT . '/views/templates/main_header.php'; ?> @extends('templates/layout_normal')
<?php require ROOT . '/views/templates/header.php'; ?>
@section('main')
<h2>Account</h2> <h2>Account</h2>
<div class="box"> <div class="box">
<form id="accountForm" action="/account" method="post" data-observe-inputs="password_new,password_new_confirm"> <form id="accountForm" action="/account" method="post" data-observe-inputs="password_new,password_new_confirm">
@ -19,5 +20,4 @@
</div> </div>
</form> </form>
</div> </div>
<?php require ROOT . '/views/templates/footer.php'; ?> @endsection
<?php require ROOT . '/views/templates/main_footer.php'; ?>

View File

@ -1,5 +1,6 @@
<?php require ROOT . '/views/templates/main_header.php'; ?> @extends('templates/layout_normal')
<?php require ROOT . '/views/templates/header.php'; ?>
@section('main')
<h2>Delete account</h2> <h2>Delete account</h2>
<div class="box"> <div class="box">
<form id="deleteAccountForm" action="/account/delete" method="post" data-redirect-on-success="/"> <form id="deleteAccountForm" action="/account/delete" method="post" data-redirect-on-success="/">
@ -11,5 +12,4 @@
</div> </div>
</form> </form>
</div> </div>
<?php require ROOT . '/views/templates/footer.php'; ?> @endsection
<?php require ROOT . '/views/templates/main_footer.php'; ?>

View File

@ -1,3 +1,4 @@
@extra
<?php <?php
$cssFiles = [ $cssFiles = [
'node_modules/leaflet/dist/leaflet.css', 'node_modules/leaflet/dist/leaflet.css',
@ -12,16 +13,12 @@ $jsFiles = [
'js/map_editor.js', 'js/map_editor.js',
]; ];
?> ?>
<?php require ROOT . '/views/templates/main_header.php'; ?> @endextra
<header class="small">
<h1> @extends('templates/layout_full')
<a href="/" title="<?= $_ENV['APP_NAME'] ?>">
<img class="inline" width="1em" height="1em" src="<?= $_ENV['STATIC_ROOT'] ?>/img/icon.svg?rev=<?= REVISION ?>"><!-- @section('subheader')
--><span><?= $_ENV['APP_NAME'] ?></span> <span><a href="javascript:;" id="mapName" title="Edit map data"><?= $mapName ?></a></span><!--
</a>
</h1>
<p class="header">
<span><a href="javascript:;" id="mapName" title="Edit map data"><?= $mapName ?></a></span><!--
--><span><!-- --><span><!--
<?php /* Copyright (c) 2019 The Bootstrap Authors. License can be found in 'USED_SOFTWARE' in section 'Bootstrap Icons'. */ ?> <?php /* Copyright (c) 2019 The Bootstrap Authors. License can be found in 'USED_SOFTWARE' in section 'Bootstrap Icons'. */ ?>
--><svg class="inline" width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg"> --><svg class="inline" width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
@ -46,8 +43,9 @@ $jsFiles = [
</svg><!-- </svg><!--
--><span id="deleted" class="bold">0</span><!-- --><span id="deleted" class="bold">0</span><!--
--></span> --></span>
</p> @endsection
</header>
@section('pagemodal')
<div id="metadata" class="modal"> <div id="metadata" class="modal">
<h2>Edit map data</h2> <h2>Edit map data</h2>
<form id="metadataForm" class="marginTop" data-no-submit="true"> <form id="metadataForm" class="marginTop" data-no-submit="true">
@ -59,7 +57,9 @@ $jsFiles = [
</div> </div>
</form> </form>
</div> </div>
<div class="full"> @endsection
@section('main')
<div id="map"></div> <div id="map"></div>
<div id="panorama"></div> <div id="panorama"></div>
<div id="noPano"> <div id="noPano">
@ -73,7 +73,9 @@ $jsFiles = [
<button id="closeButton" class="gray fullWidth marginTop">Close</button> <button id="closeButton" class="gray fullWidth marginTop">Close</button>
<button id="deleteButton" class="red fullWidth marginTop">Delete</button> <button id="deleteButton" class="red fullWidth marginTop">Delete</button>
</div> </div>
</div> @endsection
@section('pagescript')
<script> <script>
var tileUrl = '<?= $_ENV['LEAFLET_TILESERVER_URL'] ?>'; var tileUrl = '<?= $_ENV['LEAFLET_TILESERVER_URL'] ?>';
var tileAttribution = '<?= $_ENV['LEAFLET_TILESERVER_ATTRIBUTION'] ?>'; var tileAttribution = '<?= $_ENV['LEAFLET_TILESERVER_ATTRIBUTION'] ?>';
@ -81,4 +83,4 @@ $jsFiles = [
var mapBounds = <?= json_encode($bounds) ?>; var mapBounds = <?= json_encode($bounds) ?>;
var places = <?= json_encode($places, JSON_FORCE_OBJECT) ?>; var places = <?= json_encode($places, JSON_FORCE_OBJECT) ?>;
</script> </script>
<?php require ROOT . '/views/templates/main_footer.php'; ?> @endsection

View File

@ -1,6 +1,6 @@
<?php require ROOT . '/views/templates/main_header.php'; ?> @extends('templates/layout_normal')
<?php require ROOT . '/views/templates/header.php'; ?>
@section('main')
<h2>404 | Page not found</h2> <h2>404 | Page not found</h2>
<p>The requested URL was not found on this server. <a href="/" title="<?= $_ENV['APP_NAME'] ?>">Back to start.</a></p> <p>The requested URL was not found on this server. <a href="/" title="<?= $_ENV['APP_NAME'] ?>">Back to start.</a></p>
<?php require ROOT . '/views/templates/footer.php'; ?> @endsection
<?php require ROOT . '/views/templates/main_footer.php'; ?>

View File

@ -1,3 +1,4 @@
@extra
<?php <?php
$cssFiles = [ $cssFiles = [
'css/game.css' 'css/game.css'
@ -7,21 +8,17 @@ $jsFiles = [
'js/game.js', 'js/game.js',
]; ];
?> ?>
<?php require ROOT . '/views/templates/main_header.php'; ?> @endextra
<header class="small">
<h1> @extends('templates/layout_full')
<a href="/" title="<?= $_ENV['APP_NAME'] ?>">
<img class="inline" width="1em" height="1em" src="<?= $_ENV['STATIC_ROOT'] ?>/img/icon.svg?rev=<?= REVISION ?>"><!-- @section('subheader')
--><span><?= $_ENV['APP_NAME'] ?></span>
</a>
</h1>
<p class="header">
<span id="mapName" class="bold"><?= $mapName ?></span><!-- <span id="mapName" class="bold"><?= $mapName ?></span><!--
--><span>Round <span id="currentRound" class="bold"></span></span><!-- --><span>Round <span id="currentRound" class="bold"></span></span><!--
--><span>Score <span id="currentScoreSum" class="bold"></span></span> --><span>Score <span id="currentScoreSum" class="bold"></span></span>
</p> @endsection
</header>
<div class="full"> @section('main')
<div id="panoCover"></div> <div id="panoCover"></div>
<div id="panorama"></div> <div id="panorama"></div>
<div id="showGuessButtonContainer"> <div id="showGuessButtonContainer">
@ -56,9 +53,11 @@ $jsFiles = [
<button id="startNewGameButton" class="fullWidth">Play this map again</button> <button id="startNewGameButton" class="fullWidth">Play this map again</button>
</div> </div>
</div> </div>
</div> @endsection
@section('pagescript')
<script> <script>
var mapId = <?= $mapId ?>; var mapId = <?= $mapId ?>;
var mapBounds = <?= json_encode($bounds) ?>; var mapBounds = <?= json_encode($bounds) ?>;
</script> </script>
<?php require ROOT . '/views/templates/main_footer.php'; ?> @endsection

View File

@ -1,8 +1,8 @@
<?php require ROOT . '/views/templates/main_header.php'; ?> @extends('templates/layout_normal')
<?php require ROOT . '/views/templates/header.php'; ?>
@section('main')
<h2>Account activation</h2> <h2>Account activation</h2>
<div class="box"> <div class="box">
<p class="error justify">Activation failed. Please check the link you entered or retry <a href="/signup" title="Sign up">sign up</a>!</p> <p class="error justify">Activation failed. Please check the link you entered or retry <a href="/signup" title="Sign up">sign up</a>!</p>
</div> </div>
<?php require ROOT . '/views/templates/footer.php'; ?> @endsection
<?php require ROOT . '/views/templates/main_footer.php'; ?>

View File

@ -1,5 +1,6 @@
<?php require ROOT . '/views/templates/main_header.php'; ?> @extends('templates/layout_normal')
<?php require ROOT . '/views/templates/header.php'; ?>
@section('main')
<h2>Account cancellation</h2> <h2>Account cancellation</h2>
<div class="box"> <div class="box">
<?php if ($success) : ?> <?php if ($success) : ?>
@ -8,5 +9,4 @@
<p class="error justify">Cancellation failed. Please check the link you entered! Maybe the account was already deleted, in this case no further action is required.</p> <p class="error justify">Cancellation failed. Please check the link you entered! Maybe the account was already deleted, in this case no further action is required.</p>
<?php endif; ?> <?php endif; ?>
</div> </div>
<?php require ROOT . '/views/templates/footer.php'; ?> @endsection
<?php require ROOT . '/views/templates/main_footer.php'; ?>

View File

@ -1,8 +1,8 @@
<?php require ROOT . '/views/templates/main_header.php'; ?> @extends('templates/layout_normal')
<?php require ROOT . '/views/templates/header.php'; ?>
@section('main')
<h2>Login up with Google</h2> <h2>Login up with Google</h2>
<div class="box"> <div class="box">
<p class="error justify">Authenticating with Google failed. Please <a href="/login/google" title="Login with Google">retry</a>!</p> <p class="error justify">Authenticating with Google failed. Please <a href="/login/google" title="Login with Google">retry</a>!</p>
</div> </div>
<?php require ROOT . '/views/templates/footer.php'; ?> @endsection
<?php require ROOT . '/views/templates/main_footer.php'; ?>

View File

@ -1,10 +1,14 @@
@extra
<?php <?php
$jsFiles = [ $jsFiles = [
'js/login/google_signup.js', 'js/login/google_signup.js',
]; ];
?> ?>
<?php require ROOT . '/views/templates/main_header.php'; ?> @endextra
<?php require ROOT . '/views/templates/header.php'; ?>
@extends('templates/layout_normal')
@section('main')
<h2>Sign up</h2> <h2>Sign up</h2>
<div class="box"> <div class="box">
<form id="googleSignupForm" action="/signup/google" method="post" data-redirect-on-success="/"> <form id="googleSignupForm" action="/signup/google" method="post" data-redirect-on-success="/">
@ -26,5 +30,4 @@ $jsFiles = [
</div> </div>
</form> </form>
</div> </div>
<?php require ROOT . '/views/templates/footer.php'; ?> @endsection
<?php require ROOT . '/views/templates/main_footer.php'; ?>

View File

@ -1,5 +1,6 @@
<?php require ROOT . '/views/templates/main_header.php'; ?> @extends('templates/layout_normal')
<?php require ROOT . '/views/templates/header.php'; ?>
@section('main')
<h2>Login</h2> <h2>Login</h2>
<div class="box"> <div class="box">
<form id="loginForm" action="/login" method="post" data-redirect-on-success="/"> <form id="loginForm" action="/login" method="post" data-redirect-on-success="/">
@ -15,5 +16,4 @@
</div> </div>
</form> </form>
</div> </div>
<?php require ROOT . '/views/templates/footer.php'; ?> @endsection
<?php require ROOT . '/views/templates/main_footer.php'; ?>

View File

@ -1,10 +1,14 @@
@extra
<?php <?php
$jsFiles = [ $jsFiles = [
'js/login/signup.js', 'js/login/signup.js',
]; ];
?> ?>
<?php require ROOT . '/views/templates/main_header.php'; ?> @endextra
<?php require ROOT . '/views/templates/header.php'; ?>
@extends('templates/layout_normal')
@section('main')
<h2>Sign up</h2> <h2>Sign up</h2>
<div class="box"> <div class="box">
<form id="signupForm" action="/signup" method="post" data-redirect-on-success="/signup/success"> <form id="signupForm" action="/signup" method="post" data-redirect-on-success="/signup/success">
@ -30,5 +34,4 @@ $jsFiles = [
</div> </div>
</form> </form>
</div> </div>
<?php require ROOT . '/views/templates/footer.php'; ?> @endsection
<?php require ROOT . '/views/templates/main_footer.php'; ?>

View File

@ -1,8 +1,8 @@
<?php require ROOT . '/views/templates/main_header.php'; ?> @extends('templates/layout_normal')
<?php require ROOT . '/views/templates/header.php'; ?>
@section('main')
<h2>Sign up</h2> <h2>Sign up</h2>
<div class="box"> <div class="box">
<p class="justify">Sign up was successful. Please check your email and click on the activation link to activate your account!</p> <p class="justify">Sign up was successful. Please check your email and click on the activation link to activate your account!</p>
</div> </div>
<?php require ROOT . '/views/templates/footer.php'; ?> @endsection
<?php require ROOT . '/views/templates/main_footer.php'; ?>

View File

@ -1,3 +1,4 @@
@extra
<?php <?php
$cssFiles = [ $cssFiles = [
'css/maps.css' 'css/maps.css'
@ -9,8 +10,11 @@ if ($isAdmin) {
$jsFiles[] = 'js/maps_admin.js'; $jsFiles[] = 'js/maps_admin.js';
} }
?> ?>
<?php require ROOT . '/views/templates/main_header.php'; ?> @endextra
<?php require ROOT . '/views/templates/header.php'; ?>
@extends('templates/layout_normal')
@section('main')
<div id="mapContainer"> <div id="mapContainer">
<?php foreach ($maps as $map): ?> <?php foreach ($maps as $map): ?>
<div class="mapItem"> <div class="mapItem">
@ -66,5 +70,4 @@ if ($isAdmin) {
<?php endfor; ?> <?php endfor; ?>
<?php endif; ?> <?php endif; ?>
</div> </div>
<?php require ROOT . '/views/templates/footer.php'; ?> @endsection
<?php require ROOT . '/views/templates/main_footer.php'; ?>

View File

@ -1,5 +0,0 @@
</main>
<footer>
<p><span class="bold"><?= $_ENV['APP_NAME'] ?></span> <?= str_replace('Release_', '', VERSION) ?></p><!--
--><p>&copy; Pőcze Bence <?= (new DateTime(REVISION_DATE))->format('Y') ?></p>
</footer>

View File

@ -0,0 +1,18 @@
@extends('templates/mapguesser')
@section('content')
<header class="small">
<h1>
<a href="/" title="<?= $_ENV['APP_NAME'] ?>">
<img class="inline" width="1em" height="1em" src="<?= $_ENV['STATIC_ROOT'] ?>/img/icon.svg?rev=<?= REVISION ?>"><!--
--><span><?= $_ENV['APP_NAME'] ?></span>
</a>
</h1>
<p class="header">
@yields('subheader')
</p>
</header>
<main class="full">
@yields('main')
</main>
@endsection

View File

@ -1,3 +1,5 @@
@extends('templates/mapguesser')
@section('content')
<header> <header>
<h1> <h1>
<a href="/" title="<?= $_ENV['APP_NAME'] ?>"> <a href="/" title="<?= $_ENV['APP_NAME'] ?>">
@ -22,3 +24,10 @@
</p> </p>
</header> </header>
<main> <main>
@yields('main')
</main>
<footer>
<p><span class="bold"><?= $_ENV['APP_NAME'] ?></span> <?= str_replace('Release_', '', VERSION) ?></p><!--
--><p>&copy; Pőcze Bence <?= (new DateTime(REVISION_DATE))->format('Y') ?></p>
</footer>
@endsection

View File

@ -1,50 +0,0 @@
<script>
const STATIC_ROOT = '<?= $_ENV['STATIC_ROOT'] ?>';
const REVISION = '<?= REVISION ?>';
var ANTI_CSRF_TOKEN = '<?= \Container::$request->session()->get('anti_csrf_token') ?>';
const GOOGLE_MAPS_JS_API_KEY = '<?= $_ENV['GOOGLE_MAPS_JS_API_KEY'] ?>';
<?php if (!empty($_ENV['GOOGLE_ANALITICS_ID'])): ?>
const GOOGLE_ANALITICS_ID = '<?= $_ENV['GOOGLE_ANALITICS_ID'] ?>';
<?php endif; ?>
</script>
<script src="<?= $_ENV['STATIC_ROOT'] ?>/js/mapguesser.js?rev=<?= REVISION ?>"></script>
<?php if (isset($jsFiles)) : ?>
<?php foreach ($jsFiles as $jsFile) : ?>
<?php
if (!preg_match('/^http(s)?/', $jsFile)) {
$jsFile = $_ENV['STATIC_ROOT'] . '/' . $jsFile . '?rev=' . REVISION;
}
?>
<script src="<?= $jsFile ?>"></script>
<?php endforeach; ?>
<?php endif; ?>
<?php if (!isset($_COOKIE['COOKIES_CONSENT'])): ?>
<script>
(function () {
// we don't want user to agree cookies when clicking on the notice itself
document.getElementById('cookiesNotice').onclick = function (e) {
e.stopPropagation();
};
document.getElementById('agreeCookiesButton').onclick = function () {
MapGuesser.agreeCookies();
document.getElementById('cookiesNotice').style.display = 'none';
};
window.onclick = function () {
MapGuesser.agreeCookies();
};
})();
</script>
<?php else: ?>
<?php if (!empty($_ENV['GOOGLE_ANALITICS_ID'])): ?>
<script>
(function () {
MapGuesser.initGoogleAnalitics();
})();
</script>
<?php endif; ?>
<?php endif; ?>
</body>
</html>

View File

@ -39,3 +39,56 @@
<p id="modalText" class="justify marginTop"></p> <p id="modalText" class="justify marginTop"></p>
<div id="modalButtons" class="right"></div> <div id="modalButtons" class="right"></div>
</div> </div>
@yields('pagemodal')
@yields('content')
<script>
const STATIC_ROOT = '<?= $_ENV['STATIC_ROOT'] ?>';
const REVISION = '<?= REVISION ?>';
var ANTI_CSRF_TOKEN = '<?= \Container::$request->session()->get('anti_csrf_token') ?>';
const GOOGLE_MAPS_JS_API_KEY = '<?= $_ENV['GOOGLE_MAPS_JS_API_KEY'] ?>';
<?php if (!empty($_ENV['GOOGLE_ANALITICS_ID'])): ?>
const GOOGLE_ANALITICS_ID = '<?= $_ENV['GOOGLE_ANALITICS_ID'] ?>';
<?php endif; ?>
</script>
@yields('pagescript')
<script src="<?= $_ENV['STATIC_ROOT'] ?>/js/mapguesser.js?rev=<?= REVISION ?>"></script>
<?php if (isset($jsFiles)) : ?>
<?php foreach ($jsFiles as $jsFile) : ?>
<?php
if (!preg_match('/^http(s)?/', $jsFile)) {
$jsFile = $_ENV['STATIC_ROOT'] . '/' . $jsFile . '?rev=' . REVISION;
}
?>
<script src="<?= $jsFile ?>"></script>
<?php endforeach; ?>
<?php endif; ?>
<?php if (!isset($_COOKIE['COOKIES_CONSENT'])): ?>
<script>
(function () {
// we don't want user to agree cookies when clicking on the notice itself
document.getElementById('cookiesNotice').onclick = function (e) {
e.stopPropagation();
};
document.getElementById('agreeCookiesButton').onclick = function () {
MapGuesser.agreeCookies();
document.getElementById('cookiesNotice').style.display = 'none';
};
window.onclick = function () {
MapGuesser.agreeCookies();
};
})();
</script>
<?php else: ?>
<?php if (!empty($_ENV['GOOGLE_ANALITICS_ID'])): ?>
<script>
(function () {
MapGuesser.initGoogleAnalitics();
})();
</script>
<?php endif; ?>
<?php endif; ?>
</body>
</html>