1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17:
18:
19: 20: 21:
22: defined('XOOPS_ROOT_PATH') || exit('Restricted access');
23:
24: include_once $GLOBALS['xoops']->path('class/xoopsblock.php');
25: include_once $GLOBALS['xoops']->path('class/template.php');
26:
27: 28: 29: 30: 31: 32: 33: 34:
35: class xos_logos_PageBuilder
36: {
37: public $theme = false;
38: public $blocks = array();
39:
40: 41: 42: 43: 44: 45: 46:
47: public function xoInit($options = array())
48: {
49: $this->retrieveBlocks();
50: if ($this->theme) {
51: $this->theme->template->assign_by_ref('xoBlocks', $this->blocks);
52: }
53:
54: return true;
55: }
56:
57: 58: 59: 60:
61: public function preRender($zone = '')
62: {
63: }
64:
65: 66: 67: 68:
69: public function postRender($zone = '')
70: {
71: }
72:
73: 74: 75: 76: 77:
78: public function retrieveBlocks()
79: {
80: global $xoopsConfig;
81: $xoopsPreload = XoopsPreload::getInstance();
82:
83: $startMod = ($xoopsConfig['startpage'] == '--') ? 'system' : $xoopsConfig['startpage'];
84: if (isset($GLOBALS['xoopsModule']) && is_object($GLOBALS['xoopsModule'])) {
85: list($mid, $dirname) = array(
86: $GLOBALS['xoopsModule']->getVar('mid'),
87: $GLOBALS['xoopsModule']->getVar('dirname'));
88: $isStart = (substr($_SERVER['PHP_SELF'], -9) === 'index.php' && $xoopsConfig['startpage'] == $dirname && empty($_SERVER['QUERY_STRING']));
89: } else {
90: list($mid, $dirname) = array(
91: 0,
92: 'system');
93: $isStart = !empty($GLOBALS['xoopsOption']['show_cblock']);
94: }
95:
96: $groups = (isset($GLOBALS['xoopsUser']) && is_object($GLOBALS['xoopsUser'])) ? $GLOBALS['xoopsUser']->getGroups() : array(
97: XOOPS_GROUP_ANONYMOUS);
98:
99: $oldzones = array(
100: XOOPS_SIDEBLOCK_LEFT => 'canvas_left',
101: XOOPS_SIDEBLOCK_RIGHT => 'canvas_right',
102: XOOPS_CENTERBLOCK_LEFT => 'page_topleft',
103: XOOPS_CENTERBLOCK_CENTER => 'page_topcenter',
104: XOOPS_CENTERBLOCK_RIGHT => 'page_topright',
105: XOOPS_CENTERBLOCK_BOTTOMLEFT => 'page_bottomleft',
106: XOOPS_CENTERBLOCK_BOTTOM => 'page_bottomcenter',
107: XOOPS_CENTERBLOCK_BOTTOMRIGHT => 'page_bottomright',
108: XOOPS_FOOTERBLOCK_LEFT => 'footer_left',
109: XOOPS_FOOTERBLOCK_RIGHT => 'footer_right',
110: XOOPS_FOOTERBLOCK_CENTER => 'footer_center',
111: XOOPS_FOOTERBLOCK_ALL => 'footer_all');
112:
113: foreach ($oldzones as $zone) {
114: $this->blocks[$zone] = array();
115: }
116: if ($this->theme) {
117: $template =& $this->theme->template;
118: $backup = array(
119: $template->caching,
120: $template->cache_lifetime);
121: } else {
122: $template = null;
123: $template = new XoopsTpl();
124: }
125: $xoopsblock = new XoopsBlock();
126: $block_arr = array();
127: $block_arr = $xoopsblock->getAllByGroupModule($groups, $mid, $isStart, XOOPS_BLOCK_VISIBLE);
128: $xoopsPreload->triggerEvent('core.class.theme_blocks.retrieveBlocks', array(&$this, &$template, &$block_arr));
129: foreach ($block_arr as $block) {
130: $side = $oldzones[$block->getVar('side')];
131: if ($var = $this->buildBlock($block, $template)) {
132: $this->blocks[$side][$var['id']] = $var;
133: }
134: }
135: if ($this->theme) {
136: list($template->caching, $template->cache_lifetime) = $backup;
137: }
138: }
139:
140: 141: 142: 143: 144: 145:
146: public function generateCacheId($cache_id)
147: {
148: if ($this->theme) {
149: $cache_id = $this->theme->generateCacheId($cache_id);
150: }
151:
152: return $cache_id;
153: }
154:
155: 156: 157: 158: 159: 160: 161:
162: public function buildBlock($xobject, &$template)
163: {
164:
165:
166: $block = array(
167: 'id' => $xobject->getVar('bid'),
168: 'module' => $xobject->getVar('dirname'),
169: 'title' => $xobject->getVar('title'),
170:
171: 'weight' => $xobject->getVar('weight'),
172: 'lastmod' => $xobject->getVar('last_modified'));
173:
174: $bcachetime = (int)$xobject->getVar('bcachetime');
175: if (empty($bcachetime)) {
176: $template->caching = 0;
177: } else {
178: $template->caching = 2;
179: $template->cache_lifetime = $bcachetime;
180: }
181: $template->setCompileId($xobject->getVar('dirname', 'n'));
182: $tplName = ($tplName = $xobject->getVar('template')) ? "db:$tplName" : 'db:system_block_dummy.tpl';
183: $cacheid = $this->generateCacheId('blk_' . $xobject->getVar('bid'));
184:
185: $xoopsLogger = XoopsLogger::getInstance();
186: if (!$bcachetime || !$template->is_cached($tplName, $cacheid)) {
187:
188:
189: if ($this->theme && $bcachetime) {
190: foreach ($this->theme->metas as $type => $value) {
191: $old[$type] = $this->theme->metas[$type];
192: }
193: }
194:
195:
196: $xoopsLogger->addBlock($xobject->getVar('name'));
197: if ($bresult = $xobject->buildBlock()) {
198: $template->assign('block', $bresult);
199: $block['content'] = $template->fetch($tplName, $cacheid);
200: } else {
201: $block = false;
202: }
203:
204:
205: if ($this->theme && $bcachetime) {
206: $metas = array();
207: foreach ($this->theme->metas as $type => $value) {
208: $dif = array_diff_key($this->theme->metas[$type], $old[$type]);
209: if (count($dif)) {
210: $metas[$type] = $dif;
211: }
212: }
213: if (count($metas)) {
214: xoops_load('xoopscache');
215: $cache = XoopsCache::getInstance();
216: $cache->write($cacheid, $metas);
217: }
218: }
219: } else {
220: $xoopsLogger->addBlock($xobject->getVar('name'), true, $bcachetime);
221: $block['content'] = $template->fetch($tplName, $cacheid);
222: }
223:
224:
225: if ($this->theme && $bcachetime) {
226: xoops_load('xoopscache');
227: $cache = XoopsCache::getInstance();
228: if ($metas = $cache->read($cacheid)) {
229: foreach ($metas as $type => $value) {
230: $this->theme->metas[$type] = array_merge($this->theme->metas[$type], $metas[$type]);
231: }
232: }
233: }
234:
235: $template->setCompileId();
236:
237: return $block;
238: }
239: }
240: