Index: trunk/xpressme_integration_kit/class/config_from_xoops.class.php
===================================================================
--- trunk/xpressme_integration_kit/class/config_from_xoops.class.php	(revision 252)
+++ trunk/xpressme_integration_kit/class/config_from_xoops.class.php	(revision 326)
@@ -15,4 +15,5 @@
 	var $xoops_mainfile_path;
 	var $define_arry = array();	
+	var $external_define_path;
 	var $xoops_root_path;
 	var $xoops_url;
@@ -56,68 +57,24 @@
     {  
     	$this->xoops_mainfile_path = $this->get_xoops_mainfile_path();
-    	$this->module_path=dirname(dirname(__FILE__));   	
+    	$this->module_path=dirname(dirname(__FILE__));
     	$this->module_name=basename($this->module_path);
-		if(file_exists($this->xoops_mainfile_path)){
-			$array_file = file($this->xoops_mainfile_path);
-			$pattern = '^\s*define\s*\(\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++){
-				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];
-
-					switch ($keys){
-						case  'XOOPS_ROOT_PATH':
-							$this->xoops_root_path = $this->xpress_eval($key_value);
-							$this->xoops_url . '/modules/' . $this->module_name;
-							break;
-						case  'XOOPS_URL':
-							$this->xoops_url = $this->xpress_eval($key_value);
-							$this->module_url = $this->xoops_url . '/modules/' . $this->module_name;
-							break;
-						case  'XOOPS_TRUST_PATH':
-							$this->xoops_trust_path = $this->xpress_eval($key_value);
-							break;
-						case  'XOOPS_DB_PREFIX':
-							$this->xoops_db_prefix = $this->xpress_eval($key_value);
-							break;
-						case  'XOOPS_DB_NAME':
-							$this->xoops_db_name = $this->xpress_eval($key_value);
-							break;
-						case  'XOOPS_DB_USER':
-							$this->xoops_db_user = $this->xpress_eval($key_value);
-							break;
-						case  'XOOPS_DB_PASS':
-							$this->xoops_db_pass = $this->xpress_eval($key_value);
-							break;
-						case  'XOOPS_DB_HOST':
-							$this->xoops_db_host = $this->xpress_eval($key_value);
-							break;
-						case  'XOOPS_DB_SALT':
-							$this->xoops_db_salt = $this->xpress_eval($key_value);
-							break;
-						case  'XOOPS_SALT':
-							$this->xoops_salt = $this->xpress_eval($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*;';
+    	if (defined('XOOPS_MAINFILE_INCLUDED')){
+    		$this->xoops_root_path = XOOPS_ROOT_PATH;
+    		$this->xoops_url = XOOPS_URL;
+    		$this->module_url = $this->xoops_url . '/modules/' . $this->module_name;
+    		if(defined('XOOPS_TRUST_PATH')) $this->xoops_trust_path = XOOPS_TRUST_PATH; else $this->xoops_trust_path = '';
+    		$this->xoops_db_prefix = XOOPS_DB_PREFIX;
+    		$this->xoops_db_name = XOOPS_DB_NAME;
+    		$this->xoops_db_user = XOOPS_DB_USER;
+    		$this->xoops_db_pass = XOOPS_DB_PASS;
+    		$this->xoops_db_host = XOOPS_DB_HOST;
+			if(defined('XOOPS_DB_SALT')) $this->xoops_db_salt = XOOPS_DB_SALT; else $this->xoops_db_salt = '';
+    		if(defined('XOOPS_SALT')) $this->xoops_salt = XOOPS_SALT; else $this->xoops_salt = '';
+    	} else {
+			if(file_exists($this->xoops_mainfile_path)){
+				$array_file = file($this->xoops_mainfile_path);
+				$pattern = '^\s*define\s*\(\s*(\'[^\']+\'|"[^"]+")\s*,\s*([^\s]+.*)\s*\)\s*;';
+				$impress_include_pattern = '^\s*(include_once|include)\s*\(\s*XOOPS_TRUST_PATH\s*.\s*[\'"]([^\'"]+)[\'"]\s*\)';
+				$external_define_file_pattern = '^\s*(include_once|include|require_once|require_once)\s*\((.*mainfile\.php.*)\)';
 				for ($i = 0 ; $i <count($array_file) ; $i++){
 					if (preg_match('/' . $pattern . '/' ,$array_file[$i],$matchs)){
@@ -128,29 +85,114 @@
 
 						switch ($keys){
-							case  'SDATA_DB_SALT':
+							case  'XOOPS_ROOT_PATH':
+								$this->xoops_root_path = $this->xpress_eval($key_value);
+								break;
+							case  'XOOPS_URL':
+								$this->xoops_url = $this->xpress_eval($key_value);
+								$this->module_url = $this->xoops_url . '/modules/' . $this->module_name;
+								break;
+							case  'XOOPS_TRUST_PATH':
+								$this->xoops_trust_path = $this->xpress_eval($key_value);
+								break;
+							case  'XOOPS_DB_PREFIX':
+								$this->xoops_db_prefix = $this->xpress_eval($key_value);
+								break;
+							case  'XOOPS_DB_NAME':
+								$this->xoops_db_name = $this->xpress_eval($key_value);
+								break;
+							case  'XOOPS_DB_USER':
+								$this->xoops_db_user = $this->xpress_eval($key_value);
+								break;
+							case  'XOOPS_DB_PASS':
+								$this->xoops_db_pass = $this->xpress_eval($key_value);
+								break;
+							case  'XOOPS_DB_HOST':
+								$this->xoops_db_host = $this->xpress_eval($key_value);
+								break;
+							case  'XOOPS_DB_SALT':
 								$this->xoops_db_salt = $this->xpress_eval($key_value);
 								break;
-							case  'SDATA_DB_PREFIX':
-								$this->xoops_db_prefix = $this->xpress_eval($key_value);
-								break;
-							case  'SDATA_DB_NAME':
-								$this->xoops_db_name = $this->xpress_eval($key_value);
-								break;
-							case  'SDATA_DB_USER':
-								$this->xoops_db_user = $this->xpress_eval($key_value);
-								break;
-							case  'SDATA_DB_PASS':
-								$this->xoops_db_pass = $this->xpress_eval($key_value);
-								break;
-							case  'SDATA_DB_HOST':
-								$this->xoops_db_host = $this->xpress_eval($key_value);
+							case  'XOOPS_SALT':
+								$this->xoops_salt = $this->xpress_eval($key_value);
 								break;
 							default :
 								
 						}	// end of switch
+					}	 // end of if preg_match
+					
+					// Check External Define File
+					if (preg_match('/' . $external_define_file_pattern . '/' ,$array_file[$i],$trust_main_matchs)){
+						$include_path = $this->xpress_eval($trust_main_matchs[2]);
+						if (file_exists($include_path))
+							$this->external_define_path = $include_path;
 					}
-				} // end of for
+					
+					// 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];
+
+							switch ($keys){
+								case  'SDATA_DB_SALT':
+									$this->xoops_db_salt = $this->xpress_eval($key_value);
+									break;
+								case  'SDATA_DB_PREFIX':
+									$this->xoops_db_prefix = $this->xpress_eval($key_value);
+									break;
+								case  'SDATA_DB_NAME':
+									$this->xoops_db_name = $this->xpress_eval($key_value);
+									break;
+								case  'SDATA_DB_USER':
+									$this->xoops_db_user = $this->xpress_eval($key_value);
+									break;
+								case  'SDATA_DB_PASS':
+									$this->xoops_db_pass = $this->xpress_eval($key_value);
+									break;
+								case  'SDATA_DB_HOST':
+									$this->xoops_db_host = $this->xpress_eval($key_value);
+									break;
+								default :
+									
+							}	// end of switch
+						}
+					} // end of for
+				} // end of if file_exists
+			} // end ofImpress CMS
+			
+			// DB Config from external define file
+			if(!empty($this->external_define_path)){
+				if(file_exists($this->external_define_path)){
+					require_once($this->external_define_path);
+					
+					$this->xoops_root_path = XOOPS_ROOT_PATH;
+		    		$this->xoops_url = XOOPS_URL;
+		    		$this->module_url = $this->xoops_url . '/modules/' . $this->module_name;
+		    		if(defined('XOOPS_TRUST_PATH')) $this->xoops_trust_path = XOOPS_TRUST_PATH; else $this->xoops_trust_path = '';
+		    		$this->xoops_db_prefix = XOOPS_DB_PREFIX;
+		    		$this->xoops_db_name = XOOPS_DB_NAME;
+		    		$this->xoops_db_user = XOOPS_DB_USER;
+		    		$this->xoops_db_pass = XOOPS_DB_PASS;
+		    		$this->xoops_db_host = XOOPS_DB_HOST;
+					if(defined('XOOPS_DB_SALT')) $this->xoops_db_salt = XOOPS_DB_SALT; else $this->xoops_db_salt = '';
+    				if(defined('XOOPS_SALT')) $this->xoops_salt = XOOPS_SALT; else $this->xoops_salt = '';
+				} // end of if file_exists
 			}
 		}
+
 			
 		//  define from /settings/definition.inc.php (XCL)  or /include/common.php(2016a-JP)
