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

📄 smarty.class.php

📁 通达OA官方提供的30源代码,感觉很实在
💻 PHP
📖 第 1 页 / 共 5 页
字号:
                	break;
            	default:
                	if (isset($this->resource_funcs[$resource_type])) {
                    	$funcname = $this->resource_funcs[$resource_type];
                    	if (function_exists($funcname)) {
                        	// call the function to fetch the template
                        	$_return = $funcname($resource_name, $template_source, $template_timestamp, $get_source, $this);
                    	}
                	}
                	break;
        	}
		}

		if(!$_return) {
			// see if we can get a template with the default template handler
			if(!empty($this->default_template_handler_func)) {
				if(!function_exists($this->default_template_handler_func)) {
                    $this->_trigger_error_msg("default template handler function \"$this->default_template_handler_func\" doesn't exist.");
                    $_return = false;
				}
				$funcname = $this->default_template_handler_func;
				$_return = $funcname($resource_type, $resource_name, $template_source, $template_timestamp, $this);
			}
		}

		if(!$_return) {
			$this->_trigger_error_msg("unable to read template resource: \"$tpl_path\"");
		} elseif ($_return && $this->security && !$this->_is_secure($resource_type, $resource_name) && !$this->_is_trusted($resource_type, $resource_name)) {
            $this->_trigger_error_msg("(secure mode) accessing \"$tpl_path\" is not allowed");
			$template_source = null;
			$template_timestamp = null;
			return false;
        }
        return $_return;
    }


/*======================================================================*\
    Function:   _compile_template()
    Purpose:    called to compile the templates
\*======================================================================*/
    function _compile_template($tpl_file, $template_source, &$template_compiled)
    {
        include_once SMARTY_DIR.$this->compiler_class . '.class.php';

        $smarty_compiler = new $this->compiler_class;

        $smarty_compiler->template_dir      = $this->template_dir;
        $smarty_compiler->compile_dir       = $this->compile_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->custom_funcs      = $this->custom_funcs;
        $smarty_compiler->custom_mods       = $this->custom_mods;
        $smarty_compiler->_version          = $this->_version;
        $smarty_compiler->prefilter_funcs   = $this->prefilter_funcs;
        $smarty_compiler->postfilter_funcs  = $this->postfilter_funcs;
        $smarty_compiler->compiler_funcs    = $this->compiler_funcs;
        $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;

        if ($smarty_compiler->_compile_file($tpl_file, $template_source, $template_compiled))
            return true;
        else {
            $this->_trigger_error_msg($smarty_compiler->_error_msg);
            return false;
        }
    }

/*======================================================================*\
    Function:   _smarty_include()
    Purpose:    called for included templates
\*======================================================================*/
    function _smarty_include($_smarty_include_tpl_file, $_smarty_include_vars)
    {
        if ($this->debugging) {
            $debug_start_time = $this->_get_microtime();
            $this->_smarty_debug_info[] = array('type'      => 'template',
                                                'filename'  => $_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, $_smarty_include_vars);
        extract($this->_tpl_vars);

        array_unshift($this->_config, $this->_config[0]);
        $compile_path = $this->_get_compile_path($_smarty_include_tpl_file);

		$this->_parse_file_path($this->template_dir, $_smarty_include_tpl_file, $resource_type, $resource_name);
		if ($this->security && $this->_is_trusted($resource_type, $resource_name)) {
			$_smarty_trusted = true;
			$this->security = false;
		} else {
			$_smarty_trusted = false;
		}

        if ($this->_process_template($_smarty_include_tpl_file, $compile_path)) {
            if ($this->show_info_include) {
                echo "\n<!-- SMARTY_BEGIN: ".$_smarty_include_tpl_file." -->\n";
            }
            include($compile_path);
            if ($this->show_info_include) {
                echo "\n<!-- SMARTY_END: ".$_smarty_include_tpl_file." -->\n";
            }
        }

		if ($_smarty_trusted) {
			$this->security = true;
		}

        array_shift($this->_config);
        $this->_inclusion_depth--;

        if ($this->debugging) {
            // capture time for debugging info
            $this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = $this->_get_microtime() - $debug_start_time;
        }

        if ($this->caching) {
            $this->_cache_info[] = array('template', $_smarty_include_tpl_file);
        }
    }

/*======================================================================*\
    Function: _config_load
    Purpose:  load configuration values
\*======================================================================*/
    function _config_load($file, $section, $scope)
    {

        if ($this->debugging) {
            $debug_start_time = $this->_get_microtime();
        }

        if ($this->caching) {
            $this->_cache_info[] = array('config', $file);
        }

        if (!isset($this->_config[0]['files'][$file])) {
            $this->_config[0]['vars'] = array_merge($this->_config[0]['vars'], $this->_conf_obj->get($file));
            $this->_config[0]['files'][$file] = true;
        }
        if ($scope == 'parent') {
            if (count($this->_config) > 0 && !isset($this->_config[1]['files'][$file])) {
                $this->_config[1]['vars'] = array_merge($this->_config[1]['vars'], $this->_conf_obj->get($file));
                $this->_config[1]['files'][$file] = true;
            }
        } else if ($scope == 'global')
            for ($i = 1; $i < count($this->_config); $i++) {
                if (!isset($this->_config[$i]['files'][$file])) {
                    $this->_config[$i]['vars'] = array_merge($this->_config[$i]['vars'], $this->_conf_obj->get($file));
                    $this->_config[$i]['files'][$file] = true;
                }
            }

        if (!empty($section)) {
            $this->_config[0]['vars'] = array_merge($this->_config[0]['vars'], $this->_conf_obj->get($file, $section));
            if ($scope == 'parent') {
                if (count($this->_config) > 0)
                    $this->_config[1]['vars'] = array_merge($this->_config[1]['vars'], $this->_conf_obj->get($file, $section));
            } else if ($scope == 'global')
                for ($i = 1; $i < count($this->_config); $i++)
                    $this->_config[$i]['vars'] = array_merge($this->_config[$i]['vars'], $this->_conf_obj->get($file, $section));
        }

        if ($this->debugging) {
            $debug_start_time = $this->_get_microtime();
            $this->_smarty_debug_info[] = array('type'      => 'config',
                                                'filename'  => $file.' ['.$section.'] '.$scope,
                                                'depth'     => $this->_inclusion_depth,
                                                'exec_time' => $this->_get_microtime() - $debug_start_time);
        }
    }


/*======================================================================*\
    Function: _process_cached_inserts
    Purpose:  Replace cached inserts with the actual results
\*======================================================================*/
    function _process_cached_inserts($results)
    {

        preg_match_all('!'.$this->_smarty_md5.'{insert_cache (.*)}'.$this->_smarty_md5.'!Uis',
                       $results, $match);
        list($cached_inserts, $insert_args) = $match;

        for ($i = 0; $i < count($cached_inserts); $i++) {
        	if ($this->debugging) {
            	$debug_start_time = $this->_get_microtime();
        	}

            $args = unserialize($insert_args[$i]);

            $name = $args['name'];
            unset($args['name']);

            if (isset($args['script'])) {
                $this->_parse_file_path($this->trusted_dir, $this->_dequote($args['script']), $resource_type, $resource_name);
                if ($this->security) {
                    if( $resource_type != 'file' || !@is_file($resource_name)) {
                        $this->_syntax_error("include_php: $resource_type: $resource_name is not readable");                return false;
                    }
                    if (!$this->_is_trusted($resource_type, $resource_name)) {
                        $this->_syntax_error("include_php: $resource_type: $resource_name is not trusted");
                        return false;
                    }
                }
                include_once($resource_name);
                unset($args['script']);
            }

            $function_name = 'insert_' . $name;
            $replace = $function_name($args, $this);

            $results = str_replace($cached_inserts[$i], $replace, $results);
            if ($this->debugging) {
                $this->_smarty_debug_info[] = array('type'      => 'insert',
                                                    'filename'  => 'insert_'.$name,
                                                    'depth'     => $this->_inclusion_depth,
                                                    'exec_time' => $this->_get_microtime() - $debug_start_time);
            }
        }

        return $results;
    }


/*======================================================================*\
    Function: _run_insert_handler
    Purpose:  Handle insert tags
\*======================================================================*/
function _run_insert_handler($args)
{
    if ($this->debugging) {
        $debug_start_time = $this->_get_microtime();
    }

    if ($this->caching) {
        $arg_string = serialize($args);
        return $this->_smarty_md5."{insert_cache $arg_string}".$this->_smarty_md5;
    } else {
        $function_name = 'insert_'.$args['name'];
        if (isset($args['script'])) {
            $this->_parse_file_path($this->trusted_dir, $this->_dequote($args['script']), $resource_type, $resource_name);
            if ($this->security) {
                if( $resource_type != 'file' || !@is_file($resource_name)) {
                    $this->_syntax_error("include_php: $resource_type: $resource_name is not readable");                return false;
                }
                if (!$this->_is_trusted($resource_type, $resource_name)) {
                    $this->_syntax_error("include_php: $resource_type: $resource_name is not trusted");
                    return false;
                }
            }
            include_once($resource_name);
        }

        $content = $function_name($args, $this);
        if ($this->debugging) {
            $this->_smarty_debug_info[] = array('type'      => 'insert',
                                                'filename'  => 'insert_'.$args['name'],
                                                'depth'     => $this->_inclusion_depth,
                                                'exec_time' => $this->_get_microtime() - $debug_start_time);
        }
        if (!empty($args["assign"])) {
            $this->assign($args["assign"],$content);
        } else {
            return $content;
        }
    }
}


/*======================================================================*\
    Function: _run_mod_handler
    Purpose:  Handle modifiers
\*======================================================================*/
    function _run_mod_handler()
    {
        $args = func_get_args();
        list($func_name, $map_array) = array_splice($args, 0, 2);
        $var = $args[0];

        if ($map_array && is_array($var)) {
            foreach ($var as $key => $val) {
                $args[0] = $val;
                $var[$key] = $this->my_call_user_func_array($func_name, $args);
            }
            return $var;
        } else {
            return $this->my_call_user_func_array($func_name, $args);
        }
    }


/*======================================================================*\
    Function: _dequote
    Purpose:  Remove starting and ending quotes from the string
\*======================================================================*/
    function _dequote($string)
    {
        if (($string{0} == "'" || $string{0} == '"') &&
            $string{strlen($string)-1} == $string{0})
            return substr($string, 1, -1);
        else
            return $string;
    }

⌨️ 快捷键说明

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