loading

Sitemap Generation tool, 1 tree deep but gets you started

I wanted a simple site map generator for getting static pages (so no dynamic on page ones) quickest method is dir function but I added into some extras such as folder ignore, file type allowance, Change priority of the pages, direct output with your own site url in XML format ready to copy paste to notepad and save as sitemap.xml

This is not the most in depth script in the world but it suited my needs and its pretty tidy for what it does <?PHP
$usetitle 
"Stonerscolony custom Sitemap.xml generator";
include(
"include/top2.php");
// Staged file locator and spit too sitemap output, Only digs 1 branch deep
// Place this file in the root that you wish to start outputting from
// Make sure you set settings parts 1 and 2!, Its pretty straight foward

//Open a text area and dump XML header
echo "<TEXTAREA NAME='output', ROWS=26, COLS=106 wrap='soft'>\n";
echo 
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo 
"<urlset\n";
echo 
"xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n";
echo 
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
echo 
"xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9\n";
echo 
"http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">\n";

//***********************
// SETTINGS PART 1 ********************

$MasterDirdir("./"); // Master directory to start from | Use ("./") for root
$MasterDir2 "./"// Again but as string only
$DoNotSearch = array(".","..","admin","include","forbidden","restricted","images"); // Do not search these directories
//***********************

//Child function for 1 branch scan
function InnerChild($branch){

//***********************
// SETTINGS PART 2 ********************

$SiteURL "http://www.stonerscolony.com";
$UseFiles = array("html","php"); // Set Which Files you wish to be shown on the output
//*****************************

$dir dir($branch);
//List php files in $branch directory
    
while (($file $dir->read()) !== false){
        if (
$file=="." OR $file=="..") {}else{
            
$rr=end(explode("."$file));//Explode for end extention
            
$escapedir=explode(".",$file);//Explode for count, pesky directory catch for those not caught by is_dir
            
$Cescape=count($escapedir);//2 part name and extention, If less than 2 then still a directory
                
if(is_dir($file)||!$rr||$Cescape<2){}else{
                
//Set your own extentions you want included in sitemap output
                    //if($rr=="php" or $rr=="html")                        {
                    
if (in_array($rr$UseFilestrue)) {
                            if(
$branch=="./"){ $branch2 ""; }else{ $branch2 $branch "/"; } //Check if parent or in dir
                            
echo "\n <url>\n";
                            echo 
"        <loc>" $SiteURL "/" $branch2 $file "</loc>";
                            print 
"\n    <priority>0.8</priority>\n    <changefreq>always</changefreq>\n </url>";
                        }
                }            
        }
    }
    
$dir->close();
}

//First spit out the Root directory listings
InnerChild($MasterDir2);

//now do all sub folders
while (($file $MasterDir->read()) !== false){ //Find all folders within master
    
if(is_dir($file)){
            if (
in_array($file$DoNotSearchtrue)) {}else{//Skip dir set as do not search
                
InnerChild($file);
            }
    }
}
$MasterDir->close();
?>

</urlset></TEXTAREA>
<BR /><BR /><font size="3">Save the text as sitemap.xml and your done!</font>
(unrated) | by FaTe on May 11th, 2008

An account is required to post comments and adaptations

unsubscribe from human rights abuse in the war on terror
RIP The Internet 1969-2012 | Powered by: Apache / PHP / MySQL | Made in Ninjapad NX | © defproc.co.uk, 2007_