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->assignByRef('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: |
|
175: | if (0 === strpos($block['title'], '// ')) {
|
176: | $block['title'] = '';
|
177: | }
|
178: |
|
179: | $bcachetime = (int)$xobject->getVar('bcachetime');
|
180: | if (empty($bcachetime)) {
|
181: | $template->caching = 0;
|
182: | } else {
|
183: | $template->caching = 2;
|
184: | $template->cache_lifetime = $bcachetime;
|
185: | }
|
186: | $template->setCompileId($xobject->getVar('dirname', 'n'));
|
187: | $tplName = ($tplName = $xobject->getVar('template')) ? "db:$tplName" : 'db:system_block_dummy.tpl';
|
188: | $cacheid = $this->generateCacheId('blk_' . $xobject->getVar('bid'));
|
189: |
|
190: | $xoopsLogger = XoopsLogger::getInstance();
|
191: | if (!$bcachetime || !$template->isCached($tplName, $cacheid)) {
|
192: |
|
193: |
|
194: | if ($this->theme && $bcachetime) {
|
195: | foreach ($this->theme->metas as $type => $value) {
|
196: | $old[$type] = $this->theme->metas[$type];
|
197: | }
|
198: | }
|
199: |
|
200: |
|
201: | $xoopsLogger->addBlock($xobject->getVar('name'));
|
202: | if ($bresult = $xobject->buildBlock()) {
|
203: | $template->assign('block', $bresult);
|
204: | $block['content'] = $template->fetch($tplName, $cacheid);
|
205: | } else {
|
206: | $block = false;
|
207: | }
|
208: |
|
209: |
|
210: | if ($this->theme && $bcachetime) {
|
211: | $metas = array();
|
212: | foreach ($this->theme->metas as $type => $value) {
|
213: | $dif = array_diff_key($this->theme->metas[$type], $old[$type]);
|
214: | if (count($dif)) {
|
215: | $metas[$type] = $dif;
|
216: | }
|
217: | }
|
218: | if (count($metas)) {
|
219: | xoops_load('xoopscache');
|
220: | $cache = XoopsCache::getInstance();
|
221: | $cache->write($cacheid, $metas);
|
222: | }
|
223: | }
|
224: | } else {
|
225: | $xoopsLogger->addBlock($xobject->getVar('name'), true, $bcachetime);
|
226: | $block['content'] = $template->fetch($tplName, $cacheid);
|
227: | }
|
228: |
|
229: |
|
230: | if ($this->theme && $bcachetime) {
|
231: | xoops_load('xoopscache');
|
232: | $cache = XoopsCache::getInstance();
|
233: | if ($metas = $cache->read($cacheid)) {
|
234: | foreach ($metas as $type => $value) {
|
235: | $this->theme->metas[$type] = array_merge($this->theme->metas[$type], $metas[$type]);
|
236: | }
|
237: | }
|
238: | }
|
239: |
|
240: | $template->setCompileId();
|
241: |
|
242: | return $block;
|
243: | }
|
244: | }
|
245: | |