From 83cc0c82a6252de88ec493bfb1dfd5f000c0f1f2 Mon Sep 17 00:00:00 2001 From: Fred Tempez Date: Sat, 23 Mar 2024 15:43:21 +0100 Subject: [PATCH] Init Folder --- module/folder/folder.php | 235 ++++++++++++++++++++++++++ module/folder/view/config/config.css | 19 +++ module/folder/view/config/config.php | 64 +++++++ module/folder/view/index/index.css | 72 ++++++++ module/folder/view/index/index.js.php | 11 ++ module/folder/view/index/index.php | 6 + 6 files changed, 407 insertions(+) create mode 100644 module/folder/folder.php create mode 100644 module/folder/view/config/config.css create mode 100644 module/folder/view/config/config.php create mode 100644 module/folder/view/index/index.css create mode 100644 module/folder/view/index/index.js.php create mode 100644 module/folder/view/index/index.php diff --git a/module/folder/folder.php b/module/folder/folder.php new file mode 100644 index 00000000..7c959b3b --- /dev/null +++ b/module/folder/folder.php @@ -0,0 +1,235 @@ + + * @copyright Copyright (C) 2008-2018, Rémi Jean + * @author Frédéric Tempez + * @copyright Copyright (C) 2018-2024, Frédéric Tempez + * @license CC Attribution-NonCommercial-NoDerivatives 4.0 International + * @link http://zwiicms.fr/ + */ + +class folder extends common +{ + + const VERSION = '0.1'; + const REALNAME = 'Partage de dossier'; + const DATADIRECTORY = ''; // Contenu localisé inclus par défaut (page.json et module.json) + + public static $actions = [ + 'config' => self::GROUP_EDITOR, + 'index' => self::GROUP_VISITOR, + ]; + + // Contenu du chemin sélectionné + public static $folders = ''; + + public static $sharePath = [ + 'site/file/source/' + ]; + + public function index() + { + + // Configuration de l'affichage + $config['showsubfolder'] = $this->getData(['module', $this->getUrl(0), 'subfolder']); + $config['sort'] = $this->getData(['module', $this->getUrl(0), 'sort']); + $config['showdetails'] = $this->getData(['module', $this->getUrl(0), 'details']); + $config['initialfolderstate'] = $this->getData(['module', $this->getUrl(0), 'folderstate']); + + // Générer l'affichage + self::$folders = $this->getFolderContent($this->getData(['module', $this->getUrl(0), 'path']), $config); + + // Valeurs en sortie + $this->addOutput([ + 'showBarEditButton' => true, + 'showPageContent' => true, + 'view' => 'index' + ]); + } + + + public function config() + { + // Soumission du formulaire + if ( + $this->getUser('permission', __CLASS__, __FUNCTION__) === true && + $this->isPost() + ) { + $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), + 'details' => $this->getInput('folderConfigDetails', helper::FILTER_BOOLEAN), + 'folderstate' => $this->getInput('folderConfigFolderState', helper::FILTER_BOOLEAN), + ] + ]); + + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0), + 'notification' => helper::translate('Modifications enregistrées'), + 'state' => true + ]); + + } + + self::$sharePath = $this->getSubdirectories('site/file/source'); + self::$sharePath = array_flip(self::$sharePath); + + // Valeurs en sortie + $this->addOutput([ + 'view' => 'config' + ]); + } + + 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 = '"; + + return $items; + } + } + + return ''; + } + + + + + private function formatSizeUnits($bytes) + { + $units = array('octets', 'Ko', 'Mo', 'Go', 'To'); + $i = 0; + while ($bytes >= 1024) { + $bytes /= 1024; + $i++; + } + return round($bytes, 2) . ' ' . $units[$i]; + } + + + + + + + + + + /** + * 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)); + } + } + // Fermez le gestionnaire de dossier + closedir($dh); + return $subdirs; + } + +} \ No newline at end of file diff --git a/module/folder/view/config/config.css b/module/folder/view/config/config.css new file mode 100644 index 00000000..f3cc838d --- /dev/null +++ b/module/folder/view/config/config.css @@ -0,0 +1,19 @@ + +/** + * 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 + * @copyright Copyright (C) 2008-2018, Rémi Jean + * @author Frédéric Tempez + * @copyright Copyright (C) 2018-2024, Frédéric Tempez + * @license CC Attribution-NonCommercial-NoDerivatives 4.0 International + * @link http://zwiicms.fr/ + */ + +/** NE PAS EFFACER +* admin.css +*/ + diff --git a/module/folder/view/config/config.php b/module/folder/view/config/config.php new file mode 100644 index 00000000..2d7702f5 --- /dev/null +++ b/module/folder/view/config/config.php @@ -0,0 +1,64 @@ + +
+
+ 'buttonGrey', + 'href' => helper::baseUrl() . 'page/edit/' . $this->getUrl(0), + 'value' => template::ico('left') + ]); ?> +
+
+ +
+
+
+
+
+

+ +

+
+
+ 'Dossier', + 'class' => 'filemanager', + 'selected' => $this->getData(['module', $this->getUrl(0), 'path']) + ]); ?> +
+
+ 'Titre', + 'placeholder' => 'Répertoire', + 'value' => empty ($this->getData(['module', $this->getUrl(0), 'title'])) ? 'Répertoire' : $this->getData(['module', $this->getUrl(0), 'title']) + ]); ?> +
+
+
+
+ $this->getData(['module', $this->getUrl(0), 'sort']) + ]); ?> +
+
+ $this->getData(['module', $this->getUrl(0), 'subfolder']) + ]); ?> +
+
+ $this->getData(['module', $this->getUrl(0), 'details']) + ]); ?> +
+
+ $this->getData(['module', $this->getUrl(0), 'folderstate']) + ]); ?> +
+
+
+
+
+ +
Version n° + +
\ No newline at end of file diff --git a/module/folder/view/index/index.css b/module/folder/view/index/index.css new file mode 100644 index 00000000..b8499eda --- /dev/null +++ b/module/folder/view/index/index.css @@ -0,0 +1,72 @@ +#dirindex article { + display: block; + margin: 0 auto; + width: 600px; +} + +#dirindex a { + color: #004466; + text-decoration: none; +} + +#dirindex a:hover { + text-decoration: underline; +} + +#dirindex a:visited { + color: #666666; +} + +#dirindex details summary, +#dirindex details summary::-webkit-details-marker { + list-style: none; + cursor: pointer; +} + +#dirindex { + list-style: none; +} + +#dirindex .directory { + list-style-type: "\1F4C1"; +} + +#dirindex .file { + list-style-type: "\1F4C4"; +} + +#dirindex ul li { + margin-top: 10px; +} + +#dirindex li { + padding-left: 5px; + list-style-position : outside; +} + +/* Style pour le pliage/dépliage des dossiers */ +.toggle { + cursor: pointer; +} + +/* Style pour les sous-éléments des dossiers */ +.sub-items { + list-style-type: none; + margin-left: -40px; +} + + +.file-info-container { + display: flex; + float: right; + align-content: left; + /* Ajout d'une largeur fixe à la div */ + width: 200px; +} + +.file-name { + max-width: 400px; /* Largeur maximale du nom de fichier */ + white-space: nowrap; /* Empêcher le débordement du texte à la ligne suivante */ + overflow: hidden; /* Cacher tout texte qui dépasse */ + text-overflow: ellipsis; /* Ajouter des points de suspension (...) pour indiquer que le texte a été tronqué */ +} \ No newline at end of file diff --git a/module/folder/view/index/index.js.php b/module/folder/view/index/index.js.php new file mode 100644 index 00000000..106f4cbb --- /dev/null +++ b/module/folder/view/index/index.js.php @@ -0,0 +1,11 @@ + + +$(document).ready(function() { + // Gérer le clic sur les éléments avec la classe toggle + $('.toggle').click(function() { + // Trouver le prochain élément de type ul avec la classe sub-items + var subItems = $(this).next('ul.sub-items'); + // Toggle pour afficher ou cacher les sous-éléments + subItems.slideToggle(); + }); +}); diff --git a/module/folder/view/index/index.php b/module/folder/view/index/index.php new file mode 100644 index 00000000..cf4506dc --- /dev/null +++ b/module/folder/view/index/index.php @@ -0,0 +1,6 @@ +
+
+

getData(['module', $this->getUrl(0), 'title']);?>

+ +
+
\ No newline at end of file