Created
November 27, 2018 21:19
-
-
Save bazooka07/b1b15548580a3b9088b885be40d5bb6b to your computer and use it in GitHub Desktop.
3 fonctions ré-écrites dans class.plx.medias.php pour le CMS PluXml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Méthode qui retourne un tableau de tous les dossiers et sous-dossiers d'un répertoire. | |
* | |
* @author J.P. Pourrez (bazooka07) | |
**/ | |
private function _getAllDirs() { | |
$result = array(); | |
$pattern = '*/'; | |
$offset = strlen($this->path); | |
for($i=1; $i<10; $i++) { | |
$dirs = glob($this->path . str_repeat($pattern, $i), GLOB_ONLYDIR); | |
if(empty($dirs)) { break; } | |
foreach($dirs as $d) { | |
$path = substr($d, $offset); | |
$result[] = array( | |
'level' => $i, | |
/* 'name' => '/'.$path, // totalement inutile et jamais utilisé ! */ | |
'path' => $path | |
); | |
} | |
} | |
usort($result, function($a, $b) { return strcasecmp($a['path'], $b['path']); }); | |
return $result; | |
} | |
/** | |
* Méthode qui retourne la liste des fichiers d'un répertoire | |
* | |
* @param dir répertoire de lecture | |
* @return files tableau contenant la liste de tous les fichiers d'un dossier | |
* @author Stephane F | |
**/ | |
private function _getDirFiles($dir) { | |
$src = $this->path.$dir; | |
if(!is_dir($src)) return array(); | |
$defaultSample = PLX_CORE.'admin/theme/images/file.png'; | |
$offset = strlen($this->path); | |
$files = array(); | |
foreach(array_filter( | |
glob($src.'*'), | |
function($item) { return !preg_match('@\.tb\.\w+$@', $item); } # On rejette les miniatures | |
) as $filename) { | |
if(is_dir($filename)) { continue; } | |
$thumbInfos = false; | |
if(preg_match('@\.(jpe?g|png|gif)$@i', $filename, $matches)) { | |
# Youpi! We catch a picture | |
$thumbName = plxUtils::thumbName($filename); | |
if(file_exists($thumbName)) { | |
$thumbInfos = array( | |
'infos' => getimagesize($thumbName), | |
'filesize' => filesize($thumbName) | |
); | |
} | |
$sample = $this->path. '.thumbs/' .substr($filename, $offset); | |
$sampleOk = ( | |
file_exists($sample) or | |
plxUtils::makeThumb( | |
$filename, | |
$sample | |
) | |
); | |
$imgSize = getimagesize($filename); | |
} else { | |
$imgSize = false; | |
} | |
$stats = stat($filename); | |
$files[basename($filename)] = array( | |
'.thumb' => (!empty($sampleOk)) ? $sample : $defaultSample, | |
'name' => basename($filename), | |
'path' => $filename, | |
'date' => $stats['mtime'], | |
'filesize' => $stats['size'], | |
'extension' => '.' . strtolower(pathinfo($filename, PATHINFO_EXTENSION)), | |
'infos' => $imgSize, | |
'thumb' => $thumbInfos | |
); | |
} | |
ksort($files); | |
return $files; | |
} | |
/** | |
* Méthode qui formate l'affichage de la liste déroulante des dossiers | |
* | |
* @return string balise select à afficher | |
* @author J.P. Pourrez (bazooka07) | |
**/ | |
public function contentFolder() { | |
$currentFolder = $this->dir; | |
if(!empty($this->aDirs)) { | |
$options = array_map( | |
function($item) use($currentFolder) { | |
$selected = ($item['path'] == $currentFolder) ? ' selected' : ''; | |
return <<< OPTION | |
<option class="level_{$item['level']}" value="${item['path']}"$selected>/${item['path']}</option> | |
OPTION; | |
}, | |
$this->aDirs | |
); | |
} | |
$selectedRoot = (empty($this->dir)) ? ' selected' : ''; | |
$caption = L_PLXMEDIAS_ROOT; | |
$start = <<< START | |
<select class="folder" id="folder" name="folder"> | |
<option value="."$selectedRoot>($caption)</option>\n | |
START; | |
$stop = <<< STOP | |
</select>\n | |
STOP; | |
return $start . ((!empty($options)) ? implode("\n", $options) : '') . $stop; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment