]> BookStack Code Mirror - bookstack/blob - app/Exports/ZipExportReferences.php
Zip Exports: Added attachment/image link resolving & JSON null handling
[bookstack] / app / Exports / ZipExportReferences.php
1 <?php
2
3 namespace BookStack\Exports;
4
5 use BookStack\App\Model;
6 use BookStack\Exports\ZipExportModels\ZipExportAttachment;
7 use BookStack\Exports\ZipExportModels\ZipExportPage;
8
9 class ZipExportReferences
10 {
11     /** @var ZipExportPage[] */
12     protected array $pages = [];
13     protected array $books = [];
14     protected array $chapters = [];
15
16     /** @var ZipExportAttachment[] */
17     protected array $attachments = [];
18
19     public function __construct(
20         protected ZipReferenceParser $parser,
21     ) {
22     }
23
24     public function addPage(ZipExportPage $page): void
25     {
26         if ($page->id) {
27             $this->pages[$page->id] = $page;
28         }
29
30         foreach ($page->attachments as $attachment) {
31             if ($attachment->id) {
32                 $this->attachments[$attachment->id] = $attachment;
33             }
34         }
35     }
36
37     public function buildReferences(): void
38     {
39         // TODO - References to images, attachments, other entities
40
41         // TODO - Parse page MD & HTML
42         foreach ($this->pages as $page) {
43             $page->html = $this->parser->parse($page->html ?? '', function (Model $model): ?string {
44                 // TODO - Handle found link to $model
45                 //   - Validate we can see/access $model, or/and that it's
46                 //     part of the export in progress.
47
48                 // TODO - Add images after the above to files
49                 return '[CAT]';
50             });
51             // TODO - markdown
52         }
53
54 //        dd('end');
55         // TODO - Parse chapter desc html
56         // TODO - Parse book desc html
57     }
58 }