Skip to content

Commit

Permalink
Merge pull request #4392 from LibreSign/backport/4389/stable29
Browse files Browse the repository at this point in the history
[stable29] chore: prevent generate unecessary temp file
  • Loading branch information
vitormattos authored Jan 19, 2025
2 parents 3dabe5b + ce3a22b commit a45bed3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
18 changes: 12 additions & 6 deletions lib/Handler/FooterHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ private function getMetadata(): array {
}

private function getRenderedHtmlFooter(): string {
$tempFile = $this->tempManager->getTemporaryFile('footerTemplate.php');
file_put_contents($tempFile, $this->getTemplate());
$templates = new Engine($this->tempManager->getTempBaseDir());
return $templates->render(pathinfo($tempFile, PATHINFO_FILENAME), $this->getTemplateVars());
$templateFile = $this->getTemplateFile();
$pathInfo = pathinfo($templateFile);
$templates = new Engine($pathInfo['dirname']);
return $templates->render($pathInfo['filename'], $this->getTemplateVars());
}

public function setTemplateVar(string $name, mixed $value): self {
Expand Down Expand Up @@ -153,8 +153,14 @@ private function getTemplateVars(): array {
return $this->templateVars;
}

private function getTemplate(): string {
return $this->appConfig->getValueString(Application::APP_ID, 'footer_template', file_get_contents(__DIR__ . '/Templates/footer.php'));
private function getTemplateFile(): string {
$footerTemplate = $this->appConfig->getValueString(Application::APP_ID, 'footer_template', '');
if ($footerTemplate) {
$tempFile = $this->tempManager->getTemporaryFile('footerTemplate.php');
file_put_contents($tempFile, $footerTemplate);
return $tempFile;
}
return __DIR__ . '/Templates/footer.php';
}

private function getQrCodeImageBase64(string $text): string {
Expand Down
5 changes: 1 addition & 4 deletions lib/Handler/Templates/footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
<a href="<?= $linkToSite; ?>" style="text-decoration: none;color:unset;"><?= $signedBy; ?></a>
<?php if ($validateIn) { ?>
<br>
<a href="<?=$validationSite; ?>"
style="text-decoration: none;color:unset;">
<?= str_replace('%s', $validationSite, $validateIn); ?>
</a>
<a href="<?=$validationSite; ?>" style="text-decoration: none;color:unset;"><?= str_replace('%s', $validationSite, $validateIn); ?></a>
<?php } ?>
</td>
</tr>
Expand Down

0 comments on commit a45bed3

Please sign in to comment.