<? 
//error_reporting(E_STRICT);
require_once('tp_globais.php');
require_once('js/conn.php'); 
require_once('js/funcoes.php');  // Necessita da função "FormatarURL"


if (isset($_GET['country'])) $MM_CountryISO = strtolower($_GET['country']);
elseif (isset($_GET['z'])) $MM_CountryISO = strtolower($_GET['z']);
else $MM_CountryISO = "pt";

header ("Content-Type: text/xml");

echo '<?xml version="1.0" encoding="utf-8"?>';
?>
<urlset
      xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
            http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc><? echo $_ENV['URL_']?></loc>
<lastmod><? echo gmdate("Y-m-d\TH:i:s");?>+00:00</lastmod>
<changefreq>daily</changefreq>
<priority>1.00</priority>
</url>
<url>
<loc><? echo "{$_ENV['URL_']}/{$_ENV['CONTACTOS_']}/$MM_CountryISO"?></loc>
<lastmod><? echo gmdate("Y-m-d\TH:i:s");?>+00:00</lastmod>
<changefreq>daily</changefreq>
<priority>0.96</priority>
</url>
<url>
<loc><? echo "{$_ENV['URL_']}/$MM_CountryISO"?></loc>
<lastmod><? echo gmdate("Y-m-d\TH:i:s");?>+00:00</lastmod>
<changefreq>daily</changefreq>
<priority>0.94</priority>
</url>
<url>
<loc><? echo "{$_ENV['URL_']}/{$_ENV['ANUNCIAR_']}/$MM_CountryISO"?></loc>
<lastmod><? echo gmdate("Y-m-d\TH:i:s");?>+00:00</lastmod>
<changefreq>daily</changefreq>
<priority>0.93</priority>
</url>
<url>
<loc><? echo "{$_ENV['URL_']}/{$_ENV['REG_']}/$MM_CountryISO"?></loc>
<lastmod><? echo gmdate("Y-m-d\TH:i:s");?>+00:00</lastmod>
<changefreq>daily</changefreq>
<priority>0.93</priority>
</url>
<url>
<loc><? echo "{$_ENV['URL_']}/rss.php?country=$MM_CountryISO";?></loc>
<lastmod><? echo gmdate("Y-m-d\TH:i:s");?>+00:00</lastmod>
<changefreq>daily</changefreq>
<priority>0.93</priority>
</url>
<?
	
	$query = "SELECT * FROM conteudo WHERE country = '$MM_CountryISO'";
	$tabela = mysql_query($query, $conn) or die(mysql_error());
	$linhas = mysql_fetch_assoc($tabela);
	$totallinhas = mysql_num_rows($tabela);
	
	if($totallinhas>0) {
		do{
			$url = "{$_ENV['URL_']}/{$linhas['id']}/".FormatarURL($linhas['titulo']);
			echo "<url>\n";
			echo "<loc>$url</loc>\n";
			echo "<lastmod>" . gmdate("Y-m-d\TH:i:s", strtotime($linhas['data_registo'])) . "+00:00</lastmod>\n";
			echo "<changefreq>weekly</changefreq>\n";
			echo "<priority>0.90</priority>\n";
			echo "</url>\n";	
		}while ($linhas = mysql_fetch_assoc($tabela));
	}
	
	
	mysql_free_result($tabela);
?>
</urlset>
