Lots more work bringing over functionality and refining styles. Also implimented settings.ini

This commit is contained in:
Chris Kankiewicz
2010-11-27 20:23:55 -07:00
parent 7e0f3535d4
commit a7fe932a34
4 changed files with 208 additions and 31 deletions

View File

@@ -19,28 +19,26 @@
<span class="fileSize">Size</span>
<span class="fileModTime">Last Modified</span>
</div>
<ul id="directoryListing">
<?php foreach($lister->listDirectory() as $name => $fileInfo): ?>
<li>
<a href="?dir=<?php echo $fileInfo['file_path']; ?>" class="clearfix">
<?php $x = 1; foreach($lister->listDirectory() as $name => $fileInfo): ?>
<li class="<?php echo $x %2 == 0 ? 'even' : 'odd'; ?>">
<a href="<?php if($fileInfo['file_type'] == 'directory' || 'back') { echo '?dir=' . $fileInfo['file_path']; } else { echo $fileInfo['file_path']; } ?>" class="clearfix <?php echo $fileInfo['file_type']; ?>">
<span class="fileName"><?php echo $name; ?></span>
<span class="fileSize"><?php echo $fileInfo['file_size']; ?>KB</span>
<span class="fileSize"><?php echo $fileInfo['file_size']; ?></span>
<span class="fileModTime"><?php echo $fileInfo['mod_time']; ?></span>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php $x++; endforeach; ?>
</ul>
</div>
<div id="footer" class="clearfix">
<div class="path left"><a href="home">Home</a> &raquo; dir &raquo; another_dir</div>
<div id="credit right"></div>
<div class="left"><a href="home">Home</a> &raquo; dir &raquo; another_dir</div>
<div id="right"></div>
</div>
<hr/>
<pre>
<?php print_r($lister->listDirectory()); ?>
</pre>

View File

@@ -6,6 +6,7 @@
class DirectoryLister {
// Set some default variables
protected $_settings = NULL;
protected $_directory = NULL;
protected $_hiddenFiles = NULL;
@@ -32,6 +33,9 @@ class DirectoryLister {
define('__DIR__', substr(__FILE__, 0, $iPos) . '/');
}
// Get file settings
$this->_settings = parse_ini_file(__DIR__ . '/settings.ini', true);
// Get hidden files and add them to
// $this->_hiddenFiles = $this->_readHiddenFiles();
}
@@ -61,7 +65,7 @@ class DirectoryLister {
if ($handle = opendir($directory)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if ($file != ".") {
// Get files relative and absolute path
$relativePath = $directory . '/' . $file;
@@ -72,12 +76,48 @@ class DirectoryLister {
$realPath = realpath($relativePath);
// Add file info to the array
$directoryArray[pathinfo($realPath, PATHINFO_BASENAME)] = array(
'file_path' => $relativePath,
'file_size' => round(filesize($realPath) / 1024),
'mod_time' => date("Y-m-d H:i:s", filemtime($realPath))
);
// Get file type
if (is_dir($realPath)) {
$fileType = 'directory';
} else {
// Get file extension
$fileExt = pathinfo($realPath, PATHINFO_EXTENSION);
if (isset($this->_settings['file_types'][$fileExt])) {
$fileType = $this->_settings['file_types'][$fileExt];
} else {
$fileType = 'unknown';
}
}
if ($file == '..') {
// Get parent directory path
$pathArray = explode('/', $relativePath);
unset($pathArray[count($pathArray)-1]);
unset($pathArray[count($pathArray)-1]);
$directoryPath = implode('/', $pathArray);
// Add file info to the array
$directoryArray['..'] = array(
'file_path' => $directoryPath,
'file_size' => '-',
'mod_time' => date("Y-m-d H:i:s", filemtime($realPath)),
'file_type' => 'back'
);
} else {
// Add file info to the array
$directoryArray[pathinfo($realPath, PATHINFO_BASENAME)] = array(
'file_path' => $relativePath,
'file_size' => $fileType == 'directory' ? '-' : round(filesize($realPath) / 1024) . 'KB',
'mod_time' => date("Y-m-d H:i:s", filemtime($realPath)),
'file_type' => $fileType
);
}
}
}

View File

@@ -26,6 +26,10 @@ body {
padding: 3px 0 2px;
}
#header .fileName {
width: 510px;
}
.fileName {
float: left;
margin: 3px;
@@ -53,22 +57,52 @@ body {
#directoryListing li {
background-color: #FFF;
border-top: 1px solid #555;
display: block;
list-style: none;
}
/*#directoryListing li.even a {
background-color: #FFF;
}
#directoryListing li.odd a {
background-color: #FFF;
}*/
#directoryListing li a {
background: #FFF url(../images/icons/blank.png) no-repeat 3px center;
background: transparent url(../images/icons/blank.png) no-repeat 3px center;
border-top: 1px solid #555;
color: #333;
display: block;
padding-left: 20px;
text-decoration: none;
}
#directoryListing li a:focus {
background-color: #DEDEDE;
outline: none;
}
#directoryListing li a:hover {
background-color: #DC4C00;
color: #FFF;
outline: none;
}
#directoryListing li a.back {
background-image: url(../images/icons/back.png);
}
#directoryListing li a.directory {
background-image: url(../images/icons/folder.png);
}
#directoryListing li a.code {
background-image: url(../images/icons/code.png);
}
#directoryListing li a.text {
background-image: url(../images/icons/text.png);
}
@@ -78,6 +112,11 @@ body {
#footer {
font-size: .9em;
margin: 2px auto 20px;
margin: 0 auto 20px;
width: 760px;
}
}
#footer .left,
#footer .right {
margin: 3px;
}

View File

@@ -1,11 +1,111 @@
; This is the default DirectoryLister config file.
; Change the following values to customize DirectoryLister.
; Change the following values to customize DirectoryLister settings.
[basic_settings]
thumbnail_size = 100
images_per_page = 0
cache_expiration = 0
sort_order = alphabetical
[settings]
[advanced_settings]
cache_directory = "cache"
hide_dot_Files = true
list_sort_by = alphabetical
list_folders_first = true
;enable_cache = false
;cache_expiration = 0
; Define custom hidden files here
[hidden_files]
hide[] = resources
hide[] = .htaccess
hide[] = .htpasswd
; The following section defines file icons more explanation
; is needed on how to use this feature
[file_types]
; Applications
app = app
bat = app
deb = app
exe = app
msi = app
rpm = app
; Archives
7z = archive
gz = archive
rar = archive
tar = archive
zip = archive
; Audio
aac = music
mid = music
midi = music
mp3 = music
ogg = music
wma = music
wav = music
; Code
c = code
cpp = code
css = code
erb = code
htm = code
html = code
java = code
js = code
php = code
pl = code
py = code
rb = code
xhtml = code
xml = code
; Disc Images
cue = cd
iso = cd
mdf = cd
mds = cd
mdx = cd
nrg = cd
; Documents
csv = excel
doc = word
docx = word
odt = text
pdf = pdf
xls = excel
xlsx = excel
; Images
bmp = image
gif = image
jpg = image
jpeg = image
png = image
tga = image
; Scripts
bat = terminal
cmd = terminal
sh = terminal
; Text
log = text
rtf = text
txt = text
; Video
avi = video
mkv = video
mov = video
mp4 = video
mpg = video
wmv = video
swf = flash
; Other
msg = message