1: <?php
2: /**
3: *
4: * @package Legacy
5: * @version $Id: Legacy_BlockProcedure.class.php,v 1.4 2008/09/25 15:11:56 kilica Exp $
6: * @copyright Copyright 2005-2007 XOOPS Cube Project <https://github.com/xoopscube/legacy>
7: * @license https://github.com/xoopscube/legacy/blob/master/docs/GPL_V2.txt GNU GENERAL PUBLIC LICENSE Version 2
8: *
9: */
10:
11: if (!defined('XOOPS_ROOT_PATH')) die();
12:
13: /**
14: * The class for blocks which has interfaces to exchange informations with the
15: * controller. The sub-class must implement these interfaces with helper
16: * functions, to be called back by the controller.
17: */
18: class Legacy_AbstractBlockProcedure
19: {
20: /**
21: * @var XCube_RenderTarget
22: */
23: var $mRender = null;
24:
25: function Legacy_AbstractBlockProcedure()
26: {
27: }
28:
29: /**
30: * Preparation. If it's in exception case, returns false.
31: * @return bool
32: */
33: function prepare()
34: {
35: return true;
36: }
37:
38: /**
39: * @var XCube_RenderTarget
40: */
41: function &getRenderTarget()
42: {
43: if (!is_object($this->mRender)) {
44: $this->_createRenderTarget();
45: }
46:
47: return $this->mRender;
48: }
49:
50: /**
51: * Gets a name of the dependence render-system.
52: * @return string
53: */
54: function getRenderSystemName()
55: {
56: $root =& XCube_Root::getSingleton();
57: return $root->mContext->mBaseRenderSystemName;
58: }
59:
60: /**
61: * Creates a instance of the render buffer, and set it to the property.
62: * This is a helper function for sub-classes.
63: * @access protected
64: */
65: function &_createRenderTarget()
66: {
67: $this->mRender = new XCube_RenderTarget();
68: $this->mRender->setType(XCUBE_RENDER_TARGET_TYPE_BLOCK);
69:
70: return $this->mRender;
71: }
72:
73: /**
74: * Gets a number as ID.
75: * @return int
76: */
77: function getId()
78: {
79: }
80:
81: /**
82: * Gets a name of this block.
83: * @return string
84: */
85: function getName()
86: {
87: }
88:
89: /**
90: * Gets a value indicating whether the block can be cached.
91: * @return bool
92: */
93: function isEnableCache()
94: {
95: }
96:
97: /**
98: * Return cache time
99: * @return int
100: */
101: function getCacheTime()
102: {
103: }
104:
105: /**
106: * Gets a title of this block.
107: * @return string
108: */
109: function getTitle()
110: {
111: return $this->_mBlock->get('title');
112: }
113:
114: /**
115: * Gets a column index of this block.
116: * @return int
117: */
118: function getEntryIndex()
119: {
120: }
121:
122: /**
123: * Gets a weight of this block.
124: * @return int
125: */
126: function getWeight()
127: {
128: }
129:
130: /**
131: * Gets a value indicating whether this block nees to display its content.
132: * @return bool
133: */
134: function isDisplay()
135: {
136: return true;
137: }
138:
139: function &createCacheInfo()
140: {
141: $cacheInfo = new Legacy_BlockCacheInformation();
142: $cacheInfo->setBlock($this);
143: return $cacheInfo;
144: }
145:
146: function execute()
147: {
148: }
149: }
150:
151: /**
152: * This class extends the base class to exchange of information with the
153: * controller. And, it has a XoopsBlock instance, and some public methods for
154: * the public side and the control panel side.
155: */
156: class Legacy_BlockProcedure extends Legacy_AbstractBlockProcedure
157: {
158: /**
159: * @var XoopsBlock
160: */
161: var $_mBlock = null;
162:
163: /**
164: * @var XCube_RenderTarget
165: */
166: var $mRender = null;
167:
168: function Legacy_BlockProcedure(&$block)
169: {
170: $this->_mBlock =& $block;
171: }
172:
173: function prepare()
174: {
175: return true;
176: }
177:
178: function getId()
179: {
180: return $this->_mBlock->get('bid');
181: }
182:
183: function getName()
184: {
185: return $this->_mBlock->get('name');
186: }
187:
188: function isEnableCache()
189: {
190: return $this->_mBlock->get('bcachetime') > 0;
191: }
192:
193: function getCacheTime()
194: {
195: return $this->_mBlock->get('bcachetime');
196: }
197:
198: function getTitle()
199: {
200: return $this->_mBlock->get('title');
201: }
202:
203: function getEntryIndex()
204: {
205: return $this->_mBlock->getVar('side');
206: }
207:
208: function getWeight()
209: {
210: return $this->_mBlock->get('weight');
211: }
212:
213: /**
214: * @public
215: * @breaf [Secret Agreement] Gets a value indicating whether the option form of this block needs the row to display the form.
216: * @remark Only block management actions should use this method, and this method should not be overridden usually.
217: */
218: function _hasVisibleOptionForm()
219: {
220: return true;
221: }
222:
223: /**
224: * Gets rendered HTML buffer for the option form of the control panel.
225: * @return string
226: */
227: function getOptionForm()
228: {
229: return null;
230: }
231: }
232:
233: /**
234: * The adapter class for XoopsBlock objects of XOOPS2 JP.
235: * @see Legacy_AbstractBlockProcedure
236: */
237: class Legacy_BlockProcedureAdapter extends Legacy_BlockProcedure
238: {
239: var $_mDisplayFlag = true;
240:
241: function execute()
242: {
243: $result =& $this->_mBlock->buildBlock();
244:
245: if (empty($result)) {
246: $this->_mDisplayFlag = false;
247: return;
248: }
249:
250: $render =& $this->getRenderTarget();
251: $render->setAttribute("mid", $this->_mBlock->get('mid'));
252: $render->setAttribute("bid", $this->_mBlock->get('bid'));
253:
254: if ($this->_mBlock->get('template') == null) {
255: $render->setTemplateName('system_dummy.html');
256: $render->setAttribute('dummy_content', $result['content']);
257: }
258: else {
259: $render->setTemplateName($this->_mBlock->get('template'));
260: $render->setAttribute('block', $result);
261: }
262:
263: $root =& XCube_Root::getSingleton();
264: $renderSystem =& $root->getRenderSystem($this->getRenderSystemName());
265:
266: $renderSystem->renderBlock($render);
267: }
268:
269: function isDisplay()
270: {
271: return $this->_mDisplayFlag;
272: }
273:
274: function _hasVisibleOptionForm()
275: {
276: return ($this->_mBlock->get('func_file') && $this->_mBlock->get('edit_func'));
277: }
278:
279: function getOptionForm()
280: {
281: if ($this->_mBlock->get('func_file') && $this->_mBlock->get('edit_func')) {
282: $func_file = XOOPS_MODULE_PATH . "/" . $this->_mBlock->get('dirname') . "/blocks/" . $this->_mBlock->get('func_file');
283: if (file_exists($func_file)) {
284: require $func_file;
285: $edit_func = $this->_mBlock->get('edit_func');
286:
287: $options = explode('|', $this->_mBlock->get('options'));
288:
289: if (function_exists($edit_func)) {
290: //
291: // load language file.
292: //
293: $root =& XCube_Root::getSingleton();
294: $langManager =& $root->getLanguageManager();
295: $langManager->loadBlockMessageCatalog($this->_mBlock->get('dirname'));
296:
297: return call_user_func($edit_func, $options);
298: }
299: }
300: }
301:
302: //
303: // The block may have options, even it doesn't have end_func
304: //
305: if ($this->_mBlock->get('options')) {
306: $root =& XCube_Root::getSingleton();
307: $textFilter =& $root->getTextFilter();
308:
309: $buf = "";
310: $options = explode('|', $this->_mBlock->get('options'));
311: foreach ($options as $val) {
312: $val = $textFilter->ToEdit($val);
313: $buf .= "<input type='hidden' name='options[]' value='${val}'/>";
314: }
315:
316: return $buf;
317: }
318:
319: return null;
320: }
321: }
322:
323: ?>
324: