mapserver->legendIconCacheDir)) { $legendIconCacheDir = $configObj->mapserver->legendIconCacheDir; // check for closing '/' $legendIconCacheDir = str_replace( '\\', '/', trim( $legendIconCacheDir ) ); if ( substr( $legendIconCacheDir, -1 ) != '/' ) { $legendIconCacheDir .= '/'; } $cacheLegendIcons = true; //$str = file_get_contents($_SESSION['maps'][$mapName]); /* create a unique location for the map icons based on * the content of the of map file. If the content changes * then the icons should be rebuilt anyway */ $legendIconCacheDir = $legendIconCacheDir.md5($str)."/"; if (!is_dir($legendIconCacheDir)) { mkdir($legendIconCacheDir); } /* TODO: can we figure out what the content type is? */ $legendIconCacheFile = $legendIconCacheDir."_".$REQUEST_VARS['layername']."_".$REQUEST_VARS['classindex'].".png"; /* if the icon exists, return it */ if (file_exists($legendIconCacheFile)) { /* TODO: can we figure out what the content type is? */ header('Content-type: image/png'); $etag = '"' . md5_file($legendIconCacheFile) . '"'; header ("ETag: " . $etag ); $cache_time = mktime(0, 0, 0, 1, 1, 2004); $expires = 3600 * 256; header("last-modified: " . gmdate("D, d M Y H:i:s",$cache_time) . " GMT"); $inm = split(',', getenv("HTTP_IF_NONE_MATCH")); $send_body = true; foreach ($inm as $i) { if (trim($i) == $etag || trim($i) == $cache_time) { header ("HTTP/1.0 304 Not Modified"); $send_body = false; } } //last modified test if(getenv("HTTP_IF_MODIFIED_SINCE") == gmdate("D, d M Y H:i:s",$cache_time). " GMT") { header ("HTTP/1.0 304 Not Modified"); $send_body = false; } //more headers header("Expires: " . gmdate("D, d M Y H:i:s",$cache_time+$expires) . " GMT"); header("Cache-Control: max-age=$expires, must-revalidate"); //header('Content-Length: ' . strlen($body)); //if we're not cacheing if ($send_body) { readfile($legendIconCacheFile); } exit; } } $oMap = ms_newMapObj($mapFile); $oLayer = $oMap->getLayerByName($REQUEST_VARS['layername']); $oClass = $oLayer->getClass($REQUEST_VARS['classindex']); $width = $oMap->legend->keysizex; $height = $oMap->legend->keysizey; if ($width <=0) { $width = 16; } if ($height <=0) { $height = 16; } if ($oClass) { $oImg = $oClass->createLegendIcon($width, $height); } else { $oMap->setSize($width,$height); $oImg = $oMap->prepareImage(); } /* TODO: can we figure out what the content type is? */ header('Content-type: image/png'); if ($cacheLegendIcons) { $oImg->saveImage($legendIconCacheFile); $etag = '"' . md5_file($legendIconCacheFile) . '"'; header ("ETag: " . $etag ); $cache_time = mktime(0, 0, 0, 1, 1, 2004); $expires = 3600 * 256; header("last-modified: " . gmdate("D, d M Y H:i:s",$cache_time) . " GMT"); readfile($legendIconCacheFile); } else { $oImg->saveImage(""); } $oImg->free(); } ?>