X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Third Party Add-Ons for X-Cart 4 (https://forum.x-cart.com/forumdisplay.php?f=45)
-   -   free google sitemap (https://forum.x-cart.com/showthread.php?t=51775)

lewaff 09-03-2010 03:23 PM

Re: free google sitemap
 
Hi
Me Again
I did that but when I logged in today (next Day) it created another blank sitemap.xml
so re- commented them out again

any idea's
thanks
lewis


Quote:

Originally Posted by jones
Turn off previous Sitemap Generator, then change sitemap1.xml to sitemap.xml,
then visit your admin home page. And only after that un-comment these lines.

:)


jones 09-03-2010 11:21 PM

Re: free google sitemap
 
Hi,

It's very strange. I think that problem in previous Sitemap Generator. You turned off it, but it still generate empty sitemap file.

I think you comment 2 lines of code in my module and my module has generated correct sitemap.xml. These 2 lines just allow my script generate sitemap only once per day. When they are commented my script generate sitemap each time when you visit your admin home page.

Alex

Maybe previous Sitemap Generator used cron and you did not turn off it?

Quote:

Originally Posted by lewaff
Hi
Me Again
I did that but when I logged in today (next Day) it created another blank sitemap.xml
so re- commented them out again

any idea's
thanks
lewis


lewaff 09-04-2010 04:46 AM

Re: free google sitemap
 
Hi Alex
Yes its strange
Yes i have proved it it rewriting the sitemap every i login ok
with those lines commented out 8O
is there something we are missing here
lewis
Quote:

Originally Posted by jones
Hi,

It's very strange. I think that problem in previous Sitemap Generator. You turned off it, but it still generate empty sitemap file.

I think you comment 2 lines of code in my module and my module has generated correct sitemap.xml. These 2 lines just allow my script generate sitemap only once per day. When they are commented my script generate sitemap each time when you visit your admin home page.

Alex

Maybe previous Sitemap Generator used cron and you did not turn off it?


jones 09-04-2010 07:39 AM

Re: free google sitemap
 
Lewis,

I have found bug in this file. Thank you very much for your help :)

I have fixed it. Also I have made new version of this this module.

New features:
- you can turn on/off this module by admin area (General Settings/Google SiteMap options)
- you can add any links in sitemap.xml file by admin area

For updating just owerwrite sitemap.php file !

Thank you
Alex

UPDATED: last version on #34 post.

lewaff 09-04-2010 11:59 PM

Re: free google sitemap
 
Hi Alex
Yes You have fixed it great, its updated fine today
thank you very much for a great service
:D/
lewis
Quote:

Originally Posted by jones
Lewis,

I have found bug in this file. Thank you very much for your help :)

I have fixed it. Also I have made new version of this this module.

New features:
- you can turn on/off this module by admin area (General Settings/Google SiteMap options)
- you can add any links in sitemap.xml file by admin area

For updating just owerwrite sitemap.php file !

Thank you
Alex


cflsystems 09-05-2010 08:55 AM

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.

lewaff 09-05-2010 10:28 AM

Re: free google sitemap
 
Hi Alex
Just a quick note
after looking at the sitemap.xml after the last post.
I see the the categories dont have the following slash

<loc>http://www.qualitechnic.co.uk/cat-Tools-Toolkits</loc>
<lastmod>2010-09-05</lastmod>

and the the product dont have the .html
<loc>http://www.qualitechnic.co.uk/SE-Z400-Connecting-Ribbon</loc>
<lastmod>2010-09-05</lastmod>

is this OK
Thank you Lewis

Quote:

Originally Posted by lewaff
Hi Alex
Yes You have fixed it great, its updated fine today
thank you very much for a great service
:D/
lewis


cflsystems 09-05-2010 11:17 AM

Re: free google sitemap
 
No that is not ok. And is not only the cats but your products links are missing the .html extension. See my post above for a fix.

lewaff 09-05-2010 12:43 PM

Re: free google sitemap
 
Thanks Steve
But You Code dont match my code as mine is the latest see couple posts before
Quote:

<?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
?>

thanks
lewis
Quote:

Originally Posted by cflsystems
No that is not ok. And is not only the cats but your products links are missing the .html extension. See my post above for a fix.


cflsystems 09-05-2010 01:15 PM

Re: free google sitemap
 
Actually the code I posted fixes the code you are reffering to. But you can still use the code you have just replace
Code:

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>';
}

with this
Code:

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>
';
 }



All times are GMT -8. The time now is 06:03 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.