display.block.php
Блоки на странице
Вызывается из:
Смотрите описание cms/html/block/block.block.php
Исходный код
<?php
$Block = $App->get('block');
switch (strval($Page->getInfo('block'))) {
case 'N':
# Не показываем никакие блоки
return;
case 'Y':
# Список блоков или список блоков по умолчанию
if (!$_blockList = $Block->getBlockList($Page)) $_blockList = $Block->getDefaultBlockList($Page);
break;
default:
# Список блоков по умолчанию
$_blockList = $Block->getDefaultBlockList($Page);
}
# Список активных блоков с индексами block:n
$blockList = array();
foreach ($_blockList as $order => &$block) if ($block['active']) {
$key = $block['block'] . ':' . $block['n'];
$blockList[$key] = $block;
if ($block['parent_n'] && $block['parent_block']) {
$parentKey = $block['parent_block'] . ':' . $block['parent_n'];
if (isset($blockList[$parentKey])) {
# Ссылки на дочерные блоки
if (!is_array($blockList[$parentKey]['children'])) $blockList[$parentKey]['children'] = array();
$blockList[$parentKey]['children'][$key] = &$blockList[$key];
}
}
}
# Список блоков для построения 2 колонок
$block2colList = null;
foreach ($blockList as $key => &$block) {
if ($block['parent_n'] && $block['parent_block']) continue;
if ($block2colList) {
$block2colList[$key] = &$blockList[$key];
} elseif ($block['block'] === '2col' && !$block['children']) {
$block2colList[$key] = &$blockList[$key];
}
}
# Есть 2 колонки из предыдущей версии системы
if ($block2colList) {
foreach (array_reverse(array_keys($block2colList)) as $block2colKey) {
$block2col = &$block2colList[$block2colKey];
if ($block2col['block'] === '2col' && !$block2col['children']) {
$needBlockCount1 = $needBlockCount2 = 0;
foreach ($block2colList as $key => &$block) {
if ($key === $block2colKey) {
$needBlockCount1 = intval($block['data']['col1-block-count']); if (!$needBlockCount1) $needBlockCount1 = 1;
$needBlockCount2 = intval($block['data']['col2-block-count']); if (!$needBlockCount2) $needBlockCount2 = 1;
$block2col['children1'] = array();
$block2col['children2'] = array();
} elseif ($needBlockCount1 > 0) {
$block2colList[$key]['parent_n'] = $block2col['n'];
$block2colList[$key]['parent_block'] = $block2col['block'];
$block2col['children1'][$key] = &$block2colList[$key];
unset($block2colList[$key]);
$needBlockCount1 --;
} elseif ($needBlockCount2 > 0) {
$block2colList[$key]['parent_n'] = $block2col['n'];
$block2colList[$key]['parent_block'] = $block2col['block'];
$block2col['children2'][$key] = &$block2colList[$key];
unset($block2colList[$key]);
$needBlockCount2 --;
}
}
}
}
}
# Отображение всех блоков в обратном порядке
foreach (array_reverse(array_keys($blockList)) as $key) {
$block = &$blockList[$key];
if (substr($block['block'], 0, 5) === 'list.') {
$list = substr($block['block'], 5);
if ($App->resolvePath('cms/html/block/list.' . $list . '.php')) $blockList[$key]['html'] = $Main->callTemplate('block/list', $list, $Page, array( 'block' => $block ));
else $blockList[$key]['html'] = $Page->displayBlock($list);
} else {
$blockList[$key]['html'] = $Main->callTemplate('block/block', $block['block'], $Page, array( 'block' => $block ));
}
}
# Отображение всех блоков
foreach ($blockList as $key => &$block) {
if ($block['parent_n'] && $block['parent_block']) continue;
print $block['html'];
}
?>