<?php
mb_internal_encoding('UTF-8');
header('Content-Type: text/html; charset=UTF-8');
function u($hex){ return hex2bin($hex); }
function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); }
function cut($s,$n){ $s=trim(strip_tags((string)$s)); return mb_strlen($s)>$n ? mb_substr($s,0,$n).'...' : $s; }
function pic($u){ if(!$u) return '/placeholder.svg'; return preg_match('#doubanio#i',$u) ? '/img_proxy.php?u='.rawurlencode($u) : $u; }
function rows($pdo,$where,$limit=36){ $st=$pdo->query('SELECT vod_id,vod_name,vod_pic,vod_year,vod_class,vod_time,vod_remarks FROM mac_vod WHERE vod_status=1 '.$where.' LIMIT '.intval($limit)); return $st ? $st->fetchAll() : array(); }
function site_brand($host){ $name=preg_replace('/^www\./','',$host); $map=array('168movie.com'=>'168影院','9527movie.com'=>'9527影院','haoduoyy.com'=>'好多影院','jisufilm.com'=>'极速影视','kukanfilm.com'=>'酷看影视','pianyiku.com'=>'片一库','shandiankan.com'=>'闪电看','wuxianyy.com'=>'无限影院','zhuijubar.com'=>'追剧吧','zhujubar.com'=>'追剧吧'); return $map[$name] ?? $name; }
function fmt_time($ts){ return $ts ? date('m-d H:i', intval($ts)) : ''; }

$cfg=require __DIR__.'/application/database.php';
$pdo=new PDO('mysql:host='.$cfg['hostname'].';port='.($cfg['hostport']?:3306).';dbname='.$cfg['database'].';charset=utf8mb4',$cfg['username'],$cfg['password'],array(PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION,PDO::ATTR_DEFAULT_FETCH_MODE=>PDO::FETCH_ASSOC));
$host=$_SERVER['HTTP_HOST']??'localhost'; $uri=parse_url($_SERVER['REQUEST_URI']??'/',PHP_URL_PATH); $base=((!empty($_SERVER['HTTPS'])&&$_SERVER['HTTPS']!=='off')?'https':'http').'://'.$host; $brand=site_brand($host);
$primary='#38bdf8'; $bg='#0f172a'; $card='#162033';
$homeTitle=u('e69c80e696b0e69bb4e696b0'); $hotTitle=u('e783ade692ade6a69c'); $shortTitle=u('e79fade589a7e6a69c'); $scoreTitle=u('e9ab98e58886e6a69c');
$pageMap=array(
 '/movie-hot.html'=>array(u('e794b5e5bdb1e783ade692ade6a69c'),'AND type_id_1=1 ORDER BY vod_hits DESC, vod_time DESC'),
 '/tv-hot.html'=>array(u('e794b5e8a786e589a7e783ade692ade6a69c'),'AND type_id_1=2 ORDER BY vod_hits DESC, vod_time DESC'),
 '/cartoon-hot.html'=>array(u('e58aa8e6bcabe783ade692ade6a69c'),'AND (type_id=3 OR type_id_1=3) ORDER BY vod_hits DESC, vod_time DESC'),
 '/variety-hot.html'=>array(u('e7bbbce889bae783ade692ade6a69c'),'AND (type_id=4 OR type_id_1=4) ORDER BY vod_hits DESC, vod_time DESC'),
 '/gangtai-hot.html'=>array(u('e6b8afe58fb0e783ade692ade6a69c'),'AND (type_id=16 OR vod_area LIKE "%'.u('e9a699e6b8af').'%" OR vod_area LIKE "%'.u('e58fb0e6b9be').'%") ORDER BY vod_hits DESC, vod_time DESC'),
 '/classic.html'=>array(u('e7bb8fe585b8e78987e58d95'),'AND (vod_year<="2015" OR vod_tag LIKE "%'.u('e7bb8fe585b8').'%") ORDER BY vod_hits DESC, vod_time DESC'),
 '/upcoming.html'=>array(u('e69c80e696b0e5bdb1e8a786e68ea8e88d90'),'ORDER BY vod_time DESC, vod_hits DESC')
);

if ($uri==='/' || $uri==='/index.html') {
  $title=$brand.' - '.$homeTitle;
  $desc=$brand.u('e68c81e7bbade69bb4e696b0e69c80e696b0e5bdb1e8a786e8b584e6ba90efbc8ce68c89e585a5e5ba93e697b6e997b4e5b195e7a4bae69c80e696b0e5bdb1e78987e38082');
  $latest=rows($pdo,'ORDER BY vod_time DESC, vod_id DESC',24);
  $hot=rows($pdo,'ORDER BY vod_hits DESC, vod_time DESC',18);
  $short=rows($pdo,'AND (type_id=5 OR type_id_1=5 OR vod_class LIKE "%'.u('e79fade589a7').'%") ORDER BY vod_time DESC, vod_hits DESC',18);
} elseif (isset($pageMap[$uri])) {
  $title=$pageMap[$uri][0].' - '.$brand;
  $desc=$pageMap[$uri][0].u('efbc8ce68c89e69c80e696b0e585a5e5ba93e5928ce783ade5baa6e695b4e79086e5bdb1e8a786e8b584e6ba90e38082');
  $list=rows($pdo,$pageMap[$uri][1],48);
} elseif (strpos($uri,'/news')===0) {
  $title=u('e5bdb1e8a786e8b584e8aeaf').' - '.$brand;
  $desc=$brand.u('e5bdb1e8a786e8b584e8aeafefbc8ce58c85e590abe783ade692ade38081e79fade589a7e38081e6bc94e59198e4b893e9a298e5928ce8a782e58985e68ea8e88d90e38082');
  $news=true;
} else {
  $title=$homeTitle.' - '.$brand;
  $desc=$brand.u('e69c80e696b0e5bdb1e8a786e8b584e6ba90e38082');
  $list=rows($pdo,'ORDER BY vod_time DESC, vod_id DESC',48);
}
$schema=json_encode(array('@context'=>'https://schema.org','@type'=>'CollectionPage','name'=>$title,'description'=>$desc,'url'=>$base.$uri),JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
?><!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title><?php echo h($title); ?></title><meta name="description" content="<?php echo h($desc); ?>"><link rel="canonical" href="<?php echo h($base.$uri); ?>"><style>:root{--p:<?php echo $primary;?>;--bg:<?php echo $bg;?>;--card:<?php echo $card;?>}body{margin:0;background:var(--bg);color:#e5e7eb;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Microsoft YaHei,sans-serif}a{text-decoration:none;color:inherit}.wrap{max-width:1220px;margin:auto;padding:18px}.top{display:flex;align-items:center;gap:18px;margin-bottom:20px}.logo{font-size:22px;font-weight:900;color:var(--p)}.nav a{margin-right:12px;color:#cbd5e1}.hero{padding:8px 0 18px}.hero h1{font-size:30px;margin:0 0 8px}.muted{color:#94a3b8}.grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:14px}.card,.box{background:var(--card);border:1px solid rgba(148,163,184,.14);border-radius:14px;overflow:hidden;padding:12px}.poster{aspect-ratio:2/3;background:#1e293b;margin:-12px -12px 10px}.poster img{width:100%;height:100%;object-fit:cover}.card h3{font-size:14px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;margin:6px 0}.tag{font-size:12px;color:#93c5fd}.time{font-size:12px;color:#fbbf24}.section{margin-top:26px}.section h2{font-size:22px;margin:0 0 12px}.chips a{display:inline-block;margin:5px 6px 5px 0;padding:7px 12px;border:1px solid rgba(148,163,184,.2);border-radius:999px;color:#cbd5e1}.mini{display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:12px}@media(max-width:760px){.grid{grid-template-columns:repeat(3,1fr);gap:10px}.nav{display:none}.card{padding:8px}.poster{margin:-8px -8px 8px}.card h3{font-size:13px}.hero h1{font-size:24px}}</style><script type="application/ld+json"><?php echo $schema; ?></script></head><body><div class="wrap"><div class="top"><a class="logo" href="/"><?php echo h($brand); ?></a><div class="nav"><a href="/"><?php echo u('e9a696e9a1b5'); ?></a><a href="/new.html"><?php echo u('e69bb4e696b0'); ?></a><a href="/hot.html"><?php echo u('e783ade692ad'); ?></a><a href="/duanju.html"><?php echo u('e79fade589a7'); ?></a><a href="/score.html"><?php echo u('e9ab98e58886'); ?></a></div></div>
<div class="hero"><h1><?php echo h($title); ?></h1><p class="muted"><?php echo h($desc); ?></p><div class="chips"><a href="/new.html"><?php echo $homeTitle; ?></a><a href="/hot.html"><?php echo $hotTitle; ?></a><a href="/duanju.html"><?php echo $shortTitle; ?></a><a href="/movie-hot.html"><?php echo u('e794b5e5bdb1'); ?></a><a href="/tv-hot.html"><?php echo u('e794b5e8a786e589a7'); ?></a></div></div>
<?php function render_grid($items,$showTime=false){ foreach($items as $v): ?><a class="card" href="/voddetail/<?php echo intval($v['vod_id']); ?>.html"><div class="poster"><img src="<?php echo h(pic($v['vod_pic'])); ?>" loading="lazy" referrerpolicy="no-referrer" onerror="this.src='/placeholder.svg'"></div><h3><?php echo h($v['vod_name']); ?></h3><div class="tag"><?php echo h(trim(($v['vod_year']?$v['vod_year'].' ':'').($v['vod_class']?:''))); ?></div><?php if($showTime): ?><div class="time"><?php echo u('e585a5e5ba93'); ?> <?php echo h(fmt_time($v['vod_time'])); ?></div><?php endif; ?></a><?php endforeach; } ?>
<?php if(isset($latest)): ?><section class="section"><h2><?php echo $homeTitle; ?></h2><p class="muted"><?php echo u('e4b88be99da2e68c89e585a5e5ba93e697b6e997b4e58092e5ba8fe5b195e7a4baefbc8ce98787e99b86e5908ee5ba94e8afa5e69c80e58588e587bae78eb0e59ca8e8bf99e9878ce38082'); ?></p><div class="grid"><?php render_grid($latest,true); ?></div></section><section class="section"><h2><?php echo $hotTitle; ?></h2><div class="grid"><?php render_grid($hot,false); ?></div></section><section class="section"><h2><?php echo $shortTitle; ?></h2><div class="grid"><?php render_grid($short,true); ?></div></section><?php elseif(isset($list)): ?><section class="section"><div class="grid"><?php render_grid($list, strpos($uri,'new')!==false || strpos($uri,'upcoming')!==false); ?></div></section><?php else: ?><section class="section"><div class="mini"><a class="box" href="/new.html"><?php echo $homeTitle; ?></a><a class="box" href="/hot.html"><?php echo $hotTitle; ?></a><a class="box" href="/duanju.html"><?php echo $shortTitle; ?></a><a class="box" href="/score.html"><?php echo $scoreTitle; ?></a></div></section><?php endif; ?></div></body></html>
