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)
-   -   X-Cart Product Images Sitemap Generator (https://forum.x-cart.com/showthread.php?t=75149)

PhilJ 03-29-2017 06:54 PM

X-Cart Product Images Sitemap Generator
 
  • Generates a separate product images sitemap to maximise Google Images SEO
  • Lists detailed images first, then product images, then thumbnails
  • Supports X-Cart Clean URLs by default
  • X-Cart v4.4.x - v4.7.x (for v4.4.x see note 8 )
  • Easy to install
Info
Quote:

Image sitemap information helps Google discover images that we might not otherwise find (such as images your site reaches with JavaScript code), and allows you to indicate images on your site that you want Google to crawl and index.

Download

Changelog


1st August 2018 - Updated, to handle special characters in image captions/titles better, geolocation and license info disabled by default, HTTPS urls used.

2nd April 2017 - Updated to use htmlspecialchars instead of htmlentities and added 'memory_limit' setting.

10th May 2017 - Updated, with note for v4.4.x stores.

anandat 03-30-2017 12:20 AM

Re: X-Cart Product Images Sitemap Generator
 
Hi Phil,
You are amazing..no words to describe my happiness...I just requested this stuff in forum yesterday & no time you created this module & that's also for FREE !! :)

It's generating image sitemap but even though my site url starting from https:// the sitemap data still generated http:// links !
But that's easy to replace in text editor in no time.

Also I am using CDN so can I replace image url with https://cdn.mysite.com/images/D/sample_image.jpg ?

Quick Tip to users:
------------------
If you have large number of products for example more than 5000 & if you are getting 500 -Internal Server Error generating site map then in your config.php increase memory limit to 256
For example ini_set('memory_limit','256M');
After you generate sitemap successfully you revert back it to your original memory value limit.

ITVV 03-30-2017 08:26 AM

Re: X-Cart Product Images Sitemap Generator
 
Hi @anandat

Quote:

Originally Posted by anandat
It's generating image sitemap but even though my site url starting from https:// the sitemap data still generated http:// links !
But that's easy to replace in text editor in no time.


Phil covers that very issue in the "install.txt" file! Have a read of "Notes 4)" for help on the http -v- https

@Phil Great little addon - Thank You Phil

Kind regards

ITVV

elmirage001 03-30-2017 03:25 PM

Re: X-Cart Product Images Sitemap Generator
 
Hi Phil,

You are amazing! I'll get when my workload slows down some. I'm in the middle of building our new house so my orders decide to jump 300%... Can't complain :-)

Thank you so much!

Paul

wnc2 03-31-2017 01:58 AM

Re: X-Cart Product Images Sitemap Generator
 
hi phil,

thanks for your valuable addon.

i'm having some issues with products including strange chars in the name like & ™ ® and accented italian chars like àèìòù.

any solution?

PhilJ 04-01-2017 07:52 AM

Re: X-Cart Product Images Sitemap Generator
 
ok, I have updated the mod to use htmlspecialchars instead of htmlentities and tested with those characters.

I've also added a 'memory_limit' setting if needed (line 9).

wnc2 04-01-2017 09:25 AM

Re: X-Cart Product Images Sitemap Generator
 
Quote:

Originally Posted by PhilJ
ok, I have updated the mod to use htmlspecialchars instead of htmlentities and tested with those characters. Thanks.


problem solved THANKS

mattstyle2 04-03-2017 09:27 PM

Re: X-Cart Product Images Sitemap Generator
 
nice mod.. for old xcart versions and people using wcm_cdseo, change the query and first part of the foreach sections to this:

Code:

$images_D = db_query("
SELECT * FROM $sql_tbl[products]
INNER JOIN $sql_tbl[images_D] ON $sql_tbl[products].productid = $sql_tbl[images_D].id
WHERE forsale='Y' ORDER BY productid DESC LIMIT $products_limit
");

while ($row = db_fetch_array($images_D)) {
  $results[] = $row;
}

foreach ($results as $result){

        //$clean_url = $result['clean_url'] . $product_urls_extension;

        $pid=$result['productid'];
        $cdseo_url = func_query_first_cell("SELECT cdseoUrl FROM wcm_cdseo WHERE cdseoReplaceID='$pid' AND cdseoType='product'");
        if ($cdseo_url!='') {
                $cdseo_url.=".html";
                $clean_url=$cdseo_url;
        } else {
                continue;
        }


you have to do that for the images_p and images_t sections too.

-Matt

mattstyle2 04-03-2017 11:15 PM

Re: X-Cart Product Images Sitemap Generator
 
I rewrote this.. There was an issue with this making a new url LOC for each image file which didnt match the specs:
https://support.google.com/webmasters/answer/178636?hl=en


so google was saying there was 40k images and 40k urls in the sitemap.. not sure if I broke something or it happens to everyone..

This works perfect with xc4.1.12 with cdseo and should work with newer versions

this only does detailed imgs, splits files if there's more than 40k images..

uses https filenames.. note this code only works with CDSEO urls.. you can change the part that gets the url pretty easily though.


Code:

require "./auth.php";

//================== Settings ==================

$sitemap_filename = "images_sitemap";

$products_limit = "1000000";
$sm='';

//$product_urls_extension = $config['SEO']['clean_urls_ext_p'];

//$geolocation = $config['Company']['location_address'].", ".$config['Company']['location_city'].", ".$config['Company']['location_state_name'].", ".$config['Company']['location_zipcode'].", ".$config['Company']['location_country_name'];
//$license_info_url = $https_location."/pages.php?pageid=3#images";

$geolocation = false; // Uncomment to not display geo_location info
$license_info_url = false; // Uncomment to not display license info

//================== / Settings ================

$images_sitemap = fopen($sitemap_filename.$sm.'.xml', "wb");

//-----------------------

$build = '<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">'."\n";

//-----------------------


$count=0;

$products=func_query("SELECT * FROM $sql_tbl[products] WHERE forsale='Y' ORDER BY productid DESC LIMIT $products_limit");

foreach ($products as $product)
        {

                $pid=$product['productid'];

//get URL!
                $cdseo_url = func_query_first_cell("SELECT cdseoUrl FROM wcm_cdseo WHERE cdseoReplaceID='$pid' AND cdseoType='product'",true);
                if ($cdseo_url!='') {
                        $cdseo_url.=".html";
                        $clean_url=$cdseo_url;
                } else {
                        continue; //if no clean url, skip the product
                }
                $build .= "\t<url>
                <loc>$https_location/$clean_url</loc>\n";
               
                $query="SELECT * FROM $sql_tbl[images_D] WHERE id='$pid'";
               
                $images = func_query($query);
                foreach ($images as $result)
                        {
                                $build.="\t\t".'<image:image>
                        <image:loc><![CDATA['.$https_location."/".str_replace(array("./"),"",$result['image_path']).']]></image:loc>'."\r\n";
                                if ($result['alt']) {
                                  $build .= "\t\t\t".'<image:caption>'.sanitize_for_xml($result['alt']).'</image:caption>
                        <image:title>'.sanitize_for_xml($result['alt']).'</image:title>'."\r\n";
                                }
                                if ($geolocation) {
                                  $build .= "\t".'<image:geo_location>'.htmlspecialchars($geolocation).'</image:geo_location>'."\r\n";
                                }
                                if ($license_info_url) {
                                  $build .= "\t".'<image:license>'.$license_info_url.'</image:license>'."\r\n";
                                }
                                $build .= "\t\t".'</image:image>';
                                $count  ;
                        } //end foreach image
               
                $build.="\n\t</url>\n";
                if ($count>=40000) //split the file
                        {
                               
                                $build .= '</urlset>';
                               
                                if ($sm=='')
                                        $sm=2;
                                else
                                        $sm  ;
                                fwrite($images_sitemap, $build);
                                fclose($images_sitemap);
                                $images_sitemap = fopen($sitemap_filename.$sm.'.xml', "wb");
                                $build = '<?xml version="1.0" encoding="UTF-8"?>
        <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">'."\n";
                                $count=0;
                        }
        } //end foreach product


$build .= '</urlset>';

//-----------------------

fwrite($images_sitemap, $build);
fclose($images_sitemap);

echo "DONE! images: $count\n";

exit;

function sanitize_for_xml($v) {
  // Strip invalid UTF-8 byte sequences - this part may not be strictly necessary, could be separated to another function
  $v = mb_convert_encoding(mb_convert_encoding($v, 'UTF-16', 'UTF-8'), 'UTF-8', 'UTF-16');
       
  // Remove various characters not allowed in XML
  $v = preg_replace('/[^\x{0009}\x{000A}\x{000D}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]/u', '?', $v);
       
  return htmlspecialchars($v);
}


mpcommercial 05-08-2017 11:37 AM

Re: X-Cart Product Images Sitemap Generator
 
hello, Phil:

I installed the mod, but the sitemap it produces is blank: any ideas of what I might be missing?


All times are GMT -8. The time now is 04:06 PM.

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