+ $containedHtml = $this->exportService->pageToPlainText($page);
+ return response()->make($containedHtml, 200, [
+ 'Content-Type' => 'application/octet-stream',
+ 'Content-Disposition' => 'attachment; filename="' . $pageSlug . '.txt'
+ ]);
+ }
+
+ /**
+ * Show a listing of recently created pages
+ * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
+ */
+ public function showRecentlyCreated()
+ {
+ $pages = $this->pageRepo->getRecentlyCreatedPaginated(20)->setPath(baseUrl('/pages/recently-created'));
+ return view('pages/detailed-listing', [
+ 'title' => trans('entities.recently_created_pages'),
+ 'pages' => $pages
+ ]);
+ }
+
+ /**
+ * Show a listing of recently created pages
+ * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
+ */
+ public function showRecentlyUpdated()
+ {
+ $pages = $this->pageRepo->getRecentlyUpdatedPaginated(20)->setPath(baseUrl('/pages/recently-updated'));
+ return view('pages/detailed-listing', [
+ 'title' => trans('entities.recently_updated_pages'),
+ 'pages' => $pages
+ ]);
+ }
+
+ /**
+ * Show the Restrictions view.
+ * @param string $bookSlug
+ * @param string $pageSlug
+ * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
+ */
+ public function showRestrict($bookSlug, $pageSlug)
+ {
+ $book = $this->bookRepo->getBySlug($bookSlug);
+ $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
+ $this->checkOwnablePermission('restrictions-manage', $page);
+ $roles = $this->userRepo->getRestrictableRoles();
+ return view('pages/restrictions', [
+ 'page' => $page,
+ 'roles' => $roles
+ ]);
+ }
+
+ /**
+ * Show the view to choose a new parent to move a page into.
+ * @param string $bookSlug
+ * @param string $pageSlug
+ * @return mixed
+ * @throws NotFoundException
+ */
+ public function showMove($bookSlug, $pageSlug)
+ {
+ $book = $this->bookRepo->getBySlug($bookSlug);
+ $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
+ $this->checkOwnablePermission('page-update', $page);
+ return view('pages/move', [
+ 'book' => $book,
+ 'page' => $page
+ ]);
+ }
+
+ /**
+ * Does the action of moving the location of a page
+ * @param string $bookSlug
+ * @param string $pageSlug
+ * @param Request $request
+ * @return mixed
+ * @throws NotFoundException
+ */
+ public function move($bookSlug, $pageSlug, Request $request)
+ {
+ $book = $this->bookRepo->getBySlug($bookSlug);
+ $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
+ $this->checkOwnablePermission('page-update', $page);
+
+ $entitySelection = $request->get('entity_selection', null);
+ if ($entitySelection === null || $entitySelection === '') {
+ return redirect($page->getUrl());
+ }
+
+ $stringExploded = explode(':', $entitySelection);
+ $entityType = $stringExploded[0];
+ $entityId = intval($stringExploded[1]);
+
+ $parent = false;
+
+ if ($entityType == 'chapter') {
+ $parent = $this->chapterRepo->getById($entityId);
+ } else if ($entityType == 'book') {
+ $parent = $this->bookRepo->getById($entityId);
+ }
+
+ if ($parent === false || $parent === null) {
+ session()->flash(trans('entities.selected_book_chapter_not_found'));
+ return redirect()->back();
+ }
+
+ $this->pageRepo->changePageParent($page, $parent);
+ Activity::add($page, 'page_move', $page->book->id);
+ session()->flash('success', trans('entities.pages_move_success', ['parentName' => $parent->name]));
+
+ return redirect($page->getUrl());
+ }
+
+ /**
+ * Set the permissions for this page.
+ * @param string $bookSlug
+ * @param string $pageSlug
+ * @param Request $request
+ * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
+ */
+ public function restrict($bookSlug, $pageSlug, Request $request)
+ {
+ $book = $this->bookRepo->getBySlug($bookSlug);
+ $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
+ $this->checkOwnablePermission('restrictions-manage', $page);
+ $this->pageRepo->updateEntityPermissionsFromRequest($request, $page);
+ session()->flash('success', trans('entities.pages_permissions_success'));
+ return redirect($page->getUrl());