Updates for twig

This commit is contained in:
David Bomba 2024-05-16 10:20:54 +10:00
parent f7fb20a7ec
commit 7940f9c3b7
4 changed files with 11 additions and 20 deletions

View File

@ -137,7 +137,7 @@ class UpdateCompanyRequest extends Request
}
if (isset($settings['email_style_custom'])) {
$settings['email_style_custom'] = str_replace(['{!!','!!}','{{','}}','@dd', '@dump', '@if', '@if(','@endif','@isset','@unless','@auth','@empty','@guest','@env','@section','@switch', '@foreach', '@while', '@include', '@each', '@once', '@push', '@use', '@forelse', '@verbatim', '<?php', '@php', '@for','@class','</s','<s','html;base64'], '', $settings['email_style_custom']);
$settings['email_style_custom'] = str_replace(['{!!','!!}','{{','}}','@checked','@dd', '@dump', '@if', '@if(','@endif','@isset','@unless','@auth','@empty','@guest','@env','@section','@switch', '@foreach', '@while', '@include', '@each', '@once', '@push', '@use', '@forelse', '@verbatim', '<?php', '@php', '@for','@class','</sc','<sc','html;base64', '@elseif', '@else', '@endunless', '@endisset', '@endempty', '@endauth', '@endguest', '@endproduction', '@endenv', '@hasSection', '@endhasSection', '@sectionMissing', '@endsectionMissing', '@endfor', '@endforeach', '@empty', '@endforelse', '@endwhile', '@continue', '@break', '@includeIf', '@includeWhen', '@includeUnless', '@includeFirst', '@component', '@endcomponent', '@endsection', '@yield', '@show', '@append', '@overwrite', '@stop', '@extends', '@endpush', '@stack', '@prepend', '@endprepend', '@slot', '@endslot', '@endphp', '@method', '@csrf', '@error', '@enderror', '@json', '@endverbatim', '@inject'], '', $settings['email_style_custom']);
}
if(isset($settings['company_logo']) && strlen($settings['company_logo']) > 2)

View File

@ -100,6 +100,7 @@ class TemplateService
$this->twig->addExtension(new IntlExtension());
$this->twig->addExtension(new \Twig\Extension\DebugExtension());
$function = new \Twig\TwigFunction('img', function ($string, $style = '') {
return '<img src="' . $string . '" style="' . $style . '"></img>';
});
@ -122,25 +123,14 @@ class TemplateService
$this->twig->addFilter($filter);
$filter = new \Twig\TwigFilter('filter', function ($array, $arrow){
$allowedTags = ['if', 'for', 'set', 'filter'];
$allowedFilters = ['escape', 'e', 'upper', 'lower', 'capitalize', 'filter', 'length', 'merge','format_currency','map', 'join', 'first', 'date','sum'];
$allowedFunctions = ['range', 'cycle', 'constant', 'date',];
$allowedProperties = [];
$allowedMethods = ['img','t'];
if(is_string($arrow) && in_array($arrow, ['popen','exec','shell_exec','system','passthru','proc_open','pcntl_exec','sleep','escapeshellcmd','escapeshellarg']))
throw new RuntimeError("Attempt to access command line");
if (!is_iterable($array)) {
throw new RuntimeError(sprintf('The "filter" filter expects an array or "Traversable", got "%s".', \is_object($array) ? \get_class($array) : \gettype($array)));
}
if (\is_array($array)) {
return array_filter($array, $arrow, \ARRAY_FILTER_USE_BOTH);
}
// the IteratorIterator wrapping is needed as some internal PHP classes are \Traversable but do not implement \Iterator
return new \CallbackFilterIterator(new \IteratorIterator($array), $arrow);
});
$this->twig->addFilter($filter);
$policy = new \Twig\Sandbox\SecurityPolicy($allowedTags, $allowedFilters, $allowedFunctions, $allowedProperties, $allowedMethods);
$this->twig->addExtension(new \Twig\Extension\SandboxExtension($policy, true));
return $this;
}

View File

@ -255,7 +255,7 @@ class TemplateEngine
/*If no custom design exists, send back a blank!*/
if (strlen($wrapper) > 1) {
$wrapper = $this->renderView($wrapper, $data);
// $wrapper = $this->renderView($wrapper, $data);
} else {
$wrapper = '';
}

View File

@ -36,6 +36,7 @@ trait MakesInvoiceHtml
* @param string $string The Blade file string
* @param array $data The array of template variables
* @return string The return HTML string
* @deprecated // not needed!
* @throws FatalThrowableError
*/
public function renderView($string, $data = []): string