2017-12-14 23:06:08 +01:00
|
|
|
<?php
|
|
|
|
namespace Saccas\Mjml\Domain\Renderer;
|
|
|
|
|
|
|
|
use TYPO3\CMS\Core\Utility\CommandUtility;
|
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
2018-01-19 16:08:14 +01:00
|
|
|
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
|
2017-12-14 23:06:08 +01:00
|
|
|
|
|
|
|
class Command implements RendererInterface
|
|
|
|
{
|
2017-12-14 23:26:39 +01:00
|
|
|
public function getHtmlFromMjml($mjml)
|
2017-12-14 23:06:08 +01:00
|
|
|
{
|
|
|
|
$configuration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['mjml']);
|
|
|
|
|
|
|
|
$temporaryMjmlFileWithPath = GeneralUtility::tempnam('mjml_', '.mjml');
|
|
|
|
|
|
|
|
GeneralUtility::writeFileToTypo3tempDir($temporaryMjmlFileWithPath, $mjml);
|
|
|
|
|
|
|
|
// see https://mjml.io/download and https://www.npmjs.com/package/mjml-cli
|
2018-01-19 16:08:14 +01:00
|
|
|
$cmd = $configuration['nodeBinaryPath'] . ' ' . ExtensionManagementUtility::extPath('mjml') . $configuration['mjmlBinaryPath'] . $configuration['mjmlBinary'];
|
2017-12-14 23:06:08 +01:00
|
|
|
$args = $configuration['mjmlParams'] . ' ' . $temporaryMjmlFileWithPath;
|
|
|
|
|
|
|
|
$result = [];
|
|
|
|
$returnValue = '';
|
2018-01-19 16:08:14 +01:00
|
|
|
|
2017-12-14 23:06:08 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|