Init Folder
This commit is contained in:
parent
060aa9e4d5
commit
83cc0c82a6
|
@ -0,0 +1,235 @@
|
|||
<?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/
|
||||
*/
|
||||
|
||||
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 = '<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);
|
||||
$fileInfo = "<div class='file-info-container'>" . date("d-m-Y H:i", filemtime($fileFullPath)) . " - $fileSizeFormatted</div>";
|
||||
}
|
||||
$items .= "<li class='file'><div class='file-name'>$file</div>$fileInfo</li>";
|
||||
}
|
||||
|
||||
// Fermer la liste
|
||||
$items .= "</ul>";
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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 <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/
|
||||
*/
|
||||
|
||||
/** NE PAS EFFACER
|
||||
* admin.css
|
||||
*/
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
<?php echo template::formOpen('folderConfig'); ?>
|
||||
<div class="row">
|
||||
<div class="col1">
|
||||
<?php echo template::button('folderConfigBack', [
|
||||
'class' => 'buttonGrey',
|
||||
'href' => helper::baseUrl() . 'page/edit/' . $this->getUrl(0),
|
||||
'value' => template::ico('left')
|
||||
]); ?>
|
||||
</div>
|
||||
<div class="col2 offset9">
|
||||
<?php echo template::submit('folderConfigSubmit'); ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class='row'>
|
||||
<div class="col12">
|
||||
<div class="block">
|
||||
<h4>
|
||||
<?php echo helper::translate('Paramètres'); ?>
|
||||
</h4>
|
||||
<div class="row">
|
||||
<div class="col6">
|
||||
<?php echo template::select('folderConfigPath', $module::$sharePath, [
|
||||
'label' => 'Dossier',
|
||||
'class' => 'filemanager',
|
||||
'selected' => $this->getData(['module', $this->getUrl(0), 'path'])
|
||||
]); ?>
|
||||
</div>
|
||||
<div class="col6">
|
||||
<?php echo template::text('folderConfigTitle', [
|
||||
'label' => 'Titre',
|
||||
'placeholder' => 'Répertoire',
|
||||
'value' => empty ($this->getData(['module', $this->getUrl(0), 'title'])) ? 'Répertoire' : $this->getData(['module', $this->getUrl(0), 'title'])
|
||||
]); ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col3">
|
||||
<?php echo template::checkbox('folderConfigSort', true, 'Trier les dossiers et les fichiers', [
|
||||
'checked' => $this->getData(['module', $this->getUrl(0), 'sort'])
|
||||
]); ?>
|
||||
</div>
|
||||
<div class="col3">
|
||||
<?php echo template::checkbox('folderConfigSubfolder', true, 'Descendre dans l\'arboresence', [
|
||||
'checked' => $this->getData(['module', $this->getUrl(0), 'subfolder'])
|
||||
]); ?>
|
||||
</div>
|
||||
<div class="col3">
|
||||
<?php echo template::checkbox('folderConfigDetails', true, 'Date et poids', [
|
||||
'checked' => $this->getData(['module', $this->getUrl(0), 'details'])
|
||||
]); ?>
|
||||
</div>
|
||||
<div class="col3">
|
||||
<?php echo template::checkbox('folderConfigFolderState', true, 'Dossiers pliés', [
|
||||
'checked' => $this->getData(['module', $this->getUrl(0), 'folderstate'])
|
||||
]); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php echo template::formClose(); ?>
|
||||
<div class="moduleVersion">Version n°
|
||||
<?php echo $module::VERSION; ?>
|
||||
</div>
|
|
@ -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é */
|
||||
}
|
|
@ -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();
|
||||
});
|
||||
});
|
|
@ -0,0 +1,6 @@
|
|||
<div id="dirindex">
|
||||
<article>
|
||||
<h1><?php echo $this->getData(['module', $this->getUrl(0), 'title']);?></h1>
|
||||
<?php echo $module::$folders; ?>
|
||||
</article>
|
||||
</div>
|
Loading…
Reference in New Issue