|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
use 5.010;
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use XML::LibXML;
|
|
|
|
use Data::Dumper;
|
|
|
|
|
|
|
|
my ($name, $coordinates, $article) = @ARGV;
|
|
|
|
|
|
|
|
my $filename = 'ours.kml';
|
|
|
|
my $dom = XML::LibXML->load_xml(location => $filename, no_blanks => 1);
|
|
|
|
my $xpc = XML::LibXML::XPathContext->new($dom);
|
|
|
|
$xpc->registerNs('k', "http://earth.google.com/kml/2.2");
|
|
|
|
|
|
|
|
append_placemark($name, $coordinates, $article);
|
|
|
|
|
|
|
|
# say $dom->toString(1);
|
|
|
|
print $dom->toString(1);
|
|
|
|
|
|
|
|
sub add_empty_child
|
|
|
|
{
|
|
|
|
my $node = shift;
|
|
|
|
my $element_name = shift;
|
|
|
|
my $child_node = $dom->createElement($element_name);
|
|
|
|
$node->appendChild($child_node);
|
|
|
|
return $child_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub append_placemark
|
|
|
|
{
|
|
|
|
my $name = shift;
|
|
|
|
my $coordinates = shift;
|
|
|
|
my $article_name = shift;
|
|
|
|
my $placemark = add_empty_child($dom->documentElement, 'Placemark');
|
|
|
|
$placemark->{id} = to_id($name);
|
|
|
|
|
|
|
|
my $name_node = add_empty_child($placemark, 'name');
|
|
|
|
my $name_content;
|
|
|
|
if(defined($article_name))
|
|
|
|
{
|
|
|
|
$name_content = "<a href=\"https://jackpoint.obscuritus.ca/index.php?title=$article_name\">$name</a>";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$name_content = $name;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $name_cdata = $dom->createCDATASection($name_content);
|
|
|
|
$name_node->appendChild($name_cdata);
|
|
|
|
|
|
|
|
my $style_node = add_empty_child($placemark, 'styleUrl');
|
|
|
|
$style_node->appendText('#jackpoint-logo');
|
|
|
|
|
|
|
|
my $point_node = add_empty_child($placemark, 'Point');
|
|
|
|
my $coordinates_node = add_empty_child($point_node, 'coordinates');
|
|
|
|
$coordinates_node->appendText($coordinates);
|
|
|
|
}
|
|
|
|
sub to_id
|
|
|
|
{
|
|
|
|
my $string = shift;
|
|
|
|
$string =~ s/ /_/g;
|
|
|
|
$string =~ s/\W//g;
|
|
|
|
return lc($string);
|
|
|
|
}
|