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

Back to archive index

Minahito minah****@users*****
2006年 8月 3日 (木) 18:40: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.59 xoops2jp/html/modules/base/kernel/Legacy_Controller.class.php:1.1.2.60
--- xoops2jp/html/modules/base/kernel/Legacy_Controller.class.php:1.1.2.59	Thu Aug  3 02:01:51 2006
+++ xoops2jp/html/modules/base/kernel/Legacy_Controller.class.php	Thu Aug  3 18:40:27 2006
@@ -1,7 +1,7 @@
 <?php
 /**
  * @package Legacy
- * @version $Id: Legacy_Controller.class.php,v 1.1.2.59 2006/08/02 17:01:51 minahito Exp $
+ * @version $Id: Legacy_Controller.class.php,v 1.1.2.60 2006/08/03 09:40:27 minahito Exp $
  */
 
 if (!defined('XOOPS_ROOT_PATH')) exit();
@@ -9,6 +9,8 @@
 define("LEGACY_CONTROLLER_STATE_PUBLIC", 1);
 define("LEGACY_CONTROLLER_STATE_ADMIN", 2);
 
+require_once XOOPS_ROOT_PATH . "/modules/base/kernel/Legacy_BlockProcedure.class.php";
+
 /**
  * This class is a virtual controller that has the compatibility with XOOPS 2.0.x.
  * 
@@ -26,7 +28,7 @@
 	var $mXoopsUser;
 
 	var $_mAdminModeFlag = false;
-	var $_mControllerState = null;
+	var $_mStrategy = null;
 	
 	var $mDialogMode = false;
 	
@@ -65,6 +67,14 @@
 	 */
 	var $mCreateLanguageManager = null;
 	
+	var $mBlockShowFlags = array();
+	var $mBlockContents = array();
+	
+	/**
+	 * @deprecated
+	 */
+	var $mRenderSystem = null;
+	
 	function Legacy_Controller()
 	{
 		//
@@ -105,7 +115,7 @@
 			$adminStateFlag=true;
 		}
 
-		$this->_mControllerState= $adminStateFlag ?  new BaseControllerAdminState() : new BaseControllerPublicState();
+		$this->_mStrategy = $adminStateFlag ?  new Legacy_AdminControllerStrategy($this) : new Legacy_PublicControllerStrategy($this);
 	}
 
 	/**
@@ -136,9 +146,6 @@
 
 		$this->_processPreBlockFilter();	// What's !?
 
-		// $languageManager =& $this->_createLanguageManager();
-		// $this->mRoot->setLanguageManager($languageManager);
-
 		$this->_processHostAbstractLayer();
 
 		$this->_setupSession();
@@ -147,8 +154,6 @@
 
 		$this->_setupModuleController();
 
-		$this->_setupRenderSystem();
-
 		$this->_processModuleController();
 	}
 	
@@ -224,28 +229,44 @@
 
 	function _setupBlock()
 	{
-		$this->_mControllerState->setupBlock($this);
+		$this->_mStrategy->setupBlock();
 	}
 
+	/**
+	 * Process of Block. Fetch objects from $this->mBlockChain, render the
+	 * result of the object with html data, and set those result to member
+	 * property.
+	 * 
+	 * In this member function, the cache mechanism has to be important. If the
+	 * object has its cache, this function loads the cache data instead of
+	 * calling the business logic of the block.
+	 *
+	 * @access protected
+	 */
 	function _processBlock()
 	{
 		$i=0;
 		
-		$blockTarget=new XCube_RenderTarget();
-		$blockTarget->setType(XCUBE_RENDER_TARGET_TYPE_BLOCK);
+		//
+		// Create render-target for blocks. We use reset() to re-cycle this
+		// object in the foreach loop.
+		//
+		$renderTarget =& new XCube_RenderTarget();
+		$renderTarget->setType(XCUBE_RENDER_TARGET_TYPE_BLOCK);
 		
 		$cache =& $this->mRoot->getCacheSystem();
 
-		foreach($this->mBlockChain as $blockProcedure) {
+		foreach ($this->mBlockChain as $blockProcedure) {
 			$cache->reset();
-			$blockTarget->reset();
+			$renderTarget->reset();
 
 			$cache->setResourceName("block" . $blockProcedure->getId());
 			if ($cache->isCache($blockProcedure->getCacheTime())) {
 				$content = $cache->load();
 				if ($content) {
-					$this->mRenderSystem->mBlockShowFlags[$blockProcedure->getEntryIndex()] = true;
-					$this->mRenderSystem->mBlockContents[$blockProcedure->getEntryIndex()][] = array(
+					$this->mBlockShowFlags[$blockProcedure->getEntryIndex()] = true;
+					$this->mBlockContents[$blockProcedure->getEntryIndex()][] = array(
+							'name' => $blockProcedure->getName(),
 							'title'   => $blockProcedure->getTitle(),
 							'content' => $content,
 							'weight'  => $blockProcedure->getWeight()
@@ -253,41 +274,25 @@
 				}
 			}
 			else {
-				$blockProcedure->execute($this,$this->getXoopsUser());
+				$blockProcedure->execute($this, $this->getXoopsUser(), $renderTarget);
 
 				if (!$blockProcedure->hasResult()) {
 					continue;
 				}
-					
-				$blockTarget->setAttribute("mid",$blockProcedure->getId());
-
-				if ($blockProcedure->getTemplateName() == null) {
-					$this->mRenderSystem->mBlockShowFlags[$blockProcedure->getEntryIndex()] = true;
-					$result = $blockProcedure->getResult();
-					
-					$blockTarget->setTemplateName('system_dummy.html');
-					$blockTarget->setAttribute('dummy_content', $result['content']);
-				}
-				else {
-					$blockTarget->setTemplateName($blockProcedure->getTemplateName());
-					$blockTarget->setAttribute("block",$blockProcedure->getResult());
-				}
-
-				$this->mRenderSystem->renderBlock($blockTarget);
 				
-				$content = $blockTarget->getResult();
+				$renderSystem =& $this->mRoot->getRenderSystem($blockProcedure->getRenderSystemName());
+				$renderSystem->renderBlock($renderTarget);
 				
-				if ($content) {
-					$this->mRenderSystem->mBlockShowFlags[$blockProcedure->getEntryIndex()] = true;
-					$this->mRenderSystem->mBlockContents[$blockProcedure->getEntryIndex()][] = array(
-							'title'=>$blockProcedure->getTitle(),
-							'content'=>$content,
-							'weight'=>$blockProcedure->getWeight()
-					);
-				}
+				$this->mBlockShowFlags[$blockProcedure->getEntryIndex()] = true;
+				$this->mBlockContents[$blockProcedure->getEntryIndex()][] = array(
+						'name' => $blockProcedure->getName(),
+						'title'=>$blockProcedure->getTitle(),
+						'content'=>$renderTarget->getResult(),
+						'weight'=>$blockProcedure->getWeight()
+				);
 
 				if ($blockProcedure->getCacheTime() > 0) {
-					$cache->save($blockTarget);
+					$cache->save($renderTarget);
 				}
 			}
 
@@ -307,7 +312,7 @@
 
 	function _setupModuleController()
 	{
-		$this->_mControllerState->setupModuleController($this);
+		$this->_mStrategy->setupModuleController();
 	}
 
 	function _processModuleController()
@@ -574,26 +579,12 @@
 		session_start();
 	}
 
-	/**
-	 * @deprecated
-	 */	
-	function _setupRenderSystem()
-	{
-		// TODO remove this method.
-	}
 	
 	function executeHeader()
 	{
 		//
 		// TODO Now, I done for working admin panel.
 		//
-		$renderSystem =& $this->mRoot->getRenderSystem($this->mModuleController->getDependRenderSystem());
-
-		// TODO
-		$this->mRenderSystem =& $renderSystem;
-		
-		$this->mRenderSystem->prepare($this);
-
 		parent::executeHeader();
 
 		//
@@ -615,14 +606,13 @@
 		$cacheSystem =& $this->mRoot->getCacheSystem();
 		$xoopsModule =& $this->mModuleController->getXoopsModule();
 		
-		$renderTarget=new Legacy_RenderTargetMain();
-
 		if ($this->_isModuleCache($xoopsModule)) {
 			$url = xoops_getenv('REQUEST_URI');
 			$cacheSystem->setResourceName($url);
 			
 			if ($cacheSystem->isCache($this->_getModuleCacheTime($xoopsModule))) {
-				$renderTarget =& new Legacy_RenderTargetMain();
+				$renderSystem =& $this->mRoot->getRenderSystem($this->mModuleController->getDependRenderSystem());
+				$renderTarget =& $renderSystem->createRenderTarget(XCUBE_RENDER_TARGET_TYPE_MAIN);
 				$renderTarget->setResult($cacheSystem->load());
 
 				$this->_executeViewTheme($renderTarget);
@@ -632,8 +622,6 @@
 		}
 
 		ob_start();
-
-		$this->mRenderSystem->setRenderTarget($renderTarget);
 	}
 	
 	/**
@@ -663,44 +651,47 @@
 	
 	function executeView()
 	{
+		$renderSystem =& $this->mRoot->getRenderSystem($this->mModuleController->getDependRenderSystem());
+		$renderTarget =& $this->mModuleController->getRenderTarget();
+		
 		//
 		//  Buffering handling of standard output for main render target is responsibility
 		// of a controller. Of course all controllers do not have to implement this.
 		// The following lines are movement for compatibility and the feature of
 		// this controller.
 		//
-		if(!$this->mRenderSystem->mTemplateName)
-			$this->mRenderSystem->mTemplateName = isset($GLOBALS['xoopsOption']['template_main']) ? $GLOBALS['xoopsOption']['template_main'] : null;
 		
-		$renderTarget=&$this->mRenderSystem->getRenderTarget();
 
 		// require_once XOOPS_ROOT_PATH . '/include/notification_select.php';
 
 		// Wmm...
-		if($renderTarget->getTemplateName()==null) {
-			$renderTarget->setTemplateName($this->mRenderSystem->mTemplateName);
-			if ($this->mModuleController->isModuleProcess()) {
-				$renderTarget->setModuleName($this->mModuleController->getDirname());
+		if (is_object($renderTarget)) {
+			if ($renderTarget->getTemplateName() == null) {
+				if (isset($GLOBALS['xoopsOption']['template_main'])) {
+					$renderTarget->setTemplateName($GLOBALS['xoopsOption']['template_main']);
+				}
 			}
+			
+			$renderTarget->setAttribute("stdout_buffer", ob_get_contents());
 		}
 
-		$renderTarget->setAttribute("stdout_buffer",ob_get_contents());
 		ob_end_clean();
 		
-//		$this->mRenderSystem->mRenderTarget->copyAttributes($mainRenderTarget);
-
-		$this->mRenderSystem->renderWithTarget($renderTarget);
+		if (is_object($renderTarget)) {
+			$renderSystem->renderWithTarget($renderTarget);
 
-		//
-		// Cache Control
-		//
-		$xoopsModule =& $this->mModuleController->getXoopsModule();
-		if ($this->_isModuleCache($xoopsModule)) {
-			$url = xoops_getenv('REQUEST_URI');
-			$cacheSystem =& $this->mRoot->getCacheSystem();
-			$cacheSystem->setResourceName($url);
-			$cacheSystem->save($renderTarget);
+			//
+			// Cache Control
+			//
+			$xoopsModule =& $this->mModuleController->getXoopsModule();
+			if ($this->_isModuleCache($xoopsModule)) {
+				$url = xoops_getenv('REQUEST_URI');
+				$cacheSystem =& $this->mRoot->getCacheSystem();
+				$cacheSystem->setResourceName($url);
+				$cacheSystem->save($renderTarget);
+			}
 		}
+
 		
 		$this->_executeViewTheme($renderTarget);
 	}
@@ -714,12 +705,15 @@
 		// Theme Control
 		//
 		$screenTarget = $this->mDialogMode ? new Legacy_DialogRenderTarget() : new Legacy_ThemeRenderTarget();
-		$screenTarget->setAttribute('xoops_contents', $resultRenderTarget->getResult());
+		
+		if (is_object($resultRenderTarget)) {
+			$screenTarget->setAttribute('xoops_contents', $resultRenderTarget->getResult());
+		}
 
 		//
 		// Get the render-system through theme object.
 		//
-		$theme =& $this->_mControllerState->getMainThemeObject($this);
+		$theme =& $this->_mStrategy->getMainThemeObject();
 
 		$renderSystem =& $this->mRoot->getRenderSystem($theme->get('render_system'));
 		$screenTarget->setTemplateName($theme->get('dirname'));
@@ -863,20 +857,18 @@
 	 * Because this method changes state after executeCommon, this resets now property.
 	 * It depends on XCube_Controller steps.
 	 *
-	 * @param $state BaseControllerState*
+	 * @param Legacy_AbstractControllerStrategy $strategy
 	 */
-	function switchStateCompulsory($state)
+	function switchStateCompulsory($strategy)
 	{
-		if($state->mStatusFlag != $this->_mControllerState->mStatusFlag) {
-			unset($this->mRenderSystem);
-			$this->_mControllerState=&$state;
+		if($state->mStatusFlag != $this->_mStrategy->mStatusFlag) {
+			$this->_mStrategy =& $strategy;
 			
 			//
 			// The following line depends on XCube_Controller process of executeCommon.
 			// But, There is no other method.
 			//
 			$this->_setupModuleController();
-			$this->_setupRenderSystem();
 			$this->_processModuleController();
 		}
 	}
@@ -915,7 +907,7 @@
 	 */
 	function &getVirtualCurrentModule()
 	{
-		$ret =& $this->_mControllerState->getVirtualCurrentModule($this);
+		$ret =& $this->_mStrategy->getVirtualCurrentModule();
 		return $ret;
 	}
 	
@@ -1040,9 +1032,19 @@
 /**
  * @abstract
  */
-class BaseControllerState
+class Legacy_AbstractControllerStrategy
 {
+	/**
+	 * @var Legacy_Controller
+	 */
+	var $mController = null;
+	
 	var $mStatusFlag;
+	
+	function Legacy_AbstractControllerStrategy(&$controller)
+	{
+		$this->mController =& $controller;
+	}
 
 	/**
 	 * Create a instance of ModuleController, and set it to mModuleController
@@ -1050,15 +1052,11 @@
 	 * 
 	 * @param $controller Legacy_Controller
 	 */
-	function setupModuleController(&$controller)
+	function setupModuleController()
 	{
 	}
 
-	function setupRenderSystem(&$controller)
-	{
-	}
-	
-	function setupBlock(&$controller)
+	function setupBlock()
 	{
 	}
 
@@ -1066,45 +1064,44 @@
 	 * @return XoopsModule
 	 * @see Legacy_Controller::getVirtualCurrentModule()
 	 */	
-	function &getVirtualCurrentModule(&$controller)
+	function &getVirtualCurrentModule()
 	{
 		$ret = null;
 		return $ret;
 	}
 	
-	function &getMainThemeObject(&$controller)
+	function &getMainThemeObject()
 	{
 	}
 }
 
-class BaseControllerPublicState extends BaseControllerState
+class Legacy_PublicControllerStrategy extends Legacy_AbstractControllerStrategy
 {
-	var $mStatusFlag=LEGACY_CONTROLLER_STATE_PUBLIC;
+	var $mStatusFlag = LEGACY_CONTROLLER_STATE_PUBLIC;
 	
-	function BaseControllerPublicState()
+	function Legacy_PublicControllerStrategy(&$controller)
 	{
-		@define("LEGACY_DEPENDENCE_RENDERER", "Legacy_RenderSystem");
+		parent::Legacy_AbstractControllerStrategy($controller);
+		
+		if (!defined("LEGACY_DEPENDENCE_RENDERER")) {
+			define("LEGACY_DEPENDENCE_RENDERER", "Legacy_RenderSystem");
+		}
 	}
 
-	function setupModuleController(&$controller)
+	function setupModuleController()
 	{
 		require_once XOOPS_BASE_PATH . "/kernel/Legacy_ModuleController.class.php";
-		$controller->mModuleController =& new Legacy_ModuleController($controller);
+		$this->mController->mModuleController =& new Legacy_ModuleController($this->mController);
 	}
 
-	function setupRenderSystem(&$controller)
-	{
-		// TODO remove this method.
-	}
-	
-	function setupBlock(&$controller)
+	function setupBlock()
 	{
 		$showFlag =0;
 		$mid=0;
 
-		if($controller->mModuleController->isModuleProcess()) {
-			$showFlag = (preg_match("/index\.php$/i", xoops_getenv('PHP_SELF')) && $controller->mConfig['startpage'] == $controller->mModuleController->mModuleObject->getVar('dirname'));
-			$mid = $controller->mModuleController->mModuleObject->getVar('mid');
+		if($this->mController->mModuleController->isModuleProcess()) {
+			$showFlag = (preg_match("/index\.php$/i", xoops_getenv('PHP_SELF')) && $this->mController->mConfig['startpage'] == $this->mController->mModuleController->mModuleObject->getVar('dirname'));
+			$mid = $this->mController->mModuleController->mModuleObject->getVar('mid');
 		}
 		else {
 			//
@@ -1117,31 +1114,31 @@
 		$showCenterFlag = (SHOW_CENTERBLOCK_LEFT | SHOW_CENTERBLOCK_CENTER | SHOW_CENTERBLOCK_RIGHT);
 		$showRightFlag = SHOW_SIDEBLOCK_RIGHT;
 		$showFlag = SHOW_SIDEBLOCK_LEFT | $showRightFlag | $showCenterFlag;
-		$groups = is_object($controller->mXoopsUser) ? $controller->mXoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
+		$groups = is_object($this->mController->mXoopsUser) ? $this->mController->mXoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
 
 		$blockObjects=&$blockHandler->getBlocks($groups, $mid, $showFlag);
 		foreach($blockObjects as $blockObject) {
-			$controller->mBlockChain[]=new XCube_LegacyAdaptBlockProcedure($blockObject);
+			$this->mController->mBlockChain[] =& new Legacy_AdaptBlockProcedure($blockObject);
 			unset($blockObject);
 		}
 	}
 
-	function &getMainThemeObject(&$controller)
+	function &getMainThemeObject()
 	{
 		// [TODO]
 		// Because get() of the virtual handler is heavy, we have to consider
 		// the new solution about this process.
 		//
 		$handler =& xoops_getmodulehandler('theme', 'base');
-		$theme =& $handler->get($controller->getMainTheme());
+		$theme =& $handler->get($this->mController->getMainTheme());
 		
 		return $theme;
 	}
 }
 
-class BaseControllerAdminState extends BaseControllerState
+class Legacy_AdminControllerStrategy extends Legacy_AbstractControllerStrategy
 {
-	var $mStatusFlag=LEGACY_CONTROLLER_STATE_ADMIN;
+	var $mStatusFlag = LEGACY_CONTROLLER_STATE_ADMIN;
 	
 	/**
 	 *  If this array includes current action, getVirtualCurrentModule() returns
@@ -1151,47 +1148,38 @@
 	 */
 	var $_mSpecialActions = array("Help", "CommentList");
 
-	function BaseControllerAdminState()
+	function Legacy_AdminControllerStrategy(&$controller)
 	{
+		parent::Legacy_AbstractControllerStrategy($controller);
+		
 		//
 		// TODO We have to develop complated-switching-controller-mechanizm.
 		//
-		@define("LEGACY_DEPENDENCE_RENDERER", "Legacy_AdminRenderSystem");
+		if (!defined("LEGACY_DEPENDENCE_RENDERER")) {
+			define("LEGACY_DEPENDENCE_RENDERER", "Legacy_AdminRenderSystem");
+		}
 	}
 
-	function setupModuleController(&$controller)
+	function setupModuleController()
 	{
 		require_once XOOPS_BASE_PATH . "/class/Legacy_AdminModuleController.class.php";
-		$controller->mModuleController =& new Legacy_AdminModuleController($controller);
+		$this->mController->mModuleController =& new Legacy_AdminModuleController($this->mController);
 	}
 
-	function setupRenderSystem(&$controller)
+	function setupBlock()
 	{
-		// TODO remove this method.
-
-		//
-		// [TODO]
-		// Controller or Root should have factory-method so that we create a 
-		// instance by a site config.
-		//
-		$renderSystem =& $this->mRoot->getRenderSystem("Legacy_AdminRenderSystem");
-		$controller->mRenderSystem->prepare();
-	}
-	
-	function setupBlock(&$controller)
-	{
-		require_once XOOPS_BASE_PATH."/admin/blocks/AdminActionSearch.class.php";
-		require_once XOOPS_BASE_PATH."/admin/blocks/AdminSideMenu.class.php";
-		$controller->mBlockChain[] =& new Legacy_AdminActionSearch();
-		$controller->mBlockChain[] =& new Legacy_AdminSideMenu();
+		require_once XOOPS_BASE_PATH . "/admin/blocks/AdminActionSearch.class.php";
+		require_once XOOPS_BASE_PATH . "/admin/blocks/AdminSideMenu.class.php";
+		$this->mController->mBlockChain[] =& new Legacy_AdminActionSearch();
+		$this->mController->mBlockChain[] =& new Legacy_AdminSideMenu();
 	}
 
-	function &getVirtualCurrentModule(&$controller)
+	function &getVirtualCurrentModule()
 	{
 		$module = null;
 		
-		if ($controller->mModuleController->isModuleProcess()) {
-			$module =& $controller->mModuleController->getXoopsModule();
+		if ($this->mController->mModuleController->isModuleProcess()) {
+			$module =& $this->mController->mModuleController->getXoopsModule();
 			
 			if ($module->get('dirname') == "base" && isset($_REQUEST['dirname'])) {
 				if (in_array(xoops_getrequest('action'), $this->_mSpecialActions)) {
@@ -1204,7 +1192,7 @@
 		return $module;
 	}
 
-	function &getMainThemeObject(&$controller)
+	function &getMainThemeObject()
 	{
 		$handler =& xoops_getmodulehandler('theme', 'base');
 		$theme =& $handler->create();
@@ -1212,7 +1200,7 @@
 		//
 		// TODO Load manifesto here.
 		//
-		$theme->set('dirname', $controller->mRoot->mSiteConfig['Legacy']['Theme']);
+		$theme->set('dirname', $this->mController->mRoot->mSiteConfig['Legacy']['Theme']);
 		$theme->set('render_system', 'Legacy_AdminRenderSystem');
 		
 		return $theme;


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