ignoreFiles) && $file != "fComments.txt"){
if($isOpen){ $class1 = "file_open icon_".$this->getExt($file); $class2 = "props_open"; }else{ $class1 = "file icon_".$this->getExt($file); $class2 = "props"; }
// remove double slash
$path = str_replace("//","/",$path);
$filesret .= "
".$this->doFileLink($file,$path)." stripID("F_$path/$file")."\" class=\"properties ".$this->stripID("$path/$file")."\" title=\"show properties\">View $file Properties
stripID("F_$path/$file")."\">
".$this->doFileProps($file,$path) . "
";
}
}
return $filesret ;
}
/**
* returns html properties of given file
*
* @param string $file
* @param string $path
*/
function doFileProps($file,$path){
// get the file extension for checking file type:
$ext = substr(strrchr($file, '.'), 1);
if(substr($path,0,3) == ".//"){
$absolute = $this->pathToHere . substr($path,3);
}else if(substr($path,0,2) == "./"){
$absolute = $this->pathToHere . substr($path,2);
}else{
$absolute = $this->pathToHere . $path;
}
$absolute = str_replace(" ","%20",$absolute);
if(in_array(strtolower($ext),$this->imgTypes)){
// get image dimensions
$imageDim = @getimagesize($path);
$ret = "
last changed:
" . date($this->dateFormat, filectime($path)) . "
dimensions:
".$imageDim[0]."x".$imageDim[1]."
size:
" . $this->returnFileSize(filesize($path)) . "
HTML Image Code:
UBB Embed Code:
";
if($this->flickr == true) $ret .= "Options:Send to Flickr";
return $ret;
}else if(in_array(strtolower($ext),$this->embedTypes)){
return "
last changed:
" . date($this->dateFormat, filectime($path)) . "
size:
" . $this->returnFileSize(filesize($path)) . "
HTML Embed Code:
UBB Embed Code:
Options:
download";
}else if(in_array(strtolower($ext),$this->phpTypes) || in_array(strtolower($ext),$this->htmlTypes)){
return "
last changed:
" . date($this->dateFormat, filectime($path)) . "
size:
" . $this->returnFileSize(filesize($path)) . "
HTML Link:
UBB Link:
Options:
view source";
}else if(in_array(strtolower($ext),$this->miscTypes)){
$ret = "
last changed:
" . date($this->dateFormat, filectime($path)) . "
size:
" . $this->returnFileSize(filesize($path)) . "
HTML Link:
UBB Link:
Options:
download";
return $ret;
}
}
/**
* returns html link of given file
*
* @param string $file
* @param string $path
*/
function doFileLink($file,$path){
// get the file extension for checking file type:
$ext = substr(strrchr($file, '.'), 1);
if(in_array(strtolower($ext),$this->imgTypes)){
return "$file";
}else if(in_array(strtolower($ext),$this->embedTypes)){
return "$file";
}else if(in_array(strtolower($ext),$this->phpTypes) || in_array(strtolower($ext),$this->htmlTypes)){
return "$file";
}else if(in_array(strtolower($ext),$this->miscTypes)){
return "$file";
}
}
/**
* returns fileNice view link of given file
*
* @param string $file
* @param string $path
*/
function doFileLinkInt($file,$path){
// get the file extension for checking file type:
$ext = substr(strrchr($file, '.'), 1);
if(in_array(strtolower($ext),$this->imgTypes)){
return "$file";
}else if(in_array(strtolower($ext),$this->embedTypes)){
return "$file";
}else if(in_array(strtolower($ext),$this->phpTypes) || in_array(strtolower($ext),$this->htmlTypes)){
return "$file";
}else if(in_array(strtolower($ext),$this->miscTypes)){
return "$file";
}
}
function searchResults($arr,$sstring){
//echo("");
//print_r($arr);
//echo("");
$output = "Search results for '$sstring':
";
//$output = "Search results for '$sstring':
";
if(count($arr) > 0){
for($i = 0; $i < count($arr); $i++){
$folderOK = true;
$fileOK = false;
if(substr($arr[$i][1],0,3) == ".//"){ $hPath = substr($arr[$i][1],3); }else{ $hPath = $arr[$i][1]; };
// make a folders array to check that none are in the ignore list
$folders = explode("/",$this->getFolder($hPath));
while(count($folders) > 0){
$tempPath = implode("/",$folders);
//$output .= "
Checking: " .$tempPath;
if(in_array($tempPath,$this->ignoreFolders)){
//$output .= "
" . $tempPath . " is in ignoreFolders
";
$folderOK = false;
}
array_pop($folders);
}
// check file is not private
if(substr($arr[$i][1],0,3) == ".//"){ $hPath = substr($arr[$i][1],3); }else{ $hPath = $arr[$i][1]; };
if(!in_array($hPath,$this->ignoreFiles) && $arr[$i][0] != "fComments.txt"){
$fileOK = true;
}
if($folderOK == true && $fileOK == true){
$output .= "" . $this->doFileLinkInt($arr[$i][0],$arr[$i][1]) . "";
$output .= "(" . $arr[$i][1] . ")";
}
}
}else{
$output .= "Sorry, the search term '$sstring' returned no results.";
}
$output .= "";
echo($output);
}
/**
* returns human readable file size
*
* @param int $sizeInBytes
* @param int $precision
*/
function returnFileSize($sizeInBytes,$precision=2){
if($sizeInBytes < 1024){
return "$sizeInBytes bytes";
}else{
$k = intval($sizeInBytes/1024);
if($k < 1024){
return $k . "k ish";
}else{
$m = number_format((($sizeInBytes/1024) / 1024),2);
return $m . "mb ish";
}
}
}
function showSource($file){
echo "";
echo $this->get_sourcecode($file);
echo "";
}
function nextAndPrev($currentPic){
$fileNum = 0;
$fileArray = array();
$dir = $this->getFolder($currentPic);
$hook = @opendir($dir);
while (false !== ($file = readdir($hook))) {
array_push($fileArray,$file);
}
// order the file list the same as in the dir listing
// ignorecasesort($fileArray);
for($i = 0; $i < count($fileArray); $i++){
// look for current pic
if($dir."/".$fileArray[$i] == $currentPic){
$currentFileNum = $i;
}
}
// loop through fileArray to find previous and next images
for($i = $currentFileNum-1; $i>=0; $i--){
$type=$this->getExt($fileArray[$i]);
if(in_array(strtolower($type),$this->imgTypes)){
$prev = $dir."/".$fileArray[$i];
break;
}
}
for($i = $currentFileNum+1; $igetExt($fileArray[$i]);
if(in_array(strtolower($type),$this->imgTypes)){
$next = $dir."/".$fileArray[$i];
break;
}
}
for($i = 0; $i<=count($fileArray); $i++){
$type=$this->getExt($fileArray[$i]);
if(in_array(strtolower($type),$this->imgTypes)){
$first = $dir."/".$fileArray[$i];
break;
}
}
return array($prev,$next,$first);
closedir($hook);
}
function viewFile($file){
$path = $_GET['view'];
$ext = substr(strrchr($_GET['view'], '.'), 1);
if(substr($path,0,3) == ".//"){
$absolute = $this->pathToHere . substr($path,3);
}else{
$absolute = $this->pathToHere . $path;
}
if(in_array($ext,$this->imgTypes)){
// we're showing an image
$imageDim = @getimagesize($file);
$preNext = $this->nextAndPrev($_GET['view']);
echo("\n\n
");
if($preNext[0] != ""){
echo("\n
Prev");
}
if($preNext[0] != "" && $preNext[1] != ""){
echo(" | ");
}
if($preNext[1] != ""){
echo("\n
Next");
}
echo "\n
";
if($preNext[1] != ""){
echo("\n
![\"".$_GET['view']."\"](\"".$_GET['view']."\")
\n
");
}else{
echo("\n

");
}
echo("\n
getFolder($file)."\" title=\"close image\">close");
echo("\n
\n
\n
\nstart slideshow
\n".basename($_GET['view'])."
last changed: " . date($this->dateFormat, filectime($_GET['view'])) . "
dimensions: ".$imageDim[0]."x".$imageDim[1]."
size: " . $this->returnFileSize(filesize($_GET['view'])) . "
\n
");
if($this->flickr == true) echo("\n
Send to Flickr");
echo("\n
\n
");
}else if(in_array($ext,$this->embedTypes)){
// we're embedding
$dimensiones=getimagesize($_GET['view']);
echo("
".$_GET['view']."
".$_GET['view']."
last changed: " . date($this->dateFormat, filectime($_GET['view'])) . "
size: " . $this->returnFileSize(filesize($_GET['view'])) . "
");
}
}
function getExt($file){
return substr(strrchr($file, '.'), 1);
}
function getFolder($filePath){
$temp = explode("/",$filePath);
array_pop($temp);
return implode("/",$temp);
}
/**
* returns syntax hi-lited html / php
*
* @author unknown
* @param string $filename
*
*/
function get_sourcecode($filename) {
if(!isset($filename) || !$filename) return false;
// Get highlighted code
$html_code = highlight_file($filename, TRUE);
// Remove the first "" tag from "$html_code" (if any)
if (substr($html_code, 0, 6) == "") {
$html_code = substr($html_code, 6, strlen($html_code));
}
// Replacement-map to replace deprecated "" tag with ""
$xhtml_convmap = array(
' '' => '',
'color="' => 'style="color:'
);
// Replace "" tags with "" tags, to generate a valid XHTML code
$html_code = strtr($html_code, $xhtml_convmap);
### Okay, Now we have a valid XHTML code
$retval = "" . $html_code; // Why? remember Bookmark #1, that I removed the tag ""
return $retval;
}
function stripID($str){
$pattern = '/[^\d\w]/';
$replace = '_';
return preg_replace($pattern, $replace, $str);
}
}
/**
* FNFileList - Handles directory/file listings
*
*/
class FNFileList{
var $allowHTML;
var $allowScripts;
var $allowImages;
var $allowEmbed;
var $allowMisc;
var $hook;
var $folders = array();
var $files = array();
var $file;
var $path;
var $openPath;
var $allowedTypes = array();
//default sort
var $sortBy;
var $sortDir;
var $searchArray = array();
/**
* Sets up initial variables for the FileList class
*
* @return FileList
*/
function FNFileList(){
// init the file list and set up necessary variables
global $sortBy, $sortDir, $showImg, $showEmbed, $showHtml, $showScript, $showMisc, $imgTypes, $embedTypes, $htmlTypes, $phpTypes, $miscTypes;
// set up allowed types
if($showImg == "show"){
for($i=0; $iallowedTypes,$imgTypes[$i]);
}
}
if($showEmbed == "show"){
for($i=0; $iallowedTypes,$embedTypes[$i]);
}
}
if($showHtml == "show"){
for($i=0; $iallowedTypes,$htmlTypes[$i]);
}
}
if($showScript == "show"){
for($i=0; $iallowedTypes,$phpTypes[$i]);
}
}
if($showMisc == "show"){
for($i=0; $iallowedTypes,$miscTypes[$i]);
}
}
// get openPath
if(isset($_GET['src'])){
$this->openPath = secCheck($_GET['src']);
}else if(isset($_GET['view'])){
$this->openPath = secCheck($_GET['view']);
}else{
$this->openPath = false;
}
$this->sortBy = $sortBy;
$this->sortDir = $sortDir;
}
function getFolderArray($dir){
$folders = array();
$hook = @opendir($dir);
while (($file = @readdir($hook))!==false){
if (substr($file,0,1) != "."){
$path = $dir."/".$file;
if(is_dir($path)){
// get last modified time for date sorting
$mod = filectime($path);
if(substr($this->openPath,0,strlen($path)) == $path){
array_push($folders,array($file,$path,true,$mod));
}else{
array_push($folders,array($file,$path,false,$mod));
}
}
}
}
// sort the array before passing it on
// make the sort by arrays
foreach ($folders as $key => $row) {
$namesTemp[$key] = strtolower($row[1]);
$timesTemp[$key] = $row[3];
}
// do the sort
if($this->sortBy == "name"){
if($this->sortDir == "ascending"){
@array_multisort($folders, SORT_ASC, SORT_STRING, $namesTemp, SORT_ASC, SORT_STRING);
}else{
@array_multisort($folders, SORT_DESC, SORT_STRING, $namesTemp, SORT_DESC, SORT_STRING);
}
}else{
if($this->sortDir == "ascending"){
@array_multisort($folders, SORT_ASC, SORT_NUMERIC, $timesTemp, SORT_ASC, SORT_NUMERIC);
}else{
@array_multisort($folders, SORT_DESC, SORT_NUMERIC, $timesTemp, SORT_DESC, SORT_NUMERIC);
}
}
return $folders;
}
function getFilesArray($dir){
$files = array();
$hook = @opendir($dir);
while (($file = @readdir($hook))!==false){
if (substr($file,0,1) != "."){
$path = $dir."/".$file;
if(!is_dir($path) && in_array($this->getExt($file),$this->allowedTypes)){
// get last modified time for date sorting
$mod = filectime($path);
if($path == $this->openPath){
array_push($files,array($file,$path,true,$mod));
}else{
array_push($files,array($file,$path,false,$mod));
}
}
}
}
// sort the array before passing it on
// make the sort by arrays
foreach ($files as $key => $row) {
$namesTemp[$key] = strtolower($row[1]);
$timesTemp[$key] = $row[3];
}
// do the sort
if($this->sortBy == "name"){
if($this->sortDir == "ascending"){
@array_multisort($files, SORT_ASC, SORT_STRING, $namesTemp, SORT_ASC, SORT_STRING);
}else{
@array_multisort($files, SORT_DESC, SORT_STRING, $namesTemp, SORT_DESC, SORT_STRING);
}
}else{
if($this->sortDir == "ascending"){
@array_multisort($files, SORT_ASC, SORT_NUMERIC, $timesTemp, SORT_ASC, SORT_NUMERIC);
}else{
@array_multisort($files, SORT_DESC, SORT_NUMERIC, $timesTemp, SORT_DESC, SORT_NUMERIC);
}
}
return $files;
}
function getFilesRecursive($files,$dir,$noreturn = false){
if(!is_dir($dir)){
return false;
}
$hook = @opendir($dir);
while (($file = readdir($hook))!==false){
if (substr($file,0,1) != "."){
$path = $dir."/".$file;
if(!is_dir($path) && in_array($this->getExt($file),$this->allowedTypes)){
// get last modified time for date sorting
$mod = filectime($path);
if($path == $this->openPath){
array_push($this->searchArray ,array($file,$path,true,$mod));
}else{
array_push($this->searchArray ,array($file,$path,false,$mod));
}
}else{
if(is_dir($path)){
$this->getFilesRecursive($this->searchArray ,$path,true);
}
}
}
}
// sort the array before passing it on
// make the sort by arrays
foreach ($this->searchArray as $key => $row) {
$namesTemp[$key] = strtolower($row[1]);
$timesTemp[$key] = $row[3];
}
// do the sort
if($this->sortBy == "name"){
if($this->sortDir == "ascending"){
@array_multisort($this->searchArray , SORT_ASC, SORT_STRING, $namesTemp, SORT_ASC, SORT_STRING);
}else{
@array_multisort($this->searchArray , SORT_DESC, SORT_STRING, $namesTemp, SORT_DESC, SORT_STRING);
}
}else{
if($this->sortDir == "ascending"){
@array_multisort($this->searchArray , SORT_ASC, SORT_NUMERIC, $timesTemp, SORT_ASC, SORT_NUMERIC);
}else{
@array_multisort($this->searchArray , SORT_DESC, SORT_NUMERIC, $timesTemp, SORT_DESC, SORT_NUMERIC);
}
}
if($noreturn != true){
return $this->searchArray ;
}
}
function search($sstring){
if(strlen($sstring)>0){
$this->searchArray = array();
$f = $this->getFilesRecursive($array,"./");
$found = array();
for($i = 0; $i< count($this->searchArray);$i++){
if(strstr(strtolower($this->searchArray[$i][0]),strtolower($sstring))){
array_push($found,$this->searchArray[$i]);
}
}
$out = new FNOutput;
$out->searchResults($found,$sstring);
}
}
function getDirList($dir){
$this->folders = $this->getFolderArray($dir);
$this->files = $this->getFilesArray($dir);
$out = new FNOutput;
$out->html .= $out->folderList($this->folders);
$out->html .= $out->fileList($this->files);
$out->sendOutput();
}
function getExt($file){
return strtolower(substr(strrchr($file, '.'), 1));
}
function namesort($a, $b) {
return strnatcasecmp($a["name"], $b["name"]);
}
function unset_by_val($needle,&$haystack) {
while(($gotcha = array_search($needle,$haystack)) > -1)
unset($haystack[$gotcha]);
}
}
/**
* UserInfo - Handles display of error and debug messages
*
*/
class UserInfo{
var $info;
function info($str){
$this->info .= "$str
";
}
function warn($str){
$this->info .= "$str
";
}
function output(){
if($this->info != ""){
?>
info); ?>