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

📄 smarty.class.php

📁 Smarty class which may explain many things that you need. This class is very often use to start.
💻 PHP
📖 第 1 页 / 共 5 页
字号:
        if (!$_return) {            // see if we can get a template with the default template handler            if (!empty($this->default_template_handler_func)) {                if (!is_callable($this->default_template_handler_func)) {                    $this->trigger_error("default template handler function \"$this->default_template_handler_func\" doesn't exist.");                } else {                    $_return = call_user_func_array(                        $this->default_template_handler_func,                        array($_params['resource_type'], $_params['resource_name'], &$params['source_content'], &$params['resource_timestamp'], &$this));                }            }        }        if (!$_return) {            if (!$params['quiet']) {                $this->trigger_error('unable to read resource: "' . $params['resource_name'] . '"');            }        } else if ($_return && $this->security) {            require_once(SMARTY_CORE_DIR . 'core.is_secure.php');            if (!smarty_core_is_secure($_params, $this)) {                if (!$params['quiet'])                    $this->trigger_error('(secure mode) accessing "' . $params['resource_name'] . '" is not allowed');                $params['source_content'] = null;                $params['resource_timestamp'] = null;                return false;            }        }        return $_return;    }    /**     * parse out the type and name from the resource     *     * @param string $resource_base_path     * @param string $resource_name     * @param string $resource_type     * @param string $resource_name     * @return boolean     */    function _parse_resource_name(&$params)    {        // split tpl_path by the first colon        $_resource_name_parts = explode(':', $params['resource_name'], 2);        if (count($_resource_name_parts) == 1) {            // no resource type given            $params['resource_type'] = $this->default_resource_type;            $params['resource_name'] = $_resource_name_parts[0];        } else {            if(strlen($_resource_name_parts[0]) == 1) {                // 1 char is not resource type, but part of filepath                $params['resource_type'] = $this->default_resource_type;                $params['resource_name'] = $params['resource_name'];            } else {                $params['resource_type'] = $_resource_name_parts[0];                $params['resource_name'] = $_resource_name_parts[1];            }        }        if ($params['resource_type'] == 'file') {            if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $params['resource_name'])) {                // relative pathname to $params['resource_base_path']                // use the first directory where the file is found                foreach ((array)$params['resource_base_path'] as $_curr_path) {                    $_fullpath = $_curr_path . DIRECTORY_SEPARATOR . $params['resource_name'];                    if (file_exists($_fullpath) && is_file($_fullpath)) {                        $params['resource_name'] = $_fullpath;                        return true;                    }                    // didn't find the file, try include_path                    $_params = array('file_path' => $_fullpath);                    require_once(SMARTY_CORE_DIR . 'core.get_include_path.php');                    if(smarty_core_get_include_path($_params, $this)) {                        $params['resource_name'] = $_params['new_file_path'];                        return true;                    }                }                return false;            } else {                /* absolute path */                return file_exists($params['resource_name']);            }        } elseif (empty($this->_plugins['resource'][$params['resource_type']])) {            $_params = array('type' => $params['resource_type']);            require_once(SMARTY_CORE_DIR . 'core.load_resource_plugin.php');            smarty_core_load_resource_plugin($_params, $this);        }        return true;    }    /**     * Handle modifiers     *     * @param string|null $modifier_name     * @param array|null $map_array     * @return string result of modifiers     */    function _run_mod_handler()    {        $_args = func_get_args();        list($_modifier_name, $_map_array) = array_splice($_args, 0, 2);        list($_func_name, $_tpl_file, $_tpl_line) =            $this->_plugins['modifier'][$_modifier_name];        $_var = $_args[0];        foreach ($_var as $_key => $_val) {            $_args[0] = $_val;            $_var[$_key] = call_user_func_array($_func_name, $_args);        }        return $_var;    }    /**     * Remove starting and ending quotes from the string     *     * @param string $string     * @return string     */    function _dequote($string)    {        if ((substr($string, 0, 1) == "'" || substr($string, 0, 1) == '"') &&            substr($string, -1) == substr($string, 0, 1))            return substr($string, 1, -1);        else            return $string;    }    /**     * read in a file     *     * @param string $filename     * @return string     */    function _read_file($filename)    {        if ( file_exists($filename) && ($fd = @fopen($filename, 'rb')) ) {            $contents = '';            while (!feof($fd)) {                $contents .= fread($fd, 8192);            }            fclose($fd);            return $contents;        } else {            return false;        }    }    /**     * get a concrete filename for automagically created content     *     * @param string $auto_base     * @param string $auto_source     * @param string $auto_id     * @return string     * @staticvar string|null     * @staticvar string|null     */    function _get_auto_filename($auto_base, $auto_source = null, $auto_id = null)    {        $_compile_dir_sep =  $this->use_sub_dirs ? DIRECTORY_SEPARATOR : '^';        $_return = $auto_base . DIRECTORY_SEPARATOR;        if(isset($auto_id)) {            // make auto_id safe for directory names            $auto_id = str_replace('%7C',$_compile_dir_sep,(urlencode($auto_id)));            // split into separate directories            $_return .= $auto_id . $_compile_dir_sep;        }        if(isset($auto_source)) {            // make source name safe for filename            $_filename = urlencode(basename($auto_source));            $_crc32 = sprintf('%08X', crc32($auto_source));            // prepend %% to avoid name conflicts with            // with $params['auto_id'] names            $_crc32 = substr($_crc32, 0, 2) . $_compile_dir_sep .                      substr($_crc32, 0, 3) . $_compile_dir_sep . $_crc32;            $_return .= '%%' . $_crc32 . '%%' . $_filename;        }        return $_return;    }    /**     * unlink a file, possibly using expiration time     *     * @param string $resource     * @param integer $exp_time     */    function _unlink($resource, $exp_time = null)    {        if(isset($exp_time)) {            if(time() - @filemtime($resource) >= $exp_time) {                return @unlink($resource);            }        } else {            return @unlink($resource);        }    }    /**     * returns an auto_id for auto-file-functions     *     * @param string $cache_id     * @param string $compile_id     * @return string|null     */    function _get_auto_id($cache_id=null, $compile_id=null) {    if (isset($cache_id))        return (isset($compile_id)) ? $cache_id . '|' . $compile_id  : $cache_id;    elseif(isset($compile_id))        return $compile_id;    else        return null;    }    /**     * trigger Smarty plugin error     *     * @param string $error_msg     * @param string $tpl_file     * @param integer $tpl_line     * @param string $file     * @param integer $line     * @param integer $error_type     */    function _trigger_fatal_error($error_msg, $tpl_file = null, $tpl_line = null,            $file = null, $line = null, $error_type = E_USER_ERROR)    {        if(isset($file) && isset($line)) {            $info = ' ('.basename($file).", line $line)";        } else {            $info = '';        }        if (isset($tpl_line) && isset($tpl_file)) {            $this->trigger_error('[in ' . $tpl_file . ' line ' . $tpl_line . "]: $error_msg$info", $error_type);        } else {            $this->trigger_error($error_msg . $info, $error_type);        }    }    /**     * callback function for preg_replace, to call a non-cacheable block     * @return string     */    function _process_compiled_include_callback($match) {        $_func = '_smarty_tplfunc_'.$match[2].'_'.$match[3];        ob_start();        $_func($this);        $_ret = ob_get_contents();        ob_end_clean();        return $_ret;    }    /**     * called for included templates     *     * @param string $_smarty_include_tpl_file     * @param string $_smarty_include_vars     */    // $_smarty_include_tpl_file, $_smarty_include_vars    function _smarty_include($params)    {        if ($this->debugging) {            $_params = array();            require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');            $debug_start_time = smarty_core_get_microtime($_params, $this);            $this->_smarty_debug_info[] = array('type'      => 'template',                                                  'filename'  => $params['smarty_include_tpl_file'],                                                  'depth'     => ++$this->_inclusion_depth);            $included_tpls_idx = count($this->_smarty_debug_info) - 1;        }        $this->_tpl_vars = array_merge($this->_tpl_vars, $params['smarty_include_vars']);        // config vars are treated as local, so push a copy of the        // current ones onto the front of the stack        array_unshift($this->_config, $this->_config[0]);        $_smarty_compile_path = $this->_get_compile_path($params['smarty_include_tpl_file']);        if ($this->_is_compiled($params['smarty_include_tpl_file'], $_smarty_compile_path)            || $this->_compile_resource($params['smarty_include_tpl_file'], $_smarty_compile_path))        {            include($_smarty_compile_path);        }        // pop the local vars off the front of the stack        array_shift($this->_config);        $this->_inclusion_depth--;        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;        }        if ($this->caching) {            $this->_cache_info['template'][$params['smarty_include_tpl_file']] = true;        }    }    /**     * get or set an array of cached attributes for function that is     * not cacheable     * @return array     */    function &_smarty_cache_attrs($cache_serial, $count) {        $_cache_attrs =& $this->_cache_info['cache_attrs'][$cache_serial][$count];        if ($this->_cache_including) {            /* return next set of cache_attrs */            $_return = current($_cache_attrs);            next($_cache_attrs);            return $_return;        } else {            /* add a reference to a new set of cache_attrs */            $_cache_attrs[] = array();            return $_cache_attrs[count($_cache_attrs)-1];        }    }    /**     * wrapper for include() retaining $this     * @return mixed     */    function _include($filename, $once=false, $params=null)    {        if ($once) {            return include_once($filename);        } else {            return include($filename);        }    }    /**     * wrapper for eval() retaining $this     * @return mixed     */    function _eval($code, $params=null)    {        return eval($code);    }        /**     * Extracts the filter name from the given callback     *      * @param callback $function     * @return string     */	function _get_filter_name($function)	{		if (is_array($function)) {			$_class_name = (is_object($function[0]) ?				get_class($function[0]) : $function[0]);			return $_class_name . '_' . $function[1];		}		else {			return $function;		}	}        /**#@-*/}/* vim: set expandtab: */?>

⌨️ 快捷键说明

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