From baa260a03d872c59e8dd086a0969522df5e492d4 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Sat, 13 Aug 2016 17:56:20 +0100 Subject: [PATCH] Started work on subdirectory support --- app/Book.php | 2 +- app/Chapter.php | 2 +- app/Page.php | 2 +- app/User.php | 6 +++--- app/helpers.php | 15 +++++++++++++-- config/app.php | 2 +- resources/views/base.blade.php | 24 ++++++++++++------------ 7 files changed, 32 insertions(+), 21 deletions(-) diff --git a/app/Book.php b/app/Book.php index 919af80a5..af6d59bfd 100644 --- a/app/Book.php +++ b/app/Book.php @@ -11,7 +11,7 @@ class Book extends Entity */ public function getUrl() { - return '/books/' . $this->slug; + return baseUrl('/books/' . $this->slug); } /* diff --git a/app/Chapter.php b/app/Chapter.php index 08faef68e..250e323f5 100644 --- a/app/Chapter.php +++ b/app/Chapter.php @@ -30,7 +30,7 @@ class Chapter extends Entity public function getUrl() { $bookSlug = $this->getAttribute('bookSlug') ? $this->getAttribute('bookSlug') : $this->book->slug; - return '/books/' . $bookSlug. '/chapter/' . $this->slug; + return baseUrl('/books/' . $bookSlug. '/chapter/' . $this->slug); } /** diff --git a/app/Page.php b/app/Page.php index c6978d34b..5902f4f5a 100644 --- a/app/Page.php +++ b/app/Page.php @@ -63,7 +63,7 @@ class Page extends Entity $bookSlug = $this->getAttribute('bookSlug') ? $this->getAttribute('bookSlug') : $this->book->slug; $midText = $this->draft ? '/draft/' : '/page/'; $idComponent = $this->draft ? $this->id : $this->slug; - return '/books/' . $bookSlug . $midText . $idComponent; + return baseUrl('/books/' . $bookSlug . $midText . $idComponent); } /** diff --git a/app/User.php b/app/User.php index 74aec7e3a..6ab7ad3bf 100644 --- a/app/User.php +++ b/app/User.php @@ -138,8 +138,8 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon */ public function getAvatar($size = 50) { - if ($this->image_id === 0 || $this->image_id === '0' || $this->image_id === null) return '/user_avatar.png'; - return $this->avatar->getThumb($size, $size, false); + if ($this->image_id === 0 || $this->image_id === '0' || $this->image_id === null) return baseUrl('/user_avatar.png'); + return baseUrl($this->avatar->getThumb($size, $size, false)); } /** @@ -157,7 +157,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon */ public function getEditUrl() { - return '/settings/users/' . $this->id; + return baseUrl('/settings/users/' . $this->id); } /** diff --git a/app/helpers.php b/app/helpers.php index 42e4c1894..0b9a6afc6 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -20,11 +20,11 @@ if (!function_exists('versioned_asset')) { } if (isset($manifest[$file])) { - return '/' . $manifest[$file]; + return baseUrl($manifest[$file]); } if (file_exists(public_path($file))) { - return '/' . $file; + return baseUrl($file); } throw new InvalidArgumentException("File {$file} not defined in asset manifest."); @@ -62,6 +62,17 @@ function setting($key, $default = false) return $settingService->get($key, $default); } +/** + * Helper to create url's relative to the applications root path. + * @param $path + * @return string + */ +function baseUrl($path) +{ + $path = trim($path, '/'); + return rtrim(config('app.url'), '/') . '/' . $path; +} + /** * Generate a url with multiple parameters for sorting purposes. * Works out the logic to set the correct sorting direction diff --git a/config/app.php b/config/app.php index d305af3c0..6819fa481 100644 --- a/config/app.php +++ b/config/app.php @@ -31,7 +31,7 @@ return [ | */ - 'url' => env('APP_URL', 'http://localhost'), + 'url' => env('APP_URL', '') === 'http://bookstack.dev' ? '' : env('APP_URL', ''), /* |-------------------------------------------------------------------------- diff --git a/resources/views/base.blade.php b/resources/views/base.blade.php index d09912c37..e9ed436c5 100644 --- a/resources/views/base.blade.php +++ b/resources/views/base.blade.php @@ -11,11 +11,11 @@ - + - - + + @yield('head') @@ -34,15 +34,15 @@
- @@ -50,12 +50,12 @@
@if(isset($signedIn) && $signedIn) @@ -66,13 +66,13 @@