Advertisement
Guest User

shortcode.php

a guest
Mar 28th, 2012
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.25 KB | None | 0 0
  1. <?php
  2.  
  3. if ( !function_exists('cgmp_autoimage_shortcode_handler') ):
  4.     function cgmp_autoimage_shortcode_handler($attr, $content = null, $code = null) {
  5.  
  6.         if (is_admin() || is_feed()) {
  7.             return;
  8.         }
  9.  
  10.  
  11.         global $post;
  12.  
  13.         $args = array(
  14.            'post_type' => 'attachment',
  15.            'post_parent' => $post->ID
  16.           );
  17.  
  18.         $attachments = get_posts( $args );
  19.         $list_coord_gps="";
  20.  
  21.  
  22.         if ( $attachments ) {
  23.             foreach ( $attachments as $attachment ) {
  24.  
  25.                 $image_attributes = wp_get_attachment_image_src($attachment->ID,'full');
  26.                 $image_thumbnail = wp_get_attachment_image_src($attachment->ID,'thumbnail');
  27.  
  28.                 // from http://stackoverflow.com/questions/2526304/php-extract-gps-exif-data
  29.                 $exif = exif_read_data($image_attributes[0], 0, false);
  30.  
  31.  
  32.                 if ( $exif ) {
  33.                     $gps['LatDegree']=$exif["GPSLatitude"][0];
  34.                     $gps['LatMinute']=$exif["GPSLatitude"][1];
  35.                     $gps['LatSeconds']=$exif["GPSLatitude"][2];
  36.                     $gps['LongDegree']=$exif["GPSLongitude"][0];
  37.                     $gps['LongMinute']=$exif["GPSLongitude"][1];
  38.                     $gps['LongSeconds']=$exif["GPSLongitude"][2];
  39.  
  40.                     //get the Hemisphere multiplier
  41.                     $LatM = 1;
  42.                     $LongM = 1;
  43.  
  44.                     if($exif["GPSLatitudeRef"] == 'S')
  45.                     {
  46.                     $LatM = -1;
  47.                     }
  48.  
  49.                     if($exif["GPSLongitudeRef"] == 'W')
  50.                     {
  51.                     $LongM = -1;
  52.                     }
  53.  
  54.  
  55.                     //convert strings to numbers
  56.                     foreach($gps as $key => $value)
  57.                     {
  58.                         $pos = strpos($value, '/');
  59.                         if($pos !== false)
  60.                         {
  61.                             $temp = explode('/',$value);
  62.                             $gps[$key] = $temp[0] / $temp[1];
  63.                         }
  64.                     }
  65.  
  66.                     //calculate the decimal degree
  67.                     $result['latitude'] = $LatM * ($gps['LatDegree'] + ($gps['LatMinute'] / 60) + ($gps['LatSeconds'] / 3600));
  68.                     $result['longitude'] = $LongM * ($gps['LongDegree'] + ($gps['LongMinute'] / 60) + ($gps['LongSeconds'] / 3600));
  69.  
  70.  
  71.                     if( $result['latitude'] && $result['longitude'] ) {
  72.                         // Store image data
  73.                         if (!isset($nbimages)){
  74.                             $nbimages=1;
  75.                         }else{
  76.                             $nbimages++;
  77.                         }
  78.  
  79.                         $tab_coord_gps[$nbimages]['date']=$exif["DateTime"];
  80.                         $tab_coord_gps[$nbimages]['latlong']=$result['latitude'].",".$result['longitude'];
  81.                         $tab_coord_gps[$nbimages]['marker']="1-default.png";
  82.                         $tab_coord_gps[$nbimages]['thumb'].="#@$image_thumbnail[0]#@";
  83.                     }
  84.  
  85.                 }
  86.  
  87.             }
  88.  
  89.  
  90.                 // Sort photos by date
  91.                 foreach($tab_coord_gps as $c=>$key) {
  92.                     $sort_date[] = $key['date'];
  93.                 }
  94.  
  95.                 array_multisort($sort_date, SORT_ASC, $tab_coord_gps);
  96.  
  97.  
  98.  
  99.                 // Prepare string for addmarkerlist
  100.                 $nbimages=1;
  101.  
  102.                                 foreach($tab_coord_gps as $img)
  103.                                 {
  104.  
  105.                                     if (!empty($list_coord_gps)){
  106.                                             $list_coord_gps.="|";
  107.                                             $nbimages++;
  108.                                     }
  109.                     $list_coord_gps.=$img['latlong'];
  110.                     $list_coord_gps.="{}".$img['marker'];
  111.                     $list_coord_gps.="{}Image n&deg;".$nbimages."#-";
  112.                     $list_coord_gps.=$img['thumb'];
  113.                     $date=date_create_from_format('Y:m:d H:i:s', $img['date']);
  114.                     $list_coord_gps.="#-".date_format($date,'d/m/Y H:i:s');
  115.                     $list_coord_gps.="#-#*".$img['latlong']."#*";
  116.                                 }
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.             $shortcode_attribs = shortcode_atts(array(
  124.                 'latitude' => 0,
  125.                 'longitude' => 0,
  126.                 'zoom' => '12',
  127.                 'width' => 600,
  128.                 'height' => 500,
  129.                 'maptype' => 'terrain',
  130.                 'maptypecontrol' => 'true',
  131.                 'pancontrol' => 'false',
  132.                 'addresscontent' => '',
  133.                 'zoomcontrol' => 'true',
  134.                 'scalecontrol' => 'true',
  135.                 'streetviewcontrol' => 'true',
  136.                 'scrollwheelcontrol' => 'false',
  137.                 'showbike' => 'false',
  138.                 'bubbleautopan' => 'true',
  139.                 'showtraffic' => 'false',
  140.                 'showpanoramio' => 'false',
  141.                 'addmarkerlist' => $list_coord_gps,
  142.                 'kml' => '',
  143.                 'directionhint' => 'false',
  144.                 'mapalign' => 'center',
  145.                 'panoramiouid' => '',
  146.                 'addmarkermashup' => 'false',
  147.                 'language' => 'default',
  148.                 'poweredby' => 'true',
  149.                 'draggable' => 'true',
  150.                 'tiltfourtyfive' => 'false',
  151.                 'addmarkermashupbubble' => 'false'), $attr);
  152.  
  153.             return "<br style=\"clear: both;\" /><br><br>".cgmp_shortcode_googlemap_handler($shortcode_attribs);
  154.         }else{
  155.             return;
  156.         }
  157.     }
  158. endif;
  159.  
  160.  
  161. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement