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