fix writing of kml file
authorJoey Hess <joey@kitenet.net>
Tue, 13 Mar 2012 21:16:09 +0000 (17:16 -0400)
committerJoey Hess <joey@kitenet.net>
Tue, 13 Mar 2012 21:55:47 +0000 (17:55 -0400)
It just didn't work, but also, it didn't use writefile, which is not
desirable for security. Fixed both issues.

Also removed some unnecessary debug messages.

IkiWiki/Plugin/osm.pm

index 2b5d0d5f120c80ae478407f4358d4666a0e3034d..47c752881625292016d44d0b10dc138b4cf88243 100644 (file)
@@ -341,8 +341,7 @@ sub writejson($;$) {
                                "geometry" => { "type" => "LineString", "coordinates" => $linestring });
                        push @{$geojson{'features'}}, \%json;
                }
-               debug('writing pois file pois.json in ' . $config{destdir} . "/$map");
-               writefile("pois.json",$config{destdir} . "/$map",to_json(\%geojson));
+               writefile("pois.json", $config{destdir} . "/$map", to_json(\%geojson));
        }
 }
 
@@ -352,7 +351,6 @@ sub writekml($;$) {
        eval q{use XML::Writer};
        error $@ if $@;
        foreach my $map (keys %waypoints) {
-               debug("writing pois file pois.kml in " . $config{destdir} . "/$map");
 
 =pod
 Sample placemark:
@@ -388,10 +386,9 @@ Sample style:
 
 =cut
 
-               use IO::File;
-               my $output = IO::File->new(">".$config{destdir} . "/$map/pois.kml");
-
-               my $writer = XML::Writer->new( OUTPUT => $output, DATA_MODE => 1, ENCODING => 'UTF-8');
+               my $output;
+               my $writer = XML::Writer->new( OUTPUT => \$output,
+                       DATA_MODE => 1, ENCODING => 'UTF-8');
                $writer->xmlDecl();
                $writer->startTag("kml", "xmlns" => "http://www.opengis.net/kml/2.2");
 
@@ -454,7 +451,8 @@ Sample style:
                }
                $writer->endTag();
                $writer->end();
-               $output->close();
+
+               writefile("pois.kmp", $config{destdir} . "/$map", $output);
        }
 }
 
@@ -472,8 +470,7 @@ sub writecsvs($;$) {
                                $options{'icon'} . "\n";
                        $poisf .= $line;
                }
-               debug("writing pois file pois.txt in " . $config{destdir} . "/$map");
-               writefile("pois.txt",$config{destdir} . "/$map",$poisf);
+               writefile("pois.txt", $config{destdir} . "/$map", $poisf);
        }
 }