GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 05-Feb-2006, 12:42
ccannon ccannon is offline
New Member
 
Join Date: Feb 2006
Location: Vancouver, BC
Posts: 1
ccannon is on a distinguished road

a php sitemap that's almost perfect


hi there, i was looking everywhere for a good php sitemap and finally i found this great script by Mystic Dreams. it does a recursive directory and file listing with links, which is great, but i'd like to a) be able to replace "_" underscores with spaces in file and directory names, and b) remove file extensions from file names. i spent a few hours yesterday trying to tweak it myself and concluded i really don't know how. so, i'm hoping someone can help. here's the include script:

PHP Code:

<?php
////////////////////////////////////////////////////////////////////////////////
//
// EzMap - Sitemap System
// sitemap.php
// Sitemap for your website
// Date Created : 15 October, 2003
// Last Modified: 31 October, 2005
//
// Version 1.01
//
// * This script is released under the terms of the GNU General Public License. 
// A copy of the GPL is included with this script.
//
// * Mystic Dreams Enterprises - http://www.mysticdreams.net
//
////////////////////////////////////////////////////////////////////////////////

/////NOTE "dirStyle" is class name for directory headings
/////NOTE "fileStyle" is class name for directory headings


// User configuration
// Show size of each file, 1 for YES, 0 for NO
$showsize = 0;


//relative path to image files directory (note leave off the leading slash "/"
$imagePath = "images/sitemap2/";

// Array with file types to display and the images to use.
// Syntax: $display['filetype'] = "image";
$display['php'] = $imagePath."php.gif";
$display['html'] = $imagePath."html.gif";
$display['htm'] = $imagePath."html.gif";
$display['shtml'] = $imagePath."html.gif";

// Array with directories to exclude.
// Syntax: $excludedir[] = "directory";
$excludedir[] = "cgi-bin";
$excludedir[] = "css";
$excludedir[] = "images";

// Array with files to exclude.
// Syntax: $excludefile[] = "filename";
$excludefile[] = "_randomText.html";
$excludefile[] = "_rungTest.html";


$stime = gettimeofday();

// Set some important stuff
$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 width=\"80%\" class=\"sitemap_tag2\" align=\"center\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">\n";
echo "<tr><td><img align=\"absmiddle\" src=\"".$imagePath."server.gif\" border=\"0\"> <b>http://".$_SERVER['SERVER_NAME'];
echo "$prefix/";
echo "</b></td></tr><tr><td><img align=\"absmiddle\" src=\"".$imagePath."vertical.gif\" border=\"0\"></td></tr>\n";

function get_extension($name) {
$array = explode(".", $name);
$retval = strtolower(array_pop($array));
return $retval;
}

// Recursion! And away we go...
// Set some globals and clean up a bit...
// What a pig...
function list_dir($chdir) {
global $root, $prefix, $showsize, $display, $excludedir, $excludefile, $imagePath;
unset($sdirs);
unset($sfiles);
chdir($chdir);
$self = basename($_SERVER['PHP_SELF']);

// Open the current directory
$handle = opendir('.');
// Read directory. If the item is a directory, place it in $sdirs.
// If it's a filetype we want, 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.
// Add lines to make it pretty.
$dir = getcwd();
$dir1 = str_replace($root, "", $dir."/");
$count = substr_count($dir1, "/") + substr_count($dir1, "\\");


//DIRECTORY LISTING SECTION...        
// Display directory names and recursively list 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=\"".$imagePath."vertical.gif\" border=\"0\">&nbsp;&nbsp;&nbsp;"; }
if(is_array($sfiles))
{ echo "<img align=\"absmiddle\" src=\"".$imagePath."verhor.gif\" border=\"0\">"; }
else
{ echo "<img align=\"absmiddle\" src=\"".$imagePath."verhor1.gif\" border=\"0\">"; }
echo "<span class=\"dirStyle\">";
echo "<img align=\"absmiddle\" src=\"".$imagePath."folder.gif\" border=\"0\"><a href=\"http://".$_SERVER['SERVER_NAME']."$prefix/$dir1$sdirs[$y]\" target=\"_top\">$sdirs[$y]</a>";
echo "</span>";
list_dir($dir."/".$sdirs[$y]);

}
}
           
chdir($chdir);

//FILE LISTING SECTION...

// Run through the array of files and show them.
if(is_array($sfiles)) {
sort($sfiles);
reset($sfiles);
                 
$sizeof = sizeof($sfiles);
             
// What file types shall we display?
for($y=0; $y<$sizeof; $y++) {
echo "<tr><td>";
for($z=1; $z<=$count; $z++)
{ echo "<img align=\"absmiddle\" src=\"".$imagePath."vertical.gif\" border=\"0\">&nbsp;&nbsp;&nbsp;"; }
if($y == ($sizeof -1))
{ echo "<img align=\"absmiddle\" src=\"".$imagePath."verhor1.gif\" border=\"0\">"; }
else
{ echo "<img align=\"absmiddle\" src=\"".$imagePath."verhor.gif\" border=\"0\">"; }
echo "<img align=\"absmiddle\" src=\"";
echo $display[get_extension($sfiles[$y])];
echo "\" border=\"0\"> ";
echo "<span class=\"fileStyle\">";
echo "<a href=\"http://".$_SERVER['SERVER_NAME']."$prefix/$dir1$sfiles[$y]\" target=\"_top\">$sfiles[$y]</a>";
echo "</span>";
if($showsize) {
$fsize = @filesize($sfiles[$y])/1024;
printf(" (%.2f kB)", $fsize);
}
echo "</td></tr>";
            
}
echo "<tr><td>";
for($z=1; $z<=$count; $z++)
{ echo "<img align=\"absmiddle\" src=\"".$imagePath."vertical.gif\" border=\"0\">&nbsp;&nbsp;&nbsp;"; }
echo "</td></tr>\n"; 
}
}

list_dir($root);

echo "</table><br>\n";

// How long did that take?
$ftime = gettimeofday();
$time = round(($ftime[sec] + $ftime[usec] / 1000000) - ($stime[sec] + $stime[usec] / 1000000), 5);
echo "<div align=\"center\" class=\"sitemap_tag2\">This page was generated in $time seconds.</div>\n";

?>


let me know if this is something you can help with.

cheers,

-Chris
Last edited by cable_guy_67 : 05-Feb-2006 at 12:45. Reason: Please enclose php code in [php] ... [/php] tags
 
 

Recent GIDBlogNARMY by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP - sizes and generation times cable_guy_67 MySQL / PHP Forum 3 29-Sep-2005 08:26
Help ! I need help starting up on Php ! onauc MySQL / PHP Forum 11 04-Jan-2005 23:57
uisng php to display php dopee MySQL / PHP Forum 6 14-May-2004 18:40
php software dopee MySQL / PHP Forum 0 04-May-2004 11:26
All the big PHP script collections that matter jrobbio MySQL / PHP Forum 5 06-Jun-2003 16:14

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 02:08.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.