Exemplo n.º 1
0
 /**
  * Blocks::buildBlock()
  *
  * @param XoopsBlock $xobject  block to render
  * @param XoopsTpl   $template template engine
  *
  * @return array|bool
  */
 public function buildBlock(XoopsBlock $xobject, XoopsTpl $template)
 {
     $xoops = \Xoops::getInstance();
     // The lame type workaround will change
     // bid is added temporarily as workaround for specific block manipulation
     $dirname = $xobject->getVar('dirname');
     $block = array('id' => $xobject->getVar('bid'), 'module' => $dirname, 'title' => $xobject->getVar('title'), 'weight' => $xobject->getVar('weight'), 'lastmod' => $xobject->getVar('last_modified'));
     $bcachetime = (int) $xobject->getVar('bcachetime');
     if (empty($bcachetime)) {
         $template->caching = 0;
     } else {
         $template->caching = 2;
         $template->cache_lifetime = $bcachetime;
     }
     $template->setCompileId($dirname);
     $tplName = ($tplName = $xobject->getVar('template')) ? "block:{$dirname}/{$tplName}" : "module:system/system_block_dummy.tpl";
     //$tplName = str_replace('.html', '.tpl', $tplName);
     $cacheid = $this->generateCacheId('blk_' . $xobject->getVar('bid'));
     $xoops->preload()->triggerEvent('core.themeblocks.buildblock.start', array($xobject, $template->isCached($tplName, $cacheid)));
     if (!$bcachetime || !$template->isCached($tplName, $cacheid)) {
         //Get theme metas
         $old = array();
         if ($this->theme && $bcachetime) {
             foreach ($this->theme->metas as $type => $value) {
                 $old[$type] = $this->theme->metas[$type];
             }
         }
         //build block
         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 = \Xoops\Utils::arrayRecursiveDiff($this->theme->metas[$type], $old[$type]);
                 if (count($dif)) {
                     $metas[$type] = $dif;
                 }
             }
             if (count($metas)) {
                 \Xoops\Cache::write($cacheid, $metas);
             }
         }
     } else {
         $block['content'] = $template->fetch($tplName, $cacheid);
     }
     //add block cached metas
     if ($this->theme && $bcachetime) {
         if ($metas = \Xoops\Cache::read($cacheid)) {
             foreach ($metas as $type => $value) {
                 $this->theme->metas[$type] = array_merge($this->theme->metas[$type], $metas[$type]);
             }
         }
     }
     $template->setCompileId();
     return $block;
 }