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

📄 smarty_config.class.php

📁 通达网络办公 - Office Anywhere 2008 增强版100%源码(3.4.081216) 内含 通达OA2008增強版接近完美破解补丁20081216集 及 最新通达OA2008ADV(
💻 PHP
字号:
<?php

require_once( "./smarty/PEAR.php" );
class Config_File extends PEAR
{

	public $overwrite = TRUE;
	public $booleanize = TRUE;
	public $read_hidden = TRUE;
	public $_config_path = "";
	public $_config_data = array( );
	public $_separator = "";

	public function Config_File( $config_path = NULL )
	{
		$this->PEAR( );
		if ( substr( PHP_OS, 1, 3 ) == "WIN" || substr( PHP_OS, 1, 4 ) == "OS/2" )
		{
			$this->_separator = "\\";
		}
		else
		{
			$this->_separator = "/";
		}
		if ( isset( $config_path ) )
		{
			$this->set_path( $config_path );
		}
	}

	public function set_path( $config_path )
	{
		if ( !empty( $config_path ) )
		{
			if ( is_string( $config_path ) )
			{
				if ( file_exists( $config_path ) )
				{
				}
			}
			if ( !is_dir( $config_path ) )
			{
				( "Bad config file path '".$config_path."'" );
				return new Config_File_Error( );
			}
			$this->_config_path = $config_path.$this->_separator;
		}
	}

	public function &get( $file_name, $section_name = NULL, $var_name = NULL )
	{
		if ( empty( $file_name ) )
		{
			( "Empty config file name" );
			return new Config_File_Error( );
		}
		$file_name = $this->_config_path.$file_name;
		if ( !isset( $this->_config_data[$file_name] ) )
		{
			$this->load_file( $file_name, FALSE );
		}
		if ( !empty( $var_name ) )
		{
			if ( empty( $section_name ) )
			{
				return $this->_config_data[$file_name]['vars'][$var_name];
			}
			return $this->_config_data[$file_name]['sections'][$section_name]['vars'][$var_name];
		}
		if ( empty( $section_name ) )
		{
			return ( array )$this->_config_data[$file_name]['vars'];
		}
		return ( array )$this->_config_data[$file_name]['sections'][$section_name]['vars'];
	}

	public function &get_key( $config_key )
	{
		list( $file_name, $section_name, $var_name ) = explode( "/", $config_key, 3 );
		$result =& $this->get( $file_name, $section_name, $var_name );
		return $result;
	}

	public function get_file_names( )
	{
		return array_keys( $this->_config_data );
	}

	public function get_section_names( $file_name )
	{
		$file_name = $this->_config_path.$file_name;
		if ( !isset( $this->_config_data[$file_name] ) )
		{
			( "Unknown config file '".$file_name."'" );
			return new Config_File_Error( );
		}
		return array_keys( $this->_config_data[$file_name]['sections'] );
	}

	public function get_var_names( $file_name, $section = NULL )
	{
		if ( empty( $file_name ) )
		{
			( "Empty config file name" );
			return new Config_File_Error( );
		}
		if ( !isset( $this->_config_data[$file_name] ) )
		{
			( "Unknown config file '".$file_name."'" );
			return new Config_File_Error( );
		}
		if ( empty( $section ) )
		{
			return array_keys( $this->_config_data[$file_name]['vars'] );
		}
		return array_keys( $this->_config_data[$file_name]['sections'][$section]['vars'] );
	}

	public function clear( $file_name = NULL )
	{
		if ( $file_name === NULL )
		{
			$this->_config_data = array( );
		}
		else if ( isset( $this->_config_data[$file_name] ) )
		{
			$this->_config_data[$file_name] = array( );
		}
	}

	public function load_file( $file_name, $prepend_path = TRUE )
	{
		global $php_errormsg;
		if ( $prepend_path && $this->_config_path != "" )
		{
			$config_file = $this->_config_path.$file_name;
		}
		else
		{
			$config_file = $file_name;
		}
		ini_set( "track_errors", TRUE );
		$fp = @fopen( $config_file, "r" );
		if ( !is_resource( $fp ) )
		{
			( $php_errormsg );
			return new Config_File_Error( );
		}
		$contents = fread( $fp, filesize( $config_file ) );
		fclose( $fp );
		$config_data = array( );
		if ( preg_match( "/^(.*?)(\n\\[|\\Z)/s", $contents, $match ) )
		{
			$config_data['vars'] = $this->_parse_config_block( $match[1] );
		}
		$config_data['sections'] = array( );
		preg_match_all( "/^\\[(.*?)\\]/m", $contents, $match );
		foreach ( $match[1] as $section )
		{
			if ( $section[0] == "." && !$this->read_hidden )
			{
			}
			else
			{
				if ( preg_match( "/\\[".preg_quote( $section )."\\](.*?)(\n\\[|\\Z)/s", $contents, $match ) && $section[0] == "." )
				{
					$section = substr( $section, 1 );
				}
				$config_data['sections'][$section]['vars'] = $this->_parse_config_block( $match[1] );
			}
		}
		$this->_config_data[$config_file] = $config_data;
	}

	public function _parse_config_block( $config_block )
	{
		$vars = array( );
		if ( preg_match_all( "/^([^=\n]+)=\\s*\"{3}(.*?)\"{3}\\s*\$/ms", $config_block, $match, PREG_SET_ORDER ) )
		{
			$i = 0;
			for ( ;	$i < count( $match );	++$i	)
			{
				$this->_set_config_var( $vars, trim( $match[$i][1] ), $match[$i][2], FALSE );
			}
			$config_block = preg_replace( "/^[^=\n]+=\\s*\"{3}.*?\"{3}\\s*\$/ms", "", $config_block );
		}
		$config_lines = preg_split( "/\n+/", $config_block );
		foreach ( $config_lines as $line )
		{
			if ( preg_match( "/^\\s*(\\.?\\w+)\\s*=(.*)/", $line, $match ) )
			{
				$var_value = preg_replace( "/^(['\"])(.*)\\1\$/", "\\2", trim( $match[2] ) );
				$this->_set_config_var( $vars, trim( $match[1] ), $var_value, $this->booleanize );
			}
		}
		return $vars;
	}

	public function _set_config_var( &$container, $var_name, $var_value, $booleanize )
	{
		if ( $var_name[0] == "." )
		{
			if ( !$this->read_hidden )
			{
				return;
			}
			$var_name = substr( $var_name, 1 );
		}
		if ( !preg_match( "/^[a-zA-Z_]\\w*\$/", $var_name ) )
		{
			( "Bad variable name '".$var_name."'" );
			return new Config_File_Error( );
		}
		if ( $booleanize )
		{
			if ( preg_match( "/^(on|true|yes)\$/i", $var_value ) )
			{
				$var_value = TRUE;
			}
			else if ( preg_match( "/^(off|false|no)\$/i", $var_value ) )
			{
				$var_value = FALSE;
			}
		}
		if ( !isset( $container[$var_name] ) && $this->overwrite )
		{
			$container[$var_name] = $var_value;
		}
		else
		{
			settype( &$container[$var_name], "array" );
			$container[$var_name][] = $var_value;
		}
	}

}

class Config_File_Error extends PEAR_Error
{

	public $error_message_prefix = "Config_File: ";

	public function Config_File_Error( $message, $code = 0, $mode = PEAR_ERROR_PRINT, $level = E_USER_NOTICE )
	{
		$this->PEAR_Error( $message."\n", $code, $mode, $level );
	}

}

?>

⌨️ 快捷键说明

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