Jump to content
jdice

SITEMAP GENERATOR BY BOBBY EASLAND

Recommended Posts

Hi...I uploaded googlesitemap generator by bobby about a year ago. It only has two files...googlesitemapcategories.php & googlesitemapproducts.php. Then I go to google.com/webmasters/sitemaps and put my website in. However, the googlesitecategories.php is fine but googlesitemapproducts.php is not. Google is giving me this error: 1193 Invalid date

An invalid date was found. Please fix the date or formatting before resubmitting....FOR MY googlesitemapproducts.php page. does anyone know how I fix this? Here is my products.php page:

<?php 
       /** 
        * Google Sitemap Generator 
        *  
        * Script to generate a Google sitemap for osCommerce based stores 
        * 
        * @license http://opensource.org/licenses/gpl-license.php GNU Public License 
        * @version 1.2 
        * @link http://www.oscommerce-freelancers.com/ osCommerce-Freelancers 
        * @copyright Copyright 2006, Bobby Easland  
        * @author Bobby Easland  
        * @filesource 
        */ 

       /* 
        * Include the application_top.php script 
        */ 
       include_once('includes/application_top.php'); 

       /* 
        * Send the XML content header 
        */ 
       header('Content-Type: text/xml'); 

       /* 
        * Echo the XML out tag 
        */ 
       echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; 
?> 
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> 
<?php 

       /* 
        * Define the uniform node function  
        */ 
       function GenerateNode($data){ 
               $content = ''; 
               $content .= "\t" . '<url>' . "\n"; 
               $content .= "\t\t" . '<loc>'.trim($data['loc']).'</loc>' . "\n"; 
               $content .= "\t\t" . '<lastmod>'.trim($data['lastmod']).'</lastmod>' . "\n"; 
               $content .= "\t\t" . '<changefreq>'.trim($data['changefreq']).'</changefreq>' . "\n"; 
               $content .= "\t\t" . '<priority>'.trim($data['priority']).'</priority>' . "\n"; 
               $content .= "\t" . '</url>' . "\n"; 
               return $content; 
       } # end function 

       /* 
        * Define the SQL for the products query  
        */ 
       $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_last_modified DESC,  
                                                products_date_added DESC,  
                                                                        products_ordered DESC"; 

       /* 
        * Execute the query 
        */ 
       $query = tep_db_query($sql); 

       /* 
        * If there are returned rows... 
        * Basic sanity check  
        */ 
       if ( tep_db_num_rows($query) > 0 ){ 

               /* 
                * Initialize the variable containers 
                */ 
               $container = array(); 
               $number = 0; 
               $top = 0; 

               /* 
                * Loop the query result set 
                */ 
               while( $result = tep_db_fetch_array($query) ){ 
                       $top = max($top, $result['products_ordered']); 
                       $location = tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $result['pID'], 'NONSSL', false); 
                       if ( tep_not_null($result['last_mod']) ){ 
                               $lastmod = $result['last_mod']; 
                       } else { 
                               $lastmod = $result['date_added']; 
                       } 
                       $changefreq = 'weekly'; 
                       $ratio = ($top > 0) ? ($result['products_ordered']/$top) : 0; 
                       $priority = $ratio < .1 ? .1 : number_format($ratio, 1, '.', '');  

                       /* 
                        * Initialize the content container array 
                        */ 
                       $container = array('loc' => htmlspecialchars(utf8_encode($location)), 
                                                                                                'lastmod' => date ("Y-m-d", strtotime($lastmod)), 
                                                                                                'changefreq' => $changefreq, 
                                                                                                'priority' => $priority 
                                                                                               ); 

                       /* 
                        * Echo the generated node 
                        */ 
                       echo generateNode($container); 
               } # end while 
       } # end if 

       /* 
        * Close the urlset 
        */ 
       echo '</urlset>'; 

       /* 
        * Include the application_bottom.php script  
        */ 
       include_once('includes/application_bottom.php'); 
?>

Share this post


Link to post
Share on other sites

I had problems with that as well. I didn't keep track of the changes, so here's the whole file:

<?php
/*
 $Id: sitemap_categories.php v1.4 2008-11-29 Kymation $
 $Loc: catalog/

 See http://www.sitemaps.org/protocol.php for the expected output

 Original author's information:
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 * @link http://www.oscommerce-freelancers.com/ osCommerce-Freelancers
 * @copyright Copyright 2006, Bobby Easland 
 * @author Bobby Easland 
 * @filesource
 */


////
// Set up and initialize data

 // Get all osCommerce functions and open the database connection
 include_once('includes/application_top.php');

 // Set the frequency of change for your categories. 
 // Valid values are:
 //   always
 //   hourly
 //   daily
 //   weekly
 //   monthly
 //   yearly
 //   never
 define ('CHANGE_FREQUENCY', 'weekly');

 // Send the XML content header
 header ('Content-Type: text/xml');

 // Output the XML and opening URLSET tags
 echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
 echo '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' . "\n" . 
              'xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 ' . "\n" . 
              'http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" ' . "\n" . 
              'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";

 // Initialize the data array
 $xml_data = array();


////
// Get the products data and format it 

 // SQL for the products data
 $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_last_modified DESC, 
                  products_date_added DESC, 
                  products_ordered DESC";
 $query = tep_db_query ($sql);

 // Check that the query returned some data
 if (tep_db_num_rows ($query) > 0) {
   // Set initial parameters
   $top = 0;

   // Loop through the query result and populate the container array
   while ($result = tep_db_fetch_array ($query) ) {
     $location = tep_href_link (FILENAME_PRODUCT_INFO, 'products_id=' . $result['pID'], 'NONSSL', false);
     $lastmod = max ($result['last_mod'], 
                     $result['date_added']
                    );
     // Calculate priority based on number of products ordered
     $top = max ($top, $result['products_ordered']);
     $ratio = ($top > 0) ? ($result['products_ordered'] / $top) : 0;
     $priority = number_format ($ratio, 4, '.', ''); 

     // Set up the products data
     $xml_data = array ('loc' => htmlspecialchars (utf8_encode ($location) ),
                        'lastmod' => date ("Y-m-d", strtotime ($lastmod) ),
                        'changefreq' => CHANGE_FREQUENCY,
                        'priority' => $priority
                       );

     // Output an XML node for each product
     echo tep_generate_sitemap_node ($xml_data);
   } // while ($result
 } //if (tep_db_num_rows


////
// Finish up and quit

// Output the closing urlset
echo '</urlset>';

// Cleanup
include_once ('includes/application_bottom.php');
?>

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites

Hi Jim, I have the same problem with date but when upload your map google giving me eror - invalid url.Can you help me?

Thank you!

Edited by bgtes

Share this post


Link to post
Share on other sites

You may want to try the Google XML Sitemap SEO add instead. It is based on his code but ehanced in a number of ways.

Share this post


Link to post
Share on other sites

Thanks for the quick reply. Do you think I'll lose my indexed pages and google will start index them again if replaced with v 1.5 because my site has thousands of pages

Share this post


Link to post
Share on other sites

No, it shouldn't make a difference because the urls should be the same. If they are not the same, the updating will cause them to be correct so, if anything, it will improve the ratings.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×