3 namespace BookStack\Http\Controllers;
6 use BookStack\Repos\EntityRepo;
7 use BookStack\Http\Requests;
8 use Illuminate\Http\Response;
11 class HomeController extends Controller
13 protected $entityRepo;
16 * HomeController constructor.
17 * @param EntityRepo $entityRepo
19 public function __construct(EntityRepo $entityRepo)
21 $this->entityRepo = $entityRepo;
22 parent::__construct();
27 * Display the homepage.
30 public function index()
32 $activity = Activity::latest(10);
33 $draftPages = $this->signedIn ? $this->entityRepo->getUserDraftPages(6) : [];
34 $recentFactor = count($draftPages) > 0 ? 0.5 : 1;
35 $recents = $this->signedIn ? Views::getUserRecentlyViewed(12*$recentFactor, 0) : $this->entityRepo->getRecentlyCreated('book', 10*$recentFactor);
36 $recentlyCreatedPages = $this->entityRepo->getRecentlyCreated('page', 5);
37 $recentlyUpdatedPages = $this->entityRepo->getRecentlyUpdated('page', 5);
39 'activity' => $activity,
40 'recents' => $recents,
41 'recentlyCreatedPages' => $recentlyCreatedPages,
42 'recentlyUpdatedPages' => $recentlyUpdatedPages,
43 'draftPages' => $draftPages
48 * Get a js representation of the current translations
49 * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
51 public function getTranslations() {
52 $locale = trans()->getLocale();
53 $cacheKey = 'GLOBAL_TRANSLATIONS_' . $locale;
54 if (cache()->has($cacheKey) && config('app.env') !== 'development') {
55 $resp = cache($cacheKey);
58 // Get only translations which might be used in JS
59 'common' => trans('common'),
60 'components' => trans('components'),
61 'entities' => trans('entities'),
62 'errors' => trans('errors')
64 if ($locale !== 'en') {
66 'common' => trans('common', [], null, 'en'),
67 'components' => trans('components', [], null, 'en'),
68 'entities' => trans('entities', [], null, 'en'),
69 'errors' => trans('errors', [], null, 'en')
71 $translations = array_replace_recursive($enTrans, $translations);
73 $resp = 'window.translations = ' . json_encode($translations);
74 cache()->put($cacheKey, $resp, 120);
77 return response($resp, 200, [
78 'Content-Type' => 'application/javascript'