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

View File

@@ -0,0 +1,6 @@
<?php
class MediaListing_Exception_NotADirectory extends MediaListing_Exception {};
class MediaListing_Exception_NotAFile extends MediaListing_Exception {};
?>

View File

@@ -0,0 +1,23 @@
<?php
class MediaListing_File extends MediaListing_FileObject {
protected $size;
public function __construct($path) {
if ( ! is_file($path)) {
throw new MediaListing_Exception_NotAFile($path);
}
parent::__construct(parent::TYPE_File, $path);
$this->size = filesize($this->path);
}
public function size() {
return $this->size;
}
}
?>

View File

@@ -0,0 +1,56 @@
<?php
abstract class MediaListing_FileObject {
const TYPE_File = 1;
const TYPE_Directory = 2;
protected $type;
protected $basename;
protected $path;
public static function create($path, $parent = null, $scan = true) {
if ( ! file_exists($path)) {
throw new MediaListing_Exception_FileNotFound($path);
}
switch (filetype($path)) {
case "file": {
return new MediaListing_File($path);
} break;
case "dir": {
return new MediaListing_Directory($path, $parent, $scan);
} break;
}
}
protected function __construct($type, $path) {
$this->type = $type;
$this->path = $path;
$this->basename = basename($path);
}
public function isFile() {
return $this->type == self::TYPE_File;
}
public function isDirectory() {
return $this->type == self::TYPE_Directory;
}
public function type() {
return $this->type;
}
public function path() {
return $this->path;
}
public function basename() {
return $this->basename;
}
}
?>

View File

@@ -0,0 +1,36 @@
<?php
class MediaListing_Source {
protected $name;
protected $path;
protected $root;
public function __construct($name, $path, $scan = true) {
$this->name = $name;
$this->path = $path;
if ($scan) {
$this->scan();
}
}
protected function scan() {
$this->root = MediaListing_FileObject::create($this->path);
}
public function name() {
return $this->name;
}
public function path() {
return $this->path();
}
public function root() {
return $this->root;
}
}
?>

View File

@@ -0,0 +1,9 @@
<?php
class MediaListing_Utility_VideoFilesIterator extends FilterIterator {
public function accept() {
return preg_match('/\.(?:avi|ogm|m4v|mkv|mov|mp4|mpg|srt)$/i', $this->current()->getFilename());
}
}
?>

View File

@@ -0,0 +1,3 @@
<?php
?>

View File

@@ -0,0 +1,10 @@
<?php
$main = MediaListing_Main::instance();
$config = $main->config();
$this->smarty->assign('display_exceptions', $config->get('debug.display_exceptions'));
$this->smarty->assign('exception', $exception);
$this->smarty->assign('exception_type', get_class($exception));
?>

15
source/pages/home.php Normal file
View File

@@ -0,0 +1,15 @@
<?php
$config = MediaListing_Main::instance()->config();
$source_paths = $config->get('sources');
$sources = array();
foreach ($source_paths as $source_path) {
list($name, $path) = explode(':', $source_path);
$sources[] = new MediaListing_Source($name, $path, false);
}
$smarty->assign('sources', $sources);
?>

40
source/pages/list.php Normal file
View File

@@ -0,0 +1,40 @@
<?php
$config = MediaListing_Main::instance()->config();
$source_paths = $config->get('sources');
$sources = array();
foreach ($source_paths as $source_path) {
list($name, $path) = explode(':', $source_path);
$sources[$name] = new MediaListing_Source($name, $path);
}
$source_name = $request->get('source');
$source = $sources[$source_name];
$source_path = $request->getRemainder('source', true);
$directory = $sources[$source_name]->root();
foreach ($source_path as $subdir) {
$directory = $directory->file($subdir);
}
$path = implode('/', $source_path);
if ($path) {
$path .= '/';
}
$parent_source_path = $source_path;
array_pop($parent_source_path);
$parent_path = implode('/', $parent_source_path);
if ($parent_path) {
$parent_path .= '/';
}
$smarty->assign('parent', $directory->parent());
$smarty->assign('parent_path', $parent_path);
$smarty->assign('source', $source);
$smarty->assign('path', $path);
$smarty->assign('root', $directory);
$smarty->assign('files', $directory->files());
?>

View File

@@ -0,0 +1 @@
Error 404

View File

@@ -0,0 +1,46 @@
<h2>An unhandled error has occurred</h2>
<p>
There was a problem trying to complete the requested action. Please try again and if the problem persists, let us know.
</p>
{if $display_exceptions}
<p>
An unhandled exception was caught during the page template processing. The full details are shown below:
</p>
<table class="exception-details">
<colgroup id="header">
<col />
</colgroup>
<colgroup>
<col />
</colgroup>
<tbody>
<tr>
<th>Exception</th>
<td>{$exception_type}</td>
</tr>
<tr>
<th>File</th>
<td>{$exception->getFile()}</td>
</tr>
<tr>
<th>Line</th>
<td>{$exception->getLine()}</td>
</tr>
<tr>
<th>Message</th>
<td>{$exception->getMessage()}</td>
</tr>
<tr>
<th>Stack Trace</th>
<td><pre>{$exception->getTrace()|print_r}</pre></td>
</tr>
</tbody>
</table>
<p>
<em>Note:</em> Exception details should not be displayed on production systems.
Disable the <a href="{$base_uri}admin/settings/key/debug.show_exceptions/"><code>debug.show_exceptions</code></a>
setting to omit the exception details from this page.
</p>
{/if}

View File

@@ -0,0 +1,5 @@
<ul>
{foreach from=$sources item=source}
<li><a href="{$base_uri}list/source/{$source->name()}" title="{$source->name()}">{$source->name()}</a></li>
{/foreach}
</ul>

View File

@@ -0,0 +1,49 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Media Listing</title>
<script language="javascript"></script>
<link rel="stylesheet" type="text/css" href="{$base_uri}styles/normal.css" />
<link type="text/css" href="{$base_uri}styles/3rdparty/jquery-ui/smoothness/jquery-ui-1.8.custom.css" rel="Stylesheet" />
<script type="text/javascript" src="{$base_uri}scripts/3rdparty/jquery-1.4.2.js"></script>
<script type="text/javascript" src="{$base_uri}scripts/3rdparty/jquery-ui-1.8.custom.min.js"></script>
</head>
<body>
<div id="container">
<div id="banner">
<h1>Media Listing</h1>
</div>
<div id="page-container">
<div id="sidebar">
{include file=sidebar.tpl}
</div>
<div id="page">
{if $messages}
<div id="messages">
{foreach from=$messages item=message}
{$message}
{/foreach}
</div>
{/if}
{$page_content}
</div>
</div>
<div id="footer">
Powered by Media Listing {$version}. Written by Ben Roberts.
</div>
</div>
</body>
</html>

31
source/templates/list.tpl Normal file
View File

@@ -0,0 +1,31 @@
<table>
<thead>
<tr>
<th>Filename</th>
<th>Size</th>
</tr>
</thead>
<tbody>
{if $parent}
<tr>
<td><a href="{$base_uri}list/source/{$source->name()}/{$parent_path}" title="Parent Directory">../ <em>Parent Directory</em></a></td>
<td>-</td>
</tr>
{/if}
{foreach from=$files item=file}
<tr>
{if $file->isFile()}
<td>{$file->basename()}</td>
{else}
<td><a href="{$base_uri}list/source/{$source->name()}/{$path}{$file->basename()}" title="{$file->basename()}">{$file->basename()}</a></td>
{/if}
<td>{if $file->isFile()}
{$file->size()|formatFilesize}
{else}
-
{/if}
</td>
</tr>
{/foreach}
</tbody>
</table>

View File

@@ -0,0 +1,5 @@
<ul>
<li><a href="{$base_uri}list/source/TV" title="TV">TV</a>
<li><a href="{$base_uri}list/source/Movies" title="Movies">Movies</a>
<li><a href="{$base_uri}list/source/Music" title="Music">Music</a>
</ul>