/** * Render the page * The theme engine builds pages from 2 templates: canvas and content. * A module can call this method directly and specify what templates the theme engine must use. * If render() hasn't been called before, the theme defaults will be used for the canvas and * page template (and xoopsOption['template_main'] for the content). * * @param string $canvasTpl The canvas template, if different from the theme default * @param string $pageTpl The page template, if different from the theme default (unsupported, 2.3+ only) * @param string $contentTpl The content template * @param array $vars Template variables to send to the template engine * * @return bool */ public function render($canvasTpl = null, $pageTpl = null, $contentTpl = null, $vars = array()) { if ($this->renderCount) { return false; } $xoops = \Xoops::getInstance(); $xoops->events()->triggerEvent('core.theme.render.start', array($this)); $cache = $xoops->cache($this->headersCacheEngine); //Get meta information for cached pages if ($this->contentCacheLifetime && $this->contentCacheId && ($content = $cache->read($this->contentCacheId))) { //we need to merge metas set by blocks with the module cached meta $this->htmlHeadStrings = array_merge($this->htmlHeadStrings, $content['htmlHeadStrings']); foreach ($content['metas'] as $type => $value) { $this->metas[$type] = array_merge($this->metas[$type], $content['metas'][$type]); } $xoops->setOption('xoops_pagetitle', $content['xoops_pagetitle']); $xoops->setOption('xoops_module_header', $content['header']); } if ($xoops->getOption('xoops_pagetitle')) { $this->template->assign('xoops_pagetitle', $xoops->getOption('xoops_pagetitle')); } $header = !$xoops->getOption('xoops_module_header') ? $this->template->getTemplateVars('xoops_module_header') : $xoops->getOption('xoops_module_header'); //save meta information of cached pages if ($this->contentCacheLifetime && $this->contentCacheId && !$contentTpl) { $content['htmlHeadStrings'] = (array) $this->htmlHeadStrings; $content['metas'] = (array) $this->metas; $content['xoops_pagetitle'] = $this->template->getTemplateVars('xoops_pagetitle'); $content['header'] = $header; $cache->write($this->contentCacheId, $content); } // @internal : Lame fix to ensure the metas specified in the xoops config page don't appear twice $old = array('robots', 'keywords', 'description', 'rating', 'author', 'copyright'); foreach ($this->metas['meta'] as $name => $value) { if (in_array($name, $old)) { $this->template->assign("xoops_meta_{$name}", htmlspecialchars($value, ENT_QUOTES)); unset($this->metas['meta'][$name]); } } // We assume no overlap between $GLOBALS['xoopsOption']['xoops_module_header'] and // $this->template->getTemplateVars( 'xoops_module_header' ) ? $this->template->assign('xoops_module_header', $this->renderMetas(true) . "\n" . $header); if ($canvasTpl) { $this->canvasTemplate = $canvasTpl; } if ($contentTpl) { $this->contentTemplate = $contentTpl; } if (!empty($vars)) { $this->template->assign($vars); } if ($this->contentTemplate) { $this->content = $this->template->fetch($this->contentTemplate, $this->contentCacheId); } if ($this->bufferOutput) { $this->content .= ob_get_contents(); ob_end_clean(); } $this->template->assignByRef('xoops_contents', $this->content); // Do not cache the main (theme.html) template output $this->template->caching = 0; if (false === (bool) $xoops->getConfig('disable_theme_shortcodes')) { $this->template->loadFilter('output', 'shortcodes'); } $this->template->display($this->path . '/' . $this->canvasTemplate); $this->renderCount++; $xoops->events()->triggerEvent('core.theme.render.end', array($this)); return true; }