<?php
/*
From Ben Stephens - Big Carrot ? on JSHop forums
-------------------
save this with xml extension then add the following
to htaccess to render this xml file as php
--------------------
<Files google_sitemap.xml>
ForceType application/x-httpd-php
</Files>
---------------------------
example sitemap:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
	<url>
		<loc>http://www.mezefood.co.uk/</loc>
		<lastmod>2005-01-01</lastmod>
		<changefreq>monthly</changefreq>
		<priority>0.8</priority>
	</url>  
</urlset>


product.php?xProd=4
section.php?xSec=3

Used to be the default URLs for non SE friendly links
<loc><?php echo $jssStoreWebDirHTTP . 'section.php?xSec=' . $section['sectionID']; ?></loc>
<loc><?php echo $jssStoreWebDirHTTP . 'product.php?xProd=' . $product['productID']; ?></loc>
<loc><?php echo $jssStoreWebDirHTTP . 'page.php?xPage=' . urlencode($page); ?></loc>
<loc><?php echo $jssStoreWebDirHTTP . $extra; ?></loc>
*/

include("static/includeBase_front.php");

function walk_dir($path) {
	if ($dir = opendir($path)) {
		while (false !== ($file = readdir($dir)))
		{
			if ($file[0]==".") continue;
			if (is_file($path."/".$file))
				$retval[]=$path."/".$file;
			}
		closedir($dir);
		}
	return $retval;
}

function get_pages($non_page_templates){
	global $jssShopFileSystem;
	$path = $jssShopFileSystem . 'templates';
	foreach (walk_dir($path) as $file) {
		$file = preg_replace("#//+#", '/', $file);
		$path = preg_replace("#//+#", '/', $path);
		$file = preg_replace("#$path/#", '', $file);
		if (!in_array($file, $non_page_templates)) {
			$files[] = $file;	//adding filenames to array
		}
	}
	return $files;
}

$non_page_templates = array('advsearch.html','affiliateaccount.html','affiliatebanners.html','affiliateedit.html','affiliatelogin.html','affiliatepayments.html','affiliatesales.html','affiliatesignup.html','affiliatesignupthanks.html','affiliatestats.html','cart.html','cartstockproblem.html','checkoutlogin.html','checkoutstep1.html','checkoutstep2.html','checkoutstep3.html','checkoutstep4.html','contact.html','contactsent.html','customeraccount.html','customeraddress.html','customeraddresses.html','customerdetails.html','customerlogin.html','customernew.html','customerorder.html','customerorderlist.html','customerreview.html','customerreviewerror.html','customerreviewthanks.html','customerwishlist.html','databaseproblem.html','downloadproblem.html','forgottenpassword.html','forgottenpasswordsuccess.html','gatewaytransfer.html','giftcertificate.html','giftcert_print.html','giftcheckoutstep1.html','giftcheckoutstep3.html','giftcheckoutstep4.html','help.html','index.html','newsletter.html','newsletteractivation.html','newslettererror.html','newslettersubscribe.html','newsletterunsubscribe.html','orderfailed.html','ordersuccess.html','product.html','productreviews.html','receipt.html','recentview.html','search.html','send2friend.html','section.html','send2friendsent.html','unavailable.html');

$more_non_page_templates = array('AA_links.html','AA_sitemap.html','order-status.html','postcodeanywhere-handler.html','product-moreinfo.html','product-nonlogo.html','product_stock.html','product-personalise-templates.zip','product-personalise-1.html','product-personalise-2.html','receipt-ALANS.html','receipt_VAT.html','section-brochure-form.html','section-brochure-invalid.html','section-brochure-success.html','section-brochure-wrong.html','section-brochure-emptyfield.html','section-customise.html','section-customise-duvets.html','section-customise-embroidery.html','section-customise-kitchen-coordinates.html','section-customise-mats.html','section-customise-printed-towels.html','section-customise-tea-towels.html','section-customise-woven-towels.html','section-ego-feedback-archive.html','section-frames-other-sites-unused.html','section_support.html','section_support_robesizes.html','section_services.html');

$non_page_templates = array_merge($non_page_templates, $more_non_page_templates);

dbConnect($dbA);

$sections = $dbA->retrieveAllRecordsFromQuery("select sectionID from $tableSections where visible = 'Y'");
$products = $dbA->retrieveAllRecordsFromQuery("select productID from $tableProducts where visible = 'Y' or allowDirect = 'Y'");
$pages = get_pages($non_page_templates);
$extras = array('contact.php');


header('Content-type: application/xml');

?>
<?php echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?><urlset xmlns=\"http://www.google.com/schemas/sitemap/0.84\">"; ?>  

<?php foreach($sections as $section){ ?>
	<url>
		<loc><?php echo $jssStoreWebDirHTTP . 'section/' . $section['sectionID'] . '/1' ; ?></loc>
	</url>
<?php } ?>
<?php foreach($products as $product){ ?>
	<url>
		<loc><?php echo $jssStoreWebDirHTTP . 'product/' . $product['productID'] . '' ; ?></loc>
	</url>
<?php } ?>
<?php foreach($pages as $page){ ?>
	<url>
		<loc><?php echo $jssStoreWebDirHTTP . 'page/' . urlencode($page); ?></loc>
	</url>
<?php } ?>
<?php foreach($extras as $extra){ ?>
	<url>
		<loc><?php echo $jssStoreWebDirHTTP . $extra; ?></loc>
	</url>
<?php } ?>
</urlset>