本文整理汇总了PHP中XoopsBlock::buildBlock方法的典型用法代码示例。如果您正苦于以下问题:PHP XoopsBlock::buildBlock方法的具体用法?PHP XoopsBlock::buildBlock怎么用?PHP XoopsBlock::buildBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XoopsBlock
的用法示例。
在下文中一共展示了XoopsBlock::buildBlock方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: XoopsTpl
$html = $myts->stripSlashesGPC($html);
$tpltpl_handler =& xoops_gethandler('tplfile');
$tplfile =& $tpltpl_handler->get($id, true);
$xoopsTpl = new XoopsTpl();
if (is_object($tplfile)) {
$dummylayout = '<html><head><meta http-equiv="content-type" content="text/html; charset=' . _CHARSET . '" /><meta http-equiv="content-language" content="' . _LANGCODE . '" /><title>' . $xoopsConfig['sitename'] . '</title><style type="text/css" media="all">';
$css =& $tpltpl_handler->find($xoopsConfig['template_set'], 'css', 0, null, null, true);
$csscount = count($css);
for ($i = 0; $i < $csscount; $i++) {
$dummylayout .= "\n" . $css[$i]->getVar('tpl_source');
}
$dummylayout .= "\n" . '</style></head><body><{$content}></body></html>';
if ($tplfile->getVar('tpl_type') == 'block') {
include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
$block = new XoopsBlock($tplfile->getVar('tpl_refid'));
$xoopsTpl->assign('block', $block->buildBlock());
}
$dummytpl = '_dummytpl_' . time() . '.html';
$fp = fopen(XOOPS_CACHE_PATH . '/' . $dummytpl, 'w');
fwrite($fp, $html);
fclose($fp);
$xoopsTpl->assign('content', $xoopsTpl->fetch('file:' . XOOPS_CACHE_PATH . '/' . $dummytpl));
$xoopsTpl->clear_compiled_tpl('file:' . XOOPS_CACHE_PATH . '/' . $dummytpl);
unlink(XOOPS_CACHE_PATH . '/' . $dummytpl);
$dummyfile = '_dummy_' . time() . '.html';
$fp = fopen(XOOPS_CACHE_PATH . '/' . $dummyfile, 'w');
fwrite($fp, $dummylayout);
fclose($fp);
$tplset = $tplfile->getVar('tpl_tplset');
$tform = array('tpl_tplset' => $tplset, 'tpl_id' => $id, 'tpl_file' => $tplfile->getVar('tpl_file'), 'tpl_desc' => $tplfile->getVar('tpl_desc'), 'tpl_lastmodified' => $tplfile->getVar('tpl_lastmodified'), 'tpl_source' => htmlspecialchars($html, ENT_QUOTES), 'tpl_module' => $moddir);
include_once XOOPS_ROOT_PATH . '/modules/system/admin/tplsets/tplform.php';
示例2: buildBlock
/**
* 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;
}
示例3: list
//.........这里部分代码省略.........
$arr = $xoopsblock->getAllBlocksByGroup($this->plugin_xoopsblock_getByType("Anonymous"));
}
}
$ret = "";
if ($tgt == "?") {
foreach ($arr as $myblock) {
$block = array();
$block_type = @$myblock->getVar("type") ? $myblock->getVar("type") : $myblock->getVar("block_type");
$name = @$myblock->getVar("title") ? $myblock->getVar("title") : $myblock->getVar("name");
$bid = $myblock->getVar('bid');
$ret .= "<li>(" . $bid . ")" . $name . "</li>";
}
} else {
global $xoopsTpl;
require_once XOOPS_ROOT_PATH . '/class/template.php';
$xoopsTpl = new XoopsTpl();
if (is_object($xoopsUser)) {
$xoopsTpl->assign(array('xoops_isuser' => true, 'xoops_userid' => $xoopsUser->getVar('uid'), 'xoops_uname' => $xoopsUser->getVar('uname'), 'xoops_isadmin' => $xoopsUser->isAdmin()));
}
$xoopsTpl->assign('xoops_requesturi', htmlspecialchars($GLOBALS['xoopsRequestUri'], ENT_QUOTES));
foreach ($tgt_bids as $bid) {
$myblock = new XoopsBlock($bid);
$_bid = $myblock->getVar('bid');
if (!empty($_bid)) {
$bcachetime = $myblock->getVar('bcachetime');
// Only a guest enable cache. by nao-pon
//if (empty($bcachetime)) {
if ($bcachetime % 10 == 1) {
$bcachetime_guest = TRUE;
$bcachetime = $bcachetime - 1;
} else {
$bcachetime_guest = FALSE;
}
if (empty($bcachetime) || is_object($xoopsUser) && $bcachetime_guest) {
//if (empty($bcachetime)) {
$xoopsTpl->xoops_setCaching(0);
} else {
$xoopsTpl->xoops_setCaching(2);
$xoopsTpl->xoops_setCacheTime($bcachetime);
}
$btpl = $myblock->getVar('template');
if ($btpl != '') {
if (empty($bcachetime) || !$xoopsTpl->is_cached('db:' . $btpl, 'blk_' . $myblock->getVar('bid'))) {
//$xoopsLogger->addBlock($myblock->getVar('name'));
$bresult = $myblock->buildBlock();
if (!$bresult) {
continue;
}
$xoopsTpl->assign_by_ref('block', $bresult);
$bcontent = $xoopsTpl->fetch('db:' . $btpl, 'blk_' . $myblock->getVar('bid'));
$xoopsTpl->clear_assign('block');
} else {
//$xoopsLogger->addBlock($myblock->getVar('name'), true, $bcachetime);
$bcontent = $xoopsTpl->fetch('db:' . $btpl, 'blk_' . $myblock->getVar('bid'));
}
} else {
//$bid = $myblock->getVar('bid');
if (empty($bcachetime) || !$xoopsTpl->is_cached('db:system_dummy.html', 'blk_' . $bid)) {
//$xoopsLogger->addBlock($myblock->getVar('name'));
$bresult = $myblock->buildBlock();
if (!$bresult) {
continue;
}
$xoopsTpl->assign_by_ref('dummy_content', $bresult['content']);
$bcontent = $xoopsTpl->fetch('db:system_dummy.html', 'blk_' . $bid);
$xoopsTpl->clear_assign('block');
} else {
//$xoopsLogger->addBlock($myblock->getVar('name'), true, $bcachetime);
$bcontent = $xoopsTpl->fetch('db:system_dummy.html', 'blk_' . $bid);
}
}
$btitle = $myblock->getVar('title');
} else {
$btitle = "Block({$bid})";
$bcontent = "Block({$bid}) is not found.";
}
if ($bcontent) {
$ret .= "<h5>" . $btitle . "</h5>\n";
$ret .= $bcontent;
foreach (explode("\n", $xoopsTpl->get_template_vars('xoops_block_header')) as $str) {
$this->root->head_tags[] = rtrim($str);
}
foreach (explode("\n", $xoopsTpl->get_template_vars('xoops_module_header')) as $str) {
$this->root->head_tags[] = rtrim($str);
}
$this->root->head_tags = array_unique($this->root->head_tags);
}
}
unset($myblock);
}
if (!$css_show) {
$css_show = true;
$this->root->head_pre_tags[] = "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"" . XOOPS_URL . "/xoops.css\" />";
}
if ($tgt == "?") {
$ret = "<ul>{$ret}</ul>";
}
unset($xoopsblock, $xoopsgroup);
return "<div{$style}>{$ret}</div>{$clear}";
}
示例4: test_buildBlock
public function test_buildBlock()
{
$instance = new XoopsBlock();
$value = $instance->buildBlock();
$this->assertSame(false, $value);
$instance->setVar('block_type', '');
$value = $instance->isCustom();
$this->assertFalse($value);
$value = $instance->buildBlock();
$this->assertSame(false, $value);
$instance->setVar('block_type', 'C');
$value = $instance->isCustom();
$this->assertTrue($value);
$instance->setVar('dirname', 'page');
$instance->setVar('func_file', 'page_blocks.php');
$instance->setVar('show_func', 'page_blocks_show');
$instance->setVar('options', 'a|b|c|d|e');
$value = $instance->buildBlock();
$this->assertSame(false, $value);
$instance->setVar('dirname', 'page');
$instance->setVar('func_file', 'page_blocks.php');
$instance->setVar('show_func', 'function_not_exists');
$instance->setVar('options', 'a|b|c|d|e');
$value = $instance->buildBlock();
$this->assertSame(false, $value);
$instance->setVar('dirname', 'page');
$instance->setVar('func_file', 'file_not_found.php');
$instance->setVar('show_func', 'page_blocks_show');
$instance->setVar('options', 'a|b|c|d|e');
$value = $instance->buildBlock();
$this->assertSame(false, $value);
}