Hi Richard,

There are a couple out there... I created one for
myself (V1."un") that does something similar...  It
relies on a couple of support files for mime-types and
icons.  Here's the code... if you like the idea, I can
zip up the icons and extension-to-mime folders and
send it to ya.  My website (www.jwfarrell.com) is
supposed to be online later this afternoon (after a
week of promises from my ISP), so you'll be able to
look at the code in action.

B

listtree.php
<?php
$MetaTitle = "Locally-Mirrored Documentation";
$MetaDescription ="Answerbase for Multivalue
Programmers";
$MetaKeywords =  "UNIVERSE, UNIDATA, APACHE PERL, HTML
REFERENCE, CSS, CASCADING STYLE SHEET, REFERENCE,
SEARCH";
include( "style/htmlhead.php" );

$SuppressSearch = false;
$OnLoad = "";
include("style/bodytemplate_top.php");

// user config
$Gaol = "$DocRoot/help";                // set a ceiling so people
don't prowl the system
$GaolURL = "/help";                     // ceiling in URLspace
$IconsFolder = "$DocRoot/graphics/icons";       // directory
for icons
$MimeTypeFolder = "$DocRoot/ext2mime";          //
extension-to-icon map

$Subdirectories = array();
$SimpleFiles = array();
$TitleStart = "ThEtItLe";
$TitleReplacement = MV_FM . $TitleStart . MV_FM;
$TitleEnd = MV_FM;

//echo "Method is $Method<br>\n";
?>

<h2>Browse the Documentation Tree</h2>

<form action="/listtree.php" method="POST">
<fieldset style="width: 500px; text-align: left;
text-indent: 0em;">

<table border="0" cellpadding="0" cellspacing="0"
width="100%">
<col style="width: 20px;">
<col style="width: 20px;">
<col>

<caption>Folder contents</caption>

<?php
unset( $DocDirectory );

if ( $Method == "POST" ) {
        $TargetFolder = $Folder;
        if (  substr( $TargetFolder, -2 ) != '..' ) {
                if ( $TargetFolder == $GaolURL ) { $TargetFolder =
""; }
//echo "Setting folders from $TargetFolder<br>\n";

                $DocArray = explode( '/', $TargetFolder );
                $DocDirectoryArray = array_slice( $DocArray, 1 );
                $DocDirectory = implode( '/', $DocDirectoryArray );
                $CurrentFolder = "$TargetFolder";

//echo "Doc Directory is $DocDirectory<br>\n";
                $FullPath = explode( '/', $DocDirectory );
                $PreviousDirectoryArray = array_slice( $FullPath, 0,
count( $FullPath ) - 2 );
                $PreviousDirectory = implode( '/',
$PreviousDirectoryArray );

                $FullURL = explode( '/', $CurrentFolder );
                $PreviousFolderArray = array_slice( $FullURL, 0,
count( $FullURL ) - 1 );
                $PreviousFolder = implode( '/', $PreviousFolderArray
);

        }
}

// init tree - disallow attempts to go above gaol
if ( ( !isset( $DocDirectory ) ) | ( strlen(
$DocDirectory ) < strlen( $GaolURL ) ) ) {
        $DocDirectory = $Gaol;
        $DocDirectoryArray = array( $DocDirectory );
        $CurrentFolder = $GaolURL;
        $PreviousFolderArray = array( "" );
        $PreviousFolder = "";
}

if ( ( $Docs = opendir( $DocDirectory ) ) === false )
{ die( "$DocDirectory doesn't exist!" ); }

while ( false !== ( $Subdir = readdir( $Docs ) ) ) {
        if ( ( substr( $Subdir, 0, 1 ) != "." ) ) {
                if ( is_dir( "$DocDirectory/$Subdir" ) ) {
                        array_push( $Subdirectories, $Subdir );
                } else {
                        array_push( $SimpleFiles, $Subdir );
                }
        }
}

sort( $Subdirectories );
sort( $SimpleFiles );

?>
        <tr>
                <th>&nbsp;</th>
                <th>&nbsp;</th>
                <th>Name</th>
                <th>Size</th>
        </tr>


<?php
$Level = 0; // how many t-bars in?

echo "<tr>\n";
echo "<td align=\"left\" valign=\"top\"
style=\"line-height: 125%;\"><a href=\"/help\"><img
style=\"border: none;background: transparent;
line-height: 110%;\" height=\"16\"
src=\"/graphics/icons/folder_home.png\"></td>\n";
echo "<td>&nbsp;</td>\n";
echo "<td>Documentation Home Page</td>\n";
echo "</tr>\n";

echo "<tr><td>&nbsp;</td></td>\n";

if ( $DocDirectory != $Gaol ) {
        echo "<tr>\n";
        echo "<td align=\"left\" valign=\"top\"><input
name=\"Folder\" style=\"border: none;background:
transparent;\" type=\"image\" height=\"16\" value=\"\"
src=\"/graphics/icons/mark_top.gif\"></td>\n";
        echo "<td>&nbsp;</td>\n";
        echo "<td>Top of the Tree</td>\n";
        echo "</tr>\n";

        echo "<tr><td>&nbsp;</td></tr>\n";

        echo "<tr>\n";
        echo "<td align=\"left\" valign=\"top\"><input
name=\"Folder\" style=\"border: none;background:
transparent;\" type=\"image\" height=\"16\"
value=\"$PreviousFolder\"
src=\"/graphics/icons/back.gif\"></td>\n";
        echo "<td>&nbsp;</td>\n";
        echo "<td>Up one level to $PreviousFolder</td>\n";
        echo "</tr>\n";

        echo "<tr><td>&nbsp;</td></tr>\n";
}
?>
        <tr>
                <td align="left" valign="top"><img
src="/graphics/icons/folder_open.png"></td>
                <td>&nbsp;</td>
                <td align="left"><?php echo $CurrentFolder; ?></td>
        </tr>

<?php

$LastFolder = $Subdirectories[ count( $Subdirectories
) - 1 ];
$LastFile = $SimpleFiles[ count( $SimpleFiles ) - 1 ];

foreach ( $Subdirectories as $Subdir ) {
        echo "<tr>\n";
        if ( ( $Subdir == $LastFolder ) & ( $LastFile == "" )
) {
                echo "<td align=\"left\" valign=\"top\"><img
src=\"/graphics/icons/tree_f.gif\"></td>\n";
        } else {
                echo "<td align=\"left\" valign=\"top\"><img
src=\"/graphics/icons/tree_e.gif\"></td>\n";
        }
        echo "<td align=\"left\" valign=\"top\"><input
style=\"border: none;background: transparent;\"
value=\"$CurrentFolder/$Subdir\" name=\"Folder\"
type=\"image\"
src=\"/graphics/icons/folder_blue.png\"></td>\n";
        echo "<td align=\"left\"
valign=\"top\">$CurrentFolder/$Subdir</td>\n";
        echo "</tr>\n";

}

foreach ( $SimpleFiles as $SimpleFile ) {
        echo "<tr>\n";

        if ( $SimpleFile == $LastFile ) {
                echo "<td align=\"left\" valign=\"top\"><img
src=\"/graphics/icons/tree_f.gif\"></td>\n";
        } else {
                echo "<td align=\"left\" valign=\"top\"><img
src=\"/graphics/icons/tree_e.gif\"></td>\n";
        }

// find the right icon for the file type
        unset( $Icon );
        $SplitName = explode( '.', $SimpleFile );
        $NameParts = count( $SplitName );
        if ( $NameParts == 1 ) {
                $Icon = "generic.gif";
        } else {
                $NameParts--;
                $Extension = $SplitName[ $NameParts ];
                if ( is_file( "$MimeTypeFolder/$Extension" ) ) {
                        list( $MimeType, $TheRest ) = file(
"$MimeTypeFolder/$Extension" );
                        $MimeType = rtrim( $MimeType );
                        if ( is_file( "$IconsFolder/mime_$MimeType.gif" ) )
{
                                $Icon = "mime_$MimeType.gif";
                        }
                }
        }

        if ( !isset( $Icon ) ) { $Icon = "generic.gif"; }

        echo "<td align=\"left\" valign=\"top\"><img
src=\"/graphics/icons/$Icon\" height=\"16\"></td>\n";
        echo "<td align=\"left\" valign=\"top\"><a
href=\"$CurrentFolder/$SimpleFile\">$CurrentFolder/$SimpleFile</a></td>\n";
        
        echo "<td align=\"right\" valign=\"top\">" .
filesize( "$DocRoot/$CurrentFolder/$SimpleFile" ) .
"</td>";
        echo "</tr>\n";
}

?>
</table>

<input type="hidden" name="CurrentFolder" value="<?php
echo $CurrentFolder; ?>">

</fieldset>
</form>

<?php
//include( "$DocRoot/searchbody.php" );
?>
<?php
include("$DocRoot/style/bodytemplate_bottom.php");?>


=====
Bill Farrell
Multivalue and *nix Support Specialist

Phone: (828) 667-2245
Fax:   (928) 563-5189
Web:   http://www.jwfarrell.com

__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to