XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
Legacy_AdminRenderSystem.class.php
1<?php
6
7if (!defined('XOOPS_ROOT_PATH')) {
8 exit();
9}
10
11//
12// TODO
13//
14require_once XOOPS_ROOT_PATH . '/modules/legacyRender/kernel/Legacy_RenderSystem.class.php';
15
16define('LEGACY_ADMIN_RENDER_TEMPLATE_DIRNAME', 'templates');
17
18define('LEGACY_ADMIN_RENDER_FALLBACK_PATH', XOOPS_MODULE_PATH . '/legacy/admin/theme');
19define('LEGACY_ADMIN_RENDER_FALLBACK_URL', XOOPS_MODULE_URL . '/legacy/admin/theme');
20
21require_once SMARTY_DIR.'/Smarty.class.php';
22
29class Legacy_AdminSmarty extends Smarty
30{
31 public $mModulePrefix = null;
32 public $_canUpdateFromFile = true;
33
34 //
35 // If you don't intend to override the theme, set false.
36 //
37 public $overrideMode = true;
38
39 public function Legacy_AdminSmarty()
40 {
42 }
43
44 public function __construct()
45 {
46 parent::Smarty();
47
48 $this->compile_id = XOOPS_URL;
49 $this->_canUpdateFromFile = true;
50 $this->compile_check = true;
51 $this->compile_dir = XOOPS_COMPILE_PATH;
52 $this->left_delimiter = '<{';
53 $this->right_delimiter = '}>';
54 //loading under root_path for compatibility with XCL2.1
55 //$this->plugins_dir = [SMARTY_DIR . 'plugins', XOOPS_ROOT_PATH . '/class/smarty/plugins'];
56 $this->plugins_dir = [SMARTY_DIR . 'plugins'];
62 $this->force_compile = false;
63 }
64
65 public function setModulePrefix($prefix)
66 {
67 $this->mModulePrefix = $prefix;
68 }
69
70 public function _get_auto_filename($autoBase, $autoSource = null, $auotId = null)
71 {
72 $autoSource = $this->mModulePrefix . '_admin_' . $autoSource;
73 return parent::_get_auto_filename($autoBase, $autoSource, $auotId);
74 }
75
76 public function _fetch_resource_info(&$params)
77 {
78 $_return = false;
79
80 $root =& XCube_Root::getSingleton();
81 $theme = $root->mSiteConfig['Legacy']['Theme'];
82 $dirname = $this->mModulePrefix;
83
84 if (null != $dirname) {
85 $params['resource_base_path'] = XOOPS_THEME_PATH . '/' . $theme . '/modules/' . $dirname;
86 $params['quiet'] = true;
87
88 $_return = parent::_fetch_resource_info($params);
89 }
90
91 if (!$_return) {
92 unset($params['resource_base_path']);
93 $params['quiet'] = false;
94
95 $_return = parent::_fetch_resource_info($params);
96 }
97
98 return $_return;
99 }
100}
101
107{
108 public $mController;
109 public $mSmarty;
110
118 public $_mStdoutBuffer = null;
119
120 public function prepare(&$controller)
121 {
122 $this->mController =& $controller;
123
124 $this->mSmarty =new Legacy_AdminSmarty();
125 $this->mSmarty->register_modifier('theme', 'Legacy_modifier_theme');
126 $this->mSmarty->register_function('stylesheet', 'Legacy_function_stylesheet');
127
133 global $xoopsUser, $xoopsModule, $xoopsOption, $xoopsConfig;
134 $dirname = is_object( @$xoopsModule ) ? $xoopsModule->getVar('dirname') : '' ;
135 $modname = is_object( @$xoopsModule ) ? $xoopsModule->getVar('name') : '' ;
136 $modicon = is_object( @$xoopsModule ) ? $xoopsModule->getInfo('icon') : '' ;
137
138 $uid = is_object( @$xoopsUser ) ? $xoopsUser->getVar('uid') : '' ;
139
140 // Render System - get configuration
141 $moduleHandler = xoops_gethandler('module');
142 $legacyRender =& $moduleHandler->getByDirname('legacyRender');
143 $configHandler = xoops_gethandler('config');
144 $configs =& $configHandler->getConfigsByCat(0, $legacyRender->get('mid'));
145
146 $this->mSmarty->assign(
147 [
148 'xoops_url' => XOOPS_URL,
149 'xoops_rootpath' => XOOPS_ROOT_PATH,
150 'xoops_langcode' => _LANGCODE,
151 'xoops_charset' => _CHARSET,
152 'xoops_version' => XOOPS_VERSION,
153 'xoops_upload_url' => XOOPS_UPLOAD_URL,
154 'modulename' => $modname,
155 'moduleicon' => $modicon,
156 'dirname' => $dirname,
157 'xoops_dirname' => $dirname,
158 'uid' => $uid,
159 'module_name' => $modname,
160 'module_dir' => $dirname,
161 'logotype' => $configs['favicon'],
162 'favicon' => $configs['favicon'],
163 ]
164 );
165
166 if (true == $controller->mRoot->mSiteConfig['Legacy_AdminRenderSystem']['ThemeDevelopmentMode']) {
167 $this->mSmarty->force_compile = true;
168 }
169 }
170
171 public function renderBlock(&$target)
172 {
173 $this->mSmarty->template_dir = XOOPS_ROOT_PATH . '/modules/legacy/admin/templates';
174
175 foreach ($target->getAttributes() as $key => $value) {
176 $this->mSmarty->assign($key, $value);
177 }
178
179 $this->mSmarty->setModulePrefix($target->getAttribute('legacy_module'));
180 $result = $this->mSmarty->fetch('blocks/' . $target->getTemplateName());
181 $target->setResult($result);
182
183 //
184 // Reset
185 //
186 foreach ($target->getAttributes() as $key => $value) {
187 $this->mSmarty->clear_assign($key);
188 }
189 }
190
191 public function renderTheme(&$target)
192 {
193 //
194 // Assign from attributes of the render-target.
195 //
196 $smarty = $this->mSmarty;
197 $vars = ['stdout_buffer' =>$this->_mStdoutBuffer];
198 foreach ($target->getAttributes() as $key=>$value) {
199 $vars[$key] = $value;
200 }
201
202 //jQuery Ready functions
203 $context = $this->mController->mRoot->mContext;
204 XCube_DelegateUtils::call('Site.JQuery.AddFunction', new XCube_Ref($context->mAttributes['headerScript']));
205 $headerScript = $context->getAttribute('headerScript');
206 $moduleHeader = $headerScript->createLibraryTag() . $headerScript->createOnloadFunctionTag();
207 $vars['xoops_module_header'] = $moduleHeader;
208
209 //
210 // Get a virtual current module object from the controller and assign it.
211 //
212 $moduleObject =& $this->mController->getVirtualCurrentModule();
213 $vars['currentModule'] = $moduleObject;
214
215 //
216 // Other attributes
217 //
218 $vars['legacy_sitename'] = $context->getAttribute('legacy_sitename');
219 $vars['legacy_pagetitle'] = $context->getAttribute('legacy_pagetitle');
220 $vars['legacy_slogan'] = $context->getAttribute('legacy_slogan');
221
222 //
223 // Theme rendering
224 //
225 $blocks = [];
226 foreach ($context->mAttributes['legacy_BlockContents'][0] as $key => $result) {
227 // $smarty->append('xoops_lblocks', $result);
228 $blocks[$result['name']] = $result;
229 }
230 $vars['xoops_lblocks'] = $blocks;
231
232 $smarty->assign($vars);
233
234 //
235 // Check Theme or Fallback
236 //
237 $root =& XCube_Root::getSingleton();
238 $theme = $root->mSiteConfig['Legacy']['Theme'];
239
240 if (file_exists(XOOPS_ROOT_PATH.'/themes/'.$theme.'/admin_theme.html')) {
241 $smarty->template_dir=XOOPS_THEME_PATH.'/'.$theme;
242 } else {
243 $smarty->template_dir=LEGACY_ADMIN_RENDER_FALLBACK_PATH;
244 }
245
246 $smarty->setModulePrefix('');
247 $result=$smarty->fetch('file:admin_theme.html');
248
249 $target->setResult($result);
250 }
251
252 public function renderMain(&$target)
253 {
254 //
255 // Assign from attributes of the render-target.
256 //
257 foreach ($target->getAttributes() as $key=>$value) {
258 $this->mSmarty->assign($key, $value);
259 }
260
261 $result = null;
262
263 if ($target->getTemplateName()) {
264 if (null != $target->getAttribute('legacy_module')) {
265 $this->mSmarty->setModulePrefix($target->getAttribute('legacy_module'));
266 $this->mSmarty->template_dir = XOOPS_MODULE_PATH . '/' . $target->getAttribute('legacy_module') . '/admin/'. LEGACY_ADMIN_RENDER_TEMPLATE_DIRNAME;
267 }
268
269 $result=$this->mSmarty->fetch('file:'.$target->getTemplateName());
270 $buffer = $target->getAttribute('stdout_buffer');
271
272 $this->_mStdoutBuffer .= $buffer;
273 } else {
274 $result=$target->getAttribute('stdout_buffer');
275 }
276
277 $target->setResult($result);
278
279 //
280 // Clear assign.
281 //
282 foreach ($target->getAttributes() as $key=>$value) {
283 $this->mSmarty->clear_assign($key);
284 }
285 }
286}
287
288/***
289 * @param $string
290 * @return string
291 * @internal
292 * Return URL string by "overriding" rule.
293 * (Now, test implement)
294 * 1) Search file in specified theme directory.
295 * 2) Search file in current module template directory.
296 * 3) Search file in fallback theme directory.
297 */
298function Legacy_modifier_theme($string)
299{
300 $infoArr = Legacy_get_override_file($string);
301
302 if (null != $infoArr['theme'] && null != $infoArr['dirname']) {
303 return XOOPS_THEME_URL . '/' . $infoArr['theme'] . '/templates/' . $infoArr['dirname'] . '/' . $string; // XCL 2.3.x changed /modules/ to /templates/
304 } elseif (null != $infoArr['theme']) {
305 return XOOPS_THEME_URL . '/' . $infoArr['theme'] . '/' . $string;
306 } elseif (null != $infoArr['dirname']) {
307 return XOOPS_MODULE_URL . '/' . $infoArr['dirname'] . '/admin/templates/' . $string;
308 }
309
310 return LEGACY_ADMIN_RENDER_FALLBACK_URL . '/' . $string;
311}
312
313function Legacy_function_stylesheet($params, &$smarty)
314{
315 $request = [];
316 if (!isset($params['file'])) {
317 $smarty->trigger_error('stylesheet: missing file parameter.');
318 return;
319 }
320
321 $file = $params['file'];
322
323 if (false !== strstr($file, '..')) {
324 $smarty->trigger_error('stylesheet: missing file parameter.');
325 return;
326 }
327
328 $media = $params['media'] ?? 'all';
329
330 $infoArr = Legacy_get_override_file($file, 'stylesheets/');
331
332 // TEMP
333 // XCL 2.3.x changed /modules/ to /templates/
334 // TODO We must return FALLBACK_URL here.
335 if (null != $infoArr['file']) {
336 if ($params['static']) {
337 $theme=$infoArr['theme'];
338 $dirname=$infoArr['dirname'];
339 $file='stylesheets/'.$file;
340 if (!empty($theme) && !empty($dirname)) {
341 $url = XOOPS_THEME_URL . "/$theme/templates/$dirname/$file"; // XCL 2.3.x changed /modules/ to /templates/
342 } elseif (!empty($theme)) {
343 $url = XOOPS_THEME_URL . "/$theme/$file";
344 } elseif (!empty($infoArr['dirname'])) {
345 $url = XOOPS_MODULE_URL . "/$dirname/admin/templates/$file";
346 } else {
347 $url = LEGACY_ADMIN_RENDER_FALLBACK_URL . "/$file";
348 }
349 } else {
350 if (null != $infoArr['file']) {
351 $request = [];
352 foreach ($infoArr as $key => $value) {
353 if (null != $value) {
354 $request[] = "{$key}={$value}";
355 }
356 }
357 }
358 $url = XOOPS_MODULE_URL . '/legacyRender/admin/css.php?' . implode('&amp;', $request);
359 }
360
361 return '<link rel="stylesheet" type="text/css" media="'. $media .'" href="' . $url . '" />';
362 }
363}
364
365function Legacy_get_override_file($file, $prefix = null, $isSpDirname = false)
366{
367 $dirname = null;
368 $root =& XCube_Root::getSingleton();
369 $moduleObject =& $root->mContext->mXoopsModule;
370
371 if ($isSpDirname && is_object($moduleObject) && 'legacy' == $moduleObject->get('dirname') && isset($_REQUEST['dirname'])) {
372// TODO test this
373//$dirname = xoops_getrequest('dirname');
374 $root->mContext->mRequest->getRequest($dirname);
375 if (preg_match('/^[a-z0-9_]+$/i', $dirname)) {
376 $handler = xoops_gethandler('module');
377 $moduleObject =& $handler->getByDirname($dirname);
378 }
379 }
380
381 $theme = $root->mSiteConfig['Legacy']['Theme'];
382
383 $ret = [];
384 $ret['theme'] = $theme;
385 $ret['file'] = $file;
386
387 $file = $prefix . $file;
388
389 static $checkCache = [];
390 if (isset($checkCache[$file])) {
391 return $checkCache[$file];
392 }
393
394 $themePath = XOOPS_THEME_PATH . '/' . $theme . '/';
395 if (!is_object($moduleObject)) {
396 if (file_exists($themePath. $file)) {
397 return $checkCache[$file] = &$ret;
398 }
399
400 $ret['theme'] = null;
401 return $checkCache[$file] = &$ret;
402 } else {
403 $ret['dirname'] = $dirname = $moduleObject->get('dirname');
404
405 $mfile = $dirname . '/' . $file;
406 if (isset($checkCache[$mfile])) {
407 return $checkCache[$mfile];
408 }
409 if (file_exists($themePath.'modules/'.$mfile)) {
410 return $checkCache[$mfile] = &$ret;
411 }
412
413 if (file_exists($themePath. $file)) {
414 $ret['dirname'] = null;
415 return $checkCache[$mfile] = &$ret;
416 }
417
418 $ret['theme'] = null;
419
420 if (file_exists(XOOPS_MODULE_PATH . '/' . $dirname . '/admin/templates/' . $file)) {
421 return $checkCache[$mfile] = &$ret;
422 }
423
424 $ret['dirname'] = null;
425
426 if (file_exists(LEGACY_ADMIN_RENDER_FALLBACK_PATH . '/' . $file)) {
427
428 return $checkCache[$mfile] = &$ret;
429 }
430
431 $ret['file'] =null;
432 return $checkCache[$mfile] = &$ret;
433 }
434}
The specific FILE-TYPE render-system.
This allows you to directly manage the theme and the main rendering target. And, this implements the ...