[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/vendor/openpsa/universalfeedcreator/lib/Creator/ -> KMLCreator.php (source)

   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  
  63          for ($i = 0; $i < count($this->items); $i++) {
  64              //added here beucase description gets auto surrounded by cdata
  65              $this->items[$i]->description = "<b>".$this->items[$i]->description."</b><br/>
  66              ".$this->items[$i]->licence."
  67              <br/><br/><a href=\"".htmlspecialchars($this->items[$i]->link)."\">View Online</a>";
  68  
  69              $feed .= "
  70              <Placemark>
  71              <description>".$this->items[$i]->getDescription(true)."</description>
  72              <name>".FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)), 100)."</name>
  73              <visibility>1</visibility>
  74              <Point>
  75              <coordinates>".$this->items[$i]->long.",".$this->items[$i]->lat.",25</coordinates>
  76              </Point>";
  77              if ($this->items[$i]->thumb != "") {
  78                  $feed .= "
  79                  <styleUrl>$style</styleUrl>
  80                  <Style>
  81                  <icon>".htmlspecialchars($this->items[$i]->thumb)."</icon>
  82                      </Style>";
  83              }
  84              $feed .= "
  85              </Placemark>\n";
  86          }
  87          $feed .= "</Folder>\n</Document>\n</kml>\n";
  88  
  89          return $feed;
  90      }
  91  
  92      /**
  93       * Generate a filename for the feed cache file. Overridden from FeedCreator to prevent XML data types.
  94       *
  95       * @return string the feed cache filename
  96       * @since  1.4
  97       * @access private
  98       */
  99      protected function _generateFilename()
 100      {
 101          $fileInfo = pathinfo($_SERVER["SCRIPT_NAME"]);
 102  
 103          return substr($fileInfo["basename"], 0, -(strlen($fileInfo["extension"]) + 1)).".kml";
 104      }
 105  }