-<?php\r
-// from php manual page\r
-function formatBytes($val, $digits = 3, $mode = 'SI', $bB = 'B'){ //$mode == 'SI'|'IEC', $bB == 'b'|'B'\r
- $si = array('', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y');\r
- $iec = array('', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi');\r
- switch(strtoupper($mode)) {\r
- case 'SI' : $factor = 1000; $symbols = $si; break;\r
- case 'IEC' : $factor = 1024; $symbols = $iec; break;\r
- default : $factor = 1000; $symbols = $si; break;\r
- }\r
- switch($bB) {\r
- case 'b' : $val *= 8; break;\r
- default : $bB = 'B'; break;\r
- }\r
- for($i=0;$i<count($symbols)-1 && $val>=$factor;$i++)\r
- $val /= $factor;\r
- $p = strpos($val, '.');\r
- if($p !== false && $p > $digits) $val = round($val);\r
- elseif($p !== false) $val = round($val, $digits-$p);\r
- return round($val, $digits) . ' ' . $symbols[$i] . $bB;\r
-}\r
-\r
-// grab the custom params\r
-$path = isset($_REQUEST['path'])&&$_REQUEST['path'] == 'extjs' ? '../../../' : '../../';\r
-\r
-$node = isset($_REQUEST['node']) ? $_REQUEST['node'] : '';\r
-\r
-if(strpos($node, '..') !== false){\r
- die('Nice try buddy.');\r
-}\r
-\r
-$nodes = array();\r
-$directory = $path.$node;\r
-if (is_dir($directory)){\r
- $d = dir($directory);\r
- while($f = $d->read()){\r
- if($f == '.' || $f == '..' || substr($f, 0, 1) == '.') continue;\r
-\r
- $filename = $directory . '/' . $f;\r
- $lastmod = date('M j, Y, g:i a', filemtime($filename));\r
-\r
- if(is_dir($directory.'/'.$f)){\r
- $qtip = 'Type: Folder<br />Last Modified: '.$lastmod;\r
- $nodes[] = array(\r
- 'text' => $f,\r
- 'id' => $node.'/'.$f,\r
- //'qtip' => $qtip,\r
- 'cls' => 'folder'\r
- );\r
- } else {\r
- $size = formatBytes(filesize($filename), 2);\r
- $qtip = 'Type: JavaScript File<br />Last Modified: '.$lastmod.'<br />Size: '.$size;\r
- $nodes[] = array(\r
- 'text' => $f,\r
- 'id' => $node.'/'.$f,\r
- 'leaf' => true,\r
- //'qtip' => $qtip,\r
- //'qtipTitle' => $f,\r
- 'cls' => 'file'\r
- );\r
- }\r
- }\r
- $d->close();\r
-}\r
-\r
-echo json_encode($nodes);
\ No newline at end of file
+<?php
+// from php manual page
+function formatBytes($val, $digits = 3, $mode = 'SI', $bB = 'B'){ //$mode == 'SI'|'IEC', $bB == 'b'|'B'
+ $si = array('', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y');
+ $iec = array('', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi');
+ switch(strtoupper($mode)) {
+ case 'SI' : $factor = 1000; $symbols = $si; break;
+ case 'IEC' : $factor = 1024; $symbols = $iec; break;
+ default : $factor = 1000; $symbols = $si; break;
+ }
+ switch($bB) {
+ case 'b' : $val *= 8; break;
+ default : $bB = 'B'; break;
+ }
+ for($i=0;$i<count($symbols)-1 && $val>=$factor;$i++)
+ $val /= $factor;
+ $p = strpos($val, '.');
+ if($p !== false && $p > $digits) $val = round($val);
+ elseif($p !== false) $val = round($val, $digits-$p);
+ return round($val, $digits) . ' ' . $symbols[$i] . $bB;
+}
+
+// grab the custom params
+$path = isset($_REQUEST['path'])&&$_REQUEST['path'] == 'extjs' ? '../../../' : '../../';
+
+$node = isset($_REQUEST['node']) ? $_REQUEST['node'] : '';
+$isXml = isset($_REQUEST['isXml']);
+
+if(strpos($node, '..') !== false){
+ die('Nice try buddy.');
+}
+
+$nodes = array();
+$directory = $path.$node;
+if (is_dir($directory)){
+ $d = dir($directory);
+ while($f = $d->read()){
+ if($f == '.' || $f == '..' || substr($f, 0, 1) == '.') continue;
+
+ $filename = $directory . '/' . $f;
+ date_default_timezone_set('America/Los_Angeles');
+ $lastmod = date('M j, Y, g:i a', filemtime($filename));
+
+ if(is_dir($directory.'/'.$f)){
+ $qtip = 'Type: Folder<br />Last Modified: '.$lastmod;
+ $nodes[] = array(
+ 'text' => $f,
+ 'id' => $node.'/'.$f,
+ 'cls' => 'folder'
+ );
+ } else {
+ $size = formatBytes(filesize($filename), 2);
+ $qtip = 'Type: JavaScript File<br />Last Modified: '.$lastmod.'<br />Size: '.$size;
+ $nodes[] = array(
+ 'text' => $f,
+ 'id' => $node.'/'.$f,
+ 'leaf' => true,
+ 'cls' => 'file'
+ );
+ }
+ }
+ $d->close();
+}
+
+if ($isXml) {
+ $xmlDoc = new DOMDocument();
+ $root = $xmlDoc->appendChild($xmlDoc->createElement("nodes"));
+ foreach ($nodes as $node) {
+ $xmlNode = $root->appendChild($xmlDoc->createElement("node"));
+ $xmlNode->appendChild($xmlDoc->createElement("text", $node['text']));
+ $xmlNode->appendChild($xmlDoc->createElement("id", $node['id']));
+ $xmlNode->appendChild($xmlDoc->createElement("cls", $node['cls']));
+ $xmlNode->appendChild($xmlDoc->createElement("leaf", isset($node['leaf'])));
+ }
+ header("Content-Type: text/xml");
+ $xmlDoc->formatOutput = true;
+ echo $xmlDoc->saveXml();
+} else {
+ echo json_encode($nodes);
+}
\ No newline at end of file