<?php
include __DIR__ . '/auth.php';
admin_check();
include __DIR__ . '/layout.php';
admin_header('站群管理');

$domains = is_file(__DIR__ . '/../config/domain.php') ? include __DIR__ . '/../config/domain.php' : array();
$companies = is_file(__DIR__ . '/../data/company.php') ? include __DIR__ . '/../data/company.php' : array();
$themes = admin_site_themes();
function sites_count_channel($domain, $channel){
    $dir = __DIR__ . '/../data/sites/' . $domain . '/' . $channel;
    $txt = is_dir($dir) ? count(glob($dir.'/*.txt')) : 0;
    $cc = 0;
    $base = __DIR__ . '/../data/content_center/sites/' . preg_replace('/[^a-z0-9\.\-_]/i','-', $domain) . '/' . $channel;
    if(is_dir($base)) $cc = count(glob($base.'/*.php'));
    return $txt + $cc;
}
?>
<div class="card">
<h2>站群管理</h2>
<p class="help">域名和企业基础资料已统一到“站群管理”页面维护；内容发布请使用“内容中心”。前台各栏目只显示已发布内容，定时内容到期后由 cron 发布。</p>
<p><a class="btn" href="<?php echo admin_h(cms_admin_url('site_config.php')); ?>">进入站群管理</a> <a class="btn ghost" href="<?php echo admin_h(cms_admin_url('content_center.php')); ?>">发布内容</a></p>
<table>
<tr><th>序号</th><th>域名</th><th>企业名称</th><th>城市</th><th>主题</th><th>新闻</th><th>产品</th><th>案例</th><th>FAQ</th><th>操作</th></tr>
<?php $i=1; foreach($domains as $domain=>$cfg): if(in_array($domain,array('localhost','127.0.0.1','::1'),true)) continue; $cid=intval($cfg['company_id']??0); $company=$companies[$cid]??array(); $theme=$cfg['theme']??''; ?>
<tr>
<td><?php echo $i++; ?></td>
<td><?php echo admin_h($domain); ?></td>
<td><?php echo admin_h($company['name'] ?? ''); ?></td>
<td><?php echo admin_h($company['city'] ?? ''); ?></td>
<td><?php echo admin_h(($themes[$theme] ?? $theme) . ($theme ? ' / '.$theme : '')); ?></td>
<td><?php echo sites_count_channel($domain,'news'); ?></td>
<td><?php echo sites_count_channel($domain,'product'); ?></td>
<td><?php echo sites_count_channel($domain,'case'); ?></td>
<td><?php echo sites_count_channel($domain,'faq'); ?></td>
<td><a class="btn small" href="<?php echo admin_h(cms_admin_url('site_config.php')); ?>?edit=<?php echo urlencode($domain); ?>">编辑</a> <a class="btn small ghost" target="_blank" href="http://<?php echo admin_h($domain); ?>/">前台</a></td>
</tr>
<?php endforeach; ?>
</table>
</div>
<?php admin_footer(); ?>
