diff --git a/.htaccess b/.htaccess index 7cac6a1..eba3ddb 100644 --- a/.htaccess +++ b/.htaccess @@ -34,5 +34,5 @@ FileETag None Header set X-Content-Type-Options nosniff Header set X-XSS-Protection "1; mode=block" Header set Referrer-Policy no-referrer - Header set Content-Security-Policy "default-src 'self'; object-src 'none'; script-src 'none'; img-src http:" + Header set Content-Security-Policy "default-src 'self'; object-src 'none'; script-src 'none'; style-src 'self' 'unsafe-inline'; img-src http:" diff --git a/classes/Config.php b/classes/Config.php index c20c931..0e0efeb 100644 --- a/classes/Config.php +++ b/classes/Config.php @@ -135,6 +135,8 @@ class Config */ public $genericFormats = []; + public $debug = false; + /** * Config constructor. * diff --git a/controllers/FrontController.php b/controllers/FrontController.php index 733bbd5..b1a3c87 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -16,6 +16,7 @@ use Slim\Container; use Slim\Http\Request; use Slim\Http\Response; use Slim\Views\Smarty; +use Symfony\Component\Debug\ExceptionHandler; /** * Main controller. @@ -233,18 +234,23 @@ class FrontController extends BaseController */ public function error(Request $request, Response $response, Exception $exception) { - $this->view->render( - $response, - 'error.tpl', - [ - 'config' => $this->config, - 'errors' => $exception->getMessage(), - 'class' => 'video', - 'title' => _('Error'), - 'canonical' => $this->getCanonicalUrl($request), - 'locale' => $this->localeManager->getLocale(), - ] - ); + if ($this->config->debug) { + $handler = new ExceptionHandler(); + $handler->handle($exception); + } else { + $this->view->render( + $response, + 'error.tpl', + [ + 'config' => $this->config, + 'errors' => $exception->getMessage(), + 'class' => 'video', + 'title' => _('Error'), + 'canonical' => $this->getCanonicalUrl($request), + 'locale' => $this->localeManager->getLocale(), + ] + ); + } return $response->withStatus(500); } diff --git a/index.php b/index.php index 62f5435..ca3f619 100644 --- a/index.php +++ b/index.php @@ -10,6 +10,7 @@ use Alltube\LocaleMiddleware; use Alltube\UglyRouter; use Alltube\ViewFactory; use Slim\App; +use Symfony\Component\Debug\Debug; if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '/index.php') !== false) { header('Location: ' . str_ireplace('/index.php', '/', $_SERVER['REQUEST_URI'])); @@ -26,6 +27,11 @@ $config = Config::getInstance(); if ($config->uglyUrls) { $container['router'] = new UglyRouter(); } + +if ($config->debug) { + Debug::enable(); +} + $container['view'] = ViewFactory::create($container); if (!class_exists('Locale')) {