services-maps/map.php

298 lines
9.1 KiB
PHP
Executable File

<?php
set_time_limit(0);
error_reporting(0);
include('php/library.php');
$id = $_GET['id'];
if ($id == '')
die('map.php returns a map for a given IMDb id<br />usage: map.php?id=ID&q=QUERY<br />ID: IMDb id<br />QUERY: search term');
$id = str_pad($id, 7, '0', STR_PAD_LEFT);
$size = $_GET['size'];
if ($size != 'small')
$size = 'large';
$q = urldecode($_GET['q']);
$q = htmlentities($q);
$point = movie2locations($id);
if ($point) {
$point_ = $point;
foreach ($point as $key => $value) {
foreach ($point_ as $key_ => $value_) {
if ($key != $key_ && $value_['location'] == substr($value['location'], -1 * strlen($value_['location']))) {
// echo $value_['location'] . '<br>';
unset($point_[$key_]);
break;
}
}
}
unset($point);
$key = 0;
foreach ($point_ as $key_ => $value_) {
$point[$key] = $value_;
$key++;
}
foreach ($point as $key => $value) {
if (!$flag || $value['coordinates']['latitude'] - $value['coordinates']['spanLatitude'] / 2 < $minLatitude)
$minLatitude = $value['coordinates']['latitude'] - $value['coordinates']['spanLatitude'] / 2;
if (!$flag || $value['coordinates']['latitude'] + $value['coordinates']['spanLatitude'] / 2 > $maxLatitude)
$maxLatitude = $value['coordinates']['latitude'] + $value['coordinates']['spanLatitude'] / 2;
if (!$flag || $value['coordinates']['longitude'] - $value['coordinates']['spanLongitude'] / 2 < $minLongitude)
$minLongitude = $value['coordinates']['longitude'] - $value['coordinates']['spanLongitude'] / 2;
if (!$flag || $value['coordinates']['longitude'] + $value['coordinates']['spanLongitude'] / 2 > $maxLongitude)
$maxLongitude = $value['coordinates']['longitude'] + $value['coordinates']['spanLongitude'] / 2;
$flag = true;
}
// var_dump($point); exit;
$centerLatitude = ($minLatitude + $maxLatitude) / 2;
$centerLongitude = ($minLongitude + $maxLongitude) / 2;
$spanLatitude = $maxLatitude - $minLatitude;
$spanLongitude = $maxLongitude - $minLongitude;
echo <<<HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Map ($id)</title>
<style>
body {
margin: 0px;
}
a:hover {
text-decoration: underline;
}
.highlight {
background: rgb(255, 255, 0);
}
</style>
<script type="text/javascript" src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAAukyaOEFK-iC7DVRKTk2AhTjRsO7ykTzkif7ZnlfpRIvHm3E1BRKbDFCAjenzn3yzm0_wxNnHMDP2g"></script>
<script type="text/javascript">
function load() {
if (GBrowserIsCompatible()) {
HTML;
echo "var map = new GMap2(document.getElementById('map'));\n";
if ($size == 'large') {
echo <<<HTML
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
HTML;
}
echo <<<HTML
var baseIcon = new GIcon();
baseIcon.shadow = 'http://services.0xdb.org/maps/png/markerShadow.png';
baseIcon.iconSize = new GSize(20, 34);
baseIcon.shadowSize = new GSize(37, 34);
baseIcon.iconAnchor = new GPoint(9, 34);
baseIcon.infoWindowAnchor = new GPoint(9, 2);
baseIcon.infoShadowAnchor = new GPoint(18, 25);
HTML;
echo "\t\t\t\tvar centerLatitude = $centerLatitude;\n";
echo "\t\t\t\tvar centerLongitude = $centerLongitude;\n";
echo "\t\t\t\tvar spanLatitude = $spanLatitude;\n";
echo "\t\t\t\tvar spanLongitude = $spanLongitude;\n";
// echo "alert($minLatitude + ' ' + $maxLatitude + ' ' + $minLongitude + ' ' + $maxLongitude + ' ' + $centerLatitude + ' ' + $centerLongitude + ' ' + $spanLatitude + ' ' + $spanLongitude + ' ' + $zoom);\n";
echo <<<HTML
var lngSpan = 0;
var latSpan = 0;
var zoom = 20;
map.setCenter(new GLatLng(centerLatitude, centerLongitude), zoom);
while (spanLatitude > latSpan || spanLongitude > lngSpan) {
zoom--;
map.setCenter(new GLatLng(centerLatitude, centerLongitude), zoom);
var bounds = map.getBounds();
var southWest = bounds.getSouthWest();
var northEast = bounds.getNorthEast();
latSpan = northEast.lat() - southWest.lat();
lngSpan = northEast.lng() - southWest.lng();
if (lngSpan < 0)
lngSpan = 360 - lngSpan;
// alert(spanLatitude + ' ' + spanLongitude + ' ' + zoom + ' ' + latSpan + ' ' + lngSpan);
}
HTML;
if ($size == 'small')
echo 'map.setMapType(G_SATELLITE_MAP);' . "\n";
else
echo 'map.setMapType(G_HYBRID_MAP);' . "\n";
echo <<<HTML
function createMarker(point, marker, label) {
var icon = new GIcon(baseIcon);
icon.image = marker;
var marker = new GMarker(point, icon);
// label = label.replace(/ - /g, '<br />');
// label = label.replace(/, /g, '<br />');
HTML;
if ($size == 'large') {
echo <<<HTML
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml('<span style="font-family: Helvetica, Arial; font-size: 13px">' + label + '</span>');
});
HTML;
}
echo <<<HTML
return marker;
}
createMarkers();
}
function createMarkers() {
var location = [];
var description = [];
var latitude = [];
var longitude = [];
var coordinates = [];
var marker = [];
HTML;
foreach ($point as $key => $value) {
$value['location'] = htmlentities($value['location']);
$value['description'] = htmlentities(html_entity_decode($value['description']));
$value['marker'] = 'http://services.0xdb.org/maps/png/markerBlue.png';
if ($q) {
$str[0] = $value['location'];
$str[1] = $value['description'];
$qlen = strlen($q);
foreach ($str as $i => $s) {
if (stristr($s, $q)) {
$slen = strlen($s);
for ($c = strlen($s) - strlen($q); $c >= 0; $c--) {
if (strtolower(substr($s, $c, $qlen)) == strtolower($q)) {
$s = substr($s, 0, $c) . '<span class=\"highlight\">' . str_replace(', ', '</span>, <span style=\"background: rgb(255,255,0)\">', substr($s, $c, $qlen)) . '</span>' . substr($s, $c + $qlen);
echo "// tmp $i = '$s';\n";
}
}
if ($i == 0)
$value['location'] = $s;
else
$value['description'] = $s;
$value['marker'] = 'http://services.0xdb.org/maps/png/markerYellow.png';
}
}
}
$string = explode(', ', $value['location']);
for ($i = 0; $i < count($string); $i++) {
$array = $string;
for ($j = 0; $j < $i; $j++)
array_shift($array);
$query = strip_tags(implode(', ', $array));
if ($value['level'] > $i)
$string[$i] = '<a href=\"http://0xdb.org/search?f=location&q=' . urlencode(html_entity_decode($query)) . '\" target=\"_parent\" class=\"link\" style=\"font-style: italic; text-decoration: none; color: rgb(0, 0, 128); cursor: pointer\">' . $string[$i] . '</a>';
else
$string[$i] = '<a href=\"http://0xdb.org/search?f=location&q=' . urlencode(html_entity_decode($query)) . '\" target=\"_parent\" class=\"link\" style=\"text-decoration: none; color: rgb(0, 0, 128); cursor: pointer\">' . $string[$i] . '</a>';
}
$value['location'] = implode('<br />', $string);
if ($value['description']) {
$value['description'] = str_replace(') (', ')<br />(', $value['description']);
$value['description'] .= '<br />';
}
echo "\t\t\t\t" . 'location[' . $key . '] = "' . $value['location'] . '";' . "\n";
echo "\t\t\t\t" . 'description[' . $key . '] = "' . $value['description'] . '";' . "\n";
echo "\t\t\t\t" . 'latitude[' . $key . '] = ' . $value['coordinates']['latitude'] .';' . "\n";
echo "\t\t\t\t" . 'longitude[' . $key . '] = ' . $value['coordinates']['longitude'] . ';' . "\n";
echo "\t\t\t\t" . 'coordinates[' . $key . '] = "' . coordinates2string($value['coordinates']['latitude'], $value['coordinates']['longitude']) . '";' . "\n";
echo "\t\t\t\t" . 'marker[' . $key . '] = "' . $value['marker'] . '";' . "\n";
}
echo <<<HTML
for (var i = 0; i < location.length; i++) {
var point = new GLatLng(latitude[i], longitude[i]);
HTML;
if ($size == 'small')
echo "map.addOverlay(createMarker(point, marker[i], ''))";
else
echo "map.addOverlay(createMarker(point, marker[i], location[i] + '<br /><span style=\"font-size: 10px\">' + description[i] + '</span><span style=\"font-size: 10px\">' + coordinates[i] + '</span>'));";
echo <<<HTML
}
}
}
</script>
</head>
<body onload="load()" onunload="GUnload()">
HTML;
if ($size == 'small')
echo '<div id="map" style="width: 672px; height: 192px; background: rgb(0, 0, 0)"></div>';
else
echo '<div id="map" style="width:808px; height: 505px; background: rgb(0, 0, 0)"></div>';
echo <<<HTML
</body>
</html>
HTML;
}
else {
echo <<<HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Map ($id)</title>
<style>
body {
margin: 0px;
}
</style>
</head>
<body>
HTML;
if ($size == 'small')
echo "<div id=\"map\" style=\"width: 672px; height: 192px; background: url(png/mapSmall.png)\"></div>";
else
echo "<div id=\"map\" style=\"width:808px; height: 505px; background: url(png/mapLarge.png)\"></div>";
echo <<<HTML
</body>
</html>
HTML;
}
?>