When you install Ultimate Seo Urls 5 (USU5) and you allready have Google XML sitemap installed, then the chances are big that you will get trouble with Google XML sitemap. With the installation files of Ultimate Seo Urls 5 you can find under the extras folder 2 files of Google XML sitemap, that you have to replace. These files are catalog/googlesitemap/index.php and catalog/googlesitemap/sitemap.class.php
The problem with this files is that FWR media made them for version 1.1 of Google XML sitemaps, and that we need files now for version 1.3.
FWR media gave in the forum of USU5 allready some code to work with version 1.2. So I compared the origininal files for version 1.1 with the files original in Google sitemaps and then with version 1.2 and version 1.3. I finally had a working version. I will give you the codes for the files below. I can’t guarantee that Google XML sitemaps is working for 100%, but I have it now for a couple of weeks and the sitemaps are all working and Google is indexing my site.
Warning: be careful if you copy any code from the blog. It is possible that WordPress breaks the code and that during copying whitespaces or other hidden caracters occur in your files, so always check if your codes look normal
Files
catalog/googlesitemap/index.php
<?php
/**
* Google XML Sitemap Feed Cron Script
*
* The Google sitemap service was announced on 2 June 2005 and represents
* a huge development in terms of crawler technology. This contribution is
* designed to create the sitemap XML feed per the specification delineated
* by Google. This cron script will call the code to create the scripts and
* eliminate the session auto start issues.
* @package Google-XML-Sitemap-Feed
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version 1.2
* @link http://www.oscommerce-freelancers.com/ osCommerce-Freelancers
* @link http://www.google.com/webmasters/sitemaps/docs/en/about.html About Google Sitemap
* @copyright Copyright 2005, Bobby Easland
* @author Bobby Easland
* @filesource
*/chdir(‘../’);
/**
* Option to compress the files
*/
define(‘GOOGLE_SITEMAP_COMPRESS’, ‘false’);
/**
* Option for change frequency of products
*/
define(‘GOOGLE_SITEMAP_PROD_CHANGE_FREQ’, ‘weekly’);
/**
* Option for change frequency of categories
*/
define(‘GOOGLE_SITEMAP_CAT_CHANGE_FREQ’, ‘weekly’);
/**
* Carried over from application_top.php for compatibility
*/
define(‘GOOGLE_SITEMAP_MAN_CHANGE_FREQ’, ‘weekly’);
/**
* Carried over from application_top.php for compatibility
*/
define(‘GOOGLE_SITEMAP_SPECIALS_CHANGE_FREQ’, ‘weekly’);
/**
* Carried over from application_top.php for compatibility
*/
define(‘GOOGLE_SITEMAP_PAGES_CHANGE_FREQ’, ‘weekly’);
include_once ‘includes/application_top.php’;$mapfile = ((GOOGLE_XML_SITEMAP_SEO != ‘Standard’) ? ’sitemap.class_Alternate.php’ : ’sitemap.class.php’);
require_once(‘googlesitemap/’ . $mapfile);
$google = new GoogleSitemap(DB_SERVER, DB_SERVER_USERNAME, DB_DATABASE, DB_SERVER_PASSWORD);$submit = true;
echo ‘<pre>’;
if ($google->GenerateProductSitemap()){
echo ‘Generated Google Product Sitemap Successfully’ . “\n\n”;
} else {
$submit = false;
echo ‘ERROR: Google Product Sitemap Generation FAILED!’ . “\n\n”;
}if ($google->GenerateCategorySitemap()){
echo ‘Generated Google Category Sitemap Successfully’ . “\n\n”;
} else {
$submit = false;
echo ‘ERROR: Google Category Sitemap Generation FAILED!’ . “\n\n”;
}if (GOOGLE_XML_SITEMAP_CREATE_MANU == ‘true’) {
$showManufacturers = true;
if ($google->GenerateManufacturerSitemap()){
echo ‘Generated Google Manufacturers Sitemap Successfully’ . “\n\n”;
} else {
$manufacturers_query = tep_db_query(“select manufacturers_id from ” . TABLE_MANUFACTURERS . ” limit 1″);
if (tep_db_num_rows($manufacturers_query) > 0)
{
$submit = false;
echo ‘ERROR: Google Manufacturers Sitemap Generation FAILED!’ . “\n\n”;
}
else
{
$showManufacturers = false;
echo ‘Google Sitemap Manufacturers not generated – no Manufacturers found!’ . “\n\n”;
}
}
}if (GOOGLE_XML_SITEMAP_CREATE_SPECIALS == ‘true’) {
$showSpecials = true;
if ($google->GenerateSpecialsSitemap()){
echo ‘Generated Google Specials Sitemap Successfully’ . “\n\n”;
} else {
$specials_query = tep_db_query(“select p.products_id from ” . TABLE_PRODUCTS . ” p, ” . TABLE_PRODUCTS_DESCRIPTION . ” pd, ” . TABLE_SPECIALS . ” s where p.products_status = ‘1′ and p.products_id = s.products_id and pd.products_id = s.products_id and pd.language_id = ‘” . (int)$languages_id . “‘ and s.status = ‘1′ limit 1″);
if (tep_db_num_rows($specials_query) > 0)
{
$submit = false;
echo ‘ERROR: Google Specials Sitemap Generation FAILED!’ . “\n\n”;
}
else
{
$showSpecials = false;
echo ‘Google Sitemap Specials not generated – no specials found!’ . “\n\n”;
}
}
}if (GOOGLE_XML_SITEMAP_CREATE_PAGES == ‘true’) {
if ($google->GeneratePagesSitemap()){
echo ‘Generated Google Pages Sitemap Successfully’ . “\n\n”;
} else {
$submit = false;
echo ‘ERROR: Google Pages Sitemap Generation FAILED!’ . “\n\n”;
}
}if ($google->GenerateSitemapIndex()){
echo ‘Generated Google Sitemap Index Successfully’ . “\n\n”;
} else {
$submit = false;
echo ‘ERROR: Google Sitemap Index Generation FAILED!’ . “\n\n”;
}
if ($submit){
echo ‘CONGRATULATIONS! All files generated successfully.’ . “\n\n”;
echo ‘If you have not already submitted the sitemap index to Google click the link below.’ . “\n”;
echo ‘Before you do I HIGHLY recommend that you view the XML files to make sure the data is correct.’ . “\n\n”;
echo $google->GenerateSubmitURL() . “\n\n”;
echo ‘For your convenience here is the CRON command for your site:’ . “\n”;
echo ‘php ‘ . dirname($_SERVER['SCRIPT_FILENAME']) . ‘/index.php’ . “\n\n”;
echo ‘Here is your sitemap index: ‘ . $google->base_url . ’sitemapindex.xml’ . “\n”;
echo ‘Here is your product sitemap: ‘ . $google->base_url . ’sitemapproducts.xml’ . “\n”;
echo ‘Here is your category sitemap: ‘ . $google->base_url . ’sitemapcategories.xml’ . “\n”;
if (GOOGLE_XML_SITEMAP_CREATE_MANU == ‘true’ && $showManufacturers)
echo ‘Here is your manufacturers sitemap: ‘ . $google->base_url . ’sitemapmanufacturers.xml’ . “\n”;if (GOOGLE_XML_SITEMAP_CREATE_PAGES == ‘true’)
echo ‘Here is your pages sitemap: ‘ . $google->base_url . ’sitemappages.xml’ . “\n”;
if (GOOGLE_XML_SITEMAP_CREATE_SPECIALS == ‘true’ && $showSpecials)
echo ‘Here is your specials sitemap: ‘ . $google->base_url . ’sitemapspecials.xml’ . “\n”;
} else {
print_r($google->debug);
}echo ‘</pre>’;
include_once ‘includes/application_bottom.php’;
?>
catalog/googlesitemap/sitemap.class.php
<?php
/**
* Google XML Sitemap Feed
*
* The Google sitemap service was announced on 2 June 2005 and represents
* a huge development in terms of crawler technology. This contribution is
* designed to create the sitemap XML feed per the specification delineated
* by Google.
* @package Google-XML-Sitemap-Feed
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version 1.0
* @link http://www.oscommerce-freelancers.com/ osCommerce-Freelancers
* @link http://www.google.com/webmasters/sitemaps/docs/en/about.html About Google Sitemap
* @copyright Copyright 2005, Bobby Easland
* @author Bobby Easland
* @filesource
*//**
* MySQL_Database Class
*
* The MySQL_Database class provides abstraction so the databaes can be accessed
* without having to use tep API functions. This class has minimal error handling
* so make sure your code is tight!
* @package Google-XML-Sitemap-Feed
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version 1.1
* @link http://www.oscommerce-freelancers.com/ osCommerce-Freelancers
* @copyright Copyright 2005, Bobby Easland
* @author Bobby Easland
*//**
* Google Sitemap Base Class
*
* The MySQL_Database class provides abstraction so the databaes can be accessed
* @package Google-XML-Sitemap-Feed
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version 1.2
* @link http://www.oscommerce-freelancers.com/ osCommerce-Freelancers
* @link http://www.google.com/webmasters/sitemaps/docs/en/about.html About Google Sitemap
* @copyright Copyright 2005, Bobby Easland
* @author Bobby Easland
*/
class GoogleSitemap{
/**
* $DB is the database object
* @var object
*/
var $DB;
/**
* $filename is the base name of the feeds (i.e. – ’sitemap’)
* @var string
*/
var $filename;
/**
* $savepath is the path where the feeds will be saved – store root
* @var string
*/
var $savepath;
/**
* $base_url is the URL for the catalog
* @var string
*/
var $base_url;
/**
* $debug holds all the debug data
* @var array
*/
var $debug;
/**
* $excludeList holds the files being excluded from the pages map
* @var array
*/
var $excludeList;
/**
* GoogleSitemap class constructor
* @author Bobby Easland
* @version 1.0
* @param string $host Database host setting (i.e. – localhost)
* @param string $user Database user
* @param string $db Database name
* @param string $pass Database password
*/
function GoogleSitemap(){
$this->filename = “sitemap”;
$this->savepath = DIR_FS_CATALOG;
$this->base_url = HTTP_SERVER . DIR_WS_HTTP_CATALOG;
$this->debug = array();
$this->excludeList = array(0 => ‘account.php’,
1 => ‘account_edit.php’,
2 => ‘account_history.php’,
3 => ‘account_history_info.php’,
4 => ‘account_newsletters.php’,
5 => ‘account_notifications.php’,
6 => ‘account_password.php’,
7 => ‘address_book.php’,
8 => ‘address_book_process.php’,
9 => ‘checkout_confirmation.php’,
10 => ‘checkout_payment.php’,
11 => ‘checkout_payment_address.php’,
12 => ‘checkout_process.php’,
13 => ‘checkout_shipping.php’,
14 => ‘checkout_shipping_address.php’,
15 => ‘checkout_success.php’,
16 => ‘cookie_usage.php’,
17 => ‘create_account.php’,
18 => ‘create_account_success.php’,
19 => ‘down_for_maintenance.php’,
20 => ‘download.php’,
21 => ‘info_shopping_cart.php’,
22 => ‘links_submit_success.php’,
23 => ‘login.php’,
24 => ‘logoff.php’,
25 => ‘password_forgotten.php’,
26 => ’shopping_cart.php’,
27 => ’ssl_check.php’
);
// Add the pages listed in the database
$adminExclude = explode(“,”,GOOGLE_XML_SITEMAP_EXCLUDE_PAGES);
$newFiles = array();
for ($i = 0; $i < count($adminExclude); ++$i)
$newFiles[] = trim($adminExclude[$i]);
$this->excludeList = array_merge($this->excludeList, $newFiles);
} # end class constructor/**
* Function to save the sitemap data to file as either XML or XML.GZ format
* @author Bobby Easland
* @version 1.1
* @param string $data XML data
* @param string $type Feed type (index, products, categories)
* @return boolean
*/
function SaveFile($data, $type){
$filename = $this->savepath . $this->filename . $type;if (strpos($filename, ‘googlesitemap’) !== FALSE)
{
$file_check = file_exists($filename) ? ‘true’ : ‘false’;
$this->debug['SAVE_FILE_XML'][] = array(‘file’ => $filename, ’status’ => ‘failure due to incorrect file name’, ‘file_exists’ => $file_check);
return false;
}
$compress = defined(‘GOOGLE_SITEMAP_COMPRESS’) ? GOOGLE_SITEMAP_COMPRESS : ‘false’;
if ($type == ‘index’) $compress = ‘false’;
switch($compress){
case ‘true’:
$filename .= ‘.xml.gz’;
if ($gz = gzopen($filename,’wb9′)){
gzwrite($gz, $data);
gzclose($gz);
$this->debug['SAVE_FILE_COMPRESS'][] = array(‘file’ => $filename, ’status’ => ’success’, ‘file_exists’ => ‘true’);
return true;
} else {
$file_check = file_exists($filename) ? ‘true’ : ‘false’;
$this->debug['SAVE_FILE_COMPRESS'][] = array(‘file’ => $filename, ’status’ => ‘failure’, ‘file_exists’ => $file_check);
return false;
}
break;
default:
$filename .= ‘.xml’;
if (GOOGLE_XML_SITEMAP_SHOW_DIAGNOSTIC == ‘true’)
echo ‘Opening ‘.$filename. ‘<br>FS_CAT ‘.DIR_FS_CATALOG. ‘<br>Server ‘ . HTTP_SERVER . ‘<br>Save Path ‘. $this->savepath . ‘<br>WS_CAT ‘. DIR_WS_HTTP_CATALOG.’ <br>’;
if ($fp = fopen($filename, ‘w+’)){
echo ‘Write ‘.$filename.’<br>’;
fwrite($fp, $data);
fclose($fp);
$this->debug['SAVE_FILE_XML'][] = array(‘file’ => $filename, ’status’ => ’success’, ‘file_exists’ => ‘true’);
return true;
} else {
$file_check = file_exists($filename) ? ‘true’ : ‘false’;
$this->debug['SAVE_FILE_XML'][] = array(‘file’ => $filename, ’status’ => ‘failure’, ‘file_exists’ => $file_check);
return false;
}
break;
} # end switch
} # end function
/**
* Function to compress a normal file
* @author Bobby Easland
* @version 1.0
* @param string $file
* @return boolean
*/
function CompressFile($file){
$source = $this->savepath . $file . ‘.xml’;
$filename = $this->savepath . $file . ‘.xml.gz’;
$error_encountered = false;
if( $gz_out = gzopen($filename, ‘wb9′) ){
if($fp_in = fopen($source,’rb’)){
while(!feof($fp_in)) gzwrite($gz_out, fread($fp_in, 1024*512));
fclose($fp_in);
} else {
$error_encountered = true;
}
gzclose($gz_out);
} else {
$error_encountered = true;
}
if($error_encountered){
return false;
} else {
return true;
}
} # end function/**
* Function to generate sitemap file from data
* @author Bobby Easland
* @version 1.0
* @param array $data
* @param string $file
* @return boolean
*/
function GenerateSitemap($data, $file){
$content = ‘<?xml version=”1.0″ encoding=”UTF-8″?>’ . “\n”;
$content = ‘<?xml-stylesheet type=”text/xsl” href=”gss.xsl”?>’ . “\n”;
$content .= ‘<urlset xmlns=”http://www.google.com/schemas/sitemap/0.84″>’ . “\n”;
foreach ($data as $url){
$content .= “\t” . ‘<url>’ . “\n”;
$content .= “\t\t” . ‘<loc>’.$url['loc'].’</loc>’ . “\n”;
$content .= “\t\t” . ‘<lastmod>’.$url['lastmod'].’</lastmod>’ . “\n”;
$content .= “\t\t” . ‘<changefreq>’.$url['changefreq'].’</changefreq>’ . “\n”;
$content .= “\t\t” . ‘<priority>’.$url['priority'].’</priority>’ . “\n”;
$content .= “\t” . ‘</url>’ . “\n”;
} # end foreach
$content .= ‘</urlset>’;
return $this->SaveFile($content, $file);
} # end function
/**
* Function to generate sitemap index file
* @author Bobby Easland
* @version 1.1
* @return boolean
*/
function GenerateSitemapIndex(){
$content = ‘<?xml version=”1.0″ encoding=”UTF-8″?>’ . “\n”;
$content = ‘<?xml-stylesheet type=”text/xsl” href=”gss.xsl”?>’ . “\n”; //human readable
$content .= ‘<sitemapindex xmlns=”http://www.google.com/schemas/sitemap/0.84″>’ . “\n”;
$pattern = defined(‘GOOGLE_SITEMAP_COMPRESS’)
? GOOGLE_SITEMAP_COMPRESS == ‘true’
? ”{sitemap*.xml.gz}”
: ”{sitemap*.xml}”
: ”{sitemap*.xml}”;
foreach ( glob($this->savepath . $pattern, GLOB_BRACE) as $filename ) {
if ( eregi(‘index’, $filename) ) continue;
if ( eregi(‘manufacturers’, $filename) && GOOGLE_XML_SITEMAP_CREATE_MANU != ‘true’ ) continue;
if ( eregi(‘pages’, $filename) && GOOGLE_XML_SITEMAP_CREATE_PAGES != ‘true’ ) continue;
if ( eregi(’specials’, $filename) && GOOGLE_XML_SITEMAP_CREATE_SPECIALS != ‘true’ ) continue;
$content .= “\t” . ‘<sitemap>’ . “\n”;
$content .= “\t\t” . ‘<loc>’.$this->base_url . basename($filename).’</loc>’ . “\n”;
$content .= “\t\t” . ‘<lastmod>’.date (“Y-m-d”, filemtime($filename)).’</lastmod>’ . “\n”;
$content .= “\t” . ‘</sitemap>’ . “\n”;
} # end foreach
$content .= ‘</sitemapindex>’;
return $this->SaveFile($content, ‘index’);
} # end function
/**
* Function to generate product sitemap data
* @author Bobby Easland
* @version 1.1
* @return boolean
*/
function GenerateProductSitemap(){
$sql = “SELECT products_id as pID, products_date_added as date_added, products_last_modified as last_mod, products_ordered
FROM ” . TABLE_PRODUCTS . “
WHERE products_status=’1′
ORDER BY products_ordered DESC”;
if ( $products_query = tep_db_query($sql) ){
$this->debug['QUERY']['PRODUCTS']['STATUS'] = ’success’;
$this->debug['QUERY']['PRODUCTS']['NUM_ROWS'] = tep_db_num_rows($products_query);
$container = array();
$number = 0;
$top = 0;
while( $result = tep_db_fetch_array($products_query) ){
$top = max($top, $result['products_ordered']);
$location = tep_href_link(FILENAME_PRODUCT_INFO, ‘products_id=’ . $result['pID'], ‘NONSSL’, false);
$lastmod = tep_not_null($result['last_mod']) ? $result['last_mod'] : $result['date_added'];
$changefreq = GOOGLE_SITEMAP_PROD_CHANGE_FREQ;
$ratio = $top > 0 ? $result['products_ordered']/$top : 0;
$priority = $ratio < .1 ? .1 : number_format($ratio, 1, ‘.’, ”);
$container[] = array(‘loc’ => htmlspecialchars(utf8_encode($location)),
‘lastmod’ => date (“Y-m-d”, strtotime($lastmod)),
‘changefreq’ => $changefreq,
‘priority’ => $priority
);
if ( sizeof($container) >= 50000 ){
$type = $number == 0 ? ‘products’ : ‘products’ . $number;
$this->GenerateSitemap($container, $type);
$container = array();
$number++;
}
} # end while
tep_db_free_result($products_query);
if ( sizeof($container) > 0 ) {
$type = $number == 0 ? ‘products’ : ‘products’ . $number;
return $this->GenerateSitemap($container, $type);
} # end if
} else {
$this->debug['QUERY']['PRODUCTS']['STATUS'] = ‘false’;
$this->debug['QUERY']['PRODUCTS']['NUM_ROWS'] = ‘0′;
}
} # end function
/**
* Funciton to generate category sitemap data
* @author Bobby Easland
* @version 1.1
* @return boolean
*/
function GenerateCategorySitemap(){
$sql = “SELECT categories_id as cID, date_added, last_modified as last_mod
FROM ” . TABLE_CATEGORIES . “
ORDER BY parent_id ASC, sort_order ASC, categories_id ASC”;
if ( $categories_query = tep_db_query($sql) ){
$this->debug['QUERY']['CATEOGRY']['STATUS'] = ’success’;
$this->debug['QUERY']['CATEOGRY']['NUM_ROWS'] = tep_db_num_rows($categories_query);
$container = array();
$number = 0;
while( $result = tep_db_fetch_array($categories_query) ){
$location =tep_href_link(FILENAME_DEFAULT, ‘cPath=’ . $this->GetFullcPath($result['cID']), ‘NONSSL’, false);
$lastmod = tep_not_null($result['last_mod']) ? $result['last_mod'] : $result['date_added'];
$changefreq = GOOGLE_SITEMAP_CAT_CHANGE_FREQ;
$priority = .5;
$container[] = array(‘loc’ => htmlspecialchars(utf8_encode($location)),
‘lastmod’ => date (“Y-m-d”, strtotime($lastmod)),
‘changefreq’ => $changefreq,
‘priority’ => $priority
);
if ( sizeof($container) >= 50000 ){
$type = $number == 0 ? ‘categories’ : ‘categories’ . $number;
$this->GenerateSitemap($container, $type);
$container = array();
$number++;
}
} # end while
tep_db_free_result($categories_query);
if ( sizeof($container) > 0 ) {
$type = $number == 0 ? ‘categories’ : ‘categories’ . $number;
return $this->GenerateSitemap($container, $type);
} # end if
} else {
$this->debug['QUERY']['CATEOGRY']['STATUS'] = ‘false’;
$this->debug['QUERY']['CATEOGRY']['NUM_ROWS'] = ‘0′;
}
} # end function
/**
* Funciton to generate manufacturer sitemap data
* @author Jack_mcs from Bobbys code
* @version 1.1
* @return boolean
*/
function GenerateManufacturerSitemap(){
$sql = “SELECT manufacturers_id as mID, date_added, last_modified as last_mod, manufacturers_name
FROM ” . TABLE_MANUFACTURERS . ” order by manufacturers_name DESC”;if ( $manufacturers_query = tep_db_query($sql) ){
$this->debug['QUERY']['MANUFACTURERS']['STATUS'] = ’success’;
$this->debug['QUERY']['MANUFACTURERS']['NUM_ROWS'] = tep_db_num_rows($manufacturers_query);
$container = array();
$number = 0;
while( $result = tep_db_fetch_array($manufacturers_query) ){
$location = tep_href_link(FILENAME_DEFAULT, ‘manufacturers_id=’ . $result['mID'], ‘NONSSL’, false);
$lastmod = tep_not_null($result['last_mod']) ? $result['last_mod'] : $result['date_added'];
$changefreq = GOOGLE_SITEMAP_MAN_CHANGE_FREQ;
$priority = .5;$container[] = array(‘loc’ => htmlspecialchars(utf8_encode($location)),
‘lastmod’ => date (“Y-m-d”, strtotime($lastmod)),
‘changefreq’ => $changefreq,
‘priority’ => $priority
);
if ( sizeof($container) >= 50000 ){
$type = $number == 0 ? ‘manufacturers’ : ‘manufacturers’ . $number;
$this->GenerateSitemap($container, $type);
$container = array();
$number++;
}
} # end while
tep_db_free_result($manufacturers_query);
if ( sizeof($container) > 0 ) {
$type = $number == 0 ? ‘manufacturers’ : ‘manufacturers’ . $number;
return $this->GenerateSitemap($container, $type);
} # end if
} else {
$this->debug['QUERY']['MANUFACTURERS']['STATUS'] = ‘false’;
$this->debug['QUERY']['MANUFACTURERS']['NUM_ROWS'] = ‘0′;
}
} # end function/**
* Funciton to generate manufacturer sitemap data
* @author Jack_mcs from Bobbys code
* @version 1.1
* @return boolean
*/
function GenerateSpecialsSitemap(){
$sql = “SELECT p.products_id as pID, s.specials_date_added as date_added, s.specials_last_modified as last_mod, p.products_ordered
FROM ” . TABLE_PRODUCTS . ” p left join ” . TABLE_PRODUCTS_DESCRIPTION . ” pd on p.products_id = pd.products_id left join ” . TABLE_SPECIALS . ” s on pd.products_id = s.products_id
where p.products_status = ‘1′ and s.status = ‘1′ order by s.specials_date_added desc “;
if ( $products_query = tep_db_query($sql) ){
$this->debug['QUERY']['SPECIALS']['STATUS'] = ’success’;
$this->debug['QUERY']['SPECIALS']['NUM_ROWS'] = tep_db_num_rows($products_query);
$container = array();
$number = 0;
$top = 0;
while( $result = tep_db_fetch_array($products_query) ){
$top = max($top, $result['products_ordered']);
$location = tep_href_link(FILENAME_PRODUCT_INFO, ‘products_id=’ . $result['pID'], ‘NONSSL’, false);
$lastmod = tep_not_null($result['last_mod']) ? $result['last_mod'] : $result['date_added'];
$changefreq = GOOGLE_SITEMAP_SPECIALS_CHANGE_FREQ;
$ratio = $top > 0 ? $result['products_ordered']/$top : 0;
$priority = $ratio < .1 ? .1 : number_format($ratio, 1, ‘.’, ”);
$container[] = array(‘loc’ => htmlspecialchars(utf8_encode($location)),
‘lastmod’ => date (“Y-m-d”, strtotime($lastmod)),
‘changefreq’ => $changefreq,
‘priority’ => $priority
);
if ( sizeof($container) >= 50000 ){
$type = $number == 0 ? ’specials’ : ’specials’ . $number;
$this->GenerateSitemap($container, $type);
$container = array();
$number++;
}
} # end while
tep_db_free_result($products_query);
if ( sizeof($container) > 0 ) {
$type = $number == 0 ? ’specials’ : ’specials’ . $number;
return $this->GenerateSitemap($container, $type);
} # end if
} else {
$this->debug['QUERY']['SPECIALS']['STATUS'] = ‘false’;
$this->debug['QUERY']['SPECIALS']['NUM_ROWS'] = ‘0′;
}
} # end function
/**
* Function to generate sitemap pages file
* @author Jack_mcs
* @version 1.1
* @return boolean
*/
function GeneratePagesSitemap(){
$container = array();
$changefreq = GOOGLE_SITEMAP_PAGES_CHANGE_FREQ;
$priority = ‘.1′;include_once(DIR_WS_CLASSES . ‘language.php’);
$lng = new language();
$slash = substr(DIR_FS_CATALOG, 0 -1) == ‘/’ ? 1 : 0;
$path = (($pos = strpos(DIR_FS_CATALOG, “googlesitemap”)) !== FALSE) ? substr(DIR_FS_CATALOG, 0, -strlen(‘googlesitemap’) – $slash) : DIR_FS_CATALOG;
$pages = $this->GetPagesArray($path, DIR_WS_LANGUAGES . $lng->language['directory'], $lng->language['id']);
for ($i = 0; $i < count($pages); ++$i)
{
$container[] = array(‘loc’ => htmlspecialchars(utf8_encode($pages[$i]['filename'])),
‘lastmod’ => $pages[$i]['lastmod'],
‘changefreq’ => $changefreq,
‘priority’ => $priority
);
}
if ($i > 0)
return $this->GenerateSitemap($container, ‘pages’);
} # end function/**
* Function to retrieve full cPath from category ID
* @author Bobby Easland
* @version 1.0
* @param mixed $cID Could contain cPath or single category_id
* @return string Full cPath string
*/
function GetFullcPath($cID){
if ( ereg(‘_’, $cID) ){
return $cID;
} else {
$c = array();
$this->GetParentCategories($c, $cID);
$c = array_reverse($c);
$c[] = $cID;
$cID = sizeof($c) > 1 ? implode(‘_’, $c) : $cID;
return $cID;
}
} # end function/**
* Recursion function to retrieve parent categories from category ID
* @author Bobby Easland
* @version 1.0
* @param mixed $categories Passed by reference
* @param integer $categories_id
*/
function GetParentCategories(&$categories, $categories_id) {
$sql = “SELECT parent_id
FROM ” . TABLE_CATEGORIES . “
WHERE categories_id=’” . (int)$categories_id . “‘”;
$parent_categories_query = tep_db_query($sql);
while ($parent_categories = tep_db_fetch_array($parent_categories_query)) {
if ($parent_categories['parent_id'] == 0) return true;
$categories[sizeof($categories)] = $parent_categories['parent_id'];
if ($parent_categories['parent_id'] != $categories_id) {
$this->GetParentCategories($categories, $parent_categories['parent_id']);
}
}
} # end function/**
* Utility function to read and return the contents of a GZ formatted file
* @author Bobby Easland
* @version 1.0
* @param string $file File to open
* @return string
*/
function ReadGZ( $file ){
$file = $this->savepath . $file;
$lines = gzfile($file);
return implode(”, $lines);
} # end function
/**
* Utility function to generate the submit URL
* @author Bobby Easland
* @version 1.0
* @return string
*/
function GenerateSubmitURL(){
$url = urlencode($this->base_url . ’sitemapindex.xml’);
return htmlspecialchars(utf8_encode(‘http://www.google.com/webmasters/sitemaps/ping?sitemap=’ . $url));
} # end function
function GetPagesArray($locn, $languagesDir, $languageID)
{
$cwd = getcwd();
$pagesArray = array();
$end = (substr($locn, strlen($locn) – 1) !== ‘/’) ? ‘/’ : ”;
$root = $locn . $end;
$path = $root . $languagesDir;
$end = (substr($path, strlen($path) – 1) !== ‘/’) ? ‘/’ : ”;
$path = $path . $end;
chdir ($path);foreach (glob(“*.php”) as $filename)
{
if (! in_array($filename, $this->excludeList) && $this->IsViewable($root . $filename))
{
$r = @stat($filename);
$displayName = ucwords(str_replace(“_”, ” “, substr($filename, 0, strpos($filename, “.”)))); //remove the .php and underscores
$pagesArray[] = array(‘filename’ => $this->base_url . $filename,
‘lastmod’ => gmstrftime (“%Y-%m-%d”, $r[9]));
/*** ADD ARTICLES ***/
if ($filename === ‘articles.php’)
{
$sql = “SELECT a.articles_id, DATE_FORMAT(a.articles_last_modified,’%Y-%m-%d’) AS lastmod, DATE_FORMAT(articles.date_added,’%Y-%m-%d’) AS date_added from ” . TABLE_ARTICLES . ” a left join ” . TABLE_ARTICLES_DESCRIPTION . ” ad on a.articles_id = ad.articles_id where a.articles_status = ‘1′ and ad.language_id = ‘” . (int)$languageID . “‘”;
if ( $articles_query = tep_db_query($sql) )
{
while( $result = tep_db_fetch_array($articles_query) )
{
$pagesArray[] = array(‘filename’ => $this->base_url . ‘article_info.php?articles_id=’ . $result['articles_id'],
‘lastmod’ => $this->NotNull($result['lastmod']) ? $result['lastmod'] : $result['date_added']);
}
}
$sql = “SELECT t.topics_id, DATE_FORMAT(t.last_modified,’%Y-%m-%d’) AS lastmod, DATE_FORMAT(t.date_added,’%Y-%m-%d’) AS date_added from ” . TABLE_TOPICS . ” t left join ” . TABLE_TOPICS_DESCRIPTION . ” td on t.topics_id = td.topics_id where td.language_id = ‘” . (int)$languageID . “‘”;
if ( $articles_query = tep_db_query($sql) )
{
while( $result = tep_db_fetch_array($articles_query) )
{
$pagesArray[] = array(‘filename’ => $this->base_url . ‘articles.php?tPath=’ . $result['topics_id'],
‘lastmod’ => $this->NotNull($result['lastmod']) ? $result['lastmod'] : $result['date_added']);
}
}
}
/*** ADD INFORMATION PAGES ***/
else if ($filename === ‘information.php’)
{
$sql = “SELECT information_id from ” . TABLE_INFORMATION . ” where visible = ‘1′ and language_id = ‘” . (int)$languageID . “‘”;
if ( $information_query = tep_db_query($sql) )
{
while( $result = tep_db_fetch_array($information_query) )
{
$pagesArray[] = array(‘filename’ => $this->base_url . ‘information.php?info_id=’ . $result['information_id'],
‘lastmod’ => gmstrftime (“%Y-%m-%d”, $r[9]));
}
}
}
}
}/*** ADD PAGE MANAGER ***/
//special case since it doesn’t have a language file
if (file_exists($root.’pages.php’) && $this->IsViewable($root.’pages.php’))
{
$r = @stat(‘pages.php’);
$pagesArray[] = array(‘filename’ => $this->base_url . ‘pages.php’,
‘lastmod’ => gmstrftime (“%Y-%m-%d”, $r[9]));
$sql = “SELECT p.pages_id, p.pages_name from ” . TABLE_PAGES . ” p left join ” . TABLE_PAGES_DESCRIPTION . ” pd on p.pages_id = pd.pages_id where p.pages_status = ‘1′ and pd.language_id = ‘” . (int)$languageID . “‘”;
if ( $pages_query = tep_db_query($sql) )
{
while( $result = tep_db_fetch_array($pages_query) )
{
$pagesArray[] = array(‘filename’ => $this->base_url . ‘pages.php?page=’ . $result['pages_name'],
‘lastmod’ => gmstrftime (“%Y-%m-%d”, $r[9]));
}
}
}
chdir ($cwd);
return $pagesArray;
}
function IsViewable($file)
{
if (($fp = @file($file)))
{
for ($idx = 0; $idx < count($fp); ++$idx)
{
if (strpos($fp[$idx], “<head>”) !== FALSE)
return true;
}
}
return false;
}
} # end class
?>