<?php
# IronShop.fr - Google SiteMap XML
if ( !defined('XCART_SESSION_START') ) { header("Location: ../../"); die("Access denied"); }
if (!isset($config["Google_SiteMap"])) {
db_query("DELETE FROM xcart_config WHERE name='iron_sitemap'");
db_query("DELETE FROM xcart_config WHERE name='iron_sitemap_time'");
db_query("INSERT INTO xcart_config (name, comment, value, category, orderby, type) VALUES ('iron_sitemap', 'IronShop.fr - Google SiteMap XML', 'Y', 'Google_SiteMap', '10', 'checkbox')");
db_query("INSERT INTO xcart_config (name, comment, value, category, orderby, type) VALUES ('iron_sitemap_links', 'Additional URLs. Please, dont add here links to products, categories, brands and static pages. Changes will be added to sitemap.xml only on next day after you save it.', '".$http_location."/help.php?section=business\r\n".$http_location."/help.php?section=conditions\r\n".$http_location."/register.php\r\n".$http_location."/help.php?section=Password_Recovery', 'Google_SiteMap', '20', 'textarea')");
db_query("INSERT INTO xcart_config (name, comment, value, category, orderby, type) VALUES ('iron_sitemap_time', 'IronShop.fr - Google SiteMap XML', '0', '', '0', 'text')");
}
if ($config["Google_SiteMap"]["iron_sitemap"] != "Y")
return;
$xm_today = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
if ($xm_today == $config["iron_sitemap_time"])
return;
$filename = '../sitemap.xml';
if(!$fp = fopen($filename, 'w')) {
print "Cannot open file ($filename)";
exit;
}
db_query("UPDATE $sql_tbl[config] SET value='$xm_today' WHERE name='iron_sitemap_time'");
$today = date("Y-m-d");
$xml = '<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>'.$http_location.'/</loc>
<lastmod>'.$today.'</lastmod>
<changefreq>monthly</changefreq>
<priority>1.0</priority>
</url>';
if ($config['SEO']['clean_urls_enabled'] == "N") {
$cats = func_query("SELECT * FROM $sql_tbl[categories] WHERE avail='Y'");
$mans = func_query("SELECT * FROM $sql_tbl[manufacturers] WHERE avail='Y'");
$prods = func_query("SELECT * FROM $sql_tbl[products] WHERE forsale='Y'");
$pages = func_query("SELECT * FROM $sql_tbl[pages] WHERE active='Y' AND padeid!=8");
}
else {
$cats = func_query("SELECT $sql_tbl[categories].*, $sql_tbl[clean_urls].clean_url FROM $sql_tbl[categories], $sql_tbl[clean_urls] WHERE $sql_tbl[categories].avail='Y' AND $sql_tbl[clean_urls].resource_type = 'C' AND $sql_tbl[clean_urls].resource_id = $sql_tbl[categories].categoryid");
$mans = func_query("SELECT $sql_tbl[manufacturers].*, $sql_tbl[clean_urls].clean_url FROM $sql_tbl[manufacturers], $sql_tbl[clean_urls] WHERE $sql_tbl[manufacturers].avail='Y' AND $sql_tbl[clean_urls].resource_type = 'M' AND $sql_tbl[clean_urls].resource_id = $sql_tbl[manufacturers].manufacturerid");
$prods = func_query("SELECT $sql_tbl[products].*, $sql_tbl[clean_urls].clean_url FROM $sql_tbl[products], $sql_tbl[clean_urls] WHERE $sql_tbl[products].forsale='Y' AND $sql_tbl[clean_urls].resource_type = 'P' AND $sql_tbl[clean_urls].resource_id = $sql_tbl[products].productid");
$pages = func_query("SELECT $sql_tbl[pages].*, $sql_tbl[clean_urls].clean_url FROM $sql_tbl[pages], $sql_tbl[clean_urls] WHERE $sql_tbl[pages].active='Y' AND $sql_tbl[clean_urls].resource_type = 'S' AND $sql_tbl[clean_urls].resource_id = $sql_tbl[pages].pageid AND $sql_tbl[pages].pageid != 8");
}
if (is_array($cats[0]))
foreach($cats as $ca) {
if ($ca["clean_url"] == "")
$url = $http_location.'/home.php?cat='.$ca["categoryid"];
else
$url = $http_location.'/'.$ca["clean_url"];
$xml .= '<url>
<loc>'.$url.'</loc>
<lastmod>'.$today.'</lastmod>
<changefreq>monthly</changefreq>
<priority>0.8</priority>
</url>';
}
if (is_array($mans[0]))
foreach($mans as $ma) {
if ($ca["clean_url"] == "")
$url = $http_location.'/manufacturers.php?manufacturerid='.$ma["manufacturerid"];
else
$url = $http_location.'/'.$ma["clean_url"];
$xml .= '<url>
<loc>'.$url.'</loc>
<lastmod>'.$today.'</lastmod>
<changefreq>monthly</changefreq>
<priority>0.8</priority>
</url>';
}
if (is_array($prods[0]))
foreach($prods as $pr) {
if ($pr["clean_url"] == "")
$url = $http_location.'/product.php?productid='.$pr["productid"];
else
$url = $http_location.'/'.$pr["clean_url"];
$xml .= '<url>
<loc>'.$url.'</loc>
<lastmod>'.$today.'</lastmod>
<changefreq>monthly</changefreq>
<priority>0.6</priority>
</url>';
}
if (is_array($pages[0]))
foreach($pages as $pa) {
if ($pa["clean_url"] == "")
$url = $http_location.'/pages.php?pageid='.$pa["pageid"];
else
$url = $http_location.'/'.$pa["clean_url"];
$xml .= '<url>
<loc>'.$url.'</loc>
<lastmod>'.$today.'</lastmod>
<changefreq>monthly</changefreq>
<priority>0.6</priority>
</url>';
}
if ($config["Google_SiteMap"]["iron_sitemap_links"] != "") {
$links = explode("\r\n", $config["Google_SiteMap"]["iron_sitemap_links"]);
if (is_array($links))
foreach ($links as $li) {
if ($li == "")
continue;
$xml .= '<url>
<loc>'.$li.'</loc>
<lastmod>'.$today.'</lastmod>
<changefreq>monthly</changefreq>
<priority>0.6</priority>
</url>';
}
}
$xml .= '</urlset>';
if (!fwrite($fp, $xml)) {
print "Cannot write to file ($filename)";
exit;
}
fclose($fp);
# IronShop.fr - Google SiteMap XML
?>
|