Pastoid

gpsexif

The page you are looking at now is at this URL: http://pastoid.com/bw6

This paste was last updated on September 10, 2009 at 12:00 am.

Pasted Coderaw

 
<?php 
class IphoneGPS extends Plugin
{
public function filter_post_content_out ($content, $post) {
		$matches= array();
		if ( preg_match( '/<img [^>]+>/', $content, $matches) ) {
			// we got one! Now tease out the src element
			$html= new HTMLTokenizer( $matches[0] );
			$tokens= $html->parse();
			foreach ($tokens as $node ) {
				if ( 'img' == $node['name'] ) {
					$elements= $node['attrs'];
				}
			}
		}
		if ( ! isset( $elements['src'] ) ) {
			// no src= found, so don't try to do anything else
			return $content;
		}
		else
		{
			$url=get_location($elements['src']);
			str_replace($matches[0],$matches[0] . '<a href="'.$url.'">Map </a>', $content);
			return $content;
		}
	}
 
	private function get_location ($src)
	{
		$exif = exif_read_data($src, 0, true);
 
		$ns = (($exif['GPS']['GPSLatitudeRef']=="N") ? 1 : -1) ;
		$ndeg= explode("/",$exif['GPS']['GPSLatitude']['0']);
		$ndegrees = ($ndeg[0]/$ndeg[1]);
		$nmin= explode("/",$exif['GPS']['GPSLatitude']['1']);
		$nminutes = (($nmin[0]/$nmin[1])/60);
		$nsec= explode("/",$exif['GPS']['GPSLatitude']['2']);
		$nseconds = (($nsec[0]/$nsec[1])/360);
		$north = ($ns*($ndegrees+$nminutes+$nseconds));
 
		$ew = (($exif['GPS']['GPSLongitudeRef']=="N") ? 1 : -1) ;
		$edeg= explode("/",$exif['GPS']['GPSLongitude']['0']);
		$edegrees = ($edeg[0]/$edeg[1]);
		$emin= explode("/",$exif['GPS']['GPSLongitude']['1']);
		$eminutes = (($emin[0]/$emin[1])/60);
		$esec= explode("/",$exif['GPS']['GPSLongitude']['2']);
		$eseconds = (($esec[0]/$esec[1])/360);
		$east = ($ew*($edegrees+$eminutes+$eseconds));
 
		$url = "http://maps.google.com?q=$north,$east";
		return $url;
	}
}
?>

Toggle wordwrap

Referring DomainHits
Unknown Referer 127
pastoid.com 6
drunkenmonkey.org 2
Is this paste spam?
<Hide