<?php
    $pstart 
= <<<END
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
    <head>
        <title>Filelisting</title>
        <style>
            body { font-family: Calibri, Tahoma, Verdana, Sans-Serif; font-size: 12px; }
            ul { list-style: none; margin: 0px; padding: 0px; }
            li { margin: 0px; padding: 0px 0px 1px 0px; height: 16px; }
            a { cursor: pointer; text-decoration: none; color: #227; }
            a:hover { border: 1px dotted #66C; border-width: 0px 0px 1px 0px; filter: alpha(opacity=50); opacity: 0.5; }
            .dirzimg { width: 18px; height: 16px; background: url('http://mp3.ziphoid.com/img/dir.gif') no-repeat; float: left; display: block; }
            .dirupimg { width: 18px; height: 16px; background: url('http://mp3.ziphoid.com/img/updir.gif') no-repeat; float: left; }
            .fileimg { width: 18px; height: 16px; background: url('http://mp3.ziphoid.com/img/file.gif') no-repeat; float: left; }
            .mp3, .wav { background-image: url('http://mp3.ziphoid.com/img/mp3.gif'); }
            .txt { background-image: url('http://mp3.ziphoid.com/img/txt.gif'); }
            .gif, .jpg { background-image: url('http://mp3.ziphoid.com/img/pic.gif'); }
            a:hover img { filter: alpha(opacity=50); opacity: 0.5; }
        </style>
        <link rel="stylesheet type="text/css" href="/colorbox/colorbox.css" />
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
        <script src="/colorbox/jquery.colorbox-min.js" type="text/javascript"></script>
        <script type="text/javascript">
        <!--
            $(document).ready(function(){
                $("a[rel='collection']").colorbox({maxWidth: "97%", maxHeight: "97%", initialWidth: "400px"});
                $(document).bind('cbox_complete', function(){
                    var el = $.fn.colorbox.element(); 
                    $("#cboxBottomCenter").html("<div id='inbox' style='text-align: center;'>" + $(el).attr("id") + "</div>");
//                    setTimeout($.fn.colorbox.next, 2500);
                    
                });
            });
        // -->
        </script>

    </head>
    
    <body>
END;
    
$pstop = <<<END
    </body>
</html>
END;


    
$deniedDirs = array("hemligt""hemligt2""images");
    
$deniedFiles = array("robots.txt""colorbox.css""jquery.colorbox-min.js"".htaccess");
    
$deniedExts = array("php"".htaccess");
    
$allowedExts = array("exe""*");
    
    
$infotext "";
    if(isset(
$_REQUEST['dirname'])) {
        
$dirname $_REQUEST['dirname'];
    } else {
        
$dirname ".";
    }

    
$infofile "";
    if(
$dirname != ".") {
        
$infofile .= $dirname."/";
    }
    
$infofile .= ".dirinfo";
    if(
file_exists($infofile)) {
        
$infotext file_get_contents($infofile);
    }
    
    
$showext true;
    
$showsize true;
    
$sizetype "k"// Choose between b/k/MB
    
$flaps = array("[""]");
    
$dirs = array();
    
$links = array();
    if(
is_dir($dirname)) {
        if(
$dh opendir($dirname)) {
            
$c 0;
            while(
false != ($file readdir($dh))) {
                
$cDir "";
                if(
$dirname != ".") {
                    
$cDir .= $dirname."/";
                }
                
$cDir .= $file;
                if(
is_dir($cDir)) {
                    if(
$file != "." && !($file == ".." && $dirname == ".") && !in_array($file$deniedDirs)) {
                        
$dName "<li>";
                        
$dName .= "<a href=\"{$_SERVER['PHP_SELF']}?dirname=";
                        
$dArr explode("/"$dirname);
                        if(
$file == "..") {
                            if(
count($dArr) == 1) {
                                
$dName .= ".";
                            } else {
                                
$trash array_pop($dArr);
                                
$dName .= implode("/"$dArr);
                            }
                        } else {
                            
$dName .= implode("/"$dArr)."/$file";
                        }
                        
$dName .= "\">";
                        
$dName .= "<img src=\"http://mp3.ziphoid.com/img/spc.gif\" width=\"0\" height=\"0\" alt=\"\" border=\"0\" class=\"dir";
                        if(
$file == "..") {
                            
$dName .= "up";
                        } else {
                            
$dName .= "z";
                        }
                        
$dName .= "img\">";
                        
$dName .= "$file</a></li>";
                        
$dirs[] = $dName;
                    }
                } else {
                    
$fName explode("."$file);
                    if(
count($fName) > 0) {
                        
$ext strtolower($fName[count($fName)-1]);
                        if(((
in_array($ext$allowedExts) && !in_array($file$deniedFiles)) || in_array("*"$allowedExts)) && (!(in_array($ext$deniedExts) || in_array($file$deniedFiles)))) {
                            
$i 0;
                            
$m count($fName)-1;
                            
$outname "";
                            if(
$showext) {
                                
$outname $file;
                            } else {
                                foreach(
$fName as $val) {
                                    if(
$i $m) {
                                        
$outname .= $val;
                                    }
                                    
$i++;
                                }
                            }
                            if(
$showsize) {
                                
$cFile "";
                                if(
$dirname != ".") {
                                    
$cFile .= $dirname."/";
                                }
                                
$cFile .= $file;
                                switch(
$sizetype) {
                                    case 
"k":
                                        
$fsize round((filesize($cFile)/1024), 1)."k";
                                    break;
                                        case 
"MB":
                                        
$fsize round((filesize($cFile)/1024000), 1)." MB";
                                        break;
                                    default:
                                        
$fsize filesize($cFile)." bytes";
                                        break;
                                }
                                
$outname .= " {$flaps[0]}$fsize{$flaps[1]}";
                            }
                            
$cLink "<li>";
                            
$cLink .= "<a ";
                            
$cLink .= "href=\"";
                            if(
$dirname != ".") {
                                
$cLink .= $dirname."/";
                            }
                            
$cLink .= str_replace(" ""%20"$file)."\" ";
                            if(
$ext == "jpg" || $ext == "gif" || $ext == "png") {
                                
$cLink .= "rel=\"collection\" class=\"cboxElement\" ";
                                
$cLink .= "id=\"";
                                
$cLink .= "pic_".$c;
                                
$cLink .= "\" ";
                                
$cLink .= "title=\"".$outname."\" ";
                            }
                            
$cLink .= ">";
                            
$cLink .= "<img src=\"http://mp3.ziphoid.com/img/spc.gif\" width=\"0\" height=\"0\" alt=\"\" border=\"0\" class=\"fileimg ".$ext."\" />";
                            
$cLink .= str_replace("_"" "$outname)."</a></li>";
                            
$links[] = $cLink;
                        }
                    }
                }
                
$c++;
            }
        }
    }

    echo 
$pstart;
    echo 
$infotext;
    echo 
"<div id=\"filediv\">";
    if(
count($dirs) > 0) {
        
natcasesort($dirs);
        echo 
"<ul class=\"dirlist\">";
        echo 
implode("\n"$dirs);
        echo 
"</ul>";
    }
    if(
count($links) > 0) {
        
natcasesort($links);
        echo 
"<ul class=\"filelist\">";
        echo 
implode("\n"$links);
        echo 
"</ul>";
    }
    echo 
"</div>";
    echo 
$pstop;
?>