| 213 |
*/ |
*/ |
| 214 |
function exif2gmap_process($text, $format = -1) { |
function exif2gmap_process($text, $format = -1) { |
| 215 |
//parse text in order to check gps exif. |
//parse text in order to check gps exif. |
| 216 |
$mapkey=variable_get('exif2gmap_MapKey',''); |
//$mapkey=variable_get('exif2gmap_MapKey',''); |
| 217 |
$width=variable_get('exif2gmap_GMwidth', ''); |
//$width=variable_get('exif2gmap_GMwidth', ''); |
| 218 |
$height=variable_get('exif2gmap_GMheight', ''); |
//$height=variable_get('exif2gmap_GMheight', ''); |
| 219 |
|
|
| 220 |
$url = trim(url('<front>', array('absolute' => TRUE)),"/"); |
$url = trim(url('<front>', array('absolute' => TRUE)),"/"); |
|
|
|
|
|
|
| 221 |
$res=array(); |
$res=array(); |
| 222 |
|
|
| 223 |
preg_match_all('/<a[^>]*href=["\']([^"\']*)["\'][^>]*>(.*?)<\/a>/', $text, $res,PREG_SET_ORDER); |
preg_match_all('/<a[^>]*href=["\']([^"\']*)["\'][^>]*>(.*?)<\/a>/', $text, $res,PREG_SET_ORDER); |
| 229 |
drupal_set_message("count=".$cnt); |
drupal_set_message("count=".$cnt); |
| 230 |
} |
} |
| 231 |
|
|
|
|
|
|
|
|
|
|
|
| 232 |
$ans=array(); |
$ans=array(); |
| 233 |
$j=-1; |
$j=-1; |
| 234 |
for($i=0;$i<$cnt;$i++){ |
for($i=0;$i<$cnt;$i++){ |
| 271 |
} |
} |
| 272 |
} |
} |
| 273 |
} |
} |
| 274 |
|
|
| 275 |
|
|
| 276 |
if(variable_get('exif2gmap_debug','')){ |
if(variable_get('exif2gmap_debug','')){ |
| 277 |
drupal_set_message(print_r($ans)); |
drupal_set_message(print_r($ans)); |
| 278 |
drupal_set_message("latnum=" .count($ans)); |
drupal_set_message("latnum=" .count($ans)); |
| 279 |
drupal_set_message("gps=". print_r($gps)); |
drupal_set_message("gps=". print_r($gps)); |
| 280 |
} |
} |
| 281 |
|
|
| 282 |
|
|
| 283 |
|
|
| 284 |
//Map Center point. |
//Map Center point. |
| 285 |
$Clat=0; |
$Clat=0; |
| 286 |
$Clon=0; |
$Clon=0; |
| 310 |
drupal_set_message("Clat=" .$Clat." Clon=".$Clon); |
drupal_set_message("Clat=" .$Clat." Clon=".$Clon); |
| 311 |
} |
} |
| 312 |
|
|
|
|
|
| 313 |
//google map javascript maker... |
//google map javascript maker... |
| 314 |
$digest=hash("sha256",$text); |
$digest=hash("sha256",$text); |
| 315 |
|
|
| 345 |
//add div portion. |
//add div portion. |
| 346 |
$text .= '<br><div id="map'.$digest.'" style="width: '.$width.'; height: '.$height.'"></div>'; |
$text .= '<br><div id="map'.$digest.'" style="width: '.$width.'; height: '.$height.'"></div>'; |
| 347 |
return $text; |
return $text; |
| 348 |
|
|
| 349 |
|
/* |
| 350 |
|
$ret=array(); |
| 351 |
|
$ret=exif2gmap_make_gmapcode($ans); |
| 352 |
|
drupal_set_message(print_r($ans)); |
| 353 |
|
drupal_set_message(print_r($ret)); |
| 354 |
|
drupal_set_html_head($ret[javascript_head]); |
| 355 |
|
drupal_add_js($ret[javascript_body]); |
| 356 |
|
$text .='<br>'; |
| 357 |
|
$text .=$ret[html]; |
| 358 |
|
|
| 359 |
|
return $text; |
| 360 |
|
*/ |
| 361 |
|
} |
| 362 |
|
|
| 363 |
|
/** |
| 364 |
|
* Implementation of hook_theme(), which enables api access to exif2gmap. |
| 365 |
|
*/ |
| 366 |
|
|
| 367 |
|
|
| 368 |
|
function exif2gmap_theme() { |
| 369 |
|
return array( |
| 370 |
|
'exif2gmap' => array('arguments' => array('photos')), |
| 371 |
|
); |
| 372 |
|
} |
| 373 |
|
|
| 374 |
|
|
| 375 |
|
/* |
| 376 |
|
* the arguments array format is below; |
| 377 |
|
* $photos = array( |
| 378 |
|
* array( |
| 379 |
|
* 'path' => 'my path', //required. |
| 380 |
|
* 'long' => 'long', //optional |
| 381 |
|
* 'lat' => 'lat', //optional |
| 382 |
|
* 'url' => 'destination url' //required |
| 383 |
|
* ), |
| 384 |
|
* array( |
| 385 |
|
* 'path' => 'my path', |
| 386 |
|
* 'long' => 'long', |
| 387 |
|
* 'lat' => 'lat', |
| 388 |
|
* 'url' => 'destination url' |
| 389 |
|
* ), |
| 390 |
|
* ---snip--- |
| 391 |
|
* ); |
| 392 |
|
*/ |
| 393 |
|
|
| 394 |
|
function theme_exif2gmap($photos){ |
| 395 |
|
/* |
| 396 |
|
Check argument first. |
| 397 |
|
*/ |
| 398 |
|
$ans=array(); |
| 399 |
|
$tmp=array(); |
| 400 |
|
$j=-1; |
| 401 |
|
|
| 402 |
|
for($i=0;$i<count($photos);$i++){ |
| 403 |
|
$gpsflag=0; |
| 404 |
|
if(isset($photos[$i][path]) && isset($photos[$i][url])){ |
| 405 |
|
/*Check file has gpsdata or not.*/ |
| 406 |
|
$tmp=get_gpsdata($photos[$i][path]); |
| 407 |
|
if(isnull($tmp)){ |
| 408 |
|
if(!isset($photos[$i][long]) || !isset($photos[$i][lat])){ |
| 409 |
|
/*NG case */ |
| 410 |
|
}else{ |
| 411 |
|
$j++; |
| 412 |
|
$ans[$j]=array(); |
| 413 |
|
$ans[$j]['lat']=$photos[$i][lat]; |
| 414 |
|
$ans[$j]['lon']=$photos[$i][long]; |
| 415 |
|
$ans[$j]['fpath']=$photos[$i][path]; |
| 416 |
|
$ans[$j]['tag']=$photos[$i][url]; |
| 417 |
|
} |
| 418 |
|
}else{ |
| 419 |
|
$j++; |
| 420 |
|
$ans[$j]=array(); |
| 421 |
|
$ans[$j]['lat']=get_xxxitude( $tmp, 'lat' ); |
| 422 |
|
$ans[$j]['lon']=get_xxxitude( $tmp, 'lon' ); |
| 423 |
|
$ans[$j]['fpath']=$photos[$i][path]; |
| 424 |
|
$ans[$j]['tag']=$photos[$i][url]; |
| 425 |
|
} |
| 426 |
|
} |
| 427 |
|
} |
| 428 |
|
|
| 429 |
|
/*Latter is same.*/ |
| 430 |
|
|
| 431 |
|
return exif2gmap_male_gmapcode($ans); |
| 432 |
|
|
| 433 |
} |
} |
| 434 |
|
|
| 435 |
|
|
| 436 |
|
function exif2gmap_make_gmapcode($ans){ |
| 437 |
|
$width=variable_get('exif2gmap_GMwidth', ''); |
| 438 |
|
$height=variable_get('exif2gmap_GMheight', ''); |
| 439 |
|
$mapkey=variable_get('exif2gmap_MapKey',''); |
| 440 |
|
|
| 441 |
|
if(variable_get('exif2gmap_debug','')){ |
| 442 |
|
drupal_set_message(print_r($ans)); |
| 443 |
|
drupal_set_message("latnum=" .count($ans)); |
| 444 |
|
drupal_set_message("gps=". print_r($gps)); |
| 445 |
|
} |
| 446 |
|
//Map Center point. |
| 447 |
|
$Clat=0; |
| 448 |
|
$Clon=0; |
| 449 |
|
if(count($ans)==0){ |
| 450 |
|
return NULL; |
| 451 |
|
} |
| 452 |
|
$SW=260; |
| 453 |
|
$NE=-260; |
| 454 |
|
for($i=0;$i<count($ans);$i++){ |
| 455 |
|
$Clat += $ans[$i]['lat']; |
| 456 |
|
$Clon += $ans[$i]['lon']; |
| 457 |
|
if(($ans[$i]['lat']+$ans[$i]['lon'])>$NE){ |
| 458 |
|
$NE=$ans[$i]['lat']+$ans[$i]['lon']; |
| 459 |
|
$NElat=$ans[$i]['lat']; |
| 460 |
|
$NElon=$ans[$i]['lon']; |
| 461 |
|
} |
| 462 |
|
if(($ans[$i]['lat']+$ans[$i]['lon'])<$SW){ |
| 463 |
|
$SW=$ans[$i]['lat']+$ans[$i]['lon']; |
| 464 |
|
$SWlat=$ans[$i]['lat']; |
| 465 |
|
$SWlon=$ans[$i]['lon']; |
| 466 |
|
} |
| 467 |
|
} |
| 468 |
|
$Clat=$Clat/count($ans); |
| 469 |
|
$Clon=$Clon/count($ans); |
| 470 |
|
|
| 471 |
|
if(variable_get('exif2gmap_debug','')){ |
| 472 |
|
drupal_set_message("Clat=" .$Clat." Clon=".$Clon); |
| 473 |
|
} |
| 474 |
|
|
| 475 |
|
//google map javascript maker... |
| 476 |
|
$digest=hash("sha256",$ans[0][fpath]); |
| 477 |
|
|
| 478 |
|
$script = 'var map; window.onload= function load(){ if (GBrowserIsCompatible()) { |
| 479 |
|
map = new GMap2(document.getElementById("map'.$digest.'"));'; |
| 480 |
|
$script .= 'map.setCenter(new GLatLng(' .$Clat. ',' .$Clon. '), 7);'; |
| 481 |
|
$script .= 'map.addControl(new GLargeMapControl());'; |
| 482 |
|
$script .= 'var rectObj = new GLatLngBounds(new GLatLng('.$SWlat.','.$SWlon.'), new GLatLng('.$NElat.','.$NElon.'));'; |
| 483 |
|
$script .= 'var zm = map.getBoundsZoomLevel(rectObj); map.setZoom(zm-1);'; |
| 484 |
|
|
| 485 |
|
//Marker part. |
| 486 |
|
for($i=0;$i<count($ans);$i++){ |
| 487 |
|
|
| 488 |
|
$script .= 'var marker'.$i.'= new GMarker(new GLatLng(' .$ans[$i]['lat']. ',' .$ans[$i]['lon']. '));'; |
| 489 |
|
$script .= 'GEvent.addListener(marker'.$i.', "mouseover", function(){'; |
| 490 |
|
$tag=str_replace( '"','\'',$ans[$i]['tag']); |
| 491 |
|
$script .= 'marker'.$i.'.openInfoWindowHtml("' .$tag. '");});'; |
| 492 |
|
$script .= 'map.addOverlay(marker'.$i.');'; |
| 493 |
|
} |
| 494 |
|
$script .='}}'; |
| 495 |
|
//inline coding.. |
| 496 |
|
|
| 497 |
|
$ret=array(); |
| 498 |
|
//add div portion. |
| 499 |
|
$ret[html]='<div id="map'.$digest.'" style="width: '.$width.'; height: '.$height.'"></div>'; |
| 500 |
|
$ret[javascript_head]='<script type="text/javascript" src="http://maps.google.com/maps?file=api&v=2&key='.$mapkey.'"></script>'; |
| 501 |
|
$ret[javascript_body]=$script; |
| 502 |
|
return $ret; |
| 503 |
|
} |