Dan Brown

Started work on subdirectory support

...@@ -11,7 +11,7 @@ class Book extends Entity ...@@ -11,7 +11,7 @@ class Book extends Entity
11 */ 11 */
12 public function getUrl() 12 public function getUrl()
13 { 13 {
14 - return '/books/' . $this->slug; 14 + return baseUrl('/books/' . $this->slug);
15 } 15 }
16 16
17 /* 17 /*
......
...@@ -30,7 +30,7 @@ class Chapter extends Entity ...@@ -30,7 +30,7 @@ class Chapter extends Entity
30 public function getUrl() 30 public function getUrl()
31 { 31 {
32 $bookSlug = $this->getAttribute('bookSlug') ? $this->getAttribute('bookSlug') : $this->book->slug; 32 $bookSlug = $this->getAttribute('bookSlug') ? $this->getAttribute('bookSlug') : $this->book->slug;
33 - return '/books/' . $bookSlug. '/chapter/' . $this->slug; 33 + return baseUrl('/books/' . $bookSlug. '/chapter/' . $this->slug);
34 } 34 }
35 35
36 /** 36 /**
......
...@@ -63,7 +63,7 @@ class Page extends Entity ...@@ -63,7 +63,7 @@ class Page extends Entity
63 $bookSlug = $this->getAttribute('bookSlug') ? $this->getAttribute('bookSlug') : $this->book->slug; 63 $bookSlug = $this->getAttribute('bookSlug') ? $this->getAttribute('bookSlug') : $this->book->slug;
64 $midText = $this->draft ? '/draft/' : '/page/'; 64 $midText = $this->draft ? '/draft/' : '/page/';
65 $idComponent = $this->draft ? $this->id : $this->slug; 65 $idComponent = $this->draft ? $this->id : $this->slug;
66 - return '/books/' . $bookSlug . $midText . $idComponent; 66 + return baseUrl('/books/' . $bookSlug . $midText . $idComponent);
67 } 67 }
68 68
69 /** 69 /**
......
...@@ -138,8 +138,8 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon ...@@ -138,8 +138,8 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
138 */ 138 */
139 public function getAvatar($size = 50) 139 public function getAvatar($size = 50)
140 { 140 {
141 - if ($this->image_id === 0 || $this->image_id === '0' || $this->image_id === null) return '/user_avatar.png'; 141 + if ($this->image_id === 0 || $this->image_id === '0' || $this->image_id === null) return baseUrl('/user_avatar.png');
142 - return $this->avatar->getThumb($size, $size, false); 142 + return baseUrl($this->avatar->getThumb($size, $size, false));
143 } 143 }
144 144
145 /** 145 /**
...@@ -157,7 +157,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon ...@@ -157,7 +157,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
157 */ 157 */
158 public function getEditUrl() 158 public function getEditUrl()
159 { 159 {
160 - return '/settings/users/' . $this->id; 160 + return baseUrl('/settings/users/' . $this->id);
161 } 161 }
162 162
163 /** 163 /**
......
...@@ -20,11 +20,11 @@ if (!function_exists('versioned_asset')) { ...@@ -20,11 +20,11 @@ if (!function_exists('versioned_asset')) {
20 } 20 }
21 21
22 if (isset($manifest[$file])) { 22 if (isset($manifest[$file])) {
23 - return '/' . $manifest[$file]; 23 + return baseUrl($manifest[$file]);
24 } 24 }
25 25
26 if (file_exists(public_path($file))) { 26 if (file_exists(public_path($file))) {
27 - return '/' . $file; 27 + return baseUrl($file);
28 } 28 }
29 29
30 throw new InvalidArgumentException("File {$file} not defined in asset manifest."); 30 throw new InvalidArgumentException("File {$file} not defined in asset manifest.");
...@@ -63,6 +63,17 @@ function setting($key, $default = false) ...@@ -63,6 +63,17 @@ function setting($key, $default = false)
63 } 63 }
64 64
65 /** 65 /**
66 + * Helper to create url's relative to the applications root path.
67 + * @param $path
68 + * @return string
69 + */
70 +function baseUrl($path)
71 +{
72 + $path = trim($path, '/');
73 + return rtrim(config('app.url'), '/') . '/' . $path;
74 +}
75 +
76 +/**
66 * Generate a url with multiple parameters for sorting purposes. 77 * Generate a url with multiple parameters for sorting purposes.
67 * Works out the logic to set the correct sorting direction 78 * Works out the logic to set the correct sorting direction
68 * Discards empty parameters and allows overriding. 79 * Discards empty parameters and allows overriding.
......
...@@ -31,7 +31,7 @@ return [ ...@@ -31,7 +31,7 @@ return [
31 | 31 |
32 */ 32 */
33 33
34 - 'url' => env('APP_URL', 'http://localhost'), 34 + 'url' => env('APP_URL', '') === 'http://bookstack.dev' ? '' : env('APP_URL', ''),
35 35
36 /* 36 /*
37 |-------------------------------------------------------------------------- 37 |--------------------------------------------------------------------------
......
...@@ -11,11 +11,11 @@ ...@@ -11,11 +11,11 @@
11 <!-- Styles and Fonts --> 11 <!-- Styles and Fonts -->
12 <link rel="stylesheet" href="{{ versioned_asset('css/styles.css') }}"> 12 <link rel="stylesheet" href="{{ versioned_asset('css/styles.css') }}">
13 <link rel="stylesheet" media="print" href="{{ versioned_asset('css/print-styles.css') }}"> 13 <link rel="stylesheet" media="print" href="{{ versioned_asset('css/print-styles.css') }}">
14 - <link rel="stylesheet" href="/libs/material-design-iconic-font/css/material-design-iconic-font.min.css"> 14 + <link rel="stylesheet" href="{{ baseUrl('/libs/material-design-iconic-font/css/material-design-iconic-font.min.css') }}">
15 15
16 <!-- Scripts --> 16 <!-- Scripts -->
17 - <script src="/libs/jquery/jquery.min.js?version=2.1.4"></script> 17 + <script src="{{ baseUrl('/libs/jquery/jquery.min.js?version=2.1.4') }}"></script>
18 - <script src="/libs/jquery/jquery-ui.min.js?version=1.11.4"></script> 18 + <script src="{{ baseUrl('/libs/jquery/jquery-ui.min.js?version=1.11.4') }}"></script>
19 19
20 @yield('head') 20 @yield('head')
21 21
...@@ -34,15 +34,15 @@ ...@@ -34,15 +34,15 @@
34 <div class="container"> 34 <div class="container">
35 <div class="row"> 35 <div class="row">
36 <div class="col-lg-4 col-sm-4" ng-non-bindable> 36 <div class="col-lg-4 col-sm-4" ng-non-bindable>
37 - <a href="/" class="logo"> 37 + <a href="{{ baseUrl('/') }}" class="logo">
38 @if(setting('app-logo', '') !== 'none') 38 @if(setting('app-logo', '') !== 'none')
39 - <img class="logo-image" src="{{ setting('app-logo', '') === '' ? '/logo.png' : setting('app-logo', '') }}" alt="Logo"> 39 + <img class="logo-image" src="{{ setting('app-logo', '') === '' ? baseUrl('/logo.png') : baseUrl(setting('app-logo', '')) }}" alt="Logo">
40 @endif 40 @endif
41 <span class="logo-text">{{ setting('app-name', 'BookStack') }}</span> 41 <span class="logo-text">{{ setting('app-name', 'BookStack') }}</span>
42 </a> 42 </a>
43 </div> 43 </div>
44 <div class="col-lg-4 col-sm-3 text-center"> 44 <div class="col-lg-4 col-sm-3 text-center">
45 - <form action="/search/all" method="GET" class="search-box"> 45 + <form action="{{ baseUrl('/search/all') }}" method="GET" class="search-box">
46 <input id="header-search-box-input" type="text" name="term" tabindex="2" value="{{ isset($searchTerm) ? $searchTerm : '' }}"> 46 <input id="header-search-box-input" type="text" name="term" tabindex="2" value="{{ isset($searchTerm) ? $searchTerm : '' }}">
47 <button id="header-search-box-button" type="submit" class="text-button"><i class="zmdi zmdi-search"></i></button> 47 <button id="header-search-box-button" type="submit" class="text-button"><i class="zmdi zmdi-search"></i></button>
48 </form> 48 </form>
...@@ -50,12 +50,12 @@ ...@@ -50,12 +50,12 @@
50 <div class="col-lg-4 col-sm-5"> 50 <div class="col-lg-4 col-sm-5">
51 <div class="float right"> 51 <div class="float right">
52 <div class="links text-center"> 52 <div class="links text-center">
53 - <a href="/books"><i class="zmdi zmdi-book"></i>Books</a> 53 + <a href="{{ baseUrl('/books') }}"><i class="zmdi zmdi-book"></i>Books</a>
54 @if(isset($currentUser) && userCan('settings-manage')) 54 @if(isset($currentUser) && userCan('settings-manage'))
55 - <a href="/settings"><i class="zmdi zmdi-settings"></i>Settings</a> 55 + <a href="{{ baseUrl('/settings') }}"><i class="zmdi zmdi-settings"></i>Settings</a>
56 @endif 56 @endif
57 @if(!isset($signedIn) || !$signedIn) 57 @if(!isset($signedIn) || !$signedIn)
58 - <a href="/login"><i class="zmdi zmdi-sign-in"></i>Sign In</a> 58 + <a href="{{ baseUrl('/login') }}"><i class="zmdi zmdi-sign-in"></i>Sign In</a>
59 @endif 59 @endif
60 </div> 60 </div>
61 @if(isset($signedIn) && $signedIn) 61 @if(isset($signedIn) && $signedIn)
...@@ -66,13 +66,13 @@ ...@@ -66,13 +66,13 @@
66 </span> 66 </span>
67 <ul> 67 <ul>
68 <li> 68 <li>
69 - <a href="/user/{{$currentUser->id}}" class="text-primary"><i class="zmdi zmdi-account zmdi-hc-fw zmdi-hc-lg"></i>View Profile</a> 69 + <a href="{{ baseUrl("/user/{$currentUser->id}") }}" class="text-primary"><i class="zmdi zmdi-account zmdi-hc-fw zmdi-hc-lg"></i>View Profile</a>
70 </li> 70 </li>
71 <li> 71 <li>
72 - <a href="/settings/users/{{$currentUser->id}}" class="text-primary"><i class="zmdi zmdi-edit zmdi-hc-fw zmdi-hc-lg"></i>Edit Profile</a> 72 + <a href="{{ baseUrl("/settings/users/{$currentUser->id}") }}" class="text-primary"><i class="zmdi zmdi-edit zmdi-hc-fw zmdi-hc-lg"></i>Edit Profile</a>
73 </li> 73 </li>
74 <li> 74 <li>
75 - <a href="/logout" class="text-neg"><i class="zmdi zmdi-run zmdi-hc-fw zmdi-hc-lg"></i>Logout</a> 75 + <a href="{{ baseUrl('/logout') }}" class="text-neg"><i class="zmdi zmdi-run zmdi-hc-fw zmdi-hc-lg"></i>Logout</a>
76 </li> 76 </li>
77 </ul> 77 </ul>
78 </div> 78 </div>
......