Initial commit

Working directory listing. Hardcoded sidebar template.
This commit is contained in:
2011-01-16 22:59:18 +00:00
parent ee1707d86e
commit 65c560cdf0
20 changed files with 558 additions and 0 deletions

View 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;
}
}
?>