- bugfix on error message in smarty_internal_compile_block.php

- bugfix mb handling in strip modifier
- bugfix for Smarty2 style registered compiler function on unnamed attribute passing like {tag $foo $bar}
This commit is contained in:
uwe.tews@googlemail.com
2011-03-28 22:18:39 +00:00
parent 6b0f3a6ede
commit 1757b274d6
4 changed files with 132 additions and 123 deletions

View File

@@ -1,4 +1,9 @@
===== SVN trunk ===== ===== SVN trunk =====
29/03/2011
- bugfix on error message in smarty_internal_compile_block.php
- bugfix mb handling in strip modifier
- bugfix for Smarty2 style registered compiler function on unnamed attribute passing like {tag $foo $bar}
17/03/2011 17/03/2011
- bugfix on default {function} parameters when {function} was used in nocache sections - bugfix on default {function} parameters when {function} was used in nocache sections
- bugfix on compiler object destruction. compiler_object property was by mistake unset. - bugfix on compiler object destruction. compiler_object property was by mistake unset.

View File

@@ -26,8 +26,8 @@ function smarty_modifiercompiler_strip($params, $compiler)
{ {
if (!isset($params[1])) { if (!isset($params[1])) {
$params[1] = "' '"; $params[1] = "' '";
} }
return "preg_replace('!\s+!', {$params[1]},{$params[0]})"; return "preg_replace('!\s+!u', {$params[1]},{$params[0]})";
} }
?> ?>

View File

@@ -1,12 +1,12 @@
<?php <?php
/** /**
* Smarty Internal Plugin Compile Block * Smarty Internal Plugin Compile Block
* *
* Compiles the {block}{/block} tags * Compiles the {block}{/block} tags
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
@@ -18,7 +18,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
public $shorttag_order = array('name'); public $shorttag_order = array('name');
/** /**
* Compiles code for the {block} tag * Compiles code for the {block} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return boolean true * @return boolean true
@@ -36,12 +36,12 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
// set flag for {block} tag // set flag for {block} tag
$compiler->smarty->inheritance = true; $compiler->smarty->inheritance = true;
// must merge includes // must merge includes
$this->compiler->smarty->merge_compiled_includes = true; $this->compiler->smarty->merge_compiled_includes = true;
$compiler->parser->current_buffer = new _smarty_template_buffer($compiler->parser); $compiler->parser->current_buffer = new _smarty_template_buffer($compiler->parser);
$compiler->has_code = false; $compiler->has_code = false;
return true; return true;
} }
static function saveBlockData($block_content, $block_tag, $template, $filepath) static function saveBlockData($block_content, $block_tag, $template, $filepath)
@@ -53,7 +53,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
$error_text = 'Syntax Error in template "' . $template->getTemplateFilepath() . '" "' . htmlspecialchars($block_tag) . '" illegal options'; $error_text = 'Syntax Error in template "' . $template->getTemplateFilepath() . '" "' . htmlspecialchars($block_tag) . '" illegal options';
throw new SmartyCompilerException($error_text); throw new SmartyCompilerException($error_text);
} else { } else {
$_name = trim($_match[3], '\'"'); $_name = trim($_match[3], '\'"');
// replace {$smarty.block.child} // replace {$smarty.block.child}
if (strpos($block_content, $template->smarty->left_delimiter . '$smarty.block.child' . $template->smarty->right_delimiter) !== false) { if (strpos($block_content, $template->smarty->left_delimiter . '$smarty.block.child' . $template->smarty->right_delimiter) !== false) {
if (isset($template->block_data[$_name])) { if (isset($template->block_data[$_name])) {
@@ -63,8 +63,8 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
} else { } else {
$block_content = str_replace($template->smarty->left_delimiter . '$smarty.block.child' . $template->smarty->right_delimiter, $block_content = str_replace($template->smarty->left_delimiter . '$smarty.block.child' . $template->smarty->right_delimiter,
'', $block_content); '', $block_content);
} }
} }
if (isset($template->block_data[$_name])) { if (isset($template->block_data[$_name])) {
if (strpos($template->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) { if (strpos($template->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
$template->block_data[$_name]['source'] = $template->block_data[$_name]['source'] =
@@ -73,17 +73,17 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
$template->block_data[$_name]['source'] .= $block_content; $template->block_data[$_name]['source'] .= $block_content;
} elseif ($template->block_data[$_name]['mode'] == 'append') { } elseif ($template->block_data[$_name]['mode'] == 'append') {
$template->block_data[$_name]['source'] = $block_content . $template->block_data[$_name]['source']; $template->block_data[$_name]['source'] = $block_content . $template->block_data[$_name]['source'];
} }
} else { } else {
$template->block_data[$_name]['source'] = $block_content; $template->block_data[$_name]['source'] = $block_content;
} }
if ($_match[6] == 'append') { if ($_match[6] == 'append') {
$template->block_data[$_name]['mode'] = 'append'; $template->block_data[$_name]['mode'] = 'append';
} elseif ($_match[6] == 'prepend') { } elseif ($_match[6] == 'prepend') {
$template->block_data[$_name]['mode'] = 'prepend'; $template->block_data[$_name]['mode'] = 'prepend';
} else { } else {
$template->block_data[$_name]['mode'] = 'replace'; $template->block_data[$_name]['mode'] = 'replace';
} }
$template->block_data[$_name]['file'] = $filepath; $template->block_data[$_name]['file'] = $filepath;
} }
} }
@@ -104,13 +104,13 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
$compiler->template->block_data[$_name]['compiled'] = true; $compiler->template->block_data[$_name]['compiled'] = true;
} }
if ($_name == null) { if ($_name == null) {
$compiler->trigger_template_error('{$smarty.block.child} used out of context', $this->compiler->lex->taglineno); $compiler->trigger_template_error('{$smarty.block.child} used out of context', $compiler->lex->taglineno);
} }
// undefined child? // undefined child?
if (!isset($compiler->template->block_data[$_name])) { if (!isset($compiler->template->block_data[$_name])) {
return ''; return '';
} }
$_tpl = new Smarty_Internal_template ('eval:' . $compiler->template->block_data[$_name]['source'], $compiler->smarty, $compiler->template, $compiler->template->cache_id, $_tpl = new Smarty_Internal_template ('eval:' . $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); $compiler->template->compile_id = null, $compiler->template->caching, $compiler->template->cache_lifetime);
$_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash']; $_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash'];
$_tpl->template_filepath = $compiler->template->block_data[$_name]['file']; $_tpl->template_filepath = $compiler->template->block_data[$_name]['file'];
@@ -154,7 +154,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase { class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase {
/** /**
* Compiles code for the {/block} tag * Compiles code for the {/block} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object $compiler compiler object
* @return string compiled code * @return string compiled code
@@ -163,7 +163,7 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase {
{ {
$this->compiler = $compiler; $this->compiler = $compiler;
$this->smarty = $compiler->smarty; $this->smarty = $compiler->smarty;
$this->compiler->has_code = true; $this->compiler->has_code = true;
// check and get attributes // check and get attributes
$_attr = $this->_get_attributes($args); $_attr = $this->_get_attributes($args);
$saved_data = $this->_close_tag(array('block')); $saved_data = $this->_close_tag(array('block'));
@@ -182,6 +182,6 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase {
// $_output content has already nocache code processed // $_output content has already nocache code processed
$compiler->suppressNocacheProcessing = true; $compiler->suppressNocacheProcessing = true;
return $_output; return $_output;
} }
} }
?> ?>

View File

@@ -1,12 +1,12 @@
<?php <?php
/** /**
* Smarty Internal Plugin Smarty Template Compiler Base * Smarty Internal Plugin Smarty Template Compiler Base
* *
* This file contains the basic classes and methodes for compiling Smarty templates with lexer/parser * This file contains the basic classes and methodes for compiling Smarty templates with lexer/parser
* *
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
@@ -14,13 +14,13 @@
*/ */
class Smarty_Internal_TemplateCompilerBase { class Smarty_Internal_TemplateCompilerBase {
// hash for nocache sections // hash for nocache sections
private $nocache_hash = null; private $nocache_hash = null;
// suppress generation of nocache code // suppress generation of nocache code
public $suppressNocacheProcessing = false; public $suppressNocacheProcessing = false;
// compile tag objects // compile tag objects
static $_tag_objects = array(); static $_tag_objects = array();
// tag stack // tag stack
public $_tag_stack = array(); public $_tag_stack = array();
// current template // current template
public $template = null; public $template = null;
// optional log of tag/attributes // optional log of tag/attributes
@@ -32,11 +32,11 @@ class Smarty_Internal_TemplateCompilerBase {
public function __construct() public function __construct()
{ {
$this->nocache_hash = str_replace('.', '-', uniqid(rand(), true)); $this->nocache_hash = str_replace('.', '-', uniqid(rand(), true));
} }
/** /**
* Methode to compile a Smarty template * Methode to compile a Smarty template
* *
* @param $template template object to compile * @param $template template object to compile
* @return bool true if compiling succeeded, false if it failed * @return bool true if compiling succeeded, false if it failed
*/ */
@@ -46,38 +46,38 @@ class Smarty_Internal_TemplateCompilerBase {
$template->properties['nocache_hash'] = $this->nocache_hash; $template->properties['nocache_hash'] = $this->nocache_hash;
} else { } else {
$this->nocache_hash = $template->properties['nocache_hash']; $this->nocache_hash = $template->properties['nocache_hash'];
} }
// flag for nochache sections // flag for nochache sections
$this->nocache = false; $this->nocache = false;
$this->tag_nocache = false; $this->tag_nocache = false;
// save template object in compiler class // save template object in compiler class
$this->template = $template; $this->template = $template;
$this->smarty->_current_file = $saved_filepath = $this->template->getTemplateFilepath(); $this->smarty->_current_file = $saved_filepath = $this->template->getTemplateFilepath();
// template header code // template header code
$template_header = ''; $template_header = '';
if (!$template->suppressHeader) { if (!$template->suppressHeader) {
$template_header .= "<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . "\n"; $template_header .= "<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . "\n";
$template_header .= " compiled from \"" . $this->template->getTemplateFilepath() . "\" */ ?>\n"; $template_header .= " compiled from \"" . $this->template->getTemplateFilepath() . "\" */ ?>\n";
} }
do { do {
// flag for aborting current and start recompile // flag for aborting current and start recompile
$this->abort_and_recompile = false; $this->abort_and_recompile = false;
// get template source // get template source
$_content = $template->getTemplateSource(); $_content = $template->getTemplateSource();
// run prefilter if required // run prefilter if required
if (isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre'])) { if (isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre'])) {
$template->template_source = $_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $template); $template->template_source = $_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $template);
} }
// on empty template just return header // on empty template just return header
if ($_content == '') { if ($_content == '') {
if ($template->suppressFileDependency) { if ($template->suppressFileDependency) {
$template->compiled_template = ''; $template->compiled_template = '';
} else { } else {
$template->compiled_template = $template_header . $template->createPropertyHeader(); $template->compiled_template = $template_header . $template->createPropertyHeader();
} }
return true; return true;
} }
// call compiler // call compiler
$_compiled_code = $this->doCompile($_content); $_compiled_code = $this->doCompile($_content);
} while ($this->abort_and_recompile); } while ($this->abort_and_recompile);
@@ -88,26 +88,26 @@ class Smarty_Internal_TemplateCompilerBase {
$template->compiled_template = $_compiled_code; $template->compiled_template = $_compiled_code;
} else { } else {
$template->compiled_template = $template_header . $template->createPropertyHeader() . $_compiled_code; $template->compiled_template = $template_header . $template->createPropertyHeader() . $_compiled_code;
} }
// run postfilter if required // run postfilter if required
if (isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) { if (isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) {
$template->compiled_template = Smarty_Internal_Filter_Handler::runFilter('post', $template->compiled_template, $template); $template->compiled_template = Smarty_Internal_Filter_Handler::runFilter('post', $template->compiled_template, $template);
} }
} }
/** /**
* Compile Tag * Compile Tag
* *
* This is a call back from the lexer/parser * This is a call back from the lexer/parser
* It executes the required compile plugin for the Smarty tag * It executes the required compile plugin for the Smarty tag
* *
* @param string $tag tag name * @param string $tag tag name
* @param array $args array with tag attributes * @param array $args array with tag attributes
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* @return string compiled code * @return string compiled code
*/ */
public function compileTag($tag, $args, $parameter = array()) public function compileTag($tag, $args, $parameter = array())
{ {
// $args contains the attributes parsed and compiled by the lexer/parser // $args contains the attributes parsed and compiled by the lexer/parser
// assume that tag does compile into code, but creates no HTML output // assume that tag does compile into code, but creates no HTML output
$this->has_code = true; $this->has_code = true;
@@ -115,7 +115,7 @@ class Smarty_Internal_TemplateCompilerBase {
// log tag/attributes // log tag/attributes
if (isset($this->smarty->get_used_tags) && $this->smarty->get_used_tags) { if (isset($this->smarty->get_used_tags) && $this->smarty->get_used_tags) {
$this->used_tags[] = array($tag,$args); $this->used_tags[] = array($tag,$args);
} }
// check nocache option flag // check nocache option flag
if (in_array("'nocache'",$args) || in_array(array('nocache'=>'true'),$args) if (in_array("'nocache'",$args) || in_array(array('nocache'=>'true'),$args)
|| in_array(array('nocache'=>'"true"'),$args) || in_array(array('nocache'=>"'true'"),$args)) { || in_array(array('nocache'=>'"true"'),$args) || in_array(array('nocache'=>"'true'"),$args)) {
@@ -127,8 +127,8 @@ class Smarty_Internal_TemplateCompilerBase {
// template defined by {template} tag // template defined by {template} tag
$args['_attr']['name'] = "'" . $tag . "'"; $args['_attr']['name'] = "'" . $tag . "'";
$_output = $this->callTagCompiler('call', $args, $parameter); $_output = $this->callTagCompiler('call', $args, $parameter);
} }
} }
if ($_output !== false) { if ($_output !== false) {
if ($_output !== true) { if ($_output !== true) {
// did we get compiled code // did we get compiled code
@@ -136,11 +136,11 @@ class Smarty_Internal_TemplateCompilerBase {
// Does it create output? // Does it create output?
if ($this->has_output) { if ($this->has_output) {
$_output .= "\n"; $_output .= "\n";
} }
// return compiled code // return compiled code
return $_output; return $_output;
} }
} }
// tag did not produce compiled code // tag did not produce compiled code
return ''; return '';
} else { } else {
@@ -149,9 +149,9 @@ class Smarty_Internal_TemplateCompilerBase {
foreach ($args['_attr'] as $key => $attribute) { foreach ($args['_attr'] as $key => $attribute) {
if (is_array($attribute)) { if (is_array($attribute)) {
$args = array_merge($args, $attribute); $args = array_merge($args, $attribute);
} }
} }
} }
// not an internal compiler tag // not an internal compiler tag
if (strlen($tag) < 6 || substr($tag, -5) != 'close') { if (strlen($tag) < 6 || substr($tag, -5) != 'close') {
// check if tag is a registered object // check if tag is a registered object
@@ -164,20 +164,24 @@ class Smarty_Internal_TemplateCompilerBase {
return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $methode); return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $methode);
} else { } else {
return $this->trigger_template_error ('unallowed methode "' . $methode . '" in registered object "' . $tag . '"', $this->lex->taglineno); return $this->trigger_template_error ('unallowed methode "' . $methode . '" in registered object "' . $tag . '"', $this->lex->taglineno);
} }
} }
// check if tag is registered // check if tag is registered
foreach (array(Smarty::PLUGIN_COMPILER, Smarty::PLUGIN_FUNCTION, Smarty::PLUGIN_BLOCK) as $type) { foreach (array(Smarty::PLUGIN_COMPILER, Smarty::PLUGIN_FUNCTION, Smarty::PLUGIN_BLOCK) as $type) {
if (isset($this->smarty->registered_plugins[$type][$tag])) { if (isset($this->smarty->registered_plugins[$type][$tag])) {
// if compiler function plugin call it now // if compiler function plugin call it now
if ($type == Smarty::PLUGIN_COMPILER) { if ($type == Smarty::PLUGIN_COMPILER) {
$new_args = array(); $new_args = array();
foreach ($args as $mixed) { foreach ($args as $key => $mixed) {
$new_args = array_merge($new_args, $mixed); if (is_array($mixed)) {
} $new_args = array_merge($new_args, $mixed);
} else {
$new_args[$key] = $mixed;
}
}
if (!$this->smarty->registered_plugins[$type][$tag][1]) { if (!$this->smarty->registered_plugins[$type][$tag][1]) {
$this->tag_nocache = true; $this->tag_nocache = true;
} }
$function = $this->smarty->registered_plugins[$type][$tag][0]; $function = $this->smarty->registered_plugins[$type][$tag][0];
if (!is_array($function)) { if (!is_array($function)) {
return $function($new_args, $this); return $function($new_args, $this);
@@ -185,14 +189,14 @@ class Smarty_Internal_TemplateCompilerBase {
return $this->smarty->registered_plugins[$type][$tag][0][0]->$function[1]($new_args, $this); return $this->smarty->registered_plugins[$type][$tag][0][0]->$function[1]($new_args, $this);
} else { } else {
return call_user_func_array($this->smarty->registered_plugins[$type][$tag][0], array($new_args, $this)); return call_user_func_array($this->smarty->registered_plugins[$type][$tag][0], array($new_args, $this));
} }
} }
// compile registered function or block function // compile registered function or block function
if ($type == Smarty::PLUGIN_FUNCTION || $type == Smarty::PLUGIN_BLOCK) { if ($type == Smarty::PLUGIN_FUNCTION || $type == Smarty::PLUGIN_BLOCK) {
return $this->callTagCompiler('private_registered_' . $type, $args, $parameter, $tag); return $this->callTagCompiler('private_registered_' . $type, $args, $parameter, $tag);
} }
} }
} }
// check plugins from plugins folder // check plugins from plugins folder
foreach ($this->smarty->plugin_search_order as $plugin_type) { foreach ($this->smarty->plugin_search_order as $plugin_type) {
if ($plugin_type == Smarty::PLUGIN_BLOCK && $this->smarty->loadPlugin('smarty_compiler_' . $tag)) { if ($plugin_type == Smarty::PLUGIN_BLOCK && $this->smarty->loadPlugin('smarty_compiler_' . $tag)) {
@@ -206,25 +210,25 @@ class Smarty_Internal_TemplateCompilerBase {
} else { } else {
$new_args[$key] = $mixed; $new_args[$key] = $mixed;
} }
} }
return $plugin($new_args, $this->smarty); return $plugin($new_args, $this->smarty);
} }
if (class_exists($plugin, false)) { if (class_exists($plugin, false)) {
$plugin_object = new $plugin; $plugin_object = new $plugin;
if (method_exists($plugin_object, 'compile')) { if (method_exists($plugin_object, 'compile')) {
return $plugin_object->compile($args, $this); return $plugin_object->compile($args, $this);
} }
} }
throw new SmartyException("Plugin \"{$tag}\" not callable"); throw new SmartyException("Plugin \"{$tag}\" not callable");
} else { } else {
if ($function = $this->getPlugin($tag, $plugin_type)) { if ($function = $this->getPlugin($tag, $plugin_type)) {
return $this->callTagCompiler('private_' . $plugin_type . '_plugin', $args, $parameter, $tag, $function); return $this->callTagCompiler('private_' . $plugin_type . '_plugin', $args, $parameter, $tag, $function);
} }
} }
} }
} else { } else {
// compile closing tag of block function // compile closing tag of block function
$base_tag = substr($tag, 0, -5); $base_tag = substr($tag, 0, -5);
// check if closing tag is a registered object // check if closing tag is a registered object
if (isset($this->smarty->registered_objects[$base_tag]) && isset($parameter['object_methode'])) { if (isset($this->smarty->registered_objects[$base_tag]) && isset($parameter['object_methode'])) {
$methode = $parameter['object_methode']; $methode = $parameter['object_methode'];
@@ -232,41 +236,41 @@ class Smarty_Internal_TemplateCompilerBase {
return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $methode); return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $methode);
} else { } else {
return $this->trigger_template_error ('unallowed closing tag methode "' . $methode . '" in registered object "' . $base_tag . '"', $this->lex->taglineno); return $this->trigger_template_error ('unallowed closing tag methode "' . $methode . '" in registered object "' . $base_tag . '"', $this->lex->taglineno);
} }
} }
// registered block tag ? // registered block tag ?
if (isset($this->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$base_tag])) { if (isset($this->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$base_tag])) {
return $this->callTagCompiler('private_registered_block', $args, $parameter, $tag); return $this->callTagCompiler('private_registered_block', $args, $parameter, $tag);
} }
// block plugin? // block plugin?
if ($function = $this->getPlugin($base_tag, Smarty::PLUGIN_BLOCK)) { if ($function = $this->getPlugin($base_tag, Smarty::PLUGIN_BLOCK)) {
return $this->callTagCompiler('private_block_plugin', $args, $parameter, $tag, $function); return $this->callTagCompiler('private_block_plugin', $args, $parameter, $tag, $function);
} }
if ($this->smarty->loadPlugin('smarty_compiler_' . $tag)) { if ($this->smarty->loadPlugin('smarty_compiler_' . $tag)) {
$plugin = 'smarty_compiler_' . $tag; $plugin = 'smarty_compiler_' . $tag;
if (is_callable($plugin)) { if (is_callable($plugin)) {
return $plugin($args, $this->smarty); return $plugin($args, $this->smarty);
} }
if (class_exists($plugin, false)) { if (class_exists($plugin, false)) {
$plugin_object = new $plugin; $plugin_object = new $plugin;
if (method_exists($plugin_object, 'compile')) { if (method_exists($plugin_object, 'compile')) {
return $plugin_object->compile($args, $this); return $plugin_object->compile($args, $this);
} }
} }
throw new SmartyException("Plugin \"{$tag}\" not callable"); throw new SmartyException("Plugin \"{$tag}\" not callable");
} }
} }
$this->trigger_template_error ("unknown tag \"" . $tag . "\"", $this->lex->taglineno); $this->trigger_template_error ("unknown tag \"" . $tag . "\"", $this->lex->taglineno);
} }
} }
/** /**
* lazy loads internal compile plugin for tag and calls the compile methode * lazy loads internal compile plugin for tag and calls the compile methode
* *
* compile objects cached for reuse. * compile objects cached for reuse.
* class name format: Smarty_Internal_Compile_TagName * class name format: Smarty_Internal_Compile_TagName
* plugin filename format: Smarty_Internal_Tagname.php * plugin filename format: Smarty_Internal_Tagname.php
* *
* @param $tag string tag name * @param $tag string tag name
* @param $args array with tag attributes * @param $args array with tag attributes
* @param $param1 optional parameter * @param $param1 optional parameter
@@ -275,27 +279,27 @@ class Smarty_Internal_TemplateCompilerBase {
* @return string compiled code * @return string compiled code
*/ */
public function callTagCompiler($tag, $args, $param1 = null, $param2 = null, $param3 = null) public function callTagCompiler($tag, $args, $param1 = null, $param2 = null, $param3 = null)
{ {
// re-use object if already exists // re-use object if already exists
if (isset(self::$_tag_objects[$tag])) { if (isset(self::$_tag_objects[$tag])) {
// compile this tag // compile this tag
return self::$_tag_objects[$tag]->compile($args, $this, $param1, $param2, $param3); return self::$_tag_objects[$tag]->compile($args, $this, $param1, $param2, $param3);
} }
// lazy load internal compiler plugin // lazy load internal compiler plugin
$class_name = 'Smarty_Internal_Compile_' . $tag; $class_name = 'Smarty_Internal_Compile_' . $tag;
if ($this->smarty->loadPlugin($class_name)) { if ($this->smarty->loadPlugin($class_name)) {
// use plugin if found // use plugin if found
self::$_tag_objects[$tag] = new $class_name; self::$_tag_objects[$tag] = new $class_name;
// compile this tag // compile this tag
return self::$_tag_objects[$tag]->compile($args, $this, $param1, $param2, $param3); return self::$_tag_objects[$tag]->compile($args, $this, $param1, $param2, $param3);
} }
// no internal compile plugin for this tag // no internal compile plugin for this tag
return false; return false;
} }
/** /**
* Check for plugins and return function name * Check for plugins and return function name
* *
* @param $pugin_name string name of plugin or function * @param $pugin_name string name of plugin or function
* @param $type string type of plugin * @param $type string type of plugin
* @return string call name of function * @return string call name of function
@@ -309,21 +313,21 @@ class Smarty_Internal_TemplateCompilerBase {
} else if (isset($this->template->required_plugins['compiled'][$plugin_name][$type])) { } else if (isset($this->template->required_plugins['compiled'][$plugin_name][$type])) {
$this->template->required_plugins['nocache'][$plugin_name][$type] = $this->template->required_plugins['compiled'][$plugin_name][$type]; $this->template->required_plugins['nocache'][$plugin_name][$type] = $this->template->required_plugins['compiled'][$plugin_name][$type];
$function = $this->template->required_plugins['nocache'][$plugin_name][$type]['function']; $function = $this->template->required_plugins['nocache'][$plugin_name][$type]['function'];
} }
} else { } else {
if (isset($this->template->required_plugins['compiled'][$plugin_name][$type])) { if (isset($this->template->required_plugins['compiled'][$plugin_name][$type])) {
$function = $this->template->required_plugins['compiled'][$plugin_name][$type]['function']; $function = $this->template->required_plugins['compiled'][$plugin_name][$type]['function'];
} else if (isset($this->template->required_plugins['nocache'][$plugin_name][$type])) { } else if (isset($this->template->required_plugins['nocache'][$plugin_name][$type])) {
$this->template->required_plugins['compiled'][$plugin_name][$type] = $this->template->required_plugins['nocache'][$plugin_name][$type]; $this->template->required_plugins['compiled'][$plugin_name][$type] = $this->template->required_plugins['nocache'][$plugin_name][$type];
$function = $this->template->required_plugins['compiled'][$plugin_name][$type]['function']; $function = $this->template->required_plugins['compiled'][$plugin_name][$type]['function'];
} }
} }
if (isset($function)) { if (isset($function)) {
if ($type == 'modifier') { if ($type == 'modifier') {
$this->template->saved_modifier[$plugin_name] = true; $this->template->saved_modifier[$plugin_name] = true;
} }
return $function; return $function;
} }
// loop through plugin dirs and find the plugin // loop through plugin dirs and find the plugin
$function = 'smarty_' . $type . '_' . $plugin_name; $function = 'smarty_' . $type . '_' . $plugin_name;
$found = false; $found = false;
@@ -333,8 +337,8 @@ class Smarty_Internal_TemplateCompilerBase {
// require_once($file); // require_once($file);
$found = true; $found = true;
break; break;
} }
} }
if ($found) { if ($found) {
if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
$this->template->required_plugins['nocache'][$plugin_name][$type]['file'] = $file; $this->template->required_plugins['nocache'][$plugin_name][$type]['file'] = $file;
@@ -342,32 +346,32 @@ class Smarty_Internal_TemplateCompilerBase {
} else { } else {
$this->template->required_plugins['compiled'][$plugin_name][$type]['file'] = $file; $this->template->required_plugins['compiled'][$plugin_name][$type]['file'] = $file;
$this->template->required_plugins['compiled'][$plugin_name][$type]['function'] = $function; $this->template->required_plugins['compiled'][$plugin_name][$type]['function'] = $function;
} }
if ($type == 'modifier') { if ($type == 'modifier') {
$this->template->saved_modifier[$plugin_name] = true; $this->template->saved_modifier[$plugin_name] = true;
} }
return $function; return $function;
} }
if (is_callable($function)) { if (is_callable($function)) {
// plugin function is defined in the script // plugin function is defined in the script
return $function; return $function;
} }
return false; return false;
} }
/** /**
* Inject inline code for nocache template sections * Inject inline code for nocache template sections
* *
* This method gets the content of each template element from the parser. * This method gets the content of each template element from the parser.
* If the content is compiled code and it should be not cached the code is injected * If the content is compiled code and it should be not cached the code is injected
* into the rendered output. * into the rendered output.
* *
* @param string $content content of template element * @param string $content content of template element
* @param boolean $tag_nocache true if the parser detected a nocache situation * @param boolean $tag_nocache true if the parser detected a nocache situation
* @param boolean $is_code true if content is compiled code * @param boolean $is_code true if content is compiled code
* @return string content * @return string content
*/ */
public function processNocacheCode ($content, $is_code) public function processNocacheCode ($content, $is_code)
{ {
// If the template is not evaluated and we have a nocache section and or a nocache tag // If the template is not evaluated and we have a nocache section and or a nocache tag
if ($is_code && !empty($content)) { if ($is_code && !empty($content)) {
// generate replacement code // generate replacement code
@@ -376,42 +380,42 @@ class Smarty_Internal_TemplateCompilerBase {
$this->template->has_nocache_code = true; $this->template->has_nocache_code = true;
$_output = str_replace("'", "\'", $content); $_output = str_replace("'", "\'", $content);
$_output = str_replace("^#^", "'", $_output); $_output = str_replace("^#^", "'", $_output);
$_output = "<?php echo '/*%%SmartyNocache:{$this->nocache_hash}%%*/" . $_output . "/*/%%SmartyNocache:{$this->nocache_hash}%%*/';?>"; $_output = "<?php echo '/*%%SmartyNocache:{$this->nocache_hash}%%*/" . $_output . "/*/%%SmartyNocache:{$this->nocache_hash}%%*/';?>";
// make sure we include modifer plugins for nocache code // make sure we include modifer plugins for nocache code
if (isset($this->template->saved_modifier)) { if (isset($this->template->saved_modifier)) {
foreach ($this->template->saved_modifier as $plugin_name => $dummy) { foreach ($this->template->saved_modifier as $plugin_name => $dummy) {
if (isset($this->template->required_plugins['compiled'][$plugin_name]['modifier'])) { if (isset($this->template->required_plugins['compiled'][$plugin_name]['modifier'])) {
$this->template->required_plugins['nocache'][$plugin_name]['modifier'] = $this->template->required_plugins['compiled'][$plugin_name]['modifier']; $this->template->required_plugins['nocache'][$plugin_name]['modifier'] = $this->template->required_plugins['compiled'][$plugin_name]['modifier'];
} }
} }
$this->template->saved_modifier = null; $this->template->saved_modifier = null;
} }
} else { } else {
$_output = $content; $_output = $content;
} }
} else { } else {
$_output = $content; $_output = $content;
} }
$this->suppressNocacheProcessing = false; $this->suppressNocacheProcessing = false;
$this->tag_nocache = false; $this->tag_nocache = false;
return $_output; return $_output;
} }
/** /**
* display compiler error messages without dying * display compiler error messages without dying
* *
* If parameter $args is empty it is a parser detected syntax error. * If parameter $args is empty it is a parser detected syntax error.
* In this case the parser is called to obtain information about expected tokens. * In this case the parser is called to obtain information about expected tokens.
* *
* If parameter $args contains a string this is used as error message * If parameter $args contains a string this is used as error message
* *
* @param $args string individual error message or null * @param $args string individual error message or null
*/ */
public function trigger_template_error($args = null, $line = null) public function trigger_template_error($args = null, $line = null)
{ {
// get template source line which has error // get template source line which has error
if (!isset($line)) { if (!isset($line)) {
$line = $this->lex->line; $line = $this->lex->line;
} }
$match = preg_split("/\n/", $this->lex->data); $match = preg_split("/\n/", $this->lex->data);
$error_text = 'Syntax Error in template "' . $this->template->getTemplateFilepath() . '" on line ' . $line . ' "' . htmlspecialchars(trim(preg_replace('![\t\r\n]+!',' ',$match[$line-1]))) . '" '; $error_text = 'Syntax Error in template "' . $this->template->getTemplateFilepath() . '" on line ' . $line . ' "' . htmlspecialchars(trim(preg_replace('![\t\r\n]+!',' ',$match[$line-1]))) . '" ';
if (isset($args)) { if (isset($args)) {
@@ -429,13 +433,13 @@ class Smarty_Internal_TemplateCompilerBase {
} else { } else {
// otherwise internal token name // otherwise internal token name
$expect[] = $this->parser->yyTokenName[$token]; $expect[] = $this->parser->yyTokenName[$token];
} }
} }
$error_text .= ', expected one of: ' . implode(' , ', $expect); $error_text .= ', expected one of: ' . implode(' , ', $expect);
} }
} }
throw new SmartyCompilerException($error_text); throw new SmartyCompilerException($error_text);
} }
} }
?> ?>