?? smarty_compiler.class.php
字號:
/** * compile block function tag * * sets $output to compiled block function tag * @param string $tag_command * @param string $tag_args * @param string $tag_modifier * @param string $output * @return boolean */ function _compile_block_tag($tag_command, $tag_args, $tag_modifier, &$output) { if (substr($tag_command, 0, 1) == '/') { $start_tag = false; $tag_command = substr($tag_command, 1); } else $start_tag = true; $found = false; $have_function = true; /* * First we check if the block function has already been registered * or loaded from a plugin file. */ 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; } } /* * Otherwise we need to load plugin file and look for the function * inside it. */ 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; } /* * Even though we've located the plugin function, compilation * happens only once, so the plugin will still need to be loaded * at runtime for future requests. */ $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); $_cache_attrs=''; $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 .= '$_block_repeat=true;' . $this->_compile_plugin_call('block', $tag_command).'($this->_tag_stack[count($this->_tag_stack)-1][1], null, $this, $_block_repeat);'; $output .= 'while ($_block_repeat) { ob_start(); ?>'; } else { $output = '<?php $_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], $_block_content, $this, $_block_repeat)'; if ($tag_modifier != '') { $this->_parse_modifiers($_out_tag_text, $tag_modifier); } $output .= '$_block_repeat=false;echo ' . $_out_tag_text . '; } '; $output .= " array_pop(\$this->_tag_stack); " . $this->_pop_cacheable_state('block', $tag_command) . '?>'; } return true; } /** * 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; } } /* * Otherwise we need to load plugin file and look for the function * inside it. */ 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; } /* declare plugin to be loaded on display of the template that we compile right now */ $this->_add_plugin('function', $tag_command); $_cacheable_state = $this->_push_cacheable_state('function', $tag_command); $attrs = $this->_parse_attrs($tag_args); $_cache_attrs = ''; $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; } /** * compile a registered object tag * * @param string $tag_command * @param array $attrs * @param string $tag_modifier * @return string */ function _compile_registered_object_tag($tag_command, $attrs, $tag_modifier) { if (substr($tag_command, 0, 1) == '/') { $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]) { // smarty object argument format $args = "array(".implode(',', (array)$arg_list)."), \$this"; } else { // traditional argument format $args = implode(',', array_values($attrs)); if (empty($args)) { $args = 'null'; } } $prefix = ''; $postfix = ''; $newline = ''; if(!is_object($this->_reg_objects[$object][0])) { $this->_trigger_fatal_error("registered '$object' is not an object" , $this->_current_file, $this->_current_line_no, __FILE__, __LINE__); } elseif(!empty($this->_reg_objects[$object][1]) && !in_array($obj_comp, $this->_reg_objects[$object][1])) { $this->_trigger_fatal_error("'$obj_comp' is not a registered component of object '$object'", $this->_current_file, $this->_current_line_no, __FILE__, __LINE__); } elseif(method_exists($this->_reg_objects[$object][0], $obj_comp)) { // method if(in_array($obj_comp, $this->_reg_objects[$object][3])) { // block method if ($start_tag) { $prefix = "\$this->_tag_stack[] = array('$obj_comp', $args); "; $prefix .= "\$_block_repeat=true; \$this->_reg_objects['$object'][0]->$obj_comp(\$this->_tag_stack[count(\$this->_tag_stack)-1][1], null, \$this, \$_block_repeat); "; $prefix .= "while (\$_block_repeat) { ob_start();"; $return = null; $postfix = ''; } else { $prefix = "\$_obj_block_content = ob_get_contents(); ob_end_clean(); "; $return = "\$_block_repeat=false; \$this->_reg_objects['$object'][0]->$obj_comp(\$this->_tag_stack[count(\$this->_tag_stack)-1][1], \$_obj_block_content, \$this, \$_block_repeat)"; $postfix = "} array_pop(\$this->_tag_stack);"; } } else { // non-block method $return = "\$this->_reg_objects['$object'][0]->$obj_comp($args)"; } } else { // property $return = "\$this->_reg_objects['$object'][0]->$obj_comp"; } if($return != null) { if($tag_modifier != '') { $this->_parse_modifiers($return, $tag_modifier); } if(!empty($_assign_var)) { $output = "\$this->assign('" . $this->_dequote($_assign_var) ."', $return);"; } else { $output = 'echo ' . $return . ';'; $newline = $this->_additional_newline; } } else { $output = ''; } return '<?php ' . $prefix . $output . $postfix . "?>" . $newline; } /** * Compile {insert ...} tag * * @param string $tag_args * @return string */ function _compile_insert_tag($tag_args) { $attrs = $this->_parse_attrs($tag_args); $name = $this->_dequote($attrs['name']); if (empty($name)) { $this->_syntax_error("missing insert name", E_USER_ERROR, __FILE__, __LINE__); } if (!empty($attrs['script'])) { $delayed_loading = true; } else { $delayed_loading = false; } foreach ($attrs as $arg_name => $arg_value) { if (is_bool($arg_value)) $arg_value = $arg_value ? 'true' : 'false'; $arg_list[] = "'$arg_name' => $arg_value"; } $this->_add_plugin('insert', $name, $delayed_loading); $_params = "array('args' => array(".implode(', ', (array)$arg_list)."))"; return "<?php require_once(SMARTY_CORE_DIR . 'core.run_insert_handler.php');\necho smarty_core_run_insert_handler($_params, \$this); ?>" . $this->_additional_newline; } /** * Compile {include ...} tag * * @param string $tag_args * @return string */ function _compile_include_tag($tag_args) { $attrs = $this->_parse_attrs($tag_args); $arg_list = array(); if (empty($attrs['file'])) { $this->_syntax_error("missing 'file' attribute in include tag", E_USER_ERROR, __FILE__, __LINE__); } foreach ($attrs as $arg_name => $arg_value) { if ($arg_name == 'file') { $include_file = $arg_value; continue; } else if ($arg_name == 'assign') { $assign_var = $arg_value; continue; } if (is_bool($arg_value)) $arg_value = $arg_value ? 'true' : 'false'; $arg_list[] = "'$arg_name' => $arg_value"; } $output = '<?php '; if (isset($assign_var)) { $output .= "ob_start();\n"; }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -