Skip to content

Commit 43d9d2e

Browse files
committed
Updated all application urls to allow path prefix.
Allows BookStack to be installed at a non-root location on a domain. Closes #40.
1 parent baa260a commit 43d9d2e

File tree

81 files changed

+480
-404
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+480
-404
lines changed

.env.example

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ APP_ENV=production
33
APP_DEBUG=false
44
APP_KEY=SomeRandomString
55

6+
# The below url has to be set if using social auth options
7+
# or if you are not using BookStack at the root path of your domain.
8+
# APP_URL=http://bookstack.dev
9+
610
# Database details
711
DB_HOST=localhost
812
DB_DATABASE=database_database
@@ -42,8 +46,6 @@ GITHUB_APP_ID=false
4246
GITHUB_APP_SECRET=false
4347
GOOGLE_APP_ID=false
4448
GOOGLE_APP_SECRET=false
45-
# URL used for social login redirects, NO TRAILING SLASH
46-
APP_URL=http://bookstack.dev
4749

4850
# External services such as Gravatar
4951
DISABLE_EXTERNAL_SERVICES=false

app/Book.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ class Book extends Entity
77

88
/**
99
* Get the url for this book.
10+
* @param string|bool $path
1011
* @return string
1112
*/
12-
public function getUrl()
13+
public function getUrl($path = false)
1314
{
15+
if ($path !== false) {
16+
return baseUrl('/books/' . $this->slug . '/' . trim($path, '/'));
17+
}
1418
return baseUrl('/books/' . $this->slug);
1519
}
1620

app/Chapter.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@ public function pages()
2525

2626
/**
2727
* Get the url of this chapter.
28+
* @param string|bool $path
2829
* @return string
2930
*/
30-
public function getUrl()
31+
public function getUrl($path = false)
3132
{
3233
$bookSlug = $this->getAttribute('bookSlug') ? $this->getAttribute('bookSlug') : $this->book->slug;
34+
if ($path !== false) {
35+
return baseUrl('/books/' . $bookSlug. '/chapter/' . $this->slug . '/' . trim($path, '/'));
36+
}
3337
return baseUrl('/books/' . $bookSlug. '/chapter/' . $this->slug);
3438
}
3539

app/Exceptions/Handler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public function render($request, Exception $e)
4848
// Handle notify exceptions which will redirect to the
4949
// specified location then show a notification message.
5050
if ($e instanceof NotifyException) {
51-
\Session::flash('error', $e->message);
52-
return response()->redirectTo($e->redirectLocation);
51+
session()->flash('error', $e->message);
52+
return redirect($e->redirectLocation);
5353
}
5454

5555
// Handle pretty exceptions which will show a friendly application-fitting page

app/Http/Controllers/Auth/AuthController.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
<?php
2-
3-
namespace BookStack\Http\Controllers\Auth;
1+
<?php namespace BookStack\Http\Controllers\Auth;
42

53
use BookStack\Exceptions\AuthException;
6-
use BookStack\Exceptions\PrettyException;
74
use Illuminate\Contracts\Auth\Authenticatable;
85
use Illuminate\Http\Request;
96
use BookStack\Exceptions\SocialSignInException;
@@ -36,7 +33,6 @@ class AuthController extends Controller
3633
protected $redirectAfterLogout = '/login';
3734
protected $username = 'email';
3835

39-
4036
protected $socialAuthService;
4137
protected $emailConfirmationService;
4238
protected $userRepo;
@@ -53,6 +49,8 @@ public function __construct(SocialAuthService $socialAuthService, EmailConfirmat
5349
$this->socialAuthService = $socialAuthService;
5450
$this->emailConfirmationService = $emailConfirmationService;
5551
$this->userRepo = $userRepo;
52+
$this->redirectPath = baseUrl('/');
53+
$this->redirectAfterLogout = baseUrl('/login');
5654
$this->username = config('auth.method') === 'standard' ? 'email' : 'username';
5755
parent::__construct();
5856
}

app/Http/Controllers/PageController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ public function exportPlainText($bookSlug, $pageSlug)
412412
*/
413413
public function showRecentlyCreated()
414414
{
415-
$pages = $this->pageRepo->getRecentlyCreatedPaginated(20);
415+
$pages = $this->pageRepo->getRecentlyCreatedPaginated(20)->setPath(baseUrl('/pages/recently-created'));
416416
return view('pages/detailed-listing', [
417417
'title' => 'Recently Created Pages',
418418
'pages' => $pages
@@ -425,7 +425,7 @@ public function showRecentlyCreated()
425425
*/
426426
public function showRecentlyUpdated()
427427
{
428-
$pages = $this->pageRepo->getRecentlyUpdatedPaginated(20);
428+
$pages = $this->pageRepo->getRecentlyUpdatedPaginated(20)->setPath(baseUrl('/pages/recently-updated'));
429429
return view('pages/detailed-listing', [
430430
'title' => 'Recently Updated Pages',
431431
'pages' => $pages

app/Http/Middleware/Authenticate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(Guard $auth)
3333
public function handle($request, Closure $next)
3434
{
3535
if ($this->auth->check() && setting('registration-confirmation') && !$this->auth->user()->email_confirmed) {
36-
return redirect()->guest('/register/confirm/awaiting');
36+
return redirect()->guest(baseUrl('/register/confirm/awaiting'));
3737
}
3838

3939
if ($this->auth->guest() && !setting('app-public')) {

app/Page.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,19 @@ public function revisions()
5656

5757
/**
5858
* Get the url for this page.
59+
* @param string|bool $path
5960
* @return string
6061
*/
61-
public function getUrl()
62+
public function getUrl($path = false)
6263
{
6364
$bookSlug = $this->getAttribute('bookSlug') ? $this->getAttribute('bookSlug') : $this->book->slug;
6465
$midText = $this->draft ? '/draft/' : '/page/';
6566
$idComponent = $this->draft ? $this->id : $this->slug;
67+
68+
if ($path !== false) {
69+
return baseUrl('/books/' . $bookSlug . $midText . $idComponent . '/' . trim($path, '/'));
70+
}
71+
6672
return baseUrl('/books/' . $bookSlug . $midText . $idComponent);
6773
}
6874

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php namespace BookStack\Providers;
2+
3+
4+
use Illuminate\Support\ServiceProvider;
5+
use Illuminate\Pagination\Paginator;
6+
7+
class PaginationServiceProvider extends ServiceProvider
8+
{
9+
/**
10+
* Register the service provider.
11+
*
12+
* @return void
13+
*/
14+
public function register()
15+
{
16+
Paginator::currentPathResolver(function () {
17+
return baseUrl($this->app['request']->path());
18+
});
19+
20+
Paginator::currentPageResolver(function ($pageName = 'page') {
21+
$page = $this->app['request']->input($pageName);
22+
23+
if (filter_var($page, FILTER_VALIDATE_INT) !== false && (int) $page >= 1) {
24+
return $page;
25+
}
26+
27+
return 1;
28+
});
29+
}
30+
}

app/Repos/ImageRepo.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ImageRepo
1313

1414
protected $image;
1515
protected $imageService;
16-
protected $restictionService;
16+
protected $restrictionService;
1717
protected $page;
1818

1919
/**
@@ -27,7 +27,7 @@ public function __construct(Image $image, ImageService $imageService, Permission
2727
{
2828
$this->image = $image;
2929
$this->imageService = $imageService;
30-
$this->restictionService = $permissionService;
30+
$this->restrictionService = $permissionService;
3131
$this->page = $page;
3232
}
3333

@@ -52,7 +52,7 @@ public function getById($id)
5252
*/
5353
private function returnPaginated($query, $page = 0, $pageSize = 24)
5454
{
55-
$images = $this->restictionService->filterRelatedPages($query, 'images', 'uploaded_to');
55+
$images = $this->restrictionService->filterRelatedPages($query, 'images', 'uploaded_to');
5656
$images = $images->orderBy('created_at', 'desc')->skip($pageSize * $page)->take($pageSize + 1)->get();
5757
$hasMore = count($images) > $pageSize;
5858

0 commit comments

Comments
 (0)