Skip to content

Commit

Permalink
Reverted to divs for file listing and restyled them to match Bootstra…
Browse files Browse the repository at this point in the history
…p styles
  • Loading branch information
PHLAK committed Feb 2, 2012
1 parent f1e4997 commit 900887f
Show file tree
Hide file tree
Showing 7 changed files with 313 additions and 202 deletions.
48 changes: 23 additions & 25 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<link rel="shortcut icon" href="resources/img/icons/folder.png" />

<link rel="stylesheet" type="text/css" href="resources/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="resources/css/style.css" />
<link rel="stylesheet" type="text/css" href="resources/css/directorylister.css" />

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript" src="resources/js/bootstrap.min.js"></script>
<script type="text/javascript" src="resources/js/custom.js"></script>
<script type="text/javascript" src="resources/js/directorylister.js"></script>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
Expand All @@ -21,8 +21,11 @@

<div class="container">



<div class="breadcrumb-wrapper">
<ul class="breadcrumb">
<?php //foreach($lister->listBreadcrumbs() as $breadcrumb): ?>
<li>
<a href="#">Home</a> <span class="divider">/</span>
</li>
Expand All @@ -32,32 +35,27 @@
<li class="active">
<a href="#">Data</a>
</li>
<?php //endforeach; ?>
</ul>
</div>

<table id="directoryListerTable" class="table table-striped">
<thead>
<tr>
<th>File</th>
<th width="50">Size</th>
<th width="120">Last Modified</th>
</tr>
</thead>

<tbody>
<?php $x = 1; foreach($lister->listDirectory() as $name => $fileInfo): ?>
<tr>
<td class="fileName">
<a href="<?php if(is_dir($fileInfo['file_path'])) { echo '?dir=' . $fileInfo['file_path']; } else { echo $fileInfo['file_path']; } ?>">
<?php echo $name; ?>
</a>
</td>
<td class="fileSize"><?php echo $fileInfo['file_size']; ?></td>
<td class="fileTime"><?php echo $fileInfo['mod_time']; ?></td>
</tr>
<?php $x++; endforeach; ?>
</tbody>
</table>
<div id="header" class="clearfix">
<span class="fileName">File</span>
<span class="fileSize">Size</span>
<span class="fileModTime">Last Modified</span>
</div>

<ul id="directoryListing">
<?php $x = 1; foreach($lister->listDirectory() as $name => $fileInfo): ?>
<li class="<?php echo $x %2 == 0 ? 'even' : 'odd'; ?>">
<a href="<?php if(is_dir($fileInfo['file_path'])) { echo '?dir=' . $fileInfo['file_path']; } else { echo $fileInfo['file_path']; } ?>" class="clearfix">
<span class="fileName" style="background: transparent url(resources/img/icons/<?php echo $fileInfo['icon']; ?>) no-repeat left center;"><?php echo $name; ?></span>
<span class="fileSize"><?php echo $fileInfo['file_size']; ?></span>
<span class="fileModTime"><?php echo $fileInfo['mod_time']; ?></span>
</a>
</li>
<?php $x++; endforeach; ?>
</ul>

<hr/>

Expand Down
123 changes: 95 additions & 28 deletions resources/DirectoryLister.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
<?php

/**
* A simple PHP based directory lister that lists a directory and all
* it's sub-directories and allows you to navigate there within.
* A simple PHP based directory lister that lists the contents
* of a directory and all it's sub-directories and allows easy
* navigation of the files within.
*
* This software is dual liscensed under the following licenses:
* MIT License http://www.directorylister.com/COPYING-MIT.txt
* GPL Version 3 http://www.directorylister.com/COPYING-GPL.txt
* This software distributed under the MIT License
* http://www.opensource.org/licenses/mit-license.php
*
* More info available at http://www.directorylister.com
*
* @author Chris Kankiewicz (http://www.chriskankiewicz.com)
* @copyright 2011 Chris Kankiewicz
* @copyright 2012 Chris Kankiewicz
*/
class DirectoryLister {

// Define application version
const VERSION = '2.0.0-dev';

// Set some default variables
protected $_settings = NULL;
protected $_directory = NULL;
protected $_hiddenFiles = NULL;
protected $_appDir = NULL;
protected $_appURL = NULL;
protected $_settings = NULL;


/**
* DirectoryLister construct function. Runs on object creation.
Expand All @@ -42,17 +44,46 @@ function __construct() {

// Set class directory constant
if(!defined('__DIR__')) {
$iPos = strrpos(__FILE__, '/');
define('__DIR__', substr(__FILE__, 0, $iPos) . '/');
define('__DIR__', dirname(__FILE__));
}

// Set application directory
$this->_appDir = __DIR__;

// Get the server protocol
if ($_SERVER['HTTPS']) {
$protocol = 'https://';
} else {
$protocol = 'http://';
}

// Get the server hostname
$host = $_SERVER['HTTP_HOST'];

// Get the URL path
$pathParts = pathinfo($_SERVER['PHP_SELF']);
$path = $pathParts['dirname'];

// Ensure the path ends with a forward slash
if (substr($path, -1) != '/') {
$path = $path . '/';
}

// Build the application URL
$this->_appURL = $protocol . $host . $path;

// Get file settings
$this->_settings = parse_ini_file(__DIR__ . '/settings.ini', true);

// Get hidden files and add them to
// $this->_hiddenFiles = $this->_readHiddenFiles();
$configFile = $this->_appDir . '/settings.php';

if (file_exists($configFile)) {
include($configFile);
} else {
die('ERROR: Unable to locate config');
}

}


/**
* Special init method for simple one-line interface.
*
Expand All @@ -63,6 +94,7 @@ public static function init() {
return $reflection->newInstanceArgs(func_get_args());
}


/**
* Creates the directory listing and returns the formatted XHTML
*
Expand All @@ -75,6 +107,43 @@ public function listDirectory($directory = NULL) {
$directory = $this->_directory;
}

// Get the directory array
$directoryArray = $this->_readDirectory($directory);

// Return the array
return $directoryArray;
}


/**
* Description...
*
* @access public
*/
public function listBreadcrumbs($directory = NULL) {

// Set directory varriable if left blank
if ($directory === NULL) {
$directory = $this->_directory;
}

// Explode the path into an array
$dirArray = explode($directory);

print_r($dirArray); die();

// Return the breadcrumb array
// return $breadcrumbsArray;
}


/**
* Loop through directory and return array with pertinent information
*
* @access private
*/
protected function _readDirectory($directory, $sort = 'natcase') {

// Instantiate image array
$directoryArray = array();

Expand All @@ -84,16 +153,17 @@ public function listDirectory($directory = NULL) {
while (false !== ($file = readdir($handle))) {
if ($file != ".") {

// Get files relative and absolute path
// Get files relative path
$relativePath = $directory . '/' . $file;

if (substr($relativePath, 0, 2) == './') {
$relativePath = substr($relativePath, 2);
}

// Get files absolute path
$realPath = realpath($relativePath);

// Get file type
// Determine file type by extension
if (is_dir($realPath)) {
$fileIcon = 'folder.png';
$sort = 1;
Expand All @@ -117,9 +187,13 @@ public function listDirectory($directory = NULL) {
unset($pathArray[count($pathArray)-1]);
$directoryPath = implode('/', $pathArray);

if (!empty($directoryPath)) {
$directoryPath = '?dir=' . $directoryPath;
}

// Add file info to the array
$directoryArray['..'] = array(
'file_path' => $directoryPath,
'file_path' => $this->_appURL . $directoryPath,
'file_size' => '-',
'mod_time' => date("Y-m-d H:i:s", filemtime($realPath)),
'icon' => 'back.png',
Expand All @@ -140,24 +214,16 @@ public function listDirectory($directory = NULL) {

// Close open file handle
closedir($handle);

}

// Sort the array
$sortedArray = $this->_sortArray($directoryArray);

// Return the array
return $sortedArray;

}

/**
* Loop through directory and return array with pertinent information
*
* @access private
*/
protected function _readDirectory($directory, $sort = 'natcase') {

}


/**
* Description...
Expand Down Expand Up @@ -194,6 +260,7 @@ protected function _sortArray($array) {
// Return the array
return $sortedArray;
}

}

?>
Loading

0 comments on commit 900887f

Please sign in to comment.