/** * xos_logos_PageBuilder::buildBlock() * * @param mixed $xobject * @param mixed $template * @return */ function buildBlock($xobject, &$template) { // The lame type workaround will change // bid is added temporarily as workaround for specific block manipulation $block = array('id' => $xobject->getVar('bid'), 'module' => $xobject->getVar('dirname'), 'title' => $xobject->getVar('title'), 'weight' => $xobject->getVar('weight'), 'lastmod' => $xobject->getVar('last_modified')); $bcachetime = intval($xobject->getVar('bcachetime')); if (empty($bcachetime)) { $template->caching = 0; } else { $template->caching = 2; $template->cache_lifetime = $bcachetime; } $template->setCompileId($xobject->getVar('dirname', 'n')); $tplName = ($tplName = $xobject->getVar('template')) ? "db:{$tplName}" : 'db:system_block_dummy.html'; $cacheid = $this->generateCacheId('blk_' . $xobject->getVar('bid')); $xoopsLogger =& XoopsLogger::getInstance(); if (!$bcachetime || !$template->is_cached($tplName, $cacheid)) { //Get theme metas if ($this->theme && $bcachetime) { foreach ($this->theme->metas as $type => $value) { $old[$type] = $this->theme->metas[$type]; } } //build block $xoopsLogger->addBlock($xobject->getVar('name')); if ($bresult = $xobject->buildBlock()) { $template->assign('block', $bresult); $block['content'] = $template->fetch($tplName, $cacheid); } else { $block = false; } //check if theme added new metas if ($this->theme && $bcachetime) { $metas = array(); foreach ($this->theme->metas as $type => $value) { $dif = array_diff_assoc($this->theme->metas[$type], $old[$type]); if (count($dif)) { $metas[$type] = $dif; } } if (count($metas)) { xoops_load('xoopscache'); $cache =& XoopsCache::getInstance(); $cache->write($cacheid, $metas); } } } else { $xoopsLogger->addBlock($xobject->getVar('name'), true, $bcachetime); $block['content'] = $template->fetch($tplName, $cacheid); } //add block cached metas if ($this->theme && $bcachetime) { xoops_load('xoopscache'); $cache =& XoopsCache::getInstance(); if ($metas = $cache->read($cacheid)) { foreach ($metas as $type => $value) { $this->theme->metas[$type] = array_merge($this->theme->metas[$type], $metas[$type]); } } } $template->setCompileId(); return $block; }
/** * 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; } $xoopsLogger = XoopsLogger::getInstance(); $xoopsLogger->startTime('Page rendering'); xoops_load('xoopscache'); $cache = XoopsCache::getInstance(); //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]); } $GLOBALS['xoopsOption']['xoops_pagetitle'] = $content['xoops_pagetitle']; $GLOBALS['xoopsOption']['xoops_module_header'] = $content['header']; } if (!empty($GLOBALS['xoopsOption']['xoops_pagetitle'])) { $this->template->assign('xoops_pagetitle', $GLOBALS['xoopsOption']['xoops_pagetitle']); } $header = empty($GLOBALS['xoopsOption']['xoops_module_header']) ? $this->template->get_template_vars('xoops_module_header') : $GLOBALS['xoopsOption']['xoops_module_header']; //save meta information of cached pages if ($this->contentCacheLifetime && $this->contentCacheId && !$contentTpl) { $content['htmlHeadStrings'] = $this->htmlHeadStrings; $content['metas'] = $this->metas; $content['xoops_pagetitle'] =& $this->template->get_template_vars('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->get_template_vars( 'xoops_module_header' ) ? $this->template->assign('xoops_module_header', $this->renderMetas(null, 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->assign_by_ref('xoops_contents', $this->content); // Do not cache the main (theme.html) template output $this->template->caching = 0; //mb ------------------------- // $this->template->display($this->path . '/' . $this->canvasTemplate); if (file_exists($this->path . '/' . $this->canvasTemplate)) { $this->template->display($this->path . '/' . $this->canvasTemplate); } else { $this->template->display($this->path . '/theme.tpl'); } //mb ------------------------- $this->renderCount++; $xoopsLogger->stopTime('Page rendering'); return true; }
/** * Return the settings for current cache engine * * @param string $engine Name of the engine * @return array list of settings for this engine * @access public */ function settings($engine = null) { $_this =& XoopsCache::getInstance(); if (!$engine && isset($_this->configs[$_this->name]['engine'])) { $engine = $_this->configs[$_this->name]['engine']; } if (isset($_this->engine[$engine]) && !is_null($_this->engine[$engine])) { return $_this->engine[$engine]->settings(); } return array(); }
/** * Initialize parent::__construct calls this after verifying module object. * * @return void */ public function init() { \XoopsLoad::load('xoopscache'); $this->prefix = $this->module->getVar('dirname') . '_'; $this->cache = \XoopsCache::getInstance(); }