1 | <?php |
||
2 | /** |
||
3 | * xos_logos_PageBuilder component class file |
||
4 | * |
||
5 | * You may not change or alter any portion of this comment or credits |
||
6 | * of supporting developers from this source code or any supporting source code |
||
7 | * which is considered copyrighted (c) material of the original comment or credit authors. |
||
8 | * This program is distributed in the hope that it will be useful, |
||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
11 | * |
||
12 | * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) |
||
13 | * @license GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html) |
||
14 | * @author Skalpa Keo <[email protected]> |
||
15 | * @since 2.3.0 |
||
16 | * @package kernel |
||
17 | */ |
||
18 | |||
19 | /** |
||
20 | * This file cannot be requested directly |
||
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 | * xos_logos_PageBuilder main class |
||
29 | * |
||
30 | * @package xos_logos |
||
31 | * @subpackage xos_logos_PageBuilder |
||
32 | * @author Skalpa Keo |
||
33 | * @since 2.3.0 |
||
34 | */ |
||
35 | class xos_logos_PageBuilder |
||
36 | { |
||
37 | public $theme = false; |
||
38 | public $blocks = array(); |
||
39 | |||
40 | /** |
||
41 | * xos_logos_PageBuilder::xoInit() |
||
42 | * |
||
43 | * @param array $options |
||
44 | * |
||
45 | * @return bool |
||
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 | * Called before a specific zone is rendered |
||
59 | * @param string $zone |
||
60 | */ |
||
61 | public function preRender($zone = '') |
||
62 | { |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Called after a specific zone is rendered |
||
67 | * @param string $zone |
||
68 | */ |
||
69 | public function postRender($zone = '') |
||
70 | { |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * xos_logos_PageBuilder::retrieveBlocks() |
||
75 | * |
||
76 | * @return void |
||
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; |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
137 | } |
||
138 | } |
||
139 | |||
140 | /** |
||
141 | * xos_logos_PageBuilder::generateCacheId() |
||
142 | * |
||
143 | * @param mixed $cache_id |
||
144 | * @return mixed |
||
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 | * xos_logos_PageBuilder::buildBlock() |
||
157 | * |
||
158 | * @param mixed $xobject |
||
159 | * @param mixed $template |
||
160 | * @return array|bool |
||
161 | */ |
||
162 | public function buildBlock($xobject, &$template) |
||
163 | { |
||
164 | // The lame type workaround will change |
||
165 | // bid is added temporarily as workaround for specific block manipulation |
||
166 | $block = array( |
||
167 | 'id' => $xobject->getVar('bid'), |
||
168 | 'module' => $xobject->getVar('dirname'), |
||
169 | 'title' => $xobject->getVar('title'), |
||
170 | // 'name' => strtolower( preg_replace( '/[^0-9a-zA-Z_]/', '', str_replace( ' ', '_', $xobject->getVar( 'name' ) ) ) ), |
||
171 | 'weight' => $xobject->getVar('weight'), |
||
172 | 'lastmod' => $xobject->getVar('last_modified')); |
||
173 | |||
174 | // title is a comment, don't show it |
||
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 | //Get theme metas |
||
194 | if ($this->theme && $bcachetime) { |
||
195 | foreach ($this->theme->metas as $type => $value) { |
||
196 | $old[$type] = $this->theme->metas[$type]; |
||
197 | } |
||
198 | } |
||
199 | |||
200 | //build block |
||
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 | //check if theme added new metas |
||
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]); |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
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 | //add block cached metas |
||
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 |