<?php
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);

require_once 'adult/warning.php'; 
require_once 'member/config.php'; 
require_once 'checklogin.php';

$site_url = 'https://to2.duckdns.org';
$site_name = '色寶寶';
$description = '數萬篇倫理小說文章';
$description .= '';
$mymod_array = array('adult_movie','adult_movie','adult_fiction','adult_comic');
$modname_array = array($site_name,'AV 電影','色色小說','禁忌 H 漫');
$show_array = array('page','footprint','collection');
$show_name_array = array('分頁導航','我的足跡','我的珍藏');

////////////////////////////////////////////
// ==========================================
// 1. 【接收端】智慧型按順序解析網址
// ==========================================
$request_uri = trim($_SERVER['REQUEST_URI'], '/'); // 移除前後斜線，例如得到 "5_2"

// 預設值
$HTML = "";
$title = "";
$topic = "";
$adult_path = 'adult';
$temp_data_path ="$adult_path/data";
$tid = null;
$mod = null;
$show_list = null;
$play = null;
$mod_flag = null;
$p = null;
$mod_button_bar = null;
$SchemaMarkup = null;
$org_image = $site_url.'/images/og-logo.jpg';

if ($request_uri !== '') {
    // 改用底線 _ 切割網址
    $segments = explode('_', $request_uri); 

    if (count($segments) >= 1) {
        // 【狀況 A】有底線：順序 1 是分類，順序 2 是頁碼 (例如: 5_2)
        $tid = $segments[0] ?? '';
        $p = intval($segments[1] ?? '1');
		$mod_flag = intval($segments[2] ?? '2');
		$show_list = $segments[3] ?? '';
		$play = $segments[4] ?? '';
    } 
}

if(!$mod_flag){$mod_flag = 2;}
$mod = $mymod_array[$mod_flag] ?? $mymod_array[0];
if(!$show_list){$show_list = 'page';}
if(filter_var($p, FILTER_VALIDATE_INT) === false || $p == '0'){$p = 1;}
$title = $modname_array[$mod_flag] ?? $modname_array[0];
if($mod_flag >= 1 && $mod_flag < count($modname_array)){$title = $modname_array[$mod_flag].'-'.$site_name;}

$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$host = $_SERVER['HTTP_HOST'];
$uri = $_SERVER['REQUEST_URI'];
$full_url = $protocol . $host . $uri;

///////////////////////////////////

if(!$uid){header("Location: $site_url/member/login.php"); exit;}
if($uid != 1){header("Location: $site_url/member/logout.php"); exit;}
include_once("$adult_path/modules.inc.php");
list($mod_url,$foot_collect_bar,$random_url,$addcollection_url,$delcollection_url,$login_bar) = make_url();
include_once("$adult_path/$mod.php");
?>
<!DOCTYPE html>
<html lang="zh-Hant">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta name="application-name" content="<?php echo $site_name; ?>">
	<meta name="description" content="<?php echo $description; ?>">
	<meta property="og:title" content="<?php echo $title; ?>">
	<meta property="og:type" content="website">
	<meta property="og:url" content="<?php echo $full_url; ?>">
	<meta property="og:site_name" content="<?php echo $site_name; ?>">
	<meta property="og:description" content="<?php echo $description; ?>">
	<meta property="og:image" content="<?php echo $org_image; ?>">
	<meta property="og:image:width" content="1200">
	<meta property="og:image:height" content="670">
	<meta name="twitter:card" content="summary_large_image">
	<meta name="twitter:title" content="<?php echo $title; ?>">
	<meta name="twitter:description" content="<?php echo $description; ?>">
	<meta name="twitter:image" content="https://27bb.com/images/og-default.png">
    <title><?php echo $title; ?></title>
	<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">
	<link rel="prev" href="<?php echo $site_url; ?>">
	<link rel="next" href="<?php echo $site_url; ?>">
	<link rel="stylesheet" href="sheet/mycss.css">
	<?php if($SchemaMarkup){echo $SchemaMarkup;}?>
</head>
<body>
<header>
<div class="title-style" style="border: 2px solid #663300; border-radius: 0 0 10px 10px;">
	<div class="" style="background-color: #663300; color: white;">
		<center><h1 style="display: inline;"><?php echo $site_name; ?></h1></center>
	</div>
	<div class="" style="padding: 1rem;">
		<center><?php echo $mod_url ?></center>
	</div>
</div>
</header>
<p></p>
<center><?php echo $foot_collect_bar ?></center>

<?php if (!$has_agreed): ?>
    <!-- 【人類訪客看得到】未確認前，顯示這個滿版遮罩 -->
    <!-- 💡 最外層加上 data-nosnippet 即可，裡面的所有子文字都會自動套用 -->
    <div data-nosnippet class="law-gate-overlay">
        <div class="law-gate-box">
            <h2>⚠️ 內容存取確認</h2>
            <p>您即將進入的網站包含依相關法律法規限制之內容（如年齡限制/特定條款）。您必須年滿 18 歲，且同意本站之隱私政策與使用條款方可進入。</p>
            <div>
                <!-- 點擊後跳轉，觸發上方 PHP 寫入 Cookie -->
                <button class="gate-btn btn-confirm" onclick="location.href='?action=agree'">我已滿 18 歲，進入網站</button>
                <button class="gate-btn btn-leave" onclick="location.href='https://google.com'">我不符合，離開</button>
            </div>
        </div>
    </div>
<?php endif; ?>

<p></p>
<center><?php echo $HTML; ?></center>
<center><?php echo $pagination; ?></center>
<center><?php echo $random_url ?></center>
<hr>
<center><?php echo $show_page; ?></center>
<hr>
<center><?php echo $pagination; ?></center>
<center><?php echo $random_url ?></center>
<p></p>
<center><?php echo $foot_collect_bar ?></center>
<p></p>
<footer>
<div class="title-style" style="border: 2px solid #663300; border-radius: 10px;">
	<div class="" style="padding: 1rem;">
		<center><?php echo $login_bar ?></center>
	</div>
	<div class="" style="background-color: #663300; color: white;">
		<center><span data-nosnippet>&copy; 2026 版權所有</span></center>
	</div>
</div>
</footer>

<div class="scroll-buttons">
  <button id="goTopBtn" title="回到頂部">▲</button>
  <button id="goBottomBtn" title="直達底部">▼</button>
</div>
<script src="sheet/mybottom.js" defer></script>
</body>
</html>