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