
December 14th, 2004, 06:15 PM
|
|
Registered User
|
|
Join Date: Jun 2004
Location: Georgia
Posts: 8
Time spent in forums: 1 h 10 m 14 sec
Reputation Power: 0
|
|
|
a Php Sitemap Script
I use a basic php script that I found online. takes a little bit of configuration to exclude directories you don't want indexed and it only lists pages by their filename but it's dynamic so you never need to update it.
I am not sure if this is going to print out right but we will see:
Code:
<?php
$showsize = 0; /* Show size of each file, 1 for yes, 0 for no. */
/* Array with file types to display and the pictures to use.
Syntax: $display['filetype'] = "picture"; */
/*$display['php'] = "php.gif";*/
$display['html'] = "html.gif";
$display['htm'] = "html.gif";
$display['shtml'] = "html.gif";
/* Array with directories to exclude. List as many directories as you want here
Syntax: $excludedir[] = "directory"; */
$excludedir[] = "temp";
$excludedir[] = "cgi-bin";
/* Array with files to exclude. Same syntax as above */
$excludefile[] = "file1.html";
$excludefile[] = "file2.html";
?>
<html lang="en">
<head>
<title>Sitemap</title>
<meta name="description" content="Site map of your website.">
<meta name="robots" content="index,follow">
</head>
<body bgcolor="#000000" text="white" link="#2255FF" visited="magenta">
<b><a href="http://www.yoursite.com">Sitemap for My Website</a></b><br>
<p>
<?php
$stime = gettimeofday();
/* some preliminaries... */
$root = getcwd();
$pre = explode("/", $_SERVER['REQUEST_URI']);
array_pop($pre);
$prefix = join("/", $pre);
/* Uncomment the 2 lines below to create a tree of all files and directories on your webserver if the script
* is in a subdirectory */
//$root = str_replace($prefix, "", $root);
//$prefix = "";
$root .= "/";
/* Display server name and directory */
echo "<table cellspacing=0 cellpadding=0 border=0>\n";
echo "<tr><td><img align=absmiddle src=server.gif> http://".$_SERVER['SERVER_NAME'];
echo "$prefix/";
echo "</td></tr><tr><td><img align=absmiddle src=vertical.gif></td></tr>\n";
function get_extension($name) {
$array = explode(".", $name);
$retval = strtolower(array_pop($array));
return $retval;
}
/* Recursion, here we go.. */
function list_dir($chdir) {
/* some globals, some cleaning */
global $root, $prefix, $showsize, $display, $excludedir, $excludefile;
unset($sdirs);
unset($sfiles);
chdir($chdir);
$self = basename($_SERVER['PHP_SELF']);
/* open current directory */
$handle = opendir('.');
/* read directory. If the item is a directory, place it in $sdirs, if it's a filetype we want
* and not this file, put it in $sfiles */
while ($file = readdir($handle))
{
if(is_dir($file) && $file != "." && $file != ".." && !in_array($file, $excludedir))
{ $sdirs[] = $file; }
elseif(is_file($file) && $file != "$self" && array_key_exists(get_extension($file), $display)
&& !in_array($file, $excludefile))
{ $sfiles[] = $file; }
}
/* count the slashes to determine how deep we're in the directory tree and how many
* nice bars we need to add */
$dir = getcwd();
$dir1 = str_replace($root, "", $dir."/");
$count = substr_count($dir1, "/") + substr_count($dir1, "\\");
/* display directory names and recursively list all of them */
if(is_array($sdirs)) {
sort($sdirs);
reset($sdirs);
for($y=0; $y<sizeof($sdirs); $y++) {
echo "<tr><td>";
for($z=1; $z<=$count; $z++)
{ echo "<img align=absmiddle src=vertical.gif> "; }
if(is_array($sfiles))
{ echo "<img align=absmiddle src=verhor.gif>"; }
else
{ echo "<img align=absmiddle src=verhor1.gif>"; }
echo "<img align=absmiddle src=folder.gif> <a
href=\"http://".$_SERVER['SERVER_NAME']."$prefix/$dir1$sdirs[$y]\">$sdirs[$y]</a>";
list_dir($dir."/".$sdirs[$y]);
}
}
chdir($chdir);
/* iterate through the array of files and display them */
if(is_array($sfiles)) {
sort($sfiles);
reset($sfiles);
$sizeof = sizeof($sfiles);
/* what file types shall be displayed? */
for($y=0; $y<$sizeof; $y++) {
echo "<tr><td>";
for($z=1; $z<=$count; $z++)
{ echo "<img align=absmiddle src=vertical.gif> "; }
if($y == ($sizeof -1))
{ echo "<img align=absmiddle src=verhor1.gif>"; }
else
{ echo "<img align=absmiddle src=verhor.gif>"; }
echo "<img align=absmiddle src=\"";
echo $display[get_extension($sfiles[$y])];
echo "\"> ";
echo "<a href=\"http://".$_SERVER['SERVER_NAME']."$prefix/$dir1$sfiles[$y]\">$sfiles[$y]</a>";
if($showsize) {
$fsize = @filesize($sfiles[$y])/1024;
printf(" (%.2f kB)", $fsize);
}
echo "</td></tr>";
echo "<tr><td>";
}
echo "<tr><td>";
for($z=1; $z<=$count; $z++)
{ echo "<img align=absmiddle src=vertical.gif> "; }
echo "</td></tr>\n";
}
}
list_dir($root);
echo "</table>\n";
/* How long did that need..? */
$ftime = gettimeofday();
$time = round(($ftime[sec] + $ftime[usec] / 1000000) - ($stime[sec] + $stime[usec] / 1000000), 5);
echo "<center>This page was generated in $time seconds.</center>\n";
?>
</body>
</html>
|