1: <?php
2: 3: 4:
5:
6: if (!defined('XOOPS_ROOT_PATH')) exit();
7:
8:
9:
10:
11: require_once XOOPS_ROOT_PATH . '/modules/legacyRender/kernel/Legacy_RenderSystem.class.php';
12:
13: define('LEGACY_ADMIN_RENDER_TEMPLATE_DIRNAME', 'templates');
14:
15: define('LEGACY_ADMIN_RENDER_FALLBACK_PATH', XOOPS_MODULE_PATH . '/legacy/admin/theme');
16: define('LEGACY_ADMIN_RENDER_FALLBACK_URL', XOOPS_MODULE_URL . '/legacy/admin/theme');
17:
18: require_once SMARTY_DIR.'/Smarty.class.php';
19:
20: 21: 22: 23: 24: 25:
26: class Legacy_AdminSmarty extends Smarty
27: {
28: var $mModulePrefix = null;
29:
30:
31:
32:
33: var $overrideMode = true;
34:
35: function Legacy_AdminSmarty()
36: {
37: parent::Smarty();
38:
39: $this->compile_id = XOOPS_URL;
40: $this->_canUpdateFromFile = true;
41: $this->compile_check = true;
42: $this->compile_dir = XOOPS_COMPILE_PATH;
43: $this->left_delimiter = '<{';
44: $this->right_delimiter = '}>';
45: $this->plugins_dir = array(SMARTY_DIR.'plugins', XOOPS_ROOT_PATH.'/class/smarty/plugins');
46:
47:
48:
49:
50:
51:
52:
53: $this->force_compile = false;
54: }
55:
56: function setModulePrefix($prefix)
57: {
58: $this->mModulePrefix = $prefix;
59: }
60:
61: function _get_auto_filename($autoBase, $autoSource = null, $auotId = null)
62: {
63: $autoSource = $this->mModulePrefix . '_admin_' . $autoSource;
64: return parent::_get_auto_filename($autoBase, $autoSource, $auotId);
65: }
66:
67: function _fetch_resource_info(&$params)
68: {
69: $_return = false;
70:
71: $root =& XCube_Root::getSingleton();
72: $theme = $root->mSiteConfig['Legacy']['Theme'];
73: $dirname = $this->mModulePrefix;
74:
75: if ($dirname != null) {
76: $params['resource_base_path'] = XOOPS_THEME_PATH . '/' . $theme . '/modules/' . $dirname;
77: $params['quiet'] = true;
78:
79: $_return = parent::_fetch_resource_info($params);
80: }
81:
82: if (!$_return) {
83: unset ($params['resource_base_path']);
84: $params['quiet'] = false;
85:
86: $_return = parent::_fetch_resource_info($params);
87: }
88:
89: return $_return;
90: }
91:
92: }
93:
94: 95: 96: 97:
98: class Legacy_AdminRenderSystem extends Legacy_RenderSystem
99: {
100: var $mController;
101: var $mSmarty;
102:
103: 104: 105: 106: 107: 108: 109:
110: var $_mStdoutBuffer = null;
111:
112: function prepare(&$controller)
113: {
114: $this->mController =& $controller;
115:
116: $this->mSmarty =new Legacy_AdminSmarty();
117: $this->mSmarty->register_modifier('theme', 'Legacy_modifier_theme');
118: $this->mSmarty->register_function('stylesheet', 'Legacy_function_stylesheet');
119:
120: $this->mSmarty->assign(array(
121: 'xoops_url' => XOOPS_URL,
122: 'xoops_rootpath' => XOOPS_ROOT_PATH,
123: 'xoops_langcode' => _LANGCODE,
124: 'xoops_charset' => _CHARSET,
125: 'xoops_version' => XOOPS_VERSION,
126: 'xoops_upload_url' => XOOPS_UPLOAD_URL)
127: );
128:
129: if ($controller->mRoot->mSiteConfig['Legacy_AdminRenderSystem']['ThemeDevelopmentMode'] == true) {
130: $this->mSmarty->force_compile = true;
131: }
132: }
133:
134: function renderBlock(&$target)
135: {
136: $this->mSmarty->template_dir = XOOPS_ROOT_PATH . '/modules/legacy/admin/templates';
137:
138: foreach ($target->getAttributes() as $key => $value) {
139: $this->mSmarty->assign($key, $value);
140: }
141:
142: $this->mSmarty->setModulePrefix($target->getAttribute('legacy_module'));
143: $result = $this->mSmarty->fetch('blocks/' . $target->getTemplateName());
144: $target->setResult($result);
145:
146:
147:
148:
149: foreach($target->getAttributes() as $key => $value) {
150: $this->mSmarty->clear_assign($key);
151: }
152: }
153:
154: function renderTheme(&$target)
155: {
156:
157:
158:
159: $smarty = $this->mSmarty;
160: $vars = array('stdout_buffer'=>$this->_mStdoutBuffer);
161: foreach($target->getAttributes() as $key=>$value) {
162: $vars[$key] = $value;
163: }
164:
165:
166: $context = $this->mController->mRoot->mContext;
167: XCube_DelegateUtils::call('Site.JQuery.AddFunction', new XCube_Ref($context->mAttributes['headerScript']));
168: $headerScript = $context->getAttribute('headerScript');
169: $moduleHeader = $headerScript->createLibraryTag() . $headerScript->createOnloadFunctionTag();
170: $vars['xoops_module_header'] = $moduleHeader;
171:
172:
173:
174:
175: $moduleObject =& $this->mController->getVirtualCurrentModule();
176: $vars['currentModule'] = $moduleObject;
177:
178:
179:
180:
181: $vars['legacy_sitename'] = $context->getAttribute('legacy_sitename');
182: $vars['legacy_pagetitle'] = $context->getAttribute('legacy_pagetitle');
183: $vars['legacy_slogan'] = $context->getAttribute('legacy_slogan');
184:
185:
186:
187:
188: $blocks = array();
189: foreach($context->mAttributes['legacy_BlockContents'][0] as $key => $result) {
190:
191: $blocks[$result['name']] = $result;
192: }
193: $vars['xoops_lblocks'] = $blocks;
194:
195: $smarty->assign($vars);
196:
197:
198:
199:
200: $root =& XCube_Root::getSingleton();
201: $theme = $root->mSiteConfig['Legacy']['Theme'];
202:
203: if (file_exists(XOOPS_ROOT_PATH.'/themes/'.$theme.'/admin_theme.html')) {
204: $smarty->template_dir=XOOPS_THEME_PATH.'/'.$theme;
205: }
206: else {
207: $smarty->template_dir=LEGACY_ADMIN_RENDER_FALLBACK_PATH;
208: }
209:
210: $smarty->setModulePrefix('');
211: $result=$smarty->fetch('file:admin_theme.html');
212:
213: $target->setResult($result);
214: }
215:
216: function renderMain(&$target)
217: {
218:
219:
220:
221: foreach ($target->getAttributes() as $key=>$value) {
222: $this->mSmarty->assign($key, $value);
223: }
224:
225: $result = null;
226:
227: if ($target->getTemplateName()) {
228: if ($target->getAttribute('legacy_module') != null) {
229: $this->mSmarty->setModulePrefix($target->getAttribute('legacy_module'));
230: $this->mSmarty->template_dir = XOOPS_MODULE_PATH . '/' . $target->getAttribute('legacy_module') . '/admin/'. LEGACY_ADMIN_RENDER_TEMPLATE_DIRNAME;
231: }
232:
233: $result=$this->mSmarty->fetch('file:'.$target->getTemplateName());
234: $buffer = $target->getAttribute('stdout_buffer');
235:
236: $this->_mStdoutBuffer .= $buffer;
237: }
238: else {
239: $result=$target->getAttribute('stdout_buffer');
240: }
241:
242: $target->setResult($result);
243:
244:
245:
246:
247: foreach ($target->getAttributes() as $key=>$value) {
248: $this->mSmarty->clear_assign($key);
249: }
250: }
251: }
252:
253: 254: 255: 256: 257: 258: 259: 260:
261: function Legacy_modifier_theme($string)
262: {
263: $infoArr = Legacy_get_override_file($string);
264:
265: if ($infoArr['theme'] != null && $infoArr['dirname'] != null) {
266: return XOOPS_THEME_URL . '/' . $infoArr['theme'] . '/modules/' . $infoArr['dirname'] . '/' . $string;
267: }
268: elseif ($infoArr['theme'] != null) {
269: return XOOPS_THEME_URL . '/' . $infoArr['theme'] . '/' . $string;
270: }
271: elseif ($infoArr['dirname'] != null) {
272: return XOOPS_MODULE_URL . '/' . $infoArr['dirname'] . '/admin/templates/' . $string;
273: }
274:
275: return LEGACY_ADMIN_RENDER_FALLBACK_URL . '/' . $string;
276: }
277:
278: function Legacy_function_stylesheet($params, &$smarty)
279: {
280: if (!isset($params['file'])) {
281: $smarty->trigger_error('stylesheet: missing file parameter.');
282: return;
283: }
284:
285: $file = $params['file'];
286:
287: if (strstr($file, '..') !== false) {
288: $smarty->trigger_error('stylesheet: missing file parameter.');
289: return;
290: }
291:
292: $media = (isset($params['media'])) ? $params['media'] : 'all';
293:
294: $infoArr = Legacy_get_override_file($file, 'stylesheets/');
295:
296:
297:
298: if ($infoArr['file'] != null) {
299: if ($params['static']) {
300: $theme=$infoArr['theme'];
301: $dirname=$infoArr['dirname'];
302: $file='stylesheets/'.$file;
303: if (!empty($theme) && !empty($dirname)) {
304: $url = XOOPS_THEME_URL . "/$theme/modules/$dirname/$file";
305: } elseif (!empty($theme)) {
306: $url = XOOPS_THEME_URL . "/$theme/$file";
307: }
308: elseif (!empty($infoArr['dirname'])) {
309: $url = XOOPS_MODULE_URL . "/$dirname/admin/templates/$file";
310: } else {
311: $url = LEGACY_ADMIN_RENDER_FALLBACK_URL . "/$file";
312: }
313: } else {
314: if ($infoArr['file'] != null) {
315: $request = array();
316: foreach ($infoArr as $key => $value) {
317: if ($value != null) {
318: $request[] = "${key}=${value}";
319: }
320: }
321: }
322: $url = XOOPS_MODULE_URL . '/legacyRender/admin/css.php?' . implode('&', $request);
323: }
324:
325: return '<link rel="stylesheet" type="text/css" media="'. $media .'" href="' . $url . '" />';
326: }
327: }
328:
329: function Legacy_get_override_file($file, $prefix = null, $isSpDirname = false)
330: {
331: $root =& XCube_Root::getSingleton();
332: $moduleObject =& $root->mContext->mXoopsModule;
333:
334: if ($isSpDirname && is_object($moduleObject) && $moduleObject->get('dirname') == 'legacy' && isset($_REQUEST['dirname'])) {
335: $dirname = xoops_getrequest('dirname');
336: if (preg_match('/^[a-z0-9_]+$/i', $dirname)) {
337: $handler = xoops_gethandler('module');
338: $moduleObject =& $handler->getByDirname($dirname);
339: }
340: }
341:
342: $theme = $root->mSiteConfig['Legacy']['Theme'];
343:
344: $ret = array();
345: $ret['theme'] = $theme;
346: $ret['file'] = $file;
347:
348: $file = $prefix . $file;
349:
350: static $checkCache = array();
351: if (isset($checkCache[$file])) return $checkCache[$file];
352:
353: $themePath = XOOPS_THEME_PATH . '/' . $theme . '/';
354: if (!is_object($moduleObject)) {
355: if (file_exists($themePath. $file)) {
356: return $checkCache[$file] = &$ret;
357: }
358:
359: $ret['theme'] = null;
360: return $checkCache[$file] = &$ret;
361: }
362: else {
363: $ret['dirname'] = $dirname = $moduleObject->get('dirname');
364:
365: $mfile = $dirname . '/' . $file;
366: if (isset($checkCache[$mfile])) return $checkCache[$mfile];
367: if (file_exists($themePath.'modules/'.$mfile)) {
368: return $checkCache[$mfile] = &$ret;
369: }
370:
371: if (file_exists($themePath. $file)) {
372: $ret['dirname'] = null;
373: return $checkCache[$mfile] = &$ret;
374: }
375:
376: $ret['theme'] = null;
377:
378: if (file_exists(XOOPS_MODULE_PATH . '/' . $dirname . '/admin/templates/' . $file)) {
379: return $checkCache[$mfile] = &$ret;
380: }
381:
382: $ret['dirname'] = null;
383:
384: if (file_exists(LEGACY_ADMIN_RENDER_FALLBACK_PATH . '/' . $file)) {
385: return $checkCache[$mfile] = &$ret;
386: }
387:
388: $ret['file'] =null;
389: return $checkCache[$mfile] = &$ret;
390: }
391: }
392:
393: ?>
394: