⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smarty_compiler.class.php

📁 转载中国源码下载站 1) 基于PHP语言开发,MYSQL数据库驱动的多用户留言本 2) 采用PHP官方提供的编译模板引擎smarty 3) 代码、页面分离
💻 PHP
📖 第 1 页 / 共 5 页
字号:
        if (($_len=strlen($compiled_content)) && ($compiled_content{$_len - 1} == "\n" )) {            $compiled_content = substr($compiled_content, 0, -1);        }        if (!empty($this->_cache_serial)) {            $compiled_content = "<?php \$this->_cache_serials['".$this->_cache_include."'] = '".$this->_cache_serial."'; ?>" . $compiled_content;        }        // remove unnecessary close/open tags        $compiled_content = preg_replace('!\?>\n?<\?php!', '', $compiled_content);        // run compiled template through postfilter functions        if (count($this->_plugins['postfilter']) > 0) {            foreach ($this->_plugins['postfilter'] as $filter_name => $postfilter) {                if ($postfilter === false) continue;                if ($postfilter[3] || is_callable($postfilter[0])) {                    $compiled_content = call_user_func_array($postfilter[0],                                                              array($compiled_content, &$this));                    $this->_plugins['postfilter'][$filter_name][3] = true;                } else {                    $this->_trigger_fatal_error("Smarty plugin error: postfilter '$filter_name' is not implemented");                }            }        }        // put header at the top of the compiled template        $template_header = "<?php /* Smarty version ".$this->_version.", created on ".strftime("%Y-%m-%d %H:%M:%S")."\n";        $template_header .= "         compiled from ".strtr(urlencode($resource_name), array('%2F'=>'/', '%3A'=>':'))." */ ?>\n";        /* Emit code to load needed plugins. */        $this->_plugins_code = '';        if (count($this->_plugin_info)) {            $_plugins_params = "array('plugins' => array(";            foreach ($this->_plugin_info as $plugin_type => $plugins) {                foreach ($plugins as $plugin_name => $plugin_info) {                    $_plugins_params .= "array('$plugin_type', '$plugin_name', '$plugin_info[0]', $plugin_info[1], ";                    $_plugins_params .= $plugin_info[2] ? 'true),' : 'false),';                }            }            $_plugins_params .= '))';			$plugins_code = "<?php require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.load_plugins.php');\nsmarty_core_load_plugins($_plugins_params, \$this); ?>\n";            $template_header .= $plugins_code;            $this->_plugin_info = array();            $this->_plugins_code = $plugins_code;        }        if ($this->_init_smarty_vars) {            $template_header .= "<?php require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.assign_smarty_interface.php');\nsmarty_core_assign_smarty_interface(null, \$this); ?>\n";            $this->_init_smarty_vars = false;        }        $compiled_content = $template_header . $compiled_content;        return true;    }	/**	 * Compile a template tag	 *	 * @param string $template_tag     * @return string	 */    function _compile_tag($template_tag)    {		// default to php output		$this->_output_type = 'php';				        /* Matched comment. */        if ($template_tag{0} == '*' && $template_tag{strlen($template_tag) - 1} == '*')            return '';		        /* Split tag into two three parts: command, command modifiers and the arguments. */        if(! preg_match('/^(?:(' . $this->_obj_call_regexp . '|' . $this->_var_regexp				. '|\/?' . $this->_reg_obj_regexp . '|\/?' . $this->_func_regexp . ')(' . $this->_mod_regexp . '*))                      (?:\s+(.*))?$                    /xs', $template_tag, $match)) {			$this->_syntax_error("unrecognized tag: $template_tag", E_USER_ERROR, __FILE__, __LINE__);		}        $tag_command = $match[1];        $tag_modifier = isset($match[2]) ? $match[2] : null;        $tag_args = isset($match[3]) ? $match[3] : null;        if (preg_match('!^' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '$!', $tag_command)) {        	/* tag name is a variable or object */            $_return = $this->_parse_var_props($tag_command . $tag_modifier, $this->_parse_attrs($tag_args));			if(isset($_tag_attrs['assign'])) {				return "<?php \$this->assign('" . $this->_dequote($_tag_attrs['assign']) . "', $_return ); ?>\n";  			} elseif ($this->_output_type == 'php') {            	return "<?php echo $_return; ?>" . $this->_additional_newline;			} else {				// static				return $_return;			}		}			    /* If the tag name is a registered object, we process it. */        if (preg_match('!^\/?' . $this->_reg_obj_regexp . '$!', $tag_command)) {			return $this->_compile_registered_object_tag($tag_command, $this->_parse_attrs($tag_args), $tag_modifier);		}        switch ($tag_command) {            case 'include':                return $this->_compile_include_tag($tag_args);            case 'include_php':                return $this->_compile_include_php_tag($tag_args);            case 'if':                return $this->_compile_if_tag($tag_args);            case 'else':                return '<?php else: ?>';            case 'elseif':                return $this->_compile_if_tag($tag_args, true);            case '/if':                return '<?php endif; ?>';            case 'capture':                return $this->_compile_capture_tag(true, $tag_args);            case '/capture':                return $this->_compile_capture_tag(false);            case 'ldelim':                return $this->left_delimiter;            case 'rdelim':                return $this->right_delimiter;            case 'section':                array_push($this->_sectionelse_stack, false);                return $this->_compile_section_start($tag_args);            case 'sectionelse':                $this->_sectionelse_stack[count($this->_sectionelse_stack)-1] = true;                return "<?php endfor; else: ?>";            case '/section':                if (array_pop($this->_sectionelse_stack))                    return "<?php endif; ?>";                else                    return "<?php endfor; endif; ?>";            case 'foreach':                array_push($this->_foreachelse_stack, false);                return $this->_compile_foreach_start($tag_args);                break;            case 'foreachelse':                $this->_foreachelse_stack[count($this->_foreachelse_stack)-1] = true;                return "<?php endforeach; unset(\$_from); else: ?>";            case '/foreach':                if (array_pop($this->_foreachelse_stack))                    return "<?php endif; ?>";                else                    return "<?php endforeach; unset(\$_from); endif; ?>";            case 'strip':            case '/strip':                if ($tag_command{0}=='/') {                    if (--$this->_strip_depth==0) { /* outermost closing {/strip} */                        $this->_additional_newline = "\n";                        return $this->left_delimiter.$tag_command.$this->right_delimiter;                    }                } else {                    if ($this->_strip_depth++==0) { /* outermost opening {strip} */                        $this->_additional_newline = "";                        return $this->left_delimiter.$tag_command.$this->right_delimiter;                    }                }                return '';            case 'literal':                list (,$literal_block) = each($this->_literal_blocks);                $this->_current_line_no += substr_count($literal_block, "\n");                return "<?php echo '".str_replace("'", "\'", str_replace("\\", "\\\\", $literal_block))."'; ?>" . $this->_additional_newline;            case 'php':                if ($this->security && !$this->security_settings['PHP_TAGS']) {                    $this->_syntax_error("(secure mode) php tags not permitted", E_USER_WARNING, __FILE__, __LINE__);                    return;                }                list (,$php_block) = each($this->_php_blocks);                $this->_current_line_no += substr_count($php_block, "\n");                return '<?php '.$php_block.' ?>';            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 {                    return $this->_compile_custom_tag($tag_command, $tag_args, $tag_modifier);                }        }    }	/**	 * compile the custom compiler tag	 *     * sets $output to the compiled custom compiler tag	 * @param string $tag_command	 * @param string $tag_args	 * @param string $output     * @return boolean	 */    function _compile_compiler_tag($tag_command, $tag_args, &$output)    {        $found = false;        $have_function = true;        /*         * First we check if the compiler function has already been registered         * or loaded from a plugin file.         */        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;            }        }        /*         * Otherwise we need to load plugin file and look for the function         * inside it.         */        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);            }        }        /*         * True return value means that we either found a plugin or a         * dynamically registered function. False means that we didn't and the         * compiler should now emit code to load custom function plugin for this         * tag.         */        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;        }    }	/**	 * 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 ($tag_command{0} == '/') {            $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) {            $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\$_params = \$this->_tag_stack[] = array('$tag_command', array(".implode(',', $arg_list).')); ';            $output .= $this->_compile_plugin_call('block', $tag_command).'($_params[1], null, $this, $_block_repeat=true); unset($_params);';

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -