<?php
include __DIR__ . '/auth.php';
admin_check();
include __DIR__ . '/layout.php';

$site = preg_replace('/[^a-zA-Z0-9\.\-_]/','', $_GET['site'] ?? '');
$channel = preg_replace('/[^a-zA-Z0-9\-_]/','', $_GET['channel'] ?? 'news');
$dir = realpath(__DIR__ . '/../data/sites/' . $site . '/' . $channel);
$root = realpath(__DIR__ . '/../data/sites');

admin_header('TXT内容管理');

if(!$dir || !$root || strpos($dir,$root)!==0){
    echo '<div class="card">目录不存在</div>';
    admin_footer();
    exit;
}
$files = glob($dir.'/*.txt');
?>
<div class="card">
<h2><?php echo admin_h($site.' / '.$channel); ?></h2>
<p><a class="btn" href="edit.php?site=<?php echo urlencode($site); ?>&channel=<?php echo urlencode($channel); ?>">新增TXT</a></p>
<table>
<tr><th>序号</th><th>文件</th><th>大小</th><th>修改时间</th><th>操作</th></tr>
<?php $i=1; foreach($files as $file): ?>
<tr>
<td><?php echo $i++; ?></td>
<td><?php echo admin_h(basename($file)); ?></td>
<td><?php echo filesize($file); ?> B</td>
<td><?php echo date('Y-m-d H:i:s', filemtime($file)); ?></td>
<td><a class="btn small" href="edit.php?site=<?php echo urlencode($site); ?>&channel=<?php echo urlencode($channel); ?>&file=<?php echo urlencode(basename($file)); ?>">编辑</a></td>
</tr>
<?php endforeach; ?>
</table>
</div>
<?php admin_footer(); ?>
