diff --git a/composer.json b/composer.json index 4db4946041..5ab9a0cecb 100644 --- a/composer.json +++ b/composer.json @@ -2,12 +2,12 @@ "require": { "endroid/qr-code": "^5.0", "jsignpdf/jsignpdf-php": "^1.2", + "league/plates": "^3.5", "libresign/whatosami": "^0.0.1", "mikehaertl/php-pdftk": "^0.13.0", "mpdf/mpdf": "^8.2", "pagerfanta/pagerfanta": "^4.5", "smalot/pdfparser": "^2.4", - "twig/twig": "^3.9", "wobeto/email-blur": "^1.0" }, "require-dev": { @@ -33,16 +33,13 @@ "cs:check": "php-cs-fixer fix --dry-run --diff", "cs:fix": "php-cs-fixer fix", "openapi": "generate-spec --verbose && (npm run typescript:generate || echo 'Please manually regenerate the typescript OpenAPI models')", - "psalm": "psalm --threads=1", - "psalm:update-baseline": "psalm --threads=1 --update-baseline --set-baseline=tests/psalm-baseline.xml", + "psalm": "psalm --threads=$(nproc)", + "psalm:update-baseline": "psalm --threads=$(nproc) --update-baseline --set-baseline=tests/psalm-baseline.xml", "psalm:clear": "psalm --clear-cache && psalm --clear-global-cache", "post-install-cmd": [ "@composer bin all install --ansi", "composer dump-autoload" ], - "post-update-cmd": [ - "composer dump-autoload" - ], "test:unit": "vendor/bin/phpunit --no-coverage", "test:coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit" }, diff --git a/composer.lock b/composer.lock index 95ef58265e..68905cbbb0 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7c0f8e232cc3b5985ff418baa1a1ae59", + "content-hash": "a9845eeee46fd0ad5f449b99f1a1d629", "packages": [ { "name": "bacon/bacon-qr-code", @@ -235,6 +235,70 @@ }, "time": "2024-04-24T17:19:52+00:00" }, + { + "name": "league/plates", + "version": "v3.5.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/plates.git", + "reference": "a6a3238e46c6e19af7318fdc36bfbe49b0620231" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/plates/zipball/a6a3238e46c6e19af7318fdc36bfbe49b0620231", + "reference": "a6a3238e46c6e19af7318fdc36bfbe49b0620231", + "shasum": "" + }, + "require": { + "php": "^7.0|^8.0" + }, + "require-dev": { + "mikey179/vfsstream": "^1.6", + "phpunit/phpunit": "^9.5", + "squizlabs/php_codesniffer": "^3.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "League\\Plates\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jonathan Reinink", + "email": "jonathan@reinink.ca", + "role": "Developer" + }, + { + "name": "RJ Garcia", + "email": "ragboyjr@icloud.com", + "role": "Developer" + } + ], + "description": "Plates, the native PHP template system that's fast, easy to use and easy to extend.", + "homepage": "https://platesphp.com", + "keywords": [ + "league", + "package", + "templates", + "templating", + "views" + ], + "support": { + "issues": "https://github.com/thephpleague/plates/issues", + "source": "https://github.com/thephpleague/plates/tree/v3.5.0" + }, + "time": "2023-01-16T20:25:45+00:00" + }, { "name": "libresign/whatosami", "version": "0.0.1", @@ -1104,85 +1168,6 @@ ], "time": "2024-04-18T09:32:20+00:00" }, - { - "name": "symfony/polyfill-ctype", - "version": "v1.31.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "a3cc8b044a6ea513310cbd48ef7333b384945638" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/a3cc8b044a6ea513310cbd48ef7333b384945638", - "reference": "a3cc8b044a6ea513310cbd48ef7333b384945638", - "shasum": "" - }, - "require": { - "php": ">=7.2" - }, - "provide": { - "ext-ctype": "*" - }, - "suggest": { - "ext-ctype": "For best performance" - }, - "type": "library", - "extra": { - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Polyfill\\Ctype\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Gert de Pagter", - "email": "BackEndTea@gmail.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for ctype functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "ctype", - "polyfill", - "portable" - ], - "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.31.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2024-09-09T11:45:10+00:00" - }, { "name": "symfony/polyfill-mbstring", "version": "v1.31.0", @@ -1263,161 +1248,6 @@ ], "time": "2024-09-09T11:45:10+00:00" }, - { - "name": "symfony/polyfill-php81", - "version": "v1.31.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-php81.git", - "reference": "4a4cfc2d253c21a5ad0e53071df248ed48c6ce5c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php81/zipball/4a4cfc2d253c21a5ad0e53071df248ed48c6ce5c", - "reference": "4a4cfc2d253c21a5ad0e53071df248ed48c6ce5c", - "shasum": "" - }, - "require": { - "php": ">=7.2" - }, - "type": "library", - "extra": { - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Polyfill\\Php81\\": "" - }, - "classmap": [ - "Resources/stubs" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "polyfill", - "portable", - "shim" - ], - "support": { - "source": "https://github.com/symfony/polyfill-php81/tree/v1.31.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2024-09-09T11:45:10+00:00" - }, - { - "name": "twig/twig", - "version": "v3.14.0", - "source": { - "type": "git", - "url": "https://github.com/twigphp/Twig.git", - "reference": "126b2c97818dbff0cdf3fbfc881aedb3d40aae72" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/126b2c97818dbff0cdf3fbfc881aedb3d40aae72", - "reference": "126b2c97818dbff0cdf3fbfc881aedb3d40aae72", - "shasum": "" - }, - "require": { - "php": ">=8.0.2", - "symfony/deprecation-contracts": "^2.5|^3", - "symfony/polyfill-ctype": "^1.8", - "symfony/polyfill-mbstring": "^1.3", - "symfony/polyfill-php81": "^1.29" - }, - "require-dev": { - "psr/container": "^1.0|^2.0", - "symfony/phpunit-bridge": "^5.4.9|^6.4|^7.0" - }, - "type": "library", - "autoload": { - "files": [ - "src/Resources/core.php", - "src/Resources/debug.php", - "src/Resources/escaper.php", - "src/Resources/string_loader.php" - ], - "psr-4": { - "Twig\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com", - "homepage": "http://fabien.potencier.org", - "role": "Lead Developer" - }, - { - "name": "Twig Team", - "role": "Contributors" - }, - { - "name": "Armin Ronacher", - "email": "armin.ronacher@active-4.com", - "role": "Project Founder" - } - ], - "description": "Twig, the flexible, fast, and secure template language for PHP", - "homepage": "https://twig.symfony.com", - "keywords": [ - "templating" - ], - "support": { - "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v3.14.0" - }, - "funding": [ - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/twig/twig", - "type": "tidelift" - } - ], - "time": "2024-09-09T17:55:12+00:00" - }, { "name": "wobeto/email-blur", "version": "1.0.0", diff --git a/lib/Handler/FooterHandler.php b/lib/Handler/FooterHandler.php index 108c9ea033..b77b2a3281 100644 --- a/lib/Handler/FooterHandler.php +++ b/lib/Handler/FooterHandler.php @@ -16,18 +16,15 @@ use Endroid\QrCode\QrCode; use Endroid\QrCode\RoundBlockSizeMode; use Endroid\QrCode\Writer\PngWriter; +use League\Plates\Engine; use Mpdf\Mpdf; use OCA\Libresign\Db\File as FileEntity; -use OCA\Libresign\Exception\LibresignException; use OCA\Libresign\Service\PdfParserService; use OCP\AppFramework\Services\IAppConfig; use OCP\Files\File; use OCP\IL10N; use OCP\ITempManager; use OCP\IURLGenerator; -use Twig\Environment; -use Twig\Error\SyntaxError; -use Twig\Loader\FilesystemLoader; class FooterHandler { private QrCode $qrCode; @@ -97,16 +94,10 @@ private function getMetadata(): array { } private function getRenderedHtmlFooter(): string { - try { - $twigEnvironment = new Environment( - new FilesystemLoader(), - ); - return $twigEnvironment - ->createTemplate($this->getTemplate()) - ->render($this->getTemplateVars()); - } catch (SyntaxError $e) { - throw new LibresignException($e->getMessage()); - } + $tempFile = $this->tempManager->getTemporaryFile('.php'); + file_put_contents($tempFile, $this->getTemplate()); + $templates = new Engine($this->tempManager->getTempBaseDir()); + return $templates->render(pathinfo($tempFile, PATHINFO_FILENAME), $this->getTemplateVars()); } public function setTemplateVar(string $name, mixed $value): self { @@ -143,28 +134,7 @@ private function getTemplateVars(): array { } private function getTemplate(): string { - return $this->appConfig->getAppValue('footer_template', <<<'HTML' -
- - | - {% endif %} -
- {{ signedBy }}
- {% if validateIn %}
- - - {{ validateIn|replace({'%s': validationSite}) }} - - {% endif %} - |
-
+ + | + +
+ = $signedBy; ?>
+
+ + + = str_replace('%s', $validationSite, $validateIn); ?> + + + |
+
@@ -94,6 +94,9 @@
connection->getDatabasePlatform()]]>
+