uranus.webhop.net

functions.php source code

<?php 

/* Everyone is free to use all the code on this site, but I would really appreciate if the site the code is used for becomes open as well. I would really like to hear from you if you use the code, and send me a link to your site. */
function page($nospec,$illeg,$readno) {
    if( 
$nospec == "" ) { $nospec "no_file.php"; }
    if( 
$illeg == "" ) { $illeg "sec_no.php"; }
    if( 
$readno == "" ) { $readno "load_failed.php"; }
    
$page $_GET['page'];
    if( 
$page == "" && $nospec == "no_file.php" ) {
        
$info = array($nospec,basename($nospec),"1"); // Address first, name second, f(ailure)|s(uccess) last
    
} elseif( $page == "" && $nospec != "no_file.php" ) {
        
$info = array($nospec,basename($nospec),"0");
    } elseif( 
$page[0] == "/" || $page[0] . $page[1] == ".." || dirname($page) == "sec" && $illeg == "sec_no.php" ) {
        
$info = array($illeg,basename($illeg),$page);
    } elseif( 
$page[0] == "/" || $page[0] . $page[1] == ".." || dirname($page) == "sec" && $illeg != "sec_no.php" ) {
        
$info = array($illeg,basename($illeg),"0");
    } elseif( ! 
is_readable($page) && $readno == "load_failed.php" ) {
        
$info = array($readno,basename($readno),$page);
    } elseif( ! 
is_readable($page) && $readno != "load_failed.php" ){
        
$info = array($readno,basename($readno),"0");
    } else {
        
$info = array($page,basename($page),"0");
    }
    return 
$info;
}

function 
numprint($file) { // Prints a file with the lines numbered
        
print("\n<ol>\n");
        foreach(
file($file) as $line) {
                
$line chop($line); // This is there to make sure the resulting code is tidy
                
$line htmlentities($line); // Make sure that XML/*ML files are displayed correctly
                
print("<li>$line</li>\n");
    }
        print(
"</ol>\n");
}

function 
title($prefix,$name,$suffix,$failure "") { // Gives the filename + suffix/prefix for use as title/header
    
if( $failure ) {
        print(
"Error");
    } else {
        print(
"$prefix $name $suffix");
    }
}

function 
rootdir() { // Gives the web page's current directory (since all the PHP files are in the root directory, it effectively gives that)
    
print( $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/" );
}

function 
sitemap() { // Returns a complete, styled list of all the files in the web page's current directory
    
$list = array();
        
$li 0;
        
$php = array();
        
$img = array();
        
$txt = array();
        
$fld = array();
        
$cphp 0;
        
$cimg 0;
        
$ctxt 0;
        
$cfld 0;
        
$a 0;
        
// Initialize all the variables - don't forget to keep them global when used in functions

    
print("<div class=\"note\">Note: (s) for page sourcecode, (p) for plain text<br /><br /></div>");
    print(
"<div class=\"filelist shell\">\n");
    
filelist("");
        
writeout();
    global 
$fld;
    foreach( 
$fld as $ffld ) {
            if( 
$a == ) {
                         print(
"</div><div class=\"filelist shell\">\n");
                } elseif( 
$a == ) {
                         print(
"</div><div class=\"filelist shell\">\n");
                }
                
filelist("$ffld");
            
writeout();
                
$a++;
        }
        print(
"</div>\n");
    
$fld = array();
    while( list(
$key,$val) = each($list) ) {
        print(
$val);
    }
}

function 
cdate($dir) {
    
$date 0;
    
$files = array();
    
$files glob("$dir*");
    while( list(
$key,$val) = each($files) ) {
        if( 
filetype("$dir$val") == "dir" && $val != "." && $val != ".." ) {
            
$subdir glob("$dir$val/*");
            if( 
$subdir ) {
                while( list(
$k,$v) = each($subdir) ) {
                    if( 
filectime($v) > $date ) {
                        
$date filectime($v);
                    }
                }
            }
            
$subdir = array();
        }
        if( 
$val != "public_html" && filectime($val) > $date ) {
            
$date filectime($val);
        }
    }
    print(
date("F d Y H:i:s",$date));
}

function 
filelist($dir) { // Retrieves all the filenames in the directory, makes sure that a filetype is specified and writes out the appropriate links
    
global $list// I used opendir(), readdir() and closedir() first, but this is so much cleaner!
        
$list glob("$dir*"); // Give the option to print the contents of directories other than the current working directory
    
if( $list && $dir != "sec/" ) {
            
sort($list); // Dunno whether this is of any use for glob(), but with readdir() the output isn't in alphabetical order (but in order encountered)
            
while( list($key,$val) = each($list) ) {
                if( 
$val !== "." && $val !== ".." ) { // Don't print the . and .. files
                
$val basename($val);
                
spectype($dir,$val);
            }
            }
            print(
"/$dir<br />\n");
    }
}

function 
spectype($dir,$name) { // Specifies the filetype of a certain file (first by using filetype(), then by looking at the suffix)
    
if( filetype("$dir$name") == "dir" ) {
            
alloc("$dir$name/",dir);
        } else {
                
$temp explode(".",$name); // Splits the filename into the pieces divided by .'s - the last piece most likely contains the suffix
                
$i count($temp) - 1;
                
alloc("$dir$name",$temp[$i]);
        }
}

function 
alloc($name,$suff) { // Puts a filename into the appropriate array
    
if( $suff == "php" || $suff == "phtml" || $suff == "php3" ) { // The most important filetype :)
            
global $php;
                global 
$cphp;
                
$php[$cphp] = $name;
                
$cphp++;
        } elseif( 
$suff == "png" || $suff == "ico" || $suff == "jpg" || $suff == "gif" || $suff == "xcf" ) {
                global 
$img;
                global 
$cimg;
                
$img[$cimg] = $name;
                
$cimg++;
        } elseif( 
$suff == "unk" || $suff == "txt" || $suff == "css" ) { // The unk(nown) filetype is only actually used when a first run of the file through this function fails
                
global $txt;
                global 
$ctxt;
                
$txt[$ctxt] = $name;
                
$ctxt++;
        }elseif( 
$suff == "dir" ) {
                global 
$fld// Using the variable $dir conflicted with other $dir variables in the file, and would be confusing anyway
                
global $cfld;
                
$fld[$cfld] = $name;
                
$cfld++;
        } else {
                
alloc($name,"unk"); // Make sure that all the files (also those with a suffix not listed above) are shown in the sitemap
        
}
}

function 
writeout() { // Writes a nice link in the appropriate list for every file put in the arrays by alloc()
    
global $php;
        global 
$fphp;
        global 
$img;
        global 
$fimg;
        global 
$txt;
        global 
$ftxt;
        global 
$fld;
        global 
$ffld;

        if( 
count($php) > ) {
            print(
"PHP:<br />\n");
                foreach( 
$php as $fphp ) {
                    if( 
$fphp == "pagesource.php" || $fphp == "readconf.php" ) {
                            print(
"<a href=\"$fphp\">" basename($fphp) . "</a> <a href=\"pagesource.php?page=$fphp\">(s)</a><br />\n");
                } elseif( 
$fphp != "header.php" && $fphp != "footer.php" && $fphp != "index.php" && $fphp != "functions.php" ) {
                            print(
"<a href=\"index.php?page=$fphp\">" basename($fphp) . "</a> <a href=\"pagesource.php?page=$fphp\">(s)</a><br />\n");
            } elseif( 
$fphp == "index.php" ) {
                print(
"<a href=\"$fphp\">" basename($fphp) . "</a> <a href=\"pagesource.php?page=$fphp\">(s)</a><br />\n");
                    } else {
                            print(
basename($fphp) . " <a href=\"pagesource.php?page=$fphp\">(s)</a><br />\n");
                    }
            }
            print(
"<br />\n");
    }
        if( 
count($img) > ) {
        print(
"Images:<br />\n");
        foreach( 
$img as $fimg ) {
                    print(
"<a href=\"$fimg\">" basename($fimg) . "</a><br />\n");
            }
            print(
"<br />");
    }
    if( 
count($txt) > ) {
            print(
"Plain text:<br />\n");
            foreach( 
$txt as $ftxt ) {
            print(
"<a href=\"readconf.php?page=$ftxt\">" basename($ftxt) . "</a> <a href=\"$ftxt\">(p)</a><br />\n");
        }
    print(
"<br />");
    }
        
$php = array();
        
$img = array();
    
$txt = array();
}

function 
is_php($name) { // Tests whether a certain file is a PHP file, and sets $returnval accordingly
    
global $returnval;
    if( 
dirname($name) != "." ) {
        
$pathto dirname($name) . "/";
    }
    
$file basename($name);
    global 
$php;
    
$php = array();
    
spectype("$pathto","$file");
    if( 
count($php) == "1" ) {
        
$returnval true;
    } else {
        
$returnval false;
    }
    
$php = array();
    
$img = array();
    
$txt = array();
    
$fld = array();
}


?>

Valid XHTML 1.0! Valid CSS!
Get Firefox!
.: Page last modified: December 03 2023 23:32:39 - Copyleft 2004 :.