1<?php 2 3/** 4 * KMLCreator is a FeedCreator that implements a KML output, suitable for Keyhole/Google Earth 5 * 6 * @since 1.7.3 7 * @author Barry Hunter <geo@barryhunter.co.uk> 8 * @package de.bitfolge.feedcreator 9 */ 10class KMLCreator extends FeedCreator 11{ 12 13 /** 14 * KMLCreator constructor. 15 */ 16 public function __construct() 17 { 18 $this->contentType = "application/vnd.google-earth.kml+xml"; 19 $this->encoding = "utf-8"; 20 } 21 22 /** @inheritdoc */ 23 public function createFeed() 24 { 25 $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n"; 26 $feed .= $this->_createStylesheetReferences(); 27 $feed .= "<kml xmlns=\"http://earth.google.com/kml/2.0\">\n"; 28 $feed .= "<Document>\n"; 29 if ($_GET['LinkControl']) { 30 $feed .= "<NetworkLinkControl>\n<minRefreshPeriod>3600</minRefreshPeriod>\n</NetworkLinkControl>\n"; 31 } 32 if (!empty($_GET['simple']) && count($this->items) > 0) { 33 $feed .= "<Style id=\"defaultIcon\"> 34 <LabelStyle> 35 <scale>0</scale> 36 </LabelStyle> 37 </Style> 38 <Style id=\"hoverIcon\">". 39 (($this->items[0]->thumb != "") ? " 40 <IconStyle id=\"hoverIcon\"> 41 <scale>2.1</scale> 42 </IconStyle>" : '')." 43 </Style> 44 <StyleMap id=\"defaultStyle\"> 45 <Pair> 46 <key>normal</key> 47 <styleUrl>#defaultIcon</styleUrl> 48 </Pair> 49 <Pair> 50 <key>highlight</key> 51 <styleUrl>#hoverIcon</styleUrl> 52 </Pair> 53 </StyleMap> 54 "; 55 $style = "#defaultStyle"; 56 } else { 57 $style = "root://styleMaps#default?iconId=0x307"; 58 } 59 $feed .= "<Folder>\n"; 60 $feed .= " <name>".FeedCreator::iTrunc(htmlspecialchars($this->title), 100)."</name> 61 <description>".$this->getDescription()."</description> 62 <visibility>1</visibility>\n"; 63 $this->truncSize = 500; 64 65 for ($i = 0; $i < count($this->items); $i++) { 66 //added here beucase description gets auto surrounded by cdata 67 $this->items[$i]->description = "<b>".$this->items[$i]->description."</b><br/> 68 ".$this->items[$i]->licence." 69 <br/><br/><a href=\"".htmlspecialchars($this->items[$i]->link)."\">View Online</a>"; 70 71 $feed .= " 72 <Placemark> 73 <description>".$this->items[$i]->getDescription(true)."</description> 74 <name>".FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)), 100)."</name> 75 <visibility>1</visibility> 76 <Point> 77 <coordinates>".$this->items[$i]->long.",".$this->items[$i]->lat.",25</coordinates> 78 </Point>"; 79 if ($this->items[$i]->thumb != "") { 80 $feed .= " 81 <styleUrl>$style</styleUrl> 82 <Style> 83 <icon>".htmlspecialchars($this->items[$i]->thumb)."</icon> 84 </Style>"; 85 } 86 $feed .= " 87 </Placemark>\n"; 88 } 89 $feed .= "</Folder>\n</Document>\n</kml>\n"; 90 91 return $feed; 92 } 93 94 /** 95 * Generate a filename for the feed cache file. Overridden from FeedCreator to prevent XML data types. 96 * 97 * @return string the feed cache filename 98 * @since 1.4 99 * @access private 100 */ 101 protected function _generateFilename() 102 { 103 $fileInfo = pathinfo($_SERVER["PHP_SELF"]); 104 105 return substr($fileInfo["basename"], 0, -(strlen($fileInfo["extension"]) + 1)).".kml"; 106 } 107} 108