3 namespace BookStack\Http\Controllers;
6 use BookStack\Repos\EntityRepo;
7 use BookStack\Http\Requests;
10 class HomeController extends Controller
12 protected $entityRepo;
15 * HomeController constructor.
16 * @param EntityRepo $entityRepo
18 public function __construct(EntityRepo $entityRepo)
20 $this->entityRepo = $entityRepo;
21 parent::__construct();
26 * Display the homepage.
29 public function index()
31 $activity = Activity::latest(10);
32 $draftPages = $this->signedIn ? $this->entityRepo->getUserDraftPages(6) : [];
33 $recentFactor = count($draftPages) > 0 ? 0.5 : 1;
34 $recents = $this->signedIn ? Views::getUserRecentlyViewed(12*$recentFactor, 0) : $this->entityRepo->getRecentlyCreatedBooks(10*$recentFactor);
35 $recentlyCreatedPages = $this->entityRepo->getRecentlyCreatedPages(5);
36 $recentlyUpdatedPages = $this->entityRepo->getRecentlyUpdatedPages(5);
38 'activity' => $activity,
39 'recents' => $recents,
40 'recentlyCreatedPages' => $recentlyCreatedPages,
41 'recentlyUpdatedPages' => $recentlyUpdatedPages,
42 'draftPages' => $draftPages
47 * Get a js representation of the current translations
48 * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
50 public function getTranslations() {
51 $locale = trans()->getLocale();
52 $cacheKey = 'GLOBAL_TRANSLATIONS_' . $locale;
53 if (cache()->has($cacheKey) && config('app.env') !== 'development') {
54 $resp = cache($cacheKey);
57 // Get only translations which might be used in JS
58 'common' => trans('common'),
59 'components' => trans('components'),
60 'entities' => trans('entities'),
61 'errors' => trans('errors')
63 if ($locale !== 'en') {
65 'common' => trans('common', [], null, 'en'),
66 'components' => trans('components', [], null, 'en'),
67 'entities' => trans('entities', [], null, 'en'),
68 'errors' => trans('errors', [], null, 'en')
70 $translations = array_replace_recursive($enTrans, $translations);
72 $resp = 'window.translations = ' . json_encode($translations);
73 cache()->put($cacheKey, $resp, 120);
76 return response($resp, 200, [
77 'Content-Type' => 'application/javascript'