sanitizes siteTilte before saving pdf

This commit is contained in:
buttle 2021-09-06 19:00:22 +02:00
parent 7ce33f02ff
commit 8aed07719e
2 changed files with 10 additions and 1 deletions

View File

@ -76,5 +76,9 @@ class TechDocumentBlockForm extends Form
'rows' => '10',
],
]);
$this->add([
'name' => 'o:block[__blockIndex__][o:data][document_name]',
'type' => Element\Hidden::class,
]);
}
}

View File

@ -66,6 +66,7 @@ class TechDocument extends AbstractBlockLayout
{
$data = $block->getData();
$site_title = $block->getPage()->getSite()->getTitle();
//$file_name = preg_replace( '/[^a-z0-9]+/', '-', strtolower( $site_title ) );
$site_url = null;
$parsedown = new Parsedown();
@ -86,6 +87,7 @@ class TechDocument extends AbstractBlockLayout
$text .= "\n\n### Long-term Care: (in storage and on display)\n";
$text .= $data['longtermcare'];
$document_name = $data['document_name'];
$html = $parsedown->setBreaksEnabled(true)->text($text);
$mpdf = new \Mpdf\Mpdf();
$mpdf->SetHTMLFooter('
@ -100,7 +102,7 @@ class TechDocument extends AbstractBlockLayout
</tr>
</table>');
$mpdf->WriteHTML($html);
$mpdf->Output($this->storage_dir.'/docs/'.$site_title.'.pdf', \Mpdf\Output\Destination::FILE);
$mpdf->Output($this->storage_dir.'/docs/'.$document_name, \Mpdf\Output\Destination::FILE);
}
public function form(PhpRenderer $view,
@ -109,6 +111,8 @@ class TechDocument extends AbstractBlockLayout
SitePageBlockRepresentation $block = null
) {
$form = $this->formElementManager->get(TechDocumentBlockForm::class);
$site_title = $view->site->title();
$file_name = preg_replace( '/[^a-z0-9]+/', '-', strtolower($site_title) ).'.pdf';
$data = $block
? $block->data() + $this->defaultSettings
: $this->defaultSettings;
@ -119,6 +123,7 @@ class TechDocument extends AbstractBlockLayout
'o:block[__blockIndex__][o:data][installation]' => $data['installation'],
'o:block[__blockIndex__][o:data][shipping]' => $data['shipping'],
'o:block[__blockIndex__][o:data][longtermcare]' => $data['longtermcare'],
'o:block[__blockIndex__][o:data][document_name]' => $file_name,
]);
$form->prepare();