Ajout de la fonctionnalité de suppression de fichiers
This commit is contained in:
@@ -49,9 +49,16 @@ if(isset($controller->splitted_url[1]) && $user->rankIsHigher("moderator")) {
|
|||||||
$rows_per_pages = 50;
|
$rows_per_pages = 50;
|
||||||
$files_folder = $config['medias_folder']."wiki/";
|
$files_folder = $config['medias_folder']."wiki/";
|
||||||
|
|
||||||
// Get the file list
|
// Effacer un fichier
|
||||||
|
if(isset($controller->splitted_url[2]) && $controller->splitted_url[2]=='delete' && isset($controller->splitted_url[3])) {
|
||||||
|
$filename=$files_folder.$controller->splitted_url[3];
|
||||||
|
if (file_exists($filename))
|
||||||
|
unlink($filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the file list
|
||||||
$files_list = scandir($files_folder);
|
$files_list = scandir($files_folder);
|
||||||
// Populate table
|
// Populate table
|
||||||
foreach ($files_list as $file) {
|
foreach ($files_list as $file) {
|
||||||
$file_path = $files_folder.$file;
|
$file_path = $files_folder.$file;
|
||||||
|
|
||||||
@@ -68,7 +75,7 @@ if(isset($controller->splitted_url[1]) && $user->rankIsHigher("moderator")) {
|
|||||||
}
|
}
|
||||||
$filenb = count($files);
|
$filenb = count($files);
|
||||||
|
|
||||||
// Manage sorting
|
// Manage sorting
|
||||||
if(isset($_GET['orderby']))
|
if(isset($_GET['orderby']))
|
||||||
$orderby = $_GET['orderby'];
|
$orderby = $_GET['orderby'];
|
||||||
else
|
else
|
||||||
@@ -82,13 +89,13 @@ if(isset($controller->splitted_url[1]) && $user->rankIsHigher("moderator")) {
|
|||||||
usort($files, function ($a, $b) use ($orderby) { return $b[$orderby] <=> $a[$orderby]; });
|
usort($files, function ($a, $b) use ($orderby) { return $b[$orderby] <=> $a[$orderby]; });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the correct page number
|
// 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])) {
|
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;
|
$page = 0;
|
||||||
} else {
|
} else {
|
||||||
$page = $controller->splitted_url[2] - 1;
|
$page = $controller->splitted_url[2] - 1;
|
||||||
}
|
}
|
||||||
// In case the wanted page is too big
|
// In case the wanted page is too big
|
||||||
if($rows_per_pages * $page >= $filenb)
|
if($rows_per_pages * $page >= $filenb)
|
||||||
$page = 0;
|
$page = 0;
|
||||||
|
|
||||||
@@ -99,10 +106,10 @@ if(isset($controller->splitted_url[1]) && $user->rankIsHigher("moderator")) {
|
|||||||
else {
|
else {
|
||||||
$notfound = 1;
|
$notfound = 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$notfound = 1;
|
$notfound = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if($user->rankIsHigher("moderator")) {
|
else if($user->rankIsHigher("moderator")) {
|
||||||
@@ -116,38 +123,38 @@ else {
|
|||||||
// Fonctions de mise en forme
|
// Fonctions de mise en forme
|
||||||
|
|
||||||
function getFontAwesomeIcon($mimeType) {
|
function getFontAwesomeIcon($mimeType) {
|
||||||
$icons = [
|
$icons = [
|
||||||
'application/pdf' => 'fa-file-pdf',
|
'application/pdf' => 'fa-file-pdf',
|
||||||
'image/jpeg' => 'fa-file-image',
|
'image/jpeg' => 'fa-file-image',
|
||||||
'image/png' => 'fa-file-image',
|
'image/png' => 'fa-file-image',
|
||||||
'application/zip' => 'fa-file-archive',
|
'application/zip' => 'fa-file-archive',
|
||||||
'text/plain' => 'fa-file-alt',
|
'text/plain' => 'fa-file-alt',
|
||||||
'application/vnd.ms-excel' => 'fa-file-excel',
|
'application/vnd.ms-excel' => 'fa-file-excel',
|
||||||
'application/msword' => 'fa-file-word',
|
'application/msword' => 'fa-file-word',
|
||||||
'video/mp4' => 'fa-file-video',
|
'video/mp4' => 'fa-file-video',
|
||||||
'audio/mpeg' => 'fa-file-audio',
|
'audio/mpeg' => 'fa-file-audio',
|
||||||
];
|
];
|
||||||
|
|
||||||
return $icons[$mimeType] ?? 'fa-file'; // Default
|
return $icons[$mimeType] ?? 'fa-file'; // Default
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatBytes($bytes, $locale = 'en', $precision = 2) {
|
function formatBytes($bytes, $locale = 'en', $precision = 2) {
|
||||||
$unitMap = [
|
$unitMap = [
|
||||||
'en' => ['B', 'KB', 'MB', 'GB', 'TB', 'PB'],
|
'en' => ['B', 'KB', 'MB', 'GB', 'TB', 'PB'],
|
||||||
'fr' => ['o', 'Ko', 'Mo', 'Go', 'To', 'Po']
|
'fr' => ['o', 'Ko', 'Mo', 'Go', 'To', 'Po']
|
||||||
];
|
];
|
||||||
|
|
||||||
$locale = explode('_', $locale)[0];
|
$locale = explode('_', $locale)[0];
|
||||||
$units = $unitMap[$locale] ?? $unitMap['en'];
|
$units = $unitMap[$locale] ?? $unitMap['en'];
|
||||||
|
|
||||||
if ($bytes == 0) {
|
if ($bytes == 0) {
|
||||||
return '0 ' . $units[0];
|
return '0 ' . $units[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
$power = floor(log($bytes, 1024));
|
$power = floor(log($bytes, 1024));
|
||||||
$formatted = round($bytes / pow(1024, $power), $precision);
|
$formatted = round($bytes / pow(1024, $power), $precision);
|
||||||
|
|
||||||
return $formatted . ' ' . $units[$power];
|
return $formatted . ' ' . $units[$power];
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@@ -43,7 +43,7 @@
|
|||||||
<td><?=formatBytes($file['size'], $user->locale)?></td>
|
<td><?=formatBytes($file['size'], $user->locale)?></td>
|
||||||
<td><? echo datefmt_format($user->date_format,date_create($file['creation_date'], new DateTimeZone("UTC"))) ?></td>
|
<td><? echo datefmt_format($user->date_format,date_create($file['creation_date'], new DateTimeZone("UTC"))) ?></td>
|
||||||
<td>
|
<td>
|
||||||
<a href="<?=$file['name']?>"><span class="external-link"><i class="fas fa-trash"></i></span></a>
|
<a href="<?=$config['rel_root_folder']?>admin/wiki-files/delete/<?=$file['name']?>?orderby=<?=$orderby?>&order=<?=$order?>" onclick="return confirm('Es-tu sûr de vouloir supprimer ?');"><span class="external-link"><i class="fas fa-trash"></i></span></a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<? } ?>
|
<? } ?>
|
||||||
|
|||||||
Reference in New Issue
Block a user