--- /dev/null
+// Array stuff
+
+
+
+
+
+
+
+//
+Array.prototype.inArray = function (value)
+// Returns true if the passed value is found in the
+// array. Returns false if it is not.
+{
+ var i;
+ for (i=0; i < this.length; i++) {
+ // Matches identical (===), not just similar (==).
+ if (this[i] === value) {
+ return true;
+ }
+ }
+ return false;
+};
+
+
+
+
+
+// Array.concat() - Join two arrays
+if( typeof Array.prototype.concat==='undefined' ) {
+ Array.prototype.concat = function( a ) {
+ for( var i = 0, b = this.copy(); i<a.length; i++ ) {
+ b[b.length] = a[i];
+ }
+ return b;
+ };
+}
+
+// Array.copy() - Copy an array
+if( typeof Array.prototype.copy==='undefined' ) {
+ Array.prototype.copy = function() {
+ var a = [], i = this.length;
+ while( i-- ) {
+ a[i] = typeof this[i].copy!=='undefined' ? this[i].copy() : this[i];
+ }
+ return a;
+ };
+}
+
+// Array.pop() - Remove and return the last element of an array
+if( typeof Array.prototype.pop==='undefined' ) {
+ Array.prototype.pop = function() {
+ var b = this[this.length-1];
+ this.length--;
+ return b;
+ };
+}
+
+// Array.push() - Add an element to the end of an array, return the new length
+if( typeof Array.prototype.push==='undefined' ) {
+ Array.prototype.push = function() {
+ for( var i = 0, b = this.length, a = arguments, l = a.length; i<l; i++ ) {
+ this[b+i] = a[i];
+ }
+ return this.length;
+ };
+}
+
+// Array.shift() - Remove and return the first element
+if( typeof Array.prototype.shift==='undefined' ) {
+ Array.prototype.shift = function() {
+ for( var i = 0, b = this[0], l = this.length-1; i<l; i++ ) {
+ this[i] = this[i+1];
+ }
+ this.length--;
+ return b;
+ };
+}
+
+// Array.slice() - Copy and return several elements
+if( typeof Array.prototype.slice==='undefined' ) {
+ Array.prototype.slice = function( a, c ) {
+ var i, l = this.length, r = [];
+ if( !c ) { c = l; }
+ if( c<0 ) { c = l + c; }
+ if( a<0 ) { a = l - a; }
+ if( c<a ) { i = a; a = c; c = i; }
+ for( i = 0; i < c - a; i++ ) { r[i] = this[a+i]; }
+ return r;
+ };
+}
+
+// Array.splice() - Remove or replace several elements and return any deleted elements
+if( typeof Array.prototype.splice==='undefined' ) {
+ Array.prototype.splice = function( a, c ) {
+ var i = 0, e = arguments, d = this.copy(), f = a, l = this.length;
+ if( !c ) { c = l - a; }
+ for( i; i < e.length - 2; i++ ) { this[a + i] = e[i + 2]; }
+ for( a; a < l - c; a++ ) { this[a + e.length - 2] = d[a - c]; }
+ this.length -= c - e.length + 2;
+ return d.slice( f, f + c );
+ };
+}
+
+// Array.unshift() - Add an element to the beginning of an array
+if( typeof Array.prototype.unshift==='undefined' ) {
+ Array.prototype.unshift = function() {
+ this.reverse();
+ var a = arguments, i = a.length;
+ while(i--) { this.push(a[i]); }
+ this.reverse();
+ return this.length;
+ };
+}
+
+// -- 4umi additional functions
+
+// Array.forEach( function ) - Apply a function to each element
+Array.prototype.forEach = function( f ) {
+ var i = this.length, j, l = this.length;
+ for( i=0; i<l; i++ ) { if( ( j = this[i] ) ) { f( j ); } }
+};
+
+// Array.indexOf( value, begin, strict ) - Return index of the first element that matches value
+Array.prototype.indexOf = function( v, b, s ) {
+ for( var i = +b || 0, l = this.length; i < l; i++ ) {
+ if( this[i]===v || s && this[i]==v ) { return i; }
+ }
+ return -1;
+};
+
+// Array.insert( index, value ) - Insert value at index, without overwriting existing keys
+Array.prototype.insert = function( i, v ) {
+ if( i>=0 ) {
+ var a = this.slice(), b = a.splice( i );
+ a[i] = v;
+ return a.concat( b );
+ }
+};
+
+// Array.lastIndexOf( value, begin, strict ) - Return index of the last element that matches value
+Array.prototype.lastIndexOf = function( v, b, s ) {
+ b = +b || 0;
+ var i = this.length; while(i-->b) {
+ if( this[i]===v || s && this[i]==v ) { return i; }
+ }
+ return -1;
+};
+
+// Array.random( range ) - Return a random element, optionally up to or from range
+Array.prototype.random = function( r ) {
+ var i = 0, l = this.length;
+ if( !r ) { r = this.length; }
+ else if( r > 0 ) { r = r % l; }
+ else { i = r; r = l + r % l; }
+ return this[ Math.floor( r * Math.random() - i ) ];
+};
+
+// Array.shuffle( deep ) - Randomly interchange elements
+Array.prototype.shuffle = function( b ) {
+ var i = this.length, j, t;
+ while( i ) {
+ j = Math.floor( ( i-- ) * Math.random() );
+ t = b && typeof this[i].shuffle!=='undefined' ? this[i].shuffle() : this[i];
+ this[i] = this[j];
+ this[j] = t;
+ }
+ return this;
+};
+
+// Array.unique( strict ) - Remove duplicate values
+Array.prototype.unique = function( b ) {
+ var a = [], i, l = this.length;
+ for( i=0; i<l; i++ ) {
+ if( a.indexOf( this[i], 0, b ) < 0 ) { a.push( this[i] ); }
+ }
+ return a;
+};
+
+// Array.walk() - Change each value according to a callback function
+Array.prototype.walk = function( f ) {
+ var a = [], i = this.length;
+ while(i--) { a.push( f( this[i] ) ); }
+ return a.reverse();
+};
+
+
+
--- /dev/null
+// javascript functions
+
+
+// do url
+function _do(url)
+{
+ var jsel = document.createElement('SCRIPT');
+ jsel.type = 'text/javascript';
+ jsel.src = url;
+ document.body.appendChild (jsel);
+}
+
+
+// remove all child nodes by ID
+function removeChildNodesById(id) {
+ var cell = document.getElementById(id);
+ if ( cell.hasChildNodes() ) {
+ while ( cell.childNodes.length >= 1 ) {
+ cell.removeChild( cell.firstChild );
+ }
+ }
+}
+
+
+// remove all child nodes by Element
+function removeChildNodes(cell) {
+ if ( cell.hasChildNodes() ) {
+ while ( cell.childNodes.length >= 1 ) {
+ cell.removeChild( cell.firstChild );
+ }
+ }
+}
+
+
+
+
+
+
+/**
+ * Returns true if 'e' is contained in the array 'a'
+ * @author Johan Kanngord, http://dev.kanngard.net
+ */
+function contains(a, e) {
+ for(j=0;j<a.length;j++) if( a[j] == e )return true;
+ return false;
+}
+
+
+
+
+
+
+// getters
+
+// get window width / height
+function getWindowDims()
+{
+ var myWidth = 0, myHeight = 0;
+ if( typeof( window.innerWidth ) == 'number' ) { //Non-IE
+ myWidth = window.innerWidth;
+ myHeight = window.innerHeight;
+ } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode'
+ myWidth = document.documentElement.clientWidth;
+ myHeight = document.documentElement.clientHeight;
+ } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible
+ myWidth = document.body.clientWidth;
+ myHeight = document.body.clientHeight;
+ }
+ return [ myWidth, myHeight ];
+}
+
+// scrolling x / y
+function getScrollXY() {
+ var scrOfX = 0, scrOfY = 0;
+ if( typeof( window.pageYOffset ) == 'number' ) { //Netscape compliant
+ scrOfY = window.pageYOffset;
+ scrOfX = window.pageXOffset;
+ } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) { //DOM compliant
+ scrOfY = document.body.scrollTop;
+ scrOfX = document.body.scrollLeft;
+ } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) { //IE6 standards compliant mode
+ scrOfY = document.documentElement.scrollTop;
+ scrOfX = document.documentElement.scrollLeft;
+ }
+ return [ scrOfX, scrOfY ];
+}
+
+
+
+
+
+
+
+
--- /dev/null
+<?php
+
+/*********************************************
+ SETTINGS
+ *********************************************/
+
+$settings = array();
+
+$settings['title'] = 'browse';
+$settings['folders_on_top'] = true;
+$settings['hide_file_ext'] = false;
+$settings['hide_this_file'] = true;
+
+_RUN();
+
+?>
+<html>
+
+<head>
+
+ <style type="text/css">
+
+ body { font-family:Arial; margin:4em; font-size: 1em; }
+ h1 { font-size:1em; margin-bottom:2em; }
+
+ a { color:#99aa00; text-decoration:none; }
+ a:hover { background:#ddffdd; color:#663304; }
+
+ li, ol { padding:0; margin:0; color:#bbb; }
+ li { }
+ li.file a { color:#553300; }
+ li.folder a { color:#128800; }
+ li.notice { list-style-type:none; color:#944; }
+
+ #parent { position:absolute; left:2em; display:block; width:2em; text-align:center; }
+
+ </style>
+
+ <title><?php echo $settings['title']; ?> <?php echo $p == "" ? "" : " : " . $p; ?></title>
+
+</head>
+
+<body>
+
+ <?php if ($parent_dir) : ?>
+ <a href="?p=<?php echo $parent_dir;?>" id="parent">↑</a>
+ <?php endif; ?>
+
+ <h1>
+ <a href="<?php echo $_SERVER['SCRIPT_NAME'];?>"><?php echo $settings['title']; ?></a>
+ :
+ <?php echo breadcrumbs($p); ?>
+ </h1>
+
+ <ol>
+ <?php if($fileList) : ?>
+
+ <?php foreach($fileList as $f) : ?>
+
+ <?
+ if($f['type'] == "Folder") {
+ $class = 'folder';
+ $href = "?p=" . $p . $f['name'];
+ $name = $f['name'];
+ }
+ else {
+ $class = 'file';
+ $href = pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME) . '/' . $p . $f['name'];
+ $name = $settings['hide_file_ext'] ? removeExtension($f['name']) : $f['name'];
+ }
+ ?>
+
+ <li class="<?php echo $class; ?>">
+ <a href="<?php echo $href; ?>"><?php echo $name; ?></a>
+ </li>
+
+ <?php endforeach; ?>
+
+ <?php else : ?>
+
+ <li class="notice">
+ error: <strong>not found</strong>
+ </li>
+
+ <?php endif; ?>
+ </ol>
+
+</body>
+
+</html>
+
+<?php
+
+/*********************************************
+ FUNCTIONS
+ *********************************************/
+
+/**
+ * init
+ */
+function _RUN()
+{
+ global $p, $parent_dir, $fileList, $settings;
+
+ // get current path from URL
+ $p = isset($_GET['p']) ? $_GET['p'] : false;
+
+ // clean path to make sure it's not hacked
+ if($p && (strstr($p, '../') || strstr($p, '//') || $p == "./")) $p = "";
+
+ // get parent directory of current path
+ $parent_dir = $p ? pathinfo($p, PATHINFO_DIRNAME) . '/' : false;
+
+ // create file array from path, if it's a legit folder
+ $fileList = array();
+ if(is_dir("./" . $p)) {
+ $fileList = fileArray("./" . $p);
+ if($settings['folders_on_top']) {
+ $folders = array();
+ $files = array();
+ foreach($fileList as $f) {
+ if($settings['hide_this_file'] &&
+ pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME) . '/' . $p . $f['name'] ==
+ pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME) . '/' . pathinfo(__FILE__, PATHINFO_BASENAME))
+ continue;
+ if($f['type'] == 'Folder')
+ $folders[] = $f;
+ else
+ $files[] = $f;
+ }
+ $fileList = array_merge($folders, $files);
+ }
+ }
+ else {
+ $p == false;
+ }
+
+ return false;
+}
+
+/**
+ * file/folder array
+ *
+ * @param String $p the path
+ * @param String[] $extensions extensions of files to show
+ * @param String[] $excludes files to exclude
+ * @param Bool $show_hidden show hidden files
+ * @param Array[] the array of files
+ *
+ */
+function fileArray($p, $extensions = Array(), $excludes = Array('.', '..'), $show_hidden = false)
+{
+ $result = Array();
+ $parsedResult = Array();
+
+ if ($handle = opendir($p)) {
+ while (false !== ($file = readdir($handle))) {
+ if (!in_array($file, $excludes)) {
+
+ if(!$show_hidden)
+ if( $file{0} == ".") continue;
+
+ // is a folder
+ if(is_dir($p.$file)) {
+ $folderInfo = Array (
+ 'name' => $file .'/',
+ 'mtime' => $mtime = filemtime($p . $file),
+ 'type' => 'Folder',
+ 'size' => null,
+ );
+
+ if(in_array('Folder', $excludes)) continue;
+ if(in_array('Folder', $extensions)) {
+ $parsedResult[] = $folderInfo;
+ continue;
+ }
+ $result[] = $folderInfo;
+ }
+ // is a file
+ else {
+ $fileInfo = Array(
+ 'name' => $file,
+ 'mtime' => $mtime = filemtime($p . $file),
+ 'type' => $type = pathinfo($file, PATHINFO_EXTENSION),
+ 'size' => filesize($p.$file),
+ );
+ if(in_array($type, $extensions)) {
+ $parsedResult[] = $fileInfo;
+ continue;
+ }
+ $result[] = $fileInfo;
+ }
+ }
+ }
+ }
+
+// if(sizeof($extensions) > 0)
+// return sortArray($parsedResult, 'A', 'N');
+// else
+ return sort_array_of_arrays($result, 'name', 'name'); //sortArray($result, 'A', 'N');
+}
+
+
+/**
+ * sort array of arrays
+ * requires array of associative arrays -- not checked within array
+ *
+ * @author : http://phosphorusandlime.blogspot.com/2005/12/php-sort-array-by-one-field-in-array.html
+ *
+ * @param Array[] $ARRAY (two dimensional array of arrays)
+ * @param String $sortby_index index/column to be sorted on
+ * @param String $key_index equivalent to primary key column in SQL
+ */
+function sort_array_of_arrays($ARRAY, $sortby_index, $key_index)
+{
+ $ORDERING = array();
+ $SORTED = array();
+ $_DATA = array();
+ $_key = '';
+ $_sort_col_val = '';
+ $_i = 0;
+
+ // get ordering array
+ foreach ( $ARRAY as $_DATA ) {
+ $_key = $_DATA[$key_index];
+ $ORDERING[$_key] = $_DATA[$sortby_index];
+ }
+
+ // sort ordering array
+ asort($ORDERING);
+
+ // map ARRAY back to ordering array
+ foreach ( $ORDERING as $_key => $_sort_col_val ) {
+ // get index for ARRAY where ARRAY[][$key_index] == $_key
+ foreach ($ARRAY as $_i => $_DATA) {
+ if ( $_key == $_DATA[$key_index] ) {
+ $SORTED[] = $ARRAY[$_i];
+ continue;
+ }
+ }
+ }
+ return $SORTED;
+}
+
+
+/**
+ * Format Size
+ * @param int $size in bytes
+ * @param int $round round value
+ *
+ */
+function format_size($size, $round = 0)
+{
+ $sizes = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
+ for ($i = 0; $size > 1024 && $i < count($sizes) - 1; $i++) $size /= 1024;
+ return round($size, $round) . $sizes[$i];
+}
+
+
+/**
+ * remove file extension from string
+ */
+function removeExtension($strName)
+{
+ $ext = strrchr($strName, '.');
+ if($ext !== false)
+ $strName = substr($strName, 0, -strlen($ext));
+ return $strName;
+}
+
+/**
+ * breadcrumbs
+ * @param String $path path
+ * @param String $sep separator
+ * @param String $path_var path variable for the url
+ * @return String
+ */
+function breadcrumbs($path, $sep = " / ", $path_var = "p")
+{
+ $pathParts = explode("/", $path);
+ $pathCT = 0;
+ $br = "";
+ foreach($pathParts as $pt) {
+ $br .= '<a href="?' . $path_var . '=';
+ for($i=0; $i <= $pathCT; $i++) {
+ $br .= $pathParts[$i].'/';
+ }
+ $br .= '">'.$pt.'</a>';
+ if($pathCT < sizeof($pathParts)-2)
+ $br .= $sep;
+ $pathCT++;
+ }
+ return $br;
+}
+
+?>
--- /dev/null
+<?
+
+
+// returns comma separated value string
+function arrayToCSVString($array) // return: String
+{
+ $str = "";
+ $c=0;
+ foreach($array as $a) {
+ $str .= "'".$a['id']."'";
+ $str .= $c < count($array)-1 ? "," : "";
+ $c++;
+ }
+ return $str;
+}
+
+
+
+?>
--- /dev/null
+<?
+
+require_once('function.filelist.php');
+
+?>
--- /dev/null
+<?
+
+function fileExtension($filename)
+{
+ return substr(strrchr($filename, '.'), 1);
+/*
+ $path_info = pathinfo($filename) ? pathinfo($filename) : array('extension');
+ return $path_info['extension'] ? $path_info['extension'] : "";
+ */
+}
+
+
+function verifyPath($path) {
+ if (preg_match("/\.\.\//", $path)) return false;
+ else return true;
+}
+
+/*
+ function formatSize($bytes) {
+
+ if(is_integer($bytes) && $bytes > 0) {
+ $formats = array("%d bytes", "%.1f kb", "%.1f mb", "%.1f gb", "%.1f tb");
+ $logsize = min( (int)(log($bytes) / log(1024)), count($formats)-1);
+ return sprintf($formats[$logsize], $bytes/pow(1024, $logsize));
+ }
+
+ // it's a folder without calculating size
+ else if(!is_integer($bytes) && $bytes == '-') {
+ return '-';
+ }
+ else {
+ return '0 bytes';
+ }
+
+
+ }
+ */
+
+
+ function formatSize($size, $round = 0) {
+ //Size must be bytes!
+ $sizes = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
+ for ($i=0; $size > 1024 && $i < count($sizes) - 1; $i++) $size /= 1024;
+ return round($size,$round)." ".$sizes[$i];
+}
+
+
+
+
+?>
--- /dev/null
+<?php\r
+\r
+include_once('function.file.php');\r
+\r
+\r
+function quickFileList()\r
+{\r
+ $output = `ls -1|fgrep -v index.php |awk '{ print "<a href=" $1 ">" $1 "</a>" }'`;\r
+ return $output;\r
+}\r
+\r
+\r
+function fileList($directory, $recursive) \r
+{\r
+ $array_items = array();\r
+ if ($handle = opendir($directory)) {\r
+ while (false !== ($file = readdir($handle))) {\r
+ if ($file != "." && $file != "..") {\r
+ if (is_dir($directory. "/" . $file)) {\r
+ if($recursive) {\r
+ $array_items = array_merge($array_items, directoryToArray($directory. "/" . $file, $recursive));\r
+ }\r
+ $file = $directory . "/" . $file;\r
+ $array_items[] = preg_replace("/\/\//si", "/", $file);\r
+ } else {\r
+ $file = $directory . "/" . $file;\r
+ $array_items[] = preg_replace("/\/\//si", "/", $file);\r
+ }\r
+ }\r
+ }\r
+ closedir($handle);\r
+ }\r
+ return $array_items;\r
+}\r
+\r
+\r
+function fileArray(\r
+ $p, \r
+ $extensions = Array(), \r
+ $excludes = Array('.', '..'), \r
+ $www_root = "http://", \r
+ $skipHidden = true)\r
+{\r
+ // root urls\r
+ $AR = $p;\r
+ $WWW = $www_root;\r
+\r
+ $result = Array();\r
+ $parsedResult = Array();\r
+ \r
+ if ($handle = opendir($p)) {\r
+ while (false !== ($file = readdir($handle))) {\r
+ if (!in_array($file, $excludes)) {\r
+\r
+ if($skipHidden) {\r
+ if( $file{0} == ".") continue;\r
+ }\r
+ \r
+ // is a folder\r
+ if(is_dir($p.$file)) {\r
+ $folderInfo = Array (\r
+ 'name' => $file,\r
+ 'mtime' => $mtime = filemtime($p.$file),\r
+ 'type' => 'Folder',\r
+ 'size' => null,\r
+ 'localroot' => $p.$file."/",\r
+ 'url' => str_replace($AR, $WWW, $p.$file)\r
+ ); \r
+\r
+ if(in_array('Folder', $excludes)) continue;\r
+ if(in_array('Folder', $extensions)) {\r
+ $parsedResult[] = $folderInfo;\r
+ continue;\r
+ }\r
+ $result[] = $folderInfo;\r
+ }\r
+ \r
+ // is a file\r
+ else {\r
+ $fileInfo = Array(\r
+ 'name' => $file,\r
+ 'mtime' => $mtime = filemtime($p.$file),\r
+ 'type' => $type = fileExtension($p.$file),\r
+ 'size' => filesize($p.$file),\r
+ 'localroot' => $p.$file,\r
+ 'url' => str_replace($AR, $WWW, $p.$file)\r
+ );\r
+ if(in_array($type, $extensions)) {\r
+ $parsedResult[] = $fileInfo;\r
+ continue;\r
+ }\r
+ $result[] = $fileInfo;\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ if(sizeof($extensions) > 0)\r
+ return sortFiles($parsedResult, 'A', 'N');\r
+ else\r
+ return sortFiles($result, 'A', 'N');\r
+}\r
+\r
+\r
+// sort file list from fileArray()\r
+function sortFiles($files, $mode, $col) \r
+{ \r
+ $sortedFiles = orderByColumn($files, $col);\r
+ $sortOrder = $mode;\r
+ if($sortOrder == 'A') {\r
+ ksort($sortedFiles);\r
+ $result = $sortedFiles;\r
+ }\r
+ else {\r
+ krsort($sortedFiles);\r
+ $result = $sortedFiles;\r
+ }\r
+ $r = Array();\r
+ foreach($result as $res)\r
+ $r[] = $res;\r
+\r
+ return $r;\r
+}\r
+\r
+\r
+\r
+// (N = name, S = size, T = type, M = mtime\r
+function orderByColumn($input, $type)\r
+{ \r
+ $column = $type; \r
+ $result = Array();\r
+ $columnList = Array(\r
+ 'N'=>'name', \r
+ 'S'=>'size', \r
+ 'T'=>'type', \r
+ 'M'=>'mtime'\r
+ );\r
+ $rowcount = 0;\r
+ \r
+ foreach($input as $key=>$value) {\r
+ $naturalSort = true;\r
+ // natural sort - make array keys lowercase\r
+ if($naturalSort) {\r
+ $col = $value[$columnList[$column]];\r
+ $res = strtolower($col).'.'.$rowcount.$type;\r
+ $result[$res] = $value;\r
+ }\r
+ // regular sort - uppercase values get sorted on top\r
+ else {\r
+ $res = $value[$columnList[$column]].'.'.$rowcount.$type;\r
+ $result[$res] = $value;\r
+ }\r
+ $rowcount++;\r
+ }\r
+ return $result;\r
+}\r
+\r
+\r
+\r
+function dirTree($dir)\r
+{\r
+ $tree = array();\r
+ $dirs = array(array($dir, &$tree));\r
+ for($i = 0; $i < count($dirs); ++$i) {\r
+ $d = opendir($dirs[$i][0]);\r
+ $tier =& $dirs[$i][1];\r
+ while($file = readdir($d)) {\r
+ if ($file != '.' and $file != '..') {\r
+ $path = $dirs[$i][0] . DIRECTORY_SEPARATOR . $file;\r
+ if (is_dir($path)) {\r
+ $tier[$file] = array();\r
+ $dirs[] = array($path, &$tier[$file]);\r
+ }\r
+ else {\r
+ $tier[$file] = filesize($path);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ return $tree;\r
+}\r
+\r
+\r
+\r
+function breadcrumbs($path, $sep = " / ") // return String\r
+{\r
+ $pathParts = explode("/", $path); \r
+ \r
+ // path counter\r
+ $pathCT = 0; \r
+ \r
+ $br = "";\r
+ // path parts for breadcrumbs\r
+ foreach($pathParts as $pt) {\r
+ $br .= '<a href="?p=';\r
+ for($i=0; $i <= $pathCT; $i++) {\r
+ $br .= $pathParts[$i].'/'; \r
+ }\r
+ $br .= '">'.$pt.'</a>'; \r
+ if($pathCT < sizeof($pathParts)-2)\r
+ $br .= $sep; \r
+ $pathCT++;\r
+ }\r
+ \r
+ return $br;\r
+}\r
+?>\r
--- /dev/null
+<?
+
+include_once('function.array.php');
+include_once('function.browser.php');
+include_once('function.filelist.php');
+include_once('function.file.php');
+include_once('function.session.php');
+include_once('function.unicode.php');
+include_once('function.util.php');
+
+?>
--- /dev/null
+<?
+
+// set session variables
+function setSessionVar($sessionvar, $default) {
+ if (isset($_GET[$sessionvar])) $var = $_GET[$sessionvar];
+ else if (isset($_SESSION[$sessionvar])) $var = $_SESSION[$sessionvar];
+ else $var = $default;
+ return $var;
+}
+
+?>
--- /dev/null
+<?
+
+
+// utf8_to_unicode
+function utf8_to_unicode( $str ) {
+ $unicode = array();
+ $values = array();
+ $lookingFor = 1;
+ for ($i = 0; $i < strlen( $str ); $i++ ) {
+ $thisValue = ord( $str[ $i ] );
+ if ( $thisValue < 128 ) $unicode[] = $thisValue;
+ else {
+ if ( count( $values ) == 0 ) $lookingFor = ( $thisValue < 224 ) ? 2 : 3;
+ $values[] = $thisValue;
+ if ( count( $values ) == $lookingFor ) {
+ $number = ( $lookingFor == 3 ) ?
+ ( ( $values[0] % 16 ) * 4096 ) + ( ( $values[1] % 64 ) * 64 ) + ( $values[2] % 64 ):
+ ( ( $values[0] % 32 ) * 64 ) + ( $values[1] % 64 );
+ $unicode[] = $number;
+ $values = array();
+ $lookingFor = 1;
+ }
+ }
+ }
+ return $unicode;
+}
+
+// unicode_to_entities
+function unicode_to_entities( $unicode ) {
+ $entities = '';
+ foreach( $unicode as $value ) $entities .= '&#' . $value . ';';
+ return $entities;
+}
+
+// convert string from unicode to entities in one hit
+function convertUnicodeToEntities($unicode_str){
+ $unicode = utf8_to_unicode($unicode_str);
+ return unicode_to_entities($unicode);
+}
+
+// unicode_to_entities_preserving_ascii
+function unicode_to_entities_preserving_ascii( $unicode ) {
+ $entities = '';
+ foreach( $unicode as $value ) {
+ $entities .= ( $value > 127 ) ? '&#' . $value . ';' : chr( $value );
+ }
+ return $entities;
+}
+
+// strpos_unicode
+// $position = strpos_unicode( $unicode , utf8_to_unicode( '42' ) );
+function strpos_unicode( $haystack , $needle , $offset = 0 ) {
+ $position = $offset;
+ $found = FALSE;
+ while( (! $found ) && ( $position < count( $haystack ) ) ) {
+ if ( $needle[0] == $haystack[$position] ) {
+ for ($i = 1; $i < count( $needle ); $i++ ) {
+ if ( $needle[$i] != $haystack[ $position + $i ] ) break;
+ }
+ if ( $i == count( $needle ) ) {
+ $found = TRUE;
+ $position--;
+ }
+ }
+ $position++;
+ }
+ return ( $found == TRUE ) ? $position : FALSE;
+}
+
+//unicode_to_utf8
+function unicode_to_utf8( $str ) {
+ $utf8 = '';
+ foreach( $str as $unicode ) {
+ if ( $unicode < 128 ) {
+ $utf8.= chr( $unicode );
+ } elseif ( $unicode < 2048 ) {
+ $utf8.= chr( 192 + ( ( $unicode - ( $unicode % 64 ) ) / 64 ) );
+ $utf8.= chr( 128 + ( $unicode % 64 ) );
+ } else {
+ $utf8.= chr( 224 + ( ( $unicode - ( $unicode % 4096 ) ) / 4096 ) );
+ $utf8.= chr( 128 + ( ( ( $unicode % 4096 ) - ( $unicode % 64 ) ) / 64 ) );
+ $utf8.= chr( 128 + ( $unicode % 64 ) );
+ }
+ }
+ return $utf8;
+}
+
+
+
+?>
--- /dev/null
+<?
+
+
+function print_pre($array)
+{
+ echo '<pre>';
+ print_r($array);
+ echo '</pre>';
+}
+
+
+?>
--- /dev/null
+<?\r
+/* \r
+ * File Browser\r
+ *\r
+ * Lists files in script directory, creating\r
+ * a browsable file tree.\r
+ *\r
+ * many options are available for easy tweaking in the $SETTINGS array\r
+ *\r
+ * @copyright : 2005\r
+ * @author : Gabriel Dunne\r
+ * @email : gdunne@quilime.com\r
+ * @url : http://www.quilime.com\r
+ *\r
+ *\r
+ * @param string $root : Directory to list\r
+ * Examples:\r
+ * '/' : drive root\r
+ * './' : script root\r
+ * './Users/Me/Pictures/gallery1/' : a folder\r
+ */\r
+class FileBrowser {\r
+ \r
+ // settings\r
+ var $SETTING = array();\r
+ \r
+ // if there's a custom index, this will get set\r
+ var $customIndex, $root, $path, $files;\r
+\r
+ var $totalFiles, $totalFolders;\r
+\r
+ function FileBrowser($root = './') {\r
+ \r
+ $this->totalFiles = 0;\r
+ $this->totalFolders = 0;\r
+\r
+ // allow the users to browse folders\r
+ $this->SETTINGS['browse'] = true;\r
+\r
+ // the current index file \r
+ $this->SETTINGS['filename'] = 'index.php';\r
+ \r
+ // track downloads\r
+ $this->SETTINGS['trackdls'] = true;\r
+ \r
+ // enable uploading\r
+ $this->SETTINGS['upload'] = false;\r
+ $this->SETTINGS['uploaddir'] = 'uploads/'; \r
+\r
+ // download config file\r
+ $this->SETTINGS['dlconfig'] = '';\r
+ \r
+ // title in the HTML header\r
+ $this->SETTINGS['title'] = 'bin';\r
+ \r
+ // html DOM id\r
+ $this->SETTINGS['id'] = 'fileBrowser';\r
+\r
+ // show footer \r
+ $this->SETTINGS['footer'] = true;\r
+ \r
+ // show header\r
+ $this->SETTINGS['header'] = true;\r
+ \r
+ // show sorting header\r
+ $this->SETTINGS['sort'] = true;\r
+ \r
+ // show/hide columns\r
+ $this->SETTINGS['lineNumbers'] = true;\r
+ $this->SETTINGS['showFileSize'] = true;\r
+ $this->SETTINGS['showFileModDate'] = true;\r
+ $this->SETTINGS['showFileType'] = true;\r
+ \r
+ // calculate folder sizes (increases processing time)\r
+ $this->SETTINGS['calcFolderSizes'] = false;\r
+ \r
+ // display MIME type, or "simple" file type \r
+ // (MIME type increases processing time)\r
+ $this->SETTINGS['simpleType'] = true;\r
+ \r
+ // open linked files in new windows \r
+ $this->SETTINGS['linkNewWin'] = false;\r
+ \r
+ // if a folder contains a file listed in this array, \r
+ //it'll automatically use that file instead.\r
+ $this->SETTINGS['folderIndexes'] = array(\r
+ //'index.html',\r
+ //'index.php'\r
+ );\r
+ // sort folders on top of files\r
+ $this->SETTINGS['separateFolders'] = true;\r
+ \r
+ // natural sort files, as opposed to regular sort (files with capital\r
+ // letters get sorted first)\r
+ $this->SETTINGS['naturalSort'] = true;\r
+ \r
+ // show hidden files (files with a dot as the first char)\r
+ $this->SETTINGS['showHiddenFiles'] = false;\r
+ \r
+ // date format. see the url \r
+ // http://us3.php.net/manual/en/function.date.php\r
+ // for more information\r
+ $this->SETTINGS['dateFormat'] = 'F d, Y g:i A';\r
+ \r
+ \r
+ $this->root = $root;\r
+ \r
+ // get path if browsing a tree\r
+ $this->path = ( $this->SETTINGS['browse'] && isset($_GET['p']) ) ? $_GET['p']: "";\r
+\r
+ // get sorting vars from URL, if nothing is set, sort by N [file Name]\r
+ // I'm doing this apache 1.2 style. Add whatever sort mode you need if you add more columnes,\r
+ $this->SETTINGS['sortMode'] = (isset($_GET['N']) ? 'N' : // sort by name \r
+ (isset($_GET['S']) ? 'S' : // sort by size \r
+ (isset($_GET['T']) ? 'T' : // sort by file type\r
+ (isset($_GET['M']) ? 'M' : 'N' )))); // sort by modify time\r
+ \r
+ // get sortascending or descending \r
+ $this->SETTINGS['sortOrder'] = \r
+ isset($_GET[$this->SETTINGS['sortMode']]) ? \r
+ $_GET[$this->SETTINGS['sortMode']] : 'A'; \r
+\r
+ \r
+ // create array of files in tree\r
+ $this->files = $this->makeFileArray($this->root, $this->path);\r
+\r
+ \r
+ // use index file if contains\r
+ if(isset($this->customIndex)){\r
+ $newindex = 'http://'.$_SERVER['HTTP_HOST'].'/'.substr($this->customIndex, '2');\r
+ header("Location: $newindex");\r
+ } \r
+ \r
+ \r
+ // get size of arrays before sort\r
+ //$this->totalFolders = sizeof($files['folders']);\r
+ //$this->totalFiles = sizeof($files['files']);\r
+ \r
+ // sort files\r
+ $this->files = $this->sortFiles($this->files); \r
+\r
+ }\r
+ \r
+ /*\r
+ * list directory\r
+ *\r
+ * list the directory in html\r
+ *\r
+ * @param $root : the root of the folder to navigate\r
+ *\r
+ */\r
+ function listDir() {\r
+\r
+ // container div\r
+ echo '<div id="'.$this->SETTINGS['id'].'">';\r
+ \r
+ // header\r
+ echo $this->SETTINGS['header'] ? $this->headerInfo($this->root, $this->path, $totalFolders, $totalFiles) : ''; \r
+ \r
+ // upload form \r
+ echo $this->SETTINGS['upload'] ? \r
+ $this->uploadForm($this->SETTINGS['uploaddir']) : ''; \r
+ \r
+ // the file list table\r
+ $this->fileList($this->$root, $this->$path, $this->$files); \r
+ \r
+ // end of container div\r
+ echo '</div>'; \r
+ }\r
+\r
+ function listDirMinim()\r
+ {\r
+ echo '<div id="browser">';\r
+ $this->fileListMinim($this->root, $this->path, $this->files);\r
+ echo '<div>';\r
+ }\r
+\r
+ \r
+ \r
+ /* \r
+ * upload form \r
+ * @param path : the path to the form \r
+ */\r
+ function uploadForm($path) {\r
+ $server = 'http://media.quilime.com/upload/?config='.$this->SETTINGS['dlconfig'];\r
+ $uload = '<div id="uploadform">';\r
+ $uload .= '<form><input type="button" value="Upload Files" onClick="window.location=\''.$server.'\'"> </form>';\r
+ $uload .= '</div>';\r
+ return $uload;\r
+ } \r
+ \r
+ /* Create array out of files\r
+ *\r
+ * @param string $root : path root \r
+ * @param string $path : folder to list\r
+ * @return string array : Array of files and folders inside the current \r
+ */\r
+ function makeFileArray($root, $path) {\r
+\r
+ if (!function_exists('mime_content_type')) {\r
+ /* MIME Content Type\r
+ *\r
+ * @param string $file : the extension\r
+ * @return string : the files mime type\r
+ * @note : alternate function written for UNIX \r
+ * environments when PHP function may \r
+ * not be available.\r
+ */\r
+ function mime_content_type($file) { \r
+ $file = escapeshellarg($file);\r
+ $type = `file -bi $file`;\r
+ $expl = explode(";", $type); \r
+ return $expl[0];\r
+ }\r
+ }\r
+ \r
+ \r
+ // if the path is legit\r
+ if ($this->verifyPath($path)) {\r
+ \r
+ $path = $root.$path;\r
+ $fileArray = array();\r
+ $folderArray = array();\r
+ \r
+ if ($handle = opendir($path)) {\r
+ \r
+ \r
+ \r
+ while (false !== ($file = readdir($handle))) {\r
+ if ($file != '.' && $file != '..') {\r
+ \r
+ // show/hide hidden files\r
+ if (!$this->SETTINGS['showHiddenFiles'] && substr($file,0,1) == '.') {\r
+ continue; \r
+ }\r
+ \r
+ // is a folder\r
+ if(is_dir($path.$file)) { \r
+ \r
+ // store elements of the folder\r
+ $folderInfo = array();\r
+ \r
+ $folderInfo['name'] = $file;\r
+ $folderInfo['mtime'] = filemtime($path.$file);\r
+ $folderInfo['type'] = 'Folder';\r
+ $folderInfo['size'] = $this->SETTINGS['calcFolderSizes'] ? $this->folderSize($path.$file) : '-'; \r
+ $folderInfo['rowType'] = 'fr';\r
+ $this->totalFolders++;\r
+ $folderArray[] = $folderInfo;\r
+ } \r
+ // is a file\r
+ else { \r
+ \r
+ // if it's the index, skip\r
+ if($path.$file == $root.$this->SETTINGS['filename'] || $path.$file == $root.$this->SETTINGS['filename'].'~'){\r
+ continue;\r
+ }\r
+ \r
+ // if this file is in the index array, flag it\r
+ if(in_array($file, $this->SETTINGS['folderIndexes'])){\r
+ $this->customIndex = $path.$file;\r
+ }\r
+ \r
+ // store elements of the file\r
+ $fileInfo = array();\r
+ \r
+ $fileInfo['name'] = $file;\r
+ $fileInfo['mtime'] = filemtime($path.$file);\r
+ $fileInfo['type'] = $this->SETTINGS['simpleType'] ? $this->getExtension($path.$file) : mime_content_type($path.$file);\r
+ $fileInfo['size'] = filesize($path.$file);\r
+ $fileInfo['rowType'] = 'fl';\r
+ $fileArray[] = $fileInfo;\r
+ $this->totalFiles++;\r
+ }\r
+ }\r
+ }\r
+ closedir($handle); \r
+ } \r
+ \r
+ // everything gets returned\r
+ $dirArray = array('folders'=> $folderArray, 'files'=> $fileArray); \r
+ return $dirArray;\r
+ } \r
+ else {\r
+ echo 'Not a valid directory!';\r
+ return false;\r
+ exit; \r
+ }\r
+ } \r
+ \r
+ /* check path for sneakiness , such as (../)'s\r
+ *\r
+ * @param string $path : The path to parse\r
+ * @return bool \r
+ */\r
+ function verifyPath($path) {\r
+ if (preg_match("/\.\.\//", $path)) return false;\r
+ else return true;\r
+ }\r
+ \r
+ /* Get the file extension from a filename\r
+ *\r
+ * @param string $filename : filename from which to get extension\r
+ * @return string : the extension\r
+ */\r
+ function getExtension($filename) {\r
+ $justfile = explode("/", $filename);\r
+ $justfile = $justfile[(sizeof($justfile)-1)];\r
+ $expl = explode(".", $justfile);\r
+ if(sizeof($expl)>1 && $expl[sizeof($expl)-1]) {\r
+ return $expl[sizeof($expl)-1]; \r
+ }\r
+ else {\r
+ return '?';\r
+ }\r
+ }\r
+ \r
+ /* Get the parent directory of a path\r
+ *\r
+ * @param string $path : the working dir\r
+ * @return string : the parent directory of the path\r
+ */\r
+ function parentDir($path) {\r
+ $expl = explode("/", substr($path, 0, -1));\r
+ return substr($path, 0, -strlen($expl[(sizeof($expl)-1)].'/')); \r
+ }\r
+ \r
+ /* Format Byte to Human-Readable Format\r
+ *\r
+ * @param int $bytes : the byte size\r
+ * @return string : the ledgable result\r
+ */\r
+ function formatSize($bytes) {\r
+\r
+ if(is_integer($bytes) && $bytes > 0) {\r
+ $formats = array("%d bytes", "%.1f kb", "%.1f mb", "%.1f gb", "%.1f tb");\r
+ $logsize = min( (int)(log($bytes) / log(1024)), count($formats)-1);\r
+ return sprintf($formats[$logsize], $bytes/pow(1024, $logsize));\r
+ }\r
+\r
+ // it's a folder without calculating size\r
+ else if(!is_integer($bytes) && $bytes == '-') {\r
+ return '-';\r
+ }\r
+ else {\r
+ return '0 bytes';\r
+ }\r
+ }\r
+ \r
+ /* Calculate the size of a folder recursivly\r
+ *\r
+ * @param string $bytes : the byte size\r
+ * @return string : the ledgable result\r
+ */ \r
+ function folderSize($path) {\r
+ $size = 0;\r
+ if ($handle = opendir($path)) {\r
+ while (($file = readdir($handle)) !== false) {\r
+ if ($file != '.' && $file != '..') {\r
+ if(is_dir($path.'/'.$file)) {\r
+ $size += $this->folderSize($path.'/'.$file);\r
+ } \r
+ else {\r
+ $size += filesize($path.'/'.$file);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ return $size;\r
+ }\r
+ \r
+ /* Header Info for current path\r
+ *\r
+ * @param string $root : root directory\r
+ * @param string $path : working directory\r
+ * @param int $totalFolders : total folders in working dir\r
+ * @param int $totalFiles : total files in working dir\r
+ * @return string : HTML header <div> \r
+ */ \r
+ function headerInfo($root, $path, $totalFolders, $totalFiles) {\r
+ $slash = ' / ';\r
+ $header = '<div class="header">\r
+ <div class="breadcrumbs">\r
+ <a href="'.$_SERVER['PHP_SELF'].'">'.$this->SETTINGS['title'].'</a>';\r
+ \r
+ // explode path into links\r
+ $pathParts = explode("/", $path); \r
+ \r
+ // path counter\r
+ $pathCT = 0; \r
+ \r
+ // path parts for breadcrumbs\r
+ foreach($pathParts as $pt) {\r
+ $header .= $slash; \r
+ $header .= '<a href="?p=';\r
+ for($i=0;$i<=$pathCT;$i++) {\r
+ $header .= $pathParts[$i].'/'; \r
+ }\r
+ $header .= '">'.$pt.'</a>'; \r
+ $pathCT++;\r
+ }\r
+ \r
+ $header .= '</div><div>';\r
+ \r
+ $header .= $this->totalFolders.' Folders';\r
+ $header .= ', ';\r
+ $header .= $this->totalFiles .' Files';\r
+ $header .= '</div></div>'."\n";\r
+ \r
+ return $header;\r
+ }\r
+ \r
+\r
+\r
+ function headerInfom($root, $path, $totalFolders, $totalFiles) {\r
+ $slash = ' / ';\r
+ $header = '<div class="header">\r
+ <div class="breadcrumbs">\r
+ <a href="'.$_SERVER['PHP_SELF'].'">'.$this->SETTINGS['title'].'</a>';\r
+ \r
+ // explode path into links\r
+ $pathParts = explode("/", $path); \r
+ \r
+ // path counter\r
+ $pathCT = 0; \r
+ \r
+ // path parts for breadcrumbs\r
+ foreach($pathParts as $pt) {\r
+ $header .= $slash; \r
+ $header .= '<a href="?p=';\r
+ for($i=0;$i<=$pathCT;$i++) {\r
+ $header .= $pathParts[$i].'/'; \r
+ }\r
+ $header .= '">'.$pt.'</a>'; \r
+ $pathCT++;\r
+ }\r
+ \r
+ $header .= '</div><div>';\r
+ \r
+ \r
+ return $header;\r
+ }\r
+ \r
+\r
+ \r
+ /* Sort files\r
+ *\r
+ * @param string array $files : files/folders in the current tree\r
+ * @param string $sortMode : the current sorted column\r
+ * @param string $sortOrder : the current sort order. 'A' of 'D'\r
+ * @return string : the resulting sort\r
+ */\r
+ function sortFiles($files) { \r
+ \r
+ // sort folders on top\r
+ if($this->SETTINGS['separateFolders']) {\r
+ \r
+ $sortedFolders = $this->orderByColumn($files['folders'], '2'); \r
+ $sortedFiles = $this->orderByColumn($files['files'], '1');\r
+ \r
+ // sort files depending on sort order\r
+ if($this->SETTINGS['sortOrder'] == 'A') {\r
+ ksort($sortedFolders);\r
+ ksort($sortedFiles);\r
+ $result = array_merge($sortedFolders, $sortedFiles);\r
+ }\r
+ else {\r
+ krsort($sortedFolders);\r
+ krsort($sortedFiles);\r
+ $result = array_merge($sortedFiles, $sortedFolders);\r
+ }\r
+ }\r
+ \r
+ // sort folders and files together\r
+ else {\r
+ \r
+ $files = array_merge($files['folders'], $files['files']);\r
+ $result = $this->orderByColumn($files,'1');\r
+ \r
+ // sort files depending on sort order\r
+ $this->SETTINGS['sortOrder'] == 'A' ? ksort($result):krsort($result);\r
+ }\r
+ return $result;\r
+ }\r
+ \r
+ /* Order By Column\r
+ * \r
+ * @param string array $input : the array to sort\r
+ * @param string $type : the type of array. 1 = files, 2 = folders\r
+ */\r
+ function orderByColumn($input, $type) {\r
+ \r
+ $column = $this->SETTINGS['sortMode'];\r
+ \r
+ $result = array();\r
+ \r
+ // available sort columns\r
+ $columnList = array('N'=>'name', \r
+ 'S'=>'size', \r
+ 'T'=>'type', \r
+ 'M'=>'mtime');\r
+ \r
+ // row count \r
+ // each array key gets $rowcount and $type \r
+ // concatinated to account for duplicate array keys\r
+ $rowcount = 0;\r
+ \r
+ // create new array with sort mode as the key\r
+ foreach($input as $key=>$value) {\r
+ // natural sort - make array keys lowercase\r
+ if($this->SETTINGS['naturalSort']) {\r
+ $col = $value[$columnList[$column]];\r
+ $res = strtolower($col).'.'.$rowcount.$type;\r
+ $result[$res] = $value;\r
+ }\r
+ // regular sort - uppercase values get sorted on top\r
+ else {\r
+ $res = $value[$columnList[$column]].'.'.$rowcount.$type;\r
+ $result[$res] = $value;\r
+ }\r
+ $rowcount++;\r
+ }\r
+ return $result;\r
+ }\r
+ \r
+ \r
+ /* List Files\r
+ *\r
+ * @param string $path : working dir\r
+ * @param string $files : the files contined therin\r
+ * @param mixed array $options : user options\r
+ * @return none\r
+ */\r
+ function fileList() {\r
+ \r
+ // remove the './' from the path\r
+ $root = substr($this->root, '2');\r
+ \r
+ // start of HTML file table \r
+ echo '<table class="filelist" cellspacing="0" border="0">';\r
+ \r
+ // sorting row\r
+ echo $this->SETTINGS['sort'] ? $this->row('sort', null, $this->path) : '';\r
+ \r
+ // parent directory row (if inside a path)\r
+ echo $this->path ? $this->row('parent', null, $this->path) : '';\r
+ \r
+ // total number of files\r
+ $rowcount = 1; \r
+ \r
+ // total byte size of the current tree\r
+ $totalsize = 0; \r
+ \r
+ // rows of files\r
+ foreach($this->files as $file) {\r
+ echo $this->row($file['rowType'], $this->root, $this->path, $rowcount, $file);\r
+ $rowcount++; \r
+ $totalsize += $file['size'];\r
+ }\r
+ \r
+ $this->SETTINGS['totalSize'] = $this->formatSize($totalsize);\r
+ \r
+ // footer row\r
+ echo $this->SETTINGS['footer'] ? $this->row('footer') : '';\r
+ \r
+ // end of table\r
+ echo '</table>';\r
+ }\r
+ \r
+\r
+\r
+ function fileListMinim() {\r
+ \r
+ // remove the './' from the path\r
+ $root = substr($this->root, '2');\r
+ \r
+ // sorting row\r
+ // echo $this->SETTINGS['sort'] ? $this->rowm('sort', null, $this->path) : '';\r
+ \r
+ echo $this->headerInfom($this->root, $this->path, $totalFolders, $totalFiles); \r
+\r
+ // parent directory row (if inside a path)\r
+ echo $this->path ? $this->rowm('parent', null, $this->path) : '<p> </p>';\r
+\r
+ \r
+ // total number of files\r
+ $rowcount = 1; \r
+ \r
+ // total byte size of the current tree\r
+ $totalsize = 0; \r
+ \r
+ // rows of files\r
+ foreach($this->files as $file) {\r
+ echo $this->rowm($file['rowType'], $this->root, $this->path, $rowcount, $file);\r
+ $rowcount++; \r
+ $totalsize += $file['size'];\r
+ }\r
+ \r
+ }\r
+\r
+\r
+ function rowm($type, $root=null, $path=null, $rowcount=null, $file=null) {\r
+ // alternating row styles\r
+ $rnum = $rowcount ? ($rowcount%2 == 0 ? ' r2' : ' r1') : null;\r
+ \r
+ // start row string variable to be returned\r
+ $row = "\n"; \r
+ \r
+ switch($type) {\r
+ \r
+ // file / folder row\r
+ case 'fl' : \r
+ case 'fr' : \r
+ \r
+ // filename\r
+ $row .= '<li>';\r
+ $row .= '<a class="'.$type.'" ';\r
+ $row .= 'title="'.$this->formatSize($file['size']).' '.date($this->SETTINGS['dateFormat'], $file['mtime']).'"';\r
+ $row .= $this->SETTINGS['linkNewWin'] && $type== 'fl' ? 'target="_blank" ' : ''; \r
+ $row .= 'href="';\r
+ $row .= $this->SETTINGS['browse'] && $type == 'fr' ? '?p='.$path.$file['name'].'/' : $root.$path.$file['name'];\r
+ $row .= '" ';\r
+ $row .= '>';\r
+ $row .= $type == 'fl' ? $file['name'] : $file['name'].'/';\r
+$row .= '</li>';\r
+ \r
+ break;\r
+ \r
+ // sorting header \r
+ case 'sort' :\r
+ \r
+ // sort order. Setting ascending or descending for sorting links\r
+ $N = ($this->SETTINGS['sortMode'] == 'N') ? ($this->SETTINGS['sortOrder'] == 'A' ? 'D' : 'A') : 'A';\r
+ $S = ($this->SETTINGS['sortMode'] == 'S') ? ($this->SETTINGS['sortOrder'] == 'A' ? 'D' : 'A') : 'A';\r
+ $T = ($this->SETTINGS['sortMode'] == 'T') ? ($this->SETTINGS['sortOrder'] == 'A' ? 'D' : 'A') : 'A';\r
+ $M = ($this->SETTINGS['sortMode'] == 'M') ? ($this->SETTINGS['sortOrder'] == 'A' ? 'D' : 'A') : 'A';\r
+\r
+ $row .= $this->SETTINGS['lineNumbers'] ? '<td class="ln"> </td>' : ''; \r
+\r
+ $row .= '<td><a href="?N='.$N.'&p='.$path.'">Name</a></td>';\r
+\r
+ $row .= $this->SETTINGS['showFileSize'] ?'<td class="sz"><a href="?S='.$S.'&p='.$path.'">Size</a></td>' : '';\r
+ $row .= $this->SETTINGS['showFileType'] ? '<td class="tp"><a href="?T='.$T.'&p='.$path.'">Type</a></td>' : '';\r
+ $row .= $this->SETTINGS['showFileModDate'] ? '<td class="dt"><a href="?M='.$M.'&p='.$path.'">Last Modified</a></td>' : '';\r
+ break;\r
+ \r
+ // parent directory row \r
+ case 'parent' : \r
+\r
+ $row = '<p><a href="?p='.$this->parentDir($path).'">↑</a></p>';\r
+\r
+ break;\r
+ \r
+ // footer row\r
+ case 'footer' : \r
+ $row .= $this->SETTINGS['lineNumbers'] ? '<td class="ln"> </td>' : '';\r
+ $row .= '<td class="nm"> </td>';\r
+ $row .= $this->SETTINGS['showFileSize'] ? '<td class="sz">'.$this->SETTINGS['totalSize'].'</td>' : '';\r
+ $row .= $this->SETTINGS['showFileType'] ? '<td class="tp"> </td>' : '';\r
+ $row .= $this->SETTINGS['showFileModDate'] ? '<td class="dt"> </td>' : '';\r
+ break;\r
+ }\r
+ \r
+ $row .= '</tr>';\r
+ return $row;\r
+ } \r
+\r
+ \r
+\r
+ /* file / folder row\r
+ *\r
+ * @param string $type : either 'fr' or 'fl', representing a file row\r
+ * or a folder row.\r
+ * @param string $path : working path\r
+ * @param int $rowcount : current count of the row for line numbering\r
+ * @param string $file : the file to be rendered on the row\r
+ * @return string : HTML table row\r
+ *\r
+ * notes: still need to edit code to wrap to 73 chars, hard to read at\r
+ * the moment.\r
+ *\r
+ *\r
+ *\r
+ */ \r
+ function row($type, $root=null, $path=null, $rowcount=null, $file=null) {\r
+ // alternating row styles\r
+ $rnum = $rowcount ? ($rowcount%2 == 0 ? ' r2' : ' r1') : null;\r
+ \r
+ // start row string variable to be returned\r
+ $row = "\n".'<tr class="'.$type.$rnum.'">'."\n"; \r
+ \r
+ switch($type) {\r
+ \r
+ // file / folder row\r
+ case 'fl' : \r
+ case 'fr' : \r
+ \r
+ // line number\r
+ $row .= $this->SETTINGS['lineNumbers'] ? '<td class="ln">'.$rowcount.'</td>' : '';\r
+ \r
+ // filename\r
+ $row .= '<td class="nm">';\r
+ $row .= '<a ';\r
+ $row .= $this->SETTINGS['linkNewWin'] && $type== 'fl' ? 'target="_blank" ' : ''; \r
+ $row .= 'href="';\r
+ $row .= $this->SETTINGS['browse'] && $type == 'fr' ? '?p='.$path.$file['name'].'/' : $root.$path.$file['name'];\r
+ $row .= '" ';\r
+ $row .= '>';\r
+ $row .= $file['name'].'</a></td>';\r
+ \r
+ // file size\r
+ $row .= $this->SETTINGS['showFileSize'] ? '<td class="sz">'.$this->formatSize($file['size']).'</td>' : '';\r
+ \r
+ // file type\r
+ $row .= $this->SETTINGS['showFileType'] ? '<td class="tp">'.$file['type'].'</td>' : ''; \r
+ \r
+ // date\r
+ $row .= $this->SETTINGS['showFileModDate'] ? '<td class="dt">'.date($this->SETTINGS['dateFormat'], $file['mtime']).'</td>' : '';\r
+ \r
+ break;\r
+ \r
+ // sorting header \r
+ case 'sort' :\r
+ \r
+ // sort order. Setting ascending or descending for sorting links\r
+ $N = ($this->SETTINGS['sortMode'] == 'N') ? ($this->SETTINGS['sortOrder'] == 'A' ? 'D' : 'A') : 'A';\r
+ $S = ($this->SETTINGS['sortMode'] == 'S') ? ($this->SETTINGS['sortOrder'] == 'A' ? 'D' : 'A') : 'A';\r
+ $T = ($this->SETTINGS['sortMode'] == 'T') ? ($this->SETTINGS['sortOrder'] == 'A' ? 'D' : 'A') : 'A';\r
+ $M = ($this->SETTINGS['sortMode'] == 'M') ? ($this->SETTINGS['sortOrder'] == 'A' ? 'D' : 'A') : 'A';\r
+\r
+ $row .= $this->SETTINGS['lineNumbers'] ? '<td class="ln"> </td>' : ''; \r
+\r
+ $row .= '<td><a href="?N='.$N.'&p='.$path.'">Name</a></td>';\r
+\r
+ $row .= $this->SETTINGS['showFileSize'] ?'<td class="sz"><a href="?S='.$S.'&p='.$path.'">Size</a></td>' : '';\r
+ $row .= $this->SETTINGS['showFileType'] ? '<td class="tp"><a href="?T='.$T.'&p='.$path.'">Type</a></td>' : '';\r
+ $row .= $this->SETTINGS['showFileModDate'] ? '<td class="dt"><a href="?M='.$M.'&p='.$path.'">Last Modified</a></td>' : '';\r
+ break;\r
+ \r
+ // parent directory row \r
+ case 'parent' : \r
+ $row .= $this->SETTINGS['lineNumbers'] ? '<td class="ln">↑</td>' : '';\r
+ $row .= '<td class="nm"><a href="?p='.$this->parentDir($path).'">';\r
+ $row .= 'Parent Directory';\r
+ $row .= '</a></td>';\r
+ $row .= $this->SETTINGS['showFileSize'] ? '<td class="sz"> </td>' : '';\r
+ $row .= $this->SETTINGS['showFileType'] ? '<td class="tp"> </td>' : '';\r
+ $row .= $this->SETTINGS['showFileModDate'] ? '<td class="dt"> </td>' : '';\r
+ break;\r
+ \r
+ // footer row\r
+ case 'footer' : \r
+ $row .= $this->SETTINGS['lineNumbers'] ? '<td class="ln"> </td>' : '';\r
+ $row .= '<td class="nm"> </td>';\r
+ $row .= $this->SETTINGS['showFileSize'] ? '<td class="sz">'.$this->SETTINGS['totalSize'].'</td>' : '';\r
+ $row .= $this->SETTINGS['showFileType'] ? '<td class="tp"> </td>' : '';\r
+ $row .= $this->SETTINGS['showFileModDate'] ? '<td class="dt"> </td>' : '';\r
+ break;\r
+ }\r
+ \r
+ $row .= '</tr>';\r
+ return $row;\r
+ } \r
+\r
+\r
+\r
+\r
+ /*\r
+ * javascript\r
+ *\r
+ *\r
+ */\r
+ function js(){\r
+/* \r
+?>\r
+ <script>\r
+ \r
+ // Link Tracker referenced from GLEN JONES\r
+ // For details: http://www.glennjones.net/\r
+\r
+ window.onload = function() {\r
+ initLinkTracks.initList();\r
+ };\r
+\r
+ var LinkTracker = {\r
+\r
+ initLinkTracks : function(){\r
+ if (!document.getElementsByTagName) return false;\r
+ links = document.getElementsByTagName('a')\r
+ for (var i = 0; i < links.length; i++) {\r
+ addEvent(links[i], 'mousedown', recordClick, false);\r
+ // If a link does not have any id it is given one\r
+ if (! links[i].getAttribute('id') )\r
+ links[i].setAttribute('id',"link_" + i)\r
+ }\r
+ }\r
+\r
+ recordClick : function() {\r
+ alert("test");\r
+ }\r
+\r
+ }\r
+ \r
+ \r
+ </script> \r
+ <? */\r
+ }\r
+}\r
+\r
+// redirect if uploaded\r
+if(isset($_GET['tmp_sid'])){\r
+ $dir = explode("/",$_SERVER['PHP_SELF']);\r
+ $server = "http://media.quilime.com/".$dir[1]."/?p=uploads/";\r
+ header("Location: ".$server);\r
+}\r
+\r
+?>
\ No newline at end of file
--- /dev/null
+<?
+
+/*
+
+// quick file uploading
+
+// HTML
+<form enctype="multipart/form-data" action="upload.php" method="POST">
+ <input type="hidden" name="MAX_FILE_SIZE" value="512000" />
+ Send this file: <input name="userfile" type="file" />
+ <input type="submit" value="Send File" />
+</form>
+
+// PHP
+$uploaddir = '/var/www/uploads/';
+$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
+
+echo "<p>";
+
+if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
+ echo "File is valid, and was successfully uploaded.\n";
+} else {
+ echo "Upload failed";
+}
+
+echo "</p>";
+echo '<pre>';
+echo 'Here is some more debugging info:';
+print_r($_FILES);
+print "</pre>";
+
+*/
+
+?>
--- /dev/null
+<?php
+
+ include_once 'class.get.image.php';
+
+ $image = new GetImage;
+
+ if (isset($_GET['i']))
+ {
+ $image->source = $_GET['i'];
+ $image->save_to = '../agg/';
+ $get = $image->download('curl');
+ $i = basename($image->source);
+ if($get) {
+
+ ?>
+
+
+ <img src="../agg/<? echo $i ?>" /> <br/>
+ <a href="http://media.quilime.com/aggregate/?l=<? echo $i ?>"><? echo $i ?></a><br/>
+
+ <form class="ed" name="ed_<? echo $i ?>" id="ed_<? echo $i ?>">
+ <input type="hidden" name="img" value="<? echo $i ?>">
+ <label>link</label><input type="text" name="link" /><br/>
+ <label>title</label><input type="text" name="title"/><br/>
+ <label>tags</label><input type="text" name="tags"/><br/>
+ <label>desc</label><input type="text" name="desc" /><br/>
+ <input type="button" value="post" onClick="sub();">
+ </form>
+
+ <a href="http://twitter.com/share" class="twitter-share-button" data-count="none">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
+
+ <script>
+
+ function sub()
+ {
+ var img = document.forms[0].img.value;
+ var link = document.forms[0].link.value;
+ var tags = document.forms[0].tags.value;
+ var title = document.forms[0].title.value;
+ var desc = document.forms[0].desc.value;
+ doURL( '../index.php?return=js&tags=' + tags + '&img=' + escape(img) + '&link=' + escape(link) + '&title=' + escape(title) + '&desc=' + escape(desc) );
+ }
+
+
+ function doURL(url) {
+ var jsel = document.createElement('script');
+ jsel.type = 'text/javascript';
+ jsel.src = url;
+ document.body.appendChild (jsel);
+ }
+
+ </script>
+
+ <?
+
+ exit;
+ }
+ }
+