📄 smarty_compiler.class.php
字号:
case '/capture':
return $this->_compile_capture_tag(false);
case 'ldelim':
return $this->left_delimiter;
case 'rdelim':
return $this->right_delimiter;
case 'section':
$this->_push_tag('section');
return $this->_compile_section_start($tag_args);
case 'sectionelse':
$this->_push_tag('sectionelse');
return "<?php endfor; else: ?>";
break;
case '/section':
$_open_tag = $this->_pop_tag('section');
if ($_open_tag == 'sectionelse')
return "<?php endif; ?>";
else
return "<?php endfor; endif; ?>";
case 'foreach':
$this->_push_tag('foreach');
return $this->_compile_foreach_start($tag_args);
break;
case 'foreachelse':
$this->_push_tag('foreachelse');
return "<?php endforeach; unset(\$_from); else: ?>";
case '/foreach':
$_open_tag = $this->_pop_tag('foreach');
if ($_open_tag == 'foreachelse')
return "<?php endif; ?>";
else
return "<?php endforeach; unset(\$_from); endif; ?>";
break;
case 'strip':
case '/strip':
if ($tag_command{0}=='/') {
$this->_pop_tag('strip');
if (--$this->_strip_depth==0) { /* outermost closing {/strip} */
$this->_additional_newline = "\n";
return $this->left_delimiter.$tag_command.$this->right_delimiter;
}
} else {
$this->_push_tag('strip');
if ($this->_strip_depth++==0) { /* outermost opening {strip} */
$this->_additional_newline = "";
return $this->left_delimiter.$tag_command.$this->right_delimiter;
}
}
return '';
case 'php':
/* handle folded tags replaced by {php} */
list(, $block) = each($this->_folded_blocks);
$this->_current_line_no += substr_count($block[0], "\n");
/* the number of matched elements in the regexp in _compile_file()
determins the type of folded tag that was found */
switch (count($block)) {
case 2: /* comment */
return '';
case 3: /* literal */
return "<?php echo '" . strtr($block[2], array("'"=>"\'", "\\"=>"\\\\")) . "'; ?>" . $this->_additional_newline;
case 4: /* php */
if ($this->security && !$this->security_settings['PHP_TAGS']) {
$this->_syntax_error("(secure mode) php tags not permitted", E_USER_WARNING, __FILE__, __LINE__);
return;
}
return '<?php ' . $block[3] .' ?>';
}
break;
case 'insert':
return $this->_compile_insert_tag($tag_args);
default:
if ($this->_compile_compiler_tag($tag_command, $tag_args, $output)) {
return $output;
} else if ($this->_compile_block_tag($tag_command, $tag_args, $tag_modifier, $output)) {
return $output;
} else if ($this->_compile_custom_tag($tag_command, $tag_args, $tag_modifier, $output)) {
return $output;
} else {
$this->_syntax_error("unrecognized tag '$tag_command'", E_USER_ERROR, __FILE__, __LINE__);
}
}
}
function _compile_compiler_tag($tag_command, $tag_args, &$output)
{
$found = false;
$have_function = true;
if (isset($this->_plugins['compiler'][$tag_command])) {
$found = true;
$plugin_func = $this->_plugins['compiler'][$tag_command][0];
if (!is_callable($plugin_func)) {
$message = "compiler function '$tag_command' is not implemented";
$have_function = false;
}
}
else if ($plugin_file = $this->_get_plugin_filepath('compiler', $tag_command)) {
$found = true;
include_once $plugin_file;
$plugin_func = 'smarty_compiler_' . $tag_command;
if (!is_callable($plugin_func)) {
$message = "plugin function $plugin_func() not found in $plugin_file\n";
$have_function = false;
} else {
$this->_plugins['compiler'][$tag_command] = array($plugin_func, null, null, null, true);
}
}
if ($found) {
if ($have_function) {
$output = call_user_func_array($plugin_func, array($tag_args, &$this));
if($output != '') {
$output = '<?php ' . $this->_push_cacheable_state('compiler', $tag_command)
. $output
. $this->_pop_cacheable_state('compiler', $tag_command) . ' ?>';
}
} else {
$this->_syntax_error($message, E_USER_WARNING, __FILE__, __LINE__);
}
return true;
} else {
return false;
}
}
function _compile_block_tag($tag_command, $tag_args, $tag_modifier, &$output)
{
if ($tag_command{0} == '/') {
$start_tag = false;
$tag_command = substr($tag_command, 1);
} else
$start_tag = true;
$found = false;
$have_function = true;
if (isset($this->_plugins['block'][$tag_command])) {
$found = true;
$plugin_func = $this->_plugins['block'][$tag_command][0];
if (!is_callable($plugin_func)) {
$message = "block function '$tag_command' is not implemented";
$have_function = false;
}
}
else if ($plugin_file = $this->_get_plugin_filepath('block', $tag_command)) {
$found = true;
include_once $plugin_file;
$plugin_func = 'smarty_block_' . $tag_command;
if (!function_exists($plugin_func)) {
$message = "plugin function $plugin_func() not found in $plugin_file\n";
$have_function = false;
} else {
$this->_plugins['block'][$tag_command] = array($plugin_func, null, null, null, true);
}
}
if (!$found) {
return false;
} else if (!$have_function) {
$this->_syntax_error($message, E_USER_WARNING, __FILE__, __LINE__);
return true;
}
$this->_add_plugin('block', $tag_command);
if ($start_tag)
$this->_push_tag($tag_command);
else
$this->_pop_tag($tag_command);
if ($start_tag) {
$output = '<?php ' . $this->_push_cacheable_state('block', $tag_command);
$attrs = $this->_parse_attrs($tag_args);
$arg_list = $this->_compile_arg_list('block', $tag_command, $attrs, $_cache_attrs='');
$output .= "$_cache_attrs\$this->_tag_stack[] = array('$tag_command', array(".implode(',', $arg_list).')); ';
$output .= $this->_compile_plugin_call('block', $tag_command).'($this->_tag_stack[count($this->_tag_stack)-1][1], null, $this, $_block_repeat=true);';
$output .= 'while ($_block_repeat) { ob_start(); ?>';
} else {
$output = '<?php $this->_block_content = ob_get_contents(); ob_end_clean(); ';
$_out_tag_text = $this->_compile_plugin_call('block', $tag_command).'($this->_tag_stack[count($this->_tag_stack)-1][1], $this->_block_content, $this, $_block_repeat=false)';
if ($tag_modifier != '') {
$this->_parse_modifiers($_out_tag_text, $tag_modifier);
}
$output .= 'echo '.$_out_tag_text.'; } ';
$output .= " array_pop(\$this->_tag_stack); " . $this->_pop_cacheable_state('block', $tag_command) . '?>';
}
return true;
}
function _compile_custom_tag($tag_command, $tag_args, $tag_modifier, &$output)
{
$found = false;
$have_function = true;
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_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 false;
} else if (!$have_function) {
$this->_syntax_error($message, E_USER_WARNING, __FILE__, __LINE__);
return true;
}
$this->_add_plugin('function', $tag_command);
$_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;
}
return true;
}
function _compile_registered_object_tag($tag_command, $attrs, $tag_modifier)
{
if ($tag_command{0} == '/') {
$start_tag = false;
$tag_command = substr($tag_command, 1);
} else {
$start_tag = true;
}
list($object, $obj_comp) = explode('->', $tag_command);
$arg_list = array();
if(count($attrs)) {
$_assign_var = false;
foreach ($attrs as $arg_name => $arg_value) {
if($arg_name == 'assign') {
$_assign_var = $arg_value;
unset($attrs['assign']);
continue;
}
if (is_bool($arg_value))
$arg_value = $arg_value ? 'true' : 'false';
$arg_list[] = "'$arg_name' => $arg_value";
}
}
if($this->_reg_objects[$object][2]) {
$args = "array(".implode(',', (array)$arg_list)."), \$this";
} else {
$args = implode(',', array_values($attrs));
if (empty($args)) {
$args = 'null';
}
}
$prefix = '';
$postfix = '';
$newline = '';
if(!is_object($this->_reg_objects[$object][0])) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -