Files
ICEcoder/files.php
Matt Pass e2aefab2ae SESSION userLevel now loggedIn
Moving away from the idea of multiple user levels, users will either
have full access or no access
Swapped all userLevel session vars to a loggedIn var, which is a bool
Makes things simpler and paves the way towards the new login screen
(before you see any files, code etc)
2012-09-18 08:53:13 +01:00

150 lines
6.6 KiB
PHP

<?php include("lib/settings.php");?>
<!DOCTYPE html>
<html onMouseDown="top.ICEcoder.mouseDown=true" onMouseUp="top.ICEcoder.mouseDown=false" onMouseMove="if(top.ICEcoder) {top.ICEcoder.getMouseXY(event,'files');top.ICEcoder.canResizeFilesW()}" onContextMenu="top.ICEcoder.rightClickedFile=top.ICEcoder.thisFileFolderLink; return top.ICEcoder.showMenu()" onClick="top.ICEcoder.selectFileFolder()">
<head>
<title>ICEcoder file manager</title>
<link rel="stylesheet" type="text/css" href="lib/files.css">
<script src="lib/coder.js" type="text/javascript"></script>
</head>
<body onLoad="top.ICEcoder.fileManager()" onDblClick="top.ICEcoder.openFile()" onKeyDown="return top.ICEcoder.interceptKeys('files', event);" onKeyUp="top.ICEcoder.resetKeys(event);">
<div title="Refresh" onClick="top.ICEcoder.refreshFileManager()" class="refresh"></div>
<?php
$ICEcoder["restrictedFiles"] = $_SESSION['restrictedFiles'];
$ICEcoder["bannedFiles"] = $_SESSION['bannedFiles'];
// Function to sort given values alphabetically
function alphasort($a, $b) {
return strcasecmp($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);
}
public function getIterator() {
return $this->iterator;
}
}
// Get a full list of dirs & files and begin sorting using above class & function
$objectList = new SortingIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($docRoot.$iceRoot), RecursiveIteratorIterator::SELF_FIRST), 'alphasort');
// With that done, create arrays for out final ordered list and a temp container of files
$finalArray = $tempArray = array();
// To start, push folders from object into finalArray, files into tempArray
foreach ($objectList as $objectRef) {
$fileFolderName = substr($objectRef->getPathname(), strlen($docRoot.$iceRoot));
$canAdd = true;
for ($i=0;$i<count($ICEcoder["bannedFiles"]);$i++) {
if(strpos($fileFolderName,$ICEcoder["bannedFiles"][$i])!==false) {$canAdd = false;}
}
if ($objectRef->getFilename()!="." && $objectRef->getFilename()!=".." && $fileFolderName[strlen($fileFolderName)-1]!="/" && $canAdd) {
$fileFolderName!="/" && is_dir($docRoot.$iceRoot.$fileFolderName) ? array_push($finalArray,$fileFolderName) : array_push($tempArray,$fileFolderName);
}
}
// Now push root files onto the end of finalArray and splice from the temp, leaving only files that reside in subdirs
for ($i=0;$i<count($tempArray);$i++) {
if (count(explode("/",$tempArray[$i]))==2) {
array_push($finalArray,$tempArray[$i]);
array_splice($tempArray,$i,1);
$i--;
}
}
// Lastly we push remaining files into the right subdirs in finalArray
for ($i=0;$i<count($tempArray);$i++) {
$insertAt = array_search(dirname($tempArray[$i]),$finalArray)+1;
for ($j=$insertAt;$j<count($finalArray);$j++) {
if ( strcasecmp(dirname($finalArray[$j]), dirname($tempArray[$i]))==0 &&
strcasecmp(basename($finalArray[$j]), basename($tempArray[$i]))<0 ||
strpos(dirname($finalArray[$j]),dirname($tempArray[$i]))===0) {
$insertAt++;
}
}
array_splice($finalArray, $insertAt, 0, $tempArray[$i]);
}
// Finally, we have our ordered list, so display in a UL
$fileAtts = "";
if ($serverType=="Linux") {
$chmodInfo = substr(sprintf('%o', fileperms($docRoot.$iceRoot)), -3);
$fileAtts = '<span style="color: #888; font-size: 8px" id="|_perms">'.$chmodInfo.'</span>';
}
echo "<ul class=\"fileManager\">\n";
echo "<li class=\"pft-directory\">";
echo "<a nohref title=\"/\" onMouseOver=\"top.ICEcoder.overFileFolder('folder','/')\" onMouseOut=\"top.ICEcoder.overFileFolder('folder','')\" style=\"position: relative; left:-22px\">";
echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ";
echo "<span id=\"|\">/ ";
echo $iceRoot == "" ? "[ROOT]" : trim($iceRoot,"/");
echo "</span> ";
echo $fileAtts;
echo "</a>";
echo "</li>\n";
$lastPath="";
$fileCount=0;
$fileBytes=0;
$dirCount=0;
for ($i=0;$i<count($finalArray);$i++) {
$fileFolderName = str_replace("\\","/",$finalArray[$i]);
$type = is_dir($docRoot.$iceRoot.$fileFolderName) ? "folder" : "file";
$type=="folder" ? $dirCount++ : $fileCount++;
if ($type=="file") {
$fileBytes+=filesize($docRoot.$iceRoot.$fileFolderName);
// Get extension (prefix 'ext-' to prevent invalid classes from extensions that begin with numbers)
$ext = "ext-".pathinfo($docRoot.$iceRoot.$fileFolderName, PATHINFO_EXTENSION);
}
$thisDepth = count(explode("/",$fileFolderName));
$lastDepth = count(explode("/",$lastPath));
if ($thisDepth > $lastDepth) {echo "<ul>\n";}
if ($thisDepth < $lastDepth) {
for ($j=$lastDepth;$j>$thisDepth;$j--) {
echo "</ul>\n";
}
}
$restrictedFile=false;
for ($j=0;$j<count($ICEcoder["restrictedFiles"]);$j++) {
if (strpos($fileFolderName,$ICEcoder["restrictedFiles"][$j])!="") {
$restrictedFile=true;
}
}
if ($serverType=="Linux") {
$chmodInfo = substr(sprintf('%o', fileperms($docRoot.$iceRoot.$fileFolderName)), -3);
$fileAtts = '<span style="color: #888; font-size: 8px" id="'.str_replace($docRoot,"",str_replace("/","|",$fileFolderName)).'_perms">'.$chmodInfo.'</span>';
}
$type == "folder" ? $class = 'pft-directory' : $class = 'pft-file '.strtolower($ext);
if ($_SESSION['loggedIn'] || (!$_SESSION['loggedIn'] && !$restrictedFile)) {
echo "<li class=\"".$class."\"><a nohref title=\"$fileFolderName\" onMouseOver=\"top.ICEcoder.overFileFolder('$type','".str_replace($docRoot,"",str_replace("/","|",$fileFolderName))."')\" onMouseOut=\"top.ICEcoder.overFileFolder('$type','')\" style=\"position: relative; left:-22px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span id=\"".str_replace($docRoot,"",str_replace("/","|",$fileFolderName))."\">".basename($fileFolderName)."</span> ".$fileAtts."</a>\n";
} else {
echo "<li class=\"".$class."\" style=\"cursor: default\"><span style=\"position: relative; left:-22px; color: #888\" onClick=\"top.ICEcoder.message('Sorry, you need higher admin level rights to view.')\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [HIDDEN]</span>";
}
if ($i<count($finalArray)) {echo "</li>\n";}
$lastPath = $fileFolderName;
}
echo "</ul>\n</ul>\n";
echo "<script>\n";
$varOutput = "top.ICEcoder.dirCount=";
$varOutput .= $dirCount ? $dirCount : "0";
$varOutput .= ";\ntop.ICEcoder.fileCount=";
$varOutput .= $fileCount ? $fileCount : "0";
$varOutput .= ";\ntop.ICEcoder.fileBytes=";
$varOutput .= $fileBytes ? $fileBytes : "0";
// Output the JS vars
echo $varOutput;
echo ";\n</script>";
?>
<iframe name="fileControl" style="display: none"></iframe>
</body>
</html>