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

Back to archive index

Minahito minah****@users*****
2006年 7月 19日 (水) 19:18:27 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.47 xoops2jp/html/modules/base/kernel/Legacy_Controller.class.php:1.1.2.48
--- xoops2jp/html/modules/base/kernel/Legacy_Controller.class.php:1.1.2.47	Tue Jul 11 19:06:48 2006
+++ xoops2jp/html/modules/base/kernel/Legacy_Controller.class.php	Wed Jul 19 19:18:27 2006
@@ -1,9 +1,12 @@
 <?php
+/**
+ * @package legacy
+ */
 
 if (!defined('XOOPS_ROOT_PATH')) exit();
 
-define("LEGACY_CONTROLLER_STATE_PUBLIC",1);
-define("LEGACY_CONTROLLER_STATE_ADMIN",2);
+define("LEGACY_CONTROLLER_STATE_PUBLIC", 1);
+define("LEGACY_CONTROLLER_STATE_ADMIN", 2);
 
 /**
  * This class is a virtual controller that has the compatibility with XOOPS 2.0.x.
@@ -21,10 +24,10 @@
 {
 	var $mXoopsUser;
 
-	var $_mAdminModeFlag=false;
-	var $_mControllerState=null;
+	var $_mAdminModeFlag = false;
+	var $_mControllerState = null;
 	
-	var $mDialogMode=false;
+	var $mDialogMode = false;
 	
 	/**
 	 * @todo Rename this with "mModule"
@@ -46,6 +49,16 @@
 	 */
 	var $mGetPMInboxUrl = null;
 	
+	/**
+	 * @var XCube_NewDelegate
+	 */
+	var $mCheckLogin = null;
+	
+	/**
+	 * @var XCube_NewDelegate
+	 */
+	var $mLogout = null;
+	
 	function Legacy_Controller()
 	{
 		//
@@ -56,6 +69,12 @@
 		
 		$this->mGetCountUnreadPM =& new XCube_NewDelegate();
 		$this->mGetPMInboxUrl =& new XCube_NewDelegate();
+		
+		$this->mCheckLogin =& new XCube_NewDelegate();
+		$this->mCheckLogin->register("Site.CheckLogin");
+		
+		$this->mLogout =& new XCube_NewDelegate();
+		$this->mLogout->register("Site.Logout");
 				
 		set_magic_quotes_runtime(0);	// ^^;
 		
@@ -372,22 +391,33 @@
 		$GLOBALS['xoopsDB']=&$this->mDB;
 	}
 	
+	/**
+	 * Create a instance of Legacy_LanguageManager by the specified language,
+	 * and set it to member properties.
+	 * 
+	 * [Notice]
+	 * Now, this member function sets a string to the member property without
+	 * language manager.
+	 */
 	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'));
+            $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');
+                $this->mLanguage = $configs[0]->getVar('conf_value', 'none');
             }
         }
+		
+		//
+		// Load the additional file to control DB.
 	    if ($this->mLanguage) {
-	        $fname = XOOPS_MODULE_PATH .'/base/language/' .$this->mLanguage .'/charset_'.XOOPS_DB_TYPE.'.php';
-	        if (file_exists($fname)) {
-	            require_once($fname);
+	        $filename = XOOPS_MODULE_PATH . '/base/language/' . $this->mLanguage . '/charset_' . XOOPS_DB_TYPE . '.php';
+	        if (file_exists($filename)) {
+	            require_once($filename);
 	        }
 	    }
     }
@@ -668,9 +698,6 @@
 		$manager->setAnchorDelegate("Legacypage.Backend.Access", new XCube_Delegate("Legacy_EventFunction", "AccessToBackend"));
 		$manager->setAnchorDelegate("Legacypage.Search.Access", new XCube_Delegate("Legacy_EventFunction", "AccessToSearch"));
 
-		$manager->setAnchorDelegate("Site.CheckLogin", new XCube_InstanceDelegate($this, "eventCheckLogin"));
-		$manager->setAnchorDelegate("Site.Logout", new XCube_InstanceDelegate($this, "eventLogout"));
-
 		return $manager;
 	}
 	
@@ -685,39 +712,81 @@
 
 		return $manager;
 	}
-
-	function eventCheckLogin(&$sender,&$eventArgs)
+	
+	/**
+	 * Check the login request through delegates, and set XoopsObject to member
+	 * property if the login is success.
+	 * 
+	 * @access public
+	 */
+	function checkLogin()
 	{
-		if($eventArgs->isSuccess()) {
-			// RMV-NOTIFY
-			// Perform some maintenance of notification records
-			// $notification_handler =& xoops_gethandler('notification');
-			// $notification_handler->doLoginMaintenance($user->getVar('uid'));
-
-			$successEventArgs=array();
-			$successEventArgs['user']=&$eventArgs->getUser();
-			$successEventArgs['xoopsUser']=&$eventArgs->getXoopsUser();
-
-			$this->mRoot->mEventManager->raiseEvent("Site.CheckLogin.Success",$this,$successEventArgs);
-
-			$xoopsUser=&$eventArgs->getXoopsUser();
-			if($xoopsUser!=null) {
-				$message=sprintf(_US_LOGGINGU,$xoopsUser->getVar('uname'));
+		if (!is_object($this->mXoopsUser)) {
+			$this->mCheckLogin->call(new XCube_Ref($this->mXoopsUser));
+
+			if(is_object($this->mXoopsUser)) {
+				// RMV-NOTIFY
+				// Perform some maintenance of notification records
+				// $notification_handler =& xoops_gethandler('notification');
+				// $notification_handler->doLoginMaintenance($user->getVar('uid'));
+
+				XCube_DelegateUtils::call("Site.CheckLogin.Success", new XCube_Ref($this->mXoopsUser));
+
+				//
+				// Fall back process for login success.
+				//
+				$url = XOOPS_URL;
+				if (!empty($_POST['xoops_redirect']) && !strpos(xoops_getrequest('xoops_redirect'), 'register')) {
+					$parsed = parse_url(XOOPS_URL);
+					$url = isset($parsed['scheme']) ? $parsed['scheme'].'://' : 'http://';
+					
+					if (isset($parsed['host'])) {
+						$url .= isset($parsed['port']) ? $parsed['host'] . ':' . $parsed['port'] . trim(xoops_getrequest('xoops_redirect')): $parsed['host'] . trim(xoops_getrequest('xoops_redirect'));
+					} else {
+						$url .= xoops_getenv('HTTP_HOST') . trim(xoops_getrequest('xoops_redirect'));
+					}
+				}
+				
+				$this->mRoot->mLanguageManager->loadModuleLanguage('base');
+
+				$this->executeRedirect($url, 1, XCube_Utils::formatMessage(_MD_BASE_MESSAGE_LOGIN_SUCCESS, $this->mXoopsUser->get('uname')));
+			}
+			else {
+				XCube_DelegateUtils::call("Site.CheckLogin.Fail", new XCube_Ref($this->mXoopsUser));
+				
+				//
+				// Fall back process for login fail.
+				//
+				$this->executeRedirect(XOOPS_ROOT_PATH . "/user.php", 1, _US_INCORRECTLOGIN);
 			}
-			XCube_Utils::redirectHeader($eventArgs->getRedirectUrl(),1,$message);
 		}
 		else {
-			XCube_Utils::redirectHeader($eventArgs->getRedirectUrl(),1,$eventArgs->getRedirectMessage());
+			$this->executeFoward(XOOPS_URL);
 		}
 	}
 	
-	function eventLogout(&$sender,&$eventArgs)
+	/**
+	 * The current user logout.
+	 * 
+	 * @access public
+	 */
+	function logout()
 	{
-		if($eventArgs['successFlag']) {
-			//
-			// TODO : We depends on a message catalog of user module, yet.
-			//
-			XCube_Utils::redirectHeader(XOOPS_URL,1,_US_LOGGEDOUT.'<br />'._US_THANKYOUFORVISIT);
+		$successFlag = false;
+		$xoopsUser =& $this->getXoopsUser();
+		
+		if (is_object($xoopsUser)) {
+			$this->mLogout->call(new XCube_Ref($successFlag), $xoopsUser);
+			if ($successFlag) {
+				XCube_DelegateUtils::call("Site.Logout.Success");
+				$this->executeRedirect(XOOPS_URL, 1, array(_US_LOGGEDOUT, _US_THANKYOUFORVISIT));
+			}
+			else {
+				XCube_DelegateUtils::call("Site.Logout.Fail");
+			}
+		}
+		else {
+			$this->executeForward(XOOPS_URL);
 		}
 	}
 
@@ -837,8 +906,8 @@
 		
 		$displayMessage = "";
 		if (is_array($message)) {
-			foreach (array_keys($message) as $id) {
-				$message[$id] = htmlspecialchars($message, ENT_QUOTES);
+			foreach (array_keys($message) as $key) {
+				$message[$key] = htmlspecialchars($message[$key], ENT_QUOTES);
 			}
 			$displayMessage = implode("<br/>", $message);
 		}


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