In 1.13.0 a call was added to a function to add additional images into the feed.
After quite some time seeing 404 errors in my server logs while googlebot was looking for images in the images root instead of subdirectories, I eventually find the problem here.
So, for those of you with additional images (most people I imagine) have a look at your feed to see if the image path is correct for additional images. It should be already correct for the base image.
If you find the additional images link to be pointing to /images/myimage01.jpg instead of /images/mysubdirectory/myimage_01.jpg (deliberate underscore: http://www.zen-cart.com/content.php?100), here is my fix.
Rather than just fix what was broke, I took at look at the whole function and tried to improve it, and add comments for the terminally curious like me.
So, in /classes/google_base.php at the start of the file, replace the entire function:
with thisPHP Code:function additional_images($products_image) {
if ($products_image != '') {
$images_array = array();
// prepare image name
$products_image_extension = substr($products_image, strrpos($products_image, '.'));
$products_image_base = str_replace($products_image_extension, '', $products_image);
// if in a subdirectory
if (strrpos($products_image, '/')) {
$products_image_match = substr($products_image, strrpos($products_image, '/')+1);
$products_image_match = str_replace($products_image_extension, '', $products_image_match) . '_';
$products_image_base = $products_image_match;
}
$products_image_directory = str_replace($products_image, '', substr($products_image, strrpos($products_image, '/')));
if ($products_image_directory != '') {
$products_image_directory = DIR_WS_IMAGES . str_replace($products_image_directory, '', $products_image) . "/";
} else {
$products_image_directory = DIR_WS_IMAGES;
}
// Check for additional matching images
$file_extension = $products_image_extension;
$products_image_match_array = array();
if ($dir = @dir($products_image_directory)) {
while ($file = $dir->read()) {
if (!is_dir($products_image_directory . $file)) {
if (substr($file, strrpos($file, '.')) == $file_extension) {
if(preg_match("/" . $products_image_base . "/i", $file) == 1) {
if ($file != $products_image) {
if ($products_image_base . str_replace($products_image_base, '', $file) == $file) {
$images_array[] = $this->google_base_image_url($file);
if (count($images_array) >= 8) break;
} else {
// no match
}
}
}
}
}
}
$dir->close();
}
return $images_array;
} else {
// default
return false;
}
}
PHP Code:function additional_images($products_image) {//eg. image_subdirectory/myimage.jpg
if ($products_image != '') {
$images_array = array();
// prepare image name
$products_image_extension = substr($products_image, strrpos($products_image, '.'));//get the extension
$products_image_base = str_replace($products_image_extension, '', $products_image);//strip extension to get the (optional path and) base filename
$products_image_directory = str_replace(substr($products_image, strrpos($products_image, '/')), '',$products_image);//get the subdirectory path
if (strrpos($products_image_base, '/')) {//is the image in a subdirectory?
$products_image_base = substr($products_image_base, strrpos($products_image, '/')+1).'_';//strip the path and add the underscore: see http://www.zen-cart.com/content.php?100
$products_image_directory = $products_image_directory.'/';
}
$products_image_match_array = array();
if ($dir = @dir(DIR_WS_IMAGES . $products_image_directory)) {
while ($file = $dir->read()) {
if (!is_dir(DIR_WS_IMAGES . $products_image_directory . $file)) {
if ($file != $products_image) {//ignore the primary image
if (preg_match("/" . $products_image_base . "/i", $file) == 1) {//does this filename contain the image base filename?
if ($products_image_base . str_replace($products_image_base, '', $file) == $file) {//does this filename start with image base_?
if (substr($file, strrpos($file, '.')) == $products_image_extension) {//does it have the same extension as the image base?
$file = $products_image_directory.$file;//add subdirectory path to filename for subsequent function call
if (GOOGLE_PRODUCTS_DEBUG == 'true') {echo 'google_base 36:additional image found $file='.$file.'<br />';}//debug
$images_array[] = $this->google_base_image_url($file);//this function needs image_subdirectory/myimage.jpg
if (count($images_array) >= 8) break;//only 10 images allowed by Google
} else {
// no match
}
}
}
}
}
}
$dir->close();
}
return $images_array;
} else {
// default
return false;
}
}


Reply With Quote
