Minahito
minah****@users*****
2006年 10月 5日 (木) 18:08:12 JST
Index: xoops2jp/html/modules/base/kernel/Legacy_PublicControllerStrategy.class.php diff -u /dev/null xoops2jp/html/modules/base/kernel/Legacy_PublicControllerStrategy.class.php:1.1.2.1 --- /dev/null Thu Oct 5 18:08:12 2006 +++ xoops2jp/html/modules/base/kernel/Legacy_PublicControllerStrategy.class.php Thu Oct 5 18:08:12 2006 @@ -0,0 +1,134 @@ +<?php +/** + * @package Legacy + * @version $Id: Legacy_PublicControllerStrategy.class.php,v 1.1.2.1 2006/10/05 09:08:12 minahito Exp $ + */ + +if (!defined('XOOPS_ROOT_PATH')) exit(); + +class Legacy_PublicControllerStrategy extends Legacy_AbstractControllerStrategy +{ + var $mStatusFlag = LEGACY_CONTROLLER_STATE_PUBLIC; + + function Legacy_PublicControllerStrategy(&$controller) + { + parent::Legacy_AbstractControllerStrategy($controller); + + $controller->mRoot->mContext->mBaseRenderSystemName = "Legacy_RenderSystem"; + + if (!defined("LEGACY_DEPENDENCE_RENDERER")) { + define("LEGACY_DEPENDENCE_RENDERER", "Legacy_RenderSystem"); + } + } + + function setupModuleContext(&$context, $dirname) + { + $handler =& xoops_gethandler('module'); + $context->mModule =& $this->_createModule(); + $context->mModule->mXoopsModule =& $handler->getByDirname($dirname); + $context->mXoopsModule =& $context->mModule->mXoopsModule; + + if ($context->mXoopsModule == null) { + return; + } + + if ($context->mXoopsModule->get('hasconfig') == 1 || $context->mXoopsModule->get('hascomments') == 1) { + $handler =& xoops_gethandler('config'); + $context->mModule->mModuleConfig =& $handler->getConfigsByCat(0, $context->mXoopsModule->get('mid')); + $context->mModuleConfig =& $context->mModule->mModuleConfig; + } + + // + // Load Roles + // @todo clean code + // + $xoopsUser =& $context->mXoopsUser; + $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; + + $handler =& xoops_gethandler('groupperm'); + if ($handler->checkRight('module_read', $context->mXoopsModule->get('mid'), $groups)) { + $this->mController->mRoot->mContext->mUser->addRole('Module.' . $context->mXoopsModule->get('dirname') . '.Visitor'); + } + + if (is_object($xoopsUser) && $handler->checkRight('module_admin', $context->mXoopsModule->get('mid'), $groups)) { + $this->mController->mRoot->mContext->mUser->addRole('Module.' . $context->mXoopsModule->get('dirname') . '.Admin'); + } + + $handler =& xoops_getmodulehandler('group_permission', 'base'); + $roleArr = $handler->getRolesByModule($context->mXoopsModule->get('mid'), $groups); + foreach ($roleArr as $role) { + $context->mUser->addRole($role); + } + } + + function &_createModule() + { + $module =& new Legacy_Module(); + return $module; + } + + function setupBlock() + { + $showFlag =0; + $mid=0; + + if($this->mController->mRoot->mContext->mModule != null) { + $showFlag = (preg_match("/index\.php$/i", xoops_getenv('PHP_SELF')) && $this->mController->mConfig['startpage'] == $this->mController->mRoot->mContext->mXoopsModule->get('dirname')); + $mid = $this->mController->mRoot->mContext->mXoopsModule->get('mid'); + } + else { + // + // If you does not have module_contoller, this request is to toppage or other pages of toppage. + // + $mid = preg_match("/index\.php$/i", xoops_getenv('PHP_SELF')) ? -1 : 0; + } + + $blockHandler =& xoops_gethandler('block'); + $showCenterFlag = (SHOW_CENTERBLOCK_LEFT | SHOW_CENTERBLOCK_CENTER | SHOW_CENTERBLOCK_RIGHT); + $showRightFlag = SHOW_SIDEBLOCK_RIGHT; + $showFlag = SHOW_SIDEBLOCK_LEFT | $showRightFlag | $showCenterFlag; + $groups = is_object($this->mController->mRoot->mContext->mXoopsUser) ? $this->mController->mRoot->mContext->mXoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; + + $blockObjects=&$blockHandler->getBlocks($groups, $mid, $showFlag); + foreach($blockObjects as $blockObject) { + $block =& new Legacy_BlockProcedureAdapter($blockObject); + if ($block->prepare() !== false) { + $this->mController->_mBlockChain[] =& $block; + } + unset($block); + unset($blockObject); + } + } + + 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($this->mController->getTheme()); + + return $theme; + } + + function isEnableCacheFeature() + { + return true; + } + + function enableAccess() + { + if ($this->mController->mRoot->mContext->mModule != null) { + $dirname = $this->mController->mRoot->mContext->mXoopsModule->get('dirname'); + + $GLOBALS['xoopsUserIsAdmin'] = $this->mController->mRoot->mContext->mUser->isInRole("Module.${dirname}.Admin"); + + return $this->mController->mRoot->mContext->mUser->isInRole("Module.${dirname}.Visitor"); + } + + return true; + } +} + +?> \ No newline at end of file