123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170 |
- <?php
-
-
-
-
- abstract class Smarty_Internal_TemplateCompilerBase
- {
-
-
-
- public $smarty = null;
-
-
-
- public $parser = null;
-
-
-
- public $nocache_hash = null;
-
-
-
- public $suppressNocacheProcessing = false;
-
-
-
- public $_tag_objects = array();
-
-
-
- public $_tag_stack = array();
-
-
-
- public $template = null;
-
-
-
- public $mergedSubTemplatesData = array();
-
-
-
- public $mergedSubTemplatesCode = array();
-
-
-
- public $templateProperties = array();
-
-
-
- public $trace_line_offset = 0;
-
-
-
- public $trace_uid = '';
-
-
-
- public $trace_filepath = '';
-
-
-
- public $trace_stack = array();
-
-
-
- public $default_handler_plugins = array();
-
-
-
- public $default_modifier_list = null;
-
-
-
- public $forceNocache = false;
-
-
-
- public $write_compiled_code = true;
-
-
-
- public $tpl_function = array();
-
-
-
- public $called_functions = array();
-
-
-
- public $blockOrFunctionCode = '';
-
-
-
- public $php_handling = 0;
-
-
-
- public $modifier_plugins = array();
-
-
-
- public $known_modifier_type = array();
-
-
-
- public $parent_compiler = null;
-
-
-
- public $nocache = false;
-
-
-
- public $tag_nocache = false;
-
-
-
- public $prefix_code = array();
-
-
-
- public $prefixCodeStack = array();
-
-
-
- public $has_code = false;
-
-
-
- public $has_variable_string = false;
-
-
-
- public $has_output = false;
-
-
-
- public $variable_filter_stack = array();
-
-
-
- public $variable_filters = array();
-
-
-
- public $loopNesting = 0;
-
-
-
- public $stripRegEx = '![\t ]*[\r\n]+[\t ]*!';
-
-
-
- public $plugin_search_order = array('function', 'block', 'compiler', 'class');
-
-
-
- public $_cache = array();
-
-
-
- abstract protected function doCompile($_content, $isTemplateSource = false);
-
-
-
- public function __construct(Smarty $smarty)
- {
- $this->smarty = $smarty;
- $this->nocache_hash = str_replace(array('.', ','), '_', uniqid(rand(), true));
- }
-
-
-
- public function compileTemplate(Smarty_Internal_Template $template, $nocache = null,
- Smarty_Internal_TemplateCompilerBase $parent_compiler = null)
- {
-
- $_compiled_code = $template->smarty->ext->_codeFrame->create($template,
- $this->compileTemplateSource($template, $nocache,
- $parent_compiler),
- $this->postFilter($this->blockOrFunctionCode) .
- join('', $this->mergedSubTemplatesCode), false,
- $this);
- return $_compiled_code;
- }
-
-
-
- public function compileTemplateSource(Smarty_Internal_Template $template, $nocache = null,
- Smarty_Internal_TemplateCompilerBase $parent_compiler = null)
- {
- try {
-
- $this->template = $template;
- if (property_exists($this->template->smarty, 'plugin_search_order')) {
- $this->plugin_search_order = $this->template->smarty->plugin_search_order;
- }
- if ($this->smarty->debugging) {
- $this->smarty->_debug->start_compile($this->template);
- }
- if (isset($this->template->smarty->security_policy)) {
- $this->php_handling = $this->template->smarty->security_policy->php_handling;
- } else {
- $this->php_handling = $this->template->smarty->php_handling;
- }
- $this->parent_compiler = $parent_compiler ? $parent_compiler : $this;
- $nocache = isset($nocache) ? $nocache : false;
- if (empty($template->compiled->nocache_hash)) {
- $template->compiled->nocache_hash = $this->nocache_hash;
- } else {
- $this->nocache_hash = $template->compiled->nocache_hash;
- }
-
- $this->nocache = $nocache;
- $this->tag_nocache = false;
-
- $this->template->compiled->has_nocache_code = false;
- $this->has_variable_string = false;
- $this->prefix_code = array();
-
- $this->parent_compiler->template->compiled->file_dependency[ $this->template->source->uid ] =
- array($this->template->source->filepath, $this->template->source->getTimeStamp(),
- $this->template->source->type);
- $this->smarty->_current_file = $this->template->source->filepath;
-
- if (!empty($this->template->source->components)) {
-
-
- $_content =
- Smarty_Internal_Compile_Extends::extendsSourceArrayCode($this->template->source->components);
- } else {
-
- $_content = $this->template->source->getContent();
- }
- $_compiled_code = $this->postFilter($this->doCompile($this->preFilter($_content), true));
- }
- catch (Exception $e) {
- if ($this->smarty->debugging) {
- $this->smarty->_debug->end_compile($this->template);
- }
- $this->_tag_stack = array();
- $this->_tag_objects = array();
-
- $this->parent_compiler = null;
- $this->template = null;
- $this->parser = null;
- throw $e;
- }
- if ($this->smarty->debugging) {
- $this->smarty->_debug->end_compile($this->template);
- }
- $this->parent_compiler = null;
- $this->template = null;
- $this->parser = null;
- return $_compiled_code;
- }
-
-
-
- public function postFilter($code)
- {
-
- if (!empty($code) &&
- (isset($this->smarty->autoload_filters[ 'post' ]) || isset($this->smarty->registered_filters[ 'post' ]))
- ) {
- return $this->smarty->ext->_filterHandler->runFilter('post', $code, $this->template);
- } else {
- return $code;
- }
- }
-
-
-
- public function preFilter($_content)
- {
-
- if ($_content != '' &&
- ((isset($this->smarty->autoload_filters[ 'pre' ]) || isset($this->smarty->registered_filters[ 'pre' ])))
- ) {
- return $this->smarty->ext->_filterHandler->runFilter('pre', $_content, $this->template);
- } else {
- return $_content;
- }
- }
-
-
-
- public function compileTag($tag, $args, $parameter = array())
- {
- $this->prefixCodeStack[] = $this->prefix_code;
- $this->prefix_code = array();
- $result = $this->compileTag2($tag, $args, $parameter);
- $this->prefix_code = array_merge($this->prefix_code, array_pop($this->prefixCodeStack));
- return $result;
- }
-
-
-
- private function compileTag2($tag, $args, $parameter)
- {
- $plugin_type = '';
-
-
- $this->has_code = true;
- $this->has_output = false;
-
- if (isset($this->smarty->_cache[ 'get_used_tags' ])) {
- $this->template->_cache[ 'used_tags' ][] = array($tag, $args);
- }
-
- 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;
- }
-
- if (($_output = $this->callTagCompiler($tag, $args, $parameter)) === false) {
- if (isset($this->parent_compiler->template->tpl_function[ $tag ])) {
-
- $args[ '_attr' ][ 'name' ] = "'" . $tag . "'";
- $_output = $this->callTagCompiler('call', $args, $parameter);
- }
- }
- if ($_output !== false) {
- if ($_output !== true) {
-
- if ($this->has_code) {
-
- if ($this->has_output) {
- $_output .= "\n";
- }
-
- return $_output;
- }
- }
-
- return null;
- } else {
-
- if (isset($args[ '_attr' ])) {
- foreach ($args[ '_attr' ] as $key => $attribute) {
- if (is_array($attribute)) {
- $args = array_merge($args, $attribute);
- }
- }
- }
-
- if (strlen($tag) < 6 || substr($tag, - 5) != 'close') {
-
- if (isset($this->smarty->registered_objects[ $tag ]) && isset($parameter[ 'object_method' ])) {
- $method = $parameter[ 'object_method' ];
- if (!in_array($method, $this->smarty->registered_objects[ $tag ][ 3 ]) &&
- (empty($this->smarty->registered_objects[ $tag ][ 1 ]) ||
- in_array($method, $this->smarty->registered_objects[ $tag ][ 1 ]))
- ) {
- return $this->callTagCompiler('private_object_function', $args, $parameter, $tag, $method);
- } elseif (in_array($method, $this->smarty->registered_objects[ $tag ][ 3 ])) {
- return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag,
- $method);
- } else {
-
- $this->trigger_template_error('not allowed method "' . $method . '" in registered object "' .
- $tag . '"', null, true);
- }
- }
-
- foreach (array(Smarty::PLUGIN_COMPILER, Smarty::PLUGIN_FUNCTION, Smarty::PLUGIN_BLOCK) as $plugin_type)
- {
- if (isset($this->smarty->registered_plugins[ $plugin_type ][ $tag ])) {
-
- 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;
- }
- }
- if (!$this->smarty->registered_plugins[ $plugin_type ][ $tag ][ 1 ]) {
- $this->tag_nocache = true;
- }
- $function = $this->smarty->registered_plugins[ $plugin_type ][ $tag ][ 0 ];
- if (!is_array($function)) {
- return $function($new_args, $this);
- } elseif (is_object($function[ 0 ])) {
- return $this->smarty->registered_plugins[ $plugin_type ][ $tag ][ 0 ][ 0 ]->{$function[ 1 ]}($new_args,
- $this);
- } else {
- return call_user_func_array($function, array($new_args, $this));
- }
- }
-
- if ($plugin_type == Smarty::PLUGIN_FUNCTION || $plugin_type == Smarty::PLUGIN_BLOCK) {
- return $this->callTagCompiler('private_registered_' . $plugin_type, $args, $parameter,
- $tag);
- }
- }
- }
-
- foreach ($this->plugin_search_order as $plugin_type) {
- if ($plugin_type == Smarty::PLUGIN_COMPILER &&
- $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)) {
-
- $new_args = array();
- foreach ($args as $key => $mixed) {
- if (is_array($mixed)) {
- $new_args = array_merge($new_args, $mixed);
- } else {
- $new_args[ $key ] = $mixed;
- }
- }
-
- return $plugin($new_args, $this->smarty);
- }
- if (class_exists($plugin, false)) {
- $plugin_object = new $plugin;
- if (method_exists($plugin_object, 'compile')) {
- return $plugin_object->compile($args, $this);
- }
- }
- throw new SmartyException("Plugin \"{$tag}\" not callable");
- } else {
- if ($function = $this->getPlugin($tag, $plugin_type)) {
- 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;
-
- foreach ($this->plugin_search_order as $plugin_type) {
- if (isset($this->default_handler_plugins[ $plugin_type ][ $tag ])) {
- $found = true;
- break;
- }
- }
- if (!$found) {
-
- foreach ($this->plugin_search_order as $plugin_type) {
- if ($this->getPluginFromDefaultHandler($tag, $plugin_type)) {
- $found = true;
- break;
- }
- }
- }
- if ($found) {
-
- 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);
- } elseif (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);
- }
- }
- }
- } else {
-
- $base_tag = substr($tag, 0, - 5);
-
- if (isset($this->smarty->registered_objects[ $base_tag ]) && isset($parameter[ 'object_method' ])) {
- $method = $parameter[ 'object_method' ];
- if (in_array($method, $this->smarty->registered_objects[ $base_tag ][ 3 ])) {
- return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag,
- $method);
- } else {
-
- $this->trigger_template_error('not allowed closing tag method "' . $method .
- '" in registered object "' . $base_tag . '"', null, true);
- }
- }
-
- 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);
- }
-
- if (isset($this->smarty->registered_plugins[ Smarty::PLUGIN_FUNCTION ][ $tag ])) {
- return $this->callTagCompiler('private_registered_function', $args, $parameter, $tag);
- }
-
- if ($function = $this->getPlugin($base_tag, Smarty::PLUGIN_BLOCK)) {
- return $this->callTagCompiler('private_block_plugin', $args, $parameter, $tag, $function);
- }
-
- if ($function = $this->getPlugin($tag, Smarty::PLUGIN_FUNCTION)) {
- if (!isset($this->smarty->security_policy) ||
- $this->smarty->security_policy->isTrustedTag($tag, $this)
- ) {
- return $this->callTagCompiler('private_function_plugin', $args, $parameter, $tag, $function);
- }
- }
-
- if (isset($this->smarty->registered_plugins[ Smarty::PLUGIN_COMPILER ][ $tag ])) {
-
- $args = array();
- if (!$this->smarty->registered_plugins[ Smarty::PLUGIN_COMPILER ][ $tag ][ 1 ]) {
- $this->tag_nocache = true;
- }
- $function = $this->smarty->registered_plugins[ Smarty::PLUGIN_COMPILER ][ $tag ][ 0 ];
- if (!is_array($function)) {
- return $function($args, $this);
- } elseif (is_object($function[ 0 ])) {
- return $this->smarty->registered_plugins[ Smarty::PLUGIN_COMPILER ][ $tag ][ 0 ][ 0 ]->$function[ 1 ]($args,
- $this);
- } else {
- return call_user_func_array($function, array($args, $this));
- }
- }
- if ($this->smarty->loadPlugin('smarty_compiler_' . $tag)) {
- $plugin = 'smarty_compiler_' . $tag;
- if (is_callable($plugin)) {
- return $plugin($args, $this->smarty);
- }
- if (class_exists($plugin, false)) {
- $plugin_object = new $plugin;
- if (method_exists($plugin_object, 'compile')) {
- return $plugin_object->compile($args, $this);
- }
- }
- throw new SmartyException("Plugin \"{$tag}\" not callable");
- }
- }
- $this->trigger_template_error("unknown tag \"" . $tag . "\"", null, true);
- }
- }
-
-
-
- public function compileVariable($variable)
- {
- if (strpos($variable, '(') == 0) {
-
- $var = trim($variable, '\'');
- $this->tag_nocache = $this->tag_nocache |
- $this->template->ext->getTemplateVars->_getVariable($this->template, $var, null, true, false)->nocache;
-
- }
- return '$_smarty_tpl->tpl_vars[' . $variable . ']->value';
- }
-
-
-
- public function compileConfigVariable($variable)
- {
-
- return '$_smarty_tpl->smarty->ext->configLoad->_getConfigVariable($_smarty_tpl, ' . $variable . ')';
- }
-
-
-
- public function processText($text)
- {
- if ((string) $text != '') {
- $store = array();
- $_store = 0;
- $_offset = 0;
- if ($this->parser->strip) {
- if (strpos($text, '<') !== false) {
-
- $_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(
-
- '#(:SMARTY@!@|>)\s+(?=@!@SMARTY:|<)#s' => '\1 \2',
-
- '#(([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);
- }
- }
- return new Smarty_Internal_ParseTree_Text($text);
- }
- return null;
- }
-
-
-
- public function callTagCompiler($tag, $args, $param1 = null, $param2 = null, $param3 = null)
- {
-
- if (!isset($this->_tag_objects[ $tag ])) {
-
- $_tag = explode('_', $tag);
- $_tag = array_map('ucfirst', $_tag);
- $class_name = 'Smarty_Internal_Compile_' . implode('_', $_tag);
- if (class_exists($class_name) &&
- (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this))
- ) {
- $this->_tag_objects[ $tag ] = new $class_name;
- } else {
- $this->_tag_objects[ $tag ] = false;
- return false;
- }
- }
-
- return $this->_tag_objects[ $tag ] === false ? false :
- $this->_tag_objects[ $tag ]->compile($args, $this, $param1, $param2, $param3);
- }
-
-
-
- public function getPlugin($plugin_name, $plugin_type)
- {
- $function = null;
- if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
- if (isset($this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ])) {
- $function =
- $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ];
- } elseif (isset($this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ])) {
- $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ] =
- $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ];
- $function =
- $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ];
- }
- } else {
- if (isset($this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ])) {
- $function =
- $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ];
- } elseif (isset($this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ])) {
- $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ] =
- $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ];
- $function =
- $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ];
- }
- }
- if (isset($function)) {
- if ($plugin_type == 'modifier') {
- $this->modifier_plugins[ $plugin_name ] = true;
- }
-
- return $function;
- }
-
- $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->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'file' ] =
- $file;
- $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ] =
- $function;
- } else {
- $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'file' ] =
- $file;
- $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ] =
- $function;
- }
- if ($plugin_type == 'modifier') {
- $this->modifier_plugins[ $plugin_name ] = true;
- }
-
- return $function;
- }
- if (is_callable($function)) {
-
- return $function;
- }
-
- return false;
- }
-
-
-
- public function getPluginFromDefaultHandler($tag, $plugin_type)
- {
- $callback = null;
- $script = null;
- $cacheable = true;
- $result = call_user_func_array($this->smarty->default_plugin_handler_func,
- array($tag, $plugin_type, $this->template, &$callback, &$script, &$cacheable));
- if ($result) {
- $this->tag_nocache = $this->tag_nocache || !$cacheable;
- if ($script !== null) {
- if (is_file($script)) {
- if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
- $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $tag ][ $plugin_type ][ 'file' ] =
- $script;
- $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $tag ][ $plugin_type ][ 'function' ] =
- $callback;
- } else {
- $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $tag ][ $plugin_type ][ 'file' ] =
- $script;
- $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $tag ][ $plugin_type ][ 'function' ] =
- $callback;
- }
- require_once $script;
- } else {
- $this->trigger_template_error("Default plugin handler: Returned script file \"{$script}\" for \"{$tag}\" not found");
- }
- }
- if (!is_string($callback) &&
- !(is_array($callback) && is_string($callback[ 0 ]) && is_string($callback[ 1 ]))
- ) {
- $this->trigger_template_error("Default plugin handler: Returned callback for \"{$tag}\" must be a static function name or array of class and function name");
- }
- if (is_callable($callback)) {
- $this->default_handler_plugins[ $plugin_type ][ $tag ] = array($callback, true, array());
-
- return true;
- } else {
- $this->trigger_template_error("Default plugin handler: Returned callback for \"{$tag}\" not callable");
- }
- }
-
- return false;
- }
-
-
-
- public function appendCode($left, $right)
- {
- if (preg_match('/\s*\?>\s*$/', $left) && preg_match('/^\s*<\?php\s+/', $right)) {
- $left = preg_replace('/\s*\?>\s*$/', "\n", $left);
- $left .= preg_replace('/^\s*<\?php\s+/', '', $right);
- } else {
- $left .= $right;
- }
- return $left;
- }
-
-
-
- public function processNocacheCode($content, $is_code)
- {
-
- if ($is_code && !empty($content)) {
-
- if ((!($this->template->source->handler->recompiled) || $this->forceNocache) && $this->template->caching &&
- !$this->suppressNocacheProcessing && ($this->nocache || $this->tag_nocache)
- ) {
- $this->template->compiled->has_nocache_code = true;
- $_output = addcslashes($content, '\'\\');
- $_output = str_replace("^#^", "'", $_output);
- $_output = "<?php echo '/*%%SmartyNocache:{$this->nocache_hash}%%*/" . $_output .
- "/*/%%SmartyNocache:{$this->nocache_hash}%%*/';?>\n";
-
- foreach ($this->modifier_plugins as $plugin_name => $dummy) {
- if (isset($this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ 'modifier' ])) {
- $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ 'modifier' ] =
- $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ 'modifier' ];
- }
- }
- } else {
- $_output = $content;
- }
- } else {
- $_output = $content;
- }
- $this->modifier_plugins = array();
- $this->suppressNocacheProcessing = false;
- $this->tag_nocache = false;
-
- return $_output;
- }
-
-
-
- public function getId($input)
- {
- if (preg_match('~^[\'"]*([0-9]*[a-zA-Z_]\w*)[\'"]*$~', $input, $match)) {
- return $match[ 1 ];
- }
- return false;
- }
-
-
-
- public function getVariableName($input)
- {
- if (preg_match('~^[$]_smarty_tpl->tpl_vars\[[\'"]*([0-9]*[a-zA-Z_]\w*)[\'"]*\]->value$~', $input, $match)) {
- return $match[ 1 ];
- }
- return false;
- }
-
-
-
- public function makeNocacheCode($code)
- {
- return "echo '/*%%SmartyNocache:{$this->nocache_hash}%%*/<?php " .
- str_replace("^#^", "'", addcslashes($code, '\'\\')) . "?>/*/%%SmartyNocache:{$this->nocache_hash}%%*/';\n";
- }
-
-
-
- public function trigger_template_error($args = null, $line = null, $tagline = null)
- {
- $lex = $this->parser->lex;
- if ($tagline === true) {
-
- $line = $lex->taglineno;
- } elseif (!isset($line)) {
-
- $line = $lex->line;
- } else {
- $line = (int) $line;
- }
-
- if (in_array($this->template->source->type, array('eval', 'string'))) {
- $templateName = $this->template->source->type . ':' . trim(preg_replace('![\t\r\n]+!', ' ',
- strlen($lex->data) > 40 ?
- substr($lex->data, 0, 40) .
- '...' : $lex->data));
- } else {
- $templateName = $this->template->source->type . ':' . $this->template->source->filepath;
- }
-
-
- $match = preg_split("/\n/", $lex->data);
- $error_text =
- 'Syntax error in template "' . (empty($this->trace_filepath) ? $templateName : $this->trace_filepath) .
- '" on line ' . ($line + $this->trace_line_offset) . ' "' .
- trim(preg_replace('![\t\r\n]+!', ' ', $match[ $line - 1 ])) . '" ';
- if (isset($args)) {
-
- $error_text .= $args;
- } else {
- $expect = array();
-
- $error_text .= ' - Unexpected "' . $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($lex->smarty_token_names[ $exp_token ])) {
-
- $expect[] = '"' . $lex->smarty_token_names[ $exp_token ] . '"';
- } else {
-
- $expect[] = $this->parser->yyTokenName[ $token ];
- }
- }
- $error_text .= ', expected one of: ' . implode(' , ', $expect);
- }
- }
- $e = new SmartyCompilerException($error_text);
- $e->line = $line;
- $e->source = trim(preg_replace('![\t\r\n]+!', ' ', $match[ $line - 1 ]));
- $e->desc = $args;
- $e->template = $this->template->source->filepath;
- throw $e;
- }
- }
|