Skip to content

Commit

Permalink
Merge branch 'v0.11' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
ssddanbrown committed Aug 14, 2016
2 parents c6404d8 + 43d9d2e commit d2a5ab4
Show file tree
Hide file tree
Showing 89 changed files with 559 additions and 459 deletions.
6 changes: 4 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ APP_ENV=production
APP_DEBUG=false
APP_KEY=SomeRandomString

# The below url has to be set if using social auth options
# or if you are not using BookStack at the root path of your domain.
# APP_URL=http://bookstack.dev

# Database details
DB_HOST=localhost
DB_DATABASE=database_database
Expand Down Expand Up @@ -42,8 +46,6 @@ GITHUB_APP_ID=false
GITHUB_APP_SECRET=false
GOOGLE_APP_ID=false
GOOGLE_APP_SECRET=false
# URL used for social login redirects, NO TRAILING SLASH
APP_URL=http://bookstack.dev

# External services such as Gravatar
DISABLE_EXTERNAL_SERVICES=false
Expand Down
8 changes: 6 additions & 2 deletions app/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ class Book extends Entity

/**
* Get the url for this book.
* @param string|bool $path
* @return string
*/
public function getUrl()
public function getUrl($path = false)
{
return '/books/' . $this->slug;
if ($path !== false) {
return baseUrl('/books/' . $this->slug . '/' . trim($path, '/'));
}
return baseUrl('/books/' . $this->slug);
}

/*
Expand Down
8 changes: 6 additions & 2 deletions app/Chapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ public function pages()

/**
* Get the url of this chapter.
* @param string|bool $path
* @return string
*/
public function getUrl()
public function getUrl($path = false)
{
$bookSlug = $this->getAttribute('bookSlug') ? $this->getAttribute('bookSlug') : $this->book->slug;
return '/books/' . $bookSlug. '/chapter/' . $this->slug;
if ($path !== false) {
return baseUrl('/books/' . $bookSlug. '/chapter/' . $this->slug . '/' . trim($path, '/'));
}
return baseUrl('/books/' . $bookSlug. '/chapter/' . $this->slug);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public function render($request, Exception $e)
// Handle notify exceptions which will redirect to the
// specified location then show a notification message.
if ($e instanceof NotifyException) {
\Session::flash('error', $e->message);
return response()->redirectTo($e->redirectLocation);
session()->flash('error', $e->message);
return redirect($e->redirectLocation);
}

// Handle pretty exceptions which will show a friendly application-fitting page
Expand Down
8 changes: 3 additions & 5 deletions app/Http/Controllers/Auth/AuthController.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?php

namespace BookStack\Http\Controllers\Auth;
<?php namespace BookStack\Http\Controllers\Auth;

use BookStack\Exceptions\AuthException;
use BookStack\Exceptions\PrettyException;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Http\Request;
use BookStack\Exceptions\SocialSignInException;
Expand Down Expand Up @@ -36,7 +33,6 @@ class AuthController extends Controller
protected $redirectAfterLogout = '/#';
protected $username = 'email';


protected $socialAuthService;
protected $emailConfirmationService;
protected $userRepo;
Expand All @@ -53,6 +49,8 @@ public function __construct(SocialAuthService $socialAuthService, EmailConfirmat
$this->socialAuthService = $socialAuthService;
$this->emailConfirmationService = $emailConfirmationService;
$this->userRepo = $userRepo;
$this->redirectPath = baseUrl('/');
$this->redirectAfterLogout = baseUrl('/#');
$this->username = config('auth.method') === 'standard' ? 'email' : 'username';
parent::__construct();
}
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ public function exportPlainText($bookSlug, $pageSlug)
*/
public function showRecentlyCreated()
{
$pages = $this->pageRepo->getRecentlyCreatedPaginated(20);
$pages = $this->pageRepo->getRecentlyCreatedPaginated(20)->setPath(baseUrl('/pages/recently-created'));
return view('pages/detailed-listing', [
'title' => 'Recently Created Pages',
'pages' => $pages
Expand All @@ -425,7 +425,7 @@ public function showRecentlyCreated()
*/
public function showRecentlyUpdated()
{
$pages = $this->pageRepo->getRecentlyUpdatedPaginated(20);
$pages = $this->pageRepo->getRecentlyUpdatedPaginated(20)->setPath(baseUrl('/pages/recently-updated'));
return view('pages/detailed-listing', [
'title' => 'Recently Updated Pages',
'pages' => $pages
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/Authenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(Guard $auth)
public function handle($request, Closure $next)
{
if ($this->auth->check() && setting('registration-confirmation') && !$this->auth->user()->email_confirmed) {
return redirect()->guest('/register/confirm/awaiting');
return redirect()->guest(baseUrl('/register/confirm/awaiting'));
}

if ($this->auth->guest() && !setting('app-public')) {
Expand Down
10 changes: 8 additions & 2 deletions app/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,20 @@ public function revisions()

/**
* Get the url for this page.
* @param string|bool $path
* @return string
*/
public function getUrl()
public function getUrl($path = false)
{
$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;

if ($path !== false) {
return baseUrl('/books/' . $bookSlug . $midText . $idComponent . '/' . trim($path, '/'));
}

return baseUrl('/books/' . $bookSlug . $midText . $idComponent);
}

/**
Expand Down
30 changes: 30 additions & 0 deletions app/Providers/PaginationServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php namespace BookStack\Providers;


use Illuminate\Support\ServiceProvider;
use Illuminate\Pagination\Paginator;

class PaginationServiceProvider extends ServiceProvider
{
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
Paginator::currentPathResolver(function () {
return baseUrl($this->app['request']->path());
});

Paginator::currentPageResolver(function ($pageName = 'page') {
$page = $this->app['request']->input($pageName);

if (filter_var($page, FILTER_VALIDATE_INT) !== false && (int) $page >= 1) {
return $page;
}

return 1;
});
}
}
16 changes: 7 additions & 9 deletions app/Repos/BookRepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,20 +216,18 @@ public function doesSlugExist($slug, $currentId = false)
*/
public function findSuitableSlug($name, $currentId = false)
{
$originalSlug = Str::slug($name);
$slug = $originalSlug;
$count = 2;
$slug = Str::slug($name);
if ($slug === "") $slug = substr(md5(rand(1, 500)), 0, 5);
while ($this->doesSlugExist($slug, $currentId)) {
$slug = $originalSlug . '-' . $count;
$count++;
$slug .= '-' . substr(md5(rand(1, 500)), 0, 3);
}
return $slug;
}

/**
* Get all child objects of a book.
* Returns a sorted collection of Pages and Chapters.
* Loads the bookslug onto child elements to prevent access database access for getting the slug.
* Loads the book slug onto child elements to prevent access database access for getting the slug.
* @param Book $book
* @param bool $filterDrafts
* @return mixed
Expand All @@ -245,7 +243,7 @@ public function getChildren(Book $book, $filterDrafts = false)

$pages = $pageQuery->get();

$chapterQuery = $book->chapters()->with(['pages' => function($query) use ($filterDrafts) {
$chapterQuery = $book->chapters()->with(['pages' => function ($query) use ($filterDrafts) {
$this->permissionService->enforcePageRestrictions($query, 'view');
if ($filterDrafts) $query->where('draft', '=', false);
}]);
Expand All @@ -263,7 +261,7 @@ public function getChildren(Book $book, $filterDrafts = false)
$child->pages->each(function ($page) use ($bookSlug) {
$page->setAttribute('bookSlug', $bookSlug);
});
$child->pages = $child->pages->sortBy(function($child, $key) {
$child->pages = $child->pages->sortBy(function ($child, $key) {
$score = $child->priority;
if ($child->draft) $score -= 100;
return $score;
Expand All @@ -272,7 +270,7 @@ public function getChildren(Book $book, $filterDrafts = false)
});

// Sort items with drafts first then by priority.
return $children->sortBy(function($child, $key) {
return $children->sortBy(function ($child, $key) {
$score = $child->priority;
if ($child->isA('page') && $child->draft) $score -= 100;
return $score;
Expand Down
3 changes: 2 additions & 1 deletion app/Repos/ChapterRepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function getChildren(Chapter $chapter)
{
$pages = $this->permissionService->enforcePageRestrictions($chapter->pages())->get();
// Sort items with drafts first then by priority.
return $pages->sortBy(function($child, $key) {
return $pages->sortBy(function ($child, $key) {
$score = $child->priority;
if ($child->draft) $score -= 100;
return $score;
Expand Down Expand Up @@ -151,6 +151,7 @@ public function doesSlugExist($slug, $bookId, $currentId = false)
public function findSuitableSlug($name, $bookId, $currentId = false)
{
$slug = Str::slug($name);
if ($slug === "") $slug = substr(md5(rand(1, 500)), 0, 5);
while ($this->doesSlugExist($slug, $bookId, $currentId)) {
$slug .= '-' . substr(md5(rand(1, 500)), 0, 3);
}
Expand Down
6 changes: 3 additions & 3 deletions app/Repos/ImageRepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ImageRepo

protected $image;
protected $imageService;
protected $restictionService;
protected $restrictionService;
protected $page;

/**
Expand All @@ -27,7 +27,7 @@ public function __construct(Image $image, ImageService $imageService, Permission
{
$this->image = $image;
$this->imageService = $imageService;
$this->restictionService = $permissionService;
$this->restrictionService = $permissionService;
$this->page = $page;
}

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

Expand Down
11 changes: 6 additions & 5 deletions app/Repos/PageRepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function publishDraft(Page $draftPage, array $input)
$draftPage->fill($input);

// Save page tags if present
if(isset($input['tags'])) {
if (isset($input['tags'])) {
$this->tagRepo->saveTagsToEntity($draftPage, $input['tags']);
}

Expand Down Expand Up @@ -319,7 +319,7 @@ public function updatePage(Page $page, $book_id, $input)
}

// Save page tags if present
if(isset($input['tags'])) {
if (isset($input['tags'])) {
$this->tagRepo->saveTagsToEntity($page, $input['tags']);
}

Expand Down Expand Up @@ -405,7 +405,7 @@ public function saveUpdateDraft(Page $page, $data = [])

$draft->fill($data);
if (setting('app-editor') !== 'markdown') $draft->markdown = '';

$draft->save();
return $draft;
}
Expand Down Expand Up @@ -591,14 +591,15 @@ public function changePageParent(Page $page, Entity $parent)

/**
* Gets a suitable slug for the resource
* @param $name
* @param $bookId
* @param string $name
* @param int $bookId
* @param bool|false $currentId
* @return string
*/
public function findSuitableSlug($name, $bookId, $currentId = false)
{
$slug = Str::slug($name);
if ($slug === "") $slug = substr(md5(rand(1, 500)), 0, 5);
while ($this->doesSlugExist($slug, $bookId, $currentId)) {
$slug .= '-' . substr(md5(rand(1, 500)), 0, 3);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Services/ImageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ private function getPublicUrl($filePath)
$this->storageUrl = $storageUrl;
}

return ($this->storageUrl == false ? '' : rtrim($this->storageUrl, '/')) . $filePath;
return ($this->storageUrl == false ? rtrim(baseUrl(''), '/') : rtrim($this->storageUrl, '/')) . $filePath;
}


Expand Down
7 changes: 4 additions & 3 deletions app/Services/SocialAuthService.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,20 @@ public function handleLoginCallback($socialDriver)
if ($isLoggedIn && $socialAccount === null) {
$this->fillSocialAccount($socialDriver, $socialUser);
$currentUser->socialAccounts()->save($this->socialAccount);
\Session::flash('success', title_case($socialDriver) . ' account was successfully attached to your profile.');
session()->flash('success', title_case($socialDriver) . ' account was successfully attached to your profile.');
return redirect($currentUser->getEditUrl());
}

// When a user is logged in and the social account exists and is already linked to the current user.
if ($isLoggedIn && $socialAccount !== null && $socialAccount->user->id === $currentUser->id) {
\Session::flash('error', 'This ' . title_case($socialDriver) . ' account is already attached to your profile.');
session()->flash('error', 'This ' . title_case($socialDriver) . ' account is already attached to your profile.');
return redirect($currentUser->getEditUrl());
}

// When a user is logged in, A social account exists but the users do not match.
// Change the user that the social account is assigned to.
if ($isLoggedIn && $socialAccount !== null && $socialAccount->user->id != $currentUser->id) {
\Session::flash('success', 'This ' . title_case($socialDriver) . ' account is already used by another user.');
session()->flash('success', 'This ' . title_case($socialDriver) . ' account is already used by another user.');
return redirect($currentUser->getEditUrl());
}

Expand All @@ -135,6 +135,7 @@ public function handleLoginCallback($socialDriver)
if (setting('registration-enabled')) {
$message .= ' or, If you do not yet have an account, You can register an account using the ' . $socialDriver . ' option';
}

throw new SocialSignInException($message . '.', '/#');
}

Expand Down
15 changes: 12 additions & 3 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ public function hasSocialAccount($socialDriver = false)
*/
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));
}

/**
Expand All @@ -157,7 +157,16 @@ public function avatar()
*/
public function getEditUrl()
{
return '/settings/users/' . $this->id;
return baseUrl('/settings/users/' . $this->id);
}

/**
* Get the url that links to this user's profile.
* @return mixed
*/
public function getProfileUrl()
{
return baseUrl('/user/' . $this->id);
}

/**
Expand Down
Loading

0 comments on commit d2a5ab4

Please # to comment.