OK here is what I have so far, the problem I have is figuring out if google is responding to it. For this to work you need furl’s on.
1) Download the GoogleSiteMap snippet from the package manager.
2) Setup up a document with
a)Published
b)hidden from menus
c)no template
d)Content Type (this is under Page Settings) needs to be XML
e)in the content box the following [[GoogleSiteMap]]
f)and alias of sitemap
This should create a site map in xml format that google will accept.
3) submit the sitemap to google using http://www.google.com/webmasters/ Not needed unless you want to.
4) setup a template variable as follows
name = NotifyGoogle
input type = checkbox
input options values = ==true
default value = false
make sure all templates have access to it
5)create a plugin called PingGoogleSiteMap
6) paste in the following code
<?php
function pingGoogleSitemaps( $url_xml )
{
$status = 0;
$google = 'www.google.com';
if( $fp=@fsockopen($google, 80) )
{
$req = 'GET /webmasters/sitemaps/ping?sitemap=' .
urlencode( $url_xml ) . " HTTP/1.1\r\n" .
"Host: $google\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 );
}
$notify = false;
$eventName = $modx->event->name;
switch($eventName) {
case 'OnDocFormSave':
if ($resource->published==1 && $resource->getTVValue('NotifyGoogle')){
$notify = true;
}
else {
$notify = false;
}
break;
case 'OnDocPublished':
if ($resource->getTVValue('NotifyGoogle')){
$notify = true;
}
else {
$notify = false;
}
break;
}
if ($notify) {
$url_xml = $modx->config['site_url'].'/sitemap.xml';
$returncode = pingGoogleSitemaps( $url_xml );
if (!$returncode == 200) {
$modx->log(modX::LOG_LEVEL_DEBUG, 'There was an error connecting to the google server it returned the following code '.$returncode);
}
}
7)under the system events tab select both
OnDocFormSave
OnDocPublish
Now all you have to do when you create a doc is set the template variable under the template variables tab and it should then ping google sitemaps for an update.
A few things still to sort once we know this bit works
1) Clear the template variable so that future updates won’t ping unless we specifically tell it to
2) Move the TV to the main editing page so it’s easier to use
3) create a package of all this which I will need help with since I have never done that
So try it as I say as far as I can tell it works. If anyone spots any issues here at all please let me know.