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

📄 smarty.class.php

📁 Smarty class which may explain many things that you need. This class is very often use to start.
💻 PHP
📖 第 1 页 / 共 5 页
字号:
                    $_smarty_results = smarty_core_process_cached_inserts($_params, $this);                }                if (!empty($this->_cache_info['cache_serials'])) {                    $_params = array('results' => $_smarty_results);                    require_once(SMARTY_CORE_DIR . 'core.process_compiled_include.php');                    $_smarty_results = smarty_core_process_compiled_include($_params, $this);                }                if ($display) {                    if ($this->debugging)                    {                        // capture time for debugging info                        $_params = array();                        require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');                        $this->_smarty_debug_info[$_included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $_debug_start_time;                        require_once(SMARTY_CORE_DIR . 'core.display_debug_console.php');                        $_smarty_results .= smarty_core_display_debug_console($_params, $this);                    }                    if ($this->cache_modified_check) {                        $_server_vars = ($this->request_use_auto_globals) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS'];                        $_last_modified_date = @substr($_server_vars['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_server_vars['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3);                        $_gmt_mtime = gmdate('D, d M Y H:i:s', $this->_cache_info['timestamp']).' GMT';                        if (@count($this->_cache_info['insert_tags']) == 0                            && !$this->_cache_serials                            && $_gmt_mtime == $_last_modified_date) {                            if (php_sapi_name()=='cgi')                                header('Status: 304 Not Modified');                            else                                header('HTTP/1.1 304 Not Modified');                        } else {                            header('Last-Modified: '.$_gmt_mtime);                            echo $_smarty_results;                        }                    } else {                            echo $_smarty_results;                    }                    error_reporting($_smarty_old_error_level);                    // restore initial cache_info                    $this->_cache_info = array_pop($_cache_info);                    return true;                } else {                    error_reporting($_smarty_old_error_level);                    // restore initial cache_info                    $this->_cache_info = array_pop($_cache_info);                    return $_smarty_results;                }            } else {                $this->_cache_info['template'][$resource_name] = true;                if ($this->cache_modified_check && $display) {                    header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT');                }            }        }        // load filters that are marked as autoload        if (count($this->autoload_filters)) {            foreach ($this->autoload_filters as $_filter_type => $_filters) {                foreach ($_filters as $_filter) {                    $this->load_filter($_filter_type, $_filter);                }            }        }        $_smarty_compile_path = $this->_get_compile_path($resource_name);        // if we just need to display the results, don't perform output        // buffering - for speed        $_cache_including = $this->_cache_including;        $this->_cache_including = false;        if ($display && !$this->caching && count($this->_plugins['outputfilter']) == 0) {            if ($this->_is_compiled($resource_name, $_smarty_compile_path)                    || $this->_compile_resource($resource_name, $_smarty_compile_path))            {                include($_smarty_compile_path);            }        } else {            ob_start();            if ($this->_is_compiled($resource_name, $_smarty_compile_path)                    || $this->_compile_resource($resource_name, $_smarty_compile_path))            {                include($_smarty_compile_path);            }            $_smarty_results = ob_get_contents();            ob_end_clean();            foreach ((array)$this->_plugins['outputfilter'] as $_output_filter) {                $_smarty_results = call_user_func_array($_output_filter[0], array($_smarty_results, &$this));            }        }        if ($this->caching) {            $_params = array('tpl_file' => $resource_name,                        'cache_id' => $cache_id,                        'compile_id' => $compile_id,                        'results' => $_smarty_results);            require_once(SMARTY_CORE_DIR . 'core.write_cache_file.php');            smarty_core_write_cache_file($_params, $this);            require_once(SMARTY_CORE_DIR . 'core.process_cached_inserts.php');            $_smarty_results = smarty_core_process_cached_inserts($_params, $this);            if ($this->_cache_serials) {                // strip nocache-tags from output                $_smarty_results = preg_replace('!(\{/?nocache\:[0-9a-f]{32}#\d+\})!s'                                                ,''                                                ,$_smarty_results);            }            // restore initial cache_info            $this->_cache_info = array_pop($_cache_info);        }        $this->_cache_including = $_cache_including;        if ($display) {            if (isset($_smarty_results)) { echo $_smarty_results; }            if ($this->debugging) {                // capture time for debugging info                $_params = array();                require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');                $this->_smarty_debug_info[$_included_tpls_idx]['exec_time'] = (smarty_core_get_microtime($_params, $this) - $_debug_start_time);                require_once(SMARTY_CORE_DIR . 'core.display_debug_console.php');                echo smarty_core_display_debug_console($_params, $this);            }            error_reporting($_smarty_old_error_level);            return;        } else {            error_reporting($_smarty_old_error_level);            if (isset($_smarty_results)) { return $_smarty_results; }        }    }    /**     * load configuration values     *     * @param string $file     * @param string $section     * @param string $scope     */    function config_load($file, $section = null, $scope = 'global')    {        require_once($this->_get_plugin_filepath('function', 'config_load'));        smarty_function_config_load(array('file' => $file, 'section' => $section, 'scope' => $scope), $this);    }    /**     * return a reference to a registered object     *     * @param string $name     * @return object     */    function &get_registered_object($name) {        if (!isset($this->_reg_objects[$name]))        $this->_trigger_fatal_error("'$name' is not a registered object");        if (!is_object($this->_reg_objects[$name][0]))        $this->_trigger_fatal_error("registered '$name' is not an object");        return $this->_reg_objects[$name][0];    }    /**     * clear configuration values     *     * @param string $var     */    function clear_config($var = null)    {        if(!isset($var)) {            // clear all values            $this->_config = array(array('vars'  => array(),                                         'files' => array()));        } else {            unset($this->_config[0]['vars'][$var]);        }    }    /**     * get filepath of requested plugin     *     * @param string $type     * @param string $name     * @return string|false     */    function _get_plugin_filepath($type, $name)    {        $_params = array('type' => $type, 'name' => $name);        require_once(SMARTY_CORE_DIR . 'core.assemble_plugin_filepath.php');        return smarty_core_assemble_plugin_filepath($_params, $this);    }   /**     * test if resource needs compiling     *     * @param string $resource_name     * @param string $compile_path     * @return boolean     */    function _is_compiled($resource_name, $compile_path)    {        if (!$this->force_compile && file_exists($compile_path)) {            if (!$this->compile_check) {                // no need to check compiled file                return true;            } else {                // get file source and timestamp                $_params = array('resource_name' => $resource_name, 'get_source'=>false);                if (!$this->_fetch_resource_info($_params)) {                    return false;                }                if ($_params['resource_timestamp'] <= filemtime($compile_path)) {                    // template not expired, no recompile                    return true;                } else {                    // compile template                    return false;                }            }        } else {            // compiled template does not exist, or forced compile            return false;        }    }   /**     * compile the template     *     * @param string $resource_name     * @param string $compile_path     * @return boolean     */    function _compile_resource($resource_name, $compile_path)    {        $_params = array('resource_name' => $resource_name);        if (!$this->_fetch_resource_info($_params)) {            return false;        }        $_source_content = $_params['source_content'];        $_cache_include    = substr($compile_path, 0, -4).'.inc';        if ($this->_compile_source($resource_name, $_source_content, $_compiled_content, $_cache_include)) {            // if a _cache_serial was set, we also have to write an include-file:            if ($this->_cache_include_info) {                require_once(SMARTY_CORE_DIR . 'core.write_compiled_include.php');                smarty_core_write_compiled_include(array_merge($this->_cache_include_info, array('compiled_content'=>$_compiled_content, 'resource_name'=>$resource_name)),  $this);            }            $_params = array('compile_path'=>$compile_path, 'compiled_content' => $_compiled_content);            require_once(SMARTY_CORE_DIR . 'core.write_compiled_resource.php');            smarty_core_write_compiled_resource($_params, $this);            return true;        } else {            return false;        }    }   /**     * 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 $this->compiler_class;        $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;    }    /**     * Get the compile path for this resource     *     * @param string $resource_name     * @return string results of {@link _get_auto_filename()}     */    function _get_compile_path($resource_name)    {        return $this->_get_auto_filename($this->compile_dir, $resource_name,                                         $this->_compile_id) . '.php';    }    /**     * fetch the template info. Gets timestamp, and source     * if get_source is true     *     * sets $source_content to the source of the template, and     * $resource_timestamp to its time stamp     * @param string $resource_name     * @param string $source_content     * @param integer $resource_timestamp     * @param boolean $get_source     * @param boolean $quiet     * @return boolean     */    function _fetch_resource_info(&$params)    {        if(!isset($params['get_source'])) { $params['get_source'] = true; }        if(!isset($params['quiet'])) { $params['quiet'] = false; }        $_return = false;        $_params = array('resource_name' => $params['resource_name']) ;        if (isset($params['resource_base_path']))            $_params['resource_base_path'] = $params['resource_base_path'];        else            $_params['resource_base_path'] = $this->template_dir;        if ($this->_parse_resource_name($_params)) {            $_resource_type = $_params['resource_type'];            $_resource_name = $_params['resource_name'];            switch ($_resource_type) {                case 'file':                    if ($params['get_source']) {                        $params['source_content'] = $this->_read_file($_resource_name);                    }                    $params['resource_timestamp'] = filemtime($_resource_name);                    $_return = is_file($_resource_name);                    break;                default:                    // call resource functions to fetch the template source and timestamp                    if ($params['get_source']) {                        $_source_return = isset($this->_plugins['resource'][$_resource_type]) &&                            call_user_func_array($this->_plugins['resource'][$_resource_type][0][0],                                                 array($_resource_name, &$params['source_content'], &$this));                    } else {                        $_source_return = true;                    }                    $_timestamp_return = isset($this->_plugins['resource'][$_resource_type]) &&                        call_user_func_array($this->_plugins['resource'][$_resource_type][0][1],                                             array($_resource_name, &$params['resource_timestamp'], &$this));                    $_return = $_source_return && $_timestamp_return;                    break;            }        }

⌨️ 快捷键说明

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