class ExportFormatter
{
- protected ImageService $imageService;
- protected PdfGenerator $pdfGenerator;
- protected CspService $cspService;
-
- /**
- * ExportService constructor.
- */
- public function __construct(ImageService $imageService, PdfGenerator $pdfGenerator, CspService $cspService)
- {
- $this->imageService = $imageService;
- $this->pdfGenerator = $pdfGenerator;
- $this->cspService = $cspService;
+ public function __construct(
+ protected ImageService $imageService,
+ protected PdfGenerator $pdfGenerator,
+ protected CspService $cspService
+ ) {
}
/**
*
* @throws Throwable
*/
- public function pageToContainedHtml(Page $page)
+ public function pageToContainedHtml(Page $page): string
{
$page->html = (new PageContent($page))->render();
$pageHtml = view('exports.page', [
'page' => $page,
'format' => 'html',
'cspContent' => $this->cspService->getCspMetaTagValue(),
+ 'locale' => user()->getLocale(),
])->render();
return $this->containHtml($pageHtml);
*
* @throws Throwable
*/
- public function chapterToContainedHtml(Chapter $chapter)
+ public function chapterToContainedHtml(Chapter $chapter): string
{
$pages = $chapter->getVisiblePages();
$pages->each(function ($page) {
'pages' => $pages,
'format' => 'html',
'cspContent' => $this->cspService->getCspMetaTagValue(),
+ 'locale' => user()->getLocale(),
])->render();
return $this->containHtml($html);
*
* @throws Throwable
*/
- public function bookToContainedHtml(Book $book)
+ public function bookToContainedHtml(Book $book): string
{
$bookTree = (new BookContents($book))->getTree(false, true);
$html = view('exports.book', [
'bookChildren' => $bookTree,
'format' => 'html',
'cspContent' => $this->cspService->getCspMetaTagValue(),
+ 'locale' => user()->getLocale(),
])->render();
return $this->containHtml($html);
*
* @throws Throwable
*/
- public function pageToPdf(Page $page)
+ public function pageToPdf(Page $page): string
{
$page->html = (new PageContent($page))->render();
$html = view('exports.page', [
'page' => $page,
'format' => 'pdf',
'engine' => $this->pdfGenerator->getActiveEngine(),
+ 'locale' => user()->getLocale(),
])->render();
return $this->htmlToPdf($html);
*
* @throws Throwable
*/
- public function chapterToPdf(Chapter $chapter)
+ public function chapterToPdf(Chapter $chapter): string
{
$pages = $chapter->getVisiblePages();
$pages->each(function ($page) {
'pages' => $pages,
'format' => 'pdf',
'engine' => $this->pdfGenerator->getActiveEngine(),
+ 'locale' => user()->getLocale(),
])->render();
return $this->htmlToPdf($html);
*
* @throws Throwable
*/
- public function bookToPdf(Book $book)
+ public function bookToPdf(Book $book): string
{
$bookTree = (new BookContents($book))->getTree(false, true);
$html = view('exports.book', [
'bookChildren' => $bookTree,
'format' => 'pdf',
'engine' => $this->pdfGenerator->getActiveEngine(),
+ 'locale' => user()->getLocale(),
])->render();
return $this->htmlToPdf($html);
/** @var DOMElement $iframe */
foreach ($iframes as $iframe) {
$link = $iframe->getAttribute('src');
- if (strpos($link, '//') === 0) {
+ if (str_starts_with($link, '//')) {
$link = 'https:' . $link;
}
foreach ($linksOutput[0] as $index => $linkMatch) {
$oldLinkString = $linkMatch;
$srcString = $linksOutput[2][$index];
- if (strpos(trim($srcString), 'http') !== 0) {
+ if (!str_starts_with(trim($srcString), 'http')) {
$newSrcString = url($srcString);
$newLinkString = str_replace($srcString, $newSrcString, $oldLinkString);
$htmlContent = str_replace($oldLinkString, $newLinkString, $htmlContent);