_apikey = $api_key; } function geocode($str){ $out = "xml"; $q = urlencode($str); $url = "http://maps.google.com/maps/geo?output={$out}&key={$this->_apikey}&q={$q}"; $res = $this->get($url); return $res; } function get($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $res = curl_exec($ch); return $res; } } # # # $args = array('folds' => 1, 'borders' => 0); $pdf = new pmPDF($args); $pdf->SetFont('Helvetica'); $pdf->SetFontSize(10); $fh = fopen("./paris.txt", "r"); $data = array(); $pg = 2; $key = "YER API KEY HERE"; $g = new google_geocoder($key); while (! feof($fh)){ $ln = fgets($fh); if (preg_match("/^#(.*)/", $ln, $m)){ $data['name'] = $m[1]; } else if (preg_match("/^t:(.*)/", $ln, $m)){ $data['phone'] = $m[1]; } else if (preg_match("/^-(.*)/", $ln, $m)){ # } else if (trim($ln)){ $data['addr'] = trim($ln); } else { if (! $data['addr']){ # print_r($data); $data=array(); continue; } $location = urlencode($data['addr'] . " Paris France"); $d = $g->geocode($location); # SO MUCH HATE.... preg_match("/([^<]+)<\/coordinates>/", $d, $m); list($lon, $lat) = explode(",", $m[1]); $tmp1 = get_img($lat, $lon, 4); $tmp2 = get_img($lat, $lon, 2); $res = $pdf->add_image($tmp1, $pg); $qr_init = array( 'data' => '/home/asc/lib/php/qr/data', 'images' => '/home/asc/lib/php/qr/image', ); $qr_addr_path = '/home/asc/Desktop/qr_addr.png'; $qr_addr = new QR($qr_init); $qr_addr->encode(array( 'd' => "{$location}\n{$data['phone']}", 'path' => $qr_addr_path, 'color' => array(0, 0, 51), )); $qr_edit_path = '/home/asc/Desktop/qr_edit.png'; $qr_edit = new QR($qr_init); $qr_edit->encode(array( 'd' => "http://example.com/edit/{$data['name']}", 'path' => $qr_edit_path, 'color' => array(84, 84, 84), )); $qr_geo_path = '/home/asc/Desktop/qr_geo.png'; $qr_geo = new QR($qr_init); $qr_geo->encode(array( 'd' => geospum($lat, $lon), 'path' => $qr_geo_path, 'color' => array(69, 139, 0), )); $pdf->add_image($qr_addr_path, $pg, array('y' => 2.5, 'h' => .75)); $pdf->add_image($qr_geo_path, $pg, array('y' => 2.5, 'x' => .75, 'h' => .75)); $pdf->add_image($qr_edit_path, $pg, array('y' => 2.5, 'x' => 1.5, 'h' => .75)); # $pg ++; $res = $pdf->add_image($tmp2, $pg); $txt = "{$data['name']}\n{$data['addr']}"; $pdf->add_text($txt, $pg, array('y' => 2.5, 'resume' => false)); # $pg ++; $data = array(); unlink($tmp1); unlink($tmp2); } } $pdf->Output(); # function get($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $res = curl_exec($ch); return $res; } function get_img($lat, $lon, $zoom){ $req = "http://api.local.yahoo.com/MapsService/V1/mapImage?appid=YahooDemo&latitude={$lat}&longitude={$lon}&zoom={$zoom}&image_width=500&image_type=png"; $res = get($req); $xml = new SimpleXMLElement($res); if (! $xml){ return; } $tmp = tempnam("/tmp", time()) . "-{$zoom}.png"; $fh = fopen($tmp, "w"); fwrite($fh, get($xml)); fclose($fh); return $tmp; } function geospum($lat, $lon){ $url = "http://geo.spum.org/?l={$lat},{$lon}"; return $url; } ?>