Display a specific part of a page or a global part. [[PageContent?part=Partname&site=PAGE_ID&escape=0]]
<?php
// determine site
$site = isset($site) ? $site : PAGE_ID;
$naviSite = ($site != 0) ? $site : REFERRER_ID;
// include template info file to get block names
require WB_PATH . '/templates/' . TEMPLATE . '/info.php';
global $database;
if (!isset($block)
|| !is_array($block)
|| count($block) < 1
) {
// load normally if no blocks in template are defined
ob_start();
page_content();
$content = ob_get_clean();
} else {
$blocks = array_flip($block);
if (!isset($part)) {
// take first block
$blockNr = 1;
$blockName = strtolower($block[1]);
} else {
$blockNr = (int)$blocks[$part];
if (!isset($blockNr)) {
// give up
return 'Block "' . strtolower($part) . '" doesn\'t exist!';
}
$blockName = strtolower($part);
}
// check if local block exists
$localBlockQuery = $database->query('
SELECT
`section_id`, `module`
FROM
`' . TABLE_PREFIX . 'sections`
WHERE
`block` = ' . $blockNr . ' AND
`page_id` = ' . $site . '
ORDER BY
`position` ASC
');
ob_start();
page_content($blockNr);
$content = ob_get_clean();
if($localBlockQuery->numRows() > 0) {
ob_start();
// fetch data
while ($localBlock = $localBlockQuery->fetchRow()) {
$sid = $localBlock['section_id'];
$module = $localBlock['module'];
// use SectionPicker droplet to display section
// echo '[[SectionPicker?sid=' . $sid . ']]';
$css = '/modules/' . $module . '/frontend.css';
if (is_readable(WB_PATH . $css)) {
$search = preg_quote(WB_URL.'/modules/' . $module . '/frontend.css', '/');
if (preg_match('/<link[^>]*?href\s*=\s*\"' . $search . '\".*?\/>/si', $wb_page_data)) {
$css = '';
} else {
$css = '<link href="' . WB_URL . $css . '" rel="stylesheet" type="text/css" media="screen" />';
}
} else {
$css = '';
}
if (isset($section_id)) {
$oldSid = $section_id; // save old sectionID
}
$section_id = $sid;
echo $css;
require(WB_PATH . '/modules/' . $module . '/view.php');
if (isset($oldSid)) {
$section_id = $oldSid; // restore old sectionID
}
}
$content = ob_get_clean();
} else if ($localBlockQuery->numRows() < 1 && $content == '') {
// get link from root parent of the site
$rootParents = $database->query('
SELECT
`p`.`link`
FROM
`' . TABLE_PREFIX . 'pages`
INNER JOIN
`' . TABLE_PREFIX . 'pages` as `p`
ON `p`.`page_id` = `' . TABLE_PREFIX . 'pages`.`root_parent`
WHERE
`' . TABLE_PREFIX . 'pages`.`page_id` = ' . $naviSite . '
');
$rootParent = $rootParents->fetchRow();
// url to pages
$address = WB_URL . PAGES_DIRECTORY;
// try to load language global content block
$content = @file_get_contents($address . $rootParent['link'] . '/' . $blockName . PAGE_EXTENSION . '?page=' . $site);
if (!$content) {
// give up
return 'No content found for block: <b>' . $blockName . '</b> (site nr. ' . $site . ')';
}
}
}
$strip = isset($strip) ? true : false;
if ($strip) {
// strip all tags
$content = strip_tags($content);
}
return $content;