Skip to content

Commit c6134d1

Browse files
committed
Merge branch 'master' into release
2 parents 2046f9b + 4f78838 commit c6134d1

File tree

215 files changed

+11633
-6004
lines changed

Some content is hidden

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

215 files changed

+11633
-6004
lines changed

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ SESSION_DRIVER=file
2020
#CACHE_DRIVER=memcached
2121
#SESSION_DRIVER=memcached
2222
QUEUE_DRIVER=sync
23+
# A different prefix is useful when multiple BookStack instances use the same caching server
24+
CACHE_PREFIX=bookstack
2325

2426
# Memcached settings
2527
# If using a UNIX socket path for the host, set the port to 0
@@ -73,3 +75,5 @@ MAIL_PORT=1025
7375
MAIL_USERNAME=null
7476
MAIL_PASSWORD=null
7577
MAIL_ENCRYPTION=null
78+
MAIL_FROM=null
79+
MAIL_FROM_NAME=null

app/Book.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
class Book extends Entity
44
{
5+
public $searchFactor = 2;
56

67
protected $fillable = ['name', 'description', 'image_id'];
78

app/Chapter.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
class Chapter extends Entity
44
{
5+
public $searchFactor = 1.3;
6+
57
protected $fillable = ['name', 'description', 'priority', 'book_id'];
68

79
protected $with = ['book'];

app/Entity.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,16 @@
55
class Entity extends Ownable
66
{
77

8+
/**
9+
* @var string - Name of property where the main text content is found
10+
*/
811
public $textField = 'description';
912

13+
/**
14+
* @var float - Multiplier for search indexing.
15+
*/
16+
public $searchFactor = 1.0;
17+
1018
/**
1119
* Compares this entity to another given entity.
1220
* Matches by comparing class and id.
@@ -193,4 +201,5 @@ public function getUrl($path)
193201
{
194202
return '/';
195203
}
204+
196205
}

app/Http/Controllers/HomeController.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use Activity;
44
use BookStack\Repos\EntityRepo;
5+
use Illuminate\Http\Request;
56
use Illuminate\Http\Response;
67
use Views;
78

@@ -88,6 +89,27 @@ public function getTranslations()
8889
]);
8990
}
9091

92+
/**
93+
* Get an icon via image request.
94+
* Can provide a 'color' parameter with hex value to color the icon.
95+
* @param $iconName
96+
* @param Request $request
97+
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
98+
*/
99+
public function getIcon($iconName, Request $request)
100+
{
101+
$attrs = [];
102+
if ($request->filled('color')) {
103+
$attrs['fill'] = '#' . $request->get('color');
104+
}
105+
106+
$icon = icon($iconName, $attrs);
107+
return response($icon, 200, [
108+
'Content-Type' => 'image/svg+xml',
109+
'Cache-Control' => 'max-age=3600',
110+
]);
111+
}
112+
91113
/**
92114
* Get custom head HTML, Used in ajax calls to show in editor.
93115
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View

app/Http/Controllers/ImageController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ public function uploadByType($type, Request $request)
136136
return response($e->getMessage(), 500);
137137
}
138138

139+
139140
return response()->json($image);
140141
}
141142

app/Http/Controllers/SearchController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,12 @@ public function search(Request $request)
4040
$nextPageLink = baseUrl('/search?term=' . urlencode($searchTerm) . '&page=' . ($page+1));
4141

4242
$results = $this->searchService->searchEntities($searchTerm, 'all', $page, 20);
43-
$hasNextPage = $this->searchService->searchEntities($searchTerm, 'all', $page+1, 20)['count'] > 0;
4443

4544
return view('search/all', [
4645
'entities' => $results['results'],
4746
'totalResults' => $results['total'],
4847
'searchTerm' => $searchTerm,
49-
'hasNextPage' => $hasNextPage,
48+
'hasNextPage' => $results['has_more'],
5049
'nextPageLink' => $nextPageLink
5150
]);
5251
}

app/Repos/EntityRepo.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,10 @@ protected function formatHtml($htmlText)
713713
public function renderPage(Page $page, $ignorePermissions = false)
714714
{
715715
$content = $page->html;
716+
if (!config('app.allow_content_scripts')) {
717+
$content = $this->escapeScripts($content);
718+
}
719+
716720
$matches = [];
717721
preg_match_all("/{{@\s?([0-9].*?)}}/", $content, $matches);
718722
if (count($matches[0]) === 0) {
@@ -760,6 +764,24 @@ public function renderPage(Page $page, $ignorePermissions = false)
760764
return $content;
761765
}
762766

767+
/**
768+
* Escape script tags within HTML content.
769+
* @param string $html
770+
* @return mixed
771+
*/
772+
protected function escapeScripts(string $html)
773+
{
774+
$scriptSearchRegex = '/<script.*?>.*?<\/script>/ms';
775+
$matches = [];
776+
preg_match_all($scriptSearchRegex, $html, $matches);
777+
if (count($matches) === 0) return $html;
778+
779+
foreach ($matches[0] as $match) {
780+
$html = str_replace($match, htmlentities($match), $html);
781+
}
782+
return $html;
783+
}
784+
763785
/**
764786
* Get the plain text version of a page's content.
765787
* @param Page $page

app/Repos/ImageRepo.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ public function getThumbnail(Image $image, $width = 220, $height = 220, $keepRat
225225
try {
226226
return $this->imageService->getThumbnail($image, $width, $height, $keepRatio);
227227
} catch (\Exception $exception) {
228-
dd($exception);
229228
return null;
230229
}
231230
}

app/Services/AttachmentService.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,14 @@ class AttachmentService extends UploadService
1414
*/
1515
protected function getStorage()
1616
{
17-
if ($this->storageInstance !== null) {
18-
return $this->storageInstance;
19-
}
20-
2117
$storageType = config('filesystems.default');
2218

2319
// Override default location if set to local public to ensure not visible.
2420
if ($storageType === 'local') {
2521
$storageType = 'local_secure';
2622
}
2723

28-
$this->storageInstance = $this->fileSystem->disk($storageType);
29-
30-
return $this->storageInstance;
24+
return $this->fileSystem->disk($storageType);
3125
}
3226

3327
/**

0 commit comments

Comments
 (0)