From 900887f65087faa45430eabc2c8dd68ffd9df7e9 Mon Sep 17 00:00:00 2001 From: Chris Kankiewicz Date: Wed, 1 Feb 2012 11:26:27 -0700 Subject: [PATCH] Reverted to divs for file listing and restyled them to match Bootstrap styles --- index.php | 48 +++-- resources/DirectoryLister.php | 123 +++++++++--- resources/css/directorylister.css | 177 ++++++++++++++++++ resources/css/style.css | 34 ---- .../js/{custom.js => directorylister.js} | 0 resources/settings.ini-sample | 103 ---------- resources/settings.php | 30 +-- 7 files changed, 313 insertions(+), 202 deletions(-) create mode 100644 resources/css/directorylister.css delete mode 100644 resources/css/style.css rename resources/js/{custom.js => directorylister.js} (100%) delete mode 100644 resources/settings.ini-sample diff --git a/index.php b/index.php index 7b6687f2d..82c57fe1a 100644 --- a/index.php +++ b/index.php @@ -6,11 +6,11 @@ - + - + @@ -21,8 +21,11 @@
+ + - - - - - - - - - - - listDirectory() as $name => $fileInfo): ?> - - - - - - - -
FileSizeLast Modified
- - - -
+ + +
diff --git a/resources/DirectoryLister.php b/resources/DirectoryLister.php index 28a834596..e1a478b9f 100644 --- a/resources/DirectoryLister.php +++ b/resources/DirectoryLister.php @@ -1,17 +1,17 @@ _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. * @@ -63,6 +94,7 @@ public static function init() { return $reflection->newInstanceArgs(func_get_args()); } + /** * Creates the directory listing and returns the formatted XHTML * @@ -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(); @@ -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; @@ -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', @@ -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... @@ -194,6 +260,7 @@ protected function _sortArray($array) { // Return the array return $sortedArray; } + } ?> \ No newline at end of file diff --git a/resources/css/directorylister.css b/resources/css/directorylister.css new file mode 100644 index 000000000..a1e0e5ad5 --- /dev/null +++ b/resources/css/directorylister.css @@ -0,0 +1,177 @@ +/* -------------------------------------------------------------------------- */ +/* -----| GENERAL |---------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +body { + padding-top: 15px; +} + + +/* -------------------------------------------------------------------------- */ +/* -----| BREADCRUMBS |------------------------------------------------------ */ +/* -------------------------------------------------------------------------- */ + +.breadcrumb-fixed { + background-color: #FBFBFB; + background-image: -moz-linear-gradient(center top , #FFFFFF, #F5F5F5); + background-repeat: repeat-x; + border: 1px solid #DDDDDD; + box-shadow: 0 1px 0 #FFFFFF inset, 0 1px 5px rgba(0, 0, 0, 0.1); + left: 0; + position: fixed; + right: 0; + top: 0; + z-index: 1000; +} + +.breadcrumb-fixed .breadcrumb { + background: transparent; + border: none; + border-left: 1px solid transparent; + border-right: 1px solid transparent; + margin: 0 auto; + width: 912px; +} + + +/* -------------------------------------------------------------------------- */ +/* -----| DIRECTORY LISTER |------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +/* ----- HEADER ----- */ + +#header { + color: #333; + font-weight: bold; +} + +#header .fileName { + display: inline-block; + float: left; + margin: 8px; + overflow: hidden; + width: 645px; +} + +#header .fileSize { + display: inline-block; + float: left; + margin: 8px; + text-align: right; + width: 100px; +} + +#header .fileModTime { + display: inline-block; + float: right; + margin: 8px; + text-align: right; +} + +/* ----- FILE LIST ----- */ + +#directoryListing { + margin: 0; +} + +#directoryListing li { + background-color: #FFF; + display: block; + list-style: none; +} + +#directoryListing li.even a { + background-color: #FFF; +} + +#directoryListing li.odd a { + background-color: #F9F9F9; +} + +#directoryListing li a { + border-top: 1px solid #DDD; + color: #333; + display: block; + text-decoration: none; +} + +#directoryListing li a:focus { + background-color: #DEDEDE; + outline: none; +} + +#directoryListing li a:hover { + background-color: #555; + color: #FFF; + outline: none; +} + +#directoryListing .fileIcon { + display: inline-block; + margin: 8px; + margin-right: -19px; + width: 16px; +} + +#directoryListing .fileName { + display: inline-block; + float: left; + margin: 8px; + padding-left: 19px; + overflow: hidden; + white-space: nowrap; + width: 625px; +} + +#directoryListing .fileSize { + display: inline-block; + float: left; + margin: 8px; + overflow: hidden; + text-align: right; + white-space: nowrap; + width: 100px; +} + +#directoryListing .fileModTime { + display: inline-block; + float: right; + margin: 8px; + overflow: hidden; + text-align: right; + white-space: nowrap; + width: 125px; +} + + +/* -------------------------------------------------------------------------- */ +/* -----| FOOTER |----------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +footer p { + text-align: right; +} + + +/* -------------------------------------------------------------------------- */ +/* -----| MISCELLANEOUS |---------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +/* --- CLEAR FIX --- */ + +.clearfix:after { + visibility: hidden; + display: block; + font-size: 0; + content: " "; + clear: both; + height: 0; +} + +* html .clearfix { + zoom: 1; /* IE6 */ +} + +*:first-child+html .clearfix { + zoom: 1; /* IE7 */ +} diff --git a/resources/css/style.css b/resources/css/style.css deleted file mode 100644 index cd23eb50a..000000000 --- a/resources/css/style.css +++ /dev/null @@ -1,34 +0,0 @@ -body { - padding-top: 15px; -} - -footer p { - text-align: right; -} - -/*.breadcrumb-fixed-top { - position: fixed; - top: 0; -}*/ - -.breadcrumb-fixed { - background-color: #FBFBFB; - background-image: -moz-linear-gradient(center top , #FFFFFF, #F5F5F5); - background-repeat: repeat-x; - border: 1px solid #DDDDDD; - box-shadow: 0 1px 0 #FFFFFF inset, 0 1px 5px rgba(0, 0, 0, 0.1); - left: 0; - position: fixed; - right: 0; - top: 0; - z-index: 1000; -} - -.breadcrumb-fixed .breadcrumb { - background: transparent; - border: none; - border-left: 1px solid transparent; - border-right: 1px solid transparent; - margin: 0 auto; - width: 912px; -} diff --git a/resources/js/custom.js b/resources/js/directorylister.js similarity index 100% rename from resources/js/custom.js rename to resources/js/directorylister.js diff --git a/resources/settings.ini-sample b/resources/settings.ini-sample deleted file mode 100644 index 1bcbdc7a8..000000000 --- a/resources/settings.ini-sample +++ /dev/null @@ -1,103 +0,0 @@ -; Change the following values to customize DirectoryLister settings. - -[settings] - -hide_dot_Files = true -list_sort_by = alphabetical -list_folders_first = true - -;enable_cache = false -;cache_expiration = 0 - - -; The following section defines file icons more explanation -; is needed on how to use this feature - -[file_types] - -; Applications -app = app.png -bat = app.png -deb = app.png -exe = app.png -msi = app.png -rpm = app.png - -; Archives -7z = archive.png -gz = archive.png -rar = archive.png -tar = archive.png -zip = archive.png - -; Audio -aac = music.png -mid = music.png -midi = music.png -mp3 = music.png -ogg = music.png -wma = music.png -wav = music.png - -; Code -c = code.png -cpp = code.png -css = code.png -erb = code.png -htm = code.png -html = code.png -java = code.png -js = code.png -php = code.png -pl = code.png -py = code.png -rb = code.png -xhtml= code.png -xml = code.png - -; Disc Images -cue = cd.png -iso = cd.png -mdf = cd.png -mds = cd.png -mdx = cd.png -nrg = cd.png - -; Documents -csv = excel.png -doc = word.png -docx = word.png -odt = text.png -pdf = pdf.png -xls = excel.png -xlsx = excel.png - -; Images -bmp = image.png -gif = image.png -jpg = image.png -jpeg = image.png -png = image.png -tga = image.png - -; Scripts -bat = terminal.png -cmd = terminal.png -sh = terminal.png - -; Text -log = text.png -rtf = text.png -txt = text.png - -; Video -avi = video.png -mkv = video.png -mov = video.png -mp4 = video.png -mpg = video.png -wmv = video.png -swf = flash.png - -; Other -msg = message.png \ No newline at end of file diff --git a/resources/settings.php b/resources/settings.php index f2f144f08..325eca03b 100644 --- a/resources/settings.php +++ b/resources/settings.php @@ -1,37 +1,43 @@ _settings = array(); + /** * Basic settings */ -$hideDotFiles = true; -$listFoldersFirst = true; -$listSort = 'alphabetical'; +$this->_settings['hide_dot_files'] = TRUE; +$this->_settings['list_folders_first'] = TRUE; +$this->_settings['list_sort_order'] = 'alphabetical'; /** * Cache settings */ -// $cacheEnabled = false; -// $cacheExpiration = 0; - +// $this->_settings['cache_enable'] = FALSE; +// $this->_settings['cache_expire'] = 0; + /** * Hidden files */ - -$hiddenFiles = array(); -$hiddenFiles[] = '.htaccess'; -$hiddenFiles[] = '.htpasswd'; -$hiddenFiles[] = 'resources'; +$this->_settings['hidden_files'] = array(); + +$this->_settings['hidden_files'][] = '.htaccess'; +$this->_settings['hidden_files'][] = '.htpasswd'; +$this->_settings['hidden_files'][] = 'resources'; /** * Icon settings */ -$fileTypes = array( +$this->_settings['file_types'] = array( //Applications 'app' => 'app.png',