'; }
$folderhtml = ""; // variable that will hold all the HTML about the folder
$folder_contents = scandir($folder_path); // get folder contents in alphabetical order
foreach( $folder_contents as $element ) { // one by one, set $element to a file or folder inside the passed folder
if( ($element != '.') and ($element != '..') ) { // ignore current and parent folders
clearstatcache(); // make sure each is_dir call is not using cached information from last is_dir check
if( is_dir("$folder_path/$element") ) { // if $element is a folder, call this function recursively and create HTML for that folder
$folderhtml .= "
'; }
return $folderhtml;
}
###################################################################################################### says whether sections are in this path
# returns: true or false
# parameters: path to directory to inspect
function filesys_sections_present($path)
{
if(kDEBUG) { print 'Entering filesys_sections_present...
'; }
$handle = '';
if(is_dir($path)) // make sure the path passed here is really a directory
{ $handle = opendir($path) or errors_collect('path','Cannot open this directory, try again.'); }
else {
errors_collect('path','Path is not a directory, try again.','HIGH');
if(kDEBUG) { print 'Leaving filesys_sections_present, exiting false 1.
'; }
return(0);
}
while($child = readdir($handle) and $child !== FALSE) {
if(is_dir($path.'/'.$child)
and ($child !== '..')
and ($child !== '.')
and (substr($child,2,1)=='_') ) // all valid section folders will have the format: xx_sectionname
{
if(kDEBUG) { print 'Leaving filesys_sections_present, exiting true.
'; }
return(1); // as soon as we find at least one section, return true
}
}
if(kDEBUG) { print 'Leaving filesys_sections_present, exiting false 2.
'; }
return(0); // if we get to this point, no sections are present, so return false
}
###################################################################################################### removes unwanted subfolders/files
# returns: array of safe dir children
# parameters: 1) array of dir children; 2) path to directory; 3) command to remove [files,folders]
function filesys_remove_unwanted_children($children,$path,$cmd)
{
if(kDEBUG) { print 'Entering filesys_remove_unwanted_children...
'; }
$cmd = strtolower($cmd);
if(($key = array_search('.',$children)) !== FALSE) // search for '.' current dir (always undesireable)
{ array_splice($children,$key,1); } // take out current dir
if(($key = array_search('..',$children)) !== FALSE) // search for '..' parent dir (always undesireable)
{ array_splice($children,$key,1); } // take out parent dir
if($cmd == 'files') { // remove all files from directory listing
foreach($children as $child) {
if(!is_dir($path.'/'.$child))
{ array_splice($children,array_search($child,$children),1); }
}
}
elseif($cmd == 'folders') { // remove all folders from directory listing
foreach($children as $child) {
if(is_dir($path.'/'.$child))
{ array_splice($children,array_search($child,$children),1); }
}
}
if(kDEBUG) { print 'Leaving filesys_remove_unwanted_children...
'; }
return($children); // return the much more friendly array of directory contents
}
?>