Skip to content

Commit

Permalink
Moved all directory-lister folder to resources and styled page
Browse files Browse the repository at this point in the history
  • Loading branch information
PHLAK committed Nov 27, 2010
1 parent 053e7fa commit 7e0f353
Show file tree
Hide file tree
Showing 26 changed files with 384 additions and 163 deletions.
131 changes: 0 additions & 131 deletions directory-lister/css/style.css

This file was deleted.

54 changes: 49 additions & 5 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,49 @@
<?php
include('directory-lister/DirectoryLister.php');
$lister = new DirectoryLister();
$lister->listDirectory();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Directory listing of &lt;DIRECTORY&gt;</title>
<link rel="shortcut icon" href="resources/images/icons/folder.png" />

<link rel="stylesheet" type="text/css" href="resources/css/rebase.css" />
<link rel="stylesheet" type="text/css" href="resources/css/directorylister.css" />
<link rel="stylesheet" type="text/css" href="resources/css/colorbox.css" />
<body>

<?php include('resources/DirectoryLister.php'); $lister = new DirectoryLister(); ?>

<div id="contentWraper">

<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 foreach($lister->listDirectory() as $name => $fileInfo): ?>
<li>
<a href="?dir=<?php echo $fileInfo['file_path']; ?>" class="clearfix">
<span class="fileName"><?php echo $name; ?></span>
<span class="fileSize"><?php echo $fileInfo['file_size']; ?>KB</span>
<span class="fileModTime"><?php echo $fileInfo['mod_time']; ?></span>
</a>
</li>
<?php 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>

<hr/>

<pre>
<?php print_r($lister->listDirectory()); ?>
</pre>

</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,54 @@
class DirectoryLister {

// Set some default variables
protected $_directoryPath = '.';
protected $_hiddenFiles = NULL;
protected $_directory = NULL;
protected $_hiddenFiles = NULL;

/**
* DirectoryLister construct function. Runs on object creation.
*/
function __construct() {

// Add trailing slash if none present
if(substr($this->_directoryPath,-1,1) === '/') {
$this->_directoryPath = substr_replace($this->_directoryPath, '', -1, 1);

// Set the directory to list
if (@$_GET['dir']) {
$this->_directory = $_GET['dir'];
} else {
$this->_directory = '.';
}

// Remove trailing slash if present
if(substr($this->_directory, -1, 1) == '/') {
$this->_directory = substr($this->_directory, 0, -1);
}

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

// Get hidden files and add them to
// $this->_hiddenFiles = $this->_readHiddenFiles();

print_r($this->listDirectory());
}

/**
* DirectoryLister destruct function. Runs on object destruction.
*/
function __destruct() {
echo "<br/>" . PHP_EOL . "END OF LINE"; // TODO: Remove me
// NULL
}

/**
* Creates the directory listing and returns the formatted XHTML
* @param string $path Relative path of directory to list
*/
public function listDirectory($path = NULL) {
public function listDirectory($directory = NULL) {

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

return $this->_readDirectory($path);

}

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

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

Expand All @@ -61,13 +63,20 @@ protected function _readDirectory($directory, $sort = 'natcase') {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {

// Get files real path
$realPath = realpath($directory . '/' . $file);
// Get files relative and absolute path
$relativePath = $directory . '/' . $file;

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

$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"))
'mod_time' => date("Y-m-d H:i:s", filemtime($realPath))
);
}
}
Expand All @@ -79,6 +88,14 @@ protected function _readDirectory($directory, $sort = 'natcase') {

// Return the file array
return $directoryArray;

}

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

}

}
Expand Down
50 changes: 50 additions & 0 deletions resources/css/colorbox.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
ColorBox Core Style
The following rules are the styles that are consistant between themes.
Avoid changing this area to maintain compatability with future versions of ColorBox.
*/
#colorbox, #cboxOverlay, #cboxWrapper{position:absolute; top:0; left:0; z-index:9999; overflow:hidden;}
#cboxOverlay{position:fixed; width:100%; height:100%;}
#cboxMiddleLeft, #cboxBottomLeft{clear:left;}
#cboxContent{position:relative; overflow:visible;}
#cboxLoadedContent{overflow:auto;}
#cboxLoadedContent iframe{display:block; width:100%; height:100%; border:0;}
#cboxTitle{margin:0;}
#cboxLoadingOverlay, #cboxLoadingGraphic{position:absolute; top:0; left:0; width:100%;}
#cboxPrevious, #cboxNext, #cboxClose, #cboxSlideshow{cursor:pointer;}

/*
ColorBox example user style
The following rules are ordered and tabbed in a way that represents the
order/nesting of the generated HTML, so that the structure easier to understand.
*/
#cboxOverlay{background:#000;}

#colorbox{}
#cboxTopLeft{width:14px; height:14px; background:url(../images/controls.png) 0 0 no-repeat;}
#cboxTopCenter{height:14px; background:url(../images/border.png) top left repeat-x;}
#cboxTopRight{width:14px; height:14px; background:url(../images/controls.png) -36px 0 no-repeat;}
#cboxBottomLeft{width:14px; height:43px; background:url(../images/controls.png) 0 -32px no-repeat;}
#cboxBottomCenter{height:43px; background:url(../images/border.png) bottom left repeat-x;}
#cboxBottomRight{width:14px; height:43px; background:url(../images/controls.png) -36px -32px no-repeat;}
#cboxMiddleLeft{width:14px; background:url(../images/controls.png) -175px 0 repeat-y;}
#cboxMiddleRight{width:14px; background:url(../images/controls.png) -211px 0 repeat-y;}
#cboxContent{background:#fff;}
#cboxLoadedContent{margin-bottom:5px;}
#cboxLoadingOverlay{background:url(../images/loading_background.png) center center no-repeat;}
#cboxLoadingGraphic{background:url(../images/loading.gif) center center no-repeat;}
#cboxTitle{position:absolute; bottom:-25px; left:0; text-align:center; width:100%; font-size: .9em; color:#7C7C7C;}
#cboxCurrent{position:absolute; bottom:-25px; left:58px; font-weight:bold; color:#7C7C7C; display: none !important;}

#cboxPrevious, #cboxNext, #cboxClose, #cboxSlideshow{position:absolute; bottom:-29px; background:url(../images/controls.png) 0px 0px no-repeat; width:23px; height:23px; text-indent:-9999px;}
#cboxPrevious{left:0px; background-position: -51px -25px;}
#cboxPrevious.hover{background-position:-51px 0px;}
#cboxNext{left:27px; background-position:-75px -25px;}
#cboxNext.hover{background-position:-75px 0px;}
#cboxClose{right:0; background-position:-100px -25px;}
#cboxClose.hover{background-position:-100px 0px;}

.cboxSlideshow_on #cboxSlideshow{background-position:-125px 0px; right:27px;}
.cboxSlideshow_on #cboxSlideshow.hover{background-position:-150px 0px;}
.cboxSlideshow_off #cboxSlideshow{background-position:-150px -25px; right:27px;}
.cboxSlideshow_off #cboxSlideshow.hover{background-position:-125px 0px;}
Loading

0 comments on commit 7e0f353

Please sign in to comment.