1: <?php
2: 3: 4:
5:
6: if (!defined('XOOPS_ROOT_PATH')) exit();
7:
8: require_once XOOPS_ROOT_PATH.'/modules/legacyRender/kernel/Legacy_RenderTarget.class.php';
9: require_once XOOPS_ROOT_PATH . '/class/template.php';
10:
11: 12: 13: 14:
15: define('LEGACY_RENDERSYSTEM_BANNERSETUP_BEFORE', false);
16:
17: 18: 19: 20: 21:
22: class Legacy_XoopsTpl extends XoopsTpl
23: {
24: 25: 26: 27: 28:
29: var $_mContextReserve = array();
30:
31: function Legacy_XoopsTpl()
32: {
33: $this->_mContextReserve = array ('xoops_pagetitle' => 'legacy_pagetitle');
34: parent::XoopsTpl();
35: }
36:
37: function assign($tpl_var, $value = null)
38: {
39: if (is_array($tpl_var)){
40: $root =& XCube_Root::getSingleton();
41: $context = $root->mContext;
42: $reserve = $this->_mContextReserve;
43: foreach ($tpl_var as $key => $val) {
44: if ($key != '') {
45: if (isset($reserve[$key])) {
46: $context->setAttribute($reserve[$key], htmlspecialchars_decode($val));
47: }
48: $this->_tpl_vars[$key] = $val;
49: }
50: }
51: }
52: else {
53: if ($tpl_var) {
54: if (isset($this->_mContextReserve[$tpl_var])) {
55: $root =& XCube_Root::getSingleton();
56: $root->mContext->setAttribute($this->_mContextReserve[$tpl_var], htmlspecialchars_decode($value));
57: }
58: $this->_tpl_vars[$tpl_var] = $value;
59: }
60: }
61: }
62:
63: function assign_by_ref($tpl_var, &$value)
64: {
65: if ($tpl_var != '') {
66: if (isset($this->_mContextReserve[$tpl_var])) {
67: $root =& XCube_Root::getSingleton();
68: $root->mContext->setAttribute($this->_mContextReserve[$tpl_var], htmlspecialchars_decode($value));
69: }
70: $this->_tpl_vars[$tpl_var] =& $value;
71: }
72: }
73:
74: function &get_template_vars($name = null)
75: {
76: $root =& XCube_Root::getSingleton();
77: if (!isset($name)) {
78: foreach ($this->_mContextReserve as $t_key => $t_value) {
79: if (isset($this->_mContextReserve[$t_value])) {
80: $this->_tpl_vars[$t_key] = htmlspecialchars($root->mContext->getAttribute($this->_mContextReserve[$t_value]), ENT_QUOTES);
81: }
82: }
83: $value =& parent::get_template_vars($name);
84: }
85: elseif (isset($this->_mContextReserve[$name])) {
86: $value = htmlspecialchars($root->mContext->getAttribute($this->_mContextReserve[$name]), ENT_QUOTES);
87: }
88: else {
89: $value =& parent::get_template_vars($name);
90: }
91: return $value;
92: }
93: }
94:
95: 96: 97: 98: 99: 100:
101: class Legacy_RenderSystem extends XCube_RenderSystem
102: {
103: var $mXoopsTpl;
104:
105: 106: 107:
108: var $mThemeRenderTarget;
109:
110: 111: 112:
113: var $mMainRenderTarget;
114:
115: var $_mContentsData = null;
116:
117: 118: 119:
120: var $mSetupXoopsTpl = null;
121:
122: 123: 124:
125: var $_mIsActiveBanner = false;
126:
127: var $mBeginRender = null;
128:
129: function Legacy_RenderSystem()
130: {
131: parent::XCube_RenderSystem();
132: $this->mSetupXoopsTpl =new XCube_Delegate();
133: $this->mSetupXoopsTpl->register('Legacy_RenderSystem.SetupXoopsTpl');
134:
135: $this->mBeginRender =new XCube_Delegate();
136: $this->mBeginRender->register('Legacy_RenderSystem.BeginRender');
137: }
138:
139: function prepare(&$controller)
140: {
141: parent::prepare($controller);
142:
143: $root =& $this->mController->mRoot;
144: $context =& $root->getContext();
145: $textFilter =& $root->getTextFilter();
146:
147:
148: if ( isset($GLOBALS['xoopsTpl']) ) {
149: $this->mXoopsTpl =& $GLOBALS['xoopsTpl'];
150: } else {
151: $this->mXoopsTpl =new Legacy_XoopsTpl();
152: }
153: $mTpl = $this->mXoopsTpl;
154: $mTpl->register_function('legacy_notifications_select', 'LegacyRender_smartyfunction_notifications_select');
155: $this->mSetupXoopsTpl->call(new XCube_Ref($mTpl));
156:
157:
158: $GLOBALS['xoopsTpl'] =& $mTpl;
159:
160: $mTpl->xoops_setCaching(0);
161:
162:
163: if ($controller->mDebugger->isDebugRenderSystem()) {
164: $mTpl->xoops_setDebugging(true);
165: }
166:
167: $mTpl->assign(array('xoops_requesturi' => htmlspecialchars($GLOBALS['xoopsRequestUri'], ENT_QUOTES),
168:
169: 'xoops_js' => '//--></script><script type="text/javascript" src="'.XOOPS_URL.'/include/xoops.js"></script><script type="text/javascript"><!--'
170: ));
171:
172: $mTpl->assign('xoops_sitename', $textFilter->toShow($context->getAttribute('legacy_sitename')));
173: $mTpl->assign('xoops_pagetitle', $textFilter->toShow($context->getAttribute('legacy_pagetitle')));
174: $mTpl->assign('xoops_slogan', $textFilter->toShow($context->getAttribute('legacy_slogan')));
175:
176:
177:
178:
179: $moduleHandler = xoops_gethandler('module');
180: $legacyRender =& $moduleHandler->getByDirname('legacyRender');
181:
182: if (is_object($legacyRender)) {
183: $configHandler = xoops_gethandler('config');
184: $configs =& $configHandler->getConfigsByCat(0, $legacyRender->get('mid'));
185:
186:
187:
188:
189:
190: $this->_mIsActiveBanner = $configs['banners'];
191: if (LEGACY_RENDERSYSTEM_BANNERSETUP_BEFORE == true) {
192: if ($configs['banners'] == 1) {
193: $mTpl->assign('xoops_banner',xoops_getbanner());
194: }
195: else {
196: $mTpl->assign('xoops_banner',' ');
197: }
198: }
199: }
200: else {
201: $mTpl->assign('xoops_banner',' ');
202: }
203:
204:
205:
206:
207: $arr = null;
208: if (is_object($context->mXoopsUser)) {
209: $arr = array(
210: 'xoops_isuser' => true,
211: 'xoops_userid' => $context->mXoopsUser->getVar('uid', 'n'),
212: 'xoops_uname' => $context->mXoopsUser->getVar('uname')
213: );
214: }
215: else {
216: $arr = array(
217: 'xoops_isuser' => false
218: );
219: }
220:
221: $mTpl->assign($arr);
222: }
223:
224: function setAttribute($key,$value)
225: {
226: $this->mRenderTarget->setAttribute($key,$value);
227: }
228:
229: function getAttribute($key)
230: {
231: $this->mRenderTarget->getAttribute($key);
232: }
233:
234: 235: 236: 237:
238: function _commonPrepareRender()
239: {
240: $root =& $this->mController->mRoot;
241: $context =& $root->getContext();
242: $textFilter =& $root->getTextFilter();
243:
244: $themeName = $context->getThemeName();
245: $vars = array('xoops_theme'=>$themeName,
246: 'xoops_imageurl'=>XOOPS_THEME_URL . "/${themeName}/",
247: 'xoops_themecss'=>xoops_getcss($themeName),
248: 'xoops_sitename'=>$textFilter->toShow($context->getAttribute('legacy_sitename')),
249: 'xoops_pagetitle'=>$textFilter->toShow($context->getAttribute('legacy_pagetitle')),
250: 'xoops_slogan'=>$textFilter->toShow($context->getAttribute('legacy_slogan')));
251:
252:
253:
254:
255: if($context->mModule != null) {
256: $xoopsModule =& $context->mXoopsModule;
257: $vars['xoops_modulename'] = $xoopsModule->getVar('name');
258: $vars['xoops_dirname'] = $xoopsModule->getVar('dirname');
259: }
260:
261: if (isset($GLOBALS['xoopsUserIsAdmin'])) {
262: $vars['xoops_isadmin']=$GLOBALS['xoopsUserIsAdmin'];
263: }
264: $this->mXoopsTpl->assign($vars);
265: }
266:
267: function renderBlock(&$target)
268: {
269: $this->_commonPrepareRender();
270:
271:
272:
273:
274: $mTpl = $this->mXoopsTpl;
275: $mTpl->xoops_setCaching(0);
276:
277: $vars = $target->getAttributes();
278: $mTpl->assign($vars);
279:
280: $this->mBeginRender->call(new XCube_Ref($mTpl));
281: $result=&$mTpl->fetchBlock($target->getTemplateName(),$target->getAttribute('bid'));
282: $target->setResult($result);
283:
284:
285:
286:
287: $mTpl->clear_assign(array_keys($vars));
288: }
289:
290: function _render(&$target)
291: {
292: foreach($target->getAttributes() as $key=>$value) {
293: $this->mXoopsTpl->assign($key,$value);
294: }
295:
296: $this->mBeginRender->call(new XCube_Ref($this->mXoopsTpl), $target->getAttribute('legacy_buffertype'));
297: $result=$this->mXoopsTpl->fetch('db:'.$target->getTemplateName());
298: $target->setResult($result);
299:
300: foreach ($target->getAttributes() as $key => $value) {
301: $this->mXoopsTpl->clear_assign($key);
302: }
303: }
304:
305: function render(&$target)
306: {
307:
308:
309:
310: switch ($target->getAttribute('legacy_buffertype')) {
311: case XCUBE_RENDER_TARGET_TYPE_BLOCK:
312: $this->renderBlock($target);
313: break;
314:
315: case XCUBE_RENDER_TARGET_TYPE_MAIN:
316: $this->renderMain($target);
317: break;
318:
319: case XCUBE_RENDER_TARGET_TYPE_THEME:
320: $this->renderTheme($target);
321: break;
322:
323: case XCUBE_RENDER_TARGET_TYPE_BUFFER:
324: default:
325: break;
326: }
327: }
328:
329: function renderMain(&$target)
330: {
331: $this->_commonPrepareRender();
332:
333: $cachedTemplateId = isset($GLOBLAS['xoopsCachedTemplateId']) ? $GLOBLAS['xoopsCachedTemplateId'] : null;
334:
335: foreach($target->getAttributes() as $key=>$value) {
336: $this->mXoopsTpl->assign($key,$value);
337: }
338:
339: if ($target->getTemplateName()) {
340: if ($cachedTemplateId!==null) {
341: $contents=$this->mXoopsTpl->fetch('db:'.$target->getTemplateName(), $xoopsCachedTemplateId);
342: } else {
343: $contents=$this->mXoopsTpl->fetch('db:'.$target->getTemplateName());
344: }
345: } else {
346: if ($cachedTemplateId!==null) {
347: $this->mXoopsTpl->assign('dummy_content', $target->getAttribute('stdout_buffer'));
348: $contents=$this->mXoopsTpl->fetch($GLOBALS['xoopsCachedTemplate'], $xoopsCachedTemplateId);
349: } else {
350: $contents=$target->getAttribute('stdout_buffer');
351: }
352: }
353:
354: $target->setResult($contents);
355: }
356:
357: function renderTheme(&$target)
358: {
359: $this->_commonPrepareRender();
360:
361:
362: $mRoot = $this->mController->mRoot;
363: $mContext = $mRoot->mContext;
364: XCube_DelegateUtils::call('Site.JQuery.AddFunction', new XCube_Ref($mContext->mAttributes['headerScript']));
365: $headerScript = $mContext->getAttribute('headerScript');
366: $mTpl = $this->mXoopsTpl;
367: $moduleHeader = $mTpl->get_template_vars('xoops_module_header');
368: $moduleHeader = $headerScript->createLibraryTag() . $moduleHeader . $headerScript->createOnloadFunctionTag();
369:
370:
371:
372:
373: $vars = $target->getAttributes();
374: $vars['xoops_module_header'] = $moduleHeader;
375:
376: $moduleHandler = xoops_gethandler('module');
377: $legacyRender =& $moduleHandler->getByDirname('legacyRender');
378: $configHandler = xoops_gethandler('config');
379: $configs =& $configHandler->getConfigsByCat(0, $legacyRender->get('mid'));
380:
381: $textFilter =& $mRoot->getTextFilter();
382: $headerScript = $mContext->getAttribute('headerScript');
383: $vars['xoops_meta_keywords'] = $textFilter->toShow($headerScript->getMeta('keywords') ? $headerScript->getMeta('keywords') : $configs['meta_keywords']);
384: $vars['xoops_meta_description'] = $textFilter->toShow($headerScript->getMeta('description') ? $headerScript->getMeta('description') : $configs['meta_description']);
385: $vars['xoops_meta_robots'] = $textFilter->toShow($headerScript->getMeta('robots') ? $headerScript->getMeta('robots') : $configs['meta_robots']);
386: $vars['xoops_meta_rating'] = $textFilter->toShow($headerScript->getMeta('rating') ? $headerScript->getMeta('rating') : $configs['meta_rating']);
387: $vars['xoops_meta_author'] = $textFilter->toShow($headerScript->getMeta('author') ? $headerScript->getMeta('author') : $configs['meta_author']);
388: $vars['xoops_meta_copyright'] = $textFilter->toShow($headerScript->getMeta('copyright') ? $headerScript->getMeta('copyright') : $configs['meta_copyright']);
389: $vars['xoops_footer'] = $configs['footer'];
390:
391:
392:
393:
394:
395: if (LEGACY_RENDERSYSTEM_BANNERSETUP_BEFORE == false) {
396: $vars['xoops_banner'] = ($this->_mIsActiveBanner == 1)?xoops_getbanner():' ';
397: }
398:
399: $mTpl->assign($vars);
400:
401:
402:
403:
404:
405:
406:
407:
408:
409: $assignNameMap = array(
410: XOOPS_SIDEBLOCK_LEFT=>array('showflag'=>'xoops_showlblock','block'=>'xoops_lblocks'),
411: XOOPS_CENTERBLOCK_LEFT=>array('showflag'=>'xoops_showcblock','block'=>'xoops_clblocks'),
412: XOOPS_CENTERBLOCK_RIGHT=>array('showflag'=>'xoops_showcblock','block'=>'xoops_crblocks'),
413: XOOPS_CENTERBLOCK_CENTER=>array('showflag'=>'xoops_showcblock','block'=>'xoops_ccblocks'),
414: XOOPS_SIDEBLOCK_RIGHT=>array('showflag'=>'xoops_showrblock','block'=>'xoops_rblocks')
415: );
416:
417: foreach($assignNameMap as $key=>$val) {
418: $mTpl->assign($val['showflag'],$this->_getBlockShowFlag($val['showflag']));
419: if(isset($mContext->mAttributes['legacy_BlockContents'][$key])) {
420: foreach($mContext->mAttributes['legacy_BlockContents'][$key] as $result) {
421: $mTpl->append($val['block'], $result);
422: }
423: }
424: }
425:
426: $this->mBeginRender->call(new XCube_Ref($mTpl));
427:
428:
429:
430:
431: $result=null;
432: if($target->getAttribute('isFileTheme')) {
433: $result=$mTpl->fetch($target->getTemplateName().'/theme.html');
434: }
435: else {
436: $result=$mTpl->fetch('db:'.$target->getTemplateName());
437: }
438:
439: $result .= $mTpl->fetchDebugConsole();
440:
441: $target->setResult($result);
442: }
443:
444: function _getBlockShowFlag($area) {
445: switch($area) {
446: case 'xoops_showrblock' :
447: if (isset($GLOBALS['show_rblock']) && empty($GLOBALS['show_rblock'])) return 0;
448: return (!empty($this->mController->mRoot->mContext->mAttributes['legacy_BlockShowFlags'][XOOPS_SIDEBLOCK_RIGHT])) ? 1 : 0;
449: break;
450: case 'xoops_showlblock' :
451: if (isset($GLOBALS['show_lblock']) && empty($GLOBALS['show_lblock'])) return 0;
452: return (!empty($this->mController->mRoot->mContext->mAttributes['legacy_BlockShowFlags'][XOOPS_SIDEBLOCK_LEFT])) ? 1 : 0;
453: break;
454: case 'xoops_showcblock' :
455: if (isset($GLOBALS['show_cblock']) && empty($GLOBALS['show_cblock'])) return 0;
456: return (!empty($this->mController->mRoot->mContext->mAttributes['legacy_BlockShowFlags'][XOOPS_CENTERBLOCK_LEFT])||
457: !empty($this->mController->mRoot->mContext->mAttributes['legacy_BlockShowFlags'][XOOPS_CENTERBLOCK_RIGHT])||
458: !empty($this->mController->mRoot->mContext->mAttributes['legacy_BlockShowFlags'][XOOPS_CENTERBLOCK_CENTER])) ? 1 : 0;
459: break;
460: default :
461: return 0;
462: }
463: }
464:
465:
466:
467:
468:
469: 470: 471:
472: function sendHeader()
473: {
474: header('Content-Type:text/html; charset='._CHARSET);
475: header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
476: header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
477: header('Cache-Control: no-store, no-cache, must-revalidate');
478: header('Cache-Control: post-check=0, pre-check=0', false);
479: header('Pragma: no-cache');
480: }
481:
482: 483: 484:
485: function showXoopsHeader($closeHead=true)
486: {
487: global $xoopsConfig;
488: $myts =& MyTextSanitizer::getInstance();
489: if ($xoopsConfig['gzip_compression'] == 1) {
490: ob_start('ob_gzhandler');
491: } else {
492: ob_start();
493: }
494:
495: $this->sendHeader();
496: $this->_renderHeader($closeHead);
497: }
498:
499:
500: 501: 502:
503: function _renderHeader($closehead=true)
504: {
505: global $xoopsConfig, $xoopsTheme, $xoopsConfigMetaFooter;
506:
507: echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
508:
509: echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'._LANGCODE.'" lang="'._LANGCODE.'">
510: <head>
511: <meta http-equiv="content-type" content="text/html; charset='._CHARSET.'" />
512: <meta http-equiv="content-language" content="'._LANGCODE.'" />
513: <meta name="robots" content="'.htmlspecialchars($xoopsConfigMetaFooter['meta_robots']).'" />
514: <meta name="keywords" content="'.htmlspecialchars($xoopsConfigMetaFooter['meta_keywords']).'" />
515: <meta name="description" content="'.htmlspecialchars($xoopsConfigMetaFooter['meta_desc']).'" />
516: <meta name="rating" content="'.htmlspecialchars($xoopsConfigMetaFooter['meta_rating']).'" />
517: <meta name="author" content="'.htmlspecialchars($xoopsConfigMetaFooter['meta_author']).'" />
518: <meta name="copyright" content="'.htmlspecialchars($xoopsConfigMetaFooter['meta_copyright']).'" />
519: <meta name="generator" content="XOOPS" />
520: <title>'.htmlspecialchars($xoopsConfig['sitename']).'</title>
521: <script type="text/javascript" src="'.XOOPS_URL.'/include/xoops.js"></script>
522: ';
523: $themecss = getcss($xoopsConfig['theme_set']);
524: echo '<link rel="stylesheet" type="text/css" media="all" href="'.XOOPS_URL.'/xoops.css" />';
525: if ($themecss) {
526: echo '<link rel="stylesheet" type="text/css" media="all" href="'.$themecss.'" />';
527:
528: }
529: if ($closehead) {
530: echo '</head><body>';
531: }
532: }
533:
534: 535: 536:
537: function _renderFooter()
538: {
539: echo '</body></html>';
540: ob_end_flush();
541: }
542:
543: 544: 545:
546: function showXoopsFooter()
547: {
548: $this->_renderFooter();
549: }
550:
551: function &createRenderTarget($type = LEGACY_RENDER_TARGET_TYPE_MAIN, $option = null)
552: {
553: $renderTarget = null;
554: switch ($type) {
555: case XCUBE_RENDER_TARGET_TYPE_MAIN:
556: $renderTarget =new Legacy_RenderTargetMain();
557: break;
558:
559: case LEGACY_RENDER_TARGET_TYPE_BLOCK:
560: $renderTarget =new XCube_RenderTarget();
561: $renderTarget->setAttribute('legacy_buffertype', LEGACY_RENDER_TARGET_TYPE_BLOCK);
562: break;
563:
564: default:
565: $renderTarget =new XCube_RenderTarget();
566: break;
567: }
568:
569: return $renderTarget;
570: }
571:
572: 573: 574:
575: function &getThemeRenderTarget($isDialog = false)
576: {
577: $screenTarget = $isDialog ? new Legacy_DialogRenderTarget() : new Legacy_ThemeRenderTarget();
578: return $screenTarget;
579: }
580: }
581:
582: function LegacyRender_smartyfunction_notifications_select($params, &$smarty)
583: {
584: $root =& XCube_Root::getSingleton();
585: $renderSystem =& $root->getRenderSystem('Legacy_RenderSystem');
586:
587: $renderTarget =& $renderSystem->createRenderTarget('main');
588: $renderTarget->setTemplateName('legacy_notification_select_form.html');
589:
590: XCube_DelegateUtils::call('Legacyfunction.Notifications.Select', new XCube_Ref($renderTarget));
591:
592: $renderSystem->render($renderTarget);
593:
594: return $renderTarget->getResult();
595: }
596:
597: ?>
598: