mirror of
https://github.com/saccas/mjml-typo3.git
synced 2024-11-15 12:36:09 +01:00
d1a97b9be8
* [TASK][SECURITY][!!!] Update to mjml 4 due to security npm issues * WIP|TASK: Fix broken test Fix error in test. Still the expected HTML is not as returned from mjml. * [TASK] Remove comment generated by the consoleOutput in the test * [TASK] Modify Expected.html to fit generated entry * [TASK] Add same conversions on both outputs * [TASK] Try with phpunit assertStringEqualsFile function * [TASK] remove the \n again * [BUGFIX] Add some compression configs to keep it small * [BUGFIX] reduce line length
49 lines
1.5 KiB
PHP
49 lines
1.5 KiB
PHP
<?php
|
|
namespace Saccas\Mjml\Domain\Renderer;
|
|
|
|
use TYPO3\CMS\Core\Utility\CommandUtility;
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
|
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
|
|
|
|
class Command implements RendererInterface
|
|
{
|
|
public function getHtmlFromMjml($mjml)
|
|
{
|
|
$conf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['mjml']);
|
|
|
|
$temporaryMjmlFileWithPath = GeneralUtility::tempnam('mjml_', '.mjml');
|
|
|
|
GeneralUtility::writeFileToTypo3tempDir($temporaryMjmlFileWithPath, $mjml);
|
|
|
|
$mjmlExtPath = ExtensionManagementUtility::extPath('mjml');
|
|
|
|
// see https://mjml.io/download and https://www.npmjs.com/package/mjml-cli
|
|
$cmd = $conf['nodeBinaryPath'] . ' ' . $mjmlExtPath . $conf['mjmlBinaryPath'] . $conf['mjmlBinary'];
|
|
$args = $temporaryMjmlFileWithPath . ' ' . $conf['mjmlParams'];
|
|
|
|
$result = [];
|
|
$returnValue = '';
|
|
|
|
CommandUtility::exec($this->getEscapedCommand($cmd, $args), $result, $returnValue);
|
|
|
|
GeneralUtility::unlink_tempfile($temporaryMjmlFileWithPath);
|
|
|
|
return implode('', $result);
|
|
}
|
|
|
|
/**
|
|
* @param string $cmd
|
|
* @param string $args
|
|
* @return string
|
|
*/
|
|
protected function getEscapedCommand(string $cmd, string $args)
|
|
{
|
|
$escapedCmd = escapeshellcmd($cmd);
|
|
|
|
$argsArray = explode(' ', $args);
|
|
$escapedArgsArray = CommandUtility::escapeShellArguments($argsArray);
|
|
$escapedArgs = implode(' ', $escapedArgsArray);
|
|
|
|
return $escapedCmd . ' ' . $escapedArgs;
|
|
}
|
|
}
|