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

📄 smarty.class.php

📁 通达OA官方提供的30源代码,感觉很实在
💻 PHP
📖 第 1 页 / 共 5 页
字号:
            echo $_smarty_info_header;
            if ($this->_process_template($_smarty_tpl_file, $compile_path))
            {
                if ($this->show_info_include) {
                    echo "\n<!-- SMARTY_BEGIN: ".$_smarty_tpl_file." -->\n";
                }
                include($compile_path);
                if ($this->show_info_include) {
                    echo "\n<!-- SMARTY_END: ".$_smarty_tpl_file." -->\n";
                }
            }
        } else {
            ob_start();
            echo $_smarty_info_header;
            if ($this->_process_template($_smarty_tpl_file, $compile_path))
            {
                if ($this->show_info_include) {
                    echo "\n<!-- SMARTY_BEGIN: ".$_smarty_tpl_file." -->\n";
                }
                	include($compile_path);
                if ($this->show_info_include) {
                    echo "\n<!-- SMARTY_END: ".$_smarty_tpl_file." -->\n";
                }
            }
            $_smarty_results = ob_get_contents();
            ob_end_clean();
        }
		if ($_smarty_trusted) {
			$this->security = true;
		}

        if ($this->caching) {
            $this->_write_cache_file($_smarty_tpl_file, $_smarty_cache_id, $_smarty_compile_id, $_smarty_results);
            $_smarty_results = $this->_process_cached_inserts($_smarty_results);
        }

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

                    echo $this->_generate_debug_output();
                }
            return;
        } else {
            if (isset($_smarty_results)) { return $_smarty_results; }
        }
    }


/*======================================================================*\
    Function: _assign_smarty_interface
    Purpose:  assign $smarty interface variable
\*======================================================================*/
    function _assign_smarty_interface()
    {
        $egpcs  = array('e'        => 'env',
                        'g'        => 'get',
                        'p'        => 'post',
                        'c'        => 'cookies',
                        's'        => 'server');
        $globals_map = array('get'      => 'HTTP_GET_VARS',
                             'post'     => 'HTTP_POST_VARS',
                             'cookies'  => 'HTTP_COOKIE_VARS',
                             'session'  => 'HTTP_SESSION_VARS',
                             'server'   => 'HTTP_SERVER_VARS',
                             'env'      => 'HTTP_ENV_VARS');

        $smarty  = array('request'  => array());

        foreach ($globals_map as $key => $array) {
            $smarty[$key] = isset($GLOBALS[$array]) ? $GLOBALS[$array] : array();
        }

        foreach (preg_split('!!', strtolower($this->request_vars_order)) as $c) {
            if (isset($egpcs[$c])) {
                $smarty['request'] = array_merge($smarty['request'], $smarty[$egpcs[$c]]);
            }
        }
        $smarty['request'] = @array_merge($smarty['request'], $smarty['session']);

        $this->_smarty_vars = $smarty;
    }


/*======================================================================*\
    Function:   _generate_debug_output()
    Purpose:    generate debug output
\*======================================================================*/

function _generate_debug_output() {
    // we must force compile the debug template in case the environment
    // changed between separate applications.
    ob_start();
    $force_compile_orig = $this->force_compile;
    $this->force_compile = true;
    $compile_path = $this->_get_compile_path($this->debug_tpl);
    if ($this->_process_template($this->debug_tpl, $compile_path))
    {
        if ($this->show_info_include) {
          echo "\n<!-- SMARTY_BEGIN: ".$this->debug_tpl." -->\n";
        }
        include($compile_path);
        if ($this->show_info_include) {
          echo "\n<!-- SMARTY_END: ".$this->debug_tpl." -->\n";
        }
    }
    $results = ob_get_contents();
    $this->force_compile = $force_compile_orig;
    ob_end_clean();
    return $results;
}

/*======================================================================*\
    Function:   _is_trusted()
    Purpose:	determines if a template is within the trusted_dir or not.
\*======================================================================*/
function _is_trusted($resource_type, $resource_name)
{
	$_smarty_trusted = false;
	if (!empty($this->trusted_dir)) {
		// see if template file is within a trusted directory. If so,
		// disable security during the execution of the template.

		if ($resource_type == 'file') {
			if (!empty($this->trusted_dir)) {
				foreach ((array)$this->trusted_dir as $curr_dir) {
					if ( !empty($curr_dir) && is_readable ($curr_dir)) {
                		if (substr(realpath($resource_name),0, strlen(realpath($curr_dir))) == realpath($curr_dir)) {
                    		$_smarty_trusted = true;
                    		break;
						}
					}
                }
			}
		} else {
			// resource is not on local file system
			$_smarty_trusted = false;
		}
	}
	return $_smarty_trusted;
}

/*======================================================================*\
    Function:   _is_secure()
    Purpose:	determins if a template is secure or not.
\*======================================================================*/
	function _is_secure($resource_type, $resource_name) {

	if (!$this->security || $this->security_settings['INCLUDE_ANY']) {
		return true;
	}

	$_smarty_secure = false;
	if ($resource_type == 'file') {
			if (!empty($this->secure_dir)) {
				foreach ((array)$this->secure_dir as $curr_dir) {
					if ( !empty($curr_dir) && is_readable ($curr_dir)) {
                		if (substr(realpath($resource_name),0, strlen(realpath($curr_dir))) == realpath($curr_dir)) {
                    		$_smarty_secure = true;
                    		break;
						}
					}
                }
			}
	} else {
		// resource is not on local file system
		$_smarty_secure = true;
	}

	return $_smarty_secure;
}


/*======================================================================*\
    Function:   _process_template()
    Purpose:
\*======================================================================*/
    function _process_template($tpl_file, $compile_path)
    {
		// test if template needs to be compiled
        if (!$this->force_compile && $this->_compiled_template_exists($compile_path)) {
            if (!$this->compile_check) {
                // no need to check if the template needs recompiled
                return true;
            } else {
                // get template source and timestamp
                if (!$this->_fetch_template_info($tpl_file, $template_source,
                                                 $template_timestamp)) {
                    return false;
                }
                if ($template_timestamp <= $this->_fetch_compiled_template_timestamp($compile_path)) {
                    // template not expired, no recompile
                    return true;
                } else {
                    // compile template
                    $this->_compile_template($tpl_file, $template_source, $template_compiled);
                    $this->_write_compiled_template($compile_path, $template_compiled);
                    return true;
                }
            }
        } else {
            // compiled template does not exist, or forced compile
            if (!$this->_fetch_template_info($tpl_file, $template_source,
                                             $template_timestamp)) {
                return false;
            }
            $this->_compile_template($tpl_file, $template_source, $template_compiled);
            $this->_write_compiled_template($compile_path, $template_compiled);
            return true;
        }
    }

/*======================================================================*\
    Function:   _get_compile_path
    Purpose:    Get the compile path for this template file
\*======================================================================*/
    function _get_compile_path($tpl_file)
    {
        return $this->_get_auto_filename($this->compile_dir, $tpl_file,
                                         $this->_compile_id);
    }


/*======================================================================*\
    Function:   _compiled_template_exists
    Purpose:
\*======================================================================*/
    function _compiled_template_exists($include_path)
    {
        // everything is in $compile_dir
        return file_exists($include_path);
    }

/*======================================================================*\
    Function:   _fetch_compiled_template_timestamp
    Purpose:
\*======================================================================*/
    function _fetch_compiled_template_timestamp($include_path)
    {
        // everything is in $compile_dir
        return filemtime($include_path);
    }

/*======================================================================*\
    Function:   _write_compiled_template
    Purpose:
\*======================================================================*/
    function _write_compiled_template($compile_path, $template_compiled)
    {
        // we save everything into $compile_dir
        $this->_write_file($compile_path, $template_compiled, true);
        return true;
    }

/*======================================================================*\
    Function:   _parse_file_path
    Purpose:	parse out the type and name from the template resource
\*======================================================================*/
	function _parse_file_path($file_base_path, $file_path, &$resource_type, &$resource_name) {

        // split tpl_path by the first colon
        $file_path_parts = explode(':', $file_path, 2);

        if (count($file_path_parts) == 1) {
            // no resource type, treat as type "file"
            $resource_type = 'file';
            $resource_name = $file_path_parts[0];
        } else {
            $resource_type = $file_path_parts[0];
            $resource_name = $file_path_parts[1];
        }

		if ($resource_type == 'file') {
        	if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/", $resource_name)) {
            	// relative pathname to $file_base_path
				// use the first directory where the file is found
				foreach((array)$file_base_path as $curr_path) {
					if(@is_file($curr_path.'/'.$resource_name)) {
            			$resource_name = $curr_path.'/'.$resource_name;
						return true;
					}
				}
				// didn't find the file
				return false;
        	}
		}

		// resource type != file
		return true;
	}


/*======================================================================*\
    Function:   _fetch_template_info()
    Purpose:    fetch the template info. Gets timestamp, and source
                if get_source is true
\*======================================================================*/
    function _fetch_template_info($tpl_path, &$template_source, &$template_timestamp, $get_source=true)
    {
        $_return = false;
		if($this->_parse_file_path($this->template_dir, $tpl_path, $resource_type, $resource_name)) {
        	switch ($resource_type) {
            	case 'file':
                	if (@is_file($resource_name)) {
                    	if ($get_source) {
                        	$template_source = $this->_read_file($resource_name);
                    	}
                    	$template_timestamp = filemtime($resource_name);
						$_return = true;
                	}

⌨️ 快捷键说明

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