/[drupal]/contributions/modules/exif2gmap/exif2gmap.module
ViewVC logotype

Diff of /contributions/modules/exif2gmap/exif2gmap.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.2.3, Tue Jan 20 12:15:03 2009 UTC revision 1.1.2.4, Tue Apr 21 16:24:32 2009 UTC
# Line 6  Line 6 
6    
7    
8  variable_set('exif2gmap_debug',0);  variable_set('exif2gmap_debug',0);
9    variable_set('exif2gmap_counter',0);
10    variable_set('exif2gmap_marker_counter',0);
11    variable_set('exif2gmap_script_body','');
12    
13  /**  /**
14   * Implementation of hook_help().   * Implementation of hook_help().
# Line 41  function exif2gmap_admin_settings() { Line 44  function exif2gmap_admin_settings() {
44      '#return_value' => 1,      '#return_value' => 1,
45      '#default_value' => variable_get('exif2gmap_valid', 0),      '#default_value' => variable_get('exif2gmap_valid', 0),
46    );    );
47      $form['exif2gmap']['exif2gmap_exif_show'] = array(
48   $form['exif2gmap']['exif2gmap_MapKey'] = array(      '#type' => 'checkbox',
49        '#title' => t('Show exif camera and lens info on gmap window'),
50        '#return_value' => 1,
51        '#default_value' => variable_get('exif2gmap_exif_show', 0),
52      );
53      $form['exif2gmap']['exif2gmap_MapKey'] = array(
54      '#type' => 'textfield',      '#type' => 'textfield',
55      '#title' => t('Google Map API Key'),      '#title' => t('Google Map API Key'),
56      '#default_value'=> variable_get('exif2gmap_MapKey', ''),      '#default_value'=> variable_get('exif2gmap_MapKey', ''),
# Line 52  function exif2gmap_admin_settings() { Line 60  function exif2gmap_admin_settings() {
60      '#attributes' => NULL,      '#attributes' => NULL,
61      '#required' => TRUE,      '#required' => TRUE,
62    );    );
63      $form['exif2gmap']['exif2gmap_GMwidth'] = array(
  $form['exif2gmap']['exif2gmap_GMwidth'] = array(  
64      '#type' => 'textfield',      '#type' => 'textfield',
65      '#title' => t('google map size(width)'),      '#title' => t('google map size(width)'),
66      '#default_value'=> variable_get('exif2gmap_GMwidth', ''),      '#default_value'=> variable_get('exif2gmap_GMwidth', ''),
# Line 63  function exif2gmap_admin_settings() { Line 70  function exif2gmap_admin_settings() {
70      '#attributes' => NULL,      '#attributes' => NULL,
71      '#required' => TRUE,      '#required' => TRUE,
72    );    );
73   $form['exif2gmap']['exif2gmap_GMheight'] = array(    $form['exif2gmap']['exif2gmap_GMheight'] = array(
74      '#type' => 'textfield',      '#type' => 'textfield',
75      '#title' => t('google map size(height)'),      '#title' => t('google map size(height)'),
76      '#default_value'=> variable_get('exif2gmap_GMheight', ''),      '#default_value'=> variable_get('exif2gmap_GMheight', ''),
# Line 207  function get_xxxitude( $gps, $type = 'la Line 214  function get_xxxitude( $gps, $type = 'la
214          return $ret;          return $ret;
215  }  }
216    
217    function get_cameradata($filename){
218           if(variable_get('exif2gmap_exif_show','')){
219                   $exif = exif_read_data($filename,0,true);
220           if($exif==FALSE){
221                           if(variable_get('exif2gmap_debug','')){
222                                   drupal_set_message("get_cameradata failed\n");
223                           }
224                   }
225                   $ret=array();
226                   foreach ($exif as $key => $section) {
227                           foreach ($section as $name => $val) {
228                                   //echo "$key.$name: $val\n";
229                                   if($key == 'MAKERNOTE' && $name == 'UndefinedTag:0x0095'){
230                                           $ret['Lens']=$val;
231                                   }
232                                   if($key == 'IFD0' && $name == 'Model'){
233                                           $ret['Model']=$val;
234                                   }
235                           }
236                   }
237                   return $ret;
238           }
239           return NULL;
240    }
241    
242    
243    
244    
245    
246  /**  /**
247   * Core part of exif2gmap google map marker.   * Core part of exif2gmap google map marker.
248   *   *
249   */   */
250  function exif2gmap_process($text, $format = -1) {  function exif2gmap_process($text, $format = -1) {
251          //parse text in order to check gps exif.          //parse text in order to check gps exif.
252    //$mapkey=variable_get('exif2gmap_MapKey','');    $mapkey=variable_get('exif2gmap_MapKey','');
253    //$width=variable_get('exif2gmap_GMwidth', '');    $width=variable_get('exif2gmap_GMwidth', '');
254    //$height=variable_get('exif2gmap_GMheight', '');    $height=variable_get('exif2gmap_GMheight', '');
255    
256    $url = trim(url('<front>', array('absolute' => TRUE)),"/");    $url = trim(url('<front>', array('absolute' => TRUE)),"/");
257          $res=array();          $res=array();
# Line 258  function exif2gmap_process($text, $forma Line 294  function exif2gmap_process($text, $forma
294                                          $fname=$res[$i][1];                                          $fname=$res[$i][1];
295                                  }                                  }
296    
297                            $gps=get_gpsdata($fname);                          $gps=get_gpsdata($fname);
298                            $camera=get_cameradata($fname);
299                                  if($gps!=NULL){                                  if($gps!=NULL){
300                                          $j++;                                          $j++;
301                                          $ans[$j]=array();                                          $ans[$j]=array();
# Line 267  function exif2gmap_process($text, $forma Line 304  function exif2gmap_process($text, $forma
304                                          $ans[$j]['fpath']=$fname;                                          $ans[$j]['fpath']=$fname;
305                                          $ans[$j]['tag']=$res[$i][0];                                          $ans[$j]['tag']=$res[$i][0];
306    
307                                            //Add exif data parse
308                                            if(isset($camera['Model'])){
309                                                    $ans[$j]['Model']=$camera['Model'];
310                                            }else{
311                                                    $ans[$j]['Model']=NULL;
312                                            }
313                                            if(isset($camera['Lens'])){
314                                                    $ans[$j]['Lens']=$camera['Lens'];
315                                            }else{
316                                                    $ans[$j]['Lens']=NULL;
317                                            }
318                                  }                                  }
319                          }                          }
320                  }                  }
# Line 312  function exif2gmap_process($text, $forma Line 360  function exif2gmap_process($text, $forma
360    
361          //google map javascript maker...          //google map javascript maker...
362          $digest=hash("sha256",$text);          $digest=hash("sha256",$text);
363            $map_counter=intval(variable_get('exif2gmap_counter',''));
364          $script = 'var map; window.onload= function load(){ if (GBrowserIsCompatible()) {          $marker_counter=intval(variable_get('exif2gmap_marker_counter',''));
365          map = new GMap2(document.getElementById("map'.$digest.'"));  
366          ';          $script_body=variable_get('exif2gmap_script_body','');
367    
368            $script_head = 'window.onload= function load(){ if (GBrowserIsCompatible()) {';
369            $script_body .= 'var map'.$map_counter.';map'.$map_counter.' = new GMap2(document.getElementById("map'.$digest.'"), { size: new GSize('.intval($width).','.intval($height).') });
370      ';
371    
372    $script .= 'map.setCenter(new GLatLng(' .$Clat. ',' .$Clon. '), 7);    $script_body .= 'map'.$map_counter.'.setCenter(new GLatLng(' .$Clat. ',' .$Clon. '), 7);
373          ';          ';
374    $script .= 'map.addControl(new GLargeMapControl());    $script_body .= 'map'.$map_counter.'.addControl(new GLargeMapControl());
375          ';          ';
376    
377          $script .= 'var rectObj = new GLatLngBounds(new GLatLng('.$SWlat.','.$SWlon.'), new GLatLng('.$NElat.','.$NElon.'));';          $script_body .= 'var rectObj = new GLatLngBounds(new GLatLng('.$SWlat.','.$SWlon.'), new GLatLng('.$NElat.','.$NElon.'));';
378          $script .= 'var zm = map.getBoundsZoomLevel(rectObj); map.setZoom(zm-1)';          $script_body .= 'var zm = map'.$map_counter.'.getBoundsZoomLevel(rectObj); map'.$map_counter.'.setZoom(zm-1)';
379    
380  //Marker part.  //Marker part.
381          for($i=0;$i<count($ans);$i++){          for($i=0;$i<count($ans);$i++){
382        $marker_counter=$marker_counter+$i;
383                  $script .= '                  $script_body .= '
384                  var marker'.$i.'= new GMarker(new GLatLng(' .$ans[$i]['lat']. ',' .$ans[$i]['lon']. '));';                  var marker'.$marker_counter.'= new GMarker(new GLatLng(' .$ans[$i]['lat']. ',' .$ans[$i]['lon']. '));';
385            $script .= 'GEvent.addListener(marker'.$i.', "mouseover", function(){';            $script_body .= 'GEvent.addListener(marker'.$marker_counter.', "mouseover", function(){';
386                  $tag=str_replace( '"','\'',$ans[$i]['tag']);                  $tag=str_replace( '"','\'',$ans[$i]['tag']);
387                  $script .= 'marker'.$i.'.openInfoWindowHtml("' .$tag. '");});';                  $script_body .= 'marker'.$marker_counter.'.openInfoWindowHtml("' .$tag. '<br>' .$ans[$i]['Model']. '<br>' .$ans[$i]['Lens']. '");});';
388          $script .= 'map.addOverlay(marker'.$i.');';          $script_body .= 'map'.$map_counter.'.addOverlay(marker'.$marker_counter.');';
389          }          }
390    
391          $script .='}}';          $script_tail ='}}';
392    
393            $script=$script_head.$script_body.$script_tail;
394    //inline coding..    //inline coding..
395          drupal_set_html_head('<script type="text/javascript" src="http://maps.google.com/maps?file=api&amp;v=2&amp;key='.$mapkey.'"></script>');          drupal_set_html_head('<script type="text/javascript" src="http://maps.google.com/maps?file=api&amp;v=2&amp;key='.$mapkey.'"></script>');
396          drupal_add_js($script,'inline');          drupal_add_js($script,'inline');
397    
398          //add div portion.          //add div portion.
399          $text .= '<br><div id="map'.$digest.'" style="width: '.$width.'; height: '.$height.'"></div>';          $text .= '<br><div id="map'.$digest.'" style="width: '.$width.'; height: '.$height.'"></div>';
400    
401            $map_counter=$map_counter+1;
402            $marker_counter=$marker_counter+1;
403    
404            variable_set('exif2gmap_counter',$map_counter);
405            variable_set('exif2gmap_marker_counter',$marker_counter);
406            variable_set('exif2gmap_script_body',$script_body);
407    
408          return $text;          return $text;
409    
410  /*  /*

Legend:
Removed from v.1.1.2.3  
changed lines
  Added in v.1.1.2.4

  ViewVC Help
Powered by ViewVC 1.1.2