<?php
/**
 * 首页
 */
require_once __DIR__ . '/config/config.php';
require_once __DIR__ . '/common/functions.php';

$db = getDB();
// 获取最新的桌游，按修改时间倒序，最多显示40个
$stmt = $db->query("SELECT * FROM game_boardgame WHERE checked = 1 ORDER BY lastdotime DESC, newstime DESC LIMIT 40");
$games = $stmt->fetchAll();
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="google-adsense-account" content="ca-pub-1956258494221261">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" >
<meta name="renderer" content="webkit">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="format-detection" content="telephone=no" />
<?php $homeSeo = seoHomeMeta(); ?>
<link rel="canonical" href="http://www.186996.com/" />
<meta property="og:title" content="<?= h($homeSeo['og_title']) ?>" />
<meta property="og:description" content="<?= h($homeSeo['og_description']) ?>" />
<meta property="og:type" content="website" />
<meta property="og:url" content="http://www.186996.com/" />
<link href="/css/font-awesome.min.css" rel="stylesheet">
<link href="/css/style.css" rel="stylesheet">
<link href="/css/media.css" rel="stylesheet">
<link href="/css/site-header.css" rel="stylesheet">
<link href="/css/site-unified.css" rel="stylesheet">
<?php echo renderSignupFooterHeadAssetsHtml('/'); ?>
<?php echo getAnalyticsCode('head'); ?>
<title><?= h($homeSeo['title']) ?></title>
<meta name="keywords" content="<?= h($homeSeo['keywords']) ?>">
<meta name="description" content="<?= h($homeSeo['description']) ?>">
</head>

<body oncopy="return false;">
<?php
// 统一头部组件（首页无面包屑）
$basePath = '/';
$activeNav = '';
include __DIR__ . '/common/header.php';
?>
<!-- 头部结束 -->

<!-- 中间内容 -->
<div id="container"> 

<!-- 广告 -->
<div class="banner"></div>
<!-- 广告结束 --> 

  <!-- 桌游 -->
  <div class="boardgame-list">
    <div class="list-title">
      <h2>BOARDGAME</h2>
    </div>
    <!-- items -->
    <?php if (empty($games)): ?>
      <div style="text-align: center; padding: 40px;">暂无桌游</div>
    <?php else: ?>
      <?php 
      $deviceType = detectDeviceType();
      $listAdCode = getAdCodeByPosition('home_list', $deviceType);
      $adInterval = 12; // 每12个桌游插入一个广告
      $gameIndex = 0;
      foreach ($games as $game): 
        $gameIndex++;
      ?>
        <dl>
          <?php
          // 确保filename有.html后缀
          $filename = $game['filename'];
          if (!preg_match('/\.html$/i', $filename)) {
              $filename .= '.html';
          }
          $imageBase = boardgameCdnGameImageUrl(boardgameImageSlug($filename), 0);
          $fullTitle = isset($game['title']) ? $game['title'] : '';
          // 标题限制长度：18 单位（≈9 个汉字），避免超长影响布局
          $shortTitle = truncateTitle($fullTitle, 18);
          ?>
          <a href="/boardgame/<?= h($filename) ?>" target="_blank" title='<?= h(seoBoardgameLinkTitle($game)) ?>'>
            <img src="<?= $imageBase ?>" alt="<?= h(seoBoardgameImageAlt($game)) ?>">
            <p><?= h($shortTitle) ?></p>
          </a>
        </dl>
        <?php 
        // 每12个桌游后插入广告（电脑端显示为3排，每排4个，共12个）
        if ($gameIndex % $adInterval == 0 && !empty($listAdCode)): 
        ?>
        <div style="width: 100%; clear: both; margin: 20px 0; padding: 15px; background: #f9fafb; border-radius: 8px; text-align: center;">
          <?= $listAdCode ?>
        </div>
        <?php endif; ?>
      <?php endforeach; ?>
    <?php endif; ?>
    <!-- more items --> </div>
  <!-- 桌游结束 --> 
  
  <!-- 隐藏的分类表格 -->
  <?= renderBoardgameTypeHiddenNavHtml('/') ?>
  <!-- 隐藏的分类表格结束 -->
  
</div>
<!-- 中间结束 -->
<div class="site-clearfix" aria-hidden="true"></div>

<script type="text/javascript" src="http://www.186996.com/js/jquery.min.js"></script>
<script type="text/javascript" src="http://www.186996.com/js/global.js"></script>
<script type="text/javascript" src="http://www.186996.com/common/device_redirect.js"></script>

<!-- 底部 -->
<?php
// 统一底部组件
$basePath = '/';
include __DIR__ . '/common/footer.php';
?>
<?php echo getAnalyticsCode('body'); ?>

</body>
</html>

