메인 배너 영상재생 기능추가.

This commit is contained in:
2025-12-15 17:55:17 +09:00
parent d125d39965
commit 40c757ea36
3 changed files with 244 additions and 35 deletions

View File

@ -29,6 +29,26 @@ if (!sql_query("SELECT bn_device FROM rb_banner LIMIT 0, 1")) {
sql_query("UPDATE rb_banner SET bn_device = 'pc'", true);
}
// 콘텐츠 유형 필드 추가 (image/video/video_url/youtube/vimeo)
if (!sql_query("SELECT bn_content_type FROM rb_banner LIMIT 0, 1")) {
sql_query("ALTER TABLE `rb_banner` ADD `bn_content_type` varchar(20) NOT NULL DEFAULT 'image' AFTER `bn_device`", true);
}
// 비디오 URL 필드 추가
if (!sql_query("SELECT bn_video_url FROM rb_banner LIMIT 0, 1")) {
sql_query("ALTER TABLE `rb_banner` ADD `bn_video_url` varchar(500) NOT NULL DEFAULT '' AFTER `bn_content_type`", true);
}
// 유튜브 URL 필드 추가
if (!sql_query("SELECT bn_youtube_url FROM rb_banner LIMIT 0, 1")) {
sql_query("ALTER TABLE `rb_banner` ADD `bn_youtube_url` varchar(500) NOT NULL DEFAULT '' AFTER `bn_video_url`", true);
}
// 비메오 URL 필드 추가
if (!sql_query("SELECT bn_vimeo_url FROM rb_banner LIMIT 0, 1")) {
sql_query("ALTER TABLE `rb_banner` ADD `bn_vimeo_url` varchar(500) NOT NULL DEFAULT '' AFTER `bn_youtube_url`", true);
}
include_once(G5_ADMIN_PATH . '/admin.head.php');
?>
@ -45,9 +65,23 @@ include_once(G5_ADMIN_PATH . '/admin.head.php');
</colgroup>
<tbody>
<tr>
<th scope="row"><label for="bn_content_type">콘텐츠 유형</label></th>
<td>
<?php echo help("배너의 콘텐츠 유형을 선택하세요."); ?>
<?php $bn_content_type = isset($bn['bn_content_type']) ? $bn['bn_content_type'] : 'image'; ?>
<select name="bn_content_type" id="bn_content_type" onchange="toggleContentInputs()">
<option value="image" <?php echo get_selected($bn_content_type, 'image', true); ?>>이미지</option>
<option value="video" <?php echo get_selected($bn_content_type, 'video', true); ?>>동영상 파일 (로컬 업로드)</option>
<option value="video_url" <?php echo get_selected($bn_content_type, 'video_url', true); ?>>비디오 URL (MP4, M3U8 등)</option>
<option value="youtube" <?php echo get_selected($bn_content_type, 'youtube', true); ?>>유튜브</option>
<option value="vimeo" <?php echo get_selected($bn_content_type, 'vimeo', true); ?>>비메오</option>
</select>
</td>
</tr>
<tr id="image_row">
<th scope="row">이미지</th>
<td>
<input type="file" name="bn_bimg">
<input type="file" name="bn_bimg" accept="image/*">
<?php
$bimg_str = "";
$bimg = G5_DATA_PATH . "/banners/" . $bn['bn_id'];
@ -66,6 +100,43 @@ include_once(G5_ADMIN_PATH . '/admin.head.php');
?>
</td>
</tr>
<tr id="video_row" style="display:none;">
<th scope="row">동영상 파일</th>
<td>
<?php echo help("MP4, MKV, MOV, WebM 등의 동영상 파일을 업로드하세요."); ?>
<input type="file" name="bn_video_file" accept="video/*">
<?php
if (isset($bn['bn_id']) && $bn['bn_id'] && $bn_content_type === 'video') {
$video_file = G5_DATA_PATH . "/banners/" . $bn['bn_id'];
if (file_exists($video_file)) {
echo '<div><p>업로드된 파일: ' . basename($video_file) . '</p>';
echo '<input type="checkbox" name="bn_video_del" value="1" id="bn_video_del"> <label for="bn_video_del">삭제</label></div>';
}
}
?>
</td>
</tr>
<tr id="video_url_row" style="display:none;">
<th scope="row">비디오 URL</th>
<td>
<?php echo help("MP4, M3U8, DASH 등의 비디오 파일 직접 URL을 입력하세요."); ?>
<input type="text" name="bn_video_url" value="<?php echo isset($bn['bn_video_url']) ? htmlspecialchars($bn['bn_video_url']) : ''; ?>" class="frm_input" size="80" placeholder="https://example.com/video.mp4">
</td>
</tr>
<tr id="youtube_row" style="display:none;">
<th scope="row">유튜브</th>
<td>
<?php echo help("유튜브 URL을 입력하세요. (예: https://www.youtube.com/watch?v=xxxxx 또는 https://youtu.be/xxxxx)"); ?>
<input type="text" name="bn_youtube_url" value="<?php echo isset($bn['bn_youtube_url']) ? htmlspecialchars($bn['bn_youtube_url']) : ''; ?>" class="frm_input" size="80" placeholder="https://www.youtube.com/watch?v=...">
</td>
</tr>
<tr id="vimeo_row" style="display:none;">
<th scope="row">비메오</th>
<td>
<?php echo help("비메오 URL을 입력하세요. (예: https://vimeo.com/xxxxx)"); ?>
<input type="text" name="bn_vimeo_url" value="<?php echo isset($bn['bn_vimeo_url']) ? htmlspecialchars($bn['bn_vimeo_url']) : ''; ?>" class="frm_input" size="80" placeholder="https://vimeo.com/...">
</td>
</tr>
<tr>
<th scope="row"><label for="bn_alt">메인타이틀</label></th>
<td>
@ -205,6 +276,20 @@ include_once(G5_ADMIN_PATH . '/admin.head.php');
</form>
<script>
function toggleContentInputs() {
const contentType = document.getElementById('bn_content_type').value;
document.getElementById('image_row').style.display = (contentType === 'image') ? 'table-row' : 'none';
document.getElementById('video_row').style.display = (contentType === 'video') ? 'table-row' : 'none';
document.getElementById('video_url_row').style.display = (contentType === 'video_url') ? 'table-row' : 'none';
document.getElementById('youtube_row').style.display = (contentType === 'youtube') ? 'table-row' : 'none';
document.getElementById('vimeo_row').style.display = (contentType === 'vimeo') ? 'table-row' : 'none';
}
// 페이지 로드 시 초기화
document.addEventListener('DOMContentLoaded', toggleContentInputs);
</script>
<?php
include_once(G5_ADMIN_PATH . '/admin.tail.php');
?>

View File

@ -16,24 +16,60 @@ check_admin_token();
$bn_bimg = isset($_FILES['bn_bimg']['tmp_name']) ? $_FILES['bn_bimg']['tmp_name'] : null;
$bn_bimg_name = isset($_FILES['bn_bimg']['name']) ? $_FILES['bn_bimg']['name'] : null;
$bn_video_file = isset($_FILES['bn_video_file']['tmp_name']) ? $_FILES['bn_video_file']['tmp_name'] : null;
$bn_video_name = isset($_FILES['bn_video_file']['name']) ? $_FILES['bn_video_file']['name'] : null;
$bn_content_type = isset($bn_content_type) ? $bn_content_type : 'image';
$bn_video_url = isset($bn_video_url) ? clean_xss_tags($bn_video_url) : '';
$bn_youtube_url = isset($bn_youtube_url) ? clean_xss_tags($bn_youtube_url) : '';
$bn_vimeo_url = isset($bn_vimeo_url) ? clean_xss_tags($bn_vimeo_url) : '';
$bn_id = isset($bn_id) ? (int) $bn_id : 0;
$bn_bimg_del = isset($bn_bimg_del) ? $bn_bimg_del : null;
$bn_video_del = isset($bn_video_del) ? $bn_video_del : null;
if ($bn_bimg_del) {
@unlink(G5_DATA_PATH."/banners/$bn_id");
}
// 파일이 이미지인지 체크합니다.
if ($bn_bimg || $bn_bimg_name) {
if (!preg_match('/\.(gif|jpe?g|bmp|png)$/i', $bn_bimg_name)) {
alert("이미지 파일만 업로드 할 수 있습니다.");
}
if ($bn_video_del) {
@unlink(G5_DATA_PATH."/banners/$bn_id");
}
$timg = @getimagesize($bn_bimg);
if ($timg === false || $timg[2] < 1 || $timg[2] > 16) {
alert("이미지 파일만 업로드 할 수 있습니다.");
// 콘텐츠 유형에 따른 검증
if ($bn_content_type === 'image') {
// 파일이 이미지인지 체크합니다.
if ($bn_bimg || $bn_bimg_name) {
if (!preg_match('/\.(gif|jpe?g|bmp|png)$/i', $bn_bimg_name)) {
alert("이미지 파일만 업로드 할 수 있습니다.");
}
$timg = @getimagesize($bn_bimg);
if ($timg === false || $timg[2] < 1 || $timg[2] > 16) {
alert("이미지 파일만 업로드 할 수 있습니다.");
}
}
} elseif ($bn_content_type === 'video') {
// 동영상 파일 검증
if ($bn_video_file || $bn_video_name) {
if (!preg_match('/\.(mp4|mkv|mov|avi|webm|flv|wmv|m4v)$/i', $bn_video_name)) {
alert("동영상 파일(MP4, MKV, MOV, AVI, WebM, FLV, WMV, M4V)만 업로드 할 수 있습니다.");
}
}
} elseif ($bn_content_type === 'video_url') {
// URL 검증
if (!$bn_video_url) {
alert("비디오 URL을 입력하세요.");
}
} elseif ($bn_content_type === 'youtube') {
// 유튜브 URL 검증
if (!$bn_youtube_url) {
alert("유튜브 URL을 입력하세요.");
}
} elseif ($bn_content_type === 'vimeo') {
// 비메오 URL 검증
if (!$bn_vimeo_url) {
alert("비메오 URL을 입력하세요.");
}
}
@ -50,7 +86,22 @@ if(isset($_POST['bn_position_use']) && $_POST['bn_position_use']) {
}
if ($w == "") {
if (!$bn_bimg_name) alert('배너 이미지를 업로드 하세요.');
// 콘텐츠 유형별 필수 검사
if ($bn_content_type === 'image' && !$bn_bimg_name) {
alert('배너 이미지를 업로드 하세요.');
}
if ($bn_content_type === 'video' && !$bn_video_name) {
alert('동영상 파일을 업로드 하세요.');
}
if ($bn_content_type === 'video_url' && !$bn_video_url) {
alert('비디오 URL을 입력하세요.');
}
if ($bn_content_type === 'youtube' && !$bn_youtube_url) {
alert('유튜브 URL을 입력하세요.');
}
if ($bn_content_type === 'vimeo' && !$bn_vimeo_url) {
alert('비메오 URL을 입력하세요.');
}
sql_query("ALTER TABLE rb_banner AUTO_INCREMENT=1");
@ -61,6 +112,10 @@ if ($w == "") {
bn_alt4 = '$bn_alt4',
bn_url = '$bn_url',
bn_device = '$bn_device',
bn_content_type = '$bn_content_type',
bn_video_url = '$bn_video_url',
bn_youtube_url = '$bn_youtube_url',
bn_vimeo_url = '$bn_vimeo_url',
bn_position = '$bn_position',
bn_border = '$bn_border',
bn_radius = '$bn_radius',
@ -82,6 +137,10 @@ if ($w == "") {
bn_alt4 = '$bn_alt4',
bn_url = '$bn_url',
bn_device = '$bn_device',
bn_content_type = '$bn_content_type',
bn_video_url = '$bn_video_url',
bn_youtube_url = '$bn_youtube_url',
bn_vimeo_url = '$bn_vimeo_url',
bn_position = '$bn_position',
bn_border = '$bn_border',
bn_radius = '$bn_radius',
@ -100,9 +159,17 @@ if ($w == "") {
}
if ($w == "" || $w == "u") {
if (isset($_FILES['bn_bimg']['name']) && $_FILES['bn_bimg']['name']) {
rb_upload_files($_FILES['bn_bimg']['tmp_name'], $bn_id, G5_DATA_PATH."/banners");
// 콘텐츠 유형에 따라 파일 업로드
if ($bn_content_type === 'image') {
if (isset($_FILES['bn_bimg']['name']) && $_FILES['bn_bimg']['name']) {
rb_upload_files($_FILES['bn_bimg']['tmp_name'], $bn_id, G5_DATA_PATH."/banners");
}
} elseif ($bn_content_type === 'video') {
if (isset($_FILES['bn_video_file']['name']) && $_FILES['bn_video_file']['name']) {
rb_upload_files($_FILES['bn_video_file']['tmp_name'], $bn_id, G5_DATA_PATH."/banners");
}
}
// 나머지 타입(video_url, youtube, vimeo)은 파일 업로드 필요 없음 (URL만 저장)
goto_url("./banner_form.php?w=u&amp;bn_id=$bn_id");
} else {

View File

@ -49,21 +49,85 @@ while ($row = sql_fetch_array($result)) {
$bn_border = isset($row['bn_border']) && $row['bn_border'] ? ' bn_border' : '';
$bn_radius = isset($row['bn_radius']) && $row['bn_radius'] ? ' bn_radius' : '';
$bn_image = G5_DATA_URL.'/banners/'.$row['bn_id'];
$bn_content_type = isset($row['bn_content_type']) ? $row['bn_content_type'] : 'image';
$bn_video_url = isset($row['bn_video_url']) ? $row['bn_video_url'] : '';
$bn_youtube_url = isset($row['bn_youtube_url']) ? $row['bn_youtube_url'] : '';
$bn_vimeo_url = isset($row['bn_vimeo_url']) ? $row['bn_vimeo_url'] : '';
// 새창 옵션
$bn_new_win = isset($row['bn_new_win']) && $row['bn_new_win'] ? ' target="_blank"' : '';
if ($i == 0) echo '<div class="mod_bn_wrap rb_wide_bn_wrap rb_wide_bn_'.$row_mod['md_id'].'" style="background-color:'.$md_banner_bg.'"><div class="swiper-container swiper-container-slide_wide_bn_'.$row_mod['md_id'].'"><ul class="swiper-wrapper swiper-wrapper-slide_wide_bn swiper-wrapper-slide_wide_bn_'.$row_mod['md_id'].'">'.PHP_EOL;
// 콘텐츠 파일 존재 여부 확인
$bimg = G5_DATA_PATH.'/banners/'.$row['bn_id'];
if (file_exists($bimg)) {
$banner = '';
$size = getimagesize($bimg);
$img_width = $size[0];
$file_exists = file_exists($bimg);
// 콘텐츠 유형별 출력 가능 여부 확인
$can_display = false;
if ($bn_content_type === 'image' && $file_exists) {
$can_display = true;
} elseif ($bn_content_type === 'video' && $file_exists) {
$can_display = true;
} elseif ($bn_content_type === 'video_url' && !empty($bn_video_url)) {
$can_display = true;
} elseif ($bn_content_type === 'youtube' && !empty($bn_youtube_url)) {
$can_display = true;
} elseif ($bn_content_type === 'vimeo' && !empty($bn_vimeo_url)) {
$can_display = true;
}
// 출력 가능한 배너만 처리
if ($can_display) {
if ($i == 0) echo '<div class="mod_bn_wrap rb_wide_bn_wrap rb_wide_bn_'.$row_mod['md_id'].'" style="background-color:'.$md_banner_bg.'"><div class="swiper-container swiper-container-slide_wide_bn_'.$row_mod['md_id'].'"><ul class="swiper-wrapper swiper-wrapper-slide_wide_bn swiper-wrapper-slide_wide_bn_'.$row_mod['md_id'].'">'.PHP_EOL;
echo '<div class="swiper-slide swiper-slide-slide_wide_bn_'.$row_mod['md_id'].' slide_item top_ad">'.PHP_EOL;
echo '<div class="sl_bn_inner">'.PHP_EOL;
echo '<img src="'.$bn_image.'" class="image_roll">'.PHP_EOL;
// 콘텐츠 유형별 렌더링
if ($bn_content_type === 'image') {
echo '<img src="'.$bn_image.'" class="image_roll">'.PHP_EOL;
} elseif ($bn_content_type === 'video') {
// 로컬 업로드 동영상
echo '<video class="image_roll" autoplay muted playsinline loop controls style="width: 100%; height: 100%; object-fit: cover;">'.PHP_EOL;
echo ' <source src="'.$bn_image.'" type="video/mp4">'.PHP_EOL;
echo ' Your browser does not support the video tag.'.PHP_EOL;
echo '</video>'.PHP_EOL;
} elseif ($bn_content_type === 'video_url') {
// 외부 비디오 URL (MP4, M3U8 등)
echo '<video class="image_roll" autoplay muted playsinline loop controls style="width: 100%; height: 100%; object-fit: cover;">'.PHP_EOL;
echo ' <source src="'.$bn_video_url.'" type="application/x-mpegURL">'.PHP_EOL;
echo ' <source src="'.$bn_video_url.'" type="video/mp4">'.PHP_EOL;
echo ' Your browser does not support the video tag.'.PHP_EOL;
echo '</video>'.PHP_EOL;
} elseif ($bn_content_type === 'youtube') {
// 유튜브 embed URL 변환
$youtube_embed_url = '';
if (preg_match('/youtube\.com\/watch\?v=([a-zA-Z0-9_-]+)/', $bn_youtube_url, $match)) {
$youtube_embed_url = 'https://www.youtube.com/embed/' . $match[1];
} elseif (preg_match('/youtu\.be\/([a-zA-Z0-9_-]+)/', $bn_youtube_url, $match)) {
$youtube_embed_url = 'https://www.youtube.com/embed/' . $match[1];
} else {
$youtube_embed_url = $bn_youtube_url;
}
echo '<iframe class="image_roll" style="width: 100%; height: 100%; border: none;" src="'.$youtube_embed_url.'" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'.PHP_EOL;
} elseif ($bn_content_type === 'vimeo') {
// 비메오 embed URL 변환
$vimeo_embed_url = '';
if (preg_match('/vimeo\.com\/(\d+)/', $bn_vimeo_url, $match)) {
$vimeo_embed_url = 'https://player.vimeo.com/video/' . $match[1];
} else {
$vimeo_embed_url = $bn_vimeo_url;
}
echo '<iframe class="image_roll" style="width: 100%; height: 100%; border: none;" src="'.$vimeo_embed_url.'" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>'.PHP_EOL;
} elseif ($bn_content_type === 'link') {
// 외부 영상 링크 (MP4, M3U8, 스트리밍 URL 등)
echo '<video class="image_roll" autoplay muted playsinline loop controls style="width: 100%; height: 100%; object-fit: cover;">'.PHP_EOL;
echo ' <source src="'.$bn_video_url.'" type="application/x-mpegURL">'.PHP_EOL;
echo ' <source src="'.$bn_video_url.'" type="video/mp4">'.PHP_EOL;
echo ' Your browser does not support the video tag.'.PHP_EOL;
echo '</video>'.PHP_EOL;
}
echo '<div class="sl_overlay"></div>'.PHP_EOL;
echo '<div class="sl_content" style="width:'.$rb_core['main_width'].'px">'.PHP_EOL;
@ -93,6 +157,8 @@ while ($row = sql_fetch_array($result)) {
echo '<div class="sl_alt2 font-R"><span>'.$row['bn_alt2'].'</span></div>'.PHP_EOL;
}
// 배너 링크 처리
$banner = '';
if(isset($row['bn_url']) && $row['bn_url']) {
if ($row['bn_url'][0] == '#') {
$banner .= '<a href="'.$row['bn_url'].'" class="sl_a_links font-B">';
@ -111,10 +177,10 @@ while ($row = sql_fetch_array($result)) {
}
}
$banner .= '<div class="cb"></div>'.PHP_EOL;
echo $banner;
if($banner) {
echo $banner;
echo '<div class="cb"></div>'.PHP_EOL;
}
echo '<div class="ico_j"><ul class="ico_j_ul1">'.PHP_EOL;
@ -128,18 +194,9 @@ while ($row = sql_fetch_array($result)) {
echo '</ul><ul class="ico_j_ul2"><img src="'.G5_THEME_URL.'/rb.img/ico_j.svg"></ul></div>'.PHP_EOL;
echo '</div><div class="cb"></div>'.PHP_EOL;
echo '</div>'.PHP_EOL;
if (isset($row['bn_ad_ico']) && $row['bn_ad_ico']) {
echo '<span class="ico_ad">AD</span>'.PHP_EOL;
}
echo '</div>'.PHP_EOL;
echo '</div>'.PHP_EOL; // sl_content 닫기
echo '</div>'.PHP_EOL; // sl_bn_inner 닫기
echo '</div>'.PHP_EOL; // swiper-slide 닫기
}
$i++;
}