first commit 2
This commit is contained in:
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
|
||||
/**
|
||||
* rb.custom :: premium_ad_section/module.php
|
||||
* 프리미엄 광고 모듈 (고정형 + 다중 행 슬라이더)
|
||||
*/
|
||||
|
||||
if (!isset($md_id) || !$md_id) return;
|
||||
|
||||
$md_id_safe = sql_real_escape_string($md_id);
|
||||
$module_config = sql_fetch(" SELECT * FROM `rb_module` WHERE md_id = '{$md_id_safe}' ");
|
||||
if (!$module_config) $module_config = sql_fetch(" SELECT * FROM `rb_module_shop` WHERE md_id = '{$md_id_safe}' ");
|
||||
if (!$module_config) return;
|
||||
|
||||
$config_path = __DIR__ . '/config.php';
|
||||
if (file_exists($config_path)) include_once($config_path);
|
||||
else return;
|
||||
|
||||
// 데이터 가져오기
|
||||
$position = $premium_ad_config['position'];
|
||||
$sql = " SELECT * FROM `rb_banner` WHERE bn_position = '{$position}' AND bn_begin_time <= NOW() AND bn_end_time >= NOW() ORDER BY bn_order ASC, bn_id DESC ";
|
||||
$result = sql_query($sql);
|
||||
|
||||
$fixed_banners = [];
|
||||
$slide_groups = [];
|
||||
|
||||
while ($row = sql_fetch_array($result)) {
|
||||
$row['bn_img'] = '<img src="' . G5_DATA_URL . '/banners/' . $row['bn_id'] . '" alt="' . get_text($row['bn_alt']) . '">';
|
||||
|
||||
if (isset($row['bn_group']) && !empty($row['bn_group'])) {
|
||||
$slide_groups[$row['bn_group']][] = $row;
|
||||
} else {
|
||||
$fixed_banners[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
$md_banner_skin = isset($module_config['md_banner_skin']) && $module_config['md_banner_skin'] !='' ? $module_config['md_banner_skin'] : 'image_only';
|
||||
$item_skin_file = G5_PATH . '/rb/' . $md_banner_skin . '/skin.php';
|
||||
|
||||
$css_vars = [
|
||||
'--fixed-columns: ' . (int)$premium_ad_config['fixed_grid_columns'],
|
||||
'--banner-width: ' . (int)$premium_ad_config['banner_width'] . 'px',
|
||||
'--banner-height: ' . (int)$premium_ad_config['banner_height'] . 'px',
|
||||
'--banner-gap: ' . (int)$premium_ad_config['banner_gap'] . 'px',
|
||||
];
|
||||
|
||||
$visual_id = 'pas_' . uniqid();
|
||||
?>
|
||||
|
||||
<div class="premium-ad-section" id="<?php echo $visual_id; ?>" style="<?php echo implode('; ', $css_vars); ?>;">
|
||||
|
||||
<!-- 1. 고정형 배너 영역 -->
|
||||
<?php if (!empty($fixed_banners)): ?>
|
||||
<div class="premium-ad-fixed-grid">
|
||||
<?php
|
||||
foreach ($fixed_banners as $banner) {
|
||||
if (file_exists($item_skin_file)) {
|
||||
echo '<div class="banner-unit-wrapper">';
|
||||
include($item_skin_file);
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- 2. 슬라이드형 배너 영역 (다중 행 지원) -->
|
||||
<?php if (!empty($slide_groups)): ?>
|
||||
<?php foreach ($slide_groups as $group_name => $banners):
|
||||
$columns = (int)$premium_ad_config['fixed_grid_columns'];
|
||||
$chunk_size = $columns * 2;
|
||||
$banner_rows = array_chunk($banners, $chunk_size);
|
||||
?>
|
||||
<?php foreach ($banner_rows as $row_index => $banners_in_row):
|
||||
// 💡 [핵심 수정] 현재 행의 배너 개수를 확인합니다.
|
||||
$current_count = count($banners_in_row);
|
||||
|
||||
// 배너 개수가 설정된 컬럼 수보다 적으면, 그 개수만큼만 보여줘서 꽉 채웁니다.
|
||||
// 예: 6개 설정인데 3개만 남았다면, slidesPerView를 3으로 설정 -> 3개가 100% 너비 차지
|
||||
$slides_per_view = ($current_count < $columns) ? $current_count : $columns;
|
||||
?>
|
||||
<div class="premium-ad-row">
|
||||
<div class="swiper-container premium-ad-slider"
|
||||
data-slides-per-view="<?php echo $slides_per_view; ?>"
|
||||
data-space-between="<?php echo (int)$premium_ad_config['banner_gap']; ?>">
|
||||
<div class="swiper-wrapper">
|
||||
<?php foreach ($banners_in_row as $banner): ?>
|
||||
<div class="swiper-slide banner-unit-wrapper">
|
||||
<?php
|
||||
if (file_exists($item_skin_file)) {
|
||||
include($item_skin_file);
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="slider-controls">
|
||||
<div class="swiper-button-prev btn-prev"><i class="fa fa-chevron-left"></i></div>
|
||||
<div class="swiper-button-next btn-next"><i class="fa fa-chevron-right"></i></div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (empty($fixed_banners) && empty($slide_groups)): ?>
|
||||
<div class="empty-banner">등록된 배너가 없습니다.</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<link rel="stylesheet" href="<?php echo G5_THEME_URL; ?>/rb.custom/premium_ad_section/module.css?ver=<?php echo G5_CSS_VER; ?>">
|
||||
|
||||
<!-- 통합 동적 로더 (Swiper) -->
|
||||
<script>
|
||||
(function() {
|
||||
var currentModuleId = '<?php echo $visual_id; ?>';
|
||||
var initFunctionName = 'initPremiumAdSection';
|
||||
var themeUrl = '<?php echo G5_THEME_URL; ?>';
|
||||
var jsVer = '<?php echo G5_JS_VER; ?>';
|
||||
|
||||
function loadScript(src, id, callback) {
|
||||
if (document.getElementById(id)) {
|
||||
if (callback) callback();
|
||||
return;
|
||||
}
|
||||
var script = document.createElement('script');
|
||||
script.id = id;
|
||||
script.src = src;
|
||||
script.async = false;
|
||||
if (callback) {
|
||||
script.onload = callback;
|
||||
}
|
||||
document.head.appendChild(script);
|
||||
}
|
||||
|
||||
function finalAction() {
|
||||
if (typeof window[initFunctionName] === 'function') {
|
||||
window[initFunctionName](currentModuleId);
|
||||
}
|
||||
}
|
||||
|
||||
function loadModuleScript() {
|
||||
loadScript(themeUrl + '/rb.custom/premium_ad_section/module.js?ver=' + jsVer, 'premium-ad-section-js', finalAction);
|
||||
}
|
||||
|
||||
if (typeof Swiper === 'undefined') {
|
||||
var link = document.createElement('link');
|
||||
link.rel = 'stylesheet';
|
||||
link.href = 'https://unpkg.com/swiper/swiper-bundle.min.css';
|
||||
document.head.appendChild(link);
|
||||
|
||||
loadScript('https://unpkg.com/swiper/swiper-bundle.min.js', 'swiper-bundle-js', loadModuleScript);
|
||||
} else {
|
||||
loadModuleScript();
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
Reference in New Issue
Block a user