Ajout d'un système de listing des fichiers de dossier /medias/wiki

This commit is contained in:
leosw
2025-08-02 13:16:50 +02:00
parent 98103c096e
commit 23f8123718
5 changed files with 138 additions and 2 deletions

View File

@@ -42,6 +42,63 @@ if(isset($controller->splitted_url[1]) && $user->rankIsHigher("moderator")) {
$notfound = 1;
}
break;
case 'wiki-files':
if ($user->rankIsHigher("moderator")) {
$head['title'] = "Fichiers attachés au wiki";
$rows_per_pages = 50;
$files_folder = $config['medias_folder']."wiki/";
// Get the file list
$files_list = scandir($files_folder);
// Populate table
foreach ($files_list as $file) {
$file_path = $files_folder.$file;
if (is_file($file_path)) {
$file_info = [
'name' => $file,
'type' => mime_content_type($file_path),
'creation_date' => date("Y-m-d H:i:s", filectime($file_path)),
'size' => filesize($file_path),
];
$files[] = $file_info;
}
}
$filenb = count($files);
// Manage sorting
if(isset($_GET['orderby']))
$orderby = $_GET['orderby'];
else
$orderby = 'name';
if(isset($_GET['order']) && $_GET['order']=='ASC') {
$order = 'ASC';
usort($files, function ($a, $b) use ($orderby) { return $a[$orderby] <=> $b[$orderby]; });
}
else {
$order = 'DESC';
usort($files, function ($a, $b) use ($orderby) { return $b[$orderby] <=> $a[$orderby]; });
}
// Get the correct page number
if (!isset($controller->splitted_url[2]) OR $controller->splitted_url[2]=="" OR $controller->splitted_url[2]=="0" OR !is_numeric($controller->splitted_url[2])) {
$page = 0;
} else {
$page = $controller->splitted_url[2] - 1;
}
// In case the wanted page is too big
if($rows_per_pages * $page >= $filenb)
$page = 0;
$first = $page*$rows_per_pages+1;
$last = (($page+1)*$rows_per_pages > $filenb ? $filenb : ($page+1)*$rows_per_pages);
include ($config['views_folder']."d.admin.wiki-files.html");
}
else {
$notfound = 1;
}
break;
default:
$notfound = 1;
break;
@@ -55,4 +112,20 @@ else {
$notfound = 1;
}
function getFontAwesomeIcon($mimeType) {
$icons = [
'application/pdf' => 'fa-file-pdf',
'image/jpeg' => 'fa-file-image',
'image/png' => 'fa-file-image',
'application/zip' => 'fa-file-archive',
'text/plain' => 'fa-file-alt',
'application/vnd.ms-excel' => 'fa-file-excel',
'application/msword' => 'fa-file-word',
'video/mp4' => 'fa-file-video',
'audio/mpeg' => 'fa-file-audio',
];
return $icons[$mimeType] ?? 'fa-file'; // Default
}
?>

View File

@@ -8,7 +8,7 @@
<? include('blocks/d.nav.html'); ?>
<section>
<h1>Mise à jour</h1>
<h1><?=$head['title']?></h1>
<br>
<pre><?
foreach($output as $line) {

View File

@@ -15,6 +15,7 @@
<? } ?>
<? if($user->rankIsHigher("moderator")) { ?>
<a href="<?=$config['rel_root_folder']?>admin/logs" class="button"><i class="fas fa-history"></i> Voir les logs</a> <small>Permet d'accéder aux 200 dernières lignes des logs bruts des actions sur la base de données.</small><br><br>
<a href="<?=$config['rel_root_folder']?>admin/wiki-files" class="button"><i class="fas fa-paperclip"></i> Fichiers attachés</a><small>Gérer les fichiers attachés pour le wiki : liste, ajout suppression...</small><br><br>
<? } ?>
</section>

View File

@@ -8,7 +8,7 @@
<? include('blocks/d.nav.html'); ?>
<section>
<h1>Logs</h1>
<h1><?=$head['title']?></h1>
<span class="subtitle">
<select id="logfile">
<? $i = 0;

62
views/d.admin.wiki-files.html Executable file
View File

@@ -0,0 +1,62 @@
<!DOCTYPE html>
<html lang="fr">
<? include('blocks/d.head.html'); ?>
<body>
<? include('blocks/d.nav.html'); ?>
<section>
<h1><?=$head['title']?></h1>
<p class="subtitle">Fichiers attachés <?=$first?> à <?=$last?> sur les <?=$filenb?> présents</p>
<br><br>
<table>
<tr class="first">
<th>
<a href="<?=$config['rel_root_folder']?>admin/wiki-files/<?=$page+1?>?orderby=name&amp;order=<?=$order=='ASC'?'DESC':'ASC'?>">Nom</a>
<?=$orderby=='name'?$order=='ASC'?'<i class="fas fa-caret-down" aria-hidden="true"></i>':'<i class="fas fa-caret-up" aria-hidden="true"></i>':''?>
</th>
<th>
<a href="<?=$config['rel_root_folder']?>admin/wiki-files/<?=$page+1?>?orderby=type&amp;order=<?=$order=='ASC'?'DESC':'ASC'?>">Type</a>
<?=$orderby=='type'?$order=='ASC'?'<i class="fas fa-caret-down" aria-hidden="true"></i>':'<i class="fas fa-caret-up" aria-hidden="true"></i>':''?>
</th>
<th>
<a href="<?=$config['rel_root_folder']?>admin/wiki-files/<?=$page+1?>?orderby=size&amp;order=<?=$order=='ASC'?'DESC':'ASC'?>">Taille</a>
<?=$orderby=='size'?$order=='ASC'?'<i class="fas fa-caret-down" aria-hidden="true"></i>':'<i class="fas fa-caret-up" aria-hidden="true"></i>':''?>
</th>
<th>
<a href="<?=$config['rel_root_folder']?>admin/wiki-files/<?=$page+1?>?orderby=creation_date&amp;order=<?=$order=='ASC'?'DESC':'ASC'?>">Date de création</a>
<?=$orderby=='creation_date'?$order=='ASC'?'<i class="fas fa-caret-down" aria-hidden="true"></i>':'<i class="fas fa-caret-up" aria-hidden="true"></i>':''?>
</th>
<th>Suppression</th>
</tr>
<? foreach ($files as $file) { ?>
<tr>
<td>
<a href="<?=$config['rel_root_folder']?>medias/wiki/<?=$file['name']?>"><?=$file['name']?></a>
</td>
<td><i class='fas <?=getFontAwesomeIcon($file['type'])?>'></i> <?=$file['type']?></td>
<td><?=$file['size']?></td>
<td><? echo datefmt_format($user->date_format,date_create($file['creation_date'], new DateTimeZone("UTC"))) ?></td>
<td>
<a href="<?=$file['name']?>"><span class="external-link"><i class="fas fa-trash"></i></span></a>
</td>
</tr>
<? } ?>
</table>
<div class="pagebuttons">
<? if ($page != 0) { ?><a class="previous" href="<?=$config['rel_root_folder']?>admin/wiki-files/<?=$page?>?orderby=<?=$orderby?>&amp;order=<?=$order?>"><i class="fas fa-chevron-left fa-fw"></i></a><? }
if (($page+1)*$rows_per_pages < $filenb) { ?><a class="next" href="<?=$config['rel_root_folder']?>admin/wiki-files/<?=$page+2?>?orderby=<?=$orderby?>&amp;order=<?=$order?>"><i class="fas fa-chevron-right fa-fw"></i></a><? } ?>
</div>
</section>
<? include('blocks/d.footer.html'); ?>
</body>
</html>