From f596ff5c4ca43a5d5a016e9ee0d7cc5dec193f2e Mon Sep 17 00:00:00 2001 From: Bastian Allgeier Date: Tue, 15 Jan 2019 11:43:30 +0100 Subject: [PATCH] 3.0 --- kirby/composer.json | 2 +- kirby/composer.lock | 2 +- kirby/config/api/routes/auth.php | 16 ++++++++++------ kirby/config/helpers.php | 16 ++++++++++++++-- kirby/src/Cms/Url.php | 20 ++++++++++++++++++++ 5 files changed, 46 insertions(+), 10 deletions(-) diff --git a/kirby/composer.json b/kirby/composer.json index 2c34556..d1c230d 100755 --- a/kirby/composer.json +++ b/kirby/composer.json @@ -1,7 +1,7 @@ { "name": "getkirby/cms", "description": "The Kirby 3 core", - "version": "3.0.0-RC-6.0", + "version": "3.0.0", "license": "proprietary", "keywords": ["kirby", "cms", "core"], "homepage": "https://getkirby.com", diff --git a/kirby/composer.lock b/kirby/composer.lock index b82be84..5cb9a36 100755 --- a/kirby/composer.lock +++ b/kirby/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": "795a9baff274c8a85cd3670e696e6331", + "content-hash": "fccb729b1a9f9683c43cc376216e49cf", "packages": [ { "name": "claviska/simpleimage", diff --git a/kirby/config/api/routes/auth.php b/kirby/config/api/routes/auth.php index fe03d62..6f2371e 100755 --- a/kirby/config/api/routes/auth.php +++ b/kirby/config/api/routes/auth.php @@ -35,12 +35,16 @@ return [ $long = $this->requestBody('long'); $password = $this->requestBody('password'); - if ($user = $this->kirby()->auth()->login($email, $password, $long)) { - return [ - 'code' => 200, - 'status' => 'ok', - 'user' => $this->resolve($user)->view('auth')->toArray() - ]; + try { + if ($user = $this->kirby()->auth()->login($email, $password, $long)) { + return [ + 'code' => 200, + 'status' => 'ok', + 'user' => $this->resolve($user)->view('auth')->toArray() + ]; + } + } catch (Throwable $e) { + // catch any kind of login error } throw new InvalidArgumentException('Invalid email or password'); diff --git a/kirby/config/helpers.php b/kirby/config/helpers.php index b7e2e89..71f52c1 100755 --- a/kirby/config/helpers.php +++ b/kirby/config/helpers.php @@ -97,7 +97,13 @@ function css($url, $options = null) $url = $component($kirby, $url, $options); } - $url = $url === '@auto' ? Url::toTemplateAsset('css/templates', 'css') : Url::to($url); + if ($url === '@auto') { + if (!$url = Url::toTemplateAsset('css/templates', 'css')) { + return null; + } + } + + $url = Url::to($url); $attr = array_merge((array)$options, [ 'href' => $url, 'rel' => 'stylesheet' @@ -345,7 +351,13 @@ function js($url, $options = null) $url = $component($kirby, $url, $options); } - $url = $url === '@auto' ? Url::toTemplateAsset('js/templates', 'js') : Url::to($url); + if ($url === '@auto') { + if (!$url = Url::toTemplateAsset('js/templates', 'js')) { + return null; + } + } + + $url = Url::to($url); $attr = array_merge((array)$options, ['src' => $url]); return ''; diff --git a/kirby/src/Cms/Url.php b/kirby/src/Cms/Url.php index dd0f18b..0650c5e 100755 --- a/kirby/src/Cms/Url.php +++ b/kirby/src/Cms/Url.php @@ -42,4 +42,24 @@ class Url extends BaseUrl return file_exists($file) === true ? $url : null; } + + /** + * Smart resolver for internal and external urls + * + * @param string $path + * @param array $options + * @return string + */ + public static function to(string $path = null, array $options = null): string + { + $kirby = App::instance(); + + if ($handler = $kirby->component('url')) { + return $handler($kirby, $path, $options, function (string $path = null, array $options = null) { + return parent::to($path, $options); + }); + } + + return parent::to($path, $options); + } }