*/
function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $double_encode = true)
{
+ static $_double_encode = null;
+ if ($_double_encode === null) {
+ $_double_encode = version_compare(PHP_VERSION, '5.2.3', '>=');
+ }
+
if (!$char_set) {
$char_set = Smarty::$_CHARSET;
}
switch ($esc_type) {
case 'html':
- return htmlspecialchars($string, ENT_QUOTES, $char_set, $double_encode);
+ if ($_double_encode) {
+ // php >=5.3.2 - go native
+ return htmlspecialchars($string, ENT_QUOTES, $char_set, $double_encode);
+ } else {
+ if ($double_encode) {
+ // php <5.3.2 - only handle double encoding
+ return htmlspecialchars($string, ENT_QUOTES, $char_set);
+ } else {
+ // php <5.3.2 - prevent double encoding
+ $string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
+ $string = htmlspecialchars($string, ENT_QUOTES, $char_set);
+ $string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string);
+ return $string;
+ }
+ }
case 'htmlall':
if (Smarty::$_MBSTRING) {
// mb_convert_encoding ignores htmlspecialchars()
- $string = htmlspecialchars($string, ENT_QUOTES, $char_set, $double_encode);
+ if ($_double_encode) {
+ // php >=5.3.2 - go native
+ $string = htmlspecialchars($string, ENT_QUOTES, $char_set, $double_encode);
+ } else {
+ if ($double_encode) {
+ // php <5.3.2 - only handle double encoding
+ $string = htmlspecialchars($string, ENT_QUOTES, $char_set);
+ } else {
+ // php <5.3.2 - prevent double encoding
+ $string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
+ $string = htmlspecialchars($string, ENT_QUOTES, $char_set);
+ $string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string);
+ return $string;
+ }
+ }
+
// htmlentities() won't convert everything, so use mb_convert_encoding
return mb_convert_encoding($string, 'HTML-ENTITIES', $char_set);
}
// no MBString fallback
- return htmlentities($string, ENT_QUOTES, $char_set, $double_encode);
+ if ($_double_encode) {
+ return htmlentities($string, ENT_QUOTES, $char_set, $double_encode);
+ } else {
+ if ($double_encode) {
+ return htmlentities($string, ENT_QUOTES, $char_set);
+ } else {
+ $string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
+ $string = htmlentities($string, ENT_QUOTES, $char_set);
+ $string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string);
+ return $string;
+ }
+ }
case 'url':
return rawurlencode($string);
*/\r
function smarty_modifiercompiler_escape($params, $compiler)\r
{\r
+ static $_double_encode = null;\r
+ if ($_double_encode === null) {\r
+ $_double_encode = version_compare(PHP_VERSION, '5.2.3', '>=');\r
+ }\r
+ \r
try {\r
$esc_type = smarty_literal_compiler_param($params, 1, 'html');\r
$char_set = smarty_literal_compiler_param($params, 2, Smarty::$_CHARSET);\r
\r
switch ($esc_type) {\r
case 'html':\r
- return 'htmlspecialchars('\r
- . $params[0] .', ENT_QUOTES, '\r
- . var_export($char_set, true) . ', '\r
- . var_export($double_encode, true) . ')';\r
+ if ($_double_encode) {\r
+ return 'htmlspecialchars('\r
+ . $params[0] .', ENT_QUOTES, '\r
+ . var_export($char_set, true) . ', '\r
+ . var_export($double_encode, true) . ')';\r
+ } else if ($double_encode) {\r
+ return 'htmlspecialchars('\r
+ . $params[0] .', ENT_QUOTES, '\r
+ . var_export($char_set, true) . ')';\r
+ } else {\r
+ // fall back to modifier.escape.php\r
+ }\r
\r
case 'htmlall':\r
if (Smarty::$_MBSTRING) {\r
- return 'mb_convert_encoding(htmlspecialchars('\r
+ if ($_double_encode) {\r
+ // php >=5.3.2 - go native\r
+ return 'mb_convert_encoding(htmlspecialchars('\r
+ . $params[0] .', ENT_QUOTES, '\r
+ . var_export($char_set, true) . ', '\r
+ . var_export($double_encode, true)\r
+ . '), "HTML-ENTITIES", '\r
+ . var_export($char_set, true) . ')';\r
+ } else if ($double_encode) {\r
+ // php <5.3.2 - only handle double encoding\r
+ return 'mb_convert_encoding(htmlspecialchars('\r
+ . $params[0] .', ENT_QUOTES, '\r
+ . var_export($char_set, true)\r
+ . '), "HTML-ENTITIES", '\r
+ . var_export($char_set, true) . ')';\r
+ } else {\r
+ // fall back to modifier.escape.php\r
+ }\r
+ }\r
+\r
+ // no MBString fallback\r
+ if ($_double_encode) {\r
+ // php >=5.3.2 - go native\r
+ return 'htmlentities('\r
. $params[0] .', ENT_QUOTES, '\r
. var_export($char_set, true) . ', '\r
- . var_export($double_encode, true)\r
- . '), "HTML-ENTITIES", '\r
+ . var_export($double_encode, true) . ')';\r
+ } else if ($double_encode) {\r
+ // php <5.3.2 - only handle double encoding\r
+ return 'htmlentities('\r
+ . $params[0] .', ENT_QUOTES, '\r
. var_export($char_set, true) . ')';\r
+ } else {\r
+ // fall back to modifier.escape.php\r
}\r
\r
- // no MBString fallback\r
- return 'htmlentities('\r
- . $params[0] .', ENT_QUOTES, '\r
- . var_export($char_set, true) . ', '\r
- . var_export($double_encode, true) . ')';\r
-\r
case 'url':\r
return 'rawurlencode(' . $params[0] . ')';\r
\r
<?php
+
/**
-* Smarty Internal Plugin Compile Block
-*
-* Compiles the {block}{/block} tags
-*
-* @package Smarty
-* @subpackage Compiler
-* @author Uwe Tews
-*/
+ * Smarty Internal Plugin Compile Block
+ *
+ * Compiles the {block}{/block} tags
+ *
+ * @package Smarty
+ * @subpackage Compiler
+ * @author Uwe Tews
+ */
/**
-* Smarty Internal Plugin Compile Block Class
-*
-* @package Smarty
-* @subpackage Compiler
-*/
+ * Smarty Internal Plugin Compile Block Class
+ *
+ * @package Smarty
+ * @subpackage Compiler
+ */
class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
/**
- * Attribute definition: Overwrites base class.
- *
- * @var array
- * @see Smarty_Internal_CompileBase
- */
+ * Attribute definition: Overwrites base class.
+ *
+ * @var array
+ * @see Smarty_Internal_CompileBase
+ */
public $required_attributes = array('name');
+
/**
- * Attribute definition: Overwrites base class.
- *
- * @var array
- * @see Smarty_Internal_CompileBase
- */
+ * Attribute definition: Overwrites base class.
+ *
+ * @var array
+ * @see Smarty_Internal_CompileBase
+ */
public $shorttag_order = array('name', 'hide');
+
/**
- * Attribute definition: Overwrites base class.
- *
- * @var array
- * @see Smarty_Internal_CompileBase
- */
+ * Attribute definition: Overwrites base class.
+ *
+ * @var array
+ * @see Smarty_Internal_CompileBase
+ */
public $optional_attributes = array('hide');
/**
- * Compiles code for the {block} tag
- *
- * @param array $args array with attributes from parser
- * @param object $compiler compiler object
- * @return boolean true
- */
- public function compile($args, $compiler)
- {
+ * Compiles code for the {block} tag
+ *
+ * @param array $args array with attributes from parser
+ * @param object $compiler compiler object
+ * @return boolean true
+ */
+ public function compile($args, $compiler) {
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$save = array($_attr, $compiler->parser->current_buffer, $compiler->nocache, $compiler->smarty->merge_compiled_includes, $compiler->merged_templates, $compiler->smarty->merged_templates_func, $compiler->template->properties, $compiler->template->has_nocache_code);
}
/**
- * Save or replace child block source by block name during parsing
- *
- * @param string $block_content block source content
- * @param string $block_tag opening block tag
- * @param object $template template object
- * @param string $filepath filepath of template source
- */
- public static function saveBlockData($block_content, $block_tag, $template, $filepath)
- {
+ * Save or replace child block source by block name during parsing
+ *
+ * @param string $block_content block source content
+ * @param string $block_tag opening block tag
+ * @param object $template template object
+ * @param string $filepath filepath of template source
+ */
+ public static function saveBlockData($block_content, $block_tag, $template, $filepath) {
$_rdl = preg_quote($template->smarty->right_delimiter);
$_ldl = preg_quote($template->smarty->left_delimiter);
if ($template->smarty->auto_literal) {
$_name = trim($_match[3], '\'"');
if ($_match[8] != 'hide' || isset($template->block_data[$_name])) { // replace {$smarty.block.child}
// do we have {$smart.block.child} in nested {block} tags?
- if (0 != preg_match_all("!({$_ldl}{$al}block\s+)(name=)?(\w+|'.*'|\".*\")([\s\S]*?{$_rdl})([\s\S]*?)({$_ldl}{$al}\\\$smarty\.block\.child{$_rdl})([\s\S]*?{$_ldl}{$al}/block{$_rdl})!", $block_content, $_match2)) {
- foreach($_match2[3] as $name) {
+ if (0 != preg_match_all("!({$_ldl}{$al}block\s+)(name=)?(\w+|'.*'|\".*\")([\s\S]*?)(hide)?(\s*{$_rdl})([\s\S]*?)({$_ldl}{$al}\\\$smarty\.block\.child{$_rdl})([\s\S]*?{$_ldl}{$al}/block{$_rdl})!", $block_content, $_match2)) {
+ foreach ($_match2[3] as $key => $name) {
// get it's replacement
$_name2 = trim($name, '\'"');
- if (isset($template->block_data[$_name2])) {
- $replacement = $template->block_data[$_name2]['source'];
+ if ($_match2[5][$key] != 'hide' || isset($template->block_data[$_name2])) {
+ if (isset($template->block_data[$_name2])) {
+ $replacement = $template->block_data[$_name2]['source'];
+ } else {
+ $replacement = '';
+ }
+ // replace {$smarty.block.child} tag
+ $search = array("%({$_ldl}{$al}block[\s\S]*?{$name}[\s\S]*?{$_rdl})([\s\S]*?)({$_ldl}{$al}\\\$smarty\.block\.child{$_rdl})([\s\S]*?)({$_ldl}{$al}/block{$_rdl})%", "/§§§child§§§/");
+ $replace = array('\2§§§child§§§\4', $replacement);
+ $block_content = preg_replace($search, $replace, $block_content);
} else {
- $replacement = '';
+ // remove hidden blocks
+ $block_content = preg_replace("%({$_ldl}{$al}block[\s\S]*?{$name}[\s\S]*?{$_rdl}[\s\S]*?{$_ldl}{$al}/block{$_rdl})%", '', $block_content);
}
- // replace {$smarty.block.child} tag
- $search = array("%({$_ldl}{$al}block[\s\S]*?{$name}[\s\S]*?{$_rdl})([\s\S]*?)({$_ldl}{$al}\\\$smarty\.block\.child{$_rdl})([\s\S]*?)({$_ldl}{$al}/block{$_rdl})%","/§§§child§§§/");
- $replace = array('\2§§§child§§§\4', $replacement);
- $block_content = preg_replace($search, $replace , $block_content);
}
}
// do we have not nested {$smart.block.child}
if (isset($template->block_data[$_name])) {
if (strpos($template->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
$template->block_data[$_name]['source'] =
- str_replace('%%%%SMARTY_PARENT%%%%', $block_content, $template->block_data[$_name]['source']);
+ str_replace('%%%%SMARTY_PARENT%%%%', $block_content, $template->block_data[$_name]['source']);
} elseif ($template->block_data[$_name]['mode'] == 'prepend') {
$template->block_data[$_name]['source'] .= $block_content;
} elseif ($template->block_data[$_name]['mode'] == 'append') {
}
/**
- * Compile saved child block source
- *
- * @param object $compiler compiler object
- * @param string $_name optional name of child block
- * @return string compiled code of schild block
- */
- public static function compileChildBlock($compiler, $_name = null)
- {
+ * Compile saved child block source
+ *
+ * @param object $compiler compiler object
+ * @param string $_name optional name of child block
+ * @return string compiled code of schild block
+ */
+ public static function compileChildBlock($compiler, $_name = null) {
$_output = '';
// if called by {$smarty.block.child} we must search the name of enclosing {block}
if ($_name == null) {
$stack_count = count($compiler->_tag_stack);
while (--$stack_count >= 0) {
if ($compiler->_tag_stack[$stack_count][0] == 'block') {
- $_name = trim($compiler->_tag_stack[$stack_count][1][0]['name'] ,"'\"");
+ $_name = trim($compiler->_tag_stack[$stack_count][1][0]['name'], "'\"");
break;
}
}
if (!isset($compiler->template->block_data[$_name]['source'])) {
return '';
}
- $_tpl = new Smarty_Internal_template ('string:' . $compiler->template->block_data[$_name]['source'], $compiler->smarty, $compiler->template, $compiler->template->cache_id,
- $compiler->template->compile_id = null, $compiler->template->caching, $compiler->template->cache_lifetime);
+ $_tpl = new Smarty_Internal_template('string:' . $compiler->template->block_data[$_name]['source'], $compiler->smarty, $compiler->template, $compiler->template->cache_id,
+ $compiler->template->compile_id = null, $compiler->template->caching, $compiler->template->cache_lifetime);
$_tpl->variable_filters = $compiler->template->variable_filters;
$_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash'];
$_tpl->source->filepath = $compiler->template->block_data[$_name]['file'];
if ($_tpl->has_nocache_code) {
$compiler->template->has_nocache_code = true;
}
- foreach($_tpl->required_plugins as $key => $tmp1) {
- if ($compiler->nocache && $compiler->template->caching) {
+ foreach ($_tpl->required_plugins as $key => $tmp1) {
+ if ($compiler->nocache && $compiler->template->caching) {
$code = 'nocache';
} else {
$code = $key;
}
- foreach($tmp1 as $name => $tmp) {
- foreach($tmp as $type => $data) {
+ foreach ($tmp1 as $name => $tmp) {
+ foreach ($tmp as $type => $data) {
$compiler->template->required_plugins[$code][$name][$type] = $data;
}
}
}
/**
-* Smarty Internal Plugin Compile BlockClose Class
-*
-* @package Smarty
-* @subpackage Compiler
-*/
+ * Smarty Internal Plugin Compile BlockClose Class
+ *
+ * @package Smarty
+ * @subpackage Compiler
+ */
class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase {
/**
- * Compiles code for the {/block} tag
- *
- * @param array $args array with attributes from parser
- * @param object $compiler compiler object
- * @return string compiled code
- */
- public function compile($args, $compiler)
- {
+ * Compiles code for the {/block} tag
+ *
+ * @param array $args array with attributes from parser
+ * @param object $compiler compiler object
+ * @return string compiled code
+ */
+ public function compile($args, $compiler) {
$compiler->has_code = true;
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
} else {
$_output = $compiler->parser->current_buffer->to_smarty_php();
}
- unset ($compiler->template->block_data[$_name]['compiled']);
+ unset($compiler->template->block_data[$_name]['compiled']);
}
// reset flags
$compiler->parser->current_buffer = $saved_data[1];