diff options
Diffstat (limited to 'libs/sysplugins/smarty_internal_templatecompilerbase.php')
| -rw-r--r-- | libs/sysplugins/smarty_internal_templatecompilerbase.php | 401 |
1 files changed, 280 insertions, 121 deletions
diff --git a/libs/sysplugins/smarty_internal_templatecompilerbase.php b/libs/sysplugins/smarty_internal_templatecompilerbase.php index 32da800c..53948aba 100644 --- a/libs/sysplugins/smarty_internal_templatecompilerbase.php +++ b/libs/sysplugins/smarty_internal_templatecompilerbase.php @@ -10,19 +10,98 @@ */
/**
- * Main compiler class
+ * Main abstract compiler class
+ *
+ * @package Smarty
+ * @subpackage Compiler
*/
-class Smarty_Internal_TemplateCompilerBase {
- // hash for nocache sections
+abstract class Smarty_Internal_TemplateCompilerBase {
+
+ /**
+ * hash for nocache sections
+ *
+ * @var mixed
+ */
private $nocache_hash = null;
- // suppress generation of nocache code
+ /**
+ * suppress generation of nocache code
+ *
+ * @var bool
+ */
public $suppressNocacheProcessing = false;
- // compile tag objects
- static $_tag_objects = array();
- // tag stack
+ /**
+ * suppress generation of merged template code
+ *
+ * @var bool
+ */
+ public $suppressMergedTemplates = false;
+ /**
+ * compile tag objects
+ *
+ * @var array
+ */
+ public static $_tag_objects = array();
+ /**
+ * tag stack
+ *
+ * @var array
+ */
public $_tag_stack = array();
- // current template
+ /**
+ * current template
+ *
+ * @var Smarty_Internal_Template
+ */
public $template = null;
+ /**
+ * merged templates
+ *
+ * @var array
+ */
+ public $merged_templates = array();
+ /**
+ * flag when compiling {block}
+ *
+ * @var bool
+ */
+ public $inheritance = false;
+ /**
+ * plugins loaded by default plugin handler
+ *
+ * @var array
+ */
+ public $default_handler_plugins = array();
+ /**
+ * saved preprocessed modifier list
+ *
+ * @var mixed
+ */
+ public $default_modifier_list = null;
+ /**
+ * force compilation of complete template as nocache
+ * @var boolean
+ */
+ public $forceNocache = false;
+ /**
+ * suppress Smarty header code in compiled template
+ * @var bool
+ */
+ public $suppressHeader = false;
+ /**
+ * suppress template property header code in compiled template
+ * @var bool
+ */
+ public $suppressTemplatePropertyHeader = false;
+ /**
+ * flag if compiled template file shall we written
+ * @var bool
+ */
+ public $write_compiled_code = true;
+ /**
+ * flags for used modifier plugins
+ * @var array
+ */
+ public $modifier_plugins = array();
/**
* Initialize compiler
@@ -33,12 +112,12 @@ class Smarty_Internal_TemplateCompilerBase { }
/**
- * Methode to compile a Smarty template
+ * Method to compile a Smarty template
*
- * @param $template template object to compile
+ * @param Smarty_Internal_Template $template template object to compile
* @return bool true if compiling succeeded, false if it failed
*/
- public function compileTemplate($template)
+ public function compileTemplate(Smarty_Internal_Template $template)
{
if (empty($template->properties['nocache_hash'])) {
$template->properties['nocache_hash'] = $this->nocache_hash;
@@ -50,47 +129,56 @@ class Smarty_Internal_TemplateCompilerBase { $this->tag_nocache = false;
// save template object in compiler class
$this->template = $template;
- $this->smarty->_current_file = $saved_filepath = $this->template->getTemplateFilepath();
+ $this->smarty->_current_file = $saved_filepath = $this->template->source->filepath;
// template header code
$template_header = '';
- if (!$template->suppressHeader) {
+ if (!$this->suppressHeader) {
$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->source->filepath . "\" */ ?>\n";
}
do {
// flag for aborting current and start recompile
$this->abort_and_recompile = false;
// get template source
- $_content = $template->getTemplateSource();
+ $_content = $template->source->content;
// run prefilter if required
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->source->content = $_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $template);
}
// on empty template just return header
if ($_content == '') {
- if ($template->suppressFileDependency) {
- $template->compiled_template = '';
+ if ($this->suppressTemplatePropertyHeader) {
+ $code = '';
} else {
- $template->compiled_template = $template_header . $template->createPropertyHeader();
+ $code = $template_header . $template->createTemplateCodeFrame();
}
- return true;
+ return $code;
}
// call compiler
$_compiled_code = $this->doCompile($_content);
} while ($this->abort_and_recompile);
- // restore original filepath which could have been modified by template inheritance
- $this->template->template_filepath = $saved_filepath;
+ $this->template->source->filepath = $saved_filepath;
+ // free memory
+ unset($this->parser->root_buffer, $this->parser->current_buffer, $this->parser, $this->lex, $this->template);
+ self::$_tag_objects = array();
// return compiled code to template object
- if ($template->suppressFileDependency) {
- $template->compiled_template = $_compiled_code;
+ $merged_code = '';
+ if (!$this->suppressMergedTemplates) {
+ foreach ($this->merged_templates as $code) {
+ $merged_code .= $code;
+ }
+ }
+ if ($this->suppressTemplatePropertyHeader) {
+ $code = $_compiled_code . $merged_code;
} else {
- $template->compiled_template = $template_header . $template->createPropertyHeader() . $_compiled_code;
+ $code = $template_header . $template->createTemplateCodeFrame($_compiled_code) . $merged_code;
}
// run postfilter if required
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);
+ $code = Smarty_Internal_Filter_Handler::runFilter('post', $code, $template);
}
+ return $code;
}
/**
@@ -99,9 +187,9 @@ class Smarty_Internal_TemplateCompilerBase { * This is a call back from the lexer/parser
* It executes the required compile plugin for the Smarty tag
*
- * @param string $tag tag name
- * @param array $args array with tag attributes
- * @param array $parameter array with compilation parameter
+ * @param string $tag tag name
+ * @param array $args array with tag attributes
+ * @param array $parameter array with compilation parameter
* @return string compiled code
*/
public function compileTag($tag, $args, $parameter = array())
@@ -112,12 +200,12 @@ class Smarty_Internal_TemplateCompilerBase { $this->has_output = false;
// log tag/attributes
if (isset($this->smarty->get_used_tags) && $this->smarty->get_used_tags) {
- $this->template->used_tags[] = array($tag,$args);
+ $this->template->used_tags[] = array($tag, $args);
}
- // check nocache option flag
+ // check nocache option flag
if (in_array("'nocache'",$args) || in_array(array('nocache'=>'true'),$args)
- || in_array(array('nocache'=>'"true"'),$args) || in_array(array('nocache'=>"'true'"),$args)) {
- $this->tag_nocache = true;
+ || in_array(array('nocache'=>'"true"'),$args) || in_array(array('nocache'=>"'true'"),$args)) {
+ $this->tag_nocache = true;
}
// compile the smarty tag (required compile classes to compile the tag are autoloaded)
if (($_output = $this->callTagCompiler($tag, $args, $parameter)) === false) {
@@ -156,7 +244,7 @@ class Smarty_Internal_TemplateCompilerBase { if (isset($this->smarty->registered_objects[$tag]) && isset($parameter['object_methode'])) {
$methode = $parameter['object_methode'];
if (!in_array($methode, $this->smarty->registered_objects[$tag][3]) &&
- (empty($this->smarty->registered_objects[$tag][1]) || in_array($methode, $this->smarty->registered_objects[$tag][1]))) {
+ (empty($this->smarty->registered_objects[$tag][1]) || in_array($methode, $this->smarty->registered_objects[$tag][1]))) {
return $this->callTagCompiler('private_object_function', $args, $parameter, $tag, $methode);
} elseif (in_array($methode, $this->smarty->registered_objects[$tag][3])) {
return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $methode);
@@ -165,49 +253,42 @@ class Smarty_Internal_TemplateCompilerBase { }
}
// check if tag is registered
- foreach (array(Smarty::PLUGIN_COMPILER, Smarty::PLUGIN_FUNCTION, Smarty::PLUGIN_BLOCK) as $type) {
- if (isset($this->smarty->registered_plugins[$type][$tag])) {
+ foreach (array(Smarty::PLUGIN_COMPILER, Smarty::PLUGIN_FUNCTION, Smarty::PLUGIN_BLOCK) as $plugin_type) {
+ if (isset($this->smarty->registered_plugins[$plugin_type][$tag])) {
// if compiler function plugin call it now
- if ($type == Smarty::PLUGIN_COMPILER) {
+ if ($plugin_type == Smarty::PLUGIN_COMPILER) {
$new_args = array();
- foreach ($args as $key => $mixed) {
- if (is_array($mixed)) {
- $new_args = array_merge($new_args, $mixed);
- } else {
- $new_args[$key] = $mixed;
- }
+ foreach ($args as $mixed) {
+ $new_args = array_merge($new_args, $mixed);
}
- if (!$this->smarty->registered_plugins[$type][$tag][1]) {
+ if (!$this->smarty->registered_plugins[$plugin_type][$tag][1]) {
$this->tag_nocache = true;
}
- $function = $this->smarty->registered_plugins[$type][$tag][0];
+ $function = $this->smarty->registered_plugins[$plugin_type][$tag][0];
if (!is_array($function)) {
return $function($new_args, $this);
} else if (is_object($function[0])) {
- return $this->smarty->registered_plugins[$type][$tag][0][0]->$function[1]($new_args, $this);
+ return $this->smarty->registered_plugins[$plugin_type][$tag][0][0]->$function[1]($new_args, $this);
} else {
- return call_user_func_array($this->smarty->registered_plugins[$type][$tag][0], array($new_args, $this));
+ return call_user_func_array($function, array($new_args, $this));
}
}
// compile registered function or block function
- if ($type == Smarty::PLUGIN_FUNCTION || $type == Smarty::PLUGIN_BLOCK) {
- return $this->callTagCompiler('private_registered_' . $type, $args, $parameter, $tag);
+ if ($plugin_type == Smarty::PLUGIN_FUNCTION || $plugin_type == Smarty::PLUGIN_BLOCK) {
+ return $this->callTagCompiler('private_registered_' . $plugin_type, $args, $parameter, $tag);
}
+
}
}
// check plugins from plugins folder
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) && (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this))) {
$plugin = 'smarty_compiler_' . $tag;
if (is_callable($plugin)) {
- // convert arguments format for old compiler plugins
+ // convert arguments format for old compiler plugins
$new_args = array();
- foreach ($args as $key => $mixed) {
- if (is_array($mixed)) {
- $new_args = array_merge($new_args, $mixed);
- } else {
- $new_args[$key] = $mixed;
- }
+ foreach ($args as $mixed) {
+ $new_args = array_merge($new_args, $mixed);
}
return $plugin($new_args, $this->smarty);
}
@@ -220,7 +301,47 @@ class Smarty_Internal_TemplateCompilerBase { throw new SmartyException("Plugin \"{$tag}\" not callable");
} else {
if ($function = $this->getPlugin($tag, $plugin_type)) {
- return $this->callTagCompiler('private_' . $plugin_type . '_plugin', $args, $parameter, $tag, $function);
+ if(!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this)) {
+ return $this->callTagCompiler('private_' . $plugin_type . '_plugin', $args, $parameter, $tag, $function);
+ }
+ }
+ }
+ }
+ if (is_callable($this->smarty->default_plugin_handler_func)) {
+ $found = false;
+ // look for already resolved tags
+ foreach ($this->smarty->plugin_search_order as $plugin_type) {
+ if (isset($this->default_handler_plugins[$plugin_type][$tag])) {
+ $found = true;
+ break;
+ }
+ }
+ if (!$found) {
+ // call default handler
+ foreach ($this->smarty->plugin_search_order as $plugin_type) {
+ if ($this->getPluginFromDefaultHandler($tag, $plugin_type)) {
+ $found = true;
+ break;
+ }
+ }
+ }
+ if ($found) {
+ // if compiler function plugin call it now
+ if ($plugin_type == Smarty::PLUGIN_COMPILER) {
+ $new_args = array();
+ foreach ($args as $mixed) {
+ $new_args = array_merge($new_args, $mixed);
+ }
+ $function = $this->default_handler_plugins[$plugin_type][$tag][0];
+ if (!is_array($function)) {
+ return $function($new_args, $this);
+ } else if (is_object($function[0])) {
+ return $this->default_handler_plugins[$plugin_type][$tag][0][0]->$function[1]($new_args, $this);
+ } else {
+ return call_user_func_array($function, array($new_args, $this));
+ }
+ } else {
+ return $this->callTagCompiler('private_registered_' . $plugin_type, $args, $parameter, $tag);
}
}
}
@@ -237,7 +358,7 @@ class Smarty_Internal_TemplateCompilerBase { }
}
// 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]) || isset($this->default_handler_plugins[Smarty::PLUGIN_BLOCK][$base_tag])) {
return $this->callTagCompiler('private_registered_block', $args, $parameter, $tag);
}
// block plugin?
@@ -269,11 +390,11 @@ class Smarty_Internal_TemplateCompilerBase { * class name format: Smarty_Internal_Compile_TagName
* plugin filename format: Smarty_Internal_Tagname.php
*
- * @param $tag string tag name
- * @param $args array with tag attributes
- * @param $param1 optional parameter
- * @param $param2 optional parameter
- * @param $param3 optional parameter
+ * @param string $tag tag name
+ * @param array $args list of tag attributes
+ * @param mixed $param1 optional parameter
+ * @param mixed $param2 optional parameter
+ * @param mixed $param3 optional parameter
* @return string compiled code
*/
public function callTagCompiler($tag, $args, $param1 = null, $param2 = null, $param3 = null)
@@ -286,10 +407,13 @@ class Smarty_Internal_TemplateCompilerBase { // lazy load internal compiler plugin
$class_name = 'Smarty_Internal_Compile_' . $tag;
if ($this->smarty->loadPlugin($class_name)) {
+ // check if tag allowed by security
+ if (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this)) {
// use plugin if found
self::$_tag_objects[$tag] = new $class_name;
// compile this tag
return self::$_tag_objects[$tag]->compile($args, $this, $param1, $param2, $param3);
+ }
}
// no internal compile plugin for this tag
return false;
@@ -298,55 +422,48 @@ class Smarty_Internal_TemplateCompilerBase { /**
* Check for plugins and return function name
*
- * @param $pugin_name string name of plugin or function
- * @param $type string type of plugin
+ * @param string $pugin_name name of plugin or function
+ * @param string $plugin_type type of plugin
* @return string call name of function
*/
- public function getPlugin($plugin_name, $type)
+ public function getPlugin($plugin_name, $plugin_type)
{
$function = null;
if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
- if (isset($this->template->required_plugins['nocache'][$plugin_name][$type])) {
- $function = $this->template->required_plugins['nocache'][$plugin_name][$type]['function'];
- } 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];
- $function = $this->template->required_plugins['nocache'][$plugin_name][$type]['function'];
+ if (isset($this->template->required_plugins['nocache'][$plugin_name][$plugin_type])) {
+ $function = $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['function'];
+ } else if (isset($this->template->required_plugins['compiled'][$plugin_name][$plugin_type])) {
+ $this->template->required_plugins['nocache'][$plugin_name][$plugin_type] = $this->template->required_plugins['compiled'][$plugin_name][$plugin_type];
+ $function = $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['function'];
}
} else {
- if (isset($this->template->required_plugins['compiled'][$plugin_name][$type])) {
- $function = $this->template->required_plugins['compiled'][$plugin_name][$type]['function'];
- } 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];
- $function = $this->template->required_plugins['compiled'][$plugin_name][$type]['function'];
+ if (isset($this->template->required_plugins['compiled'][$plugin_name][$plugin_type])) {
+ $function = $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['function'];
+ } else if (isset($this->template->required_plugins['nocache'][$plugin_name][$plugin_type])) {
+ $this->template->required_plugins['compiled'][$plugin_name][$plugin_type] = $this->template->required_plugins['nocache'][$plugin_name][$plugin_type];
+ $function = $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['function'];
}
}
if (isset($function)) {
- if ($type == 'modifier') {
- $this->template->saved_modifier[$plugin_name] = true;
+ if ($plugin_type == 'modifier') {
+ $this->modifier_plugins[$plugin_name] = true;
}
return $function;
}
// loop through plugin dirs and find the plugin
- $function = 'smarty_' . $type . '_' . $plugin_name;
- $found = false;
- foreach((array)$this->smarty->plugins_dir as $_plugin_dir) {
- $file = rtrim($_plugin_dir, '/\\') . DS . $type . '.' . $plugin_name . '.php';
- if (file_exists($file)) {
- // require_once($file);
- $found = true;
- break;
- }
- }
- if ($found) {
+ $function = 'smarty_' . $plugin_type . '_' . $plugin_name;
+ $file = $this->smarty->loadPlugin($function, false);
+
+ if (is_string($file)) {
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]['function'] = $function;
+ $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['file'] = $file;
+ $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['function'] = $function;
} else {
- $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][$plugin_type]['file'] = $file;
+ $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['function'] = $function;
}
- if ($type == 'modifier') {
- $this->template->saved_modifier[$plugin_name] = true;
+ if ($plugin_type == 'modifier') {
+ $this->modifier_plugins[$plugin_name] = true;
}
return $function;
}
@@ -356,6 +473,47 @@ class Smarty_Internal_TemplateCompilerBase { }
return false;
}
+
+ /**
+ * Check for plugins by default plugin handler
+ *
+ * @param string $tag name of tag
+ * @param string $plugin_type type of plugin
+ * @return boolean true if found
+ */
+ public function getPluginFromDefaultHandler($tag, $plugin_type)
+ {
+ $callback = null;
+ $script = null;
+ $result = call_user_func_array(
+ $this->smarty->default_plugin_handler_func,
+ array($tag, $plugin_type, $this->template, &$callback, &$script)
+ );
+ if ($result) {
+ if ($script !== null) {
+ if (is_file($script)) {
+ if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
+ $this->template->required_plugins['nocache'][$tag][$plugin_type]['file'] = $script;
+ $this->template->required_plugins['nocache'][$tag][$plugin_type]['function'] = $callback;
+ } else {
+ $this->template->required_plugins['compiled'][$tag][$plugin_type]['file'] = $script;
+ $this->template->required_plugins['compiled'][$tag][$plugin_type]['function'] = $callback;
+ }
+ include_once $script;
+ } else {
+ throw new SmartyCompilerException("Plugin or modifer script file $script not found");
+ }
+ }
+ if (is_callable($callback)) {
+ $this->default_handler_plugins[$plugin_type][$tag] = array($callback, true, array());
+ return true;
+ } else {
+ throw new SmartyCompilerException("Function for plugin or modifier $tag not callable");
+ }
+ }
+ return false;
+ }
+
/**
* Inject inline code for nocache template sections
*
@@ -363,30 +521,27 @@ class Smarty_Internal_TemplateCompilerBase { * If the content is compiled code and it should be not cached the code is injected
* into the rendered output.
*
- * @param string $content content of template element
- * @param boolean $tag_nocache true if the parser detected a nocache situation
+ * @param string $content content of template element
* @param boolean $is_code true if content is compiled code
* @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 ($is_code && !empty($content)) {
// generate replacement code
- if ((!$this->template->resource_object->isEvaluated || $this->template->forceNocache) && $this->template->caching && !$this->suppressNocacheProcessing &&
- ($this->nocache || $this->tag_nocache || $this->template->forceNocache == 2)) {
+ if ((!($this->template->source->recompiled) || $this->forceNocache) && $this->template->caching && !$this->suppressNocacheProcessing &&
+ ($this->nocache || $this->tag_nocache || $this->forceNocache == 2)) {
$this->template->has_nocache_code = true;
$_output = str_replace("'", "\'", $content);
+ $_output = str_replace('\\\\', '\\\\\\\\', $_output);
$_output = str_replace("^#^", "'", $_output);
$_output = "<?php echo '/*%%SmartyNocache:{$this->nocache_hash}%%*/" . $_output . "/*/%%SmartyNocache:{$this->nocache_hash}%%*/';?>\n";
// make sure we include modifer plugins for nocache code
- if (isset($this->template->saved_modifier)) {
- foreach ($this->template->saved_modifier as $plugin_name => $dummy) {
- 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'];
- }
+ foreach ($this->modifier_plugins as $plugin_name => $dummy) {
+ 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->saved_modifier = null;
}
} else {
$_output = $content;
@@ -398,6 +553,7 @@ class Smarty_Internal_TemplateCompilerBase { $this->tag_nocache = false;
return $_output;
}
+
/**
* display compiler error messages without dying
*
@@ -406,7 +562,9 @@ class Smarty_Internal_TemplateCompilerBase { *
* If parameter $args contains a string this is used as error message
*
- * @param $args string individual error message or null
+ * @param string $args individual error message or null
+ * @param string $line line-number
+ * @throws SmartyCompilerException when an unexpected token is found
*/
public function trigger_template_error($args = null, $line = null)
{
@@ -415,7 +573,7 @@ class Smarty_Internal_TemplateCompilerBase { $line = $this->lex->line;
}
$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->source->filepath . '" on line ' . $line . ' "' . htmlspecialchars(trim(preg_replace('![\t\r\n]+!',' ',$match[$line-1]))) . '" ';
if (isset($args)) {
// individual error message
$error_text .= $args;
@@ -423,21 +581,22 @@ class Smarty_Internal_TemplateCompilerBase { // expected token from parser
$error_text .= ' - Unexpected "' . $this->lex->value.'"';
if (count($this->parser->yy_get_expected_tokens($this->parser->yymajor)) <= 4 ) {
- foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $token) {
- $exp_token = $this->parser->yyTokenName[$token];
- if (isset($this->lex->smarty_token_names[$exp_token])) {
- // token type from lexer
- $expect[] = '"' . $this->lex->smarty_token_names[$exp_token] . '"';
- } else {
- // otherwise internal token name
- $expect[] = $this->parser->yyTokenName[$token];
- }
- }
- $error_text .= ', expected one of: ' . implode(' , ', $expect);
- }
+ foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $token) {
+ $exp_token = $this->parser->yyTokenName[$token];
+ if (isset($this->lex->smarty_token_names[$exp_token])) {
+ // token type from lexer
+ $expect[] = '"' . $this->lex->smarty_token_names[$exp_token] . '"';
+ } else {
+ // otherwise internal token name
+ $expect[] = $this->parser->yyTokenName[$token];
+ }
+ }
+ $error_text .= ', expected one of: ' . implode(' , ', $expect);
+ }
}
throw new SmartyCompilerException($error_text);
}
+
}
?>
\ No newline at end of file |
