diff --git a/lib/get-branch.php b/lib/get-branch.php index 57733d3..c64bafb 100644 --- a/lib/get-branch.php +++ b/lib/get-branch.php @@ -8,13 +8,107 @@ if (!$_SESSION['loggedIn']) { header("Location: ../"); } +?> + + + +ICEcoder v <?php echo $ICEcoder["versionNo"];?> get branch + + + + + + + +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 +$excluded = array(); +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 = ""; -if (isset($_GET['location'])) { - echo ' - \ No newline at end of file + + \ No newline at end of file