<?php
/*--------------------------------------------------+

| X-ZERO DYNAMIC SITEMAP MOD  1.0.2                 |

+===================================================+

| File: sitemap.php                                 |

| Mod to pull category sitemap                      |

+---------------------------------------------------+

| Copyright © 2008 David (FuNEnD3R)                 |

| Email: admin@funender.com                         |

+--------------------------[ Tue, Apr 29, 2008 ]---*/


require_once("initvars.inc.php");

require_once("config.inc.php");



$get_id = intval($_GET["id"]);
$get_type = trim(htmlspecialchars($_GET["type"]));


$schema1 = ( $get_type != 'city' ) ?  "sitemapindex" : "urlset";
$schema2 = ( $get_type != 'city' ) ?  "/sitemapindex" : "/urlset";
$map1 = ( $get_type != 'city' ) ?  "sitemap" : "url";
$map2 = ( $get_type != 'city' ) ?  "/sitemap" : "/url";



if ( $get_type == 'city' )
{
	$url_set = "<changefreq>$change_freq</changefreq>\n<!-- <priority>$priority</priority> -->\n";
	
	$res = mysql_query("SELECT a.catid, a.subcatid, a.subcatname, a.timestamp, b.catname 
						FROM $t_subcats a, $t_cats b
						WHERE a.catid = b.catid 
						ORDER BY subcatname ASC");
}
else
{
	$url_set = '';
	
	$res = mysql_query("SELECT cityid, timestamp FROM $t_cities ORDER BY cityid ASC");
}


echo '<?xml version="1.0" encoding="UTF-8"?>';
echo "\n<$schema1 xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";



while($row = mysql_fetch_array($res))
{

	switch($get_type)
	{
	   case "city":
	
		  if ( $link_type == 1 )
		  {
		  	  $row = mysql_fetch_array($res);
			  $url = $script_url."/{$vbasedir}".$get_id."/posts/%d_".RemoveBadURLChars($row['catname'])."/%d_%s/";
		  }
		  else
		  {
			  $url = $script_url."/".$get_id."/posts/%d/%d-%s.html";
		  } 
		  
		  break;
	   default:
		  
		  $url = $script_url."/sitemap-city-%s.xml";
		  
		  break;
	}

    $date = date("Y-m-d"); //substr($row["timestamp"], 0, -9);
    echo "<$map1>\n";
    printf("<loc>".$url."</loc>\n<lastmod>".$date."</lastmod>\n", $row[0], $row[1], RemoveBadURLChars($row[2]), $row[3]);
    echo $url_set;
    echo "<$map2>\n";

}

echo "<$schema2>";


?>