<?PHP include ("./vsadmin/db_conn_open.php");
mysql_select_db($db_name, $dbh);
//
//		******************************************************************************************************
// 		*  Google Sitemap XML Generator                                                                      *
// 		*  Version 1.0.0                                                                                     *
// 		*  Designed and written by PC4PEOPLE.com                                                             *
// 		*  This code is copyright (c) PC4PEOPLE, LLC, all rights reserved.                                   *
// 		*  The contents of this file are protect under law as the intellectual property of PC4PEOPLE, LLC.   *
// 		*  Any use, reproduction, disclosure or copying                                                      *
// 		*  of any kind without the express and written permission of PC4PEOPLE, LLC is forbidden.            *
// 		******************************************************************************************************
//
// ****CHANGE THESE VALUES AS YOU SEE FIT****
//
$frequencypID = "hourly"; //The frequency with which the product detail URL is likely to change. This is considered a hint and not a command. The value must be one of "always", "hourly", "daily", "weekly", "monthly", "yearly", or "never".
$tcatfrequencypID = "daily";//The frequency with which the Top Category pages URL is likely to change. This is considered a hint and not a command. The value must be one of "always", "hourly", "daily", "weekly", "monthly", "yearly", or "never".
$catfrequencypID = "weekly";//The frequency with which the Category pages URL is likely to change. This is considered a hint and not a command. The value must be one of "always", "hourly", "daily", "weekly", "monthly", "yearly", or "never".
$staticfrequencypID = "weekly";//The frequency with which the static pages URL is likely to change. This is considered a hint and not a command. The value must be one of "always", "hourly", "daily", "weekly", "monthly", "yearly", or "never".
$priorityID = "1.0";//The priority of product detail pages relative to other pages on the same site. The value is a number between 0.0 and 1.0, where 0.0 is the lowest priority and 1.0 is the highest priority. The priority can affect the order that search engines select URLs to explore on your site. Since the priority is relative, it is only used to select between URLs within your own site; the priority of your pages will not be compared to the priority of pages on other sites. 
$tcatpriorityID = "0.8";//The priority of Top Category pages relative to other pages on the same site. The value is a number between 0.0 and 1.0, where 0.0 is the lowest priority and 1.0 is the highest priority. The priority can affect the order that search engines select URLs to explore on your site. Since the priority is relative, it is only used to select between URLs within your own site; the priority of your pages will not be compared to the priority of pages on other sites. 
$catpriorityID = "0.7";//The priority of Category pages relative to other pages on the same site. The value is a number between 0.0 and 1.0, where 0.0 is the lowest priority and 1.0 is the highest priority. The priority can affect the order that search engines select URLs to explore on your site. Since the priority is relative, it is only used to select between URLs within your own site; the priority of your pages will not be compared to the priority of pages on other sites. 
$staticpriorityID = "0.8";//The priority of static pages relative to other pages on the same site. The value is a number between 0.0 and 1.0, where 0.0 is the lowest priority and 1.0 is the highest priority. The priority can affect the order that search engines select URLs to explore on your site. Since the priority is relative, it is only used to select between URLs within your own site; the priority of your pages will not be compared to the priority of pages on other sites. 
//
// Define exception files and folders.
//
//	Examples:
//	"./somedir/index.php"	    // unique exception (hides the single file: ./somedir/index.php )
//	"./some/other/folder/" 		// unique exception (hides single folder:./some/other/folder/)
//	".htaccess"    				// global exception (hides all .htaccess's)
//	"somedir/" 					// global exception (hides all somedir/'s)
//
$exceptions = array(
"inccatalog.php",
"google.xml",
"google2.xml",
"install.php",
"testpage.php",
"updatestore.php",
"config.php",
"thanks_old.php",
".htaccess",
".htpasswd",
"cart.php",
"sorry.php",
"proddetail.php",
"prodqu.php",
"code.php",
"mainwebsite_html",
"thanks.php",
//
//Don't Change
".".$_SERVER['PHP_SELF'],	// hiding this file
"/"							// hide / for good measure
    );
//
// **** Define a specific file extension that you always want invisible ****
//
// **** Examples: ****
// "php",	// excludes all *.php files
// "desc",  // excludes all *.desc files
//
//
$exceptionClasses = array(
//"php",
//"phtml",
	"jpg",
	"shtml",
	"html",
	"gif",
	"bmp",
	"zip",
	"js",
	"css",
	"ico",
	"LOG",
	"bak",
	"txt",
	"tar[1]",
	"LCK",
	"db"
	);
$calcExceptions = 	FALSE; 	
$displayFullRoot = 	FALSE;		
$rootdir='/var/www/html';										
$root = "./"; // script root dir reference
$path = (isset($_GET['path'])) ? $_GET['path'] : $root; // get path from 'get'
// security modding
if ($path == '/') $path = $root; // hijack the / to stop real root access, need to hijack everything else somehow.
if(!is_dir(".".str_replace('.','',$path))) $path = $root; // hijack everything else that isnt below the cwd.
$dirPieces = explode("/", $path); // if someone tries to go up a parent directory (..), refer to root instead 
for ($i=0; $i<sizeof($dirPieces); $i++) { if ($dirPieces[$i] == ".." || $dirPieces[$i] == "...") { $path = $root; break; } }
if (substr($path, -1) != "/") $path .= "/"; // if path does not have a trailing slash, add one
$path = preg_replace("/\/\//", "/", $path); // if path has two slashes in succession, eliminate one
$dir_handle = @opendir($path);
if(!$dir_handle) { $dir_handle = @opendir($root); $path=$root; } // if folder isn't there, go back to root
// get amount of files, dirs, and formatted size
function getSize($dir) {
global $exceptions, $exceptionClasses, $calcExceptions;
$files = 0;
$dirs = 0;
$memory = 0;
$hidden = 0;
	if ($dir_handle = @opendir($dir)) {
	   while ($file = readdir($dir_handle)) {
		   if($file != "." && $file != "..") {
		    $dir .= "/";
			$dir = preg_replace("/\/\//", "/", $dir); // error check: makes sure there are no double slashes
			if (is_dir($dir.$file)) { $dir.$file .= "/"; } // add a slash to directories
				if(@is_dir($dir.$file)) {
				   if (!$calcExceptions) { if (in_array($dir, $exceptions) || in_array($file, $exceptions) || in_array($dir.$file, $exceptions)) continue; } // skip if exception
				   $sizeBuild = getSize($dir.$file);
				   $files +=  $sizeBuild[0];
				   $dirs +=  $sizeBuild[1];
				   $memory +=  $sizeBuild[2];
				   $dirs++;
			   } else {
				     if (!$calcExceptions) { $fileExt = ereg_replace("^.+\\.([^.]+)$", "\\1", $file); if (in_array($file, $exceptions)  || in_array($fileExt, $exceptionClasses) || in_array($dir.$file, $exceptions)) continue; } // skip if exception
				   $memory += @filesize($dir.$file);
				   $files++;
			   }
		   }
	   }
	closedir($dir_handle);
	}
	$size[0] = $files;
	$size[1] = $dirs;
	$size[2] = $memory;
	$size[3] = $hidden;
	return $size;
}
$i=0;
$j=0;
while ($file = readdir($dir_handle)) { // Loop through everything in the selected $path
	if($file != "." && $file != "..") {
	if (is_dir($path.$file)) { $path.$file .= "/"; } // add a slash to directories
	$fileExt = ereg_replace("^.+\\.([^.]+)$", "\\1", $file);
		if(in_array($fileExt, $exceptionClasses) || in_array($path.$file, $exceptions) || in_array($file, $exceptions) || in_array($path, $exceptions)) continue;
			if (is_dir($path.$file)) { // if file is a directory, add to the $dirs array, increment the counter, and continue
				$file = preg_replace("/\//", "", $file);
				$dirs[$j] = $file;
				$j++;
				continue;
			}
			$files[$i] = $file; // if file, add to the $files array and increment the counter
			$i++;
		}
}
closedir($dir_handle); // close directory
//get date of current
$datecurrent = date('Y-m-d'); //The current time the URL for last modified in ISO 8601 format
//Select store URL from Admin
$rootname = mysql_query("SELECT adminStoreURL FROM admin");
while ($root = mysql_fetch_array($rootname)) {
$rootnamefinal = $root['adminStoreURL'];
}
$isoLastModifiedSite = "";
$newLine = "\n";
$indent = " ";
if (!$rootUrl) $rootUrl = $rootnamefinal;
$xmlHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
$urlsetOpen = "<urlset xmlns=\"http://www.google.com/schemas/sitemap/0.84\" 
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 
xsi:schemaLocation=\"http://www.google.com/schemas/sitemap/0.84 
http://www.google.com/schemas/sitemap/0.84/sitemap.xsd\">$newLine";
$urlsetValue = "";
$urlsetClose = "</urlset>$newLine";
function makeUrlString ($urlString) {
    return htmlentities($urlString, ENT_QUOTES, 'UTF-8'); 
}
function makeIso8601TimeStamp ($dateTime) {
    if (!$dateTime) {
        $dateTime = date('Y-m-d H:i:s');
    }
    if (is_numeric(substr($dateTime, 11, 1))) {
        $isoTS = substr($dateTime, 0, 10) ."T" 
                 .substr($dateTime, 11, 8) ."+00:00";
    }
    else {
        $isoTS = substr($dateTime, 0, 10);
    }
    return $isoTS;
}
function makeUrlTag ($url, $modifiedDateTime, $changeFrequency, $priority) {
    GLOBAL $newLine;
    GLOBAL $indent;
    GLOBAL $isoLastModifiedSite;
    $urlOpen = "$indent<url>$newLine";
    $urlValue = "";
    $urlClose = "$indent</url>$newLine";
    $locOpen = "$indent$indent<loc>";
    $locValue = "";
    $locClose = "</loc>$newLine";
    $lastmodOpen = "$indent$indent<lastmod>";
    $lastmodValue = "";
    $lastmodClose = "</lastmod>$newLine";
    $changefreqOpen = "$indent$indent<changefreq>";
    $changefreqValue = "";
    $changefreqClose = "</changefreq>$newLine";
    $priorityOpen = "$indent$indent<priority>";
    $priorityValue = "";
    $priorityClose = "</priority>$newLine";
    $urlTag = $urlOpen;
    $urlValue     = $locOpen .makeUrlString("$url") .$locClose;
    if ($modifiedDateTime) {
     $urlValue .= $lastmodOpen .makeIso8601TimeStamp($modifiedDateTime) .$lastmodClose; 
     if (!$isoLastModifiedSite) { // last modification of web site
         $isoLastModifiedSite = makeIso8601TimeStamp($modifiedDateTime); 
     } 
    }
    if ($changeFrequency) {
     $urlValue .= $changefreqOpen .$changeFrequency .$changefreqClose; 
    }
    if ($priority) {
     $urlValue .= $priorityOpen .$priority .$priorityClose; 
    }
    $urlTag .= $urlValue;
    $urlTag .= $urlClose;
    return $urlTag;
}
if (!$isoLastModifiedSite) { // last modification of web site
    $isoLastModifiedSite = makeIso8601TimeStamp(date('Y-m-d H:i:s'));

for ($i=0; $i < sizeof($files); $i++){
$urlsetValue .= makeUrlTag ("$rootUrl"."$files[$i]", $isoLastModifiedSite, "$staticfrequencypID", "$staticpriorityID");
}

//Get Top Categories Pages
$topcats=mysql_query("SELECT sectionID FROM sections WHERE rootSection = 0 ORDER BY sectionID") or print(mysql_error());
while ($tcats = mysql_fetch_array($topcats)) {
$topcatsid = $tcats['sectionID'];

//Print Top Categories on the screen and setup XML output
$output2 = $rootnamefinal . "categories.php?cat=$topcatsid";
$urlsetValue .= makeUrlTag ($output2, $isoLastModifiedSite, "$tcatfrequencypID", "$tcatpriorityID");
}

//Select Categories 
$cats2=mysql_query("SELECT sectionID FROM sections WHERE rootSection > 0 ORDER BY sectionID");
while ($catssecond = mysql_fetch_array($cats2)) {
$catsproducts = $catssecond['sectionID'];

//Print categories on screen and setup textfile output
$output3 = $rootnamefinal . "products.php?cat=$catsproducts";
$urlsetValue .= makeUrlTag ($output3, $isoLastModifiedSite, "$catfrequencypID", "$catpriorityID");
}

//Get Product Details Pages
$products = mysql_query("SELECT pID FROM products");
while ($prod2 = mysql_fetch_array($products)) {
$productdetail = $prod2['pID'];

//Print products on the screen and setup XML output
$output = $rootnamefinal . "proddetail.php?prod=$productdetail";
$urlsetValue .= makeUrlTag ($output, $isoLastModifiedSite, "$frequencypID", "$priorityID");
}
print"$xmlHeader
$urlsetOpen
$urlsetValue
$urlsetClose
";
}
//make sure this is the last line ?>