Initial commit
Working directory listing. Hardcoded sidebar template.
This commit is contained in:
60
source/lib/MediaListing/Directory.class.php
Normal file
60
source/lib/MediaListing/Directory.class.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
class MediaListing_Directory extends MediaListing_FileObject {
|
||||
|
||||
protected $files;
|
||||
protected $parent;
|
||||
|
||||
public function __construct($path, $parent, $scan) {
|
||||
if ( ! is_dir($path)) {
|
||||
throw new MediaListing_Exception_NotADirectory($path);
|
||||
}
|
||||
|
||||
parent::__construct(parent::TYPE_Directory, $path);
|
||||
$this->parent = $parent;
|
||||
|
||||
if ($scan) {
|
||||
$this->scan();
|
||||
}
|
||||
}
|
||||
|
||||
protected function scan() {
|
||||
try {
|
||||
$iterator = new MediaListing_Utility_VisibleFilesIterator(new DirectoryIterator($this->path));
|
||||
foreach ($iterator as /** @var SplFileInfo */ $source) {
|
||||
$filename = $source->getPathname();
|
||||
$basename = basename($filename);
|
||||
$this->files["{$basename}"] = MediaListing_FileObject::create($filename, $this, false);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
|
||||
uasort($this->files, function($a, $b) {
|
||||
return ($a->type() == $b->type()) ? strcasecmp($a->basename(), $b->basename()) : ($a->type() < $b->type());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function parent() {
|
||||
return $this->parent;
|
||||
}
|
||||
|
||||
public function files() {
|
||||
return $this->files;
|
||||
}
|
||||
|
||||
public function file($basename) {
|
||||
if ( ! key_exists($basename, $this->files)) {
|
||||
throw new MediaListing_Exception_FileNotFound($basename);
|
||||
}
|
||||
|
||||
$subdir = $this->files["{$basename}"];
|
||||
$subdir->scan();
|
||||
|
||||
return $subdir;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user