'/var/www/channel_live/', //base installation dir 'config'=>'channel-islands.geographs.org', //effective config 'help'=>0, //show script help? ); //very simple argument parser for($i=1; $i : base directory (/var/www/geograph_live/) --config= : effective domain config (www.geograph.org.uk) --help : show this message --------------------------------------------------------------------- ENDHELP; exit; } //set up suitable environment ini_set('include_path', $param['dir'].'/libs/'); $_SERVER['DOCUMENT_ROOT'] = $param['dir'].'/public_html/'; $_SERVER['HTTP_HOST'] = $param['config']; //-------------------------------------------- // nothing below here should need changing require_once('geograph/global.inc.php'); $db = NewADOConnection($GLOBALS['DSN']); //this upper limit is set by google $urls_per_sitemap=50000; //how many sitemap files must we write? printf("Counting images...\r"); $images=$db->GetOne("select count(*) from kmlcache where rendered = 1 and filename != '' and level in (1,5,6,7)"); $sitemaps=ceil($images / $urls_per_sitemap); //go through each sitemap file... $last_percent=0; $count=0; for ($sitemap=1; $sitemap<=$sitemaps; $sitemap++) { //prepare output file and query printf("Preparing sitemap %d of %d, %d%% complete...\r", $sitemap, $sitemaps,$percent); $filename=sprintf('%s/public_html/kml/sitemap%04d.xml', $param['dir'], $sitemap); $fh=fopen($filename, "w"); fprintf($fh, ''."\n"); fprintf($fh, ''."\n"); $maxdate=""; $offset=($sitemap-1)*$urls_per_sitemap; $recordSet = &$db->Execute( "select filename,date(ts) as ts_date ". "from kmlcache ". "where rendered = 1 and filename != '' and level in (1,5,6,7) ". "order by level ". "limit $offset,$urls_per_sitemap"); //write one line per result... while (!$recordSet->EOF) { //figure out most recent update $date=$recordSet->fields['ts_date']; if (strcmp($date,$maxdate)>0) $maxdate=$date; fprintf($fh,"". "%s". "%s". "monthly". "kml". "\n", "http://".$CONF['KML_HOST'].$recordSet->fields['filename'], $date ); $count++; $percent=round(($count*100)/$images); if ($percent!=$last_percent) { $last_percent=$percent; printf("Writing sitemap %d of %d, %d%% complete...\r", $sitemap, $sitemaps,$percent); } $recordSet->MoveNext(); } $recordSet->Close(); //finalise file fprintf($fh, ''); fclose($fh); //set datestamp on file $unixtime=strtotime($maxdate); touch($filename,$unixtime); //gzip it `gzip $filename`; } //now we write an index file pointing to our generated ones above $filename=sprintf('%s/public_html/kml/sitemap.xml', $param['dir']); $fh=fopen($filename, "w"); fprintf($fh, ''."\n"); fprintf($fh, ''."\n"); for ($s=1; $s<=$sitemaps; $s++) { fprintf($fh, ""); $fname=sprintf("sitemap%04d.xml.gz", $s); $mtime=filemtime($param['dir']."/public_html/kml/".$fname); $mtimestr=strftime("%Y-%m-%dT%H:%M:%S+00:00", $mtime); fprintf($fh, "http://{$CONF['KML_HOST']}/kml/%s", $fname); fprintf($fh, "$mtimestr", $fname); fprintf($fh, "\n"); } fprintf($fh, ''); ?>