|
<? |
|
// File: /bitrix/templates/SITE_TEMPLATE_ID/component_handlers/gallery.php |
|
|
|
$IBLOCK_ID_PHOTOS = 18; // ID инфоблока с галереей |
|
$COUNT_ROW = 3; // Сколько картинок в строку |
|
$CONTENT = $arResult['DETAIL_TEXT']; |
|
|
|
preg_match_all('/\[gallery ([0-9]+)\]/', substr($CONTENT, 0), $matches, PREG_SET_ORDER); |
|
|
|
if($matches) { |
|
$APPLICATION->SetAdditionalCSS("https://cdnjs.cloudflare.com/ajax/libs/baguettebox.js/1.8.1/baguetteBox.min.css"); |
|
$APPLICATION->AddHeadScript ("https://cdnjs.cloudflare.com/ajax/libs/baguettebox.js/1.8.1/baguetteBox.min.js"); |
|
} |
|
|
|
foreach($matches as $idx=> $val) { |
|
|
|
$gals = CIBlockElement::GetProperty($IBLOCK_ID_PHOTOS, $val[1], ["sort" => "asc"], ["CODE" => "photos"]); |
|
$offset = $gals->result->num_rows%$COUNT_ROW; |
|
|
|
$fullGallery = '<div class="tz-gallery" id="tz-gall-' . $idx . '"><div class="row">'; |
|
$items = 0; |
|
|
|
while ($ob = $gals->GetNext()) { |
|
|
|
if($offset == 2 && $items < 2){ |
|
$itemClass = 'col-sm-6'; |
|
$size = ["width" => 540, "height" => 360]; |
|
} |
|
elseif($gals->result->num_rows > 7){ |
|
$itemClass = 'col-sm-6 col-md-3'; |
|
$size = ["width" => 360, "height" => 240]; |
|
} |
|
elseif($offset == 1 && $items < 1){ |
|
$itemClass = 'col-sm-6 col-md-4'; |
|
$size = ["width" => 360, "height" => 240]; |
|
} |
|
else{ |
|
$itemClass = 'col-sm-6 col-md-4'; |
|
$size = ["width" => 360, "height" => 240]; |
|
} |
|
|
|
$pic = CFile::ResizeImageGet($ob['VALUE'], $size, BX_RESIZE_IMAGE_EXACT); |
|
$fullGallery .= '<div class="'.$itemClass.'"> |
|
<a class="lightbox" href="'.CFile::GetPath($ob['VALUE']).'"> |
|
<img alt="'.$arResult['NAME'].'" src="'.$pic['src'].'" title="'.$arResult['NAME'].'"> |
|
</a> |
|
</div>'; |
|
$items++; |
|
} |
|
$fullGallery .= '</div></div>'; |
|
|
|
$fullGallery .= '<script> baguetteBox.run("#tz-gall-' . $idx . '"); </script>'; |
|
|
|
$CONTENT = str_replace($val[0], $fullGallery, $CONTENT); |
|
} |
|
|
|
$CONTENT = preg_replace('/<\?=SITE_TEMPLATE_PATH\?>/', SITE_TEMPLATE_PATH, $CONTENT); |
|
$arResult['DETAIL_TEXT'] = $CONTENT; |
|
|
|
?> |