Skip to content

Commit e99507d

Browse files
committed
Merge branch 'master' into release
2 parents d2cacf1 + 2a4ff6f commit e99507d

60 files changed

Lines changed: 1671 additions & 535 deletions

Some content is hidden

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

.env.example

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,28 @@ CACHE_DRIVER=file
1414
SESSION_DRIVER=file
1515
QUEUE_DRIVER=sync
1616

17+
# Storage
18+
STORAGE_TYPE=local
19+
# Amazon S3 Config
20+
STORAGE_S3_KEY=false
21+
STORAGE_S3_SECRET=false
22+
STORAGE_S3_REGION=false
23+
STORAGE_S3_BUCKET=false
24+
# Storage URL
25+
# Used to prefix image urls for when using custom domains/cdns
26+
STORAGE_URL=false
27+
1728
# Social Authentication information. Defaults as off.
1829
GITHUB_APP_ID=false
1930
GITHUB_APP_SECRET=false
2031
GOOGLE_APP_ID=false
2132
GOOGLE_APP_SECRET=false
22-
# URL for social login redirects, NO TRAILING SLASH
33+
# URL used for social login redirects, NO TRAILING SLASH
2334
APP_URL=http://bookstack.dev
2435

36+
# External services
37+
USE_GRAVATAR=true
38+
2539
# Mail settings
2640
MAIL_DRIVER=smtp
2741
MAIL_HOST=localhost

app/Entity.php

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,7 @@
77
abstract class Entity extends Model
88
{
99

10-
/**
11-
* Relation for the user that created this entity.
12-
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
13-
*/
14-
public function createdBy()
15-
{
16-
return $this->belongsTo('BookStack\User', 'created_by');
17-
}
18-
19-
/**
20-
* Relation for the user that updated this entity.
21-
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
22-
*/
23-
public function updatedBy()
24-
{
25-
return $this->belongsTo('BookStack\User', 'updated_by');
26-
}
10+
use Ownable;
2711

2812
/**
2913
* Compares this entity to another given entity.
@@ -97,18 +81,29 @@ public function userViews()
9781
*/
9882
public static function isA($type)
9983
{
100-
return static::getName() === strtolower($type);
84+
return static::getClassName() === strtolower($type);
10185
}
10286

10387
/**
10488
* Gets the class name.
10589
* @return string
10690
*/
107-
public static function getName()
91+
public static function getClassName()
10892
{
10993
return strtolower(array_slice(explode('\\', static::class), -1, 1)[0]);
11094
}
11195

96+
/**
97+
*Gets a limited-length version of the entities name.
98+
* @param int $length
99+
* @return string
100+
*/
101+
public function getShortName($length = 25)
102+
{
103+
if(strlen($this->name) <= $length) return $this->name;
104+
return substr($this->name, 0, $length-3) . '...';
105+
}
106+
112107
/**
113108
* Perform a full-text search on this entity.
114109
* @param string[] $fieldsToSearch
@@ -123,20 +118,20 @@ public static function fullTextSearch($fieldsToSearch, $terms, $wheres = [])
123118
$termString .= $term . '* ';
124119
}
125120
$fields = implode(',', $fieldsToSearch);
126-
$search = static::whereRaw('MATCH(' . $fields . ') AGAINST(? IN BOOLEAN MODE)', [$termString]);
121+
$termStringEscaped = \DB::connection()->getPdo()->quote($termString);
122+
$search = static::addSelect(\DB::raw('*, MATCH(name) AGAINST('.$termStringEscaped.' IN BOOLEAN MODE) AS title_relevance'));
123+
$search = $search->whereRaw('MATCH(' . $fields . ') AGAINST(? IN BOOLEAN MODE)', [$termString]);
124+
125+
// Add additional where terms
127126
foreach ($wheres as $whereTerm) {
128127
$search->where($whereTerm[0], $whereTerm[1], $whereTerm[2]);
129128
}
130129

131-
if (!static::isA('book')) {
132-
$search = $search->with('book');
133-
}
134-
135-
if (static::isA('page')) {
136-
$search = $search->with('chapter');
137-
}
130+
// Load in relations
131+
if (!static::isA('book')) $search = $search->with('book');
132+
if (static::isA('page')) $search = $search->with('chapter');
138133

139-
return $search->get();
134+
return $search->orderBy('title_relevance', 'desc')->get();
140135
}
141136

142137
/**

app/Http/Controllers/BookController.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ public function __construct(BookRepo $bookRepo, PageRepo $pageRepo, ChapterRepo
4242
public function index()
4343
{
4444
$books = $this->bookRepo->getAllPaginated(10);
45-
$recents = $this->signedIn ? $this->bookRepo->getRecentlyViewed(10, 0) : false;
46-
return view('books/index', ['books' => $books, 'recents' => $recents]);
45+
$recents = $this->signedIn ? $this->bookRepo->getRecentlyViewed(4, 0) : false;
46+
$popular = $this->bookRepo->getPopular(4, 0);
47+
$this->setPageTitle('Books');
48+
return view('books/index', ['books' => $books, 'recents' => $recents, 'popular' => $popular]);
4749
}
4850

4951
/**
@@ -54,6 +56,7 @@ public function index()
5456
public function create()
5557
{
5658
$this->checkPermission('book-create');
59+
$this->setPageTitle('Create New Book');
5760
return view('books/create');
5861
}
5962

@@ -88,8 +91,9 @@ public function store(Request $request)
8891
public function show($slug)
8992
{
9093
$book = $this->bookRepo->getBySlug($slug);
91-
Views::add($book);
9294
$bookChildren = $this->bookRepo->getChildren($book);
95+
Views::add($book);
96+
$this->setPageTitle($book->getShortName());
9397
return view('books/show', ['book' => $book, 'current' => $book, 'bookChildren' => $bookChildren]);
9498
}
9599

@@ -103,6 +107,7 @@ public function edit($slug)
103107
{
104108
$this->checkPermission('book-update');
105109
$book = $this->bookRepo->getBySlug($slug);
110+
$this->setPageTitle('Edit Book ' . $book->getShortName());
106111
return view('books/edit', ['book' => $book, 'current' => $book]);
107112
}
108113

@@ -138,6 +143,7 @@ public function showDelete($bookSlug)
138143
{
139144
$this->checkPermission('book-delete');
140145
$book = $this->bookRepo->getBySlug($bookSlug);
146+
$this->setPageTitle('Delete Book ' . $book->getShortName());
141147
return view('books/delete', ['book' => $book, 'current' => $book]);
142148
}
143149

@@ -152,9 +158,16 @@ public function sort($bookSlug)
152158
$book = $this->bookRepo->getBySlug($bookSlug);
153159
$bookChildren = $this->bookRepo->getChildren($book);
154160
$books = $this->bookRepo->getAll();
161+
$this->setPageTitle('Sort Book ' . $book->getShortName());
155162
return view('books/sort', ['book' => $book, 'current' => $book, 'books' => $books, 'bookChildren' => $bookChildren]);
156163
}
157164

165+
/**
166+
* Shows the sort box for a single book.
167+
* Used via AJAX when loading in extra books to a sort.
168+
* @param $bookSlug
169+
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
170+
*/
158171
public function getSortItem($bookSlug)
159172
{
160173
$book = $this->bookRepo->getBySlug($bookSlug);

app/Http/Controllers/ChapterController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function create($bookSlug)
4040
{
4141
$this->checkPermission('chapter-create');
4242
$book = $this->bookRepo->getBySlug($bookSlug);
43+
$this->setPageTitle('Create New Chapter');
4344
return view('chapters/create', ['book' => $book, 'current' => $book]);
4445
}
4546

@@ -79,6 +80,7 @@ public function show($bookSlug, $chapterSlug)
7980
$chapter = $this->chapterRepo->getBySlug($chapterSlug, $book->id);
8081
$sidebarTree = $this->bookRepo->getChildren($book);
8182
Views::add($chapter);
83+
$this->setPageTitle($chapter->getShortName());
8284
return view('chapters/show', ['book' => $book, 'chapter' => $chapter, 'current' => $chapter, 'sidebarTree' => $sidebarTree]);
8385
}
8486

@@ -93,6 +95,7 @@ public function edit($bookSlug, $chapterSlug)
9395
$this->checkPermission('chapter-update');
9496
$book = $this->bookRepo->getBySlug($bookSlug);
9597
$chapter = $this->chapterRepo->getBySlug($chapterSlug, $book->id);
98+
$this->setPageTitle('Edit Chapter' . $chapter->getShortName());
9699
return view('chapters/edit', ['book' => $book, 'chapter' => $chapter, 'current' => $chapter]);
97100
}
98101

@@ -127,6 +130,7 @@ public function showDelete($bookSlug, $chapterSlug)
127130
$this->checkPermission('chapter-delete');
128131
$book = $this->bookRepo->getBySlug($bookSlug);
129132
$chapter = $this->chapterRepo->getBySlug($chapterSlug, $book->id);
133+
$this->setPageTitle('Delete Chapter' . $chapter->getShortName());
130134
return view('chapters/delete', ['book' => $book, 'chapter' => $chapter, 'current' => $chapter]);
131135
}
132136

app/Http/Controllers/Controller.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ public function __construct()
4242
$this->signedIn = auth()->check();
4343
}
4444

45+
/**
46+
* Adds the page title into the view.
47+
* @param $title
48+
*/
49+
public function setPageTitle($title)
50+
{
51+
view()->share('pageTitle', $title);
52+
}
53+
4554
/**
4655
* Checks for a permission.
4756
*

0 commit comments

Comments
 (0)