/** * @param string $template_path template file. (full path) * @return CompiledTemplate */ public function compile($template_path) { $compiler = new \Smarty_Compiler(); if ($this->plugins_dir) { $compiler->plugins_dir[] = $this->plugins_dir; } $compiler->caching = 1; $source_content = file_get_contents($template_path); $compiled_content = ''; $compiler->_compile_file($template_path, $source_content, $compiled_content); $smarty_file_name = $compiler->_get_auto_filename($this->template_dir, $template_path); return new CompiledTemplate($template_path, $this->template_dir, $smarty_file_name, $compiled_content); }
function _compile_file($tpl_file, $template_source, &$template_compiled) { global $Lens_SmartyVars; $rez = parent::_compile_file($tpl_file, $template_source, &$template_compiled); $Lens_SmartyVars = $this->_vars; return $rez; }
/** * compile custom function tag * * @param string $tag_command * @param string $tag_args * @param string $tag_modifier * @return string */ function _compile_custom_tag($tag_command, $tag_args, $tag_modifier, &$output) { $found = false; $have_function = true; /* * First we check if the custom function has already been registered * or loaded from a plugin file. */ if (isset($this->_plugins['function'][$tag_command])) { $found = true; $plugin_func = $this->_plugins['function'][$tag_command][0]; if (!is_callable($plugin_func)) { $message = "custom function '{$tag_command}' is not implemented"; $have_function = false; } } else { if ($plugin_file = $this->_get_plugin_filepath('function', $tag_command)) { $found = true; include_once $plugin_file; $plugin_func = 'smarty_cms_function_' . $tag_command; if (!function_exists($plugin_func)) { $message = "plugin function {$plugin_func}() not found in {$plugin_file}\n"; $have_function = false; } else { $this->_plugins['function'][$tag_command] = array($plugin_func, null, null, null, true); } } } if (!$found) { return parent::_compile_custom_tag($tag_command, $tag_args, $tag_modifier, $output); } else { if (!$have_function) { #$this->_syntax_error($message, E_USER_WARNING, __FILE__, __LINE__); #return true; return parent::_compile_custom_tag($tag_command, $tag_args, $tag_modifier, $output); } } /* declare plugin to be loaded on display of the template that we compile right now */ $this->_add_plugin('function', $tag_command); $this->_plugins['function'][$tag_command][4] = false; $this->_plugins['function'][$tag_command][5] = array(); $_cacheable_state = $this->_push_cacheable_state('function', $tag_command); $attrs = $this->_parse_attrs($tag_args); $arg_list = $this->_compile_arg_list('function', $tag_command, $attrs, $_cache_attrs); $output = $this->_compile_plugin_call('function', $tag_command) . '(array(' . implode(',', $arg_list) . "), \$this)"; if ($tag_modifier != '') { $this->_parse_modifiers($output, $tag_modifier); } if ($output != '') { $output = '<?php ' . $_cacheable_state . $_cache_attrs . 'echo ' . $output . ';' . $this->_pop_cacheable_state('function', $tag_command) . "?>" . $this->_additional_newline; } #var_dump($output); return true; }
function _compile_compiler_tag($tagCommand, $tagArgs, &$output) { //We first try to use Smarty's own functionality to parse the tag $found = parent::_compile_compiler_tag($tagCommand, $tagArgs, $output); if ($found === false) { try { //Check if helper exists and create output $this->zendView->getHelper($tagCommand); $helperArgs = array(); if ($tagArgs !== null) { //Start parsing our custom syntax $params = explode(' ', $tagArgs); foreach ($params as $p) { //Split each key=value pair to vars list($key, $value) = explode('=', $p, 2); $section = ''; //If there's a dot in the key, it means we //need to use associative arrays if (strpos('.', $key) != -1) { list($key, $section) = explode('.', $key); } //Use Smarty's own functions to parse the value //so that if there's a variable, it gets changed to //properly point at a template variable etc. $value = $this->_parse_var_props($value); //Put the value into the arg array if ($section == '') { if (array_key_exists($key, $helperArgs)) { if (is_array($helperArgs[$key])) { $helperArgs[$key][] = $value; } else { $helperArgs[$key] = array($helperArgs[$key], $value); } } else { $helperArgs[$key] = $value; } } else { if (!is_array($helperArgs[$key])) { $helperArgs[$key] = array(); } $helperArgs[$key][$section] = $value; } } } //Save the code to put to the template in the output $output = "<?php echo \$this->callViewHelper('{$tagCommand}',array(" . $this->_createParameterCode($helperArgs) . ")); ?>"; $found = true; } catch (Exception $e) { //Exception means the helper was not found $found = false; fwrite(fopen('php://stderr', 'a'), $e->getMessage()); } } return $found; }
/** * Assign a value to a variable, also arrays or objects. * * Available attributes: * - var (mixed) Name or variable to assign. * - value (mixed) Value to assign. * * Examples: * * Initialize an empty array. * * <samp>{setvar var='foo' php='array()'}</samp> * * Set an array item. * * <samp>{setvar var='foo.bar' value=$myValue}</samp> * * Set a variable array field. * * <samp>{setvar var="foo.$key" value=$myValue}</samp> * * Set an object property. * * <samp>{setvar var='obj->bar' value=$myValue}</samp> * * Creates a new indexed array or fill the key-values in a existing $foo array. * * <samp>{setvar var='foo' keys='a,b,c' values='1,2,3'}</samp> * * Using another delimiter. * * <samp>{setvar var='bar' keys='a-b-c' values='1-2-3' delim='-'}</samp> * * @param array $params All attributes passed to this function from the template. * @param Smarty_Compiler $compiler Reference to the {@link Zikula_View} object. * * @return void */ function smarty_compiler_setvar($params, Smarty_Compiler $compiler) { /* extract the var parameter */ if (preg_match('!(.*)var=(' . $compiler->_qstr_regexp . '|\\S+?)(.*?)!Us', $params, $_match)) { $_lval = $_match[2]; $_attrs = $compiler->_parse_attrs($_match[1] . $_match[3]); } else { $compiler->_syntax_error(__f("Missing or invalid '%s' parameter.", 'var'), E_USER_WARNING, __FILE__, __LINE__); return; } /* test a possible variable */ $_lval_var = $compiler->_parse_var_props('$' . $compiler->_dequote($_lval)); if ($_lval_var[0] == '$') { $_lval = $_lval_var; } else { /* take it as a variable-name */ $_lval = '$this->_tpl_vars[' . $compiler->_parse_var_props($_lval) . ']'; } /* check for a PHP command as value */ if (isset($_attrs['php'])) { // do not allow more than one PHP command if (strpos($_attrs['php'], ';') !== false) { $_attrs['php'] = substr($_attrs['php'], 0, strpos($_attrs['php'], ';')); } $_rval = $compiler->_dequote($_attrs['php']); /* check for a scalar the value parameter */ } elseif (isset($_attrs['value'])) { $_rval = $_attrs['value']; /* list of array-values */ } elseif (isset($_attrs['values'])) { $_delim = isset($_attrs['delim']) ? $_attrs['delim'] : "','"; $_rval = 'explode(' . $_delim . ', ' . $_attrs['values'] . ')'; /* if indexed */ if (isset($_attrs['keys'])) { if (substr_count($_attrs['keys'], $_delim) != substr_count($_attrs['values'], $_delim)) { $compiler->_syntax_error(__("Keys and values size doesn't match."), E_USER_WARNING, __FILE__, __LINE__); return; } $_code = "\$_values = {$_rval}; " . "if (!isset({$_lval})) { {$_lval} = array(); } " . "foreach (explode({$_delim}, " . $_attrs['keys'] . ") as \$_i => \$_key) { " . " {$_lval}[\$_key] = \$_values[\$_i]; " . "}"; return $_code; } } else { $compiler->_syntax_error(__f("Missing '%s' parameter.", 'value'), E_USER_WARNING, __FILE__, __LINE__); return; } return $_lval . '=' . $_rval . ';'; }
/** * Allow static method calls. */ function _parse_attrs($tag_args) { $attrs = parent::_parse_attrs($tag_args); foreach ($attrs as $key => $value) { // perhaps this was intended as a static callback? if (preg_match('#^["\']([a-zA-Z_]\\w*::[a-zA-Z_]\\w*)\\((.*)?\\)["\']$#', $value, $matches)) { $arguments = '()'; if (isset($matches[2])) { // strip '".' and '."' from beginning and end $arguments = substr($matches[2], 2, -2); // remove '.",".' from between parameters $arguments = explode('.",".', $arguments); // combine arguments into string $arguments = '(' . implode(',', $arguments) . ')'; } $attrs[$key] = $matches[1] . $arguments; } } return $attrs; }
/** * compile custom function tag * * @param string $tag_command * @param string $tag_args * @param string $tag_modifier * @return string */ function _compile_custom_tag($tag_command, $tag_args, $tag_modifier, &$output) { $found = false; $have_function = true; $tmp = array('function', $tag_command, $this->_current_file, $this->_current_line_no, false); $tmp = array('plugins' => array($tmp)); require_once SMARTY_CORE_DIR . 'core.load_plugins.php'; smarty_core_load_plugins($tmp, $this); if (isset($this->_plugins['function'][$tag_command])) { $found = true; $plugin_func = $this->_plugins['function'][$tag_command][0]; if (!is_callable($plugin_func)) { $message = "custom function '{$tag_command}' is not implemented"; $have_function = false; } } if (!$found) { return parent::_compile_custom_tag($tag_command, $tag_args, $tag_modifier, $output); } else { if (!$have_function) { return parent::_compile_custom_tag($tag_command, $tag_args, $tag_modifier, $output); } } /* declare plugin to be loaded on display of the template that we compile right now */ $this->_add_plugin('function', $tag_command); $this->_plugins['function'][$tag_command][4] = false; $this->_plugins['function'][$tag_command][5] = array(); $_cacheable_state = $this->_push_cacheable_state('function', $tag_command); $attrs = $this->_parse_attrs($tag_args); $arg_list = $this->_compile_arg_list('function', $tag_command, $attrs, $_cache_attrs); $output = $this->_compile_plugin_call('function', $tag_command) . '(array(' . implode(',', $arg_list) . "), \$this)"; if ($tag_modifier != '') { $this->_parse_modifiers($output, $tag_modifier); } if ($output != '') { $output = '<?php ' . $_cacheable_state . $_cache_attrs . 'echo ' . $output . ';' . $this->_pop_cacheable_state('function', $tag_command) . "?>" . $this->_additional_newline; } // var_dump($output); return true; }
function _pop_tag($close_tag) { $message = ''; if (count($this->_tag_stack) > 0) { list($_open_tag, $_line_no) = array_pop($this->_tag_stack); if ($close_tag == $_open_tag) { return $_open_tag; } if ($close_tag == 'formset' && $_open_tag == 'formsetelse') { $this->_pop_tag($close_tag); return $_open_tag; } if ($_open_tag == 'formsetelse') { $_open_tag = 'formset'; $message = " expected {/{$_open_tag}} (opened line {$_line_no})."; $this->_syntax_error("mismatched tag {/{$close_tag}}.{$message}", E_USER_ERROR, __FILE__, __LINE__); return; } } return parent::_pop_tag($close_tag); }
/** * End a switch statement. * * @param string $tag_arg * @param Smarty_Compiler $smarty * @return string */ function smarty_compiler_endswitch($tag_arg, &$smarty) { $switchData =& $smarty->get_template_vars("_switchData"); array_shift($switchData); return "}"; }
function _compile_file($resource_name, $source_content, &$compiled_content) { $this->current_resource_name = $resource_name; return parent::_compile_file($resource_name, $source_content, $compiled_content); }
function _compile_smarty_ref(&$indexes) { $_ref = substr($indexes[0], 1); // post, get and env variables are disabled if (in_array($_ref, array('post', 'get', 'env'))) { $this->_syntax_error("access for \$smarty.{$_ref} variables is disabled, please use \$smarty.request", E_USER_WARNING, __FILE__, __LINE__); } // Access to request variable is provided via escaped one if ($_ref == 'request') { array_shift($indexes); return '$this->_tpl_vars[\'_REQUEST\']'; } return parent::_compile_smarty_ref($indexes); }
/** * compile the given source * * @param string $resource_name * @param string $source_content * @param string $compiled_content * @return boolean */ function _compile_source($resource_name, &$source_content, &$compiled_content, $cache_include_path = null) { if (file_exists(SMARTY_DIR . $this->compiler_file)) { require_once SMARTY_DIR . $this->compiler_file; } else { // use include_path require_once $this->compiler_file; } $smarty_compiler = new Smarty_Compiler(); $smarty_compiler->template_dir = $this->template_dir; $smarty_compiler->compile_dir = $this->compile_dir; $smarty_compiler->plugins_dir = $this->plugins_dir; $smarty_compiler->config_dir = $this->config_dir; $smarty_compiler->force_compile = $this->force_compile; $smarty_compiler->caching = $this->caching; $smarty_compiler->php_handling = $this->php_handling; $smarty_compiler->left_delimiter = $this->left_delimiter; $smarty_compiler->right_delimiter = $this->right_delimiter; $smarty_compiler->_version = $this->_version; $smarty_compiler->security = $this->security; $smarty_compiler->secure_dir = $this->secure_dir; $smarty_compiler->security_settings = $this->security_settings; $smarty_compiler->trusted_dir = $this->trusted_dir; $smarty_compiler->use_sub_dirs = $this->use_sub_dirs; $smarty_compiler->_reg_objects =& $this->_reg_objects; $smarty_compiler->_plugins =& $this->_plugins; $smarty_compiler->_tpl_vars =& $this->_tpl_vars; $smarty_compiler->default_modifiers = $this->default_modifiers; $smarty_compiler->compile_id = $this->_compile_id; $smarty_compiler->_config = $this->_config; $smarty_compiler->request_use_auto_globals = $this->request_use_auto_globals; if (isset($cache_include_path) && isset($this->_cache_serials[$cache_include_path])) { $smarty_compiler->_cache_serial = $this->_cache_serials[$cache_include_path]; } $smarty_compiler->_cache_include = $cache_include_path; $_results = $smarty_compiler->_compile_file($resource_name, $source_content, $compiled_content); if ($smarty_compiler->_cache_serial) { $this->_cache_include_info = array('cache_serial' => $smarty_compiler->_cache_serial, 'plugins_code' => $smarty_compiler->_plugins_code, 'include_file_path' => $cache_include_path); } else { $this->_cache_include_info = null; } return $_results; }
function _parse_parenth_args($parenth_args) { $mods = $this->default_modifiers; $this->default_modifiers = array(); $out = parent::_parse_parenth_args($parenth_args); $this->default_modifiers = $mods; return $out; }
/** * prefilter用のフィルタ関数。プラグイン用のフックポイント処理を実行 * @param string $source ソース * @param Smarty_Compiler $smarty Smartyのコンパイラクラス * @return string $source ソース */ public function prefilter_transform($source, &$smarty) { // EC-CUBE 2.13 互換用置換 $source = preg_replace('/' . $smarty->_quote_replace($smarty->left_delimiter) . 'include_php /', $smarty->left_delimiter . 'render ', $source); if (!is_null($this->objPage)) { // フックポイントを実行. /* @var $objPlugin PluginHelper */ $objPlugin = Application::alias('eccube.helper.plugin', $this->objPage->plugin_activate_flg); if (is_object($objPlugin)) { $objPlugin->doAction('prefilterTransform', array(&$source, $this->objPage, $smarty->_current_file)); } } return $source; }
function _compile_file($resource_name, $source_content, &$compiled_content) { if (parent::_compile_file($resource_name, $source_content, $compiled_content)) { $open_tag_replace_to = "\nEOT;\n"; $close_tag_replace_to = "echo <<<EOT\n"; $content = preg_replace("/\?>/si", $close_tag_replace_to, preg_replace("/<\?(php)?/si", $open_tag_replace_to, trim($compiled_content), -1, $c_open), -1, $c_close)."\n"; if ($c_open == $c_close) $content .= "\nEOT;\n"; $compiled_content = $content; return true; } }