Files
dnssash/theme/rd.dnssash/rb.custom/pns_visual_borad_backup/module.php
T
2026-06-11 18:47:38 +09:00

225 lines
8.9 KiB
PHP

<?php
if (!defined('_GNUBOARD_')) exit;
/**
* rb.custom :: pns_visual_borad/module.php
* PNS 스타일 메인 비주얼 슬라이더 (게시판 연동)
*/
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);
// --- 설정 변수 ---
$bo_table = 'main_visual'; // 실제 생성하신 게시판 테이블명으로 수정하세요
$limit_count = 10; // 불러올 슬라이드 개수 (변수 처리)
$write_table = $g5['write_prefix'] . $bo_table;
// 💡 [추가] 팝업 내 링크 이동 방식 설정 (button, image, both)
$link_type = 'image'; // 기본값: 이미지 클릭 시 이동
// 💡 [수정] 노출 조건 추가 (숨김, 예약 노출)
$today = G5_TIME_YMD; // 오늘 날짜 (YYYY-MM-DD)
$sql_where = " wr_is_comment = 0 "; // 기본 조건: 댓글 제외
// 1. 숨김 설정 (wr_10) 체크: 값이 없거나 0인 경우만 노출
$sql_where .= " AND (wr_10 = '' OR wr_10 IS NULL OR wr_10 = '0') ";
// 2. 노출 방식 (wr_9) 체크: 즉시 노출이거나, 예약 기간 내인 경우
$sql_where .= " AND (
wr_9 != 'RESERVED'
OR (wr_9 = 'RESERVED' AND wr_2 <= '{$today}' AND wr_3 >= '{$today}')
) ";
// 데이터베이스에서 데이터 가져오기 (wr_id 역순)
$sql = " SELECT * FROM {$write_table}
WHERE {$sql_where}
ORDER BY wr_num, wr_reply LIMIT 0, {$limit_count} ";
$result = sql_query($sql);
$module_id = 'pns_visual_' . uniqid();
?>
<div id="<?php echo $module_id; ?>" class="pns-visual-slider swiper-container">
<div class="swiper-wrapper">
<?php
for ($i=0; $row=sql_fetch_array($result); $i++) {
// 💡 [수정] 이미지 가져오기 로직 개선 (원본 파일 우선 -> 썸네일 -> 기본 이미지)
$img_url = '';
// 1. 원본 파일 확인
$sql_file = " select bf_file from {$g5['board_file_table']} where bo_table = '$bo_table' and wr_id = '{$row['wr_id']}' order by bf_no limit 1 ";
$row_file = sql_fetch($sql_file);
if ($row_file['bf_file']) {
$img_url = G5_DATA_URL.'/file/'.$bo_table.'/'.$row_file['bf_file'];
}
// 2. 원본 파일이 없으면 썸네일 확인
if (!$img_url) {
$thumb = get_list_thumbnail($bo_table, $row['wr_id'], '1920', '1080', true, true);
if ($thumb['src']) {
$img_url = $thumb['src'];
}
}
// 3. 둘 다 없으면 기본 이미지
if (!$img_url) {
$img_url = G5_THEME_URL.'/rb.img/no_image.png';
}
// 원본 이미지 경로 (팝업용)
$ori_url = $img_url;
// 제목과 요약 내용 (wr_subject, wr_1)
$subject = cut_str(get_text($row['wr_subject']), 100);
$summary = get_text($row['wr_1']); // wr_1에 저장된 요약 내용
// 링크 URL (wr_link1 사용)
$link_url = $row['wr_link1'];
?>
<div class="swiper-slide">
<div class="visual-bg" style="background-image: url('<?php echo $img_url; ?>');"></div>
<div class="visual-content container">
<h2 class="visual-title" data-swiper-parallax="-300"><?php echo nl2br($subject); ?></h2>
<p class="visual-desc" data-swiper-parallax="-200"><?php echo nl2br($summary); ?></p>
<!-- 💡 [수정] 무조건 팝업을 띄우도록 원복 -->
<a href="javascript:void(0);" class="visual-btn btn-open-lightbox" data-img="<?php echo $ori_url; ?>" data-url="<?php echo $link_url; ?>" data-swiper-parallax="-100">자세히 보기</a>
</div>
</div>
<?php } ?>
<?php if($i == 0) echo '<div class="swiper-slide"><div class="visual-content">등록된 광고 데이터가 없습니다.</div></div>'; ?>
</div>
<div class="swiper-pagination"></div>
<div class="swiper-button-next"></div>
<div class="swiper-button-prev"></div>
</div>
<!-- 💡 [추가] 이미지 라이트박스 컨테이너 -->
<div id="image-lightbox" class="image-lightbox">
<span class="lightbox-close">&times;</span>
<img class="lightbox-content" id="lightbox-img">
<!-- 💡 [추가] 바로가기 버튼 -->
<a href="#" target="_blank" class="lightbox-link-btn" id="lightbox-link">바로가기</a>
</div>
<!-- CSS 파일 로드 -->
<link rel="stylesheet" href="<?php echo G5_THEME_URL; ?>/rb.custom/pns_visual_borad/module.css?ver=<?php echo G5_CSS_VER; ?>">
<!-- 통합 동적 로더 (Swiper) -->
<script>
(function() {
var currentModuleId = '<?php echo $module_id; ?>';
var themeUrl = '<?php echo G5_THEME_URL; ?>';
var jsVer = '<?php echo G5_JS_VER; ?>';
var linkType = '<?php echo $link_type; ?>'; // 💡 [추가] 링크 이동 방식 플래그
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 initSwiper() {
new Swiper('#' + currentModuleId, {
speed: 1200,
parallax: true,
loop: true,
autoplay: { delay: 6000, disableOnInteraction: false },
pagination: { el: '.swiper-pagination', clickable: true },
navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev' },
});
// 라이트박스 제어 스크립트
var lightbox = document.getElementById('image-lightbox');
var lightboxImg = document.getElementById('lightbox-img');
var lightboxLink = document.getElementById('lightbox-link');
var closeBtn = document.querySelector('.lightbox-close');
document.body.addEventListener('click', function(e) {
if (e.target.classList.contains('btn-open-lightbox')) {
e.preventDefault();
var imgSrc = e.target.getAttribute('data-img');
var linkUrl = e.target.getAttribute('data-url');
if (imgSrc) {
lightboxImg.src = imgSrc;
// 링크가 있으면 설정에 따라 처리
if (linkUrl && linkUrl !== "") {
// 1. 버튼 방식
if (linkType === 'button' || linkType === 'both') {
lightboxLink.href = linkUrl;
lightboxLink.style.display = 'inline-block';
} else {
lightboxLink.style.display = 'none';
}
// 2. 이미지 클릭 방식
if (linkType === 'image' || linkType === 'both') {
lightboxImg.onclick = function() {
window.open(linkUrl, '_blank');
};
lightboxImg.style.cursor = 'pointer';
} else {
lightboxImg.onclick = null;
lightboxImg.style.cursor = 'default';
}
} else {
// 링크가 없으면 모두 숨김/비활성
lightboxLink.style.display = 'none';
lightboxImg.onclick = null;
lightboxImg.style.cursor = 'default';
}
lightbox.style.display = 'flex';
}
}
});
if (closeBtn) {
closeBtn.addEventListener('click', function() {
lightbox.style.display = 'none';
});
}
if (lightbox) {
lightbox.addEventListener('click', function(e) {
if (e.target === lightbox) {
lightbox.style.display = 'none';
}
});
}
}
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', initSwiper);
} else {
initSwiper();
}
})();
</script>