Index: trunk/include/config_from_xoops.class.php
===================================================================
--- trunk/include/config_from_xoops.class.php	(revision 128)
+++ trunk/include/config_from_xoops.class.php	(revision 129)
@@ -31,4 +31,7 @@
 	var $xoops_upload_path;
 	var $xoops_upload_url;
+	var $xoops_db_salt;
+	var $is_impress;
+	var $impress_db_config_file;
 	
 	
@@ -46,99 +49,97 @@
 		if(file_exists($this->xoops_mainfile_path)){
 			$array_file = file($this->xoops_mainfile_path);
+			$pattern = '^\s*define\s*\(\s*(\'[^\']+\'|"[^"]+")\s*,\s*(\'[^\']*\'|"[^"]*"|[^\'"])\s*\)\s*;';
+			$impress_include_pattern = '^\s*(include_once|include)\s*\(\s*XOOPS_TRUST_PATH\s*.\s*[\'"]([^\'"]+)[\'"]\s*\)';
 			for ($i = 0 ; $i <count($array_file) ; $i++){
-/* Ref. ImpressCMS
-
-mainfile.php
-	define( 'XOOPS_TRUST_PATH', 'C:/xampp/trust_pathf6fac' );
-
-	include_once(XOOPS_TRUST_PATH . '/3aec9eefada2c57b3705952094b7b070.php');
-
-	define( 'XOOPS_DB_PREFIX', SDATA_DB_PREFIX );
-	define( 'XOOPS_DB_HOST', SDATA_DB_HOST );
-	define( 'XOOPS_DB_USER', SDATA_DB_USER );
-	define( 'XOOPS_DB_PASS', SDATA_DB_PASS );
-	define( 'XOOPS_DB_NAME', SDATA_DB_NAME );
-	define( 'XOOPS_DB_SALT', SDATA_DB_SALT );
-	
-XOOPS_TRUST_PATH . '/3aec9eefada2c57b3705952094b7b070.php'
-	define( 'SDATA_DB_HOST', 'localhost' );
-	define( 'SDATA_DB_USER', 'root' );
-	define( 'SDATA_DB_PASS', '' );
-	define( 'SDATA_DB_NAME', 'impress' );
-	define( 'SDATA_DB_PREFIX', 'id85d03cc' );
-	define( 'SDATA_DB_SALT', '3mhUHMrsTU3CTifQbenOtK1ULG5QN2Dwx8zCfwtynudub4TS9AnmZAhmdQr43Uvot' );
-
-ref. code C:\xampp\htdocs\impress\install\page_configsave.php
-			$sdata_rewrite = array();
-			$sdata_rewrite['DB_HOST'] = $vars['DB_HOST'];
-			$sdata_rewrite['DB_USER'] = $vars['DB_USER'];
-			$sdata_rewrite['DB_PASS'] = $vars['DB_PASS'];
-			$sdata_rewrite['DB_NAME'] = $vars['DB_NAME'];
-			$sdata_rewrite['DB_PREFIX'] = $vars['DB_PREFIX'];
-			$sdata_rewrite['DB_SALT'] = $vars['DB_SALT'];
-
-
-			foreach( $sdata_rewrite as $key => $val ) {
-				if( preg_match( "/(define\()([\"'])(SDATA_$key)\\2,\s*([\"'])(.*?)\\4\s*\)/", $content ) ) {
-					$val = addslashes( $val );
-					$content = preg_replace( "/(define\()([\"'])(SDATA_$key)\\2,\s*([\"'])(.*?)\\4\s*\)/",
-						"define( 'SDATA_$key', '$val' )", $content );
-				} else {
-					//$this->error = true;
-					//$this->report .= _NGIMG.sprintf( ERR_WRITING_CONSTANT, "<b>$val</b>")."<br />\n";
-				}
-			}
-*/
-				
-				$array_file[$i] = trim($array_file[$i]);
-				$array_file[$i] = str_replace(' ','',$array_file[$i]);
-				
-				$array_file[$i] = preg_replace('/\s\s+/', '', $array_file[$i]);
-				$array_file[$i] = preg_replace('/^include.*/','',$array_file[$i]);
-				$array_file[$i] = preg_replace('/^\/\/.*/','',$array_file[$i]);
-				$array_file[$i] = preg_replace('/^if.*/','',$array_file[$i]);
-				if (strstr($array_file[$i],'define')!== false){
-					$array_file[$i] = preg_replace('/\"/', '', $array_file[$i]);
-					$array_file[$i] = preg_replace('/\(/', '', $array_file[$i]);					
-					$array_file[$i] = preg_replace('/\)/', '', $array_file[$i]);
-					$array_file[$i] = preg_replace('/\;/', '', $array_file[$i]);
-					$array_file[$i] = preg_replace('/\'/', '', $array_file[$i]);
-					$array_file[$i] = preg_replace('/define/', '', $array_file[$i]);
-					$define = explode(',',$array_file[$i] );
-					$define[0] = trim($define[0]);
-					$define[1] = trim($define[1]);
-					switch ($define[0]){
+				if (preg_match('/' . $pattern . '/' ,$array_file[$i],$matchs)){
+					$keys = $matchs[1];
+					if (preg_match('/^\'[^\']*\'$/',$keys)) $keys = preg_replace('/\'/', '', $keys);
+					if (preg_match('/^"[^"]*"$/',$keys)) $keys = preg_replace('/"/', '', $keys);
+					$key_value = $matchs[2];
+					if (preg_match('/^\'[^\']*\'$/',$key_value)) $key_value = preg_replace('/\'/', '', $key_value);
+					if (preg_match('/^"[^"]*"$/',$key_value)) $key_value = preg_replace('/"/', '', $key_value);
+					switch ($keys){
 						case  'XOOPS_ROOT_PATH':
-							$this->xoops_root_path = $define[1];
+							$this->xoops_root_path = $key_value;
 							$this->xoops_url . '/modules/' . $this->module_name;
 							break;
 						case  'XOOPS_URL':
-							$this->xoops_url = $define[1];
+							$this->xoops_url = $key_value;
 							$this->module_url = $this->xoops_url . '/modules/' . $this->module_name;
 							break;
 						case  'XOOPS_TRUST_PATH':
-							$this->xoops_trust_path = $define[1];
+							$this->xoops_trust_path = $key_value;
 							break;
 						case  'XOOPS_DB_PREFIX':
-							$this->xoops_db_prefix = $define[1];
+							$this->xoops_db_prefix = $key_value;
 							break;
 						case  'XOOPS_DB_NAME':
-							$this->xoops_db_name = $define[1];
+							$this->xoops_db_name = $key_value;
 							break;
 						case  'XOOPS_DB_USER':
-							$this->xoops_db_user = $define[1];
+							$this->xoops_db_user = $key_value;
 							break;
 						case  'XOOPS_DB_PASS':
-							$this->xoops_db_pass = $define[1];
+							$this->xoops_db_pass = $key_value;
 							break;
 						case  'XOOPS_DB_HOST':
-							$this->xoops_db_host = $define[1];
+							$this->xoops_db_host = $key_value;
+							break;
+						case  'XOOPS_DB_SALT':
+							$this->xoops_db_salt = $key_value;
 							break;
 						default :
+							
+					}	// end of switch
+				}	 // end of if preg_match
+				
+				// Check ImpressCMS
+				if (preg_match('/' . $impress_include_pattern . '/' ,$array_file[$i],$impres_matchs)){
+					$this->is_impress = true;
+					$this->impress_db_config_file = $this->xoops_trust_path . $impres_matchs[2];
+				}
+			} // end of for loop
+		} // end of if file_exists
+		
+		// DB Config from Impress CMS impress_db_config file
+		if ($this->is_impress){
+			if(file_exists($this->impress_db_config_file)){
+				$array_file = file($this->impress_db_config_file);
+				$pattern = '^\s*define\s*\(\s*(\'[^\']+\'|"[^"]+")\s*,\s*(\'[^\']*\'|"[^"]*"|[^\'"])\s*\)\s*;';
+				for ($i = 0 ; $i <count($array_file) ; $i++){
+					if (preg_match('/' . $pattern . '/' ,$array_file[$i],$matchs)){
+						$keys = $matchs[1];
+						if (preg_match('/^\'[^\']*\'$/',$keys)) $keys = preg_replace('/\'/', '', $keys);
+						if (preg_match('/^"[^"]*"$/',$keys)) $keys = preg_replace('/"/', '', $keys);
+						$key_value = $matchs[2];
+						if (preg_match('/^\'[^\']*\'$/',$key_value)) $key_value = preg_replace('/\'/', '', $key_value);
+						if (preg_match('/^"[^"]*"$/',$key_value)) $key_value = preg_replace('/"/', '', $key_value);
+						switch ($keys){
+							case  'SDATA_DB_SALT':
+								$this->xoops_db_salt = $key_value;
+								break;
+							case  'SDATA_DB_PREFIX':
+								$this->xoops_db_prefix = $key_value;
+								break;
+							case  'SDATA_DB_NAME':
+								$this->xoops_db_name = $key_value;
+								break;
+							case  'SDATA_DB_USER':
+								$this->xoops_db_user = $key_value;
+								break;
+							case  'SDATA_DB_PASS':
+								$this->xoops_db_pass = $key_value;
+								break;
+							case  'SDATA_DB_HOST':
+								$this->xoops_db_host = $key_value;
+								break;
+							default :
+								
+						}	// end of switch
 					}
-				}
+				} // end of for
 			}
 		}
-		
+			
 		//  define from /settings/definition.inc.php (XCL)  or /include/common.php(2016a-JP)
 		$this->xoops_upload_path = $this->xoops_root_path .'/uploads';
@@ -163,6 +164,6 @@
 		if(file_exists($xoops_version_file)){
 			$version_file = file($xoops_version_file);
-			$version_pattern = '(\$modversion\[\s*\'version\'\s*\])\s*=\s*[\'"]([^\'"]*)[\'"]';
-			$codename_pattern = '(\$modversion\[\s*\'codename\'\s*\])\s*=\s*[\'"]([^\'"]*)[\'"]';
+			$version_pattern = '^\s*(\$modversion\[\s*\'version\'\s*\])\s*=\s*[\'"]([^\'"]*)[\'"]';
+			$codename_pattern = '^\s*(\$modversion\[\s*\'codename\'\s*\])\s*=\s*[\'"]([^\'"]*)[\'"]';
 			$version_found = false;
 			$codename_found = false;
