From cf589a1786688add293148e4b040601fbed0569e Mon Sep 17 00:00:00 2001 From: Gabriel Dunne Date: Sat, 23 Feb 2019 18:36:51 -0800 Subject: [PATCH] adding files --- i/js/Array.js | 187 +++++++++ i/js/function.js | 94 +++++ i/php/file_browser.php | 296 +++++++++++++ i/php/function.array.php | 19 + i/php/function.browser.php | 5 + i/php/function.file.php | 50 +++ i/php/function.filelist.php | 207 +++++++++ i/php/function.php | 11 + i/php/function.session.php | 11 + i/php/function.unicode.php | 90 ++++ i/php/function.util.php | 12 + i/php/inc.browser.php | 817 ++++++++++++++++++++++++++++++++++++ i/php/snippets.php | 34 ++ post/tumblr.php | 59 +++ 14 files changed, 1892 insertions(+) create mode 100644 i/js/Array.js create mode 100644 i/js/function.js create mode 100644 i/php/file_browser.php create mode 100644 i/php/function.array.php create mode 100644 i/php/function.browser.php create mode 100644 i/php/function.file.php create mode 100644 i/php/function.filelist.php create mode 100644 i/php/function.php create mode 100644 i/php/function.session.php create mode 100644 i/php/function.unicode.php create mode 100644 i/php/function.util.php create mode 100644 i/php/inc.browser.php create mode 100644 i/php/snippets.php create mode 100644 post/tumblr.php diff --git a/i/js/Array.js b/i/js/Array.js new file mode 100644 index 0000000..bb36375 --- /dev/null +++ b/i/js/Array.js @@ -0,0 +1,187 @@ +// 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=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= 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 + + + + + + + <?php echo $settings['title']; ?> <?php echo $p == "" ? "" : " : " . $p; ?> + + + + + + + + + +

+ + : + +

+ +
    + + + + + + +
  1. + +
  2. + + + + + +
  3. + error: not found +
  4. + + +
+ + + + + + $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 .= ''.$pt.''; + if($pathCT < sizeof($pathParts)-2) + $br .= $sep; + $pathCT++; + } + return $br; +} + +?> diff --git a/i/php/function.array.php b/i/php/function.array.php new file mode 100644 index 0000000..9a611f8 --- /dev/null +++ b/i/php/function.array.php @@ -0,0 +1,19 @@ + diff --git a/i/php/function.browser.php b/i/php/function.browser.php new file mode 100644 index 0000000..80387cf --- /dev/null +++ b/i/php/function.browser.php @@ -0,0 +1,5 @@ + diff --git a/i/php/function.file.php b/i/php/function.file.php new file mode 100644 index 0000000..24c96c8 --- /dev/null +++ b/i/php/function.file.php @@ -0,0 +1,50 @@ + 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]; +} + + + + +?> diff --git a/i/php/function.filelist.php b/i/php/function.filelist.php new file mode 100644 index 0000000..545b6ae --- /dev/null +++ b/i/php/function.filelist.php @@ -0,0 +1,207 @@ +" $1 "" }'`; + return $output; +} + + +function fileList($directory, $recursive) +{ + $array_items = array(); + if ($handle = opendir($directory)) { + while (false !== ($file = readdir($handle))) { + if ($file != "." && $file != "..") { + if (is_dir($directory. "/" . $file)) { + if($recursive) { + $array_items = array_merge($array_items, directoryToArray($directory. "/" . $file, $recursive)); + } + $file = $directory . "/" . $file; + $array_items[] = preg_replace("/\/\//si", "/", $file); + } else { + $file = $directory . "/" . $file; + $array_items[] = preg_replace("/\/\//si", "/", $file); + } + } + } + closedir($handle); + } + return $array_items; +} + + +function fileArray( + $p, + $extensions = Array(), + $excludes = Array('.', '..'), + $www_root = "http://", + $skipHidden = true) +{ + // root urls + $AR = $p; + $WWW = $www_root; + + $result = Array(); + $parsedResult = Array(); + + if ($handle = opendir($p)) { + while (false !== ($file = readdir($handle))) { + if (!in_array($file, $excludes)) { + + if($skipHidden) { + 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, + 'localroot' => $p.$file."/", + 'url' => str_replace($AR, $WWW, $p.$file) + ); + + 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 = fileExtension($p.$file), + 'size' => filesize($p.$file), + 'localroot' => $p.$file, + 'url' => str_replace($AR, $WWW, $p.$file) + ); + if(in_array($type, $extensions)) { + $parsedResult[] = $fileInfo; + continue; + } + $result[] = $fileInfo; + } + } + } + } + + if(sizeof($extensions) > 0) + return sortFiles($parsedResult, 'A', 'N'); + else + return sortFiles($result, 'A', 'N'); +} + + +// sort file list from fileArray() +function sortFiles($files, $mode, $col) +{ + $sortedFiles = orderByColumn($files, $col); + $sortOrder = $mode; + if($sortOrder == 'A') { + ksort($sortedFiles); + $result = $sortedFiles; + } + else { + krsort($sortedFiles); + $result = $sortedFiles; + } + $r = Array(); + foreach($result as $res) + $r[] = $res; + + return $r; +} + + + +// (N = name, S = size, T = type, M = mtime +function orderByColumn($input, $type) +{ + $column = $type; + $result = Array(); + $columnList = Array( + 'N'=>'name', + 'S'=>'size', + 'T'=>'type', + 'M'=>'mtime' + ); + $rowcount = 0; + + foreach($input as $key=>$value) { + $naturalSort = true; + // natural sort - make array keys lowercase + if($naturalSort) { + $col = $value[$columnList[$column]]; + $res = strtolower($col).'.'.$rowcount.$type; + $result[$res] = $value; + } + // regular sort - uppercase values get sorted on top + else { + $res = $value[$columnList[$column]].'.'.$rowcount.$type; + $result[$res] = $value; + } + $rowcount++; + } + return $result; +} + + + +function dirTree($dir) +{ + $tree = array(); + $dirs = array(array($dir, &$tree)); + for($i = 0; $i < count($dirs); ++$i) { + $d = opendir($dirs[$i][0]); + $tier =& $dirs[$i][1]; + while($file = readdir($d)) { + if ($file != '.' and $file != '..') { + $path = $dirs[$i][0] . DIRECTORY_SEPARATOR . $file; + if (is_dir($path)) { + $tier[$file] = array(); + $dirs[] = array($path, &$tier[$file]); + } + else { + $tier[$file] = filesize($path); + } + } + } + } + return $tree; +} + + + +function breadcrumbs($path, $sep = " / ") // return String +{ + $pathParts = explode("/", $path); + + // path counter + $pathCT = 0; + + $br = ""; + // path parts for breadcrumbs + foreach($pathParts as $pt) { + $br .= ''.$pt.''; + if($pathCT < sizeof($pathParts)-2) + $br .= $sep; + $pathCT++; + } + + return $br; +} +?> diff --git a/i/php/function.php b/i/php/function.php new file mode 100644 index 0000000..93f896f --- /dev/null +++ b/i/php/function.php @@ -0,0 +1,11 @@ + diff --git a/i/php/function.session.php b/i/php/function.session.php new file mode 100644 index 0000000..5db0683 --- /dev/null +++ b/i/php/function.session.php @@ -0,0 +1,11 @@ + diff --git a/i/php/function.unicode.php b/i/php/function.unicode.php new file mode 100644 index 0000000..630bb7b --- /dev/null +++ b/i/php/function.unicode.php @@ -0,0 +1,90 @@ + 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; +} + + + +?> diff --git a/i/php/function.util.php b/i/php/function.util.php new file mode 100644 index 0000000..7e9621c --- /dev/null +++ b/i/php/function.util.php @@ -0,0 +1,12 @@ +'; + print_r($array); + echo ''; +} + + +?> diff --git a/i/php/inc.browser.php b/i/php/inc.browser.php new file mode 100644 index 0000000..5bcaded --- /dev/null +++ b/i/php/inc.browser.php @@ -0,0 +1,817 @@ +totalFiles = 0; + $this->totalFolders = 0; + + // allow the users to browse folders + $this->SETTINGS['browse'] = true; + + // the current index file + $this->SETTINGS['filename'] = 'index.php'; + + // track downloads + $this->SETTINGS['trackdls'] = true; + + // enable uploading + $this->SETTINGS['upload'] = false; + $this->SETTINGS['uploaddir'] = 'uploads/'; + + // download config file + $this->SETTINGS['dlconfig'] = ''; + + // title in the HTML header + $this->SETTINGS['title'] = 'bin'; + + // html DOM id + $this->SETTINGS['id'] = 'fileBrowser'; + + // show footer + $this->SETTINGS['footer'] = true; + + // show header + $this->SETTINGS['header'] = true; + + // show sorting header + $this->SETTINGS['sort'] = true; + + // show/hide columns + $this->SETTINGS['lineNumbers'] = true; + $this->SETTINGS['showFileSize'] = true; + $this->SETTINGS['showFileModDate'] = true; + $this->SETTINGS['showFileType'] = true; + + // calculate folder sizes (increases processing time) + $this->SETTINGS['calcFolderSizes'] = false; + + // display MIME type, or "simple" file type + // (MIME type increases processing time) + $this->SETTINGS['simpleType'] = true; + + // open linked files in new windows + $this->SETTINGS['linkNewWin'] = false; + + // if a folder contains a file listed in this array, + //it'll automatically use that file instead. + $this->SETTINGS['folderIndexes'] = array( + //'index.html', + //'index.php' + ); + // sort folders on top of files + $this->SETTINGS['separateFolders'] = true; + + // natural sort files, as opposed to regular sort (files with capital + // letters get sorted first) + $this->SETTINGS['naturalSort'] = true; + + // show hidden files (files with a dot as the first char) + $this->SETTINGS['showHiddenFiles'] = false; + + // date format. see the url + // http://us3.php.net/manual/en/function.date.php + // for more information + $this->SETTINGS['dateFormat'] = 'F d, Y g:i A'; + + + $this->root = $root; + + // get path if browsing a tree + $this->path = ( $this->SETTINGS['browse'] && isset($_GET['p']) ) ? $_GET['p']: ""; + + // get sorting vars from URL, if nothing is set, sort by N [file Name] + // I'm doing this apache 1.2 style. Add whatever sort mode you need if you add more columnes, + $this->SETTINGS['sortMode'] = (isset($_GET['N']) ? 'N' : // sort by name + (isset($_GET['S']) ? 'S' : // sort by size + (isset($_GET['T']) ? 'T' : // sort by file type + (isset($_GET['M']) ? 'M' : 'N' )))); // sort by modify time + + // get sortascending or descending + $this->SETTINGS['sortOrder'] = + isset($_GET[$this->SETTINGS['sortMode']]) ? + $_GET[$this->SETTINGS['sortMode']] : 'A'; + + + // create array of files in tree + $this->files = $this->makeFileArray($this->root, $this->path); + + + // use index file if contains + if(isset($this->customIndex)){ + $newindex = 'http://'.$_SERVER['HTTP_HOST'].'/'.substr($this->customIndex, '2'); + header("Location: $newindex"); + } + + + // get size of arrays before sort + //$this->totalFolders = sizeof($files['folders']); + //$this->totalFiles = sizeof($files['files']); + + // sort files + $this->files = $this->sortFiles($this->files); + + } + + /* + * list directory + * + * list the directory in html + * + * @param $root : the root of the folder to navigate + * + */ + function listDir() { + + // container div + echo '
'; + + // header + echo $this->SETTINGS['header'] ? $this->headerInfo($this->root, $this->path, $totalFolders, $totalFiles) : ''; + + // upload form + echo $this->SETTINGS['upload'] ? + $this->uploadForm($this->SETTINGS['uploaddir']) : ''; + + // the file list table + $this->fileList($this->$root, $this->$path, $this->$files); + + // end of container div + echo '
'; + } + + function listDirMinim() + { + echo '
'; + $this->fileListMinim($this->root, $this->path, $this->files); + echo '
'; + } + + + + /* + * upload form + * @param path : the path to the form + */ + function uploadForm($path) { + $server = 'http://media.quilime.com/upload/?config='.$this->SETTINGS['dlconfig']; + $uload = '
'; + $uload .= '
'; + $uload .= '
'; + return $uload; + } + + /* Create array out of files + * + * @param string $root : path root + * @param string $path : folder to list + * @return string array : Array of files and folders inside the current + */ + function makeFileArray($root, $path) { + + if (!function_exists('mime_content_type')) { + /* MIME Content Type + * + * @param string $file : the extension + * @return string : the files mime type + * @note : alternate function written for UNIX + * environments when PHP function may + * not be available. + */ + function mime_content_type($file) { + $file = escapeshellarg($file); + $type = `file -bi $file`; + $expl = explode(";", $type); + return $expl[0]; + } + } + + + // if the path is legit + if ($this->verifyPath($path)) { + + $path = $root.$path; + $fileArray = array(); + $folderArray = array(); + + if ($handle = opendir($path)) { + + + + while (false !== ($file = readdir($handle))) { + if ($file != '.' && $file != '..') { + + // show/hide hidden files + if (!$this->SETTINGS['showHiddenFiles'] && substr($file,0,1) == '.') { + continue; + } + + // is a folder + if(is_dir($path.$file)) { + + // store elements of the folder + $folderInfo = array(); + + $folderInfo['name'] = $file; + $folderInfo['mtime'] = filemtime($path.$file); + $folderInfo['type'] = 'Folder'; + $folderInfo['size'] = $this->SETTINGS['calcFolderSizes'] ? $this->folderSize($path.$file) : '-'; + $folderInfo['rowType'] = 'fr'; + $this->totalFolders++; + $folderArray[] = $folderInfo; + } + // is a file + else { + + // if it's the index, skip + if($path.$file == $root.$this->SETTINGS['filename'] || $path.$file == $root.$this->SETTINGS['filename'].'~'){ + continue; + } + + // if this file is in the index array, flag it + if(in_array($file, $this->SETTINGS['folderIndexes'])){ + $this->customIndex = $path.$file; + } + + // store elements of the file + $fileInfo = array(); + + $fileInfo['name'] = $file; + $fileInfo['mtime'] = filemtime($path.$file); + $fileInfo['type'] = $this->SETTINGS['simpleType'] ? $this->getExtension($path.$file) : mime_content_type($path.$file); + $fileInfo['size'] = filesize($path.$file); + $fileInfo['rowType'] = 'fl'; + $fileArray[] = $fileInfo; + $this->totalFiles++; + } + } + } + closedir($handle); + } + + // everything gets returned + $dirArray = array('folders'=> $folderArray, 'files'=> $fileArray); + return $dirArray; + } + else { + echo 'Not a valid directory!'; + return false; + exit; + } + } + + /* check path for sneakiness , such as (../)'s + * + * @param string $path : The path to parse + * @return bool + */ + function verifyPath($path) { + if (preg_match("/\.\.\//", $path)) return false; + else return true; + } + + /* Get the file extension from a filename + * + * @param string $filename : filename from which to get extension + * @return string : the extension + */ + function getExtension($filename) { + $justfile = explode("/", $filename); + $justfile = $justfile[(sizeof($justfile)-1)]; + $expl = explode(".", $justfile); + if(sizeof($expl)>1 && $expl[sizeof($expl)-1]) { + return $expl[sizeof($expl)-1]; + } + else { + return '?'; + } + } + + /* Get the parent directory of a path + * + * @param string $path : the working dir + * @return string : the parent directory of the path + */ + function parentDir($path) { + $expl = explode("/", substr($path, 0, -1)); + return substr($path, 0, -strlen($expl[(sizeof($expl)-1)].'/')); + } + + /* Format Byte to Human-Readable Format + * + * @param int $bytes : the byte size + * @return string : the ledgable result + */ + 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'; + } + } + + /* Calculate the size of a folder recursivly + * + * @param string $bytes : the byte size + * @return string : the ledgable result + */ + function folderSize($path) { + $size = 0; + if ($handle = opendir($path)) { + while (($file = readdir($handle)) !== false) { + if ($file != '.' && $file != '..') { + if(is_dir($path.'/'.$file)) { + $size += $this->folderSize($path.'/'.$file); + } + else { + $size += filesize($path.'/'.$file); + } + } + } + } + return $size; + } + + /* Header Info for current path + * + * @param string $root : root directory + * @param string $path : working directory + * @param int $totalFolders : total folders in working dir + * @param int $totalFiles : total files in working dir + * @return string : HTML header
+ */ + function headerInfo($root, $path, $totalFolders, $totalFiles) { + $slash = ' / '; + $header = '
+
'; + + $header .= $this->totalFolders.' Folders'; + $header .= ', '; + $header .= $this->totalFiles .' Files'; + $header .= '
'."\n"; + + return $header; + } + + + + function headerInfom($root, $path, $totalFolders, $totalFiles) { + $slash = ' / '; + $header = '
+
'; + + + return $header; + } + + + + /* Sort files + * + * @param string array $files : files/folders in the current tree + * @param string $sortMode : the current sorted column + * @param string $sortOrder : the current sort order. 'A' of 'D' + * @return string : the resulting sort + */ + function sortFiles($files) { + + // sort folders on top + if($this->SETTINGS['separateFolders']) { + + $sortedFolders = $this->orderByColumn($files['folders'], '2'); + $sortedFiles = $this->orderByColumn($files['files'], '1'); + + // sort files depending on sort order + if($this->SETTINGS['sortOrder'] == 'A') { + ksort($sortedFolders); + ksort($sortedFiles); + $result = array_merge($sortedFolders, $sortedFiles); + } + else { + krsort($sortedFolders); + krsort($sortedFiles); + $result = array_merge($sortedFiles, $sortedFolders); + } + } + + // sort folders and files together + else { + + $files = array_merge($files['folders'], $files['files']); + $result = $this->orderByColumn($files,'1'); + + // sort files depending on sort order + $this->SETTINGS['sortOrder'] == 'A' ? ksort($result):krsort($result); + } + return $result; + } + + /* Order By Column + * + * @param string array $input : the array to sort + * @param string $type : the type of array. 1 = files, 2 = folders + */ + function orderByColumn($input, $type) { + + $column = $this->SETTINGS['sortMode']; + + $result = array(); + + // available sort columns + $columnList = array('N'=>'name', + 'S'=>'size', + 'T'=>'type', + 'M'=>'mtime'); + + // row count + // each array key gets $rowcount and $type + // concatinated to account for duplicate array keys + $rowcount = 0; + + // create new array with sort mode as the key + foreach($input as $key=>$value) { + // natural sort - make array keys lowercase + if($this->SETTINGS['naturalSort']) { + $col = $value[$columnList[$column]]; + $res = strtolower($col).'.'.$rowcount.$type; + $result[$res] = $value; + } + // regular sort - uppercase values get sorted on top + else { + $res = $value[$columnList[$column]].'.'.$rowcount.$type; + $result[$res] = $value; + } + $rowcount++; + } + return $result; + } + + + /* List Files + * + * @param string $path : working dir + * @param string $files : the files contined therin + * @param mixed array $options : user options + * @return none + */ + function fileList() { + + // remove the './' from the path + $root = substr($this->root, '2'); + + // start of HTML file table + echo ''; + + // sorting row + echo $this->SETTINGS['sort'] ? $this->row('sort', null, $this->path) : ''; + + // parent directory row (if inside a path) + echo $this->path ? $this->row('parent', null, $this->path) : ''; + + // total number of files + $rowcount = 1; + + // total byte size of the current tree + $totalsize = 0; + + // rows of files + foreach($this->files as $file) { + echo $this->row($file['rowType'], $this->root, $this->path, $rowcount, $file); + $rowcount++; + $totalsize += $file['size']; + } + + $this->SETTINGS['totalSize'] = $this->formatSize($totalsize); + + // footer row + echo $this->SETTINGS['footer'] ? $this->row('footer') : ''; + + // end of table + echo '
'; + } + + + + function fileListMinim() { + + // remove the './' from the path + $root = substr($this->root, '2'); + + // sorting row + // echo $this->SETTINGS['sort'] ? $this->rowm('sort', null, $this->path) : ''; + + echo $this->headerInfom($this->root, $this->path, $totalFolders, $totalFiles); + + // parent directory row (if inside a path) + echo $this->path ? $this->rowm('parent', null, $this->path) : '

 

'; + + + // total number of files + $rowcount = 1; + + // total byte size of the current tree + $totalsize = 0; + + // rows of files + foreach($this->files as $file) { + echo $this->rowm($file['rowType'], $this->root, $this->path, $rowcount, $file); + $rowcount++; + $totalsize += $file['size']; + } + + } + + + function rowm($type, $root=null, $path=null, $rowcount=null, $file=null) { + // alternating row styles + $rnum = $rowcount ? ($rowcount%2 == 0 ? ' r2' : ' r1') : null; + + // start row string variable to be returned + $row = "\n"; + + switch($type) { + + // file / folder row + case 'fl' : + case 'fr' : + + // filename + $row .= '
  • '; + $row .= 'formatSize($file['size']).' '.date($this->SETTINGS['dateFormat'], $file['mtime']).'"'; + $row .= $this->SETTINGS['linkNewWin'] && $type== 'fl' ? 'target="_blank" ' : ''; + $row .= 'href="'; + $row .= $this->SETTINGS['browse'] && $type == 'fr' ? '?p='.$path.$file['name'].'/' : $root.$path.$file['name']; + $row .= '" '; + $row .= '>'; + $row .= $type == 'fl' ? $file['name'] : $file['name'].'/'; +$row .= '
  • '; + + break; + + // sorting header + case 'sort' : + + // sort order. Setting ascending or descending for sorting links + $N = ($this->SETTINGS['sortMode'] == 'N') ? ($this->SETTINGS['sortOrder'] == 'A' ? 'D' : 'A') : 'A'; + $S = ($this->SETTINGS['sortMode'] == 'S') ? ($this->SETTINGS['sortOrder'] == 'A' ? 'D' : 'A') : 'A'; + $T = ($this->SETTINGS['sortMode'] == 'T') ? ($this->SETTINGS['sortOrder'] == 'A' ? 'D' : 'A') : 'A'; + $M = ($this->SETTINGS['sortMode'] == 'M') ? ($this->SETTINGS['sortOrder'] == 'A' ? 'D' : 'A') : 'A'; + + $row .= $this->SETTINGS['lineNumbers'] ? ' ' : ''; + + $row .= 'Name'; + + $row .= $this->SETTINGS['showFileSize'] ?'Size' : ''; + $row .= $this->SETTINGS['showFileType'] ? 'Type' : ''; + $row .= $this->SETTINGS['showFileModDate'] ? 'Last Modified' : ''; + break; + + // parent directory row + case 'parent' : + + $row = '

    '; + + break; + + // footer row + case 'footer' : + $row .= $this->SETTINGS['lineNumbers'] ? ' ' : ''; + $row .= ' '; + $row .= $this->SETTINGS['showFileSize'] ? ''.$this->SETTINGS['totalSize'].'' : ''; + $row .= $this->SETTINGS['showFileType'] ? ' ' : ''; + $row .= $this->SETTINGS['showFileModDate'] ? ' ' : ''; + break; + } + + $row .= ''; + return $row; + } + + + + /* file / folder row + * + * @param string $type : either 'fr' or 'fl', representing a file row + * or a folder row. + * @param string $path : working path + * @param int $rowcount : current count of the row for line numbering + * @param string $file : the file to be rendered on the row + * @return string : HTML table row + * + * notes: still need to edit code to wrap to 73 chars, hard to read at + * the moment. + * + * + * + */ + function row($type, $root=null, $path=null, $rowcount=null, $file=null) { + // alternating row styles + $rnum = $rowcount ? ($rowcount%2 == 0 ? ' r2' : ' r1') : null; + + // start row string variable to be returned + $row = "\n".''."\n"; + + switch($type) { + + // file / folder row + case 'fl' : + case 'fr' : + + // line number + $row .= $this->SETTINGS['lineNumbers'] ? ''.$rowcount.'' : ''; + + // filename + $row .= ''; + $row .= 'SETTINGS['linkNewWin'] && $type== 'fl' ? 'target="_blank" ' : ''; + $row .= 'href="'; + $row .= $this->SETTINGS['browse'] && $type == 'fr' ? '?p='.$path.$file['name'].'/' : $root.$path.$file['name']; + $row .= '" '; + $row .= '>'; + $row .= $file['name'].''; + + // file size + $row .= $this->SETTINGS['showFileSize'] ? ''.$this->formatSize($file['size']).'' : ''; + + // file type + $row .= $this->SETTINGS['showFileType'] ? ''.$file['type'].'' : ''; + + // date + $row .= $this->SETTINGS['showFileModDate'] ? ''.date($this->SETTINGS['dateFormat'], $file['mtime']).'' : ''; + + break; + + // sorting header + case 'sort' : + + // sort order. Setting ascending or descending for sorting links + $N = ($this->SETTINGS['sortMode'] == 'N') ? ($this->SETTINGS['sortOrder'] == 'A' ? 'D' : 'A') : 'A'; + $S = ($this->SETTINGS['sortMode'] == 'S') ? ($this->SETTINGS['sortOrder'] == 'A' ? 'D' : 'A') : 'A'; + $T = ($this->SETTINGS['sortMode'] == 'T') ? ($this->SETTINGS['sortOrder'] == 'A' ? 'D' : 'A') : 'A'; + $M = ($this->SETTINGS['sortMode'] == 'M') ? ($this->SETTINGS['sortOrder'] == 'A' ? 'D' : 'A') : 'A'; + + $row .= $this->SETTINGS['lineNumbers'] ? ' ' : ''; + + $row .= 'Name'; + + $row .= $this->SETTINGS['showFileSize'] ?'Size' : ''; + $row .= $this->SETTINGS['showFileType'] ? 'Type' : ''; + $row .= $this->SETTINGS['showFileModDate'] ? 'Last Modified' : ''; + break; + + // parent directory row + case 'parent' : + $row .= $this->SETTINGS['lineNumbers'] ? '↑' : ''; + $row .= ''; + $row .= 'Parent Directory'; + $row .= ''; + $row .= $this->SETTINGS['showFileSize'] ? ' ' : ''; + $row .= $this->SETTINGS['showFileType'] ? ' ' : ''; + $row .= $this->SETTINGS['showFileModDate'] ? ' ' : ''; + break; + + // footer row + case 'footer' : + $row .= $this->SETTINGS['lineNumbers'] ? ' ' : ''; + $row .= ' '; + $row .= $this->SETTINGS['showFileSize'] ? ''.$this->SETTINGS['totalSize'].'' : ''; + $row .= $this->SETTINGS['showFileType'] ? ' ' : ''; + $row .= $this->SETTINGS['showFileModDate'] ? ' ' : ''; + break; + } + + $row .= ''; + return $row; + } + + + + + /* + * javascript + * + * + */ + function js(){ +/* +?> + + \ No newline at end of file diff --git a/i/php/snippets.php b/i/php/snippets.php new file mode 100644 index 0000000..3d59d3e --- /dev/null +++ b/i/php/snippets.php @@ -0,0 +1,34 @@ + + + Send this file: + + + +// PHP +$uploaddir = '/var/www/uploads/'; +$uploadfile = $uploaddir . basename($_FILES['userfile']['name']); + +echo "

    "; + +if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { + echo "File is valid, and was successfully uploaded.\n"; +} else { + echo "Upload failed"; +} + +echo "

    "; +echo '
    ';
    +echo 'Here is some more debugging info:';
    +print_r($_FILES);
    +print "
    "; + +*/ + +?> diff --git a/post/tumblr.php b/post/tumblr.php new file mode 100644 index 0000000..ef0d55f --- /dev/null +++ b/post/tumblr.php @@ -0,0 +1,59 @@ +source = $_GET['i']; + $image->save_to = '../agg/'; + $get = $image->download('curl'); + $i = basename($image->source); + if($get) { + + ?> + + +
    +
    + +
    + +
    +
    +
    +
    + +
    + + + + + +