Using the v.1.3.8a zen cart and v.1.7.4 Google Base Feeder.
I also have a database with over 13K products. This database contains many special characters for copyright, trademark, registered etc. along with double quotes, degrees, ampersand and again etc.
Out of the box about half or less of my items were getting listed. After playing around with google_base.php (with suggestions I found by searching because I have almost no php experience) I was able to get 100% of my products to list using the following found on the Numinix forum pg. 26:
I pasted the code in 1.7.0A from the same file that I am using and when I downgrade to 1.7.0A everything works fine.
function google_base_sanita($str, $rt=false) { // currently using zen_xml_sanitizer below instead of zen_froogle_sanita
$str = strip_tags($str);
$str = str_replace(array("\t" , "\n", "\r"), ' ', $str);
$str = preg_replace('/\s\s+/', ' ', $str);
// $str = str_replace(array("®", "®", "©", "©", "™", "™"), ' ', $str);
$str = htmlentities(html_entity_decode($str));
$in = $out = array();
$in[] = "®"; $out[] = '(r)';
$in[] = "©"; $out[] = '(c)';
$in[] = "™"; $out[] = '(tm)';
// $str = str_replace($in, $out, $str);
if($rt) {
$str = str_replace(" ", " ", $str);
$str = str_replace(" ", "", $str);
}
$str = trim($str);
return $str;
}
function google_base_xml_sanitizer($str, $cdata = false) {
$_strip_search = array("![\t ]+$|^[\t ]+!m",'%[\r\n]+%m'); // remove CRs and newlines
$_strip_replace = array('',' ');
$_cleaner_array = array(">" => "> ", "®" => "", "®" => "", "™" => "", "™" => "", "\t" => "", " " => "");
$str = html_entity_decode($str);
$str = strtr($str, $_cleaner_array);
$str = preg_replace($_strip_search, $_strip_replace, $str);
$str = strip_tags($str);
$str = eregi_replace("[^[:alnum:][:space:].,!()'-_/+=?äÂÄöÖüÜß]", "", $str);
$str = utf8_encode(htmlentities($str));
//$str = $str;
$str = str_replace('&', '&', $str);
//if (!$cdata) {
//$str = htmlentities(html_entity_decode($str));
//$in = $out = array();
//$in[] = "®"; $out[] = '(r)';
//$in[] = "©"; $out[] = '(c)';
//$in[] = "™"; $out[] = '(tm)';
//$str = html_translate($str);
$str = trim($str);
if ($cdata) {
$str = '<![CDATA[' . $str . ']]>';
}
return $str;
}
function html_translate($value) {
$value = preg_replace("/À/", "À", $value);
$value = preg_replace("/Á/", "Á", $value);
$value = preg_replace("/Ä/", "Ä", $value);
$value = preg_replace("/Ç/", "Ç", $value);
$value = preg_replace("/È/", "È", $value);
$value = preg_replace("/É/", "É", $value);
$value = preg_replace("/Ë/", "Ë", $value);
$value = preg_replace("/Ì/", "Ì", $value);
$value = preg_replace("/Í/", "Í", $value);
$value = preg_replace("/Ï/", "Ï", $value);
$value = preg_replace("/Ò/", "Ò", $value);
$value = preg_replace("/Ó/", "Ó", $value);
$value = preg_replace("/Ö/", "Ö", $value);
$value = preg_replace("/Ù/", "Ù", $value);
$value = preg_replace("/Ú/", "Ú", $value);
$value = preg_replace("/Ü/", "Ü", $value);
$value = preg_replace("/Ü/", "Ü", $value);
$value = preg_replace("/ß/", "ß", $value);
$value = preg_replace("/à/", "à", $value);
$value = preg_replace("/á/", "á", $value);
$value = preg_replace("/ä/", "ä", $value);
$value = preg_replace("/ç/", "ç", $value);
$value = preg_replace("/è/", "è", $value);
$value = preg_replace("/é/", "é", $value);
$value = preg_replace("/ë/", "ë", $value);
$value = preg_replace("/ì/", "ì", $value);
$value = preg_replace("/í/", "í", $value);
$value = preg_replace("/ï/", "ï", $value);
$value = preg_replace("/ò/", "ò", $value);
$value = preg_replace("/ó/", "ó", $value);
$value = preg_replace("/ö/", "ö", $value);
$value = preg_replace("/ù/", "ù", $value);
$value = preg_replace("/ú/", "ú", $value);
$value = preg_replace("/ü/", "ü", $value);
return $value;
}
I replaced everything in the function google_base_sanita through the entire function google_base_xml_sanitizer section of google base feeder 1.7.4 google_base.php with the code above. After doing that I took a better look at:
$_cleaner_array = array(">" => "> ", "®" => "", "®" => "", "™" => "", "™" => "", "\t" => "", " " => "");
located within the pasted code and easily realized that I could make simple changes to character substitution by adding more of or changing the existing substitution in this format: "[character_you_want_to_remove]" => "[the_substituted_character]". Examples: I wanted the trademark to display as "(TM)" instead of ""/just being removed. I also have different type hyphens in my text, so I used: "–" => "-", "—" => "--" to replace the google base unacceptable hyphens that were getting removed leaving no space between words, with the hyphen that is acceptable "-" or "--".
So hopefully this helps some with large databases that contain a variety of characters that are either getting left our or causing the item to not get listed due to invalid encoding.
Now here is my question: Is there any way to get the ampersand & and double " or even single quote ' characters to pass through the feeder and display with the product listing?
I don't really know php so I cannot see where they are being removed in this code, yet I think when I was messing with google_base.php before, I was able to get these characters to show up in my listings.
If I cannot get a solution, I'm going to leave as is because at least all of my products are getting listed and are searchable. It would just be a nicer presentation.
Thank you all by the way. I've been able to build my first shopping website with 13+K products and get it live with what I've already learned from you!