<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가

// 5.4 미만 버전에서는 hook이 없습니다.
if (function_exists('add_event')) {
    add_event('tail_sub', 'tail_ver_hook_function', 0, 0);
}

function tail_ver_hook_function() {
    // 버전 정보를 가져옵니다.
    $version_file = file_get_contents('https://raw.githubusercontent.com/gnuboard/gnuboard5/master/version.php');
    
    // 정규 표현식으로 버전 정보 추출
    preg_match("/define\('G5_GNUBOARD_VER',\s*'([^']+)'\);/", $version_file, $matches);
    preg_match("/define\('G5_YOUNGCART_VER',\s*'([^']+)'\);/", $version_file, $matchesy);

    // 테마 및 버전 정보
    $theme = htmlspecialchars($GLOBALS['config']['cf_theme']);
    $gnuboard_version = $matches[1] ?? 'unknown';
    $youngcart_version = $matchesy[1] ?? 'unknown';

    // 스타일 및 스크립트
    echo '<style>
        .gyv {
            margin-top: -20px;
            margin-bottom: 20px;
            color: rgba(200, 200, 200, .1);
            text-align: center;
        }
        .gyv:hover {
            color: #fa0;
        }
    </style>';

    echo '<div class="gyv">
        <lii id="widthValue"></lii> <lii id="winSize"></lii>
        <script>
            var WindowsSize = function() {
                var w = $(window).width(), h = $(window).height();
                $("#winSize").html("(" + w + " * " + h + ")");
            };
            $(document).ready(WindowsSize);
            $(window).resize(WindowsSize);
        </script>';

    // 테마와 버전 정보를 출력
    echo "{$theme} / {$gnuboard_version}" . 
         (($gnuboard_version === G5_GNUBOARD_VER) ? ' latest' : '') . 
         (($youngcart_version === G5_YOUNGCART_VER) ? " / {$youngcart_version} latest" : " / {$youngcart_version}");

    echo '</div>';
}