setHook('wrmap', 'wrmapParserHook');
return true;
}
/// Format inside ... has to be like this:
///
///
/// Rodelbahn|47.143241 N 11.208959 E|Birgitzer Alm
/// ...
///
///
/// The extension produces a format like this:
///
/// 47.241731, 11.358994, Birgitzer Alm
/// Die Birgitzer Alm ist nett
/// 47.17607, 11.542763, Naviser Hütte
/// Die Naviser Hütte
///
function wrmapParserHook($input, $args, $parser) {
$debug = (isset($args['debug']) && $args['debug'] != '0');
$output = '';
$lines = explode("\n", $input);
$latitudes = array();
$longitudes = array();
foreach ($lines as $line) {
try {
$l = trim($line);
if (strlen($l) == 0) continue;
$columns = explode('|', $line);
if (count($columns) != 3) throw new Exception(sprintf(utf8_encode('Die Anzahl der Spalten ist nicht 3 sondern %d'), count($columns)));
$columns = list($type, $geo, $name) = $columns;
if (strlen(trim($geo)) == 0) continue;
list($latitude, $longitude) = wrGeoStringToGeo($geo);
$latitudes[] = $latitude;
$longitudes[] = $longitude;
$output .= sprintf("%F, %F, %s\n", $latitude, $longitude, htmlspecialchars($name));
} catch (Exception $e) {
return sprintf(utf8_encode('Ungültige Zeile in der Koordinatenliste: %s. %s'), htmlspecialchars($line), htmlspecialchars($e->getMessage()));
}
}
if (count($latitudes) == 0) return utf8_encode('Keine Koordinaten eingetragen');
$minLatitude = min($latitudes);
$centerLat = $minLatitude + (max($latitudes) - $minLatitude) / 2;
$minLongitude = min($longitudes);
$centerLon = $minLongitude + (max($longitudes) - $minLongitude) / 2;
// TODO: Varable zoom level
$output = ''. "\n" . $output . "\n";
if ($debug) return "
$output
\n";
return $parser->recursiveTagParse($output);
}
?>