From 8672508efbeb6abf7492f832c08f948890e5ae0b Mon Sep 17 00:00:00 2001 From: themohooks <81331307+themohooks@users.noreply.github.com> Date: Tue, 25 Feb 2025 23:01:50 +0300 Subject: [PATCH] update core --- .htaccess | 9 +- composer.json | 4 +- composer.lock | 241 +++++++++++++++++++++++++++++++++++++++++++++++++- index.php | 54 ++++++++--- 4 files changed, 289 insertions(+), 19 deletions(-) diff --git a/.htaccess b/.htaccess index 7277e65..f7fd314 100644 --- a/.htaccess +++ b/.htaccess @@ -15,18 +15,17 @@ Options -Indexes Deny from all - + Order allow,deny Deny from all - + Order allow,deny Deny from all - RedirectMatch 404 /\.git -RedirectMatch 404 /\.yml -RedirectMatch 404 /\.yaml +RedirectMatch 404 /\*.yml +RedirectMatch 404 /\*.yaml RedirectMatch 404 /\..*$ \ No newline at end of file diff --git a/composer.json b/composer.json index 046c37b..19c5381 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,9 @@ "chriskonnertz/bbcode": "^1.1", "paquettg/php-html-parser": "^2.2", "phpmailer/phpmailer": "^6.9", - "beeyev/disposable-email-filter-php": "^1.3" + "beeyev/disposable-email-filter-php": "^1.3", + "latte/latte": "^3.0", + "symfony/http-foundation": "^7.1" }, "require-dev": { "phpstan/phpstan": "*" diff --git a/composer.lock b/composer.lock index beaf064..80b9305 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "844a94a4ce9ce290e30dd5845c27ed3f", + "content-hash": "da68f7d816d4b35d8b2259d57d235833", "packages": [ { "name": "aws/aws-crt-php", @@ -721,6 +721,92 @@ ], "time": "2023-12-03T20:05:35+00:00" }, + { + "name": "latte/latte", + "version": "v3.0.20", + "source": { + "type": "git", + "url": "https://github.com/nette/latte.git", + "reference": "4db7a5502f8cef02fffa84fc9c34a635d9c79d4d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nette/latte/zipball/4db7a5502f8cef02fffa84fc9c34a635d9c79d4d", + "reference": "4db7a5502f8cef02fffa84fc9c34a635d9c79d4d", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-tokenizer": "*", + "php": "8.0 - 8.4" + }, + "conflict": { + "nette/application": "<3.1.7", + "nette/caching": "<3.1.4" + }, + "require-dev": { + "nette/php-generator": "^4.0", + "nette/tester": "^2.5", + "nette/utils": "^4.0", + "phpstan/phpstan": "^1", + "tracy/tracy": "^2.10" + }, + "suggest": { + "ext-fileinfo": "to use filter |datastream", + "ext-iconv": "to use filters |reverse, |substring", + "ext-intl": "to use Latte\\Engine::setLocale()", + "ext-mbstring": "to use filters like lower, upper, capitalize, ...", + "nette/php-generator": "to use tag {templatePrint}", + "nette/utils": "to use filter |webalize" + }, + "bin": [ + "bin/latte-lint" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause", + "GPL-2.0-only", + "GPL-3.0-only" + ], + "authors": [ + { + "name": "David Grudl", + "homepage": "https://davidgrudl.com" + }, + { + "name": "Nette Community", + "homepage": "https://nette.org/contributors" + } + ], + "description": "☕ Latte: the intuitive and fast template engine for those who want the most secure PHP sites. Introduces context-sensitive escaping.", + "homepage": "https://latte.nette.org", + "keywords": [ + "context-sensitive", + "engine", + "escaping", + "html", + "nette", + "security", + "template", + "twig" + ], + "support": { + "issues": "https://github.com/nette/latte/issues", + "source": "https://github.com/nette/latte/tree/v3.0.20" + }, + "time": "2024-10-08T00:58:27+00:00" + }, { "name": "mtdowling/jmespath.php", "version": "2.7.0", @@ -1722,6 +1808,83 @@ ], "time": "2024-04-18T09:32:20+00:00" }, + { + "name": "symfony/http-foundation", + "version": "v7.1.7", + "source": { + "type": "git", + "url": "https://github.com/symfony/http-foundation.git", + "reference": "5183b61657807099d98f3367bcccb850238b17a9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/http-foundation/zipball/5183b61657807099d98f3367bcccb850238b17a9", + "reference": "5183b61657807099d98f3367bcccb850238b17a9", + "shasum": "" + }, + "require": { + "php": ">=8.2", + "symfony/polyfill-mbstring": "~1.1", + "symfony/polyfill-php83": "^1.27" + }, + "conflict": { + "doctrine/dbal": "<3.6", + "symfony/cache": "<6.4" + }, + "require-dev": { + "doctrine/dbal": "^3.6|^4", + "predis/predis": "^1.1|^2.0", + "symfony/cache": "^6.4|^7.0", + "symfony/dependency-injection": "^6.4|^7.0", + "symfony/expression-language": "^6.4|^7.0", + "symfony/http-kernel": "^6.4|^7.0", + "symfony/mime": "^6.4|^7.0", + "symfony/rate-limiter": "^6.4|^7.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\HttpFoundation\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Defines an object-oriented layer for the HTTP specification", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/http-foundation/tree/v7.1.7" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-11-06T09:02:46+00:00" + }, { "name": "symfony/polyfill-ctype", "version": "v1.30.0", @@ -1881,6 +2044,82 @@ ], "time": "2024-06-19T12:30:46+00:00" }, + { + "name": "symfony/polyfill-php83", + "version": "v1.31.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php83.git", + "reference": "2fb86d65e2d424369ad2905e83b236a8805ba491" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php83/zipball/2fb86d65e2d424369ad2905e83b236a8805ba491", + "reference": "2fb86d65e2d424369ad2905e83b236a8805ba491", + "shasum": "" + }, + "require": { + "php": ">=7.2" + }, + "type": "library", + "extra": { + "thanks": { + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Php83\\": "" + }, + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 8.3+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-php83/tree/v1.31.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-09-09T11:45:10+00:00" + }, { "name": "symfony/process", "version": "v7.1.1", diff --git a/index.php b/index.php index fccece2..a22e339 100644 --- a/index.php +++ b/index.php @@ -1,19 +1,31 @@ =")) { + $problems[] = "Incompatible PHP version: " . PHP_VERSION . ""; + } + if (!is_dir(__DIR__ . "/vendor")) { + $problems[] = "Composer dependencies missing"; + } + if (!file_exists($_SERVER['DOCUMENT_ROOT'] . '/ngallery.yaml')) { + $problems[] = "Missing ngallery.yaml (create from ngallery-example.yaml)"; + } + if (sizeof($problems) === 0) { define("NGALLERY", Yaml::parse(file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/ngallery.yaml'))['ngallery']); define("NGALLERY_TASKS", Yaml::parse(file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/app/Controllers/Exec/Tasks/ngallery-tasks.yaml'))['tasks']); if (NGALLERY['root']['debug'] === true) { @@ -24,18 +36,36 @@ class App DB::connect(); Routes::init(); } else { - Page::set('Errors/ServerDown'); + $latte->render($_SERVER['DOCUMENT_ROOT'] . "/views/pages/Errors/ServerDown.latte"); } - } catch (PDOException $ex) { - echo '
Произошла ошибка MySQL'.nl2br($ex).'
'; - } catch (Exception $ex) { - echo '
Произошла скриптовая ошибка PHP'.nl2br($ex).'
'; + http_response_code(500); + + $errorCodes = [ + 'PDOException' => ['code' => '10120', 'type' => 'MYSQL_ERROR', 'message' => 'Произошла ошибка MySQL'], + 'Exception' => ['code' => '10121', 'type' => 'SCRIPT_ERROR', 'message' => 'Произошла ошибка PHP'] + ]; + + $exceptionType = $ex instanceof PDOException ? 'PDOException' : 'Exception'; + $errorDetails = $errorCodes[$exceptionType]; + + $errorResponse = NGALLERY['root']['debug'] === true + ? ['errorcode' => $errorDetails['code'], 'error' => 1, 'errormsg' => $ex, 'errortype' => $errorDetails['type']] + : ['errorcode' => '1', 'error' => 1, 'errormsg' => 'Internal Server Error', 'errortype' => $errorDetails['type']]; + + if ($request->isXmlHttpRequest() && !isset($_SERVER['HTTP_USER_AGENT'])) { + APIResponse::data($errorResponse, 500)->send(); + } else { + echo NGALLERY['root']['debug'] === true + ? '
' . $errorDetails['message'] . '' . nl2br($ex) . '
' + : $errorDetails['message']; + } } } else { - Page::set('Errors/Problems'); + $params['problems'] = $problems; + $latte->render($_SERVER['DOCUMENT_ROOT'] . "/views/pages/Errors/Problems.latte", $params); } } } -App::start(); \ No newline at end of file +App::start();