1 <?php namespace BookStack\Http\Controllers;
4 use BookStack\Repos\EntityRepo;
5 use Illuminate\Http\Response;
8 class HomeController extends Controller
10 protected $entityRepo;
13 * HomeController constructor.
14 * @param EntityRepo $entityRepo
16 public function __construct(EntityRepo $entityRepo)
18 $this->entityRepo = $entityRepo;
19 parent::__construct();
24 * Display the homepage.
27 public function index()
29 $activity = Activity::latest(10);
30 $draftPages = $this->signedIn ? $this->entityRepo->getUserDraftPages(6) : [];
31 $recentFactor = count($draftPages) > 0 ? 0.5 : 1;
32 $recents = $this->signedIn ? Views::getUserRecentlyViewed(12*$recentFactor, 0) : $this->entityRepo->getRecentlyCreated('book', 12*$recentFactor);
33 $recentlyUpdatedPages = $this->entityRepo->getRecentlyUpdated('page', 12);
35 'activity' => $activity,
36 'recents' => $recents,
37 'recentlyUpdatedPages' => $recentlyUpdatedPages,
38 'draftPages' => $draftPages
43 * Get a js representation of the current translations
44 * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
46 public function getTranslations() {
47 $locale = app()->getLocale();
48 $cacheKey = 'GLOBAL_TRANSLATIONS_' . $locale;
49 if (cache()->has($cacheKey) && config('app.env') !== 'development') {
50 $resp = cache($cacheKey);
53 // Get only translations which might be used in JS
54 'common' => trans('common'),
55 'components' => trans('components'),
56 'entities' => trans('entities'),
57 'errors' => trans('errors')
59 if ($locale !== 'en') {
61 'common' => trans('common', [], 'en'),
62 'components' => trans('components', [], 'en'),
63 'entities' => trans('entities', [], 'en'),
64 'errors' => trans('errors', [], 'en')
66 $translations = array_replace_recursive($enTrans, $translations);
68 $resp = 'window.translations = ' . json_encode($translations);
69 cache()->put($cacheKey, $resp, 120);
72 return response($resp, 200, [
73 'Content-Type' => 'application/javascript'