project_kml.php 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. $project = Project::get($id);
  3. if(!$project) throw new Exception("Project cannot be found.");
  4. if(!Core::$user->hasPermission($project)) throw new Exception("You do not have permission to access this resource.");
  5. $slug = Util::slug($project->name);
  6. $locations = $project->getLocations();
  7. header("Content-Type: text/xml; charset=utf-8");
  8. header("Content-Disposition: attachment; filename={$slug}-export.kml");
  9. $xml = simplexml_load_file(ROOT_DIR . "/files/empty.kml");
  10. $folder_node = $xml->addChild("Folder");
  11. $folder_node->addChild("name", $project->name);
  12. $folder_node->addChild("open", 1);
  13. $folder_node->addChild("description", $project->name . " Locations");
  14. foreach($locations as $location) {
  15. $placemark_node = $folder_node->addChild("Placemark");
  16. $placemark_node->addChild("name", htmlspecialchars($location->name));
  17. $placemark_node->addChild("description", htmlspecialchars($location->getDisplayAddress()));
  18. $point_node = $placemark_node->addChild("Point");
  19. $point_node->addChild("coordinates", $location->longitude . "," . $location->latitude);
  20. }
  21. echo $xml->asXML();
  22. ?>