block.b.php
Блок «Баннеры»
Вызывается из:
Исходный код
<?php
ob_start();
if (isset($block['data']['b']) && is_array($block['data']['b'])) foreach ($block['data']['b'] as $banner) {
if (!$banner['active']) continue;
print '<li>';
if ($href = $banner['href']) print '<a href="' . $href . '" class="uk-display-block">';
if ($image = $banner['background-image']) {
print '<img src="' . htmlspecialchars($image) . '" alt="" class="uk-cover" uk-cover>';
}
if ($banner['is-overlay']) {
print '<div class="uk-position-cover"' . ($banner['overlay-color'] ? ' style="background-color:' . $banner['overlay-color'] . ';"' : '') . '></div>';
}
if ($banner['is-text']) {
$classNames = array();
if ($banner['text-options']) foreach (is_array($banner['text-options']) ? $banner['text-options'] : explode('|', $banner['text-options']) as $option) if ($option) {
if (substr($option, 0, 3) === 'uk-') $classNames[] = $option;
}
print '<div class="' . implode(' ', $classNames) . '">';
if (!$banner['no-title']) if (strlen($value = $banner['title'])) {
print '<div class="h1">' . $Page->displayBrief(preg_replace('~[ ][ ]+~', "\n", $value)) . '</div>';
}
if (!$banner['no-html']) if (strlen($value = $banner['html'])) {
print '<div class="uk-clearfix">' . $value . '</div>';
}
if (!$banner['no-button']) if (strlen($value = $banner['button'] ? $banner['button'] : 'Подробнее')) {
$classNames = array('uk-button');
if ($banner['button-options']) foreach (is_array($banner['button-options']) ? $banner['button-options'] : explode('|', $banner['button-options']) as $option) if ($option) {
if (substr($option, 0, 3) === 'uk-') $classNames[] = $option;
}
print '<div class="' . implode(' ', $classNames) . '">' . $value . '</div>';
}
print '</div>';
}
if ($banner['is-image']) {
$classNames = array();
if ($banner['image-options']) foreach (is_array($banner['image-options']) ? $banner['image-options'] : explode('|', $banner['image-options']) as $option) if ($option) {
if (substr($option, 0, 3) === 'uk-') $classNames[] = $option;
}
print '<div class="' . implode(' ', $classNames) . '">';
if ($image = $banner['image']) {
print '<img src="' . htmlspecialchars($image) . '" alt="">';
}
print '</div>';
}
if ($href) print '</a>';
print '</li>';
}
if (!$html = ob_get_clean()) return;
$classNames = array('uk-slideshow', 'uk-position-relative');
$options = array();
$slidenav = null;
$dotnav = null;
if ($value = $block['data']['ratio']) $options['ratio'] = $value;
if ($value = $block['data']['min-height']) $options['min-height'] = $value;
if ($value = $block['data']['max-height']) $options['max-height'] = $value;
if ($block['data']['slideshow-options']) foreach (is_array($block['data']['slideshow-options']) ? $block['data']['slideshow-options'] : explode('|', $block['data']['slideshow-options']) as $option) if ($option) {
if (substr($option, 0, 3) === 'uk-') $classNames[] = $option;
elseif ($option === 'slidenav') $slidenav = true;
elseif ($option === 'dotnav') $dotnav = true;
elseif ($option === 'autoplay') {
$options['autoplay'] = 'true';
if ($value = $block['data']['autoplay-interval']) {
$options['autoplay-interval'] = 1000 * $value;
} else {
$options['autoplay-interval'] = 4000;
}
$options['pause-on-hover'] = 'true';
}
}
if ($options) foreach ($options as $k => $v) if (is_string($k)) $options[$k] = $k . ': ' . $v;
print '<div class="' . implode(' ', $classNames) . '" uk-slideshow' . ($options ? '="' . htmlspecialchars(implode('; ', $options)) . '"' : '') . '>';
print '<ul class="uk-slideshow-items">';
print $html;
print '</ul>';
if ($slidenav) {
$out = false;
$classNames = array();
if ($block['data']['slidenav-options']) foreach (is_array($block['data']['slidenav-options']) ? $block['data']['slidenav-options'] : explode('|', $block['data']['slidenav-options']) as $option) if ($option) {
if (substr($option, 0, 3) === 'uk-') $classNames[] = $option;
elseif ($option === 'out') $out = true;
}
print '<a class="uk-slidenav uk-slidenav-previous uk-position-center-left' . ($out ? '-out' : '') . ($classNames ? ' ' . implode(' ', $classNames) : '') . '" uk-slidenav-previous uk-slideshow-item="previous"></a>';
print '<a class="uk-slidenav uk-slidenav-next uk-position-center-right' . ($out ? '-out' : '') . ($classNames ? ' ' . implode(' ', $classNames) : '') . '" uk-slidenav-next uk-slideshow-item="next"></a>';
}
if ($dotnav) {
$classNames = array();
if ($block['data']['dotnav-options']) foreach (is_array($block['data']['dotnav-options']) ? $block['data']['dotnav-options'] : explode('|', $block['data']['dotnav-options']) as $option) if ($option) {
if (substr($option, 0, 3) === 'uk-') $classNames[] = $option;
}
print '<div class="uk-position-bottom-center' . ($classNames ? ' ' . implode(' ', $classNames) : '') . '"><ul class="uk-slideshow-nav uk-dotnav"></ul></div>';
}
print '</div>';
?>
<script>
cmsRequire(['uikit'], function() {
cmsRequire(['uikit/slideshow']);
});
</script>
<?php
$html = ob_get_clean();
ob_start();
print $Main->callTemplate('block/block', 'block', $Page, array( 'block' => $block, 'html' => $html ));
?>