From f9f6debe65419743f6cf12150f1e014cc2c14521 Mon Sep 17 00:00:00 2001 From: leosw Date: Sat, 2 Aug 2025 13:57:28 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20de=20la=20fonctionnalit=C3=A9=20de=20su?= =?UTF-8?q?ppression=20de=20fichiers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/d.admin.php | 67 +++++++++++++++++++---------------- views/d.admin.wiki-files.html | 2 +- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/controllers/d.admin.php b/controllers/d.admin.php index 1c0347e..919a9ba 100755 --- a/controllers/d.admin.php +++ b/controllers/d.admin.php @@ -49,9 +49,16 @@ if(isset($controller->splitted_url[1]) && $user->rankIsHigher("moderator")) { $rows_per_pages = 50; $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); - // Populate table + // Populate table foreach ($files_list as $file) { $file_path = $files_folder.$file; @@ -68,7 +75,7 @@ if(isset($controller->splitted_url[1]) && $user->rankIsHigher("moderator")) { } $filenb = count($files); - // Manage sorting + // Manage sorting if(isset($_GET['orderby'])) $orderby = $_GET['orderby']; 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]; }); } - // 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])) { $page = 0; } else { $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) $page = 0; @@ -99,10 +106,10 @@ if(isset($controller->splitted_url[1]) && $user->rankIsHigher("moderator")) { else { $notfound = 1; } - break; + break; default: $notfound = 1; - break; + break; } } else if($user->rankIsHigher("moderator")) { @@ -116,38 +123,38 @@ else { // Fonctions de mise en forme 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', - ]; + $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 } function formatBytes($bytes, $locale = 'en', $precision = 2) { - $unitMap = [ - 'en' => ['B', 'KB', 'MB', 'GB', 'TB', 'PB'], - 'fr' => ['o', 'Ko', 'Mo', 'Go', 'To', 'Po'] - ]; + $unitMap = [ + 'en' => ['B', 'KB', 'MB', 'GB', 'TB', 'PB'], + 'fr' => ['o', 'Ko', 'Mo', 'Go', 'To', 'Po'] + ]; - $locale = explode('_', $locale)[0]; - $units = $unitMap[$locale] ?? $unitMap['en']; + $locale = explode('_', $locale)[0]; + $units = $unitMap[$locale] ?? $unitMap['en']; - if ($bytes == 0) { - return '0 ' . $units[0]; - } + if ($bytes == 0) { + return '0 ' . $units[0]; + } - $power = floor(log($bytes, 1024)); - $formatted = round($bytes / pow(1024, $power), $precision); + $power = floor(log($bytes, 1024)); + $formatted = round($bytes / pow(1024, $power), $precision); - return $formatted . ' ' . $units[$power]; + return $formatted . ' ' . $units[$power]; } ?> \ No newline at end of file diff --git a/views/d.admin.wiki-files.html b/views/d.admin.wiki-files.html index f90e047..7c57f31 100755 --- a/views/d.admin.wiki-files.html +++ b/views/d.admin.wiki-files.html @@ -43,7 +43,7 @@ locale)?> date_format,date_create($file['creation_date'], new DateTimeZone("UTC"))) ?> - +