use BookStack\Repos\BookRepo;
use BookStack\Repos\ChapterRepo;
use BookStack\Repos\PageRepo;
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Views;
class PageController extends Controller
/**
* Display the specified page.
+ * If the page is not found via the slug the
+ * revisions are searched for a match.
*
* @param $bookSlug
* @param $pageSlug
public function show($bookSlug, $pageSlug)
{
$book = $this->bookRepo->getBySlug($bookSlug);
- $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
+
+ try {
+ $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
+ } catch (NotFoundHttpException $e) {
+ $page = $this->pageRepo->findPageUsingOldSlug($pageSlug, $bookSlug);
+ if ($page === null) abort(404);
+ return redirect($page->getUrl());
+ }
+
$sidebarTree = $this->bookRepo->getChildren($book);
Views::add($page);
$this->setPageTitle($page->getShortName());
return redirect($page->getUrl());
}
+ /**
+ * Exports a page to pdf format using barryvdh/laravel-dompdf wrapper.
+ * https://github.com/barryvdh/laravel-dompdf
+ * @param $bookSlug
+ * @param $pageSlug
+ * @return \Illuminate\Http\Response
+ */
public function exportPdf($bookSlug, $pageSlug)
{
$book = $this->bookRepo->getBySlug($bookSlug);
$page = $this->pageRepo->getBySlug($pageSlug, $book->id);
- $cssContent = file_get_contents(public_path('/css/styles.css'));
-
- return $pdf->download($pageSlug . '.pdf');
+ $pdfContent = $this->exportService->pageToPdf($page);
+ return response()->make($pdfContent, 200, [
+ 'Content-Type' => 'application/octet-stream',
+ 'Content-Disposition' => 'attachment; filename="'.$pageSlug.'.pdf'
+ ]);
}
/**
'Content-Disposition' => 'attachment; filename="'.$pageSlug.'.html'
]);
}
+
+ /**
+ * Export a page to a simple plaintext .txt file.
+ * @param $bookSlug
+ * @param $pageSlug
+ * @return \Illuminate\Http\Response
+ */
+ public function exportPlainText($bookSlug, $pageSlug)
+ {
+ $book = $this->bookRepo->getBySlug($bookSlug);
+ $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
+ $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);
+ return view('pages/detailed-listing', [
+ 'title' => '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);
+ return view('pages/detailed-listing', [
+ 'title' => 'Recently Updated Pages',
+ 'pages' => $pages
+ ]);
+ }
+
}