- 02_2003 #============================================= # # lophty directory indexer # copyright 2001 brian donovan, indexer-script@lophty.com # # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # #============================================= #== Changes (below) ========================== #============================================= # # Patches # # Sept 09, 2001 => v 1.0 # Tim Waugh (tim@cyberelk.net, http://www.cyberelk.net/tim/) # Added support for multi-dot file names (ex. stuff.under.mytoenail.foo as # opposed to single-dot file names like stuff.foo) # #Jan 05, 2002 => v 1.5 # I added more flexibility to file listing inclusion/exclusion - can # now choose to include only files with specific extensions in # listings or to list all files, excluding those with specific # extensions. Added option to block listing of all subdirectories. # Changed var names to make variable types more obvious (ie # $arrSomeArray instead of $someArray). # # July 13, 2002 => 1.5.1 # Fixed sorting. There was a typo in isortMultiD that shortcircuted # sorting. #============================================= # == Notes (below) ================================ #============================================= # # $strThisFileName : the name of this file # # $thisDirectory : the path to the directory in which this page sits. # For Apache-served sites, you can use the predefined # $REQUEST_URI variable. Note that you can also specify a string, # like a full url, but this will not affect the directory that's actually # indexed. :D # # $strThisPageFilesDir : the name of a directory in which we'll put the # css file and gifs that we need to beautify this page Note that you # don't have to put those files into a directory separate from this # file. I just do it to make global changes for all of these indexing # pages possible - by putting the css file and gifs into a folder and # then giving $strThisPageFilesDir the value of the path to that folder, # you can update the bullets or the general appearance of the page # by changing a few files in one location. If you want to put these # files into the same directory as this page, that's fine - just give # $strThisPageFilesDir a value of "" # # $arrBulletImgs : holds the filenames of the images used as bullets # # Finally, remember to change the permissions on subdirectories that # will be listed by this script if you would like visiors to be # able to drill down into them #============================================= $strThisFileName = "index.php"; $strThisDirectoryPath = $_SERVER['REQUEST_URI']; $strThisServerName = $_SERVER['SERVER_NAME']; $strThisPageFilesDir = "style/"; $strThisPageCssFile= $strThisPageFilesDir ."dirindexer.css"; $arrFileImgProps = array('filepath' => $strThisPageFilesDir ."file.gif", 'height' => '13', 'width' => '13'); $arrDirImageProps = array('filepath' => $strThisPageFilesDir ."dir.gif", 'height' => '13', 'width' => '13'); $arrBulletImgs = array('fileImg' => $arrFileImgProps, 'dirImg' => $arrDirImageProps); #--------------------------------------------------- # Add the name of this file and the namess of the files and dirs used # with it to arrays. When the files and directories are read in, files # and dirs in these 2 arrays will not by listed or counted when this # page is viewed. If there are any other files other than those # actually used by this page that you'd rather not have so readily # available to others through this page, you can add them into these # arrays #--------------------------------------------------- $arrDontListFiles = array($strThisFileName, $arrBulletImgs['dirImg']['filepath'], $arrBulletImgs['fileImg']['filepath'], $strThisPageCssFile, ".DS_Store"); $arrDontListDirs = array($strThisPageFilesDir , "cgi-bin", "style"); #--------------------------------------------------- # Below are two array declarations. These array declarations should # contain only string values corresponding to file extensions. # # Ex. $arrDontListFilesExts = array("jpeg", "jpg", "gif"); # # Files with extensions listed in the $arrDontListFilesExts array # will not be shown. If you include any extension strings in the # $arrListOnlyFilesExts array, then *ONLY* files with those # extensions will be shown. # # Note : use lower case extensions, i.e. txt, not TXT # # Ex. (1.) # # $arrDontListFilesExts = array(); # $arrListOnlyFilesExts = array(); # # result : all files (other than any listed in $arrDontListFiles) # will be shown and counted. # # # Ex. (2.) # # $arrDontListFilesExts = array("php"); # $arrListOnlyFilesExts = array(); # # result : all files (other than any listed in $arrDontListFiles) # EXCEPT php files will be shown and counted. # # # Ex. (3.) # # $arrDontListFilesExts = array(); # $arrListOnlyFilesExts = array("zip"); # # result : only zip files not listed in $arrDontListFiles # will be shown and counted. # # # Ex. (4.) # # $arrDontListFilesExts = array("txt"); # $arrListOnlyFilesExts = array("zip", "php", "txt"); # # result : only zip and php files not listed in $arrDontListFiles # will be shown and counted. Obviously this is a dumb thing to, # but it illustrates the precedence between consideration of # $arrDontListFilesExts and $arrListOnlyFilesExts #--------------------------------------------------- $arrDontListFilesExts = array(); $arrListOnlyFilesExts = array(); #--------------------------------------------------- # $intShowSubdirs <= set this to 0 and no directories will be shown. #--------------------------------------------------- $intShowSubdirs = 1; function getThisDirName($strUrl) { #--------------------------------------------------- # getThisDirName : Accepts the path to the directory either in the # form of $REQUEST_URI or a string value and pulls out the directory # name #--------------------------------------------------- $strAfterCutOne = substr($strUrl, 0, strrpos($strUrl, "/")); $strAfterCutTwo = substr($strAfterCutOne, strrpos($strAfterCutOne, "/") - strlen($strAfterCutOne) + 1); return $strAfterCutTwo; } #--------------------------------------------------- # isort and isortMultiD are 2 sorting functions used to add pseudo # alphabetical order to the list of directory names and file names #--------------------------------------------------- function isortMultiD($arrA,$arrB) { #--------------------------------------------------- # isortMultiD : This function basically is the same as issort, # except that it runs the comparison between the 2nd row in # each array, then the first. We'll be using it to sort the # filenames, where the j in $arrFiles[i][j] is the extension # (bmp, gif, jpg, etc) and the i is the name itself. #--------------------------------------------------- $intArrA0 = hexdec(ord(strtolower($arrA[0]))); $intArrB0 = hexdec(ord(strtolower($arrB[0]))); $intArrAn = hexdec(ord(strtolower($arrA[count ($arrA) - 1]))); $intArrBn = hexdec(ord(strtolower($arrB[count ($arrB) - 1]))); if($intArrAn == $intArrBn) { if($intArrA0 == $intArrB0) return 0; return ($intArrA0 < $intArrB0) ? -1: 1; } return ($intArrAn < $intArrBn) ? -1: 1; } function indexdirThisDir() { #--------------------------------------------------- # indexdirThisDir : This function scours through the current # directory (regardless of which directory u specify via the # getThisDirName call) and makes a list of directories and does the # same for files, first by their extensions and then by their names. # Remember that since it's only alphabetical on the first char php # and phtml or php3 and php files will be jumbled together, # as will html and htm (the same logic holds for file names). #--------------------------------------------------- global $arrBulletImgs; global $arrDontListFiles; global $arrDontListDirs; global $arrListOnlyFilesExts; global $arrDontListFilesExts; global $intShowSubdirs; $intNumHiddenDirs = 0; $intNumHiddenFiles = 0; $arrDirs = array(); $arrFiles = array(); $handleThisDir=opendir('.'); # get a handle on the current directory while (false!==($handleFileORdir = readdir($handleThisDir))) { if ($handleFileORdir != "." && $handleFileORdir != "..") { if(is_dir($handleFileORdir)== false) { $thisFileNoShow = 0; for ($i = 0; $i < count($arrDontListFiles); $i++) { if($handleFileORdir == $arrDontListFiles[$i]) { $thisFileNoShow = 1; //$intNumHiddenFiles++; break; } } if($thisFileNoShow == 0) { $arrFileNameAndExtension = explode(".", $handleFileORdir); array_push ($arrFiles, $arrFileNameAndExtension); } } else { $intThisDirNoShow = 0; for ($i = 0; $i < count($arrDontListDirs); $i++) { if($handleFileORdir == $arrDontListDirs[$i]) { $intThisDirNoShow = 1; break; } } if($intThisDirNoShow == 0) { array_push ($arrDirs, $handleFileORdir); } } } } closedir($handleThisDir); @usort($arrDirs, 'isort'); usort($arrFiles, 'isortMultiD'); if ($intShowSubdirs != 0) { $strListingHTML .="\n".'
'."\n"; for ($i = 0; $i < count($arrDirs); $i++) { $strListingHTML .= 'file'.$arrDirs[$i].'
'."\n"; } $strListingHTML .='
'."\n\n"; } else { $intNumHiddenDirs = count($arrDirs); $arrDirs = array(); } $intListOnlyFilesExts = count($arrListOnlyFilesExts); $intDontListFilesExts = count($arrDontListFilesExts); $strListingHTML .='
'."\n".''."\n".''."\n"; for ($i = 0; $i < count($arrFiles); $i++) { $arrFileExtBits = $arrFiles[$i]; $arrFileFileName = array_shift($arrFileExtBits); if ($intListOnlyFilesExts > 0) { $intExtensionFound = 0; for ($j= 0; $j < count($arrFileExtBits); $j++) { if ((in_array(strtolower($arrFileExtBits[$j]), $arrListOnlyFilesExts)) && (!in_array(strtolower($arrFileExtBits[$j]), $arrDontListFilesExts))){ $intExtensionFound = 1; break; } } if ($intExtensionFound > 0) { $arrFiles[$i] = join (".", $arrFiles[$i]); $fileStats = stat($arrFiles[$i]); $fileSizeInKb = round(($fileStats[7]/1024),2); $fileLastMod = date("H : i M dS Y", $fileStats[9]); $strListingHTML .= ''."\n"; } else { $intNumHiddenFiles++; } } else { $intExtensionFound = 0; for ($j= 0; $j < count($arrFileExtBits); $j++) { if (!in_array(strtolower($arrFileExtBits[$j]), $arrDontListFilesExts)){ $intExtensionFound = 1; break; } } if ($intExtensionFound > 0) { $arrFiles[$i] = join (".", $arrFiles[$i]); $fileStats = stat($arrFiles[$i]); $fileSizeInKb = round(($fileStats[7]/1024),2); $fileLastMod = date("H : i M dS Y", $fileStats[9]); $strListingHTML .= ''."\n"; } else { $intNumHiddenFiles++; } } } $strListingHTML .='
Fichier(s)Taille (kb)Derniere modification
file'.$arrFiles[$i].''.$fileSizeInKb.''.$fileLastMod.'
file'.$arrFiles[$i].''.$fileSizeInKb.''.$fileLastMod.'
'; $intNumVisibleFiles = count($arrFiles) - $intNumHiddenFiles; $strDirSummary = '
Contient '.count($arrDirs).' sous-repertoire(s) et '.$intNumVisibleFiles.' fichier(s)
'."\n"; $strReturnHTML = $strDirSummary.$strListingHTML; return $strReturnHTML; } $thisDirName = getThisDirName($strThisDirectoryPath); $strListingHTMLstring = indexdirThisDir(); header("Content-type: text/html"); print (' ::: '.$thisDirName.' :::

'.$thisDirName.'

'.$strListingHTMLstring.' '); ?>