diff --git a/app/Entities/Controllers/BookshelfExportController.php b/app/Entities/Controllers/BookshelfExportController.php new file mode 100644 index 00000000000..1d9080a92b0 --- /dev/null +++ b/app/Entities/Controllers/BookshelfExportController.php @@ -0,0 +1,129 @@ +middleware('can:content-export'); + } + + /** + * Export a book as a PDF file. + * + * @throws Throwable + */ + public function pdf(Request $request, string $bookshelfSlug) + { + $bookshelf = $this->queries->findVisibleBySlugOrFail($bookshelfSlug); + if ($request['split'] === true) { + return $this->downloadAllInZip($bookshelf, 'pdf'); + } else { + $htmlContent = $this->exportFormatter->bookshelfToPdf($bookshelf); + + return $this->download()->directly($htmlContent, $bookshelfSlug . '.pdf'); + } + } + + /** + * Export a book as a contained HTML file. + * + * @throws Throwable + */ + public function html(Request $request, string $bookshelfSlug) + { + $bookshelf = $this->queries->findVisibleBySlugOrFail($bookshelfSlug); + if ($request['split'] === true) { + return $this->downloadAllInZip($bookshelf, 'html'); + } else { + $htmlContent = $this->exportFormatter->bookshelfToContainedHtml($bookshelf); + + return $this->download()->directly($htmlContent, $bookshelfSlug . '.html'); + } + } + + /** + * Export a book as a plain text file. + */ + public function plainText(Request $request, string $bookshelfSlug) + { + $bookshelf = $this->queries->findVisibleBySlugOrFail($bookshelfSlug); + if ($request['split'] === true) { + return $this->downloadAllInZip($bookshelf, 'txt'); + } else { + $htmlContent = $this->exportFormatter->bookshelfToPlainText($bookshelf); + + return $this->download()->directly($htmlContent, $bookshelfSlug . '.txt'); + } + } + + /** + * Export a book as a markdown file. + */ + public function markdown(Request $request, string $bookshelfSlug) + { + $bookshelf = $this->queries->findVisibleBySlugOrFail($bookshelfSlug); + if ($request['split'] === true) { + return $this->downloadAllInZip($bookshelf, 'md'); + } else { + $htmlContent = $this->exportFormatter->bookshelfToMarkdown($bookshelf); + + return $this->download()->directly($htmlContent, $bookshelfSlug . '.md'); + } + } + + public function downloadAllInZip(Bookshelf $bookshelf, string $type) + { + $bookshelf->load('books'); + + $zip = new \ZipArchive(); + + $tempFilePath = storage_path('app/public/' . $bookshelf->slug . '.zip'); + if ($zip->open($tempFilePath, \ZipArchive::CREATE) === true) { + foreach ($bookshelf->books as $book) { + $pdfContent = $this->getContentBasedOntype($book, $type); + $zip->addFromString($book->slug, $pdfContent); + } + $zip->close(); + + return Response::download($tempFilePath)->deleteFileAfterSend(true); + } + } + + public function getContentBasedOntype(Book $book, string $type) + { + switch ($type) { + case 'pdf': + return $this->exportFormatter->bookToPdf($book); + break; + + + case 'html': + return $this->exportFormatter->bookToContainedHtml($book); + break; + + case 'txt': + return $this->exportFormatter->bookToPlainText($book); + break; + + case 'md': + return $this->exportFormatter->bookToMarkdown($book); + break; + default: + return ""; + break; + } + } +} diff --git a/app/Entities/Tools/BookshelfContents.php b/app/Entities/Tools/BookshelfContents.php new file mode 100644 index 00000000000..859a11dd50a --- /dev/null +++ b/app/Entities/Tools/BookshelfContents.php @@ -0,0 +1,23 @@ +bookshelf->books()->scopes('visible')->get(); + + $books->each(function ($book) use ($renderPages) { + $book->setAttribute('bookChildrens', (new BookContents($book))->getTree(false, $renderPages)); + }); + + return collect($books); + } +} diff --git a/app/Entities/Tools/ExportFormatter.php b/app/Entities/Tools/ExportFormatter.php index beddfe8e6e0..fdd4c114df0 100644 --- a/app/Entities/Tools/ExportFormatter.php +++ b/app/Entities/Tools/ExportFormatter.php @@ -3,6 +3,7 @@ namespace BookStack\Entities\Tools; use BookStack\Entities\Models\Book; +use BookStack\Entities\Models\Bookshelf; use BookStack\Entities\Models\Chapter; use BookStack\Entities\Models\Page; use BookStack\Entities\Tools\Markdown\HtmlToMarkdown; @@ -82,6 +83,25 @@ public function bookToContainedHtml(Book $book): string return $this->containHtml($html); } + /** + * Convert a bookshelf to a self-contained HTML file. + * + * @throws Throwable + */ + public function bookshelfToContainedHtml(Bookshelf $bookshelf): string + { + $bookshelfTree = (new BookshelfContents($bookshelf))->getTree(true); + $html = view('exports.shelves', [ + 'bookshelf' => $bookshelf, + 'bookshelfChildrens' => $bookshelfTree, + 'format' => 'pdf', + 'engine' => $this->pdfGenerator->getActiveEngine(), + 'locale' => user()->getLocale(), + ])->render(); + + return $this->containHtml($html); + } + /** * Convert a page to a PDF file. * @@ -142,6 +162,22 @@ public function bookToPdf(Book $book): string return $this->htmlToPdf($html); } + + public function bookshelfToPdf(Bookshelf $bookshelf): string + { + $bookshelfTree = (new BookshelfContents($bookshelf))->getTree(true); + + $html = view('exports.shelves', [ + 'bookshelf' => $bookshelf, + 'bookshelfChildrens' => $bookshelfTree, + 'format' => 'pdf', + 'engine' => $this->pdfGenerator->getActiveEngine(), + 'locale' => user()->getLocale(), + ])->render(); + + return $this->htmlToPdf($html); + } + /** * Convert normal web-page HTML to a PDF. * @@ -297,6 +333,23 @@ public function bookToPlainText(Book $book): string return $text . implode("\n\n", $parts); } + /** + * Convert a book into a plain text string. + */ + public function bookshelfToPlainText(Bookshelf $bookshelf): string + { + $bookshelfTree = (new BookshelfContents($bookshelf))->getTree(true); + $text = $bookshelf->name . "\n" . $bookshelf->description; + $text = rtrim($text) . "\n\n"; + + $parts = []; + foreach ($bookshelfTree as $bookshelfChild) { + $parts[] = $this->bookToPlainText($bookshelfChild); + } + + return $text . implode("\n\n", $parts); + } + /** * Convert a page to a Markdown file. */ @@ -340,4 +393,18 @@ public function bookToMarkdown(Book $book): string return trim($text); } + + /** + * Convert a bookshelf into a plain text string. + */ + public function bookshelfToMarkdown(Bookshelf $bookshelf): string + { + $bookshelfTree = (new BookshelfContents($bookshelf))->getTree(true); + $text = '# ' . $bookshelf->name . "\n\n"; + foreach ($bookshelfTree as $bookshelfChild) { + $text .= $this->bookToMarkdown($bookshelfChild) . "\n\n"; + } + + return trim($text); + } } diff --git a/lang/ar/common.php b/lang/ar/common.php index 454b36a9448..be6ed6c153f 100644 --- a/lang/ar/common.php +++ b/lang/ar/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'غير نشط', 'never' => 'مطلقاً', 'none' => 'لا شَيْء', + 'multiple_or_single' => "متعدد أو واحد", + 'multiple_or_single_description' => "هل تريد تنزيل الملفات في ملف واحد أو أرشيف Zip (ملفات متعددة)", // Header 'homepage' => 'الصفحة الرئيسية', diff --git a/lang/bg/common.php b/lang/bg/common.php index 30298e63941..d9213309ee0 100644 --- a/lang/bg/common.php +++ b/lang/bg/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Неактивен', 'never' => 'Никога', 'none' => 'Нищо', + 'multiple_or_single' => "Множество или единично", + 'multiple_or_single_description' => "Искате ли да изтеглите файлове в един файл или ZIP архив (множество файлове)", // Header 'homepage' => 'Начална страница', diff --git a/lang/bs/common.php b/lang/bs/common.php index 4e4631a0d9d..3439e4be7e4 100644 --- a/lang/bs/common.php +++ b/lang/bs/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Inactive', 'never' => 'Never', 'none' => 'None', + 'multiple_or_single' => "Više ili jedno", + 'multiple_or_single_description' => "Želite li preuzeti datoteke u jednoj datoteci ili ZIP arhivu (više datoteka)", // Header 'homepage' => 'Homepage', diff --git a/lang/ca/common.php b/lang/ca/common.php index f4ad19230b7..d100962b7d9 100644 --- a/lang/ca/common.php +++ b/lang/ca/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Inactiu', 'never' => 'Mai', 'none' => 'Cap', + 'multiple_or_single' => "Múltiple o únic", + 'multiple_or_single_description' => "Voleu descarregar fitxers en un únic fitxer o en un arxiu ZIP (diversos fitxers)", // Header 'homepage' => 'Pàgina d’inici', diff --git a/lang/cs/common.php b/lang/cs/common.php index 1e20b17e7dc..470e65c3fe3 100644 --- a/lang/cs/common.php +++ b/lang/cs/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Neaktivní', 'never' => 'Nikdy', 'none' => 'Žádná', + 'multiple_or_single' => "Více nebo jediné", + 'multiple_or_single_description' => "Chcete stáhnout soubory do jednoho souboru nebo ZIP archivu (více souborů)", // Header 'homepage' => 'Domovská stránka', diff --git a/lang/cy/common.php b/lang/cy/common.php index c8c770b7118..08bf31afaba 100644 --- a/lang/cy/common.php +++ b/lang/cy/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Anweithredol', 'never' => 'Byth', 'none' => 'Dim un', + 'multiple_or_single' => "Lluosog neu Unigol", + 'multiple_or_single_description' => "Eisiau lawrlwytho ffeiliau mewn Un Ffeil neu Archif ZIP (Ffeiliau Lluosog)", // Header 'homepage' => 'Tudalen cartref', diff --git a/lang/da/common.php b/lang/da/common.php index 75060b28b3f..fdde2ad9eb3 100644 --- a/lang/da/common.php +++ b/lang/da/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Inaktiv', 'never' => 'Aldrig', 'none' => 'Ingen', + 'multiple_or_single' => "Flere eller enkelt", + 'multiple_or_single_description' => "Vil du downloade filer i en enkelt fil eller en ZIP-arkiv (flere filer)", // Header 'homepage' => 'Forside', diff --git a/lang/de/common.php b/lang/de/common.php index 8ff91da0a25..e3b2aedc6a1 100644 --- a/lang/de/common.php +++ b/lang/de/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Inaktiv', 'never' => 'Niemals', 'none' => 'Nichts', + 'multiple_or_single' => "Mehrfach oder Einzel", + 'multiple_or_single_description' => "Möchten Sie Dateien in einer einzelnen Datei oder einem ZIP-Archiv (mehrere Dateien) herunterladen?", // Header 'homepage' => 'Startseite', diff --git a/lang/de_informal/common.php b/lang/de_informal/common.php index e033b63d22e..794f79f197e 100644 --- a/lang/de_informal/common.php +++ b/lang/de_informal/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Inaktiv', 'never' => 'Niemals', 'none' => 'Keine', + 'multiple_or_single' => "Mehrfach oder Einzel", + 'multiple_or_single_description' => "Möchtest du Dateien in einer einzelnen Datei oder einem ZIP-Archiv (mehrere Dateien) herunterladen?", // Header 'homepage' => 'Startseite', diff --git a/lang/el/common.php b/lang/el/common.php index d1b6bd9f790..2c7f5dcc7cf 100644 --- a/lang/el/common.php +++ b/lang/el/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Αδρανής', 'never' => 'Ποτέ', 'none' => 'Κανένας', + 'multiple_or_single' => "Πολλαπλές ή Μονές", + 'multiple_or_single_description' => "Θέλετε να κατεβάσετε αρχεία σε ένα μόνο αρχείο ή σε ZIP αρχείο (πολλαπλά αρχεία)", // Header 'homepage' => 'Αρχική σελίδα', diff --git a/lang/en/common.php b/lang/en/common.php index b05169bb2c4..64fbd4ec8b4 100644 --- a/lang/en/common.php +++ b/lang/en/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Inactive', 'never' => 'Never', 'none' => 'None', + 'multiple_or_single' => "Multiple or Single", + 'multiple_or_single_description' => "Want to Download Files in Single File or Zip Archive(Multiple Files)", // Header 'homepage' => 'Homepage', diff --git a/lang/es/common.php b/lang/es/common.php index 14eee82d97c..e069f229451 100644 --- a/lang/es/common.php +++ b/lang/es/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Inactive', 'never' => 'Nunca', 'none' => 'Ninguno', + 'multiple_or_single' => "Múltiple o único", + 'multiple_or_single_description' => "¿Deseas descargar archivos en un solo archivo o en un archivo ZIP (múltiples archivos)?", // Header 'homepage' => 'Página de Inicio', diff --git a/lang/es_AR/common.php b/lang/es_AR/common.php index ebac11119d3..cd77d887ea4 100644 --- a/lang/es_AR/common.php +++ b/lang/es_AR/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Inactivo', 'never' => 'Nunca', 'none' => 'Ninguno', + 'multiple_or_single' => "Múltiple o único", + 'multiple_or_single_description' => "¿Deseas descargar archivos en un solo archivo o en un archivo ZIP (múltiples archivos)?", // Header 'homepage' => 'Página de Inicio', diff --git a/lang/et/common.php b/lang/et/common.php index a53060a00e6..d789e1951e4 100644 --- a/lang/et/common.php +++ b/lang/et/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Mitteaktiivne', 'never' => 'Mitte kunagi', 'none' => 'Puudub', + 'multiple_or_single' => "Mitu või üksik", + 'multiple_or_single_description' => "Kas soovite failid alla laadida ühte faili või ZIP-arhiivi (mitu faili)?", // Header 'homepage' => 'Avaleht', diff --git a/lang/eu/common.php b/lang/eu/common.php index 35a67b349ab..577854385a6 100644 --- a/lang/eu/common.php +++ b/lang/eu/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Inaktibo', 'never' => 'Inoiz ez', 'none' => 'Bat ere ez', + 'multiple_or_single' => "Anitz edo bakar", + 'multiple_or_single_description' => "Fitxategiak fitxategi bakar batean edo ZIP artxibo batean (fitxategi anitzak) deskargatu nahi dituzu?", // Header 'homepage' => 'Homepage', diff --git a/lang/fa/common.php b/lang/fa/common.php index 765c1e6271d..310f23aa01f 100644 --- a/lang/fa/common.php +++ b/lang/fa/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'غیر فعال', 'never' => 'هرگز', 'none' => 'هیچکدام', + 'multiple_or_single' => "چندگانه یا تکی", + 'multiple_or_single_description' => "آیا میخواهید فایلها را در یک فایل واحد یا آرشیو ZIP (چندین فایل) دانلود کنید؟", // Header 'homepage' => 'صفحه اصلی', diff --git a/lang/fi/common.php b/lang/fi/common.php index d6efe8e0347..b89f09209ed 100644 --- a/lang/fi/common.php +++ b/lang/fi/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Ei aktiivinen', 'never' => 'Ei koskaan', 'none' => 'Ei mitään', + 'multiple_or_single' => "Useita tai Yksittäisiä", + 'multiple_or_single_description' => "Haluatko ladata tiedostot yhteen tiedostoon tai ZIP-arkistoon (useita tiedostoja)?", // Header 'homepage' => 'Kotisivu', diff --git a/lang/fr/common.php b/lang/fr/common.php index 282a72e4569..96f7b9c870f 100644 --- a/lang/fr/common.php +++ b/lang/fr/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Inactif', 'never' => 'Jamais', 'none' => 'Aucun', + 'multiple_or_single' => "Multiple ou Unique", + 'multiple_or_single_description' => "Voulez-vous télécharger les fichiers dans un fichier unique ou une archive ZIP (fichiers multiples)?", // Header 'homepage' => 'Accueil', diff --git a/lang/he/common.php b/lang/he/common.php index a427df954fe..282787007e6 100644 --- a/lang/he/common.php +++ b/lang/he/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'לא פעיל', 'never' => 'אף פעם', 'none' => 'ללא', + 'multiple_or_single' => "מרובה או יחיד", + 'multiple_or_single_description' => "האם ברצונך להוריד קבצים בקובץ יחיד או בארכיון ZIP (קבצים מרובים)?", // Header 'homepage' => 'דף הבית', diff --git a/lang/hr/common.php b/lang/hr/common.php index 3c9ed610bc6..ad7e292ece0 100644 --- a/lang/hr/common.php +++ b/lang/hr/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Neaktivno', 'never' => 'Nikada', 'none' => 'Ništa', + 'multiple_or_single' => "Višestruko ili pojedinačno", + 'multiple_or_single_description' => "Želite li preuzeti datoteke u jednu datoteku ili ZIP arhivu (više datoteka)?", // Header 'homepage' => 'Naslovna Stranica', diff --git a/lang/hu/common.php b/lang/hu/common.php index 29a87e19edf..aa41237407c 100644 --- a/lang/hu/common.php +++ b/lang/hu/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Inaktív', 'never' => 'Soha', 'none' => 'Egyik sem', + 'multiple_or_single' => "Több vagy egyetlen", + 'multiple_or_single_description' => "Szeretné a fájlokat egyetlen fájlba vagy ZIP archívumba (több fájl) letölteni?", // Header 'homepage' => 'Kezdőlap', diff --git a/lang/id/common.php b/lang/id/common.php index 06e9421c87b..f7c286b843b 100644 --- a/lang/id/common.php +++ b/lang/id/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Inactive', 'never' => 'Never', 'none' => 'None', + 'multiple_or_single' => "Banyak atau Tunggal", + 'multiple_or_single_description' => "Ingin mengunduh file dalam satu file atau arsip ZIP (beberapa file)?", // Header 'homepage' => 'Homepage', diff --git a/lang/it/common.php b/lang/it/common.php index 113ddb01405..5533401e88f 100644 --- a/lang/it/common.php +++ b/lang/it/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Inattivo', 'never' => 'Mai', 'none' => 'Nessuno', + 'multiple_or_single' => "Multiplo o Singolo", + 'multiple_or_single_description' => "Vuoi scaricare i file in un unico file o in un archivio ZIP (più file)?", // Header 'homepage' => 'Homepage', diff --git a/lang/ja/common.php b/lang/ja/common.php index 097974d8e96..2dff5b58fed 100644 --- a/lang/ja/common.php +++ b/lang/ja/common.php @@ -82,6 +82,8 @@ 'status_inactive' => '無効', 'never' => '該当なし', 'none' => 'なし', + 'multiple_or_single' => "複数または単一", + 'multiple_or_single_description' => "ファイルを単一ファイルまたはZIPアーカイブ(複数ファイル)でダウンロードしますか?", // Header 'homepage' => 'ホームページ', diff --git a/lang/ko/common.php b/lang/ko/common.php index 246a3aebc36..1f4d1e93cbf 100644 --- a/lang/ko/common.php +++ b/lang/ko/common.php @@ -82,6 +82,8 @@ 'status_inactive' => '비활성', 'never' => '안 함', 'none' => '없음', + 'multiple_or_single' => "다중 또는 단일", + 'multiple_or_single_description' => "파일을 단일 파일 또는 ZIP 아카이브(다중 파일)로 다운로드하시겠습니까?", // Header 'homepage' => '홈페이지', diff --git a/lang/lt/common.php b/lang/lt/common.php index e375c835ceb..bbcbf9d4abe 100644 --- a/lang/lt/common.php +++ b/lang/lt/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Inactive', 'never' => 'Never', 'none' => 'None', + 'multiple_or_single' => "Keli arba vienas", + 'multiple_or_single_description' => "Ar norite atsisiųsti failus į vieną failą arba ZIP archyvą (kelis failus)?", // Header 'homepage' => 'Homepage', diff --git a/lang/lv/common.php b/lang/lv/common.php index 584b24cb2e7..4bca9f568ac 100644 --- a/lang/lv/common.php +++ b/lang/lv/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Neaktīvs', 'never' => 'Nekad', 'none' => 'Neviens', + 'multiple_or_single' => "Vairāki vai viens", + 'multiple_or_single_description' => "Vai vēlaties lejupielādēt failus vienā failā vai ZIP arhīvā (vairākos failos)?", // Header 'homepage' => 'Sākumlapa', diff --git a/lang/nb/common.php b/lang/nb/common.php index 0e9e19b6e59..f50896688a3 100644 --- a/lang/nb/common.php +++ b/lang/nb/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Inaktiv', 'never' => 'Aldri', 'none' => 'Ingen', + 'multiple_or_single' => "Flere eller Enkelt", + 'multiple_or_single_description' => "Ønsker du å laste ned filer i en enkelt fil eller en ZIP-arkiv (flere filer)?", // Header 'homepage' => 'Hjemmeside', diff --git a/lang/nl/common.php b/lang/nl/common.php index 844fe91d1af..3404cb4d8f1 100644 --- a/lang/nl/common.php +++ b/lang/nl/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Inactief', 'never' => 'Nooit', 'none' => 'Geen', + 'multiple_or_single' => "Meerdere of Enkele", + 'multiple_or_single_description' => "Wilt u bestanden downloaden in één bestand of in een ZIP-archief (meerdere bestanden)?", // Header 'homepage' => 'Startpagina', diff --git a/lang/nn/common.php b/lang/nn/common.php index 3d623dbc492..52f610fd065 100644 --- a/lang/nn/common.php +++ b/lang/nn/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Inaktiv', 'never' => 'Aldri', 'none' => 'Ingen', + 'multiple_or_single' => "Fleire eller éin", + 'multiple_or_single_description' => "Ønskjer du å laste ned filer i éin fil eller ein ZIP-arkiv (fleire filer)?", // Header 'homepage' => 'Heimeside', diff --git a/lang/pl/common.php b/lang/pl/common.php index 4d5a346b2b5..794b8376f0f 100644 --- a/lang/pl/common.php +++ b/lang/pl/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Nieaktywny', 'never' => 'Nigdy', 'none' => 'Brak', + 'multiple_or_single' => "Wiele lub pojedynczy", + 'multiple_or_single_description' => "Chcesz pobrać pliki do jednego pliku lub archiwum ZIP (wiele plików)?", // Header 'homepage' => 'Strona domowa', diff --git a/lang/pt/common.php b/lang/pt/common.php index 3e005700245..225f5faad99 100644 --- a/lang/pt/common.php +++ b/lang/pt/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Inativo', 'never' => 'Nunca', 'none' => 'Nenhum', + 'multiple_or_single' => "Múltiplo ou Único", + 'multiple_or_single_description' => "Deseja baixar os arquivos em um único arquivo ou em um arquivo ZIP (vários arquivos)?", // Header 'homepage' => 'Página inicial', diff --git a/lang/pt_BR/common.php b/lang/pt_BR/common.php index f5e6d230d43..59742eb7e90 100644 --- a/lang/pt_BR/common.php +++ b/lang/pt_BR/common.php @@ -87,6 +87,8 @@ 'status_inactive' => 'Inativo', 'never' => 'Nunca', 'none' => 'Nenhum', + 'multiple_or_single' => "Múltiplo ou Único", + 'multiple_or_single_description' => "Deseja baixar os arquivos em um único arquivo ou em um arquivo ZIP (vários arquivos)?", // Header 'homepage' => 'Página inicial', diff --git a/lang/ro/common.php b/lang/ro/common.php index 1de631183f6..a8d28a4cbfa 100644 --- a/lang/ro/common.php +++ b/lang/ro/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Inactiv', 'never' => 'Niciodată', 'none' => 'Niciunul', + 'multiple_or_single' => "Multiplu sau Unic", + 'multiple_or_single_description' => "Doriți să descărcați fișierele într-un singur fișier sau într-un fișier ZIP (mai multe fișiere)?", // Header 'homepage' => 'Acasă', diff --git a/lang/ru/common.php b/lang/ru/common.php index d3860bba461..a4e50795a5d 100644 --- a/lang/ru/common.php +++ b/lang/ru/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Неактивен', 'never' => 'Никогда', 'none' => 'Нет', + 'multiple_or_single' => "Множественный или одиночный", + 'multiple_or_single_description' => "Вы хотите скачать файлы в один файл или ZIP-архив (несколько файлов)?", // Header 'homepage' => 'Главная страница', diff --git a/lang/sk/common.php b/lang/sk/common.php index 12828d6c2e5..1ef06719f3f 100644 --- a/lang/sk/common.php +++ b/lang/sk/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Neaktívny', 'never' => 'Nikdy', 'none' => 'Žiadne', + 'multiple_or_single' => "Višestruko ili pojedinačno", + 'multiple_or_single_description' => "Chcete stiahnuť súbory do jedného súboru alebo ZIP archívu (viac súborov)?", // Header 'homepage' => 'Domovská stránka', diff --git a/lang/sl/common.php b/lang/sl/common.php index 4bad22048c6..91b672fbd74 100644 --- a/lang/sl/common.php +++ b/lang/sl/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Inactive', 'never' => 'Never', 'none' => 'None', + 'multiple_or_single' => "Več ali En", + 'multiple_or_single_description' => "Želite prenesti datoteke v eno datoteko ali ZIP arhiv (več datotek)?", // Header 'homepage' => 'Homepage', diff --git a/lang/sv/common.php b/lang/sv/common.php index 8fe80899f0e..20dff8dab7d 100644 --- a/lang/sv/common.php +++ b/lang/sv/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Inaktiv', 'never' => 'Aldrig', 'none' => 'Inga', + 'multiple_or_single' => "Flera eller Enkel", + 'multiple_or_single_description' => "Vill du ladda ner filer i en enda fil eller ZIP-arkiv (flera filer)?", // Header 'homepage' => 'Startsida', diff --git a/lang/tr/common.php b/lang/tr/common.php index 3e416d37bfc..a88237e05cc 100644 --- a/lang/tr/common.php +++ b/lang/tr/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Aktif değil', 'never' => 'Hiçbir zaman', 'none' => 'Hiçbiri', + 'multiple_or_single' => "Çoklu veya Tek", + 'multiple_or_single_description' => "Dosyaları tek bir dosyada mı yoksa ZIP arşivinde mi (birden çok dosya) indirmek istiyorsunuz?", // Header 'homepage' => 'Ana sayfa', diff --git a/lang/uk/common.php b/lang/uk/common.php index d384e392447..e14659ca0a7 100644 --- a/lang/uk/common.php +++ b/lang/uk/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Неактивний', 'never' => 'Ніколи', 'none' => 'Відсутньо', + 'multiple_or_single' => "Кілька або Одиничний", + 'multiple_or_single_description' => "Ви хочете завантажити файли в один файл чи архів ZIP (декілька файлів)?", // Header 'homepage' => 'Домашня Сторінка', diff --git a/lang/uz/common.php b/lang/uz/common.php index fcbb2ea84a8..43bce1d59aa 100644 --- a/lang/uz/common.php +++ b/lang/uz/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Faol emas', 'never' => 'Hech qachon', 'none' => 'Yo‘q', + 'multiple_or_single' => "Ko'p yoki Yagona", + 'multiple_or_single_description' => "Fayllarni bitta faylda yoki ZIP arxivida (bir nechta fayl) yuklamoqchimisiz?", // Header 'homepage' => 'Bosh sahifa', diff --git a/lang/vi/common.php b/lang/vi/common.php index 16929a2fbae..51c48263568 100644 --- a/lang/vi/common.php +++ b/lang/vi/common.php @@ -82,6 +82,8 @@ 'status_inactive' => 'Không hoạt động', 'never' => 'Không bao giờ', 'none' => 'Không', + 'multiple_or_single' => "Nhiều hoặc Đơn lẻ", + 'multiple_or_single_description' => "Bạn có muốn tải tệp trong một tệp hoặc lưu trữ ZIP (nhiều tệp)?", // Header 'homepage' => 'Trang chủ', diff --git a/lang/zh_CN/common.php b/lang/zh_CN/common.php index bc391354e69..5a88799a333 100644 --- a/lang/zh_CN/common.php +++ b/lang/zh_CN/common.php @@ -82,6 +82,8 @@ 'status_inactive' => '未激活', 'never' => '从未', 'none' => '无', + 'multiple_or_single' => "多个或单个", + 'multiple_or_single_description' => "是否希望将文件下载为单个文件或 ZIP 压缩文件(多个文件)?", // Header 'homepage' => '主页', diff --git a/lang/zh_TW/common.php b/lang/zh_TW/common.php index 8b003a7303b..7ee0c5ca5fc 100644 --- a/lang/zh_TW/common.php +++ b/lang/zh_TW/common.php @@ -82,6 +82,8 @@ 'status_inactive' => '未啟用', 'never' => '永不', 'none' => '無', + 'multiple_or_single' => "多個或單個", + 'multiple_or_single_description' => "是否希望將檔案下載為單個檔案或 ZIP 壓縮檔案(多個檔案)?", // Header 'homepage' => '首頁', diff --git a/public/rJcm3wTSie.zip b/public/rJcm3wTSie.zip new file mode 100644 index 00000000000..8307f0dff71 Binary files /dev/null and b/public/rJcm3wTSie.zip differ diff --git a/resources/js/components/bookshelf-export-manager.js b/resources/js/components/bookshelf-export-manager.js new file mode 100644 index 00000000000..c545ddaa7e2 --- /dev/null +++ b/resources/js/components/bookshelf-export-manager.js @@ -0,0 +1,31 @@ +import {Component} from './component'; + +export class BookshelfExportManager extends Component { + + setup() { + this.container = this.$el; + this.confirmDialog = this.$refs.confirmDialog; + + this.setupListeners(); + } + + setupListeners() { + // Listening for the 'bookshelf-export-click' event + window.$events.listen('bookshelf-export-click', async result => { + const dialog = window.$components.firstOnElement(this.confirmDialog, 'confirm-dialog'); + this.confirmDialog.querySelector('[data-button-type="cancel"]').innerHTML = 'Single'; + this.confirmDialog.querySelector('[data-button-type="confirm"]').innerHTML = 'Split'; + + const singleBtn = this.confirmDialog.querySelector('[data-button-type="cancel"]'); + const splitBtn = this.confirmDialog.querySelector('[data-button-type="confirm"]'); + singleBtn.addEventListener('click', () => this.redirectToLink(result, false)); + splitBtn.addEventListener('click', () => this.redirectToLink(result, true)); + dialog.show(); + }); + } + + redirectToLink(link, split) { + window.location.href = `${link}?split=${split}`; + } + +} diff --git a/resources/js/components/dropdown.js b/resources/js/components/dropdown.js index 4efd428acf7..53442849ab2 100644 --- a/resources/js/components/dropdown.js +++ b/resources/js/components/dropdown.js @@ -129,7 +129,12 @@ export class Dropdown extends Component { } // Hide menu on option click - this.container.addEventListener('click', event => { + this.container.addEventListener('click', async event => { + if (this.menu.getAttribute('data-entity-type') === 'bookshelf') { + event.preventDefault(); + window.$events.emit('bookshelf-export-click', event.target.closest('a').href); + } + const possibleChildren = Array.from(this.menu.querySelectorAll('a')); if (possibleChildren.includes(event.target)) { this.hide(); diff --git a/resources/js/components/index.js b/resources/js/components/index.js index 8ad5e14cb2e..dd5ef9ac4eb 100644 --- a/resources/js/components/index.js +++ b/resources/js/components/index.js @@ -7,6 +7,7 @@ export {AutoSuggest} from './auto-suggest'; export {AutoSubmit} from './auto-submit'; export {BackToTop} from './back-to-top'; export {BookSort} from './book-sort'; +export {BookshelfExportManager} from './bookshelf-export-manager'; export {ChapterContents} from './chapter-contents'; export {CodeEditor} from './code-editor'; export {CodeHighlighter} from './code-highlighter'; diff --git a/resources/views/common/confirm-dialog.blade.php b/resources/views/common/confirm-dialog.blade.php index 736a1c49b7d..79c9584fff8 100644 --- a/resources/views/common/confirm-dialog.blade.php +++ b/resources/views/common/confirm-dialog.blade.php @@ -13,8 +13,8 @@ class="popup-background"> {{ $slot }}