[TEP-COMMIT] [CVS admin] new directory listing class
hpdl-OfajU3CKLf1/[email protected] 15 Aug 2004 18:05:45 -0000
| Newsgroups | gmane.comp.web.oscommerce.cvs |
|---|---|
| Message-ID | <[email protected]> |
Commit in admin/admin/includes/classes on MAIN
directory_listing.php +168 added 1.1
new directory listing class
----------
admin /admin /includes /classes
directory_listing.php added at 1.1
diff -N directory_listing.php
--- /dev/null Sun Aug 15 20:05:41 2004
+++ /tmp/cvsAAAEmaaOY Sun Aug 15 20:05:44 2004
@@ -0,0 +1,168 @@
+<?php
+/*
+ $Id$
+
+ osCommerce, Open Source E-Commerce Solutions
+ http://www.oscommerce.com
+
+ Copyright (c) 2004 osCommerce
+
+ Released under the GNU General Public License
+*/
+
+ class osC_DirectoryListing {
+
+/* Private methods */
+
+ var $_directory = '',
+ $_include_directories = true,
+ $_exclude_entries = array('.', '..'),
+ $_stats = false,
+ $_recursive = false,
+ $_check_extension = false,
+ $_add_directory_to_filename = false,
+ $_listing;
+
+/* Class constructor */
+
+ function osC_DirectoryListing($directory = '', $stats = false) {
+ $this->setDirectory($directory);
+ $this->setStats($stats);
+ }
+
+/* Public methods */
+
+ function setDirectory($directory) {
+ $this->_directory = $directory;
+ }
+
+ function setIncludeDirectories($boolean) {
+ if ($boolean === true) {
+ $this->_include_directories = true;
+ } else {
+ $this->_include_directories = false;
+ }
+ }
+
+ function setExcludeEntries($entries) {
+ if (is_array($entries)) {
+ foreach ($entries as $value) {
+ if (in_array($value, $this->_exclude_entries) === false) {
+ $this->_exclude_entries[] = $value;
+ }
+ }
+ } elseif (is_string($entries)) {
+ if (in_array($entries, $this->_exclude_entries) === false) {
+ $this->_exclude_entries[] = $entries;
+ }
+ }
+ }
+
+ function setStats($boolean) {
+ if ($boolean === true) {
+ $this->_stats = true;
+ } else {
+ $this->_stats = false;
+ }
+ }
+
+ function setRecursive($boolean) {
+ if ($boolean === true) {
+ $this->_recursive = true;
+ } else {
+ $this->_recursive = false;
+ }
+ }
+
+ function setCheckExtension($extension) {
+ $this->_check_extension = $extension;
+ }
+
+ function setAddDirectoryToFilename($boolean) {
+ if ($boolean === true) {
+ $this->_add_directory_to_filename = true;
+ } else {
+ $this->_add_directory_to_filename = false;
+ }
+ }
+
+ function read($directory = '') {
+ if (empty($directory)) {
+ $directory = $this->_directory;
+ }
+
+ if (is_array($this->_listing) === false) {
+ $this->_listing = array();
+ }
+
+ if ($dir = dir($directory)) {
+ while (($entry = $dir->read()) !== false) {
+ if (in_array($entry, $this->_exclude_entries) === false) {
+ if (is_file($dir->path . '/' . $entry)) {
+ if (($this->_check_extension === false) || (substr($entry, strrpos($entry, '.')+1) == $this->_check_extension)) {
+ if ($this->_add_directory_to_filename === true) {
+ if ($dir->path != $this->_directory) {
+ $entry = substr($dir->path, strlen($this->_directory)+1) . '/' . $entry;
+ }
+ }
+
+ $this->_listing[] = array('name' => $entry,
+ 'is_directory' => false);
+ if ($this->_stats === true) {
+ $stats = array('size' => filesize($dir->path . '/' . $entry),
+ 'permissions' => fileperms($dir->path . '/' . $entry),
+ 'user_id' => fileowner($dir->path . '/' . $entry),
+ 'group_id' => filegroup($dir->path . '/' . $entry),
+ 'last_modified' => filemtime($dir->path . '/' . $entry));
+ $this->_listing[sizeof($this->_listing)-1] = array_merge($this->_listing[sizeof($this->_listing)-1], $stats);
+ }
+ }
+ } elseif (is_dir($dir->path . '/' . $entry)) {
+ if ($this->_include_directories === true) {
+ $this->_listing[] = array('name' => $entry,
+ 'is_directory' => true);
+ if ($this->_stats === true) {
+ $stats = array('size' => filesize($dir->path . '/' . $entry),
+ 'permissions' => fileperms($dir->path . '/' . $entry),
+ 'user_id' => fileowner($dir->path . '/' . $entry),
+ 'group_id' => filegroup($dir->path . '/' . $entry),
+ 'last_modified' => filemtime($dir->path . '/' . $entry));
+ $this->_listing[sizeof($this->_listing)-1] = array_merge($this->_listing[sizeof($this->_listing)-1], $stats);
+ }
+ } elseif ($this->_recursive === true) {
+ $this->read($dir->path . '/' . $entry);
+ }
+ }
+ }
+ }
+
+ $dir->close();
+ unset($dir);
+ }
+ }
+
+ function getFiles() {
+ if (is_array($this->_listing) === false) {
+ $this->read();
+ }
+
+ if (is_array($this->_listing) && (sizeof($this->_listing) > 0)) {
+ usort($this->_listing, array($this, '_sortListing'));
+
+ return $this->_listing;
+ }
+
+ return array();
+ }
+
+ function getDirectory() {
+ return $this->_directory;
+ }
+
+/* Private methods */
+
+ function _sortListing($a, $b) {
+ return strcmp((($a['is_directory'] === true) ? 'D' : 'F') . $a['name'], (($b['is_directory'] === true) ? 'D' : 'F') . $b['name']);
+ }
+ }
+?>
CVSspam 0.2.9
-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285