Posts for 12th August 2010

Currently the sitemap plugin for FlatPress only pings google with changes.

To add additional ping targets two steps are required.

First generate a new class in the /class folder of the sitemap plugin to represent the ping target. For example to ping bing create a file called pingbingsitemaps.php and copy the following code into it...

<?php
function pingBingSitemaps( $url_xml )
{
   $status = 0;

   $bing = 'www.bing.com';
   if( [email protected]($bing, 80) )
   {
      $req =  'GET /webmaster/ping.aspx?sitemap=' .
              urlencode( $url_xml ) . " HTTP/1.1\r\n" .
              "Host: $bing\r\n" .
              "User-Agent: Mozilla/5.0 (compatible; " .
              PHP_OS . ") PHP/" . PHP_VERSION . "\r\n" .
              "Connection: Close\r\n\r\n";
      fwrite( $fp, $req );
      while( !feof($fp) )
      {
         if( @preg_match('~^HTTP/\d\.\d (\d+)~i', fgets($fp, 128), $m) )
         {
            $status = intval( $m[1] );
            break;
         }
      }
      fclose( $fp );
   }
   return( $status );
}
?>

Second, update the plugin.sitemap.php file in the sitemap folder. Two changes are required. The first is to load the class just created.

...
        // PHP google_sitemap Generator
        require_once( "class/pingbingsitemaps.php" );
        require_once( "class/pinggooglesitemaps.php" );
        require_once( "class/google_sitemap.class.php" ); 
        require_once("defaults.php");
...

Whilst the second is to call the new class.

... 
    // Once the sitemaps are ready, we ping Google...
    if( 200 === ($status=pingGoogleSitemaps($website_url.$sitemap_name)) ) $status = "OK";
    //   print( "Ping to Google Sitemaps successful.\r\n\r\nStatus code: $status." );
    else
      // print( "Cannot ping/connect to Google Sitemaps.\r\n\r\nStatus code: $status."  );
    $status = "KO";

    if( 200 === ($status=pingBingSitemaps($website_url.$sitemap_name)) ) 
        if( "OK" === $status )  
            $status = "OK";
    else
        $status = "KO";

    // end the script.
...