2024-03-12 18:35:44 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This file is part of Zwii.
|
|
|
|
*
|
|
|
|
* For full copyright and license information, please see the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*
|
|
|
|
* @author Rémi Jean <remi.jean@outlook.com>
|
|
|
|
* @copyright Copyright (C) 2008-2018, Rémi Jean
|
|
|
|
* @author Frédéric Tempez <frederic.tempez@outlook.com>
|
|
|
|
* @copyright Copyright (C) 2018-2024, Frédéric Tempez
|
|
|
|
* @license CC Attribution-NonCommercial-NoDerivatives 4.0 International
|
|
|
|
* @link http://zwiicms.fr/
|
|
|
|
*/
|
|
|
|
|
2024-03-13 16:56:33 +01:00
|
|
|
class folder extends common
|
2024-03-12 18:35:44 +01:00
|
|
|
{
|
|
|
|
|
2024-03-14 08:50:23 +01:00
|
|
|
const VERSION = '0.1';
|
|
|
|
const REALNAME = 'Partage de dossier';
|
2024-03-12 18:35:44 +01:00
|
|
|
const DATADIRECTORY = ''; // Contenu localisé inclus par défaut (page.json et module.json)
|
|
|
|
|
|
|
|
public static $actions = [
|
|
|
|
'config' => self::GROUP_EDITOR,
|
|
|
|
'index' => self::GROUP_VISITOR,
|
|
|
|
];
|
|
|
|
|
2024-03-13 18:45:06 +01:00
|
|
|
// Contenu du chemin sélectionné
|
|
|
|
public static $folders = '';
|
2024-03-13 16:28:19 +01:00
|
|
|
|
2024-03-13 18:45:06 +01:00
|
|
|
public static $sharePath = [
|
2024-03-14 13:33:37 +01:00
|
|
|
'site/file/source/'
|
2024-03-13 18:45:06 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
public function index()
|
|
|
|
{
|
2024-03-13 16:28:19 +01:00
|
|
|
|
2024-03-16 08:36:52 +01:00
|
|
|
// Configuration de l'affichage
|
2024-03-15 21:14:49 +01:00
|
|
|
$config['showsubfolder'] = $this->getData(['module', $this->getUrl(0), 'subfolder']);
|
|
|
|
$config['sort'] = $this->getData(['module', $this->getUrl(0), 'sort']);
|
2024-03-16 08:36:52 +01:00
|
|
|
$config['showdetails'] = $this->getData(['module', $this->getUrl(0), 'details']);
|
|
|
|
$config['initialfolderstate'] = $this->getData(['module', $this->getUrl(0), 'folderstate']);
|
2024-03-15 21:14:49 +01:00
|
|
|
|
2024-03-16 08:36:52 +01:00
|
|
|
// Générer l'affichage
|
2024-03-15 21:14:49 +01:00
|
|
|
self::$folders = $this->getFolderContent($this->getData(['module', $this->getUrl(0), 'path']), $config);
|
2024-03-13 16:28:19 +01:00
|
|
|
|
2024-03-13 18:45:06 +01:00
|
|
|
// Valeurs en sortie
|
2024-03-12 18:35:44 +01:00
|
|
|
$this->addOutput([
|
|
|
|
'showBarEditButton' => true,
|
|
|
|
'showPageContent' => true,
|
2024-03-13 16:28:19 +01:00
|
|
|
'view' => 'index'
|
2024-03-12 18:35:44 +01:00
|
|
|
]);
|
2024-03-13 18:45:06 +01:00
|
|
|
}
|
2024-03-12 18:35:44 +01:00
|
|
|
|
2024-03-13 18:45:06 +01:00
|
|
|
|
|
|
|
public function config()
|
|
|
|
{
|
|
|
|
// Soumission du formulaire
|
|
|
|
if (
|
|
|
|
$this->getUser('permission', __CLASS__, __FUNCTION__) === true &&
|
|
|
|
$this->isPost()
|
|
|
|
) {
|
2024-03-15 21:14:49 +01:00
|
|
|
$this->setData([
|
|
|
|
'module',
|
|
|
|
$this->getUrl(0),
|
|
|
|
[
|
|
|
|
'path' => preg_replace('/^\\./', '', $this->getInput('folderConfigPath')),
|
|
|
|
'title' => $this->getInput('folderConfigTitle'),
|
|
|
|
'sort' => $this->getInput('folderConfigSort', helper::FILTER_BOOLEAN),
|
|
|
|
'subfolder' => $this->getInput('folderConfigSubfolder', helper::FILTER_BOOLEAN),
|
|
|
|
'folder' => $this->getInput('folderConfigFolder', helper::FILTER_BOOLEAN),
|
2024-03-16 08:36:52 +01:00
|
|
|
'details' => $this->getInput('folderConfigDetails', helper::FILTER_BOOLEAN),
|
|
|
|
'folderstate' => $this->getInput('folderConfigFolderState', helper::FILTER_BOOLEAN),
|
2024-03-15 21:14:49 +01:00
|
|
|
]
|
|
|
|
]);
|
2024-03-13 18:45:06 +01:00
|
|
|
|
2024-03-14 13:33:37 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(0),
|
|
|
|
'notification' => helper::translate('Modifications enregistrées'),
|
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
|
2024-03-13 18:45:06 +01:00
|
|
|
}
|
|
|
|
|
2024-03-14 10:28:27 +01:00
|
|
|
self::$sharePath = $this->getSubdirectories('site/file/source');
|
2024-03-13 18:45:06 +01:00
|
|
|
self::$sharePath = array_flip(self::$sharePath);
|
|
|
|
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'view' => 'config'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2024-03-16 08:36:52 +01:00
|
|
|
private function getFolderContent($chemin, $config = [])
|
|
|
|
{
|
|
|
|
$showSubFolder = isset ($config['showsubfolder']) ? $config['showsubfolder'] : true;
|
|
|
|
$sort = isset ($config['sort']) ? $config['sort'] : true;
|
|
|
|
$showDetails = isset ($config['showdetails']) ? $config['showdetails'] : false;
|
|
|
|
$initialFolderState = isset ($config['initialfolderstate']) ? $config['initialfolderstate'] : 'collapsed';
|
|
|
|
|
|
|
|
// Vérifier si le chemin existe et est un dossier
|
|
|
|
if (is_dir($chemin)) {
|
|
|
|
// Ouvrir le dossier
|
|
|
|
if ($dh = opendir($chemin)) {
|
|
|
|
// Initialiser les tableaux pour les sous-dossiers et les fichiers
|
|
|
|
$subDirectories = [];
|
|
|
|
$files = [];
|
|
|
|
|
|
|
|
// Parcourir les éléments du dossier
|
|
|
|
while (($element = readdir($dh)) !== false) {
|
|
|
|
// Exclure les éléments spéciaux
|
|
|
|
if ($element != '.' && $element != '..') {
|
|
|
|
// Construire le chemin complet de l'élément
|
|
|
|
$cheminComplet = $chemin . '/' . $element;
|
|
|
|
|
|
|
|
// Vérifier si c'est un dossier
|
|
|
|
if (is_dir($cheminComplet)) {
|
|
|
|
// Ajouter le dossier au tableau des sous-dossiers
|
|
|
|
$subDirectories[] = $element;
|
|
|
|
} else {
|
|
|
|
// Ajouter le fichier au tableau des fichiers
|
|
|
|
$files[] = $element;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fermer le dossier
|
|
|
|
closedir($dh);
|
|
|
|
|
|
|
|
// Trier les sous-dossiers et les fichiers si nécessaire
|
|
|
|
if ($sort) {
|
|
|
|
sort($subDirectories);
|
|
|
|
sort($files);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialiser la liste des éléments
|
|
|
|
$items = '<ul>';
|
|
|
|
|
|
|
|
// Ajouter les sous-dossiers à la liste si configuré pour les afficher
|
|
|
|
if ($showSubFolder) {
|
|
|
|
foreach ($subDirectories as $subDirectory) {
|
|
|
|
$folderClass = '';
|
|
|
|
if ($initialFolderState == 'collapsed') {
|
|
|
|
$folderClass = 'collapsible';
|
|
|
|
}
|
|
|
|
$items .= "<li class='directory $folderClass'><span class='toggle'>$subDirectory</span><ul class='sub-items'";
|
|
|
|
if ($initialFolderState == 'collapsed') {
|
|
|
|
$items .= " style='display:none;'";
|
|
|
|
}
|
|
|
|
$items .= '>';
|
|
|
|
// Appeler récursivement la fonction pour ce sous-dossier
|
|
|
|
$items .= $this->getFolderContent($chemin . '/' . $subDirectory, $config);
|
|
|
|
$items .= '</ul></li>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ajouter les fichiers à la liste
|
|
|
|
foreach ($files as $file) {
|
|
|
|
$fileFullPath = $chemin . '/' . $file;
|
|
|
|
$fileInfo = '';
|
|
|
|
if ($showDetails) {
|
|
|
|
$fileSize = filesize($fileFullPath);
|
|
|
|
$fileSizeFormatted = $this->formatSizeUnits($fileSize);
|
2024-03-17 08:07:54 +01:00
|
|
|
$fileInfo = "<span class='file-info'> " . date("d-m-Y H:i", filemtime($fileFullPath)) . " - $fileSizeFormatted</span>";
|
2024-03-16 08:36:52 +01:00
|
|
|
}
|
|
|
|
$items .= "<li class='file'><a href='$fileFullPath' data-lity>$file</a>$fileInfo</li>";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fermer la liste
|
|
|
|
$items .= "</ul>";
|
|
|
|
|
|
|
|
return $items;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private function formatSizeUnits($bytes)
|
|
|
|
{
|
|
|
|
$units = array('octest', 'Ko', 'Mo', 'Go', 'To');
|
|
|
|
$i = 0;
|
|
|
|
while ($bytes >= 1024) {
|
|
|
|
$bytes /= 1024;
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
return round($bytes, 2) . ' ' . $units[$i];
|
|
|
|
}
|
2024-03-13 18:45:06 +01:00
|
|
|
|
2024-03-15 21:14:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-03-14 14:30:49 +01:00
|
|
|
|
2024-03-13 18:45:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Liste les dossier contenus dans RFM
|
|
|
|
*/
|
|
|
|
private function getSubdirectories($dir, $basePath = '')
|
|
|
|
{
|
|
|
|
$subdirs = array();
|
|
|
|
// Ouvrez le répertoire spécifié
|
|
|
|
$dh = opendir($dir);
|
|
|
|
// Parcourez tous les fichiers et répertoires dans le répertoire
|
|
|
|
while (($file = readdir($dh)) !== false) {
|
|
|
|
// Ignorer les entrées de répertoire parent et actuel
|
|
|
|
if ($file == '.' || $file == '..') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Construisez le chemin complet du fichier ou du répertoire
|
|
|
|
$path = $dir . '/' . $file;
|
|
|
|
// Vérifiez si c'est un répertoire
|
|
|
|
if (is_dir($path)) {
|
|
|
|
// Construisez la clé et la valeur pour le tableau associatif
|
|
|
|
$key = $basePath === '' ? ucfirst($file) : $basePath . '/' . $file;
|
|
|
|
$value = $path . '/';
|
|
|
|
// Ajouter la clé et la valeur au tableau associatif
|
|
|
|
$subdirs[$key] = $value;
|
|
|
|
// Appeler la fonction récursivement pour ajouter les sous-répertoires
|
|
|
|
$subdirs = array_merge($subdirs, $this->getSubdirectories($path, $key));
|
|
|
|
}
|
2024-03-13 16:28:19 +01:00
|
|
|
}
|
2024-03-13 18:45:06 +01:00
|
|
|
// Fermez le gestionnaire de dossier
|
|
|
|
closedir($dh);
|
|
|
|
return $subdirs;
|
2024-03-13 16:28:19 +01:00
|
|
|
}
|
|
|
|
|
2024-03-12 18:35:44 +01:00
|
|
|
}
|