1572dd708SAndreas Gohr<?php 2572dd708SAndreas Gohr 3572dd708SAndreas Gohr/** 4572dd708SAndreas Gohr * KMLCreator is a FeedCreator that implements a KML output, suitable for Keyhole/Google Earth 5572dd708SAndreas Gohr * 6572dd708SAndreas Gohr * @since 1.7.3 7572dd708SAndreas Gohr * @author Barry Hunter <geo@barryhunter.co.uk> 8572dd708SAndreas Gohr */ 9572dd708SAndreas Gohrclass KMLCreator extends FeedCreator 10572dd708SAndreas Gohr{ 11572dd708SAndreas Gohr 12572dd708SAndreas Gohr /** 13572dd708SAndreas Gohr * KMLCreator constructor. 14572dd708SAndreas Gohr */ 15572dd708SAndreas Gohr public function __construct() 16572dd708SAndreas Gohr { 17572dd708SAndreas Gohr $this->contentType = "application/vnd.google-earth.kml+xml"; 18572dd708SAndreas Gohr $this->encoding = "utf-8"; 19572dd708SAndreas Gohr } 20572dd708SAndreas Gohr 21572dd708SAndreas Gohr /** @inheritdoc */ 22572dd708SAndreas Gohr public function createFeed() 23572dd708SAndreas Gohr { 24572dd708SAndreas Gohr $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n"; 25572dd708SAndreas Gohr $feed .= $this->_createStylesheetReferences(); 26572dd708SAndreas Gohr $feed .= "<kml xmlns=\"http://earth.google.com/kml/2.0\">\n"; 27572dd708SAndreas Gohr $feed .= "<Document>\n"; 28572dd708SAndreas Gohr if ($_GET['LinkControl']) { 29572dd708SAndreas Gohr $feed .= "<NetworkLinkControl>\n<minRefreshPeriod>3600</minRefreshPeriod>\n</NetworkLinkControl>\n"; 30572dd708SAndreas Gohr } 31572dd708SAndreas Gohr if (!empty($_GET['simple']) && count($this->items) > 0) { 32572dd708SAndreas Gohr $feed .= "<Style id=\"defaultIcon\"> 33572dd708SAndreas Gohr <LabelStyle> 34572dd708SAndreas Gohr <scale>0</scale> 35572dd708SAndreas Gohr </LabelStyle> 36572dd708SAndreas Gohr </Style> 37572dd708SAndreas Gohr <Style id=\"hoverIcon\">". 38572dd708SAndreas Gohr (($this->items[0]->thumb != "") ? " 39572dd708SAndreas Gohr <IconStyle id=\"hoverIcon\"> 40572dd708SAndreas Gohr <scale>2.1</scale> 41572dd708SAndreas Gohr </IconStyle>" : '')." 42572dd708SAndreas Gohr </Style> 43572dd708SAndreas Gohr <StyleMap id=\"defaultStyle\"> 44572dd708SAndreas Gohr <Pair> 45572dd708SAndreas Gohr <key>normal</key> 46572dd708SAndreas Gohr <styleUrl>#defaultIcon</styleUrl> 47572dd708SAndreas Gohr </Pair> 48572dd708SAndreas Gohr <Pair> 49572dd708SAndreas Gohr <key>highlight</key> 50572dd708SAndreas Gohr <styleUrl>#hoverIcon</styleUrl> 51572dd708SAndreas Gohr </Pair> 52572dd708SAndreas Gohr </StyleMap> 53572dd708SAndreas Gohr "; 54572dd708SAndreas Gohr $style = "#defaultStyle"; 55572dd708SAndreas Gohr } else { 56572dd708SAndreas Gohr $style = "root://styleMaps#default?iconId=0x307"; 57572dd708SAndreas Gohr } 58572dd708SAndreas Gohr $feed .= "<Folder>\n"; 59572dd708SAndreas Gohr $feed .= " <name>".FeedCreator::iTrunc(htmlspecialchars($this->title), 100)."</name> 60572dd708SAndreas Gohr <description>".$this->getDescription()."</description> 61572dd708SAndreas Gohr <visibility>1</visibility>\n"; 62572dd708SAndreas Gohr 63572dd708SAndreas Gohr for ($i = 0; $i < count($this->items); $i++) { 64572dd708SAndreas Gohr //added here beucase description gets auto surrounded by cdata 65572dd708SAndreas Gohr $this->items[$i]->description = "<b>".$this->items[$i]->description."</b><br/> 66572dd708SAndreas Gohr ".$this->items[$i]->licence." 67572dd708SAndreas Gohr <br/><br/><a href=\"".htmlspecialchars($this->items[$i]->link)."\">View Online</a>"; 68572dd708SAndreas Gohr 69572dd708SAndreas Gohr $feed .= " 70572dd708SAndreas Gohr <Placemark> 71572dd708SAndreas Gohr <description>".$this->items[$i]->getDescription(true)."</description> 72572dd708SAndreas Gohr <name>".FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)), 100)."</name> 73572dd708SAndreas Gohr <visibility>1</visibility> 74572dd708SAndreas Gohr <Point> 75572dd708SAndreas Gohr <coordinates>".$this->items[$i]->long.",".$this->items[$i]->lat.",25</coordinates> 76572dd708SAndreas Gohr </Point>"; 77572dd708SAndreas Gohr if ($this->items[$i]->thumb != "") { 78572dd708SAndreas Gohr $feed .= " 79572dd708SAndreas Gohr <styleUrl>$style</styleUrl> 80572dd708SAndreas Gohr <Style> 81572dd708SAndreas Gohr <icon>".htmlspecialchars($this->items[$i]->thumb)."</icon> 82572dd708SAndreas Gohr </Style>"; 83572dd708SAndreas Gohr } 84572dd708SAndreas Gohr $feed .= " 85572dd708SAndreas Gohr </Placemark>\n"; 86572dd708SAndreas Gohr } 87572dd708SAndreas Gohr $feed .= "</Folder>\n</Document>\n</kml>\n"; 88572dd708SAndreas Gohr 89572dd708SAndreas Gohr return $feed; 90572dd708SAndreas Gohr } 91572dd708SAndreas Gohr 92572dd708SAndreas Gohr /** 93572dd708SAndreas Gohr * Generate a filename for the feed cache file. Overridden from FeedCreator to prevent XML data types. 94572dd708SAndreas Gohr * 95572dd708SAndreas Gohr * @return string the feed cache filename 96572dd708SAndreas Gohr * @since 1.4 97572dd708SAndreas Gohr * @access private 98572dd708SAndreas Gohr */ 99572dd708SAndreas Gohr protected function _generateFilename() 100572dd708SAndreas Gohr { 101*d3233986SAndreas Gohr $fileInfo = pathinfo($_SERVER["SCRIPT_NAME"]); 102572dd708SAndreas Gohr 103572dd708SAndreas Gohr return substr($fileInfo["basename"], 0, -(strlen($fileInfo["extension"]) + 1)).".kml"; 104572dd708SAndreas Gohr } 105572dd708SAndreas Gohr} 106