[xoops-cvslog 3636] CVS update: xoops2jp/html/modules/base/kernel

Back to archive index

Minahito minah****@users*****
2006年 7月 20日 (木) 17:11:48 JST


Index: xoops2jp/html/modules/base/kernel/Legacy_Controller.class.php
diff -u xoops2jp/html/modules/base/kernel/Legacy_Controller.class.php:1.1.2.50 xoops2jp/html/modules/base/kernel/Legacy_Controller.class.php:1.1.2.51
--- xoops2jp/html/modules/base/kernel/Legacy_Controller.class.php:1.1.2.50	Thu Jul 20 01:43:58 2006
+++ xoops2jp/html/modules/base/kernel/Legacy_Controller.class.php	Thu Jul 20 17:11:48 2006
@@ -59,6 +59,11 @@
 	 */
 	var $mLogout = null;
 	
+	/**
+	 * @var XCube_NewDelegate
+	 */
+	var $mCreateLanguageManager = null;
+	
 	function Legacy_Controller()
 	{
 		//
@@ -75,6 +80,9 @@
 		
 		$this->mLogout =& new XCube_NewDelegate();
 		$this->mLogout->register("Site.Logout");
+		
+		$this->mCreateLanguageManager =& new XCube_NewDelegate();
+		$this->mCreateLanguageManager->register("Legacy_Controller.CreateLanguageManager");
 				
 		set_magic_quotes_runtime(0);	// ^^;
 		
@@ -127,8 +135,8 @@
 
 		$this->_processPreBlockFilter();	// What's !?
 
-		$languageManager =& $this->_createLanguageManager();
-		$this->mRoot->setLanguageManager($languageManager);
+		// $languageManager =& $this->_createLanguageManager();
+		// $this->mRoot->setLanguageManager($languageManager);
 
 		$this->_processHostAbstractLayer();
 
@@ -401,27 +409,88 @@
 	 */
 	function _setupLanguage()
 	{
-	    if (!$this->mLanguage) {
-            $configHandler =& xoops_gethandler('config');
-            $criteria =& new CriteriaCompo(new Criteria('conf_modid', 0));
-            $criteria->add(new Criteria('conf_catid', XOOPS_CONF));
-            $criteria->add(new Criteria('conf_name', 'language'));
-            $configs =& $configHandler->getConfigs($criteria);
-            if (count($configs)) {
-                $this->mLanguage = $configs[0]->getVar('conf_value', 'none');
-            }
+		require_once XOOPS_BASE_PATH."/kernel/Legacy_LanguageManager.class.php";
+		
+		$language = "english";
+		
+		$handler =& xoops_gethandler('config');
+		$criteria =& new CriteriaCompo(new Criteria('conf_modid', 0));
+		$criteria->add(new Criteria('conf_catid', XOOPS_CONF));
+		$criteria->add(new Criteria('conf_name', 'language'));
+		$configs =& $handler->getConfigs($criteria);
+		
+		if (count($configs) > 0) {
+			$language = $configs[0]->get('conf_value', 'none');
         }
 		
-		//
-		// Load the additional file to control DB.
-	    if ($this->mLanguage) {
-	        $filename = XOOPS_MODULE_PATH . '/base/language/' . $this->mLanguage . '/charset_' . XOOPS_DB_TYPE . '.php';
-	        if (file_exists($filename)) {
-	            require_once($filename);
-	        }
-	    }
+		$this->mRoot->mLanguageManager =& $this->_createLanguageManager($language);
+		$this->mRoot->mLanguageManager->setLanguage($language);
+		$this->mRoot->mLanguageManager->prepare();
+
+		$this->mRoot->mLanguageManager->loadGlobalMessageCatalog();
+		
+		// If you use special page, load message catalog for it.
+		if (isset($xoopsOption['pagetype'])) {
+			$this->mRoot->mLanguageManager->loadPageTypeMessageCatalog($xoopsOption['pagetype']);
+		}
     }
-	
+
+	/**
+	 * Factory for the language manager. At first, this member function
+	 * delegates to get a instance of LanguageManager. If it can't get it, do
+	 * the following process: 
+	 * 
+	 * 1) Try creating a instance of 'Legacy_LanguageManager_' . ucfirst($language)
+	 * 2) If the class doesn't exist, try loading  'LanguageManager.class.php' 
+	 *    in the specified language.
+	 * 3) Re-try creating the instance.
+	 * 
+	 * If it can't create any instances, create a instance of
+	 * Legacy_LanguageManager as default.
+	 * 
+	 * @access protected
+	 * @param string $language 
+	 * @return Legacy_LanguageManager
+	 */	
+	function &_createLanguageManager($language)
+	{
+		require_once XOOPS_BASE_PATH . "/kernel/Legacy_LanguageManager.class.php";
+
+		$languageManager = null;
+		
+		$this->mCreateLanguageManager->call(new XCube_Ref($languageManager), $language);
+		
+		if (!is_object($languageManager)) {
+			$className = "Legacy_LanguageManager_" . ucfirst(strtolower($language));
+			
+			//
+			// If the class exists, create a instance. Else, load the file, and
+			// try creating a instance again.
+			//
+			if (class_exists($className)) {
+				$languageManager =& new $className();
+			}
+			else {
+				$filePath = XOOPS_ROOT_PATH . "/language/" . $language . "/LanguageManager.class.php";
+				if (file_exists($filePath)) {
+					require_once $filePath;
+				}
+				
+				if (class_exists($className)) {
+					$languageManager =& new $className();
+				}
+				else {
+					//
+					// Default
+					//
+					$languageManager =& new Legacy_LanguageManager();
+				}
+			}
+		}
+		
+		return $languageManager;
+	}
+
 	function _setupConfig()
 	{
 		$configHandler=&xoops_gethandler('config');
@@ -504,22 +573,6 @@
 		session_start();
 	}
 
-	function &_createLanguageManager()
-	{
-		global $xoopsOption;
-
-		require_once XOOPS_BASE_PATH."/kernel/Legacy_LanguageManager.class.php";
-		
-		$languageManager =& new Legacy_LanguageManager($this->mConfig['language']);
-		$languageManager->loadMainLanguage();
-		
-		// If you use special page, load message catalog for it.
-		if (isset($xoopsOption['pagetype']))
-			$languageManager->loadSpecialTypeLanguage($xoopsOption['pagetype']);
-
-		return $languageManager;
-	}
-
 	/**
 	 * @deprecated
 	 */	
@@ -747,7 +800,7 @@
 					}
 				}
 				
-				$this->mRoot->mLanguageManager->loadModuleLanguage('base');
+				$this->mRoot->mLanguageManager->loadModuleMessageCatalog('base');
 
 				$this->executeRedirect($url, 1, XCube_Utils::formatMessage(_MD_BASE_MESSAGE_LOGIN_SUCCESS, $this->mXoopsUser->get('uname')));
 			}


xoops-cvslog メーリングリストの案内
Back to archive index