View Single Post
  #26  
Old 09-05-2010, 08:55 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,201
 

Default Re: free google sitemap

Hi Alex,
I hope you don't me posting corrections for this module. The way file is right now urls have no extension if X-Cart Clean URL's are used, ie the settings in admin for Clean URL's are not applied, resulting in wrong urls in sitemap.xml. Also module is not showing in modules or settings - you are missing config and language tables entries for this to work - and I took out the initial db calls form the php file - no need for them to be there. The way you had it there was no way to turn on/off the module. Moved filename in settings if users want to experiment with different names so not to override existing file.

Here is how the install.txt looks like, see the red part
Code:
INSTALLATION GUIDE ------------------ ORIGINAL TEXT HERE Execute the following SQL statements from your admin/patch area INSERT INTO xcart_config (name, comment, value, category, orderby, type) VALUES ('gs_sitemap_name', 'Google Sitemap XML filename (ie sitemap.xml)', 'sitemap_1.xml', 'Google_Sitemap', '10', 'text'); INSERT INTO xcart_config (name, comment, value, category, orderby, type) VALUES ('gs_sitemap_links', 'Additional URLs. Please, don\'t 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.', '', 'Google_Sitemap', '20', 'textarea'); INSERT INTO xcart_config (name, comment, value, category, orderby, type) VALUES ('gs_sitemap_time', 'Google Sitemap XML time', '0', '', '0', 'text'); INSERT INTO xcart_modules (module_name, module_descr, active) VALUES ('Google_Sitemap', 'This module allows you to create Google sitemap.', 'Y'); INSERT INTO `xcart_languages` (`code`, `name`, `value`, `topic`) VALUES ('US', 'module_descr_Google_Sitemap', 'This module allows you to create Google sitemap.', 'Modules'), ('US', 'module_name_Google_Sitemap', 'Google Sitemap', 'Modules');

Here is the sitemap.php, see the red part
Code:
<?php if ( !defined('XCART_SESSION_START') ) { header("Location: ../../"); die("Access denied"); } $xm_today = mktime(0, 0, 0, date("m"), date("d"), date("Y")); if (empty($active_modules["Google_Sitemap"]) || $xm_today == $config["gs_sitemap_time"]) return; if (empty($config["Google_Sitemap"]["gs_sitemap_name"])) { $top_message["content"] = "Please specify sitemap name in Google Sitemap setting."; $top_message["type"] = 'E'; return; } else $filename = '../'.$config["Google_Sitemap"]["gs_sitemap_name"]; if(!$fp = fopen($filename, 'w')) { $top_message["content"] = "Cannot open file (".$filename.")"; $top_message["type"] = 'E'; return; } db_query("UPDATE $sql_tbl[config] SET value='$xm_today' WHERE name='gs_sitemap_time'"); $today = date("Y-m-d"); $xml = '<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="gss.xsl"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> <url><loc>'.$http_location.'/</loc><lastmod>'.$today.'</lastmod><changefreq>weekly</changefreq><priority>0.5</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"].$config['SEO']['clean_urls_ext_c']; $xml .= '<url><loc>'.$url.'</loc><lastmod>'.$today.'</lastmod><changefreq>weekly</changefreq><priority>0.5</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"].$config['SEO']['clean_urls_ext_m']; $xml .= '<url><loc>'.$url.'</loc><lastmod>'.$today.'</lastmod><changefreq>weekly</changefreq><priority>0.5</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"].$config['SEO']['clean_urls_ext_p']; $xml .= '<url><loc>'.$url.'</loc><lastmod>'.$today.'</lastmod><changefreq>weekly</changefreq><priority>0.5</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"].$config['SEO']['clean_urls_ext_s']; $xml .= '<url><loc>'.$url.'</loc><lastmod>'.$today.'</lastmod><changefreq>weekly</changefreq><priority>0.5</priority></url> '; } if ($config["Google_Sitemap"]["gs_sitemap_links"] != "") { $links = explode("\r\n", $config["Google_Sitemap"]["gs_sitemap_links"]); if (is_array($links)) foreach ($links as $li) { if ($li == "") continue; $xml .= '<url><loc>'.$li.'</loc><lastmod>'.$today.'</lastmod><changefreq>weekly</changefreq><priority>0.5</priority></url> '; } } $xml .= '</urlset>'; if (!fwrite($fp, $xml)) { print "Cannot write to file ($filename)"; exit; } fclose($fp); ?>

There are some other changes in the php file but they are mostly cosmetic.
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote