Index: functions_template.php =================================================================== --- functions_template.php (revision 8683) +++ functions_template.php (working copy) @@ -146,25 +146,42 @@ $text_blocks = str_replace($var_val[0], $new, $text_blocks); } - // This will handle the remaining root-level varrefs - // transform vars prefixed by L_ into their language variable pendant if nothing is set within the tpldata array - if (strpos($text_blocks, '{L_') !== false) - { - $text_blocks = preg_replace('#\{L_([a-z0-9\-_]*)\}#is', "_rootref['L_\\1'])) ? \$this->_rootref['L_\\1'] : ((isset(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '{ \\1 }')); ?>", $text_blocks); - } + // Handle varrefs + $text_blocks = preg_replace_callback('#\{(L_|LA_|JS_|)([a-z0-9\-_]*)\}#is', array(&$this, 'compile_var_tags_callback'), $text_blocks); - // Handle addslashed language variables prefixed with LA_ - // If a template variable already exist, it will be used in favor of it... - if (strpos($text_blocks, '{LA_') !== false) + return $text_blocks; + } + + /** + * Callback function for handling var tags + * @access private + */ + private function compile_var_tags_callback($matches) + { + switch ($matches[1]) { - $text_blocks = preg_replace('#\{LA_([a-z0-9\-_]*)\}#is', "_rootref['LA_\\1'])) ? \$this->_rootref['LA_\\1'] : ((isset(\$this->_rootref['L_\\1'])) ? addslashes(\$this->_rootref['L_\\1']) : ((isset(\$user->lang['\\1'])) ? addslashes(\$user->lang['\\1']) : '{ \\1 }'))); ?>", $text_blocks); - } + // This will handle the remaining root-level varrefs + // transform vars prefixed by L_ into their language variable pendant if nothing is set within the tpldata array + case 'L_': + return "_rootref['L_{$matches[2]}'])) ? \$this->_rootref['L_{$matches[2]}'] : ((isset(\$user->lang['{$matches[2]}'])) ? \$user->lang['{$matches[2]}'] : '{ {$matches[2]} }')); ?>"; + break; - // Handle remaining varrefs - $text_blocks = preg_replace('#\{([a-z0-9\-_]*)\}#is', "_rootref['\\1'])) ? \$this->_rootref['\\1'] : ''; ?>", $text_blocks); - $text_blocks = preg_replace('#\{\$([a-z0-9\-_]*)\}#is', "_tpldata['DEFINE']['.']['\\1'])) ? \$this->_tpldata['DEFINE']['.']['\\1'] : ''; ?>", $text_blocks); + // Handle addslashed language variables prefixed with LA_ + // If a template variable already exist, it will be used in favor of it... + case 'LA_': + return "_rootref['LA_{$matches[2]}'])) ? \$this->_rootref['LA_{$matches[2]}'] : ((isset(\$this->_rootref['L_{$matches[2]}'])) ? addslashes(\$this->_rootref['L_{$matches[2]}']) : ((isset(\$user->lang['{$matches[2]}'])) ? addslashes(\$user->lang['{$matches[2]}']) : '{ {$matches[2]} }'))); ?>"; + break; - return $text_blocks; + // This works just like LA_ but will work for normal template variables + case 'JS_': + return "_rootref['JS_{$matches[2]}'])) ? \$this->_rootref['JS_{$matches[2]}'] : ((isset(\$this->_rootref['{$matches[2]}'])) ? addslashes(\$this->_rootref['{$matches[2]}']) : '')); ?>"; + break; + + // Handle normal template variables + default: + return "_rootref['{$matches[2]}'])) ? \$this->_rootref['{$matches[2]}'] : ''; ?>"; + break; + } } /** @@ -525,7 +542,7 @@ switch ($expr_type) { case 'even': - if (@$tokens[$expr_end] == 'by') + if (isset($tokens[$expr_end]) && $tokens[$expr_end] == 'by') { $expr_end++; $expr_arg = $tokens[$expr_end++]; @@ -538,7 +555,7 @@ break; case 'odd': - if (@$tokens[$expr_end] == 'by') + if (isset($tokens[$expr_end]) && $tokens[$expr_end] == 'by') { $expr_end++; $expr_arg = $tokens[$expr_end++]; @@ -551,7 +568,7 @@ break; case 'div': - if (@$tokens[$expr_end] == 'by') + if (isset($tokens[$expr_end]) && $tokens[$expr_end] == 'by') { $expr_end++; $expr_arg = $tokens[$expr_end++]; @@ -668,9 +685,9 @@ /** * constuctor */ - function __construct(template &$template) + function __construct(template $template) { - $this->template = &$template; + $this->template = $template; } /**