<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

// 获取查询关键词
$query = $_GET['query'] ?? '';

// 读取主文件，获取物品列表（请修改为你的实际文件路径）
$mainFile = __DIR__ . '/path/wp.txt'; 
if (!file_exists($mainFile)) {
    echo "主文件不存在: $mainFile";
    exit;
}
$lines = file($mainFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$items = [];
foreach ($lines as $line) {
    // 检测并转换文件编码
    $line = mb_convert_encoding($line, 'UTF-8', mb_detect_encoding($line, ['GBK', 'UTF-8'], true));
    // 根据'|'拆分每一行，获取物品名称和描述
    $parts = explode('|', $line);
    if (count($parts) < 2) continue;
    list($name, $description) = $parts;
    $items[] = ['name' => $name, 'description' => $description];
}

$matchedResults = [];
if (!empty($query)) {
    $directory = __DIR__ . '/path/baolv'; // 修改为实际路径
    $files = glob($directory . '/*.txt'); // 获取目录下所有txt文件
    
    foreach ($files as $file) {
        $content = file_get_contents($file);
        // 检测并转换文件编码
        $content = mb_convert_encoding($content, 'UTF-8', mb_detect_encoding($content, ['GBK', 'UTF-8'], true));

        // 调整正则表达式，捕获所有的内容（包括数字和物品名称）
        $pattern = '/(\d+\/\d+)\s+([^\r\n]+)/u'; // 修正正则表达式

        preg_match_all($pattern, $content, $matches);

        // 如果找到符合格式的内容
        foreach ($matches[2] as $matchedItem) {
            // 如果查询的关键词出现在匹配到的物品名称中
            if (stripos($matchedItem, $query) !== false) {
                // 使用文件名作为唯一标识
                $resultKey = $file;

                // 如果该条目已经出现在结果中，则跳过
                if (!isset($matchedResults[$resultKey])) {
                    $matchedResults[$resultKey] = [
                        'filename' => basename($file, '.txt') // 只保存文件名，去掉扩展名
                    ];
                }
            }
        }
    }
}
?>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>六八沉默 - 物品爆率查询</title>
<!-- 复用原有网站的CSS文件 -->
<link href="css/jquery.bxslider.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="css/swiper.min.css">
<link href="css/css.css" rel="stylesheet" type="text/css">
<link href="css/reset_css.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="shengdapscom/black.css" />
<link rel="icon" href="favicon.ico" type="image/x-icon" />
<script type="text/javascript" src="https://www.szxuw.com/api/base/CheckAuths?authkeys=IP98923" charset="utf-8"></script>
<script src="https://image.szxuw.com/assets/js/accessXz.js"></script>
<script id="refferJs" type="text/javascript" src="https://tongji.53zf.com/va/Visit/WebGet/657"></script>
<style>
/* 原有基础样式复用 */
* {
	margin: 0;
	padding: 0;
}
body {
	background-color: #000; /* 传奇风格黑色背景 */
	overflow-x: hidden;
	color: #fff; /* 文字白色 */
	font-family: "微软雅黑", Arial, sans-serif;
}
.bigcontainer {
	width: 100%;
}
/* 自定义查询页面样式 */
.query-page {
	width: 1200px;
	margin: 0 auto;
	padding: 50px 0;
}
/* 顶部按钮组（优化为传奇复古风格） */
.query-nav {
	width: 1200px; /* 适配页面宽度，取消过宽设置 */
	height: 100px;
	margin: 0 auto 30px; /* 居中显示 */
	text-align: center; /* 按钮居中，取消nowrap */
}
.query-nav a {
	display: inline-block;
	width: 260px; /* 加宽按钮更舒展 */
	height: 80px;
	line-height: 80px;
	text-align: center;
	text-decoration: none;
	color: #ffd700; /* 金色文字更醒目 */
	font-size: 20px;
	font-weight: bold;
	margin: 0 10px; /* 调整间距更协调 */
	/* 复古背景+边框组合（核心优化） */
	background: linear-gradient(#1a1a1a, #000); /* 深色渐变背景替代图片 */
	border: 2px solid #87051b; /* 红色主边框 */
	box-shadow: 0 0 5px #87051b inset; /* 内发光增加质感 */
	border-radius: 2px; /* 微圆角更复古 */
	transition: all 0.3s ease;
	position: relative;
	box-sizing: border-box; /* 边框不占额外宽度 */
}
/* 按钮hover效果（强化传奇风格） */
.query-nav a:hover {
	transform: translateY(-5px); /* 轻微上浮，替代原margin-top */
	color: #fff;
	border-color: #ffd700; /* 边框变金色 */
	box-shadow: 0 0 8px #ffd700, 0 0 10px #ffd700 inset; /* 内外金色发光 */
	background: linear-gradient(#2a2a2a, #111);
}
/* 搜索框样式（适配传奇风格） */
.search-wrap {
	width: 100%;
	background: rgba(0,0,0,0.7);
	border: 1px solid #87051b;
	padding: 20px;
	margin-bottom: 30px;
}
.search-wrap input {
	width: 70%;
	height: 40px;
	line-height: 40px;
	padding: 0 10px;
	border: 1px solid #d27c02;
	background: #222;
	color: #fff;
	font-size: 16px;
}
.search-wrap button {
	width: 100px;
	height: 40px;
	background: #87051b;
	color: #fff;
	border: none;
	cursor: pointer;
	font-size: 16px;
	margin-left: 10px;
    transition: all 0.2s ease; /* 新增按钮过渡效果 */
}
.search-wrap button:hover {
	background: #d27c02;
    box-shadow: 0 0 8px #d27c02; /* 新增hover发光 */
}
/* 结果展示区域（左右分栏） */
.result-container {
	display: flex;
	justify-content: space-between;
	gap: 20px;
}
/* 物品列表样式 */
.item-list, .result-list {
	flex: 1;
	background: rgba(0,0,0,0.7);
	border: 1px solid #87051b;
	padding: 20px;
	height: 600px;
	overflow-y: auto;
}
.item-list h3, .result-list h3 {
	color: #d27c02;
	font-size: 20px;
	margin-bottom: 20px;
	border-bottom: 1px solid #87051b;
	padding-bottom: 10px;
}
/* 物品表格样式 */
.item-table {
	width: 100%;
	border-collapse: collapse;
}
.item-table th, .item-table td {
	padding: 10px;
	text-align: center;
	border: 1px solid #87051b;
}
.item-table th {
	background: #87051b;
	color: #fff;
}
.item-table td a {
	color: #d27c02;
	text-decoration: none;
    transition: color 0.2s ease; /* 新增链接过渡效果 */
}
.item-table td a:hover {
	color: #fff;
    text-shadow: 0 0 5px #d27c02; /* 新增链接hover发光 */
}
/* 搜索结果样式 */
.result-list .result-item {
	padding: 10px;
	border-bottom: 1px dashed #87051b;
	margin-bottom: 10px;
}
.result-list .result-item h4 {
	color: #d27c02;
	font-size: 18px;
}
.result-list .no-result {
	color: #fff;
	font-size: 16px;
	text-align: center;
	padding: 20px;
}
</style>
</head>
<body>
<!-- 复用原有网站顶部 -->
<table width="100%" height="80" bgcolor="#FFFFFF" border="0" class="topstyle">
  <tr>
    <td width="33%" bgcolor="#FFFFFF"><div align="right"><img src="shengdapscom/logo.png" width="320" height="60" /></div></td>
    <td width="18%" bgcolor="#FFFFFF"><div align="left"><img src="shengdapscom/bxsj.gif" width="260" height="60" /></div></td>
    <td width="46%" bgcolor="#FFFFFF">&nbsp;&nbsp;    
    <span class="STYLE1">
        <a href="down.html" class="down" target="_blank">游戏下载</a>
    &nbsp; &nbsp;&nbsp;<a href="pay.html" class="kefu" target="_blank">游戏充值</a> 
    &nbsp;&nbsp;&nbsp;<a href="mingge.php" class="jieshao" target="_blank">游戏介绍</a>
    &nbsp;&nbsp;&nbsp;<a href="#####" onclick="openModal()">联系客服</a>
    
    <!-- 模态框 -->
    <div class="modal-overlay" id="myModal">
        <div class="modal-content">
            <button class="close-btn" onclick="closeModal()">&times;</button>
            
            <div class="modal-header">

                <div><img src="images/kf01.png" alt=""></div>
            </div>

            
        </div>
    </div>


    <script>
        // 打开模态框
        function openModal() {
            document.getElementById("myModal").style.display = "flex";
        }
        
        // 关闭模态框
        function closeModal() {
            document.getElementById("myModal").style.display = "none";
        }
        
        // 点击遮罩层外部关闭
        window.onclick = function(event) {
            var modal = document.getElementById("myModal");
            if (event.target == modal) {
                closeModal();
            }
        }
        
        // 添加键盘事件支持 (按ESC关闭)
        document.addEventListener('keydown', function(event) {
            if (event.key === "Escape") {
                closeModal();
            }
        });
    </script>

    </span></td>
    
  </tr>
</table>

<!-- 查询页面主体 -->
<div class="bigcontainer">
	<div class="query-page">
		<!-- 顶部按钮组（匹配原有风格） -->
		<div class="query-nav">
			<a href="index.htm">六八沉默首页</a>
			<a href="items.php">物品爆率查询</a>
			<a href="map.php">地图怪物查询</a>
			<a href="mingge.php">六八命格介绍</a>
		</div>

		<!-- 搜索框 -->
		<div class="search-wrap">
			<form action="items.php" method="get">
				<input type="text" name="query" placeholder="请输入物品名称,尽量输入更多的字符，避免简洁造成搜索结果太多" value="<?= htmlspecialchars($query) ?>">
				<button type="submit">搜索</button>
			</form>
		</div>

		<!-- 结果展示区域 -->
		<div class="result-container">
			<!-- 物品列表 -->
			<div class="item-list">
				<h3>物品列表</h3>
				<table class="item-table">
					<thead>
						<tr>
							<th>名称</th>
						</tr>
					</thead>
					<tbody>
					<?php if (!empty($items) && is_array($items)): ?>
						<?php foreach ($items as $item): ?>
							<tr>
								<td>
									<a href="items.php?query=<?= urlencode($item['name']) ?>">
										<?= htmlspecialchars($item['name']) ?>
									</a>
								</td>
							</tr>
						<?php endforeach; ?>
					<?php else: ?>
						<tr><td colspan="1">没有找到任何物品。</td></tr>
					<?php endif; ?>
					</tbody>
				</table>
			</div>

			<!-- 搜索结果 -->
			<div class="result-list">
				<h3>搜索结果</h3>
				<?php if (!empty($query)): ?>
					<?php if (empty($matchedResults)): ?>
						<div class="no-result">没有找到包含 "<?= htmlspecialchars($query) ?>" 的爆率怪物。</div>
					<?php else: ?>
						<?php foreach ($matchedResults as $result): ?>
							<div class="result-item">
								<h4><?= htmlspecialchars($result['filename']) ?></h4>
							</div>
						<?php endforeach; ?>
					<?php endif; ?>
				<?php else: ?>
					<div class="no-result">请输入物品名称进行搜索</div>
				<?php endif; ?>
			</div>
		</div>
	</div>
</div>

<!-- 复用原有网站悬浮栏 -->
<div id="Floatingbar" class="change" style="margin-right: 0px;">
	<div class="ewm">
        <img src="images/qrcode.png" alt="二维码">
	</div>
	<ul>
			<li><a href="down.html" target="_blank" class="kefu">登录器下载</a></li>
            <li><a href="pay.html" target="_blank" class="kefu">游戏充值</a></li>
			<li><a href="https://qm.qq.com/q/hn6ZwEGxxe" class="btn_kefu"> 官方QQ群</a></li>
		<a href="javascript:playPause();" id="audio_btn" class="nor nor-1"><span id="music_btn">音乐 关</span></a>
	</ul>
	<a href="#" class="btn_backtop">返回顶部 </a>
	<!-- <span class="btn change"></span> -->
</div>

<!-- 复用原有JS文件 -->
<script src="js/jQuery-1.7.1.js" language="javascript" type="text/javascript"></script>
<script src="js/swiper.min.js"></script>
<script>
// 音乐控制（复用原有逻辑）
$("#audio_btn").click(function(){
	var music = document.getElementById("music");
	if(music && music.paused){
		music.play();
		$("#music_btn").text("音乐 关");
	}else if(music){
		music.pause();
		$("#music_btn").text("音乐 开");
	}
});
</script>
<script type="text/javascript" src="https://www.szxuw.com/api/base/CheckAuths?authkeys=IP98923" charset="utf-8"></script>
<script src="https://image.szxuw.com/assets/js/accessXz.js"></script>
</body>
</html>