diff options
author | Mario Vavti <mario@mariovavti.com> | 2015-12-18 11:33:34 +0100 |
---|---|---|
committer | Mario Vavti <mario@mariovavti.com> | 2015-12-18 11:33:34 +0100 |
commit | 84bf7058119bb2ed48358678be9c212a66c8cb83 (patch) | |
tree | 7ec4285b6b62fdfbc5f518fac516a0dacce79293 /library/Smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php | |
parent | 1b9722c65ac2169cadcf78376aaaf9d82721c9cd (diff) | |
download | volse-hubzilla-84bf7058119bb2ed48358678be9c212a66c8cb83.tar.gz volse-hubzilla-84bf7058119bb2ed48358678be9c212a66c8cb83.tar.bz2 volse-hubzilla-84bf7058119bb2ed48358678be9c212a66c8cb83.zip |
update smarty to 3.1.28 stable
Diffstat (limited to 'library/Smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php')
-rw-r--r-- | library/Smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php | 61 |
1 files changed, 57 insertions, 4 deletions
diff --git a/library/Smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php b/library/Smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php index 9487c3454..04584a40f 100644 --- a/library/Smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php +++ b/library/Smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php @@ -150,6 +150,13 @@ abstract class Smarty_Internal_TemplateCompilerBase public $write_compiled_code = true; /** + * Template functions + * + * @var array + */ + public $tpl_function = array(); + + /** * called sub functions from template function * * @var array @@ -321,7 +328,7 @@ abstract class Smarty_Internal_TemplateCompilerBase $this->compileTemplateSource($template, $nocache, $parent_compiler), $this->postFilter($this->blockOrFunctionCode) . - join('', $this->mergedSubTemplatesCode)); + join('', $this->mergedSubTemplatesCode), false, $this); return $_compiled_code; } @@ -776,12 +783,58 @@ abstract class Smarty_Internal_TemplateCompilerBase */ public function processText($text) { + $store = array(); + $_store = 0; + $_offset = 0; if ($this->parser->strip) { - return new Smarty_Internal_ParseTree_Text(preg_replace($this->stripRegEx, ' ', $text)); - } else { + if (strpos($text, '<') !== false) { + // capture html elements not to be messed with + $_offset = 0; + if (preg_match_all('#(<script[^>]*>.*?</script[^>]*>)|(<textarea[^>]*>.*?</textarea[^>]*>)|(<pre[^>]*>.*?</pre[^>]*>)#is', + $text, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { + foreach ($matches as $match) { + $store[] = $match[ 0 ][ 0 ]; + $_length = strlen($match[ 0 ][ 0 ]); + $replace = '@!@SMARTY:' . $_store . ':SMARTY@!@'; + $text = substr_replace($text, $replace, $match[ 0 ][ 1 ] - $_offset, $_length); + + $_offset += $_length - strlen($replace); + $_store ++; + } + } + + $expressions = array(// replace multiple spaces between tags by a single space + // can't remove them entirely, becaue that might break poorly implemented CSS display:inline-block elements + '#(:SMARTY@!@|>)\s+(?=@!@SMARTY:|<)#s' => '\1 \2', + // remove spaces between attributes (but not in attribute values!) + '#(([a-z0-9]\s*=\s*("[^"]*?")|(\'[^\']*?\'))|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \5', + '#^\s+<#Ss' => '<', + '#>\s+$#Ss' => '>', + $this->stripRegEx => '' + ); + + $text = preg_replace(array_keys($expressions), array_values($expressions), $text); + $_offset = 0; + if (preg_match_all('#@!@SMARTY:([0-9]+):SMARTY@!@#is', $text, $matches, + PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { + foreach ($matches as $match) { + $_length = strlen($match[ 0 ][ 0 ]); + $replace = $store[ $match[ 1 ][ 0 ] ]; + $text = substr_replace($text, $replace, $match[ 0 ][ 1 ] + $_offset, $_length); + + $_offset += strlen($replace) - $_length; + $_store ++; + } + } + } else { + $text = preg_replace($this->stripRegEx, '', $text); + } + } + if ($text) { return new Smarty_Internal_ParseTree_Text($text); } - } + return null; + } /** * lazy loads internal compile plugin for tag and calls the compile method |