getPathname(), $b->getPathname()); } // Class to put forward the values for sorting class SortingIterator implements IteratorAggregate { private $iterator = null; public function __construct(Traversable $iterator, $callback) { $array = iterator_to_array($iterator); usort($array, $callback); $this->iterator = new ArrayIterator($array); } public function getIterator() { return $this->iterator; } } // Get a full list of dirs & files and begin sorting using above class & function $path = $docRoot.$iceRoot; $objectList = new SortingIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST), 'alphasort'); // Iterator to get files $iter = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD // Ignore "Permission denied" ); // Check if dir has .gitignore file function hasGitignore($dir) { return is_file("$dir/.gitignore"); } // Get a list of .gitignore files into $gi array $gi = array(); if(hasGitignore($path)) { $gi[] = "$path/.gitignore"; } foreach ($iter as $scanpath) { if (is_dir($scanpath) && strpos($scanpath,".git") == false) { $thisDir = str_replace("\\","/",$scanpath); if(hasGitignore($thisDir)) { $gi[] = $thisDir."/.gitignore"; } } } // Get $matches array containing existing files listed in .gitignore function parseGitignore($file) { # $file = '/absolute/path/to/.gitignore' $dir = dirname($file); $matches = array(); $lines = file($file); foreach ($lines as $line) { $line = trim($line); if ($line === '') continue; # empty line if (substr($line, 0, 1) == '#') continue; # a comment if (substr($line, 0, 1) == '!') { # negated glob $line = substr($line, 1); $files = array_diff(glob("$dir/*"), glob("$dir/$line")); } else { # normal glob $files = glob("$dir/$line"); } $matches = array_merge($matches, $files); } return $matches; } // Cycle through all .gitignore files running above function to get a list of $excluded files // Exclude the .git dir as first item as we don't want to see that $excluded = array("/.git"); foreach ($gi as $scanpath) { $excludedTest = (parseGitignore($scanpath)); if (count($excludedTest) > 0) { $excluded = array_merge($excluded, $excludedTest); } } $objectListArray = array(); foreach ($objectList as $objectRef) { $fileFolderName = @ltrim(substr(str_replace("\\","/",$objectRef->getPathname()), strlen($path)),"/"); array_push($objectListArray,$fileFolderName); } } // If we're just getting a branch, get that and set as the finalArray $scanDir = $docRoot.$iceRoot; $location = ""; echo ''; if ($_SESSION['githubDiff']) { // Show the loading screen until we're done comparing files with GitHub echo ""; $i=0; $dirListArray = $dirSHAArray = $dirTypeArray = array(); // For each of the files in our local path... for ($i=0; $i