Minahito
minah****@users*****
2006年 10月 5日 (木) 18:08:50 JST
Index: xoops2jp/html/modules/base/kernel/Legacy_BlockProcedure.class.php diff -u xoops2jp/html/modules/base/kernel/Legacy_BlockProcedure.class.php:1.1.2.1.2.1 xoops2jp/html/modules/base/kernel/Legacy_BlockProcedure.class.php:1.1.2.1.2.2 --- xoops2jp/html/modules/base/kernel/Legacy_BlockProcedure.class.php:1.1.2.1.2.1 Thu Sep 28 14:03:56 2006 +++ xoops2jp/html/modules/base/kernel/Legacy_BlockProcedure.class.php Thu Oct 5 18:08:50 2006 @@ -1,37 +1,81 @@ <?php /** * @package Legacy - * @version $Id: Legacy_BlockProcedure.class.php,v 1.1.2.1.2.1 2006/09/28 05:03:56 minahito Exp $ + * @version $Id: Legacy_BlockProcedure.class.php,v 1.1.2.1.2.2 2006/10/05 09:08:50 minahito Exp $ */ if (!defined('XOOPS_ROOT_PATH')) die(); /** - * The abstract block class of XOOPS Cube Legacy. This class has must interface - * for the controller. The sub-class must implement these interfaces to be - * called back by the controller. + * The class for blocks which has interfaces to exchange informations with the + * controller. The sub-class must implement these interfaces with helper + * functions, to be called back by the controller. */ -class Legacy_BlockProcedure +class Legacy_AbstractBlockProcedure { - function XCube_BlockProcedure() + /** + * @var XCube_RenderTarget + */ + var $mRender = null; + + function Legacy_AbstractBlockProcedure() { } - function getName() + function prepare() { + return true; } - function execute(&$controller, &$user, &$render) + /** + * @var XCube_RenderTarget + */ + function &getRenderBuffer() + { + if (!is_object($this->mRender)) { + $this->_createRenderBuffer(); + } + + return $this->mRender; + } + + /** + * Gets a name of the dependence render-system. + * @return string + */ + function getRenderSystemName() { + $root =& XCube_Root::getSingleton(); + return $root->mContext->mBaseRenderSystemName; } + /** + * Creates a instance of the render buffer, and set it to the property. + * This is a helper function for sub-classes. + * @access protected + */ + function &_createRenderBuffer() + { + $this->mRender =& new XCube_RenderTarget(); + $this->mRender->setType(XCUBE_RENDER_TARGET_TYPE_BLOCK); + + return $this->mRender; + } + function getId() { } - function enableCached() + function getName() + { + } + + /** + * Gets a value indicating whether the block can be cached. + * @return bool + */ + function enableCache() { - return true; } /** @@ -40,11 +84,11 @@ */ function getCacheTime() { - return 0; } function getTitle() { + return $this->_mBlock->get('title'); } function getEntryIndex() @@ -54,105 +98,112 @@ function getWeight() { } - - function hasResult() - { - } - function &getResult() - { - } - /** - * Return a name of the render-system which this object requests to render. - * - * @return string + * Gets a value indicating whether this block nees to display its content. */ - function getRenderSystemName() + function isDisplay() { + return true; } } -/** - * The adapter class for XoopsBlock objects of XOOPS2 JP. - * @see Legacy_BlockProcedure - */ -class Legacy_AdaptBlockProcedure extends Legacy_BlockProcedure +class Legacy_BlockProcedure extends Legacy_AbstractBlockProcedure { /** - * @access private + * @var XoopsBlock */ - var $mAdapteeBlockObject; - - var $mResultData; - - function Legacy_AdaptBlockProcedure(&$blockObject) + var $_mBlock = null; + + /** + * @var XCube_RenderTarget + */ + var $mRender = null; + + function Legacy_BlockProcedure(&$block) { - $this->mAdapteeBlockObject=&$blockObject; + $this->_mBlock =& $block; } - - function execute(&$controller, &$user, &$render) + + function prepare() { - $this->mResultData =& $this->mAdapteeBlockObject->buildBlock(); - $render->setAttribute("mid", $this->getId()); - - if ($this->mAdapteeBlockObject->get('template') == null) { - $render->setTemplateName('system_dummy.html'); - $render->setAttribute('dummy_content', $this->mResultData['content']); - } - else { - $render->setTemplateName($this->mAdapteeBlockObject->get('template')); - $render->setAttribute('block', $this->mResultData); - } + return true; } function getId() { - return $this->mAdapteeBlockObject->get('bid'); + return $this->_mBlock->get('bid'); } - function enableCached() + function getName() { - return true; + return $this->_mBlock->get('title'); + } + + function enableCache() + { + return $this->_mBlock->get('bcachetime') > 0; } - /** - * Return cache time - * @return int - */ function getCacheTime() { - return $this->mAdapteeBlockObject->get('bcachetime'); + return $this->_mBlock->get('bcachetime'); } function getTitle() { - return $this->mAdapteeBlockObject->get('title'); + return $this->_mBlock->get('title'); } function getEntryIndex() { - return $this->mAdapteeBlockObject->getVar('side'); + return $this->_mBlock->getVar('side'); } function getWeight() { - return $this->mAdapteeBlockObject->get('weight'); - } - - function hasResult() - { - return !empty($this->mResultData); + return $this->_mBlock->get('weight'); } +} + +/** + * The adapter class for XoopsBlock objects of XOOPS2 JP. + * @see Legacy_AbstractBlockProcedure + */ +class Legacy_BlockProcedureAdapter extends Legacy_BlockProcedure +{ + var $_mDisplayFlag = true; - function &getResult() + function execute() { - return $this->mResultData; + $result =& $this->_mBlock->buildBlock(); + + if (empty($result)) { + $this->_mDisplayFlag = false; + return; + } + + $render =& $this->getRenderBuffer(); + $render->setAttribute("mid", $this->getId()); + + if ($this->_mBlock->get('template') == null) { + $render->setTemplateName('system_dummy.html'); + $render->setAttribute('dummy_content', $result['content']); + } + else { + $render->setTemplateName($this->_mBlock->get('template')); + $render->setAttribute('block', $result); + } + + $root =& XCube_Root::getSingleton(); + $renderSystem =& $root->getRenderSystem($this->getRenderSystemName()); + + $renderSystem->renderBlock($render); } - function getRenderSystemName() + function isDisplay() { - return 'Legacy_RenderSystem'; + return $this->_mDisplayFlag; } }