Skip to content

Commit

Permalink
Merge pull request #4389 from LibreSign/chore/prevent-generate-uneces…
Browse files Browse the repository at this point in the history
…sary-temp-file

chore: prevent generate unecessary temp file
  • Loading branch information
vitormattos authored Jan 19, 2025
2 parents d56fbb1 + 246883e commit 5a29ec1
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 @@ -96,10 +96,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 @@ -137,8 +137,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 @@ -16,10 +16,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 5a29ec1

Please sign in to comment.