hasPermission($project)) throw new Exception("You do not have permission to access this resource."); $slug = Util::slug($project->name); $locations = $project->getLocations(); header("Content-Type: text/xml; charset=utf-8"); header("Content-Disposition: attachment; filename={$slug}-export.kml"); $xml = simplexml_load_file(ROOT_DIR . "/files/empty.kml"); $folder_node = $xml->addChild("Folder"); $folder_node->addChild("name", $project->name); $folder_node->addChild("open", 1); $folder_node->addChild("description", $project->name . " Locations"); foreach($locations as $location) { $placemark_node = $folder_node->addChild("Placemark"); $placemark_node->addChild("name", htmlspecialchars($location->name)); $placemark_node->addChild("description", htmlspecialchars($location->getDisplayAddress())); $point_node = $placemark_node->addChild("Point"); $point_node->addChild("coordinates", $location->longitude . "," . $location->latitude); } echo $xml->asXML(); ?>