59 lines
2.0 KiB
PHP
59 lines
2.0 KiB
PHP
<?php
|
|
if (!isset($_GET['geo'])) {
|
|
http_response_code(200);
|
|
?>
|
|
<html>
|
|
<head>
|
|
<title>GeoHack Redirect</title>
|
|
</head>
|
|
<body>
|
|
<p>This is a quick and dirty PHP page that takes a <a href="https://geouri.org/">Geo URI</a> and redirects you to <a href="https://www.mediawiki.org/wiki/GeoHack">GeoHack</a>, on its WMF Toolforge page, to let you open it in other map services. I am no PHP developer, so expect this thing to be broken.</p>
|
|
<p>
|
|
<p>I made this because I wanted a better <code>geo:</code> protocol handler than those provided by Firefox. Specifically, the Google Maps provider no longer worked and I also wanted to use the French map service IGN and Google Earth.</p>
|
|
<h2>Try it</h2>
|
|
<form method="GET">
|
|
<label for="geo-input">Geo URI:</label>
|
|
<input type="url" name="geo" id="geo-input" placeholder="geo:[latitude],[longitude]" pattern="geo:.*" required />
|
|
<br />
|
|
<button type="submit">Submit</button>
|
|
</form>
|
|
<hr />
|
|
<p>If you have JavaScript enabled, <a href="javascript:navigator.registerProtocolHandler('geo', window.location.toString().split('?')[0].split('#')[0] + '?geo=%s', 'GeoHack Redirect')">click here</a> to register this page as a <code>geo:</code> protocol handler in your browser. <a href="https://caniuse.com/mdn-api_navigator_registerprotocolhandler_scheme_parameter_geo">Supported browsers</a></p>
|
|
</body>
|
|
</html>
|
|
<?php
|
|
die();
|
|
}
|
|
|
|
$parsed = parse_url($_GET['geo']);
|
|
if ($parsed["scheme"] != "geo") {
|
|
http_response_code(400);
|
|
echo "Unsupported URL scheme";
|
|
die();
|
|
}
|
|
|
|
$parts = explode(";", $parsed["path"]);
|
|
if (sizeof($parts) <= 0) {
|
|
http_response_code(400);
|
|
echo "Unrecognized geo: URL";
|
|
die();
|
|
};
|
|
|
|
list($lat, $lng) = explode(",", array_shift($parts));
|
|
if (!isset($lat) || !isset($lng)) {
|
|
http_response_code(400);
|
|
echo "Unrecognized geo: URL";
|
|
die();
|
|
}
|
|
|
|
$header = "Location: https://geohack.toolforge.org/geohack.php?params=$lat;$lng";
|
|
|
|
parse_str(implode("&", $parts), $params);
|
|
if (isset($params["u"])) {
|
|
$header .= "_dim:" . $params["u"];
|
|
}
|
|
|
|
http_response_code(302);
|
|
header($header);
|
|
?>
|