Thursday, 27 November 2014 01:46
beggarly

Google News and new form sitemaps...

An open forum for opinions and general questions

Google News and new form sitemaps...

Postby ddevile » Fri Nov 06, 2009 12:25 pm

Google is changing the sitemap for news...

2 steps to becompatible:

1st in line 191 of Administrator/components/com_xmap remove the comments //
so it becomes
$node->keywords = $item->metakey;
And 2nd replace the xmap.xml.php in components/com_xmap with the updated code
Code: Select all
<?php
/**
* $Id: xmap.xml.php 42 2009-08-01 19:09:42Z guilleva $
* $LastChangedDate: 2009-08-01 13:09:42 -0600 (Sat, 01 Aug 2009) $
* $LastChangedBy: guilleva $
* Xmap by Guillermo Vargas
* A Sitemap component for Joomla! CMS (http://www.joomla.org)
* Author Website: http://joomla.vargas.co.cr
* Project License: GNU/GPL http://www.gnu.org/copyleft/gpl.html
*/

defined('_JEXEC') or die('Direct Access to this location is not allowed.');

/** Wraps XML Sitemaps output */
class XmapXML extends Xmap {
   var $_links;
   var $doCompression=1;
   var $isNews=0;

   function XmapXML (&$config, &$sitemap) {
      $this->view = 'xml';
      $this->uids = array();
      Xmap::Xmap($config, $sitemap);
   }

   /** Convert sitemap tree to a XML Sitemap list */
   function printNode( &$node ) {
      global $Itemid;

      if ($this->isNews && (!isset($node->newsItem) || !$node->newsItem) ) {
         return true;
      }

      static $live_site,$len_live_site;
      if ( !isset($live_site) ) {
         $live_site = substr_replace(JURI::root(), "", -1, 1);
         $len_live_site = strlen( $live_site );
      }

      $out = '';

      $link = Xmap::getItemLink($node);

      $is_extern = ( 0 != strcasecmp( substr($link, 0, $len_live_site), $live_site ) );

      if ( !isset($node->browserNav) )
         $node->browserNav = 0;

      if ( $node->browserNav != 3         // ignore "no link"
       && !$is_extern               // ignore external links
       && empty($this->_links[$link]) ) {   // ignore links that have been added already

         $this->count++;
          $this->_links[$link] = 1;


         if( !isset($node->priority) )
            $node->priority = "0.5";

         if( !isset($node->changefreq) )
            $node->changefreq = 'daily';

         $changefreq = $this->sitemap->getProperty('changefreq',$node->changefreq,$node->id,'xml',$node->uid);
         $priority   = $this->sitemap->getProperty('priority',$node->priority,$node->id,'xml',$node->uid);

         echo '<url>'."\n";
         # Removed escapeURL until a better solution for UTF-8 is found
         # echo '<loc>', $this->escapeURL($link) ,'</loc>'."\n";
         echo '<loc>', $link ,'</loc>'."\n";
         if ($this->_isAdmin) {
            echo '<uid>', $node->uid ,'</uid>'."\n";
            echo '<itemid>', $node->id ,'</itemid>'."\n";
         }
         $timestamp = (isset($node->modified) && $node->modified != FALSE && $node->modified != -1) ? $node->modified : time();
         $modified = gmdate('Y-m-d\TH:i:s\Z', $timestamp);
         if ( !$this->isNews ) {
            echo '<lastmod>',$modified,'</lastmod>'."\n";
               echo '<changefreq>',$changefreq,'</changefreq>'."\n";
            echo '<priority>',$priority,'</priority>'."\n";
         } else {
            if ( isset($node->keywords) ) {
               # $keywords = str_replace(array('&amp;','&'),array('&','&amp;'),$node->keywords);
               # $keywords = str_replace('&','&amp;',$node->keywords);
               $keywords =  htmlspecialchars($node->keywords);
            } else {
               $keywords = '';
            }
            $title = htmlspecialchars($node->name);
            echo "<n:news>\n";
            echo "   <n:publication>\n";
            echo "      <n:name>THE_NAME_OF_YOUR_SITE</n:name>\n";
              echo "      <n:language>en</n:language>\n";
               echo "   </n:publication>\n";
               echo "<n:genres>PressRelease, Opinion</n:genres>\n";   
               echo '<n:publication_date>',$modified,'</n:publication_date>'."\n";
               echo '<n:title>',$title,'</n:title>'."\n";
            echo '<n:keywords>',$keywords,'</n:keywords>'."\n";
            echo "</n:news>\n";
         }
         echo '</url>',"\n";
      }
      return true;
   }

        function escapeURL($str) {
            static $xTrans;
            if (!isset($xTrans)) {
                $xTrans = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES);
                foreach ($xTrans as $key => $value)
                    $xTrans[$key] = '&#'.ord($key).';';
                // dont translate the '&' in case it is part of &xxx;
                $xTrans[chr(38)] = '&';
            }   
            return preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,4};)/","&amp;" , strtr($str, $xTrans));
        }

        function changeLevel($level) {
                return true;
        }

   function startOutput( &$menus, &$config ) {
      $live_site = substr_replace(JURI::root(), "", -1, 1);
      
      $this->isNews = JRequest::getInt('news',0);
      // Don't compress something if the server is going todo it anyway. Waste of time.
      $this->doCompression = ($this->sitemap->compress_xml && !ini_get('zlib.output_compression') && ini_get('output_handler')!='ob_gzhandler');

      @ob_end_clean();
      if ($this->doCompression ) {
         $encoding = JResponse::_clientEncoding();
         header('Content-Encoding: ' . $encoding);
         header('X-Content-Encoded-By: Joomla! 1.5');
         ob_start();
         
      }
      header('Content-type: application/xml; charset=utf-8');
      echo '<?xml version="1.0" encoding="UTF-8"?>'."\n";
      if (!$config->exclude_xsl && !$this->isNews ) {
         $user =& JFactory::getUser();
         if ($user->get('gid') == "25") {   
            echo '<?xml-stylesheet type="text/xsl" href="'. $live_site.'/index2.php?option=com_xmap&amp;view=xsladminfile&amp;tmpl=component"?>'."\n";
         } else {
            echo '<?xml-stylesheet type="text/xsl" href="'. $live_site.'/index2.php?option=com_xmap&amp;view=xslfile&amp;tmpl=component"?>'."\n";
         }
      }
      echo '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '.
                     'xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 '.
                     'http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" '.
                     'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"'.
                     ($this->isNews? ' xmlns:n="http://www.google.com/schemas/sitemap-news/0.9"':'').
                     ">\n";

      
   }

   function endOutput( &$menus ) {
      echo "</urlset>\n";
      if ($this->doCompression) {
         $data = ob_get_contents();
         @ob_end_clean();
         echo JResponse::_compress($data);
      }
   }

   function startMenu(&$menu) {
      return true;
   }

   function endMenu(&$menu) {
      return true;
   }

}


Also you must provide some info so edit to suite your needs:
Code: Select all
            echo "      <n:name>THE_NAME_OF_YOUR_SITE</n:name>\n";
            echo "      <n:language>en</n:language>\n";
            echo "<n:genres>PressRelease, Opinion</n:genres>\n";


make sure you read:
http://www.google.com/support/news_pub/bin/answer.py?answer=93992
and
http://www.google.com/support/news_pub/bin/answer.py?hl=en&answer=74288
Works fine


Thank you for this great extension
ddevile
Fresh Boarder
Fresh Boarder
 
Posts: 5
Joined: Sun Apr 19, 2009 7:08 pm

Re: Google News and new form sitemaps...

Postby PEP » Mon Dec 07, 2009 9:17 pm

1st in line 191 of Administrator/components/com_xmap remove the comments //


This should read administrator/components/com_xmap/extensions/com_content.php . Took me a while to find it!

Thanks for the instructions, by the way. Very helpful!

--PEP
PEP
Fresh Boarder
Fresh Boarder
 
Posts: 2
Joined: Mon Dec 07, 2009 9:14 pm

Re: Google News and new form sitemaps...

Postby saigon » Wed Dec 09, 2009 10:00 am

Registered purely to say thanks for the fix...worked flawlessly, I'll obviously upgrade to the next version of xmap when it's released as it's a great component, but this is a great fix in the meantime...Google has reaccepted my news sitemap without a problem :-)

Thanks
saigon
Fresh Boarder
Fresh Boarder
 
Posts: 1
Joined: Wed Dec 09, 2009 9:58 am


Return to General



Who is online

Users browsing this forum: No registered users and 2 guests