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

📄 smarty.class.php

📁 极限网络智能办公系统—MYOA26—100%—源程序。
💻 PHP
📖 第 1 页 / 共 3 页
字号:
				"vars" => array( ),
				"files" => array( )
			)
		);
		if ( $this->show_info_header )
		{
			$_smarty_info_header = "<!-- Smarty ".$this->_version." ".strftime( "%Y-%m-%d %H:%M:%S %Z" )." -->"."\n\n";
		}
		else
		{
			$_smarty_info_header = "";
		}
		$compile_path = $this->_get_compile_path( $_smarty_tpl_file );
		$_smarty_trusted = false;
		if ( $this->security )
		{
			$this->_parse_file_path( $this->template_dir, $_smarty_tpl_file, $resource_type, $resource_name );
			if ( $this->_is_trusted( $resource_type, $resource_name ) )
			{
				$_smarty_trusted = true;
				$this->security = false;
			}
		}
		if ( $_smarty_display && !$this->caching )
		{
			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 )
			{
				$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( )
	{
		$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( $array ) ? $$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( )
	{
		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( $resource_type, $resource_name )
	{
		$_smarty_trusted = false;
		if ( !empty( $this->trusted_dir ) )
		{
			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 ) ) && !( substr( realpath( $resource_name ), 0, strlen( realpath( $curr_dir ) ) ) == realpath( $curr_dir ) ) )
						{
							$_smarty_trusted = true;
							break;
						}
					}
				}
			}
			else
			{
				$_smarty_trusted = false;
			}
		}
		return $_smarty_trusted;
	}

	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 ) ) && !( substr( realpath( $resource_name ), 0, strlen( realpath( $curr_dir ) ) ) == realpath( $curr_dir ) ) )
					{
						$_smarty_secure = true;
						break;
					}
				}
			}
		}
		else
		{
			$_smarty_secure = true;
		}
		return $_smarty_secure;
	}

	function _process_template( $tpl_file, $compile_path )
	{
		if ( !$this->force_compile && $this->_compiled_template_exists( $compile_path ) )
		{
			if ( !$this->compile_check )
			{
				return true;
			}
			else if ( !$this->_fetch_template_info( $tpl_file, $template_source, $template_timestamp ) )
			{
				return false;
			}
			else if ( $template_timestamp <= $this->_fetch_compiled_template_timestamp( $compile_path ) )
			{
				return true;
			}
			else
			{
				$this->_compile_template( $tpl_file, $template_source, $template_compiled );
				$this->_write_compiled_template( $compile_path, $template_compiled );
				return true;
			}
		}
		else if ( !$this->_fetch_template_info( $tpl_file, $template_source, $template_timestamp ) )
		{
			return false;
		}
		else
		{
			$this->_compile_template( $tpl_file, $template_source, $template_compiled );
			$this->_write_compiled_template( $compile_path, $template_compiled );
			return true;
		}
	}

	function _get_compile_path( $tpl_file )
	{
		return $this->_get_auto_filename( $this->compile_dir, $tpl_file, $this->_compile_id );
	}

	function _compiled_template_exists( $include_path )
	{
		return file_exists( $include_path );
	}

	function _fetch_compiled_template_timestamp( $include_path )
	{
		return filemtime( $include_path );
	}

	function _write_compiled_template( $compile_path, $template_compiled )
	{
		$this->_write_file( $compile_path, $template_compiled, true );
		return true;
	}

	function _parse_file_path( $file_base_path, $file_path, &$resource_type, &$resource_name )
	{
		$file_path_parts = explode( ":", $file_path, 2 );
		if ( count( $file_path_parts ) == 1 )
		{
			$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" && !preg_match( "/^([\\/\\\\]|[a-zA-Z]:[\\/\\\\])/", $resource_name ) )
		{
			foreach ( ( array )$file_base_path as $curr_path )
			{
				if ( @is_file( $curr_path."/".$resource_name ) )
				{
					$resource_name = $curr_path."/".$resource_name;
					return true;
				}
			}
			return false;
		}
		return 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 ) )
				{
					break;
				}
				if ( $get_source )
				{
					$template_source = $this->_read_file( $resource_name );
				}
				$template_timestamp = filemtime( $resource_name );
				$_return = true;
				break;
			default :
				if ( !isset( $this->resource_funcs[$resource_type] ) )
				{
					break;
				}
				$funcname = $this->resource_funcs[$resource_type];
				if ( !function_exists( $funcname ) )
				{
					break;
				}
				$_return = $funcname( $resource_name, $template_source, $template_timestamp, $get_source, $this );
				break;
			}
		}
		if ( !$_return && !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}\"" );
		}
		else
		{
			if ( $_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( $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( $_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 )
		{
			$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( $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 ( 0 < count( $this->_config ) && !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" )
		{

⌨️ 快捷键说明

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