This commit is contained in:
j 2007-07-25 14:12:35 +00:00
commit 4d4f794fd0
11 changed files with 571 additions and 0 deletions

56
admin.php Normal file
View file

@ -0,0 +1,56 @@
<?php
include('php/library.php');
$data = unserialize(file_get_contents('data/coordinates.data'));
foreach ($data as $key => $value) {
$string = explode(', ', $key);
$index[$key] = implode(', ', array_reverse($string));
}
asort($index);
foreach ($index as $key => $value) {
$html_ .= '<tr>';
if ($data[$key]['latitude'] == 0 && $data[$key]['longitude'] == 0)
$html_ .= '<td style="padding-right: 10px; font-family: Monaco; font-size: 10px; text-align: right; color: rgb(255, 0, 0)">' . htmlentities($key) . '</td>';
else {
$html_ .= '<td style="padding-right: 10px; font-family: Monaco; font-size: 10px; text-align: right">';
$html_ .= htmlentities($key);
$html_ .= '</td>';
$string = explode(' / ', coordinates2string($data[$key]['latitude'], $data[$key]['longitude']));
$html_ .= '<td style="padding-right: 10px; font-family: Monaco; font-size: 10px; text-align: right">';
$html_ .= $string[0];
$html_ .= '</td>';
$html_ .= '<td style="padding-right: 10px; font-family: Monaco; font-size: 10px; text-align: right">';
$html_ .= $string[1];
$html_ .= '</td>';
$string = explode(' / ', coordinates2string($data[$key]['spanLatitude'], $data[$key]['spanLongitude']));
$html_ .= '<td style="padding-right: 10px; font-family: Monaco; font-size: 10px; text-align: right">';
$html_ .= substr($string[0], 0, -1);
$html_ .= '</td>';
$html_ .= '<td style="padding-right: 10px; font-family: Monaco; font-size: 10px; text-align: right">';
$html_ .= substr($string[1], 0, -1);
$html_ .= '</td>';
$count++;
}
$html_ .= '</td>';
$html_ .= '</tr>';
}
$html .= '<table style="border: 0px">';
$html .= '<tr>';
$html .= '<td style="padding-right: 10px; font-family: Monaco; font-size: 10px; text-align: right">';
$html .= number_format(count($data)) . ' locations';
$html .= '</td>';
$html .= '<td style="padding-right: 10px; font-family: Monaco; font-size: 10px; text-align: right">';
$html .= number_format($count) . ' known';
$html .= '</td>';
$html .= '<td style="padding-right: 10px; font-family: Monaco; font-size: 10px; text-align: right">';
$html .= number_format(count($data) - $count) . ' unknown';
$html .= '</td>';
$html .= '</tr>';
$html .= $html_;
$html .= '</table>';
echo $html;
?>

File diff suppressed because one or more lines are too long

1
data/coordinates.data Normal file

File diff suppressed because one or more lines are too long

1
data/locations.data Normal file

File diff suppressed because one or more lines are too long

71
kml.php Normal file
View file

@ -0,0 +1,71 @@
<?php
$location = unserialize(file_get_contents('data/locations.data'));
foreach ($location as $id => $array) {
foreach ($array as $key => $value) {
if ($value['coordinates']['latitude'] + $value['coordinates']['longitude'] != 0) {
$data[$value['location']]['coordinates'] = $value['coordinates'];
$i = count($data[$value['location']]['movies']);
$data[$value['location']]['movies'][$i]['id'] = $id;
$data[$value['location']]['movies'][$i]['description'] = $value['description'];
}
}
}
foreach ($data as $key => $value) {
$string = explode(', ', $key);
$index[$key] = implode(', ', array_reverse($string));
}
asort($index);
foreach ($index as $key => $string) {
$kml .= "\t\t<Placemark>\n";
$kml .= "\t\t\t<name><![CDATA[$key]]></name>\n";
$kml .= "\t\t\t<description>\n";
$kml .= "\t\t\t\t<![CDATA[\n";
foreach ($data[$key]['movies'] as $value) {
$kml .= "\t\t\t\t\t<a href=\"http://0xdb.org/" . $value['id'] . "?v=map\">\n";
$kml .= "\t\t\t\t\t\t<img src=\"http://0xdb.org/" . $value['id'] . "/poster.jpg\" border=\"0\" />\n";
$kml .= "\t\t\t\t\t</a>\n";
}
$kml .= "\t\t\t\t]]>\n";
$kml .= "\t\t\t</description>\n";
/*
$kml .= "\t\t\t<LookAt>\n";
$kml .= "\t\t\t\t<latitude>" . $data[$key]['coordinates']['latitude'] . "</latitude>\n";
$kml .= "\t\t\t\t<longitude>" . $data[$key]['coordinates']['longitude'] . "</longitude>\n";
$kml .= "\t\t\t\t<altitude>0</altitude>\n";
$kml .= "\t\t\t\t<range>500</range>\n";
$kml .= "\t\t\t\t<tilt>0</tilt>\n";
$kml .= "\t\t\t\t<heading>0</heading>\n";
$kml .= "\t\t\t</LookAt>\n";
*/
$kml .= "\t\t\t<Point>\n";
$kml .= "\t\t\t\t<coordinates>" . $data[$key]['coordinates']['longitude'] . ',' . $data[$key]['coordinates']['latitude'] . ",0</coordinates>\n";
$kml .= "\t\t\t</Point>\n";
$kml .= "\t\t</Placemark>\n";
$i++;
if ($i == 0)
break;
}
$kml = substr($kml, 0, -1);
header('Content-Type: application/vnd.google-earth.kml+xml kml');
header('Content-Disposition: attachment; filename=0xdb.kml');
echo <<<KML
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<Document>
<name>0xdb</name>
<LookAt>
<latitude>0</latitude>
<longitude>0</longitude>
<altitude>1000</altitude>
</LookAt>
$kml
</Document>
</kml>
KML;
?>

244
map.php Executable file
View file

@ -0,0 +1,244 @@
<?php
set_time_limit(0);
include('php/library.php');
$id = str_pad($_GET['id'], 7, '0', STR_PAD_LEFT);
$q = urldecode($_GET['q']);
$q = htmlentities($q);
if ($id == 0)
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');
$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()) {
var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
// map.addControl(new GOverviewMapControl());
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);
}
map.setMapType(G_HYBRID_MAP);
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 />');
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml('<span style="font-family: Helvetica, Arial; font-size: 13px">' + label + '</span>');
});
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]);
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>'));
}
}
}
</script>
</head>
<body onload="load()" onunload="GUnload()">
<div id="map" style="width: 808px; height: 505px; background: rgb(0, 0, 0)"></div>
</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>
<div id="map" style="width: 808px; height: 505px; background: url(png/map.png)"></div>
</body>
</html>
HTML;
}
?>

197
php/library.php Executable file
View file

@ -0,0 +1,197 @@
<?php
function movie2locations($id) {
$file = 'data/locations.data';
if (file_exists($file)) {
while (file_exists('data/locations.lock'))
usleep(100000);
$locations = unserialize(file_get_contents($file));
}
if (!$locations[$id]) {
$point = array();
$html = file_get_contents('http://imdb.com/title/tt' . $id . '/locations');
$string = explode('&&locations=', $html);
for ($i = 1; $i < count($string); $i++) {
$key = count($point);
$substring = explode('&&', $string[$i]);
$point[$key]['location'] = urldecode($substring[0]);
if (strstr($point[$key]['location'], ' - '))
$point[$key]['location'] = substr($point[$key]['location'], strpos($point[$key]['location'], ' - ') + 3);
$point[$key]['level'] = 0;
$substring = explode('<dd>', $string[$i]);
$substring = explode('</dd>', $substring[1]);
$point[$key]['description'] = trim(strip_tags($substring[0]));
}
foreach ($point as $key => $value) {
$point[$key]['coordinates'] = location2coordinates($point[$key]['location']);
while ($point[$key]['coordinates']['latitude'] == 0 && $point[$key]['coordinates']['longitude'] == 0 && strstr($value['location'], ', ')) {
$point[$key]['level']++;
$value['location'] = substr($value['location'], strpos($value['location'], ', ') + 2);
$point[$key]['coordinates'] = location2coordinates($value['location']);
}
/*
if ($point[$key]['coordinates']['latitude'] != 0 || $point[$key]['coordinates']['longitude'] != 0) {
$point_ = $point;
foreach ($point_ as $key_ => $value_) {
if ($key != $key_ && $point[$key]['latitude'] == $point_[$key_]['latitude'] && $point[$key]['longitude'] == $point_[$key_]['longitude']) {
$md5 = md5($point[$key]['location']);
$offset[$key]['latitude'] = (hexdec(substr($md5, 0, 1)) - 8) * 0.00001;
$offset[$key]['longitude'] = (hexdec(substr($md5, 1, 1)) - 8) * 0.00001;
$md5 = md5($point[$key_]['location']);
$offset[$key_]['latitude'] = (hexdec(substr($md5, 0, 1)) - 8) * 0.00001;
$offset[$key_]['longitude'] = (hexdec(substr($md5, 1, 1)) - 8) * 0.00001;
}
}
}
*/
}
/*
foreach ($point as $key => $value) {
if ($offset[$key]['latitude'])
$point[$key]['coordinates']['latitude'] += $offset[$key]['latitude'];
if ($offset[$key]['longitude'])
$point[$key]['coordinates']['longitude'] += $offset[$key]['longitude'];
}
*/
$locations[$id] = $point;
// $locations_ = unserialize(file_get_contents($file));
// $locations_[$id] = $locations[$id];
// $locations = $locations_;
ksort($locations);
touch('data/locations.lock');
file_put_contents($file, serialize($locations));
unlink('data/locations.lock');
}
return $locations[$id];
}
function location2coordinates($location) {
/*
translates a location name to coordinates (latitude/longitude)
*/
$file = 'data/coordinates.data';
if (file_exists($file)) {
while (file_exists('data/coordinates.lock'))
usleep(100000);
$coordinates = unserialize(file_get_contents($file));
}
if (!$coordinates[$location]) {
$query = urlencode($location);
$f = fsockopen('maps.google.com', 80, $err_num, $err_str, 60);
$string = 'GET /maps?q=' . $query . " HTTP/1.1\r\n";
$string .= "Accept: */*\r\n";
$string .= "Accept-Language: en\r\n";
$string .= "User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/418 (KHTML, like Gecko) Safari/417.9.3\r\n";
$string .= "Connection: close\r\n";
$string .= "Host: maps.google.com\r\n";
$string .= "\r\n";
fwrite($f, $string);
$data = stream_get_contents($f);
fclose($f);
$code = substr($data, 9, 3);
if ($code == 200)
$html = substr($data, strpos($data, "\r\n\r\n") + 4);
else
$data = $code;
$substr = substr($html, strpos($html, '{center:{lat:') + 13);
$coordinates[$location]['latitude'] = substr($substr, 0, strpos($substr, ',lng:'));
$substr = substr($substr, strpos($substr, ',lng:') + 5);
$coordinates[$location]['longitude'] = substr($substr, 0, strpos($substr, '}'));
$substr = substr($html, strpos($html, ',span:{lat:') + 11);
$coordinates[$location]['spanLatitude'] = substr($substr, 0, strpos($substr, ',lng:'));
$substr = substr($substr, strpos($substr, ',lng:') + 5);
$coordinates[$location]['spanLongitude'] = substr($substr, 0, strpos($substr, '}'));
if ($location != 'USA' && $coordinates[$location]['latitude'] == 37.0625 && $coordinates[$location]['longitude'] == -95.677068) {
$coordinates[$location]['latitude'] = 0;
$coordinates[$location]['longitude'] = 0;
$coordinates[$location]['spanLatitude'] = 0;
$coordinates[$location]['spanLongitude'] = 0;
}
// /*
if (strstr($coordinates[$location]['latitude'] . $coordinates[$location]['longitude'] . $coordinates[$location]['spanLatitude'] . $coordinates[$location]['spanLongitude'], ' ')) {
$coordinates[$location]['latitude'] = 0;
$coordinates[$location]['longitude'] = 0;
$coordinates[$location]['spanLatitude'] = 0;
$coordinates[$location]['spanLongitude'] = 0;
}
// */
/*
foreach ($coordinates as $key => $value) {
echo $key;
if (strstr($value['latitude'] . $value['longitude'] . $value['spanLatitude'] . $value['spanLongitude'], ' ')) {
die($key);
unset($coordinates[$key]);
}
}
*/
ksort($coordinates);
while (file_exists('data/coordinates.lock'))
usleep(100000);
touch('data/coordinates.lock');
file_put_contents($file, serialize($coordinates));
if (filesize($file) > 100000)
copy($file, 'data/coordinates.backup.data');
unlink('data/coordinates.lock');
}
return $coordinates[$location];
}
function coordinates2string($latitude, $longitude) {
/*
translates coordinates (latitude/longitude) to string (DD°MM'SS"X)
*/
$latitudeDegrees = floor(abs($latitude));
$latitudeDecimals = abs($latitude) - $latitudeDegrees;
$latitudeMinutes = str_pad(floor($latitudeDecimals * 60), 2, '0', STR_PAD_LEFT);
$latitudeSeconds = str_pad(round(($latitudeDecimals - $latitudeMinutes / 60) * 3600), 2, '0', STR_PAD_LEFT);
$latitudeHemisphere = str_repeat('N', $latitude >= 0) . str_repeat('S', $latitude < 0);
$longitudeDegrees = floor(abs($longitude));
$longitudeDecimals = abs($longitude) - $longitudeDegrees;
$longitudeMinutes = str_pad(floor((abs($longitude) - $longitudeDegrees) * 60), 2, '0', STR_PAD_LEFT);
$longitudeSeconds = str_pad(round(($longitudeDecimals - $longitudeMinutes / 60) * 3600), 2, '0', STR_PAD_LEFT);
$longitudeHemisphere = str_repeat('W', $longitude <= 0) . str_repeat('E', $longitude > 0);
$string = $latitudeDegrees . '&deg;' . $latitudeMinutes . '&apos;' . $latitudeSeconds . '&quot;' . $latitudeHemisphere;
$string .= ' / ';
$string .= $longitudeDegrees . '&deg;' . $longitudeMinutes . '&apos;' . $longitudeSeconds . '&quot;' . $longitudeHemisphere;
return $string;
}
?>

BIN
png/map.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

BIN
png/markerBlue.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

BIN
png/markerShadow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 665 B

BIN
png/markerYellow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB