]> BookStack Code Mirror - bookstack/blob - app/Http/Controllers/BookExportController.php
Added force option for update-url command
[bookstack] / app / Http / Controllers / BookExportController.php
1 <?php
2
3 namespace BookStack\Http\Controllers;
4
5 use BookStack\Entities\Repos\BookRepo;
6 use BookStack\Entities\Tools\ExportFormatter;
7 use Throwable;
8
9 class BookExportController extends Controller
10 {
11     protected $bookRepo;
12     protected $exportFormatter;
13
14     /**
15      * BookExportController constructor.
16      */
17     public function __construct(BookRepo $bookRepo, ExportFormatter $exportFormatter)
18     {
19         $this->bookRepo = $bookRepo;
20         $this->exportFormatter = $exportFormatter;
21         $this->middleware('can:content-export');
22     }
23
24     /**
25      * Export a book as a PDF file.
26      *
27      * @throws Throwable
28      */
29     public function pdf(string $bookSlug)
30     {
31         $book = $this->bookRepo->getBySlug($bookSlug);
32         $pdfContent = $this->exportFormatter->bookToPdf($book);
33
34         return $this->download()->directly($pdfContent, $bookSlug . '.pdf');
35     }
36
37     /**
38      * Export a book as a contained HTML file.
39      *
40      * @throws Throwable
41      */
42     public function html(string $bookSlug)
43     {
44         $book = $this->bookRepo->getBySlug($bookSlug);
45         $htmlContent = $this->exportFormatter->bookToContainedHtml($book);
46
47         return $this->download()->directly($htmlContent, $bookSlug . '.html');
48     }
49
50     /**
51      * Export a book as a plain text file.
52      */
53     public function plainText(string $bookSlug)
54     {
55         $book = $this->bookRepo->getBySlug($bookSlug);
56         $textContent = $this->exportFormatter->bookToPlainText($book);
57
58         return $this->download()->directly($textContent, $bookSlug . '.txt');
59     }
60
61     /**
62      * Export a book as a markdown file.
63      */
64     public function markdown(string $bookSlug)
65     {
66         $book = $this->bookRepo->getBySlug($bookSlug);
67         $textContent = $this->exportFormatter->bookToMarkdown($book);
68
69         return $this->download()->directly($textContent, $bookSlug . '.md');
70     }
71 }