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)

user1 01-14-2010 06:15 AM

free google sitemap
 
I was looking for a module that creates a sitemap for Google. I found one for free at xcartmod.com .

It is a nice mod but it has some downsides:

1. It looks the db and creates the urls the following way:

www.site.com//product.php?productid=xx

which is bad when you use clean urls.

2. Doesn't include the manufacturer urls


So I made some modifications to fix the above mentioned problems and, since it is a free module, I thought I could post the modifications so someone else can use them.

If for any reason you think that is wrong, please tell me and I will remove everything from this post.


So I opened the ../modules/xCartMod_Google_Sitemap/sitemap_xml.php and made the following changes:

1. Replaced
Code:

$cats = func_query("SELECT * FROM $sql_tbl[categories] WHERE avail='Y'");

if (is_array($cats[0]))
    foreach($cats as $ca) {
        $xml .= '<url>
<loc>'.$http_location.'/home.php?cat='.$ca["categoryid"].'</loc>
<lastmod>'.$today.'</lastmod>
<changefreq>monthly</changefreq>
<priority>0.8</priority>
</url>';
    }

with
Code:

$cats = func_query("SELECT * FROM $sql_tbl[categories], $sql_tbl[clean_urls] WHERE resource_type = 'C' AND categoryid = resource_id AND avail = 'Y'");

if (is_array($cats[0]))
    foreach($cats as $ca) {
        $xml .= '<url>
<loc>'.$http_location.'/'.$ca["clean_url"].'</loc>
<lastmod>'.$today.'</lastmod>
<changefreq>monthly</changefreq>
<priority>0.8</priority>
</url>';
    }


2. Replaced
Code:

$prods = func_query("SELECT * FROM $sql_tbl[products] WHERE forsale='Y'");
if (is_array($prods[0]))
    foreach($prods as $pr) {
        $xml .= '<url>
<loc>'.$http_location.'/product.php?productid='.$pr["productid"].'</loc>
<lastmod>'.$today.'</lastmod>
<changefreq>monthly</changefreq>
<priority>0.6</priority>
</url>';
    }

with
Code:

$prods = func_query("SELECT * FROM $sql_tbl[products], $sql_tbl[clean_urls] WHERE resource_type = 'P' AND productid = resource_id AND forsale = 'Y'");
if (is_array($prods[0]))
    foreach($prods as $pr) {
        $xml .= '<url>
<loc>'.$http_location.'/'.$pr["clean_url"].'.html</loc>
<lastmod>'.$today.'</lastmod>
<changefreq>monthly</changefreq>
<priority>0.6</priority>
</url>';
    }


3. Replaced
Code:

$pages = func_query("SELECT * FROM $sql_tbl[pages] WHERE active='Y'");
if (is_array($pages[0]))
    foreach($pages as $pa) {
        $xml .= '<url>
<loc>'.$http_location.'/pages.php?pageid='.$pa["pageid"].'</loc>
<lastmod>'.$today.'</lastmod>
<changefreq>monthly</changefreq>
<priority>0.6</priority>
</url>';
    }

with
Code:

$pages = func_query("SELECT * FROM $sql_tbl[pages], $sql_tbl[clean_urls] WHERE resource_type = 'S' AND pageid = resource_id AND active = 'Y'");
if (is_array($pages[0]))
    foreach($pages as $pa) {
        $xml .= '<url>
<loc>'.$http_location.'/'.$pa["clean_url"].'.html</loc>
<lastmod>'.$today.'</lastmod>
<changefreq>monthly</changefreq>
<priority>0.6</priority>
</url>';
    }


4. Added
Code:

$manufacturers = func_query("SELECT * FROM $sql_tbl[manufacturers], $sql_tbl[clean_urls] WHERE resource_type = 'M' AND manufacturerid = resource_id AND avail = 'Y'");
if (is_array($manufacturers[0]))
    foreach($manufacturers as $manuf) {
        $xml .= '<url>
<loc>'.$http_location.'/'.$manuf["clean_url"].'</loc>
<lastmod>'.$today.'</lastmod>
<changefreq>monthly</changefreq>
<priority>0.6</priority>
</url>';
    }

before
Code:

$xml .= '<url>
<loc>'.$http_location.'/help.php?section=business</loc>
<lastmod>'.$today.'</lastmod>


You are ready! Your sitemap.xml contains your products,categories, manufacturer and static pages clean urls. It is updated once a day (if you visit the admin side of your shop) and is stored in www.yoursite.com/sitemap.xml .

I made the changes on my 4.3.0 test installation (I'm now on 4.2.3 and want to upgrade to 4.3.0) and seems to work perfectly. It will work and on previous versions if the database tables maintain the same structure with 4.3.0.

Please test before you do anything on your live shop!!!

Best regards,
Andreas

Babydoll 01-25-2010 04:16 PM

Re: free google sitemap
 
thanks for mentioning this.
i modified it like you said without the last manufacturer part.
is it supposed to show the clean url after? mine is still showing the ~productid=xx

user1 01-26-2010 11:13 PM

Re: free google sitemap
 
Quote:

Originally Posted by Babydoll
thanks for mentioning this.
i modified it like you said without the last manufacturer part.
is it supposed to show the clean url after? mine is still showing the ~productid=xx



The module runs each time you load a page in the admin part of your site.
The module also creates two entries in the "config" table of your database. In one of them "xcartmod_sitemap_time", it saves the current date.
Since we need our sitemap created only once in a day there is an if statement inside it.
Before creating the sitemap, it checks if the current date is the same with the one in "xcartmod_sitemap_time".
If it isn't, it creates a new sitemap and writes the current date to the db. If it is, it does nothing.


So you have created your sitemap but you can't create another one before the day passes. Just delete the value in "xcartmod_sitemap_time" entry in the "config" table. If you don't want (for testing purposes) to update the date entry and check the date in the db then replace:
Code:

$xm_today = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
if ($xm_today == $config["xcartmod_sitemap_time"])
    return;

db_query("UPDATE $sql_tbl[config] SET value='$xm_today' WHERE name='xcartmod_sitemap_time'");

with
Code:

//$xm_today = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
//if ($xm_today == $config["xcartmod_sitemap_time"])
//    return;
//
//db_query("UPDATE $sql_tbl[config] SET value='$xm_today' WHERE name='xcartmod_sitemap_time'");

Don't forget to revert this change after you finish with testing or else you will create a new sitemap each time you visit the admin part of your site!

Andreas Nikolaidis

dmpinder 01-28-2010 09:47 AM

Re: free google sitemap
 
You are a gentleman, sir. Thank you for posting.

user1 01-28-2010 10:15 AM

Re: free google sitemap
 
You are welcome :)

Andreas Nikolaidis

stu1artuk 08-04-2010 02:35 AM

Re: free google sitemap
 
1 Attachment(s)
Works great on 4.2.

You just need to make sure you have a sitemap.xml with urlset headers and the file is set to chmod 666 in your public_html folder.

I've attached one for any novices.

dmpinder 08-04-2010 02:36 AM

Re: free google sitemap
 
Quote:

Originally Posted by stu1artuk
Works great on 4.2.

You just need to make sure you have a sitemap.xml with urlset headers and the file is set to chmod 666 in your public_html folder.

I've attached one for any novices.


I found that I had to set mine to 777 in order for the script to be able to write the XML data.

Darren

HumanNature 08-11-2010 05:11 PM

Re: free google sitemap
 
Woooh this modification is great thank you very much, it works perfectly in 4.2.3.

Just one question, i want to add an extra condition to the product query because if the main category of the product is not available I don't want the products to appear in the sitemap but i don't know how to made the JOIN to the category table in the query.

Can you help me?


$prods = func_query("SELECT * FROM $sql_tbl[products], $sql_tbl[clean_urls] WHERE resource_type = 'P' AND productid = resource_id AND forsale = 'Y'");
if (is_array($prods[0]))
foreach($prods as $pr) {
$xml .= '<url>
<loc>'.$http_location.'/'.$pr["clean_url"].'.html</loc>
<lastmod>'.$today.'</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>';
}

user1 08-12-2010 07:33 AM

Re: free google sitemap
 
For that extra condition to work we need to search two extra tables in the database.

Try to replace
Code:

$prods = func_query("SELECT * FROM $sql_tbl[products],  $sql_tbl[clean_urls] WHERE resource_type = 'P' AND productid =  resource_id AND forsale = 'Y'");

with
Code:

$prods = func_query("SELECT * FROM $sql_tbl[xcart_clean_urls],  $sql_tbl[xcart_products_categories], $sql_tbl[xcart_products],  $sql_tbl[xcart_categories] WHERE xcart_clean_urls.resource_type = 'P'  AND xcart_products.productid = xcart_clean_urls.resource_id AND main =  'Y' AND xcart_products.productid = xcart_products_categories.productid  AND xcart_products.forsale = "Y" AND  xcart_products_categories.categoryid = xcart_categories.categoryid AND  xcart_categories.avail = 'Y'");


I hope this works for you. Please check carefully to see if the result is correct.

Andreas

HumanNature 08-12-2010 09:26 AM

Re: free google sitemap
 
Quote:

Originally Posted by user1
For that extra condition to work we need to search two extra tables in the database.

Try to replace
Code:

$prods = func_query("SELECT * FROM $sql_tbl[products],  $sql_tbl[clean_urls] WHERE resource_type = 'P' AND productid =  resource_id AND forsale = 'Y'");

with
Code:

$prods = func_query("SELECT * FROM $sql_tbl[xcart_clean_urls],  $sql_tbl[xcart_products_categories], $sql_tbl[xcart_products],  $sql_tbl[xcart_categories] WHERE xcart_clean_urls.resource_type = 'P'  AND xcart_products.productid = xcart_clean_urls.resource_id AND main =  'Y' AND xcart_products.productid = xcart_products_categories.productid  AND xcart_products.forsale = "Y" AND  xcart_products_categories.categoryid = xcart_categories.categoryid AND  xcart_categories.avail = 'Y'");


I hope this works for you. Please check carefully to see if the result is correct.

Andreas


Hi Andreas, thank you very much, I have tried the folowing:

Code:

$prods = func_query("SELECT * FROM $sql_tbl[xcart_clean_urls], $sql_tbl[xcart_products_categories], $sql_tbl[xcart_products], $sql_tbl[xcart_categories] WHERE xcart_clean_urls.resource_type = 'P' AND xcart_products.productid = xcart_clean_urls.resource_id AND xcart_products_categories.main = 'Y' AND xcart_products.productid = xcart_products_categories.productid AND xcart_products.forsale = 'Y' AND xcart_products_categories.categoryid = xcart_categories.categoryid AND xcart_categories.avail = 'Y'");

that is the same as you wrote but changing
Code:

AND main =  'Y'
for
Code:

AND xcart_products_categories.main = 'Y'

I get the following error:

INVALID SQL: 1064 : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' , , WHERE xcart_clean_urls.resource_type = 'P' AND xcart_products.productid = ' at line 1
SQL QUERY FAILURE:SELECT * FROM , , , WHERE xcart_clean_urls.resource_type = 'P' AND xcart_products.productid = xcart_clean_urls.resource_id AND xcart_products_categories.main = 'Y' AND xcart_products.productid = xcart_products_categories.productid AND xcart_products.forsale = 'Y' AND xcart_products_categories.categoryid = xcart_categories.categoryid AND xcart_categories.avail = 'Y'

don't know what happens...

user1 08-12-2010 01:09 PM

Re: free google sitemap
 
My mistake. I used wrong variables for the table names. The
Code:

AND main = 'Y'
change doesn't matter.

So, try this:


Code:

$prods = func_query("SELECT * FROM $sql_tbl[clean_urls], $sql_tbl[products_categories], $sql_tbl[products], $sql_tbl[categories] WHERE xcart_clean_urls.resource_type = 'P' AND xcart_products.productid = xcart_clean_urls.resource_id AND main = 'Y' AND xcart_products.productid = xcart_products_categories.productid AND xcart_products.forsale = 'Y' AND xcart_products_categories.categoryid = xcart_categories.categoryid AND xcart_categories.avail = 'Y'");

This must be correct.

Andreas

HumanNature 08-12-2010 02:35 PM

Re: free google sitemap
 
Thanks man that worked! :)

Anyway I have find a "bug":

If you don't use ".html" in your pages and products urls you have to remove the "html" from the code so the lines are finally like this:

Code:

<loc>'.$http_location.'/'.$pr["clean_url"].'</loc>

Yours!

jones 08-31-2010 09:43 AM

Re: free google sitemap
 
Hello,

Im creator of this module.
Here version for xcart 4.3.x with supporting "clean_url" option.

Enjoy ;)

UPDATE: This is old version of module. New version on post #24 - http://forum.x-cart.com/showpost.php?p=296734&postcount=24

lewaff 09-01-2010 10:44 AM

Re: free google sitemap
 
Thanks
I have tried IronShop_Google_Sitemap this on my www.qualitechnic.co.uk site
but its creating a blank sitemap.xml
am i doing something wrong
lewis

Quote:

Originally Posted by jones
Hello,

Im creator of this module.
Here version for xcart 4.3.x with supporting "clean_url" option.

Enjoy ;)


jones 09-01-2010 11:30 PM

Re: free google sitemap
 
Hi lewis,

I have opened your site and found that you has http://www.qualitechnic.co.uk/sitemap.xml
But it was generated not by my module.
I have test it again on 4.3.2 version, results here:

http://www.ironshop.fr/ebay/sitemap.xml

Thank you,
Alex

Quote:

Originally Posted by lewaff
Thanks
I have tried IronShop_Google_Sitemap this on my www.qualitechnic.co.uk site
but its creating a blank sitemap.xml
am i doing something wrong
lewis


lewaff 09-02-2010 06:29 AM

Re: free google sitemap
 
sorry
i put the original sitemap back on my site has it was blank from your program
I think yours would me more suitable for the xcart
but i can install it again
but dont want to leave a blank one on live for long
thank you again lewis

Quote:

Originally Posted by jones
Hi lewis,

I have opened your site and found that you has http://www.qualitechnic.co.uk/sitemap.xml
But it was generated not by my module.
I have test it again on 4.3.2 version, results here:

http://www.ironshop.fr/ebay/sitemap.xml

Thank you,
Alex


lewaff 09-02-2010 11:32 AM

Re: free google sitemap
 
I tempery altered the sitemap.php
to create the sitemap at www.qualitechnic.co.uk/sitemap1.xml
and has you see its created a blank one
here's the code i changed
Quote:

}
$filename = '../sitemap1.xml';
if(!$fp = fopen($filename, 'w')) {
print "Cannot open file ($filename)";
exit;




Quote:

Originally Posted by lewaff
sorry
i put the original sitemap back on my site has it was blank from your program
I think yours would me more suitable for the xcart
but i can install it again
but dont want to leave a blank one on live for long
thank you again lewis


jones 09-02-2010 12:33 PM

Re: free google sitemap
 
Yes, you made corect changes.
Can you comment these lines in sitemap.php ?

PHP Code:

if ($xm_today == $config["iron_sitemap_time"])
    return; 


So it will look like this:

PHP Code:

//if ($xm_today == $config["iron_sitemap_time"])
//    return; 


These lines allow make refresh sitemap only one time per day.

Alex

Quote:

Originally Posted by lewaff
I tempery altered the sitemap.php
to create the sitemap at www.qualitechnic.co.uk/sitemap1.xml
and has you see its created a blank one
here's the code i changed


lewaff 09-02-2010 12:51 PM

Re: free google sitemap
 
Yes thats done the trick do i have leave these commented out
thank you very much
thats great service:D/


Quote:

Originally Posted by jones
Yes, you made corect changes.
Can you comment these lines in sitemap.php ?

PHP Code:

if ($xm_today == $config["iron_sitemap_time"])
return; 


So it will look like this:

PHP Code:

//if ($xm_today == $config["iron_sitemap_time"])
// return; 


These lines allow make refresh sitemap only one time per day.

Alex


jones 09-02-2010 02:21 PM

Re: free google sitemap
 
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.

:)

Quote:

Originally Posted by lewaff
Yes thats done the trick do i have leave these commented out
thank you very much
thats great service:D/


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


lewaff 09-05-2010 10:48 PM

Re: free google sitemap
 
Thanks
Great that works fine
Now is there anyway of stopping it putting these and any un needed lines
Quote:

- <url>
<loc>http://www.qualitechnic.co.uk/help.php?section=business</loc>

<lastmod>2010-09-06</lastmod>

<changefreq>monthly</changefreq>

<priority>0.6</priority>

</url>


- <url>
<loc>http://www.qualitechnic.co.uk/help.php?section=conditions</loc>

<lastmod>2010-09-06</lastmod>

<changefreq>monthly</changefreq>

<priority>0.6</priority>

</url>


- <url>
<loc>http://www.qualitechnic.co.uk/register.php</loc>

<lastmod>2010-09-06</lastmod>

<changefreq>monthly</changefreq>

<priority>0.6</priority>

</url>


- <url>
<loc>http://www.qualitechnic.co.uk/help.php?section=Password_Recovery</loc>

<lastmod>2010-09-06</lastmod>

<changefreq>monthly</changefreq>

<priority>0.6</priority>

</url>



thanks Lewis

Quote:

Originally Posted by cflsystems
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>
';
 }



jones 09-05-2010 11:23 PM

Re: free google sitemap
 
1 Attachment(s)
Thank you Steve,

I have added changes to module :)


Quote:

Originally Posted by lewaff
Thanks
Great that works fine
Now is there anyway of stopping it putting these and any un needed lines

thanks Lewis


You can remove/change these URLs from admin area on Genaral Settings/Google SiteMap options -> "Additional URLs." field.

Alex

UPDATED: forgot file with new version.

jones 09-05-2010 11:26 PM

Re: free google sitemap
 
Lewis,

Can you confirm that you see text "Google SiteMap options" in admin area on General Settings page under "General options" link ?

Thank you,
Alex

lewaff 09-05-2010 11:43 PM

Re: free google sitemap
 
OOOPS
Silly Me
I seen that earlier
thanks again
lewis
Quote:

Originally Posted by jones
Lewis,

Can you confirm that you see text "Google SiteMap options" in admin area on General Settings page under "General options" link ?

Thank you,
Alex


sdfjlsdfsdf 09-07-2010 01:04 AM

Re: free google sitemap
 
Just like to thank-you for all the hard work you guys put into this, was extremely useful. Your a credit to the community :)

DisCost 10-18-2010 05:36 PM

Re: free google sitemap
 
I am having the empty sitemap.xml problem, and when I comment out the "if ($xm_today..." browsing to /admin just gives me an empty page.

fou 10-19-2010 04:33 AM

Re: free google sitemap
 
Do you have last verion of module?

Quote:

Originally Posted by DisCost
I am having the empty sitemap.xml problem, and when I comment out the "if ($xm_today..." browsing to /admin just gives me an empty page.


betty4 10-19-2010 12:37 PM

Re: free google sitemap
 
Will this work on 4.0.x?

fou 10-19-2010 01:35 PM

Re: free google sitemap
 
Quote:

Originally Posted by betty4
Will this work on 4.0.x?


Yes, it should work with 4.0.x

Alex

DisCost 10-19-2010 06:08 PM

Re: free google sitemap
 
I'm using the file from post#32, it could be that the file is timing out because I have ~5k products


All times are GMT -8. The time now is 10:02 AM.

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