<?php
require_once dirname(__DIR__, 2) . '/core/lib/content_quality.php';
$allResults=cmsCollectContentQuality($db,dirname(__DIR__,2));$summary=cmsQualitySummary($allResults);
$type=trim((string)($_GET['type']??''));$severity=trim((string)($_GET['severity']??''));$issueCode=trim((string)($_GET['issue']??''));$keyword=trim((string)($_GET['keyword']??''));
$allowedTypes=array_keys(cmsQualityContentTypes());if(!in_array($type,$allowedTypes,true))$type='';if(!in_array($severity,['high','medium','low'],true))$severity='';
$issueLabels=['seo_title'=>'缺少 SEO 标题','seo_keywords'=>'缺少 SEO 关键词','seo_description'=>'缺少 SEO 描述','cover'=>'缺少封面','summary'=>'摘要为空','short_content'=>'正文不足','duplicate_title'=>'标题重复','broken_link'=>'失效站内链接'];if(!isset($issueLabels[$issueCode]))$issueCode='';
$results=array_values(array_filter($allResults,function($item)use($type,$severity,$issueCode,$keyword){if($type!==''&&$item['type']!==$type)return false;if($keyword!==''&&stripos($item['title'],$keyword)===false)return false;foreach($item['issues'] as $issue){if(($severity===''||$issue['severity']===$severity)&&($issueCode===''||$issue['code']===$issueCode))return true;}return false;}));
$page=max(1,intval($_GET['page']??1));$pageSize=20;$total=count($results);$totalPages=max(1,intval(ceil($total/$pageSize)));$results=array_slice($results,($page-1)*$pageSize,$pageSize);$query=$_GET;unset($query['page']);$queryString=http_build_query($query);
$severityLabels=['high'=>'严重','medium'=>'需优化','low'=>'建议'];
?>
<div class="page-container fade-in quality-page"><div class="page-header"><div class="page-title"><div class="page-icon"><i class="fa fa-check-square-o"></i></div><div><h1>内容质量</h1><p>集中发现影响发布质量、搜索呈现和站内访问的问题</p></div></div><div class="page-actions"><button class="btn btn-secondary" onclick="location.reload()"><i class="fa fa-refresh"></i> 重新检测</button></div></div>
<div class="quality-summary"><div><small>待优化内容</small><strong><?php echo $summary['contents']; ?></strong><span>项内容</span></div><div><small>问题总数</small><strong><?php echo $summary['issues']; ?></strong><span>个问题</span></div><div class="is-high"><small>严重问题</small><strong><?php echo $summary['high']; ?></strong><span>优先处理</span></div><div class="is-medium"><small>需要优化</small><strong><?php echo $summary['medium']; ?></strong><span>影响完整度</span></div><div><small>改进建议</small><strong><?php echo $summary['low']; ?></strong><span>可逐步完善</span></div></div>
<form class="quality-filter" method="get"><input type="hidden" name="act" value="content_quality"><input name="keyword" value="<?php echo htmlspecialchars($keyword); ?>" placeholder="搜索内容标题"><select name="type"><option value="">全部内容类型</option><?php foreach(cmsQualityContentTypes() as $k=>$v): ?><option value="<?php echo $k; ?>" <?php echo $type===$k?'selected':''; ?>><?php echo $v['label']; ?></option><?php endforeach; ?></select><select name="severity"><option value="">全部严重度</option><?php foreach($severityLabels as $k=>$v): ?><option value="<?php echo $k; ?>" <?php echo $severity===$k?'selected':''; ?>><?php echo $v; ?></option><?php endforeach; ?></select><select name="issue"><option value="">全部问题类型</option><?php foreach($issueLabels as $k=>$v): ?><option value="<?php echo $k; ?>" <?php echo $issueCode===$k?'selected':''; ?>><?php echo $v; ?></option><?php endforeach; ?></select><button class="btn btn-primary">筛选</button><a href="?act=content_quality" class="btn btn-secondary">重置</a></form>
<div class="quality-note"><i class="fa fa-info-circle"></i><span>检测为只读操作，不会自动生成标题、摘要或正文。站内链接仅校验内容详情页和上传文件，不请求外部网站。</span></div>
<div class="content-card quality-list"><?php if(!$results): ?><div class="quality-empty"><i class="fa fa-check-circle"></i><strong>当前筛选范围没有发现问题</strong><span>可更换筛选条件继续检查。</span></div><?php endif; ?><?php foreach($results as $item): ?><article class="quality-row"><div class="quality-content"><div class="quality-title"><span><?php echo $item['type_label']; ?></span><strong><?php echo htmlspecialchars($item['title']); ?></strong><em class="is-<?php echo $item['published']?'published':'draft'; ?>"><?php echo $item['published']?'已发布':'未发布'; ?></em></div><div class="quality-issues"><?php foreach($item['issues'] as $issue): if($severity!==''&&$issue['severity']!==$severity)continue;if($issueCode!==''&&$issue['code']!==$issueCode)continue; ?><button type="button" class="quality-issue is-<?php echo $issue['severity']; ?>" data-label="<?php echo htmlspecialchars($issue['label']); ?>" data-tip="<?php echo htmlspecialchars($issue['suggestion']); ?>"><b><?php echo $severityLabels[$issue['severity']]; ?></b><?php echo htmlspecialchars($issue['label']); ?></button><?php endforeach; ?></div></div><a class="btn btn-primary" href="<?php echo htmlspecialchars($item['edit_url']); ?>">立即修复</a></article><?php endforeach; ?><?php if($totalPages>1): ?><div class="pagination"><?php for($i=max(1,$page-2);$i<=min($totalPages,$page+2);$i++): ?><a class="<?php echo $i===$page?'active':''; ?>" href="?<?php echo htmlspecialchars($queryString.'&page='.$i); ?>"><?php echo $i; ?></a><?php endfor; ?></div><?php endif; ?></div></div>
<div class="quality-modal" id="qualityModal" hidden><div><button type="button" id="qualityClose">×</button><small>QUALITY SUGGESTION</small><h2 id="qualityLabel"></h2><p id="qualityTip"></p></div></div>
<style>
.quality-page{max-width:1500px}.quality-summary{display:grid;grid-template-columns:repeat(5,1fr);gap:12px;margin-bottom:16px}.quality-summary>div{padding:16px 18px;border:1px solid #e2e8f0;border-radius:14px;background:#fff}.quality-summary small,.quality-summary span{display:block;color:#94a3b8;font-size:11px}.quality-summary strong{display:inline-block;margin:5px 7px 2px 0;color:#1e293b;font-size:23px}.quality-summary .is-high strong{color:#dc2626}.quality-summary .is-medium strong{color:#d97706}.quality-filter{display:grid!important;grid-template-columns:minmax(260px,2fr) repeat(3,minmax(150px,1fr)) auto auto;align-items:center;gap:10px;padding:14px;margin-bottom:12px;border:1px solid #e2e8f0;border-radius:14px;background:#fff}.quality-filter input,.quality-filter select{width:100%!important;min-width:0!important;height:40px;margin:0!important;padding:0 11px;border:1px solid #dbe3ee;border-radius:9px;background:#fff}.quality-filter .btn{width:auto!important;min-width:74px!important;margin:0!important}.quality-note{display:flex;align-items:center;gap:9px;margin-bottom:16px;padding:10px 13px;border-radius:10px;background:#eff6ff;color:#475569;font-size:11px}.quality-note i{color:#2563eb}.quality-list{overflow:hidden}.quality-row{display:flex;align-items:center;justify-content:space-between;gap:22px;padding:18px 20px;border-bottom:1px solid #edf2f7}.quality-row:last-child{border-bottom:0}.quality-content{min-width:0;flex:1}.quality-title{display:flex;align-items:center;gap:10px}.quality-title>span{padding:4px 7px;border-radius:7px;background:#f1f5f9;color:#64748b;font-size:10px;font-weight:800}.quality-title>strong{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:#25324a;font-size:14px}.quality-title>em{font-style:normal;font-size:10px}.quality-title>em.is-published{color:#047857}.quality-title>em.is-draft{color:#94a3b8}.quality-issues{display:flex;flex-wrap:wrap;gap:7px;margin-top:10px}.quality-issue{display:inline-flex;align-items:center;gap:6px;padding:6px 8px;border:0;border-radius:8px;background:#f8fafc;color:#475569;font-size:11px;cursor:pointer}.quality-issue b{font-size:9px}.quality-issue.is-high{background:#fef2f2;color:#b91c1c}.quality-issue.is-medium{background:#fffbeb;color:#b45309}.quality-issue.is-low{background:#f0fdf4;color:#047857}.quality-empty{display:flex;flex-direction:column;align-items:center;padding:60px;color:#94a3b8}.quality-empty i{font-size:38px;color:#10b981}.quality-empty strong{margin-top:12px;color:#334155}.quality-empty span{margin-top:5px;font-size:12px}.quality-modal{position:fixed;inset:0;z-index:9999;background:rgba(15,23,42,.42);backdrop-filter:blur(3px)}.quality-modal:not([hidden]){display:flex;align-items:center;justify-content:center;padding:24px}.quality-modal>div{position:relative;width:min(520px,100%);padding:25px;border-radius:18px;background:#fff}.quality-modal button{position:absolute;right:17px;top:12px;border:0;background:none;color:#64748b;font-size:28px}.quality-modal small{color:#94a3b8;letter-spacing:.12em}.quality-modal h2{margin:8px 0;color:#1e293b}.quality-modal p{margin:0;color:#64748b;line-height:1.8}@media(max-width:1100px){.quality-summary{grid-template-columns:repeat(3,1fr)}.quality-filter{grid-template-columns:minmax(220px,2fr) repeat(3,minmax(125px,1fr)) auto auto}}@media(max-width:900px){.quality-filter{grid-template-columns:repeat(2,minmax(0,1fr))}.quality-filter .btn{width:100%!important}}@media(max-width:700px){.quality-summary{grid-template-columns:1fr}.quality-filter{grid-template-columns:1fr}.quality-row{align-items:flex-start;flex-direction:column}.quality-title{flex-wrap:wrap}}
</style>
<script>(function(){var modal=document.getElementById('qualityModal');document.querySelectorAll('.quality-issue').forEach(function(btn){btn.onclick=function(){document.getElementById('qualityLabel').textContent=this.getAttribute('data-label');document.getElementById('qualityTip').textContent=this.getAttribute('data-tip');modal.hidden=false;};});function close(){modal.hidden=true;}document.getElementById('qualityClose').onclick=close;modal.onclick=function(e){if(e.target===modal)close();};})();</script>
