<?php
/*
* Developed by Juergen Derigs 25.07.2002.
* DynToc-1.0.
* Support nested folders.
* Use this source for free but don't remove this header.
* For help, questions and bugs mail to hide@address.com
* Have fun.
*/
//Some variables to configure DynToc
/*
* Path to the closed folder image.
* If the String is empty, you will see a --+ for the closed Folder
*/
$imgClosedFolder = ""; //"<img src=\"img/f_close.gif\" width=\"30\" height=\"15\" border=\"0\">";
/*
* Path to the opened folder image.
* If the String is empty, you will see a --- for the opened Folder
*/
$imgOpenedFolder = ""; //"<img src=\"img/f_open.gif\" width=\"30\" height=\"15\" border=\"0\">";
/*
* Absolute Path to the Configuration File
* For Microsoft Systems you have to mask the Backslash. e.g. C:\\tmp\toc_config.txt
* For Unix just write normally /home/foo/toc_config.txt
*/
$configFile = "E:\\www\\toc\\config_toc.txt";
/*
* Set the name of the root folder.
* It will be urlencoded. So you can use white spaces.
*/
$rootClass = "Dyn Toc";
/*
* If you want to set a background Color for the HTML output, do it here.
* Use hex format. e.g #FFFFFF
*/
$bgColor = "#FFFFFF"; //Background-Color for the HTML-Output
/*
* If you want to set a background Image for the HTML output, do it here.
* Set the absolute or relative path (URL) to the Image.
*/
$background = "";
/*
* The font size in points.
* Enable CSS in your browser.
*/
$fontSize = 9; //Font size in points
/*
* To disable underline the folder links set this TRUE else FALSE.
* Enable CSS in your browser.
*/
$boolFolder = TRUE;
/*
* To disable underline the file links set this TRUE else FALSE.
* Enable CSS in your browser.
*/
$boolFile = TRUE;
class Dir {
var $closedFolder;
var $openedFolder;
var $entrys = array();
var $name;
var $boolFolder;
//Create new Dir
function Dir( $name, $closedFolder, $openedFolder, $boolFolder ) {
$this->name = $name;
$this->closedFolder = ( strcmp( $closedFolder, "" ) ) ? $closedFolder : "--+";
$this->openedFolder = ( strcmp( $openedFolder, "" ) )? $openedFolder : "---";
$this->boolFolder = $boolFolder;
}
function addEntry( $entry ) {
$this->entrys[$entry->name] = $entry;
}
//Display the folder
function show( $names, $indent ) {
if( sizeof( $names ) < 1 ) {
$stringNames == $names[0];
} else {
$stringNames = implode( ",", $names );
}
if( $this->extract( $names ) ) {
print $indent . "<a href=\"" . $PHP_SELF . "toc.php?folder=" .
urlencode( $this->name ) . "&names=" . urlencode( $stringNames );
print ( $this->boolFolder ) ? "\" style=\"text-decoration:none\">"
: "\">";
print $this->openedFolder . "</a> " . $this->name . "\n";
print "<br>\n";
while( $arr = each( $this->entrys ) ) {
$class =& $arr[1];
$class->show( $names, $indent . " " );
}
} else {
print $indent . "<a href=\"" . $PHP_SELF . "toc.php?folder=" .
urlencode( $this->name ) . "&names=" . urlencode( $stringNames );
print ( $this->boolFolder ) ? "\" style=\"text-decoration:none\">"
: "\">";
print $this->closedFolder . "</a> " . $this->name . "\n";
print "<br>\n";
}
}
//Check if folder opened or closed
function extract( $names ) {
$rt = 0;
for( $i = 0; $i < sizeof( $names ); $i ++ ) {
if( strcmp( $this->name, $names[$i] ) == 0 ) {
$rt = 1;
break;
}
}
return $rt;
}
}
class File {
var $name;
var $target;
var $boolFile;
//Create new File
function File( $name, $target, $boolFile ) {
$this->name = $name;
$this->target = $target;
$this->boolFile = $boolFile;
}
//Display the Link
function show( $names, $indent ) {
print $indent . $this->target;
print ( $this->boolFile ) ? "style=\"text-decoration:none\">"
: ">";
print $this->name . "</a>\n";
print "<br>\n";
}
}
//Create the namesArray
$namesArray = array();
$newNamesArray = array();
$close = 0;
if( $names ) {
if( !ereg( ".*,.*", $names ) ) {
$namesArray[0] = $names;
} else {
$namesArray = explode( ",", $names );
}
for( $i = 0; $i < sizeof( $namesArray ); $i ++ ) {
if( strcmp( $folder, $namesArray[$i] ) == 0 ) {
$close = 1;
continue;
}
array_push( $newNamesArray, $namesArray[$i] );
}
}
if( !$close ) { array_push( $newNamesArray, $folder ); }
//Parse the config_toc.txt File and create the objects
$end;
$root = new Dir( $rootClass, $imgClosedFolder, $imgOpenedFolder, $boolFolder );
$classFile;
$IN = fopen( $configFile, "r" );
while( !feof( $IN ) ) {
$line = trim( fgets( $IN, 255 ) );
if( ereg( "#.*", $line ) || strcmp( "", $line ) == 0 ) { continue; }
if( ereg( "<([^/].*)>", $line, $regs ) ) {
$end = "</" . $regs[1] . ">";
if( strcmp( $rootClass, $regs[1] ) == 0 ) {
for(;;) {
$line = trim( fgets( $IN, 255 ) );
if( ereg( "#.*", $line ) || strcmp( "", $line ) == 0 ) { continue; }
if( strcmp( $end, $line ) == 0 ) { break; }
$nameTarget = explode( ",", $line );
$classFile = $nameTarget[0];
$classFile = new File( $nameTarget[0], $nameTarget[1], $boolFile );
$root->addEntry( $classFile );
}
} else {
$name = explode( "|", $regs[1] );
$classDirName = $name[sizeof( $name ) -1 ];
$classDir = new Dir( $classDirName, $imgClosedFolder, $imgOpenedFolder, $boolFolder );
for(;;) {
$line = trim( fgets( $IN, 255 ) );
if( strcmp( $end, $line ) == 0 ) { break; }
$nameTarget = explode( ",", $line );
$classFile = $nameTarget[0];
$classFile = new File( $nameTarget[0], $nameTarget[1], $boolFile );
$classDir->addEntry( $classFile );
}
$parentClass =& $root;
$i = 1;
while( strcmp( $name[$i], $classDir->name ) ) {
$parentClass =& $parentClass->entrys[$name[$i]];
$i ++;
}
$parentClass->addEntry( $classDir );
}
}
}
//Print the table of contents
print "<!doctype html public \"-//W3C//DTD HTML 4.0 //EN\"><html>\n";
print "<head>\n";
print "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n";
print "<meta http-equiv=\"Content-Style-Type\" content=\"text/css\">\n";
print "<meta name=\"description\" content=\"Dynamic Table of Contents for php DynToc-1.0\">\n";
print "<meta name=\"author\" content=\"Juergen Derigs\">\n";
print "<meta name=\"keywords\" content=\"php toc dynamic\">\n";
print "<title>Table of Content</title>\n";
print "</head>\n";
print "<body bgcolor=\"" . $bgColor . "\" background=\"" . $background . "\">\n";
print "<span style=\"color:black; font-size:" . $fontSize . "pt; font-style:arial\"><!--Css-Style for the links-->\n";
print $root->show( $newNamesArray, "" );
print "</span>\n";
print "</body>\n";
print "</html>\n";
?>