From 6bdfb1250d1f0f1a06b6395847c0e70a29c7ba00 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 29 Nov 2018 17:53:10 +0100 Subject: [PATCH] added copy of Web Project 3.0 https://github.com/nette/web-project --- .gitignore | 1 + .htaccess | 1 + app/Booting.php | 31 +++++++++ app/config/common.neon | 15 +++++ app/presenters/Error4xxPresenter.php | 27 ++++++++ app/presenters/ErrorPresenter.php | 43 ++++++++++++ app/presenters/HomepagePresenter.php | 12 ++++ app/presenters/templates/@layout.latte | 19 ++++++ app/presenters/templates/Error/403.latte | 7 ++ app/presenters/templates/Error/404.latte | 8 +++ app/presenters/templates/Error/405.latte | 6 ++ app/presenters/templates/Error/410.latte | 6 ++ app/presenters/templates/Error/4xx.latte | 4 ++ app/presenters/templates/Error/500.phtml | 27 ++++++++ app/presenters/templates/Error/503.phtml | 24 +++++++ .../templates/Homepage/default.latte | 38 +++++++++++ app/router/RouterFactory.php | 21 ++++++ composer.json | 36 +++++++++++ log/.gitignore | 2 + readme.md | 61 ++++++++++++++++++ temp/.gitignore | 2 + www/.htaccess | 32 +++++++++ www/favicon.ico | Bin 0 -> 2550 bytes www/index.php | 10 +++ www/robots.txt | 0 25 files changed, 433 insertions(+) create mode 100644 .htaccess create mode 100644 app/Booting.php create mode 100644 app/config/common.neon create mode 100644 app/presenters/Error4xxPresenter.php create mode 100644 app/presenters/ErrorPresenter.php create mode 100644 app/presenters/HomepagePresenter.php create mode 100644 app/presenters/templates/@layout.latte create mode 100644 app/presenters/templates/Error/403.latte create mode 100644 app/presenters/templates/Error/404.latte create mode 100644 app/presenters/templates/Error/405.latte create mode 100644 app/presenters/templates/Error/410.latte create mode 100644 app/presenters/templates/Error/4xx.latte create mode 100644 app/presenters/templates/Error/500.phtml create mode 100644 app/presenters/templates/Error/503.phtml create mode 100644 app/presenters/templates/Homepage/default.latte create mode 100644 app/router/RouterFactory.php create mode 100644 composer.json create mode 100644 log/.gitignore create mode 100644 readme.md create mode 100644 temp/.gitignore create mode 100644 www/.htaccess create mode 100644 www/favicon.ico create mode 100644 www/index.php create mode 100644 www/robots.txt diff --git a/.gitignore b/.gitignore index e69de29..47cd1d9 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +app/config/local.neon diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..b66e808 --- /dev/null +++ b/.htaccess @@ -0,0 +1 @@ +Require all denied diff --git a/app/Booting.php b/app/Booting.php new file mode 100644 index 0000000..2ce5db2 --- /dev/null +++ b/app/Booting.php @@ -0,0 +1,31 @@ +setDebugMode('23.75.345.200'); // enable for your remote IP + $configurator->enableTracy(__DIR__ . '/../log'); + + $configurator->setTimeZone('Europe/Prague'); + $configurator->setTempDirectory(__DIR__ . '/../temp'); + + $configurator->createRobotLoader() + ->addDirectory(__DIR__) + ->register(); + + $configurator->addConfig(__DIR__ . '/config/common.neon'); + $configurator->addConfig(__DIR__ . '/config/local.neon'); + + return $configurator; + } +} diff --git a/app/config/common.neon b/app/config/common.neon new file mode 100644 index 0000000..02adb7f --- /dev/null +++ b/app/config/common.neon @@ -0,0 +1,15 @@ +parameters: + + +application: + errorPresenter: Error + mapping: + *: App\*Module\Presenters\*Presenter + + +session: + expiration: 14 days + + +services: + router: App\Router\RouterFactory::createRouter diff --git a/app/presenters/Error4xxPresenter.php b/app/presenters/Error4xxPresenter.php new file mode 100644 index 0000000..ee2e1b3 --- /dev/null +++ b/app/presenters/Error4xxPresenter.php @@ -0,0 +1,27 @@ +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'); + } +} diff --git a/app/presenters/ErrorPresenter.php b/app/presenters/ErrorPresenter.php new file mode 100644 index 0000000..32b766b --- /dev/null +++ b/app/presenters/ErrorPresenter.php @@ -0,0 +1,43 @@ +logger = $logger; + } + + + public function run(Nette\Application\Request $request): Nette\Application\IResponse + { + $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'; + } + }); + } +} diff --git a/app/presenters/HomepagePresenter.php b/app/presenters/HomepagePresenter.php new file mode 100644 index 0000000..ca7d196 --- /dev/null +++ b/app/presenters/HomepagePresenter.php @@ -0,0 +1,12 @@ + + + + + + + {ifset title}{include title|stripHtml} | {/ifset}Nette Web + + + +
{$flash->message}
+ + {include content} + + {block scripts} + + {/block} + + diff --git a/app/presenters/templates/Error/403.latte b/app/presenters/templates/Error/403.latte new file mode 100644 index 0000000..de00328 --- /dev/null +++ b/app/presenters/templates/Error/403.latte @@ -0,0 +1,7 @@ +{block content} +

Access Denied

+ +

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.

+ +

error 403

diff --git a/app/presenters/templates/Error/404.latte b/app/presenters/templates/Error/404.latte new file mode 100644 index 0000000..022001c --- /dev/null +++ b/app/presenters/templates/Error/404.latte @@ -0,0 +1,8 @@ +{block content} +

Page Not Found

+ +

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.

+ +

error 404

diff --git a/app/presenters/templates/Error/405.latte b/app/presenters/templates/Error/405.latte new file mode 100644 index 0000000..d424892 --- /dev/null +++ b/app/presenters/templates/Error/405.latte @@ -0,0 +1,6 @@ +{block content} +

Method Not Allowed

+ +

The requested method is not allowed for the URL.

+ +

error 405

diff --git a/app/presenters/templates/Error/410.latte b/app/presenters/templates/Error/410.latte new file mode 100644 index 0000000..99bde92 --- /dev/null +++ b/app/presenters/templates/Error/410.latte @@ -0,0 +1,6 @@ +{block content} +

Page Not Found

+ +

The page you requested has been taken off the site. We apologize for the inconvenience.

+ +

error 410

diff --git a/app/presenters/templates/Error/4xx.latte b/app/presenters/templates/Error/4xx.latte new file mode 100644 index 0000000..d5ce82f --- /dev/null +++ b/app/presenters/templates/Error/4xx.latte @@ -0,0 +1,4 @@ +{block content} +

Oops...

+ +

Your browser sent a request that this server could not understand or process.

diff --git a/app/presenters/templates/Error/500.phtml b/app/presenters/templates/Error/500.phtml new file mode 100644 index 0000000..a2b900c --- /dev/null +++ b/app/presenters/templates/Error/500.phtml @@ -0,0 +1,27 @@ + + + +Server Error + + + +
+
+

Server Error

+ +

We're sorry! The server encountered an internal error and + was unable to complete your request. Please try again later.

+ +

error 500

+
+
+ + diff --git a/app/presenters/templates/Error/503.phtml b/app/presenters/templates/Error/503.phtml new file mode 100644 index 0000000..f123919 --- /dev/null +++ b/app/presenters/templates/Error/503.phtml @@ -0,0 +1,24 @@ + + + + + + + + +Site is temporarily down for maintenance + +

We're Sorry

+ +

The site is temporarily down for maintenance. Please try again in a few minutes.

diff --git a/app/presenters/templates/Homepage/default.latte b/app/presenters/templates/Homepage/default.latte new file mode 100644 index 0000000..2edaa1c --- /dev/null +++ b/app/presenters/templates/Homepage/default.latte @@ -0,0 +1,38 @@ +{* This is the welcome page, you can delete it *} + +{block content} + + +
+

You have successfully created your Nette Web project.

+ +

+ If you are exploring Nette for the first time, you should read the + Quick Start, documentation, + tutorials and forum.

+ +

We hope you enjoy Nette!

+
+ + diff --git a/app/router/RouterFactory.php b/app/router/RouterFactory.php new file mode 100644 index 0000000..a748408 --- /dev/null +++ b/app/router/RouterFactory.php @@ -0,0 +1,21 @@ +addRoute('/[/]', 'Homepage:default'); + return $router; + } +} diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..d84cbf9 --- /dev/null +++ b/composer.json @@ -0,0 +1,36 @@ +{ + "name": "nette/web-project", + "description": "Nette: Standard Web Project", + "keywords": ["nette"], + "type": "project", + "license": ["MIT", "BSD-3-Clause", "GPL-2.0", "GPL-3.0"], + "require": { + "php": ">= 7.1", + "nette/application": "^3.0", + "nette/bootstrap": "^3.0", + "nette/caching": "^3.0", + "nette/database": "^3.0", + "nette/di": "^3.0", + "nette/finder": "^2.5", + "nette/forms": "^3.0", + "nette/http": "^3.0", + "nette/mail": "^3.0", + "nette/robot-loader": "^3.0", + "nette/security": "^3.0", + "nette/utils": "^3.0", + "latte/latte": "^2.5", + "tracy/tracy": "^2.6" + }, + "require-dev": { + "nette/tester": "^2.0" + }, + "autoload": { + "classmap": ["app/Bootstrap.php"] + }, + "minimum-stability": "dev", + "config": { + "platform": { + "php": "7.1" + } + } +} diff --git a/log/.gitignore b/log/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/log/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..fbbf302 --- /dev/null +++ b/readme.md @@ -0,0 +1,61 @@ +Nette Web Project +================= + +This is a simple, skeleton application using the [Nette](https://nette.org). This is meant to +be used as a starting point for your new projects. + +[Nette](https://nette.org) is a popular tool for PHP web development. +It is designed to be the most usable and friendliest as possible. It focuses +on security and performance and is definitely one of the safest PHP frameworks. + +If you like Nette, **[please make a donation now](https://nette.org/donate)**. Thank you! + + +Requirements +------------ + +- Web Project for Nette 3.0 requires PHP 7.1 + + +Installation +------------ + +The best way to install Web Project is using Composer. If you don't have Composer yet, +download it following [the instructions](https://doc.nette.org/composer). Then use command: + + composer create-project nette/web-project path/to/install + cd path/to/install + + +Make directories `temp/` and `log/` writable. + + +Web Server Setup +---------------- + +The simplest way to get started is to start the built-in PHP server in the root directory of your project: + + php -S localhost:8000 -t www + +Then visit `http://localhost:8000` in your browser to see the welcome page. + +For Apache or Nginx, setup a virtual host to point to the `www/` directory of the project and you +should be ready to go. + +**It is CRITICAL that whole `app/`, `log/` and `temp/` directories are not accessible directly +via a web browser. See [security warning](https://nette.org/security-warning).** + + +Notice: Composer PHP version +---------------------------- + +This project forces PHP 5.6 (eventually 7.1) as your PHP version for Composer packages. If you have newer +version on production server you should change it in `composer.json`: + +```json +"config": { + "platform": { + "php": "7.2" + } +} +``` diff --git a/temp/.gitignore b/temp/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/temp/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/www/.htaccess b/www/.htaccess new file mode 100644 index 0000000..0996638 --- /dev/null +++ b/www/.htaccess @@ -0,0 +1,32 @@ +# Apache configuration file (see https://httpd.apache.org/docs/current/mod/quickreference.html) +Require all granted + +# disable directory listing + + Options -Indexes + + +# enable cool URL + + RewriteEngine On + # RewriteBase / + + # use HTTPS + # RewriteCond %{HTTPS} !on + # RewriteRule .? https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] + + # prevents files starting with dot to be viewed by browser + RewriteRule /\.|^\.(?!well-known/) - [F] + + # front controller + RewriteCond %{REQUEST_FILENAME} !-f + RewriteCond %{REQUEST_FILENAME} !-d + RewriteRule !\.(pdf|js|ico|gif|jpg|jpeg|png|webp|svg|css|rar|zip|7z|tar\.gz|map|eot|ttf|otf|woff|woff2)$ index.php [L] + + +# enable gzip compression + + + AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript application/json application/xml image/svg+xml + + diff --git a/www/favicon.ico b/www/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..b20cfd0f056c1c9d43100f612f4319c66e2adb94 GIT binary patch literal 2550 zcmcgsdpy=>6#qV`h?U#SZJVg3NgD48bB$?q*(P0BnsTYks)Y)n7Gs6xwl1`?sD@_U z*mR*3ue;!TGX-%KzT!aoOgA9#8p?H)WL?RL7J%`}#?vCTxIT)jQ5SY=6*49?+ zh&_ole$lYAvxC8Q5iS=MLnsttXlMv`?%ctjEsbHE`WM;pN*(R2gPpQVcsz^BU^|{g zdOB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W!z>@{nZxqL{ zh=QL_y(oY&ani$2@YEN_aY*gFm*aH@{||iK?3yQO>z|YV>W4Sqo9I6p5G09PXfCPx z;&Zb&aX?Vev-kV*{k_d?**5~-RN@c`{2gue-TH}%`ch3}=ROC&rnaYAkVqm}+BD5V za{pA9-^FlZ;_>*&Z%E=g`&+o(oUB|tP7=3%{UlJbB85M$22KZ{7Oda^FYEk~m9tOZv=@F{=&ov#vg;K8};8MS`EFL7E3`erDkr Rce72createContainer() + ->getByType(Nette\Application\Application::class) + ->run(); diff --git a/www/robots.txt b/www/robots.txt new file mode 100644 index 0000000..e69de29