mirror of
https://github.com/icecoder/ICEcoder.git
synced 2026-03-03 07:13:59 +01:00
Recursive only if githubDiff, no anim if > 50
Only include github.js if in githubDiff mode Only do recursive dir loading if in gitHub diff mode Move folderItems splitting out of loop to avoid unnecessary processing showFiles now begins the process of displaying files - animated into view (using setInterval) if less than 50 items, or shows immediately (by setting showContent and skipping recursion) if more showNextFile() is a function to actually display a file or if the end, kick off the process of adding deleted files/dirs
This commit is contained in:
@@ -18,93 +18,98 @@ $t = $text['get-branch'];
|
||||
<title>ICEcoder v <?php echo $ICEcoder["versionNo"];?> get branch</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
<?php if ($_SESSION['githubDiff']) { ?>
|
||||
<script src="github.js"></script>
|
||||
<?php ;}; ?>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<?php
|
||||
// Function to sort given values alphabetically
|
||||
function alphasort($a, $b) {
|
||||
return strcmp($a->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);
|
||||
// Need to get dir contents recursively? (Used by GitHub diff mode)
|
||||
if ($_SESSION['githubDiff']) {
|
||||
// Function to sort given values alphabetically
|
||||
function alphasort($a, $b) {
|
||||
return strcmp($a->getPathname(), $b->getPathname());
|
||||
}
|
||||
public function getIterator() {
|
||||
return $this->iterator;
|
||||
|
||||
// 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');
|
||||
// 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"
|
||||
);
|
||||
// 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";
|
||||
// Check if dir has .gitignore file
|
||||
function hasGitignore($dir) {
|
||||
return is_file("$dir/.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);
|
||||
// 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";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$objectListArray = array();
|
||||
foreach ($objectList as $objectRef) {
|
||||
$fileFolderName = @ltrim(substr(str_replace("\\","/",$objectRef->getPathname()), strlen($path)),"/");
|
||||
array_push($objectListArray,$fileFolderName);
|
||||
// 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
|
||||
@@ -319,61 +324,77 @@ if ($_SESSION['githubDiff']) {
|
||||
x.parentNode.removeChild(x);
|
||||
}
|
||||
folderContent = document.getElementById('branch').innerHTML;
|
||||
folderItems = folderContent.split("\n");
|
||||
|
||||
showFiles = function () {
|
||||
// Now animate folders & files into view
|
||||
i=0;
|
||||
animFolders = setInterval(function() {
|
||||
i++;
|
||||
showFiles = function() {
|
||||
// Now display folders & files
|
||||
|
||||
// Animate into view?
|
||||
if (folderItems.length <= 50) {
|
||||
showFileI=0;
|
||||
animFolders = setInterval(function() {
|
||||
showFileI++;
|
||||
showNextFile('progressive');
|
||||
},4);
|
||||
// Display immediately
|
||||
} else {
|
||||
showFileJ = folderItems.length;
|
||||
showContent = folderContent;
|
||||
showNextFile();
|
||||
}
|
||||
}
|
||||
|
||||
showNextFile = function(progressive) {
|
||||
if (progressive) {
|
||||
showContent = "";
|
||||
folderItems = folderContent.split("\n");
|
||||
for (j=0; j<=i; j++) {
|
||||
showContent += folderItems[j];
|
||||
if (j<i) {showContent += "\n";};
|
||||
for (showFileJ=0; showFileJ<=showFileI; showFileJ++) {
|
||||
showContent += folderItems[showFileJ];
|
||||
if (showFileJ<showFileI) {showContent += "\n";};
|
||||
}
|
||||
showContent = showContent.slice(28);
|
||||
if (j==folderItems.length) {
|
||||
clearInterval(animFolders);
|
||||
showContent = showContent.slice(0,-2);
|
||||
// If we've got some deleted files (as we're in GitHub diff mode), add those into the file manager
|
||||
if ("undefined" != typeof top.deletedPaths && top.deletedPaths.length > 0) {
|
||||
k = 0;
|
||||
top.addDeletedFiles = setInterval(function() {
|
||||
fSplit = top.deletedPaths[k].lastIndexOf("/");
|
||||
thePath = top.deletedPaths[k].substr(0,fSplit);
|
||||
theFile = top.deletedPaths[k].substr(fSplit+1);
|
||||
}
|
||||
showContent = showContent.slice(28);
|
||||
if (showFileJ==folderItems.length) {
|
||||
// If we've been animating into view, clear that interval
|
||||
if ("undefined" != typeof animFolders) {clearInterval(animFolders);};
|
||||
showContent = showContent.slice(0,-2);
|
||||
// If we've got some deleted files (as we're in GitHub diff mode), add those into the file manager
|
||||
if ("undefined" != typeof top.deletedPaths && top.deletedPaths.length > 0) {
|
||||
i = 0;
|
||||
top.addDeletedFiles = setInterval(function() {
|
||||
fSplit = top.deletedPaths[i].lastIndexOf("/");
|
||||
thePath = top.deletedPaths[i].substr(0,fSplit);
|
||||
theFile = top.deletedPaths[i].substr(fSplit+1);
|
||||
|
||||
// If it's not excluded
|
||||
if ("undefined" != typeof excludedArray && excludedArray.indexOf((thePath == "" ? "" : "/" + thePath)+"/"+theFile) == -1) {
|
||||
// If it's not excluded
|
||||
if ("undefined" != typeof excludedArray && excludedArray.indexOf((thePath == "" ? "" : "/" + thePath)+"/"+theFile) == -1) {
|
||||
|
||||
// If we're adding a deleted dir/file in a sub-dir
|
||||
if ("<?php echo $location;?>" == "/"+thePath) {
|
||||
top.ICEcoder.updateFileManagerList('add','/'+thePath,theFile,false,false,false,'file');
|
||||
// If we're adding a deleted dir/file at the root level
|
||||
// If we're adding a deleted dir/file in a sub-dir
|
||||
if ("<?php echo $location;?>" == "/"+thePath) {
|
||||
top.ICEcoder.updateFileManagerList('add','/'+thePath,theFile,false,false,false,'file');
|
||||
// If we're adding a deleted dir/file at the root level
|
||||
} else {
|
||||
// Folder
|
||||
if (thePath != "") {
|
||||
top.ICEcoder.updateFileManagerList('add',top.iceRoot,thePath,false,false,false,'folder');
|
||||
// File
|
||||
} else {
|
||||
// Folder
|
||||
if (thePath != "") {
|
||||
top.ICEcoder.updateFileManagerList('add',top.iceRoot,thePath,false,false,false,'folder');
|
||||
// File
|
||||
} else {
|
||||
top.ICEcoder.updateFileManagerList('add',top.iceRoot+thePath,theFile,false,false,false,'file');
|
||||
}
|
||||
top.ICEcoder.updateFileManagerList('add',top.iceRoot+thePath,theFile,false,false,false,'file');
|
||||
}
|
||||
|
||||
}
|
||||
k++;
|
||||
if ("undefined" == typeof top.deletedPaths[k]) {
|
||||
clearInterval(top.addDeletedFiles);
|
||||
}
|
||||
|
||||
},20);
|
||||
}
|
||||
setTimeout(function(){top.ICEcoder.redoTabHighlight(top.ICEcoder.selectedTab);},4);
|
||||
if (!top.ICEcoder.fmReady) {top.ICEcoder.fmReady=true;};
|
||||
}
|
||||
i++;
|
||||
if ("undefined" == typeof top.deletedPaths[i]) {
|
||||
clearInterval(top.addDeletedFiles);
|
||||
}
|
||||
|
||||
},20);
|
||||
}
|
||||
newUL.innerHTML = showContent;
|
||||
locNest.parentNode.insertBefore(newUL,locNest.nextSibling);
|
||||
},4);
|
||||
setTimeout(function(){top.ICEcoder.redoTabHighlight(top.ICEcoder.selectedTab);},4);
|
||||
if (!top.ICEcoder.fmReady) {top.ICEcoder.fmReady=true;};
|
||||
}
|
||||
newUL.innerHTML = showContent;
|
||||
locNest.parentNode.insertBefore(newUL,locNest.nextSibling);
|
||||
}
|
||||
|
||||
// If we're not in githubDiff mode, show files here
|
||||
|
||||
Reference in New Issue
Block a user