protected $entityRepo;
protected $userRepo;
- protected $exportService;
protected $entityContextManager;
protected $imageRepo;
* BookController constructor.
* @param EntityRepo $entityRepo
* @param UserRepo $userRepo
- * @param ExportService $exportService
* @param EntityContextManager $entityContextManager
* @param ImageRepo $imageRepo
*/
public function __construct(
EntityRepo $entityRepo,
UserRepo $userRepo,
- ExportService $exportService,
EntityContextManager $entityContextManager,
ImageRepo $imageRepo
) {
$this->entityRepo = $entityRepo;
$this->userRepo = $userRepo;
- $this->exportService = $exportService;
$this->entityContextManager = $entityContextManager;
$this->imageRepo = $imageRepo;
parent::__construct();
return redirect($book->getUrl());
}
- /**
- * Export a book as a PDF file.
- * @param string $bookSlug
- * @return mixed
- */
- public function exportPdf($bookSlug)
- {
- $book = $this->entityRepo->getBySlug('book', $bookSlug);
- $pdfContent = $this->exportService->bookToPdf($book);
- return $this->downloadResponse($pdfContent, $bookSlug . '.pdf');
- }
-
- /**
- * Export a book as a contained HTML file.
- * @param string $bookSlug
- * @return mixed
- */
- public function exportHtml($bookSlug)
- {
- $book = $this->entityRepo->getBySlug('book', $bookSlug);
- $htmlContent = $this->exportService->bookToContainedHtml($book);
- return $this->downloadResponse($htmlContent, $bookSlug . '.html');
- }
-
- /**
- * Export a book as a plain text file.
- * @param $bookSlug
- * @return mixed
- */
- public function exportPlainText($bookSlug)
- {
- $book = $this->entityRepo->getBySlug('book', $bookSlug);
- $textContent = $this->exportService->bookToPlainText($book);
- return $this->downloadResponse($textContent, $bookSlug . '.txt');
- }
-
/**
* Common actions to run on book update.
* Handles updating the cover image.
--- /dev/null
+<?php
+
+namespace BookStack\Http\Controllers;
+
+use BookStack\Entities\ExportService;
+use BookStack\Entities\Repos\EntityRepo;
+use BookStack\Exceptions\NotFoundException;
+use Throwable;
+
+class BookExportController extends Controller
+{
+ /**
+ * @var EntityRepo
+ */
+ protected $entityRepo;
+
+ /**
+ * @var ExportService
+ */
+ protected $exportService;
+
+ /**
+ * BookExportController constructor.
+ * @param EntityRepo $entityRepo
+ * @param ExportService $exportService
+ */
+ public function __construct(EntityRepo $entityRepo, ExportService $exportService)
+ {
+ $this->entityRepo = $entityRepo;
+ $this->exportService = $exportService;
+ parent::__construct();
+ }
+
+ /**
+ * Export a book as a PDF file.
+ * @param string $bookSlug
+ * @return mixed
+ * @throws NotFoundException
+ * @throws Throwable
+ */
+ public function pdf(string $bookSlug)
+ {
+ $book = $this->entityRepo->getBySlug('book', $bookSlug);
+ $pdfContent = $this->exportService->bookToPdf($book);
+ return $this->downloadResponse($pdfContent, $bookSlug . '.pdf');
+ }
+
+ /**
+ * Export a book as a contained HTML file.
+ * @param string $bookSlug
+ * @return mixed
+ * @throws NotFoundException
+ * @throws Throwable
+ */
+ public function html(string $bookSlug)
+ {
+ $book = $this->entityRepo->getBySlug('book', $bookSlug);
+ $htmlContent = $this->exportService->bookToContainedHtml($book);
+ return $this->downloadResponse($htmlContent, $bookSlug . '.html');
+ }
+
+ /**
+ * Export a book as a plain text file.
+ * @param $bookSlug
+ * @return mixed
+ * @throws NotFoundException
+ */
+ public function plainText(string $bookSlug)
+ {
+ $book = $this->entityRepo->getBySlug('book', $bookSlug);
+ $textContent = $this->exportService->bookToPlainText($book);
+ return $this->downloadResponse($textContent, $bookSlug . '.txt');
+ }
+}
protected $userRepo;
protected $entityRepo;
- protected $exportService;
/**
* ChapterController constructor.
* @param EntityRepo $entityRepo
* @param UserRepo $userRepo
- * @param \BookStack\Entities\ExportService $exportService
*/
- public function __construct(EntityRepo $entityRepo, UserRepo $userRepo, ExportService $exportService)
+ public function __construct(EntityRepo $entityRepo, UserRepo $userRepo)
{
$this->entityRepo = $entityRepo;
$this->userRepo = $userRepo;
- $this->exportService = $exportService;
parent::__construct();
}
session()->flash('success', trans('entities.chapters_permissions_success'));
return redirect($chapter->getUrl());
}
-
- /**
- * Exports a chapter to pdf .
- * @param string $bookSlug
- * @param string $chapterSlug
- * @return \Illuminate\Http\Response
- */
- public function exportPdf($bookSlug, $chapterSlug)
- {
- $chapter = $this->entityRepo->getBySlug('chapter', $chapterSlug, $bookSlug);
- $pdfContent = $this->exportService->chapterToPdf($chapter);
- return $this->downloadResponse($pdfContent, $chapterSlug . '.pdf');
- }
-
- /**
- * Export a chapter to a self-contained HTML file.
- * @param string $bookSlug
- * @param string $chapterSlug
- * @return \Illuminate\Http\Response
- */
- public function exportHtml($bookSlug, $chapterSlug)
- {
- $chapter = $this->entityRepo->getBySlug('chapter', $chapterSlug, $bookSlug);
- $containedHtml = $this->exportService->chapterToContainedHtml($chapter);
- return $this->downloadResponse($containedHtml, $chapterSlug . '.html');
- }
-
- /**
- * Export a chapter to a simple plaintext .txt file.
- * @param string $bookSlug
- * @param string $chapterSlug
- * @return \Illuminate\Http\Response
- */
- public function exportPlainText($bookSlug, $chapterSlug)
- {
- $chapter = $this->entityRepo->getBySlug('chapter', $chapterSlug, $bookSlug);
- $chapterText = $this->exportService->chapterToPlainText($chapter);
- return $this->downloadResponse($chapterText, $chapterSlug . '.txt');
- }
}
--- /dev/null
+<?php
+
+namespace BookStack\Http\Controllers;
+
+use BookStack\Entities\ExportService;
+use BookStack\Entities\Repos\EntityRepo;
+use BookStack\Exceptions\NotFoundException;
+use Illuminate\Http\Response;
+use Throwable;
+
+class ChapterExportController extends Controller
+{
+ /**
+ * @var EntityRepo
+ */
+ protected $entityRepo;
+
+ /**
+ * @var ExportService
+ */
+ protected $exportService;
+
+ /**
+ * ChapterExportController constructor.
+ * @param EntityRepo $entityRepo
+ * @param ExportService $exportService
+ */
+ public function __construct(EntityRepo $entityRepo, ExportService $exportService)
+ {
+ $this->entityRepo = $entityRepo;
+ $this->exportService = $exportService;
+ parent::__construct();
+ }
+
+ /**
+ * Exports a chapter to pdf .
+ * @param string $bookSlug
+ * @param string $chapterSlug
+ * @return Response
+ * @throws NotFoundException
+ * @throws Throwable
+ */
+ public function pdf(string $bookSlug, string $chapterSlug)
+ {
+ $chapter = $this->entityRepo->getBySlug('chapter', $chapterSlug, $bookSlug);
+ $pdfContent = $this->exportService->chapterToPdf($chapter);
+ return $this->downloadResponse($pdfContent, $chapterSlug . '.pdf');
+ }
+
+ /**
+ * Export a chapter to a self-contained HTML file.
+ * @param string $bookSlug
+ * @param string $chapterSlug
+ * @return Response
+ * @throws NotFoundException
+ * @throws Throwable
+ */
+ public function html(string $bookSlug, string $chapterSlug)
+ {
+ $chapter = $this->entityRepo->getBySlug('chapter', $chapterSlug, $bookSlug);
+ $containedHtml = $this->exportService->chapterToContainedHtml($chapter);
+ return $this->downloadResponse($containedHtml, $chapterSlug . '.html');
+ }
+
+ /**
+ * Export a chapter to a simple plaintext .txt file.
+ * @param string $bookSlug
+ * @param string $chapterSlug
+ * @return Response
+ * @throws NotFoundException
+ */
+ public function plainText(string $bookSlug, string $chapterSlug)
+ {
+ $chapter = $this->entityRepo->getBySlug('chapter', $chapterSlug, $bookSlug);
+ $chapterText = $this->exportService->chapterToPlainText($chapter);
+ return $this->downloadResponse($chapterText, $chapterSlug . '.txt');
+ }
+}
use Activity;
use BookStack\Auth\UserRepo;
-use BookStack\Entities\Repos\EntityRepo;
-use BookStack\Entities\ExportService;
use BookStack\Entities\Repos\PageRepo;
use BookStack\Exceptions\NotFoundException;
+use Exception;
use GatherContent\Htmldiff\Htmldiff;
+use Illuminate\Contracts\View\Factory;
+use Illuminate\Http\JsonResponse;
+use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
+use Illuminate\Routing\Redirector;
+use Illuminate\View\View;
+use Throwable;
use Views;
class PageController extends Controller
{
protected $pageRepo;
- protected $exportService;
protected $userRepo;
/**
* PageController constructor.
- * @param \BookStack\Entities\Repos\PageRepo $pageRepo
- * @param \BookStack\Entities\ExportService $exportService
+ * @param PageRepo $pageRepo
* @param UserRepo $userRepo
*/
- public function __construct(PageRepo $pageRepo, ExportService $exportService, UserRepo $userRepo)
+ public function __construct(PageRepo $pageRepo, UserRepo $userRepo)
{
$this->pageRepo = $pageRepo;
- $this->exportService = $exportService;
$this->userRepo = $userRepo;
parent::__construct();
}
* Show form to continue editing a draft page.
* @param string $bookSlug
* @param int $pageId
- * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
+ * @return Factory|View
*/
public function editDraft($bookSlug, $pageId)
{
/**
* Get page from an ajax request.
* @param int $pageId
- * @return \Illuminate\Http\JsonResponse
+ * @return JsonResponse
*/
public function getPageAjax($pageId)
{
* Save a draft update as a revision.
* @param Request $request
* @param int $pageId
- * @return \Illuminate\Http\JsonResponse
+ * @return JsonResponse
*/
public function saveDraft(Request $request, $pageId)
{
* Redirect from a special link url which
* uses the page id rather than the name.
* @param int $pageId
- * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
+ * @return RedirectResponse|Redirector
*/
public function redirectFromLink($pageId)
{
* Show the deletion page for the specified page.
* @param string $bookSlug
* @param string $pageSlug
- * @return \Illuminate\View\View
+ * @return View
*/
public function showDelete($bookSlug, $pageSlug)
{
* Show the deletion page for the specified page.
* @param string $bookSlug
* @param int $pageId
- * @return \Illuminate\View\View
+ * @return View
* @throws NotFoundException
*/
public function showDeleteDraft($bookSlug, $pageId)
* Shows the last revisions for this page.
* @param string $bookSlug
* @param string $pageSlug
- * @return \Illuminate\View\View
+ * @return View
* @throws NotFoundException
*/
public function showRevisions($bookSlug, $pageSlug)
* @param string $bookSlug
* @param string $pageSlug
* @param int $revisionId
- * @return \Illuminate\View\View
+ * @return View
*/
public function showRevision($bookSlug, $pageSlug, $revisionId)
{
* @param string $bookSlug
* @param string $pageSlug
* @param int $revisionId
- * @return \Illuminate\View\View
+ * @return View
*/
public function showRevisionChanges($bookSlug, $pageSlug, $revisionId)
{
* @param string $bookSlug
* @param string $pageSlug
* @param int $revisionId
- * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
+ * @return RedirectResponse|Redirector
*/
public function restoreRevision($bookSlug, $pageSlug, $revisionId)
{
* @param string $bookSlug
* @param string $pageSlug
* @param int $revId
+ * @return RedirectResponse|Redirector
+ *@throws BadRequestException
* @throws NotFoundException
- * @throws BadRequestException
- * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function destroyRevision($bookSlug, $pageSlug, $revId)
{
return redirect($page->getUrl('/revisions'));
}
- /**
- * Exports a page to a PDF.
- * https://github.com/barryvdh/laravel-dompdf
- * @param string $bookSlug
- * @param string $pageSlug
- * @return \Illuminate\Http\Response
- */
- public function exportPdf($bookSlug, $pageSlug)
- {
- $page = $this->pageRepo->getPageBySlug($pageSlug, $bookSlug);
- $page->html = $this->pageRepo->renderPage($page);
- $pdfContent = $this->exportService->pageToPdf($page);
- return $this->downloadResponse($pdfContent, $pageSlug . '.pdf');
- }
-
- /**
- * Export a page to a self-contained HTML file.
- * @param string $bookSlug
- * @param string $pageSlug
- * @return \Illuminate\Http\Response
- */
- public function exportHtml($bookSlug, $pageSlug)
- {
- $page = $this->pageRepo->getPageBySlug($pageSlug, $bookSlug);
- $page->html = $this->pageRepo->renderPage($page);
- $containedHtml = $this->exportService->pageToContainedHtml($page);
- return $this->downloadResponse($containedHtml, $pageSlug . '.html');
- }
-
- /**
- * Export a page to a simple plaintext .txt file.
- * @param string $bookSlug
- * @param string $pageSlug
- * @return \Illuminate\Http\Response
- */
- public function exportPlainText($bookSlug, $pageSlug)
- {
- $page = $this->pageRepo->getPageBySlug($pageSlug, $bookSlug);
- $pageText = $this->exportService->pageToPlainText($page);
- return $this->downloadResponse($pageText, $pageSlug . '.txt');
- }
-
/**
* Show a listing of recently created pages
- * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
+ * @return Factory|View
*/
public function showRecentlyUpdated()
{
* @param string $pageSlug
* @return mixed
* @throws NotFoundException
- * @throws \Throwable
+ * @throws Throwable
*/
public function move(Request $request, string $bookSlug, string $pageSlug)
{
try {
$parent = $this->pageRepo->getById($entityType, $entityId);
- } catch (\Exception $e) {
+ } catch (Exception $e) {
session()->flash(trans('entities.selected_book_chapter_not_found'));
return redirect()->back();
}
* @param string $pageSlug
* @return mixed
* @throws NotFoundException
- * @throws \Throwable
+ * @throws Throwable
*/
public function copy(Request $request, string $bookSlug, string $pageSlug)
{
try {
$parent = $this->pageRepo->getById($entityType, $entityId);
- } catch (\Exception $e) {
+ } catch (Exception $e) {
session()->flash(trans('entities.selected_book_chapter_not_found'));
return redirect()->back();
}
* Show the Permissions view.
* @param string $bookSlug
* @param string $pageSlug
- * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
+ * @return Factory|View
* @throws NotFoundException
*/
public function showPermissions($bookSlug, $pageSlug)
* @param string $bookSlug
* @param string $pageSlug
* @param Request $request
- * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
+ * @return RedirectResponse|Redirector
* @throws NotFoundException
- * @throws \Throwable
+ * @throws Throwable
*/
public function permissions(Request $request, string $bookSlug, string $pageSlug)
{
--- /dev/null
+<?php
+
+namespace BookStack\Http\Controllers;
+
+use BookStack\Entities\ExportService;
+use BookStack\Entities\Repos\PageRepo;
+use BookStack\Exceptions\NotFoundException;
+use Illuminate\Http\Response;
+use Throwable;
+
+class PageExportController extends Controller
+{
+ /**
+ * @var PageRepo
+ */
+ protected $pageRepo;
+
+ /**
+ * @var ExportService
+ */
+ protected $exportService;
+
+ /**
+ * PageExportController constructor.
+ * @param PageRepo $pageRepo
+ * @param ExportService $exportService
+ */
+ public function __construct(PageRepo $pageRepo, ExportService $exportService)
+ {
+ $this->pageRepo = $pageRepo;
+ $this->exportService = $exportService;
+ parent::__construct();
+ }
+
+ /**
+ * Exports a page to a PDF.
+ * https://github.com/barryvdh/laravel-dompdf
+ * @param string $bookSlug
+ * @param string $pageSlug
+ * @return Response
+ * @throws NotFoundException
+ * @throws Throwable
+ */
+ public function pdf(string $bookSlug, string $pageSlug)
+ {
+ $page = $this->pageRepo->getPageBySlug($pageSlug, $bookSlug);
+ $page->html = $this->pageRepo->renderPage($page);
+ $pdfContent = $this->exportService->pageToPdf($page);
+ return $this->downloadResponse($pdfContent, $pageSlug . '.pdf');
+ }
+
+ /**
+ * Export a page to a self-contained HTML file.
+ * @param string $bookSlug
+ * @param string $pageSlug
+ * @return Response
+ * @throws NotFoundException
+ * @throws Throwable
+ */
+ public function html(string $bookSlug, string $pageSlug)
+ {
+ $page = $this->pageRepo->getPageBySlug($pageSlug, $bookSlug);
+ $page->html = $this->pageRepo->renderPage($page);
+ $containedHtml = $this->exportService->pageToContainedHtml($page);
+ return $this->downloadResponse($containedHtml, $pageSlug . '.html');
+ }
+
+ /**
+ * Export a page to a simple plaintext .txt file.
+ * @param string $bookSlug
+ * @param string $pageSlug
+ * @return Response
+ * @throws NotFoundException
+ */
+ public function plainText(string $bookSlug, string $pageSlug)
+ {
+ $page = $this->pageRepo->getPageBySlug($pageSlug, $bookSlug);
+ $pageText = $this->exportService->pageToPlainText($page);
+ return $this->downloadResponse($pageText, $pageSlug . '.txt');
+ }
+}
Route::get('/{slug}/delete', 'BookController@showDelete');
Route::get('/{bookSlug}/sort', 'BookController@sort');
Route::put('/{bookSlug}/sort', 'BookController@saveSort');
- Route::get('/{bookSlug}/export/html', 'BookController@exportHtml');
- Route::get('/{bookSlug}/export/pdf', 'BookController@exportPdf');
- Route::get('/{bookSlug}/export/plaintext', 'BookController@exportPlainText');
+ Route::get('/{bookSlug}/export/html', 'BookExportController@html');
+ Route::get('/{bookSlug}/export/pdf', 'BookExportController@pdf');
+ Route::get('/{bookSlug}/export/plaintext', 'BookExportController@plainText');
// Pages
Route::get('/{bookSlug}/create-page', 'PageController@create');
Route::get('/{bookSlug}/draft/{pageId}', 'PageController@editDraft');
Route::post('/{bookSlug}/draft/{pageId}', 'PageController@store');
Route::get('/{bookSlug}/page/{pageSlug}', 'PageController@show');
- Route::get('/{bookSlug}/page/{pageSlug}/export/pdf', 'PageController@exportPdf');
- Route::get('/{bookSlug}/page/{pageSlug}/export/html', 'PageController@exportHtml');
- Route::get('/{bookSlug}/page/{pageSlug}/export/plaintext', 'PageController@exportPlainText');
+ Route::get('/{bookSlug}/page/{pageSlug}/export/pdf', 'PageExportController@pdf');
+ Route::get('/{bookSlug}/page/{pageSlug}/export/html', 'PageExportController@html');
+ Route::get('/{bookSlug}/page/{pageSlug}/export/plaintext', 'PageExportController@plainText');
Route::get('/{bookSlug}/page/{pageSlug}/edit', 'PageController@edit');
Route::get('/{bookSlug}/page/{pageSlug}/move', 'PageController@showMove');
Route::put('/{bookSlug}/page/{pageSlug}/move', 'PageController@move');
Route::put('/{bookSlug}/chapter/{chapterSlug}/move', 'ChapterController@move');
Route::get('/{bookSlug}/chapter/{chapterSlug}/edit', 'ChapterController@edit');
Route::get('/{bookSlug}/chapter/{chapterSlug}/permissions', 'ChapterController@showPermissions');
- Route::get('/{bookSlug}/chapter/{chapterSlug}/export/pdf', 'ChapterController@exportPdf');
- Route::get('/{bookSlug}/chapter/{chapterSlug}/export/html', 'ChapterController@exportHtml');
- Route::get('/{bookSlug}/chapter/{chapterSlug}/export/plaintext', 'ChapterController@exportPlainText');
+ Route::get('/{bookSlug}/chapter/{chapterSlug}/export/pdf', 'ChapterExportController@pdf');
+ Route::get('/{bookSlug}/chapter/{chapterSlug}/export/html', 'ChapterExportController@html');
+ Route::get('/{bookSlug}/chapter/{chapterSlug}/export/plaintext', 'ChapterExportController@plainText');
Route::put('/{bookSlug}/chapter/{chapterSlug}/permissions', 'ChapterController@permissions');
Route::get('/{bookSlug}/chapter/{chapterSlug}/delete', 'ChapterController@showDelete');
Route::delete('/{bookSlug}/chapter/{chapterSlug}', 'ChapterController@destroy');