forked from BookStackApp/BookStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomeController.php
More file actions
119 lines (98 loc) · 3.97 KB
/
Copy pathHomeController.php
File metadata and controls
119 lines (98 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
namespace BookStack\Http\Controllers;
use BookStack\Actions\ActivityQueries;
use BookStack\Entities\BasicListItem;
use BookStack\Entities\Models\Book;
use BookStack\Entities\Models\Bookshelf;
use BookStack\Entities\Models\Page;
use BookStack\Uploads\FaviconHandler;
use Illuminate\Http\Request;
class HomeController extends Controller
{
/**
* Display the homepage.
*/
public function index(Request $request, ActivityQueries $activities)
{
$activeUsers = $activities->recentlyActiveUsers(3);
$newSymbols = Page::getVisiblePagesInBookshelf('symbols')
->orderBy('created_at', 'desc')
->take(10)
// ->select(Page::$listAtt ributes)
->get();
$latestDrafts = Page::getVisiblePagesInBookshelf('contribute')
->where('book_id', '=', Book::getBySlug('drafts', true)->id)
->orderBy('created_at', 'desc')
->take(3)
// ->select(Page::$listAttributes)
->get();
$draftHelp = Page::getVisiblePagesInBookshelf('contribute')
->where('book_id', '=', Book::getBySlug('draft-help', true)->id)
->orderBy('created_at', 'desc');
$communityReviews = Page::getVisiblePagesInBookshelf('contribute')
->where('book_id', '=', Book::getBySlug('community-review', true)->id)
->orderBy('created_at', 'desc');
$quickLinks = collect([
new BasicListItem('/shelves/symbols', 'All Symbols', 'See all of the official symbols', 'star-circle'),
new BasicListItem(env('TASK_MANAGER_URL', null), 'SymbolHub', 'Find new symbols to add', 'symbolhub'),
new BasicListItem('/books/general', 'Help', 'Learn how to use Symbolpedia!', 'info'),
...Bookshelf::getBySlug('contribute')->visibleBooks()->get()->all(),
]);
$recentUpdates = Page::getVisiblePagesInBookshelf('symbols')
->orderBy('updated_at', 'desc')
->where('revision_count', '>', 1)
->take(3)
->select(Page::$listAttributes)
->get();
$symbolTypesList = Bookshelf::getBySlug('symbols', true)->visibleBooks()->get();
$homepageOptions = ['default', 'books', 'bookshelves', 'page'];
$homepageOption = setting('app-homepage-type', 'default');
if (!in_array($homepageOption, $homepageOptions)) {
$homepageOption = 'default';
}
$commonData = [
'activeUsers' => $activeUsers,
'latestDrafts' => $latestDrafts,
'latestCommunityReviews' => $communityReviews->take(3)->get(),
'numCommunityReviews' => $communityReviews->count(),
'latestDraftHelp' => $draftHelp->take(3)->get(),
'numDraftHelp' => $draftHelp->count(),
'newSymbols' => $newSymbols,
'quickLinks' => $quickLinks,
'symbolTypesList' => $symbolTypesList,
'recentUpdates' => $recentUpdates,
];
return view('home.default', $commonData);
}
/**
* Show the view for /robots.txt.
*/
public function robots()
{
$sitePublic = setting('app-public', false);
$allowRobots = config('app.allow_robots');
if ($allowRobots === null) {
$allowRobots = $sitePublic;
}
return response()
->view('misc.robots', ['allowRobots' => $allowRobots])
->header('Content-Type', 'text/plain');
}
/**
* Show the route for 404 responses.
*/
public function notFound()
{
return response()->view('errors.404', [], 404);
}
/**
* Serve the application favicon.
* Ensures a 'favicon.ico' file exists at the web root location (if writable) to be served
* directly by the webserver in the future.
*/
public function favicon(FaviconHandler $favicons)
{
$exists = $favicons->restoreOriginalIfNotExists();
return response()->file($exists ? $favicons->getPath() : $favicons->getOriginalPath());
}
}