/*
+---------------------------------------------------------------------------+
| // smap v 1.01 |
| ========== |
| |
| Copyright (c) 2008 Vladd44.com vladd44@vladd44.com |
| For details, visit: http://forum.vladd44.com/php-scripts-f17.html |
| |
| This program is free software; you can redistribute it and/or modify |
| it under the terms of the GNU General Public License as published by |
| the Free Software Foundation; either version 2 of the License, or |
| (at your option) any later version. |
| |
| This program is distributed in the desire that it be useful, but |
| WITHOUT ANY WARRANTY; without even an implied warranty of USE |
| or PURPOSE. See the GNU General Public License for more details. |
| |
| You should have received a copy of the GNU General Public License |
| along with this script; If not, write to the Free Software |
| Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
+---------------------------------------------------------------------------+
*/
// user variables
session_start();
global $lc;
$password ='6b9e74a5759e951082314f57892c6b3b'; // enter pw here
$url = 'http://'.$_SERVER['HTTP_HOST'].'/sitemap.php';
//SET THE WEB SITE ADDRESS, NO TRAILING SLASH
$webdomain = 'www.vandrielengineering.co.uk';
//SET THE UPDATE DELAY - 10 SEC FOR TESTING, 86400 FOR LIVE
//$cache_time = 86400; // in seconds 86400 is 1 day
$cache_time = 10; // in seconds
$cmap = "sitemap.xml";
$auto_exclude = 'cgi-bin css phpbb2 phpbb3 forum cache scache images yahoo.php robots.txt sitemap.php sitemap_avoid.php temp tmp files twatch twatch_include files scripts/sendform.php';
$accept="(\.html$)|(\.htm$)|(\.php$)|(\.txt$)|(\.shtml$)|(\.asp$)|(\.jsp$)|(\.cgi$)"; //valid file extensions
$rid = "sitemap_avoid.php";
$email =''; // add email address here if you wish to be emailed when google sitemap adds or removes pages (suggested)
// functions
function out_xml($file, $dir, $domain, $priority, $freq, $dates) {
global $lc;
$cdate = time();
$fc.=' '.$file;
$priority = '0.5';
if ($dir){
$file = $dir.'/'.$file;
}
if (preg_match("/\bindex./i", $file) && !strrchr($file, '/')) {
$priority = '1.0';
}
$dates = date("Y-m-d",filemtime($file));
$numdate = date(filemtime($file));
$freq = 'Monthly';
if ($cdate-$numdate<86400){
$freq = 'Daily';
} elseif ($cdate-$numdate<604800) {
$freq = 'Weekly';
}
$file = str_replace("&","&",$file);
$lc++;
echo "
http://$domain/$file
$dates
$freq
$priority
";
}
$cdate = time();
// add password...force if empty
if (!$password && !$_POST["pass"]){
echo 'Leaving the password blank is not an option
';
exit;
} elseif (!$password && $_POST["pass"]){
$epass = md5(htmlspecialchars($_POST["pass"]));
echo 'Please enter '.$epass.' in the place provided in line 27. This is the md5 encryption for the password of your choice nd upload this script again. '.htmlspecialchars($_POST["pass"]).'';
exit;
}
// print out sitemap if no login
if (file_exists($cmap)) {
$exdate = $cdate-date(filemtime($cmap));
}
if (!$_GET["login"] && file_exists($cmap)){
$cfile = fopen($cmap, 'r');
$themap = fread($cfile, filesize($cmap));
fclose($cfile);
if ($exdate<$cache_time){
header("Content-Type: text/xml;charset=iso-8859-1");
echo $themap;
exit;
}
// if file does not exist
} elseif (!$_GET["login"] && !file_exists($cmap) && !file_exists($rid)){
echo 'Parameters not set, Please Login';
exit;
}
//get session pw if exists
if ($_GET["login"] && md5($_POST["pword"])<>$password && $_SESSION['pw'] ){
$_POST["pword"] = $_SESSION['pw'];
}
// if login pw is empty or incorrect
if ($_GET["login"] && md5($_POST["pword"])<>$password){
echo "";
exit;
}
$_SESSION['pw'] = $_POST["pword"];
if ( $_POST["fofi"]){
$avoid = implode(' ', $_POST["fofi"]); // get post data for files to be avoided.
}
if (($_POST["finished"] || $exdate>($cache_time-1)) || (file_exists($rid) && !file_exists($cmap))){
// $domain = $_SERVER['HTTP_HOST'];
$domain = $webdomain;
// get cached avoid values from file
if (!$_POST["fofi"] && filesize($rid)>0 ) {
$rfile = fopen($rid, 'r');
$avoid = fread($rfile, filesize($rid));
fclose($rfile);
}
// output xml for export etc
ob_start();
echo '
';
// go through root and included folders
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (is_dir($file) && !preg_match("/\b$file\b/i", $avoid )) { //dir
$dc.=' '.$file;
// folder get the files
$dir =$file;
$dh = opendir($dir);
while (($file = readdir($dh)) !== false) {
if(eregi($accept, $file) && !preg_match("/\b$file\b/i", $avoid)) { //if this file is a valid file
out_xml($file, $dir, $domain, $priority, $freq, $dates);
}}
closedir($dh);
unset($dir);
} elseif(eregi($accept, $file) && !preg_match("/\b$file\b/i", $avoid)) { //if this file is a valid file
out_xml($file, $dir, $domain, $priority, $freq, $dates);
}}}
closedir($handle);
}
echo ' ';
$new_map = ob_get_contents();
ob_end_clean();
// output cache to file
$fi = fopen($cmap, 'w') or die("Can't open file");
fwrite($fi, $new_map);
fclose($fi);
if ($themap<> $new_map) {
// send email if email address setup
if ($email) {
mail($email, $_SERVER['HTTP_HOST'].' Sitemap changed', "sitemap.php has updated and now includes $lc Pages in your sitemap");
}
// ping google if sitemap changed
if( $frep=@fsockopen('www.google.com', 80) )
{
$request = 'GET /webmasters/tools/ping?sitemap=' .
urlencode( $url ) . " HTTP/1.1\r\n" .
"Host: www.google.com\r\n" .
"User-Agent: Mozilla/5.0 (compatible; " .
PHP_OS . ") PHP/" . PHP_VERSION . "\r\n" .
"Connection: Close\r\n\r\n";
fwrite( $frep, $request );
fclose( $frep );
}}
if (!$_POST["finished"]){ // if sitemap was deleted, but avoid.php exists
header("Content-Type: text/xml;charset=iso-8859-1");
echo $new_map;
exit;
}
// output files/dirs to be avoided to file
if ($_POST["finished"]){
$fi = fopen($rid, 'w') or die("Can't open file");
fwrite($fi, $avoid);
fclose($fi);
echo "Google Sitemap complete!! with a total of $lc Links
Click here to view New Sitemap";
session_destroy();
exit;
} elseif ($exdate>($cache_time-1)) {
header("Content-Type: text/xml;charset=iso-8859-1");
echo $new_map;
}
// end of sitemap output
} else {
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (is_dir($file)) { //dir
$dc.=' '.$file;
} elseif(eregi($accept, $file)) { //if this file is a valid file
$fc.=' '.$file;
}}}
closedir($handle);
}
// output
$al = $dc.' '.$fc;
$allz = explode(' ',$al);
echo "Step 1. Please check the first box for each folder you do not wish to include in sitemap.
Submitting without checking the finished box will highlight the currently checked choices, making it easier to verify what is checked and what is not.';
}
?>