Init
This commit is contained in:
24
app/Presenters/BasePresenter.php
Executable file
24
app/Presenters/BasePresenter.php
Executable file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Presenters;
|
||||
|
||||
use Nette;
|
||||
use Vite;
|
||||
|
||||
|
||||
/**
|
||||
* Base presenter for all application presenters.
|
||||
*/
|
||||
abstract class BasePresenter extends Nette\Application\UI\Presenter
|
||||
{
|
||||
public function __construct(
|
||||
private Vite $vite,
|
||||
) {}
|
||||
|
||||
public function beforeRender(): void
|
||||
{
|
||||
$this->template->vite = $this->vite;
|
||||
}
|
||||
}
|
||||
27
app/Presenters/Error4xxPresenter.php
Executable file
27
app/Presenters/Error4xxPresenter.php
Executable file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Presenters;
|
||||
|
||||
use Nette;
|
||||
|
||||
|
||||
final class Error4xxPresenter extends Nette\Application\UI\Presenter
|
||||
{
|
||||
public function startup(): void
|
||||
{
|
||||
parent::startup();
|
||||
if (!$this->getRequest()->isMethod(Nette\Application\Request::FORWARD)) {
|
||||
$this->error();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function renderDefault(Nette\Application\BadRequestException $exception): void
|
||||
{
|
||||
// load template 403.latte or 404.latte or ... 4xx.latte
|
||||
$file = __DIR__ . "/templates/Error/{$exception->getCode()}.latte";
|
||||
$this->template->setFile(is_file($file) ? $file : __DIR__ . '/templates/Error/4xx.latte');
|
||||
}
|
||||
}
|
||||
43
app/Presenters/ErrorPresenter.php
Executable file
43
app/Presenters/ErrorPresenter.php
Executable file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Presenters;
|
||||
|
||||
use Nette;
|
||||
use Nette\Application\Responses;
|
||||
use Nette\Http;
|
||||
use Tracy\ILogger;
|
||||
|
||||
|
||||
final class ErrorPresenter implements Nette\Application\IPresenter
|
||||
{
|
||||
use Nette\SmartObject;
|
||||
|
||||
/** @var ILogger */
|
||||
private $logger;
|
||||
|
||||
|
||||
public function __construct(ILogger $logger)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
|
||||
public function run(Nette\Application\Request $request): Nette\Application\Response
|
||||
{
|
||||
$exception = $request->getParameter('exception');
|
||||
|
||||
if ($exception instanceof Nette\Application\BadRequestException) {
|
||||
[$module, , $sep] = Nette\Application\Helpers::splitName($request->getPresenterName());
|
||||
return new Responses\ForwardResponse($request->setPresenterName($module . $sep . 'Error4xx'));
|
||||
}
|
||||
|
||||
$this->logger->log($exception, ILogger::EXCEPTION);
|
||||
return new Responses\CallbackResponse(function (Http\IRequest $httpRequest, Http\IResponse $httpResponse): void {
|
||||
if (preg_match('#^text/html(?:;|$)#', (string) $httpResponse->getHeader('Content-Type'))) {
|
||||
require __DIR__ . '/templates/Error/500.phtml';
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
12
app/Presenters/HomepagePresenter.php
Executable file
12
app/Presenters/HomepagePresenter.php
Executable file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Presenters;
|
||||
|
||||
use Nette;
|
||||
|
||||
|
||||
final class HomepagePresenter extends BasePresenter
|
||||
{
|
||||
}
|
||||
29
app/Presenters/templates/@layout.latte
Executable file
29
app/Presenters/templates/@layout.latte
Executable file
@@ -0,0 +1,29 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
|
||||
<title>{ifset title}{include title|stripHtml} | {/ifset}Nette Web</title>
|
||||
|
||||
{if $vite->isEnabled()}
|
||||
<script type="module" src="{='@vite/client'|asset}"></script>
|
||||
{else}
|
||||
{foreach $vite->getCssAssets('src/scripts/main.js') as $path}
|
||||
<link rel="stylesheet" href="{$path}">
|
||||
{/foreach}
|
||||
{/if}
|
||||
|
||||
<script src="{='src/scripts/main.js'|asset}" type="module"></script>
|
||||
</head>
|
||||
|
||||
<body data-controller="body" class="bg-blue-100">
|
||||
<div n:foreach="$flashes as $flash" n:class="flash, $flash->type">{$flash->message}</div>
|
||||
|
||||
|
||||
{include content}
|
||||
|
||||
{block scripts}
|
||||
{/block}
|
||||
</body>
|
||||
</html>
|
||||
7
app/Presenters/templates/Error/403.latte
Executable file
7
app/Presenters/templates/Error/403.latte
Executable file
@@ -0,0 +1,7 @@
|
||||
{block content}
|
||||
<h1 n:block=title>Access Denied</h1>
|
||||
|
||||
<p>You do not have permission to view this page. Please try contact the web
|
||||
site administrator if you believe you should be able to view this page.</p>
|
||||
|
||||
<p><small>error 403</small></p>
|
||||
8
app/Presenters/templates/Error/404.latte
Executable file
8
app/Presenters/templates/Error/404.latte
Executable file
@@ -0,0 +1,8 @@
|
||||
{block content}
|
||||
<h1 n:block=title>Page Not Found</h1>
|
||||
|
||||
<p>The page you requested could not be found. It is possible that the address is
|
||||
incorrect, or that the page no longer exists. Please use a search engine to find
|
||||
what you are looking for.</p>
|
||||
|
||||
<p><small>error 404</small></p>
|
||||
6
app/Presenters/templates/Error/405.latte
Executable file
6
app/Presenters/templates/Error/405.latte
Executable file
@@ -0,0 +1,6 @@
|
||||
{block content}
|
||||
<h1 n:block=title>Method Not Allowed</h1>
|
||||
|
||||
<p>The requested method is not allowed for the URL.</p>
|
||||
|
||||
<p><small>error 405</small></p>
|
||||
6
app/Presenters/templates/Error/410.latte
Executable file
6
app/Presenters/templates/Error/410.latte
Executable file
@@ -0,0 +1,6 @@
|
||||
{block content}
|
||||
<h1 n:block=title>Page Not Found</h1>
|
||||
|
||||
<p>The page you requested has been taken off the site. We apologize for the inconvenience.</p>
|
||||
|
||||
<p><small>error 410</small></p>
|
||||
4
app/Presenters/templates/Error/4xx.latte
Executable file
4
app/Presenters/templates/Error/4xx.latte
Executable file
@@ -0,0 +1,4 @@
|
||||
{block content}
|
||||
<h1 n:block=title>Oops...</h1>
|
||||
|
||||
<p>Your browser sent a request that this server could not understand or process.</p>
|
||||
27
app/Presenters/templates/Error/500.phtml
Executable file
27
app/Presenters/templates/Error/500.phtml
Executable file
@@ -0,0 +1,27 @@
|
||||
<!DOCTYPE html><!-- "' --></textarea></script></style></pre></xmp></a></audio></button></canvas></datalist></details></dialog></iframe></listing></meter></noembed></noframes></noscript></optgroup></option></progress></rp></select></table></template></title></video>
|
||||
<meta charset="utf-8">
|
||||
<meta name="robots" content="noindex">
|
||||
<title>Server Error</title>
|
||||
|
||||
<style>
|
||||
#nette-error { all: initial; position: absolute; top: 0; left: 0; right: 0; height: 70vh; min-height: 400px; display: flex; align-items: center; justify-content: center; z-index: 1000 }
|
||||
#nette-error div { all: initial; max-width: 550px; background: white; color: #333; display: block }
|
||||
#nette-error h1 { all: initial; font: bold 50px/1.1 sans-serif; display: block; margin: 40px }
|
||||
#nette-error p { all: initial; font: 20px/1.4 sans-serif; margin: 40px; display: block }
|
||||
#nette-error small { color: gray }
|
||||
</style>
|
||||
|
||||
<div id=nette-error>
|
||||
<div>
|
||||
<h1>Server Error</h1>
|
||||
|
||||
<p>We're sorry! The server encountered an internal error and
|
||||
was unable to complete your request. Please try again later.</p>
|
||||
|
||||
<p><small>error 500</small></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.body.insertBefore(document.getElementById('nette-error'), document.body.firstChild);
|
||||
</script>
|
||||
24
app/Presenters/templates/Error/503.phtml
Executable file
24
app/Presenters/templates/Error/503.phtml
Executable file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
header('HTTP/1.1 503 Service Unavailable');
|
||||
header('Retry-After: 300'); // 5 minutes in seconds
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<meta name="robots" content="noindex">
|
||||
<meta name="generator" content="Nette Framework">
|
||||
|
||||
<style>
|
||||
body { color: #333; background: white; width: 500px; margin: 100px auto }
|
||||
h1 { font: bold 47px/1.5 sans-serif; margin: .6em 0 }
|
||||
p { font: 21px/1.5 Georgia,serif; margin: 1.5em 0 }
|
||||
</style>
|
||||
|
||||
<title>Site is temporarily down for maintenance</title>
|
||||
|
||||
<h1>We're Sorry</h1>
|
||||
|
||||
<p>The site is temporarily down for maintenance. Please try again in a few minutes.</p>
|
||||
5
app/Presenters/templates/Homepage/default.latte
Executable file
5
app/Presenters/templates/Homepage/default.latte
Executable file
@@ -0,0 +1,5 @@
|
||||
{* This is the welcome page, you can delete it *}
|
||||
|
||||
{block content}
|
||||
<div id="app">
|
||||
</div>
|
||||
Reference in New Issue
Block a user