/** * XoopsThemeBlocksPlugin::buildBlock() * * @param XoopsBlock $xobject * @param XoopsTpl $template * @return array|bool */ public function buildBlock($xobject, &$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; }
/** * Get a list of extensions * * @param string $name name of captcha looking for * @param string $extension extentions for captcha * * @return array|mixed */ public function getList($name, $extension = "") { if ($items = Xoops_Cache::read("captcha_captcha_{$name}")) { return $items; } $file_path = $this->xoops_root_path . "/class/captcha/image/{$name}"; $files = XoopsLists::getFileListAsArray($file_path); foreach ($files as $item) { if (empty($extension) || preg_match("/(\\.{$extension})\$/i", $item)) { $items[] = $item; } } Xoops_Cache::write("captcha_captcha_{$name}", $items); return $items; }
/** * clear config cache of a module * * * @param string $dirname module dirname * @return bool */ function mod_clearConfig($dirname = "") { if (empty($dirname)) { return false; } return Xoops_Cache::delete("{$dirname}_config"); }
/** * @param $name * @param null|string $dirname * @param null|string $cache_path * @return mixed|null */ function mod_loadFile($name, $dirname = null, $cache_path = null) { $xoops = Xoops::getInstance(); $data = null; if (empty($name)) { return $data; } $dirname = $dirname ? $dirname : $xoops->moduleDirname; $cache_path = $cache_path ? $cache_path : $xoops->globalData->getVar('cache-path'); $key = "{$dirname}_{$name}"; return Xoops_Cache::read($key); }