<?php
// 이 파일은 새로운 파일 생성시 반드시 포함되어야 함
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가

$g5_debug['php']['begin_time'] = $begin_time = get_microtime();

if (!isset($g5['title'])) {
    $g5['title'] = $config['cf_title'];
    $g5_head_title = $g5['title'];
}
else {
    $g5_head_title = $g5['title']; // 상태바에 표시될 제목
    $g5_head_title .= " | ".$config['cf_title'];
}

$g5['title'] = strip_tags($g5['title']);
$g5_head_title = strip_tags($g5_head_title);

// 현재 접속자
// 게시판 제목에 ' 포함되면 오류 발생
$g5['lo_location'] = addslashes($g5['title']);
if (!$g5['lo_location'])
    $g5['lo_location'] = addslashes(clean_xss_tags($_SERVER['REQUEST_URI']));
$g5['lo_url'] = addslashes(clean_xss_tags($_SERVER['REQUEST_URI']));
if (strstr($g5['lo_url'], '/'.G5_ADMIN_DIR.'/') || $is_admin == 'super') $g5['lo_url'] = '';

/*
// 만료된 페이지로 사용하시는 경우
header("Cache-Control: no-cache"); // HTTP/1.1
header("Expires: 0"); // rfc2616 - Section 14.21
header("Pragma: no-cache"); // HTTP/1.0
*/
?>

<!--ip 리다이렉션-->
<?php
$full_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https://" : "http://") . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
 
// https 도메인 redirect 하기
if (stripos($full_url, "https://114.200.192.149") !== false) {
    goto_url("https://dsclub.kr" . $_SERVER['REQUEST_URI']);
}
// http 도메인 redirect 하기
if (stripos($full_url, "http://114.200.192.149") !== false) {
    goto_url("https://dsclub.kr" . $_SERVER['REQUEST_URI']);
}
// 참고, 위 둘을 한꺼번에 처리하기
if (stripos($full_url, "//114.200.192.149") !== false) {
    goto_url("https://dsclub.kr" . $_SERVER['REQUEST_URI']);
}
?>
<!--끝-->
<!-- www to none{ -->
<?php
$full_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https://" : "http://") . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
 
// https 도메인 redirect 하기
if (stripos($full_url, "https://www.dsclub.kr") !== false) {
    goto_url("https://dsclub.kr" . $_SERVER['REQUEST_URI']);
}
// http 도메인 redirect 하기
if (stripos($full_url, "http://www.dsclub.kr") !== false) {
    goto_url("https://dsclub.kr" . $_SERVER['REQUEST_URI']);
}
// 참고, 위 둘을 한꺼번에 처리하기
if (stripos($full_url, "//www.dsclub.kr") !== false) {
    goto_url("https://dsclub.kr" . $_SERVER['REQUEST_URI']);
}
?>
<!--끝-->
<!--http를 https로 강제 리다이렉트-->
<?php
 
//If the HTTPS is not found to be "on"
if(!isset($_SERVER["HTTPS"]) || $_SERVER["HTTPS"] != "on")
{
    //Tell the browser to redirect to the HTTPS URL.
    header("Location: https://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"], true, 301);
    //Prevent the rest of the script from executing.
    exit;
}
?>
<!--끝-->

<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<?php
if (G5_IS_MOBILE) {
    echo '<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=0,maximum-scale=10,user-scalable=no">'.PHP_EOL;
    echo '<meta name="HandheldFriendly" content="true">'.PHP_EOL;
    echo '<meta name="format-detection" content="telephone=no">'.PHP_EOL;
} else {
    echo '<meta http-equiv="imagetoolbar" content="no">'.PHP_EOL;
    echo '<meta http-equiv="X-UA-Compatible" content="IE=edge">'.PHP_EOL;
}

if($config['cf_add_meta'])
    echo $config['cf_add_meta'].PHP_EOL;
?>
<title><?php echo $g5_head_title; ?></title>
<link rel="stylesheet" href="<?php echo run_replace('head_css_url', G5_THEME_CSS_URL.'/'.(G5_IS_MOBILE ? 'mobile' : 'default').'.css?ver='.G5_CSS_VER, G5_THEME_URL); ?>">
<!--[if lte IE 8]>
<script src="<?php echo G5_JS_URL ?>/html5.js"></script>
<![endif]-->
<script>
// 자바스크립트에서 사용하는 전역변수 선언
var g5_url       = "<?php echo G5_URL ?>";
var g5_bbs_url   = "<?php echo G5_BBS_URL ?>";
var g5_is_member = "<?php echo isset($is_member)?$is_member:''; ?>";
var g5_is_admin  = "<?php echo isset($is_admin)?$is_admin:''; ?>";
var g5_is_mobile = "<?php echo G5_IS_MOBILE ?>";
var g5_bo_table  = "<?php echo isset($bo_table)?$bo_table:''; ?>";
var g5_sca       = "<?php echo isset($sca)?$sca:''; ?>";
var g5_editor    = "<?php echo ($config['cf_editor'] && $board['bo_use_dhtml_editor'])?$config['cf_editor']:''; ?>";
var g5_cookie_domain = "<?php echo G5_COOKIE_DOMAIN ?>";
</script>
<?php
add_javascript('<script src="'.G5_JS_URL.'/jquery-1.12.4.min.js"></script>', 0);
add_javascript('<script src="'.G5_JS_URL.'/jquery-migrate-1.4.1.min.js"></script>', 0);
add_javascript('<script src="'.G5_JS_URL.'/jquery.menu.js?ver='.G5_JS_VER.'"></script>', 0);
add_javascript('<script src="'.G5_JS_URL.'/common.js?ver='.G5_JS_VER.'"></script>', 0);
add_javascript('<script src="'.G5_JS_URL.'/wrest.js?ver='.G5_JS_VER.'"></script>', 0);
add_javascript('<script src="'.G5_JS_URL.'/placeholders.min.js"></script>', 0);
add_stylesheet('<link rel="stylesheet" href="'.G5_JS_URL.'/font-awesome/css/font-awesome.min.css">', 0);

if(G5_IS_MOBILE) {
    echo '<script src="'.G5_JS_URL.'/modernizr.custom.70111.js"></script>'.PHP_EOL; // overflow scroll 감지
}
if(!defined('G5_IS_ADMIN'))
    echo $config['cf_add_script'];
?>
<!-- lazyload{ -->
<script src="<?php echo G5_JS_URL; ?>/jquery.lazyload.min.js"></script>
<script type="text/javascript" charset="utf-8"> //lazyload 기능 추가
    $(document).ready(function(){
        $("img.lazy").lazyload({
            threshold : 10,
            effect : "fadeIn",
        });
    });
</script>
<!-- 폰트 커스텀{ -->
<link rel="stylesheet" href="https://fonts.googleapis.com/earlyaccess/nanumgothic.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/earlyaccess/nanummyeongjo.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/earlyaccess/nanumbrushscript.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/earlyaccess/jejugothic.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/earlyaccess/jejuhallasan.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/earlyaccess/hanna.css">

<style>
    body, .latest_member_id, .latest_subject, .latest_content {
        font-family: 'Nanum Gothic', sans-serif;
    }
</style>

<script>
    document.addEventListener("DOMContentLoaded", function() {
        // 모든 요소가 로드된 후 스타일을 적용
        document.body.style.fontFamily = "'Nanum Gothic', sans-serif";
        // 추가적으로 필요한 요소에 대해 스타일을 적용할 수 있습니다.
    });
</script>
    <!-- }폰트 커스텀 -->
    <!-- 모바일 확대 방지{ -->
<script>
  document.addEventListener('touchstart', function(event) {
    if (event.touches.length > 1) {
      event.preventDefault();
    }
  }, { passive: false });

  document.addEventListener('gesturestart', function(event) {
    event.preventDefault();
  });
</script>
</head>
<body<?php echo isset($g5['body_script']) ? $g5['body_script'] : ''; ?>>
<?php
if ($is_member) { // 회원이라면 로그인 중이라는 메세지를 출력해준다.
    $sr_admin_msg = '';
    if ($is_admin == 'super') $sr_admin_msg = "최고관리자 ";
    else if ($is_admin == 'group') $sr_admin_msg = "그룹관리자 ";
    else if ($is_admin == 'board') $sr_admin_msg = "게시판관리자 ";

    echo '<div id="hd_login_msg">'.$sr_admin_msg.get_text($member['mb_nick']).'님 로그인 중 ';
    echo '<a href="'.G5_BBS_URL.'/logout.php">로그아웃</a></div>';
}
?>
<!-- 온라인/오프라인 표시{ -->
<style> .offline-banner{background-color:#3c3c3c;color:#ddd;border-bottom: 1px solid #4c4c4c;text-align:center;padding:10px;border-top:1px solid #ccc;position:fixed;top:0;left:0;width:100%;z-index:9999;display:none}.online-banner{background-color:#f1f1f1;color:3c3c3c;text-align:center;padding:10px;border-top:1px solid #ccc;position:fixed;top:0;left:0;width:100%;z-index:9999;display:none}.banner-content{display:flex;align-items:center;justify-content:center}.icon{margin-right:10px}</style><div id="status-banner" class="offline-banner"><div class="banner-content"><div class="icon">✈️</div><div class="status-text">오프라인</div></div></div><script>
const statusBanner=document.getElementById('status-banner');const statusText=document.querySelector('.status-text');function checkOnlineStatus(){if(navigator.onLine){statusText.textContent = '온라인입니다.';statusBanner.classList.remove('offline-banner');
statusBanner.classList.add('online-banner');setTimeout(() => {statusBanner.style.display = 'none';}, 3000);}else{statusText.textContent = '오프라인입니다.';statusBanner.style.display = 'block';statusBanner.classList.remove('online-banner');
statusBanner.classList.add('offline-banner');}}
checkOnlineStatus();window.addEventListener('online', checkOnlineStatus);window.addEventListener('offline', checkOnlineStatus);</script>

<!-- 광고{ -->
<amp-auto-ads type="adsense"
        data-ad-client="ca-pub-9785814502725457">
</amp-auto-ads>
<!-- } 자동 광고 끝 -->
<!-- 서버 정기 정검(서버 재시작) 안내{ -->
<style>
  #spopup {
    display: none;
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    border: none;
    background-color: #fff;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    border-radius: 8px;
  }

  #soverlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
  }

  .s h2 {
    margin: 0 0 10px;
    font-size: 1.5em;
    color: #333;
  }

  .s p {
    margin: 10px 0;
    color: #555;
  }

  .s button {
    background-color: #4285F4;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 10px 15px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.3s;
  }

  .s button:hover {
    background-color: #357AE8;
  }

  #countdown {
    font-weight: bold;
    color: #d32f2f; /* Red color for countdown */
  }
</style>

<div id="soverlay"></div>
<div id="spopup">
  <h2 class="s">서버 점검 안내</h2>
  <p class="s">
dsclub은 서비스의 안정성과 성능 향상을 위해<br>
매일 04시 30분에 정기 점검이 진행됩니다.
</p>
  <p class="s">점검 시간: 오전 4시 30분 ~ 4시 35분</p>
  <p class="s">해당 시간 동안 일시적으로 서비스에 접속이 불가능하오니, 양해 부탁드립니다.</p>
  <p id="countdown"></p>
  <button onclick="closePopup()" class="s">확인</button>
</div>

<script>
  function showPopup() {
    document.getElementById("soverlay").style.display = "block";
    document.getElementById("spopup").style.display = "block";
    startCountdown();
  }

  function closePopup() {
    document.getElementById("soverlay").style.display = "none";
    document.getElementById("spopup").style.display = "none";
  }

  function startCountdown() {
    const endTime = new Date();
    endTime.setHours(4, 30, 0); // 4시 30분 설정
    const countdownElement = document.getElementById("countdown");
    
    const interval = setInterval(function () {
      const now = new Date();
      const timeRemaining = endTime - now;
      
      if (timeRemaining <= 0) {
        clearInterval(interval);
        countdownElement.innerHTML = "점검 시간이 시작되었습니다.";
      } else {
        const minutes = Math.floor((timeRemaining % (1000 * 60 * 60)) / (1000 * 60));
        const seconds = Math.floor((timeRemaining % (1000 * 60)) / 1000);
        countdownElement.innerHTML = `점검 시작까지 ${minutes}분 ${seconds}초 남았습니다.`;
      }
    }, 1000);
  }

  function checkTime() {
    const now = new Date();
    if (now.getHours() === 4 && now.getMinutes() >= 25 && now.getMinutes() < 30) {
      showPopup();
    }
  }

  setInterval(checkTime, 60000); // 1분마다 시간 체크
</script>